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(
|
$data = $this->runInTransaction(
|
||||||
function () use ($validated, $user): array {
|
function () use ($validated, $user): array {
|
||||||
$rawMaterial = RawMaterial::create([
|
$rawMaterial = RawMaterial::withTrashed()
|
||||||
'name' => $validated['name'],
|
->where('name', $validated['name'])
|
||||||
'unit' => $validated['unit'],
|
->where('unit', $validated['unit'])
|
||||||
'is_active' => true,
|
->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([
|
$price = RawMaterialPrice::create([
|
||||||
'raw_material_id' => $rawMaterial->id,
|
'raw_material_id' => $rawMaterial->id,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user