Add File based templates

This commit is contained in:
gohil jayvirsinh
2021-06-19 12:11:21 +00:00
committed by Mohit Panjwani
parent 00961bcae1
commit d1dd704cdf
58 changed files with 277 additions and 382 deletions

View File

@ -34,8 +34,6 @@ class CreateInvoicesTable extends Migration
$table->boolean('sent')->default(false);
$table->boolean('viewed')->default(false);
$table->string('unique_hash')->nullable();
$table->integer('invoice_template_id')->unsigned()->nullable();
$table->foreign('invoice_template_id')->references('id')->on('invoice_templates');
$table->integer('user_id')->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('company_id')->unsigned()->nullable();

View File

@ -32,8 +32,6 @@ class CreateEstimatesTable extends Migration
$table->string('unique_hash')->nullable();
$table->integer('user_id')->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('estimate_template_id')->unsigned()->nullable();
$table->foreign('estimate_template_id')->references('id')->on('estimate_templates');
$table->integer('company_id')->unsigned()->nullable();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->timestamps();

View File

@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateInvoiceTemplatesTable extends Migration
class AddTemplateNameToInvoicesTable extends Migration
{
/**
* Run the migrations.
@ -13,12 +13,8 @@ class CreateInvoiceTemplatesTable extends Migration
*/
public function up()
{
Schema::create('invoice_templates', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('view');
$table->string('path');
$table->timestamps();
Schema::table('invoices', function (Blueprint $table) {
$table->string('template_name')->nullable();
});
}
@ -29,6 +25,8 @@ class CreateInvoiceTemplatesTable extends Migration
*/
public function down()
{
Schema::dropIfExists('invoice_templates');
Schema::table('invoices', function (Blueprint $table) {
$table->dropColumn('template_name');
});
}
}

View File

@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEstimateTemplatesTable extends Migration
class AddTemplateNameToEstimatesTable extends Migration
{
/**
* Run the migrations.
@ -13,12 +13,8 @@ class CreateEstimateTemplatesTable extends Migration
*/
public function up()
{
Schema::create('estimate_templates', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('view');
$table->string('path');
$table->timestamps();
Schema::table('estimates', function (Blueprint $table) {
$table->string('template_name')->nullable();
});
}
@ -29,6 +25,8 @@ class CreateEstimateTemplatesTable extends Migration
*/
public function down()
{
Schema::dropIfExists('estimate_templates');
Schema::table('estimates', function (Blueprint $table) {
$table->dropColumn('template_name');
});
}
}

View File

@ -0,0 +1,61 @@
<?php
use Crater\Models\Estimate;
use Crater\Models\Invoice;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class RemoveTemplateIdFromInvoicesAndEstimatesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasColumn('invoices', 'invoice_template_id'))
{
$invoices = Invoice::all();
$invoices->map(function ($invoice) {
$invoice->template_name = 'invoice'.$invoice->invoice_template_id;
$invoice->save();
});
Schema::table('invoices', function (Blueprint $table) {
$table->dropForeign(['invoice_template_id']);
$table->dropColumn('invoice_template_id');
});
}
if (Schema::hasColumn('estimates', 'estimate_template_id'))
{
$estimates = Estimate::all();
$estimates->map(function ($estimate) {
$estimate->template_name = 'estimate'.$estimate->estimate_template_id;
$estimate->save();
});
Schema::table('estimates', function (Blueprint $table) {
$table->dropForeign(['estimate_template_id']);
$table->dropColumn('estimate_template_id');
});
}
Schema::dropIfExists('invoice_templates');
Schema::dropIfExists('estimate_templates');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}