mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 21:52:35 +01:00
commit
f6330f9757
@ -1 +1 @@
|
||||
5.3.95
|
||||
5.3.96
|
95
app/Jobs/Inventory/AdjustProductInventory.php
Normal file
95
app/Jobs/Inventory/AdjustProductInventory.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Jobs\Inventory;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Product;
|
||||
use App\Utils\Traits\NumberFormatter;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
//todo - ensure we are MultiDB Aware in dispatched jobs
|
||||
|
||||
class AdjustProductInventory implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public Company $company;
|
||||
|
||||
public Invoice $invoice;
|
||||
|
||||
public array $old_invoice;
|
||||
|
||||
public function __construct(Company $company, Invoice $invoice, array $old_invoice = [])
|
||||
{
|
||||
|
||||
$this->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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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 = [
|
||||
|
@ -36,6 +36,9 @@ class Product extends BaseModel
|
||||
'tax_rate1',
|
||||
'tax_rate2',
|
||||
'tax_rate3',
|
||||
'in_stock_quantity',
|
||||
'stock_notification_threshold',
|
||||
'stock_notification',
|
||||
];
|
||||
|
||||
protected $touches = [];
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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', ''),
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class InventoryManagementSchema extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
|
||||
Schema::table('companies', function (Blueprint $table) {
|
||||
$table->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()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@
|
||||
<img src="{{ $logo ?? '' }}" alt="" width="155" border="0" align="middle" style="display:block;" />
|
||||
<div style="mso-hide:all;">
|
||||
<![endif]-->
|
||||
<img class="logo-light" src="{{ $logo ?? '' }}" alt="" style="margin-top: 20px; max-width: 155px; display: block; margin-left: auto; margin-right: auto;"/>
|
||||
<img class="logo-light" src="{{ $logo ?? '' }}" alt="" style="margin-top: 10px; max-width: 570px; display: block; margin-left: auto; margin-right: auto;"/>
|
||||
<!--[if gte mso 9]>
|
||||
</div>
|
||||
<![endif]-->
|
||||
|
@ -102,7 +102,7 @@
|
||||
<img src="{{ $logo ?? '' }}" alt="" width="400" border="0" align="middle" style="display:block;" />
|
||||
<div style="mso-hide:all;">
|
||||
<![endif]-->
|
||||
<img src="{{ $logo ?? '' }}" alt="" style="margin-top: 40px; display: block; margin-left: auto; margin-right: auto;"/>
|
||||
<img src="{{ $logo ?? '' }}" alt="" style="margin-top: 40px; max-width: 155px; display: block; margin-left: auto; margin-right: auto;"/>
|
||||
<!--[if gte mso 9]>
|
||||
</div>
|
||||
<![endif]-->
|
||||
|
Loading…
Reference in New Issue
Block a user