From a144b67a4eff39a64f4e7bc88df2c74dc1e20f45 Mon Sep 17 00:00:00 2001 From: jayvirsinh_gohil Date: Tue, 12 Nov 2019 18:26:29 +0530 Subject: [PATCH] validation and status changes --- app/Http/Controllers/InvoicesController.php | 1 + app/Http/Controllers/PaymentController.php | 23 +++---------------- app/Http/Requests/CustomerRequest.php | 4 ++++ app/Http/Requests/EstimatesRequest.php | 15 +++++++++--- app/Http/Requests/ExpenseRequest.php | 2 +- app/Http/Requests/InvoicesRequest.php | 15 +++++++++--- app/Http/Requests/ItemsRequest.php | 2 +- app/Http/Requests/PaymentRequest.php | 2 +- app/Http/Requests/ProfileRequest.php | 4 ++++ .../2017_04_11_081227_create_items_table.php | 2 +- ...017_04_12_090759_create_invoices_table.php | 12 +++++----- ...4_12_091015_create_invoice_items_table.php | 12 +++++----- ...17_05_05_055609_create_estimates_table.php | 10 ++++---- ..._02_123501_create_estimate_items_table.php | 12 +++++----- ...018_11_02_133956_create_expenses_table.php | 2 +- ...019_09_03_135234_create_payments_table.php | 2 +- .../2019_09_21_052548_create_taxes_table.php | 2 +- database/seeds/EstimateTemplateSeeder.php | 6 ++--- database/seeds/InvoiceTemplateSeeder.php | 6 ++--- 19 files changed, 72 insertions(+), 62 deletions(-) diff --git a/app/Http/Controllers/InvoicesController.php b/app/Http/Controllers/InvoicesController.php index ce434e24..7eaebb7b 100644 --- a/app/Http/Controllers/InvoicesController.php +++ b/app/Http/Controllers/InvoicesController.php @@ -260,6 +260,7 @@ class InvoicesController extends Controller 'error' => 'invalid_due_amount' ]); } elseif ($invoice->due_amount != 0 && $invoice->paid_status == Invoice::STATUS_PAID) { + $invoice->status = $invoice->getPreviousStatus(); $invoice->paid_status = Invoice::STATUS_PARTIALLY_PAID; } diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index e141fd7c..9ebc8203 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -170,6 +170,7 @@ class PaymentController extends Controller $invoice->status = Invoice::STATUS_COMPLETED; $invoice->paid_status = Invoice::STATUS_PAID; } else { + $invoice->status = $invoice->getPreviousStatus(); $invoice->paid_status = Invoice::STATUS_PARTIALLY_PAID; } @@ -211,16 +212,7 @@ class PaymentController extends Controller $invoice->paid_status = Invoice::STATUS_PARTIALLY_PAID; } - if ($invoice->due_date < Carbon::now()) { - $invoice->status = Invoice::STATUS_OVERDUE; - } elseif ($invoice->viewed) { - $invoice->status = Invoice::STATUS_VIEWED; - } elseif ($invoice->sent) { - $invoice->status = Invoice::STATUS_SENT; - } else { - $invoice->status = Invoice::STATUS_DRAFT; - } - + $invoice->status = $invoice->getPreviousStatus(); $invoice->save(); } @@ -246,16 +238,7 @@ class PaymentController extends Controller $invoice->paid_status = Invoice::STATUS_PARTIALLY_PAID; } - if ($invoice->due_date < Carbon::now()) { - $invoice->status = Invoice::STATUS_OVERDUE; - } elseif ($invoice->sent) { - $invoice->status = Invoice::STATUS_SENT; - } elseif ($invoice->viewed) { - $invoice->status = Invoice::STATUS_VIEWED; - } else { - $invoice->status = Invoice::STATUS_DRAFT; - } - + $invoice->status = $invoice->getPreviousStatus(); $invoice->save(); } diff --git a/app/Http/Requests/CustomerRequest.php b/app/Http/Requests/CustomerRequest.php index 9a55be44..0973264c 100644 --- a/app/Http/Requests/CustomerRequest.php +++ b/app/Http/Requests/CustomerRequest.php @@ -26,12 +26,16 @@ class CustomerRequest extends FormRequest case 'POST': return [ 'name' => 'required', + 'addresses.*.address_street_1' => 'max:255', + 'addresses.*.address_street_2' => 'max:255', 'email' => 'email|nullable|unique:users,email', ]; break; case 'PUT': return [ 'name' => 'required', + 'addresses.*.address_street_1' => 'max:255', + 'addresses.*.address_street_2' => 'max:255', ]; break; default: diff --git a/app/Http/Requests/EstimatesRequest.php b/app/Http/Requests/EstimatesRequest.php index 61b96d65..5a9c760e 100644 --- a/app/Http/Requests/EstimatesRequest.php +++ b/app/Http/Requests/EstimatesRequest.php @@ -27,13 +27,22 @@ class EstimatesRequest extends FormRequest 'expiry_date' => 'required', 'estimate_number' => 'required|unique:estimates,estimate_number', 'user_id' => 'required', - 'discount' => 'required', + 'discount' => 'required|digits_between:1,20', + 'discount_val' => 'required|digits_between:1,20', + 'sub_total' => 'required|digits_between:1,20', + 'total' => 'required|digits_between:1,20', + 'tax' => 'required|digits_between:1,20', 'estimate_template_id' => 'required', 'items' => 'required|array', + 'items.*.description' => 'max:255', 'items.*' => 'required|max:255', 'items.*.name' => 'required', - 'items.*.quantity' => 'required|numeric', - 'items.*.price' => 'required|numeric', + 'items.*.quantity' => 'required|digits_between:1,20', + 'items.*.price' => 'required|digits_between:1,20', + 'items.*.discount' => 'digits_between:1,20', + 'items.*.discount_val' => 'digits_between:1,20', + 'items.*.tax' => 'digits_between:1,20', + 'items.*.total' => 'digits_between:1,20', ]; if ($this->getMethod() == 'PUT') { diff --git a/app/Http/Requests/ExpenseRequest.php b/app/Http/Requests/ExpenseRequest.php index 576d69f5..3c03bd67 100644 --- a/app/Http/Requests/ExpenseRequest.php +++ b/app/Http/Requests/ExpenseRequest.php @@ -25,7 +25,7 @@ class ExpenseRequest extends FormRequest return [ 'expense_date' => 'required', 'expense_category_id' => 'required', - 'amount' => 'required' + 'amount' => 'required|digits_between:1,20' ]; } } diff --git a/app/Http/Requests/InvoicesRequest.php b/app/Http/Requests/InvoicesRequest.php index 2724e323..3b9306ce 100644 --- a/app/Http/Requests/InvoicesRequest.php +++ b/app/Http/Requests/InvoicesRequest.php @@ -27,13 +27,22 @@ class InvoicesRequest extends FormRequest 'due_date' => 'required', 'invoice_number' => 'required|unique:invoices,invoice_number', 'user_id' => 'required', - 'discount' => 'required', + 'discount' => 'required|digits_between:1,20', + 'discount_val' => 'required|digits_between:1,20', + 'sub_total' => 'required|digits_between:1,20', + 'total' => 'required|digits_between:1,20', + 'tax' => 'required|digits_between:1,20', 'invoice_template_id' => 'required', 'items' => 'required|array', 'items.*' => 'required|max:255', + 'items.*.description' => 'max:255', 'items.*.name' => 'required', - 'items.*.quantity' => 'required|numeric', - 'items.*.price' => 'required|numeric', + 'items.*.quantity' => 'required|digits_between:1,20', + 'items.*.price' => 'required|digits_between:1,20', + 'items.*.discount' => 'digits_between:1,20', + 'items.*.discount_val' => 'digits_between:1,20', + 'items.*.tax' => 'digits_between:1,20', + 'items.*.total' => 'digits_between:1,20', ]; if ($this->getMethod() == 'PUT') { diff --git a/app/Http/Requests/ItemsRequest.php b/app/Http/Requests/ItemsRequest.php index 1aa535f3..d24e29ef 100644 --- a/app/Http/Requests/ItemsRequest.php +++ b/app/Http/Requests/ItemsRequest.php @@ -24,7 +24,7 @@ class ItemsRequest extends FormRequest { return [ 'name' => 'required', - 'price' => 'required', + 'price' => 'required|digits_between:1,20', ]; } } diff --git a/app/Http/Requests/PaymentRequest.php b/app/Http/Requests/PaymentRequest.php index 9f326d1d..cc8a9718 100644 --- a/app/Http/Requests/PaymentRequest.php +++ b/app/Http/Requests/PaymentRequest.php @@ -26,7 +26,7 @@ class PaymentRequest extends FormRequest 'payment_date' => 'required', 'payment_number' => 'required|unique:payments,payment_number', 'user_id' => 'required', - 'amount' => 'required', + 'amount' => 'required|digits_between:1,20', ]; if ($this->getMethod() == 'PUT') { diff --git a/app/Http/Requests/ProfileRequest.php b/app/Http/Requests/ProfileRequest.php index 0a9b2e6c..6d96742d 100644 --- a/app/Http/Requests/ProfileRequest.php +++ b/app/Http/Requests/ProfileRequest.php @@ -31,6 +31,8 @@ class ProfileRequest extends FormRequest return [ 'name' => 'required', 'password' => 'required', + 'address_street_1' => 'max:255', + 'address_street_2' => 'max:255', 'email' => [ 'required', 'email', @@ -41,6 +43,8 @@ class ProfileRequest extends FormRequest case 'PUT': return [ 'name' => 'required', + 'address_street_1' => 'max:255', + 'address_street_2' => 'max:255', 'email' => 'required|email' ]; break; diff --git a/database/migrations/2017_04_11_081227_create_items_table.php b/database/migrations/2017_04_11_081227_create_items_table.php index e1041517..f383ff1f 100644 --- a/database/migrations/2017_04_11_081227_create_items_table.php +++ b/database/migrations/2017_04_11_081227_create_items_table.php @@ -18,7 +18,7 @@ class CreateItemsTable extends Migration $table->string('name'); $table->string('description')->nullable(); $table->string('unit')->nullable(); - $table->integer('price'); + $table->unsignedBigInteger('price'); $table->integer('company_id')->unsigned()->nullable(); $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); $table->timestamps(); diff --git a/database/migrations/2017_04_12_090759_create_invoices_table.php b/database/migrations/2017_04_12_090759_create_invoices_table.php index 3f30011c..7089c847 100644 --- a/database/migrations/2017_04_12_090759_create_invoices_table.php +++ b/database/migrations/2017_04_12_090759_create_invoices_table.php @@ -24,13 +24,13 @@ class CreateInvoicesTable extends Migration $table->string('tax_per_item'); $table->string('discount_per_item'); $table->text('notes')->nullable(); - $table->decimal('discount', 15, 0)->nullable(); $table->string('discount_type')->nullable(); - $table->integer('discount_val')->nullable(); - $table->integer('sub_total'); - $table->integer('total'); - $table->integer('tax'); - $table->integer('due_amount'); + $table->unsignedBigInteger('discount')->nullable(); + $table->unsignedBigInteger('discount_val')->nullable(); + $table->unsignedBigInteger('sub_total'); + $table->unsignedBigInteger('total'); + $table->unsignedBigInteger('tax'); + $table->unsignedBigInteger('due_amount'); $table->boolean('sent')->default(false); $table->boolean('viewed')->default(false); $table->string('unique_hash')->nullable(); diff --git a/database/migrations/2017_04_12_091015_create_invoice_items_table.php b/database/migrations/2017_04_12_091015_create_invoice_items_table.php index 343b6a77..26af22bf 100644 --- a/database/migrations/2017_04_12_091015_create_invoice_items_table.php +++ b/database/migrations/2017_04_12_091015_create_invoice_items_table.php @@ -17,13 +17,13 @@ class CreateInvoiceItemsTable extends Migration $table->increments('id'); $table->string('name'); $table->string('description')->nullable(); - $table->integer('quantity'); - $table->integer('price'); $table->string('discount_type'); - $table->integer('discount_val'); - $table->decimal('discount', 15, 0); - $table->integer('tax'); - $table->integer('total'); + $table->unsignedBigInteger('quantity'); + $table->unsignedBigInteger('price'); + $table->unsignedBigInteger('discount_val'); + $table->unsignedBigInteger('discount'); + $table->unsignedBigInteger('tax'); + $table->unsignedBigInteger('total'); $table->integer('invoice_id')->unsigned(); $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); $table->integer('item_id')->unsigned()->nullable(); diff --git a/database/migrations/2017_05_05_055609_create_estimates_table.php b/database/migrations/2017_05_05_055609_create_estimates_table.php index 77c43e68..cfd5b536 100644 --- a/database/migrations/2017_05_05_055609_create_estimates_table.php +++ b/database/migrations/2017_05_05_055609_create_estimates_table.php @@ -23,12 +23,12 @@ class CreateEstimatesTable extends Migration $table->string('tax_per_item'); $table->string('discount_per_item'); $table->string('notes')->nullable(); - $table->decimal('discount', 15, 0)->nullable(); $table->string('discount_type')->nullable(); - $table->integer('discount_val')->nullable(); - $table->integer('sub_total'); - $table->integer('total'); - $table->integer('tax'); + $table->unsignedBigInteger('discount')->nullable(); + $table->unsignedBigInteger('discount_val')->nullable(); + $table->unsignedBigInteger('sub_total'); + $table->unsignedBigInteger('total'); + $table->unsignedBigInteger('tax'); $table->string('unique_hash')->nullable(); $table->integer('user_id')->unsigned()->nullable(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); diff --git a/database/migrations/2017_10_02_123501_create_estimate_items_table.php b/database/migrations/2017_10_02_123501_create_estimate_items_table.php index 400086c6..a2222dcb 100644 --- a/database/migrations/2017_10_02_123501_create_estimate_items_table.php +++ b/database/migrations/2017_10_02_123501_create_estimate_items_table.php @@ -17,13 +17,13 @@ class CreateEstimateItemsTable extends Migration $table->increments('id'); $table->string('name'); $table->string('description')->nullable(); - $table->integer('quantity'); $table->string('discount_type'); - $table->decimal('discount', 15, 0); - $table->integer('discount_val'); - $table->integer('price'); - $table->integer('tax'); - $table->integer('total'); + $table->unsignedBigInteger('quantity'); + $table->unsignedBigInteger('discount'); + $table->unsignedBigInteger('discount_val'); + $table->unsignedBigInteger('price'); + $table->unsignedBigInteger('tax'); + $table->unsignedBigInteger('total'); $table->integer('item_id')->unsigned()->nullable(); $table->foreign('item_id')->references('id')->on('items')->onDelete('cascade'); $table->integer('estimate_id')->unsigned(); diff --git a/database/migrations/2018_11_02_133956_create_expenses_table.php b/database/migrations/2018_11_02_133956_create_expenses_table.php index ae3e1f2c..25912644 100644 --- a/database/migrations/2018_11_02_133956_create_expenses_table.php +++ b/database/migrations/2018_11_02_133956_create_expenses_table.php @@ -17,7 +17,7 @@ class CreateExpensesTable extends Migration $table->increments('id'); $table->date('expense_date'); $table->string('attachment_receipt')->nullable(); - $table->integer('amount'); + $table->unsignedBigInteger('amount'); $table->string('notes')->nullable(); $table->integer('expense_category_id')->unsigned(); $table->foreign('expense_category_id')->references('id')->on('expense_categories')->onDelete('cascade'); diff --git a/database/migrations/2019_09_03_135234_create_payments_table.php b/database/migrations/2019_09_03_135234_create_payments_table.php index 7797905c..d34af4f2 100644 --- a/database/migrations/2019_09_03_135234_create_payments_table.php +++ b/database/migrations/2019_09_03_135234_create_payments_table.php @@ -19,7 +19,7 @@ class CreatePaymentsTable extends Migration $table->string('payment_mode')->nullable(); $table->date('payment_date'); $table->text('notes')->nullable(); - $table->decimal('amount', 15, 0); + $table->unsignedBigInteger('amount'); $table->integer('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->integer('invoice_id')->unsigned()->nullable(); diff --git a/database/migrations/2019_09_21_052548_create_taxes_table.php b/database/migrations/2019_09_21_052548_create_taxes_table.php index 56622267..f5ae90f9 100644 --- a/database/migrations/2019_09_21_052548_create_taxes_table.php +++ b/database/migrations/2019_09_21_052548_create_taxes_table.php @@ -30,7 +30,7 @@ class CreateTaxesTable extends Migration $table->integer('company_id')->unsigned()->nullable(); $table->foreign('company_id')->references('id')->on('companies'); $table->string('name'); - $table->decimal('amount', 15, 0); + $table->unsignedBigInteger('amount'); $table->decimal('percent', 5, 2); $table->tinyInteger('compound_tax')->default(0); $table->timestamps(); diff --git a/database/seeds/EstimateTemplateSeeder.php b/database/seeds/EstimateTemplateSeeder.php index 63263e17..13219dc9 100644 --- a/database/seeds/EstimateTemplateSeeder.php +++ b/database/seeds/EstimateTemplateSeeder.php @@ -13,19 +13,19 @@ class EstimateTemplateSeeder extends Seeder public function run() { EstimateTemplate::create([ - 'name' => 'Estimate Template1', + 'name' => 'Template 1', 'view' => 'estimate1', 'path' => '/assets/img/PDF/Template1.png' ]); EstimateTemplate::create([ - 'name' => 'Estimate Template2', + 'name' => 'Template 2', 'view' => 'estimate2', 'path' => '/assets/img/PDF/Template2.png' ]); EstimateTemplate::create([ - 'name' => 'Estimate Template3', + 'name' => 'Template 3', 'view' => 'estimate3', 'path' => '/assets/img/PDF/Template3.png' ]); diff --git a/database/seeds/InvoiceTemplateSeeder.php b/database/seeds/InvoiceTemplateSeeder.php index aade6397..b0fcb647 100644 --- a/database/seeds/InvoiceTemplateSeeder.php +++ b/database/seeds/InvoiceTemplateSeeder.php @@ -13,19 +13,19 @@ class InvoiceTemplateSeeder extends Seeder public function run() { InvoiceTemplate::create([ - 'name' => 'Invoice Template1', + 'name' => 'Template 1', 'view' => 'invoice1', 'path' => '/assets/img/PDF/Template1.png' ]); InvoiceTemplate::create([ - 'name' => 'Invoice Template2', + 'name' => ' Template 2', 'view' => 'invoice2', 'path' => '/assets/img/PDF/Template2.png' ]); InvoiceTemplate::create([ - 'name' => 'Invoice Template3', + 'name' => 'Template 3', 'view' => 'invoice3', 'path' => '/assets/img/PDF/Template3.png' ]);