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 @@ -54,8 +54,10 @@ using Microsoft.Service.Document;
using Microsoft.Service.History;
using Microsoft.Service.Reports;
using Microsoft.Service.Setup;
using Microsoft.Upgrade;
using Microsoft.Utilities;
using System.IO;
using System.Reflection;
using System.Security.Encryption;
using System.Security.User;
using System.Upgrade;
Expand Down Expand Up @@ -598,6 +600,7 @@ codeunit 11748 "Install Application CZL"
InitEETServiceSetup();
CreateSourceCodeSetup();
ModifyReportSelections();
InitDefaultReportLayouts();

DataClassEvalHandlerCZL.ApplyEvaluationClassificationsForPrivacy();
UpgradeTag.SetAllUpgradeTags();
Expand Down Expand Up @@ -877,4 +880,17 @@ codeunit 11748 "Install Application CZL"
ItemJournalTemplate.Modify();
until ItemJournalTemplate.Next() = 0;
end;

local procedure InitDefaultReportLayouts()
var
ReportLayoutList: Record "Report Layout List";
UpgradeApplicationCZL: Codeunit "Upgrade Application CZL";
begin
if UpgradeApplicationCZL.GetDraftInvoiceReportLayoutCZ(ReportLayoutList) then
if not UpgradeApplicationCZL.IsReportLayoutSelectionCustomized(Report::"Standard Sales - Draft Invoice") then
UpgradeApplicationCZL.SetDefaultReportLayout(ReportLayoutList);
if UpgradeApplicationCZL.GetProformaReportLayoutCZ(ReportLayoutList) then
if not UpgradeApplicationCZL.IsReportLayoutSelectionCustomized(Report::"Standard Sales - Pro Forma Inv") then
UpgradeApplicationCZL.SetDefaultReportLayout(ReportLayoutList);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using Microsoft.Service.Document;
using Microsoft.Service.History;
using Microsoft.Service.Setup;
using System.Environment.Configuration;
using System.Reflection;
using System.Security.AccessControl;
using System.Security.Encryption;
using System.Security.User;
Expand Down Expand Up @@ -141,14 +142,18 @@ codeunit 31017 "Upgrade Application CZL"
tabledata "Gen. Journal Template" = m,
tabledata "VAT Entry" = m,
tabledata "Report Selections" = m,
tabledata "G/L Entry" = m;
tabledata "G/L Entry" = m,
tabledata "Report Layout Selection" = im,
tabledata "Tenant Report Layout Selection" = im;

var
DataUpgradeMgt: Codeunit "Data Upgrade Mgt.";
UpgradeTag: Codeunit "Upgrade Tag";
UpgradeTagDefinitionsCZL: Codeunit "Upgrade Tag Definitions CZL";
InstallApplicationsMgtCZL: Codeunit "Install Applications Mgt. CZL";
AppInfo: ModuleInfo;
DraftInvoiceReportLayoutNameTok: Label 'StdSalesDraftInvoice.rdl CZL', Locked = true;
ProformaReportLayoutNameTok: Label 'StdSalesProFormaInv.rdl CZL', Locked = true;

trigger OnUpgradePerDatabase()
begin
Expand Down Expand Up @@ -187,6 +192,7 @@ codeunit 31017 "Upgrade Application CZL"
UpgradeUseVATReturnPeriodInsteadOfVATPeriod();
#endif
UpgradeOriginalVATAmountsACYInVATEntries();
UpgradeDraftInvoiceAndProformaReportLayouts();
end;

local procedure UpgradeReplaceVATDateCZL()
Expand Down Expand Up @@ -846,6 +852,123 @@ codeunit 31017 "Upgrade Application CZL"
end;
#endif

local procedure UpgradeDraftInvoiceAndProformaReportLayouts()
var
ReportLayoutList: Record "Report Layout List";
begin
if UpgradeTag.HasUpgradeTag(UpgradeTagDefinitionsCZL.GetChangeDefaultDraftInvoiceAndProformaReportLayoutsUpgradeTag()) then
exit;

if GetDraftInvoiceReportLayoutCZ(ReportLayoutList) then
if not IsReportLayoutSelectionCustomized(Report::"Standard Sales - Draft Invoice") then
SetDefaultReportLayout(ReportLayoutList);

if GetProformaReportLayoutCZ(ReportLayoutList) then
if not IsReportLayoutSelectionCustomized(Report::"Standard Sales - Pro Forma Inv") then
SetDefaultReportLayout(ReportLayoutList);

UpgradeTag.SetUpgradeTag(UpgradeTagDefinitionsCZL.GetChangeDefaultDraftInvoiceAndProformaReportLayoutsUpgradeTag());
end;

internal procedure IsReportLayoutSelectionCustomized(ReportId: Integer): Boolean
var
DefaultMetadataReportLayoutName: Text[100];
DefaultSelectionReportLayoutName: Text[250];
begin
DefaultMetadataReportLayoutName := GetDefaultMetadataReportLayoutName(ReportId);
DefaultSelectionReportLayoutName := GetDefaultSelectionReportLayoutName(ReportId);
exit((DefaultSelectionReportLayoutName <> '') and (DefaultSelectionReportLayoutName <> DefaultMetadataReportLayoutName));
end;

local procedure GetDefaultMetadataReportLayoutName(ReportId: Integer): Text[100]
var
ReportMetadata: Record "Report Metadata";
begin
if ReportMetadata.Get(ReportId) then
exit(ReportMetadata."DefaultLayoutName");
exit('');
end;

local procedure GetDefaultSelectionReportLayoutName(ReportId: Integer): Text[250]
var
TenantReportLayoutSelection: Record "Tenant Report Layout Selection";
EmptyGuid: Guid;
begin
if TenantReportLayoutSelection.Get(ReportId, CompanyName(), EmptyGuid) then
exit(TenantReportLayoutSelection."Layout Name");
exit('');
end;

internal procedure GetDraftInvoiceReportLayoutCZ(var ReportLayoutList: Record "Report Layout List"): Boolean
begin
NavApp.GetCurrentModuleInfo(AppInfo);
ReportLayoutList.Reset();
ReportLayoutList.SetRange("Report ID", Report::"Standard Sales - Draft Invoice");
ReportLayoutList.SetRange("Name", DraftInvoiceReportLayoutNameTok);
ReportLayoutList.SetRange("Application ID", AppInfo.Id);
exit(ReportLayoutList.FindFirst());
end;

internal procedure GetProformaReportLayoutCZ(var ReportLayoutList: Record "Report Layout List"): Boolean
begin
NavApp.GetCurrentModuleInfo(AppInfo);
ReportLayoutList.Reset();
ReportLayoutList.SetRange("Report ID", Report::"Standard Sales - Pro Forma Inv");
ReportLayoutList.SetRange("Name", ProformaReportLayoutNameTok);
ReportLayoutList.SetRange("Application ID", AppInfo.Id);
exit(ReportLayoutList.FindFirst());
end;

internal procedure SetDefaultReportLayout(ReportLayoutList: Record "Report Layout List")
var
ReportLayoutSelection: Record "Report Layout Selection";
begin
// Add to TenantReportLayoutSelection table with an Empty Guid.
AddLayoutSelection(ReportLayoutList);

// Add to the report layout selection table
if ReportLayoutSelection.Get(ReportLayoutList."Report ID", CompanyName()) then begin
ReportLayoutSelection.Type := GetReportLayoutSelectionCorrespondingEnum(ReportLayoutList);
ReportLayoutSelection.Modify(false);
end else begin
ReportLayoutSelection."Report ID" := ReportLayoutList."Report ID";
ReportLayoutSelection."Company Name" := CopyStr(CompanyName(), 1, MaxStrLen(ReportLayoutSelection."Company Name"));
ReportLayoutSelection."Custom Report Layout Code" := '';
ReportLayoutSelection.Type := GetReportLayoutSelectionCorrespondingEnum(ReportLayoutList);
ReportLayoutSelection.Insert(false);
end;
end;

local procedure AddLayoutSelection(ReportLayoutList: Record "Report Layout List"): Boolean
var
TenantReportLayoutSelection: Record "Tenant Report Layout Selection";
EmptyGuid: Guid;
begin
TenantReportLayoutSelection.Init();
TenantReportLayoutSelection."App ID" := ReportLayoutList."Application ID";
TenantReportLayoutSelection."Company Name" := CopyStr(CompanyName(), 1, MaxStrLen(TenantReportLayoutSelection."Company Name"));
TenantReportLayoutSelection."Layout Name" := ReportLayoutList."Name";
TenantReportLayoutSelection."Report ID" := ReportLayoutList."Report ID";
TenantReportLayoutSelection."User ID" := EmptyGuid;

if not TenantReportLayoutSelection.Insert(false) then
TenantReportLayoutSelection.Modify(false);
end;

local procedure GetReportLayoutSelectionCorrespondingEnum(SelectedReportLayoutList: Record "Report Layout List"): Integer
begin
case SelectedReportLayoutList."Layout Format" of
SelectedReportLayoutList."Layout Format"::RDLC:
exit(0);
SelectedReportLayoutList."Layout Format"::Word:
exit(1);
SelectedReportLayoutList."Layout Format"::Excel:
exit(3);
SelectedReportLayoutList."Layout Format"::Custom:
exit(4);
end
end;

local procedure InsertRepSelection(ReportUsage: Enum "Report Selection Usage"; Sequence: Code[10];
ReportID: Integer)
var
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ codeunit 31016 "Upgrade Tag Definitions CZL"
PerCompanyUpgradeTags.Add(GetUseW1RegistrationNumberFromSalesDocUpgradeTag());
PerCompanyUpgradeTags.Add(GetUseVATReturnPeriodInsteadOfVATPeriodUpgradeTag());
PerCompanyUpgradeTags.Add(GetOriginalVATAmountsACYInVATEntriesUpgradeTag());
PerCompanyUpgradeTags.Add(GetChangeDefaultDraftInvoiceAndProformaReportLayoutsUpgradeTag());
end;

procedure GetDataVersion174PerDatabaseUpgradeTag(): Code[250]
Expand Down Expand Up @@ -223,4 +224,9 @@ codeunit 31016 "Upgrade Tag Definitions CZL"
begin
exit('CZL-616614-OriginalVATAmountsACYInVATEntriesTag-20251217');
end;

procedure GetChangeDefaultDraftInvoiceAndProformaReportLayoutsUpgradeTag(): Code[250]
begin
exit('CZL-640925-ChangeDefaultDraftInvoiceAndProformaReportLayoutsUpgradeTag-20260908');
end;
}
Loading
Loading