From 5496cefdb8f224d17294f2fcfba9462976cacba1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 6 Jul 2023 12:34:35 +1000 Subject: [PATCH 1/4] Fixes for releases --- .github/workflows/release.yml | 1 - app/Export/CSV/InvoiceItemExport.php | 43 +++++++++++++++++----------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 727e9f442ed1..a120b10c5309 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,7 +47,6 @@ jobs: npm i npm run build cp -r dist/react/* ../public/react - mkdir public/tinymce_6.4.2/tinymce/js/ cp -r node_modules/tinymce ../public/tinymce_6.4.2/tinymce/js/ cd .. rm -rf ui diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index fe2533d79edf..f7e764addee4 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -30,6 +30,8 @@ class InvoiceItemExport extends BaseExport public Writer $csv; + private bool $force_keys = false; + public array $entity_keys = [ 'amount' => 'amount', 'balance' => 'balance', @@ -112,6 +114,7 @@ class InvoiceItemExport extends BaseExport $this->csv = Writer::createFromString(); if (count($this->input['report_keys']) == 0) { + $this->force_keys = true; $this->input['report_keys'] = array_values($this->entity_keys); } @@ -153,12 +156,10 @@ class InvoiceItemExport extends BaseExport } } } -nlog("item array"); -nlog($item_array); - + $entity = []; - foreach (array_values($this->input['report_keys']) as $key) { + foreach (array_values($this->input['report_keys']) as $key) { //create an array of report keys only $keyval = array_search($key, $this->entity_keys); if (array_key_exists($key, $transformed_items)) { @@ -168,9 +169,6 @@ nlog($item_array); } } -nlog("entity"); -nlog($entity); - $transformed_items = array_merge($transformed_invoice, $item_array); $entity = $this->decorateAdvancedFields($invoice, $transformed_items); @@ -187,13 +185,27 @@ nlog($entity); foreach (array_values($this->input['report_keys']) as $key) { $keyval = array_search($key, $this->entity_keys); + if(!$keyval) { + $keyval = array_search(str_replace("invoice.", "", $key), $this->entity_keys) ?? $key; + } + + if(!$keyval) { + $keyval = $key; + } +nlog($keyval); + if (array_key_exists($key, $transformed_invoice)) { $entity[$keyval] = $transformed_invoice[$key]; - } else { - $entity[$keyval] = ""; + } elseif (array_key_exists($keyval, $transformed_invoice)) { + $entity[$keyval] = $transformed_invoice[$keyval]; + } + else { + $entity[$keyval] = $this->resolveKey($keyval, $invoice, $this->invoice_transformer); } } + nlog($entity); + return $this->decorateAdvancedFields($invoice, $entity); } @@ -203,13 +215,12 @@ nlog($entity); $entity['currency'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code; } - // if(in_array('client_id', $this->input['report_keys'])) - $entity['client'] = $invoice->client->present()->name(); - $entity['client_id_number'] = $invoice->client->id_number; - $entity['client_number'] = $invoice->client->number; - - // if(in_array('status_id', $this->input['report_keys'])) - $entity['status'] = $invoice->stringStatus($invoice->status_id); + if($this->force_keys) { + $entity['client'] = $invoice->client->present()->name(); + $entity['client_id_number'] = $invoice->client->id_number; + $entity['client_number'] = $invoice->client->number; + $entity['status'] = $invoice->stringStatus($invoice->status_id); + } return $entity; } From 7dab130ecd6dbe903da9fbf0e0827e8effa59d68 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 6 Jul 2023 12:50:41 +1000 Subject: [PATCH 2/4] Fixes for release file --- .github/workflows/release.yml | 1 + app/Export/CSV/InvoiceItemExport.php | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a120b10c5309..eee6165df82b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,6 +47,7 @@ jobs: npm i npm run build cp -r dist/react/* ../public/react + mkdir -p public/tinymce_6.4.2/tinymce/js/ cp -r node_modules/tinymce ../public/tinymce_6.4.2/tinymce/js/ cd .. rm -rf ui diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index f7e764addee4..420bd023e42d 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -192,7 +192,6 @@ class InvoiceItemExport extends BaseExport if(!$keyval) { $keyval = $key; } -nlog($keyval); if (array_key_exists($key, $transformed_invoice)) { $entity[$keyval] = $transformed_invoice[$key]; @@ -204,8 +203,6 @@ nlog($keyval); } } - nlog($entity); - return $this->decorateAdvancedFields($invoice, $entity); } From 7526f347a91677f3773c40f83ebefda76e14af93 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 6 Jul 2023 13:11:35 +1000 Subject: [PATCH 3/4] Fixes for releases --- .github/workflows/release.yml | 2 +- app/Export/CSV/InvoiceItemExport.php | 18 +++++++++++++----- lang/en/texts.php | 2 +- phpstan.neon | 6 +++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eee6165df82b..462119a834ab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,7 +48,7 @@ jobs: npm run build cp -r dist/react/* ../public/react mkdir -p public/tinymce_6.4.2/tinymce/js/ - cp -r node_modules/tinymce ../public/tinymce_6.4.2/tinymce/js/ + cp -r node_modules/tinymce public/tinymce_6.4.2/tinymce/js/ cd .. rm -rf ui php artisan ninja:react diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index 420bd023e42d..83181268c152 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -69,9 +69,9 @@ class InvoiceItemExport extends BaseExport 'total_taxes' => 'total_taxes', 'currency' => 'currency_id', 'quantity' => 'item.quantity', - 'unit_cost' => 'item.cost', + 'cost' => 'item.cost', 'product_key' => 'item.product_key', - 'cost' => 'item.product_cost', + 'buy_price' => 'item.product_cost', 'notes' => 'item.notes', 'discount' => 'item.discount', 'is_amount_discount' => 'item.is_amount_discount', @@ -87,6 +87,8 @@ class InvoiceItemExport extends BaseExport 'invoice2' => 'item.custom_value2', 'invoice3' => 'item.custom_value3', 'invoice4' => 'item.custom_value4', + 'tax_category' => 'item.tax_id', + 'type' => 'item.type_id', ]; private array $decorate_keys = [ @@ -149,14 +151,18 @@ class InvoiceItemExport extends BaseExport if (str_contains($key, "item.")) { $key = str_replace("item.", "", $key); + $keyval = str_replace("custom_value", "invoice", $key); + if (property_exists($item, $key)) { - $item_array[$key] = $item->{$key}; + $item_array[$keyval] = $item->{$key}; } else { - $item_array[$key] = ''; + $item_array[$keyval] = ''; } } } - + nlog("item array"); + nlog($item_array); + $entity = []; foreach (array_values($this->input['report_keys']) as $key) { //create an array of report keys only @@ -168,6 +174,8 @@ class InvoiceItemExport extends BaseExport $entity[$keyval] = ""; } } + nlog("entity"); + nlog($entity); $transformed_items = array_merge($transformed_invoice, $item_array); $entity = $this->decorateAdvancedFields($invoice, $transformed_items); diff --git a/lang/en/texts.php b/lang/en/texts.php index 98e650a94ef5..d447137b99c9 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5113,7 +5113,7 @@ $LANG = array( 'item_tax_rate1' => 'Item Tax Rate 1', 'item_tax_rate2' => 'Item Tax Rate 2', 'item_tax_rate3' => 'Item Tax Rate 3', - + 'buy_price' => 'Buy Price', ); diff --git a/phpstan.neon b/phpstan.neon index 859693d32cae..b3411ce79b40 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,9 +4,9 @@ includes: parameters: treatPhpDocTypesAsCertain: false parallel: - jobSize: 20 - maximumNumberOfProcesses: 2 - processTimeout: 300.0 + jobSize: 5 + maximumNumberOfProcesses: 8 + processTimeout: 600.0 ignoreErrors: - '#Call to an undefined method .*badMethod\(\)#' - '#Call to an undefined method Illuminate\Database\Eloquent\Builder::exclude#' From fe4e3720340bc0b966f1736825a1441608c90e9b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 6 Jul 2023 13:53:24 +1000 Subject: [PATCH 4/4] Updates for releases --- VERSION.txt | 2 +- app/Export/CSV/InvoiceItemExport.php | 25 ++++++++++++++------ app/Models/Invoice.php | 34 ++++++++++++++++++++++++++++ config/ninja.php | 4 ++-- phpstan.neon | 4 ++-- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 3b739526c772..accefefe0c32 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.6.9 \ No newline at end of file +5.6.10 \ No newline at end of file diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index 83181268c152..be3b9e7376f4 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -145,13 +145,18 @@ class InvoiceItemExport extends BaseExport $transformed_items = []; foreach ($invoice->line_items as $item) { - $item_array = []; - + $item_array = []; foreach (array_values($this->input['report_keys']) as $key) { //items iterator produces item array + if (str_contains($key, "item.")) { + $key = str_replace("item.", "", $key); - $keyval = str_replace("custom_value", "invoice", $key); + if($key == 'type_id') + $keyval = 'type'; + + if($key == 'tax_id') + $keyval = 'tax_category'; if (property_exists($item, $key)) { $item_array[$keyval] = $item->{$key}; @@ -160,8 +165,6 @@ class InvoiceItemExport extends BaseExport } } } - nlog("item array"); - nlog($item_array); $entity = []; @@ -174,8 +177,8 @@ class InvoiceItemExport extends BaseExport $entity[$keyval] = ""; } } - nlog("entity"); - nlog($entity); + // nlog("entity"); + // nlog($entity); $transformed_items = array_merge($transformed_invoice, $item_array); $entity = $this->decorateAdvancedFields($invoice, $transformed_items); @@ -220,6 +223,14 @@ class InvoiceItemExport extends BaseExport $entity['currency'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code; } + if(array_key_exists('type', $entity)) { + $entity['type'] = $invoice->typeIdString($entity['type']); + } + + if(array_key_exists('tax_category', $entity)) { + $entity['tax_category'] = $invoice->taxTypeString($entity['tax_category']); + } + if($this->force_keys) { $entity['client'] = $invoice->client->present()->name(); $entity['client_id_number'] = $invoice->client->id_number; diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index f390f21fc507..4c0a19f0862b 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -889,4 +889,38 @@ class Invoice extends BaseModel { return ctrans('texts.invoice'); } + + public function taxTypeString($id) + { + match(intval($id)){ + Product::PRODUCT_TYPE_PHYSICAL => $tax_type = ctrans('texts.physical_goods'), + Product::PRODUCT_TYPE_SERVICE => $tax_type = ctrans('texts.services'), + Product::PRODUCT_TYPE_DIGITAL => $tax_type = ctrans('texts.digital_products'), + Product::PRODUCT_TYPE_SHIPPING => $tax_type = ctrans('texts.shipping'), + Product::PRODUCT_TYPE_EXEMPT => $tax_type = ctrans('texts.tax_exempt'), + Product::PRODUCT_TYPE_REDUCED_TAX => $tax_type = ctrans('texts.reduced_tax'), + Product::PRODUCT_TYPE_OVERRIDE_TAX => $tax_type = ctrans('texts.override_tax'), + Product::PRODUCT_TYPE_ZERO_RATED => $tax_type = ctrans('texts.zero_rated'), + Product::PRODUCT_TYPE_REVERSE_TAX => $tax_type = ctrans('texts.reverse_tax'), + default => $tax_type = ctrans('texts.physical_goods'), + }; + + return $tax_type; + } + + public function typeIdString($id) + { + match($id) { + '1' => $type = ctrans('texts.product'), + '2' => $type = ctrans('texts.service'), + '3' => $type = ctrans('texts.gateway_fees'), + '4' => $type = ctrans('texts.gateway_fees'), + '5' => $type = ctrans('texts.late_fees'), + '6' => $type = ctrans('texts.expense'), + default => $type = ctrans('texts.product'), + }; + + return $type; + + } } diff --git a/config/ninja.php b/config/ninja.php index 13b6b5cdfe37..8ba93f8f8f97 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -15,8 +15,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.6.9', - 'app_tag' => '5.6.9', + 'app_version' => '5.6.10', + 'app_tag' => '5.6.10', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/phpstan.neon b/phpstan.neon index b3411ce79b40..cebc91d3270e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,11 @@ includes: - ./vendor/nunomaduro/larastan/extension.neon - + - phpstan-baseline.neon parameters: treatPhpDocTypesAsCertain: false parallel: jobSize: 5 - maximumNumberOfProcesses: 8 + maximumNumberOfProcesses: 16 processTimeout: 600.0 ignoreErrors: - '#Call to an undefined method .*badMethod\(\)#'