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/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..4c02942c85 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -103,6 +103,10 @@ class Company extends BaseModel 'markdown_email_enabled', 'stop_on_unpaid_recurring', 'use_quote_terms_on_conversion', + '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 44ba4c668e..129a0fae19 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -36,6 +36,9 @@ class Product extends BaseModel 'tax_rate1', 'tax_rate2', 'tax_rate3', + 'in_stock_quantity', + 'stock_notification_threshold', + 'stock_notification', ]; 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/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..1010f00ce5 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' => (int) $product->stock_notification_threshold, ]; } } 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', ''), 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..783c7a8a40 --- /dev/null +++ b/database/migrations/2022_05_31_101504_inventory_management_schema.php @@ -0,0 +1,44 @@ +boolean('enable_applying_payments')->default(0); + $table->boolean('track_inventory')->default(0); + $table->integer('inventory_notification_threshold')->default(0); + $table->boolean('stock_notification')->default(1); + }); + + Schema::table('products', function (Blueprint $table){ + $table->integer('in_stock_quantity')->default(0); + $table->boolean('stock_notification')->default(1); + $table->integer('stock_notification_threshold')->default(0); + }); + + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} + 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 @@
- +