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
69 changes: 66 additions & 3 deletions CCMS/src/Customer/D4PBCCustomer.table.al
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using D4P.CCMS.Setup;
using D4P.CCMS.Tenant;
using Microsoft.Foundation.Address;
using Microsoft.Foundation.NoSeries;
using Microsoft.Sales.Customer;
using System.EMail;

table 62000 "D4P BC Customer"
Expand All @@ -21,6 +22,12 @@ table 62000 "D4P BC Customer"
{
Caption = 'No.';
ToolTip = 'Specifies the customer number.';

trigger OnLookup()
begin
LookupSalesCustomer();
end;

trigger OnValidate()
begin
TestNoSeries();
Expand Down Expand Up @@ -159,7 +166,7 @@ table 62000 "D4P BC Customer"
trigger OnInsert()
begin
if "No." = '' then begin
CCMSSetup.Get();
GetCCMSSetup();
CCMSSetup.TestField("Customer Nos.");
"No. Series" := CCMSSetup."Customer Nos.";
if NoSeries.AreRelated("No. Series", xRec."No. Series") then
Expand All @@ -172,13 +179,14 @@ table 62000 "D4P BC Customer"
CCMSSetup: Record "D4P BC Setup";
PostCode: Record "Post Code";
NoSeries: Codeunit "No. Series";
IsCCMSSetupLoaded: Boolean;

procedure AssistEdit(OldCustomer: Record "D4P BC Customer"): Boolean
var
D4PBCCustomer: Record "D4P BC Customer";
begin
D4PBCCustomer := Rec;
CCMSSetup.Get();
GetCCMSSetup();
CCMSSetup.TestField("Customer Nos.");
if NoSeries.LookupRelatedNoSeries(CCMSSetup."Customer Nos.", OldCustomer."No. Series", D4PBCCustomer."No. Series") then begin
"No." := NoSeries.GetNextNo(D4PBCCustomer."No. Series");
Expand All @@ -187,6 +195,56 @@ table 62000 "D4P BC Customer"
end;
end;

/// <summary>
/// Retrieves the CCMS setup record using a lazy-loading pattern.
/// Only loads the setup once by checking the IsCCMSSetupLoaded flag.
/// Populates the CCMSSetup global variable with the CCMS setup configuration.
/// </summary>
local procedure GetCCMSSetup()
begin
if IsCCMSSetupLoaded then
exit;

CCMSSetup := CCMSSetup.GetSetup();
IsCCMSSetupLoaded := true;
end;

/// <summary>
/// Opens the Microsoft sales customer lookup and populates this record when a customer is selected.
/// The lookup is only available when using Microsoft sales customers is enabled in setup.
/// </summary>
local procedure LookupSalesCustomer()
var
Customer: Record Customer;
begin
GetCCMSSetup();
if not CCMSSetup."Use Microsoft Sales Customer" then
exit;

if Page.RunModal(Page::"Customer Lookup", Customer) = Action::LookupOK then
PopulateFromSalesCustomer(Customer);
end;

/// <summary>
/// Populates the current CCMS customer record with data from the selected Microsoft sales customer.
/// </summary>
/// <param name="Customer">The Microsoft sales customer record to copy data from.</param>
local procedure PopulateFromSalesCustomer(var Customer: Record Customer)
begin
Rec.Validate("No.", Customer."No.");
Rec.Validate(Name, Customer.Name);
Rec.Validate("Address", Customer."Address");
Rec.Validate("Address 2", Customer."Address 2");
Rec.Validate("City", Customer."City");
Rec.Validate("Post Code", Customer."Post Code");
Rec.Validate(County, Customer.County);
Rec.Validate("Country/Region Code", Customer."Country/Region Code");
Rec.Validate("Contact Person Name", Customer.Contact);
Rec.Validate("Contact Person Email", Customer."E-Mail");

OnAfterPopulateFromSalesCustomer(Rec, xRec, Customer);
end;

local procedure TestNoSeries()
var
D4PBCCustomer: Record "D4P BC Customer";
Expand All @@ -199,7 +257,7 @@ table 62000 "D4P BC Customer"

if "No." <> xRec."No." then
if not D4PBCCustomer.Get(Rec."No.") then begin
CCMSSetup.Get();
GetCCMSSetup();
NoSeries.TestManual(CCMSSetup."Customer Nos.");
"No. Series" := '';
end;
Expand All @@ -214,6 +272,11 @@ table 62000 "D4P BC Customer"
MailManagement.CheckValidEmailAddresses("Contact Person Email");
end;

[IntegrationEvent(false, false)]
local procedure OnAfterPopulateFromSalesCustomer(var D4PBCCustomer: Record "D4P BC Customer"; xD4PBCCustomer: Record "D4P BC Customer"; MicrosoftSalesCustomer: Record Customer)
begin
end;

[IntegrationEvent(false, false)]
local procedure OnBeforeTestNoSeries(var D4PBCCustomer: Record "D4P BC Customer"; xD4PBCCustomer: Record "D4P BC Customer"; var IsHandled: Boolean)
begin
Expand Down
3 changes: 3 additions & 0 deletions CCMS/src/Setup/D4PBCSetup.page.al
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ page 62010 "D4P BC Setup"
field("Debug Mode"; Rec."Debug Mode")
{
}
field("Use Microsoft Sales Customer"; Rec."Use Microsoft Sales Customer")
{
}
}
group(Numbering)
{
Expand Down
5 changes: 5 additions & 0 deletions CCMS/src/Setup/D4PBCSetup.table.al
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ table 62009 "D4P BC Setup"
TableRelation = "No. Series";
ToolTip = 'Specifies the number series used to assign customer numbers automatically.';
}
field(6; "Use Microsoft Sales Customer"; Boolean)
{
Caption = 'Use Microsoft Sales Customer';
ToolTip = 'Specifies whether to use Microsoft Sales Customer table relation.';
}
}

keys
Expand Down
Loading