add backup file and autobackup code, partial update mutations receive on transation page
This commit is contained in:
@@ -288,4 +288,90 @@ class MutationsController extends Controller
|
||||
'current_stock' => $stock
|
||||
]);
|
||||
}
|
||||
|
||||
// API untuk mendapatkan mutasi yang perlu diterima oleh dealer
|
||||
public function getPendingMutations(Request $request)
|
||||
{
|
||||
$dealerId = $request->dealer_id;
|
||||
|
||||
$data = Mutation::with(['fromDealer', 'toDealer', 'requestedBy.role'])
|
||||
->where('to_dealer_id', $dealerId)
|
||||
->where('status', 'sent')
|
||||
->select('mutations.*');
|
||||
|
||||
return DataTables::of($data)
|
||||
->addIndexColumn()
|
||||
->addColumn('mutation_number', function($row) {
|
||||
return $row->mutation_number;
|
||||
})
|
||||
->addColumn('from_dealer', function($row) {
|
||||
return $row->fromDealer->name ?? '-';
|
||||
})
|
||||
->addColumn('status', function($row) {
|
||||
$statusColor = $row->status_color;
|
||||
$statusLabel = $row->status_label;
|
||||
|
||||
$textColorClass = match($statusColor) {
|
||||
'success' => 'text-success',
|
||||
'warning' => 'text-warning',
|
||||
'danger' => 'text-danger',
|
||||
'info' => 'text-info',
|
||||
'primary' => 'text-primary',
|
||||
'brand' => 'text-primary',
|
||||
'secondary' => 'text-muted',
|
||||
default => 'text-dark'
|
||||
};
|
||||
|
||||
return "<span class=\"font-weight-bold {$textColorClass}\">{$statusLabel}</span>";
|
||||
})
|
||||
->addColumn('total_items', function($row) {
|
||||
return number_format($row->total_items, 0);
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->rawColumns(['status', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
// API untuk mendapatkan detail mutasi
|
||||
public function getDetail(Mutation $mutation)
|
||||
{
|
||||
try {
|
||||
$mutation->load([
|
||||
'fromDealer',
|
||||
'toDealer',
|
||||
'requestedBy.role',
|
||||
'approvedBy.role',
|
||||
'receivedBy.role',
|
||||
'mutationDetails.product'
|
||||
]);
|
||||
|
||||
// Format created_at
|
||||
$mutation->created_at_formatted = $mutation->created_at->format('d/m/Y H:i');
|
||||
|
||||
// Add status color and label
|
||||
$mutation->status_color = $mutation->status_color;
|
||||
$mutation->status_label = $mutation->status_label;
|
||||
|
||||
// Check if can be received
|
||||
$mutation->can_be_received = $mutation->canBeReceived();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $mutation
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal memuat detail mutasi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user