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