From 13e104c1d959a58a2a2fb985d33b447c9b0f5147 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 29 Oct 2019 22:12:59 +1100 Subject: [PATCH] Fixes for line items (#3028) --- app/Helpers/Invoice/InvoiceItemSum.php | 2 +- app/Helpers/Invoice/InvoiceSum.php | 17 +++++++++-------- app/Helpers/Invoice/InvoiceSumInclusive.php | 16 ++++++++-------- app/Http/Controllers/OpenAPI/InvoiceSchema.php | 4 ++++ .../Requests/Invoice/StoreInvoiceRequest.php | 5 ++--- app/Repositories/InvoiceRepository.php | 1 - app/Transformers/InvoiceTransformer.php | 10 +++++----- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 63d9b20cc6..15c431213f 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -63,7 +63,7 @@ class InvoiceItemSum public function process() { - if(!$this->invoice->line_items || count($this->invoice->line_items) == 0){ + if(!$this->invoice->line_items || !isset($this->invoice->line_items) || count($this->invoice->line_items) == 0){ $this->items = []; return $this; } diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index e169034fe6..85e3103f7d 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -65,6 +65,7 @@ class InvoiceSum public function build() { + $this->calculateLineItems() ->calculateDiscount() ->calculateCustomValues() @@ -99,17 +100,17 @@ class InvoiceSum private function calculateCustomValues() { - $this->total_taxes += $this->valuerTax($this->invoice->custom_value1, $this->invoice->custom_surcharge_taxes1); - $this->total_custom_values += $this->valuer($this->invoice->custom_value1); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1); - $this->total_taxes += $this->valuerTax($this->invoice->custom_value2, $this->invoice->custom_surcharge_taxes2); - $this->total_custom_values += $this->valuer($this->invoice->custom_value2); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2); - $this->total_taxes += $this->valuerTax($this->invoice->custom_value3, $this->invoice->custom_surcharge_taxes3); - $this->total_custom_values += $this->valuer($this->invoice->custom_value3); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3); - $this->total_taxes += $this->valuerTax($this->invoice->custom_value4, $this->invoice->custom_surcharge_taxes4); - $this->total_custom_values += $this->valuer($this->invoice->custom_value4); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4); $this->total += $this->total_custom_values; diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index b2980cb552..7edeb9c112 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -100,17 +100,17 @@ class InvoiceSumInclusive private function calculateCustomValues() { - $this->total_taxes += $this->valuerTax($this->invoice->custom_value1, $this->invoice->custom_surcharge_taxes1); - $this->total_custom_values += $this->valuer($this->invoice->custom_value1); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1); - $this->total_taxes += $this->valuerTax($this->invoice->custom_value2, $this->invoice->custom_surcharge_taxes2); - $this->total_custom_values += $this->valuer($this->invoice->custom_value2); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2); - $this->total_taxes += $this->valuerTax($this->invoice->custom_value3, $this->invoice->custom_surcharge_taxes3); - $this->total_custom_values += $this->valuer($this->invoice->custom_value3); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3); - $this->total_taxes += $this->valuerTax($this->invoice->custom_value4, $this->invoice->custom_surcharge_taxes4); - $this->total_custom_values += $this->valuer($this->invoice->custom_value4); + $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4); + $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4); $this->total += $this->total_custom_values; diff --git a/app/Http/Controllers/OpenAPI/InvoiceSchema.php b/app/Http/Controllers/OpenAPI/InvoiceSchema.php index 4466d75f6e..3e73972ef2 100644 --- a/app/Http/Controllers/OpenAPI/InvoiceSchema.php +++ b/app/Http/Controllers/OpenAPI/InvoiceSchema.php @@ -39,6 +39,10 @@ * @OA\Property(property="last_viewed", type="number", format="integer", example="1434342123", description="Timestamp"), * @OA\Property(property="updated_at", type="number", format="integer", example="1434342123", description="Timestamp"), * @OA\Property(property="archived_at", type="number", format="integer", example="1434342123", description="Timestamp"), + * @OA\Property(property="custom_surcharge1", type="number", format="float", example="10.00", description="First Custom Surcharge"), + * @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"), * ) */ \ No newline at end of file diff --git a/app/Http/Requests/Invoice/StoreInvoiceRequest.php b/app/Http/Requests/Invoice/StoreInvoiceRequest.php index 1e38c982d1..31af5d0aae 100644 --- a/app/Http/Requests/Invoice/StoreInvoiceRequest.php +++ b/app/Http/Requests/Invoice/StoreInvoiceRequest.php @@ -34,7 +34,6 @@ class StoreInvoiceRequest extends Request public function rules() { $this->sanitize(); - return [ 'client_id' => 'required', // 'invoice_type_id' => 'integer', @@ -47,8 +46,8 @@ class StoreInvoiceRequest extends Request $input = $this->all(); $input['client_id'] = $this->decodePrimaryKey($input['client_id']); - $input['line_items'] = isset($input['line_items']) ?: []; - + $input['line_items'] = isset($input['line_items']) ? $input['line_items'] : []; + //$input['line_items'] = json_encode($input['line_items']); $this->replace($input); return $this->all(); diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 68b7a795ac..4161aad020 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -57,7 +57,6 @@ class InvoiceRepository extends BaseRepository $starting_amount = $invoice->amount; $invoice->fill($data); - $invoice->save(); if(isset($data['client_contacts'])) diff --git a/app/Transformers/InvoiceTransformer.php b/app/Transformers/InvoiceTransformer.php index dc7fb96182..b87d221643 100644 --- a/app/Transformers/InvoiceTransformer.php +++ b/app/Transformers/InvoiceTransformer.php @@ -116,12 +116,12 @@ class InvoiceTransformer extends EntityTransformer 'custom_value4' => (string) $invoice->custom_value4 ?: '', 'has_tasks' => (bool) $invoice->has_tasks, 'has_expenses' => (bool) $invoice->has_expenses, - 'custom_surcharge1' => $invoice->custom_surcharge1 ?: '', - 'custom_surcharge2' => $invoice->custom_surcharge2 ?: '', - 'custom_surcharge3' => $invoice->custom_surcharge3 ?: '', - 'custom_surcharge4' => $invoice->custom_surcharge4 ?: '', + 'custom_surcharge1' => (float)$invoice->custom_surcharge1, + 'custom_surcharge2' => (float)$invoice->custom_surcharge2, + 'custom_surcharge3' => (float)$invoice->custom_surcharge3, + 'custom_surcharge4' => (float)$invoice->custom_surcharge4, 'custom_surcharge_taxes' => (bool) $invoice->custom_surcharge_taxes, - 'line_items' => $invoice->line_items ?: '', + 'line_items' => $invoice->line_items ?: (array)[], 'backup' => $invoice->backup ?: '', 'settings' => $invoice->settings ?: '',