-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCreateInvoiceUsingTemplatesAX2012.xpp
68 lines (65 loc) · 2.9 KB
/
CreateInvoiceUsingTemplatesAX2012.xpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//Author:Mafigu Huggins
//Tel: +263 782 326 160
//Email: [email protected]
//Create and post a freetext invoice using invoice line template
static void CreateFTIfromTemplate(Args _args)
{
CustInvoiceTable custInvoiceTable,custInvoiceTable1;
CustInvoiceTemplate custInvoiceTemplate;
CustInvoiceLine custInvoiceLine;
CustPostInvoice custPostInvoice;
CustTable custtable;
CustInvoiceLineTemplate custInvoiceLineTemplate;
Date invoiceDate = systemdateget();
Date dueDate = systemdateget()+10;
try
{
custtable = Custtable::find("00001");
custInvoiceTemplate = CustInvoiceTemplate::findByTemplateName("Dues");
ttsBegin;
custInvoiceTable.clear();
custInvoiceTable.OrderAccount = custtable.AccountNum;
custInvoiceTable.initFromCustInvoiceTemplate(
custInvoiceTemplate,
custtable,
CustRecurrenceInvoiceDefaultType::InvoiceTemplate, //This can be defaulted from customer too
invoiceDate);
custInvoiceTable.DueDate = dueDate;
custInvoiceTable.insert();
// Creates a free text invoice lines by using customer free text invoice line template.
while select custInvoiceLineTemplate
where custInvoiceLineTemplate.CustInvoiceTemplate == custInvoiceTemplate.RecId
{
custInvoiceLine.clear();
custInvoiceLine.insertFromCustInvoiceLineTemplate(custInvoiceLineTemplate,
custInvoiceTable,
custtable,
CustRecurrenceInvoiceDefaultType::InvoiceTemplate); //This can be defaulted from customer too
}
//just to be sure for proper distributions
SourceDocumentProcessor::submitSourceDocumentLinesForHeader(custInvoiceTable.SourceDocumentHeader);
//post FTI
Select custInvoiceTable1 where custInvoiceTable1.RecId == custInvoiceTable.RecId;
custPostInvoice = new CustPostInvoice(custInvoiceTable1);
custPostInvoice.run();
ttsCommit;
info(strFmt("Invoice generated for customer %1", custtable.AccountNum));
}
catch
{
error(strFmt("Error in generating invoice for customer %1",custtable.AccountNum));
}
}