mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-22 01:49:05 +02:00
Withdraw selected part lots, when building
This commit is contained in:
parent
31a20d0692
commit
616533ea4a
6 changed files with 79 additions and 3 deletions
|
@ -22,9 +22,17 @@ namespace App\Services\ProjectSystem;
|
|||
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\ProjectSystem\ProjectBOMEntry;
|
||||
use App\Helpers\Projects\ProjectBuildRequest;
|
||||
use App\Services\Parts\PartLotWithdrawAddHelper;
|
||||
|
||||
class ProjectBuildHelper
|
||||
{
|
||||
private PartLotWithdrawAddHelper $withdraw_add_helper;
|
||||
|
||||
public function __construct(PartLotWithdrawAddHelper $withdraw_add_helper)
|
||||
{
|
||||
$this->withdraw_add_helper = $withdraw_add_helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum buildable amount of the given BOM entry based on the stock of the used parts.
|
||||
|
@ -125,4 +133,26 @@ class ProjectBuildHelper
|
|||
|
||||
return $non_buildable_entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraw the parts from the stock using the given ProjectBuildRequest.
|
||||
* The ProjectBuildRequest has to be validated before!!
|
||||
* You have to flush changes to DB afterwards
|
||||
* @param ProjectBuildRequest $buildRequest
|
||||
* @return void
|
||||
*/
|
||||
public function doWithdrawForProjectBuildRequest(ProjectBuildRequest $buildRequest): void
|
||||
{
|
||||
$message = $buildRequest->getComment();
|
||||
$message .= ' (Project build: '.$buildRequest->getProject()->getName().')';
|
||||
|
||||
foreach ($buildRequest->getBomEntries() as $bom_entry) {
|
||||
foreach ($buildRequest->getPartLotsForBOMEntry($bom_entry) as $part_lot) {
|
||||
$amount = $buildRequest->getLotWithdrawAmount($part_lot);
|
||||
if ($amount > 0) {
|
||||
$this->withdraw_add_helper->withdraw($part_lot, $amount, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue