Update product request

This commit is contained in:
David Bomba 2022-06-09 10:20:18 +10:00
parent f92070e3be
commit aa832e1d24
4 changed files with 27 additions and 35 deletions

View File

@ -38,10 +38,13 @@ class StoreProductRequest extends Request
$rules['documents'] = 'file|mimes:png,ai,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000'; $rules['documents'] = 'file|mimes:png,ai,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
} }
$rules['cost'] = 'numeric'; $rules['cost'] = 'sometimes|numeric';
$rules['price'] = 'numeric'; $rules['price'] = 'sometimes|numeric';
$rules['quantity'] = 'numeric'; $rules['quantity'] = 'sometimes|numeric';
$rules['in_stock_quantity'] = 'sometimes|numeric';
$rules['stock_notification_threshold'] = 'sometimes|numeric';
$rules['stock_notification'] = 'sometimes|bool';
return $rules; return $rules;
} }

View File

@ -44,6 +44,9 @@ class UpdateProductRequest extends Request
$rules['cost'] = 'numeric'; $rules['cost'] = 'numeric';
$rules['price'] = 'numeric'; $rules['price'] = 'numeric';
$rules['quantity'] = 'numeric'; $rules['quantity'] = 'numeric';
$rules['in_stock_quantity'] = 'sometimes|numeric';
$rules['stock_notification_threshold'] = 'sometimes|numeric';
$rules['stock_notification'] = 'sometimes|bool';
return $rules; return $rules;
} }
@ -60,6 +63,13 @@ class UpdateProductRequest extends Request
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']); $input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
} }
if(array_key_exists('in_stock_quantity', $input) && request()->has('update_in_stock_quantity') && request()->input('update_in_stock_quantity') == 'true'){
}
elseif(array_key_exists('in_stock_quantity', $input)){
unset($input['in_stock_quantity']);
}
$this->replace($input); $this->replace($input);
} }
} }

View File

@ -54,8 +54,6 @@ class AdjustProductInventory implements ShouldQueue
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
nlog("old invoice count = " . count($this->old_invoice));
if(count($this->old_invoice) > 0) if(count($this->old_invoice) > 0)
$this->existingInventoryAdjustment(); $this->existingInventoryAdjustment();
@ -74,8 +72,6 @@ nlog("old invoice count = " . count($this->old_invoice));
$line_items = $this->invoice->line_items; $line_items = $this->invoice->line_items;
nlog($line_items);
foreach($line_items as $item) foreach($line_items as $item)
{ {
@ -84,15 +80,9 @@ nlog($line_items);
if(!$p) if(!$p)
continue; continue;
nlog("subtracting back " . $item->quantity);
$p->in_stock_quantity -= $item->quantity; $p->in_stock_quantity -= $item->quantity;
$p->saveQuietly(); $p->saveQuietly();
nlog($p->toArray());
if($p->stock_notification_threshold && $p->in_stock_quantity <= $p->stock_notification_threshold) if($p->stock_notification_threshold && $p->in_stock_quantity <= $p->stock_notification_threshold)
$this->notifyStockLevels($p, 'product'); $this->notifyStockLevels($p, 'product');
elseif($this->company->stock_notification_threshold && $p->in_stock_quantity <= $this->company->stock_notification_threshold) elseif($this->company->stock_notification_threshold && $p->in_stock_quantity <= $this->company->stock_notification_threshold)
@ -112,11 +102,9 @@ nlog($p->toArray());
if(!$p) if(!$p)
continue; continue;
nlog("adding back " . $item->quantity);
$p->in_stock_quantity += $item->quantity; $p->in_stock_quantity += $item->quantity;
$p->saveQuietly(); $p->saveQuietly();
nlog($p->toArray());
} }
} }

View File

@ -50,8 +50,7 @@ class UpdateReminder extends AbstractService
$date_collection = collect(); $date_collection = collect();
if (is_null($this->invoice->reminder1_sent) && if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'after_invoice_date' && $this->settings->schedule_reminder1 == 'after_invoice_date') {
$this->settings->enable_reminder1) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -59,8 +58,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder1_sent) && if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'before_due_date' && $this->settings->schedule_reminder1 == 'before_due_date') {
$this->settings->enable_reminder1) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder1)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -68,8 +66,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder1_sent) && if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'after_due_date' && $this->settings->schedule_reminder1 == 'after_due_date') {
$this->settings->enable_reminder1) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -77,8 +74,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder2_sent) && if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'after_invoice_date' && $this->settings->schedule_reminder2 == 'after_invoice_date') {
$this->settings->enable_reminder2) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -86,8 +82,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder2_sent) && if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'before_due_date' && $this->settings->schedule_reminder2 == 'before_due_date') {
$this->settings->enable_reminder2) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder2)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -95,8 +90,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder2_sent) && if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'after_due_date' && $this->settings->schedule_reminder2 == 'after_due_date') {
$this->settings->enable_reminder2) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -104,8 +98,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder3_sent) && if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'after_invoice_date' && $this->settings->schedule_reminder3 == 'after_invoice_date') {
$this->settings->enable_reminder3) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -113,8 +106,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder3_sent) && if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'before_due_date' && $this->settings->schedule_reminder3 == 'before_due_date') {
$this->settings->enable_reminder3) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder3)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -122,8 +114,7 @@ class UpdateReminder extends AbstractService
} }
if (is_null($this->invoice->reminder3_sent) && if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'after_due_date' && $this->settings->schedule_reminder3 == 'after_due_date') {
$this->settings->enable_reminder3) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset); $reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))