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\Company\Company;
|
||||||
use App\Models\Expense\Bill;
|
use App\Models\Expense\Bill;
|
||||||
use App\Notifications\Expense\Bill as Notification;
|
use App\Notifications\Expense\Bill as Notification;
|
||||||
|
use App\Utilities\Overrider;
|
||||||
use Jenssegers\Date\Date;
|
use Date;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class BillReminder extends Command
|
class BillReminder extends Command
|
||||||
@ -27,8 +27,6 @@ class BillReminder extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -46,6 +44,13 @@ class BillReminder extends Command
|
|||||||
$companies = Company::all();
|
$companies = Company::all();
|
||||||
|
|
||||||
foreach ($companies as $company) {
|
foreach ($companies as $company) {
|
||||||
|
// Set company id
|
||||||
|
session(['company_id' => $company->id]);
|
||||||
|
|
||||||
|
// Override settings and currencies
|
||||||
|
Overrider::load('settings');
|
||||||
|
Overrider::load('currencies');
|
||||||
|
|
||||||
$company->setSettings();
|
$company->setSettings();
|
||||||
|
|
||||||
//$days = explode(',', setting('general.schedule_bill_days', '1,3'));
|
//$days = explode(',', setting('general.schedule_bill_days', '1,3'));
|
||||||
@ -57,6 +62,9 @@ class BillReminder extends Command
|
|||||||
$this->remind($day, $company);
|
$this->remind($day, $company);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unset company_id
|
||||||
|
session()->forget('company_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function remind($day, $company)
|
protected function remind($day, $company)
|
||||||
@ -65,7 +73,7 @@ class BillReminder extends Command
|
|||||||
$date = Date::today()->addDays($day)->toDateString();
|
$date = Date::today()->addDays($day)->toDateString();
|
||||||
|
|
||||||
// Get upcoming bills
|
// Get upcoming bills
|
||||||
$bills = Bill::companyId($company->id)->due($date)->with('vendor')->get();
|
$bills = Bill::with('vendor')->due($date)->get();
|
||||||
|
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
// Notify all users assigned to this company
|
// Notify all users assigned to this company
|
||||||
|
@ -5,8 +5,8 @@ namespace App\Console\Commands;
|
|||||||
use App\Models\Company\Company;
|
use App\Models\Company\Company;
|
||||||
use App\Models\Income\Invoice;
|
use App\Models\Income\Invoice;
|
||||||
use App\Notifications\Income\Invoice as Notification;
|
use App\Notifications\Income\Invoice as Notification;
|
||||||
|
use App\Utilities\Overrider;
|
||||||
use Jenssegers\Date\Date;
|
use Date;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class InvoiceReminder extends Command
|
class InvoiceReminder extends Command
|
||||||
@ -27,8 +27,6 @@ class InvoiceReminder extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -46,6 +44,13 @@ class InvoiceReminder extends Command
|
|||||||
$companies = Company::all();
|
$companies = Company::all();
|
||||||
|
|
||||||
foreach ($companies as $company) {
|
foreach ($companies as $company) {
|
||||||
|
// Set company id
|
||||||
|
session(['company_id' => $company->id]);
|
||||||
|
|
||||||
|
// Override settings and currencies
|
||||||
|
Overrider::load('settings');
|
||||||
|
Overrider::load('currencies');
|
||||||
|
|
||||||
$company->setSettings();
|
$company->setSettings();
|
||||||
|
|
||||||
//$days = explode(',', config('general.schedule_invoice_days', '1,3'));
|
//$days = explode(',', config('general.schedule_invoice_days', '1,3'));
|
||||||
@ -57,6 +62,9 @@ class InvoiceReminder extends Command
|
|||||||
$this->remind($day, $company);
|
$this->remind($day, $company);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unset company_id
|
||||||
|
session()->forget('company_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function remind($day, $company)
|
protected function remind($day, $company)
|
||||||
@ -65,7 +73,7 @@ class InvoiceReminder extends Command
|
|||||||
$date = Date::today()->subDays($day)->toDateString();
|
$date = Date::today()->subDays($day)->toDateString();
|
||||||
|
|
||||||
// Get upcoming bills
|
// Get upcoming bills
|
||||||
$invoices = Invoice::companyId($company->id)->due($date)->with('customer')->get();
|
$invoices = Invoice::with('customer')->due($date)->get();
|
||||||
|
|
||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
// Notify the customer
|
// Notify the customer
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Akaunting\Money\Currency;
|
use App\Utilities\Overrider;
|
||||||
use App\Models\Setting\Currency as Model;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
class LoadCurrencies
|
class LoadCurrencies
|
||||||
@ -23,22 +22,7 @@ class LoadCurrencies
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$currencies = Model::all();
|
Overrider::load('currencies');
|
||||||
|
|
||||||
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'));
|
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Utilities\Overrider;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
class LoadSettings
|
class LoadSettings
|
||||||
@ -21,39 +22,7 @@ class LoadSettings
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the active company settings
|
Overrider::load('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')]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ class Company implements Scope
|
|||||||
*/
|
*/
|
||||||
public function apply(Builder $builder, Model $model)
|
public function apply(Builder $builder, Model $model)
|
||||||
{
|
{
|
||||||
// Session not available in console
|
$company_id = session('company_id');
|
||||||
if (App::runningInConsole()) {
|
if (empty($company_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,8 +37,6 @@ class Company implements Scope
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply company scope
|
// Apply company scope
|
||||||
$company_id = session('company_id');
|
|
||||||
|
|
||||||
$builder->where($table . '.company_id', '=', $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