Merge branch 'master' into master
This commit is contained in:
@@ -31,17 +31,21 @@ class ModuleInstall extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$alias = $this->argument('alias');
|
||||
$company_id = $this->argument('company_id');
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
$request = [
|
||||
'company_id' => $this->argument('company_id'),
|
||||
'alias' => strtolower($this->argument('alias')),
|
||||
'company_id' => $company_id,
|
||||
'alias' => strtolower($alias),
|
||||
'status' => '1',
|
||||
];
|
||||
|
||||
$model = Module::create($request);
|
||||
|
||||
$module = $this->laravel['modules']->findByAlias($model->alias);
|
||||
|
||||
$company_id = $this->argument('company_id');
|
||||
$module = $this->laravel['modules']->findByAlias($alias);
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
@@ -61,7 +65,10 @@ class ModuleInstall extends Command
|
||||
$this->call('migrate', ['--force' => true]);
|
||||
|
||||
// Trigger event
|
||||
event(new ModuleInstalled($model->alias, $company_id));
|
||||
event(new ModuleInstalled($alias, $company_id));
|
||||
|
||||
// Unset company id
|
||||
session()->forget('company_id');
|
||||
|
||||
$this->info('Module installed!');
|
||||
}
|
||||
|
||||
@@ -178,8 +178,6 @@ class Accounts extends Controller
|
||||
$message = trans('messages.warning.disabled', ['name' => $account->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
flash($message)->warning();
|
||||
|
||||
return redirect()->route('accounts.index');
|
||||
}
|
||||
|
||||
return redirect()->route('accounts.index');
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Http\Requests\Common\Company as Request;
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\Overrider;
|
||||
|
||||
class Companies extends Controller
|
||||
{
|
||||
@@ -60,6 +61,8 @@ class Companies extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$company_id = session('company_id');
|
||||
|
||||
setting()->forgetAll();
|
||||
|
||||
// Create company
|
||||
@@ -86,6 +89,12 @@ class Companies extends Controller
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
setting()->save();
|
||||
|
||||
setting()->forgetAll();
|
||||
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
Overrider::load('settings');
|
||||
|
||||
// Redirect
|
||||
$message = trans('messages.success.added', ['type' => trans_choice('general.companies', 1)]);
|
||||
|
||||
@@ -129,6 +138,8 @@ class Companies extends Controller
|
||||
*/
|
||||
public function update(Company $company, Request $request)
|
||||
{
|
||||
$company_id = session('company_id');
|
||||
|
||||
// Check if user can update company
|
||||
if (!$this->isUserCompany($company)) {
|
||||
$message = trans('companies.error.not_user_company');
|
||||
@@ -166,6 +177,12 @@ class Companies extends Controller
|
||||
|
||||
setting()->save();
|
||||
|
||||
setting()->forgetAll();
|
||||
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
Overrider::load('settings');
|
||||
|
||||
// Redirect
|
||||
$message = trans('messages.success.updated', ['type' => trans_choice('general.companies', 1)]);
|
||||
|
||||
@@ -191,6 +208,7 @@ class Companies extends Controller
|
||||
flash($message)->success();
|
||||
|
||||
return redirect()->route('companies.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -184,7 +184,9 @@ class Invoices extends Controller
|
||||
|
||||
public function link(Invoice $invoice, Request $request)
|
||||
{
|
||||
session(['company_id' => $invoice->company_id]);
|
||||
if (empty($invoice)) {
|
||||
redirect()->route('login');
|
||||
}
|
||||
|
||||
$paid = 0;
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ class Bills extends Controller
|
||||
*/
|
||||
public function destroy(Bill $bill)
|
||||
{
|
||||
$this->deleteRelationships($bill, ['items', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$this->deleteRelationships($bill, ['items', 'itemTaxes', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$bill->delete();
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => trans_choice('general.bills', 1)]);
|
||||
|
||||
@@ -257,7 +257,7 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function destroy(Invoice $invoice)
|
||||
{
|
||||
$this->deleteRelationships($invoice, ['items', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$this->deleteRelationships($invoice, ['items', 'itemTaxes', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$invoice->delete();
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => trans_choice('general.invoices', 1)]);
|
||||
|
||||
@@ -83,7 +83,7 @@ class Updates extends Controller
|
||||
public function update($alias, $version)
|
||||
{
|
||||
if ($alias == 'core') {
|
||||
$name = 'Akaunting v' . $version;
|
||||
$name = 'Akaunting ' . $version;
|
||||
|
||||
$installed = version('short');
|
||||
} else {
|
||||
@@ -98,33 +98,6 @@ class Updates extends Controller
|
||||
return view('install.updates.edit', compact('alias', 'name', 'installed', 'version'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Final actions post update.
|
||||
*
|
||||
* @param $alias
|
||||
* @param $old
|
||||
* @param $new
|
||||
* @return Response
|
||||
*/
|
||||
public function post($alias, $old, $new)
|
||||
{
|
||||
// Check if the file mirror was successful
|
||||
if (($alias == 'core') && (version('short') != $new)) {
|
||||
flash(trans('updates.error'))->error()->important();
|
||||
|
||||
return redirect('install/updates');
|
||||
}
|
||||
|
||||
// Clear cache after update
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
event(new UpdateFinished($alias, $old, $new));
|
||||
|
||||
flash(trans('updates.success'))->success();
|
||||
|
||||
return redirect('install/updates');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for viewing the specified resource.
|
||||
*
|
||||
|
||||
@@ -286,8 +286,6 @@ class Item extends Controller
|
||||
* Final actions post update.
|
||||
*
|
||||
* @param $alias
|
||||
* @param $old
|
||||
* @param $new
|
||||
* @return Response
|
||||
*/
|
||||
public function post($alias)
|
||||
|
||||
@@ -169,7 +169,7 @@ class ProfitLoss extends Controller
|
||||
private function setAmount(&$totals, &$compares, $items, $type, $date_field)
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
if ($item['table'] == 'bill_payments' || $item['table'] == 'invoice_payments') {
|
||||
if (($item['table'] == 'bill_payments') || ($item['table'] == 'invoice_payments')) {
|
||||
$type_item = $item->$type;
|
||||
|
||||
$item->category_id = $type_item->category_id;
|
||||
@@ -183,7 +183,7 @@ class ProfitLoss extends Controller
|
||||
continue;
|
||||
}
|
||||
|
||||
$amount = $item->getConvertedAmount();
|
||||
$amount = $item->getConvertedAmount(false, false);
|
||||
|
||||
// Forecasting
|
||||
if ((($type == 'invoice') || ($type == 'bill')) && ($date_field == 'due_at')) {
|
||||
|
||||
@@ -178,8 +178,6 @@ class Categories extends Controller
|
||||
$message = trans('messages.warning.disabled', ['name' => $category->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
flash($message)->warning();
|
||||
|
||||
return redirect()->route('categories.index');
|
||||
}
|
||||
|
||||
return redirect()->route('categories.index');
|
||||
|
||||
@@ -222,8 +222,6 @@ class Currencies extends Controller
|
||||
$message = trans('messages.warning.disabled', ['name' => $currency->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
flash($message)->warning();
|
||||
|
||||
return redirect()->route('currencies.index');
|
||||
}
|
||||
|
||||
return redirect()->route('currencies.index');
|
||||
|
||||
@@ -167,8 +167,6 @@ class Taxes extends Controller
|
||||
$message = trans('messages.warning.disabled', ['name' => $tax->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
flash($message)->warning();
|
||||
|
||||
return redirect()->route('taxes.index');
|
||||
}
|
||||
|
||||
return redirect()->route('taxes.index');
|
||||
|
||||
@@ -73,6 +73,11 @@ class Kernel extends HttpKernel
|
||||
'company.settings',
|
||||
'company.currencies',
|
||||
],
|
||||
|
||||
'signed' => [
|
||||
'signed-url',
|
||||
'signed-url.company',
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -100,5 +105,6 @@ class Kernel extends HttpKernel
|
||||
'company.currencies' => \App\Http\Middleware\LoadCurrencies::class,
|
||||
'dateformat' => \App\Http\Middleware\DateFormat::class,
|
||||
'money' => \App\Http\Middleware\Money::class,
|
||||
'signed-url.company' => \App\Http\Middleware\SignedUrlCompany::class,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -36,5 +36,4 @@ class ApiCompany
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
33
app/Http/Middleware/SignedUrlCompany.php
Normal file
33
app/Http/Middleware/SignedUrlCompany.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class SignedUrlCompany
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$company_id = $request->get('company_id');
|
||||
|
||||
if (empty($company_id)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
// Set the company settings
|
||||
setting()->setExtraColumns(['company_id' => $company_id]);
|
||||
setting()->load(true);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,25 @@
|
||||
|
||||
namespace App\Http\Requests\Wizard;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Traits\Modules as RemoteModules;
|
||||
use Illuminate\Validation\Factory as ValidationFactory;
|
||||
|
||||
class Company extends FormRequest
|
||||
class Company extends Request
|
||||
{
|
||||
use RemoteModules;
|
||||
|
||||
public function __construct(ValidationFactory $validation)
|
||||
{
|
||||
$validation->extend(
|
||||
'check',
|
||||
function ($attribute, $value, $parameters) {
|
||||
return $this->checkToken($value);
|
||||
},
|
||||
trans('messages.error.invalid_token')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
@@ -23,8 +38,14 @@ class Company extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
$rules = [
|
||||
'company_logo' => 'mimes:' . setting('general.file_types') . '|between:0,' . setting('general.file_size') * 1024,
|
||||
];
|
||||
|
||||
if (!setting('general.api_token', false)) {
|
||||
$rules['api_token'] = 'required|string|check';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Modules
|
||||
public function compose(View $view)
|
||||
{
|
||||
if (setting('general.api_token')) {
|
||||
$categories = Cache::remember('modules.categories', Date::now()->addHour(6), function () {
|
||||
$categories = Cache::remember('modules.categories.' . language()->getShortCode(), Date::now()->addHour(6), function () {
|
||||
return collect($this->getCategories())->pluck('name', 'slug')
|
||||
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');
|
||||
});
|
||||
|
||||
@@ -77,7 +77,7 @@ class CreateBillItem
|
||||
$tax = Tax::find($tax_id);
|
||||
|
||||
switch ($tax->type) {
|
||||
case 'included':
|
||||
case 'inclusive':
|
||||
$inclusives[] = $tax;
|
||||
break;
|
||||
case 'compound':
|
||||
|
||||
@@ -23,7 +23,7 @@ class Bill extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['attachment', 'discount', 'paid'];
|
||||
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];
|
||||
|
||||
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
|
||||
|
||||
@@ -201,6 +201,22 @@ class Bill extends Model
|
||||
return $percent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount without tax.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAmountWithoutTaxAttribute()
|
||||
{
|
||||
$amount = $this->amount;
|
||||
|
||||
$this->totals()->where('code', 'tax')->each(function ($tax) use(&$amount) {
|
||||
$amount -= $tax->amount;
|
||||
});
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the paid amount.
|
||||
*
|
||||
|
||||
@@ -24,7 +24,7 @@ class Invoice extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['attachment', 'discount', 'paid'];
|
||||
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];
|
||||
|
||||
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
|
||||
|
||||
@@ -205,6 +205,22 @@ class Invoice extends Model
|
||||
return $percent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount without tax.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAmountWithoutTaxAttribute()
|
||||
{
|
||||
$amount = $this->amount;
|
||||
|
||||
$this->totals()->where('code', 'tax')->each(function ($tax) use(&$amount) {
|
||||
$amount -= $tax->amount;
|
||||
});
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the paid amount.
|
||||
*
|
||||
|
||||
54
app/Overrides/Akaunting/SignedUrl.php
Normal file
54
app/Overrides/Akaunting/SignedUrl.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Akaunting\SignedUrl;
|
||||
|
||||
use Spatie\UrlSigner\MD5UrlSigner;
|
||||
|
||||
class SignedUrl extends MD5UrlSigner
|
||||
{
|
||||
|
||||
/**
|
||||
* The key that is used to generate secure signatures.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signatureKey;
|
||||
|
||||
/**
|
||||
* The URL's query parameter name for the expiration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $expiresParameter;
|
||||
|
||||
/**
|
||||
* The URL's query parameter name for the signature.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signatureParameter;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->signatureKey = config('signed-url.signatureKey');
|
||||
$this->expiresParameter = config('signed-url.parameters.expires');
|
||||
$this->signatureParameter = config('signed-url.parameters.signature');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a secure URL to a controller action.
|
||||
*
|
||||
* @param string $url
|
||||
* @param \DateTime|int|null $expiration Defaults to the config value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sign($url, $expiration = null)
|
||||
{
|
||||
$url .= '?company_id=' . session('company_id');
|
||||
|
||||
$expiration = $expiration ? $expiration : config('signed-url.default_expiration_time_in_days');
|
||||
|
||||
return parent::sign($url, $expiration);
|
||||
}
|
||||
}
|
||||
@@ -60,18 +60,24 @@ trait Currencies
|
||||
return $money;
|
||||
}
|
||||
|
||||
public function getConvertedAmount($format = false)
|
||||
public function getConvertedAmount($format = false, $with_tax = true)
|
||||
{
|
||||
return $this->convert($this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
$amount = $with_tax ? $this->amount : (isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount);
|
||||
|
||||
return $this->convert($amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
|
||||
public function getReverseConvertedAmount($format = false)
|
||||
public function getReverseConvertedAmount($format = false, $with_tax = true)
|
||||
{
|
||||
return $this->reverseConvert($this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
$amount = $with_tax ? $this->amount : (isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount);
|
||||
|
||||
return $this->reverseConvert($amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
|
||||
public function getDynamicConvertedAmount($format = false)
|
||||
public function getDynamicConvertedAmount($format = false, $with_tax = true)
|
||||
{
|
||||
return $this->dynamicConvert($this->default_currency_code, $this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
$amount = $with_tax ? $this->amount : (isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount);
|
||||
|
||||
return $this->dynamicConvert($this->default_currency_code, $amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,15 @@
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Utilities\Info;
|
||||
use App\Models\Module\Module as Model;
|
||||
use Artisan;
|
||||
use Cache;
|
||||
use Date;
|
||||
use File;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Module;
|
||||
use App\Models\Module\Module as MModule;
|
||||
use ZipArchive;
|
||||
use Cache;
|
||||
use Date;
|
||||
|
||||
trait Modules
|
||||
{
|
||||
@@ -148,7 +148,7 @@ trait Modules
|
||||
|
||||
$installed = [];
|
||||
$modules = Module::all();
|
||||
$installed_modules = MModule::where('company_id', '=', session('company_id'))->pluck('status', 'alias')->toArray();
|
||||
$installed_modules = Model::where('company_id', '=', session('company_id'))->pluck('status', 'alias')->toArray();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if (!array_key_exists($module->alias, $installed_modules)) {
|
||||
@@ -528,6 +528,7 @@ trait Modules
|
||||
'Accept' => 'application/json',
|
||||
'Referer' => env('APP_URL'),
|
||||
'Akaunting' => version('short'),
|
||||
'Language' => language()->getShortCode()
|
||||
];
|
||||
|
||||
$data['http_errors'] = false;
|
||||
|
||||
@@ -18,7 +18,8 @@ trait SiteApi
|
||||
'Authorization' => 'Bearer ' . setting('general.api_token'),
|
||||
'Accept' => 'application/json',
|
||||
'Referer' => env('APP_URL'),
|
||||
'Akaunting' => version('short')
|
||||
'Akaunting' => version('short'),
|
||||
'Language' => language()->getShortCode()
|
||||
);
|
||||
|
||||
$data['http_errors'] = false;
|
||||
|
||||
@@ -10,6 +10,7 @@ use Date;
|
||||
use File;
|
||||
use Module;
|
||||
use ZipArchive;
|
||||
use Artisan;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
class Updater
|
||||
@@ -18,10 +19,7 @@ class Updater
|
||||
|
||||
public static function clear()
|
||||
{
|
||||
Cache::forget('modules');
|
||||
Cache::forget('updates');
|
||||
Cache::forget('versions');
|
||||
Cache::forget('suggestions');
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user