From 9b9761aa5abbd7debf1f681744441d46771f8625 Mon Sep 17 00:00:00 2001 From: raishvaria Date: Wed, 4 Dec 2019 16:38:25 +0530 Subject: [PATCH] refactor invoice & estimate migrations --- app/Invoice.php | 2 +- app/Listeners/Updates/v2/Version201.php | 25 +++++++++++++++++++ ...017_04_12_090759_create_invoices_table.php | 2 +- ...4_12_091015_create_invoice_items_table.php | 4 +-- ...17_05_05_055609_create_estimates_table.php | 2 +- ..._02_123501_create_estimate_items_table.php | 6 ++--- resources/assets/js/views/invoices/View.vue | 2 +- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/Invoice.php b/app/Invoice.php index acf8de53..ac578015 100644 --- a/app/Invoice.php +++ b/app/Invoice.php @@ -82,7 +82,7 @@ class Invoice extends Model // So the substr returns this 000001 // Add the string in front and higher up the number. - // the %05d part makes sure that there are always 6 numbers in the string. + // the %06d part makes sure that there are always 6 numbers in the string. // so it adds the missing zero's when needed. return sprintf('%06d', intval($number) + 1); diff --git a/app/Listeners/Updates/v2/Version201.php b/app/Listeners/Updates/v2/Version201.php index 0eb1a341..25a4ad82 100644 --- a/app/Listeners/Updates/v2/Version201.php +++ b/app/Listeners/Updates/v2/Version201.php @@ -4,6 +4,7 @@ namespace Crater\Listeners\Updates\v2; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Database\Schema\Blueprint; use Crater\Events\UpdateFinished; use Crater\Listeners\Updates\Listener; use Crater\Setting; @@ -37,6 +38,9 @@ class Version201 extends Listener // Remove the language files $this->removeLanguageFiles(); + // Change estimate & invoice migrations + $this->changeMigrations(); + // Update Crater app version Setting::setSetting('version', static::VERSION); } @@ -58,4 +62,25 @@ class Version201 extends Listener unlink($fr); } } + + private function changeMigrations() + { + \Schema::table('invoices', function (Blueprint $table) { + $table->decimal('quantity', 15, 2)->change(); + $table->decimal('discount', 15, 2)->nullable()->change(); + }); + \Schema::table('estimates', function (Blueprint $table) { + $table->decimal('quantity', 15, 2)->change(); + $table->decimal('discount', 15, 2)->nullable()->change(); + }); + \Schema::table('invoice_items', function (Blueprint $table) { + $table->decimal('quantity', 15, 2)->change(); + $table->decimal('discount', 15, 2)->nullable()->change(); + }); + \Schema::table('estimate_items', function (Blueprint $table) { + $table->decimal('quantity', 15, 2)->change(); + $table->decimal('discount', 15, 2)->nullable()->change(); + $table->unsignedBigInteger('discount_val')->nullable()->change(); + }); + } } 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 7089c847..93151370 100644 --- a/database/migrations/2017_04_12_090759_create_invoices_table.php +++ b/database/migrations/2017_04_12_090759_create_invoices_table.php @@ -25,7 +25,7 @@ class CreateInvoicesTable extends Migration $table->string('discount_per_item'); $table->text('notes')->nullable(); $table->string('discount_type')->nullable(); - $table->unsignedBigInteger('discount')->nullable(); + $table->decimal('discount', 15, 2)->nullable(); $table->unsignedBigInteger('discount_val')->nullable(); $table->unsignedBigInteger('sub_total'); $table->unsignedBigInteger('total'); 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 26af22bf..4edc65a9 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 @@ -18,10 +18,10 @@ class CreateInvoiceItemsTable extends Migration $table->string('name'); $table->string('description')->nullable(); $table->string('discount_type'); - $table->unsignedBigInteger('quantity'); $table->unsignedBigInteger('price'); + $table->decimal('quantity', 15, 2); + $table->decimal('discount', 15, 2)->nullable(); $table->unsignedBigInteger('discount_val'); - $table->unsignedBigInteger('discount'); $table->unsignedBigInteger('tax'); $table->unsignedBigInteger('total'); $table->integer('invoice_id')->unsigned(); 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 cfd5b536..d7970fa8 100644 --- a/database/migrations/2017_05_05_055609_create_estimates_table.php +++ b/database/migrations/2017_05_05_055609_create_estimates_table.php @@ -23,8 +23,8 @@ class CreateEstimatesTable extends Migration $table->string('tax_per_item'); $table->string('discount_per_item'); $table->string('notes')->nullable(); + $table->decimal('discount', 15, 2)->nullable(); $table->string('discount_type')->nullable(); - $table->unsignedBigInteger('discount')->nullable(); $table->unsignedBigInteger('discount_val')->nullable(); $table->unsignedBigInteger('sub_total'); $table->unsignedBigInteger('total'); 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 a2222dcb..5d059886 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 @@ -18,9 +18,9 @@ class CreateEstimateItemsTable extends Migration $table->string('name'); $table->string('description')->nullable(); $table->string('discount_type'); - $table->unsignedBigInteger('quantity'); - $table->unsignedBigInteger('discount'); - $table->unsignedBigInteger('discount_val'); + $table->decimal('quantity', 15, 2); + $table->decimal('discount', 15, 2)->nullable(); + $table->unsignedBigInteger('discount_val')->nullable(); $table->unsignedBigInteger('price'); $table->unsignedBigInteger('tax'); $table->unsignedBigInteger('total'); diff --git a/resources/assets/js/views/invoices/View.vue b/resources/assets/js/views/invoices/View.vue index 5643e2f4..be415123 100644 --- a/resources/assets/js/views/invoices/View.vue +++ b/resources/assets/js/views/invoices/View.vue @@ -286,7 +286,7 @@ export default { let request = await this.deleteInvoice(this.id) if (request.data.success) { window.toastr['success'](this.$tc('invoices.deleted_message', 1)) - this.$router.push('/admin/invoices/') + this.$router.push('/admin/invoices') } else if (request.data.error) { window.toastr['error'](request.data.message) }