update paramterte cabang
This commit is contained in:
parent
6a8ecc1937
commit
b7588608ec
@ -8,6 +8,7 @@
|
|||||||
use Yajra\DataTables\Html\Builder as HtmlBuilder;
|
use Yajra\DataTables\Html\Builder as HtmlBuilder;
|
||||||
use Yajra\DataTables\Html\Column;
|
use Yajra\DataTables\Html\Column;
|
||||||
use Yajra\DataTables\Services\DataTable;
|
use Yajra\DataTables\Services\DataTable;
|
||||||
|
use Nwidart\Modules\Facades\Module;
|
||||||
|
|
||||||
class BranchDataTable extends DataTable
|
class BranchDataTable extends DataTable
|
||||||
{
|
{
|
||||||
@ -20,14 +21,16 @@
|
|||||||
: EloquentDataTable
|
: EloquentDataTable
|
||||||
{
|
{
|
||||||
return (new EloquentDataTable($query))->filter(function ($query) {
|
return (new EloquentDataTable($query))->filter(function ($query) {
|
||||||
if (request()->has('search')) {
|
if (request()->has('search')) {
|
||||||
$search = request()->get('search');
|
$search = request()->get('search');
|
||||||
$query->where('kode', 'like', "%" . $search['value'] . "%")
|
$query->where('kode', 'like', "%" . $search['value'] . "%")
|
||||||
->orWhere('name', 'like', "%" . $search['value'] . "%");
|
->orWhere('name', 'like', "%" . $search['value'] . "%");
|
||||||
}
|
}
|
||||||
})->addIndexColumn()->editColumn('updated_at', function ($row) {
|
})->addIndexColumn()->editColumn('updated_at', function ($row) {
|
||||||
return $row->updated_at->format('d-m-Y H:i:s');
|
return $row->updated_at->format('d-m-Y H:i:s');
|
||||||
})->addColumn('action', 'writeoff::parameter.branch._action')->setRowId('id');
|
})->rawColumns(['action'])->addColumn('action', function ($branch) {
|
||||||
|
return view('writeoff::parameter.branches._actions', compact('branch'));
|
||||||
|
})->setRowId('id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +60,8 @@
|
|||||||
'scrollX' => false,
|
'scrollX' => false,
|
||||||
'drawCallback' => 'function() { KTMenu.createInstances(); }',
|
'drawCallback' => 'function() { KTMenu.createInstances(); }',
|
||||||
])
|
])
|
||||||
->addTableClass('align-middle table-row-dashed fs-6 gy-5');
|
->addTableClass('align-middle table-row-dashed fs-6 gy-5')
|
||||||
|
->drawCallback("function() {" . file_get_contents(Module::getModulePath('writeoff').'Resources/views/parameter/branches/_draw-scripts.js') . "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,9 +72,9 @@
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false),
|
Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false),
|
||||||
Column::make('kode')->name('Kode Branch'),
|
Column::make('kode')->title('Kode Branch'),
|
||||||
Column::make('name')->name('Nama Branch'),
|
Column::make('name')->title('Nama Branch'),
|
||||||
Column::make('updated_at')->name('Last Update')->visible(false),
|
Column::make('updated_at')->title('Last Update')->visible(false),
|
||||||
Column::computed('action')->exportable(false)->printable(false)->width(60)->addClass('text-center'),
|
Column::computed('action')->exportable(false)->printable(false)->width(60)->addClass('text-center'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\Writeoff\Http\Livewire\Branch;
|
|
||||||
|
|
||||||
use Livewire\Component;
|
|
||||||
use Modules\Writeoff\Entities\Branch;
|
|
||||||
|
|
||||||
class BranchModal extends Component
|
|
||||||
{
|
|
||||||
public $kode;
|
|
||||||
public $name;
|
|
||||||
|
|
||||||
public Branch $branch;
|
|
||||||
|
|
||||||
protected $rules = [
|
|
||||||
'kode' => 'required|string|unique:branches,kode',
|
|
||||||
'name' => 'required|string',
|
|
||||||
];
|
|
||||||
|
|
||||||
// This is the list of listeners that this component listens to.
|
|
||||||
protected $listeners = [
|
|
||||||
'modal.show.brahcn' => 'mountBranch',
|
|
||||||
'delete_branch' => 'delete'
|
|
||||||
];
|
|
||||||
|
|
||||||
public function render()
|
|
||||||
{
|
|
||||||
return view('branch::livewire.branch.branch-modal');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mountBranch($branch_name = '', $branch_kode='')
|
|
||||||
{
|
|
||||||
if (empty($branch_kode)) {
|
|
||||||
// Create new
|
|
||||||
$this->branch = new Branch;
|
|
||||||
$this->kode = '';
|
|
||||||
if (empty($branch_name)) {
|
|
||||||
$this->name = '';
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the role by name.
|
|
||||||
$permission = Branch::where('kode', $branch_kode)->first();
|
|
||||||
if (is_null($permission)) {
|
|
||||||
$this->emit('error', 'The selected kode [' . $branch_kode . '] is not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->branch = $permission;
|
|
||||||
|
|
||||||
// Set the name and checked permissions properties to the role's values.
|
|
||||||
$this->kode = $this->branch->kode;
|
|
||||||
$this->name = $this->branch->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function submit()
|
|
||||||
{
|
|
||||||
$this->validate();
|
|
||||||
|
|
||||||
$this->branch->kode = strtoupper($this->kode);
|
|
||||||
$this->branch->name = strtolower($this->name);
|
|
||||||
if ($this->branch->isDirty()) {
|
|
||||||
$this->branch->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emit a success event with a message indicating that the permissions have been updated.
|
|
||||||
$this->emit('success', 'Branch updated');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($kode)
|
|
||||||
{
|
|
||||||
$branch = Branch::where('kode', $kode)->first();
|
|
||||||
|
|
||||||
if (!is_null($branch)) {
|
|
||||||
$branch->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->emit('success', 'Branch deleted');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hydrate()
|
|
||||||
{
|
|
||||||
$this->resetErrorBag();
|
|
||||||
$this->resetValidation();
|
|
||||||
}
|
|
||||||
}
|
|
91
Livewire/Branch/BranchModal.php
Normal file
91
Livewire/Branch/BranchModal.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Writeoff\Livewire\Branch;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Livewire\Component;
|
||||||
|
use Modules\Writeoff\Entities\Branch;
|
||||||
|
|
||||||
|
class BranchModal extends Component
|
||||||
|
{
|
||||||
|
public $kode;
|
||||||
|
public $name;
|
||||||
|
|
||||||
|
public $edit_mode = false;
|
||||||
|
|
||||||
|
protected $rules = [
|
||||||
|
'kode' => 'required|string|max:255|unique:branches,kode',
|
||||||
|
'name' => 'required|string',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $listeners = [
|
||||||
|
'delete_branch' => 'deleteBranch',
|
||||||
|
'update_branch' => 'updateBranch',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('writeoff::livewire.branch.branch-modal');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function submit()
|
||||||
|
{
|
||||||
|
// Validate the form input data
|
||||||
|
$this->validate();
|
||||||
|
|
||||||
|
DB::transaction(function () {
|
||||||
|
// Prepare the data for creating a new user
|
||||||
|
$data = [
|
||||||
|
'name' => $this->name,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Create a new user record in the database
|
||||||
|
$user = Branch::updateOrCreate([
|
||||||
|
'kode' => $this->kode,
|
||||||
|
], $data);
|
||||||
|
|
||||||
|
if ($this->edit_mode) {
|
||||||
|
// Emit a success event with a message
|
||||||
|
$this->dispatch('success', __('Branch updated'));
|
||||||
|
} else {
|
||||||
|
// Emit a success event with a message
|
||||||
|
$this->dispatch('success', __('New Branch created'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reset the form fields after successful submission
|
||||||
|
$this->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteBranch($id)
|
||||||
|
{
|
||||||
|
// Prevent deletion of current user
|
||||||
|
if ($id == Auth::id()) {
|
||||||
|
$this->dispatch('error', 'Branch cannot be deleted');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the user record with the specified ID
|
||||||
|
Branch::destroy($id);
|
||||||
|
|
||||||
|
// Emit a success event with a message
|
||||||
|
$this->dispatch('success', 'Branch successfully deleted');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateBranch($id)
|
||||||
|
{
|
||||||
|
$this->edit_mode = true;
|
||||||
|
|
||||||
|
$branch = Branch::find($id);
|
||||||
|
|
||||||
|
$this->kode = $branch->kode;
|
||||||
|
$this->name = $branch->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hydrate()
|
||||||
|
{
|
||||||
|
$this->resetErrorBag();
|
||||||
|
$this->resetValidation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
72
Resources/views/livewire/branch/branch-modal.blade.php
Normal file
72
Resources/views/livewire/branch/branch-modal.blade.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<div class="modal fade" id="kt_modal_add_branch" tabindex="-1" aria-hidden="true" wire:ignore.self>
|
||||||
|
<!--begin::Modal dialog-->
|
||||||
|
<div class="modal-dialog modal-dialog-centered mw-650px">
|
||||||
|
<!--begin::Modal content-->
|
||||||
|
<div class="modal-content">
|
||||||
|
<!--begin::Modal header-->
|
||||||
|
<div class="modal-header" id="kt_modal_add_branch_header">
|
||||||
|
<!--begin::Modal title-->
|
||||||
|
<h2 class="fw-bold">Add Cabang</h2>
|
||||||
|
<!--end::Modal title-->
|
||||||
|
<!--begin::Close-->
|
||||||
|
<div class="btn btn-icon btn-sm btn-active-icon-primary" data-bs-dismiss="modal" aria-label="Close">
|
||||||
|
{!! getIcon('cross','fs-1') !!}
|
||||||
|
</div>
|
||||||
|
<!--end::Close-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal header-->
|
||||||
|
<!--begin::Modal body-->
|
||||||
|
<div class="modal-body px-5 my-7">
|
||||||
|
<!--begin::Form-->
|
||||||
|
<form id="kt_modal_add_branch_form" class="form" action="#" wire:submit.prevent="submit">
|
||||||
|
<!--begin::Scroll-->
|
||||||
|
<div class="d-flex flex-column scroll-y px-5 px-lg-10" id="kt_modal_add_branch_scroll" data-kt-scroll="true" data-kt-scroll-activate="true" data-kt-scroll-max-height="auto" data-kt-scroll-dependencies="#kt_modal_add_branch_header" data-kt-scroll-wrappers="#kt_modal_add_branch_scroll" data-kt-scroll-offset="300px">
|
||||||
|
|
||||||
|
<!--begin::Input group-->
|
||||||
|
<div class="fv-row mb-7">
|
||||||
|
<!--begin::Label-->
|
||||||
|
<label class="required fw-semibold fs-6 mb-2">Kode Cabang</label>
|
||||||
|
<!--end::Label-->
|
||||||
|
<!--begin::Input-->
|
||||||
|
<input type="text" wire:model.defer="kode" name="kode" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Kode Cabang"/>
|
||||||
|
<!--end::Input-->
|
||||||
|
@error('kode')
|
||||||
|
<span class="text-danger">{{ $message }}</span> @enderror
|
||||||
|
</div>
|
||||||
|
<!--end::Input group-->
|
||||||
|
<!--begin::Input group-->
|
||||||
|
<div class="fv-row mb-7">
|
||||||
|
<!--begin::Label-->
|
||||||
|
<label class="required fw-semibold fs-6 mb-2">Nama Cabang</label>
|
||||||
|
<!--end::Label-->
|
||||||
|
<!--begin::Input-->
|
||||||
|
<input type="text" wire:model.defer="name" name="name" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Nama Cabang"/>
|
||||||
|
<!--end::Input-->
|
||||||
|
@error('name')
|
||||||
|
<span class="text-danger">{{ $message }}</span> @enderror
|
||||||
|
</div>
|
||||||
|
<!--end::Input group-->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!--end::Scroll-->
|
||||||
|
<!--begin::Actions-->
|
||||||
|
<div class="text-center pt-15">
|
||||||
|
<button type="reset" class="btn btn-light me-3" data-bs-dismiss="modal" aria-label="Close" wire:loading.attr="disabled">Discard</button>
|
||||||
|
<button type="submit" class="btn btn-primary" data-kt-branches-modal-action="submit">
|
||||||
|
<span class="indicator-label" wire:loading.remove>Submit</span>
|
||||||
|
<span class="indicator-progress" wire:loading wire:target="submit">
|
||||||
|
Please wait...
|
||||||
|
<span class="spinner-border spinner-border-sm align-middle ms-2"></span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<!--end::Actions-->
|
||||||
|
</form>
|
||||||
|
<!--end::Form-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal body-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal content-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal dialog-->
|
||||||
|
</div>
|
23
Resources/views/parameter/branches/_actions.blade.php
Normal file
23
Resources/views/parameter/branches/_actions.blade.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<a href="#" class="btn btn-light btn-active-light-primary btn-flex btn-center btn-sm" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end">
|
||||||
|
Actions
|
||||||
|
<i class="ki-duotone ki-down fs-5 ms-1"></i>
|
||||||
|
</a>
|
||||||
|
<!--begin::Menu-->
|
||||||
|
<div class="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-600 menu-state-bg-light-primary fw-semibold fs-7 w-125px py-4" data-kt-menu="true">
|
||||||
|
<!--begin::Menu item-->
|
||||||
|
<div class="menu-item px-3">
|
||||||
|
<a href="#" class="menu-link px-3" data-kt-branch-id="{{ $branch->id }}" data-bs-toggle="modal" data-bs-target="#kt_modal_add_branch" data-kt-action="update_row">
|
||||||
|
Edit
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--end::Menu item-->
|
||||||
|
|
||||||
|
<!--begin::Menu item-->
|
||||||
|
<div class="menu-item px-3">
|
||||||
|
<a href="#" class="menu-link px-3" data-kt-branch-id="{{ $branch->id }}" data-kt-action="delete_row">
|
||||||
|
Delete
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--end::Menu item-->
|
||||||
|
</div>
|
||||||
|
<!--end::Menu-->
|
37
Resources/views/parameter/branches/_draw-scripts.js
Normal file
37
Resources/views/parameter/branches/_draw-scripts.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Initialize KTMenu
|
||||||
|
KTMenu.init();
|
||||||
|
|
||||||
|
// Add click event listener to delete buttons
|
||||||
|
document.querySelectorAll('[data-kt-action="delete_row"]').forEach(function (element) {
|
||||||
|
element.addEventListener('click', function () {
|
||||||
|
Swal.fire({
|
||||||
|
text: 'Are you sure you want to remove?',
|
||||||
|
icon: 'warning',
|
||||||
|
buttonsStyling: false,
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: 'Yes',
|
||||||
|
cancelButtonText: 'No',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-danger',
|
||||||
|
cancelButton: 'btn btn-secondary',
|
||||||
|
}
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
Livewire.dispatch('delete_branch', this.getAttribute('data-kt-branch-id'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add click event listener to update buttons
|
||||||
|
document.querySelectorAll('[data-kt-action="update_row"]').forEach(function (element) {
|
||||||
|
element.addEventListener('click', function () {
|
||||||
|
Livewire.dispatch('update_branch', this.getAttribute('data-kt-branch-id'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Listen for 'success' event emitted by Livewire
|
||||||
|
Livewire.on('success', (message) => {
|
||||||
|
// Reload the users-table datatable
|
||||||
|
LaravelDataTables['branch-table'].ajax.reload();
|
||||||
|
});
|
@ -0,0 +1,72 @@
|
|||||||
|
<x-default-layout>
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
Cabang
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('breadcrumbs')
|
||||||
|
{{ Breadcrumbs::render('parameter.branches') }}
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<!--begin::Card header-->
|
||||||
|
<div class="card-header border-0 pt-6">
|
||||||
|
<!--begin::Card title-->
|
||||||
|
<div class="card-title">
|
||||||
|
<!--begin::Search-->
|
||||||
|
<div class="d-flex align-items-center position-relative my-1">
|
||||||
|
{!! getIcon('magnifier', 'fs-3 position-absolute ms-5') !!}
|
||||||
|
<input type="text" data-kt-branch-table-filter="search" class="form-control form-control-solid w-250px ps-13" placeholder="Search branch" id="mySearchInput"/>
|
||||||
|
</div>
|
||||||
|
<!--end::Search-->
|
||||||
|
</div>
|
||||||
|
<!--begin::Card title-->
|
||||||
|
|
||||||
|
<!--begin::Card toolbar-->
|
||||||
|
<div class="card-toolbar">
|
||||||
|
<!--begin::Toolbar-->
|
||||||
|
<div class="d-flex justify-content-end" data-kt-branch-table-toolbar="base">
|
||||||
|
<!--begin::Add branch-->
|
||||||
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#kt_modal_add_branch">
|
||||||
|
{!! getIcon('plus', 'fs-2', '', 'i') !!}
|
||||||
|
Add Cabang
|
||||||
|
</button>
|
||||||
|
<!--end::Add branch-->
|
||||||
|
</div>
|
||||||
|
<!--end::Toolbar-->
|
||||||
|
|
||||||
|
<!--begin::Modal-->
|
||||||
|
<livewire:writeoff::branch.branch-modal/>
|
||||||
|
<!--end::Modal-->
|
||||||
|
</div>
|
||||||
|
<!--end::Card toolbar-->
|
||||||
|
</div>
|
||||||
|
<!--end::Card header-->
|
||||||
|
|
||||||
|
<!--begin::Card body-->
|
||||||
|
<div class="card-body py-4">
|
||||||
|
<!--begin::Table-->
|
||||||
|
<div class="table-responsive">
|
||||||
|
{{ $dataTable->table() }}
|
||||||
|
</div>
|
||||||
|
<!--end::Table-->
|
||||||
|
</div>
|
||||||
|
<!--end::Card body-->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
{{ $dataTable->scripts() }}
|
||||||
|
<script>
|
||||||
|
document.getElementById('mySearchInput').addEventListener('keyup', function () {
|
||||||
|
window.LaravelDataTables['branch-table'].search(this.value).draw();
|
||||||
|
});
|
||||||
|
document.addEventListener('livewire:initialized', function () {
|
||||||
|
Livewire.on('success', function () {
|
||||||
|
$('#kt_modal_add_branch').modal('hide');
|
||||||
|
window.LaravelDataTables['branch-table'].ajax.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
|
||||||
|
</x-default-layout>
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Writeoff",
|
"name": "Writeoff",
|
||||||
"alias": "writeoff",
|
"alias": "writeoff",
|
||||||
|
"database": "",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"priority": 0,
|
"priority": 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user