mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-06 19:19:29 +00:00
Update part merger to consider rows with same supplier and spn duplicates
This commit is contained in:
parent
a6be786d5d
commit
c27f2246a3
1 changed files with 32 additions and 32 deletions
|
|
@ -100,7 +100,8 @@ class PartMerger implements EntityMergerInterface
|
||||||
return $target;
|
return $target;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function comparePartAssociations(PartAssociation $t, PartAssociation $o): bool {
|
private function comparePartAssociations(PartAssociation $t, PartAssociation $o): bool
|
||||||
|
{
|
||||||
//We compare the translation keys, as it contains info about the type and other type info
|
//We compare the translation keys, as it contains info about the type and other type info
|
||||||
return $t->getOther() === $o->getOther()
|
return $t->getOther() === $o->getOther()
|
||||||
&& $t->getTypeTranslationKey() === $o->getTypeTranslationKey();
|
&& $t->getTypeTranslationKey() === $o->getTypeTranslationKey();
|
||||||
|
|
@ -141,40 +142,39 @@ class PartMerger implements EntityMergerInterface
|
||||||
$owner->addAssociatedPartsAsOwner($clone);
|
$owner->addAssociatedPartsAsOwner($clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge orderdetails, considering same supplier+part number as duplicates
|
||||||
$this->mergeCollections($target, $other, 'orderdetails', function (Orderdetail $t, Orderdetail $o) {
|
$this->mergeCollections($target, $other, 'orderdetails', function (Orderdetail $t, Orderdetail $o) {
|
||||||
//First check that the orderdetails infos are equal
|
// If supplier and part number match, merge the orderdetails
|
||||||
$tmp = $t->getSupplier() === $o->getSupplier()
|
if ($t->getSupplier() === $o->getSupplier() && $t->getSupplierPartNr() === $o->getSupplierPartNr()) {
|
||||||
&& $t->getSupplierPartNr() === $o->getSupplierPartNr()
|
// Update URL if target doesn't have one
|
||||||
&& $t->getSupplierProductUrl(false) === $o->getSupplierProductUrl(false);
|
if (empty($t->getSupplierProductUrl(false)) && !empty($o->getSupplierProductUrl(false))) {
|
||||||
|
$t->setSupplierProductUrl($o->getSupplierProductUrl(false));
|
||||||
if (!$tmp) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
// Merge price details: add new ones, update empty ones, keep existing non-empty ones
|
||||||
//Check if the pricedetails are equal
|
foreach ($o->getPricedetails() as $otherPrice) {
|
||||||
$t_pricedetails = $t->getPricedetails();
|
$found = false;
|
||||||
$o_pricedetails = $o->getPricedetails();
|
foreach ($t->getPricedetails() as $targetPrice) {
|
||||||
//Ensure that both pricedetails have the same length
|
if ($targetPrice->getMinDiscountQuantity() === $otherPrice->getMinDiscountQuantity()
|
||||||
if (count($t_pricedetails) !== count($o_pricedetails)) {
|
&& $targetPrice->getCurrency() === $otherPrice->getCurrency()) {
|
||||||
return false;
|
// Only update price if the existing one is zero/empty (most logical)
|
||||||
|
if ($targetPrice->getPrice()->isZero()) {
|
||||||
|
$targetPrice->setPrice($otherPrice->getPrice());
|
||||||
|
$targetPrice->setPriceRelatedQuantity($otherPrice->getPriceRelatedQuantity());
|
||||||
}
|
}
|
||||||
|
$found = true;
|
||||||
//Check if all pricedetails are equal
|
break;
|
||||||
for ($n=0, $nMax = count($t_pricedetails); $n< $nMax; $n++) {
|
|
||||||
$t_price = $t_pricedetails->get($n);
|
|
||||||
$o_price = $o_pricedetails->get($n);
|
|
||||||
|
|
||||||
if (!$t_price->getPrice()->isEqualTo($o_price->getPrice())
|
|
||||||
|| $t_price->getCurrency() !== $o_price->getCurrency()
|
|
||||||
|| $t_price->getPriceRelatedQuantity() !== $o_price->getPriceRelatedQuantity()
|
|
||||||
|| $t_price->getMinDiscountQuantity() !== $o_price->getMinDiscountQuantity()
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Add completely new price tiers
|
||||||
//If all pricedetails are equal, the orderdetails are equal
|
if (!$found) {
|
||||||
return true;
|
$clonedPrice = clone $otherPrice;
|
||||||
|
$clonedPrice->setOrderdetail($t);
|
||||||
|
$t->addPricedetail($clonedPrice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true; // Consider them equal so the other one gets skipped
|
||||||
|
}
|
||||||
|
return false; // Different supplier/part number, add as new
|
||||||
});
|
});
|
||||||
//The pricedetails are not correctly assigned to the new orderdetails, so fix that
|
//The pricedetails are not correctly assigned to the new orderdetails, so fix that
|
||||||
foreach ($target->getOrderdetails() as $orderdetail) {
|
foreach ($target->getOrderdetails() as $orderdetail) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue