remove status pending and complete
This commit is contained in:
@@ -182,8 +182,18 @@ class MutationsController extends Controller
|
||||
$mutation->receive(auth()->id(), $request->reception_notes);
|
||||
|
||||
DB::commit();
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil diterima dan menunggu persetujuan pengirim');
|
||||
|
||||
// Check user role and redirect accordingly
|
||||
if (!auth()->user()->dealer_id) {
|
||||
// Users without dealer_id are likely admin, redirect to mutations index
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil diterima dan siap untuk disetujui. Stock akan dipindahkan setelah disetujui.');
|
||||
} else {
|
||||
// Dealer users redirect back to transaction page
|
||||
return redirect()->route('transaction')
|
||||
->with('success', 'Mutasi berhasil diterima. Silakan setujui mutasi ini untuk memindahkan stock.')
|
||||
->with('active_tab', 'penerimaan');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
@@ -202,11 +212,25 @@ class MutationsController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
// Approve mutation (quantity_approved sudah diisi saat receive)
|
||||
// Approve mutation (stock will move automatically)
|
||||
$mutation->approve(auth()->id(), $request->approval_notes);
|
||||
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil disetujui');
|
||||
// Check user role and redirect accordingly
|
||||
if (!auth()->user()->dealer_id) {
|
||||
// Admin users redirect to mutations index
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil disetujui dan stock telah dipindahkan');
|
||||
} else {
|
||||
// Dealer users
|
||||
if ($request->has('from_transaction_page') || str_contains($request->header('referer', ''), '/transaction')) {
|
||||
return redirect()->route('transaction')
|
||||
->with('success', 'Mutasi berhasil disetujui dan stock telah dipindahkan')
|
||||
->with('active_tab', 'penerimaan');
|
||||
} else {
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil disetujui dan stock telah dipindahkan');
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return back()->withErrors(['error' => 'Gagal menyetujui mutasi: ' . $e->getMessage()]);
|
||||
@@ -226,30 +250,29 @@ class MutationsController extends Controller
|
||||
try {
|
||||
$mutation->reject(auth()->id(), $request->rejection_reason);
|
||||
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil ditolak');
|
||||
// Check user role and redirect accordingly
|
||||
if (!auth()->user()->dealer_id) {
|
||||
// Admin users redirect to mutations index
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil ditolak');
|
||||
} else {
|
||||
// Dealer users
|
||||
if ($request->has('from_transaction_page') || str_contains($request->header('referer', ''), '/transaction')) {
|
||||
return redirect()->route('transaction')
|
||||
->with('success', 'Mutasi berhasil ditolak')
|
||||
->with('active_tab', 'penerimaan');
|
||||
} else {
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil ditolak');
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return back()->withErrors(['error' => 'Gagal menolak mutasi: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function complete(Mutation $mutation)
|
||||
{
|
||||
if (!$mutation->canBeCompleted()) {
|
||||
return back()->withErrors(['error' => 'Mutasi tidak dapat diselesaikan dalam status saat ini']);
|
||||
}
|
||||
|
||||
try {
|
||||
$mutation->complete();
|
||||
|
||||
return redirect()->route('mutations.index')
|
||||
->with('success', 'Mutasi berhasil diselesaikan dan stock telah dipindahkan');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return back()->withErrors(['error' => 'Gagal menyelesaikan mutasi: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
// Complete method removed - Stock moves automatically after approval
|
||||
|
||||
public function cancel(Request $request, Mutation $mutation)
|
||||
{
|
||||
@@ -294,9 +317,20 @@ class MutationsController extends Controller
|
||||
{
|
||||
$dealerId = $request->dealer_id;
|
||||
|
||||
// Get mutations that need action from this dealer:
|
||||
// 1. 'sent' status where this dealer is the recipient (need to receive)
|
||||
// 2. 'received' status where this dealer is the recipient (need to approve) - CORRECTED LOGIC
|
||||
$data = Mutation::with(['fromDealer', 'toDealer', 'requestedBy.role'])
|
||||
->where('to_dealer_id', $dealerId)
|
||||
->where('status', 'sent')
|
||||
->where(function($query) use ($dealerId) {
|
||||
// Mutations sent to this dealer that need to be received
|
||||
$query->where('to_dealer_id', $dealerId)
|
||||
->where('status', 'sent');
|
||||
// OR mutations received by this dealer that need approval from recipient
|
||||
$query->orWhere(function($subQuery) use ($dealerId) {
|
||||
$subQuery->where('to_dealer_id', $dealerId)
|
||||
->where('status', 'received');
|
||||
});
|
||||
})
|
||||
->select('mutations.*');
|
||||
|
||||
return DataTables::of($data)
|
||||
@@ -307,6 +341,9 @@ class MutationsController extends Controller
|
||||
->addColumn('from_dealer', function($row) {
|
||||
return $row->fromDealer->name ?? '-';
|
||||
})
|
||||
->addColumn('to_dealer', function($row) {
|
||||
return $row->toDealer->name ?? '-';
|
||||
})
|
||||
->addColumn('status', function($row) {
|
||||
$statusColor = $row->status_color;
|
||||
$statusLabel = $row->status_label;
|
||||
@@ -330,10 +367,28 @@ class MutationsController extends Controller
|
||||
->addColumn('created_at', function($row) {
|
||||
return $row->created_at->format('d/m/Y H:i');
|
||||
})
|
||||
->addColumn('action', function($row) {
|
||||
return '<button type="button" class="btn btn-info btn-sm btn-detail" onclick="showMutationDetail('.$row->id.')">
|
||||
Detail
|
||||
</button>';
|
||||
->addColumn('action', function($row) use ($dealerId) {
|
||||
$buttons = '';
|
||||
|
||||
if ($row->status->value === 'sent' && $row->to_dealer_id == $dealerId) {
|
||||
// For sent mutations where current dealer is recipient - show detail button for receiving
|
||||
$buttons .= '<button type="button" class="btn btn-info btn-sm btn-detail" onclick="showMutationDetail('.$row->id.')">
|
||||
Detail & Terima
|
||||
</button>';
|
||||
} elseif ($row->status->value === 'received' && $row->to_dealer_id == $dealerId) {
|
||||
// For received mutations where current dealer is recipient - show approve/reject buttons
|
||||
$buttons .= '<button type="button" class="btn btn-info btn-sm btn-detail mr-1" onclick="showMutationDetail('.$row->id.')">
|
||||
Detail
|
||||
</button>';
|
||||
$buttons .= '<button type="button" class="btn btn-success btn-sm btn-approve-mutation mr-1" data-id="'.$row->id.'">
|
||||
Setujui
|
||||
</button>';
|
||||
$buttons .= '<button type="button" class="btn btn-danger btn-sm btn-reject-mutation" data-id="'.$row->id.'">
|
||||
Tolak
|
||||
</button>';
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
})
|
||||
->rawColumns(['status', 'action'])
|
||||
->make(true);
|
||||
|
||||
Reference in New Issue
Block a user