Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shopify Connector Tax ID, Multiple Company Locations, Tax ID export, Company Mapping by Tax ID, Payment Terms Export/Import, Company External ID #27577

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
299bb82
1 task. Customer No. assignment for Shopify Catalogs during Customer …
jzaksauskas Sep 30, 2024
b9b6462
2 task. Import Multiple Company locations to Business Central. Additi…
jzaksauskas Oct 3, 2024
bf343d5
2 task. Import Multiple Company locations to Business Central. Improv…
jzaksauskas Oct 3, 2024
00b9c65
3 task. Tax ID export/mapping
jzaksauskas Oct 7, 2024
51cae44
5 task. Assign External ID during Csutomer as Company export
jzaksauskas Oct 7, 2024
8cbb245
Set Company Location as default on Shopify Company creation
jzaksauskas Oct 8, 2024
ee27f39
Get Tax Registration Number moved to implementation codeunits
jzaksauskas Oct 8, 2024
accc09a
Moved Company Mapping to implementation codeunits
jzaksauskas Oct 8, 2024
2e90b5d
Implemented Export and Import for Company Location Payment Terms
jzaksauskas Oct 9, 2024
7916a9e
Re-implemented logic to get Graph queries to Interfces
jzaksauskas Oct 9, 2024
a3491c0
Fixes after PR review
jzaksauskas Oct 9, 2024
8ca4d53
Changes after PR review
jzaksauskas Oct 17, 2024
17c2f51
Created new interface to avoid destructive change. Created pagination…
jzaksauskas Oct 17, 2024
df63786
Removed locations from GetCompany graphQL
jzaksauskas Oct 18, 2024
c7f8822
Extending the compnay mapping interface
jzaksauskas Oct 21, 2024
497976b
removed implemenetions from enum for new interface
jzaksauskas Oct 21, 2024
64b60e6
test commit
petemchlk Oct 22, 2024
52426d1
remove empty line
petemchlk Oct 22, 2024
e217b4d
fix existing test, add test for catalog
petemchlk Oct 28, 2024
ca3dd8c
Task 1 test
petemchlk Oct 28, 2024
b779120
add find mapping tests
petemchlk Oct 29, 2024
2ba709b
add tests
petemchlk Oct 29, 2024
bc4d15d
Payment terms integration tests, fix create customer Payment terms ma…
petemchlk Oct 30, 2024
d86daa5
TaxID and Payment Terms export tests
petemchlk Oct 30, 2024
853e713
Add external id export test
petemchlk Oct 30, 2024
6e07369
refactor
petemchlk Oct 30, 2024
edc6480
refactor
petemchlk Oct 30, 2024
da05306
fix test
petemchlk Oct 31, 2024
58bbf66
Minor adjustment
GediminasGaubys Oct 31, 2024
f4dc384
fix naming
petemchlk Nov 12, 2024
34476e2
Merge branch 'main' into taxid_minorchanges_withunittests
petemchlk Nov 13, 2024
f6c0c19
remove duplicated object
petemchlk Nov 13, 2024
d5e6fad
fix issue with default location
petemchlk Nov 13, 2024
b6e00ce
change clear to init
petemchlk Nov 13, 2024
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
5 changes: 5 additions & 0 deletions Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ page 30101 "Shpfy Shop Card"
ApplicationArea = All;
ToolTip = 'Specifies how to map companies.';
}
field("Shpfy Comp.Tax Id Mapping"; Rec."Shpfy Comp. Tax Id Mapping")
{
ApplicationArea = All;
ToolTip = 'Specifies how to map Shopify Tax ID with Business Central.';
}
field("Auto Create Unknown Companies"; Rec."Auto Create Unknown Companies")
{
ApplicationArea = All;
Expand Down
5 changes: 5 additions & 0 deletions Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,11 @@ table 30102 "Shpfy Shop"
Caption = 'Weight Unit';
DataClassification = CustomerContent;
}
field(130; "Shpfy Comp. Tax Id Mapping"; Enum "Shpfy Comp. Tax Id Mapping")
{
Caption = 'Company Tax Id Mapping';
DataClassification = CustomerContent;
}
field(200; "Shop Id"; Integer)
{
DataClassification = SystemMetadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Microsoft.Integration.Shopify;

using Microsoft.Finance.GeneralLedger.Setup;
using Microsoft.Sales.Customer;

/// <summary>
/// Codeunit Shpfy Catalog API (ID 30290).
Expand All @@ -15,7 +16,7 @@ codeunit 30290 "Shpfy Catalog API"
JsonHelper: Codeunit "Shpfy Json Helper";
ShopifyCatalogURLLbl: Label 'https://admin.shopify.com/store/%1/catalogs/%2/editor', Comment = '%1 - Shop Name, %2 - Catalog Id', Locked = true;

internal procedure CreateCatalog(ShopifyCompany: Record "Shpfy Company")
internal procedure CreateCatalog(ShopifyCompany: Record "Shpfy Company"; Customer: Record Customer)
var
Catalog: Record "Shpfy Catalog";
GraphQLType: Enum "Shpfy GraphQL Type";
Expand All @@ -32,6 +33,7 @@ codeunit 30290 "Shpfy Catalog API"
Catalog."Shop Code" := Shop.Code;
Catalog.Name := ShopifyCompany.Name;
Catalog."Company SystemId" := ShopifyCompany.SystemId;
Catalog."Customer No." := Customer."No.";
Catalog.Insert();
CreatePublication(Catalog);
CreatePriceList(Catalog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ page 30159 "Shpfy Catalogs"
field("Customer No."; Rec."Customer No.")
{
ApplicationArea = All;
Visible = false;
Editable = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreiPanko this means each catalog will be assigned a customer and only that customer will be used to calculate the price. Not the settings in the catalogs page. ("Customer Price Group", "Customer Disc. Group", "Allow Line Disc.")

Is that the intention? Then shouldn't we remove those settings from the page?

ToolTip = 'Specifies the customer''s no. When Customer No. is Selected: Parameters like ''Customer Discount Group'', ''Customer Price Group'', and ''Allow Line Discount'' on the customer card take precedence over catalog settings';
}
field(Name; Rec.Name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Microsoft.Integration.Shopify;

using Microsoft.Sales.Customer;

/// <summary>
/// Codeunit Shpfy Comp. By Default Comp. (ID 30305) implements Interface Shpfy ICompany Mapping.
/// </summary>
codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping"
codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping"
{
Access = Internal;

Expand All @@ -15,4 +17,35 @@ codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping
Shop.Get(ShopCode);
exit(Shop."Default Company No.");
end;

internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean
var
Customer: Record Customer;
ShopifyCustomer: Record "Shpfy Customer";
begin
if not IsNullGuid(ShopifyCompany."Customer SystemId") then
if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then
exit(true)
else begin
Clear(ShopifyCompany."Customer SystemId");
ShopifyCompany.Modify(true);
end;

if IsNullGuid(ShopifyCompany."Customer SystemId") then begin
Shop.Get(ShopifyCompany."Shop Code");
if Customer.Get(Shop."Default Company No.") then begin
ShopifyCompany."Customer SystemId" := Customer.SystemId;

if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin
ShopifyCustomer.Copy(TempShopifyCustomer);
ShopifyCustomer."Customer SystemId" := Customer.SystemId;
ShopifyCustomer.Insert(true);
end;

ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id;
ShopifyCompany.Modify(true);
exit(true);
end;
end;
end;
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
namespace Microsoft.Integration.Shopify;

using Microsoft.Sales.Customer;

/// <summary>
/// Codeunit ShoShpfypify Comp. By Email/Phone (ID 30304) implements Interface Shpfy ICompany Mapping.
/// </summary>
codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping"
codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping"
{
Access = Internal;

internal procedure DoMapping(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20]
var
ShopifyCompany: Record "Shpfy Company";
begin
ShopifyCompany.SetAutoCalcFields("Customer No.");
if ShopifyCompany.Get(CompanyId) then begin
if not IsNullGuid(ShopifyCompany."Customer SystemId") then begin
ShopifyCompany.CalcFields("Customer No.");
if ShopifyCompany."Customer No." = '' then begin
Clear(ShopifyCompany."Customer SystemId");
ShopifyCompany.Modify();
ShopifyCompany.Modify(true);
end else
exit(ShopifyCompany."Customer No.");
end;
exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate));
end else
exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate));
exit('');
end;

internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean
var
Customer: Record Customer;
begin
if not IsNullGuid(ShopifyCompany."Customer SystemId") then
if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then
exit(true)
else begin
Clear(ShopifyCompany."Customer SystemId");
ShopifyCompany.Modify(true);
end;

if IsNullGuid(ShopifyCompany."Customer SystemId") then begin
if TempShopifyCustomer.Email <> '' then
exit(FindByEmail(ShopifyCompany, TempShopifyCustomer));

if TempShopifyCustomer."Phone No." <> '' then
exit(FindByPhoneNo(ShopifyCompany, TempShopifyCustomer));
end;
end;

local procedure CreateCompany(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20]
Expand All @@ -37,11 +58,61 @@ codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping"
CompanyImport.SetAllowCreate(AllowCreate);
CompanyImport.SetTemplateCode(TemplateCode);
TempCompany.Id := CompanyId;
TempCompany.Insert();
TempCompany.Insert(false);

CompanyImport.Run(TempCompany);
CompanyImport.GetCompany(ShopifyCompany);
if ShopifyCompany.Find() then
ShopifyCompany.CalcFields("Customer No.");

exit(ShopifyCompany."Customer No.");
end;

local procedure FindByEmail(var ShopifyCompany: Record "Shpfy Company"; TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean
var
Customer: Record Customer;
ShopifyCustomer: Record "Shpfy Customer";
begin
Customer.SetFilter("E-Mail", '@' + TempShopifyCustomer.Email);
if Customer.FindFirst() then begin
ShopifyCompany."Customer SystemId" := Customer.SystemId;

if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin
ShopifyCustomer.Copy(TempShopifyCustomer);
ShopifyCustomer."Customer SystemId" := Customer.SystemId;
ShopifyCustomer.Insert(true);
end;

ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id;
ShopifyCompany.Modify(true);
exit(true);
end;
end;

local procedure FindByPhoneNo(var ShopifyCompany: Record "Shpfy Company"; TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean
var
Customer: Record Customer;
ShopifyCustomer: Record "Shpfy Customer";
CustomerMapping: Codeunit "Shpfy Customer Mapping";
PhoneFilter: Text;
begin
PhoneFilter := CustomerMapping.CreatePhoneFilter(TempShopifyCustomer."Phone No.");
if PhoneFilter <> '' then begin
Clear(Customer);
Customer.SetFilter("Phone No.", PhoneFilter);
if Customer.FindFirst() then begin
ShopifyCompany."Customer SystemId" := Customer.SystemId;

if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin
ShopifyCustomer.Copy(TempShopifyCustomer);
ShopifyCustomer."Customer SystemId" := Customer.SystemId;
ShopifyCustomer.Insert(true);
end;

ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id;
ShopifyCompany.Modify(true);
exit(true);
end;
end;
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
namespace Microsoft.Integration.Shopify;

using Microsoft.Sales.Customer;

/// <summary>
/// Codeunit Shpfy Comp. By Tax Id (ID 30366) implements Interface Shpfy ICompany Mapping.
/// </summary>
codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping"
{
Access = Internal;

internal procedure DoMapping(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20]
var
ShopifyCompany: Record "Shpfy Company";
begin
if ShopifyCompany.Get(CompanyId) then begin
if not IsNullGuid(ShopifyCompany."Customer SystemId") then begin
ShopifyCompany.CalcFields("Customer No.");
if ShopifyCompany."Customer No." = '' then begin
Clear(ShopifyCompany."Customer SystemId");
ShopifyCompany.Modify(true);
end else
exit(ShopifyCompany."Customer No.");
end;
exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate));
end else
exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate));
end;

internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean
var
Customer: Record Customer;
CompanyLocation: Record "Shpfy Company Location";
begin
if not IsNullGuid(ShopifyCompany."Customer SystemId") then
if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then
exit(true)
else begin
Clear(ShopifyCompany."Customer SystemId");
ShopifyCompany.Modify(true);
end;

if IsNullGuid(ShopifyCompany."Customer SystemId") then
if ShopifyCompany."Location Id" <> 0 then begin
CompanyLocation.Get(ShopifyCompany."Location Id");
if CompanyLocation."Tax Registration Id" <> '' then
exit(FindByTaxRegistrationId(ShopifyCompany, TempShopifyCustomer, CompanyLocation));
end;
end;

local procedure CreateCompany(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20]
var
ShopifyCompany: Record "Shpfy Company";
TempShopifyCompany: Record "Shpfy Company" temporary;
CompanyImport: Codeunit "Shpfy Company Import";
begin
CompanyImport.SetShop(ShopCode);
CompanyImport.SetAllowCreate(AllowCreate);
CompanyImport.SetTemplateCode(TemplateCode);
TempShopifyCompany.Id := CompanyId;
TempShopifyCompany.Insert(false);

CompanyImport.Run(TempShopifyCompany);
CompanyImport.GetCompany(ShopifyCompany);
if ShopifyCompany.Find() then
ShopifyCompany.CalcFields("Customer No.");

exit(ShopifyCompany."Customer No.");
end;

local procedure FindByTaxRegistrationId(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary; CompanyLocation: Record "Shpfy Company Location"): Boolean
var
Customer: Record Customer;
ShopifyCustomer: Record "Shpfy Customer";
Shop: Record "Shpfy Shop";
TaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping";
begin
Clear(Customer);
Shop.Get(ShopifyCompany."Shop Code");
TaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping";
TaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation);
if Customer.FindFirst() then begin
ShopifyCompany."Customer SystemId" := Customer.SystemId;

if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin
ShopifyCustomer.Copy(TempShopifyCustomer);
ShopifyCustomer."Customer SystemId" := Customer.SystemId;
ShopifyCustomer.Insert(true);
end;

ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id;
ShopifyCompany.Modify(true);
exit(true);
end;
end;
}
Loading
Loading