mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-11 01:39:37 +00:00
Allow to pass infos from barcodes to creation dialog
This commit is contained in:
parent
a722608ae8
commit
70919d953a
3 changed files with 47 additions and 20 deletions
|
|
@ -290,6 +290,20 @@ final class PartController extends AbstractController
|
||||||
$this->addFlash('warning', t("part.create_from_info_provider.no_category_yet"));
|
$this->addFlash('warning', t("part.create_from_info_provider.no_category_yet"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lotAmount = $request->query->get('lotAmount');
|
||||||
|
$lotName = $request->query->get('lotName');
|
||||||
|
$lotUserBarcode = $request->query->get('lotUserBarcode');
|
||||||
|
|
||||||
|
if ($lotAmount !== null || $lotName !== null || $lotUserBarcode !== null) {
|
||||||
|
$partLot = new PartLot();
|
||||||
|
$partLot->setAmount($lotAmount !== null ? (float)$lotAmount : 0);
|
||||||
|
$partLot->setDescription($lotName !== null ? (string)$lotName : '');
|
||||||
|
$partLot->setUserBarcode($lotUserBarcode !== null ? (string)$lotUserBarcode : '');
|
||||||
|
|
||||||
|
$new_part->addPartLot($partLot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->renderPartForm('new', $request, $new_part, [
|
return $this->renderPartForm('new', $request, $new_part, [
|
||||||
'info_provider_dto' => $dto,
|
'info_provider_dto' => $dto,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,8 @@ final readonly class BarcodeScanResultHandler
|
||||||
throw InfoProviderNotActiveException::fromProvider($provider);
|
throw InfoProviderNotActiveException::fromProvider($provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->urlGenerator->generate('info_providers_create_part', ['providerKey' => $infos['providerKey'], 'providerId' => $infos['providerId']]);
|
//So far we can just copy over our provider info array to the URL parameters:
|
||||||
|
return $this->urlGenerator->generate('info_providers_create_part', $infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -146,7 +147,7 @@ final readonly class BarcodeScanResultHandler
|
||||||
|
|
||||||
if ($barcodeScan instanceof AmazonBarcodeScanResult) {
|
if ($barcodeScan instanceof AmazonBarcodeScanResult) {
|
||||||
return $this->em->getRepository(Part::class)->getPartByProviderInfo($barcodeScan->asin)
|
return $this->em->getRepository(Part::class)->getPartByProviderInfo($barcodeScan->asin)
|
||||||
?? $this->em->getRepository(Part::class)->getPartBySPN($barcodeScan->asin);
|
?? $this->em->getRepository(Part::class)->getPartBySPN($barcodeScan->asin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -246,7 +247,7 @@ final readonly class BarcodeScanResultHandler
|
||||||
* Returns null if no provider information could be extracted from the scan result, or if the scan result type is unknown and cannot be handled by this function.
|
* Returns null if no provider information could be extracted from the scan result, or if the scan result type is unknown and cannot be handled by this function.
|
||||||
* It is not necessarily checked that the provider is active, or that the result actually exists on the provider side.
|
* It is not necessarily checked that the provider is active, or that the result actually exists on the provider side.
|
||||||
* @param BarcodeScanResultInterface $scanResult
|
* @param BarcodeScanResultInterface $scanResult
|
||||||
* @return array{providerKey: string, providerId: string}|null
|
* @return array{providerKey: string, providerId: string, lotAmount?: float|int, lotName?: string, lotUserBarcode?: string}|null
|
||||||
* @throws InfoProviderNotActiveException If the scan result contains information for a provider which is currently not active in the system
|
* @throws InfoProviderNotActiveException If the scan result contains information for a provider which is currently not active in the system
|
||||||
*/
|
*/
|
||||||
public function getCreateInfos(BarcodeScanResultInterface $scanResult): ?array
|
public function getCreateInfos(BarcodeScanResultInterface $scanResult): ?array
|
||||||
|
|
@ -256,6 +257,9 @@ final readonly class BarcodeScanResultHandler
|
||||||
return [
|
return [
|
||||||
'providerKey' => 'lcsc',
|
'providerKey' => 'lcsc',
|
||||||
'providerId' => $scanResult->lcscCode,
|
'providerId' => $scanResult->lcscCode,
|
||||||
|
'lotAmount' => $scanResult->quantity,
|
||||||
|
'lotName' => $scanResult->orderNumber ?? $scanResult->pickBatchNumber,
|
||||||
|
'lotUserBarcode' => $scanResult->rawInput,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,7 +280,7 @@ final readonly class BarcodeScanResultHandler
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param EIGP114BarcodeScanResult $scanResult
|
* @param EIGP114BarcodeScanResult $scanResult
|
||||||
* @return array{providerKey: string, providerId: string}|null
|
* * @return array{providerKey: string, providerId: string, lotAmount?: float|int, lotName?: string, lotUserBarcode?: string}|null
|
||||||
*/
|
*/
|
||||||
private function getCreationInfoForEIGP114(EIGP114BarcodeScanResult $scanResult): ?array
|
private function getCreationInfoForEIGP114(EIGP114BarcodeScanResult $scanResult): ?array
|
||||||
{
|
{
|
||||||
|
|
@ -285,23 +289,26 @@ final readonly class BarcodeScanResultHandler
|
||||||
// Mouser: use supplierPartNumber -> search provider -> provider_id
|
// Mouser: use supplierPartNumber -> search provider -> provider_id
|
||||||
if ($vendor === 'mouser' && $scanResult->supplierPartNumber !== null
|
if ($vendor === 'mouser' && $scanResult->supplierPartNumber !== null
|
||||||
) {
|
) {
|
||||||
// Search Mouser using the MPN
|
// Search Mouser using the MPN
|
||||||
$dtos = $this->infoRetriever->searchByKeyword(
|
$dtos = $this->infoRetriever->searchByKeyword(
|
||||||
keyword: $scanResult->supplierPartNumber,
|
keyword: $scanResult->supplierPartNumber,
|
||||||
providers: ["mouser"]
|
providers: ["mouser"]
|
||||||
);
|
);
|
||||||
|
|
||||||
// If there are results, provider_id is MouserPartNumber (per MouserProvider.php)
|
// If there are results, provider_id is MouserPartNumber (per MouserProvider.php)
|
||||||
$best = $dtos[0] ?? null;
|
$best = $dtos[0] ?? null;
|
||||||
|
|
||||||
if ($best !== null) {
|
if ($best !== null) {
|
||||||
return [
|
return [
|
||||||
'providerKey' => 'mouser',
|
'providerKey' => 'mouser',
|
||||||
'providerId' => $best->provider_id,
|
'providerId' => $best->provider_id,
|
||||||
];
|
'lotAmount' => $scanResult->quantity,
|
||||||
}
|
'lotName' => $scanResult->customerPO,
|
||||||
|
'lotUserBarcode' => $scanResult->rawInput,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digi-Key: supplierPartNumber directly
|
// Digi-Key: supplierPartNumber directly
|
||||||
|
|
@ -309,6 +316,9 @@ final readonly class BarcodeScanResultHandler
|
||||||
return [
|
return [
|
||||||
'providerKey' => 'digikey',
|
'providerKey' => 'digikey',
|
||||||
'providerId' => $scanResult->supplierPartNumber ?? throw new \RuntimeException('Digikey barcode does not contain required supplier part number'),
|
'providerId' => $scanResult->supplierPartNumber ?? throw new \RuntimeException('Digikey barcode does not contain required supplier part number'),
|
||||||
|
'lotAmount' => $scanResult->quantity,
|
||||||
|
'lotName' => $scanResult->digikeyInvoiceNumber ?? $scanResult->digikeySalesOrderNumber ?? $scanResult->customerPO,
|
||||||
|
'lotUserBarcode' => $scanResult->rawInput,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,6 +327,9 @@ final readonly class BarcodeScanResultHandler
|
||||||
return [
|
return [
|
||||||
'providerKey' => 'element14',
|
'providerKey' => 'element14',
|
||||||
'providerId' => $scanResult->supplierPartNumber ?? throw new \RuntimeException('Element14 barcode does not contain required supplier part number'),
|
'providerId' => $scanResult->supplierPartNumber ?? throw new \RuntimeException('Element14 barcode does not contain required supplier part number'),
|
||||||
|
'lotAmount' => $scanResult->quantity,
|
||||||
|
'lotName' => $scanResult->customerPO,
|
||||||
|
'lotUserBarcode' => $scanResult->rawInput,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ readonly class EIGP114BarcodeScanResult implements BarcodeScanResultInterface
|
||||||
*
|
*
|
||||||
* @param array<string, string> $data The fields of the EIGP114 barcode, where the key is the field name and the value is the field content
|
* @param array<string, string> $data The fields of the EIGP114 barcode, where the key is the field name and the value is the field content
|
||||||
*/
|
*/
|
||||||
public function __construct(public array $data)
|
public function __construct(public array $data, public readonly ?string $rawInput = null)
|
||||||
{
|
{
|
||||||
//IDs per EIGP 114.2018
|
//IDs per EIGP 114.2018
|
||||||
$this->shipDate = $data['6D'] ?? null;
|
$this->shipDate = $data['6D'] ?? null;
|
||||||
|
|
@ -306,7 +306,7 @@ readonly class EIGP114BarcodeScanResult implements BarcodeScanResultInterface
|
||||||
$results[$key] = $fieldValue;
|
$results[$key] = $fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new self($results);
|
return new self($results, $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDecodedForInfoMode(): array
|
public function getDecodedForInfoMode(): array
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue