build version 400

This commit is contained in:
Mohit Panjwani
2020-12-02 17:54:08 +05:30
parent 326508e567
commit 89ee58590c
963 changed files with 62887 additions and 48868 deletions

View File

@ -1,21 +1,39 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Address;
use Faker\Generator as Faker;
use Crater\Models\Address;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Address::class, function (Faker $faker) {
return [
'name' => $faker->name,
'address_street_1' => $faker->streetAddress,
'address_street_2' => $faker->streetAddress,
'city' => $faker->city,
'state' => $faker->state,
'country_id' => 231,
'zip' => $faker->postcode,
'phone' => $faker->phoneNumber,
'fax' => $faker->phoneNumber,
'type' => Address::BILLING_TYPE
];
});
class AddressFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Address::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'address_street_1' => $this->faker->streetAddress,
'address_street_2' => $this->faker->streetAddress,
'city' => $this->faker->city,
'state' => $this->faker->state,
'country_id' => 231,
'zip' => $this->faker->postcode,
'phone' => $this->faker->phoneNumber,
'fax' => $this->faker->phoneNumber,
'type' => $this->faker->randomElement([Address::BILLING_TYPE, Address::SHIPPING_TYPE]),
'user_id' => User::factory()
];
}
}

View File

@ -1,13 +1,29 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Company;
use Faker\Generator as Faker;
use Crater\Models\Company;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Company::class, function (Faker $faker) {
return [
'unique_hash' => str_random(60),
'name' => $faker->name
];
});
class CompanyFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Company::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'unique_hash' => str_random(60),
'name' => $this->faker->name
];
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Crater\Models\CompanySetting;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class CompanySettingFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = CompanySetting::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'option' => $this->faker->word,
'value' => $this->faker->word,
'company_id' => User::where('role', 'super admin')->first()->company_id,
];
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Database\Factories;
use Crater\Models\CustomField;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class CustomFieldFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = CustomField::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'label' => $this->faker->name,
'order' => $this->faker->randomDigitNotNull,
'is_required' => $this->faker->randomElement([true, false]),
'model_type'=> $this->faker->randomElement(['Customer', 'Invoice', 'Estimate', 'Expense', 'Payment']),
'slug' => function (array $item) {
return clean_slug($item['model_type'], $item['label']);
},
'type' => $this->faker->randomElement(['Text', 'Textarea', 'Phone', 'URL', 'Number','Dropdown' , 'Switch', 'Date', 'DateTime', 'Time']),
'company_id' => User::where('role', 'super admin')->first()->company_id,
];
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Database\Factories;
use Crater\Models\CustomFieldValue;
use Crater\Models\CustomField;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class CustomFieldValueFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = CustomFieldValue::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'custom_field_valuable_type' => $this->faker->name ,
'custom_field_valuable_id' => 1,
'type' => $this->faker->name,
'custom_field_id' => CustomField::factory(),
'company_id' => User::where('role', 'super admin')->first()->company_id,
];
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Database\Factories;
use Crater\Models\EmailLog;
use Crater\Models\Estimate;
use Crater\Models\Invoice;
use Crater\Models\Payment;
use Illuminate\Database\Eloquent\Factories\Factory;
class EmailLogFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = EmailLog::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'from' => $this->faker->unique()->safeEmail,
'to' => $this->faker->unique()->safeEmail,
'subject' => $this->faker->sentence,
'body' => $this->faker->text,
'mailable_type' => $this->faker->randomElement([Invoice::class, Estimate::class, Payment::class]),
'mailable_id' => function (array $log) {
return $log['mailable_type']::factory();
}
];
}
}

View File

@ -1,45 +1,96 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Estimate;
use Crater\User;
use Crater\Tax;
use Faker\Generator as Faker;
use Crater\EstimateItem;
use Crater\EstimateTemplate;
use Crater\Models\Estimate;
use Crater\Models\EstimateTemplate;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Estimate::class, function (Faker $faker) {
return [
'estimate_date' => $faker->date($format = 'Y-m-d', $max = 'now'),
'expiry_date' => $faker->date($format = 'Y-m-d', $max = 'now'),
'estimate_number' => 'EST-'.Estimate::getNextEstimateNumber('EST'),
'reference_number' => Estimate::getNextEstimateNumber('EST'),
'company_id' => User::find(1)->company_id,
'user_id' => function () {
return factory(User::class)->create(['role' => 'customer'])->id;
},
'status' => Estimate::STATUS_DRAFT,
'estimate_template_id' => 1,
'sub_total' => $faker->randomDigitNotNull,
'discount' => 0,
'discount_type' => 'fixed',
'discount_val' => 0,
'tax_per_item' => 'YES',
'discount_per_item' => 'No',
'total' => $faker->randomDigitNotNull,
'tax' => $faker->randomDigitNotNull,
'notes' => $faker->text(80),
'unique_hash' => str_random(60)
];
});
class EstimateFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Estimate::class;
$factory->afterCreating(Estimate::class, function ($estimate, $faker) {
$estimate->items()->save(factory(EstimateItem::class)->make());
$estimate->items()->save(factory(EstimateItem::class)->make());
});
public function sent()
{
return $this->state(function (array $attributes) {
return [
'status' => Estimate::STATUS_SENT,
];
});
}
$factory->afterCreating(Estimate::class, function ($estimate, $faker) {
$estimate->taxes()->save(factory(Tax::class)->make());
$estimate->items()->save(factory(Tax::class)->make());
});
public function viewed()
{
return $this->state(function (array $attributes) {
return [
'status' => Estimate::STATUS_VIEWED,
];
});
}
public function expired()
{
return $this->state(function (array $attributes) {
return [
'status' => Estimate::STATUS_EXPIRED,
];
});
}
public function accepted()
{
return $this->state(function (array $attributes) {
return [
'status' => Estimate::STATUS_ACCEPTED,
];
});
}
public function rejected()
{
return $this->state(function (array $attributes) {
return [
'status' => Estimate::STATUS_REJECTED,
];
});
}
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'estimate_date' => $this->faker->date('Y-m-d', 'now'),
'expiry_date' => $this->faker->date('Y-m-d', 'now'),
'estimate_number' => 'EST-'.Estimate::getNextEstimateNumber('EST'),
'reference_number' => Estimate::getNextEstimateNumber('EST'),
'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(),
'sub_total' => $this->faker->randomDigitNotNull,
'total' => $this->faker->randomDigitNotNull,
'discount_type' => $this->faker->randomElement(['percentage', 'fixed']),
'discount_val' => function (array $estimate) {
return $estimate['discount_type'] == 'percentage' ? $this->faker->numberBetween($min = 0, $max = 100) : $this->faker->randomDigitNotNull;
},
'discount' => function (array $estimate) {
return $estimate['discount_type'] == 'percentage' ? (($estimate['discount_val'] * $estimate['total']) / 100) : $estimate['discount_val'];
},
'tax_per_item' => 'YES',
'discount_per_item' => 'No',
'tax' => $this->faker->randomDigitNotNull,
'notes' => $this->faker->text(80),
'unique_hash' => str_random(60),
];
}
}

View File

@ -1,34 +1,52 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\EstimateItem;
use Crater\Item;
use Faker\Generator as Faker;
use Crater\User;
use Crater\Models\EstimateItem;
use Crater\Models\Item;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(EstimateItem::class, function (Faker $faker) {
return [
'item_id' => function () {
return factory(Item::class)->create()->id;
},
'name' => function (array $item) {
return Item::find($item['item_id'])->name;
},
'description' => function (array $item) {
return Item::find($item['item_id'])->description;
},
'price' => function (array $item) {
return Item::find($item['item_id'])->price;
},
'quantity' => $faker->randomDigitNotNull,
'company_id' => User::find(1)->company_id,
'discount_type' => 'fixed',
'tax' => $faker->randomDigitNotNull,
'discount_val' => 0,
'total' => function (array $item) {
return ($item['price'] * $item['quantity']);
},
'discount' => 0
];
});
class EstimateItemFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = EstimateItem::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'item_id' => Item::factory(),
'name' => function (array $item) {
return Item::find($item['item_id'])->name;
},
'description' => function (array $item) {
return Item::find($item['item_id'])->description;
},
'price' => function (array $item) {
return Item::find($item['item_id'])->price;
},
'quantity' => $this->faker->randomDigitNotNull,
'company_id' => User::where('role', 'super admin')->first()->company_id,
'tax' => $this->faker->randomDigitNotNull,
'total' => function (array $item) {
return ($item['price'] * $item['quantity']);
},
'discount_type' => $this->faker->randomElement(['percentage', 'fixed']),
'discount_val' => function (array $estimate) {
return $estimate['discount_type'] == 'percentage' ? $this->faker->numberBetween($min = 0, $max = 100) : $this->faker->randomDigitNotNull;
},
'discount' => function (array $estimate) {
return $estimate['discount_type'] == 'percentage' ? (($estimate['discount_val'] * $estimate['total']) / 100) : $estimate['discount_val'];
}
];
}
}

View File

@ -1,14 +1,30 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\EstimateTemplate;
use Faker\Generator as Faker;
use Crater\Models\EstimateTemplate;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(EstimateTemplate::class, function (Faker $faker) {
return [
'path' => $faker->word,
'view' => $faker->word,
'name' => $faker->word,
];
});
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

@ -1,15 +1,31 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\ExpenseCategory;
use Faker\Generator as Faker;
use Crater\User;
use Crater\Models\ExpenseCategory;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(ExpenseCategory::class, function (Faker $faker) {
return [
'name' => $faker->word,
'company_id' => User::find(1)->company_id,
'description' => $faker->text
];
});
class ExpenseCategoryFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = ExpenseCategory::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->word,
'company_id' => User::where('role', 'super admin')->first()->company_id,
'description' => $this->faker->text
];
}
}

View File

@ -1,21 +1,35 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Expense;
use Crater\ExpenseCategory;
use Faker\Generator as Faker;
use Crater\User;
use Crater\Models\Expense;
use Crater\Models\User;
use Crater\Models\ExpenseCategory;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Expense::class, function (Faker $faker) {
return [
'expense_date' => $faker->date($format = 'd/m/Y', $max = 'now'),
'expense_category_id' => function () {
return factory(ExpenseCategory::class)->create()->id;
},
'company_id' => User::find(1)->company_id,
'amount' => $faker->randomDigitNotNull,
'notes' => $faker->text,
'attachment_receipt' => null
];
});
class ExpenseFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Expense::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'expense_date' => $this->faker->date('Y-m-d', 'now'),
'expense_category_id' => ExpenseCategory::factory(),
'company_id' => User::where('role', 'super admin')->first()->company_id,
'amount' => $this->faker->randomDigitNotNull,
'notes' => $this->faker->text,
'attachment_receipt' => null
];
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace Database\Factories;
use Crater\Models\FileDisk;
use Illuminate\Database\Eloquent\Factories\Factory;
class FileDiskFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = FileDisk::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->word,
'driver' => 'local',
'set_as_default' => false,
'credentials' => [
'driver' => 'local',
'root' => storage_path('app'),
]
];
}
}

View File

@ -1,49 +1,127 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Invoice;
use Crater\User;
use Crater\Tax;
use Crater\InvoiceItem;
use Crater\InvoiceTemplate;
use Faker\Generator as Faker;
use Crater\Models\Invoice;
use Crater\Models\User;
use Crater\Models\InvoiceTemplate;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Invoice::class, function (Faker $faker) {
return [
'invoice_date' => $faker->date($format = 'Y-m-d', $max = 'now'),
'due_date' => $faker->date($format = 'Y-m-d', $max = 'now'),
'invoice_number' => 'INV-'.Invoice::getNextInvoiceNumber('INV'),
'reference_number' => Invoice::getNextInvoiceNumber('INV'),
'user_id' => function () {
return factory(User::class)->create(['role' => 'customer'])->id;
},
'invoice_template_id' => 1,
'status' => Invoice::STATUS_DRAFT,
'tax_per_item' => 'NO',
'discount_per_item' => 'NO',
'paid_status' => Invoice::STATUS_UNPAID,
'company_id' => User::find(1)->company_id,
'sub_total' => $faker->randomDigitNotNull,
'discount' => 0,
'discount_type' => 'fixed',
'discount_val' => 0,
'total' => $faker->randomDigitNotNull,
'tax' => $faker->randomDigitNotNull,
'due_amount' => function (array $invoice) {
return $invoice['total'];
},
'notes' => $faker->text(80),
'unique_hash' => str_random(60)
];
});
class InvoiceFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Invoice::class;
$factory->afterCreating(Invoice::class, function ($invoice, $faker) {
$invoice->items()->save(factory(InvoiceItem::class)->make());
$invoice->items()->save(factory(InvoiceItem::class)->make());
});
public function sent()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_SENT,
];
});
}
$factory->afterCreating(Invoice::class, function ($invoice, $faker) {
$invoice->taxes()->save(factory(Tax::class)->make());
$invoice->items()->save(factory(Tax::class)->make());
});
public function viewed()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_VIEWED,
];
});
}
public function overdue()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_OVERDUE,
];
});
}
public function completed()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_COMPLETED,
];
});
}
public function due()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_DUE,
];
});
}
public function unpaid()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_UNPAID,
];
});
}
public function partiallyPaid()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_PARTIALLY_PAID,
];
});
}
public function paid()
{
return $this->state(function (array $attributes) {
return [
'status' => Invoice::STATUS_PAID,
];
});
}
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'invoice_date' => $this->faker->date('Y-m-d', 'now'),
'due_date' => $this->faker->date('Y-m-d', 'now'),
'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(),
'status' => Invoice::STATUS_DRAFT,
'tax_per_item' => 'NO',
'discount_per_item' => 'NO',
'paid_status' => Invoice::STATUS_UNPAID,
'company_id' => User::where('role', 'super admin')->first()->company_id,
'sub_total' => $this->faker->randomDigitNotNull,
'total' => $this->faker->randomDigitNotNull,
'discount_type' => $this->faker->randomElement(['percentage', 'fixed']),
'discount_val' => function (array $invoice) {
return $invoice['discount_type'] == 'percentage' ? $this->faker->numberBetween($min = 0, $max = 100) : $this->faker->randomDigitNotNull;
},
'discount' => function (array $invoice) {
return $invoice['discount_type'] == 'percentage' ? (($invoice['discount_val'] * $invoice['total']) / 100) : $invoice['discount_val'];
},
'tax' => $this->faker->randomDigitNotNull,
'due_amount' => function (array $invoice) {
return $invoice['total'];
},
'notes' => $this->faker->text(80),
'unique_hash' => str_random(60)
];
}
}

View File

@ -1,34 +1,52 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\InvoiceItem;
use Crater\Item;
use Faker\Generator as Faker;
use Crater\User;
use Crater\Models\InvoiceItem;
use Crater\Models\Item;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(InvoiceItem::class, function (Faker $faker) {
return [
'item_id' => function () {
return factory(Item::class)->create()->id;
},
'name' => function (array $item) {
return Item::find($item['item_id'])->name;
},
'description' => function (array $item) {
return Item::find($item['item_id'])->description;
},
'price' => function (array $item) {
return Item::find($item['item_id'])->price;
},
'company_id' => User::find(1)->company_id,
'quantity' => $faker->randomDigitNotNull,
'discount_type' => 'fixed',
'discount_val' => 0,
'tax' => $faker->randomDigitNotNull,
'total' => function (array $item) {
return ($item['price'] * $item['quantity']);
},
'discount' => 0
];
});
class InvoiceItemFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = InvoiceItem::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'item_id' => Item::factory(),
'name' => function (array $item) {
return Item::find($item['item_id'])->name;
},
'description' => function (array $item) {
return Item::find($item['item_id'])->description;
},
'price' => function (array $item) {
return Item::find($item['item_id'])->price;
},
'company_id' => User::where('role', 'super admin')->first()->company_id,
'quantity' => $this->faker->randomDigitNotNull,
'total' => function (array $item) {
return ($item['price'] * $item['quantity']);
},
'discount_type' => $this->faker->randomElement(['percentage', 'fixed']),
'discount_val' => function (array $invoice) {
return $invoice['discount_type'] == 'percentage' ? $this->faker->numberBetween($min = 0, $max = 100) : $this->faker->randomDigitNotNull;
},
'discount' => function (array $invoice) {
return $invoice['discount_type'] == 'percentage' ? (($invoice['discount_val'] * $invoice['total']) / 100) : $invoice['discount_val'];
},
'tax' => $this->faker->randomDigitNotNull,
];
}
}

View File

@ -1,14 +1,30 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\InvoiceTemplate;
use Faker\Generator as Faker;
use Crater\Models\InvoiceTemplate;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(InvoiceTemplate::class, function (Faker $faker) {
return [
'path' => $faker->word,
'view' => $faker->word,
'name' => $faker->word,
];
});
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

@ -1,23 +1,34 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Item;
use Crater\Tax;
use Faker\Generator as Faker;
use Crater\User;
use Crater\Models\Item;
use Crater\Models\User;
use Crater\Models\Unit;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Item::class, function (Faker $faker) {
return [
'name' => $faker->name,
'description' => $faker->text,
'company_id' => User::find(1)->company_id,
'price' => $faker->randomDigitNotNull,
'unit' => 'kg'
];
});
class ItemFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Item::class;
$factory->afterCreating(Item::class, function ($item, $faker) {
$item->taxes()->save(factory(Tax::class)->make());
$item->taxes()->save(factory(Tax::class)->make());
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'description' => $this->faker->text,
'company_id' => User::where('role', 'super admin')->first()->company_id,
'price' => $this->faker->randomDigitNotNull,
'unit_id' => Unit::factory()
];
}
}

View File

@ -1,40 +0,0 @@
<?php
use Illuminate\Support\Facades\Hash;
use Crater\Address;
use Crater\User;
use Crater\Currency;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(User::class, function (Faker\Generator $faker) {
static $password;
return [
'name' => $faker->name,
'company_name' => $faker->company,
'contact_name' => $faker->name,
'website' => $faker->url,
'enable_portal' => true,
'email' => $faker->unique()->safeEmail,
'phone' => $faker->phoneNumber,
'company_id' => User::find(1)->company_id,
'role' => 'admin',
'password' => $password ?: $password = Hash::make('secret'),
'remember_token' => str_random(10),
'currency_id' => Currency::first()->id
];
});
$factory->afterCreating(User::class, function ($user, $faker) {
$user->addresses()->save(factory(Address::class)->make());
$user->addresses()->save(factory(Address::class)->make(['type' => Address::SHIPPING_TYPE]));
});

View File

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

View File

@ -1,22 +1,34 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Payment;
use Crater\PaymentMethod;
use Crater\User;
use Crater\Invoice;
use Faker\Generator as Faker;
use Crater\Models\Payment;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Payment::class, function (Faker $faker) {
return [
'user_id' => function () {
return factory(User::class)->create(['role' => 'customer'])->id;
},
'payment_date' => $faker->date($format = 'Y-m-d', $max = 'now'),
'company_id' => User::find(1)->company_id,
'notes' => $faker->text(80),
'amount' => $faker->randomDigitNotNull,
'payment_number' => 'PAY-'.Payment::getNextPaymentNumber('PAY'),
];
});
class PaymentFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Payment::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'user_id' => User::factory()->create(['role' => 'customer'])->id,
'company_id' => User::where('role', 'super admin')->first()->company_id,
'payment_date' => $this->faker->date('Y-m-d', 'now'),
'notes' => $this->faker->text(80),
'amount' => $this->faker->randomDigitNotNull,
'payment_number' => 'PAY-' . Payment::getNextPaymentNumber('PAY'),
];
}
}

View File

@ -1,14 +1,30 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\PaymentMethod;
use Crater\User;
use Faker\Generator as Faker;
use Crater\Models\PaymentMethod;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(PaymentMethod::class, function (Faker $faker) {
return [
'name' => $faker->name,
'company_id' => User::find(1)->company_id,
];
});
class PaymentMethodFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = PaymentMethod::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'company_id' => User::where('role', 'super admin')->first()->company_id,
];
}
}

View File

@ -1,24 +1,38 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\Tax;
use Crater\TaxType;
use Faker\Generator as Faker;
use Crater\User;
use Crater\Models\Tax;
use Crater\Models\TaxType;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Tax::class, function (Faker $faker) {
return [
'tax_type_id' => function () {
return factory(TaxType::class)->create()->id;
},
'percent' => function (array $item) {
return TaxType::find($item['tax_type_id'])->percent;
},
'name' => function (array $item) {
return TaxType::find($item['tax_type_id'])->name;
},
'company_id' => User::find(1)->company_id,
'amount' => $faker->randomDigitNotNull
];
});
class TaxFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Tax::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'tax_type_id' => TaxType::factory(),
'percent' => function (array $item) {
return TaxType::find($item['tax_type_id'])->percent;
},
'name' => function (array $item) {
return TaxType::find($item['tax_type_id'])->name;
},
'company_id' => User::where('role', 'super admin')->first()->company_id,
'amount' => $this->faker->randomDigitNotNull
];
}
}

View File

@ -1,18 +1,34 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use Crater\TaxType;
use Faker\Generator as Faker;
use Crater\User;
use Crater\Models\TaxType;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(TaxType::class, function (Faker $faker) {
return [
'name' => $faker->word,
'company_id' => User::find(1)->company_id,
'percent' => $faker->randomDigitNotNull,
'description' => $faker->text,
'compound_tax' => 0,
'collective_tax' => 0
];
});
class TaxTypeFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = TaxType::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->word,
'company_id' => User::where('role','super admin')->first()->company_id,
'percent' => $this->faker->numberBetween($min = 0, $max = 100),
'description' => $this->faker->text,
'compound_tax' => 0,
'collective_tax' => 0
];
}
}

View File

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

View File

@ -0,0 +1,40 @@
<?php
namespace Database\Factories;
use Crater\Models\Currency;
use Crater\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'company_name' => $this->faker->company,
'contact_name' => $this->faker->name,
'website' => $this->faker->url,
'enable_portal' => true,
'email' => $this->faker->unique()->safeEmail,
'phone' => $this->faker->phoneNumber,
'company_id' => User::find(1)->company_id,
'role' => 'super admin',
'password' => Hash::make('secret'),
'currency_id' => Currency::first()->id
];
}
}

View File

@ -1,7 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePasswordResetsTable extends Migration
{
@ -14,7 +15,7 @@ class CreatePasswordResetsTable extends Migration
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}

View File

@ -1,90 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreatePermissionTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$tableNames = config('permission.table_names');
Schema::create($tableNames['permissions'], function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('guard_name');
$table->timestamps();
});
Schema::create($tableNames['roles'], function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('guard_name');
$table->timestamps();
});
Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames) {
$table->integer('permission_id')->unsigned();
$table->morphs('model');
$table->foreign('permission_id')
->references('id')
->on($tableNames['permissions'])
->onDelete('cascade');
$table->primary(['permission_id', 'model_id', 'model_type']);
});
Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames) {
$table->integer('role_id')->unsigned();
$table->morphs('model');
$table->foreign('role_id')
->references('id')
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary(['role_id', 'model_id', 'model_type']);
});
Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('permission_id')
->references('id')
->on($tableNames['permissions'])
->onDelete('cascade');
$table->foreign('role_id')
->references('id')
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary(['permission_id', 'role_id']);
Cache::forget('spatie.permission.cache');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$tableNames = config('permission.table_names');
Schema::drop($tableNames['role_has_permissions']);
Schema::drop($tableNames['model_has_roles']);
Schema::drop($tableNames['model_has_permissions']);
Schema::drop($tableNames['roles']);
Schema::drop($tableNames['permissions']);
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePersonalAccessTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->bigIncrements('id');
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('personal_access_tokens');
}
}

View File

@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCustomFieldsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('custom_fields', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('slug');
$table->string('label');
$table->string('model_type');
$table->string('type');
$table->string('placeholder')->nullable();
$table->json('options')->nullable();
$table->boolean('boolean_answer')->nullable();
$table->date('date_answer')->nullable();
$table->time('time_answer')->nullable();
$table->text('string_answer')->nullable();
$table->unsignedBigInteger('number_answer')->nullable();
$table->dateTime('date_time_answer')->nullable();
$table->boolean('is_required')->default(false);
$table->unsignedBigInteger('order')->default(1);
$table->integer('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('custom_fields');
}
}

View File

@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCustomFieldValuesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('custom_field_values', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('custom_field_valuable_type');
$table->unsignedInteger('custom_field_valuable_id');
$table->string('type');
$table->boolean('boolean_answer')->nullable();
$table->date('date_answer')->nullable();
$table->time('time_answer')->nullable();
$table->text('string_answer')->nullable();
$table->unsignedBigInteger('number_answer')->nullable();
$table->dateTime('date_time_answer')->nullable();
$table->unsignedBigInteger('custom_field_id');
$table->foreign('custom_field_id')->references('id')->on('custom_fields');
$table->integer('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('answers');
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFileDisksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('file_disks', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('type')->default('REMOTE');
$table->string('driver');
$table->boolean('set_as_default')->default(false);
$table->json('credentials');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('file_disks');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddColumnsToMediaTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('media', function (Blueprint $table) {
$table->uuid('uuid')->nullable();
$table->string('conversions_disk')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('media', function (Blueprint $table) {
$table->dropColumn('uuid');
$table->dropColumn('conversions_disk');
});
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUserSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_settings', function (Blueprint $table) {
$table->id();
$table->string('key');
$table->text('value');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_settings');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCompanyToAddressesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('addresses', function (Blueprint $table) {
$table->integer('user_id')->unsigned()->nullable()->change();
$table->unsignedInteger('company_id')->nullable();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('addresses', function (Blueprint $table) {
$table->dropForeign(['company_id']);
});
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateNotesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notes', function (Blueprint $table) {
$table->id();
$table->string('type');
$table->string('name');
$table->text('notes');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notes');
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ChangeValueColumnToTextOnCompanySettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('company_settings', function (Blueprint $table) {
$table->text('value')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('company_settings', function (Blueprint $table) {
$table->string('value')->change();
});
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCreatorInInvoicesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('invoices', function (Blueprint $table) {
$table->unsignedInteger('creator_id')->nullable();
$table->foreign('creator_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('invoices', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
});
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCreatorInEstimatesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('estimates', function (Blueprint $table) {
$table->unsignedInteger('creator_id')->nullable();
$table->foreign('creator_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('estimates', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
});
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCreatorInPaymentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('payments', function (Blueprint $table) {
$table->unsignedInteger('creator_id')->nullable();
$table->foreign('creator_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('payments', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
});
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCreatorInExpensesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('expenses', function (Blueprint $table) {
$table->unsignedInteger('creator_id')->nullable();
$table->foreign('creator_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('expenses', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
});
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCreatorInItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('items', function (Blueprint $table) {
$table->unsignedInteger('creator_id')->nullable();
$table->foreign('creator_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('items', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
});
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCreatorInUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->unsignedInteger('creator_id')->nullable();
$table->foreign('creator_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
});
}
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEmailLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('email_logs', function (Blueprint $table) {
$table->id();
$table->string('from');
$table->string('to');
$table->string('subject');
$table->text('body');
$table->string('mailable_type');
$table->string('mailable_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('email_logs');
}
}

View File

@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Crater\Setting;
use Crater\Models\Setting;
class UpdateCraterVersion320 extends Migration
{

View File

@ -0,0 +1,138 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Crater\Models\CompanySetting;
use Crater\Models\Estimate;
use Crater\Models\Expense;
use Crater\Models\Invoice;
use Crater\Models\Item;
use Crater\Models\Payment;
use Crater\Models\Setting;
use Crater\Models\FileDisk;
use Crater\Models\User;
class UpdateCraterVersion400 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// seed the file disk
$this->fileDiskSeed();
Setting::setSetting('version', '4.0.0');
$user = User::where('role', 'admin')->first();
if ($user && $user->role == 'admin') {
$user->update([
'role' => 'super admin'
]);
// Update language
$user->setSettings(['language' => CompanySetting::getSetting('language', $user->company_id)]);
// Update user's addresses
if ($user->addresses()->exists()) {
foreach ($user->addresses as $address) {
$address->company_id = $user->company_id;
$address->user_id = null;
$address->save();
}
}
// Update company settings
$this->updateCompanySettings($user);
// Update Creator
$this->updateCreatorId($user);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
private function fileDiskSeed()
{
$privateDisk = [
'root' => config('filesystems.disks.local.root'),
'driver' => 'local',
];
$publicDisk = [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
];
FileDisk::create([
'credentials' => json_encode($publicDisk),
'name'=> 'local_public',
'type'=> 'SYSTEM',
'driver' => 'local',
'set_as_default' => false,
]);
FileDisk::create([
'credentials' => json_encode($privateDisk),
'name'=> 'local_private',
'type'=> 'SYSTEM',
'driver' => 'local',
'set_as_default' => true,
]);
}
private function updateCreatorId($user)
{
Invoice::where('company_id', '<>', null)->update(['creator_id' => $user->id]);
Estimate::where('company_id', '<>', null)->update(['creator_id' => $user->id]);
Expense::where('company_id', '<>', null)->update(['creator_id' => $user->id]);
Payment::where('company_id', '<>', null)->update(['creator_id' => $user->id]);
Item::where('company_id', '<>', null)->update(['creator_id' => $user->id]);
User::where('role', 'customer')->update(['creator_id' => $user->id]);
}
private function updateCompanySettings($user)
{
$defaultInvoiceEmailBody = 'You have received a new invoice from <b>{COMPANY_NAME}</b>.</br>Please download using the button below:';
$defaultEstimateEmailBody = 'You have received a new estimate from <b>{COMPANY_NAME}</b>.</br>Please download using the button below:';
$defaultPaymentEmailBody = 'Thank you for the payment.</b></br>Please download your payment receipt using the button below:';
$billingAddressFormat = '<h3>{BILLING_ADDRESS_NAME}</h3><p>{BILLING_ADDRESS_STREET_1}</p><p>{BILLING_ADDRESS_STREET_2}</p><p>{BILLING_CITY} {BILLING_STATE}</p><p>{BILLING_COUNTRY} {BILLING_ZIP_CODE}</p><p>{BILLING_PHONE}</p>';
$shippingAddressFormat = '<h3>{SHIPPING_ADDRESS_NAME}</h3><p>{SHIPPING_ADDRESS_STREET_1}</p><p>{SHIPPING_ADDRESS_STREET_2}</p><p>{SHIPPING_CITY} {SHIPPING_STATE}</p><p>{SHIPPING_COUNTRY} {SHIPPING_ZIP_CODE}</p><p>{SHIPPING_PHONE}</p>';
$companyAddressFormat = '<h3><strong>{COMPANY_NAME}</strong></h3><p>{COMPANY_ADDRESS_STREET_1}</p><p>{COMPANY_ADDRESS_STREET_2}</p><p>{COMPANY_CITY} {COMPANY_STATE}</p><p>{COMPANY_COUNTRY} {COMPANY_ZIP_CODE}</p><p>{COMPANY_PHONE}</p>';
$paymentFromCustomerAddress = '<h3>{BILLING_ADDRESS_NAME}</h3><p>{BILLING_ADDRESS_STREET_1}</p><p>{BILLING_ADDRESS_STREET_2}</p><p>{BILLING_CITY} {BILLING_STATE} {BILLING_ZIP_CODE}</p><p>{BILLING_COUNTRY}</p><p>{BILLING_PHONE}</p>';
$settings = [
'invoice_auto_generate' => 'YES',
'payment_auto_generate' => 'YES',
'estimate_auto_generate' => 'YES',
'save_pdf_to_disk' => 'NO',
'invoice_mail_body' => $defaultInvoiceEmailBody,
'estimate_mail_body' => $defaultEstimateEmailBody,
'payment_mail_body' => $defaultPaymentEmailBody,
'invoice_company_address_format' => $companyAddressFormat,
'invoice_shipping_address_format' => $shippingAddressFormat,
'invoice_billing_address_format' => $billingAddressFormat,
'estimate_company_address_format' => $companyAddressFormat,
'estimate_shipping_address_format' => $shippingAddressFormat,
'estimate_billing_address_format' => $billingAddressFormat,
'payment_company_address_format' => $companyAddressFormat,
'payment_from_customer_address_format' => $paymentFromCustomerAddress
];
CompanySetting::setSettings($settings, $user->company_id);
}
}

View File

@ -1,6 +1,9 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class CountriesTableSeeder extends Seeder
{

View File

@ -1,7 +1,9 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Crater\Currency;
use Crater\Models\Currency;
class CurrenciesTableSeeder extends Seeder
{

View File

@ -1,4 +1,7 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
@ -12,9 +15,11 @@ class DatabaseSeeder extends Seeder
{
$this->call(UsersTableSeeder::class);
$this->call(CurrenciesTableSeeder::class);
$this->call(RoleSeeder::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

@ -0,0 +1,44 @@
<?php
namespace Database\Seeders;
use Crater\Models\CompanySetting;
use Crater\Models\Setting;
use Crater\Models\User;
use Illuminate\Database\Seeder;
class DefaultSettingsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user = User::where('role', 'super admin')->first();
$settings = [
'currency' => 1,
'time_zone' => 'Asia/Kolkata',
'language' => 'en',
'fiscal_year' => '1-12',
'carbon_date_format' => 'Y/m/d',
'moment_date_format' => 'YYYY/MM/DD',
'notification_email' => 'noreply@crater.in',
'notify_invoice_viewed' => 'NO',
'notify_estimate_viewed' => 'NO',
'tax_per_item' => 'NO',
'discount_per_item' => 'NO',
'invoice_auto_generate' => 'YES',
'invoice_prefix' => 'INV',
'estimate_prefix' => 'EST',
'estimate_auto_generate' => 'YES',
'payment_prefix' => 'PAY',
'payment_auto_generate' => 'YES',
'save_pdf_to_disk' => 'NO',
];
CompanySetting::setSettings($settings, $user->company_id);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Database\Seeders;
use Crater\Models\Address;
use Illuminate\Database\Seeder;
use Crater\Models\User;
use Crater\Models\Setting;
class DemoSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user = User::where('role', 'super admin')->first();
$user->setSettings(['language' => 'en']);
Address::create(['company_id' => $user->company_id, 'country_id' => 1]);
Setting::setSetting('profile_complete', 'COMPLETED');
\Storage::disk('local')->put('database_created', 'database_created');
}
}

View File

@ -1,7 +1,9 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Crater\EstimateTemplate;
use Crater\Models\EstimateTemplate;
class EstimateTemplateSeeder extends Seeder
{

View File

@ -1,7 +1,9 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Crater\InvoiceTemplate;
use Crater\Models\InvoiceTemplate;
class InvoiceTemplateSeeder extends Seeder
{

View File

@ -1,7 +1,9 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Crater\PaymentMethod;
use Crater\Models\PaymentMethod;
class PaymentMethodSeeder extends Seeder
{

View File

@ -1,7 +1,9 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Crater\Unit;
use Crater\Models\Unit;
class UnitSeeder extends Seeder
{

View File

@ -0,0 +1,37 @@
<?php
namespace Database\Seeders;
use Crater\Models\Company;
use Illuminate\Database\Seeder;
use Crater\Models\User;
use Crater\Models\Setting;
use Illuminate\Support\Facades\Hash;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user = User::create([
'email' => 'admin@craterapp.com',
'name' => 'Jane Doe',
'role' => 'super admin',
'password' => 'crater@123'
]);
$company = Company::create([
'name' => 'xyz',
'unique_hash' => str_random(20)
]);
$user->company_id = $company->id;
$user->save();
Setting::setSetting('profile_complete', 0);
}
}

View File

@ -1,19 +0,0 @@
<?php
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
class RoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Role::create(['name' => 'admin']);
Role::create(['name' => 'contact']);
Role::create(['name' => 'staff']);
}
}

View File

@ -1,44 +0,0 @@
<?php
use Illuminate\Database\Seeder;
use Crater\Company;
use Crater\User;
use Crater\Address;
use Crater\CompanySetting;
class SettingsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$company = Company::create(['name' => 'TEST', 'unique_hash' => str_random(60)]);
$user = User::find(1);
$user->company_id = $company->id;
$user->save();
$address = Address::create(['user_id' => $user->id, 'country_id' => 1]);
$sets = [
'currency' => 1,
'time_zone' => 'UTC',
'language' => 'en',
'notification_email' => $user->email,
'fiscal_year' => '1-12',
'carbon_date_format' => 'd m Y',
'moment_date_format' => 'DD MMM YYYY'
];
foreach ($sets as $key => $value) {
CompanySetting::setSetting(
$key,
$value,
$company->id
);
}
}
}

View File

@ -1,26 +0,0 @@
<?php
use Illuminate\Database\Seeder;
use Crater\User;
use Crater\Setting;
use Illuminate\Support\Facades\Hash;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
User::create([
'email' => 'admin@craterapp.com',
'name' => 'Jane Doe',
'role' => 'admin',
'password' => Hash::make('crater@123')
]);
Setting::setSetting('profile_complete', 0);
}
}