|
1 | 1 | namespace Microsoft.Integration.Shopify;
|
2 | 2 |
|
3 | 3 | using Microsoft.Inventory.Item;
|
| 4 | +using Microsoft.Finance.Currency; |
4 | 5 | using Microsoft.Sales.Document;
|
5 | 6 | using Microsoft.Foundation.Address;
|
6 | 7 | using Microsoft.Sales.History;
|
@@ -118,6 +119,10 @@ codeunit 30166 "Shpfy Process Order"
|
118 | 119 | SalesHeader.Validate("Tax Area Code", ShopifyTaxArea."Tax Area Code");
|
119 | 120 | if ShopifyOrderHeader."Shipping Method Code" <> '' then
|
120 | 121 | SalesHeader.Validate("Shipment Method Code", ShopifyOrderHeader."Shipping Method Code");
|
| 122 | + if ShopifyOrderHeader."Shipping Agent Code" <> '' then begin |
| 123 | + SalesHeader.Validate("Shipping Agent Code", ShopifyOrderHeader."Shipping Agent Code"); |
| 124 | + SalesHeader.Validate("Shipping Agent Service Code", ShopifyOrderHeader."Shipping Agent Service Code"); |
| 125 | + end; |
121 | 126 | if ShopifyOrderHeader."Payment Method Code" <> '' then
|
122 | 127 | SalesHeader.Validate("Payment Method Code", ShopifyOrderHeader."Payment Method Code");
|
123 | 128 |
|
@@ -173,8 +178,10 @@ codeunit 30166 "Shpfy Process Order"
|
173 | 178 | ShopifyOrderLine: Record "Shpfy Order Line";
|
174 | 179 | OrderShippingCharges: Record "Shpfy Order Shipping Charges";
|
175 | 180 | ShopLocation: Record "Shpfy Shop Location";
|
| 181 | + ShipmentMethodMapping: Record "Shpfy Shipment Method Mapping"; |
176 | 182 | SuppressAsmWarning: Codeunit "Shpfy Suppress Asm Warning";
|
177 | 183 | IsHandled: Boolean;
|
| 184 | + ShipmentChargeType: Boolean; |
178 | 185 | ShopfyOrderNoLbl: Label 'Shopify Order No.: %1', Comment = '%1 = Order No.';
|
179 | 186 | begin
|
180 | 187 | BindSubscription(SuppressAsmWarning);
|
@@ -230,31 +237,133 @@ codeunit 30166 "Shpfy Process Order"
|
230 | 237 | OrderShippingCharges.Reset();
|
231 | 238 | OrderShippingCharges.SetRange("Shopify Order Id", ShopifyOrderHeader."Shopify Order Id");
|
232 | 239 | OrderShippingCharges.SetFilter(Amount, '>0');
|
233 |
| - if OrderShippingCharges.FindSet() then begin |
234 |
| - ShopifyShop.TestField("Shipping Charges Account"); |
| 240 | + if OrderShippingCharges.FindSet() then |
235 | 241 | repeat
|
236 | 242 | IsHandled := false;
|
237 | 243 | OrderEvents.OnBeforeCreateShippingCostSalesLine(ShopifyOrderHeader, OrderShippingCharges, SalesHeader, SalesLine, IsHandled);
|
238 | 244 | if not IsHandled then begin
|
| 245 | + |
| 246 | + if ShipmentMethodMapping.Get(ShopifyShop.Code, OrderShippingCharges.Title) then |
| 247 | + if ShipmentMethodMapping."Shipping Charges Type" <> ShipmentMethodMapping."Shipping Charges Type"::" " then begin |
| 248 | + ShipmentMethodMapping.TestField("Shipping Charges No."); |
| 249 | + ShipmentChargeType := true; |
| 250 | + end; |
| 251 | + |
| 252 | + if not ShipmentChargeType then |
| 253 | + ShopifyShop.TestField("Shipping Charges Account"); |
| 254 | + |
239 | 255 | SalesLine.Init();
|
240 | 256 | SalesLine.SetHideValidationDialog(true);
|
241 | 257 | SalesLine.Validate("Document Type", SalesHeader."Document Type");
|
242 | 258 | SalesLine.Validate("Document No.", SalesHeader."No.");
|
243 | 259 | SalesLine.Validate("Line No.", GetNextLineNo(SalesHeader));
|
244 | 260 | SalesLine.Insert(true);
|
245 | 261 |
|
246 |
| - SalesLine.Validate(Type, SalesLine.Type::"G/L Account"); |
247 |
| - SalesLine.Validate("No.", ShopifyShop."Shipping Charges Account"); |
| 262 | + if ShipmentChargeType then begin |
| 263 | + SalesLine.Validate(Type, ShipmentMethodMapping."Shipping Charges Type"); |
| 264 | + SalesLine.Validate("No.", ShipmentMethodMapping."Shipping Charges No."); |
| 265 | + end else begin |
| 266 | + SalesLine.Validate(Type, SalesLine.Type::"G/L Account"); |
| 267 | + SalesLine.Validate("No.", ShopifyShop."Shipping Charges Account"); |
| 268 | + end; |
| 269 | + |
| 270 | + SalesLine.Validate("Shipping Agent Code", ShipmentMethodMapping."Shipping Agent Code"); |
| 271 | + SalesLine.Validate("Shipping Agent Service Code", ShipmentMethodMapping."Shipping Agent Service Code"); |
248 | 272 | SalesLine.Validate(Quantity, 1);
|
249 | 273 | SalesLine.Validate(Description, OrderShippingCharges.Title);
|
250 | 274 | SalesLine.Validate("Unit Price", OrderShippingCharges.Amount);
|
251 | 275 | SalesLine.Validate("Line Discount Amount", OrderShippingCharges."Discount Amount");
|
252 | 276 | SalesLine."Shpfy Order No." := ShopifyOrderHeader."Shopify Order No.";
|
253 | 277 | SalesLine.Modify(true);
|
| 278 | + |
| 279 | + if SalesLine.Type = SalesLine.Type::"Charge (Item)" then |
| 280 | + AssignItemCharges(SalesHeader, SalesLine); |
254 | 281 | end;
|
255 | 282 | OrderEvents.OnAfterCreateShippingCostSalesLine(ShopifyOrderHeader, OrderShippingCharges, SalesHeader, SalesLine);
|
256 | 283 | until OrderShippingCharges.Next() = 0;
|
| 284 | + end; |
| 285 | + |
| 286 | + local procedure AssignItemCharges(SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line") |
| 287 | + var |
| 288 | + AssignItemChargeSales: Codeunit "Item Charge Assgnt. (Sales)"; |
| 289 | + ItemChargeAssgntLineAmt: Decimal; |
| 290 | + AssignableQty: Decimal; |
| 291 | + begin |
| 292 | + SalesLine.TestField("No."); |
| 293 | + SalesLine.TestField(Quantity); |
| 294 | + |
| 295 | + PrepareAssignItemChargesLines(SalesHeader, SalesLine, AssignableQty, ItemChargeAssgntLineAmt); |
| 296 | + AssignItemChargeSales.AssignItemCharges(SalesLine, AssignableQty, ItemChargeAssgntLineAmt, AssignableQty, ItemChargeAssgntLineAmt, AssignItemChargeSales.AssignEquallyMenuText()); |
| 297 | + end; |
| 298 | + |
| 299 | + local procedure PrepareAssignItemChargesLines( |
| 300 | + SalesHeader: Record "Sales Header"; |
| 301 | + SalesLine: Record "Sales Line"; |
| 302 | + var AssignableQty: Decimal; |
| 303 | + var ItemChargeAssgntLineAmt: Decimal |
| 304 | + ) |
| 305 | + var |
| 306 | + ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; |
| 307 | + begin |
| 308 | + GetItemChargeAssgntLineAmt(SalesHeader, SalesLine, ItemChargeAssgntSales, ItemChargeAssgntLineAmt); |
| 309 | + GetAssignableQty(SalesLine, ItemChargeAssgntSales, AssignableQty); |
| 310 | + end; |
| 311 | + |
| 312 | + local procedure GetItemChargeAssgntLineAmt( |
| 313 | + SalesHeader: Record "Sales Header"; |
| 314 | + SalesLine: Record "Sales Line"; |
| 315 | + var ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; |
| 316 | + var ItemChargeAssgntLineAmt: Decimal |
| 317 | + ) |
| 318 | + var |
| 319 | + Currency: Record Currency; |
| 320 | + begin |
| 321 | + SalesHeader := SalesLine.GetSalesHeader(); |
| 322 | + Currency.Initialize(SalesHeader."Currency Code"); |
| 323 | + if (SalesLine."Inv. Discount Amount" = 0) and (SalesLine."Line Discount Amount" = 0) and |
| 324 | + (not SalesHeader."Prices Including VAT") |
| 325 | + then |
| 326 | + ItemChargeAssgntLineAmt := SalesLine."Line Amount" |
| 327 | + else |
| 328 | + if SalesHeader."Prices Including VAT" then |
| 329 | + ItemChargeAssgntLineAmt := |
| 330 | + Round(SalesLine.CalcLineAmount() / (1 + SalesLine."VAT %" / 100), Currency."Amount Rounding Precision") |
| 331 | + else |
| 332 | + ItemChargeAssgntLineAmt := SalesLine.CalcLineAmount(); |
| 333 | + |
| 334 | + ItemChargeAssgntSales.Reset(); |
| 335 | + ItemChargeAssgntSales.SetRange("Document Type", SalesLine."Document Type"); |
| 336 | + ItemChargeAssgntSales.SetRange("Document No.", SalesLine."Document No."); |
| 337 | + ItemChargeAssgntSales.SetRange("Document Line No.", SalesLine."Line No."); |
| 338 | + ItemChargeAssgntSales.SetRange("Item Charge No.", SalesLine."No."); |
| 339 | + if not ItemChargeAssgntSales.FindLast() then begin |
| 340 | + ItemChargeAssgntSales."Document Type" := SalesLine."Document Type"; |
| 341 | + ItemChargeAssgntSales."Document No." := SalesLine."Document No."; |
| 342 | + ItemChargeAssgntSales."Document Line No." := SalesLine."Line No."; |
| 343 | + ItemChargeAssgntSales."Item Charge No." := SalesLine."No."; |
| 344 | + ItemChargeAssgntSales."Unit Cost" := |
| 345 | + Round(ItemChargeAssgntLineAmt / SalesLine.Quantity, Currency."Unit-Amount Rounding Precision"); |
257 | 346 | end;
|
| 347 | + |
| 348 | + ItemChargeAssgntLineAmt := |
| 349 | + Round(ItemChargeAssgntLineAmt * (SalesLine."Qty. to Invoice" / SalesLine.Quantity), Currency."Amount Rounding Precision"); |
| 350 | + end; |
| 351 | + |
| 352 | + local procedure GetAssignableQty( |
| 353 | + SalesLine: Record "Sales Line"; |
| 354 | + ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; |
| 355 | + var AssignableQty: Decimal |
| 356 | + ) |
| 357 | + var |
| 358 | + AssignItemChargeSales: Codeunit "Item Charge Assgnt. (Sales)"; |
| 359 | + begin |
| 360 | + if SalesLine.IsCreditDocType() then |
| 361 | + AssignItemChargeSales.CreateDocChargeAssgn(ItemChargeAssgntSales, SalesLine."Return Receipt No.") |
| 362 | + else |
| 363 | + AssignItemChargeSales.CreateDocChargeAssgn(ItemChargeAssgntSales, SalesLine."Shipment No."); |
| 364 | + |
| 365 | + SalesLine.CalcFields("Qty. to Assign", "Item Charge Qty. to Handle", "Qty. Assigned"); |
| 366 | + AssignableQty := SalesLine."Qty. to Invoice" + SalesLine."Quantity Invoiced" - SalesLine."Qty. Assigned"; |
258 | 367 | end;
|
259 | 368 |
|
260 | 369 | /// <summary>
|
|
0 commit comments