netProfit = new Money(0); $this->grossProfit = new Money(0); $this->netCosts = new Money(0); $this->grossCosts = new Money(0); $this->netSales = new Money(0); $this->grossSales = new Money(0); $this->netDiscount = new Money(0); $this->grossDiscount = new Money(0); $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}', '{type}', ], [ $this->createdAt->format('Y'), $this->createdAt->format('m'), $this->createdAt->format('d'), $this->id, $this->type->getId(), ], $this->numberFormat ); } /** * Get Bill number. * * @return string * * @since 1.0.0 */ public function getNumber() : string { if (empty($this->number)) { $this->buildNumber(); } return $this->number; } /** * Add attribute to client * * @param BillAttribute $attribute Attribute * * @return void * * @since 1.0.0 */ public function addAttribute(BillAttribute $attribute) : void { $this->attributes[] = $attribute; } /** * Get attributes * * @return BillAttribute[] * * @since 1.0.0 */ public function getAttributes() : array { return $this->attributes; } /** * Get attribute * * @param string $attrName Attribute name * * @return null|BillAttribute * * @since 1.0.0 */ public function getAttribute(string $attrName) : ?BillAttribute { foreach ($this->attributes as $attribute) { if ($attribute->type->name === $attrName) { return $attribute->value; } } return null; } /** * 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; } /** * 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; } /** * Set language. * * @param string $language Language * * @return void * * @since 1.0.0 */ public function setLanguage(string $language) : void { $this->language = $language; } /** * Get language. * * @return string * * @since 1.0.0 */ public function getLanguage() : string { return $this->language; } /** * 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 array * * @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; } /** * Add note to item * * @param EditorDoc $note Note * * @return void * * @since 1.0.0 */ public function addNote(EditorDoc $note) : void { $this->notes[] = $note; } /** * Get notes * * @return EditorDoc[] * * @since 1.0.0 */ public function getNotes() : array { return $this->notes; } /** * Get all media * * @return Media[] * * @since 1.0.0 */ public function getMedia() : array { return $this->media; } /** * Add media * * @param Media $media Media to add * * @return void * * @since 1.0.0 */ public function addMedia(Media $media) : void { $this->media[] = $media; } /** * Get media file by type * * @param null|int $type Media type * * @return array * * @since 1.0.0 */ public function getMediaByType(int $type = null) : array { if ($type === null) { return $this->media; } $files = []; foreach ($this->media as $file) { if ($file->type !== null && $file->type->getId() === $type) { $files[] = $file; } } return $files; } /** * Get media file by type * * @param int $type Media type * * @return Media * * @since 1.0.0 */ public function getFileByType(int $type) : Media { foreach ($this->media as $file) { if ($file->hasMediaTypeId($type)) { return $file; } } return new NullMedia(); } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'number' => $this->number, 'numberFormat' => $this->numberFormat, '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(); } }