fixed #224
This commit is contained in:
parent
366a3052d3
commit
01c91b2391
@ -5,8 +5,8 @@ namespace App\Console\Commands;
|
||||
use App\Models\Company\Company;
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Notifications\Expense\Bill as Notification;
|
||||
|
||||
use Jenssegers\Date\Date;
|
||||
use App\Utilities\Overrider;
|
||||
use Date;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class BillReminder extends Command
|
||||
@ -27,8 +27,6 @@ class BillReminder extends Command
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -46,6 +44,13 @@ class BillReminder extends Command
|
||||
$companies = Company::all();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
// Set company id
|
||||
session(['company_id' => $company->id]);
|
||||
|
||||
// Override settings and currencies
|
||||
Overrider::load('settings');
|
||||
Overrider::load('currencies');
|
||||
|
||||
$company->setSettings();
|
||||
|
||||
//$days = explode(',', setting('general.schedule_bill_days', '1,3'));
|
||||
@ -57,6 +62,9 @@ class BillReminder extends Command
|
||||
$this->remind($day, $company);
|
||||
}
|
||||
}
|
||||
|
||||
// Unset company_id
|
||||
session()->forget('company_id');
|
||||
}
|
||||
|
||||
protected function remind($day, $company)
|
||||
@ -65,7 +73,7 @@ class BillReminder extends Command
|
||||
$date = Date::today()->addDays($day)->toDateString();
|
||||
|
||||
// Get upcoming bills
|
||||
$bills = Bill::companyId($company->id)->due($date)->with('vendor')->get();
|
||||
$bills = Bill::with('vendor')->due($date)->get();
|
||||
|
||||
foreach ($bills as $bill) {
|
||||
// Notify all users assigned to this company
|
||||
|
@ -5,8 +5,8 @@ namespace App\Console\Commands;
|
||||
use App\Models\Company\Company;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Notifications\Income\Invoice as Notification;
|
||||
|
||||
use Jenssegers\Date\Date;
|
||||
use App\Utilities\Overrider;
|
||||
use Date;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class InvoiceReminder extends Command
|
||||
@ -27,8 +27,6 @@ class InvoiceReminder extends Command
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -46,6 +44,13 @@ class InvoiceReminder extends Command
|
||||
$companies = Company::all();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
// Set company id
|
||||
session(['company_id' => $company->id]);
|
||||
|
||||
// Override settings and currencies
|
||||
Overrider::load('settings');
|
||||
Overrider::load('currencies');
|
||||
|
||||
$company->setSettings();
|
||||
|
||||
//$days = explode(',', config('general.schedule_invoice_days', '1,3'));
|
||||
@ -57,6 +62,9 @@ class InvoiceReminder extends Command
|
||||
$this->remind($day, $company);
|
||||
}
|
||||
}
|
||||
|
||||
// Unset company_id
|
||||
session()->forget('company_id');
|
||||
}
|
||||
|
||||
protected function remind($day, $company)
|
||||
@ -65,7 +73,7 @@ class InvoiceReminder extends Command
|
||||
$date = Date::today()->subDays($day)->toDateString();
|
||||
|
||||
// Get upcoming bills
|
||||
$invoices = Invoice::companyId($company->id)->due($date)->with('customer')->get();
|
||||
$invoices = Invoice::with('customer')->due($date)->get();
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
// Notify the customer
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Akaunting\Money\Currency;
|
||||
use App\Models\Setting\Currency as Model;
|
||||
use App\Utilities\Overrider;
|
||||
use Closure;
|
||||
|
||||
class LoadCurrencies
|
||||
@ -23,22 +22,7 @@ class LoadCurrencies
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$currencies = Model::all();
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
if (!isset($currency->precision)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
config(['money.' . $currency->code . '.precision' => $currency->precision]);
|
||||
config(['money.' . $currency->code . '.symbol' => $currency->symbol]);
|
||||
config(['money.' . $currency->code . '.symbol_first' => $currency->symbol_first]);
|
||||
config(['money.' . $currency->code . '.decimal_mark' => $currency->decimal_mark]);
|
||||
config(['money.' . $currency->code . '.thousands_separator' => $currency->thousands_separator]);
|
||||
}
|
||||
|
||||
// Set currencies with new settings
|
||||
Currency::setCurrencies(config('money'));
|
||||
Overrider::load('currencies');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Utilities\Overrider;
|
||||
use Closure;
|
||||
|
||||
class LoadSettings
|
||||
@ -21,39 +22,7 @@ class LoadSettings
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Set the active company settings
|
||||
setting()->setExtraColumns(['company_id' => $company_id]);
|
||||
setting()->load(true);
|
||||
|
||||
// Timezone
|
||||
config(['app.timezone' => setting('general.timezone', 'UTC')]);
|
||||
|
||||
// Email
|
||||
$email_protocol = setting('general.email_protocol', 'mail');
|
||||
config(['mail.driver' => $email_protocol]);
|
||||
config(['mail.from.name' => setting('general.company_name')]);
|
||||
config(['mail.from.address' => setting('general.company_email')]);
|
||||
|
||||
if ($email_protocol == 'sendmail') {
|
||||
config(['mail.sendmail' => setting('general.email_sendmail_path')]);
|
||||
} elseif ($email_protocol == 'smtp') {
|
||||
config(['mail.host' => setting('general.email_smtp_host')]);
|
||||
config(['mail.port' => setting('general.email_smtp_port')]);
|
||||
config(['mail.username' => setting('general.email_smtp_username')]);
|
||||
config(['mail.password' => setting('general.email_smtp_password')]);
|
||||
config(['mail.encryption' => setting('general.email_smtp_encryption')]);
|
||||
}
|
||||
|
||||
// Session
|
||||
config(['session.driver' => setting('general.session_handler', 'file')]);
|
||||
config(['session.lifetime' => setting('general.session_lifetime', '30')]);
|
||||
|
||||
// Locale
|
||||
if (session('locale') == '') {
|
||||
//App::setLocale(setting('general.default_language'));
|
||||
//Session::put('locale', setting('general.default_language'));
|
||||
config(['app.locale' => setting('general.default_locale')]);
|
||||
}
|
||||
Overrider::load('settings');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ class Company implements Scope
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
{
|
||||
// Session not available in console
|
||||
if (App::runningInConsole()) {
|
||||
$company_id = session('company_id');
|
||||
if (empty($company_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -37,8 +37,6 @@ class Company implements Scope
|
||||
}
|
||||
|
||||
// Apply company scope
|
||||
$company_id = session('company_id');
|
||||
|
||||
$builder->where($table . '.company_id', '=', $company_id);
|
||||
}
|
||||
|
||||
|
83
app/Utilities/Overrider.php
Normal file
83
app/Utilities/Overrider.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use App\Models\Setting\Currency;
|
||||
|
||||
class Overrider
|
||||
{
|
||||
public static $company_id;
|
||||
|
||||
public static function load($type)
|
||||
{
|
||||
// Overrides apply per company
|
||||
$company_id = session('company_id');
|
||||
if (empty($company_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
static::$company_id = $company_id;
|
||||
|
||||
$method = 'load' . ucfirst($type);
|
||||
|
||||
static::$method();
|
||||
}
|
||||
|
||||
protected static function loadSettings()
|
||||
{
|
||||
// Set the active company settings
|
||||
setting()->setExtraColumns(['company_id' => static::$company_id]);
|
||||
setting()->load(true);
|
||||
|
||||
// Timezone
|
||||
config(['app.timezone' => setting('general.timezone', 'UTC')]);
|
||||
|
||||
// Email
|
||||
$email_protocol = setting('general.email_protocol', 'mail');
|
||||
config(['mail.driver' => $email_protocol]);
|
||||
config(['mail.from.name' => setting('general.company_name')]);
|
||||
config(['mail.from.address' => setting('general.company_email')]);
|
||||
|
||||
if ($email_protocol == 'sendmail') {
|
||||
config(['mail.sendmail' => setting('general.email_sendmail_path')]);
|
||||
} elseif ($email_protocol == 'smtp') {
|
||||
config(['mail.host' => setting('general.email_smtp_host')]);
|
||||
config(['mail.port' => setting('general.email_smtp_port')]);
|
||||
config(['mail.username' => setting('general.email_smtp_username')]);
|
||||
config(['mail.password' => setting('general.email_smtp_password')]);
|
||||
config(['mail.encryption' => setting('general.email_smtp_encryption')]);
|
||||
}
|
||||
|
||||
// Session
|
||||
config(['session.driver' => setting('general.session_handler', 'file')]);
|
||||
config(['session.lifetime' => setting('general.session_lifetime', '30')]);
|
||||
|
||||
// Locale
|
||||
if (session('locale') == '') {
|
||||
//App::setLocale(setting('general.default_language'));
|
||||
//Session::put('locale', setting('general.default_language'));
|
||||
config(['app.locale' => setting('general.default_locale')]);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function loadCurrencies()
|
||||
{
|
||||
$currencies = Currency::all();
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
if (!isset($currency->precision)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
config(['money.' . $currency->code . '.precision' => $currency->precision]);
|
||||
config(['money.' . $currency->code . '.symbol' => $currency->symbol]);
|
||||
config(['money.' . $currency->code . '.symbol_first' => $currency->symbol_first]);
|
||||
config(['money.' . $currency->code . '.decimal_mark' => $currency->decimal_mark]);
|
||||
config(['money.' . $currency->code . '.thousands_separator' => $currency->thousands_separator]);
|
||||
}
|
||||
|
||||
// Set currencies with new settings
|
||||
\Akaunting\Money\Currency::setCurrencies(config('money'));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user