mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 05:14:37 -04:00
Catch up currency_id which is not passed
This commit is contained in:
parent
08f13cba2a
commit
1c906fcb52
@ -33,11 +33,18 @@ class StorePaymentRequest extends Request
|
|||||||
*/
|
*/
|
||||||
public function authorize() : bool
|
public function authorize() : bool
|
||||||
{
|
{
|
||||||
return auth()->user()->can('create', Payment::class);
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
return $user->can('create', Payment::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepareForValidation()
|
public function prepareForValidation()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
$input = $this->all();
|
$input = $this->all();
|
||||||
|
|
||||||
$invoices_total = 0;
|
$invoices_total = 0;
|
||||||
@ -86,7 +93,7 @@ class StorePaymentRequest extends Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($input['date'])) {
|
if (! isset($input['date'])) {
|
||||||
$input['date'] = now()->addSeconds(auth()->user()->company()->timezone()->utc_offset)->format('Y-m-d');
|
$input['date'] = now()->addSeconds($user->company()->timezone()->utc_offset)->format('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
@ -94,10 +101,13 @@ class StorePaymentRequest extends Request
|
|||||||
|
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'amount' => ['numeric', 'bail', new PaymentAmountsBalanceRule(), new ValidCreditsPresentRule($this->all())],
|
'amount' => ['numeric', 'bail', new PaymentAmountsBalanceRule(), new ValidCreditsPresentRule($this->all())],
|
||||||
// 'client_id' => 'bail|required|exists:clients,id',
|
// 'client_id' => 'bail|required|exists:clients,id',
|
||||||
'client_id' => 'bail|required|exists:clients,id,company_id,'.auth()->user()->company()->id.',is_deleted,0',
|
'client_id' => 'bail|required|exists:clients,id,company_id,'.$user->company()->id.',is_deleted,0',
|
||||||
'invoices.*.invoice_id' => 'bail|required|distinct|exists:invoices,id',
|
'invoices.*.invoice_id' => 'bail|required|distinct|exists:invoices,id',
|
||||||
'invoices.*.amount' => 'bail|required',
|
'invoices.*.amount' => 'bail|required',
|
||||||
'invoices.*.invoice_id' => new ValidInvoicesRules($this->all()),
|
'invoices.*.invoice_id' => new ValidInvoicesRules($this->all()),
|
||||||
@ -105,8 +115,8 @@ class StorePaymentRequest extends Request
|
|||||||
'credits.*.credit_id' => new ValidCreditsRules($this->all()),
|
'credits.*.credit_id' => new ValidCreditsRules($this->all()),
|
||||||
'credits.*.amount' => ['bail','required', new CreditsSumRule($this->all())],
|
'credits.*.amount' => ['bail','required', new CreditsSumRule($this->all())],
|
||||||
'invoices' => new ValidPayableInvoicesRule(),
|
'invoices' => new ValidPayableInvoicesRule(),
|
||||||
'number' => ['nullable', 'bail', Rule::unique('payments')->where('company_id', auth()->user()->company()->id)],
|
'number' => ['nullable', 'bail', Rule::unique('payments')->where('company_id', $user->company()->id)],
|
||||||
'idempotency_key' => ['nullable', 'bail', 'string','max:64', Rule::unique('payments')->where('company_id', auth()->user()->company()->id)],
|
'idempotency_key' => ['nullable', 'bail', 'string','max:64', Rule::unique('payments')->where('company_id', $user->company()->id)],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ class PaymentRepository extends BaseRepository
|
|||||||
$payment->is_manual = true;
|
$payment->is_manual = true;
|
||||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||||
|
|
||||||
if (! $payment->currency_id && $client) {
|
if ((!$payment->currency_id || $payment->currency_id == 0) && $client) {
|
||||||
if (property_exists($client->settings, 'currency_id')) {
|
if (property_exists($client->settings, 'currency_id')) {
|
||||||
$payment->currency_id = $client->settings->currency_id;
|
$payment->currency_id = $client->settings->currency_id;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user