feat: enhance raw material creation by restoring trashed items and updating status
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (8.3) (push) Waiting to run
tests / ci (8.4) (push) Waiting to run
tests / ci (8.5) (push) Waiting to run

This commit is contained in:
Yoga Pangestu 2026-07-31 01:13:04 +07:00
parent 11557d0b85
commit c14b32b5bb

View File

@ -287,11 +287,25 @@ public function createRawMaterialAndDraft(array $validated, User $user): array
{
$data = $this->runInTransaction(
function () use ($validated, $user): array {
$rawMaterial = RawMaterial::create([
'name' => $validated['name'],
'unit' => $validated['unit'],
'is_active' => true,
]);
$rawMaterial = RawMaterial::withTrashed()
->where('name', $validated['name'])
->where('unit', $validated['unit'])
->first();
if ($rawMaterial) {
if ($rawMaterial->trashed()) {
$rawMaterial->restore();
}
if (! $rawMaterial->is_active) {
$rawMaterial->update(['is_active' => true]);
}
} else {
$rawMaterial = RawMaterial::create([
'name' => $validated['name'],
'unit' => $validated['unit'],
'is_active' => true,
]);
}
$price = RawMaterialPrice::create([
'raw_material_id' => $rawMaterial->id,