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 \Utility\Debug::errorLog('currentbid',$item->currentBid->amount);
564 \Utility\Debug::errorLog('reserve',$item->reservePrice);
566 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice)
568 #-> We have a winner.
569 \Utility\Debug::errorLog('Winner',$item->id);
572 $item->soldToCompany = $item->currentBid->company;
573 $item->soldToProfile = $item->currentBid->profile;
574 $this->workflowNode->changeState('This.Sold');
578 #-> Each and every one a loser.
579 \Utility\Debug::errorLog('no winner',$item->id);
580 $this->workflowNode->changeState('This.Relist');
583 catch (\Exception $e)
585 \Utility\Debug::errorLog('Error on Auction cron process (state change) for item ' . $item->id, $e->getMessage());
589 $workflow->handover('Auction', $item->stock->id);
591 catch (\Exception $e)
593 \Utility\Debug::errorLog('Error on Auction cron process (handover) for item ' . $item->id, $e->getMessage());
597 foreach ($result as $item)
601 \Utility\Debug::errorLog('setting data for mail',$item->id);
603 #-> General data prep.
604 $vehicle = $item->stock->type->model->make->name
605 . ', ' . $item->stock->type->model->name
606 . ', ' . $item->stock->type->name;
607 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
608 $oNotify = new \Utility\Comms\Notification();
610 \Utility\Debug::errorLog('jobstate',$item->jobState);
611 \Utility\Debug::errorLog('currentbid',$item->currentBid->amount);
612 \Utility\Debug::errorLog('reserve',$item->reservePrice);
614 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
616 \Utility\Debug::errorLog('sending mails',$item->jobState);
619 #-> Update record to reflect winner.
620 $item->soldToCompany = $item->currentBid->company;
621 $item->soldToProfile = $item->currentBid->profile;
626 $pdf = new \Auction\Pdf\CompleteNew();
630 $docsDir = __DIR__ . '/../../../../../public/documents/';
633 $pdf_Declaration = new \Auction\Pdf\Declaration();
634 $pdf_Declaration->process(array(
637 $docsDir = __DIR__ . '/../../../../../public/documents/';
639 #-> Deliveryreceipt PDF.
640 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
641 $pdf_Deliveryreceipt->process(array(
644 $docsDir = __DIR__ . '/../../../../../public/documents/';
646 $writer = new \Utility\Export\PdfTemplate($pdf);
647 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
648 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
650 $attachments = array(
651 'auction' . $item->id . '.pdf' => $writer->output(''),
652 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
653 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
658 $oNotify->sendFromTemplate(
659 $item->company->id, $item->createdBy->id,
660 $item->currentBid->company->id, $item->currentBid->profile->id,
661 'info@bid4cars.com.na', null,
662 'Auction Successful - ' . $item->id,
663 'auction-sale-buyer',
665 'first_name' => 'Admin',
667 'vehicle' => $vehicle,
668 'price' => $currPrefix . $item->currentBid->amount,
669 'seller' => $item->company->name,
670 'seller_name' => $item->createdBy->firstName . ' '
671 . $item->createdBy->familyName,
672 'vehicle_address' => $item->company->city->region->name
673 . ', ' . $item->company->city->name
674 . ', ' . $item->company->street
675 . ', ' . $item->company->postalCode,
676 'seller_billing_address' => $item->company->billingCity
677 ? $item->company->billingCity->region->name
678 . ', ' . $item->company->billingCity->name
679 . ', ' . $item->company->billingStreet
680 . ', ' . $item->company->billingPostalCode
682 'seller_vat_number' => !is_null($item->company->vatNumber)
683 ? $item->company->vatNumber
685 'seller_email' => $item->createdBy->email,
686 'stock_number' => $item->stock->stockNumber,
687 'buyer' => $item->currentBid->company->name,
688 'buyer_name' => $item->currentBid->profile->firstName . ' '
689 . $item->currentBid->profile->familyName,
690 'buyer_address' => $item->currentBid->company->city->region->name
691 . ', ' . $item->currentBid->company->city->name
692 . ', ' . $item->currentBid->company->street
693 . ', ' . $item->currentBid->company->postalCode,
694 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
695 ? $item->currentBid->company->vatNumber
697 'buyer_email' => $item->currentBid->profile->email,
698 'buyer_mobile' => $item->currentBid->profile->mobile
706 #-> Combined freight.
707 $oNotify->sendFromTemplate(
708 $item->company->id, $item->createdBy->id,
709 $item->currentBid->company->id, $item->currentBid->profile->id,
710 'louise@combinefreight.co.za', null,
711 'Auction Successful - ' . $item->id,
712 'auction-sale-buyer',
714 'first_name' => 'Admin',
716 'vehicle' => $vehicle,
717 'price' => $currPrefix . $item->currentBid->amount,
718 'seller' => $item->company->name,
719 'seller_name' => $item->createdBy->firstName . ' '
720 . $item->createdBy->familyName,
721 'vehicle_address' => $item->company->city->region->name
722 . ', ' . $item->company->city->name
723 . ', ' . $item->company->street
724 . ', ' . $item->company->postalCode,
725 'seller_billing_address' => $item->company->billingCity
726 ? $item->company->billingCity->region->name
727 . ', ' . $item->company->billingCity->name
728 . ', ' . $item->company->billingStreet
729 . ', ' . $item->company->billingPostalCode
731 'seller_vat_number' => !is_null($item->company->vatNumber)
732 ? $item->company->vatNumber
734 'seller_email' => $item->createdBy->email,
735 'stock_number' => $item->stock->stockNumber,
736 'buyer' => $item->currentBid->company->name,
737 'buyer_name' => $item->currentBid->profile->firstName . ' '
738 . $item->currentBid->profile->familyName,
739 'buyer_address' => $item->currentBid->company->city->region->name
740 . ', ' . $item->currentBid->company->city->name
741 . ', ' . $item->currentBid->company->street
742 . ', ' . $item->currentBid->company->postalCode,
743 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
744 ? $item->currentBid->company->vatNumber
746 'buyer_email' => $item->currentBid->profile->email,
747 'buyer_mobile' => $item->currentBid->profile->mobile
757 $oNotify->sendFromTemplate(
758 $item->company->id, $item->createdBy->id,
759 $item->currentBid->company->id, $item->currentBid->profile->id,
760 $item->currentBid->profile->email, null,
761 'Bid Successful - ' . $item->id,
762 'auction-sale-buyer',
764 'first_name' => $item->currentBid->profile->firstName,
765 'family_name' => $item->currentBid->profile->familyName,
766 'vehicle' => $vehicle,
767 'price' => $currPrefix . $item->currentBid->amount,
768 'seller' => $item->company->name,
769 'seller_name' => $item->createdBy->firstName . ' '
770 . $item->createdBy->familyName,
771 'vehicle_address' => $item->company->city->region->name
772 . ', ' . $item->company->city->name
773 . ', ' . $item->company->street
774 . ', ' . $item->company->postalCode,
775 'seller_billing_address' => $item->company->billingCity
776 ? $item->company->billingCity->region->name
777 . ', ' . $item->company->billingCity->name
778 . ', ' . $item->company->billingStreet
779 . ', ' . $item->company->billingPostalCode
781 'seller_vat_number' => !is_null($item->company->vatNumber)
782 ? $item->company->vatNumber
784 'seller_email' => $item->createdBy->email,
785 'stock_number' => $item->stock->stockNumber,
786 'buyer' => $item->currentBid->company->name,
787 'buyer_name' => $item->currentBid->profile->firstName . ' '
788 . $item->currentBid->profile->familyName,
789 'buyer_address' => $item->currentBid->company->city->region->name
790 . ', ' . $item->currentBid->company->city->name
791 . ', ' . $item->currentBid->company->street
792 . ', ' . $item->currentBid->company->postalCode,
793 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
794 ? $item->currentBid->company->vatNumber
796 'buyer_email' => $item->currentBid->profile->email,
797 'buyer_mobile' => $item->currentBid->profile->mobile
805 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
807 //send `auction-sale-seller` email to $item->stock->company->contact->email
808 $oNotify->sendFromTemplate(
809 $item->company->id, $item->createdBy->id,
810 $item->company->id, $item->createdBy->id,
811 $item->stock->company->contact->email, null,
812 'Auction Successful - ' . $item->id,
813 'auction-sale-seller',
815 'first_name' => $item->stock->company->contact->firstName,
816 'family_name' => $item->stock->company->contact->familyName,
817 'vehicle' => $vehicle,
818 'price' => $currPrefix . $item->currentBid->amount,
819 'buyer' => $item->currentBid->company->name,
820 'buyer_name' => $item->currentBid->profile->firstName . ' '
821 . $item->currentBid->profile->familyName,
822 'buyer_address' => $item->currentBid->company->city->region->name
823 . ', ' . $item->currentBid->company->city->name
824 . ', ' . $item->currentBid->company->street
825 . ', ' . $item->currentBid->company->postalCode,
826 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
827 ? $item->currentBid->company->vatNumber
829 'buyer_email' => $item->currentBid->profile->email,
830 'buyer_mobile' => $item->currentBid->profile->mobile,
831 'seller' => $item->company->name,
832 'seller_name' => $item->createdBy->firstName . ' '
833 . $item->createdBy->familyName,
834 'vehicle_address' => $item->company->city->region->name
835 . ', ' . $item->company->city->name
836 . ', ' . $item->company->street
837 . ', ' . $item->company->postalCode,
838 'seller_billing_address' => $item->company->billingCity
839 ? $item->company->billingCity->region->name
840 . ', ' . $item->company->billingCity->name
841 . ', ' . $item->company->billingStreet
842 . ', ' . $item->company->billingPostalCode
844 'seller_vat_number' => !is_null($item->company->vatNumber)
845 ? $item->company->vatNumber
847 'seller_email' => $item->createdBy->email,
848 'stock_number' => $item->stock->stockNumber
859 $oNotify->sendFromTemplate(
860 $item->company->id, $item->createdBy->id,
861 $item->company->id, $item->createdBy->id,
862 $item->createdBy->email, null,
863 'Auction Successful - ' . $item->id,
864 'auction-sale-seller',
866 'first_name' => $item->createdBy->firstName,
867 'family_name' => $item->createdBy->familyName,
868 'vehicle' => $vehicle,
869 'price' => $currPrefix . $item->currentBid->amount,
870 'buyer' => $item->currentBid->company->name,
871 'buyer_name' => $item->currentBid->profile->firstName . ' '
872 . $item->currentBid->profile->familyName,
873 'buyer_address' => $item->currentBid->company->city->region->name
874 . ', ' . $item->currentBid->company->city->name
875 . ', ' . $item->currentBid->company->street
876 . ', ' . $item->currentBid->company->postalCode,
877 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
878 ? $item->currentBid->company->vatNumber
880 'buyer_email' => $item->currentBid->profile->email,
881 'buyer_mobile' => $item->currentBid->profile->mobile,
882 'seller' => $item->company->name,
883 'seller_name' => $item->createdBy->firstName . ' '
884 . $item->createdBy->familyName,
885 'vehicle_address' => $item->company->city->region->name
886 . ', ' . $item->company->city->name
887 . ', ' . $item->company->street
888 . ', ' . $item->company->postalCode,
889 'seller_billing_address' => $item->company->billingCity
890 ? $item->company->billingCity->region->name
891 . ', ' . $item->company->billingCity->name
892 . ', ' . $item->company->billingStreet
893 . ', ' . $item->company->billingPostalCode
895 'seller_vat_number' => !is_null($item->company->vatNumber)
896 ? $item->company->vatNumber
898 'seller_email' => $item->createdBy->email,
899 'stock_number' => $item->stock->stockNumber
906 $attachments = array();
910 #-> No winner, send notification to seller & admin & feeder.
911 $oNotify->sendFromTemplate(
912 $item->company->id, $item->createdBy->id,
913 $item->company->id, $item->createdBy->id,
914 $item->createdBy->email, null,
915 'No winner on Bid4Cars Auction - ' . $item->id,
918 'first_name' => $item->createdBy->firstName,
919 'family_name' => $item->createdBy->familyName,
920 'vehicle' => $vehicle,
921 'reservePrice' => $item->reservePrice,
922 'registrationNumber' => $item->stock->registrationNumber,
923 'stockNumber' => $item->stock->stockNumber
931 $oNotify->sendFromTemplate(
932 $item->company->id, $item->createdBy->id,
933 $item->company->id, $item->createdBy->id,
934 'info@bid4cars.com.na', null,
935 'No winner on Bid4Cars Auction - ' . $item->id,
938 'first_name' => $item->createdBy->firstName,
939 'family_name' => $item->createdBy->familyName,
940 'vehicle' => $vehicle,
941 'reservePrice' => $item->reservePrice,
942 'registrationNumber' => $item->stock->registrationNumber,
943 'stockNumber' => $item->stock->stockNumber
951 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
953 $oNotify->sendFromTemplate(
954 $item->company->id, $item->createdBy->id,
955 $item->company->id, $item->createdBy->id,
956 $item->stock->company->contact->email, null,
957 'No winner on Bid4Cars Auction - ' . $item->id,
960 'first_name' => $item->stock->company->contact->firstName,
961 'family_name' => $item->stock->company->contact->familyName,
962 'vehicle' => $vehicle,
963 'reservePrice' => $item->reservePrice,
964 'registrationNumber' => $item->stock->registrationNumber,
965 'stockNumber' => $item->stock->stockNumber
976 $item->emailSent = true;
977 $this->em->flush($item);
979 catch (\Exception $e)
981 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
984 error_log('Auction cron ended @ ' . date('Y-m-d H:i:s'));
985 error_log('------------------------------------');
989 * Contract get total vehicels on auction.
990 * @param object|null $jobRecord
991 * @param array $input
992 * @return \Workspace\Contract\UseOnce
994 public function contractCount($jobRecord)
996 $options = new \Workspace\UseCase\Options();
997 $requirement = new \Workspace\UseCase\Requirement();
998 return new \Workspace\Contract\Recurring($options, $requirement);
1002 * get total vehicels on auction.
1003 * @param object|null $jobRecord
1004 * @param \Workspace\Utility\ServiceInputParams $contract
1007 public function executeCount($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
1009 $result = $this->em->createQuery(
1010 'SELECT COUNT(auction) AS total '
1011 . 'FROM \Auction\Entity\Auction auction '
1012 . 'WHERE auction.jobState = \'Active\' '
1013 . ' AND auction.archived = \'0\''
1015 ->getSingleResult();
1016 return $contract->success('Totals collected.', array('Items' => $result['total']));
1026 * CRON functionality: Move Auction items as needed.
1028 public function cronProcessCustom()
1030 ini_set('memory_limit', '512M');
1031 error_log('------------------------------------');
1032 error_log('Auction cron started @ ' . date('Y-m-d H:i:s'));
1034 $date = date('Y-m-d H:i:s');
1035 $result = $this->em->createQuery(
1036 'SELECT auction FROM \Auction\Entity\Auction auction '
1037 . 'WHERE auction.id IN (:ids)'
1039 ->setParameter('ids', array(30871, 30881, 30868, 30874, 30880, 30882, 30883, 30905))
1041 error_log("Item count: " . count($result));
1042 foreach ($result as $item)
1046 #-> General data prep.
1047 $vehicle = $item->stock->type->model->make->name
1048 . ', ' . $item->stock->type->model->name
1049 . ', ' . $item->stock->type->name;
1050 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
1051 $oNotify = new \Utility\Comms\Notification();
1053 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
1055 #-> Update record to reflect winner.
1056 if (is_null($item->soldToCompany))
1058 $item->soldToCompany = $item->currentBid->company;
1060 if (is_null($item->soldToProfile))
1062 $item->soldToProfile = $item->currentBid->profile;
1067 $pdf = new \Auction\Pdf\CompleteNew();
1068 $pdf->process(array(
1069 'jobRecord' => $item
1071 $docsDir = __DIR__ . '/../../../../../public/documents/';
1073 #-> Declaration PDF.
1074 $pdf_Declaration = new \Auction\Pdf\Declaration();
1075 $pdf_Declaration->process(array(
1076 'jobRecord' => $item
1078 $docsDir = __DIR__ . '/../../../../../public/documents/';
1080 #-> Deliveryreceipt PDF.
1081 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
1082 $pdf_Deliveryreceipt->process(array(
1083 'jobRecord' => $item
1085 $docsDir = __DIR__ . '/../../../../../public/documents/';
1087 $writer = new \Utility\Export\PdfTemplate($pdf);
1088 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
1089 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
1091 $attachments = array(
1092 'auction' . $item->id . '.pdf' => $writer->output(''),
1093 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
1094 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
1099 $oNotify->sendFromTemplate(
1100 $item->company->id, $item->createdBy->id,
1101 $item->currentBid->company->id, $item->currentBid->profile->id,
1102 'info@bid4cars.com.na', null,
1103 'Auction Successful - ' . $item->id,
1104 'auction-sale-buyer',
1106 'first_name' => 'Admin',
1107 'family_name' => '',
1108 'vehicle' => $vehicle,
1109 'price' => $currPrefix . $item->currentBid->amount,
1110 'seller' => $item->company->name,
1111 'seller_name' => $item->createdBy->firstName . ' '
1112 . $item->createdBy->familyName,
1113 'vehicle_address' => $item->company->city->region->name
1114 . ', ' . $item->company->city->name
1115 . ', ' . $item->company->street
1116 . ', ' . $item->company->postalCode,
1117 'seller_billing_address' => $item->company->billingCity
1118 ? $item->company->billingCity->region->name
1119 . ', ' . $item->company->billingCity->name
1120 . ', ' . $item->company->billingStreet
1121 . ', ' . $item->company->billingPostalCode
1123 'seller_vat_number' => !is_null($item->company->vatNumber)
1124 ? $item->company->vatNumber
1126 'seller_email' => $item->createdBy->email,
1127 'stock_number' => $item->stock->stockNumber,
1128 'buyer' => $item->currentBid->company->name,
1129 'buyer_name' => $item->currentBid->profile->firstName . ' '
1130 . $item->currentBid->profile->familyName,
1131 'buyer_address' => $item->currentBid->company->city->region->name
1132 . ', ' . $item->currentBid->company->city->name
1133 . ', ' . $item->currentBid->company->street
1134 . ', ' . $item->currentBid->company->postalCode,
1135 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1136 ? $item->currentBid->company->vatNumber
1138 'buyer_email' => $item->currentBid->profile->email,
1139 'buyer_mobile' => $item->currentBid->profile->mobile
1149 $oNotify->sendFromTemplate(
1150 $item->company->id, $item->createdBy->id,
1151 $item->currentBid->company->id, $item->currentBid->profile->id,
1152 'louise@combinefreight.co.za', null,
1153 'Auction Successful - ' . $item->id,
1154 'auction-sale-buyer',
1156 'first_name' => 'Admin',
1157 'family_name' => '',
1158 'vehicle' => $vehicle,
1159 'price' => $currPrefix . $item->currentBid->amount,
1160 'seller' => $item->company->name,
1161 'seller_name' => $item->createdBy->firstName . ' '
1162 . $item->createdBy->familyName,
1163 'vehicle_address' => $item->company->city->region->name
1164 . ', ' . $item->company->city->name
1165 . ', ' . $item->company->street
1166 . ', ' . $item->company->postalCode,
1167 'seller_billing_address' => $item->company->billingCity
1168 ? $item->company->billingCity->region->name
1169 . ', ' . $item->company->billingCity->name
1170 . ', ' . $item->company->billingStreet
1171 . ', ' . $item->company->billingPostalCode
1173 'seller_vat_number' => !is_null($item->company->vatNumber)
1174 ? $item->company->vatNumber
1176 'seller_email' => $item->createdBy->email,
1177 'stock_number' => $item->stock->stockNumber,
1178 'buyer' => $item->currentBid->company->name,
1179 'buyer_name' => $item->currentBid->profile->firstName . ' '
1180 . $item->currentBid->profile->familyName,
1181 'buyer_address' => $item->currentBid->company->city->region->name
1182 . ', ' . $item->currentBid->company->city->name
1183 . ', ' . $item->currentBid->company->street
1184 . ', ' . $item->currentBid->company->postalCode,
1185 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1186 ? $item->currentBid->company->vatNumber
1188 'buyer_email' => $item->currentBid->profile->email,
1189 'buyer_mobile' => $item->currentBid->profile->mobile
1198 $oNotify->sendFromTemplate(
1199 $item->company->id, $item->createdBy->id,
1200 $item->currentBid->company->id, $item->currentBid->profile->id,
1201 $item->currentBid->profile->email, null,
1202 'Bid Successful - ' . $item->id,
1203 'auction-sale-buyer',
1205 'first_name' => $item->currentBid->profile->firstName,
1206 'family_name' => $item->currentBid->profile->familyName,
1207 'vehicle' => $vehicle,
1208 'price' => $currPrefix . $item->currentBid->amount,
1209 'seller' => $item->company->name,
1210 'seller_name' => $item->createdBy->firstName . ' '
1211 . $item->createdBy->familyName,
1212 'vehicle_address' => $item->company->city->region->name
1213 . ', ' . $item->company->city->name
1214 . ', ' . $item->company->street
1215 . ', ' . $item->company->postalCode,
1216 'seller_billing_address' => $item->company->billingCity
1217 ? $item->company->billingCity->region->name
1218 . ', ' . $item->company->billingCity->name
1219 . ', ' . $item->company->billingStreet
1220 . ', ' . $item->company->billingPostalCode
1222 'seller_vat_number' => !is_null($item->company->vatNumber)
1223 ? $item->company->vatNumber
1225 'seller_email' => $item->createdBy->email,
1226 'stock_number' => $item->stock->stockNumber,
1227 'buyer' => $item->currentBid->company->name,
1228 'buyer_name' => $item->currentBid->profile->firstName . ' '
1229 . $item->currentBid->profile->familyName,
1230 'buyer_address' => $item->currentBid->company->city->region->name
1231 . ', ' . $item->currentBid->company->city->name
1232 . ', ' . $item->currentBid->company->street
1233 . ', ' . $item->currentBid->company->postalCode,
1234 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1235 ? $item->currentBid->company->vatNumber
1237 'buyer_email' => $item->currentBid->profile->email,
1238 'buyer_mobile' => $item->currentBid->profile->mobile
1248 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1250 //send `auction-sale-seller` email to $item->stock->company->contact->email
1251 $oNotify->sendFromTemplate(
1252 $item->company->id, $item->createdBy->id,
1253 $item->company->id, $item->createdBy->id,
1254 $item->stock->company->contact->email, null,
1255 'Auction Successful - ' . $item->id,
1256 'auction-sale-seller',
1258 'first_name' => $item->stock->company->contact->firstName,
1259 'family_name' => $item->stock->company->contact->familyName,
1260 'vehicle' => $vehicle,
1261 'price' => $currPrefix . $item->currentBid->amount,
1262 'buyer' => $item->currentBid->company->name,
1263 'buyer_name' => $item->currentBid->profile->firstName . ' '
1264 . $item->currentBid->profile->familyName,
1265 'buyer_address' => $item->currentBid->company->city->region->name
1266 . ', ' . $item->currentBid->company->city->name
1267 . ', ' . $item->currentBid->company->street
1268 . ', ' . $item->currentBid->company->postalCode,
1269 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1270 ? $item->currentBid->company->vatNumber
1272 'buyer_email' => $item->currentBid->profile->email,
1273 'buyer_mobile' => $item->currentBid->profile->mobile,
1274 'seller' => $item->company->name,
1275 'seller_name' => $item->createdBy->firstName . ' '
1276 . $item->createdBy->familyName,
1277 'vehicle_address' => $item->company->city->region->name
1278 . ', ' . $item->company->city->name
1279 . ', ' . $item->company->street
1280 . ', ' . $item->company->postalCode,
1281 'seller_billing_address' => $item->company->billingCity
1282 ? $item->company->billingCity->region->name
1283 . ', ' . $item->company->billingCity->name
1284 . ', ' . $item->company->billingStreet
1285 . ', ' . $item->company->billingPostalCode
1287 'seller_vat_number' => !is_null($item->company->vatNumber)
1288 ? $item->company->vatNumber
1290 'seller_email' => $item->createdBy->email,
1291 'stock_number' => $item->stock->stockNumber
1301 $oNotify->sendFromTemplate(
1302 $item->company->id, $item->createdBy->id,
1303 $item->company->id, $item->createdBy->id,
1304 $item->createdBy->email, null,
1305 'Auction Successful - ' . $item->id,
1306 'auction-sale-seller',
1308 'first_name' => $item->createdBy->firstName,
1309 'family_name' => $item->createdBy->familyName,
1310 'vehicle' => $vehicle,
1311 'price' => $currPrefix . $item->currentBid->amount,
1312 'buyer' => $item->currentBid->company->name,
1313 'buyer_name' => $item->currentBid->profile->firstName . ' '
1314 . $item->currentBid->profile->familyName,
1315 'buyer_address' => $item->currentBid->company->city->region->name
1316 . ', ' . $item->currentBid->company->city->name
1317 . ', ' . $item->currentBid->company->street
1318 . ', ' . $item->currentBid->company->postalCode,
1319 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1320 ? $item->currentBid->company->vatNumber
1322 'buyer_email' => $item->currentBid->profile->email,
1323 'buyer_mobile' => $item->currentBid->profile->mobile,
1324 'seller' => $item->company->name,
1325 'seller_name' => $item->createdBy->firstName . ' '
1326 . $item->createdBy->familyName,
1327 'vehicle_address' => $item->company->city->region->name
1328 . ', ' . $item->company->city->name
1329 . ', ' . $item->company->street
1330 . ', ' . $item->company->postalCode,
1331 'seller_billing_address' => $item->company->billingCity
1332 ? $item->company->billingCity->region->name
1333 . ', ' . $item->company->billingCity->name
1334 . ', ' . $item->company->billingStreet
1335 . ', ' . $item->company->billingPostalCode
1337 'seller_vat_number' => !is_null($item->company->vatNumber)
1338 ? $item->company->vatNumber
1340 'seller_email' => $item->createdBy->email,
1341 'stock_number' => $item->stock->stockNumber
1348 $attachments = array();
1352 #-> No winner, send notification to seller & admin & feeder dealer.
1353 $oNotify->sendFromTemplate(
1354 $item->company->id, $item->createdBy->id,
1355 $item->company->id, $item->createdBy->id,
1356 $item->createdBy->email, null,
1357 'No winner on Bid4Cars Auction - ' . $item->id,
1360 'first_name' => $item->createdBy->firstName,
1361 'family_name' => $item->createdBy->familyName,
1362 'vehicle' => $vehicle,
1363 'reservePrice' => $item->reservePrice,
1364 'registrationNumber' => $item->stock->registrationNumber,
1365 'stockNumber' => $item->stock->stockNumber
1373 $oNotify->sendFromTemplate(
1374 $item->company->id, $item->createdBy->id,
1375 $item->company->id, $item->createdBy->id,
1376 'info@bid4cars.com.na', null,
1377 'No winner on Bid4Cars Auction - ' . $item->id,
1380 'first_name' => $item->createdBy->firstName,
1381 'family_name' => $item->createdBy->familyName,
1382 'vehicle' => $vehicle,
1383 'reservePrice' => $item->reservePrice,
1384 'registrationNumber' => $item->stock->registrationNumber,
1385 'stockNumber' => $item->stock->stockNumber
1394 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1396 $oNotify->sendFromTemplate(
1397 $item->company->id, $item->createdBy->id,
1398 $item->company->id, $item->createdBy->id,
1399 $item->stock->company->contact->email, null,
1400 'No winner on Bid4Cars Auction - ' . $item->id,
1403 'first_name' => $item->stock->company->contact->firstName,
1404 'family_name' => $item->stock->company->contact->familyName,
1405 'vehicle' => $vehicle,
1406 'reservePrice' => $item->reservePrice,
1407 'registrationNumber' => $item->stock->registrationNumber,
1408 'stockNumber' => $item->stock->stockNumber
1419 $item->emailSent = true;
1420 $this->em->flush($item);
1422 catch (\Exception $e)
1424 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
1427 error_log('Auction cron ended @ ' . date('Y-m-d H:i:s'));
1428 error_log('------------------------------------');
1432 * CRON functionality: Move Auction items as needed.
1434 public function cronProcessCleanup()
1436 $mailTo = 'dino@nirph.com';
1437 ini_set('memory_limit', '512M');
1438 error_log('------------------------------------');
1439 error_log('Auction cleanup cron started @ ' . date('Y-m-d H:i:s'));
1443 $numRecsRes = $this->em->createQuery(
1444 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction '
1445 . 'WHERE auction.endDate <= \'' . date('Y-m-d H:i:s') . '\''
1446 . ' AND auction.endDate > \'' . date('Y-m-d') . ' 00:00:00\''
1447 . ' AND auction.jobState != :jobStateArchived'
1449 ->setParameter('jobStateArchived', 'Archived')
1450 ->getSingleResult();
1451 $totalItems = (int)$numRecsRes['total'];
1452 $numRecsRes = $this->em->createQuery(
1453 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction '
1454 . 'WHERE auction.jobState = :jobState '
1455 . ' AND auction.endDate <= :startDate'
1456 . ' AND auction.endDate > :endDate'
1458 ->setParameter('jobState', 'Sold')
1459 ->setParameter('startDate', date('Y-m-d H:i:s'))
1460 ->setParameter('endDate', date('Y-m-d') . ' 00:00:00')
1461 ->getSingleResult();
1462 $successItems = (int)$numRecsRes['total'];
1463 // $result = $this->em->createQuery(
1464 // 'SELECT auction FROM \Auction\Entity\Auction auction '
1465 // . 'WHERE auction.jobState != :jobState AND auction.jobState != :jobStateTwo'
1466 // . ' AND auction.emailSent = :emailSent'
1468 // ->setParameter('jobState', 'Active')
1469 // ->setParameter('jobStateTwo', 'Relist')
1470 // ->setParameter('emailSent', false)
1473 $result = $this->em->createQuery(
1474 'SELECT auction FROM \Auction\Entity\Auction auction '
1475 . 'WHERE auction.jobState != :jobState'
1476 . ' AND auction.jobState != :jobStateArchived'
1477 . ' AND auction.emailSent = :emailSent'
1479 ->setParameter('jobState', 'Active')
1480 ->setParameter('jobStateArchived', 'Archived')
1481 ->setParameter('emailSent', false)
1484 $mailer = new \Utility\Comms\Email();
1485 $mailer->send(array(
1486 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'),
1488 'Subject' => 'Auction cleanup cron Start - ' . date('Y-m-d H:i:s'),
1489 'Html' => '<b>Total auction items:<//b> ' . $totalItems . '<br//>'
1490 . '<b>Total items sold:<//b> ' . $successItems . '<br//>'
1491 . '<b>Total items no winner:<//b> ' . ($totalItems - $successItems) . '<br//>'
1492 . '<b>Mails not yet sent:<//b> ' . count($result) . '<br//>'
1497 error_log("Item count: " . count($result));
1498 foreach ($result as $item)
1502 #-> General data prep.
1503 $vehicle = $item->stock->type->model->make->name
1504 . ', ' . $item->stock->type->model->name
1505 . ', ' . $item->stock->type->name;
1506 $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' ';
1507 $oNotify = new \Utility\Comms\Notification();
1509 if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState)
1511 #-> Update record to reflect winner.
1512 if (is_null($item->soldToCompany))
1514 $item->soldToCompany = $item->currentBid->company;
1516 if (is_null($item->soldToProfile))
1518 $item->soldToProfile = $item->currentBid->profile;
1523 $pdf = new \Auction\Pdf\CompleteNew();
1524 $pdf->process(array(
1525 'jobRecord' => $item
1527 $docsDir = __DIR__ . '/../../../../../public/documents/';
1529 #-> Declaration PDF.
1530 $pdf_Declaration = new \Auction\Pdf\Declaration();
1531 $pdf_Declaration->process(array(
1532 'jobRecord' => $item
1534 $docsDir = __DIR__ . '/../../../../../public/documents/';
1536 #-> Deliveryreceipt PDF.
1537 $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt();
1538 $pdf_Deliveryreceipt->process(array(
1539 'jobRecord' => $item
1541 $docsDir = __DIR__ . '/../../../../../public/documents/';
1543 $writer = new \Utility\Export\PdfTemplate($pdf);
1544 $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration);
1545 $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt);
1547 $attachments = array(
1548 'auction' . $item->id . '.pdf' => $writer->output(''),
1549 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''),
1550 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('')
1555 $oNotify->sendFromTemplate(
1556 $item->company->id, $item->createdBy->id,
1557 $item->currentBid->company->id, $item->currentBid->profile->id,
1558 'info@bid4cars.com.na', null,
1559 'Auction Successful - ' . $item->id,
1560 'auction-sale-buyer',
1562 'first_name' => 'Admin',
1563 'family_name' => '',
1564 'vehicle' => $vehicle,
1565 'price' => $currPrefix . $item->currentBid->amount,
1566 'seller' => $item->company->name,
1567 'seller_name' => $item->createdBy->firstName . ' '
1568 . $item->createdBy->familyName,
1569 'vehicle_address' => $item->company->city->region->name
1570 . ', ' . $item->company->city->name
1571 . ', ' . $item->company->street
1572 . ', ' . $item->company->postalCode,
1573 'seller_billing_address' => $item->company->billingCity
1574 ? $item->company->billingCity->region->name
1575 . ', ' . $item->company->billingCity->name
1576 . ', ' . $item->company->billingStreet
1577 . ', ' . $item->company->billingPostalCode
1579 'seller_vat_number' => !is_null($item->company->vatNumber)
1580 ? $item->company->vatNumber
1582 'seller_email' => $item->createdBy->email,
1583 'stock_number' => $item->stock->stockNumber,
1584 'buyer' => $item->currentBid->company->name,
1585 'buyer_name' => $item->currentBid->profile->firstName . ' '
1586 . $item->currentBid->profile->familyName,
1587 'buyer_address' => $item->currentBid->company->city->region->name
1588 . ', ' . $item->currentBid->company->city->name
1589 . ', ' . $item->currentBid->company->street
1590 . ', ' . $item->currentBid->company->postalCode,
1591 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1592 ? $item->currentBid->company->vatNumber
1594 'buyer_email' => $item->currentBid->profile->email,
1595 'buyer_mobile' => $item->currentBid->profile->mobile
1604 $oNotify->sendFromTemplate(
1605 $item->company->id, $item->createdBy->id,
1606 $item->currentBid->company->id, $item->currentBid->profile->id,
1607 'louise@combinefreight.co.za', null,
1608 'Auction Successful - ' . $item->id,
1609 'auction-sale-buyer',
1611 'first_name' => 'Admin',
1612 'family_name' => '',
1613 'vehicle' => $vehicle,
1614 'price' => $currPrefix . $item->currentBid->amount,
1615 'seller' => $item->company->name,
1616 'seller_name' => $item->createdBy->firstName . ' '
1617 . $item->createdBy->familyName,
1618 'vehicle_address' => $item->company->city->region->name
1619 . ', ' . $item->company->city->name
1620 . ', ' . $item->company->street
1621 . ', ' . $item->company->postalCode,
1622 'seller_billing_address' => $item->company->billingCity
1623 ? $item->company->billingCity->region->name
1624 . ', ' . $item->company->billingCity->name
1625 . ', ' . $item->company->billingStreet
1626 . ', ' . $item->company->billingPostalCode
1628 'seller_vat_number' => !is_null($item->company->vatNumber)
1629 ? $item->company->vatNumber
1631 'seller_email' => $item->createdBy->email,
1632 'stock_number' => $item->stock->stockNumber,
1633 'buyer' => $item->currentBid->company->name,
1634 'buyer_name' => $item->currentBid->profile->firstName . ' '
1635 . $item->currentBid->profile->familyName,
1636 'buyer_address' => $item->currentBid->company->city->region->name
1637 . ', ' . $item->currentBid->company->city->name
1638 . ', ' . $item->currentBid->company->street
1639 . ', ' . $item->currentBid->company->postalCode,
1640 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1641 ? $item->currentBid->company->vatNumber
1643 'buyer_email' => $item->currentBid->profile->email,
1644 'buyer_mobile' => $item->currentBid->profile->mobile
1653 $oNotify->sendFromTemplate(
1654 $item->company->id, $item->createdBy->id,
1655 $item->currentBid->company->id, $item->currentBid->profile->id,
1656 $item->currentBid->profile->email, null,
1657 'Bid Successful - ' . $item->id,
1658 'auction-sale-buyer',
1660 'first_name' => $item->currentBid->profile->firstName,
1661 'family_name' => $item->currentBid->profile->familyName,
1662 'vehicle' => $vehicle,
1663 'price' => $currPrefix . $item->currentBid->amount,
1664 'seller' => $item->company->name,
1665 'seller_name' => $item->createdBy->firstName . ' '
1666 . $item->createdBy->familyName,
1667 'vehicle_address' => $item->company->city->region->name
1668 . ', ' . $item->company->city->name
1669 . ', ' . $item->company->street
1670 . ', ' . $item->company->postalCode,
1671 'seller_billing_address' => $item->company->billingCity
1672 ? $item->company->billingCity->region->name
1673 . ', ' . $item->company->billingCity->name
1674 . ', ' . $item->company->billingStreet
1675 . ', ' . $item->company->billingPostalCode
1677 'seller_vat_number' => !is_null($item->company->vatNumber)
1678 ? $item->company->vatNumber
1680 'seller_email' => $item->createdBy->email,
1681 'stock_number' => $item->stock->stockNumber,
1682 'buyer' => $item->currentBid->company->name,
1683 'buyer_name' => $item->currentBid->profile->firstName . ' '
1684 . $item->currentBid->profile->familyName,
1685 'buyer_address' => $item->currentBid->company->city->region->name
1686 . ', ' . $item->currentBid->company->city->name
1687 . ', ' . $item->currentBid->company->street
1688 . ', ' . $item->currentBid->company->postalCode,
1689 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1690 ? $item->currentBid->company->vatNumber
1692 'buyer_email' => $item->currentBid->profile->email,
1693 'buyer_mobile' => $item->currentBid->profile->mobile
1702 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1704 //send `auction-sale-seller` email to $item->stock->company->contact->email
1705 $oNotify->sendFromTemplate(
1706 $item->company->id, $item->createdBy->id,
1707 $item->company->id, $item->createdBy->id,
1708 $item->stock->company->contact->email, null,
1709 'Auction Successful - ' . $item->id,
1710 'auction-sale-seller',
1712 'first_name' => $item->stock->company->contact->firstName,
1713 'family_name' => $item->stock->company->contact->familyName,
1714 'vehicle' => $vehicle,
1715 'price' => $currPrefix . $item->currentBid->amount,
1716 'buyer' => $item->currentBid->company->name,
1717 'buyer_name' => $item->currentBid->profile->firstName . ' '
1718 . $item->currentBid->profile->familyName,
1719 'buyer_address' => $item->currentBid->company->city->region->name
1720 . ', ' . $item->currentBid->company->city->name
1721 . ', ' . $item->currentBid->company->street
1722 . ', ' . $item->currentBid->company->postalCode,
1723 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1724 ? $item->currentBid->company->vatNumber
1726 'buyer_email' => $item->currentBid->profile->email,
1727 'buyer_mobile' => $item->currentBid->profile->mobile,
1728 'seller' => $item->company->name,
1729 'seller_name' => $item->createdBy->firstName . ' '
1730 . $item->createdBy->familyName,
1731 'vehicle_address' => $item->company->city->region->name
1732 . ', ' . $item->company->city->name
1733 . ', ' . $item->company->street
1734 . ', ' . $item->company->postalCode,
1735 'seller_billing_address' => $item->company->billingCity
1736 ? $item->company->billingCity->region->name
1737 . ', ' . $item->company->billingCity->name
1738 . ', ' . $item->company->billingStreet
1739 . ', ' . $item->company->billingPostalCode
1741 'seller_vat_number' => !is_null($item->company->vatNumber)
1742 ? $item->company->vatNumber
1744 'seller_email' => $item->createdBy->email,
1745 'stock_number' => $item->stock->stockNumber
1756 $oNotify->sendFromTemplate(
1757 $item->company->id, $item->createdBy->id,
1758 $item->company->id, $item->createdBy->id,
1759 $item->createdBy->email, null,
1760 'Auction Successful - ' . $item->id,
1761 'auction-sale-seller',
1763 'first_name' => $item->createdBy->firstName,
1764 'family_name' => $item->createdBy->familyName,
1765 'vehicle' => $vehicle,
1766 'price' => $currPrefix . $item->currentBid->amount,
1767 'buyer' => $item->currentBid->company->name,
1768 'buyer_name' => $item->currentBid->profile->firstName . ' '
1769 . $item->currentBid->profile->familyName,
1770 'buyer_address' => $item->currentBid->company->city->region->name
1771 . ', ' . $item->currentBid->company->city->name
1772 . ', ' . $item->currentBid->company->street
1773 . ', ' . $item->currentBid->company->postalCode,
1774 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber)
1775 ? $item->currentBid->company->vatNumber
1777 'buyer_email' => $item->currentBid->profile->email,
1778 'buyer_mobile' => $item->currentBid->profile->mobile,
1779 'seller' => $item->company->name,
1780 'seller_name' => $item->createdBy->firstName . ' '
1781 . $item->createdBy->familyName,
1782 'vehicle_address' => $item->company->city->region->name
1783 . ', ' . $item->company->city->name
1784 . ', ' . $item->company->street
1785 . ', ' . $item->company->postalCode,
1786 'seller_billing_address' => $item->company->billingCity
1787 ? $item->company->billingCity->region->name
1788 . ', ' . $item->company->billingCity->name
1789 . ', ' . $item->company->billingStreet
1790 . ', ' . $item->company->billingPostalCode
1792 'seller_vat_number' => !is_null($item->company->vatNumber)
1793 ? $item->company->vatNumber
1795 'seller_email' => $item->createdBy->email,
1796 'stock_number' => $item->stock->stockNumber
1803 $attachments = array();
1807 #-> No winner, send notification to seller & admin & feeder.
1808 $oNotify->sendFromTemplate(
1809 $item->company->id, $item->createdBy->id,
1810 $item->company->id, $item->createdBy->id,
1811 $item->createdBy->email, null,
1812 'No winner on Bid4Cars Auction - ' . $item->id,
1815 'first_name' => $item->createdBy->firstName,
1816 'family_name' => $item->createdBy->familyName,
1817 'vehicle' => $vehicle,
1818 'reservePrice' => $item->reservePrice,
1819 'registrationNumber' => $item->stock->registrationNumber,
1820 'stockNumber' => $item->stock->stockNumber
1827 $oNotify->sendFromTemplate(
1828 $item->company->id, $item->createdBy->id,
1829 $item->company->id, $item->createdBy->id,
1830 'info@bid4cars.com.na', null,
1831 'No winner on Bid4Cars Auction - ' . $item->id,
1834 'first_name' => $item->createdBy->firstName,
1835 'family_name' => $item->createdBy->familyName,
1836 'vehicle' => $vehicle,
1837 'reservePrice' => $item->reservePrice,
1838 'registrationNumber' => $item->stock->registrationNumber,
1839 'stockNumber' => $item->stock->stockNumber
1847 if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email)
1849 $oNotify->sendFromTemplate(
1850 $item->company->id, $item->createdBy->id,
1851 $item->company->id, $item->createdBy->id,
1852 $item->stock->company->contact->email, null,
1853 'No winner on Bid4Cars Auction - ' . $item->id,
1856 'first_name' => $item->stock->company->contact->firstName,
1857 'family_name' => $item->stock->company->contact->familyName,
1858 'vehicle' => $vehicle,
1859 'reservePrice' => $item->reservePrice,
1860 'registrationNumber' => $item->stock->registrationNumber,
1861 'stockNumber' => $item->stock->stockNumber
1872 $item->emailSent = true;
1873 $this->em->flush($item);
1876 catch (\Exception $e)
1878 \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage());
1881 error_log('Auction cleanup cron ended @ ' . date('Y-m-d H:i:s'));
1882 error_log('------------------------------------');
1885 $mailer = new \Utility\Comms\Email();
1886 $mailer->send(array(
1887 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'),
1889 'Subject' => 'Auction cleanup cron End - ' . date('Y-m-d H:i:s'),
1890 'Html' => '<b>Total auction items:<//b> ' . $totalItems . '<br//>'
1891 . '<b>Emails sent:<//b> ' . $sent . ' of ' . count($result) . '<br//>'