Establish initial increment value. $increments = $this->em ->getRepository('\Auction\Entity\Increment') ->findBy(array(), array('to' => 'ASC')); foreach ($increments as $incr) { if ($incr->to >= $routingData['reservePrice'] && $incr->from <= $routingData['reservePrice'] ) { break; } } #-> Create auction entry. if (isset($routingData['profileId'])) { $profile = $this->em->find('User\\Entity\\Profile', $routingData['profileId']); $email = $profile->email; $firstName = $profile->firstName; $familyName = $profile->familyName; $company = !is_null($profile->company) ? $profile->company->id : null; $profile = $profile->id; } else { $authData = \Utility\Registry::getAuthData(); $email = $authData['email']; $firstName = $authData['firstName']; $familyName = $authData['familyName']; $profile = \Utility\Registry::resolveProfileContext()->id; $company = \Utility\Registry::resolveCompanyContext()->id; } $routingData['endDate'] = str_replace(' 00:00:00', '', $routingData['endDate']); $record = $this->create(array( 'createdBy' => $profile, 'company' => $company, 'stock' => $stock->id, 'reservePrice' => $routingData['reservePrice'], 'currentBidPrice' => $routingData['reservePrice'], 'bidIncrement' => $incr->amount, 'startDate' => new \DateTime("now"), 'endDate' => new \DateTime($routingData['endDate'] . ' 14:30:00') )); #-> Update stock with count of times sent to auction. $stats = $this->em->createQuery( 'SELECT COUNT(auction.id) AS numAuctions ' . 'FROM \Auction\Entity\Auction auction ' . 'WHERE IDENTITY(auction.stock) = :stockId' ) ->setParameter('stockId', $stock->id) ->getSingleResult(); $stock->auction = $record; $stock->highestBid = 0.00; $stock->timesListed = $stats['numAuctions']; $this->em->flush($stock); #-> Send loaded notification. #-> Attachments. $pdf = new \Auction\Pdf\Complete(); $pdf->process(array( 'jobRecord' => $record ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; $writer = new \Utility\Export\PdfTemplate($pdf); $attachments = array( 'auction' . $record->id . '.pdf' => $writer->output(''), 'REGULATION_32_NOTICE_38960.pdf' => file_get_contents($docsDir . 'REGULATION_32_NOTICE_38960.pdf') ); #-> Send email. $oNotify = new \Utility\Comms\Notification(); $oNotify->sendFromTemplate( null, null, $company, $profile, $email, null, 'Vehicle live on Bid4Cars Auction - ' . $record->id, 'auction-loaded', array( 'first_name' => $firstName, 'family_name' => $familyName, 'make' => $stock->type->model->make->name, 'model' => $stock->type->model->name, 'type' => $stock->type->name, 'image' => !is_null($stock->mainImage) ? $stock->mainImage->filename : 'main_img_car.png' ), $attachments, array(), false, true ); } /** * Contract to get selectlist. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractHistoricMakeSelectList($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array'))); return new \Workspace\Contract\UseOnce($options, $requirement); } /** * Get Select List. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeHistoricMakeSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $em = \Utility\Registry::getEntityManager(); $authData = \Utility\Registry::getAuthData(); $companyId = $authData['company']['id']; $queryFilter = array(); if (isset($contract->data->filter) && is_array($contract->data->filter['Filters'])) { foreach ($contract->data->filter['Filters'] as $field => $filter) { $queryFilter[] = $field . ' = ' . $filter; } } $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : ''; $memberslistdrop = $em->createQuery(' SELECT distinct make.id, make.name FROM \Auction\Entity\Auction auction JOIN auction.company company JOIN company.city city JOIN company.contact contact JOIN city.region region JOIN auction.stock stock JOIN stock.company companyStock JOIN stock.vehicleYear vehicleYear JOIN stock.type type JOIN type.model model JOIN model.make make LEFT JOIN stock.exteriorColour exteriorColour LEFT JOIN auction.currentBid currentBid WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter . 'ORDER BY make.name'); $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days')); $memberslistdrop->setParameter('sold', 'Sold'); $memberslistu = $memberslistdrop->getArrayResult(); $datax = array(); foreach ($memberslistu as $data) { $datax[] = array( 'value' => $data['id'], 'label' => $data['name'] ); } return $contract->success('List Retrieved.', $datax); } /** * Contract to get selectlist. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractHistoricModelSelectList($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array'))); return new \Workspace\Contract\UseOnce($options, $requirement); } /** * Get Select List. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeHistoricModelSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $em = \Utility\Registry::getEntityManager(); $authData = \Utility\Registry::getAuthData(); $companyId = $authData['company']['id']; $queryFilter = array(); if (isset($contract->data->filter) && is_array($contract->data->filter['Filters'])) { foreach ($contract->data->filter['Filters'] as $field => $filter) { $queryFilter[] = $field . ' = ' . $filter; } } $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : ''; $memberslistdrop = $em->createQuery(' SELECT distinct model.id, model.name FROM \Auction\Entity\Auction auction JOIN auction.company company JOIN company.city city JOIN company.contact contact JOIN city.region region JOIN auction.stock stock JOIN stock.company companyStock JOIN stock.vehicleYear vehicleYear JOIN stock.type type JOIN type.model model JOIN model.make make LEFT JOIN stock.exteriorColour exteriorColour LEFT JOIN auction.currentBid currentBid WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter . 'ORDER BY model.name'); $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days')); $memberslistdrop->setParameter('sold', 'Sold'); $memberslistu = $memberslistdrop->getArrayResult(); $datax = array(); foreach ($memberslistu as $data) { $datax[] = array( 'value' => $data['id'], 'label' => $data['name'] ); } return $contract->success('List Retrieved.', $datax); } /** * Contract to get selectlist. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractHistoricTypeSelectList($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array'))); return new \Workspace\Contract\UseOnce($options, $requirement); } /** * Get Select List. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeHistoricTypeSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $em = \Utility\Registry::getEntityManager(); $authData = \Utility\Registry::getAuthData(); $companyId = $authData['company']['id']; $queryFilter = array(); if (isset($contract->data->filter) && is_array($contract->data->filter['Filters'])) { foreach ($contract->data->filter['Filters'] as $field => $filter) { $queryFilter[] = $field . ' = ' . $filter; } } $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : ''; $memberslistdrop = $em->createQuery(' SELECT distinct type.id, type.name FROM \Auction\Entity\Auction auction JOIN auction.company company JOIN company.city city JOIN company.contact contact JOIN city.region region JOIN auction.stock stock JOIN stock.company companyStock JOIN stock.vehicleYear vehicleYear JOIN stock.type type JOIN type.model model JOIN model.make make LEFT JOIN stock.exteriorColour exteriorColour LEFT JOIN auction.currentBid currentBid WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter . 'ORDER BY type.name'); $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days')); $memberslistdrop->setParameter('sold', 'Sold'); $memberslistu = $memberslistdrop->getArrayResult(); $datax = array(); foreach ($memberslistu as $data) { $datax[] = array( 'value' => $data['id'], 'label' => $data['name'] ); } return $contract->success('List Retrieved.', $datax); } /** * Contract to get selectlist. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractHistoricYearSelectList($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addOptionalInput(array('filter' => array('Filters' => 'Array'))); return new \Workspace\Contract\UseOnce($options, $requirement); } /** * Get Select List. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeHistoricYearSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $em = \Utility\Registry::getEntityManager(); $authData = \Utility\Registry::getAuthData(); $companyId = $authData['company']['id']; $queryFilter = array(); if (isset($contract->data->filter) && is_array($contract->data->filter['Filters'])) { foreach ($contract->data->filter['Filters'] as $field => $filter) { $queryFilter[] = $field . ' = ' . $filter; } } $queryFilter = $queryFilter ? 'AND ' . implode(' AND ', $queryFilter) : ''; $memberslistdrop = $em->createQuery(' SELECT distinct vehicleYear.id, vehicleYear.name FROM \Auction\Entity\Auction auction JOIN auction.company company JOIN company.city city JOIN company.contact contact JOIN city.region region JOIN auction.stock stock JOIN stock.company companyStock JOIN stock.vehicleYear vehicleYear JOIN stock.type type JOIN type.model model JOIN model.make make LEFT JOIN stock.exteriorColour exteriorColour LEFT JOIN auction.currentBid currentBid WHERE auction.jobState = :sold AND auction.archived = 0 AND auction.endDate > :endDate ' . $queryFilter . 'ORDER BY vehicleYear.name'); $memberslistdrop->setParameter('endDate', new \DateTime('-180 Days')); $memberslistdrop->setParameter('sold', 'Sold'); $memberslistu = $memberslistdrop->getArrayResult(); $datax = array(); foreach ($memberslistu as $data) { $datax[] = array( 'value' => $data['id'], 'label' => $data['name'] ); } return $contract->success('List Retrieved.', $datax); } /** * Contract to remove item from auction. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractRemove($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); return new \Workspace\Contract\UseOnce($options, $requirement); } /** * Remove item from auction. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeRemove($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { try { $workflow = \Utility\Registry::getServiceManager() ->get('Stock'); $workflow->handover('Auction', $jobRecord->stock->id); } catch (\Exception $e) { \Utility\Debug::errorLog( 'Error on Auction removal process for item ' . $jobRecord->id, $e->getMessage() ); } $this->workflowNode->changeState('This.Archived'); return $contract->success('Vehicle removed from auction.', array()); } /** * Contract to undo auction. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractUndo($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); return new \Workspace\Contract\UseOnce($options, $requirement); } /** * Undo auction. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeUndo($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $this->workflowNode->changeState('This.Undone'); $jobRecord->currentBid->status = 'Undone'; try { $workflow = \Utility\Registry::getServiceManager() ->get('Stock'); $workflow->handover('Auction', $jobRecord->stock->id); } catch (\Exception $e) { \Utility\Debug::errorLog( 'Error on Auction Undo process for item ' . $jobRecord->id, $e->getMessage() ); } return $contract->success('Vehicle removed from auction.', array()); } /** * CRON functionality: Send newsletter of cars coming off from auction today. */ public function newsletterProcess() { set_time_limit(0); ini_set('memory_limit', '512M'); #-> Collect data. $date = date('Y-m-d 23:59:59'); $data = $this->em->createQuery( 'SELECT DISTINCT auction.id, auction.reservePrice AS auction_reservePrice, stock.km AS stock_km, ' . 'type.name AS type_name, type.mmCode AS type_mmCode, model.name AS model_name, ' . 'make.name AS make_name, vehicleYear.name AS vehicleYear_name, region.name AS region_name ' . 'FROM \Auction\Entity\Auction auction ' . 'JOIN auction.stock stock ' . 'JOIN stock.type type ' . 'JOIN type.model model ' . 'JOIN model.make make ' . 'JOIN stock.vehicleYear vehicleYear ' . 'LEFT JOIN stock.company company ' . 'LEFT JOIN company.city city ' . 'LEFT JOIN company.contact contact' . 'LEFT JOIN city.region region ' . 'WHERE auction.jobState = \'Active\'' . ' AND auction.endDate >= :startDate ' . ' AND auction.endDate <= :endDate ' . 'ORDER BY make.name, model.name, type.name ASC' ) ->setParameter('startDate', date('Y-m-d 01:00:00')) ->setParameter('endDate', date('Y-m-d 23:59:59')) ->getScalarResult(); if (empty($data)) { return; } $i = count($data); $this->em->clear(); $oNotify = new \Utility\Comms\Notification(); $oNotify->setRepeaterData($data); $oNotify->setSendAsNewsletter(); $oNotify->sendFromTemplate( null, null, null, null, null, null, null, 'auction-list', array('auctioncount' => $i) ); } /** * CRON functionality: Move Auction items as needed. */ public function cronProcess() { ini_set('memory_limit', '512M'); error_log('------------------------------------'); error_log('Auction cron started @ ' . date('Y-m-d H:i:s')); #-> Phase 1. $date = date('Y-m-d H:i:s'); $result = $this->em->createQuery( 'SELECT auction FROM \Auction\Entity\Auction auction ' . 'WHERE auction.jobState = \'Active\'' . ' AND auction.jobState != \'Archived\'' . ' AND auction.endDate <= \'' . $date . '\'' ) ->getResult(); $workflow = \Utility\Registry::getServiceManager() ->get('Stock'); error_log("Item count: " . count($result)); foreach ($result as $item) { $this->workflowNode->setJob($item); try { if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice) { #-> We have a winner. $item->soldToCompany = $item->currentBid->company; $item->soldToProfile = $item->currentBid->profile; $this->workflowNode->changeState('This.Sold'); } else { #-> Each and every one a loser. $this->workflowNode->changeState('This.Relist'); } } catch (\Exception $e) { \Utility\Debug::errorLog('Error on Auction cron process (state change) for item ' . $item->id, $e->getMessage()); } try { $workflow->handover('Auction', $item->stock->id); } catch (\Exception $e) { \Utility\Debug::errorLog('Error on Auction cron process (handover) for item ' . $item->id, $e->getMessage()); } } $this->em->flush(); foreach ($result as $item) { try { #-> General data prep. $vehicle = $item->stock->type->model->make->name . ', ' . $item->stock->type->model->name . ', ' . $item->stock->type->name; $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' '; $oNotify = new \Utility\Comms\Notification(); if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState) { #-> Update record to reflect winner. $item->soldToCompany = $item->currentBid->company; $item->soldToProfile = $item->currentBid->profile; #-> Prep work. #-> Auction PDF. $pdf = new \Auction\Pdf\CompleteNew(); $pdf->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; #-> Declaration PDF. $pdf_Declaration = new \Auction\Pdf\Declaration(); $pdf_Declaration->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; #-> Deliveryreceipt PDF. $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt(); $pdf_Deliveryreceipt->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; $writer = new \Utility\Export\PdfTemplate($pdf); $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration); $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt); $attachments = array( 'auction' . $item->id . '.pdf' => $writer->output(''), 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''), 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('') ); #-> Admin. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, 'info@bid4cars.com.na', null, 'Auction Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => 'Admin', 'family_name' => '', 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Combined freight. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, 'louise@combinefreight.co.za', null, 'Auction Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => 'Admin', 'family_name' => '', 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Buyer. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, $item->currentBid->profile->email, null, 'Bid Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => $item->currentBid->profile->firstName, 'family_name' => $item->currentBid->profile->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email) { //send `auction-sale-seller` email to $item->stock->company->contact->email $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->stock->company->contact->email, null, 'Auction Successful - ' . $item->id, 'auction-sale-seller', array( 'first_name' => $item->stock->company->contact->firstName, 'family_name' => $item->stock->company->contact->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber ), $attachments, array(), false, true ); } #-> Seller. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->createdBy->email, null, 'Auction Successful - ' . $item->id, 'auction-sale-seller', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber ), $attachments, array(), false, true ); $attachments = array(); } else { #-> No winner, send notification to seller & admin & feeder. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->createdBy->email, null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, 'info@bid4cars.com.na', null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email) { $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->stock->company->contact->email, null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->stock->company->contact->firstName, 'family_name' => $item->stock->company->contact->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); } } $item->emailSent = true; $this->em->flush($item); } catch (\Exception $e) { \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage()); } } error_log('Auction cron ended @ ' . date('Y-m-d H:i:s')); error_log('------------------------------------'); } /** * Contract get total vehicels on auction. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractCount($jobRecord) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); return new \Workspace\Contract\Recurring($options, $requirement); } /** * get total vehicels on auction. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeCount($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $result = $this->em->createQuery( 'SELECT COUNT(auction) AS total ' . 'FROM \Auction\Entity\Auction auction ' . 'WHERE auction.jobState = \'Active\' ' . ' AND auction.archived = \'0\'' ) ->getSingleResult(); return $contract->success('Totals collected.', array('Items' => $result['total'])); } // /** * CRON functionality: Move Auction items as needed. */ public function cronProcessCustom() { ini_set('memory_limit', '512M'); error_log('------------------------------------'); error_log('Auction cron started @ ' . date('Y-m-d H:i:s')); #-> Phase 1. $date = date('Y-m-d H:i:s'); $result = $this->em->createQuery( 'SELECT auction FROM \Auction\Entity\Auction auction ' . 'WHERE auction.id IN (:ids)' ) ->setParameter('ids', array(30871, 30881, 30868, 30874, 30880, 30882, 30883, 30905)) ->getResult(); error_log("Item count: " . count($result)); foreach ($result as $item) { try { #-> General data prep. $vehicle = $item->stock->type->model->make->name . ', ' . $item->stock->type->model->name . ', ' . $item->stock->type->name; $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' '; $oNotify = new \Utility\Comms\Notification(); if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState) { #-> Update record to reflect winner. if (is_null($item->soldToCompany)) { $item->soldToCompany = $item->currentBid->company; } if (is_null($item->soldToProfile)) { $item->soldToProfile = $item->currentBid->profile; } #-> Prep work. #-> Auction PDF. $pdf = new \Auction\Pdf\CompleteNew(); $pdf->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; #-> Declaration PDF. $pdf_Declaration = new \Auction\Pdf\Declaration(); $pdf_Declaration->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; #-> Deliveryreceipt PDF. $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt(); $pdf_Deliveryreceipt->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; $writer = new \Utility\Export\PdfTemplate($pdf); $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration); $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt); $attachments = array( 'auction' . $item->id . '.pdf' => $writer->output(''), 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''), 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('') ); #-> Admin. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, 'info@bid4cars.com.na', null, 'Auction Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => 'Admin', 'family_name' => '', 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Admin. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, 'louise@combinefreight.co.za', null, 'Auction Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => 'Admin', 'family_name' => '', 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Buyer. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, $item->currentBid->profile->email, null, 'Bid Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => $item->currentBid->profile->firstName, 'family_name' => $item->currentBid->profile->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Feeder. if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email) { //send `auction-sale-seller` email to $item->stock->company->contact->email $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->stock->company->contact->email, null, 'Auction Successful - ' . $item->id, 'auction-sale-seller', array( 'first_name' => $item->stock->company->contact->firstName, 'family_name' => $item->stock->company->contact->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber ), $attachments, array(), false, true ); } #-> Seller. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->createdBy->email, null, 'Auction Successful - ' . $item->id, 'auction-sale-seller', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber ), $attachments, array(), false, true ); $attachments = array(); } else { #-> No winner, send notification to seller & admin & feeder dealer. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->createdBy->email, null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, 'info@bid4cars.com.na', null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); #No Winner Feeder if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email) { $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->stock->company->contact->email, null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->stock->company->contact->firstName, 'family_name' => $item->stock->company->contact->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); } } $item->emailSent = true; $this->em->flush($item); } catch (\Exception $e) { \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage()); } } error_log('Auction cron ended @ ' . date('Y-m-d H:i:s')); error_log('------------------------------------'); } /** * CRON functionality: Move Auction items as needed. */ public function cronProcessCleanup() { $mailTo = 'dino@nirph.com'; ini_set('memory_limit', '512M'); error_log('------------------------------------'); error_log('Auction cleanup cron started @ ' . date('Y-m-d H:i:s')); #-> Opening mail. $numRecsRes = $this->em->createQuery( 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction ' . 'WHERE auction.endDate <= \'' . date('Y-m-d H:i:s') . '\'' . ' AND auction.endDate > \'' . date('Y-m-d') . ' 00:00:00\'' . ' AND auction.jobState != :jobStateArchived' ) ->setParameter('jobStateArchived', 'Archived') ->getSingleResult(); $totalItems = (int)$numRecsRes['total']; $numRecsRes = $this->em->createQuery( 'SELECT COUNT(auction.id) AS total FROM Auction\\Entity\\Auction auction ' . 'WHERE auction.jobState = :jobState ' . ' AND auction.endDate <= :startDate' . ' AND auction.endDate > :endDate' ) ->setParameter('jobState', 'Sold') ->setParameter('startDate', date('Y-m-d H:i:s')) ->setParameter('endDate', date('Y-m-d') . ' 00:00:00') ->getSingleResult(); $successItems = (int)$numRecsRes['total']; // $result = $this->em->createQuery( // 'SELECT auction FROM \Auction\Entity\Auction auction ' // . 'WHERE auction.jobState != :jobState AND auction.jobState != :jobStateTwo' // . ' AND auction.emailSent = :emailSent' // ) // ->setParameter('jobState', 'Active') // ->setParameter('jobStateTwo', 'Relist') // ->setParameter('emailSent', false) // ->getResult(); $result = $this->em->createQuery( 'SELECT auction FROM \Auction\Entity\Auction auction ' . 'WHERE auction.jobState != :jobState' . ' AND auction.jobState != :jobStateArchived' . ' AND auction.emailSent = :emailSent' ) ->setParameter('jobState', 'Active') ->setParameter('jobStateArchived', 'Archived') ->setParameter('emailSent', false) ->getResult(); $mailer = new \Utility\Comms\Email(); $mailer->send(array( 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'), 'To' => $mailTo, 'Subject' => 'Auction cleanup cron Start - ' . date('Y-m-d H:i:s'), 'Html' => 'Total auction items: ' . $totalItems . '
' . 'Total items sold: ' . $successItems . '
' . 'Total items no winner: ' . ($totalItems - $successItems) . '
' . 'Mails not yet sent: ' . count($result) . '
' )); $sent = 0; #-> Phase 1. error_log("Item count: " . count($result)); foreach ($result as $item) { try { #-> General data prep. $vehicle = $item->stock->type->model->make->name . ', ' . $item->stock->type->model->name . ', ' . $item->stock->type->name; $currPrefix = \Utility\Definitions\Locale::getCurrencyPrefix() . ' '; $oNotify = new \Utility\Comms\Notification(); if (!is_null($item->currentBid) && $item->currentBid->amount > $item->reservePrice && 'Sold' == $item->jobState) { #-> Update record to reflect winner. if (is_null($item->soldToCompany)) { $item->soldToCompany = $item->currentBid->company; } if (is_null($item->soldToProfile)) { $item->soldToProfile = $item->currentBid->profile; } #-> Prep work. #-> Auction PDF. $pdf = new \Auction\Pdf\CompleteNew(); $pdf->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; #-> Declaration PDF. $pdf_Declaration = new \Auction\Pdf\Declaration(); $pdf_Declaration->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; #-> Deliveryreceipt PDF. $pdf_Deliveryreceipt = new \Auction\Pdf\Deliveryreceipt(); $pdf_Deliveryreceipt->process(array( 'jobRecord' => $item ), array()); $docsDir = __DIR__ . '/../../../../../public/documents/'; $writer = new \Utility\Export\PdfTemplate($pdf); $writer_Declaration = new \Utility\Export\PdfTemplate($pdf_Declaration); $writer_Deliveryreceipt = new \Utility\Export\PdfTemplate($pdf_Deliveryreceipt); $attachments = array( 'auction' . $item->id . '.pdf' => $writer->output(''), 'declaration' . $item->id . '.pdf' => $writer_Declaration->output(''), 'deliveryreceipt' . $item->id . '.pdf' => $writer_Deliveryreceipt->output('') ); #-> Admin. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, 'info@bid4cars.com.na', null, 'Auction Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => 'Admin', 'family_name' => '', 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Admin. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, 'louise@combinefreight.co.za', null, 'Auction Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => 'Admin', 'family_name' => '', 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Buyer. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->currentBid->company->id, $item->currentBid->profile->id, $item->currentBid->profile->email, null, 'Bid Successful - ' . $item->id, 'auction-sale-buyer', array( 'first_name' => $item->currentBid->profile->firstName, 'family_name' => $item->currentBid->profile->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile ), $attachments, array(), false, true ); #-> Feeder. if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email) { //send `auction-sale-seller` email to $item->stock->company->contact->email $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->stock->company->contact->email, null, 'Auction Successful - ' . $item->id, 'auction-sale-seller', array( 'first_name' => $item->stock->company->contact->firstName, 'family_name' => $item->stock->company->contact->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber ), $attachments, array(), false, true ); } #-> Seller. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->createdBy->email, null, 'Auction Successful - ' . $item->id, 'auction-sale-seller', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'price' => $currPrefix . $item->currentBid->amount, 'buyer' => $item->currentBid->company->name, 'buyer_name' => $item->currentBid->profile->firstName . ' ' . $item->currentBid->profile->familyName, 'buyer_address' => $item->currentBid->company->city->region->name . ', ' . $item->currentBid->company->city->name . ', ' . $item->currentBid->company->street . ', ' . $item->currentBid->company->postalCode, 'buyer_vat_number' => !is_null($item->currentBid->company->vatNumber) ? $item->currentBid->company->vatNumber : '', 'buyer_email' => $item->currentBid->profile->email, 'buyer_mobile' => $item->currentBid->profile->mobile, 'seller' => $item->company->name, 'seller_name' => $item->createdBy->firstName . ' ' . $item->createdBy->familyName, 'vehicle_address' => $item->company->city->region->name . ', ' . $item->company->city->name . ', ' . $item->company->street . ', ' . $item->company->postalCode, 'seller_billing_address' => $item->company->billingCity ? $item->company->billingCity->region->name . ', ' . $item->company->billingCity->name . ', ' . $item->company->billingStreet . ', ' . $item->company->billingPostalCode : '', 'seller_vat_number' => !is_null($item->company->vatNumber) ? $item->company->vatNumber : '', 'seller_email' => $item->createdBy->email, 'stock_number' => $item->stock->stockNumber ), $attachments, array(), false, true ); $attachments = array(); } else { #-> No winner, send notification to seller & admin & feeder. $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->createdBy->email, null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, 'info@bid4cars.com.na', null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->createdBy->firstName, 'family_name' => $item->createdBy->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); #No Winner Feeder if ($item->stock->company->id != $item->company->id && '' != $item->stock->company->contact->email) { $oNotify->sendFromTemplate( $item->company->id, $item->createdBy->id, $item->company->id, $item->createdBy->id, $item->stock->company->contact->email, null, 'No winner on Bid4Cars Auction - ' . $item->id, 'auction-no-sale', array( 'first_name' => $item->stock->company->contact->firstName, 'family_name' => $item->stock->company->contact->familyName, 'vehicle' => $vehicle, 'reservePrice' => $item->reservePrice, 'registrationNumber' => $item->stock->registrationNumber, 'stockNumber' => $item->stock->stockNumber ), array(), array(), false, true ); } } $item->emailSent = true; $this->em->flush($item); $sent++; } catch (\Exception $e) { \Utility\Debug::errorLog('Error on Auction cron process for item ' . $item->id, $e->getMessage()); } } error_log('Auction cleanup cron ended @ ' . date('Y-m-d H:i:s')); error_log('------------------------------------'); $mailer = new \Utility\Comms\Email(); $mailer->send(array( 'From' => \Utility\Registry::getConfigParam('sourceEmailAddress'), 'To' => $mailTo, 'Subject' => 'Auction cleanup cron End - ' . date('Y-m-d H:i:s'), 'Html' => 'Total auction items: ' . $totalItems . '
' . 'Emails sent: ' . $sent . ' of ' . count($result) . '
' )); } }