v2 first commit
This commit is contained in:
@@ -41,9 +41,11 @@ class BillReminder extends Command
|
||||
public function handle()
|
||||
{
|
||||
// Get all companies
|
||||
$companies = Company::all();
|
||||
$companies = Company::enabled()->cursor();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
$this->info('Sending bill reminders for ' . $company->name . ' company.');
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company->id]);
|
||||
|
||||
@@ -51,14 +53,14 @@ class BillReminder extends Command
|
||||
Overrider::load('settings');
|
||||
Overrider::load('currencies');
|
||||
|
||||
$company->setSettings();
|
||||
|
||||
// Don't send reminders if disabled
|
||||
if (!$company->send_bill_reminder) {
|
||||
if (!setting('schedule.send_bill_reminder')) {
|
||||
$this->info('Bill reminders disabled by ' . $company->name . '.');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$days = explode(',', $company->schedule_bill_days);
|
||||
$days = explode(',', setting('schedule.bill_days'));
|
||||
|
||||
foreach ($days as $day) {
|
||||
$day = (int) trim($day);
|
||||
@@ -69,6 +71,7 @@ class BillReminder extends Command
|
||||
|
||||
// Unset company_id
|
||||
session()->forget('company_id');
|
||||
setting()->forgetAll();
|
||||
}
|
||||
|
||||
protected function remind($day, $company)
|
||||
@@ -77,7 +80,7 @@ class BillReminder extends Command
|
||||
$date = Date::today()->addDays($day)->toDateString();
|
||||
|
||||
// Get upcoming bills
|
||||
$bills = Bill::with('vendor')->accrued()->notPaid()->due($date)->get();
|
||||
$bills = Bill::with('contact')->accrued()->notPaid()->due($date)->cursor();
|
||||
|
||||
foreach ($bills as $bill) {
|
||||
// Notify all users assigned to this company
|
||||
@@ -86,7 +89,7 @@ class BillReminder extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($bill));
|
||||
$user->notify(new Notification($bill, 'bill_remind_admin'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -38,10 +38,9 @@ class CompanySeed extends Command
|
||||
public function handle()
|
||||
{
|
||||
$class = $this->laravel->make('CompanySeeder');
|
||||
|
||||
|
||||
$seeder = $class->setContainer($this->laravel)->setCommand($this);
|
||||
|
||||
|
||||
$seeder->__invoke();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -212,7 +212,8 @@ class Install extends Command
|
||||
}
|
||||
}
|
||||
|
||||
private function createDatabaseTables() {
|
||||
private function createDatabaseTables()
|
||||
{
|
||||
$this->dbHost = $this->option(self::OPT_DB_HOST);
|
||||
$this->dbPort = $this->option(self::OPT_DB_PORT);
|
||||
$this->dbName = $this->option(self::OPT_DB_NAME);
|
||||
|
@@ -41,9 +41,11 @@ class InvoiceReminder extends Command
|
||||
public function handle()
|
||||
{
|
||||
// Get all companies
|
||||
$companies = Company::all();
|
||||
$companies = Company::enabled()->cursor();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
$this->info('Sending invoice reminders for ' . $company->name . ' company.');
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company->id]);
|
||||
|
||||
@@ -51,14 +53,14 @@ class InvoiceReminder extends Command
|
||||
Overrider::load('settings');
|
||||
Overrider::load('currencies');
|
||||
|
||||
$company->setSettings();
|
||||
|
||||
// Don't send reminders if disabled
|
||||
if (!$company->send_invoice_reminder) {
|
||||
if (!setting('schedule.send_invoice_reminder')) {
|
||||
$this->info('Invoice reminders disabled by ' . $company->name . '.');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$days = explode(',', $company->schedule_invoice_days);
|
||||
$days = explode(',', setting('schedule.invoice_days'));
|
||||
|
||||
foreach ($days as $day) {
|
||||
$day = (int) trim($day);
|
||||
@@ -69,6 +71,7 @@ class InvoiceReminder extends Command
|
||||
|
||||
// Unset company_id
|
||||
session()->forget('company_id');
|
||||
setting()->forgetAll();
|
||||
}
|
||||
|
||||
protected function remind($day, $company)
|
||||
@@ -76,13 +79,13 @@ class InvoiceReminder extends Command
|
||||
// Get due date
|
||||
$date = Date::today()->subDays($day)->toDateString();
|
||||
|
||||
// Get upcoming bills
|
||||
$invoices = Invoice::with('customer')->accrued()->notPaid()->due($date)->get();
|
||||
// Get upcoming invoices
|
||||
$invoices = Invoice::with('contact')->accrued()->notPaid()->due($date)->cursor();
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
// Notify the customer
|
||||
if ($invoice->customer && !empty($invoice->customer_email)) {
|
||||
$invoice->customer->notify(new Notification($invoice));
|
||||
if ($invoice->contact && !empty($invoice->contact_email)) {
|
||||
$invoice->contact->notify(new Notification($invoice, 'invoice_remind_customer'));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
@@ -91,7 +94,7 @@ class InvoiceReminder extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($invoice));
|
||||
$user->notify(new Notification($invoice, 'invoice_remind_admin'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Artisan;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class ModuleDelete extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:delete {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$alias = $this->argument('alias');
|
||||
$company_id = $this->argument('company_id');
|
||||
|
||||
$model = Module::alias($alias)->companyId($company_id)->first();
|
||||
|
||||
if (!$model) {
|
||||
$this->info("Module [{$alias}] not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
$module = $this->laravel['modules']->findByAlias($alias);
|
||||
$module->delete();
|
||||
|
||||
$model->status = 0;
|
||||
$model->save();
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category'),
|
||||
'version' => $module->get('version'),
|
||||
'description' => trans('modules.deleted', ['module' => $module->get('name')]),
|
||||
];
|
||||
|
||||
ModuleHistory::create($data);
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
$this->info("Module [{$alias}] deleted.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class ModuleDisable extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:disable {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Disable the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$alias = $this->argument('alias');
|
||||
$company_id = $this->argument('company_id');
|
||||
|
||||
$model = Module::alias($alias)->companyId($company_id)->first();
|
||||
|
||||
if (!$model) {
|
||||
$this->info("Module [{$alias}] not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($model->status == 1) {
|
||||
$model->status = 0;
|
||||
$model->save();
|
||||
|
||||
$module = $this->laravel['modules']->findByAlias($alias);
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category'),
|
||||
'version' => $module->get('version'),
|
||||
'description' => trans('modules.disabled', ['module' => $module->get('name')]),
|
||||
];
|
||||
|
||||
ModuleHistory::create($data);
|
||||
|
||||
$this->info("Module [{$alias}] disabled.");
|
||||
} else {
|
||||
$this->comment("Module [{$alias}] is already disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class ModuleEnable extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:enable {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Enable the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$alias = $this->argument('alias');
|
||||
$company_id = $this->argument('company_id');
|
||||
|
||||
$model = Module::alias($alias)->companyId($company_id)->first();
|
||||
|
||||
if (!$model) {
|
||||
$this->info("Module [{$alias}] not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($model->status == 0) {
|
||||
$model->status = 1;
|
||||
$model->save();
|
||||
|
||||
$module = $this->laravel['modules']->findByAlias($alias);
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category'),
|
||||
'version' => $module->get('version'),
|
||||
'description' => trans('modules.enabled', ['module' => $module->get('name')]),
|
||||
];
|
||||
|
||||
ModuleHistory::create($data);
|
||||
|
||||
$this->info("Module [{$alias}] enabled.");
|
||||
} else {
|
||||
$this->comment("Module [{$alias}] is already enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\ModuleInstalled;
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class ModuleInstall extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:install {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Install the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$alias = $this->argument('alias');
|
||||
$company_id = $this->argument('company_id');
|
||||
|
||||
$old_company_id = session('company_id');
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
$request = [
|
||||
'company_id' => $company_id,
|
||||
'alias' => strtolower($alias),
|
||||
'status' => '1',
|
||||
];
|
||||
|
||||
$model = Module::create($request);
|
||||
|
||||
$module = $this->laravel['modules']->findByAlias($alias);
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category'),
|
||||
'version' => $module->get('version'),
|
||||
'description' => trans('modules.installed', ['module' => $module->get('name')]),
|
||||
];
|
||||
|
||||
ModuleHistory::create($data);
|
||||
|
||||
// Clear cache
|
||||
$this->call('cache:clear');
|
||||
|
||||
// Update database
|
||||
$this->call('migrate', ['--force' => true]);
|
||||
|
||||
// Trigger event
|
||||
event(new ModuleInstalled($alias, $company_id));
|
||||
|
||||
// Unset company id
|
||||
session()->forget('company_id');
|
||||
|
||||
// Set company id
|
||||
if (!empty($old_company_id)) {
|
||||
session(['company_id' => $old_company_id]);
|
||||
}
|
||||
|
||||
$this->info('Module installed!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
||||
);
|
||||
}
|
||||
}
|
@@ -2,18 +2,16 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\Expense\BillCreated;
|
||||
use App\Events\Expense\BillRecurring;
|
||||
use App\Events\Income\InvoiceCreated;
|
||||
use App\Events\Income\InvoiceRecurring;
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Expense\BillHistory;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Notifications\Expense\Bill as BillNotification;
|
||||
use App\Notifications\Income\Invoice as InvoiceNotification;
|
||||
use App\Traits\Incomes;
|
||||
use App\Utilities\Overrider;
|
||||
use Carbon\Carbon;
|
||||
use Date;
|
||||
use Illuminate\Console\Command;
|
||||
use Recurr\Rule;
|
||||
use Recurr\Transformer\ArrayTransformer;
|
||||
use Recurr\Transformer\ArrayTransformerConfig;
|
||||
|
||||
class RecurringCheck extends Command
|
||||
{
|
||||
@@ -32,7 +30,14 @@ class RecurringCheck extends Command
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Check for recurring';
|
||||
|
||||
|
||||
/**
|
||||
* The current day.
|
||||
*
|
||||
* @var Carbon
|
||||
*/
|
||||
protected $today;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
@@ -48,12 +53,12 @@ class RecurringCheck extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->today = Date::today();
|
||||
|
||||
// Get all companies
|
||||
$companies = Company::all();
|
||||
$companies = Company::enabled()->cursor();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
$this->info('Creating recurring records for ' . $company->name . ' company.');
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company->id]);
|
||||
|
||||
@@ -61,43 +66,11 @@ class RecurringCheck extends Command
|
||||
Overrider::load('settings');
|
||||
Overrider::load('currencies');
|
||||
|
||||
$company->setSettings();
|
||||
$this->today = Date::today();
|
||||
|
||||
foreach ($company->recurring as $recurring) {
|
||||
foreach ($recurring->schedule() as $recur) {
|
||||
$recur_date = Date::parse($recur->getStart()->format('Y-m-d'));
|
||||
|
||||
// Check if should recur today
|
||||
if ($this->today->ne($recur_date)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$model = $recurring->recurable;
|
||||
|
||||
if (!$model) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($recurring->recurable_type) {
|
||||
case 'App\Models\Expense\Bill':
|
||||
$this->recurBill($company, $model);
|
||||
break;
|
||||
case 'App\Models\Income\Invoice':
|
||||
$this->recurInvoice($company, $model);
|
||||
break;
|
||||
case 'App\Models\Expense\Payment':
|
||||
case 'App\Models\Income\Revenue':
|
||||
$model->cloneable_relations = [];
|
||||
|
||||
// Create new record
|
||||
$clone = $model->duplicate();
|
||||
|
||||
$clone->parent_id = $model->id;
|
||||
$clone->paid_at = $this->today->format('Y-m-d');
|
||||
$clone->save();
|
||||
|
||||
break;
|
||||
}
|
||||
foreach ($recurring->schedule() as $schedule) {
|
||||
$this->recur($recurring, $schedule);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,85 +79,90 @@ class RecurringCheck extends Command
|
||||
session()->forget('company_id');
|
||||
}
|
||||
|
||||
protected function recurInvoice($company, $model)
|
||||
protected function recur($recurring, $schedule)
|
||||
{
|
||||
$model->cloneable_relations = ['items', 'totals'];
|
||||
$schedule_date = Date::parse($schedule->getStart()->format('Y-m-d'));
|
||||
|
||||
// Create new record
|
||||
$clone = $model->duplicate();
|
||||
|
||||
// Set original invoice id
|
||||
$clone->parent_id = $model->id;
|
||||
|
||||
// Days between invoiced and due date
|
||||
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
|
||||
|
||||
// Update dates
|
||||
$clone->invoiced_at = $this->today->format('Y-m-d');
|
||||
$clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
|
||||
$clone->save();
|
||||
|
||||
// Add invoice history
|
||||
InvoiceHistory::create([
|
||||
'company_id' => session('company_id'),
|
||||
'invoice_id' => $clone->id,
|
||||
'status_code' => 'draft',
|
||||
'notify' => 0,
|
||||
'description' => trans('messages.success.added', ['type' => $clone->invoice_number]),
|
||||
]);
|
||||
|
||||
// Notify the customer
|
||||
if ($clone->customer && !empty($clone->customer_email)) {
|
||||
$clone->customer->notify(new InvoiceNotification($clone));
|
||||
// Check if should recur today
|
||||
if ($this->today->ne($schedule_date)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new InvoiceNotification($clone));
|
||||
if (!$model = $recurring->recurable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update next invoice number
|
||||
$this->increaseNextInvoiceNumber();
|
||||
switch ($recurring->recurable_type) {
|
||||
case 'App\Models\Expense\Bill':
|
||||
if (!$clone = $this->getDocumentClone($model, 'billed_at')) {
|
||||
break;
|
||||
}
|
||||
|
||||
event(new BillCreated($clone));
|
||||
|
||||
event(new BillRecurring($clone));
|
||||
|
||||
break;
|
||||
case 'App\Models\Income\Invoice':
|
||||
if (!$clone = $this->getDocumentClone($model, 'invoiced_at')) {
|
||||
break;
|
||||
}
|
||||
|
||||
event(new InvoiceCreated($clone));
|
||||
|
||||
event(new InvoiceRecurring($clone));
|
||||
|
||||
break;
|
||||
case 'App\Models\Banking\Transaction':
|
||||
// Skip model created on the same day, but scheduler hasn't run yet
|
||||
if ($this->today->eq(Date::parse($model->paid_at->format('Y-m-d')))) {
|
||||
break;
|
||||
}
|
||||
|
||||
$model->cloneable_relations = [];
|
||||
|
||||
// Create new record
|
||||
$clone = $model->duplicate();
|
||||
|
||||
$clone->parent_id = $model->id;
|
||||
$clone->paid_at = $this->today->format('Y-m-d');
|
||||
$clone->save();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function recurBill($company, $model)
|
||||
/**
|
||||
* Clone the document and return it.
|
||||
*
|
||||
* @param $model
|
||||
* @param $date_field
|
||||
*
|
||||
* @return boolean|object
|
||||
*/
|
||||
protected function getDocumentClone($model, $date_field)
|
||||
{
|
||||
// Skip model created on the same day, but scheduler hasn't run yet
|
||||
if ($this->today->eq(Date::parse($model->$date_field->format('Y-m-d')))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$model->cloneable_relations = ['items', 'totals'];
|
||||
|
||||
// Create new record
|
||||
$clone = $model->duplicate();
|
||||
|
||||
// Set original bill id
|
||||
// Set original model id
|
||||
$clone->parent_id = $model->id;
|
||||
|
||||
// Days between invoiced and due date
|
||||
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
|
||||
// Days between issued and due date
|
||||
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->$date_field));
|
||||
|
||||
// Update dates
|
||||
$clone->billed_at = $this->today->format('Y-m-d');
|
||||
$clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
|
||||
$clone->$date_field = $this->today->format('Y-m-d');
|
||||
$clone->due_at = $this->today->copy()->addDays($diff_days)->format('Y-m-d');
|
||||
$clone->save();
|
||||
|
||||
// Add bill history
|
||||
BillHistory::create([
|
||||
'company_id' => session('company_id'),
|
||||
'bill_id' => $clone->id,
|
||||
'status_code' => 'draft',
|
||||
'notify' => 0,
|
||||
'description' => trans('messages.success.added', ['type' => $clone->bill_number]),
|
||||
]);
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new BillNotification($clone));
|
||||
}
|
||||
|
||||
return $clone;
|
||||
}
|
||||
}
|
||||
|
46
app/Console/Commands/UserSeed.php
Normal file
46
app/Console/Commands/UserSeed.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UserSeed extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:seed {user} {company}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Seed for specific user';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$class = $this->laravel->make('UserSeeder');
|
||||
|
||||
$seeder = $class->setContainer($this->laravel)->setCommand($this);
|
||||
|
||||
$seeder->__invoke();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user