From 62466eb52bd71925929072238f5c93fb8aeefde7 Mon Sep 17 00:00:00 2001 From: aidasberesinevicius Date: Mon, 17 Jun 2024 13:11:46 +0300 Subject: [PATCH 1/5] Implement different shipping charges types --- .../Codeunits/ShpfyProcessOrder.Codeunit.al | 25 +++++++-- .../Pages/ShpfyShipmentMethodsMapping.Page.al | 20 +++++++ .../ShpfyShipmentMethodMapping.Table.al | 52 +++++++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al index afc8ec9ef4..99d6926eb0 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al @@ -180,8 +180,10 @@ codeunit 30166 "Shpfy Process Order" ShopifyOrderLine: Record "Shpfy Order Line"; OrderShippingCharges: Record "Shpfy Order Shipping Charges"; ShopLocation: Record "Shpfy Shop Location"; + ShipmentMethodMapping: Record "Shpfy Shipment Method Mapping"; SuppressAsmWarning: Codeunit "Shpfy Suppress Asm Warning"; IsHandled: Boolean; + ShipmentChargeType: Boolean; ShopfyOrderNoLbl: Label 'Shopify Order No.: %1', Comment = '%1 = Order No.'; begin BindSubscription(SuppressAsmWarning); @@ -244,7 +246,16 @@ codeunit 30166 "Shpfy Process Order" OrderShippingCharges.SetRange("Shopify Order Id", ShopifyOrderHeader."Shopify Order Id"); OrderShippingCharges.SetFilter(Amount, '>0'); if OrderShippingCharges.FindSet() then begin - ShopifyShop.TestField("Shipping Charges Account"); + + if ShipmentMethodMapping.Get(ShopifyShop.Code, OrderShippingCharges.Title) then + if ShipmentMethodMapping."Shipping Charges Type" <> ShipmentMethodMapping."Shipping Charges Type"::" " then begin + ShipmentMethodMapping.TestField("Shipping Charges No."); + ShipmentChargeType := true; + end; + + if not ShipmentChargeType then + ShopifyShop.TestField("Shipping Charges Account"); + repeat IsHandled := false; OrderEvents.OnBeforeCreateShippingCostSalesLine(ShopifyOrderHeader, OrderShippingCharges, SalesHeader, SalesLine, IsHandled); @@ -256,8 +267,16 @@ codeunit 30166 "Shpfy Process Order" SalesLine.Validate("Line No.", GetNextLineNo(SalesHeader)); SalesLine.Insert(true); - SalesLine.Validate(Type, SalesLine.Type::"G/L Account"); - SalesLine.Validate("No.", ShopifyShop."Shipping Charges Account"); + if ShipmentChargeType then begin + SalesLine.Validate(Type, ShipmentMethodMapping."Shipping Charges Type"); + SalesLine.Validate("No.", ShipmentMethodMapping."Shipping Charges No."); + end else begin + SalesLine.Validate(Type, SalesLine.Type::"G/L Account"); + SalesLine.Validate("No.", ShopifyShop."Shipping Charges Account"); + end; + + SalesLine.Validate("Shipping Agent Code", ShipmentMethodMapping."Shipping Agent Code"); + SalesLine.Validate("Shipping Agent Service Code", ShipmentMethodMapping."Shipping Agent Service Code"); SalesLine.Validate(Quantity, 1); SalesLine.Validate(Description, OrderShippingCharges.Title); SalesLine.Validate("Unit Price", OrderShippingCharges.Amount); diff --git a/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al b/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al index 70b28df117..04a08fba38 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al +++ b/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al @@ -26,6 +26,26 @@ page 30129 "Shpfy Shipment Methods Mapping" ApplicationArea = All; ToolTip = 'Specifies the shipping method in D365BC.'; } + field("Shipping Charges Type"; Rec."Shipping Charges Type") + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the Shipping Charges Type field.'; + } + field("Shipping Charges No."; Rec."Shipping Charges No.") + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the Shipping Charges No. field.'; + } + field("Shipping Agent Code"; Rec."Shipping Agent Code") + { + ApplicationArea = All; + ToolTip = 'Specifies the code for the shipping agent who is transporting the items.'; + } + field("Shipping Agent Service Code"; Rec."Shipping Agent Service Code") + { + ApplicationArea = All; + ToolTip = 'Specifies the code for the service, such as a one-day delivery, that is offered by the shipping agent.'; + } } } } diff --git a/Apps/W1/Shopify/app/src/Shipping/Tables/ShpfyShipmentMethodMapping.Table.al b/Apps/W1/Shopify/app/src/Shipping/Tables/ShpfyShipmentMethodMapping.Table.al index ea91386f18..89819deeeb 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Tables/ShpfyShipmentMethodMapping.Table.al +++ b/Apps/W1/Shopify/app/src/Shipping/Tables/ShpfyShipmentMethodMapping.Table.al @@ -1,6 +1,9 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Foundation.Shipping; +using Microsoft.Sales.Document; +using Microsoft.Finance.GeneralLedger.Account; +using Microsoft.Inventory.Item; /// /// Table Shpfy Shipment Method Mapping (ID 30131). @@ -31,6 +34,55 @@ table 30131 "Shpfy Shipment Method Mapping" DataClassification = CustomerContent; TableRelation = "Shipment Method"; } + field(4; "Shipping Charges Type"; Enum "Sales Line Type") + { + Caption = 'Shipping Charges Type'; + DataClassification = CustomerContent; + ValuesAllowed = " ", "G/L Account", Item, "Charge (Item)"; + + trigger OnValidate() + begin + if "Shipping Charges Type" <> xRec."Shipping Charges Type" then + Clear("Shipping Charges No."); + end; + } + field(5; "Shipping Charges No."; Code[20]) + { + Caption = 'Shipping Charges No.'; + TableRelation = if ("Shipping Charges Type" = const("G/L Account")) "G/L Account" + else + if ("Shipping Charges Type" = const(Item)) Item + else + if ("Shipping Charges Type" = const("Charge (Item)")) "Item Charge"; + + trigger OnValidate() + var + GLAccount: Record "G/L Account"; + ShpfyShop: Record "Shpfy Shop"; + begin + if "Shipping Charges Type" = "Shipping Charges Type"::"G/L Account" then + if GLAccount.Get("Shipping Charges No.") then + ShpfyShop.CheckGLAccount(GLAccount); + end; + } + field(6; "Shipping Agent Code"; Code[10]) + { + AccessByPermission = TableData "Shipping Agent Services" = R; + Caption = 'Shipping Agent Code'; + TableRelation = "Shipping Agent"; + + trigger OnValidate() + begin + if "Shipping Agent Code" <> xRec."Shipping Agent Code" then + Clear("Shipping Agent Service Code"); + end; + } + field(7; "Shipping Agent Service Code"; Code[10]) + { + AccessByPermission = TableData "Shipping Agent Services" = R; + Caption = 'Shipping Agent Service Code'; + TableRelation = "Shipping Agent Services".Code where("Shipping Agent Code" = field("Shipping Agent Code")); + } } keys From 91c14bdb98ffcaa7ae261dc289e528aae832b37c Mon Sep 17 00:00:00 2001 From: aidasberesinevicius Date: Fri, 21 Jun 2024 08:56:01 +0300 Subject: [PATCH 2/5] Add additional logic for shipment agents and item charges --- .../Codeunits/ShpfyOrderEvents.Codeunit.al | 19 +++++ .../Codeunits/ShpfyOrderMapping.Codeunit.al | 23 +++++ .../Codeunits/ShpfyProcessOrder.Codeunit.al | 85 ++++++++++++++++--- .../Order handling/Pages/ShpfyOrder.Page.al | 10 +++ .../Tables/ShpfyOrderHeader.Table.al | 16 ++++ 5 files changed, 142 insertions(+), 11 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderEvents.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderEvents.Codeunit.al index 0fcc3adfad..d17d961b24 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderEvents.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderEvents.Codeunit.al @@ -78,6 +78,25 @@ codeunit 30162 "Shpfy Order Events" begin end; + [IntegrationEvent(false, false)] + /// + /// Description for OnBeforeMapShipmentAgent. + /// + /// Parameter of type Record "Shopify Order Header". + /// Parameter of type Boolean. + internal procedure OnBeforeMapShipmentAgent(var ShopifyOrderHeader: Record "Shpfy Order Header"; var Handled: Boolean) + begin + end; + + [IntegrationEvent(false, false)] + /// + /// Description for OnAfterMapShipmentAgent. + /// + /// Parameter of type Record "Shopify Order Header". + internal procedure OnAfterMapShipmentAgent(var ShopifyOrderHeader: Record "Shpfy Order Header") + begin + end; + [IntegrationEvent(false, false)] /// /// Description for OnBeforeMapPaymentMethod. diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al index ca765c3291..5114dece6a 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al @@ -1,6 +1,7 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Inventory.Item; +using Microsoft.Sales.Document; using Microsoft.CRM.Contact; using Microsoft.CRM.BusinessRelation; @@ -127,6 +128,7 @@ codeunit 30163 "Shpfy Order Mapping" end; MapShippingMethodCode(OrderHeader); + MapShippingAgent(OrderHeader); MapPaymentMethodCode(OrderHeader); OrderHeader.Modify(); exit((OrderHeader."Bill-to Customer No." <> '') and (OrderHeader."Sell-to Customer No." <> '')); @@ -163,6 +165,7 @@ codeunit 30163 "Shpfy Order Mapping" end; MapShippingMethodCode(OrderHeader); + MapShippingAgent(OrderHeader); MapPaymentMethodCode(OrderHeader); OrderHeader.Modify(); exit((OrderHeader."Bill-to Customer No." <> '') and (OrderHeader."Sell-to Customer No." <> '')); @@ -247,6 +250,26 @@ codeunit 30163 "Shpfy Order Mapping" end; end; + local procedure MapShippingAgent(var OrderHeader: Record "Shpfy Order Header") + var + OrderShippingCharges: Record "Shpfy Order Shipping Charges"; + ShipmentMethodMapping: Record "Shpfy Shipment Method Mapping"; + IsHandled: Boolean; + begin + if OrderHeader."Shipping Agent Code" = '' then begin + OrderEvents.OnBeforeMapShipmentAgent(OrderHeader, IsHandled); + if not IsHandled then begin + OrderShippingCharges.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); + if OrderShippingCharges.FindFirst() then + if ShipmentMethodMapping.Get(OrderHeader."Shop Code", OrderShippingCharges.Title) then begin + OrderHeader."Shipping Agent Code" := ShipmentMethodMapping."Shipping Agent Code"; + OrderHeader."Shipping Agent Service Code" := ShipmentMethodMapping."Shipping Agent Service Code"; + end; + OrderEvents.OnAfterMapShipmentAgent(OrderHeader); + end; + end; + end; + local procedure MapPaymentMethodCode(var OrderHeader: Record "Shpfy Order Header") var OrderTransaction: Record "Shpfy Order Transaction"; diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al index 99d6926eb0..afd30ade50 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al @@ -1,10 +1,12 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Inventory.Item; +using Microsoft.Finance.Currency; using Microsoft.Sales.Document; using Microsoft.Foundation.Address; using Microsoft.Sales.History; using Microsoft.Sales.Posting; +using Microsoft.Foundation.UOM; /// /// Codeunit Shpfy Process Order (ID 30166). @@ -121,6 +123,10 @@ codeunit 30166 "Shpfy Process Order" SalesHeader.Validate("Tax Area Code", ShopifyTaxArea."Tax Area Code"); if ShopifyOrderHeader."Shipping Method Code" <> '' then SalesHeader.Validate("Shipment Method Code", ShopifyOrderHeader."Shipping Method Code"); + if ShopifyOrderHeader."Shipping Agent Code" <> '' then begin + SalesHeader.Validate("Shipping Agent Code", ShopifyOrderHeader."Shipping Agent Code"); + SalesHeader.Validate("Shipping Agent Service Code", ShopifyOrderHeader."Shipping Agent Service Code"); + end; if ShopifyOrderHeader."Payment Method Code" <> '' then SalesHeader.Validate("Payment Method Code", ShopifyOrderHeader."Payment Method Code"); @@ -245,21 +251,21 @@ codeunit 30166 "Shpfy Process Order" OrderShippingCharges.Reset(); OrderShippingCharges.SetRange("Shopify Order Id", ShopifyOrderHeader."Shopify Order Id"); OrderShippingCharges.SetFilter(Amount, '>0'); - if OrderShippingCharges.FindSet() then begin - - if ShipmentMethodMapping.Get(ShopifyShop.Code, OrderShippingCharges.Title) then - if ShipmentMethodMapping."Shipping Charges Type" <> ShipmentMethodMapping."Shipping Charges Type"::" " then begin - ShipmentMethodMapping.TestField("Shipping Charges No."); - ShipmentChargeType := true; - end; - - if not ShipmentChargeType then - ShopifyShop.TestField("Shipping Charges Account"); - + if OrderShippingCharges.FindSet() then repeat IsHandled := false; OrderEvents.OnBeforeCreateShippingCostSalesLine(ShopifyOrderHeader, OrderShippingCharges, SalesHeader, SalesLine, IsHandled); if not IsHandled then begin + + if ShipmentMethodMapping.Get(ShopifyShop.Code, OrderShippingCharges.Title) then + if ShipmentMethodMapping."Shipping Charges Type" <> ShipmentMethodMapping."Shipping Charges Type"::" " then begin + ShipmentMethodMapping.TestField("Shipping Charges No."); + ShipmentChargeType := true; + end; + + if not ShipmentChargeType then + ShopifyShop.TestField("Shipping Charges Account"); + SalesLine.Init(); SalesLine.SetHideValidationDialog(true); SalesLine.Validate("Document Type", SalesHeader."Document Type"); @@ -283,10 +289,67 @@ codeunit 30166 "Shpfy Process Order" SalesLine.Validate("Line Discount Amount", OrderShippingCharges."Discount Amount"); SalesLine."Shpfy Order No." := ShopifyOrderHeader."Shopify Order No."; SalesLine.Modify(true); + + if SalesLine.Type = SalesLine.Type::"Charge (Item)" then + AssignItemCharges(SalesHeader, SalesLine); end; OrderEvents.OnAfterCreateShippingCostSalesLine(ShopifyOrderHeader, OrderShippingCharges, SalesHeader, SalesLine); until OrderShippingCharges.Next() = 0; + end; + + local procedure AssignItemCharges(SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line") + var + ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; + Currency: Record Currency; + AssignItemChargeSales: Codeunit "Item Charge Assgnt. (Sales)"; + ItemChargeAssgntLineAmt: Decimal; + AssignableQty: Decimal; + begin + SalesLine.TestField("No."); + SalesLine.TestField(Quantity); + + SalesLine.GetSalesHeader(); + Currency.Initialize(SalesHeader."Currency Code"); + if (SalesLine."Inv. Discount Amount" = 0) and (SalesLine."Line Discount Amount" = 0) and + (not SalesHeader."Prices Including VAT") + then + ItemChargeAssgntLineAmt := SalesLine."Line Amount" + else + if SalesHeader."Prices Including VAT" then + ItemChargeAssgntLineAmt := + Round(SalesLine.CalcLineAmount() / (1 + SalesLine."VAT %" / 100), Currency."Amount Rounding Precision") + else + ItemChargeAssgntLineAmt := SalesLine.CalcLineAmount(); + + ItemChargeAssgntSales.Reset(); + ItemChargeAssgntSales.SetRange("Document Type", SalesLine."Document Type"); + ItemChargeAssgntSales.SetRange("Document No.", SalesLine."Document No."); + ItemChargeAssgntSales.SetRange("Document Line No.", SalesLine."Line No."); + ItemChargeAssgntSales.SetRange("Item Charge No.", SalesLine."No."); + if not ItemChargeAssgntSales.FindLast() then begin + ItemChargeAssgntSales."Document Type" := SalesLine."Document Type"; + ItemChargeAssgntSales."Document No." := SalesLine."Document No."; + ItemChargeAssgntSales."Document Line No." := SalesLine."Line No."; + ItemChargeAssgntSales."Item Charge No." := SalesLine."No."; + ItemChargeAssgntSales."Unit Cost" := + Round(ItemChargeAssgntLineAmt / SalesLine.Quantity, Currency."Unit-Amount Rounding Precision"); end; + + ItemChargeAssgntLineAmt := + Round(ItemChargeAssgntLineAmt * (SalesLine."Qty. to Invoice" / SalesLine.Quantity), Currency."Amount Rounding Precision"); + + if SalesLine.IsCreditDocType() then + AssignItemChargeSales.CreateDocChargeAssgn(ItemChargeAssgntSales, SalesLine."Return Receipt No.") + else + AssignItemChargeSales.CreateDocChargeAssgn(ItemChargeAssgntSales, SalesLine."Shipment No."); + + Clear(AssignItemChargeSales); + Commit(); + + SalesLine.CalcFields("Qty. to Assign", "Item Charge Qty. to Handle", "Qty. Assigned"); + AssignableQty := SalesLine."Qty. to Invoice" + SalesLine."Quantity Invoiced" - SalesLine."Qty. Assigned"; + + AssignItemChargeSales.AssignItemCharges(SalesLine, AssignableQty, ItemChargeAssgntLineAmt, AssignableQty, ItemChargeAssgntLineAmt, AssignItemChargeSales.AssignEquallyMenuText()); end; /// diff --git a/Apps/W1/Shopify/app/src/Order handling/Pages/ShpfyOrder.Page.al b/Apps/W1/Shopify/app/src/Order handling/Pages/ShpfyOrder.Page.al index 53c7b012c8..17e7fa6610 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Pages/ShpfyOrder.Page.al +++ b/Apps/W1/Shopify/app/src/Order handling/Pages/ShpfyOrder.Page.al @@ -62,6 +62,16 @@ page 30113 "Shpfy Order" ApplicationArea = All; ToolTip = 'Specifies how items on the Shopify Order are shipped to the customer.'; } + field(ShippingAgentCode; Rec."Shipping Agent Code") + { + ApplicationArea = All; + ToolTip = 'Specifies which shipping agent is used to transport the items on the Shopify Order to the customer.'; + } + field(ShippingAgentServiceCode; Rec."Shipping Agent Service Code") + { + ApplicationArea = All; + ToolTip = 'Specifies the code that represents the default shipping agent service you are using for this Shopify Order.'; + } field("Payment Method"; Rec."Payment Method Code") { ApplicationArea = All; diff --git a/Apps/W1/Shopify/app/src/Order handling/Tables/ShpfyOrderHeader.Table.al b/Apps/W1/Shopify/app/src/Order handling/Tables/ShpfyOrderHeader.Table.al index 16fabfc966..31201852a6 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Tables/ShpfyOrderHeader.Table.al +++ b/Apps/W1/Shopify/app/src/Order handling/Tables/ShpfyOrderHeader.Table.al @@ -727,6 +727,22 @@ table 30118 "Shpfy Order Header" Caption = 'Has Order State Error'; DataClassification = SystemMetadata; } + field(1021; "Shipping Agent Code"; Code[10]) + { + Caption = 'Shipping Agent Code'; + TableRelation = "Shipping Agent"; + + trigger OnValidate() + begin + if "Shipping Agent Code" <> xRec."Shipping Agent Code" then + Clear("Shipping Agent Service Code"); + end; + } + field(1022; "Shipping Agent Service Code"; Code[10]) + { + Caption = 'Shipping Agent Service Code'; + TableRelation = "Shipping Agent Services".Code where("Shipping Agent Code" = field("Shipping Agent Code")); + } } keys { From e567633de10291449f13f3c5cd284fa44c38e74d Mon Sep 17 00:00:00 2001 From: aidasberesinevicius Date: Fri, 21 Jun 2024 10:21:00 +0300 Subject: [PATCH 3/5] Split procedure --- .../Codeunits/ShpfyProcessOrder.Codeunit.al | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al index afd30ade50..65095ee2c9 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al @@ -299,8 +299,6 @@ codeunit 30166 "Shpfy Process Order" local procedure AssignItemCharges(SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line") var - ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; - Currency: Record Currency; AssignItemChargeSales: Codeunit "Item Charge Assgnt. (Sales)"; ItemChargeAssgntLineAmt: Decimal; AssignableQty: Decimal; @@ -308,16 +306,42 @@ codeunit 30166 "Shpfy Process Order" SalesLine.TestField("No."); SalesLine.TestField(Quantity); + PrepareAssignItemChargesLines(SalesHeader, SalesLine, AssignableQty, ItemChargeAssgntLineAmt); + AssignItemChargeSales.AssignItemCharges(SalesLine, AssignableQty, ItemChargeAssgntLineAmt, AssignableQty, ItemChargeAssgntLineAmt, AssignItemChargeSales.AssignEquallyMenuText()); + end; + + local procedure PrepareAssignItemChargesLines( + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + var AssignableQty: Decimal; + var ItemChargeAssgntLineAmt: Decimal + ) + var + ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; + begin + GetItemChargeAssgntLineAmt(SalesHeader, SalesLine, ItemChargeAssgntSales, ItemChargeAssgntLineAmt); + GetAssignableQty(SalesLine, ItemChargeAssgntSales, AssignableQty); + end; + + local procedure GetItemChargeAssgntLineAmt( + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + var ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; + var ItemChargeAssgntLineAmt: Decimal + ) + var + Currency: Record Currency; + begin SalesLine.GetSalesHeader(); Currency.Initialize(SalesHeader."Currency Code"); if (SalesLine."Inv. Discount Amount" = 0) and (SalesLine."Line Discount Amount" = 0) and - (not SalesHeader."Prices Including VAT") + (not SalesHeader."Prices Including VAT") then ItemChargeAssgntLineAmt := SalesLine."Line Amount" else if SalesHeader."Prices Including VAT" then ItemChargeAssgntLineAmt := - Round(SalesLine.CalcLineAmount() / (1 + SalesLine."VAT %" / 100), Currency."Amount Rounding Precision") + Round(SalesLine.CalcLineAmount() / (1 + SalesLine."VAT %" / 100), Currency."Amount Rounding Precision") else ItemChargeAssgntLineAmt := SalesLine.CalcLineAmount(); @@ -332,24 +356,28 @@ codeunit 30166 "Shpfy Process Order" ItemChargeAssgntSales."Document Line No." := SalesLine."Line No."; ItemChargeAssgntSales."Item Charge No." := SalesLine."No."; ItemChargeAssgntSales."Unit Cost" := - Round(ItemChargeAssgntLineAmt / SalesLine.Quantity, Currency."Unit-Amount Rounding Precision"); + Round(ItemChargeAssgntLineAmt / SalesLine.Quantity, Currency."Unit-Amount Rounding Precision"); end; ItemChargeAssgntLineAmt := Round(ItemChargeAssgntLineAmt * (SalesLine."Qty. to Invoice" / SalesLine.Quantity), Currency."Amount Rounding Precision"); + end; + local procedure GetAssignableQty( + SalesLine: Record "Sales Line"; + ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; + var AssignableQty: Decimal + ) + var + AssignItemChargeSales: Codeunit "Item Charge Assgnt. (Sales)"; + begin if SalesLine.IsCreditDocType() then AssignItemChargeSales.CreateDocChargeAssgn(ItemChargeAssgntSales, SalesLine."Return Receipt No.") else AssignItemChargeSales.CreateDocChargeAssgn(ItemChargeAssgntSales, SalesLine."Shipment No."); - Clear(AssignItemChargeSales); - Commit(); - SalesLine.CalcFields("Qty. to Assign", "Item Charge Qty. to Handle", "Qty. Assigned"); AssignableQty := SalesLine."Qty. to Invoice" + SalesLine."Quantity Invoiced" - SalesLine."Qty. Assigned"; - - AssignItemChargeSales.AssignItemCharges(SalesLine, AssignableQty, ItemChargeAssgntLineAmt, AssignableQty, ItemChargeAssgntLineAmt, AssignItemChargeSales.AssignEquallyMenuText()); end; /// From b05b0f81ff4e4c0ed23163932ee74242338b1452 Mon Sep 17 00:00:00 2001 From: aidasberesinevicius Date: Wed, 26 Jun 2024 09:01:55 +0300 Subject: [PATCH 4/5] Adjust code by PR comments --- .../src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al | 2 +- .../app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al index 65095ee2c9..b2db64bc15 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al @@ -332,7 +332,7 @@ codeunit 30166 "Shpfy Process Order" var Currency: Record Currency; begin - SalesLine.GetSalesHeader(); + SalesHeader := SalesLine.GetSalesHeader(); Currency.Initialize(SalesHeader."Currency Code"); if (SalesLine."Inv. Discount Amount" = 0) and (SalesLine."Line Discount Amount" = 0) and (not SalesHeader."Prices Including VAT") diff --git a/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al b/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al index 04a08fba38..cf26927279 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al +++ b/Apps/W1/Shopify/app/src/Shipping/Pages/ShpfyShipmentMethodsMapping.Page.al @@ -34,6 +34,7 @@ page 30129 "Shpfy Shipment Methods Mapping" field("Shipping Charges No."; Rec."Shipping Charges No.") { ApplicationArea = All; + ShowMandatory = Rec."Shipping Charges Type" <> Rec."Shipping Charges Type"::" "; ToolTip = 'Specifies the value of the Shipping Charges No. field.'; } field("Shipping Agent Code"; Rec."Shipping Agent Code") From e33b62dfc8192544d7e1308c52245e0fb16579fe Mon Sep 17 00:00:00 2001 From: Tine Staric Date: Wed, 10 Jul 2024 12:24:45 +0300 Subject: [PATCH 5/5] Remove unused Using directives --- .../src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al | 1 - .../src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al | 1 - 2 files changed, 2 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al index 5114dece6a..0193e9c612 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyOrderMapping.Codeunit.al @@ -1,7 +1,6 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Inventory.Item; -using Microsoft.Sales.Document; using Microsoft.CRM.Contact; using Microsoft.CRM.BusinessRelation; diff --git a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al index b2db64bc15..1917241417 100644 --- a/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Order handling/Codeunits/ShpfyProcessOrder.Codeunit.al @@ -6,7 +6,6 @@ using Microsoft.Sales.Document; using Microsoft.Foundation.Address; using Microsoft.Sales.History; using Microsoft.Sales.Posting; -using Microsoft.Foundation.UOM; /// /// Codeunit Shpfy Process Order (ID 30166).