Created
January 10, 2022 11:49
-
-
Save bero/218721bfdae4e620d9376cae23ee2ec0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TInvoicingPool.CreateInvoice(aInvoiceDrawerParty: TDepartment; aCustomerParty: TDepartment): TInvoice; | |
begin | |
Assert(Assigned(aInvoiceDrawerParty), 'Invalid parameter (InvoiceOwner missing)'); | |
Assert(Assigned(aCustomerParty), 'Invalid parameter (customer missing)'); | |
Result := GetApplicationKernel.CreateAMObjectByClass(TInvoice) as TInvoice; | |
with Result do | |
begin | |
// systemorg/defaultdept is owner of all the invoices - set defaultdept as owner... | |
// ...even if user happened to be logged on to some other department when invoice was made... | |
// ...since only defaultdept has all the required edi-data needed in order to send eInvoices... | |
invoiceOwner := aInvoiceDrawerParty.organization.defaultDepartment; | |
customer := aCustomerParty; | |
aCustomerParty.salesInvoices.Add(Result); | |
invoiceKind := 'Auto'; | |
SetInvoiceNo; | |
SetTermOfPayment(aCustomerParty.termsOfPayment); | |
SetInvoiceDateAsLDT(Now); | |
SetDueDateAsLDT(Now + paymentDueTime); | |
SetInvoiceLanguage(aCustomerParty); | |
OverDueRate := Self.OverDueRate; | |
if not aCustomerParty.SelfBilling then | |
CustomerRef := aCustomerParty.InvoiceReference // default invoice reference | |
else | |
CustomerRef := 'Self billing'; | |
// MYSA customer - financial institution (nordea) owns the sales debt. | |
// These invoices will not go into Aholas reskontra (excluded from ExportInvoicesToFinnHansa) | |
// but are batched together (every night) and sent to nordea through an external bancing software | |
OutSourceSalesDebt := (aCustomerParty.OutSourceSalesDebt or aCustomerParty.factoring); | |
SelfBilling := aCustomerParty.SelfBilling; | |
UseCommissionNote := IsCommissionCase; // set as default value - may be later on overriden by user... | |
if AnsiCompareText(Copy(CustomerOrgVatNro, 1, 2), 'SE') = 0 then | |
InvoiceNote := GetMLString(cn_Swedish, 'invoice.reskontranote'); | |
if ((aCustomerParty.InvoiceKind = cnEInvoice) or (aCustomerParty.InvoiceKind = cnEInvoicePaper)) then | |
buffElectronicInvoices.Add(Result) | |
else if (aCustomerParty.InvoiceKind = cnPDFInvoice) then | |
buffPdfInvoices.Add(Result) | |
else if (aCustomerParty.InvoiceKind = cnXMLInvoice) or (aCustomerParty.InvoiceKind = cnXMLInvoicePaper) then | |
buffXmlInvoices.Add(Result); | |
//note! printable invoices are not stored in any sepatare buffer | |
NotifyModificationHistory('Invoice created'); | |
end; | |
Assert(Assigned(Result.language), 'Setting of Invoice Language failed. (Customer has no houseLanguage set)'); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment