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) { } 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) { if ($ex instanceof ImportException) {
$message = $ex->getMessage(); $message = $ex->getMessage();
} else { } else {
@ -510,6 +569,8 @@ class BaseImport
'company' => $this->company, 'company' => $this->company,
]; ];
nlog($this->company->company_users);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new ImportCompleted($this->company, $data); $nmo->mailable = new ImportCompleted($this->company, $data);
$nmo->company = $this->company; $nmo->company = $this->company;

View File

@ -116,7 +116,7 @@ class Csv extends BaseImport implements ImportInterface
$this->transformer = new ProductTransformer($this->company); $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; $this->entity_count['products'] = $product_count;
} }

View File

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

View File

@ -479,7 +479,6 @@ class Company extends BaseModel
public function owner() public function owner()
{ {
return $this->company_users()->withTrashed()->where('is_owner', true)->first()->user; 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) 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')]; $data['$gross_subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getGrossSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
if($this->entity->uses_inclusive_taxes) 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 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']; $data['$invoice.subtotal'] = &$data['$subtotal'];

View File

@ -302,16 +302,28 @@ trait MakesInvoiceValues
$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}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); $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 if($item->quantity > 0 || $item->cost > 0){
// $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.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $this->client->currency());
$data[$key][$table_type.'.unit_cost'] = ($item->cost == 0) ? '' : Number::formatMoneyNoRounding($item->cost, $this->client); $data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $this->client);
$data[$key][$table_type.'.cost'] = ($item->cost == 0) ? '' : Number::formatMoney($item->cost, $this->client); $data[$key][$table_type.'.cost'] = Number::formatMoney($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.'.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')) 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); $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\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
@ -34,12 +35,14 @@ class ZohoTest extends TestCase
{ {
use MakesHash; use MakesHash;
use MockAccountData; use MockAccountData;
use DatabaseTransactions; // use DatabaseTransactions;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
Session::start();
$this->withoutMiddleware(ThrottleRequests::class); $this->withoutMiddleware(ThrottleRequests::class);
config(['database.default' => config('ninja.db.default')]); config(['database.default' => config('ninja.db.default')]);