mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +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();
|
||||
|
||||
//info(print_r($input,1));
|
||||
// info(print_r($input,1));
|
||||
|
||||
$invoices_total = 0;
|
||||
$credits_total = 0;
|
||||
|
@ -34,12 +34,13 @@ class UpdatePaymentRequest extends Request
|
||||
}
|
||||
|
||||
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.*.invoice_id' => 'distinct',
|
||||
'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'))) {
|
||||
|
@ -39,10 +39,4 @@ class UpdateTaskStatusRequest extends Request
|
||||
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
|
||||
{
|
||||
$is_existing_payment = true;
|
||||
|
||||
//check currencies here and fill the exchange rate data if necessary
|
||||
if (! $payment->id) {
|
||||
$this->processExchangeRates($data, $payment);
|
||||
|
||||
$is_existing_payment = false;
|
||||
|
||||
/*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 ($data['amount'] == '') {
|
||||
@ -144,7 +147,8 @@ class PaymentRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||
if(!$is_existing_payment)
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||
|
||||
/*info("invoice totals = {$invoice_totals}");
|
||||
info("credit totals = {$credit_totals}");
|
||||
@ -162,7 +166,7 @@ class PaymentRepository extends BaseRepository
|
||||
// $payment->applied += $invoice_totals;
|
||||
// }
|
||||
|
||||
$payment->applied = $invoice_totals; //wont work because - check tests
|
||||
$payment->applied += $invoice_totals; //wont work because - check tests
|
||||
|
||||
$payment->save();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user