fix edit products using new workflow mutations

This commit is contained in:
2025-06-12 17:15:06 +07:00
parent 1a01efb1b5
commit 58578532cc
7 changed files with 535 additions and 127 deletions

View File

@@ -116,6 +116,13 @@ class MutationsController extends Controller
}
DB::commit();
// Check if request came from transaction page
if ($request->has('from_transaction_page') || str_contains($request->header('referer', ''), '/transaction')) {
return redirect()->back()
->with('success', 'Mutasi berhasil dibuat dan terkirim ke dealer tujuan');
}
return redirect()->route('mutations.index')
->with('success', 'Mutasi berhasil dibuat dan terkirim ke dealer tujuan');

View File

@@ -41,4 +41,11 @@ class Dealer extends Model
{
return $this->hasMany(Stock::class);
}
public function products()
{
return $this->belongsToMany(Product::class, 'stocks', 'dealer_id', 'product_id')
->withPivot('quantity')
->withTimestamps();
}
}

View File

@@ -29,6 +29,13 @@ class Product extends Model
return $this->hasMany(MutationDetail::class);
}
public function dealers()
{
return $this->belongsToMany(Dealer::class, 'stocks', 'product_id', 'dealer_id')
->withPivot('quantity')
->withTimestamps();
}
// Helper method untuk mendapatkan total stock saat ini
public function getCurrentTotalStockAttribute()
{