diff --git a/Modules/Product/Resources/views/barcode/print.blade.php b/Modules/Product/Resources/views/barcode/print.blade.php index 2690d7ef..decbdf7a 100644 --- a/Modules/Product/Resources/views/barcode/print.blade.php +++ b/Modules/Product/Resources/views/barcode/print.blade.php @@ -20,7 +20,7 @@ {!! $barcode !!}

- Price:: {{ number_format($price) }}

+ Price:: {{ format_currency($price) }}

@endforeach diff --git a/Modules/Product/Resources/views/products/show.blade.php b/Modules/Product/Resources/views/products/show.blade.php index fe58fc43..001220df 100644 --- a/Modules/Product/Resources/views/products/show.blade.php +++ b/Modules/Product/Resources/views/products/show.blade.php @@ -41,11 +41,11 @@ Cost - {{ $product->product_cost }} + {{ format_currency($product->product_price) }} Price - {{ $product->product_price }} + {{ format_currency($product->product_price) }} Quantity diff --git a/Modules/Setting/Config/.gitkeep b/Modules/Setting/Config/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Config/config.php b/Modules/Setting/Config/config.php new file mode 100644 index 00000000..f7930cb5 --- /dev/null +++ b/Modules/Setting/Config/config.php @@ -0,0 +1,5 @@ + 'Setting' +]; diff --git a/Modules/Setting/Console/.gitkeep b/Modules/Setting/Console/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Database/Migrations/.gitkeep b/Modules/Setting/Database/Migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Database/Migrations/2021_07_31_140531_create_settings_table.php b/Modules/Setting/Database/Migrations/2021_07_31_140531_create_settings_table.php new file mode 100644 index 00000000..a70adde5 --- /dev/null +++ b/Modules/Setting/Database/Migrations/2021_07_31_140531_create_settings_table.php @@ -0,0 +1,40 @@ +id(); + $table->string('company_name'); + $table->string('company_email'); + $table->string('company_phone'); + $table->string('site_logo')->nullable(); + $table->integer('default_currency_id'); + $table->string('default_currency_position'); + $table->string('notification_email'); + $table->string('footer_text'); + $table->text('company_address'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('settings'); + } +} diff --git a/Modules/Setting/Database/Seeders/.gitkeep b/Modules/Setting/Database/Seeders/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Database/Seeders/SettingDatabaseSeeder.php b/Modules/Setting/Database/Seeders/SettingDatabaseSeeder.php new file mode 100644 index 00000000..ec8b172e --- /dev/null +++ b/Modules/Setting/Database/Seeders/SettingDatabaseSeeder.php @@ -0,0 +1,29 @@ + 'Triangle POS', + 'company_email' => 'company@test.com', + 'company_phone' => '012345678901', + 'notification_email' => 'notification@test.com', + 'default_currency_id' => 1, + 'default_currency_position' => 'prefix', + 'footer_text' => 'Triangle Pos © 2021', + 'company_address' => 'Tangail, Bangladesh' + ]); + } +} diff --git a/Modules/Setting/Database/factories/.gitkeep b/Modules/Setting/Database/factories/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Entities/.gitkeep b/Modules/Setting/Entities/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Entities/Setting.php b/Modules/Setting/Entities/Setting.php new file mode 100644 index 00000000..f6f76c56 --- /dev/null +++ b/Modules/Setting/Entities/Setting.php @@ -0,0 +1,18 @@ +belongsTo(Currency::class, 'default_currency_id', 'id'); + } +} diff --git a/Modules/Setting/Http/Controllers/.gitkeep b/Modules/Setting/Http/Controllers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Http/Controllers/SettingController.php b/Modules/Setting/Http/Controllers/SettingController.php new file mode 100644 index 00000000..21b243fb --- /dev/null +++ b/Modules/Setting/Http/Controllers/SettingController.php @@ -0,0 +1,52 @@ +validate([ + 'company_name' => 'required|string|max:255', + 'company_email' => 'required|email|max:255', + 'company_phone' => 'required|string|max:255', + 'notification_email' => 'required|email|max:255', + 'company_address' => 'required|string|max:500', + 'default_currency_id' => 'required|numeric', + 'default_currency_position' => 'required|string|max:255', + 'footer_text' => 'required|string|max:255' + ]); + + Setting::firstOrFail()->update([ + 'company_name' => $request->company_name, + 'company_email' => $request->company_email, + 'company_phone' => $request->company_phone, + 'notification_email' => $request->notification_email, + 'company_address' => $request->company_address, + 'default_currency_id' => $request->default_currency_id, + 'default_currency_position' => $request->default_currency_position, + 'footer_text' => $request->footer_text + ]); + + toast('Settings Updated!', 'info'); + + return redirect()->route('settings.index'); + } +} diff --git a/Modules/Setting/Http/Middleware/.gitkeep b/Modules/Setting/Http/Middleware/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Http/Requests/.gitkeep b/Modules/Setting/Http/Requests/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Providers/.gitkeep b/Modules/Setting/Providers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Providers/RouteServiceProvider.php b/Modules/Setting/Providers/RouteServiceProvider.php new file mode 100644 index 00000000..0b1e1113 --- /dev/null +++ b/Modules/Setting/Providers/RouteServiceProvider.php @@ -0,0 +1,69 @@ +mapApiRoutes(); + + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + * + * @return void + */ + protected function mapWebRoutes() + { + Route::middleware('web') + ->namespace($this->moduleNamespace) + ->group(module_path('Setting', '/Routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + * + * @return void + */ + protected function mapApiRoutes() + { + Route::prefix('api') + ->middleware('api') + ->namespace($this->moduleNamespace) + ->group(module_path('Setting', '/Routes/api.php')); + } +} diff --git a/Modules/Setting/Providers/SettingServiceProvider.php b/Modules/Setting/Providers/SettingServiceProvider.php new file mode 100644 index 00000000..954c5ae5 --- /dev/null +++ b/Modules/Setting/Providers/SettingServiceProvider.php @@ -0,0 +1,112 @@ +registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register config. + * + * @return void + */ + protected function registerConfig() + { + $this->publishes([ + module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), + ], 'config'); + $this->mergeConfigFrom( + module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower + ); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = resource_path('views/modules/' . $this->moduleNameLower); + + $sourcePath = module_path($this->moduleName, 'Resources/views'); + + $this->publishes([ + $sourcePath => $viewPath + ], ['views', $this->moduleNameLower . '-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = resource_path('lang/modules/' . $this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } + + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (\Config::get('view.paths') as $path) { + if (is_dir($path . '/modules/' . $this->moduleNameLower)) { + $paths[] = $path . '/modules/' . $this->moduleNameLower; + } + } + return $paths; + } +} diff --git a/Modules/Setting/Resources/assets/.gitkeep b/Modules/Setting/Resources/assets/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Resources/assets/js/app.js b/Modules/Setting/Resources/assets/js/app.js new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Resources/assets/sass/app.scss b/Modules/Setting/Resources/assets/sass/app.scss new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Resources/lang/.gitkeep b/Modules/Setting/Resources/lang/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Resources/views/.gitkeep b/Modules/Setting/Resources/views/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Resources/views/index.blade.php b/Modules/Setting/Resources/views/index.blade.php new file mode 100644 index 00000000..341d94e1 --- /dev/null +++ b/Modules/Setting/Resources/views/index.blade.php @@ -0,0 +1,99 @@ +@extends('layouts.app') + +@section('title', 'Edit Settings') + +@section('breadcrumb') + +@endsection + +@section('content') +
+
+
+ @include('utils.alerts') +
+
+
General Settings
+
+
+
+ @csrf + @method('patch') +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+ +
+
+
+
+
+
+
+@endsection + diff --git a/Modules/Setting/Routes/.gitkeep b/Modules/Setting/Routes/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Routes/api.php b/Modules/Setting/Routes/api.php new file mode 100644 index 00000000..1f8d6770 --- /dev/null +++ b/Modules/Setting/Routes/api.php @@ -0,0 +1,18 @@ +get('/setting', function (Request $request) { + return $request->user(); +}); diff --git a/Modules/Setting/Routes/web.php b/Modules/Setting/Routes/web.php new file mode 100644 index 00000000..27368b3c --- /dev/null +++ b/Modules/Setting/Routes/web.php @@ -0,0 +1,19 @@ + 'auth'], function () { + + Route::get('/settings', 'SettingController@index')->name('settings.index'); + Route::patch('/settings', 'SettingController@update')->name('settings.update'); + +}); diff --git a/Modules/Setting/Tests/Feature/.gitkeep b/Modules/Setting/Tests/Feature/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/Tests/Unit/.gitkeep b/Modules/Setting/Tests/Unit/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/Setting/composer.json b/Modules/Setting/composer.json new file mode 100644 index 00000000..6b3013d0 --- /dev/null +++ b/Modules/Setting/composer.json @@ -0,0 +1,23 @@ +{ + "name": "nwidart/setting", + "description": "", + "authors": [ + { + "name": "Nicolas Widart", + "email": "n.widart@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\Setting\\": "" + } + } +} diff --git a/Modules/Setting/module.json b/Modules/Setting/module.json new file mode 100644 index 00000000..69774ff6 --- /dev/null +++ b/Modules/Setting/module.json @@ -0,0 +1,13 @@ +{ + "name": "Setting", + "alias": "setting", + "description": "", + "keywords": [], + "priority": 0, + "providers": [ + "Modules\\Setting\\Providers\\SettingServiceProvider" + ], + "aliases": {}, + "files": [], + "requires": [] +} diff --git a/Modules/Setting/package.json b/Modules/Setting/package.json new file mode 100644 index 00000000..4599509f --- /dev/null +++ b/Modules/Setting/package.json @@ -0,0 +1,17 @@ +{ + "private": true, + "scripts": { + "dev": "npm run development", + "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", + "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", + "watch-poll": "npm run watch -- --watch-poll", + "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", + "prod": "npm run production", + "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" + }, + "devDependencies": { + "cross-env": "^7.0", + "laravel-mix": "^5.0.1", + "laravel-mix-merge-manifest": "^0.1.2" + } +} diff --git a/Modules/Setting/webpack.mix.js b/Modules/Setting/webpack.mix.js new file mode 100644 index 00000000..a851afc8 --- /dev/null +++ b/Modules/Setting/webpack.mix.js @@ -0,0 +1,14 @@ +const dotenvExpand = require('dotenv-expand'); +dotenvExpand(require('dotenv').config({ path: '../../.env'/*, debug: true*/})); + +const mix = require('laravel-mix'); +require('laravel-mix-merge-manifest'); + +mix.setPublicPath('../../public').mergeManifest(); + +mix.js(__dirname + '/Resources/assets/js/app.js', 'js/setting.js') + .sass( __dirname + '/Resources/assets/sass/app.scss', 'css/setting.css'); + +if (mix.inProduction()) { + mix.version(); +} diff --git a/Modules/User/Database/Seeders/PermissionsTableSeeder.php b/Modules/User/Database/Seeders/PermissionsTableSeeder.php index 42407b9e..e221aed3 100644 --- a/Modules/User/Database/Seeders/PermissionsTableSeeder.php +++ b/Modules/User/Database/Seeders/PermissionsTableSeeder.php @@ -57,6 +57,8 @@ class PermissionsTableSeeder extends Seeder 'create_currencies', 'edit_currencies', 'delete_currencies', + //Settings + 'access_settings' ]; foreach ($permissions as $permission) { diff --git a/app/DataTables/ExpensesDataTable.php b/app/DataTables/ExpensesDataTable.php index a4131408..d460c555 100644 --- a/app/DataTables/ExpensesDataTable.php +++ b/app/DataTables/ExpensesDataTable.php @@ -15,6 +15,9 @@ class ExpensesDataTable extends DataTable public function dataTable($query) { return datatables() ->eloquent($query) + ->addColumn('amount', function ($data) { + return format_currency($data->amount); + }) ->addColumn('action', function ($data) { return view('expense::expenses.partials.actions', compact('data')); }); @@ -57,7 +60,7 @@ class ExpensesDataTable extends DataTable ->title('Category') ->className('text-center align-middle'), - Column::make('amount') + Column::computed('amount') ->className('text-center align-middle'), Column::make('details') diff --git a/app/DataTables/ProductDataTable.php b/app/DataTables/ProductDataTable.php index 5a862f05..322ed9b1 100644 --- a/app/DataTables/ProductDataTable.php +++ b/app/DataTables/ProductDataTable.php @@ -21,7 +21,10 @@ class ProductDataTable extends DataTable }) ->addColumn('product_image', function ($data) { $url = $data->getFirstMediaUrl(); - return ''; + return ''; + }) + ->addColumn('product_price', function ($data) { + return format_currency($data->product_price); }) ->rawColumns(['product_image']); } @@ -68,7 +71,7 @@ class ProductDataTable extends DataTable ->title('Code') ->className('text-center align-middle'), - Column::make('product_price') + Column::computed('product_price') ->title('Price') ->className('text-center align-middle'), diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index b3d9bbc7..a6fcdacf 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -1 +1,19 @@ default_currency_position == 'prefix') { + $formatted_value = settings()->currency->symbol . number_format($value, 2, settings()->currency->decimal_separator, settings()->currency->thousand_separator); + } else { + $formatted_value = number_format($value, 2, settings()->currency->decimal_separator, settings()->currency->thousand_separator) . settings()->currency->symbol; + } + + return $formatted_value; + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index cf46b540..e97bf562 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use Illuminate\Database\Seeder; +use Modules\Setting\Database\Seeders\SettingDatabaseSeeder; use Modules\User\Database\Seeders\PermissionsTableSeeder; class DatabaseSeeder extends Seeder @@ -16,5 +17,6 @@ class DatabaseSeeder extends Seeder { $this->call(PermissionsTableSeeder::class); $this->call(SuperUserSeeder::class); + $this->call(SettingDatabaseSeeder::class); } } diff --git a/modules_statuses.json b/modules_statuses.json index 71fadf8f..e33e86a9 100644 --- a/modules_statuses.json +++ b/modules_statuses.json @@ -5,5 +5,6 @@ "Adjustment": true, "Expense": true, "People": true, - "Currency": true + "Currency": true, + "Setting": true } \ No newline at end of file diff --git a/resources/views/layouts/footer.blade.php b/resources/views/layouts/footer.blade.php index 0a67a0ae..38c77f55 100644 --- a/resources/views/layouts/footer.blade.php +++ b/resources/views/layouts/footer.blade.php @@ -1,4 +1,5 @@ diff --git a/resources/views/layouts/menu.blade.php b/resources/views/layouts/menu.blade.php index 91aefb47..ca801cb4 100644 --- a/resources/views/layouts/menu.blade.php +++ b/resources/views/layouts/menu.blade.php @@ -140,11 +140,12 @@ @endcan -@can('access_currencies') +@can('access_currencies|access_settings')
  • Settings + @can('access_currencies') + @endcan + @can('access_settings') + + @endcan
  • @endcan diff --git a/resources/views/livewire/barcode/product-table.blade.php b/resources/views/livewire/barcode/product-table.blade.php index a02d4dff..93f6f11b 100644 --- a/resources/views/livewire/barcode/product-table.blade.php +++ b/resources/views/livewire/barcode/product-table.blade.php @@ -56,7 +56,7 @@ {!! $barcode !!}

    - Price:: {{ number_format($product->product_price) }} + Price:: {{ format_currency($product->product_price) }}

    @endforeach