increment('stock_quantity', $signedQty); // Calculate total cost if unit cost is provided $totalCost = $unitCost !== null ? $unitCost * $quantity : null; // Record in stocks table Stock::create([ 'restaurant_id' => $restaurantId ?? $ingredient->restaurant_id ?? null, 'ingredient_id' => $ingredientId, 'type' => $type, 'quantity' => $quantity, 'unit_cost' => $unitCost, 'total_cost' => $totalCost, 'reference_type' => $refType, 'purchase_id' => $refId, 'batch_no' => $batchNo, 'expiry_date' => $expiryDate, 'added_by' => $addedBy ?? Auth::id(), 'remarks' => ucfirst($type).' stock movement', ]); } }