Skip to content

Commit fd2a6ce

Browse files
committed
working on creation of invoices
1 parent a0af527 commit fd2a6ce

File tree

3 files changed

+159
-30
lines changed

3 files changed

+159
-30
lines changed

erabliereapi/ErabliereList.al

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ page 50102 "Erabliere List"
2121
{
2222
ApplicationArea = All;
2323
}
24+
25+
field("Invoice Customer"; Rec."Invoice Customer")
26+
{
27+
ApplicationArea = All;
28+
DrillDown = true;
29+
TableRelation = Customer;
30+
}
31+
32+
field("Invoice Contact"; Rec."Invoice Contact")
33+
{
34+
ApplicationArea = All;
35+
DrillDown = true;
36+
TableRelation = Contact;
37+
}
2438
}
2539
}
2640
}
@@ -64,9 +78,57 @@ page 50102 "Erabliere List"
6478
Dialog.PrettyMessage('Nothing to import');
6579
end;
6680
}
81+
82+
action(CreateInvoice)
83+
{
84+
Promoted = true;
85+
PromotedCategory = Process;
86+
ApplicationArea = All;
87+
Caption = 'Create Invoice';
88+
89+
trigger OnAction()
90+
var
91+
result: Boolean;
92+
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);
99+
end;
100+
}
67101
}
68102
}
69103

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+
70132
local procedure ImportErablieres(var ErabliereRec: Record Erablieres)
71133
var
72134
ErablieresArray: JsonArray;
@@ -118,6 +180,36 @@ page 50102 "Erabliere List"
118180
end;
119181
end;
120182

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);
210+
end;
211+
end;
212+
121213
var
122214
Dialog: Codeunit "DynDialog";
123215
Json: Codeunit "Json";

erabliereapi/ErablierePage.al

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,44 @@ page 50101 "Erabliere Card"
3131
ApplicationArea = All;
3232
ToolTip = 'A duration writen as text. Ex: PT1H30M';
3333
}
34+
35+
field("Invoice Customer"; Rec."Invoice Customer")
36+
{
37+
ApplicationArea = All;
38+
TableRelation = "Customer";
39+
40+
trigger OnValidate()
41+
var
42+
Customer: Record "Customer";
43+
begin
44+
if Rec."Invoice Customer" = '' then
45+
exit;
46+
47+
if not Customer.Get(Rec."Invoice Customer") then
48+
Error('Customer not found');
49+
50+
Rec."Invoice Contact" := Customer."Primary Contact No.";
51+
end;
52+
}
53+
54+
field("Invoice Contact"; Rec."Invoice Contact")
55+
{
56+
ApplicationArea = All;
57+
TableRelation = "Contact";
58+
59+
trigger OnValidate()
60+
var
61+
Contact: Record "Contact";
62+
begin
63+
if Rec."Invoice Contact" = '' then
64+
exit;
65+
66+
if not Contact.Get(Rec."Invoice Contact") then
67+
Error('Contact not found');
68+
69+
Rec."Invoice Customer" := Contact."Company No.";
70+
end;
71+
}
3472
}
3573
}
3674
}

erabliereapi/app.json

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
{
2-
"id": "a6453545-4f31-481a-8ed3-159374895cbb",
3-
"name": "ErabliereAPI-Connector",
4-
"publisher": "ErabliereAPI",
5-
"version": "1.0.0.0",
6-
"brief": "Connector for ErabliereAPI",
7-
"description": "Connector for ErabliereAPI. Allow for automatic invoice, and customer creation.",
8-
"privacyStatement": "",
9-
"EULA": "",
10-
"help": "",
11-
"url": "",
12-
"logo": "",
13-
"dependencies": [],
14-
"screenshots": [],
15-
"platform": "1.0.0.0",
16-
"application": "22.0.0.0",
17-
"idRanges": [
18-
{
19-
"from": 50100,
20-
"to": 50149
21-
}
22-
],
23-
"resourceExposurePolicy": {
24-
"allowDebugging": true,
25-
"allowDownloadingSource": true,
26-
"includeSourceInSymbolFile": true
27-
},
28-
"runtime": "11.0",
29-
"features": [
30-
"NoImplicitWith"
31-
]
2+
"id": "a6453545-4f31-481a-8ed3-159374895cbb",
3+
"name": "ErabliereAPI-Connector",
4+
"publisher": "ErabliereAPI",
5+
"version": "1.0.0.0",
6+
"brief": "Connector for ErabliereAPI",
7+
"description": "Connector for ErabliereAPI. Allow for automatic invoice, and customer creation.",
8+
"privacyStatement": "",
9+
"EULA": "",
10+
"help": "",
11+
"url": "",
12+
"logo": "",
13+
"screenshots": [],
14+
"platform": "1.0.0.0",
15+
"application": "22.0.0.0",
16+
"idRanges": [
17+
{
18+
"from": 50100,
19+
"to": 50149
20+
}
21+
],
22+
"resourceExposurePolicy": {
23+
"allowDebugging": true,
24+
"allowDownloadingSource": true,
25+
"includeSourceInSymbolFile": true
26+
},
27+
"runtime": "11.0",
28+
"features": [
29+
"NoImplicitWith"
30+
]
3231
}

0 commit comments

Comments
 (0)