Skip to content

Commit 4f8c0e6

Browse files
committed
improve preview when using action Create Invoices
1 parent fd2a6ce commit 4f8c0e6

File tree

8 files changed

+266
-84
lines changed

8 files changed

+266
-84
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
codeunit 50102 CreateEAPIInvoice
2+
{
3+
procedure CreateSalesInvoiceWorkflow(Preview: Boolean): Boolean
4+
var
5+
ErablieresRec: Record "Erablieres";
6+
Customers: Record Customer;
7+
Count: Integer;
8+
i: Integer;
9+
Dialog: Codeunit "DynDialog";
10+
begin
11+
i := 1;
12+
if ErablieresRec.FindSet() then begin
13+
Count := ErablieresRec.Count();
14+
Dialog.Open(Count);
15+
repeat begin
16+
Dialog.UpdateName(i, ErablieresRec.Description);
17+
if ErablieresRec."Invoice Customer" <> '' then begin
18+
Dialog.UpdateDescription(i, 'Creating invoice for customer ' + ErablieresRec."Invoice Contact" + ' ' + Customers.Name + '.');
19+
CreateSalesInvoice(Dialog, ErablieresRec."Invoice Customer", Preview, i);
20+
end
21+
else
22+
Dialog.UpdateError(i, 'No customer for ' + ErablieresRec.Description + ', no invoice created.');
23+
Sleep(100);
24+
i += 1;
25+
end until ErablieresRec.Next() = 0;
26+
if Preview then
27+
Dialog.DisplayAsPreviewPage();
28+
exit(true);
29+
end
30+
else
31+
Dialog.PrettyMessage('Without Erablieres, no invoice can be created');
32+
33+
exit(false);
34+
end;
35+
36+
local procedure CreateSalesInvoice(var Dialog: Codeunit DynDialog; CustomerNo: Code[20]; Preview: Boolean; i: Integer)
37+
var
38+
SalesHeader: Record "Sales Header";
39+
Series: Record "No. Series";
40+
SalesLine: Record "Sales Line";
41+
NoSeries: Record "No. Series";
42+
NoSeriesMgt: Codeunit "NoSeriesManagement";
43+
Customer: Record Customer;
44+
InvoiceNo: Code[20];
45+
begin
46+
// Initialize a new Sales Invoice header
47+
SalesHeader.Init();
48+
SalesHeader."Document Type" := SalesHeader."Document Type"::Invoice;
49+
SalesHeader."Posting Date" := WorkDate();
50+
SalesHeader."Sell-to Customer No." := CustomerNo;
51+
SalesHeader."No. Series" := 'S-INV';
52+
if Preview then begin
53+
// validate the Sell-to Customer No. field
54+
if not Customer.Get(SalesHeader."Sell-to Customer No.") then begin
55+
Dialog.UpdateError(i, 'Customer ' + SalesHeader."Sell-to Customer No." + ' does not exist.');
56+
end;
57+
end;
58+
if not Preview then begin
59+
SalesHeader."No." := NoSeriesMgt.GetNextNo(SalesHeader."No. Series", SalesHeader."Posting Date", true);
60+
SalesHeader.Insert(true);
61+
62+
// Initialize a new Sales Invoice line
63+
SalesLine.Init();
64+
SalesLine."Document Type" := SalesLine."Document Type"::Invoice;
65+
SalesLine."Document No." := SalesHeader."No.";
66+
SalesLine.Type := SalesLine.Type::Item;
67+
SalesLine.Insert(true);
68+
end;
69+
end;
70+
}

erabliereapi/ErabliereList.al

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -88,47 +88,14 @@ page 50102 "Erabliere List"
8888

8989
trigger OnAction()
9090
var
91-
result: Boolean;
91+
createEAPIInvoice: Codeunit "CreateEAPIInvoice";
9292
begin
93-
result := CreateSalesInvoiceWorkflow(True);
94-
if result then
95-
result := Dialog.PrettyConfirm('Do you want to create the invoices?');
96-
97-
if result then
98-
CreateSalesInvoiceWorkflow(False);
93+
createEAPIInvoice.CreateSalesInvoiceWorkflow(True);
9994
end;
10095
}
10196
}
10297
}
10398

104-
local procedure CreateSalesInvoiceWorkflow(Preview: Boolean): Boolean
105-
var
106-
ErablieresRec: Record "Erablieres";
107-
Count: Integer;
108-
i: Integer;
109-
begin
110-
i := 1;
111-
if ErablieresRec.FindSet() then begin
112-
Count := ErablieresRec.Count();
113-
Dialog.Open(Count);
114-
repeat begin
115-
if ErablieresRec."Invoice Customer" <> '' then begin
116-
Dialog.Update(i, 'Creating invoice for ' + ErablieresRec.Description + ' for customer ' + ErablieresRec."Invoice Contact" + '.');
117-
CreateSalesInvoice(ErablieresRec."Invoice Customer", Preview);
118-
end
119-
else
120-
Dialog.Update(i, 'No customer for ' + ErablieresRec.Description + ', no invoice created.');
121-
Sleep(100);
122-
i += 1;
123-
end until ErablieresRec.Next() = 0;
124-
exit(true);
125-
end
126-
else
127-
Dialog.PrettyMessage('Without Erablieres, no invoice can be created');
128-
129-
exit(false);
130-
end;
131-
13299
local procedure ImportErablieres(var ErabliereRec: Record Erablieres)
133100
var
134101
ErablieresArray: JsonArray;
@@ -167,7 +134,7 @@ page 50102 "Erabliere List"
167134

168135
ErabliereRec.Insert(true);
169136

170-
Dialog.Update(i + 1, propVal + ' inséré');
137+
Dialog.UpdateDescription(i + 1, propVal + ' inséré');
171138
end
172139
else begin
173140
propVal := Json.GetText(ErabliereToken, 'nom');
@@ -176,37 +143,7 @@ page 50102 "Erabliere List"
176143

177144
ErabliereRec.Modify(true);
178145

179-
Dialog.Update(i + 1, propVal + ' existe déjà');
180-
end;
181-
end;
182-
183-
procedure CreateSalesInvoice(CustomerNo: Code[20]; Preview: Boolean)
184-
var
185-
SalesHeader: Record "Sales Header";
186-
SalesLine: Record "Sales Line";
187-
NoSeriesMgt: Codeunit "NoSeriesManagement";
188-
InvoiceNo: Code[20];
189-
begin
190-
// Initialize a new Sales Invoice header
191-
SalesHeader.Init();
192-
SalesHeader."Document Type" := SalesHeader."Document Type"::Invoice;
193-
SalesHeader."No." := ''; // No. will be assigned by NoSeriesManagement
194-
SalesHeader."Sell-to Customer No." := CustomerNo;
195-
if not Preview then begin
196-
SalesHeader.Insert(true);
197-
198-
// Get the next invoice number from the number series
199-
InvoiceNo := NoSeriesMgt.GetNextNo(SalesHeader."No. Series", SalesHeader."Posting Date", true);
200-
SalesHeader."No." := InvoiceNo;
201-
SalesHeader.Modify(true);
202-
203-
// Initialize a new Sales Invoice line
204-
SalesLine.Init();
205-
SalesLine."Document Type" := SalesLine."Document Type"::Invoice;
206-
SalesLine."Document No." := SalesHeader."No.";
207-
SalesLine."Line No." := 10000; // Line number
208-
SalesLine.Type := SalesLine.Type::Item;
209-
SalesLine.Insert(true);
146+
Dialog.UpdateDescription(i + 1, propVal + ' existe déjà');
210147
end;
211148
end;
212149

erabliereapi/Pages/ContactPageExt.al

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pageextension 50120 ContactPageExt extends "Contact List"
5959
SynErabliereAPIContact(ContactRec, ContactToken);
6060
if not Preview then
6161
ContactRec.Modify(true);
62-
Dialog.Update(i + 1, StrSubstNo('Contact %1 %2 was updated', ContactRec."No.", uniqueName));
62+
Dialog.UpdateDescription(i + 1, StrSubstNo('Contact %1 %2 was updated', ContactRec."No.", uniqueName));
6363
modified := true;
6464
end;
6565

@@ -70,7 +70,7 @@ pageextension 50120 ContactPageExt extends "Contact List"
7070
SynErabliereAPIContact(ContactRec, ContactToken);
7171
if not Preview then
7272
ContactRec.Modify(true);
73-
Dialog.Update(i + 1, StrSubstNo('Contact %1 %2 updated from an existing customer', ContactRec."No.", uniqueName));
73+
Dialog.UpdateDescription(i + 1, StrSubstNo('Contact %1 %2 updated from an existing customer', ContactRec."No.", uniqueName));
7474
modified := true;
7575
end;
7676

@@ -84,11 +84,11 @@ pageextension 50120 ContactPageExt extends "Contact List"
8484
ContactRec.Insert(true);
8585
end;
8686

87-
Dialog.Update(i + 1, StrSubstNo('Contact %1 created', ContactRec."No." + ' ' + uniqueName));
87+
Dialog.UpdateDescription(i + 1, StrSubstNo('Contact %1 created', ContactRec."No." + ' ' + uniqueName));
8888
end;
8989
end
9090
else begin
91-
Dialog.Update(i + 1, StrSubstNo('Device %1 was not imported as a contact', uniqueName));
91+
Dialog.UpdateDescription(i + 1, StrSubstNo('Device %1 was not imported as a contact', uniqueName));
9292
end;
9393
end;
9494
if Preview then

erabliereapi/Pages/PreviewPage.al

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
page 50100 PreviewPage
2+
{
3+
Caption = 'Preview Page';
4+
UsageCategory = None;
5+
SourceTable = Preview;
6+
7+
Layout
8+
{
9+
area(Content)
10+
{
11+
repeater(Preview)
12+
{
13+
field("No."; Rec.No)
14+
{
15+
ApplicationArea = All;
16+
ToolTip = 'Item number';
17+
}
18+
19+
field("Item"; Rec.Name)
20+
{
21+
ApplicationArea = All;
22+
ToolTip = 'Item identifier';
23+
}
24+
25+
field("Error"; Rec.Error)
26+
{
27+
ApplicationArea = All;
28+
Style = Unfavorable;
29+
}
30+
31+
field("Description"; Rec.Description)
32+
{
33+
ApplicationArea = All;
34+
}
35+
}
36+
}
37+
}
38+
39+
actions
40+
{
41+
area("Processing")
42+
{
43+
Description = 'Create invoices';
44+
ToolTip = 'Create invoices for all items';
45+
46+
action("Create Invoices")
47+
{
48+
Promoted = true;
49+
ApplicationArea = All;
50+
Caption = 'Create';
51+
Image = NewSalesInvoice;
52+
53+
trigger OnAction()
54+
var
55+
Count: Integer;
56+
i: Integer;
57+
createEAPIInvoice: Codeunit CreateEAPIInvoice;
58+
invoices: Page "Sales Invoice List";
59+
begin
60+
if createEAPIInvoice.CreateSalesInvoiceWorkflow(false) then begin
61+
if Dialog.Confirm('Do you want to oepn the invoices page?') then begin
62+
invoices.Run();
63+
end;
64+
Close();
65+
end;
66+
end;
67+
}
68+
}
69+
70+
// area(Promoted)
71+
// {
72+
// actionref("Create Invoice")
73+
// {
74+
75+
// }
76+
// }
77+
}
78+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
pageextension 50102 SalesInvoiceListExt extends "Sales Invoice List"
2+
{
3+
actions
4+
{
5+
addlast("&Invoice")
6+
{
7+
action("Delete All")
8+
{
9+
Promoted = true;
10+
PromotedCategory = Process;
11+
ApplicationArea = All;
12+
Caption = 'Delete All';
13+
ToolTip = 'Delete all invoices';
14+
Image = Delete;
15+
trigger OnAction()
16+
var
17+
SalesHeader: Record "Sales Header";
18+
begin
19+
if Dialog.Confirm('Are you sure you want to delete every invoice?') then begin
20+
SalesHeader.Reset();
21+
while SalesHeader.FindSet() do
22+
SalesHeader.Delete();
23+
end;
24+
end;
25+
}
26+
}
27+
}
28+
}

erabliereapi/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ Connector for the ErabliereAPI project.
1111
5. https://learn.microsoft.com/en-us/dynamics365/business-central/application/system-application/codeunit/system.security.encryption.cryptography-management
1212
6. https://community.dynamics.com/blogs/post/?postid=e288a516-2d2b-44b4-bac2-b290a7a8e7f5
1313
7. https://goodworkaround.com/2020/07/07/authenticating-to-azure-ad-as-an-application-using-certificate-based-client-credential-grant/
14-
8. https://matgomes.com/understanding-base64-encoding/#:~:text=Concatenate%20the%20remaining%20bytes.%20Split%20the%20concatenated%20bits,character%20with%20the%20offsets%20from%20the%206-bit%20groups.
14+
8. https://matgomes.com/understanding-base64-encoding/#:~:text=Concatenate%20the%20remaining%20bytes.%20Split%20the%20concatenated%20bits,character%20with%20the%20offsets%20from%20the%206-bit%20groups.
15+
16+
## AL References
17+
18+
Page field style: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-style-property
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
table 50101 Preview
2+
{
3+
DataClassification = ToBeClassified;
4+
5+
fields
6+
{
7+
field(1; No; Integer)
8+
{
9+
DataClassification = ToBeClassified;
10+
}
11+
12+
field(2; Name; Text[50])
13+
{
14+
DataClassification = ToBeClassified;
15+
}
16+
17+
field(3; Error; Text[250])
18+
{
19+
DataClassification = ToBeClassified;
20+
21+
}
22+
23+
field(4; Description; Text[250])
24+
{
25+
DataClassification = ToBeClassified;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)