mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 19:51:09 -04:00
v5.0.0 update
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
@ -29,11 +30,13 @@ class AddressFactory extends Factory
|
||||
'city' => $this->faker->city,
|
||||
'state' => $this->faker->state,
|
||||
'country_id' => 231,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'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(),
|
||||
'customer_id' => Customer::factory()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CompanyFactory extends Factory
|
||||
@ -22,8 +23,9 @@ class CompanyFactory extends Factory
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'unique_hash' => str_random(60),
|
||||
'name' => $this->faker->name,
|
||||
'unique_hash' => str_random(20),
|
||||
'name' => $this->faker->name(),
|
||||
'owner_id' => User::where('role', 'super admin')->first()->id
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ class CompanySettingFactory extends Factory
|
||||
return [
|
||||
'option' => $this->faker->word,
|
||||
'value' => $this->faker->word,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class CustomFieldFactory extends Factory
|
||||
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,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ class CustomFieldValueFactory extends Factory
|
||||
'custom_field_valuable_id' => 1,
|
||||
'type' => $this->faker->name,
|
||||
'custom_field_id' => CustomField::factory(),
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
41
database/factories/CustomerFactory.php
Normal file
41
database/factories/CustomerFactory.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class CustomerFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Customer::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,
|
||||
'prefix' => $this->faker->randomDigitNotNull,
|
||||
'website' => $this->faker->url,
|
||||
'enable_portal' => true,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'phone' => $this->faker->phoneNumber,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'password' => Hash::make('secret'),
|
||||
'currency_id' => Currency::find(1)->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,11 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\User;
|
||||
use Crater\Services\SerialNumberFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class EstimateFactory extends Factory
|
||||
@ -67,13 +70,19 @@ class EstimateFactory extends Factory
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$sequenceNumber = (new SerialNumberFormatter())
|
||||
->setModel(new Estimate())
|
||||
->setCompany(User::find(1)->companies()->first()->id)
|
||||
->setNextNumbers();
|
||||
|
||||
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,
|
||||
'estimate_number' => $sequenceNumber->getNextNumber(),
|
||||
'sequence_number' => $sequenceNumber->nextSequenceNumber,
|
||||
'customer_sequence_number' => $sequenceNumber->nextCustomerSequenceNumber,
|
||||
'reference_number' => $sequenceNumber->getNextNumber(),
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'status' => Estimate::STATUS_DRAFT,
|
||||
'template_name' => 'estimate1',
|
||||
'sub_total' => $this->faker->randomDigitNotNull,
|
||||
@ -90,6 +99,13 @@ class EstimateFactory extends Factory
|
||||
'tax' => $this->faker->randomDigitNotNull,
|
||||
'notes' => $this->faker->text(80),
|
||||
'unique_hash' => str_random(60),
|
||||
'customer_id' => Customer::factory(),
|
||||
'exchange_rate' => $this->faker->randomDigitNotNull,
|
||||
'base_discount_val' => $this->faker->randomDigitNotNull,
|
||||
'base_sub_total' => $this->faker->randomDigitNotNull,
|
||||
'base_total' => $this->faker->randomDigitNotNull,
|
||||
'base_tax' => $this->faker->randomDigitNotNull,
|
||||
'currency_id' => Currency::find(1)->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\User;
|
||||
@ -34,8 +35,9 @@ class EstimateItemFactory extends Factory
|
||||
'price' => function (array $item) {
|
||||
return Item::find($item['item_id'])->price;
|
||||
},
|
||||
'estimate_id' => Estimate::factory(),
|
||||
'quantity' => $this->faker->randomDigitNotNull,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'tax' => $this->faker->randomDigitNotNull,
|
||||
'total' => function (array $item) {
|
||||
return ($item['price'] * $item['quantity']);
|
||||
@ -47,6 +49,11 @@ class EstimateItemFactory extends Factory
|
||||
'discount' => function (array $estimate) {
|
||||
return $estimate['discount_type'] == 'percentage' ? (($estimate['discount_val'] * $estimate['total']) / 100) : $estimate['discount_val'];
|
||||
},
|
||||
'exchange_rate' => $this->faker->randomDigitNotNull,
|
||||
'base_discount_val' => $this->faker->randomDigitNotNull,
|
||||
'base_price' => $this->faker->randomDigitNotNull,
|
||||
'base_total' => $this->faker->randomDigitNotNull,
|
||||
'base_tax' => $this->faker->randomDigitNotNull,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
33
database/factories/ExchangeRateLogFactory.php
Normal file
33
database/factories/ExchangeRateLogFactory.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\ExchangeRateLog;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ExchangeRateLogFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = ExchangeRateLog::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'company_id' => Currency::find(1)->id,
|
||||
'base_currency_id' => User::find(1)->companies()->first()->id,
|
||||
'currency_id' => Currency::find(4)->id,
|
||||
'exchange_rate' => $this->faker->randomDigitNotNull
|
||||
];
|
||||
}
|
||||
}
|
||||
30
database/factories/ExchangeRateProviderFactory.php
Normal file
30
database/factories/ExchangeRateProviderFactory.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\ExchangeRateProvider;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ExchangeRateProviderFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = ExchangeRateProvider::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'driver' => $this->faker->word,
|
||||
'key' => str_random(10),
|
||||
'active' => $this->faker->randomElement([true, false]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ class ExpenseCategoryFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->word,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'description' => $this->faker->text,
|
||||
];
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Expense;
|
||||
use Crater\Models\ExpenseCategory;
|
||||
use Crater\Models\User;
|
||||
@ -26,10 +28,14 @@ class ExpenseFactory extends Factory
|
||||
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,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'amount' => $this->faker->randomDigitNotNull,
|
||||
'notes' => $this->faker->text,
|
||||
'attachment_receipt' => null,
|
||||
'customer_id' => Customer::factory(),
|
||||
'exchange_rate' => $this->faker->randomDigitNotNull,
|
||||
'base_amount' => $this->faker->randomDigitNotNull,
|
||||
'currency_id' => Currency::find(1)->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,12 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\RecurringInvoice;
|
||||
use Crater\Models\User;
|
||||
use Crater\Services\SerialNumberFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class InvoiceFactory extends Factory
|
||||
@ -94,18 +98,24 @@ class InvoiceFactory extends Factory
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$sequenceNumber = (new SerialNumberFormatter())
|
||||
->setModel(new Invoice())
|
||||
->setCompany(User::find(1)->companies()->first()->id)
|
||||
->setNextNumbers();
|
||||
|
||||
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_number' => $sequenceNumber->getNextNumber(),
|
||||
'sequence_number' => $sequenceNumber->nextSequenceNumber,
|
||||
'customer_sequence_number' => $sequenceNumber->nextCustomerSequenceNumber,
|
||||
'reference_number' => $sequenceNumber->getNextNumber(),
|
||||
'template_name' => 'invoice1',
|
||||
'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,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'sub_total' => $this->faker->randomDigitNotNull,
|
||||
'total' => $this->faker->randomDigitNotNull,
|
||||
'discount_type' => $this->faker->randomElement(['percentage', 'fixed']),
|
||||
@ -121,6 +131,15 @@ class InvoiceFactory extends Factory
|
||||
},
|
||||
'notes' => $this->faker->text(80),
|
||||
'unique_hash' => str_random(60),
|
||||
'customer_id' => Customer::factory(),
|
||||
'recurring_invoice_id' => RecurringInvoice::factory(),
|
||||
'exchange_rate' => $this->faker->randomDigitNotNull,
|
||||
'base_discount_val' => $this->faker->randomDigitNotNull,
|
||||
'base_sub_total' => $this->faker->randomDigitNotNull,
|
||||
'base_total' => $this->faker->randomDigitNotNull,
|
||||
'base_tax' => $this->faker->randomDigitNotNull,
|
||||
'base_due_amount' => $this->faker->randomDigitNotNull,
|
||||
'currency_id' => Currency::find(1)->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ namespace Database\Factories;
|
||||
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\RecurringInvoice;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
@ -34,7 +35,7 @@ class InvoiceItemFactory extends Factory
|
||||
'price' => function (array $item) {
|
||||
return Item::find($item['item_id'])->price;
|
||||
},
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'quantity' => $this->faker->randomDigitNotNull,
|
||||
'total' => function (array $item) {
|
||||
return ($item['price'] * $item['quantity']);
|
||||
@ -47,6 +48,12 @@ class InvoiceItemFactory extends Factory
|
||||
return $invoice['discount_type'] == 'percentage' ? (($invoice['discount_val'] * $invoice['total']) / 100) : $invoice['discount_val'];
|
||||
},
|
||||
'tax' => $this->faker->randomDigitNotNull,
|
||||
'recurring_invoice_id' => RecurringInvoice::factory(),
|
||||
'exchange_rate' => $this->faker->randomDigitNotNull,
|
||||
'base_discount_val' => $this->faker->randomDigitNotNull,
|
||||
'base_price' => $this->faker->randomDigitNotNull,
|
||||
'base_total' => $this->faker->randomDigitNotNull,
|
||||
'base_tax' => $this->faker->randomDigitNotNull,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\Unit;
|
||||
use Crater\Models\User;
|
||||
@ -26,9 +27,12 @@ class ItemFactory extends Factory
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'description' => $this->faker->text,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'price' => $this->faker->randomDigitNotNull,
|
||||
'unit_id' => Unit::factory(),
|
||||
'creator_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'currency_id' => Currency::find(1)->id,
|
||||
'tax_per_item' => $this->faker->randomElement([true, false])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Note;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class NoteFactory extends Factory
|
||||
@ -25,6 +26,7 @@ class NoteFactory extends Factory
|
||||
'type' => $this->faker->randomElement(['Invoice', 'Estimate', 'Payment']),
|
||||
'name' => $this->faker->word,
|
||||
'notes' => $this->faker->text,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,12 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Payment;
|
||||
use Crater\Models\PaymentMethod;
|
||||
use Crater\Models\User;
|
||||
use Crater\Services\SerialNumberFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class PaymentFactory extends Factory
|
||||
@ -22,13 +26,24 @@ class PaymentFactory extends Factory
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$sequenceNumber = (new SerialNumberFormatter())
|
||||
->setModel(new Payment())
|
||||
->setCompany(User::find(1)->companies()->first()->id)
|
||||
->setNextNumbers();
|
||||
|
||||
return [
|
||||
'user_id' => User::factory()->create(['role' => 'customer'])->id,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->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'),
|
||||
'sequence_number' => $sequenceNumber->nextSequenceNumber,
|
||||
'customer_sequence_number' => $sequenceNumber->nextCustomerSequenceNumber,
|
||||
'payment_number' => $sequenceNumber->getNextNumber(),
|
||||
'unique_hash' => str_random(60),
|
||||
'payment_method_id' => PaymentMethod::find(1)->id,
|
||||
'customer_id' => Customer::factory(),
|
||||
'base_amount' => $this->faker->randomDigitNotNull,
|
||||
'currency_id' => Currency::find(1)->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ class PaymentMethodFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
47
database/factories/RecurringInvoiceFactory.php
Normal file
47
database/factories/RecurringInvoiceFactory.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\RecurringInvoice;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class RecurringInvoiceFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = RecurringInvoice::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'starts_at' => $this->faker->iso8601(),
|
||||
'send_automatically' => false,
|
||||
'status' => $this->faker->randomElement(['COMPLETED', 'ON_HOLD', 'ACTIVE']),
|
||||
'tax_per_item' => 'NO',
|
||||
'discount_per_item' => 'NO',
|
||||
'sub_total' => $this->faker->randomDigitNotNull,
|
||||
'total' => $this->faker->randomDigitNotNull,
|
||||
'tax' => $this->faker->randomDigitNotNull,
|
||||
'due_amount' => $this->faker->randomDigitNotNull,
|
||||
'discount' => $this->faker->randomDigitNotNull,
|
||||
'discount_val' => $this->faker->randomDigitNotNull,
|
||||
'customer_id' => Customer::factory(),
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'frequency' => '* * 18 * *',
|
||||
'limit_by' => $this->faker->randomElement(['NONE', 'COUNT', 'DATE']),
|
||||
'limit_count' => $this->faker->randomDigit,
|
||||
'limit_date' => $this->faker->date(),
|
||||
'exchange_rate' => $this->faker->randomDigitNotNull
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Tax;
|
||||
use Crater\Models\TaxType;
|
||||
use Crater\Models\User;
|
||||
@ -31,8 +32,11 @@ class TaxFactory extends Factory
|
||||
'name' => function (array $item) {
|
||||
return TaxType::find($item['tax_type_id'])->name;
|
||||
},
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'amount' => $this->faker->randomDigitNotNull,
|
||||
'compound_tax' => $this->faker->randomDigitNotNull,
|
||||
'base_amount' => $this->faker->randomDigitNotNull,
|
||||
'currency_id' => Currency::where('name', 'US Dollar')->first()->company_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ class TaxTypeFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->word,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
'percent' => $this->faker->numberBetween($min = 0, $max = 100),
|
||||
'description' => $this->faker->text,
|
||||
'compound_tax' => 0,
|
||||
|
||||
@ -24,7 +24,7 @@ class UnitFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'company_id' => User::where('role', 'super admin')->first()->company_id,
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ class UserFactory extends Factory
|
||||
'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,
|
||||
|
||||
@ -33,12 +33,12 @@ class UpdateCraterVersion400 extends Migration
|
||||
]);
|
||||
|
||||
// Update language
|
||||
$user->setSettings(['language' => CompanySetting::getSetting('language', $user->company_id)]);
|
||||
$user->setSettings(['language' => CompanySetting::getSetting('language', $user->companies()->first()->id)]);
|
||||
|
||||
// Update user's addresses
|
||||
if ($user->addresses()->exists()) {
|
||||
foreach ($user->addresses as $address) {
|
||||
$address->company_id = $user->company_id;
|
||||
$address->company_id = $user->companies()->first()->id;
|
||||
$address->user_id = null;
|
||||
$address->save();
|
||||
}
|
||||
@ -131,6 +131,6 @@ class UpdateCraterVersion400 extends Migration
|
||||
'payment_from_customer_address_format' => $paymentFromCustomerAddress,
|
||||
];
|
||||
|
||||
CompanySetting::setSettings($settings, $user->company_id);
|
||||
CompanySetting::setSettings($settings, $user->companies()->first()->id);
|
||||
}
|
||||
}
|
||||
|
||||
114
database/migrations/2021_06_28_105334_create_bouncer_tables.php
Normal file
114
database/migrations/2021_06_28_105334_create_bouncer_tables.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Silber\Bouncer\Database\Models;
|
||||
|
||||
class CreateBouncerTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('roles')) {
|
||||
Schema::drop(Models::table('roles'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('permissions')) {
|
||||
Schema::drop(Models::table('permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('model_has_permissions')) {
|
||||
Schema::drop(Models::table('model_has_permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('model_has_roles')) {
|
||||
Schema::drop(Models::table('model_has_roles'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('role_has_permissions')) {
|
||||
Schema::drop(Models::table('role_has_permissions'));
|
||||
}
|
||||
|
||||
Schema::create(Models::table('abilities'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('title')->nullable();
|
||||
$table->bigInteger('entity_id')->unsigned()->nullable();
|
||||
$table->string('entity_type')->nullable();
|
||||
$table->boolean('only_owned')->default(false);
|
||||
$table->json('options')->nullable();
|
||||
$table->integer('scope')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create(Models::table('roles'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('title')->nullable();
|
||||
$table->integer('level')->unsigned()->nullable();
|
||||
$table->integer('scope')->nullable()->index();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(
|
||||
['name', 'scope'],
|
||||
'roles_name_unique'
|
||||
);
|
||||
});
|
||||
|
||||
Schema::create(Models::table('assigned_roles'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('role_id')->unsigned()->index();
|
||||
$table->bigInteger('entity_id')->unsigned();
|
||||
$table->string('entity_type');
|
||||
$table->bigInteger('restricted_to_id')->unsigned()->nullable();
|
||||
$table->string('restricted_to_type')->nullable();
|
||||
$table->integer('scope')->nullable()->index();
|
||||
|
||||
$table->index(
|
||||
['entity_id', 'entity_type', 'scope'],
|
||||
'assigned_roles_entity_index'
|
||||
);
|
||||
|
||||
$table->foreign('role_id')
|
||||
->references('id')->on(Models::table('roles'))
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Schema::create(Models::table('permissions'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('ability_id')->unsigned()->index();
|
||||
$table->bigInteger('entity_id')->unsigned()->nullable();
|
||||
$table->string('entity_type')->nullable();
|
||||
$table->boolean('forbidden')->default(false);
|
||||
$table->integer('scope')->nullable()->index();
|
||||
|
||||
$table->index(
|
||||
['entity_id', 'entity_type', 'scope'],
|
||||
'permissions_entity_index'
|
||||
);
|
||||
|
||||
$table->foreign('ability_id')
|
||||
->references('id')->on(Models::table('abilities'))
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop(Models::table('permissions'));
|
||||
Schema::drop(Models::table('assigned_roles'));
|
||||
Schema::drop(Models::table('roles'));
|
||||
Schema::drop(Models::table('abilities'));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCustomersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('customers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique()->nullable();
|
||||
$table->string('phone')->nullable();
|
||||
$table->string('password')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->string('facebook_id')->nullable();
|
||||
$table->string('google_id')->nullable();
|
||||
$table->string('github_id')->nullable();
|
||||
$table->string('contact_name')->nullable();
|
||||
$table->string('company_name')->nullable();
|
||||
$table->string('website')->nullable();
|
||||
$table->boolean('enable_portal')->nullable();
|
||||
$table->integer('currency_id')->unsigned()->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->unsignedInteger('creator_id')->nullable();
|
||||
$table->foreign('creator_id')->references('id')->on('users');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('customers');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToExpensesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToPaymentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToAddressesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('addresses', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('addresses', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\CustomField;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UpdateCustomerIdInAllTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$users = User::where('role', 'customer')
|
||||
->get();
|
||||
|
||||
$users->makeVisible('password', 'remember_token');
|
||||
|
||||
if ($users) {
|
||||
foreach ($users as $user) {
|
||||
$newCustomer = Customer::create($user->toArray());
|
||||
|
||||
$customFields = CustomField::where('model_type', 'User')->get();
|
||||
|
||||
if ($customFields) {
|
||||
$user->fields->map(function ($customFieldValue) use ($newCustomer) {
|
||||
$customFieldValue->custom_field_valuable_type = "Crater\Models\Customer";
|
||||
$customFieldValue->custom_field_valuable_id = $newCustomer->id;
|
||||
$customFieldValue->save();
|
||||
|
||||
$customField = $customFieldValue->customField;
|
||||
$customField->model_type = "Customer";
|
||||
$customField->slug = Str::upper('CUSTOM_'.$customField->model_type.'_'.Str::slug($customField->label, '_'));
|
||||
$customField->save();
|
||||
});
|
||||
}
|
||||
|
||||
$user->addresses->map(function ($address) use ($newCustomer) {
|
||||
if ($address) {
|
||||
$address->customer_id = $newCustomer->id;
|
||||
$address->user_id = null;
|
||||
$address->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->expenses->map(function ($expense) use ($newCustomer) {
|
||||
if ($expense) {
|
||||
$expense->customer_id = $newCustomer->id;
|
||||
$expense->user_id = null;
|
||||
$expense->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->estimates->map(function ($estimate) use ($newCustomer) {
|
||||
if ($estimate) {
|
||||
$estimate->customer_id = $newCustomer->id;
|
||||
$estimate->user_id = null;
|
||||
$estimate->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->invoices->map(function ($invoice) use ($newCustomer) {
|
||||
if ($invoice) {
|
||||
$invoice->customer_id = $newCustomer->id;
|
||||
$invoice->user_id = null;
|
||||
$invoice->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->payments->map(function ($payment) use ($newCustomer) {
|
||||
if ($payment) {
|
||||
$payment->customer_id = $newCustomer->id;
|
||||
$payment->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('unit');
|
||||
});
|
||||
|
||||
$users = User::where('role', 'customer')
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUserCompanyTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_company', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unsignedInteger('company_id')->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('company_user');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ChangeRelationshipOfCompany extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$users = User::all();
|
||||
|
||||
if ($users) {
|
||||
foreach ($users as $user) {
|
||||
$user->companies()->attach($user->company_id);
|
||||
$user->company_id = null;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['company_id']);
|
||||
}
|
||||
$table->dropColumn('company_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class AddOwnerIdToCompaniesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('companies', function (Blueprint $table) {
|
||||
$table->string('slug')->nullable();
|
||||
$table->unsignedInteger('owner_id')->nullable();
|
||||
$table->foreign('owner_id')->references('id')->on('users');
|
||||
});
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
$companies = Company::all();
|
||||
|
||||
if ($companies) {
|
||||
foreach ($companies as $company) {
|
||||
$company->owner_id = $user->id;
|
||||
$company->slug = Str::slug($company->name);
|
||||
$company->save();
|
||||
|
||||
$company->setupRoles();
|
||||
$user->assign('super admin');
|
||||
|
||||
$users = User::where('role', 'admin')->get();
|
||||
$users->map(function ($user) {
|
||||
$user->assign('super admin');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('companies', function (Blueprint $table) {
|
||||
$table->dropColumn('slug');
|
||||
$table->dropForeign(['owner_id']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Note;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCompanyToNotesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('notes', function (Blueprint $table) {
|
||||
$table->unsignedInteger('company_id')->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
});
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
if ($user) {
|
||||
$notes = Note::where('company_id', null)->get();
|
||||
$notes->map(function ($note) use ($user) {
|
||||
$note->company_id = $user->companies()->first()->id;
|
||||
$note->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('notes', function (Blueprint $table) {
|
||||
$table->dropForeign(['company_id']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateRecurringInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('recurring_invoices', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->dateTime('starts_at', $precision = 0);
|
||||
$table->boolean('send_automatically')->default(false);
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->enum('status', ['COMPLETED', 'ON_HOLD', 'ACTIVE'])->default('ACTIVE');
|
||||
$table->dateTime('next_invoice_at', $precision = 0)->nullable();
|
||||
$table->unsignedInteger('creator_id')->nullable();
|
||||
$table->foreign('creator_id')->references('id')->on('users');
|
||||
$table->string('frequency');
|
||||
$table->enum('limit_by', ['NONE', 'COUNT', 'DATE'])->default('NONE');
|
||||
$table->integer('limit_count')->nullable();
|
||||
$table->date('limit_date')->nullable();
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->string('tax_per_item');
|
||||
$table->string('discount_per_item');
|
||||
$table->text('notes')->nullable();
|
||||
$table->string('discount_type')->nullable();
|
||||
$table->decimal('discount', 15, 2)->nullable();
|
||||
$table->unsignedBigInteger('discount_val')->nullable();
|
||||
$table->unsignedBigInteger('sub_total');
|
||||
$table->unsignedBigInteger('total');
|
||||
$table->unsignedBigInteger('tax');
|
||||
$table->string('template_name')->nullable();
|
||||
$table->unsignedBigInteger('due_amount');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('recurring_invoices');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRecurringInvoiceIdToInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('recurring_invoice_id')->nullable();
|
||||
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn('recurring_invoice_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRecurringInvoiceIdToInvoiceItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->integer('invoice_id')->unsigned()->nullable()->change();
|
||||
$table->unsignedBigInteger('recurring_invoice_id')->nullable();
|
||||
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->dropColumn('recurring_invoice_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class MakeDueDateOptionalInInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->date('due_date')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class MakeExpiryDateOptionalEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->date('expiry_date')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_sub_total')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
$table->unsignedBigInteger('base_due_amount')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'base_discount_val',
|
||||
'exchange_rate',
|
||||
'base_sub_total',
|
||||
'base_total',
|
||||
'base_tax',
|
||||
'base_due_amount'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoInvoiceItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('base_price')->nullable();
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'base_price',
|
||||
'exchange_rate',
|
||||
'base_discount_val',
|
||||
'base_tax',
|
||||
'base_total'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_sub_total')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_discount_val',
|
||||
'base_sub_total',
|
||||
'base_total',
|
||||
'base_tax',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoEstimateItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimate_items', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_price')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimate_items', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_discount_val',
|
||||
'base_price',
|
||||
'base_tax',
|
||||
'base_total'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnIntoPaymentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_amount')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->dropColumn('base_amount');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseValuesIntoTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_amount')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_amount',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoPaymentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateExchangeRateLogsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('exchange_rate_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->unsignedInteger('base_currency_id')->nullable();
|
||||
$table->foreign('base_currency_id')->references('id')->on('currencies');
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('exchange_rates');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddTaxPerItemIntoItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->boolean('tax_per_item')->default(false);
|
||||
});
|
||||
|
||||
$items = Item::with('taxes')->get();
|
||||
|
||||
if ($items) {
|
||||
foreach ($items as $item) {
|
||||
if (! $item->taxes()->get()->isEmpty()) {
|
||||
$item->tax_per_item = true;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('tax_per_item');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsToExpenseTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_amount')->nullable();
|
||||
$table->unsignedInteger('currency_id');
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_amount',
|
||||
'currency_id',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateExchangeRateProvidersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('exchange_rate_providers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('driver');
|
||||
$table->string('key');
|
||||
$table->json('currencies')->nullable();
|
||||
$table->json('driver_config')->nullable();
|
||||
$table->boolean('active')->default(true);
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('exchange_rate_providers');
|
||||
}
|
||||
}
|
||||
101
database/migrations/2021_09_28_130822_add_sequence_column.php
Normal file
101
database/migrations/2021_09_28_130822_add_sequence_column.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddSequenceColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
$table->string('prefix')->nullable()->after('id');
|
||||
});
|
||||
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->mediumInteger('sequence_number')->unsigned()->nullable()->after('id');
|
||||
$table->mediumInteger('customer_sequence_number')->unsigned()->nullable()->after('sequence_number');
|
||||
});
|
||||
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->mediumInteger('sequence_number')->unsigned()->nullable()->after('id');
|
||||
$table->mediumInteger('customer_sequence_number')->unsigned()->nullable()->after('sequence_number');
|
||||
});
|
||||
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->mediumInteger('sequence_number')->unsigned()->nullable()->after('id');
|
||||
$table->mediumInteger('customer_sequence_number')->unsigned()->nullable()->after('sequence_number');
|
||||
});
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
if ($user && $user->role == 'super admin') {
|
||||
$customers = Customer::all();
|
||||
foreach ($customers as $customer) {
|
||||
$invoices = $customer->invoices;
|
||||
if ($invoices) {
|
||||
$customerSequence = 1;
|
||||
$invoices->map(function ($invoice) use ($customerSequence) {
|
||||
$invoiceNumber = explode("-", $invoice->invoice_number);
|
||||
$invoice->sequence_number = intval(end($invoiceNumber));
|
||||
$invoice->customer_sequence_number = $customerSequence;
|
||||
$invoice->save();
|
||||
$customerSequence += 1;
|
||||
});
|
||||
}
|
||||
|
||||
$estimates = $customer->estimates;
|
||||
if ($estimates) {
|
||||
$customerSequence = 1;
|
||||
$estimates->map(function ($estimate) use ($customerSequence) {
|
||||
$estimateNumber = explode("-", $estimate->estimate_number);
|
||||
$estimate->sequence_number = intval(end($estimateNumber));
|
||||
$estimate->customer_sequence_number = $customerSequence;
|
||||
$estimate->save();
|
||||
$customerSequence += 1;
|
||||
});
|
||||
}
|
||||
|
||||
$payments = $customer->payments;
|
||||
if ($estimates) {
|
||||
$customerSequence = 1;
|
||||
$payments->map(function ($payment) use ($customerSequence) {
|
||||
$paymentNumber = explode("-", $payment->payment_number);
|
||||
$payment->sequence_number = intval(end($paymentNumber));
|
||||
$payment->customer_sequence_number = $customerSequence;
|
||||
$payment->save();
|
||||
$customerSequence += 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn('sequence_number');
|
||||
$table->dropColumn('customer_sequence_number');
|
||||
});
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->dropColumn('sequence_number');
|
||||
$table->dropColumn('customer_sequence_number');
|
||||
});
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->dropColumn('sequence_number');
|
||||
$table->dropColumn('customer_sequence_number');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRecurringInvoiceIdToTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('recurring_invoice_id')->nullable();
|
||||
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->dropColumn('recurring_invoice_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddPaymentMethodToExpenseTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->integer('payment_method_id')->unsigned()->nullable();
|
||||
$table->foreign('payment_method_id')->references('id')->on('payment_methods');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropColumn('payment_method_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CalculateBaseValuesForExistingData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
if ($user) {
|
||||
$companyId = $user->companies()->first()->id;
|
||||
|
||||
$currency_id = CompanySetting::getSetting('currency', $companyId);
|
||||
|
||||
$items = Item::all();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->currency_id = $currency_id;
|
||||
$item->save();
|
||||
}
|
||||
|
||||
$customers = Customer::all();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer->invoices()->exists()) {
|
||||
$customer->invoices->map(function ($invoice) use ($currency_id, $customer) {
|
||||
if ($customer->currency_id == $currency_id) {
|
||||
$invoice->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => 1,
|
||||
'base_discount_val' => $invoice->sub_total,
|
||||
'base_sub_total' => $invoice->sub_total,
|
||||
'base_total' => $invoice->total,
|
||||
'base_tax' => $invoice->tax,
|
||||
'base_due_amount' => $invoice->due_amount
|
||||
]);
|
||||
} else {
|
||||
$invoice->update([
|
||||
'currency_id' => $customer->currency_id,
|
||||
]);
|
||||
}
|
||||
$this->items($invoice);
|
||||
});
|
||||
}
|
||||
|
||||
if ($customer->expenses()->exists()) {
|
||||
$customer->expenses->map(function ($expense) use ($currency_id) {
|
||||
$expense->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => 1,
|
||||
'base_amount' => $expense->amount,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
if ($customer->estimates()->exists()) {
|
||||
$customer->estimates->map(function ($estimate) use ($currency_id, $customer) {
|
||||
if ($customer->currency_id == $currency_id) {
|
||||
$estimate->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => 1,
|
||||
'base_discount_val' => $estimate->sub_total,
|
||||
'base_sub_total' => $estimate->sub_total,
|
||||
'base_total' => $estimate->total,
|
||||
'base_tax' => $estimate->tax
|
||||
]);
|
||||
} else {
|
||||
$estimate->update([
|
||||
'currency_id' => $customer->currency_id,
|
||||
]);
|
||||
}
|
||||
$this->items($estimate);
|
||||
});
|
||||
}
|
||||
|
||||
if ($customer->payments()->exists()) {
|
||||
$customer->payments->map(function ($payment) use ($currency_id, $customer) {
|
||||
if ($customer->currency_id == $currency_id) {
|
||||
$payment->update([
|
||||
'currency_id' => $currency_id,
|
||||
'base_amount' => $payment->amount,
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
} else {
|
||||
$payment->update([
|
||||
'currency_id' => $customer->currency_id,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function items($model)
|
||||
{
|
||||
$model->items->map(function ($item) use ($model) {
|
||||
$item->update([
|
||||
'exchange_rate' => $model->exchange_rate,
|
||||
'base_discount_val' => $item->discount_val * $model->exchange_rate,
|
||||
'base_price' => $item->price * $model->exchange_rate,
|
||||
'base_tax' => $item->tax * $model->exchange_rate,
|
||||
'base_total' => $item->total * $model->exchange_rate
|
||||
]);
|
||||
|
||||
$this->taxes($item, $model->currency_id);
|
||||
});
|
||||
|
||||
$this->taxes($model, $model->currency_id);
|
||||
}
|
||||
|
||||
public function taxes($model, $currency_id)
|
||||
{
|
||||
if ($model->taxes()->exists()) {
|
||||
$model->taxes->map(function ($tax) use ($model, $currency_id) {
|
||||
$tax->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => $model->exchange_rate,
|
||||
'base_amount' => $tax->amount * $model->exchange_rate,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddNewCompanySettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$companies = Company::all();
|
||||
|
||||
if ($companies) {
|
||||
$companies->map(function ($company) {
|
||||
$settingsToRemove = [
|
||||
'invoice_number_length',
|
||||
'estimate_number_length',
|
||||
'payment_number_length',
|
||||
'invoice_prefix',
|
||||
'estimate_prefix',
|
||||
'payment_prefix',
|
||||
];
|
||||
|
||||
$oldSettings = CompanySetting::getSettings($settingsToRemove, $company->id);
|
||||
$oldSettings = $oldSettings->toArray();
|
||||
|
||||
$settings = [
|
||||
'invoice_set_due_date_automatically' => 'YES',
|
||||
'invoice_due_date_days' => 7,
|
||||
'estimate_set_expiry_date_automatically' => 'YES',
|
||||
'estimate_expiry_date_days' => 7,
|
||||
'estimate_convert_action' => 'no_action',
|
||||
'bulk_exchange_rate_configured' => "NO",
|
||||
'invoice_number_format' => "{{SERIES:{$oldSettings['invoice_prefix']}}}{{DELIMITER:-}}{{SEQUENCE:{$oldSettings['invoice_number_length']}}}",
|
||||
'estimate_number_format' => "{{SERIES:{$oldSettings['estimate_prefix']}}}{{DELIMITER:-}}{{SEQUENCE:{$oldSettings['estimate_number_length']}}}",
|
||||
'payment_number_format' => "{{SERIES:{$oldSettings['payment_prefix']}}}{{DELIMITER:-}}{{SEQUENCE:{$oldSettings['payment_number_length']}}}",
|
||||
];
|
||||
|
||||
CompanySetting::whereIn('option', $settingsToRemove)->delete();
|
||||
|
||||
CompanySetting::setSettings($settings, $company->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class UpdateCraterVersion500 extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Setting::setSetting('version', '5.0.0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -567,8 +567,17 @@ class CurrenciesTableSeeder extends Seeder
|
||||
'thousand_separator' => ',',
|
||||
'decimal_separator' => '.',
|
||||
],
|
||||
[
|
||||
'name' => 'Jamaican Dollar',
|
||||
'code' => 'JMD',
|
||||
'symbol' => '$',
|
||||
'precision' => '0',
|
||||
'thousand_separator' => ',',
|
||||
'decimal_separator' => '.',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
Currency::create($currency);
|
||||
}
|
||||
|
||||
@ -13,11 +13,8 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->call(UsersTableSeeder::class);
|
||||
$this->call(CurrenciesTableSeeder::class);
|
||||
$this->call(DefaultSettingsSeeder::class);
|
||||
$this->call(CountriesTableSeeder::class);
|
||||
$this->call(PaymentMethodSeeder::class);
|
||||
$this->call(UnitSeeder::class);
|
||||
$this->call(UsersTableSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
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();
|
||||
|
||||
$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,
|
||||
'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_prefix' => 'INV',
|
||||
'invoice_auto_generate' => 'YES',
|
||||
'invoice_number_length' => 6,
|
||||
'invoice_email_attachment' => 'NO',
|
||||
'estimate_prefix' => 'EST',
|
||||
'estimate_auto_generate' => 'YES',
|
||||
'estimate_number_length' => 6,
|
||||
'estimate_email_attachment' => 'NO',
|
||||
'payment_prefix' => 'PAY',
|
||||
'payment_auto_generate' => 'YES',
|
||||
'payment_number_length' => 6,
|
||||
'payment_email_attachment' => 'NO',
|
||||
'save_pdf_to_disk' => 'NO',
|
||||
];
|
||||
|
||||
CompanySetting::setSettings($settings, $user->company_id);
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ class DemoSeeder extends Seeder
|
||||
|
||||
$user->setSettings(['language' => 'en']);
|
||||
|
||||
Address::create(['company_id' => $user->company_id, 'country_id' => 1]);
|
||||
Address::create(['company_id' => $user->companies()->first()->id, 'country_id' => 1]);
|
||||
|
||||
Setting::setSetting('profile_complete', 'COMPLETED');
|
||||
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Crater\Models\PaymentMethod;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PaymentMethodSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
PaymentMethod::create(['name' => 'Cash', 'company_id' => 1]);
|
||||
PaymentMethod::create(['name' => 'Check', 'company_id' => 1]);
|
||||
PaymentMethod::create(['name' => 'Credit Card', 'company_id' => 1]);
|
||||
PaymentMethod::create(['name' => 'Bank Transfer', 'company_id' => 1]);
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Crater\Models\Unit;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UnitSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Unit::create(['name' => 'box', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'cm', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'dz', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'ft', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'g', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'in', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'kg', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'km', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'lb', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'mg', 'company_id' => 1]);
|
||||
Unit::create(['name' => 'pc', 'company_id' => 1]);
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,8 @@ use Crater\Models\Company;
|
||||
use Crater\Models\Setting;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Silber\Bouncer\BouncerFacade;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class UsersTableSeeder extends Seeder
|
||||
{
|
||||
@ -25,11 +27,16 @@ class UsersTableSeeder extends Seeder
|
||||
|
||||
$company = Company::create([
|
||||
'name' => 'xyz',
|
||||
'unique_hash' => str_random(20),
|
||||
'owner_id' => $user->id
|
||||
]);
|
||||
|
||||
$user->company_id = $company->id;
|
||||
$user->save();
|
||||
$company->unique_hash = Hashids::connection(Company::class)->encode($company->id);
|
||||
$company->save();
|
||||
$company->setupDefaultData();
|
||||
$user->companies()->attach($company->id);
|
||||
BouncerFacade::scope()->to($company->id);
|
||||
|
||||
$user->assign('super admin');
|
||||
|
||||
Setting::setSetting('profile_complete', 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user