Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,36 @@ page 8020 "Service Object API"
field(unitOfMeasure; Rec."Unit of Measure")
{
}
field(vendorNo; Rec."Vendor No.")
{
}
field(vendorName; Rec."Vendor Name")
{
}
field(vendorName2; Rec."Vendor Name 2")
{
}
field(vendorItemNo; Rec."Vendor Item No.")
{
}
field(manufacturerCode; Rec."Manufacturer Code")
{
}
field(manufacturerName; Rec."Manufacturer Name")
{
}
field(salespersonCode; Rec."Salesperson Code")
{
}
field(salesOrderNo; Rec."Sales Order No.")
{
}
field(itemLedgerEntryNo; Rec."Item Ledger Entry No.")
{
}
field(lastSalesInvoiceNo; Rec."Last Sales Invoice No.")
{
}
}
field(systemCreatedAt; Rec.SystemCreatedAt)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using Microsoft.Finance.GeneralLedger.Journal;
using Microsoft.Finance.GeneralLedger.Posting;
using Microsoft.Inventory;
using Microsoft.Inventory.Item;
using Microsoft.Inventory.Journal;
using Microsoft.Inventory.Posting;
using Microsoft.Inventory.Tracking;
using Microsoft.Purchases.Posting;
using Microsoft.Sales.Document;
Expand All @@ -20,8 +22,12 @@ codeunit 8063 "Sales Documents"

var
TempSubscriptionItemSalesLine: Record "Sales Line" temporary;
GlobalSalesHeader: Record "Sales Header";
GlobalSalesLine: Record "Sales Line";
SalesServiceCommMgmt: Codeunit "Sales Subscription Line Mgmt.";
CalledFromContractRenewal: Boolean;
NegativeQuantityMsgShown: Boolean;
SubscriptionHeaderNotCreatedMsg: Label 'For negative quantity the Subscription is not created.';

local procedure DeleteAllTempSubscriptionItemSalesLines()
begin
Expand Down Expand Up @@ -337,38 +343,76 @@ codeunit 8063 "Sales Documents"
OnAfterSkipInsertingSalesInvoiceLineIfServiceCommitmentItemsExist(SalesHeader, SalesLine, IsHandled);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnAfterInsertShipmentLine, '', false, false)]
local procedure CreateServiceObjectWithSerialNoOnAfterInsertShipmentLine(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var SalesShptLine: Record "Sales Shipment Line")
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnBeforePostItemJnlLine, '', false, false)]
local procedure CacheSalesLineContextFromSalesPost(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line")
begin
//The function creates Subscription for Sales Line with Subscription Lines
CreateServiceObjectFromSales(SalesHeader, SalesLine, SalesShptLine);
GlobalSalesHeader := SalesHeader;
GlobalSalesLine := SalesLine;
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", OnPostAssocItemJnlLineOnBeforePost, '', false, false)]
local procedure CacheSalesLineContextFromDropShipment(SalesOrderLine: Record "Sales Line")
begin
GlobalSalesHeader.Get(SalesOrderLine."Document Type", SalesOrderLine."Document No.");
GlobalSalesLine := SalesOrderLine;
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", OnAfterSalesShptLineInsert, '', false, false)]
local procedure CreateServiceObjectWithSerialNoOnAfterSalesShptLineInsert(var SalesShptLine: Record "Sales Shipment Line"; SalesShptHeader: Record "Sales Shipment Header"; SalesOrderLine: Record "Sales Line")
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Jnl.-Post Line", OnAfterPostItemJnlLine, '', false, false)]
local procedure CreateSubscriptionHeaderFromItemJournalLine(var ItemJournalLine: Record "Item Journal Line")
var
SalesHeader: Record "Sales Header";
SubscriptionHeader: Record "Subscription Header";
begin
//The function creates Subscription for Sales Line with Subscription Lines
SalesHeader.Get(SalesOrderLine."Document Type", SalesOrderLine."Document No.");
CreateServiceObjectFromSales(SalesHeader, SalesOrderLine, SalesShptLine);
if ItemJournalLine.Adjustment then
exit;
if ItemJournalLine."Entry Type" <> ItemJournalLine."Entry Type"::Sale then
exit;
if not SalesServiceCommMgmt.IsSalesLineWithSalesServiceCommitments(GlobalSalesLine, false) then
exit;
if ItemJournalLine.Quantity < 0 then begin
ShowNegativeQuantityMessageIfNeeded(ItemJournalLine.Quantity);
ResetGlobalVariables();
exit;
end;

if ItemJournalLine.Quantity > 0 then
CreateServiceObjectFromSalesLine(GlobalSalesHeader, GlobalSalesLine, ItemJournalLine."Serial No.", ItemJournalLine.Quantity, ItemJournalLine."Item Shpt. Entry No.");
if ItemJournalLine."Invoiced Quantity" <> 0 then
if ItemJournalLine."Invoice No." <> '' then begin
SubscriptionHeader.SetRange("Item Ledger Entry No.", ItemJournalLine."Item Shpt. Entry No.");
SubscriptionHeader.ModifyAll("Last Sales Invoice No.", ItemJournalLine."Invoice No.", false);
end;
end;

#if not CLEAN28
[Obsolete('Use OnAfterPostItemJnlLine event subscriber to create Subscription Headers during item journal posting', '28.0')]
procedure CreateServiceObjectFromSales(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var SalesShptLine: Record "Sales Shipment Line")
var
TempTrackingSpecBuffer: Record "Tracking Specification" temporary;
Item: Record Item;
ItemTrackingDocMgt: Codeunit "Item Tracking Doc. Management";
begin
//The function creates Subscription for Sales Line with Subscription Lines
if SalesServiceCommMgmt.IsSalesLineWithSalesServiceCommitmentsToShip(SalesLine, SalesShptLine.Quantity) then begin
if SalesServiceCommMgmt.IsSalesLineWithSalesServiceCommitmentsToShip(SalesLine) then begin
if SalesShptLine.Quantity < 0 then begin
ShowNegativeQuantityMessageIfNeeded(SalesShptLine.Quantity);
ResetGlobalVariables();
exit;
end;

ItemTrackingDocMgt.RetrieveDocumentItemTracking(TempTrackingSpecBuffer, SalesShptLine."Document No.", Database::"Sales Shipment Header", 0);
TempTrackingSpecBuffer.SetRange("Source Ref. No.", SalesShptLine."Line No.");
if not TempTrackingSpecBuffer.IsEmpty() then
CreateServiceObjectFromTrackingSpecification(SalesHeader, SalesLine, TempTrackingSpecBuffer)
if TempTrackingSpecBuffer.FindSet() then
repeat
CreateServiceObjectFromSalesLine(SalesHeader, SalesLine, TempTrackingSpecBuffer."Serial No.", TempTrackingSpecBuffer."Quantity (Base)", 0);
until TempTrackingSpecBuffer.Next() = 0
else
CreateServiceObjectFromSalesLine(SalesHeader, SalesLine);
if SalesLine.Type = Enum::"Sales Line Type"::Item then
if Item.Get(SalesLine."No.") then
if not Item.HasSNSpecificItemTracking() then
CreateServiceObjectFromSalesLine(SalesHeader, SalesLine, '', 0, 0);
end;
end;
#endif

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnPostUpdateOrderLineOnSetDefaultQtyBlank, '', false, false)]
local procedure UpdateQuantitiesOnPostUpdateOrderLineOnSetDefaultQtyBlank(var TempSalesLine: Record "Sales Line" temporary)
Expand Down Expand Up @@ -440,20 +484,7 @@ codeunit 8063 "Sales Documents"
exit(SalesServiceCommMgmt.IsSalesLineWithServiceCommitmentItem(TempSalesLine, true) or ContractRenewalMgt.IsContractRenewal(TempSalesLine));
end;

local procedure CreateServiceObjectFromSalesLine(SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line")
var
Item: Record Item;
begin
if SalesLine.Type <> Enum::"Sales Line Type"::Item then
exit;
if not Item.Get(SalesLine."No.") then
exit;
if Item.HasSNSpecificItemTracking() then
exit;
CreateServiceObjectFromSalesLine(SalesHeader, SalesLine, '', 0);
end;

local procedure CreateServiceObjectFromSalesLine(SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line"; SerialNo: Code[50]; QtyPerSerialNo: Decimal)
local procedure CreateServiceObjectFromSalesLine(SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line"; SerialNo: Code[50]; QtyPerSerialNo: Decimal; ItemLedgerEntryNo: Integer)
var
ServiceObject: Record "Subscription Header";
IsHandled: Boolean;
Expand All @@ -464,16 +495,17 @@ codeunit 8063 "Sales Documents"
exit;

if SerialNo = '' then
CreateServiceObject(ServiceObject, SalesHeader, SalesLine, SalesLine."Qty. to Ship", SerialNo)
CreateServiceObject(ServiceObject, SalesHeader, SalesLine, SalesLine."Qty. to Ship", SerialNo, ItemLedgerEntryNo)
else
CreateServiceObject(ServiceObject, SalesHeader, SalesLine, QtyPerSerialNo, SerialNo);
CreateServiceObject(ServiceObject, SalesHeader, SalesLine, QtyPerSerialNo, SerialNo, ItemLedgerEntryNo);

CreateSubscriptionLineFromSalesLine(ServiceObject, SalesHeader, SalesLine);
OnAfterCreateSubscriptionHeaderFromSalesLine(ServiceObject, SalesHeader, SalesLine);
end;

local procedure CreateServiceObject(var ServiceObject: Record "Subscription Header"; SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line"; Quantity: Decimal; SerialNo: Code[50])
local procedure CreateServiceObject(var ServiceObject: Record "Subscription Header"; SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line"; Quantity: Decimal; SerialNo: Code[50]; ItemLedgerEntryNo: Integer)
var
Item: Record Item;
begin
ServiceObject.Init();
ServiceObject.SetHideValidationDialog(true);
Expand Down Expand Up @@ -512,6 +544,13 @@ codeunit 8063 "Sales Documents"
ServiceObject."Customer Price Group" := SalesHeader."Customer Price Group";
ServiceObject."Customer Reference" := SalesHeader."Your Reference";
ServiceObject."Variant Code" := SalesLine."Variant Code";

if Item.Get(SalesLine."No.") then
ServiceObject.UpdateVendorAndManufacturerFromItem(Item);
ServiceObject."Salesperson Code" := SalesHeader."Salesperson Code";
ServiceObject."Sales Order No." := SalesHeader."No.";
ServiceObject."Item Ledger Entry No." := ItemLedgerEntryNo;

OnCreateSubscriptionHeaderFromSalesLineBeforeInsertSubscriptionHeader(ServiceObject, SalesHeader, SalesLine);
ServiceObject.Insert(true);
OnCreateSubscriptionHeaderFromSalesLineAfterInsertSubscriptionHeader(ServiceObject, SalesHeader, SalesLine);
Expand Down Expand Up @@ -604,16 +643,6 @@ codeunit 8063 "Sales Documents"
end;
end;

local procedure CreateServiceObjectFromTrackingSpecification(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var TempTrackingSpecBuffer: Record "Tracking Specification" temporary)
begin
if TempTrackingSpecBuffer.FindSet() then
repeat
CreateServiceObjectFromSalesLine(SalesHeader, SalesLine, TempTrackingSpecBuffer."Serial No.", TempTrackingSpecBuffer."Quantity (Base)");
until TempTrackingSpecBuffer.Next() = 0;
TempTrackingSpecBuffer.Reset();
TempTrackingSpecBuffer.DeleteAll(false);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Activity-Post", OnUpdateSourceDocumentOnAfterSalesLineModify, '', false, false)]
local procedure ModifyShipmentDateFromInventoryPickPostingDate(var SalesLine: Record "Sales Line"; WarehouseActivityLine: Record "Warehouse Activity Line")
var
Expand Down Expand Up @@ -793,6 +822,35 @@ codeunit 8063 "Sales Documents"
SearchFieldNo[3] := 0;
end;

local procedure ShowNegativeQuantityMessageIfNeeded(Quantity: Decimal)
begin
if Quantity < 0 then
if not NegativeQuantityMsgShown then begin
Message(SubscriptionHeaderNotCreatedMsg);
NegativeQuantityMsgShown := true;
end;
end;

local procedure ResetGlobalVariables()
begin
CalledFromContractRenewal := false;
NegativeQuantityMsgShown := false;
Clear(GlobalSalesHeader);
Clear(GlobalSalesLine);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnBeforePostSalesDoc, '', false, false)]
local procedure ResetVariablesOnBeforePostSalesDoc()
begin
ResetGlobalVariables();
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnAfterPostSalesDoc, '', false, false)]
local procedure ResetVariablesOnAfterPostSalesDoc()
begin
ResetGlobalVariables();
end;

[IntegrationEvent(false, false)]
local procedure OnCheckResetValueForSubscriptionItems(var TempSalesLine: Record "Sales Line"; var ResetValueForSubscriptionItems: Boolean; var IsHandled: Boolean)
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ codeunit 8069 "Sales Subscription Line Mgmt."
exit(true);
end;

internal procedure IsSalesLineWithSalesServiceCommitmentsToShip(SalesLine: Record "Sales Line"; QuantityToCheck: Decimal): Boolean
begin
if not IsSalesLineWithSalesServiceCommitmentsToShip(SalesLine) then
exit(false);
if CheckNegativeQuantityAndShowMessageForServiceCommitment(QuantityToCheck) then
exit(false);

exit(true);
end;

internal procedure IsSalesLineWithServiceCommitmentItemToShip(SalesLine: Record "Sales Line"): Boolean
begin
if not IsSalesLineWithServiceCommitmentItem(SalesLine, true) then
Expand Down Expand Up @@ -413,23 +403,6 @@ codeunit 8069 "Sales Subscription Line Mgmt."
begin
end;

local procedure CheckNegativeQuantityAndShowMessageForServiceCommitment(Quantity: Decimal): Boolean
begin
if Quantity <= 0 then begin
if not ServiceCommitmentWithNegativeQtyMessageThrown then begin
Message(ServiceObjectNotCreatedMsg);
ServiceCommitmentWithNegativeQtyMessageThrown := true;
end;
exit(true);
end;
exit(false);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnAfterPostSalesLines, '', false, false)]
local procedure ResetServiceCommitmentWithNegativeQtyMessageThrownOnAfterPostSalesLines()
begin
ServiceCommitmentWithNegativeQtyMessageThrown := false;
end;

[IntegrationEvent(false, false)]
local procedure OnAddAdditionalSalesSubscriptionLinesForSalesLineAfterApplyFilters(var SubscriptionPackage: Record "Subscription Package"; var SalesLine: Record "Sales Line")
Expand Down Expand Up @@ -517,7 +490,5 @@ codeunit 8069 "Sales Subscription Line Mgmt."

var
ItemManagement: Codeunit "Sub. Contracts Item Management";
ServiceCommitmentWithNegativeQtyMessageThrown: Boolean;
SalesLineRestoreInProgress: Boolean;
ServiceObjectNotCreatedMsg: Label 'For negative quantity the Subscription is not created.';
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ page 8058 "Service Comm. Package Lines"
{
Style = Strong;
StyleExpr = Bold;
ToolTip = 'Specifies the percentage at which the price of the Subscription Line is calculated. 100% means that the the price is the same as the calculation base (item or document).';
ToolTip = 'Specifies the percentage at which the price of the Subscription Line is calculated. 100% means that the price is the same as the calculation base (item or document).';
AboutTitle = 'What percentage should be applied to calculate the subscription line price?';
AboutText = 'Defines the percentage used as the basis for calculating the price of the subscription line in conjuction with the Calculation Base Type.';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ page 8055 "Service Commitment Templates"
}
field("Calculation Base %"; Rec."Calculation Base %")
{
ToolTip = 'Specifies the percentage at which the price of the Subscription Line is calculated. 100% means that the the price is the same as the calculation base (item or document).';
ToolTip = 'Specifies the percentage at which the price of the Subscription Line is calculated. 100% means that the price is the same as the calculation base (item or document).';
}
field("Billing Base Period"; Rec."Billing Base Period")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,45 @@ page 8060 "Service Object"
}
}
}
group(Details)
{
Caption = 'Details';
field("Vendor No."; Rec."Vendor No.")
{
Visible = false;
}
field("Vendor Name"; Rec."Vendor Name")
{
}
field("Vendor Name 2"; Rec."Vendor Name 2")
{
Importance = Additional;
}
field("Vendor Item No."; Rec."Vendor Item No.")
{
}
field("Manufacturer Code"; Rec."Manufacturer Code")
{
Visible = false;
}
field("Manufacturer Name"; Rec."Manufacturer Name")
{
}
field("Salesperson Code"; Rec."Salesperson Code")
{
}
field("Sales Order No."; Rec."Sales Order No.")
{
}
field("Item Ledger Entry No."; Rec."Item Ledger Entry No.")
{
Importance = Additional;
}
field("Last Sales Invoice No."; Rec."Last Sales Invoice No.")
{
Importance = Additional;
}
}
}
area(FactBoxes)
{
Expand Down
Loading
Loading