mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
v5.0.0 update
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ExpenseRequest extends FormRequest
|
||||
@ -23,22 +24,58 @@ class ExpenseRequest extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
|
||||
$rules = [
|
||||
'expense_date' => [
|
||||
'required',
|
||||
],
|
||||
'expense_category_id' => [
|
||||
'required',
|
||||
],
|
||||
'exchange_rate' => [
|
||||
'nullable'
|
||||
],
|
||||
'payment_method_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'amount' => [
|
||||
'required',
|
||||
],
|
||||
'user_id' => [
|
||||
'customer_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'notes' => [
|
||||
'nullable',
|
||||
],
|
||||
'currency_id' => [
|
||||
'required'
|
||||
],
|
||||
];
|
||||
|
||||
if ($companyCurrency !== $this->currency_id) {
|
||||
$rules['exchange_rate'] = [
|
||||
'required',
|
||||
];
|
||||
};
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getExpensePayload()
|
||||
{
|
||||
$company_currency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
$current_currency = $this->currency_id;
|
||||
$exchange_rate = $company_currency != $current_currency ? $this->exchange_rate : 1;
|
||||
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'company_id' => $this->header('company'),
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_amount' => $this->amount * $exchange_rate,
|
||||
'currency_id' => $current_currency
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user