mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 16:31:33 +02:00
Vendor Import
This commit is contained in:
parent
816cc283a0
commit
4115a6837b
@ -14,10 +14,12 @@ use App\Factory\ClientFactory;
|
|||||||
use App\Factory\InvoiceFactory;
|
use App\Factory\InvoiceFactory;
|
||||||
use App\Factory\PaymentFactory;
|
use App\Factory\PaymentFactory;
|
||||||
use App\Factory\ProductFactory;
|
use App\Factory\ProductFactory;
|
||||||
|
use App\Factory\VendorFactory;
|
||||||
use App\Http\Requests\Client\StoreClientRequest;
|
use App\Http\Requests\Client\StoreClientRequest;
|
||||||
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||||
use App\Http\Requests\Payment\StorePaymentRequest;
|
use App\Http\Requests\Payment\StorePaymentRequest;
|
||||||
use App\Http\Requests\Product\StoreProductRequest;
|
use App\Http\Requests\Product\StoreProductRequest;
|
||||||
|
use App\Http\Requests\Vendor\StoreVendorRequest;
|
||||||
use App\Import\ImportException;
|
use App\Import\ImportException;
|
||||||
use App\Import\Providers\BaseImport;
|
use App\Import\Providers\BaseImport;
|
||||||
use App\Import\Providers\ImportInterface;
|
use App\Import\Providers\ImportInterface;
|
||||||
@ -25,10 +27,12 @@ use App\Import\Transformer\Csv\ClientTransformer;
|
|||||||
use App\Import\Transformer\Csv\InvoiceTransformer;
|
use App\Import\Transformer\Csv\InvoiceTransformer;
|
||||||
use App\Import\Transformer\Csv\PaymentTransformer;
|
use App\Import\Transformer\Csv\PaymentTransformer;
|
||||||
use App\Import\Transformer\Csv\ProductTransformer;
|
use App\Import\Transformer\Csv\ProductTransformer;
|
||||||
|
use App\Import\Transformer\Csv\VendorTransformer;
|
||||||
use App\Repositories\ClientRepository;
|
use App\Repositories\ClientRepository;
|
||||||
use App\Repositories\InvoiceRepository;
|
use App\Repositories\InvoiceRepository;
|
||||||
use App\Repositories\PaymentRepository;
|
use App\Repositories\PaymentRepository;
|
||||||
use App\Repositories\ProductRepository;
|
use App\Repositories\ProductRepository;
|
||||||
|
use App\Repositories\VendorRepository;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
|
||||||
@ -135,7 +139,6 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
$this->entity_count['invoices'] = $invoice_count;
|
$this->entity_count['invoices'] = $invoice_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function payment()
|
private function payment()
|
||||||
{
|
{
|
||||||
$entity_type = 'payment';
|
$entity_type = 'payment';
|
||||||
@ -163,6 +166,44 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
$this->entity_count['payments'] = $payment_count;
|
$this->entity_count['payments'] = $payment_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function vendor()
|
||||||
|
{
|
||||||
|
$entity_type = 'vendor';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
|
$data = $this->preTransform($data, $entity_type);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['vendors'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreVendorRequest::class;
|
||||||
|
$this->repository_name = VendorRepository::class;
|
||||||
|
$this->factory_name = VendorFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new VendorTransformer($this->company);
|
||||||
|
|
||||||
|
$vendor_count = $this->ingest($data, $entity_type);
|
||||||
|
|
||||||
|
$this->entity_count['vendors'] = $vendor_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function expense()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private function quote()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private function task()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function preTransform(array $data, $entity_type)
|
public function preTransform(array $data, $entity_type)
|
||||||
{
|
{
|
||||||
|
70
app/Import/Transformer/Csv/VendorTransformer.php
Normal file
70
app/Import/Transformer/Csv/VendorTransformer.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* client Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
namespace App\Import\Transformer\Csv;
|
||||||
|
|
||||||
|
use App\Import\ImportException;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class VendorTransformer.
|
||||||
|
*/
|
||||||
|
class VendorTransformer extends BaseTransformer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return array|bool
|
||||||
|
*/
|
||||||
|
public function transform($data)
|
||||||
|
{
|
||||||
|
if (isset($data->name) && $this->hasVendor($data->name)) {
|
||||||
|
throw new ImportException('Vendor already exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'name' => $this->getString($data, 'vendor.name'),
|
||||||
|
'phone' => $this->getString($data, 'vendor.phone'),
|
||||||
|
'id_number' => $this->getString($data, 'vendor.id_number'),
|
||||||
|
'vat_number' => $this->getString($data, 'vendor.vat_number'),
|
||||||
|
'website' => $this->getString($data, 'vendor.website'),
|
||||||
|
'currency_id' => $this->getCurrencyByCode(
|
||||||
|
$data,
|
||||||
|
'vendor.currency_id'
|
||||||
|
),
|
||||||
|
'public_notes' => $this->getString($data, 'vendor.public_notes'),
|
||||||
|
'private_notes' => $this->getString($data, 'vendor.private_notes'),
|
||||||
|
'address1' => $this->getString($data, 'vendor.address1'),
|
||||||
|
'address2' => $this->getString($data, 'vendor.address2'),
|
||||||
|
'city' => $this->getString($data, 'vendor.city'),
|
||||||
|
'state' => $this->getString($data, 'vendor.state'),
|
||||||
|
'postal_code' => $this->getString($data, 'vendor.postal_code'),
|
||||||
|
'custom_value1' => $this->getString($data, 'vendor.custom_value1'),
|
||||||
|
'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' => [
|
||||||
|
[
|
||||||
|
'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'),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'country_id' => isset($data['vendor.country_id'])
|
||||||
|
? $this->getCountryId($data['vendor.country_id'])
|
||||||
|
: null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -85,7 +85,7 @@ class BaseTransformer
|
|||||||
nlog("found via contact");
|
nlog("found via contact");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nlog("did not find client");
|
// nlog("did not find client");
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ class ApplyPayment extends AbstractService
|
|||||||
->ledger()
|
->ledger()
|
||||||
->updatePaymentBalance($amount_paid);
|
->updatePaymentBalance($amount_paid);
|
||||||
|
|
||||||
nlog("updating client balance by amount {$amount_paid}");
|
// nlog("updating client balance by amount {$amount_paid}");
|
||||||
|
|
||||||
$this->invoice
|
$this->invoice
|
||||||
->client
|
->client
|
||||||
|
@ -54,6 +54,43 @@ class CsvImportTest extends TestCase
|
|||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testVendorCsvImport() {
|
||||||
|
$csv = file_get_contents( base_path() . '/tests/Feature/Import/vendors.csv' );
|
||||||
|
$hash = Str::random( 32 );
|
||||||
|
$column_map = [
|
||||||
|
0 => 'vendor.name',
|
||||||
|
19 => 'vendor.currency_id',
|
||||||
|
20 => 'vendor.public_notes',
|
||||||
|
21 => 'vendor.private_notes',
|
||||||
|
22 => 'vendor.first_name',
|
||||||
|
23 => 'vendor.last_name',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => [ 'vendor' => [ 'mapping' => $column_map ] ],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'csv',
|
||||||
|
];
|
||||||
|
|
||||||
|
$pre_import = Vendor::count();
|
||||||
|
|
||||||
|
Cache::put( $hash . '-vendor', base64_encode( $csv ), 360 );
|
||||||
|
|
||||||
|
$csv_importer = new Csv($data, $this->company);
|
||||||
|
|
||||||
|
$csv_importer->import('vendor');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasVendor("Ludwig Krajcik DVM"));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testProductImport()
|
public function testProductImport()
|
||||||
{
|
{
|
||||||
$csv = file_get_contents( base_path() . '/tests/Feature/Import/products.csv' );
|
$csv = file_get_contents( base_path() . '/tests/Feature/Import/products.csv' );
|
||||||
@ -256,10 +293,6 @@ class CsvImportTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user