mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge pull request #4522 from turbo124/v5-develop
Handle invoice numbers on restore
This commit is contained in:
commit
f45588d26e
@ -73,7 +73,6 @@ class SelfUpdateController extends BaseController
|
||||
info($e->getMessage());
|
||||
return response()->json(['message'=>$e->getMessage()], 500);
|
||||
}
|
||||
info('Are there any changes to pull? '.$repo->hasChanges());
|
||||
|
||||
dispatch(function () {
|
||||
Artisan::call('ninja:post-update');
|
||||
|
57
app/Import/Definitions/ProductMap.php
Normal file
57
app/Import/Definitions/ProductMap.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* client Ninja (https://clientninja.com).
|
||||
*
|
||||
* @link https://github.com/clientninja/clientninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. client Ninja LLC (https://clientninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Import\Definitions;
|
||||
|
||||
class ProductMap
|
||||
{
|
||||
public static function importable()
|
||||
{
|
||||
return [
|
||||
0 => 'product.product_key',
|
||||
1 => 'product.notes',
|
||||
2 => 'product.cost',
|
||||
3 => 'product.price',
|
||||
4 => 'product.quantity',
|
||||
5 => 'product.tax_name1',
|
||||
6 => 'product.tax_rate1',
|
||||
7 => 'product.tax_name2',
|
||||
8 => 'product.tax_rate2',
|
||||
9 => 'product.tax_name3',
|
||||
10 => 'product.tax_rate3',
|
||||
11 => 'product.custom_value1',
|
||||
12 => 'product.custom_value2',
|
||||
13 => 'product.custom_value3',
|
||||
14 => 'product.custom_value4',
|
||||
];
|
||||
}
|
||||
|
||||
public static function import_keys()
|
||||
{
|
||||
return [
|
||||
0 => 'texts.item',
|
||||
1 => 'texts.notes',
|
||||
2 => 'texts.cost',
|
||||
3 => 'texts.price',
|
||||
4 => 'texts.quantity',
|
||||
5 => 'texts.tax_name',
|
||||
6 => 'texts.tax_rate',
|
||||
7 => 'texts.tax_name',
|
||||
8 => 'texts.tax_rate',
|
||||
9 => 'texts.tax_name',
|
||||
10 => 'texts.tax_rate',
|
||||
11 => 'texts.custom_value',
|
||||
12 => 'texts.custom_value',
|
||||
13 => 'texts.custom_value',
|
||||
14 => 'texts.custom_value',
|
||||
];
|
||||
}
|
||||
}
|
38
app/Import/Transformers/ProductTransformer.php
Normal file
38
app/Import/Transformers/ProductTransformer.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Import\Transformers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class ProductTransformer.
|
||||
*/
|
||||
class ProductTransformer extends BaseTransformer
|
||||
{
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return bool|Item
|
||||
*/
|
||||
public function transform($data)
|
||||
{
|
||||
return [
|
||||
'company_id' => $this->maps['company']->id,
|
||||
'product_key' => $this->getString($data, 'product.product_key'),
|
||||
'notes' => $this->getString($data, 'product.notes'),
|
||||
'cost' => $this->getString($data, 'product.cost'),
|
||||
'price' => $this->getString($data, 'product.price'),
|
||||
'quantity' => $this->getString($data, 'product.quantity'),
|
||||
'tax_name1' => $this->getString($data, 'product.tax_name1'),
|
||||
'tax_rate1' => $this->getString($data, 'product.tax_rate1'),
|
||||
'tax_name2' => $this->getString($data, 'product.tax_name2'),
|
||||
'tax_rate2' => $this->getString($data, 'product.tax_rate2'),
|
||||
'tax_name3' => $this->getString($data, 'product.tax_name3'),
|
||||
'tax_rate3' => $this->getString($data, 'product.tax_rate3'),
|
||||
'custom_value1' => $this->getString($data, 'product.custom_value1'),
|
||||
'custom_value2' => $this->getString($data, 'product.custom_value2'),
|
||||
'custom_value3' => $this->getString($data, 'product.custom_value3'),
|
||||
'custom_value4' => $this->getString($data, 'product.custom_value4'),
|
||||
];
|
||||
}
|
||||
}
|
@ -12,8 +12,11 @@
|
||||
namespace App\Jobs\Import;
|
||||
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Factory\ProductFactory;
|
||||
use App\Http\Requests\Client\StoreClientRequest;
|
||||
use App\Http\Requests\Product\StoreProductRequest;
|
||||
use App\Import\Transformers\ClientTransformer;
|
||||
use App\Import\Transformers\ProductTransformer;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
@ -21,6 +24,7 @@ use App\Models\Currency;
|
||||
use App\Models\User;
|
||||
use App\Repositories\ClientContactRepository;
|
||||
use App\Repositories\ClientRepository;
|
||||
use App\Repositories\ProductRepository;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@ -54,27 +58,6 @@ class CSVImport implements ShouldQueue
|
||||
|
||||
public $maps;
|
||||
|
||||
/*
|
||||
[hash] => 2lTm7HVR3i9Zv3y86eQYZIO16yVJ7J6l
|
||||
[entity_type] => client
|
||||
[skip_header] => 1
|
||||
[column_map] => Array
|
||||
(
|
||||
[0] => client.name
|
||||
[1] => client.user_id
|
||||
[2] => client.balance
|
||||
[3] => client.paid_to_date
|
||||
[4] => client.address1
|
||||
[5] => client.address2
|
||||
[6] => client.city
|
||||
[7] => client.state
|
||||
[8] => client.postal_code
|
||||
[9] => client.country_id
|
||||
[20] => client.currency_id
|
||||
[21] => client.public_notes
|
||||
[22] => client.private_notes
|
||||
)
|
||||
*/
|
||||
public function __construct(array $request, Company $company)
|
||||
{
|
||||
$this->company = $company;
|
||||
@ -106,6 +89,51 @@ class CSVImport implements ShouldQueue
|
||||
//sort the array by key
|
||||
ksort($this->column_map);
|
||||
|
||||
$this->{"import".ucfirst($this->entity_type)}();
|
||||
}
|
||||
|
||||
public function failed($exception)
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private function importProduct()
|
||||
{
|
||||
$product_repository = new ProductRepository();
|
||||
$product_transformer new ProductTransformer($this->maps);
|
||||
|
||||
$records = $this->getCsvData();
|
||||
|
||||
if ($this->skip_header)
|
||||
array_shift($records);
|
||||
|
||||
foreach ($records as $record)
|
||||
{
|
||||
$keys = $this->column_map;
|
||||
$values = array_intersect_key($record, $this->column_map);
|
||||
|
||||
$product_data = array_combine($keys, $values);
|
||||
|
||||
$product = $product_transformer->transform($product_data);
|
||||
|
||||
$validator = Validator::make($client, (new StoreProductRequest())->rules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->error_array[] = ['product' => $product, 'error' => json_encode($validator->errors())];
|
||||
} else {
|
||||
$product = $product_repository->save($product, ProductFactory::create($this->company->id, $this->setUser($record)));
|
||||
|
||||
$product->save();
|
||||
|
||||
$this->maps['products'][] = $product->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//todo limit client imports for hosted version
|
||||
private function importClient()
|
||||
{
|
||||
//clients
|
||||
$records = $this->getCsvData();
|
||||
|
||||
@ -113,9 +141,8 @@ class CSVImport implements ShouldQueue
|
||||
$client_repository = new ClientRepository($contact_repository);
|
||||
$client_transformer = new ClientTransformer($this->maps);
|
||||
|
||||
if ($this->skip_header) {
|
||||
if ($this->skip_header)
|
||||
array_shift($records);
|
||||
}
|
||||
|
||||
foreach ($records as $record) {
|
||||
$keys = $this->column_map;
|
||||
@ -142,21 +169,19 @@ class CSVImport implements ShouldQueue
|
||||
|
||||
$client->save();
|
||||
|
||||
$this->import_array['clients'][] = $client->id;
|
||||
$this->maps['clients'][] = $client->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function failed($exception)
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private function buildMaps()
|
||||
{
|
||||
$this->maps['currencies'] = Currency::all();
|
||||
$this->maps['users'] = $this->company->users;
|
||||
$this->maps['company'] = $this->company;
|
||||
$this->maps['clients'] = [];
|
||||
$this->maps['products'] = [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -94,6 +94,9 @@ class HandleRestore extends AbstractService
|
||||
|
||||
$new_invoice_number = substr($this->invoice->number, 0, $pos);
|
||||
|
||||
if(strlen($new_invoice_number) == 0)
|
||||
$new_invoice_number = null;
|
||||
|
||||
try {
|
||||
$this->invoice->number = $new_invoice_number;
|
||||
$this->invoice->save();
|
||||
|
@ -48,7 +48,7 @@ class ProjectTransformer extends EntityTransformer
|
||||
'assigned_user_id' => (string) $this->encodePrimaryKey($project->assigned_user_id),
|
||||
'client_id' => (string) $this->encodePrimaryKey($project->client_id),
|
||||
'name' => $project->name ?: '',
|
||||
'number' => $project->number,
|
||||
'number' => $project->number ?: '',
|
||||
'created_at' => (int) $project->created_at,
|
||||
'updated_at' => (int) $project->updated_at,
|
||||
'archived_at' => (int) $project->deleted_at,
|
||||
|
Loading…
x
Reference in New Issue
Block a user