From c3c868b90da520fc5dc3cea6e299747f89963066 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 19 Dec 2020 12:45:12 +1100 Subject: [PATCH] Working on Invoice + Payment csv import --- app/Import/Definitions/PaymentMap.php | 58 +++++++++++++++++ app/Import/Definitions/ProductMap.php | 2 - app/Import/Transformers/BaseTransformer.php | 9 +++ app/Import/Transformers/ClientTransformer.php | 9 +++ .../Transformers/InvoiceTransformer.php | 65 +++++++++++++++++++ .../Transformers/PaymentTransformer.php | 47 ++++++++++++++ .../Transformers/ProductTransformer.php | 9 +++ app/Jobs/Import/CSVImport.php | 2 +- 8 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 app/Import/Definitions/PaymentMap.php create mode 100644 app/Import/Transformers/InvoiceTransformer.php create mode 100644 app/Import/Transformers/PaymentTransformer.php diff --git a/app/Import/Definitions/PaymentMap.php b/app/Import/Definitions/PaymentMap.php new file mode 100644 index 000000000000..c9567e50e044 --- /dev/null +++ b/app/Import/Definitions/PaymentMap.php @@ -0,0 +1,58 @@ + 'payment.number', + 1 => 'payment.user_id', + 2 => 'payment.amount', + 3 => 'payment.refunded', + 4 => 'payment.applied', + 5 => 'payment.transaction_reference', + 6 => 'payment.private_notes', + 7 => 'payment.custom_value1', + 8 => 'payment.custom_value2', + 9 => 'payment.custom_value3', + 10 => 'payment.custom_value4', + 11 => 'payment.client_id', + 12 => 'payment.invoice_number', + 13 => 'payment.date', + 14 => 'payment.method', + ]; + } + + public static function import_keys() + { + return [ + 0 => 'texts.number', + 1 => 'texts.user', + 2 => 'texts.amount', + 3 => 'texts.refunded', + 4 => 'texts.applied', + 5 => 'texts.transaction_reference', + 6 => 'texts.private_notes', + 7 => 'texts.custom_value', + 8 => 'texts.custom_value', + 9 => 'texts.custom_value', + 10 => 'texts.custom_value', + 11 => 'texts.client', + 12 => 'texts.invoice_number', + 13 => 'texts.date', + 14 => 'texts.method' + ]; + } +} + diff --git a/app/Import/Definitions/ProductMap.php b/app/Import/Definitions/ProductMap.php index 91506fe9aab2..d79582852819 100644 --- a/app/Import/Definitions/ProductMap.php +++ b/app/Import/Definitions/ProductMap.php @@ -31,7 +31,6 @@ class ProductMap 12 => 'product.custom_value2', 13 => 'product.custom_value3', 14 => 'product.custom_value4', - 15 => 'product.user_id', ]; } @@ -53,7 +52,6 @@ class ProductMap 12 => 'texts.custom_value', 13 => 'texts.custom_value', 14 => 'texts.custom_value', - 15 => 'texts.user', ]; } } diff --git a/app/Import/Transformers/BaseTransformer.php b/app/Import/Transformers/BaseTransformer.php index 743c12708476..dc50579a77d7 100644 --- a/app/Import/Transformers/BaseTransformer.php +++ b/app/Import/Transformers/BaseTransformer.php @@ -1,4 +1,13 @@ $this->maps['company']->id, + 'number' => $this->getString($data, 'invoice.number'), + 'user_id' => $this->getString($data, 'invoice.user_id'), + 'amount' => $this->getString($data, 'invoice.amount'), + 'balance' => $this->getString($data, 'invoice.balance'), + 'client_id' => $this->getString($data, 'invoice.client_id'), + 'discount' => $this->getString($data, 'invoice.discount'), + 'po_number' => $this->getString($data, 'invoice.po_number'), + 'date' => $this->getString($data, 'invoice.date'), + 'due_date' => $this->getString($data, 'invoice.due_date'), + 'terms' => $this->getString($data, 'invoice.terms'), + 'public_notes' => $this->getString($data, 'invoice.public_notes'), + 'is_sent' => $this->getString($data, 'invoice.is_sent'), + 'private_notes' => $this->getString($data, 'invoice.private_notes'), + 'uses_inclusive_taxes' => $this->getString($data, 'invoice.uses_inclusive_taxes'), + 'tax_name1' => $this->getString($data, 'invoice.tax_name1'), + 'tax_rate1' => $this->getString($data, 'invoice.tax_rate1'), + 'tax_name2' => $this->getString($data, 'invoice.tax_name2'), + 'tax_rate2' => $this->getString($data, 'invoice.tax_rate2'), + 'tax_name3' => $this->getString($data, 'invoice.tax_name3'), + 'tax_rate3' => $this->getString($data, 'invoice.tax_rate3'), + 'custom_value1' => $this->getString($data, 'invoice.custom_value1'), + 'custom_value2' => $this->getString($data, 'invoice.custom_value2'), + 'custom_value3' => $this->getString($data, 'invoice.custom_value3'), + 'custom_value4' => $this->getString($data, 'invoice.custom_value4'), + 'is_amount_discount' => $this->getString($data, 'invoice.is_amount_discount'), + 'footer' => $this->getString($data, 'invoice.footer'), + 'partial' => $this->getString($data, 'invoice.partial'), + 'partial_due_date' => $this->getString($data, 'invoice.partial_due_date'), + 'custom_surcharge1' => $this->getString($data, 'invoice.custom_surcharge1'), + 'custom_surcharge2' => $this->getString($data, 'invoice.custom_surcharge2'), + 'custom_surcharge3' => $this->getString($data, 'invoice.custom_surcharge3'), + 'custom_surcharge4' => $this->getString($data, 'invoice.custom_surcharge4'), + 'exchange_rate' => $this->getString($data, 'invoice.exchange_rate'), + ]; + } +} \ No newline at end of file diff --git a/app/Import/Transformers/PaymentTransformer.php b/app/Import/Transformers/PaymentTransformer.php new file mode 100644 index 000000000000..ec076f184eea --- /dev/null +++ b/app/Import/Transformers/PaymentTransformer.php @@ -0,0 +1,47 @@ + $this->maps['company']->id, + 'number' => $this->getString($data, 'payment.number'), + 'user_id' => $this->getString($data, 'payment.user_id'), + 'amount' => $this->getString($data, 'payment.amount'), + 'refunded' => $this->getString($data, 'payment.refunded'), + 'applied' => $this->getString($data, 'payment.applied'), + 'transaction_reference' => $this->getString($data, 'payment.transaction_reference '), + 'date' => $this->getString($data, 'payment.date'), + 'private_notes' => $this->getString($data, 'payment.private_notes'), + 'number' => $this->getString($data, 'number'), + 'custom_value1' => $this->getString($data, 'custom_value1'), + 'custom_value2' => $this->getString($data, 'custom_value2'), + 'custom_value3' => $this->getString($data, 'custom_value3'), + 'custom_value4' => $this->getString($data, 'custom_value4'), + 'client_id' => $this->getString($data, 'client_id'), + 'invoice_number' => $this->getString($data, 'payment.invoice_number'), + ]; + } +} \ No newline at end of file diff --git a/app/Import/Transformers/ProductTransformer.php b/app/Import/Transformers/ProductTransformer.php index 6069bb51b0ac..84ff28f3b3d8 100644 --- a/app/Import/Transformers/ProductTransformer.php +++ b/app/Import/Transformers/ProductTransformer.php @@ -1,4 +1,13 @@ column_map); + info("import".ucfirst($this->entity_type)); $this->{"import".ucfirst($this->entity_type)}(); - info(print_r($this->maps,1)); } public function failed($exception)