2 namespace Auction\Service;
9 class Auction extends \Auction\DataBin\Auction
14 * New Auction Item from existing Stock.
16 * @param \Stock\Entity\Stock $stock
17 * @param string $previousState
18 * @param array $routingData
20 public function initNewItemFromStock(
21 \Stock\Entity\Stock $stock, $previousState, array $routingData = array()
24 \Utility\Debug::errorLog('initNewItemFromStock' , $stock);
25 #-> Establish initial increment value.
26 $increments = $this->em
27 ->getRepository('\Auction\Entity\Increment')
28 ->findBy(array(), array('to' => 'ASC'));
29 foreach ($increments as $incr)
31 if ($incr->to >= $routingData['reservePrice']
32 && $incr->from <= $routingData['reservePrice']
38 #-> Create auction entry.
39 if (isset($routingData['profileId']))
40 {\Utility\Debug::errorLog('reroute1' , "true");
41 $profile = $this->em->find('User\\Entity\\Profile', $routingData['profileId']);
42 $email = $profile->email;
43 $firstName = $profile->firstName;
44 $familyName = $profile->familyName;
45 $company = !is_null($profile->company)
46 ? $profile->company->id
48 $profile = $profile->id;
51 {\Utility\Debug::errorLog('reroute1' , "false");
52 $authData = \Utility\Registry::getAuthData();
53 $email = $authData['email'];
54 $firstName = $authData['firstName'];
55 $familyName = $authData['familyName'];
56 $profile = \Utility\Registry::resolveProfileContext()->id;
57 $company = \Utility\Registry::resolveCompanyContext()->id;
59 $routingData['endDate'] = str_replace(' 00:00:00', '', $routingData['endDate']);
60 $record = $this->create(array(
61 'createdBy' => $profile,
62 'company' => $company,
63 'stock' => $stock->id,
64 'reservePrice' => $routingData['reservePrice'],
65 'currentBidPrice' => $routingData['reservePrice'],
66 'bidIncrement' => $incr->amount,
67 'startDate' => new \DateTime("now"),
68 'endDate' => new \DateTime($routingData['endDate'] . ' 14:30:00')
71 #-> Update stock with count of times sent to auction.
72 $stats = $this->em->createQuery(
73 'SELECT COUNT(auction.id) AS numAuctions '
74 . 'FROM \Auction\Entity\Auction auction '
75 . 'WHERE IDENTITY(auction.stock) = :stockId'
77 ->setParameter('stockId', $stock->id)
79 $stock->auction = $record;
80 $stock->highestBid = 0.00;
81 $stock->timesListed = $stats['numAuctions'];
82 $this->em->flush($stock);
83 \Utility\Debug::errorLog('created stock' , "true");
84 #-> Send loaded notification.
86 $pdf = new \Auction\Pdf\Complete();
88 'jobRecord' => $record
90 $docsDir = __DIR__ . '/../../../../../public/documents/';
91 $writer = new \Utility\Export\PdfTemplate($pdf);
93 'auction' . $record->id . '.pdf' => $writer->output(''),
94 'REGULATION_32_NOTICE_38960.pdf' => file_get_contents($docsDir . 'REGULATION_32_NOTICE_38960.pdf')
97 $oNotify = new \Utility\Comms\Notification();
98 $oNotify->sendFromTemplate(
102 'Vehicle live on Bid4Cars Auction - ' . $record->id,
105 'first_name' => $firstName,
106 'family_name' => $familyName,
107 'make' => $stock->type->model->make->name,
108 'model' => $stock->type->model->name,
109 'type' => $stock->type->name,
110 'image' => !is_null($stock->mainImage)
111 ? $stock->mainImage->filename
122 * Contract to get selectlist.
123 * @param object|null $jobRecord
124 * @param array $input
125 * @return \Workspace\Contract\UseOnce
127 public function contractHistoricMakeSelectList($jobRecord, array $input = array())
129 $options = new \Workspace\UseCase\Options();
130 $requirement = new \Workspace\UseCase\Requirement();
131 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
132 return new \Workspace\Contract\UseOnce($options, $requirement);
137 * @param object|null $jobRecord
138 * @param \Workspace\Utility\ServiceInputParams $contract
142 public function executeHistoricMakeSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
144 $em = \Utility\Registry::getEntityManager();
145 $authData = \Utility\Registry::getAuthData();
146 $companyId = $authData['company']['id'];
148 $queryFilter = array();
149 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
151 foreach ($contract->data->filter['Filters'] as $field => $filter)
153 $queryFilter[] = $field . ' = ' . $filter;
157 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
159 $memberslistdrop = $em->createQuery('
160 SELECT distinct make.id, make.name FROM \Auction\Entity\Auction auction
161 JOIN auction.company company
162 JOIN company.city city
163 JOIN company.contact contact
164 JOIN city.region region
165 JOIN auction.stock stock
166 JOIN stock.company companyStock
167 JOIN stock.vehicleYear vehicleYear
169 JOIN type.model model
171 LEFT JOIN stock.exteriorColour exteriorColour
172 LEFT JOIN auction.currentBid currentBid
173 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
174 'ORDER BY make.name');
176 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
177 $memberslistdrop->setParameter('sold', 'Sold');
178 $memberslistu = $memberslistdrop->getArrayResult();
180 foreach ($memberslistu as $data)
185 'value' => $data['id'],
186 'label' => $data['name']
189 return $contract->success('List Retrieved.', $datax);
193 * Contract to get selectlist.
194 * @param object|null $jobRecord
195 * @param array $input
196 * @return \Workspace\Contract\UseOnce
198 public function contractHistoricModelSelectList($jobRecord, array $input = array())
200 $options = new \Workspace\UseCase\Options();
201 $requirement = new \Workspace\UseCase\Requirement();
202 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
203 return new \Workspace\Contract\UseOnce($options, $requirement);
208 * @param object|null $jobRecord
209 * @param \Workspace\Utility\ServiceInputParams $contract
213 public function executeHistoricModelSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
215 $em = \Utility\Registry::getEntityManager();
216 $authData = \Utility\Registry::getAuthData();
217 $companyId = $authData['company']['id'];
219 $queryFilter = array();
220 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
222 foreach ($contract->data->filter['Filters'] as $field => $filter)
224 $queryFilter[] = $field . ' = ' . $filter;
228 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
230 $memberslistdrop = $em->createQuery('
231 SELECT distinct model.id, model.name FROM \Auction\Entity\Auction auction
232 JOIN auction.company company
233 JOIN company.city city
234 JOIN company.contact contact
235 JOIN city.region region
236 JOIN auction.stock stock
237 JOIN stock.company companyStock
238 JOIN stock.vehicleYear vehicleYear
240 JOIN type.model model
242 LEFT JOIN stock.exteriorColour exteriorColour
243 LEFT JOIN auction.currentBid currentBid
244 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
245 'ORDER BY model.name');
247 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
248 $memberslistdrop->setParameter('sold', 'Sold');
249 $memberslistu = $memberslistdrop->getArrayResult();
251 foreach ($memberslistu as $data)
256 'value' => $data['id'],
257 'label' => $data['name']
260 return $contract->success('List Retrieved.', $datax);
264 * Contract to get selectlist.
265 * @param object|null $jobRecord
266 * @param array $input
267 * @return \Workspace\Contract\UseOnce
269 public function contractHistoricTypeSelectList($jobRecord, array $input = array())
271 $options = new \Workspace\UseCase\Options();
272 $requirement = new \Workspace\UseCase\Requirement();
273 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
274 return new \Workspace\Contract\UseOnce($options, $requirement);
279 * @param object|null $jobRecord
280 * @param \Workspace\Utility\ServiceInputParams $contract
284 public function executeHistoricTypeSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
286 $em = \Utility\Registry::getEntityManager();
287 $authData = \Utility\Registry::getAuthData();
288 $companyId = $authData['company']['id'];
290 $queryFilter = array();
291 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
293 foreach ($contract->data->filter['Filters'] as $field => $filter)
295 $queryFilter[] = $field . ' = ' . $filter;
299 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
301 $memberslistdrop = $em->createQuery('
302 SELECT distinct type.id, type.name FROM \Auction\Entity\Auction auction
303 JOIN auction.company company
304 JOIN company.city city
305 JOIN company.contact contact
306 JOIN city.region region
307 JOIN auction.stock stock
308 JOIN stock.company companyStock
309 JOIN stock.vehicleYear vehicleYear
311 JOIN type.model model
313 LEFT JOIN stock.exteriorColour exteriorColour
314 LEFT JOIN auction.currentBid currentBid
315 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
316 'ORDER BY type.name');
318 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
319 $memberslistdrop->setParameter('sold', 'Sold');
320 $memberslistu = $memberslistdrop->getArrayResult();
322 foreach ($memberslistu as $data)
327 'value' => $data['id'],
328 'label' => $data['name']
331 return $contract->success('List Retrieved.', $datax);
335 * Contract to get selectlist.
336 * @param object|null $jobRecord
337 * @param array $input
338 * @return \Workspace\Contract\UseOnce
340 public function contractHistoricYearSelectList($jobRecord, array $input = array())
342 $options = new \Workspace\UseCase\Options();
343 $requirement = new \Workspace\UseCase\Requirement();
344 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
345 return new \Workspace\Contract\UseOnce($options, $requirement);
350 * @param object|null $jobRecord
351 * @param \Workspace\Utility\ServiceInputParams $contract
355 public function executeHistoricYearSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
357 $em = \Utility\Registry::getEntityManager();
358 $authData = \Utility\Registry::getAuthData();
359 $companyId = $authData['company']['id'];
361 $queryFilter = array();
362 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
364 foreach ($contract->data->filter['Filters'] as $field => $filter)
366 $queryFilter[] = $field . ' = ' . $filter;
370 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
372 $memberslistdrop = $em->createQuery('
373 SELECT distinct vehicleYear.id, vehicleYear.name FROM \Auction\Entity\Auction auction
374 JOIN auction.company company
375 JOIN company.city city
376 JOIN company.contact contact
377 JOIN city.region region
378 JOIN auction.stock stock
379 JOIN stock.company companyStock
380 JOIN stock.vehicleYear vehicleYear
382 JOIN type.model model
384 LEFT JOIN stock.exteriorColour exteriorColour
385 LEFT JOIN auction.currentBid currentBid
386 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
387 'ORDER BY vehicleYear.name');
389 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
390 $memberslistdrop->setParameter('sold', 'Sold');
391 $memberslistu = $memberslistdrop->getArrayResult();
393 foreach ($memberslistu as $data)
398 'value' => $data['id'],
399 'label' => $data['name']
402 return $contract->success('List Retrieved.', $datax);
406 * Contract to remove item from auction.
407 * @param object|null $jobRecord
408 * @param array $input
409 * @return \Workspace\Contract\UseOnce
411 public function contractRemove($jobRecord, array $input = array())
413 $options = new \Workspace\UseCase\Options();
414 $requirement = new \Workspace\UseCase\Requirement();
415 return new \Workspace\Contract\UseOnce($options, $requirement);
419 * Remove item from auction.
420 * @param object|null $jobRecord
421 * @param \Workspace\Utility\ServiceInputParams $contract
425 public function executeRemove($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
429 $workflow = \Utility\Registry::getServiceManager()
431 $workflow->handover('Auction', $jobRecord->stock->id);
433 catch (\Exception $e)
435 \Utility\Debug::errorLog(
436 'Error on Auction removal process for item ' . $jobRecord->id,
440 $this->workflowNode->changeState('This.Archived');
441 return $contract->success('Vehicle removed from auction.', array());
445 * Contract to undo auction.
446 * @param object|null $jobRecord
447 * @param array $input
448 * @return \Workspace\Contract\UseOnce
450 public function contractUndo($jobRecord, array $input = array())
452 $options = new \Workspace\UseCase\Options();
453 $requirement = new \Workspace\UseCase\Requirement();
454 return new \Workspace\Contract\UseOnce($options, $requirement);
459 * @param object|null $jobRecord
460 * @param \Workspace\Utility\ServiceInputParams $contract
464 public function executeUndo($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
466 $this->workflowNode->changeState('This.Undone');
467 $jobRecord->currentBid->status = 'Undone';
471 $workflow = \Utility\Registry::getServiceManager()
473 $workflow->handover('Auction', $jobRecord->stock->id);
475 catch (\Exception $e)
477 \Utility\Debug::errorLog(
478 'Error on Auction Undo process for item ' . $jobRecord->id,
483 return $contract->success('Vehicle removed from auction.', array());
487 * CRON functionality: Send newsletter of cars coming off from auction today.
489 public function newsletterProcess()
492 ini_set('memory_limit', '512M');
494 $date = date('Y-m-d 23:59:59');
495 $data = $this->em->createQuery(
496 'SELECT DISTINCT auction.id, auction.reservePrice AS auction_reservePrice, stock.km AS stock_km, '
497 . 'type.name AS type_name, type.mmCode AS type_mmCode, model.name AS model_name, '
498 . 'make.name AS make_name, vehicleYear.name AS vehicleYear_name, region.name AS region_name '
499 . 'FROM \Auction\Entity\Auction auction '
500 . 'JOIN auction.stock stock '
501 . 'JOIN stock.type type '
502 . 'JOIN type.model model '
503 . 'JOIN model.make make '
504 . 'JOIN stock.vehicleYear vehicleYear '
505 . 'LEFT JOIN stock.company company '
506 . 'LEFT JOIN company.city city '
507 . 'LEFT JOIN company.contact contact'
508 . 'LEFT JOIN city.region region '
509 . 'WHERE auction.jobState = \'Active\''
510 . ' AND auction.endDate >= :startDate '
511 . ' AND auction.endDate <= :endDate '
512 . 'ORDER BY make.name, model.name, type.name ASC'
514 ->setParameter('startDate', date('Y-m-d 01:00:00'))
515 ->setParameter('endDate', date('Y-m-d 23:59:59'))
523 $oNotify = new \Utility\Comms\Notification();
524 $oNotify->setRepeaterData($data);
525 $oNotify->setSendAsNewsletter();
526 $oNotify->sendFromTemplate(
535 array('auctioncount' => $i)
540 * CRON functionality: Move Auction items as needed.
542 public function cronProcess()
544 ini_set('memory_limit', '512M');
545 error_log('------------------------------------');
546 error_log('Auction cron started @ ' . date('Y-m-d H:i:s'));
548 $date = date('Y-m-d H:i:s');
549 $result = $this->em->createQuery(
550 'SELECT auction FROM \Auction\Entity\Auction auction '
551 . 'WHERE auction.jobState = \'Active\''
552 . ' AND auction.jobState != \'Archived\''
553 . ' AND auction.endDate <= \'' . $date . '\''
556 $workflow = \Utility\Registry::getServiceManager()
558 error_log("Item count: " . count($result));
559 foreach ($result as $item)
561 $this->workflowNode->setJob($item);
564 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice)
566 #-> We have a winner.
567 $item->soldToCompany = $item->currentBid->company;
568 $item->soldToProfile = $item->currentBid->profile;
569 $this->workflowNode->changeState('This.Sold');
573 #-> Each and every one a loser.
574 $this->workflowNode->changeState('This.Relist');
577 catch (\Exception $e)
579 \Utility\Debug::errorLog('Error on Auction cron process (state change) for item ' . $item->id, $e->getMessage());
583 $workflow->handover('Auction', $item->stock->id);
585 catch (\Exception $e)
587 \Utility\Debug::errorLog('Error on Auction cron process (handover) for item ' . $item->id, $e->getMessage());
591 foreach ($result as $item)
596 #-> General data prep.
597 $vehicle = $item->stock->type->model->make->name
598 . ', ' . $item->stock->type->model->name
599 . ', ' . $item->stock->type->name;
600 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
601 $oNotify = new \Utility\Comms\Notification();
603 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
605 #-> Update record to reflect winner.
606 $item->soldToCompany = $item->currentBid->company;
607 $item->soldToProfile = $item->currentBid->profile;
612 $pdf = new \Auction\Pdf\CompleteNew();
616 $docsDir = __DIR__ . '/../../../../../public/documents/';
619 $pdf_Declaration = new \Auction\Pdf\Declaration();
620 $pdf_Declaration->process(array(
623 $docsDir = __DIR__ . '/../../../../../public/documents/';
625 #-> Deliveryreceipt PDF.
626 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
627 $pdf_Deliveryreceipt->process(array(
630 $docsDir = __DIR__ . '/../../../../../public/documents/';
632 $writer = new \Utility\Export\PdfTemplate($pdf);
633 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
634 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
636 $attachments = array(
637 'auction' . $item->id . '.pdf' => $writer->output(''),
638 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
639 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
644 $oNotify->sendFromTemplate(
645 $item->company->id, $item->createdBy->id,
646 $item->currentBid->company->id, $item->currentBid->profile->id,
647 'info@bid4cars.com.na', null,
648 'Auction Successful - ' . $item->id,
649 'auction-sale-buyer',
651 'first_name' => 'Admin',
653 'vehicle' => $vehicle,
654 'price' => $currPrefix . $item->currentBid->amount,
655 'seller' => $item->company->name,
656 'seller_name' => $item->createdBy->firstName . ' '
657 . $item->createdBy->familyName,
658 'vehicle_address' => $item->company->city->region->name
659 . ', ' . $item->company->city->name
660 . ', ' . $item->company->street
661 . ', ' . $item->company->postalCode,
662 'seller_billing_address' => $item->company->billingCity
663 ? $item->company->billingCity->region->name
664 . ', ' . $item->company->billingCity->name
665 . ', ' . $item->company->billingStreet
666 . ', ' . $item->company->billingPostalCode
668 'seller_vat_number' => !is_null($item->company->vatNumber)
669 ? $item->company->vatNumber
671 'seller_email' => $item->createdBy->email,
672 'stock_number' => $item->stock->stockNumber,
673 'buyer' => $item->currentBid->company->name,
674 'buyer_name' => $item->currentBid->profile->firstName . ' '
675 . $item->currentBid->profile->familyName,
676 'buyer_address' => $item->currentBid->company->city->region->name
677 . ', ' . $item->currentBid->company->city->name
678 . ', ' . $item->currentBid->company->street
679 . ', ' . $item->currentBid->company->postalCode,
680 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
681 ? $item->currentBid->company->vatNumber
683 'buyer_email' => $item->currentBid->profile->email,
684 'buyer_mobile' => $item->currentBid->profile->mobile
692 #-> Combined freight.
693 $oNotify->sendFromTemplate(
694 $item->company->id, $item->createdBy->id,
695 $item->currentBid->company->id, $item->currentBid->profile->id,
696 'louise@combinefreight.co.za', null,
697 'Auction Successful - ' . $item->id,
698 'auction-sale-buyer',
700 'first_name' => 'Admin',
702 'vehicle' => $vehicle,
703 'price' => $currPrefix . $item->currentBid->amount,
704 'seller' => $item->company->name,
705 'seller_name' => $item->createdBy->firstName . ' '
706 . $item->createdBy->familyName,
707 'vehicle_address' => $item->company->city->region->name
708 . ', ' . $item->company->city->name
709 . ', ' . $item->company->street
710 . ', ' . $item->company->postalCode,
711 'seller_billing_address' => $item->company->billingCity
712 ? $item->company->billingCity->region->name
713 . ', ' . $item->company->billingCity->name
714 . ', ' . $item->company->billingStreet
715 . ', ' . $item->company->billingPostalCode
717 'seller_vat_number' => !is_null($item->company->vatNumber)
718 ? $item->company->vatNumber
720 'seller_email' => $item->createdBy->email,
721 'stock_number' => $item->stock->stockNumber,
722 'buyer' => $item->currentBid->company->name,
723 'buyer_name' => $item->currentBid->profile->firstName . ' '
724 . $item->currentBid->profile->familyName,
725 'buyer_address' => $item->currentBid->company->city->region->name
726 . ', ' . $item->currentBid->company->city->name
727 . ', ' . $item->currentBid->company->street
728 . ', ' . $item->currentBid->company->postalCode,
729 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
730 ? $item->currentBid->company->vatNumber
732 'buyer_email' => $item->currentBid->profile->email,
733 'buyer_mobile' => $item->currentBid->profile->mobile
743 $oNotify->sendFromTemplate(
744 $item->company->id, $item->createdBy->id,
745 $item->currentBid->company->id, $item->currentBid->profile->id,
746 $item->currentBid->profile->email, null,
747 'Bid Successful - ' . $item->id,
748 'auction-sale-buyer',
750 'first_name' => $item->currentBid->profile->firstName,
751 'family_name' => $item->currentBid->profile->familyName,
752 'vehicle' => $vehicle,
753 'price' => $currPrefix . $item->currentBid->amount,
754 'seller' => $item->company->name,
755 'seller_name' => $item->createdBy->firstName . ' '
756 . $item->createdBy->familyName,
757 'vehicle_address' => $item->company->city->region->name
758 . ', ' . $item->company->city->name
759 . ', ' . $item->company->street
760 . ', ' . $item->company->postalCode,
761 'seller_billing_address' => $item->company->billingCity
762 ? $item->company->billingCity->region->name
763 . ', ' . $item->company->billingCity->name
764 . ', ' . $item->company->billingStreet
765 . ', ' . $item->company->billingPostalCode
767 'seller_vat_number' => !is_null($item->company->vatNumber)
768 ? $item->company->vatNumber
770 'seller_email' => $item->createdBy->email,
771 'stock_number' => $item->stock->stockNumber,
772 'buyer' => $item->currentBid->company->name,
773 'buyer_name' => $item->currentBid->profile->firstName . ' '
774 . $item->currentBid->profile->familyName,
775 'buyer_address' => $item->currentBid->company->city->region->name
776 . ', ' . $item->currentBid->company->city->name
777 . ', ' . $item->currentBid->company->street
778 . ', ' . $item->currentBid->company->postalCode,
779 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
780 ? $item->currentBid->company->vatNumber
782 'buyer_email' => $item->currentBid->profile->email,
783 'buyer_mobile' => $item->currentBid->profile->mobile
791 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
793 //send `auction-sale-seller` email to $item->stock->company->contact->email
794 $oNotify->sendFromTemplate(
795 $item->company->id, $item->createdBy->id,
796 $item->company->id, $item->createdBy->id,
797 $item->stock->company->contact->email, null,
798 'Auction Successful - ' . $item->id,
799 'auction-sale-seller',
801 'first_name' => $item->stock->company->contact->firstName,
802 'family_name' => $item->stock->company->contact->familyName,
803 'vehicle' => $vehicle,
804 'price' => $currPrefix . $item->currentBid->amount,
805 'buyer' => $item->currentBid->company->name,
806 'buyer_name' => $item->currentBid->profile->firstName . ' '
807 . $item->currentBid->profile->familyName,
808 'buyer_address' => $item->currentBid->company->city->region->name
809 . ', ' . $item->currentBid->company->city->name
810 . ', ' . $item->currentBid->company->street
811 . ', ' . $item->currentBid->company->postalCode,
812 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
813 ? $item->currentBid->company->vatNumber
815 'buyer_email' => $item->currentBid->profile->email,
816 'buyer_mobile' => $item->currentBid->profile->mobile,
817 'seller' => $item->company->name,
818 'seller_name' => $item->createdBy->firstName . ' '
819 . $item->createdBy->familyName,
820 'vehicle_address' => $item->company->city->region->name
821 . ', ' . $item->company->city->name
822 . ', ' . $item->company->street
823 . ', ' . $item->company->postalCode,
824 'seller_billing_address' => $item->company->billingCity
825 ? $item->company->billingCity->region->name
826 . ', ' . $item->company->billingCity->name
827 . ', ' . $item->company->billingStreet
828 . ', ' . $item->company->billingPostalCode
830 'seller_vat_number' => !is_null($item->company->vatNumber)
831 ? $item->company->vatNumber
833 'seller_email' => $item->createdBy->email,
834 'stock_number' => $item->stock->stockNumber
845 $oNotify->sendFromTemplate(
846 $item->company->id, $item->createdBy->id,
847 $item->company->id, $item->createdBy->id,
848 $item->createdBy->email, null,
849 'Auction Successful - ' . $item->id,
850 'auction-sale-seller',
852 'first_name' => $item->createdBy->firstName,
853 'family_name' => $item->createdBy->familyName,
854 'vehicle' => $vehicle,
855 'price' => $currPrefix . $item->currentBid->amount,
856 'buyer' => $item->currentBid->company->name,
857 'buyer_name' => $item->currentBid->profile->firstName . ' '
858 . $item->currentBid->profile->familyName,
859 'buyer_address' => $item->currentBid->company->city->region->name
860 . ', ' . $item->currentBid->company->city->name
861 . ', ' . $item->currentBid->company->street
862 . ', ' . $item->currentBid->company->postalCode,
863 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
864 ? $item->currentBid->company->vatNumber
866 'buyer_email' => $item->currentBid->profile->email,
867 'buyer_mobile' => $item->currentBid->profile->mobile,
868 'seller' => $item->company->name,
869 'seller_name' => $item->createdBy->firstName . ' '
870 . $item->createdBy->familyName,
871 'vehicle_address' => $item->company->city->region->name
872 . ', ' . $item->company->city->name
873 . ', ' . $item->company->street
874 . ', ' . $item->company->postalCode,
875 'seller_billing_address' => $item->company->billingCity
876 ? $item->company->billingCity->region->name
877 . ', ' . $item->company->billingCity->name
878 . ', ' . $item->company->billingStreet
879 . ', ' . $item->company->billingPostalCode
881 'seller_vat_number' => !is_null($item->company->vatNumber)
882 ? $item->company->vatNumber
884 'seller_email' => $item->createdBy->email,
885 'stock_number' => $item->stock->stockNumber
892 $attachments = array();
896 #-> No winner, send notification to seller & admin & feeder.
897 $oNotify->sendFromTemplate(
898 $item->company->id, $item->createdBy->id,
899 $item->company->id, $item->createdBy->id,
900 $item->createdBy->email, null,
901 'No winner on Bid4Cars Auction - ' . $item->id,
904 'first_name' => $item->createdBy->firstName,
905 'family_name' => $item->createdBy->familyName,
906 'vehicle' => $vehicle,
907 'reservePrice' => $item->reservePrice,
908 'registrationNumber' => $item->stock->registrationNumber,
909 'stockNumber' => $item->stock->stockNumber
917 $oNotify->sendFromTemplate(
918 $item->company->id, $item->createdBy->id,
919 $item->company->id, $item->createdBy->id,
920 'info@bid4cars.com.na', null,
921 'No winner on Bid4Cars Auction - ' . $item->id,
924 'first_name' => $item->createdBy->firstName,
925 'family_name' => $item->createdBy->familyName,
926 'vehicle' => $vehicle,
927 'reservePrice' => $item->reservePrice,
928 'registrationNumber' => $item->stock->registrationNumber,
929 'stockNumber' => $item->stock->stockNumber
937 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
939 $oNotify->sendFromTemplate(
940 $item->company->id, $item->createdBy->id,
941 $item->company->id, $item->createdBy->id,
942 $item->stock->company->contact->email, null,
943 'No winner on Bid4Cars Auction - ' . $item->id,
946 'first_name' => $item->stock->company->contact->firstName,
947 'family_name' => $item->stock->company->contact->familyName,
948 'vehicle' => $vehicle,
949 'reservePrice' => $item->reservePrice,
950 'registrationNumber' => $item->stock->registrationNumber,
951 'stockNumber' => $item->stock->stockNumber
962 $item->emailSent = true;
963 $this->em->flush($item);
965 catch (\Exception $e)
967 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
970 error_log('Auction cron ended @ ' . date('Y-m-d H:i:s'));
971 error_log('------------------------------------');
975 * Contract get total vehicels on auction.
976 * @param object|null $jobRecord
977 * @param array $input
978 * @return \Workspace\Contract\UseOnce
980 public function contractCount($jobRecord)
982 $options = new \Workspace\UseCase\Options();
983 $requirement = new \Workspace\UseCase\Requirement();
984 return new \Workspace\Contract\Recurring($options, $requirement);
988 * get total vehicels on auction.
989 * @param object|null $jobRecord
990 * @param \Workspace\Utility\ServiceInputParams $contract
993 public function executeCount($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
995 $result = $this->em->createQuery(
996 'SELECT COUNT(auction) AS total '
997 . 'FROM \Auction\Entity\Auction auction '
998 . 'WHERE auction.jobState = \'Active\' '
999 . ' AND auction.archived = \'0\''
1001 ->getSingleResult();
1002 return $contract->success('Totals collected.', array('Items' => $result['total']));
1012 * CRON functionality: Move Auction items as needed.
1014 public function cronProcessCustom()
1016 ini_set('memory_limit', '512M');
1017 error_log('------------------------------------');
1018 error_log('Auction cron started @ ' . date('Y-m-d H:i:s'));
1020 $date = date('Y-m-d H:i:s');
1021 $result = $this->em->createQuery(
1022 'SELECT auction FROM \Auction\Entity\Auction auction '
1023 . 'WHERE auction.id IN (:ids)'
1025 ->setParameter('ids', array(30871, 30881, 30868, 30874, 30880, 30882, 30883, 30905))
1027 error_log("Item count: " . count($result));
1028 foreach ($result as $item)
1032 #-> General data prep.
1033 $vehicle = $item->stock->type->model->make->name
1034 . ', ' . $item->stock->type->model->name
1035 . ', ' . $item->stock->type->name;
1036 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
1037 $oNotify = new \Utility\Comms\Notification();
1039 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
1041 #-> Update record to reflect winner.
1042 if (is_null($item->soldToCompany))
1044 $item->soldToCompany = $item->currentBid->company;
1046 if (is_null($item->soldToProfile))
1048 $item->soldToProfile = $item->currentBid->profile;
1053 $pdf = new \Auction\Pdf\CompleteNew();
1054 $pdf->process(array(
1055 'jobRecord' => $item
1057 $docsDir = __DIR__ . '/../../../../../public/documents/';
1059 #-> Declaration PDF.
1060 $pdf_Declaration = new \Auction\Pdf\Declaration();
1061 $pdf_Declaration->process(array(
1062 'jobRecord' => $item
1064 $docsDir = __DIR__ . '/../../../../../public/documents/';
1066 #-> Deliveryreceipt PDF.
1067 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
1068 $pdf_Deliveryreceipt->process(array(
1069 'jobRecord' => $item
1071 $docsDir = __DIR__ . '/../../../../../public/documents/';
1073 $writer = new \Utility\Export\PdfTemplate($pdf);
1074 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
1075 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
1077 $attachments = array(
1078 'auction' . $item->id . '.pdf' => $writer->output(''),
1079 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
1080 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
1085 $oNotify->sendFromTemplate(
1086 $item->company->id, $item->createdBy->id,
1087 $item->currentBid->company->id, $item->currentBid->profile->id,
1088 'info@bid4cars.com.na', null,
1089 'Auction Successful - ' . $item->id,
1090 'auction-sale-buyer',
1092 'first_name' => 'Admin',
1093 'family_name' => '',
1094 'vehicle' => $vehicle,
1095 'price' => $currPrefix . $item->currentBid->amount,
1096 'seller' => $item->company->name,
1097 'seller_name' => $item->createdBy->firstName . ' '
1098 . $item->createdBy->familyName,
1099 'vehicle_address' => $item->company->city->region->name
1100 . ', ' . $item->company->city->name
1101 . ', ' . $item->company->street
1102 . ', ' . $item->company->postalCode,
1103 'seller_billing_address' => $item->company->billingCity
1104 ? $item->company->billingCity->region->name
1105 . ', ' . $item->company->billingCity->name
1106 . ', ' . $item->company->billingStreet
1107 . ', ' . $item->company->billingPostalCode
1109 'seller_vat_number' => !is_null($item->company->vatNumber)
1110 ? $item->company->vatNumber
1112 'seller_email' => $item->createdBy->email,
1113 'stock_number' => $item->stock->stockNumber,
1114 'buyer' => $item->currentBid->company->name,
1115 'buyer_name' => $item->currentBid->profile->firstName . ' '
1116 . $item->currentBid->profile->familyName,
1117 'buyer_address' => $item->currentBid->company->city->region->name
1118 . ', ' . $item->currentBid->company->city->name
1119 . ', ' . $item->currentBid->company->street
1120 . ', ' . $item->currentBid->company->postalCode,
1121 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1122 ? $item->currentBid->company->vatNumber
1124 'buyer_email' => $item->currentBid->profile->email,
1125 'buyer_mobile' => $item->currentBid->profile->mobile
1135 $oNotify->sendFromTemplate(
1136 $item->company->id, $item->createdBy->id,
1137 $item->currentBid->company->id, $item->currentBid->profile->id,
1138 'louise@combinefreight.co.za', null,
1139 'Auction Successful - ' . $item->id,
1140 'auction-sale-buyer',
1142 'first_name' => 'Admin',
1143 'family_name' => '',
1144 'vehicle' => $vehicle,
1145 'price' => $currPrefix . $item->currentBid->amount,
1146 'seller' => $item->company->name,
1147 'seller_name' => $item->createdBy->firstName . ' '
1148 . $item->createdBy->familyName,
1149 'vehicle_address' => $item->company->city->region->name
1150 . ', ' . $item->company->city->name
1151 . ', ' . $item->company->street
1152 . ', ' . $item->company->postalCode,
1153 'seller_billing_address' => $item->company->billingCity
1154 ? $item->company->billingCity->region->name
1155 . ', ' . $item->company->billingCity->name
1156 . ', ' . $item->company->billingStreet
1157 . ', ' . $item->company->billingPostalCode
1159 'seller_vat_number' => !is_null($item->company->vatNumber)
1160 ? $item->company->vatNumber
1162 'seller_email' => $item->createdBy->email,
1163 'stock_number' => $item->stock->stockNumber,
1164 'buyer' => $item->currentBid->company->name,
1165 'buyer_name' => $item->currentBid->profile->firstName . ' '
1166 . $item->currentBid->profile->familyName,
1167 'buyer_address' => $item->currentBid->company->city->region->name
1168 . ', ' . $item->currentBid->company->city->name
1169 . ', ' . $item->currentBid->company->street
1170 . ', ' . $item->currentBid->company->postalCode,
1171 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1172 ? $item->currentBid->company->vatNumber
1174 'buyer_email' => $item->currentBid->profile->email,
1175 'buyer_mobile' => $item->currentBid->profile->mobile
1184 $oNotify->sendFromTemplate(
1185 $item->company->id, $item->createdBy->id,
1186 $item->currentBid->company->id, $item->currentBid->profile->id,
1187 $item->currentBid->profile->email, null,
1188 'Bid Successful - ' . $item->id,
1189 'auction-sale-buyer',
1191 'first_name' => $item->currentBid->profile->firstName,
1192 'family_name' => $item->currentBid->profile->familyName,
1193 'vehicle' => $vehicle,
1194 'price' => $currPrefix . $item->currentBid->amount,
1195 'seller' => $item->company->name,
1196 'seller_name' => $item->createdBy->firstName . ' '
1197 . $item->createdBy->familyName,
1198 'vehicle_address' => $item->company->city->region->name
1199 . ', ' . $item->company->city->name
1200 . ', ' . $item->company->street
1201 . ', ' . $item->company->postalCode,
1202 'seller_billing_address' => $item->company->billingCity
1203 ? $item->company->billingCity->region->name
1204 . ', ' . $item->company->billingCity->name
1205 . ', ' . $item->company->billingStreet
1206 . ', ' . $item->company->billingPostalCode
1208 'seller_vat_number' => !is_null($item->company->vatNumber)
1209 ? $item->company->vatNumber
1211 'seller_email' => $item->createdBy->email,
1212 'stock_number' => $item->stock->stockNumber,
1213 'buyer' => $item->currentBid->company->name,
1214 'buyer_name' => $item->currentBid->profile->firstName . ' '
1215 . $item->currentBid->profile->familyName,
1216 'buyer_address' => $item->currentBid->company->city->region->name
1217 . ', ' . $item->currentBid->company->city->name
1218 . ', ' . $item->currentBid->company->street
1219 . ', ' . $item->currentBid->company->postalCode,
1220 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1221 ? $item->currentBid->company->vatNumber
1223 'buyer_email' => $item->currentBid->profile->email,
1224 'buyer_mobile' => $item->currentBid->profile->mobile
1234 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1236 //send `auction-sale-seller` email to $item->stock->company->contact->email
1237 $oNotify->sendFromTemplate(
1238 $item->company->id, $item->createdBy->id,
1239 $item->company->id, $item->createdBy->id,
1240 $item->stock->company->contact->email, null,
1241 'Auction Successful - ' . $item->id,
1242 'auction-sale-seller',
1244 'first_name' => $item->stock->company->contact->firstName,
1245 'family_name' => $item->stock->company->contact->familyName,
1246 'vehicle' => $vehicle,
1247 'price' => $currPrefix . $item->currentBid->amount,
1248 'buyer' => $item->currentBid->company->name,
1249 'buyer_name' => $item->currentBid->profile->firstName . ' '
1250 . $item->currentBid->profile->familyName,
1251 'buyer_address' => $item->currentBid->company->city->region->name
1252 . ', ' . $item->currentBid->company->city->name
1253 . ', ' . $item->currentBid->company->street
1254 . ', ' . $item->currentBid->company->postalCode,
1255 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1256 ? $item->currentBid->company->vatNumber
1258 'buyer_email' => $item->currentBid->profile->email,
1259 'buyer_mobile' => $item->currentBid->profile->mobile,
1260 'seller' => $item->company->name,
1261 'seller_name' => $item->createdBy->firstName . ' '
1262 . $item->createdBy->familyName,
1263 'vehicle_address' => $item->company->city->region->name
1264 . ', ' . $item->company->city->name
1265 . ', ' . $item->company->street
1266 . ', ' . $item->company->postalCode,
1267 'seller_billing_address' => $item->company->billingCity
1268 ? $item->company->billingCity->region->name
1269 . ', ' . $item->company->billingCity->name
1270 . ', ' . $item->company->billingStreet
1271 . ', ' . $item->company->billingPostalCode
1273 'seller_vat_number' => !is_null($item->company->vatNumber)
1274 ? $item->company->vatNumber
1276 'seller_email' => $item->createdBy->email,
1277 'stock_number' => $item->stock->stockNumber
1287 $oNotify->sendFromTemplate(
1288 $item->company->id, $item->createdBy->id,
1289 $item->company->id, $item->createdBy->id,
1290 $item->createdBy->email, null,
1291 'Auction Successful - ' . $item->id,
1292 'auction-sale-seller',
1294 'first_name' => $item->createdBy->firstName,
1295 'family_name' => $item->createdBy->familyName,
1296 'vehicle' => $vehicle,
1297 'price' => $currPrefix . $item->currentBid->amount,
1298 'buyer' => $item->currentBid->company->name,
1299 'buyer_name' => $item->currentBid->profile->firstName . ' '
1300 . $item->currentBid->profile->familyName,
1301 'buyer_address' => $item->currentBid->company->city->region->name
1302 . ', ' . $item->currentBid->company->city->name
1303 . ', ' . $item->currentBid->company->street
1304 . ', ' . $item->currentBid->company->postalCode,
1305 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1306 ? $item->currentBid->company->vatNumber
1308 'buyer_email' => $item->currentBid->profile->email,
1309 'buyer_mobile' => $item->currentBid->profile->mobile,
1310 'seller' => $item->company->name,
1311 'seller_name' => $item->createdBy->firstName . ' '
1312 . $item->createdBy->familyName,
1313 'vehicle_address' => $item->company->city->region->name
1314 . ', ' . $item->company->city->name
1315 . ', ' . $item->company->street
1316 . ', ' . $item->company->postalCode,
1317 'seller_billing_address' => $item->company->billingCity
1318 ? $item->company->billingCity->region->name
1319 . ', ' . $item->company->billingCity->name
1320 . ', ' . $item->company->billingStreet
1321 . ', ' . $item->company->billingPostalCode
1323 'seller_vat_number' => !is_null($item->company->vatNumber)
1324 ? $item->company->vatNumber
1326 'seller_email' => $item->createdBy->email,
1327 'stock_number' => $item->stock->stockNumber
1334 $attachments = array();
1338 #-> No winner, send notification to seller & admin & feeder dealer.
1339 $oNotify->sendFromTemplate(
1340 $item->company->id, $item->createdBy->id,
1341 $item->company->id, $item->createdBy->id,
1342 $item->createdBy->email, null,
1343 'No winner on Bid4Cars Auction - ' . $item->id,
1346 'first_name' => $item->createdBy->firstName,
1347 'family_name' => $item->createdBy->familyName,
1348 'vehicle' => $vehicle,
1349 'reservePrice' => $item->reservePrice,
1350 'registrationNumber' => $item->stock->registrationNumber,
1351 'stockNumber' => $item->stock->stockNumber
1359 $oNotify->sendFromTemplate(
1360 $item->company->id, $item->createdBy->id,
1361 $item->company->id, $item->createdBy->id,
1362 'info@bid4cars.com.na', null,
1363 'No winner on Bid4Cars Auction - ' . $item->id,
1366 'first_name' => $item->createdBy->firstName,
1367 'family_name' => $item->createdBy->familyName,
1368 'vehicle' => $vehicle,
1369 'reservePrice' => $item->reservePrice,
1370 'registrationNumber' => $item->stock->registrationNumber,
1371 'stockNumber' => $item->stock->stockNumber
1380 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1382 $oNotify->sendFromTemplate(
1383 $item->company->id, $item->createdBy->id,
1384 $item->company->id, $item->createdBy->id,
1385 $item->stock->company->contact->email, null,
1386 'No winner on Bid4Cars Auction - ' . $item->id,
1389 'first_name' => $item->stock->company->contact->firstName,
1390 'family_name' => $item->stock->company->contact->familyName,
1391 'vehicle' => $vehicle,
1392 'reservePrice' => $item->reservePrice,
1393 'registrationNumber' => $item->stock->registrationNumber,
1394 'stockNumber' => $item->stock->stockNumber
1405 $item->emailSent = true;
1406 $this->em->flush($item);
1408 catch (\Exception $e)
1410 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
1413 error_log('Auction cron ended @ ' . date('Y-m-d H:i:s'));
1414 error_log('------------------------------------');
1418 * CRON functionality: Move Auction items as needed.
1420 public function cronProcessCleanup()
1422 $mailTo = 'dino@nirph.com';
1423 ini_set('memory_limit', '512M');
1424 error_log('------------------------------------');
1425 error_log('Auction cleanup cron started @ ' . date('Y-m-d H:i:s'));
1429 $numRecsRes = $this->em->createQuery(
1430 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction '
1431 . 'WHERE auction.endDate <= \'' . date('Y-m-d H:i:s') . '\''
1432 . ' AND auction.endDate > \'' . date('Y-m-d') . ' 00:00:00\''
1433 . ' AND auction.jobState != :jobStateArchived'
1435 ->setParameter('jobStateArchived', 'Archived')
1436 ->getSingleResult();
1437 $totalItems = (int)$numRecsRes['total'];
1438 $numRecsRes = $this->em->createQuery(
1439 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction '
1440 . 'WHERE auction.jobState = :jobState '
1441 . ' AND auction.endDate <= :startDate'
1442 . ' AND auction.endDate > :endDate'
1444 ->setParameter('jobState', 'Sold')
1445 ->setParameter('startDate', date('Y-m-d H:i:s'))
1446 ->setParameter('endDate', date('Y-m-d') . ' 00:00:00')
1447 ->getSingleResult();
1448 $successItems = (int)$numRecsRes['total'];
1449 // $result = $this->em->createQuery(
1450 // 'SELECT auction FROM \Auction\Entity\Auction auction '
1451 // . 'WHERE auction.jobState != :jobState AND auction.jobState != :jobStateTwo'
1452 // . ' AND auction.emailSent = :emailSent'
1454 // ->setParameter('jobState', 'Active')
1455 // ->setParameter('jobStateTwo', 'Relist')
1456 // ->setParameter('emailSent', false)
1459 $result = $this->em->createQuery(
1460 'SELECT auction FROM \Auction\Entity\Auction auction '
1461 . 'WHERE auction.jobState != :jobState'
1462 . ' AND auction.jobState != :jobStateArchived'
1463 . ' AND auction.emailSent = :emailSent'
1465 ->setParameter('jobState', 'Active')
1466 ->setParameter('jobStateArchived', 'Archived')
1467 ->setParameter('emailSent', false)
1470 $mailer = new \Utility\Comms\Email();
1471 $mailer->send(array(
1472 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'),
1474 'Subject' => 'Auction cleanup cron Start - ' . date('Y-m-d H:i:s'),
1475 'Html' => '<b>Total auction items:<//b> ' . $totalItems . '<br//>'
1476 . '<b>Total items sold:<//b> ' . $successItems . '<br//>'
1477 . '<b>Total items no winner:<//b> ' . ($totalItems - $successItems) . '<br//>'
1478 . '<b>Mails not yet sent:<//b> ' . count($result) . '<br//>'
1483 error_log("Item count: " . count($result));
1484 foreach ($result as $item)
1488 #-> General data prep.
1489 $vehicle = $item->stock->type->model->make->name
1490 . ', ' . $item->stock->type->model->name
1491 . ', ' . $item->stock->type->name;
1492 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
1493 $oNotify = new \Utility\Comms\Notification();
1495 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
1497 #-> Update record to reflect winner.
1498 if (is_null($item->soldToCompany))
1500 $item->soldToCompany = $item->currentBid->company;
1502 if (is_null($item->soldToProfile))
1504 $item->soldToProfile = $item->currentBid->profile;
1509 $pdf = new \Auction\Pdf\CompleteNew();
1510 $pdf->process(array(
1511 'jobRecord' => $item
1513 $docsDir = __DIR__ . '/../../../../../public/documents/';
1515 #-> Declaration PDF.
1516 $pdf_Declaration = new \Auction\Pdf\Declaration();
1517 $pdf_Declaration->process(array(
1518 'jobRecord' => $item
1520 $docsDir = __DIR__ . '/../../../../../public/documents/';
1522 #-> Deliveryreceipt PDF.
1523 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
1524 $pdf_Deliveryreceipt->process(array(
1525 'jobRecord' => $item
1527 $docsDir = __DIR__ . '/../../../../../public/documents/';
1529 $writer = new \Utility\Export\PdfTemplate($pdf);
1530 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
1531 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
1533 $attachments = array(
1534 'auction' . $item->id . '.pdf' => $writer->output(''),
1535 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
1536 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
1541 $oNotify->sendFromTemplate(
1542 $item->company->id, $item->createdBy->id,
1543 $item->currentBid->company->id, $item->currentBid->profile->id,
1544 'info@bid4cars.com.na', null,
1545 'Auction Successful - ' . $item->id,
1546 'auction-sale-buyer',
1548 'first_name' => 'Admin',
1549 'family_name' => '',
1550 'vehicle' => $vehicle,
1551 'price' => $currPrefix . $item->currentBid->amount,
1552 'seller' => $item->company->name,
1553 'seller_name' => $item->createdBy->firstName . ' '
1554 . $item->createdBy->familyName,
1555 'vehicle_address' => $item->company->city->region->name
1556 . ', ' . $item->company->city->name
1557 . ', ' . $item->company->street
1558 . ', ' . $item->company->postalCode,
1559 'seller_billing_address' => $item->company->billingCity
1560 ? $item->company->billingCity->region->name
1561 . ', ' . $item->company->billingCity->name
1562 . ', ' . $item->company->billingStreet
1563 . ', ' . $item->company->billingPostalCode
1565 'seller_vat_number' => !is_null($item->company->vatNumber)
1566 ? $item->company->vatNumber
1568 'seller_email' => $item->createdBy->email,
1569 'stock_number' => $item->stock->stockNumber,
1570 'buyer' => $item->currentBid->company->name,
1571 'buyer_name' => $item->currentBid->profile->firstName . ' '
1572 . $item->currentBid->profile->familyName,
1573 'buyer_address' => $item->currentBid->company->city->region->name
1574 . ', ' . $item->currentBid->company->city->name
1575 . ', ' . $item->currentBid->company->street
1576 . ', ' . $item->currentBid->company->postalCode,
1577 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1578 ? $item->currentBid->company->vatNumber
1580 'buyer_email' => $item->currentBid->profile->email,
1581 'buyer_mobile' => $item->currentBid->profile->mobile
1590 $oNotify->sendFromTemplate(
1591 $item->company->id, $item->createdBy->id,
1592 $item->currentBid->company->id, $item->currentBid->profile->id,
1593 'louise@combinefreight.co.za', null,
1594 'Auction Successful - ' . $item->id,
1595 'auction-sale-buyer',
1597 'first_name' => 'Admin',
1598 'family_name' => '',
1599 'vehicle' => $vehicle,
1600 'price' => $currPrefix . $item->currentBid->amount,
1601 'seller' => $item->company->name,
1602 'seller_name' => $item->createdBy->firstName . ' '
1603 . $item->createdBy->familyName,
1604 'vehicle_address' => $item->company->city->region->name
1605 . ', ' . $item->company->city->name
1606 . ', ' . $item->company->street
1607 . ', ' . $item->company->postalCode,
1608 'seller_billing_address' => $item->company->billingCity
1609 ? $item->company->billingCity->region->name
1610 . ', ' . $item->company->billingCity->name
1611 . ', ' . $item->company->billingStreet
1612 . ', ' . $item->company->billingPostalCode
1614 'seller_vat_number' => !is_null($item->company->vatNumber)
1615 ? $item->company->vatNumber
1617 'seller_email' => $item->createdBy->email,
1618 'stock_number' => $item->stock->stockNumber,
1619 'buyer' => $item->currentBid->company->name,
1620 'buyer_name' => $item->currentBid->profile->firstName . ' '
1621 . $item->currentBid->profile->familyName,
1622 'buyer_address' => $item->currentBid->company->city->region->name
1623 . ', ' . $item->currentBid->company->city->name
1624 . ', ' . $item->currentBid->company->street
1625 . ', ' . $item->currentBid->company->postalCode,
1626 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1627 ? $item->currentBid->company->vatNumber
1629 'buyer_email' => $item->currentBid->profile->email,
1630 'buyer_mobile' => $item->currentBid->profile->mobile
1639 $oNotify->sendFromTemplate(
1640 $item->company->id, $item->createdBy->id,
1641 $item->currentBid->company->id, $item->currentBid->profile->id,
1642 $item->currentBid->profile->email, null,
1643 'Bid Successful - ' . $item->id,
1644 'auction-sale-buyer',
1646 'first_name' => $item->currentBid->profile->firstName,
1647 'family_name' => $item->currentBid->profile->familyName,
1648 'vehicle' => $vehicle,
1649 'price' => $currPrefix . $item->currentBid->amount,
1650 'seller' => $item->company->name,
1651 'seller_name' => $item->createdBy->firstName . ' '
1652 . $item->createdBy->familyName,
1653 'vehicle_address' => $item->company->city->region->name
1654 . ', ' . $item->company->city->name
1655 . ', ' . $item->company->street
1656 . ', ' . $item->company->postalCode,
1657 'seller_billing_address' => $item->company->billingCity
1658 ? $item->company->billingCity->region->name
1659 . ', ' . $item->company->billingCity->name
1660 . ', ' . $item->company->billingStreet
1661 . ', ' . $item->company->billingPostalCode
1663 'seller_vat_number' => !is_null($item->company->vatNumber)
1664 ? $item->company->vatNumber
1666 'seller_email' => $item->createdBy->email,
1667 'stock_number' => $item->stock->stockNumber,
1668 'buyer' => $item->currentBid->company->name,
1669 'buyer_name' => $item->currentBid->profile->firstName . ' '
1670 . $item->currentBid->profile->familyName,
1671 'buyer_address' => $item->currentBid->company->city->region->name
1672 . ', ' . $item->currentBid->company->city->name
1673 . ', ' . $item->currentBid->company->street
1674 . ', ' . $item->currentBid->company->postalCode,
1675 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1676 ? $item->currentBid->company->vatNumber
1678 'buyer_email' => $item->currentBid->profile->email,
1679 'buyer_mobile' => $item->currentBid->profile->mobile
1688 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1690 //send `auction-sale-seller` email to $item->stock->company->contact->email
1691 $oNotify->sendFromTemplate(
1692 $item->company->id, $item->createdBy->id,
1693 $item->company->id, $item->createdBy->id,
1694 $item->stock->company->contact->email, null,
1695 'Auction Successful - ' . $item->id,
1696 'auction-sale-seller',
1698 'first_name' => $item->stock->company->contact->firstName,
1699 'family_name' => $item->stock->company->contact->familyName,
1700 'vehicle' => $vehicle,
1701 'price' => $currPrefix . $item->currentBid->amount,
1702 'buyer' => $item->currentBid->company->name,
1703 'buyer_name' => $item->currentBid->profile->firstName . ' '
1704 . $item->currentBid->profile->familyName,
1705 'buyer_address' => $item->currentBid->company->city->region->name
1706 . ', ' . $item->currentBid->company->city->name
1707 . ', ' . $item->currentBid->company->street
1708 . ', ' . $item->currentBid->company->postalCode,
1709 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1710 ? $item->currentBid->company->vatNumber
1712 'buyer_email' => $item->currentBid->profile->email,
1713 'buyer_mobile' => $item->currentBid->profile->mobile,
1714 'seller' => $item->company->name,
1715 'seller_name' => $item->createdBy->firstName . ' '
1716 . $item->createdBy->familyName,
1717 'vehicle_address' => $item->company->city->region->name
1718 . ', ' . $item->company->city->name
1719 . ', ' . $item->company->street
1720 . ', ' . $item->company->postalCode,
1721 'seller_billing_address' => $item->company->billingCity
1722 ? $item->company->billingCity->region->name
1723 . ', ' . $item->company->billingCity->name
1724 . ', ' . $item->company->billingStreet
1725 . ', ' . $item->company->billingPostalCode
1727 'seller_vat_number' => !is_null($item->company->vatNumber)
1728 ? $item->company->vatNumber
1730 'seller_email' => $item->createdBy->email,
1731 'stock_number' => $item->stock->stockNumber
1742 $oNotify->sendFromTemplate(
1743 $item->company->id, $item->createdBy->id,
1744 $item->company->id, $item->createdBy->id,
1745 $item->createdBy->email, null,
1746 'Auction Successful - ' . $item->id,
1747 'auction-sale-seller',
1749 'first_name' => $item->createdBy->firstName,
1750 'family_name' => $item->createdBy->familyName,
1751 'vehicle' => $vehicle,
1752 'price' => $currPrefix . $item->currentBid->amount,
1753 'buyer' => $item->currentBid->company->name,
1754 'buyer_name' => $item->currentBid->profile->firstName . ' '
1755 . $item->currentBid->profile->familyName,
1756 'buyer_address' => $item->currentBid->company->city->region->name
1757 . ', ' . $item->currentBid->company->city->name
1758 . ', ' . $item->currentBid->company->street
1759 . ', ' . $item->currentBid->company->postalCode,
1760 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1761 ? $item->currentBid->company->vatNumber
1763 'buyer_email' => $item->currentBid->profile->email,
1764 'buyer_mobile' => $item->currentBid->profile->mobile,
1765 'seller' => $item->company->name,
1766 'seller_name' => $item->createdBy->firstName . ' '
1767 . $item->createdBy->familyName,
1768 'vehicle_address' => $item->company->city->region->name
1769 . ', ' . $item->company->city->name
1770 . ', ' . $item->company->street
1771 . ', ' . $item->company->postalCode,
1772 'seller_billing_address' => $item->company->billingCity
1773 ? $item->company->billingCity->region->name
1774 . ', ' . $item->company->billingCity->name
1775 . ', ' . $item->company->billingStreet
1776 . ', ' . $item->company->billingPostalCode
1778 'seller_vat_number' => !is_null($item->company->vatNumber)
1779 ? $item->company->vatNumber
1781 'seller_email' => $item->createdBy->email,
1782 'stock_number' => $item->stock->stockNumber
1789 $attachments = array();
1793 #-> No winner, send notification to seller & admin & feeder.
1794 $oNotify->sendFromTemplate(
1795 $item->company->id, $item->createdBy->id,
1796 $item->company->id, $item->createdBy->id,
1797 $item->createdBy->email, null,
1798 'No winner on Bid4Cars Auction - ' . $item->id,
1801 'first_name' => $item->createdBy->firstName,
1802 'family_name' => $item->createdBy->familyName,
1803 'vehicle' => $vehicle,
1804 'reservePrice' => $item->reservePrice,
1805 'registrationNumber' => $item->stock->registrationNumber,
1806 'stockNumber' => $item->stock->stockNumber
1813 $oNotify->sendFromTemplate(
1814 $item->company->id, $item->createdBy->id,
1815 $item->company->id, $item->createdBy->id,
1816 'info@bid4cars.com.na', null,
1817 'No winner on Bid4Cars Auction - ' . $item->id,
1820 'first_name' => $item->createdBy->firstName,
1821 'family_name' => $item->createdBy->familyName,
1822 'vehicle' => $vehicle,
1823 'reservePrice' => $item->reservePrice,
1824 'registrationNumber' => $item->stock->registrationNumber,
1825 'stockNumber' => $item->stock->stockNumber
1833 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1835 $oNotify->sendFromTemplate(
1836 $item->company->id, $item->createdBy->id,
1837 $item->company->id, $item->createdBy->id,
1838 $item->stock->company->contact->email, null,
1839 'No winner on Bid4Cars Auction - ' . $item->id,
1842 'first_name' => $item->stock->company->contact->firstName,
1843 'family_name' => $item->stock->company->contact->familyName,
1844 'vehicle' => $vehicle,
1845 'reservePrice' => $item->reservePrice,
1846 'registrationNumber' => $item->stock->registrationNumber,
1847 'stockNumber' => $item->stock->stockNumber
1858 $item->emailSent = true;
1859 $this->em->flush($item);
1862 catch (\Exception $e)
1864 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
1867 error_log('Auction cleanup cron ended @ ' . date('Y-m-d H:i:s'));
1868 error_log('------------------------------------');
1871 $mailer = new \Utility\Comms\Email();
1872 $mailer->send(array(
1873 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'),
1875 'Subject' => 'Auction cleanup cron End - ' . date('Y-m-d H:i:s'),
1876 'Html' => '<b>Total auction items:<//b> ' . $totalItems . '<br//>'
1877 . '<b>Emails sent:<//b> ' . $sent . ' of ' . count($result) . '<br//>'