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

@ -3,7 +3,6 @@
namespace Database\Factories;
use Crater\Models\Estimate;
use Crater\Models\EstimateTemplate;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
@ -76,7 +75,7 @@ class EstimateFactory extends Factory
'company_id' => User::where('role', 'super admin')->first()->company_id,
'user_id' => User::factory()->create(['role' => 'customer'])->id,
'status' => Estimate::STATUS_DRAFT,
'estimate_template_id' => EstimateTemplate::find(1) ?? EstimateTemplate::factory(),
'template_name' => 'estimate1',
'sub_total' => $this->faker->randomDigitNotNull,
'total' => $this->faker->randomDigitNotNull,
'discount_type' => $this->faker->randomElement(['percentage', 'fixed']),

View File

@ -1,30 +0,0 @@
<?php
namespace Database\Factories;
use Crater\Models\EstimateTemplate;
use Illuminate\Database\Eloquent\Factories\Factory;
class EstimateTemplateFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = EstimateTemplate::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'path' => $this->faker->word,
'view' => $this->faker->word,
'name' => $this->faker->word,
];
}
}

View File

@ -3,7 +3,6 @@
namespace Database\Factories;
use Crater\Models\Invoice;
use Crater\Models\InvoiceTemplate;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
@ -101,7 +100,7 @@ class InvoiceFactory extends Factory
'invoice_number' => 'INV-'.Invoice::getNextInvoiceNumber('INV'),
'reference_number' => Invoice::getNextInvoiceNumber('INV'),
'user_id' => User::factory()->create(['role' => 'customer'])->id,
'invoice_template_id' => InvoiceTemplate::find(1) ?? InvoiceTemplate::factory(),
'template_name' => 'invoice1',
'status' => Invoice::STATUS_DRAFT,
'tax_per_item' => 'NO',
'discount_per_item' => 'NO',

View File

@ -1,30 +0,0 @@
<?php
namespace Database\Factories;
use Crater\Models\InvoiceTemplate;
use Illuminate\Database\Eloquent\Factories\Factory;
class InvoiceTemplateFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = InvoiceTemplate::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'path' => $this->faker->word,
'view' => $this->faker->word,
'name' => $this->faker->word,
];
}
}

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()
{
//
}
}

View File

@ -17,8 +17,6 @@ class DatabaseSeeder extends Seeder
$this->call(CurrenciesTableSeeder::class);
$this->call(DefaultSettingsSeeder::class);
$this->call(CountriesTableSeeder::class);
$this->call(EstimateTemplateSeeder::class);
$this->call(InvoiceTemplateSeeder::class);
$this->call(PaymentMethodSeeder::class);
$this->call(UnitSeeder::class);
}

View File

@ -1,35 +0,0 @@
<?php
namespace Database\Seeders;
use Crater\Models\EstimateTemplate;
use Illuminate\Database\Seeder;
class EstimateTemplateSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
EstimateTemplate::create([
'name' => 'Template 1',
'view' => 'estimate1',
'path' => '/assets/img/PDF/Template1.png',
]);
EstimateTemplate::create([
'name' => 'Template 2',
'view' => 'estimate2',
'path' => '/assets/img/PDF/Template2.png',
]);
EstimateTemplate::create([
'name' => 'Template 3',
'view' => 'estimate3',
'path' => '/assets/img/PDF/Template3.png',
]);
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace Database\Seeders;
use Crater\Models\InvoiceTemplate;
use Illuminate\Database\Seeder;
class InvoiceTemplateSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
InvoiceTemplate::create([
'name' => 'Template 1',
'view' => 'invoice1',
'path' => '/assets/img/PDF/Template1.png',
]);
InvoiceTemplate::create([
'name' => ' Template 2',
'view' => 'invoice2',
'path' => '/assets/img/PDF/Template2.png',
]);
InvoiceTemplate::create([
'name' => 'Template 3',
'view' => 'invoice3',
'path' => '/assets/img/PDF/Template3.png',
]);
}
}