From 0c8aaa678265ac58bd3c174705e119702e6fc997 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 1 Sep 2022 16:09:25 +1000 Subject: [PATCH] Support for vendor and vendor contact imports --- app/Import/Definitions/VendorMap.php | 17 +++++++++ app/Import/Providers/Csv.php | 38 +++++++++++++++++-- .../Transformer/Csv/VendorTransformer.php | 37 +++++++++++++++--- app/Jobs/Import/CSVIngest.php | 2 +- 4 files changed, 84 insertions(+), 10 deletions(-) diff --git a/app/Import/Definitions/VendorMap.php b/app/Import/Definitions/VendorMap.php index ced1809c37..ca2ec64786 100644 --- a/app/Import/Definitions/VendorMap.php +++ b/app/Import/Definitions/VendorMap.php @@ -33,6 +33,15 @@ class VendorMap 14 => 'vendor.state', 15 => 'vendor.postal_code', 16 => 'vendor.country_id', + 17 => 'contact.first_name', + 18 => 'contact.last_name', + 19 => 'contact.email', + 20 => 'contact.phone', + 21 => 'contact.custom_value1', + 22 => 'contact.custom_value2', + 23 => 'contact.custom_value3', + 24 => 'contact.custom_value4', + ]; } @@ -56,6 +65,14 @@ class VendorMap 14 => 'texts.state', 15 => 'texts.postal_code', 16 => 'texts.country', + 17 => 'texts.first_name', + 18 => 'texts.last_name', + 19 => 'texts.email', + 20 => 'texts.phone', + 21 => 'texts.custom_value', + 22 => 'texts.custom_value', + 23 => 'texts.custom_value', + 24 => 'texts.custom_value', ]; } } diff --git a/app/Import/Providers/Csv.php b/app/Import/Providers/Csv.php index 408d6be43b..fcca609495 100644 --- a/app/Import/Providers/Csv.php +++ b/app/Import/Providers/Csv.php @@ -16,12 +16,14 @@ use App\Factory\ExpenseFactory; use App\Factory\InvoiceFactory; use App\Factory\PaymentFactory; use App\Factory\ProductFactory; +use App\Factory\QuoteFactory; use App\Factory\VendorFactory; use App\Http\Requests\Client\StoreClientRequest; use App\Http\Requests\Expense\StoreExpenseRequest; use App\Http\Requests\Invoice\StoreInvoiceRequest; use App\Http\Requests\Payment\StorePaymentRequest; use App\Http\Requests\Product\StoreProductRequest; +use App\Http\Requests\Quote\StoreQuoteRequest; use App\Http\Requests\Vendor\StoreVendorRequest; use App\Import\ImportException; use App\Import\Providers\BaseImport; @@ -31,12 +33,14 @@ use App\Import\Transformer\Csv\ExpenseTransformer; use App\Import\Transformer\Csv\InvoiceTransformer; use App\Import\Transformer\Csv\PaymentTransformer; use App\Import\Transformer\Csv\ProductTransformer; +use App\Import\Transformer\Csv\QuoteTransformer; use App\Import\Transformer\Csv\VendorTransformer; use App\Repositories\ClientRepository; use App\Repositories\ExpenseRepository; use App\Repositories\InvoiceRepository; use App\Repositories\PaymentRepository; use App\Repositories\ProductRepository; +use App\Repositories\QuoteRepository; use App\Repositories\VendorRepository; use Illuminate\Support\Facades\Validator; use Symfony\Component\HttpFoundation\ParameterBag; @@ -55,6 +59,7 @@ class Csv extends BaseImport implements ImportInterface 'payment', 'vendor', 'expense', + 'quote', ]) ) { $this->{$entity}(); @@ -151,6 +156,35 @@ class Csv extends BaseImport implements ImportInterface $this->entity_count['invoices'] = $invoice_count; } + public function quote() + { + $entity_type = 'quote'; + + $data = $this->getCsvData($entity_type); + + if (is_array($data)) { + $data = $this->preTransformCsv($data, $entity_type); + } + + if (empty($data)) { + $this->entity_count['quotes'] = 0; + return; + } + + $this->request_name = StoreQuoteRequest::class; + $this->repository_name = QuoteRepository::class; + $this->factory_name = QuoteFactory::class; + + $this->repository = app()->make($this->repository_name); + $this->repository->import_mode = true; + + $this->transformer = new QuoteTransformer($this->company); + + $quote_count = $this->ingestQuotes($data, 'quote.number'); + + $this->entity_count['quotes'] = $quote_count; + } + public function payment() { $entity_type = 'payment'; @@ -241,10 +275,6 @@ class Csv extends BaseImport implements ImportInterface $this->entity_count['expenses'] = $expense_count; } - public function quote() - { - } - public function task() { } diff --git a/app/Import/Transformer/Csv/VendorTransformer.php b/app/Import/Transformer/Csv/VendorTransformer.php index dcdec1f308..97356d9f66 100644 --- a/app/Import/Transformer/Csv/VendorTransformer.php +++ b/app/Import/Transformer/Csv/VendorTransformer.php @@ -52,15 +52,42 @@ class VendorTransformer extends BaseTransformer 'custom_value2' => $this->getString($data, 'vendor.custom_value2'), 'custom_value3' => $this->getString($data, 'vendor.custom_value3'), 'custom_value4' => $this->getString($data, 'vendor.custom_value4'), - 'vendor_contacts' => [ + // 'vendor_contacts' => [ + // [ + // 'first_name' => $this->getString( + // $data, + // 'vendor.first_name' + // ), + // 'last_name' => $this->getString($data, 'vendor.last_name'), + // 'email' => $this->getString($data, 'vendor.email'), + // 'phone' => $this->getString($data, 'vendor.phone'), + // ], + // ], + 'contacts' => [ [ 'first_name' => $this->getString( $data, - 'vendor.first_name' + 'contact.first_name' + ), + 'last_name' => $this->getString($data, 'contact.last_name'), + 'email' => $this->getString($data, 'contact.email'), + 'phone' => $this->getString($data, 'contact.phone'), + 'custom_value1' => $this->getString( + $data, + 'contact.custom_value1' + ), + 'custom_value2' => $this->getString( + $data, + 'contact.custom_value2' + ), + 'custom_value3' => $this->getString( + $data, + 'contact.custom_value3' + ), + 'custom_value4' => $this->getString( + $data, + 'contact.custom_value4' ), - 'last_name' => $this->getString($data, 'vendor.last_name'), - 'email' => $this->getString($data, 'vendor.email'), - 'phone' => $this->getString($data, 'vendor.phone'), ], ], 'country_id' => isset($data['vendor.country_id']) diff --git a/app/Jobs/Import/CSVIngest.php b/app/Jobs/Import/CSVIngest.php index 5313050be0..8a61d6ca30 100644 --- a/app/Jobs/Import/CSVIngest.php +++ b/app/Jobs/Import/CSVIngest.php @@ -74,7 +74,7 @@ class CSVIngest implements ShouldQueue $engine = $this->bootEngine(); - foreach (['client', 'product', 'invoice', 'payment', 'vendor', 'expense'] as $entity) { + foreach (['client', 'product', 'invoice', 'payment', 'vendor', 'expense', 'quote'] as $entity) { $engine->import($entity); }