Merge branch 'master' into title-subheading
This commit is contained in:
@ -21,7 +21,7 @@ class Currency extends Factory
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$currencies = config('money');
|
||||
$currencies = config('money.currencies');
|
||||
|
||||
Model::pluck('code')->each(function ($db_code) use (&$currencies) {
|
||||
unset($currencies[$db_code]);
|
||||
|
@ -9,6 +9,7 @@ use App\Events\Document\DocumentReceived;
|
||||
use App\Events\Document\DocumentSent;
|
||||
use App\Events\Document\DocumentViewed;
|
||||
use App\Events\Document\PaymentReceived;
|
||||
use App\Interfaces\Utility\DocumentNumber;
|
||||
use App\Jobs\Document\UpdateDocument;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Common\Item;
|
||||
@ -70,7 +71,7 @@ class Document extends AbstractFactory
|
||||
|
||||
return [
|
||||
'type' => Model::INVOICE_TYPE,
|
||||
'document_number' => $this->getDocumentNumber(Model::INVOICE_TYPE),
|
||||
'document_number' => $this->getDocumentNumber(Model::INVOICE_TYPE, $contact),
|
||||
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
@ -101,7 +102,7 @@ class Document extends AbstractFactory
|
||||
|
||||
return [
|
||||
'type' => Model::BILL_TYPE,
|
||||
'document_number' => $this->getDocumentNumber(Model::BILL_TYPE),
|
||||
'document_number' => $this->getDocumentNumber(Model::BILL_TYPE, $contact),
|
||||
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
@ -207,13 +208,16 @@ class Document extends AbstractFactory
|
||||
{
|
||||
$type = $this->getRawAttribute('type') . '-recurring';
|
||||
|
||||
$contact = Contact::find($this->getRawAttribute('contact_id'));
|
||||
|
||||
return $this->state([
|
||||
'type' => $type,
|
||||
'document_number' => $this->getDocumentNumber($type),
|
||||
'document_number' => $this->getDocumentNumber($type, $contact),
|
||||
'recurring_started_at' => $this->getRawAttribute('issued_at'),
|
||||
'recurring_frequency' => 'daily',
|
||||
'recurring_interval' => '1',
|
||||
'recurring_limit_count' => '7',
|
||||
'recurring_send_email' => '1',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -255,21 +259,20 @@ class Document extends AbstractFactory
|
||||
],
|
||||
];
|
||||
|
||||
return $this->state([
|
||||
'items' => $items,
|
||||
'recurring_frequency' => 'no',
|
||||
]);
|
||||
return $this->state(['items' => $items]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get document number
|
||||
*
|
||||
*/
|
||||
public function getDocumentNumber($type)
|
||||
public function getDocumentNumber($type, Contact $contact)
|
||||
{
|
||||
$document_number = $this->getNextDocumentNumber($type);
|
||||
|
||||
$this->increaseNextDocumentNumber($type);
|
||||
$utility = app(DocumentNumber::class);
|
||||
|
||||
$document_number = $utility->getNextNumber($type, $contact);
|
||||
|
||||
$utility->increaseNextNumber($type, $contact);
|
||||
|
||||
return $document_number;
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Abstracts\Factory;
|
||||
use App\Interfaces\Utility\TransactionNumber;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Traits\Transactions;
|
||||
use App\Utilities\Date;
|
||||
|
||||
@ -40,7 +42,7 @@ class Transaction extends Factory
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'type' => $this->type,
|
||||
'number' => $this->getNumber(),
|
||||
'number' => $this->getNumber($this->type),
|
||||
'account_id' => setting('default.account'),
|
||||
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'),
|
||||
'amount' => $this->faker->randomFloat(2, 1, 1000),
|
||||
@ -61,10 +63,22 @@ class Transaction extends Factory
|
||||
*/
|
||||
public function income()
|
||||
{
|
||||
return $this->state([
|
||||
'type' => 'income',
|
||||
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||
]);
|
||||
return $this->state(function (array $attributes): array {
|
||||
$contacts = Contact::customer()->enabled()->get();
|
||||
|
||||
if ($contacts->count()) {
|
||||
$contact = $contacts->random(1)->first();
|
||||
} else {
|
||||
$contact = Contact::factory()->customer()->enabled()->create();
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'income',
|
||||
'number' => $this->getNumber('income', '', $contact),
|
||||
'contact_id' => $contact->id,
|
||||
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,10 +88,22 @@ class Transaction extends Factory
|
||||
*/
|
||||
public function expense()
|
||||
{
|
||||
return $this->state([
|
||||
'type' => 'expense',
|
||||
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||
]);
|
||||
return $this->state(function (array $attributes): array {
|
||||
$contacts = Contact::vendor()->enabled()->get();
|
||||
|
||||
if ($contacts->count()) {
|
||||
$contact = $contacts->random(1)->first();
|
||||
} else {
|
||||
$contact = Contact::factory()->vendor()->enabled()->create();
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'expense',
|
||||
'number' => $this->getNumber('expense', '', $contact),
|
||||
'contact_id' => $contact->id,
|
||||
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,15 +113,17 @@ class Transaction extends Factory
|
||||
*/
|
||||
public function recurring()
|
||||
{
|
||||
$type = $this->getRawAttribute('type') . '-recurring';
|
||||
|
||||
return $this->state([
|
||||
'type' => $this->getRawAttribute('type') . '-recurring',
|
||||
'number' => $this->getNumber('-recurring'),
|
||||
'recurring_started_at' => $this->getRawAttribute('paid_at'),
|
||||
'type' => $type,
|
||||
'number' => $this->getNumber($type, '-recurring'),
|
||||
'recurring_started_at' => Date::now()->format('Y-m-d H:i:s'),
|
||||
'recurring_frequency' => 'daily',
|
||||
'recurring_custom_frequency' => 'daily',
|
||||
'recurring_interval' => '1',
|
||||
'recurring_limit' => 'date',
|
||||
'recurring_limit_date' => Date::now()->addDay(7)->format('Y-m-d'),
|
||||
'recurring_limit_date' => Date::now()->addDay(7)->format('Y-m-d H:i:s'),
|
||||
'disabled_transaction_paid' => "Auto-generated",
|
||||
'disabled_transaction_number' => "Auto-generated",
|
||||
'real_type' => $this->getRawAttribute('type'),
|
||||
@ -106,11 +134,13 @@ class Transaction extends Factory
|
||||
* Get transaction number
|
||||
*
|
||||
*/
|
||||
public function getNumber($suffix = '')
|
||||
public function getNumber($type, $suffix = '', $contact = null)
|
||||
{
|
||||
$number = $this->getNextTransactionNumber($suffix);
|
||||
|
||||
$this->increaseNextTransactionNumber($suffix);
|
||||
$utility = app(TransactionNumber::class);
|
||||
|
||||
$number = $utility->getNextNumber($type, $suffix, $contact);
|
||||
|
||||
$utility->increaseNextNumber($type, $suffix ,$contact);
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
53
database/migrations/2022_08_29_000000_core_v3015.php
Normal file
53
database/migrations/2022_08_29_000000_core_v3015.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Documents
|
||||
Schema::table('documents', function(Blueprint $table) {
|
||||
$table->index('contact_id');
|
||||
});
|
||||
|
||||
// User Companies
|
||||
Schema::table('user_companies', function(Blueprint $table) {
|
||||
$table->index('user_id');
|
||||
$table->index('company_id');
|
||||
});
|
||||
|
||||
// User Roles
|
||||
Schema::table('user_roles', function(Blueprint $table) {
|
||||
$table->index('user_id');
|
||||
$table->index('role_id');
|
||||
});
|
||||
|
||||
// Transactions
|
||||
Schema::table('transactions', function(Blueprint $table) {
|
||||
$table->index('number');
|
||||
});
|
||||
|
||||
// Roles
|
||||
Schema::table('roles', function(Blueprint $table) {
|
||||
$table->index('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
64
database/migrations/2023_06_22_000000_core_v3016.php
Normal file
64
database/migrations/2023_06_22_000000_core_v3016.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Settings
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$connection = Schema::getConnection();
|
||||
$d_table = $connection->getDoctrineSchemaManager()->listTableDetails($connection->getTablePrefix() . 'settings');
|
||||
|
||||
if ($d_table->hasIndex('settings_company_id_key_unique')) {
|
||||
$table->dropUnique('settings_company_id_key_unique');
|
||||
} else {
|
||||
$table->dropUnique(['company_id', 'key']);
|
||||
}
|
||||
|
||||
$table->unique(['company_id', 'key', 'deleted_at']);
|
||||
});
|
||||
|
||||
// User Invitations
|
||||
Schema::table('user_invitations', function (Blueprint $table) {
|
||||
$table->unsignedInteger('created_by')->nullable()->after('token');
|
||||
$table->string('created_from', 100)->nullable()->after('token');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// Settings
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$connection = Schema::getConnection();
|
||||
$d_table = $connection->getDoctrineSchemaManager()->listTableDetails($connection->getTablePrefix() . 'settings');
|
||||
|
||||
if ($d_table->hasIndex('settings_company_id_key_deleted_at_unique')) {
|
||||
$table->dropUnique('settings_company_id_key_deleted_at_unique');
|
||||
} else {
|
||||
$table->dropUnique(['company_id', 'key', 'deleted_at']);
|
||||
}
|
||||
|
||||
$table->unique(['company_id', 'key']);
|
||||
});
|
||||
|
||||
// User Invitations
|
||||
Schema::table('user_invitations', function (Blueprint $table) {
|
||||
$table->dropColumn('created_by');
|
||||
$table->dropColumn('created_from');
|
||||
});
|
||||
}
|
||||
};
|
@ -36,11 +36,11 @@ class Currencies extends Seeder
|
||||
'code' => 'USD',
|
||||
'rate' => '1.00',
|
||||
'enabled' => '1',
|
||||
'precision' => config('money.USD.precision'),
|
||||
'symbol' => config('money.USD.symbol'),
|
||||
'symbol_first' => config('money.USD.symbol_first'),
|
||||
'decimal_mark' => config('money.USD.decimal_mark'),
|
||||
'thousands_separator' => config('money.USD.thousands_separator'),
|
||||
'precision' => config('money.currencies.USD.precision'),
|
||||
'symbol' => config('money.currencies.USD.symbol'),
|
||||
'symbol_first' => config('money.currencies.USD.symbol_first'),
|
||||
'decimal_mark' => config('money.currencies.USD.decimal_mark'),
|
||||
'thousands_separator' => config('money.currencies.USD.thousands_separator'),
|
||||
],
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user