v2 first commit

This commit is contained in:
denisdulici
2019-11-16 10:21:14 +03:00
parent 5b23e9c2c4
commit 6d50fa8442
3075 changed files with 3451681 additions and 65594 deletions

22
app/Traits/Contacts.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Traits;
use App\Models\Common\Contact;
trait Contacts
{
public function getCustomerTypes($return = 'array')
{
$types = (string) setting('contact.type.customer', 'customer');
return ($return == 'array') ? explode(',', $types) : $types;
}
public function getVendorTypes($return = 'array')
{
$types = (string) setting('contact.type.vendor', 'vendor');
return ($return == 'array') ? explode(',', $types) : $types;
}
}

View File

@@ -7,77 +7,66 @@ use Akaunting\Money\Currency;
trait Currencies
{
public function convert($amount, $code, $rate, $format = false)
public function convert($amount, $from, $to, $rate, $format = false)
{
$default = new Currency(setting('general.default_currency', 'USD'));
$money = Money::$from($amount, $format);
if ($format) {
$money = Money::$code($amount, true)->convert($default, (double) $rate)->format();
} else {
$money = Money::$code($amount)->convert($default, (double) $rate)->getAmount();
// No need to convert same currency
if ($from == $to) {
return $format ? $money->format() : $money->getAmount();
}
return $money;
$money = $money->convert(new Currency($to), (double) $rate);
return $format ? $money->format() : $money->getAmount();
}
public function divide($amount, $code, $rate, $format = false)
{
if ($format) {
$money = Money::$code($amount, true)->divide((double) $rate)->format();
} else {
$money = Money::$code($amount)->divide((double) $rate)->getAmount();
}
$money = Money::$code($amount, $format);
return $money;
$money = $money->divide((double) $rate);
return $format ? $money->format() : $money->getAmount();
}
public function reverseConvert($amount, $code, $rate, $format = false)
public function getAmount($with_tax = true)
{
$default = setting('general.default_currency', 'USD');
$code = new Currency($code);
if ($format) {
$money = Money::$default($amount, true)->convert($code, (double) $rate)->format();
} else {
$money = Money::$default($amount)->convert($code, (double) $rate)->getAmount();
}
return $money;
return $with_tax ? $this->amount : (isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount);
}
public function dynamicConvert($default, $amount, $code, $rate, $format = false)
public function convertToDefault($amount, $from, $rate, $format = false)
{
$code = new Currency($code);
if ($format) {
$money = Money::$default($amount, true)->convert($code, (double) $rate)->format();
} else {
$money = Money::$default($amount)->convert($code, (double) $rate)->getAmount();
}
return $money;
return $this->convert($amount, $from, $this->getDefaultCurrency(), $rate, $format);
}
public function getConvertedAmount($format = false, $with_tax = true)
public function convertFromDefault($amount, $to, $rate, $format = false)
{
$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);
return $this->convert($amount, $this->getDefaultCurrency(), $to, $rate, $format);
}
public function getReverseConvertedAmount($format = false, $with_tax = true)
public function getAmountConvertedToDefault($format = false, $with_tax = true)
{
$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);
return $this->convertToDefault($this->getAmount($with_tax), $this->currency_code, $this->currency_rate, $format);
}
public function getDynamicConvertedAmount($format = false, $with_tax = true)
public function getAmountConvertedFromDefault($format = false, $with_tax = true)
{
$amount = $with_tax ? $this->amount : (isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount);
return $this->convertFromDefault($this->getAmount($with_tax), $this->currency_code, $this->currency_rate, $format);
}
return $this->dynamicConvert($this->default_currency_code, $amount, $this->currency_code, $this->currency_rate, $format);
public function getAmountConvertedFromCustomDefault($format = false, $with_tax = true)
{
return $this->convert($this->getAmount($with_tax), $this->default_currency_code, $this->currency_code, $this->currency_rate, $format);
}
public function getAmountDivided($format = false, $with_tax = true)
{
return $this->divide($this->getAmount($with_tax), $this->currency_code, $this->currency_rate, $format);
}
protected function getDefaultCurrency()
{
return setting('default.currency', 'USD');
}
}

View File

@@ -6,7 +6,6 @@ use Date;
trait DateTime
{
/*
* Get the date format based on company settings.
* getDateFormat method is used by Eloquent
@@ -15,31 +14,44 @@ trait DateTime
*/
public function getCompanyDateFormat()
{
$default = 'd M Y';
// Make sure it's installed
if (!env('APP_INSTALLED') && (env('APP_ENV') !== 'testing')) {
return $default;
}
// Make user is logged in
if (!user()) {
return $default;
}
$chars = ['dash' => '-', 'slash' => '/', 'dot' => '.', 'comma' => ',', 'space' => ' '];
$date_format = setting('general.date_format', 'd F Y');
$date_separator = $chars[setting('general.date_separator', 'space')];
$date_format = setting('localisation.date_format', $default);
$date_separator = $chars[setting('localisation.date_separator', 'space')];
return str_replace(' ', $date_separator, $date_format);
}
public function scopeMonthsOfYear($query, $field)
{
$year = request('year', Date::now()->year);
$now = Date::now();
$year = request('year', $now->year);
$start = Date::parse($year . '-01-01')->startOfDay()->format('Y-m-d H:i:s');
$end = Date::parse($year . '-12-31')->endOfDay()->format('Y-m-d H:i:s');
// check if financial year has been customized
$financial_start = $this->getFinancialStart();
if (Date::now()->startOfYear()->format('Y-m-d') !== $financial_start->format('Y-m-d')) {
// Check if FS has been customized
if ($now->startOfYear()->format('Y-m-d') === $financial_start->format('Y-m-d')) {
$start = Date::parse($year . '-01-01')->startOfDay()->format('Y-m-d H:i:s');
$end = Date::parse($year . '-12-31')->endOfDay()->format('Y-m-d H:i:s');
} else {
if (!is_null(request('year'))) {
$financial_start->year = $year;
}
$start = $financial_start->format('Y-m-d');
$end = $financial_start->addYear(1)->subDays(1)->format('Y-m-d');
$start = $financial_start->format('Y-m-d H:i:s');
$end = $financial_start->addYear(1)->subDays(1)->format('Y-m-d H:i:s');
}
return $query->whereBetween($field, [$start, $end]);
@@ -85,13 +97,51 @@ trait DateTime
public function getFinancialStart()
{
$now = Date::now()->startOfYear();
$now = Date::now();
$start = Date::now()->startOfYear();
$setting = explode('-', setting('general.financial_start'));
$setting = explode('-', setting('localisation.financial_start'));
$day = !empty($setting[0]) ? $setting[0] : $now->day;
$month = !empty($setting[1]) ? $setting[1] : $now->month;
$day = !empty($setting[0]) ? $setting[0] : $start->day;
$month = !empty($setting[1]) ? $setting[1] : $start->month;
$year = request('year', $now->year);
return Date::create(null, $month, $day);
$financial_start = Date::create($year, $month, $day);
// Check if FS is in last calendar year
if ($now->diffInDays($financial_start, false) > 0) {
$financial_start->subYear();
}
return $financial_start;
}
public function getMonthlyDateFormat()
{
$format = 'M';
if ($this->getFinancialStart()->month != 1) {
$format = 'M Y';
}
return $format;
}
public function getQuarterlyDateFormat()
{
$format = 'M';
if ($this->getFinancialStart()->month != 1) {
$format = 'M Y';
}
return $format;
}
public function getYearlyDateFormat()
{
$format = 'Y';
return $format;
}
}

View File

@@ -4,7 +4,6 @@ namespace App\Traits;
trait Incomes
{
/**
* Generate next invoice number
*
@@ -12,9 +11,9 @@ trait Incomes
*/
public function getNextInvoiceNumber()
{
$prefix = setting('general.invoice_number_prefix', 'INV-');
$next = setting('general.invoice_number_next', '1');
$digit = setting('general.invoice_number_digit', '5');
$prefix = setting('invoice.number_prefix', 'INV-');
$next = setting('invoice.number_next', '1');
$digit = setting('invoice.number_digit', '5');
$number = $prefix . str_pad($next, $digit, '0', STR_PAD_LEFT);
@@ -26,9 +25,9 @@ trait Incomes
*/
public function increaseNextInvoiceNumber()
{
// Update next invoice number
$next = setting('general.invoice_number_next', 1) + 1;
setting(['general.invoice_number_next' => $next]);
$next = setting('invoice.number_next', 1) + 1;
setting(['invoice.number_next' => $next]);
setting()->save();
}
}

40
app/Traits/Jobs.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
namespace App\Traits;
trait Jobs
{
/**
* Dispatch a job to its appropriate handler.
*
* @param mixed $job
* @return mixed
*/
public function dispatch($job)
{
$function = $this->getDispatchMethod();
return $function($job);
}
/**
* Dispatch a command to its appropriate handler in the current process.
*
* @param mixed $job
* @param mixed $handler
* @return mixed
*/
public function dispatchNow($job, $handler = null)
{
$result = dispatch_now($job, $handler);
return $result;
}
public function getDispatchMethod()
{
$config = config('queue.default');
return ($config == 'sync') ? 'dispatch_now' : 'dispatch';
}
}

View File

@@ -2,29 +2,32 @@
namespace App\Traits;
use App\Traits\SiteApi;
use App\Utilities\Info;
use App\Models\Module\Module as Model;
use App\Models\Module\Module;
use Artisan;
use Cache;
use Date;
use File;
use GuzzleHttp\Client;
use Illuminate\Support\Str;
use GuzzleHttp\Exception\RequestException;
use Module;
use ZipArchive;
trait Modules
{
use SiteApi;
public function checkToken($token)
public function checkToken($apiKey)
{
$data = [
'form_params' => [
'token' => $token,
'token' => $apiKey,
]
];
$response = $this->getRemote('token/check', 'POST', $data);
$response = static::getRemote('token/check', 'POST', $data);
if ($response && ($response->getStatusCode() == 200)) {
$result = json_decode($response->getBody());
@@ -35,103 +38,51 @@ trait Modules
return false;
}
// Get All Modules
public function getModules()
{
$response = $this->getRemote('apps/items');
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/items');
}
// Get Module
public function getModule($alias)
{
$response = $this->getRemote('apps/' . $alias);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/' . $alias);
}
public function getDocumentation($alias)
{
$response = $this->getRemote('apps/docs/' . $alias);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/docs/' . $alias);
}
public function getModuleReviews($alias, $data = [])
{
$response = $this->getRemote('apps/' . $alias . '/reviews', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/' . $alias . '/reviews', 'GET', $data);
}
public function getCategories()
{
$response = $this->getRemote('apps/categories');
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/categories');
}
public function getModulesByCategory($alias, $data = [])
{
$response = $this->getRemote('apps/categories/' . $alias, 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/categories/' . $alias, 'GET', $data);
}
public function getVendors()
{
$response = $this->getRemote('apps/vendors');
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/vendors');
}
public function getModulesByVendor($alias, $data = [])
{
$response = $this->getRemote('apps/vendors/' . $alias, 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/vendors/' . $alias, 'GET', $data);
}
public function getMyModules($data = [])
{
$response = $this->getRemote('apps/my', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/my', 'GET', $data);
}
public function getInstalledModules($data = [])
@@ -147,8 +98,9 @@ trait Modules
}
$installed = [];
$modules = Module::all();
$installed_modules = Model::where('company_id', '=', session('company_id'))->pluck('status', 'alias')->toArray();
$installed_modules = Model::where('company_id', '=', session('company_id'))->pluck('enabled', 'alias')->toArray();
foreach ($modules as $module) {
if (!array_key_exists($module->alias, $installed_modules)) {
@@ -169,75 +121,39 @@ trait Modules
public function getPreSaleModules($data = [])
{
$response = $this->getRemote('apps/pre_sale', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/pre_sale', 'GET', $data);
}
public function getPaidModules($data = [])
{
$response = $this->getRemote('apps/paid', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/paid', 'GET', $data);
}
public function getNewModules($data = [])
{
$response = $this->getRemote('apps/new', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/new', 'GET', $data);
}
public function getFreeModules($data = [])
{
$response = $this->getRemote('apps/free', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/free', 'GET', $data);
}
public function getSearchModules($data = [])
{
$response = $this->getRemote('apps/search', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/search', 'GET', $data);
}
public function getFeaturedModules($data = [])
{
$response = $this->getRemote('apps/featured', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return [];
return $this->remote('apps/featured', 'GET', $data);
}
public function getCoreVersion()
{
$data['query'] = Info::all();
$response = $this->getRemote('core/version', 'GET', $data);
$response = static::getRemote('core/version', 'GET', $data);
if ($response && ($response->getStatusCode() == 200)) {
return $response->json();
@@ -248,7 +164,7 @@ trait Modules
public function downloadModule($path)
{
$response = $this->getRemote($path);
$response = static::getRemote($path);
if ($response && ($response->getStatusCode() == 200)) {
$file = $response->getBody()->getContents();
@@ -334,7 +250,7 @@ trait Modules
$module = json_decode(file_get_contents($temp_path . '/module.json'));
$module_path = $modules_path . '/' . $module->name;
$module_path = $modules_path . '/' . Str::studly($module->alias);
// Create module directory
if (!File::isDirectory($module_path)) {
@@ -348,8 +264,8 @@ trait Modules
Artisan::call('cache:clear');
$data = [
'path' => $path,
'name' => $module->name,
'path' => $path,
'name' => Str::studly($module->alias),
'alias' => $module->alias
];
@@ -363,10 +279,10 @@ trait Modules
public function uninstallModule($alias)
{
$module = Module::findByAlias($alias);
$module = module($alias);
$data = [
'name' => $module->get('name'),
'name' => $module->getName(),
'category' => $module->get('category'),
'version' => $module->get('version'),
];
@@ -381,16 +297,16 @@ trait Modules
return [
'success' => true,
'errors' => false,
'data' => $data
'data' => $data
];
}
public function enableModule($alias)
{
$module = Module::findByAlias($alias);
$module = module($alias);
$data = [
'name' => $module->get('name'),
'name' => $module->getName(),
'category' => $module->get('category'),
'version' => $module->get('version'),
];
@@ -402,18 +318,18 @@ trait Modules
return [
'success' => true,
'errors' => false,
'data' => $data
'data' => $data
];
}
public function disableModule($alias)
{
$module = Module::findByAlias($alias);
$module = module($alias);
$data = [
'name' => $module->get('name'),
'category' => $module->get('category'),
'version' => $module->get('version'),
'name' => $module->getName(),
'category' => $module->get('category'),
'version' => $module->get('version'),
];
$module->disable();
@@ -423,7 +339,7 @@ trait Modules
return [
'success' => true,
'errors' => false,
'data' => $data
'data' => $data
];
}
@@ -431,7 +347,7 @@ trait Modules
{
$status = false;
if (Module::findByAlias($alias) instanceof \Nwidart\Modules\Module) {
if (module($alias) instanceof \Akaunting\Module\Module) {
$status = true;
}
@@ -451,7 +367,7 @@ trait Modules
$url = 'apps/suggestions';
$response = $this->getRemote($url, 'GET', ['timeout' => 30, 'referer' => true]);
$response = static::getRemote($url, 'GET', ['timeout' => 30, 'referer' => true]);
// Exception
if ($response instanceof RequestException) {
@@ -465,8 +381,10 @@ trait Modules
$suggestions = json_decode($response->getBody())->data;
foreach ($suggestions as $suggestion) {
$data[$suggestion->path] = $suggestion;
if ($suggestions) {
foreach ($suggestions as $suggestion) {
$data[$suggestion->path] = $suggestion;
}
}
Cache::put('suggestions', $data, Date::now()->addHour(6));
@@ -487,7 +405,7 @@ trait Modules
$url = 'apps/notifications';
$response = $this->getRemote($url, 'GET', ['timeout' => 30, 'referer' => true]);
$response = static::getRemote($url, 'GET', ['timeout' => 30, 'referer' => true]);
// Exception
if ($response instanceof RequestException) {
@@ -542,30 +460,14 @@ trait Modules
return false;
}
protected function getRemote($path, $method = 'GET', $data = array())
protected function remote($path, $method = 'GET', $data = [])
{
$base = 'https://akaunting.com/api/';
$response = static::getRemote($path, $method, $data);
$client = new Client(['verify' => false, 'base_uri' => $base]);
$headers['headers'] = [
'Authorization' => 'Bearer ' . setting('general.api_token'),
'Accept' => 'application/json',
'Referer' => url('/'),
'Akaunting' => version('short'),
'Language' => language()->getShortCode()
];
$data['http_errors'] = false;
$data = array_merge($data, $headers);
try {
$result = $client->request($method, $path, $data);
} catch (RequestException $e) {
$result = false;
if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data;
}
return $result;
return [];
}
}

148
app/Traits/Omnipay.php Normal file
View File

@@ -0,0 +1,148 @@
<?php
namespace App\Traits;
trait Omnipay
{
public function authorize($invoice, $request, $gateway, $extra_options = [])
{
$default_options = [
'amount' => $invoice->amount,
'currency' => $invoice->currency_code,
'transactionId' => $invoice->id,
'returnUrl' => $this->getReturnUrl($invoice),
'cancelUrl' => $this->getCancelUrl($invoice),
];
$options = array_merge($default_options, $extra_options);
try {
$response = $gateway->authorize($options)->send();
} catch (\Exception $e) {
$this->logger->info($this->module->getName() . ':: Invoice: ' . $invoice->id . ' - Error: '. $e->getMessage());
$message = $e->getMessage();
return response()->json([
'error' => $message,
'redirect' => false,
'success' => false,
'data' => false,
]);
}
if ($response->isSuccessful()) {
$this->setReference($invoice, $response->getTransactionReference());
$response = $gateway->capture([
'amount' => $invoice->amount,
'currency' => $invoice->currency_code,
'transactionId' => $this->getReference($invoice),
])->send();
return $this->finish($invoice, $request);
}
return $this->failure($invoice, $response);
}
public function purchase($invoice, $request, $gateway, $extra_options = [])
{
$default_options = [
'amount' => $invoice->amount,
'currency' => $invoice->currency_code,
'transactionId' => $invoice->id,
'returnUrl' => $this->getReturnUrl($invoice),
'cancelUrl' => $this->getCancelUrl($invoice),
];
$options = array_merge($default_options, $extra_options);
try {
$response = $gateway->purchase($options)->send();
} catch (\Exception $e) {
$this->logger->info($this->module->getName() . ':: Invoice: ' . $invoice->id . ' - Error: '. $e->getMessage());
$message = $e->getMessage();
return response()->json([
'error' => $message,
'redirect' => false,
'success' => false,
'data' => false,
]);
}
if ($response->isSuccessful()) {
$this->setReference($invoice, $response->getTransactionReference());
return $this->finish($invoice, $request);
}
if ($response->isRedirect()) {
$this->setReference($invoice, $response->getTransactionReference());
return response()->json([
'error' => false,
'redirect' => $response->getRedirectUrl(),
'success' => false,
'data' => $response->getRedirectData(),
]);
}
return $this->failure($invoice, $response);
}
public function completePurchase($invoice, $request, $gateway, $extra_options = [])
{
$default_options = [
'amount' => $invoice->amount,
'currency' => $invoice->currency_code,
'transactionId' => $invoice->id,
'transactionReference' => $this->getReference($invoice),
//'returnUrl' => $this->getReturnUrl($invoice),
//'cancelUrl' => $this->getCancelUrl($invoice),
];
$options = array_merge($default_options, $extra_options);
$response = $gateway->completePurchase($options)->send();
if ($response->isSuccessful()) {
return $this->finish($invoice, $request);
}
if ($response->isCancelled()) {
return $this->cancel($invoice);
}
return $this->failure($invoice, $response, true);
}
public function failure($invoice, $response, $force_redirect = false)
{
$data = $response->getData();
$message = $response->getMessage();
if (isset($data['error'])) {
$this->logger->info($this->module->getName() . ':: Invoice: ' . $invoice->id . ' - Error Type: ' . $data['error']['type'] . ' - Error Message: ' . $message);
} else {
$this->logger->info($this->module->getName() . ':: Invoice: ' . $invoice->id . ' - Error Message: ' . $message);
}
$invoice_url = $this->getInvoiceUrl($invoice);
flash($message)->error();
if ($force_redirect) {
return redirect($invoice_url);
}
return response()->json([
'error' => $message,
'redirect' => $invoice_url,
'success' => false,
'data' => false,
]);
}
}

View File

@@ -8,7 +8,6 @@ use Recurr\Transformer\ArrayTransformerConfig;
trait Recurring
{
public function createRecurring()
{
$request = request();
@@ -134,7 +133,7 @@ trait Recurring
public function getRuleTimeZone()
{
return setting('general.timezone');
return setting('localisation.timezone');
}
public function getRuleCount()
@@ -147,4 +146,4 @@ trait Recurring
{
return strtoupper($this->frequency);
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Collection;
trait Relationships
{
public function countRelationships($model, $relationships)
{
$counter = [];
foreach ($relationships as $relationship => $text) {
if (!$c = $model->$relationship()->count()) {
continue;
}
$counter[] = $c . ' ' . strtolower(trans_choice('general.' . $text, ($c > 1) ? 2 : 1));
}
return $counter;
}
/**
* Mass delete relationships with events being fired.
*
* @param $model
* @param $relationships
*
* @return void
*/
public function deleteRelationships($model, $relationships)
{
foreach ((array) $relationships as $relationship) {
if (empty($model->$relationship)) {
continue;
}
$items = $model->$relationship->all();
if ($items instanceof Collection) {
$items = $items->all();
}
foreach ((array) $items as $item) {
$item->delete();
}
}
}
}

View File

@@ -8,26 +8,26 @@ use GuzzleHttp\Exception\RequestException;
trait SiteApi
{
protected static function getRemote($url, $data = array())
protected static function getRemote($path, $method = 'GET', $data = [])
{
$base = 'https://akaunting.com/api/';
$base = 'https://api.akaunting.com/';
$client = new Client(['verify' => false, 'base_uri' => $base]);
$headers['headers'] = array(
'Authorization' => 'Bearer ' . setting('general.api_token'),
$headers['headers'] = [
'Authorization' => 'Bearer ' . setting('apps.api_key'),
'Accept' => 'application/json',
'Referer' => url('/'),
'Akaunting' => version('short'),
'Language' => language()->getShortCode()
);
];
$data['http_errors'] = false;
$data = array_merge($data, $headers);
try {
$result = $client->get($url, $data);
$result = $client->request($method, $path, $data);
} catch (RequestException $e) {
$result = $e;
}

42
app/Traits/Users.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace App\Traits;
use App\Models\Auth\User;
trait Users
{
/**
* Get user logged in
*
* @return object
*/
public function getCurrentUser()
{
return user();
}
/**
* Check user company assignment
*
* @param $id
*
* @return boolean
*/
public function isUserCompany($id)
{
$user = user();
if (empty($user)) {
return false;
}
$companies = $user->companies()->pluck('id')->toArray();
if (in_array($id, $companies)) {
return true;
}
return false;
}
}