remove status pending and complete
This commit is contained in:
@@ -116,11 +116,6 @@ class Mutation extends Model
|
||||
return $this->mutationDetails()->sum('quantity_approved');
|
||||
}
|
||||
|
||||
public function canBeSent()
|
||||
{
|
||||
return $this->status === MutationStatus::PENDING;
|
||||
}
|
||||
|
||||
public function canBeReceived()
|
||||
{
|
||||
return $this->status === MutationStatus::SENT;
|
||||
@@ -131,28 +126,9 @@ class Mutation extends Model
|
||||
return $this->status === MutationStatus::RECEIVED;
|
||||
}
|
||||
|
||||
public function canBeCompleted()
|
||||
{
|
||||
return $this->status === MutationStatus::APPROVED;
|
||||
}
|
||||
|
||||
public function canBeCancelled()
|
||||
{
|
||||
return in_array($this->status, [MutationStatus::PENDING, MutationStatus::SENT]);
|
||||
}
|
||||
|
||||
// Send mutation to destination dealer
|
||||
public function send($userId)
|
||||
{
|
||||
if (!$this->canBeSent()) {
|
||||
throw new \Exception('Mutasi tidak dapat dikirim dalam status saat ini');
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'status' => MutationStatus::SENT
|
||||
]);
|
||||
|
||||
return $this;
|
||||
return $this->status === MutationStatus::SENT;
|
||||
}
|
||||
|
||||
// Receive mutation by destination dealer
|
||||
@@ -172,19 +148,37 @@ class Mutation extends Model
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Approve mutation
|
||||
// Approve mutation and move stock immediately
|
||||
public function approve($userId, $approvalNotes = null)
|
||||
{
|
||||
if (!$this->canBeApproved()) {
|
||||
throw new \Exception('Mutasi tidak dapat disetujui dalam status saat ini');
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'status' => MutationStatus::APPROVED,
|
||||
'approved_by' => $userId,
|
||||
'approved_at' => now(),
|
||||
'approval_notes' => $approvalNotes
|
||||
]);
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
// Update status to approved first
|
||||
$this->update([
|
||||
'status' => MutationStatus::APPROVED,
|
||||
'approved_by' => $userId,
|
||||
'approved_at' => now(),
|
||||
'approval_notes' => $approvalNotes
|
||||
]);
|
||||
|
||||
// Immediately move stock after approval
|
||||
foreach ($this->mutationDetails as $detail) {
|
||||
// Process all details that have quantity_requested > 0
|
||||
// because goods have been sent from source dealer
|
||||
if ($detail->quantity_requested > 0) {
|
||||
$this->processStockMovement($detail);
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -223,32 +217,7 @@ class Mutation extends Model
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Complete mutation (actually move the stock)
|
||||
public function complete()
|
||||
{
|
||||
if (!$this->canBeCompleted()) {
|
||||
throw new \Exception('Mutasi tidak dapat diselesaikan dalam status saat ini');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($this->mutationDetails as $detail) {
|
||||
// Proses semua detail yang memiliki quantity_requested > 0
|
||||
// karena barang sudah dikirim dari dealer asal
|
||||
if ($detail->quantity_requested > 0) {
|
||||
$this->processStockMovement($detail);
|
||||
}
|
||||
}
|
||||
|
||||
$this->update(['status' => MutationStatus::COMPLETED]);
|
||||
DB::commit();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
// Complete method removed - Stock moves automatically after approval
|
||||
|
||||
private function processStockMovement(MutationDetail $detail)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user