Fixes for base repo ->save() method (#3392)

* Fixes for tests

* payment

* remove field from company table

* Fixes for repo save()
This commit is contained in:
David Bomba 2020-02-28 07:23:25 +11:00 committed by GitHub
parent a5cbcebcf9
commit 464dd3f9eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 22 deletions

View File

@ -192,8 +192,8 @@ class CompanySettings extends BaseSettings {
public $late_fee_endless_amount = 0; public $late_fee_endless_amount = 0;
public $late_fee_endless_percent = 0; public $late_fee_endless_percent = 0;
public $client_online_payment_notification = true; public $client_online_payment_notification = true; //@todo implement in notifications
public $client_manual_payment_notification = true; public $client_manual_payment_notification = true; //@todo implement in notifications
public $system_notifications_slack = ''; public $system_notifications_slack = '';
public $system_notifications_email = ''; public $system_notifications_email = '';
@ -381,7 +381,7 @@ class CompanySettings extends BaseSettings {
'counter_padding' => 'integer', 'counter_padding' => 'integer',
'design' => 'string', 'design' => 'string',
'website' => 'string', 'website' => 'string',
'pdf_variables' => 'object', 'pdf_variables' => 'array',
]; ];
/** /**

View File

@ -460,8 +460,12 @@ class CompanyController extends BaseController
*/ */
public function destroy(DestroyCompanyRequest $request, Company $company) public function destroy(DestroyCompanyRequest $request, Company $company)
{ {
$company->delete();
$company->delete();
//@TODO if last company, delete the account also.
return response()->json([], 200); return response()->json([], 200);
} }
} }

View File

@ -11,7 +11,6 @@
* @OA\Property(property="portal_domain", type="string", example="https://subdomain.invoicing.co", description="The fully qualified domain for client facing URLS"), * @OA\Property(property="portal_domain", type="string", example="https://subdomain.invoicing.co", description="The fully qualified domain for client facing URLS"),
* @OA\Property(property="enabled_tax_rates", type="integer", example="1", description="Number of taxes rates used per entity"), * @OA\Property(property="enabled_tax_rates", type="integer", example="1", description="Number of taxes rates used per entity"),
* @OA\Property(property="fill_products", type="boolean", example=true, description="Toggles filling a product description based on product key"), * @OA\Property(property="fill_products", type="boolean", example=true, description="Toggles filling a product description based on product key"),
* @OA\Property(property="enable_invoice_quantity", type="boolean", example=true, description="Toggles filling a product description based on product key"),
* @OA\Property(property="convert_products", type="boolean", example=true, description="___________"), * @OA\Property(property="convert_products", type="boolean", example=true, description="___________"),
* @OA\Property(property="update_products", type="boolean", example=true, description="Toggles updating a product description which description changes"), * @OA\Property(property="update_products", type="boolean", example=true, description="Toggles updating a product description which description changes"),
* @OA\Property(property="show_product_details", type="boolean", example=true, description="Toggles showing a product description which description changes"), * @OA\Property(property="show_product_details", type="boolean", example=true, description="Toggles showing a product description which description changes"),

View File

@ -63,7 +63,6 @@ class Company extends BaseModel
'enable_product_quantity', 'enable_product_quantity',
'enabled_modules', 'enabled_modules',
'default_quantity', 'default_quantity',
'enable_invoice_quantity',
'enabled_tax_rates', 'enabled_tax_rates',
'portal_mode', 'portal_mode',
'portal_domain', 'portal_domain',

View File

@ -179,18 +179,14 @@ class BaseRepository
$class = new ReflectionClass($model); $class = new ReflectionClass($model);
$state = []; $state = [];
$resource = explode('\\', $class->name)[2]; /** This will extract 'Invoice' from App\Models\Invoice */ $resource = explode('\\', $class->name)[2]; /** This will extract 'Invoice' from App\Models\Invoice */
$lcfirst_resource_id = lcfirst($resource) . '_id';
if ($class->name == 'App\Models\Invoice') { if ($class->name == Invoice::class || $class->name == Quote::class)
$state['starting_amount'] = $model->amount; $state['starting_amount'] = $model->amount;
if (!$model->id) { if (!$model->id) {
$client = Client::find($data['client_id']); $client = Client::find($data['client_id']);
$model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes'); $model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes');
}
}
if ($class->name == 'App\Models\Quote') {
$state['starting_amount'] = $model->amount;
} }
$model->fill($data); $model->fill($data);
@ -234,7 +230,7 @@ class BaseRepository
} }
$new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id); $new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id);
$new_invitation->quote_id = $model->id; $new_invitation->{$lcfirst_resource_id} = $model->id;
$new_invitation->client_contact_id = $this->decodePrimaryKey($invitation['client_contact_id']); $new_invitation->client_contact_id = $this->decodePrimaryKey($invitation['client_contact_id']);
$new_invitation->save(); $new_invitation->save();
@ -253,7 +249,7 @@ class BaseRepository
$model = $model->service()->applyNumber()->save(); $model = $model->service()->applyNumber()->save();
if ($class->name == 'App\Models\Invoice') { if ($class->name == Invoice::class) {
if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) { if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
$model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount'])); $model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount']));
@ -267,11 +263,11 @@ class BaseRepository
} }
if ($class->name == 'App\Models\Credit') { if ($class->name == Credit::class) {
$model = $model->calc()->getCredit(); $model = $model->calc()->getCredit();
} }
if ($class->name == 'App\Models\Quote') { if ($class->name == Quote::class) {
$model = $model->calc()->getQuote(); $model = $model->calc()->getQuote();
} }

View File

@ -91,7 +91,6 @@ class CompanyTransformer extends EntityTransformer
'custom_surcharge_taxes3' => (bool)$company->custom_surcharge_taxes3, 'custom_surcharge_taxes3' => (bool)$company->custom_surcharge_taxes3,
'custom_surcharge_taxes4' => (bool)$company->custom_surcharge_taxes4, 'custom_surcharge_taxes4' => (bool)$company->custom_surcharge_taxes4,
'show_product_cost' => (bool)$company->show_product_cost, 'show_product_cost' => (bool)$company->show_product_cost,
'enable_invoice_quantity' => (bool)$company->enable_invoice_quantity,
'enable_product_cost' => (bool)$company->enable_product_cost, 'enable_product_cost' => (bool)$company->enable_product_cost,
'show_product_details' => (bool)$company->show_product_details, 'show_product_details' => (bool)$company->show_product_details,
'enable_product_quantity' => (bool)$company->enable_product_quantity, 'enable_product_quantity' => (bool)$company->enable_product_quantity,

View File

@ -67,7 +67,7 @@ class CreateUsersTable extends Migration
$table->string('decimal_separator'); $table->string('decimal_separator');
$table->string('code'); $table->string('code');
$table->boolean('swap_currency_symbol')->default(false); $table->boolean('swap_currency_symbol')->default(false);
$table->decimal('exchange_rate', 6, 6); $table->decimal('exchange_rate', 6, 6)->default(1);
}); });
@ -154,7 +154,7 @@ class CreateUsersTable extends Migration
$table->boolean('custom_surcharge_taxes2')->default(false); $table->boolean('custom_surcharge_taxes2')->default(false);
$table->boolean('custom_surcharge_taxes3')->default(false); $table->boolean('custom_surcharge_taxes3')->default(false);
$table->boolean('custom_surcharge_taxes4')->default(false); $table->boolean('custom_surcharge_taxes4')->default(false);
$table->boolean('enable_invoice_quantity')->default(true); //$table->boolean('enable_invoice_quantity')->default(true);
$table->boolean('show_product_cost')->default(false); $table->boolean('show_product_cost')->default(false);
$table->unsignedInteger('enabled_tax_rates')->default(1); $table->unsignedInteger('enabled_tax_rates')->default(1);
$table->unsignedInteger('enabled_modules')->default(0); $table->unsignedInteger('enabled_modules')->default(0);