2019-04-03 13:34:28 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2023-01-29 09:21:40 +11:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 13:32:07 +10:00
|
|
|
*/
|
2019-04-03 13:34:28 +11:00
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Product;
|
|
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
|
|
|
|
use App\Models\Product;
|
|
|
|
|
|
|
|
|
|
class StoreProductRequest extends Request
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function authorize() : bool
|
|
|
|
|
{
|
|
|
|
|
return auth()->user()->can('create', Product::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
2023-02-27 20:12:59 +11:00
|
|
|
if($this->file('documents') && is_array($this->file('documents')))
|
|
|
|
|
$rules['documents.*'] = $this->file_validation;
|
|
|
|
|
elseif($this->file('documents'))
|
|
|
|
|
$rules['documents'] = $this->file_validation;
|
2020-06-22 21:41:04 +10:00
|
|
|
|
2023-02-27 20:12:59 +11:00
|
|
|
if ($this->file('file') && is_array($this->file('file'))) {
|
|
|
|
|
$rules['file.*'] = $this->file_validation;
|
|
|
|
|
} elseif ($this->file('file')) {
|
|
|
|
|
$rules['file'] = $this->file_validation;
|
2020-06-22 21:41:04 +10:00
|
|
|
}
|
|
|
|
|
|
2022-06-09 10:20:18 +10:00
|
|
|
$rules['cost'] = 'sometimes|numeric';
|
|
|
|
|
$rules['price'] = 'sometimes|numeric';
|
|
|
|
|
$rules['quantity'] = 'sometimes|numeric';
|
|
|
|
|
$rules['in_stock_quantity'] = 'sometimes|numeric';
|
|
|
|
|
$rules['stock_notification_threshold'] = 'sometimes|numeric';
|
|
|
|
|
$rules['stock_notification'] = 'sometimes|bool';
|
2022-06-21 09:57:17 +00:00
|
|
|
|
2020-06-22 21:41:04 +10:00
|
|
|
return $rules;
|
2019-04-03 13:34:28 +11:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 11:55:41 +10:00
|
|
|
public function prepareForValidation()
|
2019-10-04 21:57:33 +10:00
|
|
|
{
|
|
|
|
|
$input = $this->all();
|
|
|
|
|
|
2020-09-06 19:38:10 +10:00
|
|
|
if (! isset($input['quantity']) || $input['quantity'] < 1) {
|
2019-10-04 21:57:33 +10:00
|
|
|
$input['quantity'] = 1;
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|
2019-04-03 13:34:28 +11:00
|
|
|
|
2020-06-26 08:29:24 +10:00
|
|
|
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
|
|
|
|
|
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
|
|
|
|
|
}
|
2020-09-06 19:38:10 +10:00
|
|
|
|
2019-10-04 21:57:33 +10:00
|
|
|
$this->replace($input);
|
|
|
|
|
}
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|