mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-12 22:22:32 +01:00
Support bash payments
This commit is contained in:
parent
da9bbfd6af
commit
29b2d409f6
@ -91,7 +91,7 @@ class PaymentController extends BaseController
|
|||||||
{
|
{
|
||||||
$invoices = Invoice::scope()
|
$invoices = Invoice::scope()
|
||||||
->invoices()
|
->invoices()
|
||||||
->where('invoices.balance', '!=', 0)
|
->where('invoices.invoice_status_id', '!=', INVOICE_STATUS_PAID)
|
||||||
->with('client', 'invoice_status')
|
->with('client', 'invoice_status')
|
||||||
->orderBy('invoice_number')->get();
|
->orderBy('invoice_number')->get();
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class CreatePaymentAPIRequest extends PaymentRequest
|
|||||||
if (! $this->invoice_id || ! $this->amount) {
|
if (! $this->invoice_id || ! $this->amount) {
|
||||||
return [
|
return [
|
||||||
'invoice_id' => 'required|numeric|min:1',
|
'invoice_id' => 'required|numeric|min:1',
|
||||||
'amount' => 'required|numeric|not_in:0',
|
'amount' => 'required|numeric',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class CreatePaymentRequest extends PaymentRequest
|
|||||||
$rules = [
|
$rules = [
|
||||||
'client' => 'required', // TODO: change to client_id once views are updated
|
'client' => 'required', // TODO: change to client_id once views are updated
|
||||||
'invoice' => 'required', // TODO: change to invoice_id once views are updated
|
'invoice' => 'required', // TODO: change to invoice_id once views are updated
|
||||||
'amount' => 'required|numeric|not_in:0',
|
'amount' => 'required|numeric',
|
||||||
'payment_date' => 'required',
|
'payment_date' => 'required',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class InvoiceListener
|
|||||||
public function updatedInvoice(InvoiceWasUpdated $event)
|
public function updatedInvoice(InvoiceWasUpdated $event)
|
||||||
{
|
{
|
||||||
$invoice = $event->invoice;
|
$invoice = $event->invoice;
|
||||||
$invoice->updatePaidStatus(false);
|
$invoice->updatePaidStatus(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +71,7 @@ class InvoiceListener
|
|||||||
$partial = max(0, $invoice->partial - $payment->amount);
|
$partial = max(0, $invoice->partial - $payment->amount);
|
||||||
|
|
||||||
$invoice->updateBalances($adjustment, $partial);
|
$invoice->updateBalances($adjustment, $partial);
|
||||||
$invoice->updatePaidStatus();
|
$invoice->updatePaidStatus(true);
|
||||||
|
|
||||||
// store a backup of the invoice
|
// store a backup of the invoice
|
||||||
$activity = Activity::wherePaymentId($payment->id)
|
$activity = Activity::wherePaymentId($payment->id)
|
||||||
|
@ -560,12 +560,12 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
/**
|
/**
|
||||||
* @param bool $save
|
* @param bool $save
|
||||||
*/
|
*/
|
||||||
public function updatePaidStatus($save = true)
|
public function updatePaidStatus($paid = false, $save = true)
|
||||||
{
|
{
|
||||||
$statusId = false;
|
$statusId = false;
|
||||||
if ($this->amount != 0 && $this->balance == 0) {
|
if ($paid && $this->balance == 0) {
|
||||||
$statusId = INVOICE_STATUS_PAID;
|
$statusId = INVOICE_STATUS_PAID;
|
||||||
} elseif ($this->isSent() && $this->balance > 0 && $this->balance < $this->amount) {
|
} elseif ($paid && $this->balance > 0 && $this->balance < $this->amount) {
|
||||||
$statusId = INVOICE_STATUS_PARTIAL;
|
$statusId = INVOICE_STATUS_PARTIAL;
|
||||||
} elseif ($this->isPartial() && $this->balance > 0) {
|
} elseif ($this->isPartial() && $this->balance > 0) {
|
||||||
$statusId = ($this->balance == $this->amount ? INVOICE_STATUS_SENT : INVOICE_STATUS_PARTIAL);
|
$statusId = ($this->balance == $this->amount ? INVOICE_STATUS_SENT : INVOICE_STATUS_PARTIAL);
|
||||||
@ -648,7 +648,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
|
|
||||||
public function canBePaid()
|
public function canBePaid()
|
||||||
{
|
{
|
||||||
return floatval($this->balance) != 0 && ! $this->is_deleted && $this->isStandard();
|
return ! $this->isPaid() && ! $this->is_deleted && $this->isStandard();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function calcStatusLabel($status, $class, $entityType, $quoteInvoiceId)
|
public static function calcStatusLabel($status, $class, $entityType, $quoteInvoiceId)
|
||||||
|
@ -129,7 +129,7 @@ class InvoiceDatatable extends EntityDatatable
|
|||||||
return "javascript:submitForm_{$entityType}('markPaid', {$model->public_id})";
|
return "javascript:submitForm_{$entityType}('markPaid', {$model->public_id})";
|
||||||
},
|
},
|
||||||
function ($model) use ($entityType) {
|
function ($model) use ($entityType) {
|
||||||
return $entityType == ENTITY_INVOICE && $model->balance != 0 && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
|
return $entityType == ENTITY_INVOICE && $model->invoice_status_id != INVOICE_STATUS_PAID && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -138,7 +138,7 @@ class InvoiceDatatable extends EntityDatatable
|
|||||||
return URL::to("payments/create/{$model->client_public_id}/{$model->public_id}");
|
return URL::to("payments/create/{$model->client_public_id}/{$model->public_id}");
|
||||||
},
|
},
|
||||||
function ($model) use ($entityType) {
|
function ($model) use ($entityType) {
|
||||||
return $entityType == ENTITY_INVOICE && $model->balance > 0 && Auth::user()->can('create', ENTITY_PAYMENT);
|
return $entityType == ENTITY_INVOICE && $model->invoice_status_id != INVOICE_STATUS_PAID && Auth::user()->can('create', ENTITY_PAYMENT);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -233,7 +233,7 @@ class InvoicePresenter extends EntityPresenter
|
|||||||
$actions[] = ['url' => url("quotes/{$invoice->quote_id}/edit"), 'label' => trans('texts.view_quote')];
|
$actions[] = ['url' => url("quotes/{$invoice->quote_id}/edit"), 'label' => trans('texts.view_quote')];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$invoice->deleted_at && ! $invoice->is_recurring && $invoice->balance != 0) {
|
if ($invoice->canBePaid()) {
|
||||||
$actions[] = ['url' => 'javascript:submitBulkAction("markPaid")', 'label' => trans('texts.mark_paid')];
|
$actions[] = ['url' => 'javascript:submitBulkAction("markPaid")', 'label' => trans('texts.mark_paid')];
|
||||||
$actions[] = ['url' => 'javascript:onPaymentClick()', 'label' => trans('texts.enter_payment')];
|
$actions[] = ['url' => 'javascript:onPaymentClick()', 'label' => trans('texts.enter_payment')];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user