partial update create toggle active product and mutations
This commit is contained in:
@@ -7,10 +7,12 @@ use App\Models\Dealer;
|
|||||||
use App\Models\Menu;
|
use App\Models\Menu;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\ProductCategory;
|
use App\Models\ProductCategory;
|
||||||
|
use App\Models\StockMutation;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Yajra\DataTables\Facades\DataTables;
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class ProductsController extends Controller
|
class ProductsController extends Controller
|
||||||
{
|
{
|
||||||
@@ -37,13 +39,18 @@ class ProductsController extends Controller
|
|||||||
->addColumn('action', function ($row) use ($menu) {
|
->addColumn('action', function ($row) use ($menu) {
|
||||||
$btn = '<div class="d-flex">';
|
$btn = '<div class="d-flex">';
|
||||||
|
|
||||||
if (Auth::user()->can('delete', $menu)) {
|
// 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>';
|
// $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)) {
|
if (Auth::user()->can('update', $menu)) {
|
||||||
$btn .= '<a href="' . route('products.edit', $row->id) . '" class="btn btn-warning btn-sm">Edit</a>';
|
$btn .= '<a href="' . route('products.edit', $row->id) . '" class="btn btn-warning btn-sm" style="margin-right: 8px;">Edit</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$btn .= '<button class="btn btn-sm btn-toggle-active '
|
||||||
|
. ($row->active ? 'btn-danger' : 'btn-success') . '"
|
||||||
|
data-url="' . route('products.toggleActive', $row->id) . '" data-active="'.$row->active.'">'
|
||||||
|
. ($row->active ? 'Nonaktifkan' : 'Aktifkan') . '</button>';
|
||||||
|
|
||||||
$btn .= '</div>';
|
$btn .= '</div>';
|
||||||
|
|
||||||
@@ -76,9 +83,15 @@ class ProductsController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'code' => 'required|string|unique:products,code',
|
'code' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
Rule::unique('products')->whereNull('deleted_at'),
|
||||||
|
],
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'description' => 'nullable|string',
|
'description' => 'nullable|string',
|
||||||
|
'unit' => 'nullable|string',
|
||||||
|
'active' => 'required|boolean',
|
||||||
'product_category_id' => 'required|exists:product_categories,id',
|
'product_category_id' => 'required|exists:product_categories,id',
|
||||||
'dealer_stock' => 'nullable|array',
|
'dealer_stock' => 'nullable|array',
|
||||||
'dealer_stock.*.dealer_id' => 'required|exists:dealers,id',
|
'dealer_stock.*.dealer_id' => 'required|exists:dealers,id',
|
||||||
@@ -89,19 +102,33 @@ class ProductsController extends Controller
|
|||||||
$product = Product::create([
|
$product = Product::create([
|
||||||
'code' => $request->code,
|
'code' => $request->code,
|
||||||
'name' => $request->name,
|
'name' => $request->name,
|
||||||
|
'unit' => $request->unit,
|
||||||
'description' => $request->description,
|
'description' => $request->description,
|
||||||
'product_category_id' => $request->product_category_id,
|
'product_category_id' => $request->product_category_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Prepare dealer stock for pivot
|
// Prepare dealer stock for pivot and create mutation records
|
||||||
$pivotData = [];
|
$pivotData = [];
|
||||||
if ($request->has('dealer_stock')) {
|
if ($request->has('dealer_stock')) {
|
||||||
foreach ($request->dealer_stock as $stockData) {
|
foreach ($request->dealer_stock as $stockData) {
|
||||||
if (empty($stockData['dealer_id']) || !isset($stockData['quantity'])) continue;
|
if (empty($stockData['dealer_id']) || !isset($stockData['quantity'])) continue;
|
||||||
|
|
||||||
$pivotData[$stockData['dealer_id']] = ['quantity' => $stockData['quantity']];
|
$dealerId = $stockData['dealer_id'];
|
||||||
|
$quantity = $stockData['quantity'];
|
||||||
|
|
||||||
|
$pivotData[$dealerId] = ['quantity' => $quantity];
|
||||||
|
|
||||||
|
// Create stock mutation for initial stock "in"
|
||||||
|
StockMutation::create([
|
||||||
|
'product_id' => $product->id,
|
||||||
|
'dealer_id' => $dealerId,
|
||||||
|
'mutation_type' => 'in', // karena ini penambahan stok awal
|
||||||
|
'quantity' => $quantity,
|
||||||
|
'description' => 'Initial stock added when product created',
|
||||||
|
'user_id' => Auth::id(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach dealer stock using pivot table
|
// Attach dealer stock using pivot table
|
||||||
$product->dealers()->attach($pivotData);
|
$product->dealers()->attach($pivotData);
|
||||||
}
|
}
|
||||||
@@ -146,28 +173,75 @@ class ProductsController extends Controller
|
|||||||
public function update(Request $request, Product $product)
|
public function update(Request $request, Product $product)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'code' => 'required|string|unique:products,code,' . $product->id,
|
'code' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
Rule::unique('products')->ignore($product->id)->whereNull('deleted_at'),
|
||||||
|
],
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'description' => 'nullable|string',
|
'description' => 'nullable|string',
|
||||||
|
'unit' => 'nullable|string',
|
||||||
|
'active' => 'required|boolean',
|
||||||
'product_category_id' => 'required|exists:product_categories,id',
|
'product_category_id' => 'required|exists:product_categories,id',
|
||||||
'dealer_stock' => 'nullable|array',
|
'dealer_stock' => 'nullable|array',
|
||||||
'dealer_stock.*.dealer_id' => 'required|exists:dealers,id',
|
'dealer_stock.*.dealer_id' => 'required|exists:dealers,id',
|
||||||
'dealer_stock.*.quantity' => 'required|integer|min:0',
|
'dealer_stock.*.quantity' => 'required|integer|min:0',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$product->update($request->only(['code', 'name', 'description', 'product_category_id']));
|
$product->update($request->only(['code', 'name', 'description', 'unit', 'product_category_id']));
|
||||||
|
|
||||||
// Prepare pivot sync data
|
// Ambil stok lama dari pivot
|
||||||
|
$oldStocks = $product->dealers()->pluck('quantity', 'dealer_id')->toArray();
|
||||||
|
|
||||||
|
// Data baru untuk sync pivot
|
||||||
$syncData = [];
|
$syncData = [];
|
||||||
|
|
||||||
|
$newStocks = [];
|
||||||
if ($request->has('dealer_stock')) {
|
if ($request->has('dealer_stock')) {
|
||||||
foreach ($request->dealer_stock as $item) {
|
foreach ($request->dealer_stock as $item) {
|
||||||
$syncData[$item['dealer_id']] = ['quantity' => $item['quantity']];
|
$dealerId = $item['dealer_id'];
|
||||||
|
$newQty = $item['quantity'];
|
||||||
|
$syncData[$dealerId] = ['quantity' => $newQty];
|
||||||
|
$newStocks[$dealerId] = $newQty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync with pivot table
|
// Sync pivot table
|
||||||
$product->dealers()->sync($syncData);
|
$product->dealers()->sync($syncData);
|
||||||
|
|
||||||
|
// Hitung mutasi stok (selisih)
|
||||||
|
// Mutasi stok untuk stok baru atau perubahan stok
|
||||||
|
foreach ($newStocks as $dealerId => $newQty) {
|
||||||
|
$oldQty = $oldStocks[$dealerId] ?? 0;
|
||||||
|
$diff = $newQty - $oldQty;
|
||||||
|
|
||||||
|
if ($diff != 0) {
|
||||||
|
StockMutation::create([
|
||||||
|
'product_id' => $product->id,
|
||||||
|
'dealer_id' => $dealerId,
|
||||||
|
'mutation_type' => $diff > 0 ? 'in' : 'out',
|
||||||
|
'quantity' => abs($diff),
|
||||||
|
'description' => 'Stock updated via product update',
|
||||||
|
'user_id' => auth()->id(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutasi stok untuk dealer yang dihapus (stok jadi 0)
|
||||||
|
$deletedDealers = array_diff_key($oldStocks, $newStocks);
|
||||||
|
foreach ($deletedDealers as $dealerId => $oldQty) {
|
||||||
|
if ($oldQty > 0) {
|
||||||
|
StockMutation::create([
|
||||||
|
'product_id' => $product->id,
|
||||||
|
'dealer_id' => $dealerId,
|
||||||
|
'mutation_type' => 'out',
|
||||||
|
'quantity' => $oldQty,
|
||||||
|
'description' => 'Stock removed via product update (dealer removed)',
|
||||||
|
'user_id' => auth()->id(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->route('products.index')->with('success', 'Produk berhasil diperbarui.');
|
return redirect()->route('products.index')->with('success', 'Produk berhasil diperbarui.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,12 +253,41 @@ class ProductsController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function destroy(Product $product)
|
public function destroy(Product $product)
|
||||||
{
|
{
|
||||||
// Detach all dealer relationships (optional if using cascade on delete)
|
// Ambil stok pivot sebelum hapus
|
||||||
|
$dealerStocks = $product->dealers()->pluck('quantity', 'dealer_id')->toArray();
|
||||||
|
|
||||||
|
// Buat mutasi stok keluar (out) untuk semua stok yang dihapus
|
||||||
|
foreach ($dealerStocks as $dealerId => $qty) {
|
||||||
|
if ($qty > 0) {
|
||||||
|
StockMutation::create([
|
||||||
|
'product_id' => $product->id,
|
||||||
|
'dealer_id' => $dealerId,
|
||||||
|
'mutation_type' => 'out',
|
||||||
|
'quantity' => $qty,
|
||||||
|
'description' => 'Stock removed due to product deletion',
|
||||||
|
'user_id' => auth()->id(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hapus pivot stok dealer
|
||||||
$product->dealers()->detach();
|
$product->dealers()->detach();
|
||||||
|
|
||||||
// Delete the product
|
// Hapus produk
|
||||||
$product->delete();
|
$product->delete();
|
||||||
|
|
||||||
return response()->json(['success' => true, 'message' => 'Produk berhasil dihapus.']);
|
return redirect()->route('products.index')->with('success', 'Produk berhasil dihapus.');
|
||||||
|
}
|
||||||
|
public function toggleActive(Request $request, Product $product)
|
||||||
|
{
|
||||||
|
// You can add authorization here
|
||||||
|
$product->active = !$product->active;
|
||||||
|
$product->save();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'active' => $product->active,
|
||||||
|
'message' => 'Status produk berhasil diperbarui.'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\WarehouseManagement;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\StockMutation;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
|
|
||||||
|
class StockMutationsController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request){
|
||||||
|
if ($request->ajax()) {
|
||||||
|
$query = StockMutation::with(['product', 'dealer', 'user']);
|
||||||
|
|
||||||
|
return DataTables::of($query)
|
||||||
|
->addIndexColumn()
|
||||||
|
->addColumn('product_name', function ($row) {
|
||||||
|
return $row->product ? $row->product->name : '-';
|
||||||
|
})
|
||||||
|
->addColumn('dealer_name', function ($row) {
|
||||||
|
return $row->dealer ? $row->dealer->name : '-';
|
||||||
|
})
|
||||||
|
->addColumn('user_name', function ($row) {
|
||||||
|
return $row->user ? $row->user->name : '-';
|
||||||
|
})
|
||||||
|
->addColumn('mutation_type_label', function ($row) {
|
||||||
|
return $row->mutation_type == 'in'
|
||||||
|
? '<span class="badge bg-success">Masuk</span>'
|
||||||
|
: '<span class="badge bg-danger">Keluar</span>';
|
||||||
|
})
|
||||||
|
->editColumn('created_at', function ($row) {
|
||||||
|
return $row->created_at->format('d M Y H:i');
|
||||||
|
})
|
||||||
|
->rawColumns(['mutation_type_label'])
|
||||||
|
->make(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('warehouse_management.stock_mutations.index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ class Product extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory, SoftDeletes;
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
protected $fillable = ['code','name','description','product_category_id'];
|
protected $fillable = ['code','name','description','unit','active','product_category_id'];
|
||||||
|
|
||||||
public function category(){
|
public function category(){
|
||||||
return $this->belongsTo(ProductCategory::class, 'product_category_id');
|
return $this->belongsTo(ProductCategory::class, 'product_category_id');
|
||||||
|
|||||||
35
app/Models/StockMutation.php
Normal file
35
app/Models/StockMutation.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class StockMutation extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'product_id',
|
||||||
|
'dealer_id',
|
||||||
|
'mutation_type',
|
||||||
|
'quantity',
|
||||||
|
'description',
|
||||||
|
'user_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function product()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Product::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dealer()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Dealer::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
app/Models/StockOpname.php
Normal file
36
app/Models/StockOpname.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class StockOpname extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'product_id',
|
||||||
|
'dealer_id',
|
||||||
|
'system_quantity',
|
||||||
|
'physical_quantity',
|
||||||
|
'difference',
|
||||||
|
'opname_date',
|
||||||
|
'user_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function product()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Product::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dealer()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Dealer::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateStockMutationsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('stock_mutations', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('product_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->foreignId('dealer_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->enum('mutation_type',['in','out','adjustment']);
|
||||||
|
$table->integer('quantity');
|
||||||
|
$table->text('description')->nullable();
|
||||||
|
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('stock_mutations');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateStockOpnamesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('stock_opnames', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('product_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->foreignId('dealer_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->integer('system_quantity');
|
||||||
|
$table->integer('physical_quantity');
|
||||||
|
$table->integer('difference');
|
||||||
|
$table->date('opname_date');
|
||||||
|
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('stock_opnames');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddUnitToProductsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('products', function (Blueprint $table) {
|
||||||
|
$table->string('unit')->nullable()->after('description');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('products', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('unit');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddActiveToProductsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('products', function (Blueprint $table) {
|
||||||
|
$table->boolean('active')->default(true)->after('unit');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('products', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('active');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,10 @@ class MenuSeeder extends Seeder
|
|||||||
[
|
[
|
||||||
'name' => 'Kategori Produk',
|
'name' => 'Kategori Produk',
|
||||||
'link' => 'product_categories.index'
|
'link' => 'product_categories.index'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Mutasi Produk',
|
||||||
|
'link' => 'mutations.index'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
32
public/js/warehouse_management/stock_mutations/index.js
Normal file
32
public/js/warehouse_management/stock_mutations/index.js
Normal 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/stock_mutations/index.js":
|
||||||
|
/*!********************************************************************!*\
|
||||||
|
!*** ./resources/js/warehouse_management/stock_mutations/index.js ***!
|
||||||
|
\********************************************************************/
|
||||||
|
/***/ (() => {
|
||||||
|
|
||||||
|
eval("//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsid2VicGFjazovLy8uL3Jlc291cmNlcy9qcy93YXJlaG91c2VfbWFuYWdlbWVudC9zdG9ja19tdXRhdGlvbnMvaW5kZXguanM/OGNlZiJdLCJzb3VyY2VzQ29udGVudCI6WyIiXSwibWFwcGluZ3MiOiIiLCJmaWxlIjoiLi9yZXNvdXJjZXMvanMvd2FyZWhvdXNlX21hbmFnZW1lbnQvc3RvY2tfbXV0YXRpb25zL2luZGV4LmpzLmpzIiwic291cmNlUm9vdCI6IiJ9\n//# sourceURL=webpack-internal:///./resources/js/warehouse_management/stock_mutations/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/stock_mutations/index.js"]();
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
@@ -4,5 +4,6 @@
|
|||||||
"/js/warehouse_management/products/index.js": "/js/warehouse_management/products/index.js",
|
"/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/create.js": "/js/warehouse_management/products/create.js",
|
||||||
"/js/warehouse_management/products/edit.js": "/js/warehouse_management/products/edit.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",
|
||||||
"/css/app.css": "/css/app.css"
|
"/css/app.css": "/css/app.css"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ let table = $("#products-table").DataTable({
|
|||||||
{ data: "code", name: "code" },
|
{ data: "code", name: "code" },
|
||||||
{ data: "name", name: "name" },
|
{ data: "name", name: "name" },
|
||||||
{ data: "category_name", name: "category.name" },
|
{ data: "category_name", name: "category.name" },
|
||||||
|
{ data: "unit", name: "unit" },
|
||||||
{ data: "total_stock", name: "total_stock" },
|
{ data: "total_stock", name: "total_stock" },
|
||||||
{ data: "action", name: "action", orderable: false, searchable: false },
|
{ data: "action", name: "action", orderable: false, searchable: false },
|
||||||
],
|
],
|
||||||
@@ -48,3 +49,37 @@ $(document).on("click", ".btn-destroy-product", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$(document).on("click", ".btn-toggle-active", function () {
|
||||||
|
let button = $(this);
|
||||||
|
let url = button.data("url");
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: "Status produk?",
|
||||||
|
text: "Anda yakin ingin mengganti status produk!",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#d33",
|
||||||
|
cancelButtonColor: "#dedede",
|
||||||
|
confirmButtonText: "Ya",
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
method: "POST",
|
||||||
|
data: {
|
||||||
|
_token: $('meta[name="csrf-token"]').attr("content"),
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
if (response.success) {
|
||||||
|
$("#products-table")
|
||||||
|
.DataTable()
|
||||||
|
.ajax.reload(null, false);
|
||||||
|
alert(response.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
alert("Gagal mengubah status produk.");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -26,6 +26,11 @@
|
|||||||
<input type="text" name="name" id="name" class="form-control" required>
|
<input type="text" name="name" id="name" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="unit"><strong>Satuan Produk</strong></label>
|
||||||
|
<input type="text" name="unit" id="unit" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="description"><strong>Deskripsi</strong></label>
|
<label for="description"><strong>Deskripsi</strong></label>
|
||||||
<textarea name="description" id="description" class="form-control" rows="3"></textarea>
|
<textarea name="description" id="description" class="form-control" rows="3"></textarea>
|
||||||
|
|||||||
@@ -27,6 +27,11 @@
|
|||||||
<input type="text" name="name" id="name" class="form-control" value="{{ old('name', $product->name) }}" required>
|
<input type="text" name="name" id="name" class="form-control" value="{{ old('name', $product->name) }}" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="unit"><strong>Satuan Produk</strong></label>
|
||||||
|
<input type="text" name="unit" id="unit" class="form-control" value="{{ old('unit', $product->unit) }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="description"><strong>Deskripsi</strong></label>
|
<label for="description"><strong>Deskripsi</strong></label>
|
||||||
<textarea name="description" id="description" class="form-control" rows="3">{{ old('description', $product->description) }}</textarea>
|
<textarea name="description" id="description" class="form-control" rows="3">{{ old('description', $product->description) }}</textarea>
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
<th>Kode</th>
|
<th>Kode</th>
|
||||||
<th>Nama</th>
|
<th>Nama</th>
|
||||||
<th>Kategori</th>
|
<th>Kategori</th>
|
||||||
|
<th>Satuan</th>
|
||||||
<th>Stok</th>
|
<th>Stok</th>
|
||||||
<th>Aksi</th>
|
<th>Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
@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-line-chart"></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="mutations-table" data-url="{{ route("mutations.index") }}">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Produk</th>
|
||||||
|
<th>Dealer</th>
|
||||||
|
<th>User</th>
|
||||||
|
<th>Tipe Mutasi</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
|
||||||
@@ -9,6 +9,7 @@ use App\Http\Controllers\TransactionController;
|
|||||||
use App\Http\Controllers\UserController;
|
use App\Http\Controllers\UserController;
|
||||||
use App\Http\Controllers\WarehouseManagement\ProductCategoriesController;
|
use App\Http\Controllers\WarehouseManagement\ProductCategoriesController;
|
||||||
use App\Http\Controllers\WarehouseManagement\ProductsController;
|
use App\Http\Controllers\WarehouseManagement\ProductsController;
|
||||||
|
use App\Http\Controllers\WarehouseManagement\StockMutationsController;
|
||||||
use App\Http\Controllers\WorkController;
|
use App\Http\Controllers\WorkController;
|
||||||
use App\Models\Menu;
|
use App\Models\Menu;
|
||||||
use App\Models\Privilege;
|
use App\Models\Privilege;
|
||||||
@@ -206,7 +207,9 @@ Route::group(['middleware' => 'auth'], function() {
|
|||||||
Route::prefix('warehouse')->group(function (){
|
Route::prefix('warehouse')->group(function (){
|
||||||
Route::resource('products', ProductsController::class);
|
Route::resource('products', ProductsController::class);
|
||||||
Route::resource('product_categories', ProductCategoriesController::class);
|
Route::resource('product_categories', ProductCategoriesController::class);
|
||||||
Route::get('categories/parents', [ProductCategoriesController::class, 'getParents']);
|
Route::get('categories/parents', [ProductCategoriesController::class, 'getParents'])->name('products.parents');
|
||||||
|
Route::post('products/{product}/toggle-active', [ProductsController::class, 'toggleActive'])->name('products.toggleActive');
|
||||||
|
Route::get('mutations/index',[StockMutationsController::class, 'index'])->name('mutations.index');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -29,4 +29,8 @@ mix.js("resources/js/app.js", "public/js")
|
|||||||
"resources/js/warehouse_management/products/edit.js",
|
"resources/js/warehouse_management/products/edit.js",
|
||||||
"public/js/warehouse_management/products"
|
"public/js/warehouse_management/products"
|
||||||
)
|
)
|
||||||
|
.js(
|
||||||
|
"resources/js/warehouse_management/stock_mutations/index.js",
|
||||||
|
"public/js/warehouse_management/stock_mutations"
|
||||||
|
)
|
||||||
.sourceMaps();
|
.sourceMaps();
|
||||||
|
|||||||
Reference in New Issue
Block a user