Create customer invoice
In this introduction we will show how we can create a customer invoice, and create the customer if the customer dosn't exists.
A customer invoice is an invoice that is outbound, in contrast to supplier invoice that is incoming invoices. In this article we will use the term invoice for customer invoice.
Create invoice with new customer
Create invoice request body
POST https://test.softrig.com/api/biz/invoices
Body:
{
"InvoiceDate": "2019-10-08",
"PaymentDueDate": "2019-10-22",
"OurReference": "Per Hansen",
"CustomerID": 0,
"Customer": {
"ID": 0,
"OrgNumber": null,
"WebUrl": null,
"Info": {
"Name": "Jo A I Rivelsrud",
"Addresses": [],
"Phones": [
{
"Number": "90577981",
"_createguid": "f007cffe-38d9-4bcf-8f2f-52bbd8b50f6d"
}
],
"Emails": [],
"InvoiceAddress": {
"AddressLine1": "Veien 2",
"PostalCode": "5501",
"City": "Haugesund",
"CountryCode": null,
"_createguid": "f24a0f1a-569d-449e-89ed-f756e6e6afb9"
},
"ShippingAddress": {
"AddressLine1": "Veien 2",
"PostalCode": "5501",
"City": "Haugesund",
"CountryCode": null,
"_createguid": "f24a0f1a-569d-449e-89ed-f756e6e6afb9"
},
"DefaultPhone": {
"Number": "90577981",
"_createguid": "f007cffe-38d9-4bcf-8f2f-52bbd8b50f6d"
},
"_createguid": "279e2cd8-c6b2-4bf2-803e-6773da13511c"
},
"_createguid": "76f3afe7-4c1b-4875-81f8-c0403bb1b707"
},
"CustomerName": "Jo A I Rivelsrud",
"Items": [
{
"ProductID": 1,
"ItemText": "Weber 114",
"Unit": "stk",
"NumberOfItems": 1,
"PriceExVat": 36000,
"AccountID": 283,
"SumVat": 9000,
"_isDirty": true,
"SumVatCurrency": 9000,
"_createguid": "a46d1b85-b7c0-4495-8bad-6054f514edb0",
"VatTypeID": 11,
"PriceIncVat": 45000,
"PriceExVatCurrency": 36000,
"PriceIncVatCurrency": 45000,
"VatPercent": 25,
"SumTotalExVat": 36000,
"SumTotalIncVat": 45000,
"SumTotalExVatCurrency": 36000,
"SumTotalIncVatCurrency": 45000,
"SortIndex": 1
}
],
"PaymentInfoTypeID": 5,
"DistributionPlanID": 5
}
Create invoice with existing customer
Get customer id by name
GET https://test.softrig.com/api/biz/customers?expand=Info&filter=info.name eq 'Jo A I Rivelsrud'&select=id
Result:
[
{
"CustomValues": {},
"ID": 30,
"Deleted": false,
"BusinessRelationID": 129,
"Info": {
"CustomValues": {},
"ID": 129
}
}
]
Create invoice
POST https://test.softrig.com/api/biz/invoices
Request:
{
"InvoiceDate": "2019-10-08",
"PaymentDueDate": "2019-10-22",
"OurReference": "Jo Are Ingvaldsen Rivelsrud",
"CustomerID": 30,
"CustomerName": "Jo A I Rivelsrud",
"Items": [
{
"ProductID": 1,
"ItemText": "Weber 114",
"Unit": "stk",
"NumberOfItems": 1,
"PriceExVat": 36000,
"AccountID": 283,
"SumVat": 9000,
"_isDirty": true,
"SumVatCurrency": 9000,
"_createguid": "b46d1b85-b7c0-4495-8bad-6054f514edc2",
"VatTypeID": 11,
"PriceIncVat": 45000,
"PriceExVatCurrency": 36000,
"PriceIncVatCurrency": 45000,
"VatPercent": 25,
"SumTotalExVat": 36000,
"SumTotalIncVat": 45000,
"SumTotalExVatCurrency": 36000,
"SumTotalIncVatCurrency": 45000,
"SortIndex": 1
}
],
"PaymentInfoTypeID": 5,
"DistributionPlanID": 5
}
Calls that are made to populate the requet body
Get product
https://test.unimicro.no/api/biz/products?filter=name eq 'Weber 114'
Result:
[
{
"CustomValues": {},
"AccountID": 283,
"AverageCost": null,
"CalculateGrossPriceBasedOnNetPrice": true,
"CostPrice": 15000.0000,
"CreatedAt": "2017-06-21T07:19:11.18Z",
"CreatedBy": "864089de-3992-498d-8284-59d5dab926b0",
"DefaultProductCategoryID": 0,
"Deleted": false,
"Description": "Lite enkelt akustisk piano",
"DimensionsID": 1,
"ID": 1,
"ImageFileID": null,
"ListPrice": null,
"Name": "Weber 114",
"PartName": "W114",
"PriceExVat": 36000.0000,
"PriceIncVat": 45000.0000,
"StatusCode": 35001,
"Type": 1,
"Unit": "stk",
"UpdatedAt": "2017-06-21T07:19:11.793Z",
"UpdatedBy": "864089de-3992-498d-8284-59d5dab926b0",
"VariansParentID": 0,
"VatTypeID": 11
}
]
Get PaymentInfoType (KID-type)
GET https://test.unimicro.no/api/biz/paymentinfotype?filter=statuscode eq 42400
Result:
[
{
"CustomValues": {},
"Control": 10,
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"ID": 5,
"Length": 15,
"Locked": false,
"Name": "Uni Faktura KID",
"StatusCode": 42400,
"Type": 1,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"Control": 10,
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"ID": 10,
"Length": 16,
"Locked": false,
"Name": "SGFinans KID",
"StatusCode": 42400,
"Type": 1,
"UpdatedAt": null,
"UpdatedBy": null
}
]
Get distribution plan
GET https://test.unimicro.no/api/biz/distributions?filter=EntityType eq 'Models.Sales.CustomerInvoice'
Result:
[
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 4,
"Name": "Std. EHF",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 5,
"Name": "Std. e-post",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 8,
"Name": "Std. fakturaprint",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 9,
"Name": "Std. efaktura",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 10,
"Name": "Std. factoring",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 15,
"Name": "Ingen utsendelse",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 20,
"Name": "Std. Vippsinvoice",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 21,
"Name": "Std. AvtaleGiro",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
},
{
"CustomValues": {},
"CreatedAt": null,
"CreatedBy": null,
"Deleted": false,
"EntityType": "Models.Sales.CustomerInvoice",
"ID": 22,
"Name": "Std. AvtaleGiro + efaktura",
"StatusCode": 30001,
"UpdatedAt": null,
"UpdatedBy": null
}
]
Create a credit note
In order to create a credit note from an invoice you can use the action create-credit-draft-invoice
Action to create a credit note
PUT https://test.unimicro.no/api/biz/invoices/7?action=create-credit-draft-invoice
Note: the result is not complete
Result:
{
"InvoiceDate": "2019-10-08",
"PaymentDueDate": "2019-10-22",
"InvoiceType": 1,
"Credited": false,
"RestAmount": 0.0,
"RestAmountCurrency": 0.0,
"CreditedAmount": 0.0,
"CreditedAmountCurrency": 0.0,
"InvoiceReferenceID": 7,
"ShippingAddressLine1": "Veien 2",
"ShippingPostalCode": "5501",
"ShippingCity": "Haugesund",
"InvoiceAddressLine1": "Veien 2",
"InvoicePostalCode": "5501",
"InvoiceCity": "Haugesund",
"OurReference": "Per Hansen",
"DeliveryDate": "2019-10-08",
"TaxInclusiveAmountCurrency": -45000.00,
"TaxExclusiveAmountCurrency": -36000.00,
"VatTotalsAmountCurrency": -9000.00,
"TaxInclusiveAmount": -45000.00,
"TaxExclusiveAmount": -36000.00,
"VatTotalsAmount": -9000.00,
"CreditDays": 0,
"CustomerID": 30,
"Customer": {
"CustomerNumber": 100029,
"BusinessRelationID": 129,
"AcceptableDelta4CustomerPayment": 0.0,
"SubAccountNumberSeriesID": 6,
"DefaultCustomerInvoiceReportID": 0,
"DefaultCustomerOrderReportID": 0,
"DefaultCustomerQuoteReportID": 0,
"AvtaleGiro": false,
"AvtaleGiroNotification": false,
"StatusCode": 30001,
"ID": 30,
"Deleted": false,
"CreatedAt": "2019-10-08T18:25:39.51Z",
"UpdatedAt": "2019-10-08T19:07:18.973Z",
"CreatedBy": "864089de-3992-498d-8284-59d5dab926b0",
"UpdatedBy": "864089de-3992-498d-8284-59d5dab926b0",
"_validationResults": {}
},
"CustomerName": "Jo A I Rivelsrud",
"CurrencyCodeID": 1,
"CurrencyExchangeRate": 1.00000,
"InvoiceNumberSeriesID": 3,
"Items": [
{
"SortIndex": 1,
"ProductID": 1,
"ItemText": "Weber 114",
"NumberOfItems": -1.0000,
"PriceSetByUser": false,
"PriceExVat": 36000.0000,
"PriceExVatCurrency": 36000.0000,
"PriceIncVat": 45000.0000,
"CalculateGrossPriceBasedOnNetPrice": false,
"DiscountPercent": 0.0,
"Discount": 0.0,
"DiscountCurrency": 0.0,
"VatTypeID": 11,
"VatType": {
"Visible": true,
"OutputVat": true,
"AvailableInModules": false,
"CreatedAt": "2017-02-16T11:24:43.6Z",
"Deleted": false,
"DirectJournalEntryOnly": false,
"ID": 11,
"Name": "Utgående mva (salg)",
"OutgoingAccountID": 240,
"ReversedTaxDutyVat": false,
"VatCode": "3",
"VatCodeGroupID": 9,
"VatCodeGroupingValue": 4,
"VatTypeSetupID": 0,
"VatCodeGroup": {
"CreatedAt": "2017-02-16T11:24:43.913Z",
"CreatedBy": "864089de-3992-498d-8284-59d5dab926b0",
"Deleted": false,
"ID": 9,
"Name": "Innenlands omsetning og uttak",
"No": "B",
},
"OutgoingAccount": {
"Visible": true,
"AccountGroupID": 204,
"AccountName": "Utgående merverdiavgift, høy sats",
"AccountNumber": 2700,
"AccountSetupID": 1387,
"Active": false,
"CreatedAt": "2017-02-16T11:24:42.367Z",
"Deleted": false,
"DimensionsID": 0,
"DoSynchronize": true,
"ID": 240,
"SupplierID": 0,
"SystemAccount": false,
"TopLevelAccountGroupID": 2,
"UsePostPost": false
},
"VatTypePercentages": [
{
"Deleted": false,
"ID": 11,
"ValidFrom": "2015-01-01",
"VatPercent": 25.00,
"VatTypeID": 11
}
],
},
"VatPercent": 25.0000,
"VatDate": "2019-10-08",
"SumTotalIncVat": -45000.00,
"SumTotalExVat": -36000.00,
"SumVat": -9000.00,
"SumTotalIncVatCurrency": -45000.00,
"SumTotalExVatCurrency": -36000.00,
"SumVatCurrency": -9000.00,
"Unit": "stk",
"CustomerInvoiceID": 8,
"AccountID": 283,
"CurrencyCodeID": 1,
"CurrencyExchangeRate": 1.00000,
"OrderItemId": 0,
"StatusCode": 41301,
"ID": 8,
"Deleted": false,
"CreatedAt": "2019-10-08T19:20:00.3733844Z",
"CreatedBy": "864089de-3992-498d-8284-59d5dab926b0",
"_validationResults": {}
}
],
"PaymentInfoTypeID": 5,
"DistributionPlanID": 5,
"EntityType": "Models.Sales.CustomerInvoice",
"StatusCode": 42001,
"ID": 8,
"Deleted": false,
"CreatedAt": "2019-10-08T19:20:00.340211Z",
"CreatedBy": "864089de-3992-498d-8284-59d5dab926b0",
"_validationResults": {}
}
Then you can credit the note created above.
Invoice the credit note
POST https://test.unimicro.no/api/biz/invoices/8?action=invoice