26 foreach ($this->elementBatchTree as
$entity)
28 $currentCondition = $this->getStoreCondition(
$entity);
29 $element =
$entity->getElement();
30 $batch = $currentCondition->getStoreBatch();
31 if (
$entity->isArrivalElement())
33 $availableStoreStoke = $batch->getAvailableAmount() + $element->getAmount();
34 if (empty($batch->getPurchasingCurrency()))
36 $batch->setPurchasingCurrency($element->getBatchCurrency());
39 $documentPrice = $element->getBatchPrice();
41 !empty($batch->getPurchasingCurrency())
42 && $element->getBatchCurrency() !== $batch->getPurchasingCurrency()
43 && Loader::includeModule(
'currency')
48 $element->getBatchCurrency(),
49 $batch->getPurchasingCurrency()
53 $newPrice = (($batch->getAvailableAmount() * $batch->getPurchasingPrice()) + ($element->getAmount() * $documentPrice)) / $availableStoreStoke;
54 $batch->setAvailableAmount($availableStoreStoke);
55 $batch->setPurchasingPrice($newPrice);
58 if (!empty($negativeStoreItem))
61 foreach ($negativeStoreItem->getIterator() as
$key => $negativeItem)
63 if ($batch->getAvailableAmount() <= 0)
68 $currentStock = $batch->getAvailableAmount() - $negativeItem->getAmount();
70 $newBindingElement =
$entity->getElement();
71 if ($currentStock >= 0)
73 $newBindingElement->setBatchPrice($batch->getPurchasingPrice());
74 $newBindingElement->setBatchCurrency($batch->getPurchasingCurrency());
75 $batch->setAvailableAmount($currentStock);
77 unset($negativeStoreItem[
$key]);
81 $newBindingElement->setBatchPrice($batch->getPurchasingPrice());
82 $newBindingElement->setBatchCurrency($batch->getPurchasingCurrency());
83 $newBindingElement->setAmount($batch->getAvailableAmount());
86 $negativeItem->getElement()->setAmount(-$currentStock);
87 $batch->setAvailableAmount(0);
94 $currentStock = $batch->getAvailableAmount() -
$entity->getAmount();
95 if ($batch->getAvailableAmount() <= 0)
99 elseif ($currentStock >= 0)
101 $element->setBatchPrice($batch->getPurchasingPrice());
102 $element->setBatchCurrency($batch->getPurchasingCurrency());
107 $negativeItem = clone(
$entity);
108 $element->setBatchPrice($batch->getPurchasingPrice());
109 $element->setBatchCurrency($batch->getPurchasingCurrency());
110 $element->setAmount(-$batch->getAvailableAmount());
113 $negativeItem->getElement()->setAmount(-$currentStock);
114 $negativeStoreItem->push($negativeItem);
116 $batch->setAvailableAmount(0);
122 foreach ($this->storeConditions as $item)
124 if ($item->getStoreBatch()->hasId())
127 'filter' => [
'=PRODUCT_BATCH_ID' => $item->getStoreBatch()->getId()],
131 while ($binding = $oldBindings->fetch())
145 foreach ($sortedItems as $item)
148 $storeItem = $this->storeConditions[$item->getStoreId()];
149 if (!empty($storeItem) && $storeItem->getStoreBatch())
151 $item->getElement()->setProductBatchId($storeItem->getStoreBatch()->getId());
169 if (isset($this->storeConditions[
$entity->getStoreId()]))
171 return $this->storeConditions[
$entity->getStoreId()];
174 $batch = $this->loadBatch(
$entity->getStoreId());
175 $batch->setAvailableAmount(0);
176 $batch->setPurchasingPrice(0);
181 $this->storeConditions[
$entity->getStoreId()] = $newStoreItem;
183 return $this->storeConditions[
$entity->getStoreId()];
190 '=STORE_ID' => $storeId,
191 '=ELEMENT_ID' => $this->balancer->getProductId(),
205 $newBatch->setStoreId($storeId);
206 $newBatch->setElementId($this->balancer->getProductId());
207 $newBatch->setPurchasingPrice(0);
static getList(array $parameters=array())
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)