From 997a68faec368d6aa8c4cbeb2fa1791bf90198a9 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Mon, 2 Oct 2023 18:27:22 +0700 Subject: [PATCH] initial commit --- Config/.gitkeep | 0 Config/config.php | 5 + Console/.gitkeep | 0 DataTables/BranchDataTable.php | 86 ++++++++++ Database/Migrations/.gitkeep | 0 ...023_10_02_033421_create_branches_table.php | 38 +++++ Database/Seeders/.gitkeep | 0 Database/Seeders/WriteoffDatabaseSeeder.php | 21 +++ Database/factories/.gitkeep | 0 Entities/.gitkeep | 0 Entities/BaseModel.php | 34 ++++ Entities/Branch.php | 15 ++ Http/Controllers/.gitkeep | 0 Http/Controllers/BranchController.php | 160 ++++++++++++++++++ Http/Middleware/.gitkeep | 0 Http/Requests/.gitkeep | 0 Http/Requests/Branch/StoreBranchRequest.php | 67 ++++++++ Http/Requests/Branch/UpdateBranchRequest.php | 65 +++++++ Providers/.gitkeep | 0 Providers/RouteServiceProvider.php | 69 ++++++++ Providers/WriteoffServiceProvider.php | 114 +++++++++++++ Resources/assets/.gitkeep | 0 Resources/assets/js/app.js | 0 Resources/assets/sass/app.scss | 0 Resources/lang/.gitkeep | 0 Resources/views/.gitkeep | 0 .../views/parameter/branches/index.blade.php | 0 Resources/views/partials/menu/_app.blade.php | 29 ++++ Routes/.gitkeep | 0 Routes/api.php | 18 ++ Routes/breadcrumbs.php | 14 ++ Routes/web.php | 16 ++ Tests/Feature/.gitkeep | 0 Tests/Unit/.gitkeep | 0 composer.json | 24 +++ module.json | 11 ++ package.json | 16 ++ vite.config.js | 24 +++ 38 files changed, 826 insertions(+) create mode 100644 Config/.gitkeep create mode 100644 Config/config.php create mode 100644 Console/.gitkeep create mode 100644 DataTables/BranchDataTable.php create mode 100644 Database/Migrations/.gitkeep create mode 100644 Database/Migrations/2023_10_02_033421_create_branches_table.php create mode 100644 Database/Seeders/.gitkeep create mode 100644 Database/Seeders/WriteoffDatabaseSeeder.php create mode 100644 Database/factories/.gitkeep create mode 100644 Entities/.gitkeep create mode 100644 Entities/BaseModel.php create mode 100644 Entities/Branch.php create mode 100644 Http/Controllers/.gitkeep create mode 100644 Http/Controllers/BranchController.php create mode 100644 Http/Middleware/.gitkeep create mode 100644 Http/Requests/.gitkeep create mode 100644 Http/Requests/Branch/StoreBranchRequest.php create mode 100644 Http/Requests/Branch/UpdateBranchRequest.php create mode 100644 Providers/.gitkeep create mode 100644 Providers/RouteServiceProvider.php create mode 100644 Providers/WriteoffServiceProvider.php create mode 100644 Resources/assets/.gitkeep create mode 100644 Resources/assets/js/app.js create mode 100644 Resources/assets/sass/app.scss create mode 100644 Resources/lang/.gitkeep create mode 100644 Resources/views/.gitkeep create mode 100644 Resources/views/parameter/branches/index.blade.php create mode 100644 Resources/views/partials/menu/_app.blade.php create mode 100644 Routes/.gitkeep create mode 100644 Routes/api.php create mode 100644 Routes/breadcrumbs.php create mode 100644 Routes/web.php create mode 100644 Tests/Feature/.gitkeep create mode 100644 Tests/Unit/.gitkeep create mode 100644 composer.json create mode 100644 module.json create mode 100644 package.json create mode 100644 vite.config.js diff --git a/Config/.gitkeep b/Config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Config/config.php b/Config/config.php new file mode 100644 index 0000000..e8cea49 --- /dev/null +++ b/Config/config.php @@ -0,0 +1,5 @@ + 'Writeoff' +]; diff --git a/Console/.gitkeep b/Console/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/DataTables/BranchDataTable.php b/DataTables/BranchDataTable.php new file mode 100644 index 0000000..f39ecb9 --- /dev/null +++ b/DataTables/BranchDataTable.php @@ -0,0 +1,86 @@ +filter(function ($query) { + if (request()->has('search')) { + $search = request()->get('search'); + $query->where('kode', 'like', "%" . $search['value'] . "%") + ->orWhere('name', 'like', "%" . $search['value'] . "%"); + } + })->addIndexColumn()->editColumn('updated_at', function ($row) { + return $row->updated_at->format('d-m-Y H:i:s'); + })->addColumn('action', 'writeoff::parameter.branch._action')->setRowId('id'); + } + + /** + * Get the query source of dataTable. + */ + public function query(Branch $model) + : QueryBuilder + { + return $model->newQuery(); + } + + /** + * Optional method if you want to use the html builder. + */ + public function html() + : HtmlBuilder + { + return $this->builder() + ->setTableId('branch-table') + ->columns($this->getColumns()) + ->minifiedAjax() + ->stateSave(false) + ->responsive() + ->autoWidth(true) + ->orderBy(1) + ->parameters([ + 'scrollX' => false, + 'drawCallback' => 'function() { KTMenu.createInstances(); }', + ]) + ->addTableClass('align-middle table-row-dashed fs-6 gy-5'); + } + + /** + * Get the dataTable columns definition. + */ + public function getColumns() + : array + { + return [ + Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), + Column::make('kode')->name('Kode Branch'), + Column::make('name')->name('Nama Branch'), + Column::make('updated_at')->name('Last Update')->visible(false), + Column::computed('action')->exportable(false)->printable(false)->width(60)->addClass('text-center'), + ]; + } + + /** + * Get the filename for export. + */ + protected function filename() + : string + { + return 'Branch_' . date('YmdHis'); + } + } diff --git a/Database/Migrations/.gitkeep b/Database/Migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Database/Migrations/2023_10_02_033421_create_branches_table.php b/Database/Migrations/2023_10_02_033421_create_branches_table.php new file mode 100644 index 0000000..8e6f754 --- /dev/null +++ b/Database/Migrations/2023_10_02_033421_create_branches_table.php @@ -0,0 +1,38 @@ +id(); + $table->string('kode',9)->unique(); + $table->string('name'); + $table->timestamps(); + $table->softDeletes(); + + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('branches'); + } +}; diff --git a/Database/Seeders/.gitkeep b/Database/Seeders/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Database/Seeders/WriteoffDatabaseSeeder.php b/Database/Seeders/WriteoffDatabaseSeeder.php new file mode 100644 index 0000000..1a12996 --- /dev/null +++ b/Database/Seeders/WriteoffDatabaseSeeder.php @@ -0,0 +1,21 @@ +call("OthersTableSeeder"); + } +} diff --git a/Database/factories/.gitkeep b/Database/factories/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Entities/.gitkeep b/Entities/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Entities/BaseModel.php b/Entities/BaseModel.php new file mode 100644 index 0000000..b86bb5f --- /dev/null +++ b/Entities/BaseModel.php @@ -0,0 +1,34 @@ +connection = $module->database; + } + + public function getActivitylogOptions() + : LogOptions + { + return LogOptions::defaults()->logAll() + ->useLogName('Writeoff : '); + } + + } diff --git a/Entities/Branch.php b/Entities/Branch.php new file mode 100644 index 0000000..2483bf3 --- /dev/null +++ b/Entities/Branch.php @@ -0,0 +1,15 @@ +middleware(function ($request, $next) { + $this->user = Auth::guard('web')->user(); + return $next($request); + }); + } + + /** + * Display a listing of the Branchs. + * + * @param \Modules\Writeoff\DataTables\BranchDataTable $dataTable + * + * @return mixed + */ + public function index(BranchDataTable $dataTable, Request $request) + { + if (is_null($this->user) || !$this->user->can('master.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any master data !'); + } + + return $dataTable->render('writeoff::parameter.branches.index'); + } + + /** + * Store a newly created Branch in storage. + * + * @param \Modules\Writeoff\Http\Requests\Branch\StoreBranchRequest $request + * + * @return mixed + */ + public function store(StoreBranchRequest $request) + { + if (is_null($this->user) || !$this->user->can('master.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any master data !'); + } + + // Validate the request... + $validated = $request->validated(); + + // Store the Branch... + if ($validated) { + try { + Branch::create($validated); + echo json_encode(['status' => 'success', 'message' => 'Branch created successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => 'Branch created failed.']); + } + return; + } + + echo json_encode(['status' => 'error', 'message' => 'Branch created failed.']); + } + + /** + * Show the form for creating a new Branch. + */ + public function create() + { + if (is_null($this->user) || !$this->user->can('master.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any master data !'); + } + + abort(404); + } + + /** + * Display the specified Branch. + * + * @param \Modules\Writeoff\Entities\Branch $directorat + */ + public function show(Branch $directorat) + { + if (is_null($this->user) || !$this->user->can('master.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any master data !'); + } + } + + /** + * Show the form for editing the specified Branch. + * + * @param $id + */ + public function edit($id) + { + if (is_null($this->user) || !$this->user->can('master.update')) { + abort(403, 'Sorry !! You are Unauthorized to update any master data !'); + } + + $directorat = Branch::find($id); + echo json_encode($directorat); + } + + /** + * Update the specified Branch in storage. + * + * @param \Modules\Writeoff\Http\Requests\Branch\UpdateBranchRequest $request + * @param \Modules\Writeoff\Entities\Branch $directorat + * + * @return mixed + */ + public function update(UpdateBranchRequest $request, Branch $directorat) + { + if (is_null($this->user) || !$this->user->can('master.update')) { + abort(403, 'Sorry !! You are Unauthorized to update any master data !'); + } + + // Validate the request... + $validated = $request->validated(); + + // Update the Branch... + if ($validated) { + try { + $directorat->update($validated); + + echo json_encode(['status' => 'success', 'message' => 'Branch updated successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => 'Branch updated failed.']); + } + + return; + } + + echo json_encode(['status' => 'error', 'message' => 'Branch updated failed.']); + } + + /** + * Remove the specified Branch from storage. + * + * @param \Modules\Writeoff\Entities\Branch $directorat + * + * @return void + */ + public function destroy(Branch $directorat) + { + if (is_null($this->user) || !$this->user->can('master.delete')) { + abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); + } + + $directorat->delete(); + echo json_encode(['status' => 'success', 'message' => 'Branch deleted successfully.']); + } + } diff --git a/Http/Middleware/.gitkeep b/Http/Middleware/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Http/Requests/.gitkeep b/Http/Requests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Http/Requests/Branch/StoreBranchRequest.php b/Http/Requests/Branch/StoreBranchRequest.php new file mode 100644 index 0000000..55239bd --- /dev/null +++ b/Http/Requests/Branch/StoreBranchRequest.php @@ -0,0 +1,67 @@ + + */ + public function rules() + : array + { + return [ + 'kode' => 'required|string|max:9|min:9|unique:branches,kode', + 'name' => 'required|string|max:100' + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator) + : void + { + $validator->after(function (Validator $validator) { + if ($validator->errors()->any()) { + $errors = json_decode($validator->errors()->toJson(), true); + + + foreach ($errors as $key => $value) { + flash($value[0]); + } + return redirect()->route('parameter.branches.index')->with('error', 'Branch created failed.'); + } + + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Branch created failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + } diff --git a/Http/Requests/Branch/UpdateBranchRequest.php b/Http/Requests/Branch/UpdateBranchRequest.php new file mode 100644 index 0000000..66f6c61 --- /dev/null +++ b/Http/Requests/Branch/UpdateBranchRequest.php @@ -0,0 +1,65 @@ + + */ + public function rules() + : array + { + return [ + 'kode' => 'required|string|max:9|min:9|unique:branches,kode,' . $this->branch->id, + 'name' => 'required|string|max:100' + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator) + : void + { + $validator->after(function (Validator $validator) { + if ($validator->errors()->any()) { + $error = json_decode($validator->errors()->toJson(), true); + foreach ($error as $key => $value) { + flash($value[0]); + } + + return redirect()->route('parameter.branches.index')->with('error', 'Branch updated failed.'); + } + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Branch updated failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + } diff --git a/Providers/.gitkeep b/Providers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Providers/RouteServiceProvider.php b/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..1c7230a --- /dev/null +++ b/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('Writeoff', '/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('Writeoff', '/Routes/api.php')); + } +} diff --git a/Providers/WriteoffServiceProvider.php b/Providers/WriteoffServiceProvider.php new file mode 100644 index 0000000..7abeea3 --- /dev/null +++ b/Providers/WriteoffServiceProvider.php @@ -0,0 +1,114 @@ +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); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); + } + } + + /** + * 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/Resources/assets/.gitkeep b/Resources/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Resources/assets/js/app.js b/Resources/assets/js/app.js new file mode 100644 index 0000000..e69de29 diff --git a/Resources/assets/sass/app.scss b/Resources/assets/sass/app.scss new file mode 100644 index 0000000..e69de29 diff --git a/Resources/lang/.gitkeep b/Resources/lang/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Resources/views/.gitkeep b/Resources/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Resources/views/parameter/branches/index.blade.php b/Resources/views/parameter/branches/index.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/Resources/views/partials/menu/_app.blade.php b/Resources/views/partials/menu/_app.blade.php new file mode 100644 index 0000000..7342771 --- /dev/null +++ b/Resources/views/partials/menu/_app.blade.php @@ -0,0 +1,29 @@ +@canany(['master.read','master.create','master.update','master.delete']) + + + +@endcanany diff --git a/Routes/.gitkeep b/Routes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Routes/api.php b/Routes/api.php new file mode 100644 index 0000000..d9f6341 --- /dev/null +++ b/Routes/api.php @@ -0,0 +1,18 @@ +get('/writeoff', function (Request $request) { + return $request->user(); +}); \ No newline at end of file diff --git a/Routes/breadcrumbs.php b/Routes/breadcrumbs.php new file mode 100644 index 0000000..b2871da --- /dev/null +++ b/Routes/breadcrumbs.php @@ -0,0 +1,14 @@ +parent('home'); + $trail->push('Parameter', '#'); + }); + + Breadcrumbs::for('parameter.branches', function (BreadcrumbTrail $trail) { + $trail->parent('parameter'); + $trail->push('Cabang', route('parameter.branches.index')); + }); diff --git a/Routes/web.php b/Routes/web.php new file mode 100644 index 0000000..6583266 --- /dev/null +++ b/Routes/web.php @@ -0,0 +1,16 @@ +prefix('parameter')->group(function() { + Route::get('branches', 'BranchController@index')->name('branches.index'); +}); diff --git a/Tests/Feature/.gitkeep b/Tests/Feature/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Tests/Unit/.gitkeep b/Tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9a9fb3d --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "putrakuningan/writeoff", + "type": "laravel-module", + "description": "", + "authors": [ + { + "name": "Daeng Deni Mardaeni", + "email": "ddeni05@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\Writeoff\\": "" + } + } +} diff --git a/module.json b/module.json new file mode 100644 index 0000000..52e934a --- /dev/null +++ b/module.json @@ -0,0 +1,11 @@ +{ + "name": "Writeoff", + "alias": "writeoff", + "description": "", + "keywords": [], + "priority": 0, + "providers": [ + "Modules\\Writeoff\\Providers\\WriteoffServiceProvider" + ], + "files": [] +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..30c1a80 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "private": true, + "scripts": { + "dev": "vite", + "build": "vite build" + }, + "devDependencies": { + "axios": "^0.21.4", + "dotenv": "^10.0.0", + "dotenv-expand": "^5.1.0", + "laravel-vite-plugin": "^0.6.0", + "lodash": "^4.17.21", + "postcss": "^8.3.7", + "vite": "^3.0.9" + } +} diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..580bcdd --- /dev/null +++ b/vite.config.js @@ -0,0 +1,24 @@ +const dotenvExpand = require('dotenv-expand'); +dotenvExpand(require('dotenv').config({ path: '../../.env'/*, debug: true*/})); + +import { defineConfig } from 'vite'; +import laravel from 'laravel-vite-plugin'; + +export default defineConfig({ + build: { + outDir: '../../public/build-writeoff', + emptyOutDir: true, + manifest: true, + }, + plugins: [ + laravel({ + publicDirectory: '../../public', + buildDirectory: 'build-writeoff', + input: [ + __dirname + '/Resources/assets/sass/app.scss', + __dirname + '/Resources/assets/js/app.js' + ], + refresh: true, + }), + ], +});