mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Working on credit payments
This commit is contained in:
parent
90494547c5
commit
fd19e9dc2c
@ -38,7 +38,7 @@ class StorePaymentRequest extends Request
|
|||||||
{
|
{
|
||||||
$input = $this->all();
|
$input = $this->all();
|
||||||
|
|
||||||
//info(print_r($input,1));
|
// info(print_r($input,1));
|
||||||
|
|
||||||
$invoices_total = 0;
|
$invoices_total = 0;
|
||||||
$credits_total = 0;
|
$credits_total = 0;
|
||||||
|
@ -34,12 +34,13 @@ class UpdatePaymentRequest extends Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function rules()
|
public function rules()
|
||||||
{//min:1 removed, 'required'
|
{
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
|
'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->payment->company_id,
|
||||||
'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule],
|
'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule],
|
||||||
'invoices.*.invoice_id' => 'distinct',
|
'invoices.*.invoice_id' => 'distinct',
|
||||||
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
|
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
|
||||||
'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->company_id,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->input('documents') && is_array($this->input('documents'))) {
|
if ($this->input('documents') && is_array($this->input('documents'))) {
|
||||||
|
@ -39,10 +39,4 @@ class UpdateTaskStatusRequest extends Request
|
|||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected function prepareForValidation()
|
|
||||||
// {
|
|
||||||
// $input = $this->all();
|
|
||||||
|
|
||||||
// $this->replace($input);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,14 @@ class PaymentRepository extends BaseRepository
|
|||||||
*/
|
*/
|
||||||
private function applyPayment(array $data, Payment $payment): ?Payment
|
private function applyPayment(array $data, Payment $payment): ?Payment
|
||||||
{
|
{
|
||||||
|
$is_existing_payment = true;
|
||||||
|
|
||||||
//check currencies here and fill the exchange rate data if necessary
|
//check currencies here and fill the exchange rate data if necessary
|
||||||
if (! $payment->id) {
|
if (! $payment->id) {
|
||||||
$this->processExchangeRates($data, $payment);
|
$this->processExchangeRates($data, $payment);
|
||||||
|
|
||||||
|
$is_existing_payment = false;
|
||||||
|
|
||||||
/*We only update the paid to date ONCE per payment*/
|
/*We only update the paid to date ONCE per payment*/
|
||||||
if (array_key_exists('invoices', $data) && is_array($data['invoices']) && count($data['invoices']) > 0) {
|
if (array_key_exists('invoices', $data) && is_array($data['invoices']) && count($data['invoices']) > 0) {
|
||||||
if ($data['amount'] == '') {
|
if ($data['amount'] == '') {
|
||||||
@ -144,6 +147,7 @@ class PaymentRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$is_existing_payment)
|
||||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||||
|
|
||||||
/*info("invoice totals = {$invoice_totals}");
|
/*info("invoice totals = {$invoice_totals}");
|
||||||
@ -162,7 +166,7 @@ class PaymentRepository extends BaseRepository
|
|||||||
// $payment->applied += $invoice_totals;
|
// $payment->applied += $invoice_totals;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$payment->applied = $invoice_totals; //wont work because - check tests
|
$payment->applied += $invoice_totals; //wont work because - check tests
|
||||||
|
|
||||||
$payment->save();
|
$payment->save();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user