module Comee module Core class SalesOrderItemsController < ApplicationController include Common def index super do SalesOrderItem.includes( :sales_order, :customer_order_item, :source, :product, :unit ).where(sales_order_id: params[:id]) end end def shipment_details details = SalesOrderItem.includes(shipment_items: :item_statuses, purchase_order_item: :purchase_order) .find(params[:id]) render_content( details, { include: ["shipment_items.item_statuses", "purchase_order_item.purchase_order"], serializer: SalesOrderItemDetailSerializer } ) end def suggest_values service = CustomerOrderService.new result = service.suggest_values(params[:id], suggest_params[:unit_id]) render json: {success: true, data: result} end def cancel item = set_object item.update(canceled: true) render_content(item) end def cancel_quantity item = set_object to_cancel = cancel_quantity_params[:quantity] raise(StandardError, "Quantity to cancel is greater than available quantity.") if to_cancel > item.quantity_remaining item.quantity_canceled += to_cancel item.save! render_content(item) rescue StandardError => e render_error(e) end def activate item = set_object item.update(canceled: false) render_content(item) end def destroy Comee::Core::SalesOrderItem.destroy(params[:id]) render json: {success: true} end private def suggest_params params.permit(:unit_id, :quantity) end def model_params params.require(:payload) .permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered, :quantity_canceled, :customer_item_no, :customer_item_description, :price, :handover_date, :delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id, :pallet_no, :source_id, :processing_status) end def cancel_quantity_params params.require(:payload).permit(:quantity) end end end end