diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 512f7774e270..9e131bed5d1f 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -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); } diff --git a/app/Ninja/Datatables/EntityDatatable.php b/app/Ninja/Datatables/EntityDatatable.php index 0631f6eb3ed9..99e2a414ad89 100644 --- a/app/Ninja/Datatables/EntityDatatable.php +++ b/app/Ninja/Datatables/EntityDatatable.php @@ -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 = []; diff --git a/app/Ninja/Datatables/InvoiceDatatable.php b/app/Ninja/Datatables/InvoiceDatatable.php index 5d90107d03c3..13372bc416ec 100644 --- a/app/Ninja/Datatables/InvoiceDatatable.php +++ b/app/Ninja/Datatables/InvoiceDatatable.php @@ -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 "

$label

"; } + + 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; + } } diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index d1d0f5c3b748..afa5760e7d67 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -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); } /** diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index c0df57548e89..705c6b9cc1e0 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -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; diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 79a21077beee..5848cf8fafd2 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -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() !!}