singleListPriceNet = new Money(); $this->singleListPriceGross = new Money(); $this->totalListPriceNet = new Money(); $this->totalListPriceGross = new Money(); $this->singleSalesPriceNet = new Money(); $this->singleSalesPriceGross = new Money(); $this->totalSalesPriceNet = new Money(); $this->totalSalesPriceGross = new Money(); $this->singlePurchasePriceNet = new Money(); $this->singlePurchasePriceGross = new Money(); $this->totalPurchasePriceNet = new Money(); $this->totalPurchasePriceGross = new Money(); $this->singleProfitNet = new Money(); $this->singleProfitGross = new Money(); $this->totalProfitNet = new Money(); $this->totalProfitGross = new Money(); $this->singleDiscountP = new Money(); $this->totalDiscountP = new Money(); $this->taxP = new Money(); $this->taxR = new FloatInt(); } /** * Get id. * * @return int Model id * * @since 1.0.0 */ public function getId() : int { return $this->id; } public function setQuantity(int $quantity) : void { if ($this->quantity === $quantity) { return; } $this->quantity = $quantity; // @todo: recalculate all the prices!!! } public function getQuantity() : int { return $this->quantity; } /** * Set item. * * @param int $item Item * * @return void * * @since 1.0.0 */ public function setItem(int $item) : void { $this->item = $item; } public static function fromItem(Item $item, TaxCode $code, int $quantity = 1) : self { $element = new self(); $element->item = $item->getId(); $element->itemNumber = $item->number; $element->itemName = $item->getL11n('name1')->description; $element->itemDescription = $item->getL11n('description_short')->description; $element->quantity = $quantity; // @todo: Use pricing instead of the default sales price // @todo: discounts might be in quantities $element->singleListPriceNet->setInt($item->salesPrice->getInt()); $element->totalListPriceNet->setInt($element->quantity * $item->salesPrice->getInt()); $element->singleSalesPriceNet->setInt($item->salesPrice->getInt()); $element->totalSalesPriceNet->setInt($element->quantity * $item->salesPrice->getInt()); $element->singlePurchasePriceNet->setInt($item->purchasePrice->getInt()); $element->totalPurchasePriceNet->setInt($element->quantity * $item->purchasePrice->getInt()); $element->singleProfitNet->setInt($element->singleSalesPriceNet->getInt() - $element->singlePurchasePriceNet->getInt()); $element->totalProfitNet->setInt($element->quantity * ($element->totalSalesPriceNet->getInt() - $element->totalPurchasePriceNet->getInt())); $element->taxP = new FloatInt((int) (($code->percentageInvoice * $element->totalSalesPriceNet->getInt()) / 10000)); $element->taxR = new FloatInt($code->percentageInvoice); $element->taxCode = $code->abbr; $element->singleListPriceGross->setInt((int) ($element->singleListPriceNet->getInt() + $element->singleListPriceNet->getInt() * $element->taxR->getInt() / 10000)); $element->totalListPriceGross->setInt((int) ($element->totalListPriceNet->getInt() + $element->totalListPriceNet->getInt() * $element->taxR->getInt() / 10000)); $element->singleSalesPriceGross->setInt((int) ($element->singleSalesPriceNet->getInt() + $element->singleSalesPriceNet->getInt() * $element->taxR->getInt() / 10000)); $element->totalSalesPriceGross->setInt((int) ($element->totalSalesPriceNet->getInt() + $element->totalSalesPriceNet->getInt() * $element->taxR->getInt() / 10000)); $element->singlePurchasePriceGross->setInt((int) ($element->singlePurchasePriceNet->getInt() + $element->singlePurchasePriceNet->getInt() * $element->taxR->getInt() / 10000)); $element->totalPurchasePriceGross->setInt((int) ($element->totalPurchasePriceNet->getInt() + $element->totalPurchasePriceNet->getInt() * $element->taxR->getInt() / 10000)); $element->singleProfitGross->setInt($element->singleSalesPriceGross->getInt() - $element->singlePurchasePriceGross->getInt()); $element->totalProfitGross->setInt($element->quantity * ($element->totalSalesPriceGross->getInt() - $element->totalPurchasePriceGross->getInt())); return $element; } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'order' => $this->order, 'item' => $this->item, 'itemNumber' => $this->itemNumber, 'itemName' => $this->itemName, 'itemDescription' => $this->itemDescription, 'quantity' => $this->quantity, 'bill' => $this->bill, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } }