From 1b3a9e63983aa4e0ed04ab3c36f9337a15ed6e24 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 23 Feb 2021 09:08:43 +1100 Subject: [PATCH 1/4] Fixes for updating products --- app/DataMapper/CompanySettings.php | 4 ++-- app/Http/Controllers/OpenAPI/CompanySettingsSchema.php | 1 - app/Http/Controllers/ProductController.php | 2 +- app/Models/RecurringInvoice.php | 1 - app/Repositories/BaseRepository.php | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 9bfd34f021bb..8c096364a68a 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -136,7 +136,7 @@ class CompanySettings extends BaseSettings public $tax_name3 = ''; //@TODO where do we use this? public $tax_rate3 = 0; //@TODO where do we use this? public $payment_type_id = '0'; //@TODO where do we use this? - public $invoice_fields = ''; //@TODO is this redundant, we store this in the custom_fields on the company? + // public $invoice_fields = ''; //@TODO is this redundant, we store this in the custom_fields on the company? public $show_accept_invoice_terms = false; //@TODO ben to confirm public $show_accept_quote_terms = false; //@TODO ben to confirm @@ -392,7 +392,7 @@ class CompanySettings extends BaseSettings 'invoice_number_pattern' => 'string', 'invoice_number_counter' => 'integer', 'invoice_design_id' => 'string', - 'invoice_fields' => 'string', + // 'invoice_fields' => 'string', 'invoice_taxes' => 'int', //'enabled_item_tax_rates' => 'int', 'invoice_footer' => 'string', diff --git a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php index fe19347cc086..db5ef1542408 100644 --- a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php +++ b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php @@ -78,7 +78,6 @@ * @OA\Property(property="tax_name3", type="string", example="GST", description="The tax name"), * @OA\Property(property="payment_type_id", type="string", example="1", description="The default payment type id"), * @OA\Property(property="custom_fields", type="string", example="{}", description="JSON string of custom fields"), - * @OA\Property(property="invoice_fields", type="string", example="{}", description="JSON string of invoice fields"), * @OA\Property(property="email_footer", type="string", example="A default email footer", description="The default email footer"), * @OA\Property(property="email_sending_method", type="string", example="default", description="The email driver to use to send email, options include default, gmail"), * @OA\Property(property="gmail_sending_user_id", type="string", example="F76sd34D", description="The hashed_id of the user account to send email from"), diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 3ee844e2deeb..dcc0ef4d5739 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -406,7 +406,7 @@ class ProductController extends BaseController */ public function destroy(DestroyProductRequest $request, Product $product) { - $product->delete(); + $product = $this->product_repo->delete($product); return $this->itemResponse($product); } diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 956aa558e9e1..d824ef420f8d 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -74,7 +74,6 @@ class RecurringInvoice extends BaseModel 'due_date', 'due_date_days', 'line_items', - 'settings', 'footer', 'public_notes', 'private_notes', diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 937556290fb5..6b182baf56cd 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -292,7 +292,7 @@ class BaseRepository $model = $model->service()->applyNumber()->save(); /* Update product details if necessary */ - if ($model->company->update_products !== false) + if ($model->company->update_products) UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company); /* Perform model specific tasks */ From 47a2ff7df35894d4a268c78ada0ec1f31cedd5fb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 23 Feb 2021 09:47:54 +1100 Subject: [PATCH 2/4] Fixes for tests --- app/Http/Controllers/ProductController.php | 4 ++-- app/Models/Invoice.php | 10 ++++++++++ app/Utils/HtmlEngine.php | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index dcc0ef4d5739..aa7bca103a89 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -406,9 +406,9 @@ class ProductController extends BaseController */ public function destroy(DestroyProductRequest $request, Product $product) { - $product = $this->product_repo->delete($product); + $this->product_repo->delete($product); - return $this->itemResponse($product); + return $this->itemResponse($product->fresh()); } /** diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index eceadd894f9f..f4cd530696a8 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -150,6 +150,16 @@ class Invoice extends BaseModel return $this->belongsTo(Company::class); } + public function project() + { + return $this->belongsTo(Project::class); + } + + public function design() + { + return $this->belongsTo(Design::class); + } + public function user() { return $this->belongsTo(User::class)->withTrashed(); diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 20886313c118..1cdb6d855723 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -125,6 +125,9 @@ class HtmlEngine $data['$terms'] = &$data['$entity.terms']; $data['$view_link'] = ['value' => ''.ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; $data['$view_url'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_invoice')]; + + if($this->entity->project()->exists()) + $data['$project.name'] = ['value' => $this->entity->project->name, 'label' => ctrans('texts.project_name')]; } if ($this->entity_string == 'quote') { From 55b673241bc042cf9fb1bd010a5b7fe698343a21 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 23 Feb 2021 12:17:09 +1100 Subject: [PATCH 3/4] Fixes for fillable properties --- app/Models/Credit.php | 15 +++++++++++---- app/Models/Quote.php | 12 ++++++++++-- app/Utils/HtmlEngine.php | 3 +++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 71a0c0085743..8f942d0ea15b 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -41,14 +41,11 @@ class Credit extends BaseModel protected $presenter = CreditPresenter::class; protected $fillable = [ - 'assigned_user_id', - 'project_id', 'number', 'discount', 'po_number', 'date', 'due_date', - 'partial_due_date', 'terms', 'public_notes', 'private_notes', @@ -59,8 +56,9 @@ class Credit extends BaseModel 'tax_name3', 'tax_rate3', 'is_amount_discount', - 'footer', 'partial', + 'partial_due_date', + 'project_id', 'custom_value1', 'custom_value2', 'custom_value3', @@ -68,7 +66,16 @@ class Credit extends BaseModel 'line_items', 'client_id', 'footer', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_surcharge_tax1', + 'custom_surcharge_tax2', + 'custom_surcharge_tax3', + 'custom_surcharge_tax4', 'design_id', + 'assigned_user_id', 'exchange_rate', ]; diff --git a/app/Models/Quote.php b/app/Models/Quote.php index b02b0f99f7da..d23451290ffd 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -42,7 +42,6 @@ class Quote extends BaseModel protected $touches = []; protected $fillable = [ - 'assigned_user_id', 'number', 'discount', 'po_number', @@ -51,7 +50,6 @@ class Quote extends BaseModel 'terms', 'public_notes', 'private_notes', - 'project_id', 'tax_name1', 'tax_rate1', 'tax_name2', @@ -61,6 +59,7 @@ class Quote extends BaseModel 'is_amount_discount', 'partial', 'partial_due_date', + 'project_id', 'custom_value1', 'custom_value2', 'custom_value3', @@ -68,7 +67,16 @@ class Quote extends BaseModel 'line_items', 'client_id', 'footer', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_surcharge_tax1', + 'custom_surcharge_tax2', + 'custom_surcharge_tax3', + 'custom_surcharge_tax4', 'design_id', + 'assigned_user_id', 'exchange_rate', ]; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 1cdb6d855723..3710d25412e6 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -157,8 +157,11 @@ class HtmlEngine if ($this->entity->partial > 0) { $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')]; + $data['$balance_due_raw'] = ['value' => $this->entity->partial, 'label' => ctrans('texts.partial_due')]; } else { $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')]; + $data['$balance_due_raw'] = ['value' => $this->entity->balance, 'label' => ctrans('texts.balance_due')]; + } $data['$quote.balance_due'] = $data['$balance_due']; From c7cb299d1c07c96c5495224588b391fd1a07c4a9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 23 Feb 2021 12:17:46 +1100 Subject: [PATCH 4/4] Fixes for fillable properties --- app/Models/RecurringInvoice.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index d824ef420f8d..42ece6503403 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -96,6 +96,17 @@ class RecurringInvoice extends BaseModel 'auto_bill', 'auto_bill_enabled', 'design_id', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_surcharge_tax1', + 'custom_surcharge_tax2', + 'custom_surcharge_tax3', + 'custom_surcharge_tax4', + 'design_id', + 'assigned_user_id', + 'exchange_rate', ]; protected $casts = [