From 3d9bb490e332e6f74998bc011c9b9d74d756eb68 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 31 May 2022 21:17:18 +1000 Subject: [PATCH 1/5] first pass --- app/Jobs/Inventory/AdjustProductInventory.php | 95 +++++++++++++++++++ app/Models/Company.php | 3 + app/Models/Product.php | 2 + app/Services/Invoice/InvoiceService.php | 9 ++ ..._31_101504_inventory_management_schema.php | 43 +++++++++ 5 files changed, 152 insertions(+) create mode 100644 app/Jobs/Inventory/AdjustProductInventory.php create mode 100644 database/migrations/2022_05_31_101504_inventory_management_schema.php diff --git a/app/Jobs/Inventory/AdjustProductInventory.php b/app/Jobs/Inventory/AdjustProductInventory.php new file mode 100644 index 0000000000..60ebdf1215 --- /dev/null +++ b/app/Jobs/Inventory/AdjustProductInventory.php @@ -0,0 +1,95 @@ +company = $company; + $this->invoice = $invoice; + $this->old_invoice = $old_invoice; + } + + /** + * Execute the job. + * + * + * @return false + */ + public function handle() + { + MultiDB::setDb($this->company->db); + + if(count($this->old_invoice) > 0) + return $this->existingInventoryAdjustment(); + + return $this->newInventoryAdjustment(); + + } + + private function newInventoryAdjustment() + { + + $line_items = $this->invoice->line_items; + + foreach($line_items as $item) + { + + $p = Product::where('product_key', $item->product_key)->where('company_id', $this->company->id)->where('in_stock_quantity', '>', 0)->first(); + $p->in_stock_quantity -= $item->quantity; + $p->save(); + + //check threshols and notify user + + if($p->stock_notification_threshold && $p->in_stock_quantity <= $p->stock_notification_threshold) + $this->notifyStockLevels($p, 'product'); + elseif($this->company->stock_notification_threshold && $p->in_stock_quantity <= $this->company->stock_notification_threshold){ + $this->notifyStocklevels($p, 'company'); + } + } + + } + + private function existingInventoryAdjustment() + { + + } + + private function notifyStocklevels(Product $product, string $notification_level) + { + + } + +} diff --git a/app/Models/Company.php b/app/Models/Company.php index 8a08e6f6bb..63392d8e06 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -103,6 +103,9 @@ class Company extends BaseModel 'markdown_email_enabled', 'stop_on_unpaid_recurring', 'use_quote_terms_on_conversion', + 'enable_applying_payments', + 'track_inventory', + 'inventory_notification_threshold', ]; protected $hidden = [ diff --git a/app/Models/Product.php b/app/Models/Product.php index 44ba4c668e..0988e54bcd 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -36,6 +36,8 @@ class Product extends BaseModel 'tax_rate1', 'tax_rate2', 'tax_rate3', + 'in_stock_quantity', + 'stock_notification_threshold', ]; protected $touches = []; diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index fdb69920ea..df74ee4fb7 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -13,6 +13,7 @@ namespace App\Services\Invoice; use App\Events\Invoice\InvoiceWasArchived; use App\Jobs\Entity\CreateEntityPdf; +use App\Jobs\Inventory\AdjustProductInventory; use App\Jobs\Invoice\InvoiceWorkflowSettings; use App\Jobs\Util\UnlinkFile; use App\Libraries\Currency\Conversion\CurrencyApi; @@ -564,6 +565,14 @@ class InvoiceService return $this; } + public function adjustInventory() + { + if($this->invoice->company->track_inventory) + AdjustProductInventory::dispatch($this->invoice->company, $this->invoice, null); + + return $this; + } + /** * Saves the invoice. * @return Invoice object diff --git a/database/migrations/2022_05_31_101504_inventory_management_schema.php b/database/migrations/2022_05_31_101504_inventory_management_schema.php new file mode 100644 index 0000000000..ae88786331 --- /dev/null +++ b/database/migrations/2022_05_31_101504_inventory_management_schema.php @@ -0,0 +1,43 @@ +boolean('enable_applying_payments')->default(0); + $table->boolean('track_inventory')->default(0); + $table->integer('inventory_notification_threshold')->nullable(); + + }); + + Schema::table('products', function (Blueprint $table){ + $table->integer('in_stock_quantity')->nullable(); + $table->integer('stock_notification_threshold')->nullable(); + }); + + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} + From 849a3f6b7ced31f37ece93f193a22a3e7ea9e88a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 3 Jun 2022 20:50:19 +1000 Subject: [PATCH 2/5] Adjust schema for inventory management --- app/Models/Company.php | 1 + app/Models/Product.php | 1 + app/Transformers/CompanyTransformer.php | 4 ++++ app/Transformers/ProductTransformer.php | 3 +++ .../2022_05_31_101504_inventory_management_schema.php | 9 +++++---- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Models/Company.php b/app/Models/Company.php index 63392d8e06..4c02942c85 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -106,6 +106,7 @@ class Company extends BaseModel 'enable_applying_payments', 'track_inventory', 'inventory_notification_threshold', + 'stock_notification' ]; protected $hidden = [ diff --git a/app/Models/Product.php b/app/Models/Product.php index 0988e54bcd..129a0fae19 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -38,6 +38,7 @@ class Product extends BaseModel 'tax_rate3', 'in_stock_quantity', 'stock_notification_threshold', + 'stock_notification', ]; protected $touches = []; diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 5de5a837e8..e1a9ee0d13 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -170,6 +170,10 @@ class CompanyTransformer extends EntityTransformer 'markdown_email_enabled' => (bool) $company->markdown_email_enabled, 'stop_on_unpaid_recurring' => (bool) $company->stop_on_unpaid_recurring, 'use_quote_terms_on_conversion' => (bool) $company->use_quote_terms_on_conversion, + 'stock_notification' => (bool) $company->stock_notification, + 'inventory_notification_threshold' => (int) $company->inventory_notification_threshold, + 'track_inventory' => (bool) $company->track_inventory, + 'enable_applying_payments' => (bool) $company->enable_applying_payments, ]; } diff --git a/app/Transformers/ProductTransformer.php b/app/Transformers/ProductTransformer.php index a7ce6c3dc7..28408ae2b2 100644 --- a/app/Transformers/ProductTransformer.php +++ b/app/Transformers/ProductTransformer.php @@ -90,6 +90,9 @@ class ProductTransformer extends EntityTransformer 'custom_value3' => $product->custom_value3 ?: '', 'custom_value4' => $product->custom_value4 ?: '', 'is_deleted' => (bool) $product->is_deleted, + 'in_stock_quantity' => (int) $product->in_stock_quantity ?: 0, + 'stock_notification' => (bool) $product->stock_notification, + 'stock_notification_threshold' => (bool) $product->stock_notification_threshold, ]; } } diff --git a/database/migrations/2022_05_31_101504_inventory_management_schema.php b/database/migrations/2022_05_31_101504_inventory_management_schema.php index ae88786331..783c7a8a40 100644 --- a/database/migrations/2022_05_31_101504_inventory_management_schema.php +++ b/database/migrations/2022_05_31_101504_inventory_management_schema.php @@ -18,13 +18,14 @@ class InventoryManagementSchema extends Migration Schema::table('companies', function (Blueprint $table) { $table->boolean('enable_applying_payments')->default(0); $table->boolean('track_inventory')->default(0); - $table->integer('inventory_notification_threshold')->nullable(); - + $table->integer('inventory_notification_threshold')->default(0); + $table->boolean('stock_notification')->default(1); }); Schema::table('products', function (Blueprint $table){ - $table->integer('in_stock_quantity')->nullable(); - $table->integer('stock_notification_threshold')->nullable(); + $table->integer('in_stock_quantity')->default(0); + $table->boolean('stock_notification')->default(1); + $table->integer('stock_notification_threshold')->default(0); }); From ec7f0117fce7a81975913fa095d9c3f70c04e76e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 4 Jun 2022 08:48:52 +1000 Subject: [PATCH 3/5] Fixes for product transformer --- app/Transformers/ProductTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Transformers/ProductTransformer.php b/app/Transformers/ProductTransformer.php index 28408ae2b2..1010f00ce5 100644 --- a/app/Transformers/ProductTransformer.php +++ b/app/Transformers/ProductTransformer.php @@ -92,7 +92,7 @@ class ProductTransformer extends EntityTransformer 'is_deleted' => (bool) $product->is_deleted, 'in_stock_quantity' => (int) $product->in_stock_quantity ?: 0, 'stock_notification' => (bool) $product->stock_notification, - 'stock_notification_threshold' => (bool) $product->stock_notification_threshold, + 'stock_notification_threshold' => (int) $product->stock_notification_threshold, ]; } } From 4d3c739499e58e39c7b587a1f3b182b704e51189 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 4 Jun 2022 11:26:31 +1000 Subject: [PATCH 4/5] FIxes for email template logo size --- resources/views/email/template/admin.blade.php | 2 +- resources/views/email/template/client.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/email/template/admin.blade.php b/resources/views/email/template/admin.blade.php index 1012e51086..b8f76ee348 100644 --- a/resources/views/email/template/admin.blade.php +++ b/resources/views/email/template/admin.blade.php @@ -125,7 +125,7 @@
- + diff --git a/resources/views/email/template/client.blade.php b/resources/views/email/template/client.blade.php index 4288ead250..7265d4a141 100644 --- a/resources/views/email/template/client.blade.php +++ b/resources/views/email/template/client.blade.php @@ -102,7 +102,7 @@
- + From 3f2dfb4a6994f737e9d54a1c2f003dddb3c9aae6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 4 Jun 2022 11:30:32 +1000 Subject: [PATCH 5/5] v5.3.96 --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index b4869124b9..01f861555b 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.3.95 \ No newline at end of file +5.3.96 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index fc0d8346be..4605e82a3e 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.3.95', - 'app_tag' => '5.3.95', + 'app_version' => '5.3.96', + 'app_tag' => '5.3.96', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),