diff --git a/app/Abstracts/DocumentModel.php b/app/Abstracts/DocumentModel.php index efd540783..217cb24f2 100644 --- a/app/Abstracts/DocumentModel.php +++ b/app/Abstracts/DocumentModel.php @@ -22,7 +22,7 @@ abstract class DocumentModel extends Model public function scopeAccrued($query) { - return $query->where('status', '<>', 'draft'); + return $query->whereNotIn('status', ['draft', 'cancelled']); } public function scopePaid($query) @@ -146,6 +146,9 @@ abstract class DocumentModel extends Model case 'viewed': $label = 'warning'; break; + case 'cancelled': + $label = 'darker'; + break; default: $label = 'primary'; break; diff --git a/app/BulkActions/Purchases/Bills.php b/app/BulkActions/Purchases/Bills.php index 2cc779925..6b0088646 100644 --- a/app/BulkActions/Purchases/Bills.php +++ b/app/BulkActions/Purchases/Bills.php @@ -3,6 +3,8 @@ namespace App\BulkActions\Purchases; use App\Abstracts\BulkAction; +use App\Events\Purchase\BillCancelled; +use App\Events\Purchase\BillReceived; use App\Exports\Purchases\Bills as Export; use App\Jobs\Purchase\CreateBillHistory; use App\Jobs\Purchase\DeleteBill; @@ -18,6 +20,11 @@ class Bills extends BulkAction 'message' => 'bulk_actions.message.received', 'permission' => 'update-purchases-bills', ], + 'cancelled' => [ + 'name' => 'general.cancel', + 'message' => 'bulk_actions.message.cancelled', + 'permission' => 'update-purchases-bills', + ], 'delete' => [ 'name' => 'general.delete', 'message' => 'bulk_actions.message.delete', @@ -34,12 +41,16 @@ class Bills extends BulkAction $bills = $this->getSelectedRecords($request); foreach ($bills as $bill) { - $bill->status = 'received'; - $bill->save(); + event(new BillReceived($bill)); + } + } - $description = trans('bills.mark_recevied'); + public function cancelled($request) + { + $bills = $this->getSelectedRecords($request); - $this->dispatch(new CreateBillHistory($bill, 0, $description)); + foreach ($bills as $bill) { + event(new BillCancelled($bill)); } } diff --git a/app/BulkActions/Sales/Invoices.php b/app/BulkActions/Sales/Invoices.php index dee19f571..5d8e7dc21 100644 --- a/app/BulkActions/Sales/Invoices.php +++ b/app/BulkActions/Sales/Invoices.php @@ -3,6 +3,7 @@ namespace App\BulkActions\Sales; use App\Abstracts\BulkAction; +use App\Events\Sale\InvoiceCancelled; use App\Events\Sale\InvoiceCreated; use App\Events\Sale\InvoiceSent; use App\Events\Sale\PaymentReceived; @@ -25,6 +26,11 @@ class Invoices extends BulkAction 'message' => 'bulk_actions.message.sent', 'permission' => 'update-sales-invoices', ], + 'cancelled' => [ + 'name' => 'general.cancel', + 'message' => 'bulk_actions.message.cancelled', + 'permission' => 'update-sales-invoices', + ], 'delete' => [ 'name' => 'general.delete', 'message' => 'bulk_actions.message.delete', @@ -54,6 +60,15 @@ class Invoices extends BulkAction } } + public function cancelled($request) + { + $invoices = $this->getSelectedRecords($request); + + foreach ($invoices as $invoice) { + event(new InvoiceCancelled($invoice)); + } + } + public function duplicate($request) { $invoices = $this->getSelectedRecords($request); diff --git a/app/Events/Purchase/BillCancelled.php b/app/Events/Purchase/BillCancelled.php new file mode 100644 index 000000000..7284cd081 --- /dev/null +++ b/app/Events/Purchase/BillCancelled.php @@ -0,0 +1,22 @@ +bill = $bill; + } +} diff --git a/app/Events/Sale/InvoiceCancelled.php b/app/Events/Sale/InvoiceCancelled.php new file mode 100644 index 000000000..7ee73e5c4 --- /dev/null +++ b/app/Events/Sale/InvoiceCancelled.php @@ -0,0 +1,22 @@ +invoice = $invoice; + } +} diff --git a/app/Http/Controllers/Purchases/Bills.php b/app/Http/Controllers/Purchases/Bills.php index 76371eed4..d0260e5dc 100644 --- a/app/Http/Controllers/Purchases/Bills.php +++ b/app/Http/Controllers/Purchases/Bills.php @@ -284,7 +284,25 @@ class Bills extends Controller { event(new \App\Events\Purchase\BillReceived($bill)); - $message = trans('bills.messages.received'); + $message = trans('bills.messages.marked_received'); + + flash($message)->success(); + + return redirect()->back(); + } + + /** + * Mark the bill as cancelled. + * + * @param Bill $bill + * + * @return Response + */ + public function markCancelled(Bill $bill) + { + event(new \App\Events\Purchase\BillCancelled($bill)); + + $message = trans('bills.messages.marked_cancelled'); flash($message)->success(); diff --git a/app/Http/Controllers/Sales/Invoices.php b/app/Http/Controllers/Sales/Invoices.php index 38a2d66e2..e50285630 100644 --- a/app/Http/Controllers/Sales/Invoices.php +++ b/app/Http/Controllers/Sales/Invoices.php @@ -294,6 +294,24 @@ class Invoices extends Controller return redirect()->back(); } + /** + * Mark the invoice as cancelled. + * + * @param Invoice $invoice + * + * @return Response + */ + public function markCancelled(Invoice $invoice) + { + event(new \App\Events\Sale\InvoiceCancelled($invoice)); + + $message = trans('invoices.messages.marked_cancelled'); + + flash($message)->success(); + + return redirect()->back(); + } + /** * Download the PDF file of invoice. * diff --git a/app/Jobs/Purchase/CancelBill.php b/app/Jobs/Purchase/CancelBill.php new file mode 100644 index 000000000..195a2f022 --- /dev/null +++ b/app/Jobs/Purchase/CancelBill.php @@ -0,0 +1,38 @@ +bill = $bill; + } + + /** + * Execute the job. + * + * @return Bill + */ + public function handle() + { + $this->deleteRelationships($this->bill, [ + 'transactions', 'recurring' + ]); + + $this->bill->status = 'cancelled'; + $this->bill->save(); + + return true; + } +} diff --git a/app/Jobs/Sale/CancelInvoice.php b/app/Jobs/Sale/CancelInvoice.php new file mode 100644 index 000000000..e103f6d86 --- /dev/null +++ b/app/Jobs/Sale/CancelInvoice.php @@ -0,0 +1,38 @@ +invoice = $invoice; + } + + /** + * Execute the job. + * + * @return Invoice + */ + public function handle() + { + $this->deleteRelationships($this->invoice, [ + 'transactions', 'recurring' + ]); + + $this->invoice->status = 'cancelled'; + $this->invoice->save(); + + return true; + } +} diff --git a/app/Listeners/Purchase/MarkBillCancelled.php b/app/Listeners/Purchase/MarkBillCancelled.php new file mode 100644 index 000000000..fbb061e60 --- /dev/null +++ b/app/Listeners/Purchase/MarkBillCancelled.php @@ -0,0 +1,26 @@ +dispatch(new CancelBill($event->bill)); + + $this->dispatch(new CreateBillHistory($event->bill, 0, trans('bills.messages.marked_cancelled'))); + } +} diff --git a/app/Listeners/Purchase/MarkBillReceived.php b/app/Listeners/Purchase/MarkBillReceived.php index ce611107d..0b1eb0115 100644 --- a/app/Listeners/Purchase/MarkBillReceived.php +++ b/app/Listeners/Purchase/MarkBillReceived.php @@ -24,6 +24,6 @@ class MarkBillReceived $event->bill->save(); } - $this->dispatch(new CreateBillHistory($event->bill, 0, trans('bills.mark_received'))); + $this->dispatch(new CreateBillHistory($event->bill, 0, trans('bills.messages.marked_received'))); } } diff --git a/app/Listeners/Sale/MarkInvoiceCancelled.php b/app/Listeners/Sale/MarkInvoiceCancelled.php new file mode 100644 index 000000000..2b69a9615 --- /dev/null +++ b/app/Listeners/Sale/MarkInvoiceCancelled.php @@ -0,0 +1,26 @@ +dispatch(new CancelInvoice($event->invoice)); + + $this->dispatch(new CreateInvoiceHistory($event->invoice, 0, trans('invoices.messages.marked_cancelled'))); + } +} diff --git a/app/Listeners/Sale/MarkInvoiceSent.php b/app/Listeners/Sale/MarkInvoiceSent.php index 7445e43ea..e5081bd07 100644 --- a/app/Listeners/Sale/MarkInvoiceSent.php +++ b/app/Listeners/Sale/MarkInvoiceSent.php @@ -24,6 +24,6 @@ class MarkInvoiceSent $event->invoice->save(); } - $this->dispatch(new CreateInvoiceHistory($event->invoice, 0, trans('invoices.mark_sent'))); + $this->dispatch(new CreateInvoiceHistory($event->invoice, 0, trans('invoices.messages.marked_sent'))); } } diff --git a/app/Listeners/Sale/MarkInvoiceViewed.php b/app/Listeners/Sale/MarkInvoiceViewed.php index 3dbf79ae7..57143adef 100644 --- a/app/Listeners/Sale/MarkInvoiceViewed.php +++ b/app/Listeners/Sale/MarkInvoiceViewed.php @@ -29,6 +29,6 @@ class MarkInvoiceViewed $invoice->status = 'viewed'; $invoice->save(); - $this->dispatch(new CreateInvoiceHistory($event->invoice, 0, trans('invoices.mark_viewed'))); + $this->dispatch(new CreateInvoiceHistory($event->invoice, 0, trans('invoices.messages.marked_viewed'))); } } diff --git a/app/Providers/Event.php b/app/Providers/Event.php index 7d9afd560..d888952f6 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -33,6 +33,9 @@ class Event extends Provider 'App\Events\Purchase\BillReceived' => [ 'App\Listeners\Purchase\MarkBillReceived', ], + 'App\Events\Purchase\BillCancelled' => [ + 'App\Listeners\Purchase\MarkBillCancelled', + ], 'App\Events\Purchase\BillRecurring' => [ 'App\Listeners\Purchase\SendBillRecurringNotification', ], @@ -47,6 +50,9 @@ class Event extends Provider 'App\Events\Sale\InvoiceSent' => [ 'App\Listeners\Sale\MarkInvoiceSent', ], + 'App\Events\Sale\InvoiceCancelled' => [ + 'App\Listeners\Sale\MarkInvoiceCancelled', + ], 'App\Events\Sale\InvoiceViewed' => [ 'App\Listeners\Sale\MarkInvoiceViewed', ], diff --git a/app/Traits/Purchases.php b/app/Traits/Purchases.php index 228ae3c7d..e5189d469 100644 --- a/app/Traits/Purchases.php +++ b/app/Traits/Purchases.php @@ -45,6 +45,7 @@ trait Purchases 'paid', 'overdue', 'unpaid', + 'cancelled', ]; $statuses = collect($list)->each(function ($code) { diff --git a/app/Traits/Sales.php b/app/Traits/Sales.php index d4d9b9515..abc9e12a3 100644 --- a/app/Traits/Sales.php +++ b/app/Traits/Sales.php @@ -47,6 +47,7 @@ trait Sales 'paid', 'overdue', 'unpaid', + 'cancelled', ]; $statuses = collect($list)->each(function ($code) { diff --git a/database/factories/Bill.php b/database/factories/Bill.php index 372b40eec..160457af4 100644 --- a/database/factories/Bill.php +++ b/database/factories/Bill.php @@ -1,5 +1,6 @@ define(Bill::class, function (Faker $faker) use ($company) { $contact = factory(Contact::class)->states('enabled', 'vendor')->create(); } - $statuses = ['draft', 'received', 'partial', 'paid']; + $statuses = ['draft', 'received', 'partial', 'paid', 'cancelled']; return [ 'company_id' => $company->id, @@ -62,6 +63,8 @@ $factory->state(Bill::class, 'partial', ['status' => 'partial']); $factory->state(Bill::class, 'paid', ['status' => 'paid']); +$factory->state(Bill::class, 'cancelled', ['status' => 'cancelled']); + $factory->state(Bill::class, 'recurring', function (Faker $faker) { $frequencies = ['monthly', 'weekly']; @@ -175,6 +178,10 @@ $factory->afterCreating(Bill::class, function ($bill, $faker) use ($company) { $transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, $payment_request)); + break; + case 'cancelled': + event(new BillCancelled($updated_bill)); + break; } }); diff --git a/database/factories/Invoice.php b/database/factories/Invoice.php index 4d8f1ede4..ae8bd7707 100644 --- a/database/factories/Invoice.php +++ b/database/factories/Invoice.php @@ -1,5 +1,6 @@ define(Invoice::class, function (Faker $faker) use ($company) { $contact = factory(Contact::class)->states('enabled', 'customer')->create(); } - $statuses = ['draft', 'sent', 'viewed', 'partial', 'paid']; + $statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled']; return [ 'company_id' => $company->id, @@ -65,6 +66,8 @@ $factory->state(Invoice::class, 'partial', ['status' => 'partial']); $factory->state(Invoice::class, 'paid', ['status' => 'paid']); +$factory->state(Invoice::class, 'cancelled', ['status' => 'cancelled']); + $factory->state(Invoice::class, 'recurring', function (Faker $faker) { $frequencies = ['monthly', 'weekly']; @@ -184,6 +187,10 @@ $factory->afterCreating(Invoice::class, function ($invoice, $faker) use ($compan event(new PaymentReceived($updated_invoice, $payment_request)); + break; + case 'cancelled': + event(new InvoiceCancelled($updated_invoice)); + break; } }); diff --git a/public/css/akaunting-color.css b/public/css/akaunting-color.css index e91b7824a..edce10746 100644 --- a/public/css/akaunting-color.css +++ b/public/css/akaunting-color.css @@ -480,6 +480,32 @@ a.text-yellow:focus background-color: #bf8003; } /*--Warning Color Finish--*/ +/*--Dark Color--*/ +.badge-dark +{ + color: #fff; + background-color: #6a7783; +} +.badge-dark[href]:hover, +.badge-dark[href]:focus +{ + color: #fff; + background-color: #060607; +} +/*--Dark Color Finish--*/ +/*--Darker Color--*/ +.badge-darker +{ + color: #fff; + background-color: #525252; +} +.badge-darker[href]:hover, +.badge-darker[href]:focus +{ + color: #fff; + background-color: #000; +} +/*--Darker Color Finish--*/ /*--------Badge Colors Finish--------*/ /*--------Background Colors--------*/ @@ -1897,6 +1923,20 @@ button.bg-yellow:focus background-image: linear-gradient(to right, #ffffff , #efad32); } /*--Viewed Color Finish--*/ + +/*--Dark Color--*/ +.status-dark +{ + background-image: linear-gradient(to right, #ffffff , #6a7783); +} +/*--Dark Color Finish--*/ + +/*--Darker Color--*/ +.status-darker +{ + background-image: linear-gradient(to right, #ffffff , #525252); +} +/*--Darker Color Finish--*/ /*--------Transaction Status Colors Finish--------*/ diff --git a/resources/lang/en-GB/bills.php b/resources/lang/en-GB/bills.php index 6c2831b9e..494bc8fe1 100644 --- a/resources/lang/en-GB/bills.php +++ b/resources/lang/en-GB/bills.php @@ -31,6 +31,7 @@ return [ 'add_payment' => 'Add Payment', 'mark_paid' => 'Mark Paid', 'mark_received' => 'Mark Received', + 'mark_cancelled' => 'Mark Cancelled', 'download_pdf' => 'Download PDF', 'send_mail' => 'Send Email', 'create_bill' => 'Create Bill', @@ -44,11 +45,13 @@ return [ 'paid' => 'Paid', 'overdue' => 'Overdue', 'unpaid' => 'Unpaid', + 'cancelled' => 'Cancelled', ], 'messages' => [ - 'received' => 'Bill marked as received successfully!', + 'marked_received' => 'Bill marked as received!', 'marked_paid' => 'Bill marked as paid!', + 'marked_cancelled' => 'Bill marked as cancelled!', 'draft' => 'This is a DRAFT bill and will be reflected to charts after it gets received.', 'status' => [ diff --git a/resources/lang/en-GB/bulk_actions.php b/resources/lang/en-GB/bulk_actions.php index a9ad32f04..4c420c141 100644 --- a/resources/lang/en-GB/bulk_actions.php +++ b/resources/lang/en-GB/bulk_actions.php @@ -15,6 +15,7 @@ return [ 'paid' => 'Are you sure you want to mark selected invoice as paid?|Are you sure you want to mark selected invoices as paid?', 'sent' => 'Are you sure you want to mark selected invoice as sent?|Are you sure you want to mark selected invoices as sent?', 'received' => 'Are you sure you want to mark selected bill as received?|Are you sure you want to mark selected bills as received?', + 'cancelled' => 'Are you sure you want to cancel selected invoice/bill?|Are you sure you want to cancel selected invoices/bills?', ], ]; diff --git a/resources/lang/en-GB/invoices.php b/resources/lang/en-GB/invoices.php index a2719ca16..feb332849 100644 --- a/resources/lang/en-GB/invoices.php +++ b/resources/lang/en-GB/invoices.php @@ -31,6 +31,7 @@ return [ 'mark_paid' => 'Mark Paid', 'mark_sent' => 'Mark Sent', 'mark_viewed' => 'Mark Viewed', + 'mark_cancelled' => 'Mark Cancelled', 'download_pdf' => 'Download PDF', 'send_mail' => 'Send Email', 'all_invoices' => 'Login to view all invoices', @@ -48,12 +49,15 @@ return [ 'paid' => 'Paid', 'overdue' => 'Overdue', 'unpaid' => 'Unpaid', + 'cancelled' => 'Cancelled', ], 'messages' => [ 'email_sent' => 'Invoice email has been sent!', 'marked_sent' => 'Invoice marked as sent!', 'marked_paid' => 'Invoice marked as paid!', + 'marked_viewed' => 'Invoice marked as viewed!', + 'marked_cancelled' => 'Invoice marked as cancelled!', 'email_required' => 'No email address for this customer!', 'draft' => 'This is a DRAFT invoice and will be reflected to charts after it gets sent.', diff --git a/resources/views/portal/invoices/show.blade.php b/resources/views/portal/invoices/show.blade.php index 69c206a3a..c3138d577 100644 --- a/resources/views/portal/invoices/show.blade.php +++ b/resources/views/portal/invoices/show.blade.php @@ -273,8 +273,7 @@