diff --git a/app/Helpers/Invoice/CustomValuer.php b/app/Helpers/Invoice/CustomValuer.php index 067428cb02d4..4d00809fabb9 100644 --- a/app/Helpers/Invoice/CustomValuer.php +++ b/app/Helpers/Invoice/CustomValuer.php @@ -27,7 +27,8 @@ trait CustomValuer public function valuerTax($custom_value, $has_custom_invoice_taxes) { - if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes === true) { + + if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes) { return round($custom_value * ($this->invoice->tax_rate1 / 100), 2) + round($custom_value * ($this->invoice->tax_rate2 / 100), 2) + round($custom_value * ($this->invoice->tax_rate3 / 100), 2); } diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index badd39f055ac..53df2fdb53d6 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -57,8 +57,8 @@ class InvoiceSum { $this->calculateLineItems() ->calculateDiscount() - ->calculateCustomValues() ->calculateInvoiceTaxes() + ->calculateCustomValues() ->setTaxMap() ->calculateTotals() ->calculateBalance() @@ -89,16 +89,17 @@ class InvoiceSum private function calculateCustomValues() { - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1); + + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1); - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2); - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3); - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4); $this->total += $this->total_custom_values; @@ -108,24 +109,25 @@ class InvoiceSum private function calculateInvoiceTaxes() { - if ($this->invoice->tax_rate1 > 0) { + + if (strlen($this->invoice->tax_name1) > 1) { $tax = $this->taxer($this->total, $this->invoice->tax_rate1); $this->total_taxes += $tax; $this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.floatval($this->invoice->tax_rate1).'%', 'total' => $tax]; } - if ($this->invoice->tax_rate2 > 0) { + if (strlen($this->invoice->tax_name2) > 1) { $tax = $this->taxer($this->total, $this->invoice->tax_rate2); $this->total_taxes += $tax; $this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.floatval($this->invoice->tax_rate2).'%', 'total' => $tax]; } - if ($this->invoice->tax_rate3 > 0) { + if (strlen($this->invoice->tax_name3) > 1) { $tax = $this->taxer($this->total, $this->invoice->tax_rate3); $this->total_taxes += $tax; $this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax]; } - + return $this; } @@ -299,7 +301,7 @@ class InvoiceSum } public function getTaxMap() - { + { return $this->tax_map; } diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index a3b77684e4ab..24273b883aee 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -89,16 +89,16 @@ class InvoiceSumInclusive private function calculateCustomValues() { - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1); - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2); - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3); - $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4); $this->total += $this->total_custom_values; diff --git a/app/Http/Controllers/OpenAPI/CreditSchema.php b/app/Http/Controllers/OpenAPI/CreditSchema.php index 9b564145416b..9f7ff64e86a7 100644 --- a/app/Http/Controllers/OpenAPI/CreditSchema.php +++ b/app/Http/Controllers/OpenAPI/CreditSchema.php @@ -49,6 +49,9 @@ * @OA\Property(property="custom_surcharge2", type="number", format="float", example="10.00", description="Second Custom Surcharge"), * @OA\Property(property="custom_surcharge3", type="number", format="float", example="10.00", description="Third Custom Surcharge"), * @OA\Property(property="custom_surcharge4", type="number", format="float", example="10.00", description="Fourth Custom Surcharge"), - * @OA\Property(property="custom_surcharge_taxes", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax1", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax2", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax3", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax4", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), * ) */ diff --git a/app/Http/Controllers/OpenAPI/InvoiceSchema.php b/app/Http/Controllers/OpenAPI/InvoiceSchema.php index e4eda9cd4e3e..4376403c971e 100644 --- a/app/Http/Controllers/OpenAPI/InvoiceSchema.php +++ b/app/Http/Controllers/OpenAPI/InvoiceSchema.php @@ -48,6 +48,9 @@ * @OA\Property(property="custom_surcharge2", type="number", format="float", example="10.00", description="Second Custom Surcharge"), * @OA\Property(property="custom_surcharge3", type="number", format="float", example="10.00", description="Third Custom Surcharge"), * @OA\Property(property="custom_surcharge4", type="number", format="float", example="10.00", description="Fourth Custom Surcharge"), - * @OA\Property(property="custom_surcharge_taxes", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax1", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax2", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax3", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax4", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), * ) */ diff --git a/app/Http/Controllers/OpenAPI/QuoteSchema.php b/app/Http/Controllers/OpenAPI/QuoteSchema.php index 45bf58a6ca8e..5ccbd71f08d8 100644 --- a/app/Http/Controllers/OpenAPI/QuoteSchema.php +++ b/app/Http/Controllers/OpenAPI/QuoteSchema.php @@ -48,6 +48,9 @@ * @OA\Property(property="custom_surcharge2", type="number", format="float", example="10.00", description="Second Custom Surcharge"), * @OA\Property(property="custom_surcharge3", type="number", format="float", example="10.00", description="Third Custom Surcharge"), * @OA\Property(property="custom_surcharge4", type="number", format="float", example="10.00", description="Fourth Custom Surcharge"), - * @OA\Property(property="custom_surcharge_taxes", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax1", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax2", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax3", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), + * @OA\Property(property="custom_surcharge_tax4", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), * ) */ diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 8b5d33e6e6b8..eceadd894f9f 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -102,6 +102,10 @@ class Invoice extends BaseModel 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', + 'custom_surcharge_tax1' => 'bool', + 'custom_surcharge_tax2' => 'bool', + 'custom_surcharge_tax3' => 'bool', + 'custom_surcharge_tax4' => 'bool', ]; protected $with = []; diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 033c25dc0f14..937556290fb5 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -199,6 +199,12 @@ class BaseRepository unset($tmp_data['client_contacts']); $model->fill($tmp_data); + + $model->custom_surcharge_tax1 = $client->company->custom_surcharge_taxes1; + $model->custom_surcharge_tax2 = $client->company->custom_surcharge_taxes2; + $model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3; + $model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4; + $model->save(); /* Model now persisted, now lets do some child tasks */ diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index bd4b0cd952a1..20886313c118 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -287,10 +287,10 @@ class HtmlEngine $data['$company3'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company3', $this->settings->custom_value3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company3')]; $data['$company4'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company4', $this->settings->custom_value4, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company4')]; - $data['$custom_surcharge1'] = ['value' => $this->entity->custom_surcharge1 ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'custom_surcharge1')]; - $data['$custom_surcharge2'] = ['value' => $this->entity->custom_surcharge2 ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'custom_surcharge2')]; - $data['$custom_surcharge3'] = ['value' => $this->entity->custom_surcharge3 ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'custom_surcharge3')]; - $data['$custom_surcharge4'] = ['value' => $this->entity->custom_surcharge4 ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'custom_surcharge4')]; + $data['$custom_surcharge1'] = ['value' => Number::formatMoney($this->entity->custom_surcharge1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'surcharge1')]; + $data['$custom_surcharge2'] = ['value' => Number::formatMoney($this->entity->custom_surcharge2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'surcharge2')]; + $data['$custom_surcharge3'] = ['value' => Number::formatMoney($this->entity->custom_surcharge3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'surcharge3')]; + $data['$custom_surcharge4'] = ['value' => Number::formatMoney($this->entity->custom_surcharge4, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'surcharge4')]; $data['$product.item'] = ['value' => '', 'label' => ctrans('texts.item')]; $data['$product.date'] = ['value' => '', 'label' => ctrans('texts.date')];