diff --git a/app/Events/Vendor/VendorWasArchived.php b/app/Events/Vendor/VendorWasArchived.php index beac2117cf9a..754d626ea611 100644 --- a/app/Events/Vendor/VendorWasArchived.php +++ b/app/Events/Vendor/VendorWasArchived.php @@ -9,7 +9,7 @@ * @license https://opensource.org/licenses/AAL */ -namespace App\Events; +namespace App\Events\Vendor; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; diff --git a/app/Events/Vendor/VendorWasCreated.php b/app/Events/Vendor/VendorWasCreated.php index 5a7d090d7ce7..ee7d7260a1ba 100644 --- a/app/Events/Vendor/VendorWasCreated.php +++ b/app/Events/Vendor/VendorWasCreated.php @@ -9,7 +9,7 @@ * @license https://opensource.org/licenses/AAL */ -namespace App\Events; +namespace App\Events\Vendor; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; diff --git a/app/Events/Vendor/VendorWasDeleted.php b/app/Events/Vendor/VendorWasDeleted.php index 3e1eebdebf34..afc6cbefde13 100644 --- a/app/Events/Vendor/VendorWasDeleted.php +++ b/app/Events/Vendor/VendorWasDeleted.php @@ -9,7 +9,7 @@ * @license https://opensource.org/licenses/AAL */ -namespace App\Events; +namespace App\Events\Vendor; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; diff --git a/app/Events/Vendor/VendorWasRestored.php b/app/Events/Vendor/VendorWasRestored.php index a5324ff94468..8f00f495d095 100644 --- a/app/Events/Vendor/VendorWasRestored.php +++ b/app/Events/Vendor/VendorWasRestored.php @@ -9,7 +9,7 @@ * @license https://opensource.org/licenses/AAL */ -namespace App\Events; +namespace App\Events\Vendor; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; diff --git a/app/Events/Vendor/VendorWasUpdated.php b/app/Events/Vendor/VendorWasUpdated.php index 744304afc456..1ae648d5fa3b 100644 --- a/app/Events/Vendor/VendorWasUpdated.php +++ b/app/Events/Vendor/VendorWasUpdated.php @@ -9,7 +9,7 @@ * @license https://opensource.org/licenses/AAL */ -namespace App\Events; +namespace App\Events\Vendor; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; diff --git a/app/Helpers/Email/PaymentEmail.php b/app/Helpers/Email/PaymentEmail.php index 63b83bedfa4e..12fb79ffab68 100644 --- a/app/Helpers/Email/PaymentEmail.php +++ b/app/Helpers/Email/PaymentEmail.php @@ -10,7 +10,7 @@ namespace App\Helpers\Email; use App\Models\Payment; -class EmailPayment extends EmailBuilder +class PaymentEmail extends EmailBuilder { public function build(Payment $payment, $contact = null) { diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index e092efb075c5..a38adaf607f1 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -676,6 +676,10 @@ class InvoiceController extends BaseController return $this->listResponse($invoice); } break; + case 'cancel': + break; + case 'reverse': + break; case 'email': $this->reminder_template = $invoice->calculateTemplate(); diff --git a/app/Http/Requests/Invoice/ActionInvoiceRequest.php b/app/Http/Requests/Invoice/ActionInvoiceRequest.php index 018e6062acb7..938cfafcaa2d 100644 --- a/app/Http/Requests/Invoice/ActionInvoiceRequest.php +++ b/app/Http/Requests/Invoice/ActionInvoiceRequest.php @@ -13,17 +13,93 @@ namespace App\Http\Requests\Invoice; use App\Http\Requests\Request; use App\Models\Invoice; +use App\Utils\Traits\Invoice\ActionsInvoice; +use App\Utils\Traits\MakesHash; class ActionInvoiceRequest extends Request { + use MakesHash; + use ActionsInvoice; /** * Determine if the user is authorized to make this request. * * @return bool */ + private $error_msg; + + private $invoice; public function authorize() : bool { return auth()->user()->can('edit', $this->invoice); } + + public function rules() + { + return [ + 'action' => 'required' + ]; + } + + protected function prepareForValidation() + { + $input = $this->all(); + + $this->invoice = Invoice::find($this->decodePrimary($invoice_id)); + + if(!array_key_exists('action', $input) { + $this->error_msg = 'Action is a required field'; + } + elseif(!$this->invoiceDeletable()){ + unset($input['action']); + $this->error_msg = 'This invoice cannot be deleted'; + } + elseif(!$this->invoiceCancellable()) { + unset($input['action']); + $this->error_msg = 'This invoice cannot be cancelled'; + } + else if(!$this->invoiceReversable()) { + unset($input['action']); + $this->error_msg = 'This invoice cannot be reversed'; + } + + $this->replace($input); + } + + public function messages() + { + return [ + 'action' => $this->error_msg; + ] + } + + + private function invoiceDeletable() + { + + if($this->invoice->status_id <= 2 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL) + return true; + + return false; + } + + private function invoiceCancellable() + { + + if($this->invoice->status_id == 3 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL) + return true; + + return false; + } + + private function invoiceReversable() + { + + if(($this->invoice->status_id == 3 || $this->invoice->status_id == 4) && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL) + return true; + + return false; + } + } + diff --git a/app/Jobs/Credit/EmailCredit.php b/app/Jobs/Credit/EmailCredit.php index 48bb21c3d479..04aaf9f194ef 100644 --- a/app/Jobs/Credit/EmailCredit.php +++ b/app/Jobs/Credit/EmailCredit.php @@ -9,7 +9,7 @@ * @license https://opensource.org/licenses/AAL */ -namespace App\Jobs\Invoice; +namespace App\Jobs\Credit; use App\Events\Credit\CreditWasEmailed; use App\Events\Credit\CreditWasEmailedAndFailed; diff --git a/app/Libraries/OAuth/Providers/Google.php b/app/Libraries/OAuth/Providers/Google.php index d26b75ec9be5..187153436969 100644 --- a/app/Libraries/OAuth/Providers/Google.php +++ b/app/Libraries/OAuth/Providers/Google.php @@ -1,4 +1,6 @@ -invoice->balance; + $balance_remaining = $this->invoice->balance; $total_paid = $this->invoice->amount - $this->invoice->balance; //change invoice status diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index aae072b46361..783eb16cdb50 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -33,6 +33,7 @@ class SystemHealth 'openssl', 'mbstring', 'xml', + 'bcmath' ]; private static $php_version = 7.3; diff --git a/app/Utils/Traits/Invoice/ActionsInvoice.php b/app/Utils/Traits/Invoice/ActionsInvoice.php new file mode 100644 index 000000000000..51cd1a0da757 --- /dev/null +++ b/app/Utils/Traits/Invoice/ActionsInvoice.php @@ -0,0 +1,43 @@ +invoice->status_id <= 2 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL) + return true; + + return false; + } + + public function invoiceCancellable() :bool + { + + if($this->invoice->status_id == 3 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL) + return true; + + return false; + } + + public function invoiceReversable() :bool + { + + if(($this->invoice->status_id == 3 || $this->invoice->status_id == 4) && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL) + return true; + + return false; + } +} diff --git a/resources/views/setup/_application.blade.php b/resources/views/setup/_application.blade.php index 7988da597c8d..7ee9914522e0 100644 --- a/resources/views/setup/_application.blade.php +++ b/resources/views/setup/_application.blade.php @@ -42,6 +42,7 @@
{{ ctrans('texts.send_fail_logs_to_our_server') }} + Read more about how we use this
diff --git a/tests/Unit/InvoiceActionsTest.php b/tests/Unit/InvoiceActionsTest.php new file mode 100644 index 000000000000..89334b86aa2f --- /dev/null +++ b/tests/Unit/InvoiceActionsTest.php @@ -0,0 +1,71 @@ +makeTestData(); + } + + public function testInvoiceIsDeletable() + { + $this->assertTrue($this->invoiceDeletable()); + $this->assertFalse($this->invoiceReversable()); + $this->assertFalse($this->invoiceCancellable()); + } + + public function testInvoiceIsReversable() + { + $this->invoice->service()->markPaid()->save(); + + $this->assertFalse($this->invoiceDeletable()); + $this->assertTrue($this->invoiceReversable()); + $this->assertFalse($this->invoiceCancellable()); + } + + public function testInvoiceIsCancellable() + { + $payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id); + $payment->amount = 40; + $payment->client_id = $this->invoice->client_id; + $payment->applied = 0; + $payment->refunded = 0; + $payment->date = now(); + $payment->save(); + + $this->invoice->service()->applyPayment($payment, 5)->save(); + + $this->assertFalse($this->invoiceDeletable()); + $this->assertTrue($this->invoiceReversable()); + $this->assertTrue($this->invoiceCancellable()); + } + + public function testInvoiceUnactionable() + { + $this->invoice->delete(); + + + $this->assertFalse($this->invoiceDeletable()); + $this->assertFalse($this->invoiceReversable()); + $this->assertFalse($this->invoiceCancellable()); + } + +}