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 #-> Establish initial increment value.
25 $increments = $this->em
26 ->getRepository('\Auction\Entity\Increment')
27 ->findBy(array(), array('to' => 'ASC'));
28 foreach ($increments as $incr)
30 if ($incr->to >= $routingData['reservePrice']
31 && $incr->from <= $routingData['reservePrice']
37 #-> Create auction entry.
38 if (isset($routingData['profileId']))
40 $profile = $this->em->find('User\\Entity\\Profile', $routingData['profileId']);
41 $email = $profile->email;
42 $firstName = $profile->firstName;
43 $familyName = $profile->familyName;
44 $company = !is_null($profile->company)
45 ? $profile->company->id
47 $profile = $profile->id;
51 $authData = \Utility\Registry::getAuthData();
52 $email = $authData['email'];
53 $firstName = $authData['firstName'];
54 $familyName = $authData['familyName'];
55 $profile = \Utility\Registry::resolveProfileContext()->id;
56 $company = \Utility\Registry::resolveCompanyContext()->id;
58 $routingData['endDate'] = str_replace(' 00:00:00', '', $routingData['endDate']);
59 $record = $this->create(array(
60 'createdBy' => $profile,
61 'company' => $company,
62 'stock' => $stock->id,
63 'reservePrice' => $routingData['reservePrice'],
64 'currentBidPrice' => $routingData['reservePrice'],
65 'bidIncrement' => $incr->amount,
66 'startDate' => new \DateTime("now"),
67 'endDate' => new \DateTime($routingData['endDate'] . ' 14:30:00')
70 #-> Update stock with count of times sent to auction.
71 $stats = $this->em->createQuery(
72 'SELECT COUNT(auction.id) AS numAuctions '
73 . 'FROM \Auction\Entity\Auction auction '
74 . 'WHERE IDENTITY(auction.stock) = :stockId'
76 ->setParameter('stockId', $stock->id)
78 $stock->auction = $record;
79 $stock->highestBid = 0.00;
80 $stock->timesListed = $stats['numAuctions'];
81 $this->em->flush($stock);
83 #-> Send loaded notification.
85 $pdf = new \Auction\Pdf\Complete();
87 'jobRecord' => $record
89 $docsDir = __DIR__ . '/../../../../../public/documents/';
90 $writer = new \Utility\Export\PdfTemplate($pdf);
92 'auction' . $record->id . '.pdf' => $writer->output(''),
93 'REGULATION_32_NOTICE_38960.pdf' => file_get_contents($docsDir . 'REGULATION_32_NOTICE_38960.pdf')
96 $oNotify = new \Utility\Comms\Notification();
97 $oNotify->sendFromTemplate(
101 'Vehicle live on Bid4Cars Auction - ' . $record->id,
104 'first_name' => $firstName,
105 'family_name' => $familyName,
106 'make' => $stock->type->model->make->name,
107 'model' => $stock->type->model->name,
108 'type' => $stock->type->name,
109 'image' => !is_null($stock->mainImage)
110 ? $stock->mainImage->filename
121 * Contract to get selectlist.
122 * @param object|null $jobRecord
123 * @param array $input
124 * @return \Workspace\Contract\UseOnce
126 public function contractHistoricMakeSelectList($jobRecord, array $input = array())
128 $options = new \Workspace\UseCase\Options();
129 $requirement = new \Workspace\UseCase\Requirement();
130 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
131 return new \Workspace\Contract\UseOnce($options, $requirement);
136 * @param object|null $jobRecord
137 * @param \Workspace\Utility\ServiceInputParams $contract
141 public function executeHistoricMakeSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
143 $em = \Utility\Registry::getEntityManager();
144 $authData = \Utility\Registry::getAuthData();
145 $companyId = $authData['company']['id'];
147 $queryFilter = array();
148 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
150 foreach ($contract->data->filter['Filters'] as $field => $filter)
152 $queryFilter[] = $field . ' = ' . $filter;
156 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
158 $memberslistdrop = $em->createQuery('
159 SELECT distinct make.id, make.name FROM \Auction\Entity\Auction auction
160 JOIN auction.company company
161 JOIN company.city city
162 JOIN company.contact contact
163 JOIN city.region region
164 JOIN auction.stock stock
165 JOIN stock.company companyStock
166 JOIN stock.vehicleYear vehicleYear
168 JOIN type.model model
170 LEFT JOIN stock.exteriorColour exteriorColour
171 LEFT JOIN auction.currentBid currentBid
172 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
173 'ORDER BY make.name');
175 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
176 $memberslistdrop->setParameter('sold', 'Sold');
177 $memberslistu = $memberslistdrop->getArrayResult();
179 foreach ($memberslistu as $data)
184 'value' => $data['id'],
185 'label' => $data['name']
188 return $contract->success('List Retrieved.', $datax);
192 * Contract to get selectlist.
193 * @param object|null $jobRecord
194 * @param array $input
195 * @return \Workspace\Contract\UseOnce
197 public function contractHistoricModelSelectList($jobRecord, array $input = array())
199 $options = new \Workspace\UseCase\Options();
200 $requirement = new \Workspace\UseCase\Requirement();
201 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
202 return new \Workspace\Contract\UseOnce($options, $requirement);
207 * @param object|null $jobRecord
208 * @param \Workspace\Utility\ServiceInputParams $contract
212 public function executeHistoricModelSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
214 $em = \Utility\Registry::getEntityManager();
215 $authData = \Utility\Registry::getAuthData();
216 $companyId = $authData['company']['id'];
218 $queryFilter = array();
219 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
221 foreach ($contract->data->filter['Filters'] as $field => $filter)
223 $queryFilter[] = $field . ' = ' . $filter;
227 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
229 $memberslistdrop = $em->createQuery('
230 SELECT distinct model.id, model.name FROM \Auction\Entity\Auction auction
231 JOIN auction.company company
232 JOIN company.city city
233 JOIN company.contact contact
234 JOIN city.region region
235 JOIN auction.stock stock
236 JOIN stock.company companyStock
237 JOIN stock.vehicleYear vehicleYear
239 JOIN type.model model
241 LEFT JOIN stock.exteriorColour exteriorColour
242 LEFT JOIN auction.currentBid currentBid
243 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
244 'ORDER BY model.name');
246 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
247 $memberslistdrop->setParameter('sold', 'Sold');
248 $memberslistu = $memberslistdrop->getArrayResult();
250 foreach ($memberslistu as $data)
255 'value' => $data['id'],
256 'label' => $data['name']
259 return $contract->success('List Retrieved.', $datax);
263 * Contract to get selectlist.
264 * @param object|null $jobRecord
265 * @param array $input
266 * @return \Workspace\Contract\UseOnce
268 public function contractHistoricTypeSelectList($jobRecord, array $input = array())
270 $options = new \Workspace\UseCase\Options();
271 $requirement = new \Workspace\UseCase\Requirement();
272 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
273 return new \Workspace\Contract\UseOnce($options, $requirement);
278 * @param object|null $jobRecord
279 * @param \Workspace\Utility\ServiceInputParams $contract
283 public function executeHistoricTypeSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
285 $em = \Utility\Registry::getEntityManager();
286 $authData = \Utility\Registry::getAuthData();
287 $companyId = $authData['company']['id'];
289 $queryFilter = array();
290 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
292 foreach ($contract->data->filter['Filters'] as $field => $filter)
294 $queryFilter[] = $field . ' = ' . $filter;
298 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
300 $memberslistdrop = $em->createQuery('
301 SELECT distinct type.id, type.name FROM \Auction\Entity\Auction auction
302 JOIN auction.company company
303 JOIN company.city city
304 JOIN company.contact contact
305 JOIN city.region region
306 JOIN auction.stock stock
307 JOIN stock.company companyStock
308 JOIN stock.vehicleYear vehicleYear
310 JOIN type.model model
312 LEFT JOIN stock.exteriorColour exteriorColour
313 LEFT JOIN auction.currentBid currentBid
314 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
315 'ORDER BY type.name');
317 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
318 $memberslistdrop->setParameter('sold', 'Sold');
319 $memberslistu = $memberslistdrop->getArrayResult();
321 foreach ($memberslistu as $data)
326 'value' => $data['id'],
327 'label' => $data['name']
330 return $contract->success('List Retrieved.', $datax);
334 * Contract to get selectlist.
335 * @param object|null $jobRecord
336 * @param array $input
337 * @return \Workspace\Contract\UseOnce
339 public function contractHistoricYearSelectList($jobRecord, array $input = array())
341 $options = new \Workspace\UseCase\Options();
342 $requirement = new \Workspace\UseCase\Requirement();
343 $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array')));
344 return new \Workspace\Contract\UseOnce($options, $requirement);
349 * @param object|null $jobRecord
350 * @param \Workspace\Utility\ServiceInputParams $contract
354 public function executeHistoricYearSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
356 $em = \Utility\Registry::getEntityManager();
357 $authData = \Utility\Registry::getAuthData();
358 $companyId = $authData['company']['id'];
360 $queryFilter = array();
361 if (isset($contract->data->filter) && is_array($contract->data->filter['Filters']))
363 foreach ($contract->data->filter['Filters'] as $field => $filter)
365 $queryFilter[] = $field . ' = ' . $filter;
369 $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : '';
371 $memberslistdrop = $em->createQuery('
372 SELECT distinct vehicleYear.id, vehicleYear.name FROM \Auction\Entity\Auction auction
373 JOIN auction.company company
374 JOIN company.city city
375 JOIN company.contact contact
376 JOIN city.region region
377 JOIN auction.stock stock
378 JOIN stock.company companyStock
379 JOIN stock.vehicleYear vehicleYear
381 JOIN type.model model
383 LEFT JOIN stock.exteriorColour exteriorColour
384 LEFT JOIN auction.currentBid currentBid
385 WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter .
386 'ORDER BY vehicleYear.name');
388 $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days'));
389 $memberslistdrop->setParameter('sold', 'Sold');
390 $memberslistu = $memberslistdrop->getArrayResult();
392 foreach ($memberslistu as $data)
397 'value' => $data['id'],
398 'label' => $data['name']
401 return $contract->success('List Retrieved.', $datax);
405 * Contract to remove item from auction.
406 * @param object|null $jobRecord
407 * @param array $input
408 * @return \Workspace\Contract\UseOnce
410 public function contractRemove($jobRecord, array $input = array())
412 $options = new \Workspace\UseCase\Options();
413 $requirement = new \Workspace\UseCase\Requirement();
414 return new \Workspace\Contract\UseOnce($options, $requirement);
418 * Remove item from auction.
419 * @param object|null $jobRecord
420 * @param \Workspace\Utility\ServiceInputParams $contract
424 public function executeRemove($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
428 $workflow = \Utility\Registry::getServiceManager()
430 $workflow->handover('Auction', $jobRecord->stock->id);
432 catch (\Exception $e)
434 \Utility\Debug::errorLog(
435 'Error on Auction removal process for item ' . $jobRecord->id,
439 $this->workflowNode->changeState('This.Archived');
440 return $contract->success('Vehicle removed from auction.', array());
444 * Contract to undo auction.
445 * @param object|null $jobRecord
446 * @param array $input
447 * @return \Workspace\Contract\UseOnce
449 public function contractUndo($jobRecord, array $input = array())
451 $options = new \Workspace\UseCase\Options();
452 $requirement = new \Workspace\UseCase\Requirement();
453 return new \Workspace\Contract\UseOnce($options, $requirement);
458 * @param object|null $jobRecord
459 * @param \Workspace\Utility\ServiceInputParams $contract
463 public function executeUndo($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
465 $this->workflowNode->changeState('This.Undone');
466 $jobRecord->currentBid->status = 'Undone';
470 $workflow = \Utility\Registry::getServiceManager()
472 $workflow->handover('Auction', $jobRecord->stock->id);
474 catch (\Exception $e)
476 \Utility\Debug::errorLog(
477 'Error on Auction Undo process for item ' . $jobRecord->id,
482 return $contract->success('Vehicle removed from auction.', array());
486 * CRON functionality: Send newsletter of cars coming off from auction today.
488 public function newsletterProcess()
491 ini_set('memory_limit', '512M');
493 $date = date('Y-m-d 23:59:59');
494 $data = $this->em->createQuery(
495 'SELECT DISTINCT auction.id, auction.reservePrice AS auction_reservePrice, stock.km AS stock_km, '
496 . 'type.name AS type_name, type.mmCode AS type_mmCode, model.name AS model_name, '
497 . 'make.name AS make_name, vehicleYear.name AS vehicleYear_name, region.name AS region_name '
498 . 'FROM \Auction\Entity\Auction auction '
499 . 'JOIN auction.stock stock '
500 . 'JOIN stock.type type '
501 . 'JOIN type.model model '
502 . 'JOIN model.make make '
503 . 'JOIN stock.vehicleYear vehicleYear '
504 . 'LEFT JOIN stock.company company '
505 . 'LEFT JOIN company.city city '
506 . 'LEFT JOIN company.contact contact'
507 . 'LEFT JOIN city.region region '
508 . 'WHERE auction.jobState = \'Active\''
509 . ' AND auction.endDate >= :startDate '
510 . ' AND auction.endDate <= :endDate '
511 . 'ORDER BY make.name, model.name, type.name ASC'
513 ->setParameter('startDate', date('Y-m-d 01:00:00'))
514 ->setParameter('endDate', date('Y-m-d 23:59:59'))
522 $oNotify = new \Utility\Comms\Notification();
523 $oNotify->setRepeaterData($data);
524 $oNotify->setSendAsNewsletter();
525 $oNotify->sendFromTemplate(
534 array('auctioncount' => $i)
539 * CRON functionality: Move Auction items as needed.
541 public function cronProcess()
543 ini_set('memory_limit', '512M');
544 error_log('------------------------------------');
545 error_log('Auction cron started @ ' . date('Y-m-d H:i:s'));
547 $date = date('Y-m-d H:i:s');
548 $result = $this->em->createQuery(
549 'SELECT auction FROM \Auction\Entity\Auction auction '
550 . 'WHERE auction.jobState = \'Active\''
551 . ' AND auction.jobState != \'Archived\''
552 . ' AND auction.endDate <= \'' . $date . '\''
555 $workflow = \Utility\Registry::getServiceManager()
557 error_log("Item count: " . count($result));
558 foreach ($result as $item)
560 $this->workflowNode->setJob($item);
563 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice)
565 #-> We have a winner.
566 $item->soldToCompany = $item->currentBid->company;
567 $item->soldToProfile = $item->currentBid->profile;
568 $this->workflowNode->changeState('This.Sold');
572 #-> Each and every one a loser.
573 $this->workflowNode->changeState('This.Relist');
576 catch (\Exception $e)
578 \Utility\Debug::errorLog('Error on Auction cron process (state change) for item ' . $item->id, $e->getMessage());
582 $workflow->handover('Auction', $item->stock->id);
584 catch (\Exception $e)
586 \Utility\Debug::errorLog('Error on Auction cron process (handover) for item ' . $item->id, $e->getMessage());
590 foreach ($result as $item)
595 #-> General data prep.
596 $vehicle = $item->stock->type->model->make->name
597 . ', ' . $item->stock->type->model->name
598 . ', ' . $item->stock->type->name;
599 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
600 $oNotify = new \Utility\Comms\Notification();
602 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
604 #-> Update record to reflect winner.
605 $item->soldToCompany = $item->currentBid->company;
606 $item->soldToProfile = $item->currentBid->profile;
611 $pdf = new \Auction\Pdf\CompleteNew();
615 $docsDir = __DIR__ . '/../../../../../public/documents/';
618 $pdf_Declaration = new \Auction\Pdf\Declaration();
619 $pdf_Declaration->process(array(
622 $docsDir = __DIR__ . '/../../../../../public/documents/';
624 #-> Deliveryreceipt PDF.
625 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
626 $pdf_Deliveryreceipt->process(array(
629 $docsDir = __DIR__ . '/../../../../../public/documents/';
631 $writer = new \Utility\Export\PdfTemplate($pdf);
632 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
633 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
635 $attachments = array(
636 'auction' . $item->id . '.pdf' => $writer->output(''),
637 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
638 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
643 $oNotify->sendFromTemplate(
644 $item->company->id, $item->createdBy->id,
645 $item->currentBid->company->id, $item->currentBid->profile->id,
646 'info@bid4cars.com.na', null,
647 'Auction Successful - ' . $item->id,
648 'auction-sale-buyer',
650 'first_name' => 'Admin',
652 'vehicle' => $vehicle,
653 'price' => $currPrefix . $item->currentBid->amount,
654 'seller' => $item->company->name,
655 'seller_name' => $item->createdBy->firstName . ' '
656 . $item->createdBy->familyName,
657 'vehicle_address' => $item->company->city->region->name
658 . ', ' . $item->company->city->name
659 . ', ' . $item->company->street
660 . ', ' . $item->company->postalCode,
661 'seller_billing_address' => $item->company->billingCity
662 ? $item->company->billingCity->region->name
663 . ', ' . $item->company->billingCity->name
664 . ', ' . $item->company->billingStreet
665 . ', ' . $item->company->billingPostalCode
667 'seller_vat_number' => !is_null($item->company->vatNumber)
668 ? $item->company->vatNumber
670 'seller_email' => $item->createdBy->email,
671 'stock_number' => $item->stock->stockNumber,
672 'buyer' => $item->currentBid->company->name,
673 'buyer_name' => $item->currentBid->profile->firstName . ' '
674 . $item->currentBid->profile->familyName,
675 'buyer_address' => $item->currentBid->company->city->region->name
676 . ', ' . $item->currentBid->company->city->name
677 . ', ' . $item->currentBid->company->street
678 . ', ' . $item->currentBid->company->postalCode,
679 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
680 ? $item->currentBid->company->vatNumber
682 'buyer_email' => $item->currentBid->profile->email,
683 'buyer_mobile' => $item->currentBid->profile->mobile
691 #-> Combined freight.
692 $oNotify->sendFromTemplate(
693 $item->company->id, $item->createdBy->id,
694 $item->currentBid->company->id, $item->currentBid->profile->id,
695 'louise@combinefreight.co.za', null,
696 'Auction Successful - ' . $item->id,
697 'auction-sale-buyer',
699 'first_name' => 'Admin',
701 'vehicle' => $vehicle,
702 'price' => $currPrefix . $item->currentBid->amount,
703 'seller' => $item->company->name,
704 'seller_name' => $item->createdBy->firstName . ' '
705 . $item->createdBy->familyName,
706 'vehicle_address' => $item->company->city->region->name
707 . ', ' . $item->company->city->name
708 . ', ' . $item->company->street
709 . ', ' . $item->company->postalCode,
710 'seller_billing_address' => $item->company->billingCity
711 ? $item->company->billingCity->region->name
712 . ', ' . $item->company->billingCity->name
713 . ', ' . $item->company->billingStreet
714 . ', ' . $item->company->billingPostalCode
716 'seller_vat_number' => !is_null($item->company->vatNumber)
717 ? $item->company->vatNumber
719 'seller_email' => $item->createdBy->email,
720 'stock_number' => $item->stock->stockNumber,
721 'buyer' => $item->currentBid->company->name,
722 'buyer_name' => $item->currentBid->profile->firstName . ' '
723 . $item->currentBid->profile->familyName,
724 'buyer_address' => $item->currentBid->company->city->region->name
725 . ', ' . $item->currentBid->company->city->name
726 . ', ' . $item->currentBid->company->street
727 . ', ' . $item->currentBid->company->postalCode,
728 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
729 ? $item->currentBid->company->vatNumber
731 'buyer_email' => $item->currentBid->profile->email,
732 'buyer_mobile' => $item->currentBid->profile->mobile
742 $oNotify->sendFromTemplate(
743 $item->company->id, $item->createdBy->id,
744 $item->currentBid->company->id, $item->currentBid->profile->id,
745 $item->currentBid->profile->email, null,
746 'Bid Successful - ' . $item->id,
747 'auction-sale-buyer',
749 'first_name' => $item->currentBid->profile->firstName,
750 'family_name' => $item->currentBid->profile->familyName,
751 'vehicle' => $vehicle,
752 'price' => $currPrefix . $item->currentBid->amount,
753 'seller' => $item->company->name,
754 'seller_name' => $item->createdBy->firstName . ' '
755 . $item->createdBy->familyName,
756 'vehicle_address' => $item->company->city->region->name
757 . ', ' . $item->company->city->name
758 . ', ' . $item->company->street
759 . ', ' . $item->company->postalCode,
760 'seller_billing_address' => $item->company->billingCity
761 ? $item->company->billingCity->region->name
762 . ', ' . $item->company->billingCity->name
763 . ', ' . $item->company->billingStreet
764 . ', ' . $item->company->billingPostalCode
766 'seller_vat_number' => !is_null($item->company->vatNumber)
767 ? $item->company->vatNumber
769 'seller_email' => $item->createdBy->email,
770 'stock_number' => $item->stock->stockNumber,
771 'buyer' => $item->currentBid->company->name,
772 'buyer_name' => $item->currentBid->profile->firstName . ' '
773 . $item->currentBid->profile->familyName,
774 'buyer_address' => $item->currentBid->company->city->region->name
775 . ', ' . $item->currentBid->company->city->name
776 . ', ' . $item->currentBid->company->street
777 . ', ' . $item->currentBid->company->postalCode,
778 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
779 ? $item->currentBid->company->vatNumber
781 'buyer_email' => $item->currentBid->profile->email,
782 'buyer_mobile' => $item->currentBid->profile->mobile
790 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
792 //send `auction-sale-seller` email to $item->stock->company->contact->email
793 $oNotify->sendFromTemplate(
794 $item->company->id, $item->createdBy->id,
795 $item->company->id, $item->createdBy->id,
796 $item->stock->company->contact->email, null,
797 'Auction Successful - ' . $item->id,
798 'auction-sale-seller',
800 'first_name' => $item->stock->company->contact->firstName,
801 'family_name' => $item->stock->company->contact->familyName,
802 'vehicle' => $vehicle,
803 'price' => $currPrefix . $item->currentBid->amount,
804 'buyer' => $item->currentBid->company->name,
805 'buyer_name' => $item->currentBid->profile->firstName . ' '
806 . $item->currentBid->profile->familyName,
807 'buyer_address' => $item->currentBid->company->city->region->name
808 . ', ' . $item->currentBid->company->city->name
809 . ', ' . $item->currentBid->company->street
810 . ', ' . $item->currentBid->company->postalCode,
811 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
812 ? $item->currentBid->company->vatNumber
814 'buyer_email' => $item->currentBid->profile->email,
815 'buyer_mobile' => $item->currentBid->profile->mobile,
816 'seller' => $item->company->name,
817 'seller_name' => $item->createdBy->firstName . ' '
818 . $item->createdBy->familyName,
819 'vehicle_address' => $item->company->city->region->name
820 . ', ' . $item->company->city->name
821 . ', ' . $item->company->street
822 . ', ' . $item->company->postalCode,
823 'seller_billing_address' => $item->company->billingCity
824 ? $item->company->billingCity->region->name
825 . ', ' . $item->company->billingCity->name
826 . ', ' . $item->company->billingStreet
827 . ', ' . $item->company->billingPostalCode
829 'seller_vat_number' => !is_null($item->company->vatNumber)
830 ? $item->company->vatNumber
832 'seller_email' => $item->createdBy->email,
833 'stock_number' => $item->stock->stockNumber
844 $oNotify->sendFromTemplate(
845 $item->company->id, $item->createdBy->id,
846 $item->company->id, $item->createdBy->id,
847 $item->createdBy->email, null,
848 'Auction Successful - ' . $item->id,
849 'auction-sale-seller',
851 'first_name' => $item->createdBy->firstName,
852 'family_name' => $item->createdBy->familyName,
853 'vehicle' => $vehicle,
854 'price' => $currPrefix . $item->currentBid->amount,
855 'buyer' => $item->currentBid->company->name,
856 'buyer_name' => $item->currentBid->profile->firstName . ' '
857 . $item->currentBid->profile->familyName,
858 'buyer_address' => $item->currentBid->company->city->region->name
859 . ', ' . $item->currentBid->company->city->name
860 . ', ' . $item->currentBid->company->street
861 . ', ' . $item->currentBid->company->postalCode,
862 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
863 ? $item->currentBid->company->vatNumber
865 'buyer_email' => $item->currentBid->profile->email,
866 'buyer_mobile' => $item->currentBid->profile->mobile,
867 'seller' => $item->company->name,
868 'seller_name' => $item->createdBy->firstName . ' '
869 . $item->createdBy->familyName,
870 'vehicle_address' => $item->company->city->region->name
871 . ', ' . $item->company->city->name
872 . ', ' . $item->company->street
873 . ', ' . $item->company->postalCode,
874 'seller_billing_address' => $item->company->billingCity
875 ? $item->company->billingCity->region->name
876 . ', ' . $item->company->billingCity->name
877 . ', ' . $item->company->billingStreet
878 . ', ' . $item->company->billingPostalCode
880 'seller_vat_number' => !is_null($item->company->vatNumber)
881 ? $item->company->vatNumber
883 'seller_email' => $item->createdBy->email,
884 'stock_number' => $item->stock->stockNumber
891 $attachments = array();
895 #-> No winner, send notification to seller & admin & feeder.
896 $oNotify->sendFromTemplate(
897 $item->company->id, $item->createdBy->id,
898 $item->company->id, $item->createdBy->id,
899 $item->createdBy->email, null,
900 'No winner on Bid4Cars Auction - ' . $item->id,
903 'first_name' => $item->createdBy->firstName,
904 'family_name' => $item->createdBy->familyName,
905 'vehicle' => $vehicle,
906 'reservePrice' => $item->reservePrice,
907 'registrationNumber' => $item->stock->registrationNumber,
908 'stockNumber' => $item->stock->stockNumber
916 $oNotify->sendFromTemplate(
917 $item->company->id, $item->createdBy->id,
918 $item->company->id, $item->createdBy->id,
919 'info@bid4cars.com.na', null,
920 'No winner on Bid4Cars Auction - ' . $item->id,
923 'first_name' => $item->createdBy->firstName,
924 'family_name' => $item->createdBy->familyName,
925 'vehicle' => $vehicle,
926 'reservePrice' => $item->reservePrice,
927 'registrationNumber' => $item->stock->registrationNumber,
928 'stockNumber' => $item->stock->stockNumber
936 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
938 $oNotify->sendFromTemplate(
939 $item->company->id, $item->createdBy->id,
940 $item->company->id, $item->createdBy->id,
941 $item->stock->company->contact->email, null,
942 'No winner on Bid4Cars Auction - ' . $item->id,
945 'first_name' => $item->stock->company->contact->firstName,
946 'family_name' => $item->stock->company->contact->familyName,
947 'vehicle' => $vehicle,
948 'reservePrice' => $item->reservePrice,
949 'registrationNumber' => $item->stock->registrationNumber,
950 'stockNumber' => $item->stock->stockNumber
961 $item->emailSent = true;
962 $this->em->flush($item);
964 catch (\Exception $e)
966 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
969 error_log('Auction cron ended @ ' . date('Y-m-d H:i:s'));
970 error_log('------------------------------------');
974 * Contract get total vehicels on auction.
975 * @param object|null $jobRecord
976 * @param array $input
977 * @return \Workspace\Contract\UseOnce
979 public function contractCount($jobRecord)
981 $options = new \Workspace\UseCase\Options();
982 $requirement = new \Workspace\UseCase\Requirement();
983 return new \Workspace\Contract\Recurring($options, $requirement);
987 * get total vehicels on auction.
988 * @param object|null $jobRecord
989 * @param \Workspace\Utility\ServiceInputParams $contract
992 public function executeCount($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
994 $result = $this->em->createQuery(
995 'SELECT COUNT(auction) AS total '
996 . 'FROM \Auction\Entity\Auction auction '
997 . 'WHERE auction.jobState = \'Active\' '
998 . ' AND auction.archived = \'0\''
1000 ->getSingleResult();
1001 return $contract->success('Totals collected.', array('Items' => $result['total']));
1011 * CRON functionality: Move Auction items as needed.
1013 public function cronProcessCustom()
1015 ini_set('memory_limit', '512M');
1016 error_log('------------------------------------');
1017 error_log('Auction cron started @ ' . date('Y-m-d H:i:s'));
1019 $date = date('Y-m-d H:i:s');
1020 $result = $this->em->createQuery(
1021 'SELECT auction FROM \Auction\Entity\Auction auction '
1022 . 'WHERE auction.id IN (:ids)'
1024 ->setParameter('ids', array(30871, 30881, 30868, 30874, 30880, 30882, 30883, 30905))
1026 error_log("Item count: " . count($result));
1027 foreach ($result as $item)
1031 #-> General data prep.
1032 $vehicle = $item->stock->type->model->make->name
1033 . ', ' . $item->stock->type->model->name
1034 . ', ' . $item->stock->type->name;
1035 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
1036 $oNotify = new \Utility\Comms\Notification();
1038 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
1040 #-> Update record to reflect winner.
1041 if (is_null($item->soldToCompany))
1043 $item->soldToCompany = $item->currentBid->company;
1045 if (is_null($item->soldToProfile))
1047 $item->soldToProfile = $item->currentBid->profile;
1052 $pdf = new \Auction\Pdf\CompleteNew();
1053 $pdf->process(array(
1054 'jobRecord' => $item
1056 $docsDir = __DIR__ . '/../../../../../public/documents/';
1058 #-> Declaration PDF.
1059 $pdf_Declaration = new \Auction\Pdf\Declaration();
1060 $pdf_Declaration->process(array(
1061 'jobRecord' => $item
1063 $docsDir = __DIR__ . '/../../../../../public/documents/';
1065 #-> Deliveryreceipt PDF.
1066 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
1067 $pdf_Deliveryreceipt->process(array(
1068 'jobRecord' => $item
1070 $docsDir = __DIR__ . '/../../../../../public/documents/';
1072 $writer = new \Utility\Export\PdfTemplate($pdf);
1073 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
1074 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
1076 $attachments = array(
1077 'auction' . $item->id . '.pdf' => $writer->output(''),
1078 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
1079 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
1084 $oNotify->sendFromTemplate(
1085 $item->company->id, $item->createdBy->id,
1086 $item->currentBid->company->id, $item->currentBid->profile->id,
1087 'info@bid4cars.com.na', null,
1088 'Auction Successful - ' . $item->id,
1089 'auction-sale-buyer',
1091 'first_name' => 'Admin',
1092 'family_name' => '',
1093 'vehicle' => $vehicle,
1094 'price' => $currPrefix . $item->currentBid->amount,
1095 'seller' => $item->company->name,
1096 'seller_name' => $item->createdBy->firstName . ' '
1097 . $item->createdBy->familyName,
1098 'vehicle_address' => $item->company->city->region->name
1099 . ', ' . $item->company->city->name
1100 . ', ' . $item->company->street
1101 . ', ' . $item->company->postalCode,
1102 'seller_billing_address' => $item->company->billingCity
1103 ? $item->company->billingCity->region->name
1104 . ', ' . $item->company->billingCity->name
1105 . ', ' . $item->company->billingStreet
1106 . ', ' . $item->company->billingPostalCode
1108 'seller_vat_number' => !is_null($item->company->vatNumber)
1109 ? $item->company->vatNumber
1111 'seller_email' => $item->createdBy->email,
1112 'stock_number' => $item->stock->stockNumber,
1113 'buyer' => $item->currentBid->company->name,
1114 'buyer_name' => $item->currentBid->profile->firstName . ' '
1115 . $item->currentBid->profile->familyName,
1116 'buyer_address' => $item->currentBid->company->city->region->name
1117 . ', ' . $item->currentBid->company->city->name
1118 . ', ' . $item->currentBid->company->street
1119 . ', ' . $item->currentBid->company->postalCode,
1120 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1121 ? $item->currentBid->company->vatNumber
1123 'buyer_email' => $item->currentBid->profile->email,
1124 'buyer_mobile' => $item->currentBid->profile->mobile
1134 $oNotify->sendFromTemplate(
1135 $item->company->id, $item->createdBy->id,
1136 $item->currentBid->company->id, $item->currentBid->profile->id,
1137 'louise@combinefreight.co.za', null,
1138 'Auction Successful - ' . $item->id,
1139 'auction-sale-buyer',
1141 'first_name' => 'Admin',
1142 'family_name' => '',
1143 'vehicle' => $vehicle,
1144 'price' => $currPrefix . $item->currentBid->amount,
1145 'seller' => $item->company->name,
1146 'seller_name' => $item->createdBy->firstName . ' '
1147 . $item->createdBy->familyName,
1148 'vehicle_address' => $item->company->city->region->name
1149 . ', ' . $item->company->city->name
1150 . ', ' . $item->company->street
1151 . ', ' . $item->company->postalCode,
1152 'seller_billing_address' => $item->company->billingCity
1153 ? $item->company->billingCity->region->name
1154 . ', ' . $item->company->billingCity->name
1155 . ', ' . $item->company->billingStreet
1156 . ', ' . $item->company->billingPostalCode
1158 'seller_vat_number' => !is_null($item->company->vatNumber)
1159 ? $item->company->vatNumber
1161 'seller_email' => $item->createdBy->email,
1162 'stock_number' => $item->stock->stockNumber,
1163 'buyer' => $item->currentBid->company->name,
1164 'buyer_name' => $item->currentBid->profile->firstName . ' '
1165 . $item->currentBid->profile->familyName,
1166 'buyer_address' => $item->currentBid->company->city->region->name
1167 . ', ' . $item->currentBid->company->city->name
1168 . ', ' . $item->currentBid->company->street
1169 . ', ' . $item->currentBid->company->postalCode,
1170 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1171 ? $item->currentBid->company->vatNumber
1173 'buyer_email' => $item->currentBid->profile->email,
1174 'buyer_mobile' => $item->currentBid->profile->mobile
1183 $oNotify->sendFromTemplate(
1184 $item->company->id, $item->createdBy->id,
1185 $item->currentBid->company->id, $item->currentBid->profile->id,
1186 $item->currentBid->profile->email, null,
1187 'Bid Successful - ' . $item->id,
1188 'auction-sale-buyer',
1190 'first_name' => $item->currentBid->profile->firstName,
1191 'family_name' => $item->currentBid->profile->familyName,
1192 'vehicle' => $vehicle,
1193 'price' => $currPrefix . $item->currentBid->amount,
1194 'seller' => $item->company->name,
1195 'seller_name' => $item->createdBy->firstName . ' '
1196 . $item->createdBy->familyName,
1197 'vehicle_address' => $item->company->city->region->name
1198 . ', ' . $item->company->city->name
1199 . ', ' . $item->company->street
1200 . ', ' . $item->company->postalCode,
1201 'seller_billing_address' => $item->company->billingCity
1202 ? $item->company->billingCity->region->name
1203 . ', ' . $item->company->billingCity->name
1204 . ', ' . $item->company->billingStreet
1205 . ', ' . $item->company->billingPostalCode
1207 'seller_vat_number' => !is_null($item->company->vatNumber)
1208 ? $item->company->vatNumber
1210 'seller_email' => $item->createdBy->email,
1211 'stock_number' => $item->stock->stockNumber,
1212 'buyer' => $item->currentBid->company->name,
1213 'buyer_name' => $item->currentBid->profile->firstName . ' '
1214 . $item->currentBid->profile->familyName,
1215 'buyer_address' => $item->currentBid->company->city->region->name
1216 . ', ' . $item->currentBid->company->city->name
1217 . ', ' . $item->currentBid->company->street
1218 . ', ' . $item->currentBid->company->postalCode,
1219 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1220 ? $item->currentBid->company->vatNumber
1222 'buyer_email' => $item->currentBid->profile->email,
1223 'buyer_mobile' => $item->currentBid->profile->mobile
1233 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1235 //send `auction-sale-seller` email to $item->stock->company->contact->email
1236 $oNotify->sendFromTemplate(
1237 $item->company->id, $item->createdBy->id,
1238 $item->company->id, $item->createdBy->id,
1239 $item->stock->company->contact->email, null,
1240 'Auction Successful - ' . $item->id,
1241 'auction-sale-seller',
1243 'first_name' => $item->stock->company->contact->firstName,
1244 'family_name' => $item->stock->company->contact->familyName,
1245 'vehicle' => $vehicle,
1246 'price' => $currPrefix . $item->currentBid->amount,
1247 'buyer' => $item->currentBid->company->name,
1248 'buyer_name' => $item->currentBid->profile->firstName . ' '
1249 . $item->currentBid->profile->familyName,
1250 'buyer_address' => $item->currentBid->company->city->region->name
1251 . ', ' . $item->currentBid->company->city->name
1252 . ', ' . $item->currentBid->company->street
1253 . ', ' . $item->currentBid->company->postalCode,
1254 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1255 ? $item->currentBid->company->vatNumber
1257 'buyer_email' => $item->currentBid->profile->email,
1258 'buyer_mobile' => $item->currentBid->profile->mobile,
1259 'seller' => $item->company->name,
1260 'seller_name' => $item->createdBy->firstName . ' '
1261 . $item->createdBy->familyName,
1262 'vehicle_address' => $item->company->city->region->name
1263 . ', ' . $item->company->city->name
1264 . ', ' . $item->company->street
1265 . ', ' . $item->company->postalCode,
1266 'seller_billing_address' => $item->company->billingCity
1267 ? $item->company->billingCity->region->name
1268 . ', ' . $item->company->billingCity->name
1269 . ', ' . $item->company->billingStreet
1270 . ', ' . $item->company->billingPostalCode
1272 'seller_vat_number' => !is_null($item->company->vatNumber)
1273 ? $item->company->vatNumber
1275 'seller_email' => $item->createdBy->email,
1276 'stock_number' => $item->stock->stockNumber
1286 $oNotify->sendFromTemplate(
1287 $item->company->id, $item->createdBy->id,
1288 $item->company->id, $item->createdBy->id,
1289 $item->createdBy->email, null,
1290 'Auction Successful - ' . $item->id,
1291 'auction-sale-seller',
1293 'first_name' => $item->createdBy->firstName,
1294 'family_name' => $item->createdBy->familyName,
1295 'vehicle' => $vehicle,
1296 'price' => $currPrefix . $item->currentBid->amount,
1297 'buyer' => $item->currentBid->company->name,
1298 'buyer_name' => $item->currentBid->profile->firstName . ' '
1299 . $item->currentBid->profile->familyName,
1300 'buyer_address' => $item->currentBid->company->city->region->name
1301 . ', ' . $item->currentBid->company->city->name
1302 . ', ' . $item->currentBid->company->street
1303 . ', ' . $item->currentBid->company->postalCode,
1304 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1305 ? $item->currentBid->company->vatNumber
1307 'buyer_email' => $item->currentBid->profile->email,
1308 'buyer_mobile' => $item->currentBid->profile->mobile,
1309 'seller' => $item->company->name,
1310 'seller_name' => $item->createdBy->firstName . ' '
1311 . $item->createdBy->familyName,
1312 'vehicle_address' => $item->company->city->region->name
1313 . ', ' . $item->company->city->name
1314 . ', ' . $item->company->street
1315 . ', ' . $item->company->postalCode,
1316 'seller_billing_address' => $item->company->billingCity
1317 ? $item->company->billingCity->region->name
1318 . ', ' . $item->company->billingCity->name
1319 . ', ' . $item->company->billingStreet
1320 . ', ' . $item->company->billingPostalCode
1322 'seller_vat_number' => !is_null($item->company->vatNumber)
1323 ? $item->company->vatNumber
1325 'seller_email' => $item->createdBy->email,
1326 'stock_number' => $item->stock->stockNumber
1333 $attachments = array();
1337 #-> No winner, send notification to seller & admin & feeder dealer.
1338 $oNotify->sendFromTemplate(
1339 $item->company->id, $item->createdBy->id,
1340 $item->company->id, $item->createdBy->id,
1341 $item->createdBy->email, null,
1342 'No winner on Bid4Cars Auction - ' . $item->id,
1345 'first_name' => $item->createdBy->firstName,
1346 'family_name' => $item->createdBy->familyName,
1347 'vehicle' => $vehicle,
1348 'reservePrice' => $item->reservePrice,
1349 'registrationNumber' => $item->stock->registrationNumber,
1350 'stockNumber' => $item->stock->stockNumber
1358 $oNotify->sendFromTemplate(
1359 $item->company->id, $item->createdBy->id,
1360 $item->company->id, $item->createdBy->id,
1361 'info@bid4cars.com.na', null,
1362 'No winner on Bid4Cars Auction - ' . $item->id,
1365 'first_name' => $item->createdBy->firstName,
1366 'family_name' => $item->createdBy->familyName,
1367 'vehicle' => $vehicle,
1368 'reservePrice' => $item->reservePrice,
1369 'registrationNumber' => $item->stock->registrationNumber,
1370 'stockNumber' => $item->stock->stockNumber
1379 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1381 $oNotify->sendFromTemplate(
1382 $item->company->id, $item->createdBy->id,
1383 $item->company->id, $item->createdBy->id,
1384 $item->stock->company->contact->email, null,
1385 'No winner on Bid4Cars Auction - ' . $item->id,
1388 'first_name' => $item->stock->company->contact->firstName,
1389 'family_name' => $item->stock->company->contact->familyName,
1390 'vehicle' => $vehicle,
1391 'reservePrice' => $item->reservePrice,
1392 'registrationNumber' => $item->stock->registrationNumber,
1393 'stockNumber' => $item->stock->stockNumber
1404 $item->emailSent = true;
1405 $this->em->flush($item);
1407 catch (\Exception $e)
1409 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
1412 error_log('Auction cron ended @ ' . date('Y-m-d H:i:s'));
1413 error_log('------------------------------------');
1417 * CRON functionality: Move Auction items as needed.
1419 public function cronProcessCleanup()
1421 $mailTo = 'dino@nirph.com';
1422 ini_set('memory_limit', '512M');
1423 error_log('------------------------------------');
1424 error_log('Auction cleanup cron started @ ' . date('Y-m-d H:i:s'));
1428 $numRecsRes = $this->em->createQuery(
1429 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction '
1430 . 'WHERE auction.endDate <= \'' . date('Y-m-d H:i:s') . '\''
1431 . ' AND auction.endDate > \'' . date('Y-m-d') . ' 00:00:00\''
1432 . ' AND auction.jobState != :jobStateArchived'
1434 ->setParameter('jobStateArchived', 'Archived')
1435 ->getSingleResult();
1436 $totalItems = (int)$numRecsRes['total'];
1437 $numRecsRes = $this->em->createQuery(
1438 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction '
1439 . 'WHERE auction.jobState = :jobState '
1440 . ' AND auction.endDate <= :startDate'
1441 . ' AND auction.endDate > :endDate'
1443 ->setParameter('jobState', 'Sold')
1444 ->setParameter('startDate', date('Y-m-d H:i:s'))
1445 ->setParameter('endDate', date('Y-m-d') . ' 00:00:00')
1446 ->getSingleResult();
1447 $successItems = (int)$numRecsRes['total'];
1448 // $result = $this->em->createQuery(
1449 // 'SELECT auction FROM \Auction\Entity\Auction auction '
1450 // . 'WHERE auction.jobState != :jobState AND auction.jobState != :jobStateTwo'
1451 // . ' AND auction.emailSent = :emailSent'
1453 // ->setParameter('jobState', 'Active')
1454 // ->setParameter('jobStateTwo', 'Relist')
1455 // ->setParameter('emailSent', false)
1458 $result = $this->em->createQuery(
1459 'SELECT auction FROM \Auction\Entity\Auction auction '
1460 . 'WHERE auction.jobState != :jobState'
1461 . ' AND auction.jobState != :jobStateArchived'
1462 . ' AND auction.emailSent = :emailSent'
1464 ->setParameter('jobState', 'Active')
1465 ->setParameter('jobStateArchived', 'Archived')
1466 ->setParameter('emailSent', false)
1469 $mailer = new \Utility\Comms\Email();
1470 $mailer->send(array(
1471 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'),
1473 'Subject' => 'Auction cleanup cron Start - ' . date('Y-m-d H:i:s'),
1474 'Html' => '<b>Total auction items:<//b> ' . $totalItems . '<br//>'
1475 . '<b>Total items sold:<//b> ' . $successItems . '<br//>'
1476 . '<b>Total items no winner:<//b> ' . ($totalItems - $successItems) . '<br//>'
1477 . '<b>Mails not yet sent:<//b> ' . count($result) . '<br//>'
1482 error_log("Item count: " . count($result));
1483 foreach ($result as $item)
1487 #-> General data prep.
1488 $vehicle = $item->stock->type->model->make->name
1489 . ', ' . $item->stock->type->model->name
1490 . ', ' . $item->stock->type->name;
1491 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
1492 $oNotify = new \Utility\Comms\Notification();
1494 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
1496 #-> Update record to reflect winner.
1497 if (is_null($item->soldToCompany))
1499 $item->soldToCompany = $item->currentBid->company;
1501 if (is_null($item->soldToProfile))
1503 $item->soldToProfile = $item->currentBid->profile;
1508 $pdf = new \Auction\Pdf\CompleteNew();
1509 $pdf->process(array(
1510 'jobRecord' => $item
1512 $docsDir = __DIR__ . '/../../../../../public/documents/';
1514 #-> Declaration PDF.
1515 $pdf_Declaration = new \Auction\Pdf\Declaration();
1516 $pdf_Declaration->process(array(
1517 'jobRecord' => $item
1519 $docsDir = __DIR__ . '/../../../../../public/documents/';
1521 #-> Deliveryreceipt PDF.
1522 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
1523 $pdf_Deliveryreceipt->process(array(
1524 'jobRecord' => $item
1526 $docsDir = __DIR__ . '/../../../../../public/documents/';
1528 $writer = new \Utility\Export\PdfTemplate($pdf);
1529 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
1530 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
1532 $attachments = array(
1533 'auction' . $item->id . '.pdf' => $writer->output(''),
1534 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
1535 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
1540 $oNotify->sendFromTemplate(
1541 $item->company->id, $item->createdBy->id,
1542 $item->currentBid->company->id, $item->currentBid->profile->id,
1543 'info@bid4cars.com.na', null,
1544 'Auction Successful - ' . $item->id,
1545 'auction-sale-buyer',
1547 'first_name' => 'Admin',
1548 'family_name' => '',
1549 'vehicle' => $vehicle,
1550 'price' => $currPrefix . $item->currentBid->amount,
1551 'seller' => $item->company->name,
1552 'seller_name' => $item->createdBy->firstName . ' '
1553 . $item->createdBy->familyName,
1554 'vehicle_address' => $item->company->city->region->name
1555 . ', ' . $item->company->city->name
1556 . ', ' . $item->company->street
1557 . ', ' . $item->company->postalCode,
1558 'seller_billing_address' => $item->company->billingCity
1559 ? $item->company->billingCity->region->name
1560 . ', ' . $item->company->billingCity->name
1561 . ', ' . $item->company->billingStreet
1562 . ', ' . $item->company->billingPostalCode
1564 'seller_vat_number' => !is_null($item->company->vatNumber)
1565 ? $item->company->vatNumber
1567 'seller_email' => $item->createdBy->email,
1568 'stock_number' => $item->stock->stockNumber,
1569 'buyer' => $item->currentBid->company->name,
1570 'buyer_name' => $item->currentBid->profile->firstName . ' '
1571 . $item->currentBid->profile->familyName,
1572 'buyer_address' => $item->currentBid->company->city->region->name
1573 . ', ' . $item->currentBid->company->city->name
1574 . ', ' . $item->currentBid->company->street
1575 . ', ' . $item->currentBid->company->postalCode,
1576 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1577 ? $item->currentBid->company->vatNumber
1579 'buyer_email' => $item->currentBid->profile->email,
1580 'buyer_mobile' => $item->currentBid->profile->mobile
1589 $oNotify->sendFromTemplate(
1590 $item->company->id, $item->createdBy->id,
1591 $item->currentBid->company->id, $item->currentBid->profile->id,
1592 'louise@combinefreight.co.za', null,
1593 'Auction Successful - ' . $item->id,
1594 'auction-sale-buyer',
1596 'first_name' => 'Admin',
1597 'family_name' => '',
1598 'vehicle' => $vehicle,
1599 'price' => $currPrefix . $item->currentBid->amount,
1600 'seller' => $item->company->name,
1601 'seller_name' => $item->createdBy->firstName . ' '
1602 . $item->createdBy->familyName,
1603 'vehicle_address' => $item->company->city->region->name
1604 . ', ' . $item->company->city->name
1605 . ', ' . $item->company->street
1606 . ', ' . $item->company->postalCode,
1607 'seller_billing_address' => $item->company->billingCity
1608 ? $item->company->billingCity->region->name
1609 . ', ' . $item->company->billingCity->name
1610 . ', ' . $item->company->billingStreet
1611 . ', ' . $item->company->billingPostalCode
1613 'seller_vat_number' => !is_null($item->company->vatNumber)
1614 ? $item->company->vatNumber
1616 'seller_email' => $item->createdBy->email,
1617 'stock_number' => $item->stock->stockNumber,
1618 'buyer' => $item->currentBid->company->name,
1619 'buyer_name' => $item->currentBid->profile->firstName . ' '
1620 . $item->currentBid->profile->familyName,
1621 'buyer_address' => $item->currentBid->company->city->region->name
1622 . ', ' . $item->currentBid->company->city->name
1623 . ', ' . $item->currentBid->company->street
1624 . ', ' . $item->currentBid->company->postalCode,
1625 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1626 ? $item->currentBid->company->vatNumber
1628 'buyer_email' => $item->currentBid->profile->email,
1629 'buyer_mobile' => $item->currentBid->profile->mobile
1638 $oNotify->sendFromTemplate(
1639 $item->company->id, $item->createdBy->id,
1640 $item->currentBid->company->id, $item->currentBid->profile->id,
1641 $item->currentBid->profile->email, null,
1642 'Bid Successful - ' . $item->id,
1643 'auction-sale-buyer',
1645 'first_name' => $item->currentBid->profile->firstName,
1646 'family_name' => $item->currentBid->profile->familyName,
1647 'vehicle' => $vehicle,
1648 'price' => $currPrefix . $item->currentBid->amount,
1649 'seller' => $item->company->name,
1650 'seller_name' => $item->createdBy->firstName . ' '
1651 . $item->createdBy->familyName,
1652 'vehicle_address' => $item->company->city->region->name
1653 . ', ' . $item->company->city->name
1654 . ', ' . $item->company->street
1655 . ', ' . $item->company->postalCode,
1656 'seller_billing_address' => $item->company->billingCity
1657 ? $item->company->billingCity->region->name
1658 . ', ' . $item->company->billingCity->name
1659 . ', ' . $item->company->billingStreet
1660 . ', ' . $item->company->billingPostalCode
1662 'seller_vat_number' => !is_null($item->company->vatNumber)
1663 ? $item->company->vatNumber
1665 'seller_email' => $item->createdBy->email,
1666 'stock_number' => $item->stock->stockNumber,
1667 'buyer' => $item->currentBid->company->name,
1668 'buyer_name' => $item->currentBid->profile->firstName . ' '
1669 . $item->currentBid->profile->familyName,
1670 'buyer_address' => $item->currentBid->company->city->region->name
1671 . ', ' . $item->currentBid->company->city->name
1672 . ', ' . $item->currentBid->company->street
1673 . ', ' . $item->currentBid->company->postalCode,
1674 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1675 ? $item->currentBid->company->vatNumber
1677 'buyer_email' => $item->currentBid->profile->email,
1678 'buyer_mobile' => $item->currentBid->profile->mobile
1687 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1689 //send `auction-sale-seller` email to $item->stock->company->contact->email
1690 $oNotify->sendFromTemplate(
1691 $item->company->id, $item->createdBy->id,
1692 $item->company->id, $item->createdBy->id,
1693 $item->stock->company->contact->email, null,
1694 'Auction Successful - ' . $item->id,
1695 'auction-sale-seller',
1697 'first_name' => $item->stock->company->contact->firstName,
1698 'family_name' => $item->stock->company->contact->familyName,
1699 'vehicle' => $vehicle,
1700 'price' => $currPrefix . $item->currentBid->amount,
1701 'buyer' => $item->currentBid->company->name,
1702 'buyer_name' => $item->currentBid->profile->firstName . ' '
1703 . $item->currentBid->profile->familyName,
1704 'buyer_address' => $item->currentBid->company->city->region->name
1705 . ', ' . $item->currentBid->company->city->name
1706 . ', ' . $item->currentBid->company->street
1707 . ', ' . $item->currentBid->company->postalCode,
1708 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1709 ? $item->currentBid->company->vatNumber
1711 'buyer_email' => $item->currentBid->profile->email,
1712 'buyer_mobile' => $item->currentBid->profile->mobile,
1713 'seller' => $item->company->name,
1714 'seller_name' => $item->createdBy->firstName . ' '
1715 . $item->createdBy->familyName,
1716 'vehicle_address' => $item->company->city->region->name
1717 . ', ' . $item->company->city->name
1718 . ', ' . $item->company->street
1719 . ', ' . $item->company->postalCode,
1720 'seller_billing_address' => $item->company->billingCity
1721 ? $item->company->billingCity->region->name
1722 . ', ' . $item->company->billingCity->name
1723 . ', ' . $item->company->billingStreet
1724 . ', ' . $item->company->billingPostalCode
1726 'seller_vat_number' => !is_null($item->company->vatNumber)
1727 ? $item->company->vatNumber
1729 'seller_email' => $item->createdBy->email,
1730 'stock_number' => $item->stock->stockNumber
1741 $oNotify->sendFromTemplate(
1742 $item->company->id, $item->createdBy->id,
1743 $item->company->id, $item->createdBy->id,
1744 $item->createdBy->email, null,
1745 'Auction Successful - ' . $item->id,
1746 'auction-sale-seller',
1748 'first_name' => $item->createdBy->firstName,
1749 'family_name' => $item->createdBy->familyName,
1750 'vehicle' => $vehicle,
1751 'price' => $currPrefix . $item->currentBid->amount,
1752 'buyer' => $item->currentBid->company->name,
1753 'buyer_name' => $item->currentBid->profile->firstName . ' '
1754 . $item->currentBid->profile->familyName,
1755 'buyer_address' => $item->currentBid->company->city->region->name
1756 . ', ' . $item->currentBid->company->city->name
1757 . ', ' . $item->currentBid->company->street
1758 . ', ' . $item->currentBid->company->postalCode,
1759 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1760 ? $item->currentBid->company->vatNumber
1762 'buyer_email' => $item->currentBid->profile->email,
1763 'buyer_mobile' => $item->currentBid->profile->mobile,
1764 'seller' => $item->company->name,
1765 'seller_name' => $item->createdBy->firstName . ' '
1766 . $item->createdBy->familyName,
1767 'vehicle_address' => $item->company->city->region->name
1768 . ', ' . $item->company->city->name
1769 . ', ' . $item->company->street
1770 . ', ' . $item->company->postalCode,
1771 'seller_billing_address' => $item->company->billingCity
1772 ? $item->company->billingCity->region->name
1773 . ', ' . $item->company->billingCity->name
1774 . ', ' . $item->company->billingStreet
1775 . ', ' . $item->company->billingPostalCode
1777 'seller_vat_number' => !is_null($item->company->vatNumber)
1778 ? $item->company->vatNumber
1780 'seller_email' => $item->createdBy->email,
1781 'stock_number' => $item->stock->stockNumber
1788 $attachments = array();
1792 #-> No winner, send notification to seller & admin & feeder.
1793 $oNotify->sendFromTemplate(
1794 $item->company->id, $item->createdBy->id,
1795 $item->company->id, $item->createdBy->id,
1796 $item->createdBy->email, null,
1797 'No winner on Bid4Cars Auction - ' . $item->id,
1800 'first_name' => $item->createdBy->firstName,
1801 'family_name' => $item->createdBy->familyName,
1802 'vehicle' => $vehicle,
1803 'reservePrice' => $item->reservePrice,
1804 'registrationNumber' => $item->stock->registrationNumber,
1805 'stockNumber' => $item->stock->stockNumber
1812 $oNotify->sendFromTemplate(
1813 $item->company->id, $item->createdBy->id,
1814 $item->company->id, $item->createdBy->id,
1815 'info@bid4cars.com.na', null,
1816 'No winner on Bid4Cars Auction - ' . $item->id,
1819 'first_name' => $item->createdBy->firstName,
1820 'family_name' => $item->createdBy->familyName,
1821 'vehicle' => $vehicle,
1822 'reservePrice' => $item->reservePrice,
1823 'registrationNumber' => $item->stock->registrationNumber,
1824 'stockNumber' => $item->stock->stockNumber
1832 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1834 $oNotify->sendFromTemplate(
1835 $item->company->id, $item->createdBy->id,
1836 $item->company->id, $item->createdBy->id,
1837 $item->stock->company->contact->email, null,
1838 'No winner on Bid4Cars Auction - ' . $item->id,
1841 'first_name' => $item->stock->company->contact->firstName,
1842 'family_name' => $item->stock->company->contact->familyName,
1843 'vehicle' => $vehicle,
1844 'reservePrice' => $item->reservePrice,
1845 'registrationNumber' => $item->stock->registrationNumber,
1846 'stockNumber' => $item->stock->stockNumber
1857 $item->emailSent = true;
1858 $this->em->flush($item);
1861 catch (\Exception $e)
1863 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
1866 error_log('Auction cleanup cron ended @ ' . date('Y-m-d H:i:s'));
1867 error_log('------------------------------------');
1870 $mailer = new \Utility\Comms\Email();
1871 $mailer->send(array(
1872 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'),
1874 'Subject' => 'Auction cleanup cron End - ' . date('Y-m-d H:i:s'),
1875 'Html' => '<b>Total auction items:<//b> ' . $totalItems . '<br//>'
1876 . '<b>Emails sent:<//b> ' . $sent . ' of ' . count($result) . '<br//>'