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;
524 $this->company = $em->getReference('\Company\Entity\Company', $companyId);
525 $this->createdBy = $em->getReference('\User\Entity\Profile', 1);
527 $this->created = new \DateTime("now");
528 if (0.0 != $this->tradePrice && is_null($this->tradePriceDate))
530 $this->tradePriceDate = new \DateTime('now');
532 if (0.0 != $this->oldTradePrice && is_null($this->oldTradePriceDate))
534 $this->oldTradePriceDate = new \DateTime('now');
537 if (0.0 != $this->listPrice && is_null($this->listPriceDate))
539 $this->listPriceDate = new \DateTime('now');
541 if (0.0 != $this->oldListPrice && is_null($this->oldListPriceDate))
543 $this->oldListPriceDate = new \DateTime('now');
550 public function setUpdateTime()
552 $this->updated = new \DateTime("now");
553 if (0.0 != $this->tradePrice && is_null($this->tradePriceDate))
555 $this->tradePriceDate = new \DateTime('now');
557 if (0.0 != $this->oldTradePrice && is_null($this->oldTradePriceDate))
559 $this->oldTradePriceDate = new \DateTime('now');
562 if (0.0 != $this->listPrice && is_null($this->listPriceDate))
564 $this->listPriceDate = new \DateTime('now');
566 if (0.0 != $this->oldListPrice && is_null($this->oldListPriceDate))
568 $this->oldListPriceDate = new \DateTime('now');
570 /* if ('' == $this->jobState
571 && is_null($this->loadedOnPriceGuide))
573 $this->loadedOnPriceGuide = new \DateTime("now");
578 * Automatically called from DataBin if HAVE_POST_INSERT constant is set on entity.
581 public function postInsert()
583 if (is_null($this->id) || !is_numeric($this->id))
587 $this->referenceNumber = 'S' . str_pad($this->id, 7, '0', STR_PAD_LEFT);
592 * Convert the object to an array.
593 * @param array $expand
594 * @param array $intersect
595 * @param boolean $showIdentifiers
596 * @param integer $expandAll
599 public function toArray(
600 array $expand = array(), array $intersect = array(),
601 $showIdentifiers = false, $expandAll = 0
604 $intersect = array_flip($intersect);
605 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
606 $includeAll = empty($intersect);
608 ($includeAll || isset($intersect['id']))
609 && $data['id'] = $this->id;
610 ($includeAll || isset($intersect['uvi']))
611 && $data['uvi'] = $this->uvi;
612 ($includeAll || isset($intersect['company']))
613 && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
614 && !is_null($this->company)
615 ? (!$showIdentifiers || in_array('company', $expand) ? $this->company->toArray(
616 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
617 ) : $this->company->id)
619 ($includeAll || isset($intersect['auction']))
620 && $data['auction'] = (in_array('auction', $expand) || $expandAll || $showIdentifiers)
621 && !is_null($this->auction)
622 ? (!$showIdentifiers || in_array('auction', $expand) ? $this->auction->toArray(
623 array(), array('id','company','soldToCompany','stock','endDate','reservePrice','jobState'), true, ($expandAll - 1)
624 ) : $this->auction->id)
626 if (isset($data['auction']))
628 $date = new \DateTime($data['auction']['endDate']);
629 $data['auction']['Within30DaysOfEnd'] = time() < ($date->getTimestamp() + 2592000);
631 ($includeAll || isset($intersect['createdBy']))
632 && $data['createdBy'] = (in_array('createdBy', $expand) || $expandAll || $showIdentifiers)
633 && !is_null($this->createdBy)
634 ? (!$showIdentifiers || in_array('createdBy', $expand) ? $this->createdBy->toArray(
635 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
636 ) : $this->createdBy->id)
638 ($includeAll || isset($intersect['valuation']))
639 && $data['valuation'] = (in_array('valuation_', $expand) || $expandAll || $showIdentifiers)
640 && !is_null($this->valuation)
641 ? (!$showIdentifiers || in_array('valuation_', $expand) ? $this->valuation->toArray(
642 /* $expand, $intersect, $showIdentifiers, ($expandAll - 1) */
643 ) : $this->valuation->id)
645 ($includeAll || isset($intersect['region']))
646 && $data['region'] = (in_array('region', $expand) || $expandAll || $showIdentifiers)
647 && !is_null($this->region)
648 ? (!$showIdentifiers || in_array('region', $expand) ? $this->region->toArray(
649 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
650 ) : $this->region->id)
652 (!\Utility\Registry::checkOnce('Stock.IgnorePriceGuide', false) && ($includeAll || isset($intersect['priceGuide'])))
653 && $data['priceGuide'] = (in_array('priceGuide', $expand) || $expandAll || $showIdentifiers)
654 && !is_null($this->priceGuide)
655 ? (!$showIdentifiers || in_array('priceGuide', $expand) ? $this->priceGuide->toArray(
656 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
657 ) : $this->priceGuide->id)
659 if (2 == $showIdentifiers)
661 $data['mmCode'] = $this->type->mmCode;
662 $data['category'] = $this->type->category->id;
663 $data['make'] = $this->type->model->make->id;
664 $data['model'] = $this->type->model->id;
666 ($includeAll || isset($intersect['type']))
667 && $data['type'] = (in_array('type', $expand) || $expandAll || $showIdentifiers)
668 && !is_null($this->type)
669 ? (!$showIdentifiers || in_array('type', $expand) ? $this->type->toArray(
670 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
673 ($includeAll || isset($intersect['referenceNumber']))
674 && $data['referenceNumber'] = $this->referenceNumber;
675 ($includeAll || isset($intersect['stockNumber']))
676 && $data['stockNumber'] = $this->stockNumber;
677 ($includeAll || isset($intersect['registrationNumber']))
678 && $data['registrationNumber'] = $this->registrationNumber;
679 ($includeAll || isset($intersect['vinNumber']))
680 && $data['vinNumber'] = $this->vinNumber;
681 ($includeAll || isset($intersect['engineNumber']))
682 && $data['engineNumber'] = $this->engineNumber;
683 ($includeAll || isset($intersect['fuelType']))
684 && $data['fuelType'] = (in_array('fuelType', $expand) || $expandAll || $showIdentifiers)
685 && !is_null($this->fuelType)
686 ? (!$showIdentifiers || in_array('fuelType', $expand) ? $this->fuelType->toArray(
687 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
688 ) : $this->fuelType->id)
690 ($includeAll || isset($intersect['transmissionType']))
691 && $data['transmissionType'] = (in_array('transmissionType', $expand) || $expandAll || $showIdentifiers)
692 && !is_null($this->transmissionType)
693 ? (!$showIdentifiers || in_array('transmissionType', $expand) ? $this->transmissionType->toArray(
694 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
695 ) : $this->transmissionType->id)
697 ($includeAll || isset($intersect['exteriorColour']))
698 && $data['exteriorColour'] = (in_array('exteriorColour', $expand) || $expandAll || $showIdentifiers)
699 && !is_null($this->exteriorColour)
700 ? (!$showIdentifiers || in_array('exteriorColour', $expand) ? $this->exteriorColour->toArray(
701 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
702 ) : $this->exteriorColour->id)
704 ($includeAll || isset($intersect['interiorColour']))
705 && $data['interiorColour'] = (in_array('interiorColour', $expand) || $expandAll || $showIdentifiers)
706 && !is_null($this->interiorColour)
707 ? (!$showIdentifiers || in_array('interiorColour', $expand) ? $this->interiorColour->toArray(
708 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
709 ) : $this->interiorColour->id)
711 ($includeAll || isset($intersect['condition']))
712 && $data['condition'] = (in_array('condition', $expand) || $expandAll || $showIdentifiers)
713 && !is_null($this->condition)
714 ? (!$showIdentifiers || in_array('condition', $expand) ? $this->condition->toArray(
715 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
716 ) : $this->condition->id)
718 ($includeAll || isset($intersect['vehicleYear']))
719 && $data['vehicleYear'] = (in_array('vehicleYear', $expand) || $expandAll || $showIdentifiers)
720 && !is_null($this->vehicleYear)
721 ? (!$showIdentifiers || in_array('vehicleYear', $expand) ? $this->vehicleYear->toArray(
722 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
723 ) : $this->vehicleYear->id)
725 ($includeAll || isset($intersect['km']))
726 && $data['km'] = $this->km;
727 ($includeAll || isset($intersect['upholstery']))
728 && $data['upholstery'] = (in_array('upholstery', $expand) || $expandAll || $showIdentifiers)
729 && !is_null($this->upholstery)
730 ? (!$showIdentifiers || in_array('upholstery', $expand) ? $this->upholstery->toArray(
731 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
732 ) : $this->upholstery->id)
734 ($includeAll || isset($intersect['papers']))
735 && $data['papers'] = (in_array('papers', $expand) || $expandAll || $showIdentifiers)
736 && !is_null($this->papers)
737 ? (!$showIdentifiers || in_array('papers', $expand) ? $this->papers->toArray(
738 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
739 ) : $this->papers->id)
741 ($includeAll || isset($intersect['papersNotes']))
742 && $data['papersNotes'] = $this->papersNotes;
743 ($includeAll || isset($intersect['natis']))
744 && $data['natis'] = (in_array('natis', $expand) || $expandAll || $showIdentifiers)
745 && !is_null($this->natis)
746 ? (!$showIdentifiers || in_array('natis', $expand) ? $this->natis->toArray(
747 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
748 ) : $this->natis->id)
750 ($includeAll || isset($intersect['spareKeys']))
751 && $data['spareKeys'] = $this->spareKeys;
752 ($includeAll || isset($intersect['fullServiceHistory']))
753 && $data['fullServiceHistory'] = (in_array('fullServiceHistory', $expand) || $expandAll || $showIdentifiers)
754 && !is_null($this->fullServiceHistory)
755 ? (!$showIdentifiers || in_array('fullServiceHistory', $expand) ? $this->fullServiceHistory->toArray(
756 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
757 ) : $this->fullServiceHistory->id)
759 ($includeAll || isset($intersect['fshNotes']))
760 && $data['fshNotes'] = $this->fshNotes;
761 ($includeAll || isset($intersect['tradePriceDate']))
762 && $data['tradePriceDate'] = !is_null($this->tradePriceDate)
763 ? $this->tradePriceDate->format($dateTimeFormat)
765 ($includeAll || isset($intersect['listPriceDate']))
766 && $data['listPriceDate'] = !is_null($this->listPriceDate)
767 ? $this->listPriceDate->format($dateTimeFormat)
769 ($includeAll || isset($intersect['tradePrice']))
770 && $data['tradePrice'] = $this->tradePrice;
771 ($includeAll || isset($intersect['retailPrice']))
772 && $data['retailPrice'] = $this->retailPrice;
773 ($includeAll || isset($intersect['listPrice']))
774 && $data['listPrice'] = $this->listPrice;
775 ($includeAll || isset($intersect['oldTradePriceDate']))
776 && $data['oldTradePriceDate'] = !is_null($this->oldTradePriceDate)
777 ? $this->oldTradePriceDate->format($dateTimeFormat)
779 ($includeAll || isset($intersect['oldListPriceDate']))
780 && $data['oldListPriceDate'] = !is_null($this->oldListPriceDate)
781 ? $this->oldListPriceDate->format($dateTimeFormat)
783 ($includeAll || isset($intersect['oldTradePrice']))
784 && $data['oldTradePrice'] = $this->oldTradePrice;
785 ($includeAll || isset($intersect['oldRetailPrice']))
786 && $data['oldRetailPrice'] = $this->oldRetailPrice;
787 ($includeAll || isset($intersect['oldListPrice']))
788 && $data['oldListPrice'] = $this->oldListPrice;
789 ($includeAll || isset($intersect['retailAmountRequired']))
790 && $data['retailAmountRequired'] = $this->retailAmountRequired;
791 ($includeAll || isset($intersect['mainImage']))
792 && $data['mainImage'] = (in_array('mainImage', $expand) || $expandAll || $showIdentifiers)
793 && !is_null($this->mainImage)
794 ? (!$showIdentifiers || in_array('mainImage', $expand) ? $this->mainImage->toArray(
795 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
796 ) : $this->mainImage->id)
798 ($includeAll || isset($intersect['frontImage']))
799 && $data['frontImage'] = (in_array('frontImage', $expand) || $expandAll || $showIdentifiers)
800 && !is_null($this->frontImage)
801 ? (!$showIdentifiers || in_array('frontImage', $expand) ? $this->frontImage->toArray(
802 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
803 ) : $this->frontImage->id)
805 ($includeAll || isset($intersect['rightImage']))
806 && $data['rightImage'] = (in_array('rightImage', $expand) || $expandAll || $showIdentifiers)
807 && !is_null($this->rightImage)
808 ? (!$showIdentifiers || in_array('rightImage', $expand) ? $this->rightImage->toArray(
809 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
810 ) : $this->rightImage->id)
812 ($includeAll || isset($intersect['leftImage']))
813 && $data['leftImage'] = (in_array('leftImage', $expand) || $expandAll || $showIdentifiers)
814 && !is_null($this->leftImage)
815 ? (!$showIdentifiers || in_array('leftImage', $expand) ? $this->leftImage->toArray(
816 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
817 ) : $this->leftImage->id)
819 ($includeAll || isset($intersect['backImage']))
820 && $data['backImage'] = (in_array('backImage', $expand) || $expandAll || $showIdentifiers)
821 && !is_null($this->backImage)
822 ? (!$showIdentifiers || in_array('backImage', $expand) ? $this->backImage->toArray(
823 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
824 ) : $this->backImage->id)
826 ($includeAll || isset($intersect['interiorImage']))
827 && $data['interiorImage'] = (in_array('interiorImage', $expand) || $expandAll || $showIdentifiers)
828 && !is_null($this->interiorImage)
829 ? (!$showIdentifiers || in_array('interiorImage', $expand) ? $this->interiorImage->toArray(
830 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
831 ) : $this->interiorImage->id)
833 ($includeAll || isset($intersect['engineImage']))
834 && $data['engineImage'] = (in_array('engineImage', $expand) || $expandAll || $showIdentifiers)
835 && !is_null($this->engineImage)
836 ? (!$showIdentifiers || in_array('engineImage', $expand) ? $this->engineImage->toArray(
837 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
838 ) : $this->engineImage->id)
840 ($includeAll || isset($intersect['natisImage']))
841 && $data['natisImage'] = (in_array('natisImage', $expand) || $expandAll || $showIdentifiers)
842 && !is_null($this->natisImage)
843 ? (!$showIdentifiers || in_array('natisImage', $expand) ? $this->natisImage->toArray(
844 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
845 ) : $this->natisImage->id)
847 ($includeAll || isset($intersect['accessories']))
848 && $data['accessories'] = (in_array('accessories', $expand) || $expandAll || $showIdentifiers)
849 && !is_null($this->accessories)
850 ? $this->accessoriesToArray($showIdentifiers)
852 ($includeAll || isset($intersect['accessoryNotes']))
853 && $data['accessoryNotes'] = $this->accessoryNotes;
854 ($includeAll || isset($intersect['damages']))
855 && $data['damages'] = (in_array('damages', $expand) || $expandAll || $showIdentifiers)
856 && !is_null($this->damages)
857 ? $this->damagesToArray($showIdentifiers)
859 ($includeAll || isset($intersect['damageTotal']))
860 && $data['damageTotal'] = $this->damageTotal;
861 ($includeAll || isset($intersect['damageNotes']))
862 && $data['damageNotes'] = $this->damageNotes;
863 ($includeAll || isset($intersect['previousRepairsNoted']))
864 && $data['previousRepairsNoted'] = $this->previousRepairsNoted;
865 ($includeAll || isset($intersect['previousRepairsNotes']))
866 && $data['previousRepairsNotes'] = $this->previousRepairsNotes;
867 ($includeAll || isset($intersect['coverReceived']))
868 && $data['coverReceived'] = $this->coverReceived;
869 ($includeAll || isset($intersect['numberOfOffers']))
870 && $data['numberOfOffers'] = $this->numberOfOffers;
871 ($includeAll || isset($intersect['highestOffer']))
872 && $data['highestOffer'] = $this->highestOffer;
873 ($includeAll || isset($intersect['loadedOnPriceGuide']))
874 && $data['loadedOnPriceGuide'] = !is_null($this->loadedOnPriceGuide)
875 ? $this->loadedOnPriceGuide->format($dateTimeFormat)
877 ($includeAll || isset($intersect['timesListed']))
878 && $data['timesListed'] = $this->timesListed;
879 ($includeAll || isset($intersect['highestBid']))
880 && $data['highestBid'] = $this->highestBid;
881 ($includeAll || isset($intersect['jobState']))
882 && $data['jobState'] = $this->jobState;
883 ($includeAll || isset($intersect['created']))
884 && $data['created'] = !is_null($this->created)
885 ? $this->created->format($dateTimeFormat)
887 ($includeAll || isset($intersect['updated']))
888 && $data['updated'] = !is_null($this->updated)
889 ? $this->updated->format($dateTimeFormat)
891 ($includeAll || isset($intersect['reset']))
892 && $data['reset'] = !is_null($this->reset)
893 ? $this->reset->format($dateTimeFormat)
899 * Internal utility to change accessories collection into array.
900 * @param boolean $showIdentifiers
903 public function accessoriesToArray($showIdentifiers = false)
906 $iterator = $this->accessories->getIterator();
907 if (2 == $showIdentifiers)
909 foreach ($iterator as $accessory)
911 $data[] = $accessory->accessory->id;
916 foreach ($iterator as $accessory)
918 $data[] = $showIdentifiers
919 ? array('id' => $accessory->accessory->id)
920 : $accessory->toArray();
927 * Internal utility to change damages collection into array.
928 * @param boolean $showIdentifiers
931 public function damagesToArray($showIdentifiers = false)
934 $iterator = $this->damages->getIterator();
935 foreach ($iterator as $damage)
937 $data[] = $damage->toArray(array(), array(), $showIdentifiers);
943 * Populate from an array.
946 public function fromArray($data = array())
949 && $this->id = $data['id'];
951 && $this->uvi = $data['uvi'];
952 isset($data['company'])
953 && $this->company = $data['company'];
954 isset($data['createdBy'])
955 && $this->createdBy = $data['createdBy'];
956 isset($data['region'])
957 && $this->region = $data['region'];
959 && $this->type = $data['type'];
960 isset($data['stockNumber'])
961 && $this->stockNumber = $data['stockNumber'];
962 isset($data['registrationNumber'])
963 && $this->registrationNumber = $data['registrationNumber'];
964 isset($data['vinNumber'])
965 && $this->vinNumber = $data['vinNumber'];
966 isset($data['engineNumber'])
967 && $this->engineNumber = $data['engineNumber'];
968 isset($data['fuelType'])
969 && $this->fuelType = $data['fuelType'];
970 isset($data['transmissionType'])
971 && $this->transmissionType = $data['transmissionType'];
972 isset($data['exteriorColour'])
973 && $this->exteriorColour = $data['exteriorColour'];
974 isset($data['interiorColour'])
975 && $this->interiorColour = $data['interiorColour'];
976 isset($data['condition'])
977 && $this->condition = $data['condition'];
978 isset($data['vehicleYear'])
979 && $this->vehicleYear = $data['vehicleYear'];
981 && $this->km = $data['km'];
982 isset($data['upholstery'])
983 && $this->upholstery = $data['upholstery'];
984 isset($data['papers'])
985 && $this->papers = $data['papers'];
986 isset($data['papersNotes'])
987 && $this->papersNotes = $data['papersNotes'];
988 isset($data['natis'])
989 && $this->natis = $data['natis'];
990 isset($data['spareKeys'])
991 && $this->spareKeys = $data['spareKeys'];
992 isset($data['fullServiceHistory'])
993 && $this->fullServiceHistory = $data['fullServiceHistory'];
994 isset($data['fshNotes'])
995 && $this->fshNotes = $data['fshNotes'];
996 isset($data['tradePrice'])
997 && $this->tradePrice = $data['tradePrice'];
998 isset($data['retailPrice'])
999 && $this->retailPrice = $data['retailPrice'];
1000 isset($data['listPrice'])
1001 && $this->listPrice = $data['listPrice'];
1002 isset($data['oldTradePrice'])
1003 && $this->oldTradePrice = $data['oldTradePrice'];
1004 isset($data['oldRetailPrice'])
1005 && $this->oldRetailPrice = $data['oldRetailPrice'];
1006 isset($data['oldListPrice'])
1007 && $this->oldListPrice = $data['oldListPrice'];
1008 isset($data['retailAmountRequired'])
1009 && $this->retailAmountRequired = $data['retailAmountRequired'];
1010 isset($data['mainImage'])
1011 && $this->mainImage = $data['mainImage'];
1012 isset($data['frontImage'])
1013 && $this->frontImage = $data['frontImage'];
1014 isset($data['rightImage'])
1015 && $this->rightImage = $data['rightImage'];
1016 isset($data['leftImage'])
1017 && $this->leftImage = $data['leftImage'];
1018 isset($data['backImage'])
1019 && $this->backImage = $data['backImage'];
1020 isset($data['interiorImage'])
1021 && $this->interiorImage = $data['interiorImage'];
1022 isset($data['engineImage'])
1023 && $this->engineImage = $data['engineImage'];
1024 isset($data['natisImage'])
1025 && $this->natisImage = $data['natisImage'];
1026 isset($data['accessoryNotes'])
1027 && $this->accessoryNotes = $data['accessoryNotes'];
1028 isset($data['damageTotal'])
1029 && $this->damageTotal = $data['damageTotal'];
1030 isset($data['damageNotes'])
1031 && $this->damageNotes = $data['damageNotes'];
1032 isset($data['previousRepairsNoted'])
1033 && $this->previousRepairsNoted = $data['previousRepairsNoted'];
1034 isset($data['previousRepairsNotes'])
1035 && $this->previousRepairsNotes = $data['previousRepairsNotes'];
1037 isset($data['coverReceived'])
1038 && $this->coverReceived = $data['coverReceived'];
1040 isset($data['numberOfOffers'])
1041 && $this->numberOfOffers = $data['numberOfOffers'];
1042 isset($data['highestOffer'])
1043 && $this->highestOffer = $data['highestOffer'];
1044 isset($data['loadedOnPriceGuide'])
1045 && $this->loadedOnPriceGuide = $data['loadedOnPriceGuide'];
1046 isset($data['jobState'])
1047 && $this->jobState = $data['jobState'];
1048 if (isset($data['accessories']))
1050 $em = \Utility\Registry::getEntityManager();
1052 foreach ($data['accessories'] as $acc)
1054 $newAccs[$acc['id']] = $acc['id'];
1056 $currentAccs = array();
1057 $iterator = $this->accessories->getIterator();
1058 foreach ($iterator as $acc)
1060 $currentAccs[$acc->accessory->id] = $acc->accessory->id;
1061 !isset($newAccs[$acc->accessory->id])
1062 && $em->remove($acc);
1064 foreach ($data['accessories'] as $acc)
1066 if (!isset($currentAccs[$acc['id']]))
1068 $stockAcc = new \Stock\Entity\StockAccessory();
1069 $stockAcc->accessory = $em->getReference('\Stock\Entity\Accessory', $acc['id']);
1070 $stockAcc->stock = $this;
1071 $this->accessories->add($stockAcc);
1075 if (isset($data['damages']))
1077 $em = \Utility\Registry::getEntityManager();
1080 foreach ($data['damages'] as $dmg)
1082 $total += $dmg['amount'];
1083 $newDmgs[$dmg['id']] = $dmg['amount'];
1085 $this->damageTotal = $total;
1086 $currentDmgs = array();
1087 $iterator = $this->damages->getIterator();
1088 foreach ($iterator as $dmg)
1090 $currentDmgs[$dmg->damage->id] = $dmg->damage->id;
1091 if (!isset($newDmgs[$dmg->damage->id]))
1097 $dmg->amount = $newDmgs[$dmg->damage->id];
1100 foreach ($data['damages'] as $dmg)
1102 if (!isset($currentDmgs[$dmg['id']]))
1104 $stockDamage = new \Stock\Entity\StockDamage();
1105 $stockDamage->damage = $em->getReference('\Stock\Entity\Damage', $dmg['id']);
1106 $stockDamage->amount = $dmg['amount'];
1107 $stockDamage->stock = $this;
1108 $this->damages->add($stockDamage);
1113 #-> Update de-normalized auction data.
1114 \Utility\Registry::getEntityManager()->createQuery(
1115 'UPDATE \Auction\Entity\Auction a '
1116 . "SET a.referenceNumber = :referenceNumber, "
1117 . " a.registrationNumber = :registrationNumber, "
1118 . " a.makeId = :makeId, "
1119 . " a.makeName = :makeName, "
1120 . " a.modelName = :modelName, "
1121 . " a.typeName = :typeName, "
1122 . " a.yearName = :yearName, "
1123 . " a.stockKm = :km "
1124 . 'WHERE a.jobState = :jobState '
1125 . ' AND IDENTITY(a.stock) = :id'
1127 ->setParameter('jobState', 'Active')
1128 ->setParameter('id', $this->id)
1129 ->setParameter('referenceNumber', $this->referenceNumber)
1130 ->setParameter('registrationNumber', $this->registrationNumber)
1131 ->setParameter('makeId', $this->type->model->make->id)
1132 ->setParameter('makeName', $this->type->model->make->name)
1133 ->setParameter('modelName', $this->type->model->name)
1134 ->setParameter('typeName', $this->type->name)
1135 ->setParameter('yearName', $this->vehicleYear->name)
1136 ->setParameter('km', $this->km)