Make quick sale products on machines as orders paid when ready
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Sales\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Inventory\Application\DTOs\StockUseData;
|
||||
use App\Modules\Inventory\Application\UseCases\RecordStockUse;
|
||||
use App\Modules\Inventory\Application\UseCases\RecordStockWriteOff;
|
||||
use App\Modules\Inventory\Domain\ValueObjects\StockQuantity;
|
||||
use App\Modules\Sales\Application\Contracts\OrderMaterials;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
/**
|
||||
* Stock used in making quick sale orders, through the Inventory module.
|
||||
* Reasons are stored in Finnish, like the rest of the business records.
|
||||
*/
|
||||
class StockForOrders implements OrderMaterials
|
||||
{
|
||||
public function __construct(
|
||||
private RecordStockUse $recordUse,
|
||||
private RecordStockWriteOff $recordWriteOff,
|
||||
) {}
|
||||
|
||||
public function use(int $stockItemId, int $quantityMilli, int $orderLineId, ?int $machineId, int $userId): bool
|
||||
{
|
||||
try {
|
||||
$this->recordUse->execute(new StockUseData($stockItemId, StockQuantity::inputValue($quantityMilli), machineId: $machineId, orderLineId: $orderLineId), $userId);
|
||||
} catch (DomainException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function writeOff(int $stockItemId, int $quantityMilli, int $orderLineId, ?int $machineId, int $userId, string $reason): bool
|
||||
{
|
||||
try {
|
||||
$this->recordWriteOff->execute(new StockUseData(
|
||||
$stockItemId,
|
||||
StockQuantity::inputValue($quantityMilli),
|
||||
machineId: $machineId,
|
||||
orderLineId: $orderLineId,
|
||||
reason: __('sales.orders.reasons.'.$reason, [], 'fi'),
|
||||
), $userId);
|
||||
} catch (DomainException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user