initial commit
[namibia] / module / Auction / src / Auction / Pdf / Admin.php
1 <?php
2
3 namespace Auction\Pdf;
4
5 class Admin extends \Utility\Service\PdfTemplate
6 {
7
8   /**
9    * PDF title.
10    * @var string
11    */
12   protected $_title = 'Stock Information';
13
14   /**
15    * @var \Stock\Entity\Stock
16    */
17   protected $jobRecord;
18
19   /**
20    * @var boolean
21    */
22   protected $showTradeDataOnly = true;
23
24   /**
25    * @var boolean
26    */
27   protected $showCustomerDetails = false;
28
29   /**
30    * @var boolean
31    */
32   protected $showValuationDetails = false;
33
34   /**
35    * @var boolean
36    */
37   protected $showMainImage = true;
38
39   /**
40    * @var boolean
41    */
42   protected $showPricingDetails = true;
43
44   /**
45    * @var boolean
46    */
47   protected $showVehicleDetails = true;
48
49   /**
50    * @var boolean
51    */
52   protected $showVehicleNotes = true;
53
54   /**
55    * @var boolean
56    */
57   protected $showDamageDetails = true;
58
59   /**
60    * @var boolean
61    */
62   protected $showAccessoryDetails = true;
63
64   /**
65    * @var boolean
66    */
67   protected $showSignatureLines = false;
68
69   /**
70    * @var boolean
71    */
72   protected $showTermsAndConditions = false;
73
74   /**
75    * @var boolean
76    */
77   protected $showOffersReceived = true;
78
79   /**
80    * @var boolean
81    */
82   protected $showOfferMade = true;
83
84   /**
85    * Utility for easy parameter retrieval.
86    * @param string $param
87    * @param unknown $default
88    * @return unknown
89    */
90   protected function getStockParam($param, $default)
91   {
92     return !is_null($this->jobRecord->$param) ? $this->jobRecord->$param : $default;
93   }
94
95   /**
96    * Utility for easy parameter retrieval.
97    * @param string $param
98    * @param unknown $default
99    * @return unknown
100    */
101   protected function getStockSubParam($ref, $param, $default)
102   {
103     $ref = !is_null($this->jobRecord->$ref) ? $this->jobRecord->$ref : null;
104     return is_object($ref) ? $ref->$param : $default;
105   }
106
107   /**
108    * Utility for easy parameter retrieval.
109    * @param string $param
110    * @param unknown $default
111    * @return unknown
112    */
113   protected function getValuationParam($param, $default)
114   {
115     return !is_null($this->jobRecord->valuation) && !is_null($this->jobRecord->valuation->$param) ? $this->jobRecord->valuation->$param : $default;
116   }
117
118   /**
119    * Build the content.
120    */
121   public function build()
122   {
123     #-> Set data item to work with.
124     $this->auctionRecord = $this->_input['jobRecord'];
125     $this->jobRecord = $this->_input['jobRecord']->stock;
126     $dateTimeFormat = \Utility\Definitions\Locale::getDateTimeFormat();
127     $currencyPrefix = \Utility\Definitions\Locale::getCurrencyPrefix();
128     $authData = \Utility\Registry::getAuthData();
129     $dateOfPrint = 'Date of print: <span style="color:#333;">' . date('Y-m-d H:i:s') . '</span>';
130     $printedBy = 'Printed by: <span style="color:#333;">' . $authData['firstName']
131       . ' ' . $authData['familyName'] . '</span>';
132     $referenceNo = 'Reference no.: <span style="color:#333;">' . $this->jobRecord->referenceNumber . '</span>';
133
134
135     \Utility\Debug::errorLog('jobrecord' , $this->jobRecord->jobState);
136     /* --------------------------------- CUSTOMER, VALUATION, PRICING --------------------------------- */
137     $type = $this->jobRecord->type;
138     $this->append(
139       '<br /><div style="font-size:16px;font-weight:bold;">'
140       . $type->model->make->name . ' '
141       . $type->model->name . ' '
142       . $type->name . ' ('
143       . $type->introYear->name . ' - '
144       . (!is_null($type->discYear) ? $type->discYear->name : 'Current') . ')'
145       . '</div><hr /><br />'
146     );
147
148
149     /* --------------------------------- CUSTOMER, VALUATION, PRICING --------------------------------- */
150     #-> Customer
151     $customerDetail = '&nbsp;';
152     if ($this->showCustomerDetails)
153     {
154       $table = $this->newTable(
155         array(60, 40), 'padding:0;margin:0;font-size:10px;', '',
156         'padding:2px 3px 2px 0;margin:0;'
157       );
158       $department = $this->getValuationParam('department', null);
159       $department = !is_null($department) ? $department : '&nbsp;';
160       $table
161         ->addTitle('Customer',
162           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
163         ->addKeyValueDataSet(array(
164           'Customer name:' => $this->getValuationParam('firstName', ''),
165           'Customer surname:' => $this->getValuationParam('familyName', ''),
166           'ID:' => $this->getValuationParam('idNumber', ''),
167           'Mobile:' => $this->getValuationParam('mobile', ''),
168           'Email:' => $this->getValuationParam('email', ''),
169           'Department:' => $department,
170           'Address:' => '&nbsp;',
171           '<span style="color:#FFF;font-size:20px;">a1</span>' => '&nbsp;',
172           '<span style="color:#FFF;font-size:10px;">1</span><span style="color:#000;font-size:10px;">______________________________________</span>' => '&nbsp;',
173           '<span style="color:#FFF;font-size:20px;">a</span>' => '&nbsp;',
174           '<span style="color:#FFF;font-size:10px;">2</span><span style="color:#000;font-size:10px;">______________________________________</span>' => '&nbsp;',
175           '<span style="color:#FFF;font-size:20px;">b</span>' => '&nbsp;',
176           '<span style="color:#FFF;font-size:10px;">3</span><span style="color:#000;font-size:10px;">______________________________________</span>' => '&nbsp;'
177           ), 0, 'font-weight:bold;', 'color:#666;');
178       $customerDetail = $table->publish();
179     }
180     #-> Customer alternated with dealership details for traders.
181     if ($this->showTradeDataOnly)
182     {
183       $table = $this->newTable(
184         array(60, 40), 'padding:0;margin:0;font-size:10px;', '',
185         'padding:2px 3px 2px 0;margin:0;'
186       );
187       $department = $this->getValuationParam('department', null);
188       $department = !is_null($department) ? $department : '&nbsp;';
189       $contact = $this->getStockSubParam('company', 'contact', null);
190       $table
191         ->addTitle('Dealership',
192           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
193         ->addKeyValueDataSet(array(
194           'Dealership name:' => $this->getStockSubParam('company', 'name', ''),
195           'Contact:' => !is_null($contact) ? $contact->firstName . ' ' . $contact->familyName : '',
196           'Mobile:' => !is_null($contact) ? $contact->mobile : '',
197           'Email:' => !is_null($contact) ? $contact->email : ''
198           ), 0, 'font-weight:bold;', 'color:#666;');
199       $customerDetail = $table->publish();
200     }
201
202     #-> Valuation
203     $valuationDetail = '&nbsp;';
204     if ($this->showValuationDetails)
205     {
206       $table = $this->newTable(
207         array(55, 45), 'padding:0;margin:0;font-size:10px;', '',
208         'padding:2px 3px 2px 0;margin:0;'
209       );
210       $pgItem = $this->em
211         ->getRepository('\Auction\Entity\Auction')
212         ->findOneBy(array('stock' => $this->jobRecord));
213       $pgLoaded = !is_null($pgItem) ? $pgItem->created->format($dateTimeFormat) : '&nbsp;';
214       $valCreated = $this->getValuationParam('created', null);
215       $valCreated = !is_null($valCreated) ? $valCreated->format($dateTimeFormat) : '&nbsp;';
216       $table
217         ->addTitle('Valuation details',
218           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
219         ->addKeyValueDataSet($this->showTradeDataOnly ? array(
220             'Date created:' => $valCreated,
221             'Date loaded on price guide:' => $pgLoaded
222             ) : array(
223             'Date created:' => $valCreated,
224             'Valuation no.:' => $this->getValuationParam('valuationNumber', ''),
225             'Reference no.:' => $this->getStockParam('referenceNumber', ''),
226             'Date loaded on price guide:' => $pgLoaded
227             ), 0, 'font-weight:bold;', 'color:#F00;');
228       $valuationDetail = $table->publish();
229     }
230     $mainImage = '&nbsp;';
231     if ($this->showMainImage)
232     {
233       $pic = $this->getStockParam('mainImage', '');
234       if (is_object($pic))
235       {
236         $mainImage = '<img src="' . __DIR__ . '/../../../../../public/img/bin/' . $pic->filename . '" style="padding:0;margin:0;width:100%;" />';
237       }
238     }
239
240     #-> Pricing details
241     $pricingDetail = '&nbsp;';
242     $total = $this->getValuationParam('overAllowance', '0.00') + $this->getValuationParam('amountOffered',
243         '0.00');
244     $total = number_format($total, 2, '.', '');
245     if ($this->showPricingDetails)
246     {
247       $table = $this->newTable(
248         array(60, 40), 'padding:0;margin:0;font-size:10px;', '',
249         'padding:2px 3px 2px 0;margin:0;'
250       );
251       $table
252         ->addTitle('Pricing details',
253           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
254         ->addKeyValueDataSet($this->showTradeDataOnly ? array(
255             'Trade:' => $currencyPrefix . $this->getStockParam('tradePrice',
256               '0.00'),
257             'Retail:' => $currencyPrefix . $this->getStockParam('retailPrice',
258               '0.00'),
259             'List:' => $currencyPrefix . $this->getStockParam('listPrice',
260                  '0.00'),
261             'Reserve price:' => $currencyPrefix . $this->auctionRecord->reservePrice,
262             'Highest bid:' => $currencyPrefix . $this->getStockParam('highestBid',
263               '0.00')
264
265
266
267             /* 'Amount offered:'            => $currencyPrefix . $this->getValuationParam('amountOffered', '0.00'), */
268             /* 'O.A.:'                      => $currencyPrefix . $this->getValuationParam('overAllowance', '0.00'), */
269             /* 'Total offer:'                    => $currencyPrefix . $total, // total offer =  amount offered + O.A */
270             ) : array(
271             'Trade:' => $currencyPrefix . $this->getStockParam('tradePrice',
272               '0.00'),
273             'Retail:' => $currencyPrefix . $this->getStockParam('retailPrice',
274               '0.00'),
275             'List:' => $currencyPrefix . $this->getStockParam('listPrice',
276                     '0.00'),
277             'Amount offered:' => $currencyPrefix . $this->getValuationParam('amountOffered',
278               '0.00'),
279             'O.A.:' => $currencyPrefix . $this->getValuationParam('overAllowance',
280               '0.00'),
281             'Total offer:' => $currencyPrefix . $total, // total offer =  amount offered + O.A
282             'Projected retail:' => $currencyPrefix,
283             'Planned margin:' => $currencyPrefix,
284             'Price guide highest offer:' => $currencyPrefix . $this->getStockParam('highestOffer',
285               '0.00')
286             ), 0, 'font-weight:bold;', 'color:#F00;');
287       $pricingDetail = $table->publish();
288     }
289
290     #-> First row of data-blocks.
291     if ($this->showCustomerDetails || $this->showValuationDetails || $this->showMainImage || $this->showPricingDetails)
292     {
293       $container = $this
294         ->newTable(
295           array(30, 5, 30, 5, 30),
296           'margin:0;font-size:10px;vertical-align:top;', '',
297           'padding:10px 0 0 0;'
298         )
299         ->setCellValue(0, 0, $customerDetail)
300         ->setCellValue(0, 2, $pricingDetail)
301         ->setCellValue(0, 4, $valuationDetail . $mainImage);
302       $this->append($container->publish() . '<br />');
303     }
304
305     /* --------------------------------- Buyer Details --------------------------------- */
306     if (true)
307     {
308       $table = $this->newTable(
309         array(30, 30), 'padding:0;margin:0;font-size:10px;', '',
310         'padding:2px 3px 2px 0;margin:0;'
311       );
312
313       $table
314         ->addTitle('Buyers Details',
315           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
316         ->addKeyValueDataSet(array(
317           'Dealership name:' => $this->auctionRecord->soldToCompany->name,
318           'Contact:' => !is_null($this->auctionRecord->soldToProfile) ? $this->auctionRecord->soldToProfile->firstName . ' ' . $this->auctionRecord->soldToProfile->familyName : '',
319           'Mobile:' => !is_null($this->auctionRecord->soldToProfile) ? $this->auctionRecord->soldToProfile->mobile : '',
320           'Email:' => !is_null($this->auctionRecord->soldToProfile) ? $this->auctionRecord->soldToProfile->email : ''
321           ), 0, 'font-weight:bold;', 'color:#666;');
322       $buyerDetails = $table->publish();
323
324       $this->append($buyerDetails . '<br />');
325     }
326
327
328     /* --------------------------------- VEHICLE, DAMAGES, ACCESSORIES --------------------------------- */
329
330     #-> Vehicle details
331     $vehicleDetail = '&nbsp;';
332     if ($this->showVehicleDetails)
333     {
334       $keys = $this->getStockParam('spareKeys', null);
335       if (is_null($keys))
336       {
337         $keys = '';
338       }
339       else
340       {
341         $keys = $keys ? 'Yes' : 'No';
342       }
343       $table = $this->newTable(
344         array(55, 45), 'padding:0;margin:0;font-size:10px;', '',
345         'padding:2px 3px 2px 0;margin:0;'
346       );
347       $table
348         ->addTitle('Vehicle specifications',
349           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
350         ->addKeyValueDataSet(array(
351           'Year:' => $this->getStockSubParam('vehicleYear', 'name', ''),
352           'Category:' => $type->category->name,
353           'Make:' => $type->model->make->name,
354           'Model:' => $type->model->name,
355           'Type:' => $type->name,
356           'Registration no.:' => $this->getStockParam('registrationNumber', ''),
357           'Fuel type:' => $this->getStockSubParam('fuelType', 'name', ''),
358           'Transmission type:' => $this->getStockSubParam('transmissionType',
359             'name', ''),
360           'VIN no.:' => $this->getStockParam('vinNumber', ''),
361           'Engine no.:' => $this->getStockParam('engineNumber', ''),
362           'MM code:' => $type->mmCode,
363           'Kms:' => $this->getStockParam('km', ''),
364           'Condition:' => $this->getStockSubParam('condition', 'name', ''),
365           'Main exterior colour:' => $this->getStockSubParam('exteriorColour',
366             'name', ''),
367           'Main interior colour:' => $this->getStockSubParam('interiorColour',
368             'name', ''),
369           'Upholstery:' => $this->getStockSubParam('upholstery', 'name', ''),
370           'Papers:' => $this->getStockSubParam('papers', 'name', ''),
371           'Papers comments:' => $this->getStockParam('papersNotes', ''),
372           'Natis:' => $this->getStockSubParam('natis', 'name', ''),
373           'Spare keys:' => $keys,
374           'FSH:' => $this->getStockSubParam('fullServiceHistory', 'name', ''),
375           'FSH comments:' => $this->getStockParam('fshNotes', ''),
376           'Stock number:' => $this->getStockParam('stockNumber', '')
377           ), 0, '', 'color:#666;');
378       $vehicleDetail = $table->publish();
379     }
380
381     #-> Damages
382     $damagesDetail = '&nbsp;';
383     if ($this->showDamageDetails)
384     {
385       $damageData = array();
386       $damages = $this->jobRecord->damagesToArray();
387       foreach ($damages as $damage)
388       {
389         $damageData[$damage['damage']['name'] . ':'] = $currencyPrefix . $damage['amount'];
390       }
391       $damageData['Total estimated repair cost:'] = '<span style="color:#F00;">' . $currencyPrefix . $this->getStockParam('damageTotal',
392           '') . '</span>';
393       $damageData['Damages comments:'] = $this->getStockParam('damageNotes', '');
394       $damageData['Previous repairs noted:'] = $this->getStockParam('previousRepairsNoted',
395           false) ? 'Yes' : 'No';
396       $damageData['Previous repairs comments:'] = $this->getStockParam('previousRepairsNotes',
397         '');
398       $table = $this->newTable(
399         array(50, 50), 'padding:0;margin:0;font-size:10px;', '',
400         'padding:2px 3px 2px 0;margin:0;'
401       );
402       $type = $this->jobRecord->type;
403       $table
404         ->addTitle('Damages',
405           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
406         ->addKeyValueDataSet($damageData, 0, '', 'color:#666;');
407       $damagesDetail = $table->publish();
408     }
409
410     #-> Accessories
411     $accessoriesDetail = '&nbsp;';
412     if ($this->showAccessoryDetails)
413     {
414       $accs = array();
415       $accData = array();
416       $accessories = $this->jobRecord->accessoriesToArray();
417       foreach ($accessories as $accessory)
418       {
419         $accs[] = $accessory['accessory']['name'];
420       }
421       if (!empty($accs))
422       {
423         for ($i = 0; $i <= count($accs); $i += 2)
424         {
425           if (isset($accs[$i]))
426           {
427             $accData[$accs[$i]] = isset($accs[$i + 1]) ? $accs[$i + 1] : '';
428           }
429         }
430       }
431       $accData['<span style="color:#000;font-size:10px;">Comments:</span>'] = '<span style="color:#666;font-size:10px;">' . $this->getStockParam('accessoryNotes',
432           '') . '</span>';
433       $table = $this->newTable(
434         array(50, 50), 'padding:0;margin:0;font-size:9px;', '',
435         'padding:2px 3px 2px 0;margin:0;'
436       );
437       $type = $this->jobRecord->type;
438       $table
439         ->addTitle('Accessories',
440           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
441         ->addKeyValueDataSet($accData, 0, 'color:#666;', 'color:#666;');
442       $accessoriesDetail = $table->publish();
443     }
444
445     #-> Second row of data-blocks.
446     if ($this->showVehicleDetails || $this->showDamageDetails || $this->showAccessoryDetails)
447     {
448       $container = $this
449         ->newTable(
450           array(30, 5, 30, 5, 30),
451           'margin:0;font-size:10px;vertical-align:top;', '',
452           'padding:10px 0 0 0;'
453         )
454         ->setCellValue(0, 0, $vehicleDetail)
455         ->setCellValue(0, 2, $damagesDetail)
456         ->setCellValue(0, 4, $accessoriesDetail);
457       $this->append($container->publish() . '<br />');
458     }
459
460     /* --------------------------------- VEHICLE NOTES --------------------------------- */
461     #-> Vehicle Notes
462     $VehicleNotes = '&nbsp;';
463     if ($this->showVehicleNotes)
464     {
465       $table = $this->newTable(
466         array(55, 45), 'padding:0;margin:0;font-size:10px;', '',
467         'padding:15px 15px 15px 0;margin:0;'
468       );
469
470       $dSet = array(
471         '1______________________________________________________________________________________________________________________________________' => '&nbsp;',
472         '2______________________________________________________________________________________________________________________________________' => '&nbsp;',
473         '3______________________________________________________________________________________________________________________________________' => '&nbsp;'
474       );
475
476       $table
477         ->addTitle('Notes:',
478           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
479         ->addKeyValueDataSet($dSet, 0, '', 'color:#666;');
480       $VehicleNotes = $table->publish();
481     }
482     #-> Third row of data-blocks.
483     if ($this->showVehicleNotes)
484     {
485       $container = $this
486         ->newTable(
487           array(30, 5, 30, 5, 30),
488           'margin:0;font-size:10px;vertical-align:top;', '',
489           'padding:10px 0 0 0;'
490         )
491         ->setCellValue(0, 0, $VehicleNotes);
492       $this->append($container->publish() . '<br />');
493     }
494
495
496
497
498
499     /* --------------------------------- SIGNATURES --------------------------------- */
500     #-> Signatures.
501     if ($this->showSignatureLines)
502     {
503       $this->append(
504         $this->newSignatureLine()
505           ->addSignatureLine('Customer (name)', 'Signature', 'Date')
506           ->addSignatureLine('Manager (name)', 'Signature', 'Date')
507           ->publish()
508       );
509     }
510
511     $this->append(
512       '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
513       . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
514       . '<tr>'
515       . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
516       . $dateOfPrint . '</i></td>'
517       . '<td style="width:5%">&nbsp;</td>'
518       . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
519       . $printedBy . '</i></td>'
520       . '<td style="width:5%">&nbsp;</td>'
521       . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
522       . $referenceNo . '</i></td>'
523       . '</tr>'
524       . '</table>'
525       . '</div>'
526     );
527
528
529
530
531     /* --------------------------------- TERMS AND CONDITIONS --------------------------------- */
532     #-> Terms and Conditions.
533     if ($this->showTermsAndConditions)
534     {
535       $this->nextPage();
536       $this->append('<br/>');
537
538       $table = $this->newTable(
539         array(90, 10), 'padding:0;margin:0;font-size:9px;', '',
540         'padding:2px 3px 2px 0;margin:0;'
541       );
542       $type = $this->jobRecord->type;
543       $table
544         ->addTitle('Terms and Conditions',
545           'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
546         ->addKeyValueDataSet(array(
547           'I acknowledge, confirm and agree that:' => '',
548           '1. Ownership' => '',
549           '1.1. I am the owner of my trade-in vehicle and I am legally allowed to sell my trade-in vehicle.' => 'Yes / No',
550           '1.2. I am a South African resident.' => 'Yes / No',
551           '1.3. My trade-in vehicle is not subject to a claim of any nature whatsoever by any other person or entity and I '
552           . 'indemnify the Dealer against any claims of any ' => 'Yes / No',
553           '1.4. If my trade-in vehicle is subject to any claim by any other person or entity, the Dealer will not be bound '
554           . 'to this valuation.' => 'Yes / No',
555           '2. VAT Registration' => '',
556           'This transaction is subject to the payment of VAT.' => 'Yes / No',
557           '3. Status of the Vehicle' => '',
558           '3.1. My trade-in vehicle was new when I purchased it.' => 'Yes / No',
559           '3.2. My trade-in vehicle has been used for self-drive hire or taxi work.' => 'Yes / No',
560           '3.3. My trade-in vehicle has a full service history.' => 'Yes / No',
561           '3.4. My trade in vehicle has not been involved in any accident.' => 'Yes / No',
562           '3.5. If my trade-in vehicle has been involved in an accident, there was a total loss claim made (Stolen & Recovered).' => 'Yes / No',
563           '3.6. A current registration paper has been handed over by me.' => 'Yes / No',
564           '3.7. I have supplied the owners and service manuals to the Dealer.' => 'Yes / No',
565           '3.8. My trade-in vehicle is subject to a service and/or maintenance plan and/or warranty.' => 'Yes / No',
566           '4. Status of the Vehicle' => '',
567           'The Dealer will only be bound by its appraised trade-in value of my trade-in vehicle as far as the trade-in has '
568           . 'been approved and accepted in writing by either the dealer principle, designated sales manager or used car manager'
569           . ' and the parties have entered into the Dealer\'s standard Offer to Purchase in respect of my trade-in vehicle.' => '',
570           '5. Outstanding Finance' => '',
571           '5.1. The Dealer, in its absolute and sole discretion, may agree to settle the existing finance in lieu of payment '
572           . '(or part payment) of the trade-in vehicle to me.' => '',
573           '5.2. If the agreed trade-in allowance of the trade-in vehicle is lower than the settlement figure in clause 5.1 above, '
574           . 'I must pay the Registered Credit Provider the difference between the settlement figure and the trade-in allowance with '
575           . 'proof of such payment (made to the registered Credit Provider) submitted to the Dealer prior to the signing of the Offer to Purchase.' => '',
576           '5.3. I will remain liable to the registered Credit Provider in respect of the related finance at all times until the '
577           . 'credit Agreement has been legally terminated.' => '',
578           '5.4. For purposes of clarity, the Dealer does not accept any liability with respect to the related finance set out in '
579           . 'clause 5.4 above at any time or for any reason.' => '',
580           '5.5. The Dealer will use its best endeavors to pay the trade-in allowance to the registered Credit Provider as soon as '
581           . 'is reasonably possible. However the Dealer accepts no liability for any costs or liability incurred by me as a result '
582           . 'of any delay in the payment by the Dealer.' => '',
583           '6. No Financial Advice' => '',
584           'This trade-in valuation does not constitute financial advice to me as contemplated in the Financial Advisory and '
585           . 'Intermediary Services Act 37 of 2002 but is subject to the Consumer Protection Act 68 of 2008.' => '',
586           '7. Risk' => '',
587           '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 '
588           . '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.' => '',
589           '8. The Dealer\'s right to withdraw from the offer' => '',
590           'The Dealer is bound by this offer only in so far as:' => '',
591           '8.1. I have signed an Offer to Purchase with the same Dealer in respect of this valuation; and' => '',
592           '8.2. Fewer than 7 (seven) days have passed since the issuing of this valuation; and' => '',
593           '8.3. My trade-in vehicle is in the same condition as the date of inspection; and' => '',
594           '8.4. This trade-in valuation was signed by the Valuator and the Manager of the Dealer.' => '',
595           '&nbsp;<br />&nbsp;' => '',
596           'I HAVE READ THE ABOVE TERMS AND CONDITIONS AND CONFIRM MY UNDERSTANDING AND AGREE TO BE BOUND THERETO.' => '',
597           '&nbsp;<br />&nbsp;' => '',
598           'Acceptance' => '',
599           'By signing this form, I agree to the [Dealership Name] valuation terms and conditions above.' => '',
600           '&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />' => '',
601           '<b>Signature:</b>' => '',
602           '&nbsp;' => '',
603           'Date: ' . date('Y-m-d') => ''
604           ), 0, 'color:#333;', 'color:#000;');
605       $this->append($table->publish() . '<br />');
606
607       $this->append(
608         '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
609         . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
610         . '<tr>'
611         . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
612         . $dateOfPrint . '</i></td>'
613         . '<td style="width:5%">&nbsp;</td>'
614         . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
615         . $printedBy . '</i></td>'
616         . '<td style="width:5%">&nbsp;</td>'
617         . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
618         . $referenceNo . '</i></td>'
619         . '</tr>'
620         . '</table>'
621         . '</div>'
622       );
623     }
624
625     /* --------------------------------- OFFERS RECEIVED/MADE --------------------------------- */
626     #-> Offers received.
627     if ($this->showOffersReceived || $this->showOfferMade)
628     {
629
630
631       if ($this->showOffersReceived)
632       {
633         $offers = array();
634         $pgItems = $this->em
635             ->getRepository('\PriceGuide\Entity\PriceGuide')
636             ->findBy(array('stock' => $this->jobRecord));
637         if (!empty($pgItems))
638         {
639           foreach ($pgItems as $pgItem)
640           {
641             $iterator = $pgItem->offers->getIterator();
642             foreach ($iterator as $offer)
643             {
644               $status = $offer->status;
645               $offers[] = array(
646                   $offer->company->name,
647                   $offer->created->format($dateTimeFormat),
648                   $currencyPrefix . $offer->amount,
649                   $offer->profile->mobile,
650                   $offer->profile->email,
651                   $status
652               );
653             }
654           }
655
656           $this->nextPage();
657           $this->append('<br/>');
658           $table = $this->newTable(
659               array(20, 15, 15, 10, 30, 10),
660               'padding:0;margin:0;font-size:10px;',
661               '',
662               'padding:2px 5px 2px 2px;margin:0;'
663           );
664           $table
665               ->addTitle('Offers received', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
666               ->setColumnHeaders(array(
667                   'Buyer', 'Date', 'Offer', 'Mobile', 'Email', 'Status'
668               ), array(20, 15, 15, 10, 30, 10),
669                   'padding:2px 2px 2px 5px;background-color:#F00;color:#FFF;font-weight:bold;font-size:10px;')
670               ->setDataSet($offers);
671           $this->append($table->publish() . '<br />');
672
673           $this->append(
674               '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
675               . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
676               . '<tr>'
677               . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
678               . $dateOfPrint . '</i></td>'
679               . '<td style="width:5%">&nbsp;</td>'
680               . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
681               . $printedBy . '</i></td>'
682               . '<td style="width:5%">&nbsp;</td>'
683               . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
684               . $referenceNo . '</i></td>'
685               . '</tr>'
686               . '</table>'
687               . '</div>'
688           );
689         }
690
691       }
692
693       #-> Offer made.
694       if ($this->showOfferMade)
695       {
696         $offers = array();
697         $pgItem = $this->em
698             ->getRepository('\PriceGuide\Entity\PriceGuide')
699             ->findOneBy(array('stock' => $this->jobRecord));
700         if (!is_null($pgItem))
701         {
702           $companyId = \Utility\Registry::resolveCompanyContext();
703           $iterator = $pgItem->offers->getIterator();
704           foreach ($iterator as $offer)
705           {
706             $status = $offer->status;
707             $offers[] = array(
708                 $offer->company->name,
709                 $offer->created->format($dateTimeFormat),
710                 $currencyPrefix . $offer->amount,
711                 $offer->profile->mobile,
712                 $offer->profile->email,
713                 $status
714             );
715           }
716
717           $table = $this->newTable(
718               array(20, 15, 15, 10, 30, 10),
719               'padding:0;margin:0;font-size:10px;',
720               '',
721               'padding:2px 5px 2px 2px;margin:0;'
722           );
723
724           $this->nextPage();
725           $this->append('<br/>');
726           $table
727               ->addTitle('Offers made', 'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1)
728               ->setColumnHeaders(array(
729                   'Buyer', 'Date', 'Offer', 'Mobile', 'Email', 'Status'
730               ), array(20, 15, 15, 10, 30, 10),
731                   'padding:2px 2px 2px 5px;background-color:#F00;color:#FFF;font-weight:bold;font-size:10px;')
732               ->setDataSet($offers);
733           $this->append($table->publish() . '<br />');
734
735           $this->append(
736               '<div style="position:absolute;bottom:0;left:0;padding:0;margin:0;width:100%;">'
737               . '<table cellpadding="0px" cellspacing="0px" style="border:0px;width:100%;">'
738               . '<tr>'
739               . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
740               . $dateOfPrint . '</i></td>'
741               . '<td style="width:5%">&nbsp;</td>'
742               . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
743               . $printedBy . '</i></td>'
744               . '<td style="width:5%">&nbsp;</td>'
745               . '<td style="width:30%;border-bottom: solid 1px #333;font-size:10px;font-weight:bold;color:#666;"><i>'
746               . $referenceNo . '</i></td>'
747               . '</tr>'
748               . '</table>'
749               . '</div>'
750           );
751         }
752
753       }
754
755
756     }
757
758     /* --------------------------------- BID HISTORY --------------------------------- */
759     $this->nextPage();
760     $table = $this->newTable(
761       array(20, 15, 10, 10, 20, 15, 10), 'padding:0;margin:0;font-size:10px;',
762       '', 'padding:2px 3px 2px 0;margin:0;'
763     );
764
765     $table
766       ->addTitle('Bid History',
767         'padding:0 0 10px 0;font-weight:bold;font-size:11px;', 0, 1);
768     
769     $table->setColumnHeaders(array(
770       'Dealership',
771       'User',
772       'Bid Amount',
773       'Mobile',
774       'Email',
775       'Created',
776       'Status'
777     ), array(20, 15, 10, 10, 20, 15, 10), 'font-weight: bold; color: #ffffff; background-color: #D42E30;');
778     
779     $data = array();
780     foreach ($this->auctionRecord->bids as $bid)
781     {
782       $data[] = array (
783         $bid->company->name,
784         $bid->profile->firstName . ' ' . $bid->profile->familyName,
785         $bid->amount,
786         $bid->profile->mobile,
787         $bid->profile->email,
788         $bid->created->format('Y-m-d H:i:s'),
789         $bid->status,
790       );
791     }
792     
793     $table->setDataSet($data);
794
795
796     $bidHistory = $table->publish();
797
798     //do not show the bid history if a vehicle is sold.
799     if('Sold' !== $this->jobRecord->jobState)
800       $this->append($bidHistory . '<br />');
801
802     return;
803   }
804
805 }