partial update opnames and detail table

This commit is contained in:
2025-06-04 18:29:05 +07:00
parent 8305e44c42
commit ff498cd98f
20 changed files with 864 additions and 174 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers\WarehouseManagement;
use App\Http\Controllers\Controller;
use App\Models\Menu;
use App\Models\Opname;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Yajra\DataTables\Facades\DataTables;
class OpnamesController extends Controller
{
public function index(Request $request){
$menu = Menu::where('link','opnames.index')->first();
if($request->ajax()){
$data = Opname::with('user','dealer');
return DataTables::of($data)
->addIndexColumn()
->addColumn('user_name', function ($row){
return $row->user ? $row->user->name : '-';
})
->addColumn('dealer_name', function ($row){
return $row->dealer ? $row->dealer->name : '-';
})
->addColumn('action', function ($row) use ($menu) {
$btn = '<div class="d-flex">';
$btn .= '<button class="btn btn-sm btn-secondary btn-product-stock-dealers">Detail</button>';
$btn .= '</div>';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
return view('warehouse_management.opnames.index');
}
public function create(){
return view('warehouse_management.opnames.create');
}
public function store(Request $request){
try{
}catch(\Exception $ex){
Log::error($ex->getMessage());
}
}
}

View File

@@ -32,16 +32,10 @@ class ProductsController extends Controller
return $row->category ? $row->category->name : '-';
})
->addColumn('total_stock', function ($row){
return $row->dealers->sum(function($dealer){
return $dealer->pivot->quantity ?? 0;
});
return 0;
})
->addColumn('action', function ($row) use ($menu) {
$btn = '<div class="d-flex">';
// if (Auth::user()->can('delete', $menu)) {
// $btn .= '<button style="margin-right: 8px;" class="btn btn-danger btn-sm btn-destroy-product" data-action="' . route('products.destroy', $row->id) . '" data-id="' . $row->id . '">Hapus</button>';
// }
if (Auth::user()->can('update', $menu)) {
$btn .= '<a href="' . route('products.edit', $row->id) . '" class="btn btn-warning btn-sm" style="margin-right: 8px;">Edit</a>';

View File

@@ -23,9 +23,7 @@ class Dealer extends Model
return $this->hasMany(Transaction::class, 'dealer_id', 'id');
}
public function products(){
return $this->belongsToMany(Product::class, 'stock')
->withPivot('quantity')
->withTimestamps();
public function opnames(){
return $this->hasMany(Opname::class);
}
}

26
app/Models/Opname.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Opname extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = ['dealer_id','opname_date','user_id','note'];
public function dealer(){
return $this->belongsTo(Dealer::class);
}
public function details(){
return $this->hasMany(OpnameDetail::class);
}
public function user(){
return $this->belongsTo(User::class);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class OpnameDetail extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'opname_id',
'product_id',
'physical_stock',
'system_stock',
'difference',
'note',
];
public function opname()
{
return $this->belongsTo(Opname::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
}

View File

@@ -16,9 +16,7 @@ class Product extends Model
return $this->belongsTo(ProductCategory::class, 'product_category_id');
}
public function dealers(){
return $this->belongsToMany(Dealer::class, 'stock')
->withPivot('quantity')
->withTimestamps();
public function opnameDetails(){
return $this->hasMany(OpnameDetail::class);
}
}

565
ckb.sql Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOpnamesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('opnames', function (Blueprint $table) {
$table->id();
$table->foreignId('dealer_id')->constrained()->onDelete('cascade');
$table->date('opname_date');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->text("note")->nullable();
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('opnames');
}
}

View File

@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOpnameDetailsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('opname_details', function (Blueprint $table) {
$table->id();
$table->foreignId('opname_id')->constrained()->onDelete('cascade');
$table->foreignId('product_id')->constrained()->onDelete('cascade');
$table->integer('system_stock');
$table->integer('physical_stock');
$table->integer('difference')->default(0);
$table->text('note')->nullable();
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('opname_details');
}
}

View File

@@ -0,0 +1,32 @@
/*
* ATTENTION: An "eval-source-map" devtool has been used.
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./resources/js/warehouse_management/opnames/index.js":
/*!************************************************************!*\
!*** ./resources/js/warehouse_management/opnames/index.js ***!
\************************************************************/
/***/ (() => {
eval("$.ajaxSetup({\n headers: {\n \"X-CSRF-TOKEN\": $('meta[name=\"csrf-token\"]').attr(\"content\")\n }\n});\nvar tableContainer = $(\"#opnames-table\");\nvar url = tableContainer.data(\"url\");\nvar table = $(\"#opnames-table\").DataTable({\n processing: true,\n serverSide: true,\n ajax: url,\n columns: [{\n data: \"dealer_name\",\n name: \"dealer.name\"\n }, {\n data: \"user_name\",\n name: \"user.name\"\n }, {\n data: \"opname_date\",\n name: \"opname_date\"\n }, {\n data: \"action\",\n name: \"action\",\n orderable: false,\n searchable: false\n }]\n});//# sourceURL=[module]\n//# sourceMappingURL=data:application/json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0FKSztBQUo2QixDQUE5QixDQUFaIn0=\n//# sourceURL=webpack-internal:///./resources/js/warehouse_management/opnames/index.js\n");
/***/ })
/******/ });
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval-source-map devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./resources/js/warehouse_management/opnames/index.js"]();
/******/
/******/ })()
;

View File

@@ -4,8 +4,6 @@
"/js/warehouse_management/products/index.js": "/js/warehouse_management/products/index.js",
"/js/warehouse_management/products/create.js": "/js/warehouse_management/products/create.js",
"/js/warehouse_management/products/edit.js": "/js/warehouse_management/products/edit.js",
"/js/warehouse_management/stock_mutations/index.js": "/js/warehouse_management/stock_mutations/index.js",
"/js/warehouse_management/stock_opnames/index.js": "/js/warehouse_management/stock_opnames/index.js",
"/js/warehouse_management/stock_opnames/create.js": "/js/warehouse_management/stock_opnames/create.js",
"/js/warehouse_management/opnames/index.js": "/js/warehouse_management/opnames/index.js",
"/css/app.css": "/css/app.css"
}

View File

@@ -0,0 +1,18 @@
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
});
let tableContainer = $("#opnames-table");
let url = tableContainer.data("url");
let table = $("#opnames-table").DataTable({
processing: true,
serverSide: true,
ajax: url,
columns: [
{ data: "dealer_name", name: "dealer.name" },
{ data: "user_name", name: "user.name" },
{ data: "opname_date", name: "opname_date" },
{ data: "action", name: "action", orderable: false, searchable: false },
],
});

View File

@@ -215,9 +215,9 @@
</li>
@endcan
@can('view', $menus['mutations.index'])
@can('view', $menus['opnames.index'])
<li class="kt-menu__item" aria-haspopup="true">
<a href="{{ route('mutations.index') }}" class="kt-menu__link">
<a href="{{ route('opnames.index') }}" class="kt-menu__link">
<i class="fa fa-list" style="display: flex; align-items: center; margin-right: 10px;"></i>
<span class="kt-menu__link-text">Mutasi Produk</span>
</a>

View File

@@ -0,0 +1,46 @@
@extends('layouts.backapp')
@section('content')
<div class="kt-portlet kt-portlet--mobile" id="kt_blockui_datatable">
<div class="kt-portlet__head kt-portlet__head--lg">
<div class="kt-portlet__head-label">
<span class="kt-portlet__head-icon">
<i class="kt-font-brand flaticon2-list-1"></i>
</span>
<h3 class="kt-portlet__head-title">
Tabel Opnames
</h3>
</div>
@can('create', $menus['product_categories.index'])
<div class="kt-portlet__head-toolbar">
<div class="kt-portlet__head-wrapper">
<div class="kt-portlet__head-actions">
<a href="{{ route('opnames.create') }}" class="btn btn-bold btn-label-brand btn--sm">Tambah</a>
</div>
</div>
</div>
@endcan
</div>
<div class="kt-portlet__body">
<div class="table-responsive">
<!--begin: Datatable -->
<table class="table table-striped table-bordered table-hover" id="opnames-table" data-url="{{ route("opnames.index") }}">
<thead>
<tr>
<th>Dealer</th>
<th>Pengguna</th>
<th>Tanggal Opname</th>
<th>Aksi</th>
</tr>
</thead>
</table>
<!--end: Datatable -->
</div>
</div>
</div>
@endsection
@section('javascripts')
<script src="{{ mix('js/warehouse_management/opnames/index.js') }}"></script>
@endsection

View File

@@ -1,48 +0,0 @@
@extends('layouts.backapp')
@section('content')
<div class="kt-portlet kt-portlet--mobile" id="kt_blockui_datatable">
<div class="kt-portlet__head kt-portlet__head--lg">
<div class="kt-portlet__head-label">
<span class="kt-portlet__head-icon">
<i class="kt-font-brand flaticon2-list-1"></i>
</span>
<h3 class="kt-portlet__head-title">
Tabel Mutasi Stock Produk
</h3>
</div>
{{-- @can('create', $menus['mutations.index'])
<div class="kt-portlet__head-toolbar">
<div class="kt-portlet__head-wrapper">
<div class="kt-portlet__head-actions">
<a href="{{ route('products.create') }}" class="btn btn-bold btn-label-brand btn--sm">Tambah</a>
</div>
</div>
</div>
@endcan --}}
</div>
<div class="kt-portlet__body">
<div class="table-responsive">
<!--begin: Datatable -->
<table class="table table-striped table-bordered table-hover" id="stock-mutations-table" data-url="{{ route("mutations.index") }}">
<thead>
<tr>
<th>Produk</th>
<th>Dealer</th>
<th>Pengguna</th>
<th>Tipe Mutasi</th>
<th>Jumlah</th>
<th>Dibuat</th>
</tr>
</thead>
</table>
<!--end: Datatable -->
</div>
</div>
</div>
@endsection
@section('javascripts')
<script src="{{mix('js/warehouse_management/stock_mutations/index.js')}}"></script>
@endsection

View File

@@ -1,56 +0,0 @@
@extends('layouts.backapp')
@section('content')
<div class="kt-portlet kt-portlet--mobile" id="kt_blockui_datatable">
<div class="kt-portlet__head kt-portlet__head--lg">
<div class="kt-portlet__head-label">
<span class="kt-portlet__head-icon">
<i class="kt-font-brand flaticon2-plus"></i>
</span>
<h3 class="kt-portlet__head-title">
Tambah Opname
</h3>
</div>
</div>
<div class="kt-portlet__body">
<form action="{{ route('opnames.store') }}" method="POST" id="opnameForm">
@csrf
<div class="form-group">
<label for="product"><strong>Produk</strong></label>
<input type="text" class="form-control" name="product" />
</div>
<div class="form-group">
<label for="dealer"><strong>Dealer</strong></label>
<input type="text" class="form-control" name="dealer" />
</div>
<div class="form-group">
<label for="system_quantity"><strong>Total Sistem</strong></label>
<input type="number" class="form-control" name="system_quantity" />
</div>
<div class="form-group">
<label for="phisycal_quantity"><strong>Total Sistem</strong></label>
<input type="number" class="form-control" name="phisycal_quantity" />
</div>
<div class="form-group">
<label for="difference"><strong>Perbedaan</strong></label>
<input type="number" class="form-control" name="difference" />
</div>
<div class="form-group mt-4">
<button type="submit" class="btn btn-primary">Simpan</button>
<a href="{{ route('opnames.index') }}" class="btn btn-secondary">Batal</a>
</div>
</form>
</div>
</div>
@endsection
@section('javascripts')
<script src="{{mix('js/warehouse_management/stock_opnames/create.js')}}"></script>
@endsection

View File

@@ -1,49 +0,0 @@
@extends('layouts.backapp')
@section('content')
<div class="kt-portlet kt-portlet--mobile" id="kt_blockui_datatable">
<div class="kt-portlet__head kt-portlet__head--lg">
<div class="kt-portlet__head-label">
<span class="kt-portlet__head-icon">
<i class="kt-font-brand flaticon2-list-1"></i>
</span>
<h3 class="kt-portlet__head-title">
Tabel Stock Opname
</h3>
</div>
@can('create', $menus['opnames.index'])
<div class="kt-portlet__head-toolbar">
<div class="kt-portlet__head-wrapper">
<div class="kt-portlet__head-actions">
<a href="{{ route('opnames.create') }}" class="btn btn-bold btn-label-brand btn--sm">Tambah</a>
</div>
</div>
</div>
@endcan
</div>
<div class="kt-portlet__body">
<div class="table-responsive">
<!--begin: Datatable -->
<table class="table table-striped table-bordered table-hover" id="stock-opnames-table" data-url="{{ route("opnames.index") }}">
<thead>
<tr>
<th>Produk</th>
<th>Dealer</th>
<th>Pengguna</th>
<th>Total Sistem</th>
<th>Total Fisik</th>
<th>Perbedaan</th>
<th>Tanggal Opname</th>
</tr>
</thead>
</table>
<!--end: Datatable -->
</div>
</div>
</div>
@endsection
@section('javascripts')
<script src="{{mix('js/warehouse_management/stock_opnames/index.js')}}"></script>
@endsection

View File

@@ -7,6 +7,7 @@ use App\Http\Controllers\ReportController;
use App\Http\Controllers\RolePrivilegeController;
use App\Http\Controllers\TransactionController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\WarehouseManagement\OpnamesController;
use App\Http\Controllers\WarehouseManagement\ProductCategoriesController;
use App\Http\Controllers\WarehouseManagement\ProductsController;
use App\Http\Controllers\WorkController;
@@ -227,7 +228,12 @@ Route::group(['middleware' => 'auth'], function() {
Route::get('{product_category}/edit', 'edit')->name('product_categories.edit');
Route::put('{product_category}', 'update')->name('product_categories.update');
Route::delete('{product_category}', 'destroy')->name('product_categories.destroy');
});
});
Route::prefix('opnames')->controller(OpnamesController::class)->group(function (){
Route::get('/','index')->name('opnames.index');
Route::get('create','create')->name('opnames.create');
});
});
});

View File

@@ -29,6 +29,10 @@ mix.js("resources/js/app.js", "public/js")
"resources/js/warehouse_management/products/edit.js",
"public/js/warehouse_management/products"
)
.js(
"resources/js/warehouse_management/opnames/index.js",
"public/js/warehouse_management/opnames"
)
.sourceMaps();
mix.browserSync({