Skip to content

Commit

Permalink
Add more fields for invoice builder
Browse files Browse the repository at this point in the history
  • Loading branch information
printesoi committed Mar 20, 2024
1 parent 7b26aa1 commit 615157d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 13 deletions.
87 changes: 76 additions & 11 deletions builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,17 @@ type InvoiceBuilder struct {

taxExeptionReasons map[TaxCategoryCodeType]taxExemptionReason

billingReferences []InvoiceBillingReference
supplier InvoiceSupplierParty
customer InvoiceCustomerParty
accountingCost string
buyerReference string
orderReference *InvoiceOrderReference
notes []InvoiceNote
invoicePeriod *InvoicePeriod
billingReferences []InvoiceDocumentReference
contractDocumentReference *string
supplier InvoiceSupplierParty
customer InvoiceCustomerParty
paymentMeans *InvoicePaymentMeans
paymentTerms *InvoicePaymentTerms

allowancesCharges []InvoiceDocumentAllowanceCharge
invoiceLines []InvoiceLine
Expand Down Expand Up @@ -495,13 +503,13 @@ func (b *InvoiceBuilder) WithTaxCurrencyCode(currencyID CurrencyCodeType) *Invoi
return b
}

func (b *InvoiceBuilder) WithBillingReferences(billingReferences []InvoiceBillingReference) *InvoiceBuilder {
func (b *InvoiceBuilder) WithBillingReferences(billingReferences []InvoiceDocumentReference) *InvoiceBuilder {
b.billingReferences = billingReferences
return b
}

func (b *InvoiceBuilder) AppendBillingReferences(billingReference InvoiceBillingReference) *InvoiceBuilder {
return b.WithBillingReferences(append(b.billingReferences, billingReference))
func (b *InvoiceBuilder) AppendBillingReferences(billingReferences ...InvoiceDocumentReference) *InvoiceBuilder {
return b.WithBillingReferences(append(b.billingReferences, billingReferences...))
}

func (b *InvoiceBuilder) WithSupplier(supplier InvoiceSupplierParty) *InvoiceBuilder {
Expand Down Expand Up @@ -533,6 +541,51 @@ func (b *InvoiceBuilder) Append(lines ...InvoiceLine) *InvoiceBuilder {
return b
}

func (b *InvoiceBuilder) WithAccountingCost(accountingCost string) *InvoiceBuilder {
b.accountingCost = accountingCost
return b
}

func (b *InvoiceBuilder) WithBuyerReference(buyerReference string) *InvoiceBuilder {
b.buyerReference = buyerReference
return b
}

func (b *InvoiceBuilder) WithOrderReference(orderReference InvoiceOrderReference) *InvoiceBuilder {
b.orderReference = &orderReference
return b
}

func (b *InvoiceBuilder) WithNotes(notes []InvoiceNote) *InvoiceBuilder {
b.notes = notes
return b
}

func (b *InvoiceBuilder) AppendNotes(notes ...InvoiceNote) *InvoiceBuilder {
b.notes = append(b.notes, notes...)
return b
}

func (b *InvoiceBuilder) WithInvoicePeriod(invoicePeriod InvoicePeriod) *InvoiceBuilder {
b.invoicePeriod = &invoicePeriod
return b
}

func (b *InvoiceBuilder) WithContractDocumentReference(contractDocumentReference string) *InvoiceBuilder {
b.contractDocumentReference = &contractDocumentReference
return b
}

func (b *InvoiceBuilder) WithPaymentMeans(paymentMeans InvoicePaymentMeans) *InvoiceBuilder {
b.paymentMeans = &paymentMeans
return b
}

func (b *InvoiceBuilder) WithPaymentTerms(paymentTerms InvoicePaymentTerms) *InvoiceBuilder {
b.paymentTerms = &paymentTerms
return b
}

func (b *InvoiceBuilder) AddTaxExemptionReason(taxCategoryCode TaxCategoryCodeType, reason string, exemptionCode TaxExemptionReasonCodeType) *InvoiceBuilder {
if b.taxExeptionReasons == nil {
b.taxExeptionReasons = make(map[TaxCategoryCodeType]taxExemptionReason)
Expand Down Expand Up @@ -576,16 +629,28 @@ func (b InvoiceBuilder) Build() (retInvoice Invoice, err error) {
invoice.InvoiceTypeCode = b.invoiceType
invoice.DocumentCurrencyCode = b.documentCurrencyID
invoice.TaxCurrencyCode = b.taxCurrencyID
invoice.AccountingCost = b.accountingCost
invoice.BuyerReference = b.buyerReference
invoice.OrderReference = b.orderReference
invoice.Note = b.notes
invoice.InvoicePeriod = b.invoicePeriod

for _, ref := range b.billingReferences {
invoice.BillingReferences = append(invoice.BillingReferences, InvoiceBillingReference{
InvoiceDocumentReference: ref,
})
}

// TODO:

invoice.BillingReferences = b.billingReferences

// TODO:
if b.contractDocumentReference != nil {
invoice.ContractDocumentReference = NewIDNode(*b.contractDocumentReference)
}

invoice.Supplier.Party = b.supplier
invoice.Customer.Party = b.customer

invoice.PaymentMeans = b.paymentMeans
invoice.PaymentTerms = b.paymentTerms

// amountToTaxAmount converts an Amount assumed to be in the
// DocumentCurrencyCode to an amount in TaxCurrencyCode
amountToTaxAmount := func(a Decimal) Decimal {
Expand Down
4 changes: 2 additions & 2 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type Invoice struct {
// ID: BT-20
// Term: Termeni de plată
// Cardinality: 0..1
PaymentTerms *PaymentTerms `xml:"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2 PaymentTerms,omitempty"`
PaymentTerms *InvoicePaymentTerms `xml:"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2 PaymentTerms,omitempty"`
// test[cbc:ChargeIndicator == false] =>
// ID: BG-20
// Term: DEDUCERI LA NIVELUL DOCUMENTULUI
Expand Down Expand Up @@ -717,7 +717,7 @@ type PayeeFinancialAccount struct {
FinancialInstitutionBranch *IDNode `xml:"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2 FinancialInstitutionBranch,omitempty"`
}

type PaymentTerms struct {
type InvoicePaymentTerms struct {
Note string `xml:"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2 Note"`
}

Expand Down

0 comments on commit 615157d

Please sign in to comment.