1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Support bulk mark paid

This commit is contained in:
Hillel Coren 2016-12-14 21:47:22 +02:00
parent 9201004f33
commit 16dba695b1
6 changed files with 81 additions and 7 deletions

View File

@ -142,6 +142,7 @@ class InvoiceController extends BaseController
}
if (!$invoice->is_recurring && $invoice->balance > 0 && $invoice->is_public) {
$actions[] = ['url' => 'javascript:submitBulkAction("markPaid")', 'label' => trans('texts.mark_paid')];
$actions[] = ['url' => 'javascript:onPaymentClick()', 'label' => trans('texts.enter_payment')];
}
@ -511,7 +512,13 @@ class InvoiceController extends BaseController
$count = $this->invoiceService->bulk($ids, $action);
if ($count > 0) {
$key = $action == 'markSent' ? "updated_{$entityType}" : "{$action}d_{$entityType}";
if ($action == 'markSent') {
$key = 'marked_sent_invoice';
} elseif ($action == 'markPaid') {
$key = 'created_payment';
} else {
$key = "{$action}d_{$entityType}";
}
$message = Utils::pluralize($key, $count);
Session::flash('message', $message);
}

View File

@ -27,6 +27,20 @@ class EntityDatatable
return [];
}
public function bulkActions()
{
return [
[
'label' => mtrans($this->entityType, 'archive_'.$this->entityType),
'url' => 'javascript:submitForm_'.$this->entityType.'("archive")',
],
[
'label' => mtrans($this->entityType, 'delete_'.$this->entityType),
'url' => 'javascript:submitForm_'.$this->entityType.'("delete")',
]
];
}
public function columnFields()
{
$data = [];

View File

@ -117,6 +117,15 @@ class InvoiceDatatable extends EntityDatatable
return $model->invoice_status_id < INVOICE_STATUS_SENT && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
}
],
[
trans('texts.mark_paid'),
function ($model) use ($entityType) {
return "javascript:submitForm_{$entityType}('markPaid', {$model->public_id})";
},
function ($model) {
return $model->balance > 0 && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
}
],
[
trans('texts.enter_payment'),
function ($model) {
@ -190,4 +199,25 @@ class InvoiceDatatable extends EntityDatatable
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
}
public function bulkActions()
{
$actions = parent::bulkActions();
if ($this->entityType == ENTITY_INVOICE || $this->entityType == ENTITY_QUOTE) {
$actions[] = [
'label' => mtrans($this->entityType, 'mark_sent'),
'url' => 'javascript:submitForm_'.$this->entityType.'("markSent")',
];
}
if ($this->entityType == ENTITY_INVOICE) {
$actions[] = [
'label' => mtrans($this->entityType, 'mark_paid'),
'url' => 'javascript:submitForm_'.$this->entityType.'("markPaid")',
];
}
return $actions;
}
}

View File

@ -22,10 +22,11 @@ class InvoiceRepository extends BaseRepository
return 'App\Models\Invoice';
}
public function __construct(PaymentService $paymentService, DocumentRepository $documentRepo)
public function __construct(PaymentService $paymentService, DocumentRepository $documentRepo, PaymentRepository $paymentRepo)
{
$this->documentRepo = $documentRepo;
$this->paymentService = $paymentService;
$this->paymentRepo = $paymentRepo;
}
public function all()
@ -753,6 +754,26 @@ class InvoiceRepository extends BaseRepository
$invoice->is_public = true;
$invoice->save();
$invoice->markInvitationsSent();
}
/**
* @param Invoice $invoice
*/
public function markPaid(Invoice $invoice)
{
if (floatval($invoice->balance) <= 0) {
return;
}
$data = [
'client_id' => $invoice->client_id,
'invoice_id' => $invoice->id,
'amount' => $invoice->balance,
];
return $this->paymentRepo->save($data);
}
/**

View File

@ -2269,7 +2269,9 @@ $LANG = array(
'user_guide' => 'User Guide',
'promo_message' => 'Upgrade before :expires and get :amount% OFF your first year of our Pro or Enterprise packages.',
'discount_message' => ':amount% off expires :expires',
'mark_paid' => 'Mark Paid',
'marked_sent_invoice' => 'Successfully marked invoice sent',
'marked_sent_invoices' => 'Successfully marked invoices sent',
);
return $LANG;

View File

@ -17,10 +17,10 @@
@endif
@endcan
{!! DropdownButton::normal(trans('texts.archive'))->withContents([
['label' => mtrans($entityType, 'archive_'.$entityType), 'url' => 'javascript:submitForm_'.$entityType.'("archive")'],
['label' => mtrans($entityType, 'delete_'.$entityType), 'url' => 'javascript:submitForm_'.$entityType.'("delete")'],
])->withAttributes(['class'=>'archive'])->split() !!}
{!! DropdownButton::normal(trans('texts.archive'))
->withContents($datatable->bulkActions())
->withAttributes(['class'=>'archive'])
->split() !!}
&nbsp;
<span id="statusWrapper_{{ $entityType }}" style="display:none">