New Schema Dump

This commit is contained in:
David Bomba 2022-04-26 16:53:41 +10:00
parent ea39f4eefc
commit e521718605
8 changed files with 978 additions and 867 deletions

View File

@ -181,6 +181,65 @@ class BaseImport
} catch (\Exception $ex) {
if(\DB::connection(config('database.default'))->transactionLevel() > 0)
\DB::connection(config('database.default'))->rollBack();
if ($ex instanceof ImportException) {
$message = $ex->getMessage();
} else {
report($ex);
$message = 'Unknown error';
}
$this->error_array[$entity_type][] = [
$entity_type => $record,
'error' => $message,
];
}
}
return $count;
}
public function ingestProducts($data, $entity_type)
{
$count = 0;
foreach ($data as $key => $record) {
try {
$entity = $this->transformer->transform($record);
$validator = $this->request_name::runFormRequest($entity);
if ($validator->fails()) {
$this->error_array[$entity_type][] = [
$entity_type => $record,
'error' => $validator->errors()->all(),
];
} else {
if($this->transformer->hasProduct($entity['product_key']))
$product = $this->transformer->getProduct($entity['product_key']);
else
$product = $this->factory_name::create($this->company->id,$this->getUserIDForRecord($entity));
$entity = $this->repository->save(
array_diff_key($entity, ['user_id' => false]),
$product
);
$entity->saveQuietly();
$count++;
}
} catch (\Exception $ex) {
if(\DB::connection(config('database.default'))->transactionLevel() > 0)
\DB::connection(config('database.default'))->rollBack();
if ($ex instanceof ImportException) {
$message = $ex->getMessage();
} else {
@ -510,6 +569,8 @@ class BaseImport
'company' => $this->company,
];
nlog($this->company->company_users);
$nmo = new NinjaMailerObject;
$nmo->mailable = new ImportCompleted($this->company, $data);
$nmo->company = $this->company;

View File

@ -116,7 +116,7 @@ class Csv extends BaseImport implements ImportInterface
$this->transformer = new ProductTransformer($this->company);
$product_count = $this->ingest($data, $entity_type);
$product_count = $this->ingestProducts($data, $entity_type);
$this->entity_count['products'] = $product_count;
}

View File

@ -199,20 +199,16 @@ class BaseTransformer
*
* @return string
*/
public function getProduct($data, $key, $field, $default = false)
public function getProduct($key)
{
$product = $this->company
->products()
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $data->{$key})),
strtolower(str_replace(' ', '', $key)),
])
->first();
if ($product) {
return $product->{$field} ?: $default;
}
return $default;
return $product;
}
/**

View File

@ -479,7 +479,6 @@ class Company extends BaseModel
public function owner()
{
return $this->company_users()->withTrashed()->where('is_owner', true)->first()->user;
//return $this->company_users->where('is_owner', true)->first()->user;
}
public function resolveRouteBinding($value, $field = null)

View File

@ -213,9 +213,9 @@ class HtmlEngine
$data['$gross_subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getGrossSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
if($this->entity->uses_inclusive_taxes)
$data['$net_subtotal'] = ['value' => Number::formatMoney(($this->entity_calc->getSubTotal() - $this->entity->total_taxes), $this->client) ?: ' ', 'label' => ctrans('texts.net_subtotal')];
$data['$net_subtotal'] = ['value' => Number::formatMoney(($this->entity_calc->getSubTotal() - $this->entity->total_taxes - $this->entity_calc->getTotalDiscount()), $this->client) ?: ' ', 'label' => ctrans('texts.net_subtotal')];
else
$data['$net_subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.net_subtotal')];
$data['$net_subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getSubTotal() - $this->entity_calc->getTotalDiscount(), $this->client) ?: ' ', 'label' => ctrans('texts.net_subtotal')];
$data['$invoice.subtotal'] = &$data['$subtotal'];

View File

@ -301,17 +301,29 @@ trait MakesInvoiceValues
$data[$key][$table_type . ".{$_table_type}2"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}2", $item->custom_value2, $this->client);
$data[$key][$table_type . ".{$_table_type}3"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}3", $item->custom_value3, $this->client);
$data[$key][$table_type . ".{$_table_type}4"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}4", $item->custom_value4, $this->client);
// 08-02-2022 - fix for regression below
// $data[$key][$table_type.'.quantity'] = Number::formatValue($item->quantity, $this->client->currency());
$data[$key][$table_type.'.quantity'] = ($item->quantity == 0) ? '' : Number::formatValueNoTrailingZeroes($item->quantity, $this->client->currency());
$data[$key][$table_type.'.unit_cost'] = ($item->cost == 0) ? '' : Number::formatMoneyNoRounding($item->cost, $this->client);
if($item->quantity > 0 || $item->cost > 0){
$data[$key][$table_type.'.cost'] = ($item->cost == 0) ? '' : Number::formatMoney($item->cost, $this->client);
$data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $this->client->currency());
$data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $this->client);
$data[$key][$table_type.'.line_total'] = ($item->line_total == 0) ? '' :Number::formatMoney($item->line_total, $this->client);
$data[$key][$table_type.'.cost'] = Number::formatMoney($item->cost, $this->client);
$data[$key][$table_type.'.line_total'] = Number::formatMoney($item->line_total, $this->client);
}
else {
$data[$key][$table_type.'.quantity'] = '';
$data[$key][$table_type.'.unit_cost'] = '';
$data[$key][$table_type.'.cost'] = '';
$data[$key][$table_type.'.line_total'] = '';
}
if(property_exists($item, 'gross_line_total'))
$data[$key][$table_type.'.gross_line_total'] = ($item->gross_line_total == 0) ? '' :Number::formatMoney($item->gross_line_total, $this->client);

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@ use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Tests\MockAccountData;
use Tests\TestCase;
@ -34,12 +35,14 @@ class ZohoTest extends TestCase
{
use MakesHash;
use MockAccountData;
use DatabaseTransactions;
// use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
Session::start();
$this->withoutMiddleware(ThrottleRequests::class);
config(['database.default' => config('ninja.db.default')]);
@ -120,7 +123,7 @@ class ZohoTest extends TestCase
Cache::put($hash . '-client', base64_encode($csv), 360);
$csv_importer = new Zoho($data, $this->company);
$count = $csv_importer->import('client');
$base_transformer = new BaseTransformer($this->company);