summaryrefslogtreecommitdiff
path: root/src/import_service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/import_service.cpp')
-rw-r--r--src/import_service.cpp49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/import_service.cpp b/src/import_service.cpp
index b7a519c..0aaa839 100644
--- a/src/import_service.cpp
+++ b/src/import_service.cpp
@@ -69,9 +69,33 @@ static int _ai_document_to_invoice_t(void *arg) {
strops_replace(template_buffer, 50000, "{{INVOICE_LINE_LIST}}", peppol_invoice_line_template);
char* ai_query =
- "\n\nI have provided a file containing an invoice. Fill in the above Peppol 3.0 template with the information from the invoice."
- "Do not add any fields to the template. If you can't find data for a given field, leave it empty. Do not make up any information."
- "Only return the filled out template in valid XML format. Nothing else.\n";
+ "\n\nI have provided a file containing an invoice. Fill in the above Peppol 3.0 template with the information from the invoice.\n"
+ "Do not add any fields to the template. If you can't find data for a given field, leave it empty. Do not make up any information.\n"
+ "Only return the filled out template in valid XML format. Nothing else.\n\n"
+ "{{LINE_AMOUNT}} equals the net paid amount for an order line.\n"
+ "{{UNIT_PRICE}} is the net price per unit in an order line.\n"
+ "{{QUANTITY}} is the amount of units per order line. If this is not defined, default to 1.\n"
+ "If {{UNIT_PRICE}} is less than 1.00 and {{QUANTITY}} is more than 10, {{QUANTITY}} should equal 1, {{UNIT_PRICE}} should equal {{LINE_AMOUNT}} and {{ITEM_NAME}} should include the original {{QUANTITY}}.\n" // High quantity, small price, might result in incorrect unit price. e.g. 700x resistor for 2,00 total.
+ "{{UNIT_CODE}} should always be 'X' unless you know for sure know the line item amount is defined as a percentage, in which case it should be '%'.\n"
+ "Every invoice line will atleast have {{LINE_AMOUNT}} and {{ITEM_NAME}} defined.\n"
+ "{{LINE_TAX_PERCENT}} is the tax rate for the line item. This could also be described as VAT rate. Often an invoice only has 1 tax rate defined intstead of per line item.\n"
+ "{{LINE_TAX_ID}} should be set to the country code and tax rate, in the format 'CC/PP' where CC is the 2 letter country code and PP is the tax rate as a number with 2 decimals.\n"
+ "If a line item is taxted with vat reverse Charge, {{LINE_TAX_ID}} should be set to '00/AE'.\n"
+ "If a line item is exempt from Tax, {{LINE_TAX_ID}} should be set to '00/E'.\n"
+ "If a line item is categorized as zero rated goods, {{LINE_TAX_ID}} should be set to '00/Z'.\n"
+ "If a line item is a service outside scope of tax, {{LINE_TAX_ID}} should be set to '00/O'.\n"
+ "If a line item is VAT exempt for EEA intra-community supply of goods and services, {{LINE_TAX_ID}} should be set to '00/K'.\n"
+ "All of there tax rates can be declared as per line item, or per invoice.\n"
+ "If you can find the tax rate for 1 line item but not another, assume they are taxed at the same rate and their {{LINE_TAX_ID}} should match.\n"
+ "If shipping costs are provided, these should also be added to the result as a cac:InvoiceLine.\n"
+ "{{INVOICE_SEQUENCE_ID}} should be set to the provided invoice id or invoice number. This is always defined.\n"
+ "{{ISSUE_DATE}} is the date the invoice was issued and should be stored in format 'YYYY-MM-DD'.\n"
+ "{{DUE_DATE}} is the date the invoice is due and should be stored in format 'YYYY-MM-DD'. If the due date is not defined, {{DUE_DATE}} should equal 0.\n"
+ "{{DELIVERY_DATE}} might be defined and should be stored in format 'YYYY-MM-DD'. If the delivery date is not defined, {{DELIVERY_DATE}} should equal 0.\n"
+ "cac:AccountingSupplierParty contains all information of the supplier. This information might be under the section 'Supplier', 'Seller', 'Sold by' or something similar.\n"
+ "cac:AccountingCustomerParty contains all information of the customer. This information might be under the section 'Customer', 'Ordered by', 'Billing address' or something similar.\n"
+ "cac:Delivery contains the delivery address for physical goods. This information might be under the section 'Shipping address', 'Shipped to' or something similar. If this is not explicitly set, leave this section empty.\n"
+ ;
size_t query_len = strlen(template_buffer);
strncpy(template_buffer + query_len, ai_query, query_buffer_len - query_len);
@@ -92,17 +116,30 @@ static int _ai_document_to_invoice_t(void *arg) {
return 0;
}
- invoice tmp = administration_invoice_create_empty();
-
inv.status = invoice_status::INVOICE_RECEIVED;
- strops_copy(inv.id, tmp.id, MAX_LEN_ID); // TODO next_id is not being incremented
+
+ // Set customer or supplier depending on incomming or outgoing.
contact my_info = administration_company_info_get();
memcpy(&inv.customer, &my_info, sizeof(contact));
strops_copy(inv.customer.id, MY_COMPANY_ID, MAX_LEN_ID);
+ // Project and cost centers cannot be interpreted from file so are set to 0.
+ strops_copy(inv.project_id, "", MAX_LEN_ID);
+ strops_copy(inv.cost_center_id, "", MAX_LEN_ID);
+
+ // Set document references and save copy to disk.
strops_copy(inv.document.original_path, file_path, MAX_LEN_PATH);
strops_copy(inv.document.copy_path, "", MAX_LEN_PATH);
+ // Set dates.
+ if (inv.expires_at == 0) {
+ inv.expires_at = inv.issued_at + administration_get_default_invoice_expire_duration();
+ }
+
+ if (inv.delivered_at == 0) {
+ inv.delivered_at = inv.issued_at;
+ }
+
free(template_buffer);
free(response);