2 namespace Stock\Entity;
4 use Doctrine\ORM\Mapping as ORM;
12 * @ORM\HasLifecycleCallbacks
13 * @ORM\Table(name="stock")
19 * Can archive records.
23 * Pull Synchronization Strategy for this table.
25 const PULL_SYNCH_STRATEGY = false;
27 * Push Synchronization Strategy for this table.
29 const PUSH_SYNCH_STRATEGY = false;
31 * Post insert action must be called after new entity is flushed to database.
33 const HAVE_POST_INSERT = true;
37 /* ------------------------------------ Identification ------------------------------------ */
40 * @ORM\Column(type="integer");
41 * @ORM\GeneratedValue(strategy="AUTO")
46 * @ORM\Column(type="string", length=40);
51 /* ------------------------------------ Ownership ------------------------------------ */
53 * @ORM\ManyToOne(targetEntity="\Company\Entity\Company")
54 * @ORM\JoinColumn(nullable=false, name="company_id")
59 * @ORM\ManyToOne(targetEntity="\User\Entity\Profile")
60 * @ORM\JoinColumn(nullable=false, name="created_by_profile_id")
65 * @ORM\ManyToOne(targetEntity="\Valuation\Entity\Valuation", cascade={"all"})
66 * @ORM\JoinColumn(nullable=true, name="stock_valuation_id")
71 * @ORM\ManyToOne(targetEntity="\PriceGuide\Entity\PriceGuide")
72 * @ORM\JoinColumn(nullable=true, name="price_guide_id")
74 protected $priceGuide;
77 * @ORM\ManyToOne(targetEntity="\Auction\Entity\Auction")
78 * @ORM\JoinColumn(nullable=true, name="auction_id")
83 /* ------------------------------------ General vehicle details ------------------------------------ */
85 * @ORM\ManyToOne(targetEntity="\Location\Entity\Region")
86 * @ORM\JoinColumn(nullable=true, name="lib_region_id")
91 * @ORM\ManyToOne(targetEntity="Type")
92 * @ORM\JoinColumn(nullable=true, name="vehicle_type_id")
97 * @ORM\Column(type="string", length=12, nullable=true, name="reference_no")
99 protected $referenceNumber;
102 * @ORM\Column(type="string", length=20, nullable=true, name="stock_no")
104 protected $stockNumber;
107 * @ORM\Column(type="string", length=15, nullable=true, name="registration_number")
109 protected $registrationNumber;
112 * @ORM\Column(type="string", length=40, nullable=true, name="vin_number")
114 protected $vinNumber;
117 * @ORM\Column(type="string", length=40, nullable=true, name="engine_number")
119 protected $engineNumber;
122 * @ORM\ManyToOne(targetEntity="FuelType")
123 * @ORM\JoinColumn(nullable=true, name="vehicle_fuel_type_id")
128 * @ORM\ManyToOne(targetEntity="TransmissionType")
129 * @ORM\JoinColumn(nullable=true, name="vehicle_transmission_type_id")
131 protected $transmissionType;
134 * @ORM\ManyToOne(targetEntity="ExteriorColour")
135 * @ORM\JoinColumn(nullable=true, name="vehicle_exterior_colour_id")
137 protected $exteriorColour;
140 * @ORM\ManyToOne(targetEntity="InteriorColour")
141 * @ORM\JoinColumn(nullable=true, name="vehicle_interior_colour_id")
143 protected $interiorColour;
146 * @ORM\ManyToOne(targetEntity="Condition")
147 * @ORM\JoinColumn(nullable=true, name="vehicle_condition_id")
149 protected $condition;
152 * @ORM\ManyToOne(targetEntity="Year")
153 * @ORM\JoinColumn(nullable=true, name="vehicle_year_id")
155 protected $vehicleYear;
158 * @ORM\Column(type="integer", nullable=true, options={"unsigned"=true})
163 * @ORM\ManyToOne(targetEntity="Upholstery")
164 * @ORM\JoinColumn(nullable=true, name="vehicle_upholstery_id")
166 protected $upholstery;
169 * @ORM\ManyToOne(targetEntity="Paper")
170 * @ORM\JoinColumn(nullable=true, name="vehicle_paper_id")
175 * @ORM\Column(type="text", name="papers_notes")
177 protected $papersNotes = '';
180 * @ORM\ManyToOne(targetEntity="Natis")
181 * @ORM\JoinColumn(nullable=true, name="vehicle_natis_id")
186 * @ORM\Column(nullable=true, type="boolean", name="spare_keys");
188 protected $spareKeys;
191 * @ORM\ManyToOne(targetEntity="FullServiceHistory")
192 * @ORM\JoinColumn(nullable=true, name="vehicle_fsh_id")
194 protected $fullServiceHistory;
197 * @ORM\Column(type="text", name="fsh_notes")
199 protected $fshNotes = '';
202 /* ------------------------------------ Pricing ------------------------------------ */
204 * @ORM\Column(type="datetime", name="trade_price_date", nullable=true);
206 protected $tradePriceDate;
209 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="trade_price", options={"unsigned"=true});
211 protected $tradePrice = 0.0;
214 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="retail_price", options={"unsigned"=true});
216 protected $retailPrice = 0.0;
219 * @ORM\Column(type="datetime", name="old_trade_price_date", nullable=true);
221 protected $oldTradePriceDate;
224 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="old_trade_price", options={"unsigned"=true});
226 protected $oldTradePrice = 0.0;
229 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="old_retail_price", options={"unsigned"=true});
231 protected $oldRetailPrice = 0.0;
234 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="retail_amount_required", options={"unsigned"=true});
236 protected $retailAmountRequired = 0.0;
239 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="purchase_price", options={"unsigned"=true});
241 protected $purchasePrice = 0.0;
244 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="sale_price", options={"unsigned"=true});
246 protected $salePrice = 0.0;
250 * @ORM\Column(type="datetime", name="list_price_date", nullable=true);
252 protected $listPriceDate;
255 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="list_price", options={"unsigned"=true});
257 protected $listPrice = 0.0;
260 * @ORM\Column(type="datetime", name="old_list_price_date", nullable=true);
262 protected $oldListPriceDate;
265 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="old_list_price", options={"unsigned"=true});
267 protected $oldListPrice = 0.0;
270 /* ------------------------------------ Vehicle photos ------------------------------------ */
272 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
273 * @ORM\JoinColumn(nullable=true, name="main_lib_photo_id")
275 protected $mainImage;
278 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
279 * @ORM\JoinColumn(nullable=true, name="front_lib_photo_id")
281 protected $frontImage;
284 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
285 * @ORM\JoinColumn(nullable=true, name="right_lib_photo_id")
287 protected $rightImage;
290 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
291 * @ORM\JoinColumn(nullable=true, name="left_lib_photo_id")
293 protected $leftImage;
296 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
297 * @ORM\JoinColumn(nullable=true, name="back_lib_photo_id")
299 protected $backImage;
302 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
303 * @ORM\JoinColumn(nullable=true, name="interior_lib_photo_id")
305 protected $interiorImage;
308 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
309 * @ORM\JoinColumn(nullable=true, name="engine_lib_photo_id")
311 protected $engineImage;
314 * @ORM\ManyToOne(targetEntity="\Utility\Entity\Image")
315 * @ORM\JoinColumn(nullable=true, name="natis_lib_photo_id")
317 protected $natisImage;
320 /* ------------------------------------ Accessories ------------------------------------ */
322 * @ORM\OneToMany(targetEntity="StockAccessory", mappedBy="stock", cascade={"all"}, fetch="EXTRA_LAZY")
324 protected $accessories;
327 * @ORM\Column(type="text", name="accessory_notes")
329 protected $accessoryNotes = '';
332 /* ------------------------------------ Damages ------------------------------------ */
334 * @ORM\OneToMany(targetEntity="StockDamage", mappedBy="stock", cascade={"all"}, fetch="EXTRA_LAZY")
339 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="damage_total", options={"unsigned"=true});
341 protected $damageTotal = 0.0;
344 * @ORM\Column(type="text", name="damage_notes")
346 protected $damageNotes = '';
349 * @ORM\Column(type="boolean", name="previous_repairs_noted");
351 protected $previousRepairsNoted = false;
354 * @ORM\Column(type="text", name="previous_repairs_notes")
356 protected $previousRepairsNotes = '';
358 /* ------------------------------------ Cover Received ------------------------------------ */
361 * @ORM\Column(type="text", name="cover_received")
363 protected $coverReceived = '';
366 /* ------------------------------------ Price Guide ------------------------------------ */
368 * @ORM\Column(type="integer", nullable=false, name="number_of_offers");
370 protected $numberOfOffers = 0;
373 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="highest_offer", options={"unsigned"=true});
375 protected $highestOffer = 0.0;
378 * @ORM\Column(type="datetime", nullable=true, name="loaded_on_priceguide");
380 protected $loadedOnPriceGuide;
383 /* ------------------------------------ Auction ------------------------------------ */
385 * @ORM\Column(type="integer", nullable=false, name="times_listed");
387 protected $timesListed = 0;
390 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="highest_bid", options={"unsigned"=true});
392 protected $highestBid = 0.0;
395 /* ------------------------------------ Adherence ------------------------------------ */
397 * @ORM\OneToMany(targetEntity="\Adherence\Entity\AdherenceStock", mappedBy="stock", cascade={"all"}, fetch="EXTRA_LAZY")
399 protected $adherence;
403 /* ------------------------------------ Tracking ------------------------------------ */
406 * @ORM\Column(type="datetime", nullable=true);
411 * @ORM\Column(type="string", length=25, nullable=true, name="previous_status");
413 protected $previousState;
416 * @ORM\Column(type="string", length=25, nullable=true, name="status");
421 * @ORM\Column(type="datetime");
426 * @ORM\Column(type="datetime", nullable=true);
431 * @ORM\Column(type="boolean");
433 protected $archived = false;
438 * Initialize collections.
440 public function __construct()
442 $this->accessories = new \Doctrine\Common\Collections\ArrayCollection();
443 $this->damages = new \Doctrine\Common\Collections\ArrayCollection();
444 $this->adherence = new \Doctrine\Common\Collections\ArrayCollection();
448 * Add a new Accessory to this Stock Item.
449 * @param Accessory $accessory
450 * @return \Stock\Entity\Stock
452 public function addAccessory(Accessory $accessory)
454 $this->accessories[] = $accessory;
459 * Add a new Damage to this Stock Item.
460 * @param Damage $damage
461 * @return \Stock\Entity\Stock
463 public function addDamage(Damage $damage)
465 $this->damages[] = $damage;
472 * Magic getter to expose protected properties.
474 * @param string $property
477 public function __get($property)
479 return $this->$property;
483 * Magic setter to save protected properties.
485 * @param string $property
486 * @param mixed $value
488 public function __set($property, $value)
490 $this->$property = $value;
496 public function setCreateTime()
498 if (is_null($this->uvi))
500 list($usec, $sec) = explode(" ", microtime());
501 $this->uvi = $sec . substr($usec, 2, 3);
503 if (\Utility\Registry::get('IsDeviceApiCall', false))
505 // Leave company and createdBy for controller to set.
507 else if (\Utility\Registry::get('IsBulkImport', false))
509 // Leave company and createdBy for controller to set.
511 else if (\Utility\Registry::isAuthenticated())
513 $this->company = \Utility\Registry::resolveCompanyContext($this->company);
514 $this->createdBy = \Utility\Registry::resolveProfileContext($this->createdBy);
518 $em = \Utility\Registry::getEntityManager();
519 // $companyId = IS_STAGE_ENV ? 1953 : 2283;
520 $companyId = IS_STAGE_ENV ? 1 : 1;
525 $this->company = $em->getReference('\Company\Entity\Company', $companyId);
526 $this->createdBy = $em->getReference('\User\Entity\Profile', 1);
528 $this->created = new \DateTime("now");
529 if (0.0 != $this->tradePrice && is_null($this->tradePriceDate))
531 $this->tradePriceDate = new \DateTime('now');
533 if (0.0 != $this->oldTradePrice && is_null($this->oldTradePriceDate))
535 $this->oldTradePriceDate = new \DateTime('now');
538 if (0.0 != $this->listPrice && is_null($this->listPriceDate))
540 $this->listPriceDate = new \DateTime('now');
542 if (0.0 != $this->oldListPrice && is_null($this->oldListPriceDate))
544 $this->oldListPriceDate = new \DateTime('now');
551 public function setUpdateTime()
553 $this->updated = new \DateTime("now");
554 if (0.0 != $this->tradePrice && is_null($this->tradePriceDate))
556 $this->tradePriceDate = new \DateTime('now');
558 if (0.0 != $this->oldTradePrice && is_null($this->oldTradePriceDate))
560 $this->oldTradePriceDate = new \DateTime('now');
563 if (0.0 != $this->listPrice && is_null($this->listPriceDate))
565 $this->listPriceDate = new \DateTime('now');
567 if (0.0 != $this->oldListPrice && is_null($this->oldListPriceDate))
569 $this->oldListPriceDate = new \DateTime('now');
571 /* if ('' == $this->jobState
572 && is_null($this->loadedOnPriceGuide))
574 $this->loadedOnPriceGuide = new \DateTime("now");
579 * Automatically called from DataBin if HAVE_POST_INSERT constant is set on entity.
582 public function postInsert()
584 if (is_null($this->id) || !is_numeric($this->id))
588 $this->referenceNumber = 'S' . str_pad($this->id, 7, '0', STR_PAD_LEFT);
593 * Convert the object to an array.
594 * @param array $expand
595 * @param array $intersect
596 * @param boolean $showIdentifiers
597 * @param integer $expandAll
600 public function toArray(
601 array $expand = array(), array $intersect = array(),
602 $showIdentifiers = false, $expandAll = 0
605 $intersect = array_flip($intersect);
606 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
607 $includeAll = empty($intersect);
609 ($includeAll || isset($intersect['id']))
610 && $data['id'] = $this->id;
611 ($includeAll || isset($intersect['uvi']))
612 && $data['uvi'] = $this->uvi;
613 ($includeAll || isset($intersect['company']))
614 && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
615 && !is_null($this->company)
616 ? (!$showIdentifiers || in_array('company', $expand) ? $this->company->toArray(
617 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
618 ) : $this->company->id)
620 ($includeAll || isset($intersect['auction']))
621 && $data['auction'] = (in_array('auction', $expand) || $expandAll || $showIdentifiers)
622 && !is_null($this->auction)
623 ? (!$showIdentifiers || in_array('auction', $expand) ? $this->auction->toArray(
624 array(), array('id','company','soldToCompany','stock','endDate','reservePrice','jobState'), true, ($expandAll - 1)
625 ) : $this->auction->id)
627 if (isset($data['auction']))
629 $date = new \DateTime($data['auction']['endDate']);
630 $data['auction']['Within30DaysOfEnd'] = time() < ($date->getTimestamp() + 2592000);
632 ($includeAll || isset($intersect['createdBy']))
633 && $data['createdBy'] = (in_array('createdBy', $expand) || $expandAll || $showIdentifiers)
634 && !is_null($this->createdBy)
635 ? (!$showIdentifiers || in_array('createdBy', $expand) ? $this->createdBy->toArray(
636 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
637 ) : $this->createdBy->id)
639 ($includeAll || isset($intersect['valuation']))
640 && $data['valuation'] = (in_array('valuation_', $expand) || $expandAll || $showIdentifiers)
641 && !is_null($this->valuation)
642 ? (!$showIdentifiers || in_array('valuation_', $expand) ? $this->valuation->toArray(
643 /* $expand, $intersect, $showIdentifiers, ($expandAll - 1) */
644 ) : $this->valuation->id)
646 ($includeAll || isset($intersect['region']))
647 && $data['region'] = (in_array('region', $expand) || $expandAll || $showIdentifiers)
648 && !is_null($this->region)
649 ? (!$showIdentifiers || in_array('region', $expand) ? $this->region->toArray(
650 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
651 ) : $this->region->id)
653 (!\Utility\Registry::checkOnce('Stock.IgnorePriceGuide', false) && ($includeAll || isset($intersect['priceGuide'])))
654 && $data['priceGuide'] = (in_array('priceGuide', $expand) || $expandAll || $showIdentifiers)
655 && !is_null($this->priceGuide)
656 ? (!$showIdentifiers || in_array('priceGuide', $expand) ? $this->priceGuide->toArray(
657 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
658 ) : $this->priceGuide->id)
660 if (2 == $showIdentifiers)
662 $data['mmCode'] = $this->type->mmCode;
663 $data['category'] = $this->type->category->id;
664 $data['make'] = $this->type->model->make->id;
665 $data['model'] = $this->type->model->id;
667 ($includeAll || isset($intersect['type']))
668 && $data['type'] = (in_array('type', $expand) || $expandAll || $showIdentifiers)
669 && !is_null($this->type)
670 ? (!$showIdentifiers || in_array('type', $expand) ? $this->type->toArray(
671 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
674 ($includeAll || isset($intersect['referenceNumber']))
675 && $data['referenceNumber'] = $this->referenceNumber;
676 ($includeAll || isset($intersect['stockNumber']))
677 && $data['stockNumber'] = $this->stockNumber;
678 ($includeAll || isset($intersect['registrationNumber']))
679 && $data['registrationNumber'] = $this->registrationNumber;
680 ($includeAll || isset($intersect['vinNumber']))
681 && $data['vinNumber'] = $this->vinNumber;
682 ($includeAll || isset($intersect['engineNumber']))
683 && $data['engineNumber'] = $this->engineNumber;
684 ($includeAll || isset($intersect['fuelType']))
685 && $data['fuelType'] = (in_array('fuelType', $expand) || $expandAll || $showIdentifiers)
686 && !is_null($this->fuelType)
687 ? (!$showIdentifiers || in_array('fuelType', $expand) ? $this->fuelType->toArray(
688 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
689 ) : $this->fuelType->id)
691 ($includeAll || isset($intersect['transmissionType']))
692 && $data['transmissionType'] = (in_array('transmissionType', $expand) || $expandAll || $showIdentifiers)
693 && !is_null($this->transmissionType)
694 ? (!$showIdentifiers || in_array('transmissionType', $expand) ? $this->transmissionType->toArray(
695 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
696 ) : $this->transmissionType->id)
698 ($includeAll || isset($intersect['exteriorColour']))
699 && $data['exteriorColour'] = (in_array('exteriorColour', $expand) || $expandAll || $showIdentifiers)
700 && !is_null($this->exteriorColour)
701 ? (!$showIdentifiers || in_array('exteriorColour', $expand) ? $this->exteriorColour->toArray(
702 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
703 ) : $this->exteriorColour->id)
705 ($includeAll || isset($intersect['interiorColour']))
706 && $data['interiorColour'] = (in_array('interiorColour', $expand) || $expandAll || $showIdentifiers)
707 && !is_null($this->interiorColour)
708 ? (!$showIdentifiers || in_array('interiorColour', $expand) ? $this->interiorColour->toArray(
709 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
710 ) : $this->interiorColour->id)
712 ($includeAll || isset($intersect['condition']))
713 && $data['condition'] = (in_array('condition', $expand) || $expandAll || $showIdentifiers)
714 && !is_null($this->condition)
715 ? (!$showIdentifiers || in_array('condition', $expand) ? $this->condition->toArray(
716 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
717 ) : $this->condition->id)
719 ($includeAll || isset($intersect['vehicleYear']))
720 && $data['vehicleYear'] = (in_array('vehicleYear', $expand) || $expandAll || $showIdentifiers)
721 && !is_null($this->vehicleYear)
722 ? (!$showIdentifiers || in_array('vehicleYear', $expand) ? $this->vehicleYear->toArray(
723 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
724 ) : $this->vehicleYear->id)
726 ($includeAll || isset($intersect['km']))
727 && $data['km'] = $this->km;
728 ($includeAll || isset($intersect['upholstery']))
729 && $data['upholstery'] = (in_array('upholstery', $expand) || $expandAll || $showIdentifiers)
730 && !is_null($this->upholstery)
731 ? (!$showIdentifiers || in_array('upholstery', $expand) ? $this->upholstery->toArray(
732 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
733 ) : $this->upholstery->id)
735 ($includeAll || isset($intersect['papers']))
736 && $data['papers'] = (in_array('papers', $expand) || $expandAll || $showIdentifiers)
737 && !is_null($this->papers)
738 ? (!$showIdentifiers || in_array('papers', $expand) ? $this->papers->toArray(
739 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
740 ) : $this->papers->id)
742 ($includeAll || isset($intersect['papersNotes']))
743 && $data['papersNotes'] = $this->papersNotes;
744 ($includeAll || isset($intersect['natis']))
745 && $data['natis'] = (in_array('natis', $expand) || $expandAll || $showIdentifiers)
746 && !is_null($this->natis)
747 ? (!$showIdentifiers || in_array('natis', $expand) ? $this->natis->toArray(
748 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
749 ) : $this->natis->id)
751 ($includeAll || isset($intersect['spareKeys']))
752 && $data['spareKeys'] = $this->spareKeys;
753 ($includeAll || isset($intersect['fullServiceHistory']))
754 && $data['fullServiceHistory'] = (in_array('fullServiceHistory', $expand) || $expandAll || $showIdentifiers)
755 && !is_null($this->fullServiceHistory)
756 ? (!$showIdentifiers || in_array('fullServiceHistory', $expand) ? $this->fullServiceHistory->toArray(
757 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
758 ) : $this->fullServiceHistory->id)
760 ($includeAll || isset($intersect['fshNotes']))
761 && $data['fshNotes'] = $this->fshNotes;
762 ($includeAll || isset($intersect['tradePriceDate']))
763 && $data['tradePriceDate'] = !is_null($this->tradePriceDate)
764 ? $this->tradePriceDate->format($dateTimeFormat)
766 ($includeAll || isset($intersect['listPriceDate']))
767 && $data['listPriceDate'] = !is_null($this->listPriceDate)
768 ? $this->listPriceDate->format($dateTimeFormat)
770 ($includeAll || isset($intersect['tradePrice']))
771 && $data['tradePrice'] = $this->tradePrice;
772 ($includeAll || isset($intersect['retailPrice']))
773 && $data['retailPrice'] = $this->retailPrice;
774 ($includeAll || isset($intersect['listPrice']))
775 && $data['listPrice'] = $this->listPrice;
776 ($includeAll || isset($intersect['oldTradePriceDate']))
777 && $data['oldTradePriceDate'] = !is_null($this->oldTradePriceDate)
778 ? $this->oldTradePriceDate->format($dateTimeFormat)
780 ($includeAll || isset($intersect['oldListPriceDate']))
781 && $data['oldListPriceDate'] = !is_null($this->oldListPriceDate)
782 ? $this->oldListPriceDate->format($dateTimeFormat)
784 ($includeAll || isset($intersect['oldTradePrice']))
785 && $data['oldTradePrice'] = $this->oldTradePrice;
786 ($includeAll || isset($intersect['oldRetailPrice']))
787 && $data['oldRetailPrice'] = $this->oldRetailPrice;
788 ($includeAll || isset($intersect['oldListPrice']))
789 && $data['oldListPrice'] = $this->oldListPrice;
790 ($includeAll || isset($intersect['retailAmountRequired']))
791 && $data['retailAmountRequired'] = $this->retailAmountRequired;
792 ($includeAll || isset($intersect['mainImage']))
793 && $data['mainImage'] = (in_array('mainImage', $expand) || $expandAll || $showIdentifiers)
794 && !is_null($this->mainImage)
795 ? (!$showIdentifiers || in_array('mainImage', $expand) ? $this->mainImage->toArray(
796 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
797 ) : $this->mainImage->id)
799 ($includeAll || isset($intersect['frontImage']))
800 && $data['frontImage'] = (in_array('frontImage', $expand) || $expandAll || $showIdentifiers)
801 && !is_null($this->frontImage)
802 ? (!$showIdentifiers || in_array('frontImage', $expand) ? $this->frontImage->toArray(
803 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
804 ) : $this->frontImage->id)
806 ($includeAll || isset($intersect['rightImage']))
807 && $data['rightImage'] = (in_array('rightImage', $expand) || $expandAll || $showIdentifiers)
808 && !is_null($this->rightImage)
809 ? (!$showIdentifiers || in_array('rightImage', $expand) ? $this->rightImage->toArray(
810 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
811 ) : $this->rightImage->id)
813 ($includeAll || isset($intersect['leftImage']))
814 && $data['leftImage'] = (in_array('leftImage', $expand) || $expandAll || $showIdentifiers)
815 && !is_null($this->leftImage)
816 ? (!$showIdentifiers || in_array('leftImage', $expand) ? $this->leftImage->toArray(
817 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
818 ) : $this->leftImage->id)
820 ($includeAll || isset($intersect['backImage']))
821 && $data['backImage'] = (in_array('backImage', $expand) || $expandAll || $showIdentifiers)
822 && !is_null($this->backImage)
823 ? (!$showIdentifiers || in_array('backImage', $expand) ? $this->backImage->toArray(
824 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
825 ) : $this->backImage->id)
827 ($includeAll || isset($intersect['interiorImage']))
828 && $data['interiorImage'] = (in_array('interiorImage', $expand) || $expandAll || $showIdentifiers)
829 && !is_null($this->interiorImage)
830 ? (!$showIdentifiers || in_array('interiorImage', $expand) ? $this->interiorImage->toArray(
831 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
832 ) : $this->interiorImage->id)
834 ($includeAll || isset($intersect['engineImage']))
835 && $data['engineImage'] = (in_array('engineImage', $expand) || $expandAll || $showIdentifiers)
836 && !is_null($this->engineImage)
837 ? (!$showIdentifiers || in_array('engineImage', $expand) ? $this->engineImage->toArray(
838 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
839 ) : $this->engineImage->id)
841 ($includeAll || isset($intersect['natisImage']))
842 && $data['natisImage'] = (in_array('natisImage', $expand) || $expandAll || $showIdentifiers)
843 && !is_null($this->natisImage)
844 ? (!$showIdentifiers || in_array('natisImage', $expand) ? $this->natisImage->toArray(
845 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
846 ) : $this->natisImage->id)
848 ($includeAll || isset($intersect['accessories']))
849 && $data['accessories'] = (in_array('accessories', $expand) || $expandAll || $showIdentifiers)
850 && !is_null($this->accessories)
851 ? $this->accessoriesToArray($showIdentifiers)
853 ($includeAll || isset($intersect['accessoryNotes']))
854 && $data['accessoryNotes'] = $this->accessoryNotes;
855 ($includeAll || isset($intersect['damages']))
856 && $data['damages'] = (in_array('damages', $expand) || $expandAll || $showIdentifiers)
857 && !is_null($this->damages)
858 ? $this->damagesToArray($showIdentifiers)
860 ($includeAll || isset($intersect['damageTotal']))
861 && $data['damageTotal'] = $this->damageTotal;
862 ($includeAll || isset($intersect['damageNotes']))
863 && $data['damageNotes'] = $this->damageNotes;
864 ($includeAll || isset($intersect['previousRepairsNoted']))
865 && $data['previousRepairsNoted'] = $this->previousRepairsNoted;
866 ($includeAll || isset($intersect['previousRepairsNotes']))
867 && $data['previousRepairsNotes'] = $this->previousRepairsNotes;
868 ($includeAll || isset($intersect['coverReceived']))
869 && $data['coverReceived'] = $this->coverReceived;
870 ($includeAll || isset($intersect['numberOfOffers']))
871 && $data['numberOfOffers'] = $this->numberOfOffers;
872 ($includeAll || isset($intersect['highestOffer']))
873 && $data['highestOffer'] = $this->highestOffer;
874 ($includeAll || isset($intersect['loadedOnPriceGuide']))
875 && $data['loadedOnPriceGuide'] = !is_null($this->loadedOnPriceGuide)
876 ? $this->loadedOnPriceGuide->format($dateTimeFormat)
878 ($includeAll || isset($intersect['timesListed']))
879 && $data['timesListed'] = $this->timesListed;
880 ($includeAll || isset($intersect['highestBid']))
881 && $data['highestBid'] = $this->highestBid;
882 ($includeAll || isset($intersect['jobState']))
883 && $data['jobState'] = $this->jobState;
884 ($includeAll || isset($intersect['created']))
885 && $data['created'] = !is_null($this->created)
886 ? $this->created->format($dateTimeFormat)
888 ($includeAll || isset($intersect['updated']))
889 && $data['updated'] = !is_null($this->updated)
890 ? $this->updated->format($dateTimeFormat)
892 ($includeAll || isset($intersect['reset']))
893 && $data['reset'] = !is_null($this->reset)
894 ? $this->reset->format($dateTimeFormat)
900 * Internal utility to change accessories collection into array.
901 * @param boolean $showIdentifiers
904 public function accessoriesToArray($showIdentifiers = false)
907 $iterator = $this->accessories->getIterator();
908 if (2 == $showIdentifiers)
910 foreach ($iterator as $accessory)
912 $data[] = $accessory->accessory->id;
917 foreach ($iterator as $accessory)
919 $data[] = $showIdentifiers
920 ? array('id' => $accessory->accessory->id)
921 : $accessory->toArray();
928 * Internal utility to change damages collection into array.
929 * @param boolean $showIdentifiers
932 public function damagesToArray($showIdentifiers = false)
935 $iterator = $this->damages->getIterator();
936 foreach ($iterator as $damage)
938 $data[] = $damage->toArray(array(), array(), $showIdentifiers);
944 * Populate from an array.
947 public function fromArray($data = array())
950 && $this->id = $data['id'];
952 && $this->uvi = $data['uvi'];
953 isset($data['company'])
954 && $this->company = $data['company'];
955 isset($data['createdBy'])
956 && $this->createdBy = $data['createdBy'];
957 isset($data['region'])
958 && $this->region = $data['region'];
960 && $this->type = $data['type'];
961 isset($data['stockNumber'])
962 && $this->stockNumber = $data['stockNumber'];
963 isset($data['registrationNumber'])
964 && $this->registrationNumber = $data['registrationNumber'];
965 isset($data['vinNumber'])
966 && $this->vinNumber = $data['vinNumber'];
967 isset($data['engineNumber'])
968 && $this->engineNumber = $data['engineNumber'];
969 isset($data['fuelType'])
970 && $this->fuelType = $data['fuelType'];
971 isset($data['transmissionType'])
972 && $this->transmissionType = $data['transmissionType'];
973 isset($data['exteriorColour'])
974 && $this->exteriorColour = $data['exteriorColour'];
975 isset($data['interiorColour'])
976 && $this->interiorColour = $data['interiorColour'];
977 isset($data['condition'])
978 && $this->condition = $data['condition'];
979 isset($data['vehicleYear'])
980 && $this->vehicleYear = $data['vehicleYear'];
982 && $this->km = $data['km'];
983 isset($data['upholstery'])
984 && $this->upholstery = $data['upholstery'];
985 isset($data['papers'])
986 && $this->papers = $data['papers'];
987 isset($data['papersNotes'])
988 && $this->papersNotes = $data['papersNotes'];
989 isset($data['natis'])
990 && $this->natis = $data['natis'];
991 isset($data['spareKeys'])
992 && $this->spareKeys = $data['spareKeys'];
993 isset($data['fullServiceHistory'])
994 && $this->fullServiceHistory = $data['fullServiceHistory'];
995 isset($data['fshNotes'])
996 && $this->fshNotes = $data['fshNotes'];
997 isset($data['tradePrice'])
998 && $this->tradePrice = $data['tradePrice'];
999 isset($data['retailPrice'])
1000 && $this->retailPrice = $data['retailPrice'];
1001 isset($data['listPrice'])
1002 && $this->listPrice = $data['listPrice'];
1003 isset($data['oldTradePrice'])
1004 && $this->oldTradePrice = $data['oldTradePrice'];
1005 isset($data['oldRetailPrice'])
1006 && $this->oldRetailPrice = $data['oldRetailPrice'];
1007 isset($data['oldListPrice'])
1008 && $this->oldListPrice = $data['oldListPrice'];
1009 isset($data['retailAmountRequired'])
1010 && $this->retailAmountRequired = $data['retailAmountRequired'];
1011 isset($data['mainImage'])
1012 && $this->mainImage = $data['mainImage'];
1013 isset($data['frontImage'])
1014 && $this->frontImage = $data['frontImage'];
1015 isset($data['rightImage'])
1016 && $this->rightImage = $data['rightImage'];
1017 isset($data['leftImage'])
1018 && $this->leftImage = $data['leftImage'];
1019 isset($data['backImage'])
1020 && $this->backImage = $data['backImage'];
1021 isset($data['interiorImage'])
1022 && $this->interiorImage = $data['interiorImage'];
1023 isset($data['engineImage'])
1024 && $this->engineImage = $data['engineImage'];
1025 isset($data['natisImage'])
1026 && $this->natisImage = $data['natisImage'];
1027 isset($data['accessoryNotes'])
1028 && $this->accessoryNotes = $data['accessoryNotes'];
1029 isset($data['damageTotal'])
1030 && $this->damageTotal = $data['damageTotal'];
1031 isset($data['damageNotes'])
1032 && $this->damageNotes = $data['damageNotes'];
1033 isset($data['previousRepairsNoted'])
1034 && $this->previousRepairsNoted = $data['previousRepairsNoted'];
1035 isset($data['previousRepairsNotes'])
1036 && $this->previousRepairsNotes = $data['previousRepairsNotes'];
1038 isset($data['coverReceived'])
1039 && $this->coverReceived = $data['coverReceived'];
1041 isset($data['numberOfOffers'])
1042 && $this->numberOfOffers = $data['numberOfOffers'];
1043 isset($data['highestOffer'])
1044 && $this->highestOffer = $data['highestOffer'];
1045 isset($data['loadedOnPriceGuide'])
1046 && $this->loadedOnPriceGuide = $data['loadedOnPriceGuide'];
1047 isset($data['jobState'])
1048 && $this->jobState = $data['jobState'];
1049 if (isset($data['accessories']))
1051 $em = \Utility\Registry::getEntityManager();
1053 foreach ($data['accessories'] as $acc)
1055 $newAccs[$acc['id']] = $acc['id'];
1057 $currentAccs = array();
1058 $iterator = $this->accessories->getIterator();
1059 foreach ($iterator as $acc)
1061 $currentAccs[$acc->accessory->id] = $acc->accessory->id;
1062 !isset($newAccs[$acc->accessory->id])
1063 && $em->remove($acc);
1065 foreach ($data['accessories'] as $acc)
1067 if (!isset($currentAccs[$acc['id']]))
1069 $stockAcc = new \Stock\Entity\StockAccessory();
1070 $stockAcc->accessory = $em->getReference('\Stock\Entity\Accessory', $acc['id']);
1071 $stockAcc->stock = $this;
1072 $this->accessories->add($stockAcc);
1076 if (isset($data['damages']))
1078 $em = \Utility\Registry::getEntityManager();
1081 foreach ($data['damages'] as $dmg)
1083 $total += $dmg['amount'];
1084 $newDmgs[$dmg['id']] = $dmg['amount'];
1086 $this->damageTotal = $total;
1087 $currentDmgs = array();
1088 $iterator = $this->damages->getIterator();
1089 foreach ($iterator as $dmg)
1091 $currentDmgs[$dmg->damage->id] = $dmg->damage->id;
1092 if (!isset($newDmgs[$dmg->damage->id]))
1098 $dmg->amount = $newDmgs[$dmg->damage->id];
1101 foreach ($data['damages'] as $dmg)
1103 if (!isset($currentDmgs[$dmg['id']]))
1105 $stockDamage = new \Stock\Entity\StockDamage();
1106 $stockDamage->damage = $em->getReference('\Stock\Entity\Damage', $dmg['id']);
1107 $stockDamage->amount = $dmg['amount'];
1108 $stockDamage->stock = $this;
1109 $this->damages->add($stockDamage);
1114 #-> Update de-normalized auction data.
1115 \Utility\Registry::getEntityManager()->createQuery(
1116 'UPDATE \Auction\Entity\Auction a '
1117 . "SET a.referenceNumber = :referenceNumber, "
1118 . " a.registrationNumber = :registrationNumber, "
1119 . " a.makeId = :makeId, "
1120 . " a.makeName = :makeName, "
1121 . " a.modelName = :modelName, "
1122 . " a.typeName = :typeName, "
1123 . " a.yearName = :yearName, "
1124 . " a.stockKm = :km "
1125 . 'WHERE a.jobState = :jobState '
1126 . ' AND IDENTITY(a.stock) = :id'
1128 ->setParameter('jobState', 'Active')
1129 ->setParameter('id', $this->id)
1130 ->setParameter('referenceNumber', $this->referenceNumber)
1131 ->setParameter('registrationNumber', $this->registrationNumber)
1132 ->setParameter('makeId', $this->type->model->make->id)
1133 ->setParameter('makeName', $this->type->model->make->name)
1134 ->setParameter('modelName', $this->type->model->name)
1135 ->setParameter('typeName', $this->type->name)
1136 ->setParameter('yearName', $this->vehicleYear->name)
1137 ->setParameter('km', $this->km)