diff --git a/.travis.yml b/.travis.yml index ee09abcd0..7e9fc52bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ before_install: before_script: - cp .env.testing .env - - composer install --no-interaction + - composer test --no-interaction script: - vendor/bin/phpunit \ No newline at end of file diff --git a/app/Console/Commands/ModuleInstall.php b/app/Console/Commands/ModuleInstall.php index 6ae58108b..8774e2814 100644 --- a/app/Console/Commands/ModuleInstall.php +++ b/app/Console/Commands/ModuleInstall.php @@ -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!'); } diff --git a/app/Http/Controllers/Banking/Accounts.php b/app/Http/Controllers/Banking/Accounts.php index 51765fe0c..63cfa052c 100644 --- a/app/Http/Controllers/Banking/Accounts.php +++ b/app/Http/Controllers/Banking/Accounts.php @@ -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'); diff --git a/app/Http/Controllers/Common/Companies.php b/app/Http/Controllers/Common/Companies.php index 1c8efba9e..95892f98a 100644 --- a/app/Http/Controllers/Common/Companies.php +++ b/app/Http/Controllers/Common/Companies.php @@ -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'); + } /** diff --git a/app/Http/Controllers/Customers/Invoices.php b/app/Http/Controllers/Customers/Invoices.php index aff6c3b32..a53fb0041 100644 --- a/app/Http/Controllers/Customers/Invoices.php +++ b/app/Http/Controllers/Customers/Invoices.php @@ -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; diff --git a/app/Http/Controllers/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index 9fa40c25f..a327d79be 100644 --- a/app/Http/Controllers/Expenses/Bills.php +++ b/app/Http/Controllers/Expenses/Bills.php @@ -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)]); diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index 6e3c66f14..83e1983f0 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -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)]); diff --git a/app/Http/Controllers/Install/Updates.php b/app/Http/Controllers/Install/Updates.php index c4b171ce4..54c10e896 100644 --- a/app/Http/Controllers/Install/Updates.php +++ b/app/Http/Controllers/Install/Updates.php @@ -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. * diff --git a/app/Http/Controllers/Modules/Item.php b/app/Http/Controllers/Modules/Item.php index b5d64e6d6..488fa87a1 100644 --- a/app/Http/Controllers/Modules/Item.php +++ b/app/Http/Controllers/Modules/Item.php @@ -286,8 +286,6 @@ class Item extends Controller * Final actions post update. * * @param $alias - * @param $old - * @param $new * @return Response */ public function post($alias) diff --git a/app/Http/Controllers/Reports/ProfitLoss.php b/app/Http/Controllers/Reports/ProfitLoss.php index b05c13f5c..fa640b6af 100644 --- a/app/Http/Controllers/Reports/ProfitLoss.php +++ b/app/Http/Controllers/Reports/ProfitLoss.php @@ -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')) { diff --git a/app/Http/Controllers/Settings/Categories.php b/app/Http/Controllers/Settings/Categories.php index d84baecb9..8284b6b15 100644 --- a/app/Http/Controllers/Settings/Categories.php +++ b/app/Http/Controllers/Settings/Categories.php @@ -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'); diff --git a/app/Http/Controllers/Settings/Currencies.php b/app/Http/Controllers/Settings/Currencies.php index 4620ff2f0..0045b922e 100644 --- a/app/Http/Controllers/Settings/Currencies.php +++ b/app/Http/Controllers/Settings/Currencies.php @@ -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'); diff --git a/app/Http/Controllers/Settings/Taxes.php b/app/Http/Controllers/Settings/Taxes.php index bf296fdd8..cea870792 100644 --- a/app/Http/Controllers/Settings/Taxes.php +++ b/app/Http/Controllers/Settings/Taxes.php @@ -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'); diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 8f21fcc23..596f625a2 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -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, ]; } diff --git a/app/Http/Middleware/ApiCompany.php b/app/Http/Middleware/ApiCompany.php index b054ddd0d..f081ac07b 100644 --- a/app/Http/Middleware/ApiCompany.php +++ b/app/Http/Middleware/ApiCompany.php @@ -36,5 +36,4 @@ class ApiCompany return $next($request); } - -} \ No newline at end of file +} diff --git a/app/Http/Middleware/SignedUrlCompany.php b/app/Http/Middleware/SignedUrlCompany.php new file mode 100644 index 000000000..88dee5246 --- /dev/null +++ b/app/Http/Middleware/SignedUrlCompany.php @@ -0,0 +1,33 @@ +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); + } +} diff --git a/app/Http/Requests/Wizard/Company.php b/app/Http/Requests/Wizard/Company.php index 114f6877f..c2d708fc8 100644 --- a/app/Http/Requests/Wizard/Company.php +++ b/app/Http/Requests/Wizard/Company.php @@ -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; } } diff --git a/app/Http/ViewComposers/Modules.php b/app/Http/ViewComposers/Modules.php index 1b02c939f..0f1ad2d9f 100644 --- a/app/Http/ViewComposers/Modules.php +++ b/app/Http/ViewComposers/Modules.php @@ -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)]), ''); }); diff --git a/app/Jobs/Expense/CreateBillItem.php b/app/Jobs/Expense/CreateBillItem.php index cc83823b3..9df227f78 100644 --- a/app/Jobs/Expense/CreateBillItem.php +++ b/app/Jobs/Expense/CreateBillItem.php @@ -77,7 +77,7 @@ class CreateBillItem $tax = Tax::find($tax_id); switch ($tax->type) { - case 'included': + case 'inclusive': $inclusives[] = $tax; break; case 'compound': diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index 3588f0402..aaf7cbe98 100644 --- a/app/Models/Expense/Bill.php +++ b/app/Models/Expense/Bill.php @@ -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. * diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index e6e3d9c36..3e6810828 100644 --- a/app/Models/Income/Invoice.php +++ b/app/Models/Income/Invoice.php @@ -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. * diff --git a/app/Overrides/Akaunting/SignedUrl.php b/app/Overrides/Akaunting/SignedUrl.php new file mode 100644 index 000000000..65464c747 --- /dev/null +++ b/app/Overrides/Akaunting/SignedUrl.php @@ -0,0 +1,54 @@ +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); + } +} diff --git a/app/Traits/Currencies.php b/app/Traits/Currencies.php index ae84cd911..6e8bbe69b 100644 --- a/app/Traits/Currencies.php +++ b/app/Traits/Currencies.php @@ -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); } } \ No newline at end of file diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php index 89df5c919..56681268c 100644 --- a/app/Traits/Modules.php +++ b/app/Traits/Modules.php @@ -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; diff --git a/app/Traits/SiteApi.php b/app/Traits/SiteApi.php index 3a07eb060..173475683 100644 --- a/app/Traits/SiteApi.php +++ b/app/Traits/SiteApi.php @@ -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; diff --git a/app/Utilities/Updater.php b/app/Utilities/Updater.php index 2deddb51b..989d4d5f6 100644 --- a/app/Utilities/Updater.php +++ b/app/Utilities/Updater.php @@ -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; } diff --git a/composer.json b/composer.json index bc092a99f..03595dd51 100644 --- a/composer.json +++ b/composer.json @@ -81,6 +81,13 @@ "php artisan clear-compiled", "php artisan optimize", "composer dump-autoload" + ], + "test": [ + "composer install --no-scripts", + "Illuminate\\Foundation\\ComposerScripts::postInstall", + "php artisan clear-compiled", + "php artisan optimize", + "composer dump-autoload" ] }, "config": { diff --git a/config/language.php b/config/language.php index df777dbd2..48a2866ba 100644 --- a/config/language.php +++ b/config/language.php @@ -21,7 +21,17 @@ return [ | to url('/') | */ - 'home' => true, + 'home' => false, + + /* + |-------------------------------------------------------------------------- + | Add Language Code + |-------------------------------------------------------------------------- + | + | This option will add the language code to the redirected url + | + */ + 'url' => false, /* |-------------------------------------------------------------------------- @@ -177,6 +187,6 @@ return [ ['short' => 'tr', 'long' => 'tr-TR', 'english' => 'Turkish', 'native' => 'Türkçe'], ['short' => 'tw', 'long' => 'zh-TW', 'english' => 'Chinese (T)', 'native' => '繁體中文'], ['short' => 'uk', 'long' => 'uk-UA', 'english' => 'Ukrainian', 'native' => 'Українська'], - ['short' => 'vn', 'long' => 'vi-VN', 'english' => 'Vietnamese', 'native' => 'Tiếng Việt'], + ['short' => 'vi', 'long' => 'vi-VN', 'english' => 'Vietnamese', 'native' => 'Tiếng Việt'], ], ]; diff --git a/database/seeds/CompanySeeder.php b/database/seeds/CompanySeeder.php index bbcf49a85..83bbe8d3f 100644 --- a/database/seeds/CompanySeeder.php +++ b/database/seeds/CompanySeeder.php @@ -18,6 +18,5 @@ class CompanySeeder extends Seeder $this->call(Database\Seeds\InvoiceStatuses::class); $this->call(Database\Seeds\Modules::class); $this->call(Database\Seeds\Settings::class); - $this->call(Database\Seeds\Taxes::class); } } diff --git a/database/seeds/Taxes.php b/database/seeds/Taxes.php deleted file mode 100644 index dc3cd6a80..000000000 --- a/database/seeds/Taxes.php +++ /dev/null @@ -1,54 +0,0 @@ -create(); - - Model::reguard(); - } - - private function create() - { - $company_id = $this->command->argument('company'); - - $rows = [ - [ - 'company_id' => $company_id, - 'name' => trans('demo.taxes_exempt'), - 'rate' => '0', - 'enabled' => '1' - ], - [ - 'company_id' => $company_id, - 'name' => trans('demo.taxes_normal'), - 'rate' => '5', - 'enabled' => '1' - ], - [ - 'company_id' => $company_id, - 'name' => trans('demo.taxes_sales'), - 'rate' => '15', - 'enabled' => '1' - ], - ]; - - foreach ($rows as $row) { - Tax::create($row); - } - } -} diff --git a/modules/OfflinePayment/Assets/.gitkeep b/modules/OfflinePayment/Assets/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Config/.gitkeep b/modules/OfflinePayment/Config/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Config/config.php b/modules/OfflinePayment/Config/config.php deleted file mode 100644 index f580eb589..000000000 --- a/modules/OfflinePayment/Config/config.php +++ /dev/null @@ -1,7 +0,0 @@ - 'OfflinePayment', - -]; diff --git a/modules/OfflinePayment/Console/.gitkeep b/modules/OfflinePayment/Console/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Database/Migrations/.gitkeep b/modules/OfflinePayment/Database/Migrations/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Database/Seeders/.gitkeep b/modules/OfflinePayment/Database/Seeders/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Entities/.gitkeep b/modules/OfflinePayment/Entities/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Events/.gitkeep b/modules/OfflinePayment/Events/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Events/Handlers/.gitkeep b/modules/OfflinePayment/Events/Handlers/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Http/Controllers/.gitkeep b/modules/OfflinePayment/Http/Controllers/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Http/Controllers/OfflinePayment.php b/modules/OfflinePayment/Http/Controllers/OfflinePayment.php index 61218ae71..4074a37d8 100644 --- a/modules/OfflinePayment/Http/Controllers/OfflinePayment.php +++ b/modules/OfflinePayment/Http/Controllers/OfflinePayment.php @@ -4,7 +4,6 @@ namespace Modules\OfflinePayment\Http\Controllers; use App\Events\InvoicePaid; -use Illuminate\Http\Response; use Illuminate\Routing\Controller; use Illuminate\Http\Request; @@ -16,11 +15,12 @@ use SignedUrl; class OfflinePayment extends Controller { + /** * Show the form for editing the specified resource. * @param Invoice * @param PaymentRequest - * @return Response + * @return JSON */ public function show(Invoice $invoice, PaymentRequest $request) { @@ -46,11 +46,12 @@ class OfflinePayment extends Controller 'html' => $html, ]); } + /** * Show the form for editing the specified resource. * @param $invoice * @param $request - * @return Response + * @return JSON */ public function link(Invoice $invoice, PaymentRequest $request) { diff --git a/modules/OfflinePayment/Http/Controllers/Settings.php b/modules/OfflinePayment/Http/Controllers/Settings.php index b0b14e110..9e5fca632 100644 --- a/modules/OfflinePayment/Http/Controllers/Settings.php +++ b/modules/OfflinePayment/Http/Controllers/Settings.php @@ -12,6 +12,7 @@ use Modules\OfflinePayment\Http\Requests\SettingDelete as DRequest; class Settings extends Controller { + /** * Show the form for editing the specified resource. * @@ -66,7 +67,7 @@ class Settings extends Controller Artisan::call('cache:clear'); - return redirect('apps/offlinepayment/settings'); + return redirect()->route('offlinepayment.edit'); } /** diff --git a/modules/OfflinePayment/Http/Middleware/.gitkeep b/modules/OfflinePayment/Http/Middleware/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Http/Requests/.gitkeep b/modules/OfflinePayment/Http/Requests/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Http/routes.php b/modules/OfflinePayment/Http/routes.php index c2c27f400..0dc0b97f7 100644 --- a/modules/OfflinePayment/Http/routes.php +++ b/modules/OfflinePayment/Http/routes.php @@ -1,18 +1,30 @@ ['web', 'auth', 'language', 'adminmenu', 'permission:read-admin-panel'], 'prefix' => 'apps/offlinepayment', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () { - Route::get('settings', 'Settings@edit'); - Route::post('settings', 'Settings@update'); - Route::post('settings/get', 'Settings@get'); - Route::post('settings/delete', 'Settings@delete'); +Route::group([ + 'middleware' => 'admin', + 'prefix' => 'apps/offlinepayment', + 'namespace' => 'Modules\OfflinePayment\Http\Controllers' +], function () { + Route::get('settings', 'Settings@edit')->name('offlinepayment.edit'); + Route::post('settings', 'Settings@update')->name('offlinepayment.update'); + Route::post('settings/get', 'Settings@get')->name('offlinepayment.get'); + Route::post('settings/delete', 'Settings@delete')->name('offlinepayment.delete'); }); -Route::group(['middleware' => ['web', 'auth', 'language', 'customermenu', 'permission:read-customer-panel'], 'prefix' => 'customers', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () { +Route::group([ + 'middleware' => ['web', 'auth', 'language', 'customermenu', 'permission:read-customer-panel'], + 'prefix' => 'customers', + 'namespace' => 'Modules\OfflinePayment\Http\Controllers' +], function () { Route::get('invoices/{invoice}/offlinepayment', 'OfflinePayment@show'); Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm'); }); -Route::group(['middleware' => ['web', 'language'], 'prefix' => 'links', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () { +Route::group([ + 'middleware' => ['web', 'language'], + 'prefix' => 'links', + 'namespace' => 'Modules\OfflinePayment\Http\Controllers' +], function () { Route::group(['middleware' => 'signed-url'], function () { Route::post('invoices/{invoice}/offlinepayment', 'OfflinePayment@link'); Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm'); diff --git a/modules/OfflinePayment/Jobs/.gitkeep b/modules/OfflinePayment/Jobs/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Events/Handlers/OfflinePaymentAdminMenu.php b/modules/OfflinePayment/Listeners/AdminMenu.php similarity index 73% rename from modules/OfflinePayment/Events/Handlers/OfflinePaymentAdminMenu.php rename to modules/OfflinePayment/Listeners/AdminMenu.php index 3ad2fb310..69b049221 100644 --- a/modules/OfflinePayment/Events/Handlers/OfflinePaymentAdminMenu.php +++ b/modules/OfflinePayment/Listeners/AdminMenu.php @@ -1,12 +1,12 @@ user(); // Settings if ($user->can(['read-settings-settings', 'read-settings-categories', 'read-settings-currencies', 'read-settings-taxes'])) { // Add child to existing item $item = $event->menu->whereTitle(trans_choice('general.settings', 2)); - $item->url('apps/offlinepayment/settings', trans('offlinepayment::offlinepayment.offlinepayment'), 4, ['icon' => 'fa fa-angle-double-right']); + $item->url('apps/offlinepayment/settings', trans('offlinepayment::general.title'), 4, ['icon' => 'fa fa-angle-double-right']); } } } diff --git a/modules/OfflinePayment/Events/Handlers/OfflinePaymentGateway.php b/modules/OfflinePayment/Listeners/Gateway.php similarity index 79% rename from modules/OfflinePayment/Events/Handlers/OfflinePaymentGateway.php rename to modules/OfflinePayment/Listeners/Gateway.php index eaf12a187..4c0b51511 100644 --- a/modules/OfflinePayment/Events/Handlers/OfflinePaymentGateway.php +++ b/modules/OfflinePayment/Listeners/Gateway.php @@ -1,10 +1,10 @@ registerTranslations(); - $this->registerConfig(); $this->registerViews(); - $this->registerFactories(); - - $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); - - $this->app['events']->listen(AdminMenuCreated::class, OfflinePaymentAdminMenu::class); - $this->app['events']->listen(PaymentGatewayListing::class, OfflinePaymentGateway::class); + $this->registerMigrations(); + $this->registerEvents(); } /** @@ -48,21 +40,6 @@ class OfflinePaymentServiceProvider extends ServiceProvider // } - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - __DIR__.'/../Config/config.php' => config_path('offlinepayment.php'), - ], 'config'); - $this->mergeConfigFrom( - __DIR__.'/../Config/config.php', 'offlinepayment' - ); - } - /** * Register views. * @@ -99,15 +76,15 @@ class OfflinePaymentServiceProvider extends ServiceProvider } } - /** - * Register an additional directory of factories. - * @source https://github.com/sebastiaanluca/laravel-resource-flow/blob/develop/src/Modules/ModuleServiceProvider.php#L66 - */ - public function registerFactories() + public function registerMigrations() { - if (! app()->environment('production')) { - app(Factory::class)->load(__DIR__ . '/Database/factories'); - } + $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + } + + public function registerEvents() + { + $this->app['events']->listen(AdminMenuCreated::class, AdminMenu::class); + $this->app['events']->listen(PaymentGatewayListing::class, Gateway::class); } /** diff --git a/modules/OfflinePayment/Repositories/.gitkeep b/modules/OfflinePayment/Repositories/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Resources/lang/.gitkeep b/modules/OfflinePayment/Resources/lang/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Resources/lang/en-GB/general.php b/modules/OfflinePayment/Resources/lang/en-GB/general.php new file mode 100644 index 000000000..1a159e418 --- /dev/null +++ b/modules/OfflinePayment/Resources/lang/en-GB/general.php @@ -0,0 +1,21 @@ + 'Offline Payments', + + 'add_new' => 'Add New', + 'edit' => 'Edit: :method', + + 'form' => [ + 'code' => 'Code', + 'customer' => 'Show to Customer', + 'order' => 'Order' + ], + + 'payment_gateways' => 'Offline Payment Methods', + + 'confirm' => 'Confirm', + 'loading' => 'Loading', + +]; diff --git a/modules/OfflinePayment/Resources/lang/en-GB/offlinepayment.php b/modules/OfflinePayment/Resources/lang/en-GB/offlinepayment.php deleted file mode 100644 index 541a5c57c..000000000 --- a/modules/OfflinePayment/Resources/lang/en-GB/offlinepayment.php +++ /dev/null @@ -1,16 +0,0 @@ - 'Offline Payments', - 'add_new' => 'Add New', - 'edit' => 'Edit: :method', - 'code' => 'Code', - 'customer' => 'Show to Customer', - 'order' => 'Order', - 'payment_gateways' => 'Offline Payment Methods', - - 'confirm' => 'Confirm', - 'loading' => 'Loading', - -]; diff --git a/modules/OfflinePayment/Resources/views/.gitkeep b/modules/OfflinePayment/Resources/views/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/OfflinePayment/Resources/views/confirm.blade.php b/modules/OfflinePayment/Resources/views/confirm.blade.php index 7ab1f30bf..793869e38 100644 --- a/modules/OfflinePayment/Resources/views/confirm.blade.php +++ b/modules/OfflinePayment/Resources/views/confirm.blade.php @@ -4,4 +4,4 @@
{{ $gateway['description'] }}
-@endif \ No newline at end of file +@endif diff --git a/modules/OfflinePayment/Resources/views/edit.blade.php b/modules/OfflinePayment/Resources/views/edit.blade.php index c7dfd9be3..be5e0b6e2 100644 --- a/modules/OfflinePayment/Resources/views/edit.blade.php +++ b/modules/OfflinePayment/Resources/views/edit.blade.php @@ -1,29 +1,29 @@ @extends('layouts.admin') -@section('title', trans('offlinepayment::offlinepayment.offlinepayment')) +@section('title', trans('offlinepayment::general.title')) @section('content')
-

{{ trans('offlinepayment::offlinepayment.add_new') }}

+

{{ trans('offlinepayment::general.add_new') }}

- {!! Form::open(['url' => 'apps/offlinepayment/settings', 'files' => true, 'role' => 'form']) !!} + {!! Form::open(['route' => 'offlinepayment.update', 'files' => true, 'role' => 'form', 'class' => 'form-loading-button']) !!}
{{ Form::textGroup('name', trans('general.name'), 'id-card-o', ['required' => 'required'], null, 'col-md-12') }} - {{ Form::textGroup('code', trans('offlinepayment::offlinepayment.code'), 'key', ['required' => 'required'], null, 'col-md-12') }} + {{ Form::textGroup('code', trans('offlinepayment::general.form.code'), 'key', ['required' => 'required'], null, 'col-md-12') }} - {{ Form::radioGroup('customer', trans('offlinepayment::offlinepayment.customer'), '', ['required' => 'required'], 0, 'col-md-12') }} + {{ Form::radioGroup('customer', trans('offlinepayment::general.form.customer'), '', ['required' => 'required'], 0, 'col-md-12') }} - {{ Form::textGroup('order', trans('offlinepayment::offlinepayment.order'), 'sort', [], null, 'col-md-12') }} + {{ Form::textGroup('order', trans('offlinepayment::general.form.order'), 'sort', [], null, 'col-md-12') }} {{ Form::textareaGroup('description', trans('general.description')) }}
@@ -38,22 +38,25 @@
+
-

{{ trans('offlinepayment::offlinepayment.payment_gateways') }}

+

{{ trans('offlinepayment::general.payment_gateways') }}

+
+
- - + + @@ -86,13 +89,14 @@ @push('stylesheet') @endpush @@ -115,22 +123,25 @@
{{ trans('general.name') }}{{ trans('offlinepayment::offlinepayment.code') }}{{ trans('offlinepayment::offlinepayment.order') }}{{ trans('offlinepayment::general.form.code') }}{{ trans('offlinepayment::general.form.order') }} {{ trans('general.actions') }}