2 namespace PriceGuide\Pdf;
6 class Complete extends \Utility\Service\PdfTemplate
14 protected $_title = 'Stock Information';
16 * @var \Stock\Entity\Stock
22 protected $showTradeDataOnly = true;
26 protected $showCustomerDetails = false;
30 protected $showValuationDetails = true;
34 protected $showPricingDetails = true;
38 protected $showVehicleDetails = true;
42 protected $showDamageDetails = true;
46 protected $showAccessoryDetails = true;
50 protected $showSignatureLines = true;
54 protected $showTermsAndConditions = true;
58 protected $showOffersReceived = true;
62 protected $showOfferMade = true;
66 * Utility for easy parameter retrieval.
67 * @param string $param
68 * @param unknown $default
71 protected function getStockParam($param, $default)
73 return !is_null($this->jobRecord->$param)
74 ? $this->jobRecord->$param
79 * Utility for easy parameter retrieval.
80 * @param string $param
81 * @param unknown $default
84 protected function getStockSubParam($ref, $param, $default)
86 $ref = !is_null($this->jobRecord->$ref)
87 ? $this->jobRecord->$ref
89 return is_object($ref)
95 * Utility for easy parameter retrieval.
96 * @param string $param
97 * @param unknown $default
100 protected function getValuationParam($param, $default)
102 return !is_null($this->jobRecord->valuation)
103 && !is_null($this->jobRecord->valuation->$param)
104 ? $this->jobRecord->valuation->$param
112 public function build()
114 #-> Set data item to work with.
115 $this->jobRecord = $this->_input['jobRecord']->stock;
116 $dateTimeFormat = \Utility\Definitions\Locale::getDateTimeFormat();
117 $currencyPrefix = \Utility\Definitions\Locale::getCurrencyPrefix();
118 $authData = \Utility\Registry::getAuthData();
119 $dateOfPrint = 'Date of print: <span style="color:#333;">' . date('Y-m-d H:i:s') . '</span>';
120 $printedBy = 'Printed by: <span style="color:#333;">' . $authData['firstName']
121 . ' ' . $authData['familyName'] . '</span>';
122 $referenceNo = 'Reference no.: <span style="color:#333;">' . $this->jobRecord->referenceNumber . '</span>';
125 /* --------------------------------- CUSTOMER, VALUATION, PRICING --------------------------------- */
126 $type = $this->jobRecord->type;
128 '<br /><div style="font-size:16px;font-weight:bold;">'
129 . $type->model->make->name . ' '
130 . $type->model->name . ' '
132 . $type->introYear->name . ' - '
133 . (!is_null($type->discYear) ? $type->discYear->name : 'Current') . ')'
134 . '</div><hr /><br />'
138 /* --------------------------------- CUSTOMER, VALUATION, PRICING --------------------------------- */
140 $customerDetail = ' ';
141 if ($this->showCustomerDetails)
143 $table = $this->newTable(
145 'padding:0;margin:0;font-size:10px;',
147 'padding:2px 3px 2px 0;margin:0;'
149 $department = $this->getValuationParam('department', null);
150 $department = !is_null($department)
154 ->addTitle('Customer', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
155 ->addKeyValueDataSet(array(
156 'Customer name:' => $this->getValuationParam('firstName', ''),
157 'Customer surname:' => $this->getValuationParam('familyName', ''),
158 'ID:' => $this->getValuationParam('idNumber', ''),
159 'Mobile:' => $this->getValuationParam('mobile', ''),
160 'Email:' => $this->getValuationParam('email', ''),
161 'Department:' => $department
162 ), 0, 'font-weight:bold;', 'color:#666;');
163 $customerDetail = $table->publish();
165 #-> Customer alternated with dealership details for traders.
166 if ($this->showTradeDataOnly)
168 $table = $this->newTable(
170 'padding:0;margin:0;font-size:10px;',
172 'padding:2px 3px 2px 0;margin:0;'
174 $department = $this->getValuationParam('department', null);
175 $department = !is_null($department)
178 $contact = $this->getStockSubParam('company', 'contact', null);
180 ->addTitle('Dealership', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
181 ->addKeyValueDataSet(array(
182 'Dealership name:' => $this->getStockSubParam('company', 'name', ''),
183 'Contact:' => !is_null($contact) ? $contact->firstName . ' ' . $contact->familyName : '',
184 'Mobile:' => !is_null($contact) ? $contact->mobile : '',
185 'Email:' => !is_null($contact) ? $contact->email : ''
186 ), 0, 'font-weight:bold;', 'color:#666;');
187 $customerDetail = $table->publish();
191 $valuationDetail = ' ';
192 if ($this->showValuationDetails)
194 $table = $this->newTable(
196 'padding:0;margin:0;font-size:10px;',
198 'padding:2px 3px 2px 0;margin:0;'
201 ->getRepository('\PriceGuide\Entity\PriceGuide')
202 ->findOneBy(array('stock' => $this->jobRecord));
203 $pgLoaded = !is_null($pgItem)
204 ? $pgItem->created->format($dateTimeFormat)
206 $valCreated = $this->getValuationParam('created', null);
207 $valCreated = !is_null($valCreated)
208 ? $valCreated->format($dateTimeFormat)
211 ->addTitle('Valuation details', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
212 ->addKeyValueDataSet($this->showTradeDataOnly
214 'Date created:' => $valCreated,
215 'Date loaded on price guide:' => $pgLoaded
218 'Date created:' => $valCreated,
219 'Valuation no.:' => $this->getValuationParam('valuationNumber', ''),
220 'Reference no.:' => $this->getStockParam('referenceNumber', ''),
221 'Date loaded on price guide:' => $pgLoaded
222 ), 0, 'font-weight:bold;', 'color:#F00;');
223 $valuationDetail = $table->publish();
227 $pricingDetail = ' ';
228 $total = $this->getValuationParam('overAllowance', '0.00') + $this->getValuationParam('amountOffered', '0.00');
229 $total = number_format($total, 2, '.', '');
230 if ($this->showPricingDetails)
232 $table = $this->newTable(
234 'padding:0;margin:0;font-size:10px;',
236 'padding:2px 3px 2px 0;margin:0;'
239 ->addTitle('Pricing details', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
240 ->addKeyValueDataSet($this->showTradeDataOnly
242 'Trade:' => $currencyPrefix . $this->getStockParam('tradePrice', '0.00'),
243 'Retail:' => $currencyPrefix . $this->getStockParam('retailPrice', '0.00'),
244 'List:' => $currencyPrefix . $this->getStockParam('listPrice', '0.00')
247 'Trade:' => $currencyPrefix . $this->getStockParam('tradePrice', '0.00'),
248 'Retail:' => $currencyPrefix . $this->getStockParam('retailPrice', '0.00'),
249 'List:' => $currencyPrefix . $this->getStockParam('listPrice', '0.00'),
250 'Amount offered:' => $currencyPrefix . $this->getValuationParam('amountOffered', '0.00'),
251 'O.A.:' => $currencyPrefix . $this->getValuationParam('overAllowance', '0.00'),
252 'Total Offer:' => $total, // total offer = amount offered + O.A
253 'Projected retail:' => $currencyPrefix,
254 'Planned margin:' => $currencyPrefix,
255 'Price Guide highest offer:' => $currencyPrefix . $this->getStockParam('highestOffer', '0.00')
256 ), 0, 'font-weight:bold;', 'color:#F00;');
257 $pricingDetail = $table->publish();
260 #-> First row of data-blocks.
261 if ($this->showCustomerDetails
262 || $this->showValuationDetails
263 || $this->showPricingDetails)
267 array(30, 5, 30, 5, 30),
268 'margin:0;font-size:10px;vertical-align:top;',
270 'padding:10px 0 0 0;'
272 ->setCellValue(0, 0, $customerDetail)
273 ->setCellValue(0, 2, $valuationDetail)
274 ->setCellValue(0, 4, $pricingDetail);
275 $this->append($container->publish() . '<br />');
279 /* --------------------------------- VEHICLE, DAMAGES, ACCESSORIES --------------------------------- */
282 $vehicleDetail = ' ';
283 if ($this->showVehicleDetails)
285 $keys = $this->getStockParam('spareKeys', null);
296 $table = $this->newTable(
298 'padding:0;margin:0;font-size:10px;',
300 'padding:2px 3px 2px 0;margin:0;'
303 ->addTitle('Vehicle specifications', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
304 ->addKeyValueDataSet(array(
305 'Year:' => $this->getStockSubParam('vehicleYear', 'name', ''),
306 'Category:' => $type->category->name,
307 'Make:' => $type->model->make->name,
308 'Model:' => $type->model->name,
309 'Type:' => $type->name,
310 'Registration no.:' => $this->getStockParam('registrationNumber', ''),
311 'Fuel type:' => $this->getStockSubParam('fuelType', 'name', ''),
312 'Transmission type:' => $this->getStockSubParam('transmissionType', 'name', ''),
313 'VIN no.:' => $this->getStockParam('vinNumber', ''),
314 'Engine no.:' => $this->getStockParam('engineNumber', ''),
315 'MM code:' => $type->mmCode,
316 'Kms:' => $this->getStockParam('km', ''),
317 'Condition:' => $this->getStockSubParam('condition', 'name', ''),
318 'Main exterior colour:' => $this->getStockSubParam('exteriorColour', 'name', ''),
319 'Main interior colour:' => $this->getStockSubParam('interiorColour', 'name', ''),
320 'Upholstery:' => $this->getStockSubParam('upholstery', 'name', ''),
321 'Papers:' => $this->getStockSubParam('papers', 'name', ''),
322 'Papers comments:' => $this->getStockParam('papersNotes', ''),
323 'Natis:' => $this->getStockSubParam('natis', 'name', ''),
324 'Spare keys:' => $keys,
325 'FSH:' => $this->getStockSubParam('fullServiceHistory', 'name', ''),
326 'FSH comments:' => $this->getStockParam('fshNotes', '')
327 ), 0, '', 'color:#666;');
328 $vehicleDetail = $table->publish();
332 $damagesDetail = ' ';
333 if ($this->showDamageDetails)
335 $damageData = array();
336 $damages = $this->jobRecord->damagesToArray();
337 foreach ($damages as $damage)
339 $damageData[$damage['damage']['name'] . ':'] = $currencyPrefix . $damage['amount'];
341 $damageData['Total estimated repair cost:'] =
342 '<span style="color:#F00;">' . $currencyPrefix . $this->getStockParam('damageTotal', '') . '</span>';
343 $damageData['Damages comments:'] = $this->getStockParam('damageNotes', '');
344 $damageData['Previous repairs noted:'] = $this->getStockParam('previousRepairsNoted', false)
347 $damageData['Previous repairs comments:'] = $this->getStockParam('previousRepairsNotes', '');
348 $table = $this->newTable(
350 'padding:0;margin:0;font-size:10px;',
352 'padding:2px 3px 2px 0;margin:0;'
354 $type = $this->jobRecord->type;
356 ->addTitle('Damages', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
357 ->addKeyValueDataSet($damageData, 0, '', 'color:#666;');
358 $damagesDetail = $table->publish();
362 $accessoriesDetail = ' ';
363 if ($this->showAccessoryDetails)
367 $accessories = $this->jobRecord->accessoriesToArray();
368 foreach ($accessories as $accessory)
370 $accs[] = $accessory['accessory']['name'];
374 for ($i = 0; $i <= count($accs); $i += 2)
376 if (isset($accs[$i]))
378 $accData[$accs[$i]] = isset($accs[$i + 1])
384 $accData['<span style="color:#000;font-size:10px;">Comments:</span>'] =
385 '<span style="color:#666;font-size:10px;">' . $this->getStockParam('accessoryNotes', '') . '</span>';
386 $table = $this->newTable(
388 'padding:0;margin:0;font-size:9px;',
390 'padding:2px 3px 2px 0;margin:0;'
392 $type = $this->jobRecord->type;
394 ->addTitle('Accessories', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
395 ->addKeyValueDataSet($accData, 0, 'color:#666;', 'color:#666;');
396 $accessoriesDetail = $table->publish();
399 #-> Second row of data-blocks.
400 if ($this->showVehicleDetails
401 || $this->showDamageDetails
402 || $this->showAccessoryDetails)
406 array(30, 5, 30, 5, 30),
407 'margin:0;font-size:10px;vertical-align:top;',
409 'padding:10px 0 0 0;'
411 ->setCellValue(0, 0, $vehicleDetail)
412 ->setCellValue(0, 2, $damagesDetail)
413 ->setCellValue(0, 4, $accessoriesDetail);
414 $this->append($container->publish() . '<br />');
419 /* --------------------------------- SIGNATURES --------------------------------- */
421 if ($this->showSignatureLines)
424 $this->newSignatureLine()
425 ->addSignatureLine('Customer (name)', 'Signature', 'Date')
426 ->addSignatureLine('Manager (name)', 'Signature', 'Date')
432 '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
433 . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
435 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
436 . $dateOfPrint . '</i></td>'
437 . '<td style="width:5%"> </td>'
438 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
439 . $printedBy . '</i></td>'
440 . '<td style="width:5%"> </td>'
441 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
442 . $referenceNo . '</i></td>'
451 /* --------------------------------- OFFERS RECEIVED/MADE --------------------------------- */
453 if ($this->showOffersReceived || $this->showOfferMade)
455 \Utility\Debug::errorLog('showingoffers' , 'here');
457 if ($this->showOffersReceived)
461 ->getRepository('\PriceGuide\Entity\PriceGuide')
462 ->findOneBy(array('stock' => $this->jobRecord));
463 if (!is_null($pgItem))
466 $this->append('<br/>');
467 \Utility\Debug::errorLog('item1' ,'added');
469 $iterator = $pgItem->offers->getIterator();
470 foreach ($iterator as $offer)
472 $status = $offer->status;
474 $offer->company->name,
475 $offer->created->format($dateTimeFormat),
476 $currencyPrefix . $offer->amount,
477 $offer->profile->mobile,
478 $offer->profile->email,
482 if(1==sizeof($offers)){
484 $this->append('<br/>');
485 \Utility\Debug::errorLog('OffersReceived' ,'has values');
487 $table = $this->newTable(
488 array(20, 15, 15, 10, 30, 10),
489 'padding:0;margin:0;font-size:10px;',
491 'padding:2px 5px 2px 2px;margin:0;'
494 ->addTitle('Offers received', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
495 ->setColumnHeaders(array(
496 'Buyer', 'Date', 'Offer', 'Mobile', 'Email', 'Status'
497 ), array(20, 15, 15, 10, 30, 10),
498 'padding:2px 2px 2px 5px;background-color:#F00;color:#FFF;font-weight:bold;font-size:10px;')
499 ->setDataSet($offers);
500 $this->append($table->publish() . '<br />');
509 if ($this->showOfferMade)
513 ->getRepository('\PriceGuide\Entity\PriceGuide')
514 ->findOneBy(array('stock' => $this->jobRecord));
515 if (!is_null($pgItem))
517 $company = \Utility\Registry::resolveCompanyContext();
518 $iterator = $pgItem->offers->getIterator();
519 foreach ($iterator as $offer)
521 $status = $offer->status;
522 if ($offer->company->id != $company->id)
527 $offer->company->name,
528 $offer->created->format($dateTimeFormat),
529 $currencyPrefix . $offer->amount,
530 $offer->profile->mobile,
531 $offer->profile->email,
535 //create new page only once and only when offers array has the first item
536 if(1==sizeof($offers)){
538 $this->append('<br/>');
539 \Utility\Debug::errorLog('OfferMade' ,'has values');
540 $table = $this->newTable(
541 array(20, 15, 15, 10, 30, 10),
542 'padding:0;margin:0;font-size:10px;',
544 'padding:2px 5px 2px 2px;margin:0;'
547 ->addTitle('Offers made', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
548 ->setColumnHeaders(array(
549 'Buyer', 'Date', 'Offer', 'Mobile', 'Email', 'Status'
550 ), array(20, 15, 15, 10, 30, 10),
551 'padding:2px 2px 2px 5px;background-color:#F00;color:#FFF;font-weight:bold;font-size:10px;')
552 ->setDataSet($offers);
553 $this->append($table->publish() . '<br />');
561 '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
562 . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
564 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
565 . $dateOfPrint . '</i></td>'
566 . '<td style="width:5%"> </td>'
567 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
568 . $printedBy . '</i></td>'
569 . '<td style="width:5%"> </td>'
570 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
571 . $referenceNo . '</i></td>'
581 /* --------------------------------- TERMS AND CONDITIONS --------------------------------- */
582 #-> Terms and Conditions.
583 if ($this->showTermsAndConditions)
586 $this->append('<br/>');
588 $table = $this->newTable(
590 'padding:0;margin:0;font-size:9px;',
592 'padding:2px 3px 2px 0;margin:0;'
594 $type = $this->jobRecord->type;
596 ->addTitle('Terms and Conditions', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
597 ->addKeyValueDataSet(array(
598 'I acknowledge, confirm and agree that:' => '',
599 '1. Ownership' => '',
600 '1.1. I am the owner of my trade-in vehicle and I am legally allowed to sell my trade-in vehicle.' => 'Yes / No',
601 '1.2. I am a South African resident.' => 'Yes / No',
602 '1.3. My trade-in vehicle is not subject to a claim of any nature whatsoever by any other person or entity and I '
603 . 'indemnify the Dealer against any claims of any ' => 'Yes / No',
604 '1.4. If my trade-in vehicle is subject to any claim by any other person or entity, the Dealer will not be bound '
605 . 'to this valuation.' => 'Yes / No',
606 '2. VAT Registration' => '',
607 'This transaction is subject to the payment of VAT.' => '',
608 '3. Status of the Vehicle' => '',
609 '3.1. My trade-in vehicle was new when I purchased it.' => 'Yes / No',
610 '3.2. My trade-in vehicle has been used for self-drive hire or taxi work.' => 'Yes / No',
611 '3.3. My trade-in vehicle has a full service history.' => 'Yes / No',
612 '3.4. My trade in vehicle has not been involved in any accident.' => 'Yes / No',
613 '3.5. If my trade-in vehicle has been involved in an accident, there was a total loss claim made (Stolen & Recovered).' => 'Yes / No',
614 '3.6. A current registration paper has been handed over by me.' => 'Yes / No',
615 '3.7. I have supplied the owners and service manuals to the Dealer.' => 'Yes / No',
616 '3.8. My trade-in vehicle is subject to a service and/or maintenance plan and/or warranty.' => 'Yes / No',
617 '4. Status of the Vehicle' => '',
618 'The Dealer will only be bound by its appraised trade-in value of my trade-in vehicle as far as the trade-in has '
619 . 'been approved and accepted in writing by either the dealer principle, designated sales manager or used car manager'
620 . ' and the parties have entered into the Dealer\'s standard Offer to Purchase in respect of my trade-in vehicle.' => '',
621 '5. Outstanding Finance' => '',
622 '5.1. The Dealer, in its absolute and sole discretion, may agree to settle the existing finance in lieu of payment '
623 . '(or part payment) of the trade-in vehicle to me.' => '',
624 '5.2. If the agreed trade-in allowance of the trade-in vehicle is lower than the settlement figure in clause 5.1 above, '
625 . 'I must pay the Registered Credit Provider the difference between the settlement figure and the trade-in allowance with '
626 . 'proof of such payment (made to the registered Credit Provider) submitted to the Dealer prior to the signing of the Offer to Purchase.' => '',
627 '5.3. I will remain liable to the registered Credit Provider in respect of the related finance at all times until the '
628 . 'credit Agreement has been legally terminated.' => '',
629 '5.4. For purposes of clarity, the Dealer does not accept any liability with respect to the related finance set out in '
630 . 'clause 5.4 above at any time or for any reason.' => '',
631 '5.5. The Dealer will use its best endeavors to pay the trade-in allowance to the registered Credit Provider as soon as '
632 . 'is reasonably possible. However the Dealer accepts no liability for any costs or liability incurred by me as a result '
633 . 'of any delay in the payment by the Dealer.' => '',
634 '6. No Financial Advice' => '',
635 'This trade-in valuation does not constitute financial advice to me as contemplated in the Financial Advisory and '
636 . 'Intermediary Services Act 37 of 2002 but is subject to the Consumer Protection Act 68 of 2008.' => '',
638 '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 '
639 . '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.' => '',
640 '8. The Dealer\'s right to withdraw from the offer' => '',
641 'The Dealer is bound by this offer only in so far as:' => '',
642 '8.1. I have signed an Offer to Purchase with the same Dealer in respect of this valuation; and' => '',
643 '8.2. Fewer than 7 (seven) days have passed since the issuing of this valuation; and' => '',
644 '8.3. My trade-in vehicle is in the same condition as the date of inspection; and' => '',
645 '8.4. This trade-in valuation was signed by the Valuator and the Manager of the Dealer.' => '',
646 ' <br /> ' => '',
647 'I HAVE READ THE ABOVE TERMS AND CONDITIONS AND CONFIRM MY UNDERSTANDING AND AGREE TO BE BOUND THERETO.' => '',
648 ' <br /> ' => '',
650 'By signing this form, I agree to the [Dealership Name] valuation terms and conditions above.' => '',
651 ' <br /> <br /> <br /> <br /> <br />' => '',
652 '<b>Signature:</b>' => '',
654 'Date: ' . date('Y-m-d') => ''
655 ), 0, 'color:#333;', 'color:#000;');
656 $this->append($table->publish() . '<br />');
659 '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
660 . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
662 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
663 . $dateOfPrint . '</i></td>'
664 . '<td style="width:5%"> </td>'
665 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
666 . $printedBy . '</i></td>'
667 . '<td style="width:5%"> </td>'
668 . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
669 . $referenceNo . '</i></td>'