1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Support bash payments

This commit is contained in:
Hillel Coren 2017-08-09 10:57:24 +03:00
parent da9bbfd6af
commit 29b2d409f6
7 changed files with 12 additions and 12 deletions

View File

@ -91,7 +91,7 @@ class PaymentController extends BaseController
{
$invoices = Invoice::scope()
->invoices()
->where('invoices.balance', '!=', 0)
->where('invoices.invoice_status_id', '!=', INVOICE_STATUS_PAID)
->with('client', 'invoice_status')
->orderBy('invoice_number')->get();

View File

@ -26,7 +26,7 @@ class CreatePaymentAPIRequest extends PaymentRequest
if (! $this->invoice_id || ! $this->amount) {
return [
'invoice_id' => 'required|numeric|min:1',
'amount' => 'required|numeric|not_in:0',
'amount' => 'required|numeric',
];
}

View File

@ -37,7 +37,7 @@ class CreatePaymentRequest extends PaymentRequest
$rules = [
'client' => 'required', // TODO: change to client_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',
];

View File

@ -48,7 +48,7 @@ class InvoiceListener
public function updatedInvoice(InvoiceWasUpdated $event)
{
$invoice = $event->invoice;
$invoice->updatePaidStatus(false);
$invoice->updatePaidStatus(false, false);
}
/**
@ -71,7 +71,7 @@ class InvoiceListener
$partial = max(0, $invoice->partial - $payment->amount);
$invoice->updateBalances($adjustment, $partial);
$invoice->updatePaidStatus();
$invoice->updatePaidStatus(true);
// store a backup of the invoice
$activity = Activity::wherePaymentId($payment->id)

View File

@ -560,12 +560,12 @@ class Invoice extends EntityModel implements BalanceAffecting
/**
* @param bool $save
*/
public function updatePaidStatus($save = true)
public function updatePaidStatus($paid = false, $save = true)
{
$statusId = false;
if ($this->amount != 0 && $this->balance == 0) {
if ($paid && $this->balance == 0) {
$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;
} elseif ($this->isPartial() && $this->balance > 0) {
$statusId = ($this->balance == $this->amount ? INVOICE_STATUS_SENT : INVOICE_STATUS_PARTIAL);
@ -648,7 +648,7 @@ class Invoice extends EntityModel implements BalanceAffecting
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)

View File

@ -129,7 +129,7 @@ class InvoiceDatatable extends EntityDatatable
return "javascript:submitForm_{$entityType}('markPaid', {$model->public_id})";
},
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}");
},
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);
},
],
[

View File

@ -233,7 +233,7 @@ class InvoicePresenter extends EntityPresenter
$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:onPaymentClick()', 'label' => trans('texts.enter_payment')];
}