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->taxP = new FloatInt(0); $this->billDate = new \DateTime('now'); $this->createdAt = new \DateTimeImmutable(); $this->createdBy = new NullAccount(); $this->referral = new NullAccount(); $this->type = new NullBillType(); } /** * Build the invoice number. * * @return void * * @since 1.0.0 */ public function buildNumber() : void { $this->number = \str_replace( [ '{y}', '{m}', '{d}', '{id}', '{sequence}', '{type}', '{unit}', '{account}', '{country}', ], [ $this->createdAt->format('Y'), $this->createdAt->format('m'), $this->createdAt->format('d'), $this->id, $this->sequence, $this->type->id, $this->unit, $this->accountNumber, $this->billCountry, ], $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 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; } /** * 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->value += $element->totalProfitNet->value; $this->grossProfit->value += $element->totalProfitGross->value; $this->netCosts->value += $element->totalPurchasePriceNet->value; $this->grossCosts->value += $element->totalPurchasePriceGross->value; $this->netSales->value += $element->totalSalesPriceNet->value; $this->grossSales->value += $element->totalSalesPriceGross->value; $this->netDiscount->value += $element->totalDiscountP->value; // @todo Discount might be in quantities $this->grossDiscount->value += (int) ($element->taxR->value * $element->totalDiscountP->value / 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; }