netProfit = new FloatInt(0); $this->grossProfit = new FloatInt(0); $this->netCosts = new FloatInt(0); $this->grossCosts = new FloatInt(0); $this->netSales = new FloatInt(0); $this->grossSales = new FloatInt(0); $this->netDiscount = new FloatInt(0); $this->grossDiscount = new FloatInt(0); $this->billDate = new \DateTime('now'); $this->createdAt = new \DateTimeImmutable(); $this->createdBy = new NullAccount(); $this->referral = new NullAccount(); $this->type = new NullBillType(); } /** * Get id. * * @return int Model id * * @since 1.0.0 */ public function getId() : int { return $this->id; } /** * Build the invoice number. * * @return void * * @since 1.0.0 */ public function buildNumber() : void { $this->number = \str_replace( [ '{y}', '{m}', '{d}', '{id}', '{sequence}', '{type}', ], [ $this->createdAt->format('Y'), $this->createdAt->format('m'), $this->createdAt->format('d'), $this->id, $this->sequence, $this->type->id, ], $this->type->numberFormat ); } /** * Get Bill number. * * @return string * * @since 1.0.0 */ public function getNumber() : string { if (empty($this->number)) { $this->buildNumber(); } return $this->number; } /** * Get status * * @return int * * @since 1.0.0 */ public function getStatus() : int { return $this->status; } /** * Set status * * @param int $status Status * * @return void * * @since 1.0.0 */ public function setStatus(int $status) : void { $this->status = $status; } /** * Get paymentStatus * * @return int * * @since 1.0.0 */ public function getPaymentStatus() : int { return $this->paymentStatus; } /** * Set paymentStatus * * @param int $paymentStatus Status * * @return void * * @since 1.0.0 */ public function setPaymentStatus(int $paymentStatus) : void { $this->paymentStatus = $paymentStatus; } /** * Set currency. * * @param string $currency Currency * * @return void * * @since 1.0.0 */ public function setCurrency(string $currency) : void { $this->currency = $currency; } /** * Get currency. * * @return string * * @since 1.0.0 */ public function getCurrency() : string { return $this->currency; } /** * Get vouchers. * * @return array * * @since 1.0.0 */ public function getVouchers() : array { return $this->vouchers; } /** * Add voucher. * * @param string $voucher Voucher code * * @return void * * @since 1.0.0 */ public function addVoucher(string $voucher) : void { $this->vouchers[] = $voucher; } /** * Get tracking ids for shipment. * * @return array * * @since 1.0.0 */ public function getTrackings() : array { return $this->trackings; } /** * Add tracking id. * * @param string $tracking Tracking id * * @return void * * @since 1.0.0 */ public function addTracking(string $tracking) : void { $this->trackings[] = $tracking; } /** * Get Bill elements. * * @return BillElement[] * * @since 1.0.0 */ public function getElements() : array { return $this->elements; } /** * Add Bill element. * * @param BillElement $element Bill element * * @return void * * @since 1.0.0 */ public function addElement(BillElement $element) : void { $this->elements[] = $element; $this->netProfit->add($element->totalProfitNet->getInt()); $this->grossProfit->add($element->totalProfitGross->getInt()); $this->netCosts->add($element->totalPurchasePriceNet->getInt()); $this->grossCosts->add($element->totalPurchasePriceGross->getInt()); $this->netSales->add($element->totalSalesPriceNet->getInt()); $this->grossSales->add($element->totalSalesPriceGross->getInt()); $this->netDiscount->add($element->totalDiscountP->getInt()); // @todo: Discount might be in quantities $this->grossDiscount->add((int) ($element->taxR->getInt() * $element->totalDiscountP->getInt() / 10000)); } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'number' => $this->number, 'type' => $this->type, 'shipTo' => $this->shipTo, 'shipFAO' => $this->shipFAO, 'shipAddress' => $this->shipAddress, 'shipCity' => $this->shipCity, 'shipZip' => $this->shipZip, 'shipCountry' => $this->shipCountry, 'billTo' => $this->billTo, 'billFAO' => $this->billFAO, 'billAddress' => $this->billAddress, 'billCity' => $this->billCity, 'billZip' => $this->billZip, 'billCountry' => $this->billCountry, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } use \Modules\Attribute\Models\AttributeHolderTrait; use \Modules\Editor\Models\EditorDocListTrait; use \Modules\Media\Models\MediaListTrait; }