6 class Complete extends \Utility\Service\PdfTemplate
14 protected $_title = 'Stock Information';
16 * @var \Stock\Entity\Stock
22 protected $showCustomerDetails = true;
26 protected $showValuationDetails = true;
30 protected $showPricingDetails = true;
34 protected $showVehicleDetails = true;
38 protected $showVehicleNotes = true;
42 protected $showDamageDetails = true;
47 protected $showAccessoryDetails = true;
51 protected $showSignatureLines = true;
55 protected $showTermsAndConditions = true;
59 protected $showOffersReceived = true;
63 protected $showOfferMade = true;
67 * Utility for easy parameter retrieval.
68 * @param string $param
69 * @param unknown $default
72 protected function getStockParam($param, $default)
74 return !is_null($this->jobRecord->$param)
75 ? $this->jobRecord->$param
80 * Utility for easy parameter retrieval.
81 * @param string $param
82 * @param unknown $default
85 protected function getStockSubParam($ref, $param, $default)
87 $ref = !is_null($this->jobRecord->$ref)
88 ? $this->jobRecord->$ref
90 return is_object($ref)
96 * Utility for easy parameter retrieval.
97 * @param string $param
98 * @param unknown $default
101 protected function getValuationParam($param, $default)
103 return !is_null($this->jobRecord->valuation)
104 && !is_null($this->jobRecord->valuation->$param)
105 ? $this->jobRecord->valuation->$param
113 public function build()
115 #-> Set data item to work with.
116 $this->jobRecord = $this->_input['jobRecord'];
117 $dateTimeFormat = \Utility\Definitions\Locale::getDateTimeFormat();
118 $currencyPrefix = \Utility\Definitions\Locale::getCurrencyPrefix();
119 $authData = \Utility\Registry::getAuthData();
120 $dateOfPrint = 'Date of print: <span style="color:#333;">' . date('Y-m-d H:i:s') . '</span>';
121 $printedBy = 'Printed by: <span style="color:#333;">' . $authData['firstName']
122 . ' ' . $authData['familyName'] . '</span>';
123 $referenceNo = 'Reference no.: <span style="color:#333;">' . $this->jobRecord->referenceNumber . '</span>';
126 /* --------------------------------- CUSTOMER, VALUATION, PRICING --------------------------------- */
127 $type = $this->jobRecord->type;
129 '<br /><div style="font-size:16px;font-weight:bold;">'
130 . $type->model->make->name . ' '
131 . $type->model->name . ' '
133 . $type->introYear->name . ' - '
134 . (!is_null($type->discYear) ? $type->discYear->name : 'Current') . ')'
135 . '</div><hr /><br />'
139 /* --------------------------------- CUSTOMER, VALUATION, PRICING --------------------------------- */
141 $customerDetail = ' ';
142 if ($this->showCustomerDetails)
144 $table = $this->newTable(
146 'padding:0;margin:0;font-size:10px;',
148 'padding:2px 3px 2px 0;margin:0;'
150 $department = $this->getValuationParam('department', null);
151 $department = !is_null($department)
155 ->addTitle('Customer', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
156 ->addKeyValueDataSet(array(
157 'Customer name:' => $this->getValuationParam('firstName', ''),
158 'Customer surname:' => $this->getValuationParam('familyName', ''),
159 'ID:' => $this->getValuationParam('idNumber', ''),
160 'Mobile:' => $this->getValuationParam('mobile', ''),
161 'Email:' => $this->getValuationParam('email', ''),
162 'Department:' => $department,
163 'Address:' => ' ',
164 '<span style="color:#FFF;font-size:20px;">a1</span>' => ' ',
165 '<span style="color:#FFF;font-size:10px;">1</span><span style="color:#000;font-size:10px;">______________________________________</span>' => ' ',
166 '<span style="color:#FFF;font-size:20px;">a</span>' => ' ',
167 '<span style="color:#FFF;font-size:10px;">2</span><span style="color:#000;font-size:10px;">______________________________________</span>' => ' ',
168 '<span style="color:#FFF;font-size:20px;">b</span>' => ' ',
169 '<span style="color:#FFF;font-size:10px;">3</span><span style="color:#000;font-size:10px;">______________________________________</span>' => ' '
170 ), 0, 'font-weight:bold;', 'color:#000;');
171 $customerDetail = $table->publish();
175 $valuationDetail = ' ';
176 if ($this->showValuationDetails)
178 $table = $this->newTable(
180 'padding:0;margin:0;font-size:10px;',
182 'padding:2px 3px 2px 0;margin:0;'
185 ->getRepository('\PriceGuide\Entity\PriceGuide')
186 ->findOneBy(array('stock' => $this->jobRecord));
187 $pgLoaded = !is_null($pgItem)
188 ? $pgItem->created->format($dateTimeFormat)
190 $valCreated = $this->getValuationParam('created', null);
191 $valCreated = !is_null($valCreated)
192 ? $valCreated->format($dateTimeFormat)
195 ->addTitle('Valuation details', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
196 ->addKeyValueDataSet(array(
197 'Date created:' => $valCreated,
198 'Valuation no.:' => $this->getValuationParam('valuationNumber', ''),
199 'Reference no.:' => $this->getStockParam('referenceNumber', ''),
200 'Date loaded on price guide:' => $pgLoaded,
201 'Cover Received:' => $this->getStockParam('coverReceived', '')
202 ), 0, 'font-weight:bold;', 'color:#F00;');
203 $valuationDetail = $table->publish();
207 $pricingDetail = ' ';
208 $total = $this->getValuationParam('overAllowance', '0.00') + $this->getValuationParam('amountOffered', '0.00');
209 $total = number_format($total, 2, '.', '');
210 if ($this->showPricingDetails)
212 $table = $this->newTable(
214 'padding:0;margin:0;font-size:10px;',
216 'padding:2px 3px 2px 0;margin:0;'
219 ->addTitle('Pricing details', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
220 ->addKeyValueDataSet(array(
221 'Trade:' => $currencyPrefix . $this->getStockParam('tradePrice', '0.00'),
222 'Retail:' => $currencyPrefix . $this->getStockParam('retailPrice', '0.00'),
223 'List:' => $currencyPrefix . $this->getStockParam('listPrice', '0.00'),
224 'Amount offered:' => $currencyPrefix . $this->getValuationParam('amountOffered', '0.00'),
225 'O.A.:' => $currencyPrefix . $this->getValuationParam('overAllowance', '0.00'),
226 'Total offer:' => $currencyPrefix . $total, // total offer = amount offered + O.A
227 'Projected retail:' => $currencyPrefix . $this->getValuationParam('projectedRetail', '0.00'),
228 'Planned margin:' => $currencyPrefix . $this->getValuationParam('plannedMargin', '0.00'),
229 'Price guide highest offer:' => $currencyPrefix . $this->getStockParam('highestOffer', '0.00')
230 ), 0, 'font-weight:bold;', 'color:#F00;');
231 $pricingDetail = $table->publish();
234 #-> First row of data-blocks.
235 if ($this->showCustomerDetails
236 || $this->showValuationDetails
237 || $this->showPricingDetails)
241 array(30, 5, 30, 5, 30),
242 'margin:0;font-size:10px;vertical-align:top;',
244 'padding:10px 0 0 0;'
246 ->setCellValue(0, 0, $customerDetail)
247 ->setCellValue(0, 2, $valuationDetail)
248 ->setCellValue(0, 4, $pricingDetail);
249 $this->append($container->publish() . '<br />');
253 /* --------------------------------- VEHICLE, DAMAGES, ACCESSORIES --------------------------------- */
256 $vehicleDetail = ' ';
257 if ($this->showVehicleDetails)
259 $keys = $this->getStockParam('spareKeys', null);
270 $table = $this->newTable(
272 'padding:0;margin:0;font-size:10px;',
274 'padding:2px 3px 2px 0;margin:0;'
277 ->addTitle('Vehicle specifications', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
278 ->addKeyValueDataSet(array(
279 'Year:' => $this->getStockSubParam('vehicleYear', 'name', ''),
280 'Category:' => $type->category->name,
281 'Make:' => $type->model->make->name,
282 'Model:' => $type->model->name,
283 'Type:' => $type->name,
284 'Registration no.:' => $this->getStockParam('registrationNumber', ''),
285 'Fuel type:' => $this->getStockSubParam('fuelType', 'name', ''),
286 'Transmission type:' => $this->getStockSubParam('transmissionType', 'name', ''),
287 'VIN no.:' => $this->getStockParam('vinNumber', ''),
288 'Engine no.:' => $this->getStockParam('engineNumber', ''),
289 'MM code:' => $type->mmCode,
290 'Kms:' => $this->getStockParam('km', ''),
291 'Condition:' => $this->getStockSubParam('condition', 'name', ''),
292 'Main exterior colour:' => $this->getStockSubParam('exteriorColour', 'name', ''),
293 'Main interior colour:' => $this->getStockSubParam('interiorColour', 'name', ''),
294 'Upholstery:' => $this->getStockSubParam('upholstery', 'name', ''),
295 'Papers:' => $this->getStockSubParam('papers', 'name', ''),
296 'Papers comments:' => $this->getStockParam('papersNotes', ''),
297 'Natis:' => $this->getStockSubParam('natis', 'name', ''),
298 'Spare keys:' => $keys,
299 'FSH:' => $this->getStockSubParam('fullServiceHistory', 'name', ''),
300 'FSH comments:' => $this->getStockParam('fshNotes', '')
301 ), 0, '', 'color:#000;');
302 $vehicleDetail = $table->publish();
306 $damagesDetail = ' ';
307 if ($this->showDamageDetails)
309 $damageData = array();
310 $damages = $this->jobRecord->damagesToArray();
311 foreach ($damages as $damage)
313 $damageData[$damage['damage']['name'] . ':'] = $currencyPrefix . $damage['amount'];
315 $damageData['Total estimated repair cost:'] =
316 '<span style="color:#F00;">' . $currencyPrefix . $this->getStockParam('damageTotal', '') . '</span>';
317 $damageData['Damages comments:'] = $this->getStockParam('damageNotes', '');
318 $damageData['Previous repairs noted:'] = $this->getStockParam('previousRepairsNoted', false)
321 $damageData['Previous repairs comments:'] = $this->getStockParam('previousRepairsNotes', '');
322 $table = $this->newTable(
324 'padding:0;margin:0;font-size:10px;',
326 'padding:2px 3px 2px 0;margin:0;'
328 $type = $this->jobRecord->type;
330 ->addTitle('Damages', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
331 ->addKeyValueDataSet($damageData, 0, '', 'color:#000;');
332 $damagesDetail = $table->publish();
336 $accessoriesDetail = ' ';
337 if ($this->showAccessoryDetails)
341 $accessories = $this->jobRecord->accessoriesToArray();
342 foreach ($accessories as $accessory)
344 $accs[] = $accessory['accessory']['name'];
348 for ($i = 0; $i <= count($accs); $i += 2)
350 if (isset($accs[$i]))
352 $accData[$accs[$i]] = isset($accs[$i + 1])
358 $accData['<span style="color:#000;font-size:10px;">Comments:</span>'] =
359 '<span style="color:#000;font-size:10px;">' . $this->getStockParam('accessoryNotes', '') . '</span>';
360 $table = $this->newTable(
362 'padding:0;margin:0;font-size:9px;',
364 'padding:2px 3px 2px 0;margin:0;'
366 $type = $this->jobRecord->type;
368 ->addTitle('Accessories', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
369 ->addKeyValueDataSet($accData, 0, 'color:#000;', 'color:#000;');
370 $accessoriesDetail = $table->publish();
373 #-> Second row of data-blocks.
374 if ($this->showVehicleDetails
375 || $this->showDamageDetails
376 || $this->showAccessoryDetails)
380 array(30, 5, 30, 5, 30),
381 'margin:0;font-size:10px;vertical-align:top;',
383 'padding:10px 0 0 0;'
385 ->setCellValue(0, 0, $vehicleDetail)
386 ->setCellValue(0, 2, $damagesDetail)
387 ->setCellValue(0, 4, $accessoriesDetail);
388 $this->append($container->publish() . '<br />');
391 /* --------------------------------- VEHICLE NOTES --------------------------------- */
393 $VehicleNotes = ' ';
394 if ($this->showVehicleNotes)
396 $table = $this->newTable(
398 'padding:0;margin:0;font-size:10px;',
400 'padding:15px 15px 15px 0;margin:0;'
404 '1______________________________________________________________________________________________________________________________________' => ' ',
405 '2______________________________________________________________________________________________________________________________________' => ' ',
406 '3______________________________________________________________________________________________________________________________________' => ' '
410 ->addTitle('Notes:', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
411 ->addKeyValueDataSet($dSet, 0, '', 'color:#000;');
412 $VehicleNotes = $table->publish();
414 #-> Third row of data-blocks.
415 if ($this->showVehicleNotes)
419 array(30, 5, 30, 5, 30),
420 'margin:0;font-size:10px;vertical-align:top;',
422 'padding:10px 0 0 0;'
424 ->setCellValue(0, 0, $VehicleNotes);
425 $this->append($container->publish() . '<br />');
429 /* --------------------------------- SIGNATURES --------------------------------- */
431 if ($this->showSignatureLines)
434 $this->newSignatureLine()
435 ->addSignatureLine('Customer (name)', 'Signature', 'Date')
436 ->addSignatureLine('Manager (name)', 'Signature', 'Date')
442 '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
443 . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
445 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
446 . $dateOfPrint . '</i></td>'
447 . '<td style="width:5%"> </td>'
448 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
449 . $printedBy . '</i></td>'
450 . '<td style="width:5%"> </td>'
451 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
452 . $referenceNo . '</i></td>'
461 /* --------------------------------- OFFERS RECEIVED/MADE --------------------------------- */
463 if ($this->showOffersReceived || $this->showOfferMade)
466 $this->append('<br/>');
468 if ($this->showOffersReceived)
472 ->getRepository('\PriceGuide\Entity\PriceGuide')
473 ->findBy(array('stock' => $this->jobRecord));
474 if (!empty($pgItems))
476 foreach ($pgItems as $pgItem)
478 $iterator = $pgItem->offers->getIterator();
479 foreach ($iterator as $offer)
481 $status = $offer->status;
483 $offer->company->name,
484 $offer->created->format($dateTimeFormat),
485 $currencyPrefix . $offer->amount,
486 $offer->profile->mobile,
487 $offer->profile->email,
493 $table = $this->newTable(
494 array(20, 15, 15, 10, 30, 10),
495 'padding:0;margin:0;font-size:10px;',
497 'padding:2px 5px 2px 2px;margin:0;'
500 ->addTitle('Offers received', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
501 ->setColumnHeaders(array(
502 'Buyer', 'Date', 'Offer', 'Mobile', 'Email', 'Status'
503 ), array(20, 15, 15, 10, 30, 10),
504 'padding:2px 2px 2px 5px;background-color:#F00;color:#FFF;font-weight:bold;font-size:10px;')
505 ->setDataSet($offers);
506 $this->append($table->publish() . '<br />');
510 if ($this->showOfferMade)
514 ->getRepository('\PriceGuide\Entity\PriceGuide')
515 ->findOneBy(array('stock' => $this->jobRecord));
516 if (!is_null($pgItem))
518 $companyId = \Utility\Registry::resolveCompanyContext();
519 $iterator = $pgItem->offers->getIterator();
520 foreach ($iterator as $offer)
522 $status = $offer->status;
524 $offer->company->name,
525 $offer->created->format($dateTimeFormat),
526 $currencyPrefix . $offer->amount,
527 $offer->profile->mobile,
528 $offer->profile->email,
533 $table = $this->newTable(
534 array(20, 15, 15, 10, 30, 10),
535 'padding:0;margin:0;font-size:10px;',
537 'padding:2px 5px 2px 2px;margin:0;'
540 ->addTitle('Offers made', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
541 ->setColumnHeaders(array(
542 'Buyer', 'Date', 'Offer', 'Mobile', 'Email', 'Status'
543 ), array(20, 15, 15, 10, 30, 10),
544 'padding:2px 2px 2px 5px;background-color:#F00;color:#FFF;font-weight:bold;font-size:10px;')
545 ->setDataSet($offers);
546 $this->append($table->publish() . '<br />');
550 '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
551 . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
553 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
554 . $dateOfPrint . '</i></td>'
555 . '<td style="width:5%"> </td>'
556 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
557 . $printedBy . '</i></td>'
558 . '<td style="width:5%"> </td>'
559 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
560 . $referenceNo . '</i></td>'
570 /* --------------------------------- TERMS AND CONDITIONS --------------------------------- */
571 #-> Terms and Conditions.
572 if ($this->showTermsAndConditions)
575 $this->append('<br/>');
577 $table = $this->newTable(
579 'padding:0;margin:0;font-size:9px;',
581 'padding:2px 3px 2px 0;margin:0;'
583 $type = $this->jobRecord->type;
585 ->addTitle('Terms and Conditions', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
586 ->addKeyValueDataSet(array(
587 'I acknowledge, confirm and agree that:' => '',
588 '1. Ownership' => '',
589 '1.1. I am the owner of my trade-in vehicle and I am legally allowed to sell my trade-in vehicle.' => 'Yes / No',
590 '1.2. I am a South African resident.' => 'Yes / No',
591 '1.3. My trade-in vehicle is not subject to a claim of any nature whatsoever by any other person or entity and I '
592 . 'indemnify the Dealer against any claims of any ' => 'Yes / No',
593 '1.4. If my trade-in vehicle is subject to any claim by any other person or entity, the Dealer will not be bound '
594 . 'to this valuation.' => 'Yes / No',
595 '2. VAT Registration' => '',
596 'This transaction is subject to the payment of VAT.' => 'Yes / No',
597 '3. Status of the Vehicle' => '',
598 '3.1. My trade-in vehicle was new when I purchased it.' => 'Yes / No',
599 '3.2. My trade-in vehicle has been used for self-drive hire or taxi work.' => 'Yes / No',
600 '3.3. My trade-in vehicle has a full service history.' => 'Yes / No',
601 '3.4. My trade in vehicle has not been involved in any accident.' => 'Yes / No',
602 '3.5. If my trade-in vehicle has been involved in an accident, there was a total loss claim made (Stolen & Recovered).' => 'Yes / No',
603 '3.6. A current registration paper has been handed over by me.' => 'Yes / No',
604 '3.7. I have supplied the owners and service manuals to the Dealer.' => 'Yes / No',
605 '3.8. My trade-in vehicle is subject to a service and/or maintenance plan and/or warranty.' => 'Yes / No',
606 '4. Status of the Vehicle' => '',
607 'The Dealer will only be bound by its appraised trade-in value of my trade-in vehicle as far as the trade-in has '
608 . 'been approved and accepted in writing by either the dealer principle, designated sales manager or used car manager'
609 . ' and the parties have entered into the Dealer\'s standard Offer to Purchase in respect of my trade-in vehicle.' => '',
610 '5. Outstanding Finance' => '',
611 '5.1. The Dealer, in its absolute and sole discretion, may agree to settle the existing finance in lieu of payment '
612 . '(or part payment) of the trade-in vehicle to me.' => '',
613 '5.2. If the agreed trade-in allowance of the trade-in vehicle is lower than the settlement figure in clause 5.1 above, '
614 . 'I must pay the Registered Credit Provider the difference between the settlement figure and the trade-in allowance with '
615 . 'proof of such payment (made to the registered Credit Provider) submitted to the Dealer prior to the signing of the Offer to Purchase.' => '',
616 '5.3. I will remain liable to the registered Credit Provider in respect of the related finance at all times until the '
617 . 'credit Agreement has been legally terminated.' => '',
618 '5.4. For purposes of clarity, the Dealer does not accept any liability with respect to the related finance set out in '
619 . 'clause 5.4 above at any time or for any reason.' => '',
620 '5.5. The Dealer will use its best endeavors to pay the trade-in allowance to the registered Credit Provider as soon as '
621 . 'is reasonably possible. However the Dealer accepts no liability for any costs or liability incurred by me as a result '
622 . 'of any delay in the payment by the Dealer.' => '',
623 '6. No Financial Advice' => '',
624 'This trade-in valuation does not constitute financial advice to me as contemplated in the Financial Advisory and '
625 . 'Intermediary Services Act 37 of 2002 but is subject to the Consumer Protection Act 68 of 2008.' => '',
627 'The risk of damage or loss in and to the trade-in vehicle will pass from me to the Dealer only once the Dealer has '
628 . 'taken possession of my trade-in vehicle and has received the proper documentation from me to enable it to re-register my trade-in vehicle.' => '',
629 '8. The Dealer\'s right to withdraw from the offer' => '',
630 'The Dealer is bound by this offer only in so far as:' => '',
631 '8.1. I have signed an Offer to Purchase with the same Dealer in respect of this valuation; and' => '',
632 '8.2. Fewer than 7 (seven) days have passed since the issuing of this valuation; and' => '',
633 '8.3. My trade-in vehicle is in the same condition as the date of inspection; and' => '',
634 '8.4. This trade-in valuation was signed by the Valuator and the Manager of the Dealer.' => '',
635 ' <br /> ' => '',
636 'I HAVE READ THE ABOVE TERMS AND CONDITIONS AND CONFIRM MY UNDERSTANDING AND AGREE TO BE BOUND THERETO.' => '',
637 ' <br /> ' => '',
639 'By signing this form, I agree to the [Dealership Name] valuation terms and conditions above.' => '',
640 ' <br /> <br /> <br /> <br /> <br />' => '',
641 '<b>Signature:</b>' => '',
643 'Date: ' . date('Y-m-d') => ''
644 ), 0, 'color:#333;', 'color:#000;');
645 $this->append($table->publish() . '<br />');
648 '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
649 . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
651 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
652 . $dateOfPrint . '</i></td>'
653 . '<td style="width:5%"> </td>'
654 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
655 . $printedBy . '</i></td>'
656 . '<td style="width:5%"> </td>'
657 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#000;"><i>'
658 . $referenceNo . '</i></td>'