feat: enhance raw material creation by restoring trashed items and updating status
This commit is contained in:
parent
11557d0b85
commit
c14b32b5bb
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user