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

18
app/Utilities/Chartjs.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App\Utilities;
use ConsoleTVs\Charts\Classes\Chartjs\Chart;
class Chartjs extends Chart
{
/**
* Initializes the chart.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
}

View File

@ -4,6 +4,7 @@ namespace App\Utilities;
use Date;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Str;
class Import
{
@ -92,7 +93,7 @@ class Import
$title = $t[1];
}
if ($sheet->getTitle() != str_plural(snake_case($title))) {
if ($sheet->getTitle() != Str::plural(Str::snake($title))) {
return false;
}

View File

@ -25,7 +25,7 @@ class Info
{
$data = static::versions();
$data['token'] = setting('general.api_token');
$data['token'] = setting('apps.api_key');
$data['companies'] = Company::all()->count();

View File

@ -8,6 +8,7 @@ use Artisan;
use Config;
use DB;
use File;
use Illuminate\Support\Str;
/**
* Class Installer
@ -176,7 +177,7 @@ class Installer
public static function saveDbVariables($host, $port, $database, $username, $password)
{
$prefix = strtolower(str_random(3) . '_');
$prefix = strtolower(Str::random(3) . '_');
// Update .env file
static::updateEnv([
@ -215,10 +216,10 @@ class Installer
// Set settings
setting()->setExtraColumns(['company_id' => $company->id]);
setting()->set([
'general.company_name' => $name,
'general.company_email' => $email,
'general.default_currency' => 'USD',
'general.default_locale' => $locale,
'company.name' => $name,
'company.email' => $email,
'default.currency' => 'USD',
'default.locale' => $locale,
]);
setting()->save();
}
@ -238,15 +239,21 @@ class Installer
// Attach company
$user->companies()->attach('1');
Artisan::call('user:seed', [
'user' => $user->id,
'company' => 1
]);
}
public static function finalTouches()
{
// Update .env file
static::updateEnv([
'APP_LOCALE' => session('locale'),
'APP_INSTALLED' => 'true',
'APP_DEBUG' => 'false',
'APP_LOCALE' => session('locale'),
'APP_INSTALLED' => 'true',
'APP_DEBUG' => 'false',
'FIREWALL_ENABLED' => 'true',
]);
// Rename the robots.txt file

View File

@ -4,13 +4,9 @@ namespace App\Utilities;
use Cache;
use Date;
use Module;
use App\Events\PaymentGatewayListing;
class Modules
{
public static function getPaymentMethods($type = null)
{
$company_id = session('company_id');
@ -20,13 +16,13 @@ class Modules
$payment_methods = Cache::get($cache_admin);
$customer = true;
$contact = true;
if (auth()->user()) {
$customer = auth()->user()->customer;
if (user()) {
$contact = user()->contact;
}
if ($customer && $type != 'all') {
if ($contact && ($type != 'all')) {
$payment_methods = Cache::get($cache_customer);
}
@ -34,41 +30,33 @@ class Modules
return $payment_methods;
}
$gateways = [];
$methods = [];
$list = [];
// Fire the event to extend the menu
$results = event(new PaymentGatewayListing($gateways));
$modules = new \stdClass();
$modules->payment_methods = [];
foreach ($results as $gateways) {
foreach ($gateways as $gateway) {
if (!isset($gateway['name']) || !isset($gateway['code'])) {
continue;
}
// Fire the event to get the list of payment methods
event(new \App\Events\Module\PaymentMethodShowing($modules));
if (($customer && empty($gateway['customer'])) && $type != 'all') {
continue;
}
$methods[] = $gateway;
foreach ($modules->payment_methods as $method) {
if (!isset($method['name']) || !isset($method['code'])) {
continue;
}
if (($contact && empty($method['customer'])) && ($type != 'all')) {
continue;
}
$list[] = $method;
}
$sort_order = [];
static::sortPaymentMethods($list);
if ($methods) {
foreach ($methods as $key => $value) {
$sort_order[$key] = !empty($value['order']) ? $value['order'] : 0;
}
array_multisort($sort_order, SORT_ASC, $methods);
foreach ($methods as $method) {
$payment_methods[$method['code']] = $method['name'];
}
foreach ($list as $method) {
$payment_methods[$method['code']] = $method['name'];
}
if ($customer) {
if ($contact) {
Cache::put($cache_customer, $payment_methods, Date::now()->addHour(6));
} else {
Cache::put($cache_admin, $payment_methods, Date::now()->addHour(6));
@ -76,4 +64,19 @@ class Modules
return ($payment_methods) ? $payment_methods : [];
}
protected static function sortPaymentMethods(&$list)
{
$sort_order = [];
foreach ($list as $key => $value) {
$sort_order[$key] = !empty($value['order']) ? $value['order'] : 0;
}
if (empty($sort_order)) {
return;
}
array_multisort($sort_order, SORT_ASC, $list);
}
}

View File

@ -30,33 +30,30 @@ class Overrider
setting()->load(true);
// Timezone
config(['app.timezone' => setting('general.timezone', 'UTC')]);
config(['app.timezone' => setting('localisation.timezone', 'UTC')]);
date_default_timezone_set(config('app.timezone'));
// Email
$email_protocol = setting('general.email_protocol', 'mail');
$email_protocol = setting('email.protocol', 'mail');
config(['mail.driver' => $email_protocol]);
config(['mail.from.name' => setting('general.company_name')]);
config(['mail.from.address' => setting('general.company_email')]);
config(['mail.from.name' => setting('company.name')]);
config(['mail.from.address' => setting('company.email')]);
if ($email_protocol == 'sendmail') {
config(['mail.sendmail' => setting('general.email_sendmail_path')]);
config(['mail.sendmail' => setting('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')]);
config(['mail.host' => setting('email.smtp_host')]);
config(['mail.port' => setting('email.smtp_port')]);
config(['mail.username' => setting('email.smtp_username')]);
config(['mail.password' => setting('email.smtp_password')]);
config(['mail.encryption' => setting('email.smtp_encryption')]);
}
// Session
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')]);
//App::setLocale(setting('default.locale'));
//Session::put('locale', setting('default.locale'));
config(['app.locale' => setting('default.locale')]);
}
// Set app url dynamically
@ -83,4 +80,4 @@ class Overrider
\Akaunting\Money\Currency::setCurrencies(config('money'));
}
}
}

View File

@ -7,20 +7,9 @@ use Date;
class Recurring
{
public static function reflect(&$items, $type, $issued_date_field, $status)
public static function reflect(&$items, $type, $issued_date_field)
{
foreach ($items as $key => $item) {
if (($item->getTable() == 'bill_payments') || ($item->getTable() == 'invoice_payments')) {
$i = $item->$type;
$i->category_id = $item->category_id;
$item = $i;
}
if (($status == 'upcoming') && (($type == 'revenue') || ($type == 'payment'))) {
$items->forget($key);
}
if (!$item->recurring || !empty($item->parent_id)) {
continue;
}

91
app/Utilities/Reports.php Normal file
View File

@ -0,0 +1,91 @@
<?php
namespace App\Utilities;
use App\Models\Module\Module;
class Reports
{
public static function getClasses()
{
$classes = [];
$core_classes = [
'App\Reports\IncomeSummary',
'App\Reports\ExpenseSummary',
'App\Reports\IncomeExpenseSummary',
'App\Reports\TaxSummary',
'App\Reports\ProfitLoss',
];
static::parseClasses($classes, $core_classes);
$modules = Module::enabled()->get();
foreach ($modules as $module) {
$m = module($module->alias);
// Check if the module exists and has reports
if (!$m || empty($m->get('reports'))) {
continue;
}
static::parseClasses($classes, $m->get('reports'));
}
return $classes;
}
protected static function parseClasses(&$classes, $list)
{
foreach ($list as $class) {
if (!class_exists($class)) {
continue;
}
$name = (new $class())->getName();
$classes[$class] = $name;
}
}
public static function getGroups()
{
return [
'category' => trans_choice('general.categories', 1),
'account' => trans_choice('general.accounts', 1),
'customer' => trans_choice('general.customers', 1),
'vendor' => trans_choice('general.vendors', 1),
];
}
public static function getPeriods()
{
return [
'monthly' => trans('general.monthly'),
'quarterly' => trans('general.quarterly'),
'yearly' => trans('general.yearly'),
];
}
public static function getBasises()
{
return [
'accrual' => trans('general.accrual'),
'cash' => trans('general.cash'),
];
}
public static function getCharts()
{
return [
'0' => trans('general.disabled'),
'line' => trans('reports.charts.line'),
];
}
public static function getClassInstance($report, $get_totals = true)
{
return (new $report->class($report, $get_totals));
}
}

View File

@ -2,14 +2,12 @@
namespace App\Utilities;
use App\Events\UpdateFinished;
use App\Models\Module\Module as Model;
use App\Models\Module\ModuleHistory as ModelHistory;
use App\Traits\SiteApi;
use Cache;
use Date;
use File;
use Module;
use ZipArchive;
use Artisan;
use GuzzleHttp\Exception\RequestException;
@ -25,75 +23,7 @@ class Updater
return true;
}
// Update
public static function update($alias, $version)
{
// Download file
if (!$data = static::download($alias, $version)) {
return false;
}
// Create temp directory
$path = 'temp-' . md5(mt_rand());
$temp_path = storage_path('app/temp') . '/' . $path;
if (!File::isDirectory($temp_path)) {
File::makeDirectory($temp_path);
}
$file = $temp_path . '/upload.zip';
// Add content to the Zip file
$uploaded = is_int(file_put_contents($file, $data)) ? true : false;
if (!$uploaded) {
return false;
}
// Unzip the file
$zip = new ZipArchive();
if (($zip->open($file) !== true) || !$zip->extractTo($temp_path)) {
return false;
}
$zip->close();
// Delete zip file
File::delete($file);
if ($alias == 'core') {
// Move all files/folders from temp path
if (!File::copyDirectory($temp_path, base_path())) {
return false;
}
} else {
// Get module instance
$module = Module::findByAlias($alias);
$model = Model::where('alias', $alias)->first();
// Move all files/folders from temp path
if (!File::copyDirectory($temp_path, module_path($module->get('name')))) {
return false;
}
// Add history
ModelHistory::create([
'company_id' => session('company_id'),
'module_id' => $model->id,
'category' => $module->get('category'),
'version' => $version,
'description' => trans('modules.history.updated', ['module' => $module->get('name')]),
]);
}
// Delete temp directory
File::deleteDirectory($temp_path);
return true;
}
public static function download($name, $alias, $version)
public static function download($alias, $version, $installed)
{
$file = null;
$path = null;
@ -107,7 +37,7 @@ class Updater
$url = 'apps/' . $alias . '/download/' . $version . '/' . $info['akaunting'] . '/' . $info['token'];
}
$response = static::getRemote($url, ['timeout' => 50, 'track_redirects' => true]);
$response = static::getRemote($url, 'GET', ['timeout' => 50, 'track_redirects' => true]);
// Exception
if ($response instanceof RequestException) {
@ -139,34 +69,42 @@ class Updater
if (!$uploaded) {
return [
'success' => false,
'errors' => trans('modules.errors.upload', ['module' => $name]),
'errors' => trans('modules.errors.zip', ['module' => $alias]),
'data' => [
'path' => $path
]
];
}
$data = [
'path' => $path
];
try {
event(new \App\Events\Install\UpdateDownloaded($alias, $version, $installed));
return [
'success' => true,
'errors' => false,
'data' => $data,
];
return [
'success' => true,
'errors' => false,
'data' => [
'path' => $path
]
];
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.download', ['module' => $alias]),
'data' => []
];
}
}
return [
'success' => false,
'errors' => trans('modules.errors.download', ['module' => $name]),
'errors' => trans('modules.errors.download', ['module' => $alias]),
'data' => [
'path' => $path
]
];
}
public static function unzip($name, $path)
public static function unzip($path, $alias, $version, $installed)
{
$temp_path = storage_path('app/temp') . '/' . $path;
@ -178,7 +116,7 @@ class Updater
if (($zip->open($file) !== true) || !$zip->extractTo($temp_path)) {
return [
'success' => false,
'errors' => trans('modules.errors.unzip', ['module' => $name]),
'errors' => trans('modules.errors.unzip', ['module' => $alias]),
'data' => [
'path' => $path
]
@ -190,16 +128,26 @@ class Updater
// Delete zip file
File::delete($file);
return [
'success' => true,
'errors' => false,
'data' => [
'path' => $path
]
];
try {
event(new \App\Events\Install\UpdateUnzipped($alias, $version, $installed));
return [
'success' => true,
'errors' => false,
'data' => [
'path' => $path
]
];
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.unzip', ['module' => $alias]),
'data' => []
];
}
}
public static function fileCopy($name, $alias, $path, $version)
public static function fileCopy($path, $alias, $version, $installed)
{
$temp_path = storage_path('app/temp') . '/' . $path;
@ -208,7 +156,7 @@ class Updater
if (!File::copyDirectory($temp_path, base_path())) {
return [
'success' => false,
'errors' => trans('modules.errors.file_copy', ['module' => $name]),
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => [
'path' => $path
]
@ -216,9 +164,9 @@ class Updater
}
} else {
// Get module instance
$module = Module::findByAlias($alias);
$module = module($alias);
$module_path = module_path($module->get('name'));
$module_path = $module->getPath();
// Create module directory
if (!File::isDirectory($module_path)) {
@ -229,7 +177,7 @@ class Updater
if (!File::copyDirectory($temp_path, $module_path)) {
return [
'success' => false,
'errors' => trans('modules.errors.file_copy', ['module' => $name]),
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => [
'path' => $path
]
@ -245,7 +193,7 @@ class Updater
'module_id' => $model->id,
'category' => $module->get('category'),
'version' => $version,
'description' => trans('modules.history.updated', ['module' => $module->get('name')]),
'description' => trans('modules.history.updated', ['module' => $module->get('alias')]),
]);
}
}
@ -255,22 +203,32 @@ class Updater
Artisan::call('cache:clear');
return [
'success' => true,
'errors' => false,
'data' => [
'path' => $path
]
];
try {
event(new \App\Events\Install\UpdateCopied($alias, $version, $installed));
return [
'success' => true,
'errors' => false,
'data' => [
'path' => $path
]
];
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => []
];
}
}
public static function migrate($name, $alias, $version, $installed)
public static function finish($alias, $version, $installed)
{
// Check if the file mirror was successful
if (($alias == 'core') && (version('short') != $version)) {
return [
'success' => false,
'errors' => trans('modules.errors.migrate core', ['module' => $name]),
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => []
];
}
@ -279,7 +237,7 @@ class Updater
Artisan::call('cache:clear');
try {
event(new UpdateFinished($alias, $installed, $version));
event(new \App\Events\Install\UpdateFinished($alias, $installed, $version));
return [
'success' => true,
@ -289,7 +247,7 @@ class Updater
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.migrate', ['module' => $name]),
'errors' => trans('modules.errors.finish', ['module' => $alias]),
'data' => []
];
}
@ -307,7 +265,7 @@ class Updater
// No data in cache, grab them from remote
$data = array();
$modules = Module::all();
$modules = module()->all();
$versions = Versions::latest($modules);
@ -318,7 +276,7 @@ class Updater
$data['core'] = $version;
}
} else {
$module = Module::findByAlias($alias);
$module = module($alias);
// Up-to-date
if (version_compare($module->get('version'), $version) == 0) {

View File

@ -70,7 +70,7 @@ class Versions
// Check core first
$url = 'core/version/' . $info['akaunting'] . '/' . $info['php'] . '/' . $info['mysql'] . '/' . $info['companies'];
$data['core'] = static::getLatestVersion($url);
$data['core'] = static::getLatestVersion($url, $info['akaunting']);
// Then modules
foreach ($modules as $module) {
@ -79,7 +79,7 @@ class Versions
$url = 'apps/' . $alias . '/version/' . $version . '/' . $info['akaunting'];
$data[$alias] = static::getLatestVersion($url);
$data[$alias] = static::getLatestVersion($url, $version);
}
Cache::put('versions', $data, Date::now()->addHour(6));
@ -87,11 +87,9 @@ class Versions
return $data;
}
public static function getLatestVersion($url)
public static function getLatestVersion($url, $latest)
{
$latest = '0.0.0';
$response = static::getRemote($url, ['timeout' => 10, 'referer' => true]);
$response = static::getRemote($url, 'GET', ['timeout' => 10, 'referer' => true]);
// Exception
if ($response instanceof RequestException) {

39
app/Utilities/helpers.php Normal file
View File

@ -0,0 +1,39 @@
<?php
use App\Traits\DateTime;
use Jenssegers\Date\Date;
if (!function_exists('user')) {
/**
* Get the authenticated user.
*
* @return \App\Models\Auth\User
*/
function user()
{
// Get user from api/web
if (request()->is('api/*')) {
$user = app('Dingo\Api\Auth\Auth')->user();
} else {
$user = auth()->user();
}
return $user;
}
}
if (!function_exists('company_date')) {
/**
* Format the given date based on company settings.
*
* @return string
*/
function company_date($date)
{
$date_time = new class() {
use DateTime;
};
return Date::parse($date)->format($date_time->getCompanyDateFormat());
}
}