initial commit

This commit is contained in:
Daeng Deni Mardaeni 2023-10-02 18:27:22 +07:00
commit 997a68faec
38 changed files with 826 additions and 0 deletions

0
Config/.gitkeep Normal file
View File

5
Config/config.php Normal file
View File

@ -0,0 +1,5 @@
<?php
return [
'name' => 'Writeoff'
];

0
Console/.gitkeep Normal file
View File

View File

@ -0,0 +1,86 @@
<?php
namespace Modules\Writeoff\DataTables;
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
use Modules\Writeoff\Entities\Branch;
use Yajra\DataTables\EloquentDataTable;
use Yajra\DataTables\Html\Builder as HtmlBuilder;
use Yajra\DataTables\Html\Column;
use Yajra\DataTables\Services\DataTable;
class BranchDataTable extends DataTable
{
/**
* Build the DataTable class.
*
* @param QueryBuilder $query Results from query() method.
*/
public function dataTable(QueryBuilder $query)
: EloquentDataTable
{
return (new EloquentDataTable($query))->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');
}
}

View File

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('branches', function (Blueprint $table) {
$table->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');
}
};

View File

View File

@ -0,0 +1,21 @@
<?php
namespace Modules\Writeoff\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class WriteoffDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call("OthersTableSeeder");
}
}

View File

0
Entities/.gitkeep Normal file
View File

34
Entities/BaseModel.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace Modules\Writeoff\Entities;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Wildside\Userstamps\Userstamps;
class BaseModel extends Model
{
use LogsActivity, HasFactory, SoftDeletes, Userstamps;
protected $connection;
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$module = file_get_contents(dirname(__FILE__, 2) . '/module.json');
$module = json_decode($module);
$this->connection = $module->database;
}
public function getActivitylogOptions()
: LogOptions
{
return LogOptions::defaults()->logAll()
->useLogName('Writeoff : ');
}
}

15
Entities/Branch.php Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace Modules\Writeoff\Entities;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Branch extends BaseModel
{
protected $fillable = [
'kode',
'name'
];
}

View File

View File

@ -0,0 +1,160 @@
<?php
namespace Modules\Writeoff\Http\Controllers;
use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Modules\Writeoff\DataTables\BranchDataTable;
use Modules\Writeoff\Entities\Branch;
use Modules\Writeoff\Http\Requests\Branch\StoreBranchRequest;
use Modules\Writeoff\Http\Requests\Branch\UpdateBranchRequest;
class BranchController extends Controller
{
public $user;
public function __construct()
{
$this->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.']);
}
}

0
Http/Middleware/.gitkeep Normal file
View File

0
Http/Requests/.gitkeep Normal file
View File

View File

@ -0,0 +1,67 @@
<?php
namespace Modules\Writeoff\Http\Requests\Branch;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\ValidationException;
use Illuminate\Validation\Validator;
use Symfony\Component\HttpFoundation\JsonResponse;
class StoreBranchRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize()
: bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
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));
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace Modules\Writeoff\Http\Requests\Branch;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use Illuminate\Validation\Validator;
class UpdateBranchRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize()
: bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
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));
}
}

0
Providers/.gitkeep Normal file
View File

View File

@ -0,0 +1,69 @@
<?php
namespace Modules\Writeoff\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* The module namespace to assume when generating URLs to actions.
*
* @var string
*/
protected $moduleNamespace = 'Modules\Writeoff\Http\Controllers';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* @return void
*/
public function boot()
{
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->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'));
}
}

View File

@ -0,0 +1,114 @@
<?php
namespace Modules\Writeoff\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
class WriteoffServiceProvider extends ServiceProvider
{
/**
* @var string $moduleName
*/
protected $moduleName = 'Writeoff';
/**
* @var string $moduleNameLower
*/
protected $moduleNameLower = 'writeoff';
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->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;
}
}

View File

View File

View File

0
Resources/lang/.gitkeep Normal file
View File

0
Resources/views/.gitkeep Normal file
View File

View File

@ -0,0 +1,29 @@
@canany(['master.read','master.create','master.update','master.delete'])
<!--begin:Menu item-->
<div data-kt-menu-trigger="click" class="menu-item menu-accordion {{ $route[0] == 'parameter' ? 'show' : '' }}">
<!--begin:Menu link-->
<span class="menu-link">
<span class="menu-icon">{!! getIcon('people', 'fs-2') !!}</span>
<span class="menu-title">Parameter</span>
<span class="menu-arrow"></span>
</span>
<!--end:Menu link-->
<!--begin:Menu sub-->
<div class="menu-sub menu-sub-accordion">
<!--begin:Menu item-->
<div class="menu-item ">
<!--begin:Menu link-->
<a class="menu-link {{ isset($route[1]) && $route[1] == 'branches' ? 'active' : '' }}" href="{{ route('parameter.branches.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Cabang</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
</div>
<!--end:Menu sub-->
</div>
<!--end:Menu item-->
@endcanany

0
Routes/.gitkeep Normal file
View File

18
Routes/api.php Normal file
View File

@ -0,0 +1,18 @@
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/writeoff', function (Request $request) {
return $request->user();
});

14
Routes/breadcrumbs.php Normal file
View File

@ -0,0 +1,14 @@
<?php
use Diglactic\Breadcrumbs\Breadcrumbs;
use Diglactic\Breadcrumbs\Generator as BreadcrumbTrail;
Breadcrumbs::for('parameter', function (BreadcrumbTrail $trail) {
$trail->parent('home');
$trail->push('Parameter', '#');
});
Breadcrumbs::for('parameter.branches', function (BreadcrumbTrail $trail) {
$trail->parent('parameter');
$trail->push('Cabang', route('parameter.branches.index'));
});

16
Routes/web.php Normal file
View File

@ -0,0 +1,16 @@
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::name('parameter.')->prefix('parameter')->group(function() {
Route::get('branches', 'BranchController@index')->name('branches.index');
});

0
Tests/Feature/.gitkeep Normal file
View File

0
Tests/Unit/.gitkeep Normal file
View File

24
composer.json Normal file
View File

@ -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\\": ""
}
}
}

11
module.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "Writeoff",
"alias": "writeoff",
"description": "",
"keywords": [],
"priority": 0,
"providers": [
"Modules\\Writeoff\\Providers\\WriteoffServiceProvider"
],
"files": []
}

16
package.json Normal file
View File

@ -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"
}
}

24
vite.config.js Normal file
View File

@ -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,
}),
],
});