2 namespace Workspace\Controller;
23 \\_'. > '-._ '. \ / / /
34 (_ ) /b) \ '. : \___.-:_/ \__/
35 /:/: , ) : ( /_.'_/-' |_ _ /
36 /:/: __/\ > __,_.----.__\ / (/(/(/
37 (_(,_/V .'/--' _/ __/ | /
45 THERE BE DRAGONS HERE, DO NOT MESS WITH THIS CODE
49 class WorkspaceController extends \Zend\Mvc\Controller\AbstractActionController
53 * @var \Zend\Session\Container
65 * @var \Zend\ServiceManager\ServiceManager
69 * @var \Doctrine\ORM\EntityManager
75 protected $authenticated;
77 * @var \User\Service\Authentication
79 protected $authDetails;
83 public function checkWsdlAction()
87 //$h="http://secureuat.decisionsystems.co.za/AISConvergedB2BService/AISConvergedB2BService.svc?singleWsdl";
91 /* $service = new \Zend\Soap\Client("/test/php/bassa.wsdl", array(
92 "soap_version" => SOAP_1_2,
95 "location" => "http://".$h.":".$p)); */
98 /* $client = new \Zend\Soap\Client("http://196.36.251.126/AISConvergedB2BService/AISConvergedB2BService.svc?wsdl", array(
99 'soap_version' => SOAP_1_1
103 //$url = "http://secureuat.decisionsystems.co.za/AISConvergedB2BService/AISConvergedB2BService.svc?singleWsdl";
104 // http://secureuat.decisionsystems.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl
105 // https://autoinsight.transunion.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl
107 $client = new \Zend\Soap\Client("https://autotest.transunion.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl", array(
108 'soap_version' => SOAP_1_1
114 //$header = new Zend\Soap\Header("http://www.example.com/webservices/", "APICredentials", $auth, false);
116 // M)andatory/ (O)ptional /(C)onditional //trade and retail
119 //$client->setHttpLogin('181306');
120 //$client->setHttpPassword('PW181306#');
121 //$client->setLocation("http://secureuat.decisionsystems.co.za/AISConvergedB2BService/AISConvergedB2BService.svc?singleWsdl");
124 /*$res = $client->call("AISConvergedB2B", array(
125 'AISConvergedB2B' => array(
127 'ExtensionData' => null,
128 'ClientReference' => "",
130 'Condition' => "FAIR",
131 'CustomerProductId' => 0,
132 'EngineNumber' => "2E5060747",
135 //'LoginId' => "181367",
136 'LoginId' => "171887",
137 'OptionCodeNew' => "0",
138 'OptionCodeUsed' => "0",
139 //'Password' => "PW181367#",
140 'Password' => "PW171887#",
141 'RegistrationNumber' => "SLD174GP",
142 'RegistrationYear' => 2005,
143 'RequestorPerson' => "Andre",
144 'RequestorTelNumber' => "0",
145 'VehicleCode' => "22020110",
146 'VehicleMileage' => 0,
147 'VinOrChasisNumber' => "AHT54EE900A030001"
151 $res = $client->call("AISConvergedB2B", array(
152 'AISConvergedB2B' => array(
154 'ExtensionData' => null,
155 'ClientReference' => "",
156 //'Colour' => "White",
157 'Condition' => "Good",
158 'CustomerProductId' => 0,
159 'EngineNumber' => "G4HGBM370811",
162 'LoginId' => "181367",
163 'OptionCodeNew' => "0",
164 'OptionCodeUsed' => "0",
165 'Password' => "PW181367#",
166 'RegistrationNumber' => "NPN47328",
167 'RegistrationYear' => 2012,
168 'RequestorPerson' => "Andre",
169 'RequestorTelNumber' => "0825732810",
170 'VehicleCode' => "26516101",
171 'VehicleMileage' => 0,
172 'VinOrChasisNumber' => "MALAN51BLCM020415"
176 /* $res = $client->call("AISConvergedB2B", array(
177 'AISConvergedB2B' => array(
179 'ExtensionData' => null,
180 'ClientReference' => "",
181 'Colour' => "Silver",
182 'Condition' => "Good",
183 'CustomerProductId' => 0,
184 'EngineNumber' => "CLP126405",
187 'LoginId' => "181367",
188 'OptionCodeNew' => "0",
189 'OptionCodeUsed' => "0",
190 'Password' => "PW181367#",
191 'RegistrationNumber' => "CJ28TLGP",
192 'RegistrationYear' => 2013,
193 'RequestorPerson' => "Andre",
194 'RequestorTelNumber' => "0825732810",
195 'VehicleCode' => "26516101",
196 'VehicleMileage' => 0,
197 'VinOrChasisNumber' => "AAVZZZ6SZDU019961"
201 \Utility\Debug::errorLog('test', $res->AISConvergedB2BResult);
202 //echo 'Please check the php error log :)';
204 var_dump($res->AISConvergedB2BResult);
207 //var_dump($client->getFunctions());
217 public function imageUploadAction()
219 \Utility\Registry::setServiceManager($this->serviceLocator);
220 \Utility\Registry::addDynamicConfig(
221 \Utility\Cache::fetchEntity(
222 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
225 $upload = new \Utility\Upload\Image();
230 public function documentUploadAction()
232 \Utility\Registry::setServiceManager($this->serviceLocator);
233 \Utility\Registry::addDynamicConfig(
234 \Utility\Cache::fetchEntity(
235 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
238 $upload = new \Utility\Upload\Document();
242 public function attachmentUploadAction()
244 \Utility\Registry::setServiceManager($this->serviceLocator);
245 \Utility\Registry::addDynamicConfig(
246 \Utility\Cache::fetchEntity(
247 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
250 $upload = new \Utility\Upload\Attachment();
254 public function init()
256 $this->getServiceLocator()->get('Application')->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function($event){
257 $event->getResponse()->getHeaders()->addHeaderLine('Content-Type', 'application/json');
263 * Retrieve workspace manager.
265 public function initJson()
268 define('APPLICATION', 'Portal');
269 $this->session = new \Zend\Session\Container(__CLASS__);
270 isset($this->session->hashLog)
271 || $this->session->hashLog = array();
272 $this->request = json_decode(file_get_contents('php://input'), true);
273 if (is_null($this->request))
278 $this->response = array();
279 $this->authenticated = \Utility\Registry::isAuthenticated();
280 if ($this->authenticated)
282 $this->authDetails = \Utility\Registry::getAuthData();
284 \Utility\Registry::setServiceManager($this->serviceLocator);
285 \Utility\Registry::addDynamicConfig(
286 \Utility\Cache::fetchEntity(
287 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
292 public function banner1Action()
294 \Utility\Registry::setServiceManager($this->serviceLocator);
295 $click = new \Statistical\Entity\Click();
296 $click->bannerId = 'Home: Banner 1 (Left)';
297 $click->ipAddress = $_SERVER['REMOTE_ADDR'];
298 $click->created = new \DateTime("now");
299 $em = \Utility\Registry::getEntityManager();
300 $em->persist($click);
302 header('Location: http://www.combinefreight.co.za');
306 public function banner2Action()
308 \Utility\Registry::setServiceManager($this->serviceLocator);
309 $click = new \Statistical\Entity\Click();
310 $click->bannerId = 'Home: Banner 2 (Right)';
311 $click->ipAddress = $_SERVER['REMOTE_ADDR'];
312 $click->created = new \DateTime("now");
313 $em = \Utility\Registry::getEntityManager();
314 $em->persist($click);
316 header('Location: http://www.combinefreight.co.za');
320 public function checkUniqueEmailAction()
322 header('Expires: Fri, 26 Nov 1976 05:00:00 GMT');
323 header('Cache-Control: no-cache, must-revalidate');
324 header("Pragma: no-cache");
325 header('Content-type: application/json; charset=utf-8');
326 $request = array_merge($_POST, $_GET);
327 if (!isset($request['email']))
329 echo \Zend\Json\Json::encode('Email address is required.');
332 $email = $request['email'];
333 \Utility\Registry::setServiceManager($this->serviceLocator);
334 $em = \Utility\Registry::getEntityManager();
335 $entry = $em->getRepository('\User\Entity\Profile')
336 ->findOneBy(array('email' => $email));
337 echo \Zend\Json\Json::encode(
340 : 'Email address already in use.'
345 public function checkUniqueCompanyAction()
347 header('Expires: Fri, 26 Nov 1976 05:00:00 GMT');
348 header('Cache-Control: no-cache, must-revalidate');
349 header("Pragma: no-cache");
350 header('Content-type: application/json; charset=utf-8');
351 $request = array_merge($_POST, $_GET);
352 if (!isset($request['name']))
354 echo \Zend\Json\Json::encode('Company name is required.');
357 $name = $request['name'];
358 \Utility\Registry::setServiceManager($this->serviceLocator);
359 $em = \Utility\Registry::getEntityManager();
360 $entry = $em->getRepository('\Company\Entity\Company')
361 ->findOneBy(array('name' => $name));
362 echo \Zend\Json\Json::encode(
365 : 'Company name already in use.'
371 * Retrieve workspace manager.
373 public function initPost()
375 $this->session = new \Zend\Session\Container(__CLASS__);
376 isset($this->session->hashLog)
377 || $this->session->hashLog = array();
378 $this->request = array($_POST);
379 $this->response = array();
380 $this->authenticated = \Utility\Registry::isAuthenticated();
381 if ($this->authenticated)
383 $this->authDetails = \Utility\Registry::getAuthData();
385 \Utility\Registry::setServiceManager($this->serviceLocator);
386 \Utility\Registry::addDynamicConfig(
387 \Utility\Cache::fetchEntity(
388 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
394 * Convenience method to extract parameters from request packet.
395 * @param integer $requestId
396 * @param string $paramName
397 * @param unknown $default
400 protected function reqParam($requestId, $paramName, $default = null)
402 return isset($this->request[$requestId][$paramName])
403 ? $this->request[$requestId][$paramName]
410 * Display list of tasks for specified workflows.
411 * @see \Zend\Mvc\Controller\AbstractActionController::indexAction()
412 * @return \Zend\View\Model\ViewModel
414 public function indexAction()
418 #-> Input format safety check.
419 if (!is_array($this->request))
421 return new \Zend\View\Model\JsonModel(array(
422 'Status' => 'Exception',
423 'StatusReason' => 'This api call requires an array of Workflow names as input.'
427 #-> Process requests.
428 foreach ($this->request as $requestId => $request)
430 #-> Collect basic data.
431 if (is_array($request))
433 list($workflow, $state) = each($request);
437 $workflow = $request;
444 $this->response[$requestId]['Status'] = 'Exception';
445 $this->response[$requestId]['StatusReason'] = 'Malformed server request. No Workflow name provided.';
448 $this->response[$requestId] = array();
450 #-> Retrieve task list.
453 $wf = $this->getServiceLocator()->get($workflow);
454 $this->response[$requestId] = array_merge(
455 $this->response[$requestId],
456 $wf->listStateTasks($state)
459 catch (\Exception $e)
461 $this->response[$requestId]['Status'] = 'Exception';
462 $this->response[$requestId]['StatusReason'] = 'Invalid Workflow requested.';
463 $this->response[$requestId]['Exception'] = "$e";
466 return new \Zend\View\Model\JsonModel($this->response);
470 * Negotiate task contract(s).
471 * @return \Zend\View\Model\JsonModel
473 protected function contract($type)
477 #-> Input format safety check.
478 if (!is_array($this->request))
480 return new \Zend\View\Model\JsonModel(array(
481 'Status' => 'Exception',
482 'StatusReason' => 'This api call requires an array of Contract Request Items as input.'
486 #-> Process requests.
487 foreach ($this->request as $requestId => $request)
489 #-> Collect basic data.
490 $workflow = $this->reqParam($requestId, 'Workspace', false);
491 $jobId = $this->reqParam($requestId, 'JobId', null);
492 $task = $this->reqParam($requestId, $type, false);
493 $packet = $this->reqParam($requestId, 'Packet', array());
496 && !isset($packet['id'])
497 && $packet['id'] = $jobId;
500 if (!$workflow || !$task)
502 $this->response[$requestId]['Status'] = 'Exception';
503 $this->response[$requestId]['StatusReason'] = 'Malformed server request. Parameters `Workspace` and `' . $type . '` required.';
506 $hash = md5(serialize($request) . '.Contract');
507 $this->response[$requestId] = array(
508 'Workflow' => $workflow,
514 $taskParts = explode('.', $task);
515 $theme = $taskParts[0];
516 $action = isset($taskParts[1])
520 #-> Store contract request
521 $this->session->hashLog[$hash] = array(
522 'Workspace' => $workflow,
528 'LifeTime' => 'UseOnce'
531 #-> Retrieve contract.
532 $action = 'contract' . $action;
535 $wf = $this->getServiceLocator()->get($workflow);
539 ->contractTask($task, $jobId, $packet)
545 ->contractRoute($task, $jobId, $packet)
548 $this->session->hashLog[$hash] = array_merge($this->session->hashLog[$hash], $contract);
549 $this->response[$requestId] = array_merge(
550 $this->response[$requestId],
554 catch (\Exception $e)
556 unset($this->response[$requestId]['Hash']);
557 $this->response[$requestId]['Status'] = 'Exception';
558 $this->response[$requestId]['StatusReason'] = $e->getMessage();
559 $this->response[$requestId]['Exception'] = "$e";
560 unset($this->session->hashLog[$hash]);
563 return new \Zend\View\Model\JsonModel($this->response);
567 * Execute contracted task(s).
568 * @return \Zend\View\Model\JsonModel
570 public function execute($type)
574 #-> Input format safety check.
575 if (!is_array($this->request))
577 return new \Zend\View\Model\JsonModel(array(
578 'Status' => 'Exception',
579 'StatusReason' => 'This api call requires an array of Contract Execution Items as input.'
583 #-> Process requests.
584 foreach ($this->request as $requestId => $request)
586 #-> Collect basic data.
587 $hash = $this->reqParam($requestId, 'Contract', false);
588 $packet = $this->reqParam($requestId, 'Packet', array());
589 $options = $this->reqParam($requestId, 'Options', array());
591 // error_log('$hash: ' . $hash);
596 $this->response[$requestId]['Status'] = 'Exception';
597 $this->response[$requestId]['StatusReason'] = 'Malformed server request. Parameter `Contract` required.';
600 if (!isset($this->session->hashLog[$hash]))
602 $this->response[$requestId]['Status'] = 'Exception';
603 $this->response[$requestId]['StatusReason'] = 'Invalid contract request. No such contract found for execution.';
606 if ($type != $this->session->hashLog[$hash]['Type'])
608 $this->response[$requestId]['Status'] = 'Exception';
609 $this->response[$requestId]['StatusReason'] = 'Call type mismatch, contract is of type '
610 . $this->session->hashLog[$hash]['Type'] . '.';
612 $this->response[$requestId] = array();
616 #-> Validate contract.
617 $packet = array_merge(
619 $this->session->hashLog[$hash]['Packet']
621 $contractClass = '\\Workspace\\Contract\\' . $this->session->hashLog[$hash]['LifeTime'];
622 $contract = new $contractClass(null, null, $this->session->hashLog[$hash], $packet, $options);
623 $workflow = $this->session->hashLog[$hash]['Workspace'];
624 $jobId = $this->session->hashLog[$hash]['JobId'];
625 $theme = $this->session->hashLog[$hash]['Theme'];
626 $action = $this->session->hashLog[$hash]['Action'];
627 $wf = $this->getServiceLocator()->get($workflow);
628 if (!$contract->isValid($wf))
630 $this->response[$requestId]['Status'] = 'Exception';
631 $this->response[$requestId]['StatusReason'] = 'Input validation errors.';
632 $this->response[$requestId]['Messages'] = $contract->getMessages();
636 #-> Execute contract.
639 $this->response[$requestId] = array_merge(
640 $this->response[$requestId],
644 $contract->getSignedContract($requestId, $hash)
650 $this->response[$requestId] = array_merge(
651 $this->response[$requestId],
655 $contract->getSignedContract($requestId, $hash)
659 if ($this->session->hashLog[$hash]['LifeTime'] == 'UseOnce' && 'Success' == $this->response[$requestId]['Status'])
661 #-> Contract fulfilled and expired.
662 unset($this->session->hashLog[$hash]);
665 catch (\Exception $e)
667 #-> Oops, something went wrong.
668 $this->response[$requestId]['Status'] = 'Exception';
669 $this->response[$requestId]['StatusReason'] = $e->getMessage();
670 $this->response[$requestId]['Exception'] = "$e";
673 return new \Zend\View\Model\JsonModel($this->response);
677 * Execute direct task(s).
678 * @return \Zend\View\Model\JsonModel
680 public function executeDirect($type)
684 #-> Input format safety check.
685 if (!is_array($this->request))
687 return new \Zend\View\Model\JsonModel(array(
688 'Status' => 'Exception',
689 'StatusReason' => 'This api call requires an array of Contract Request Items as input.'
693 #-> Process requests.
694 foreach ($this->request as $requestId => $request)
696 #-> Collect basic data.
697 $workflow = $this->reqParam($requestId, 'Workspace', false);
698 $jobId = $this->reqParam($requestId, 'JobId', null);
699 $task = $this->reqParam($requestId, $type, false);
700 $packet = $this->reqParam($requestId, 'Packet', array());
703 if (!$workflow || !$task)
705 $this->response[$requestId]['Status'] = 'Exception';
706 $this->response[$requestId]['StatusReason'] = 'Malformed server request. Parameters `Workspace` and `' . $type . '` required.';
709 $hash = md5(serialize($request) . '.Contract');
710 $this->response[$requestId] = array(
711 'Workflow' => $workflow,
717 $taskParts = explode('.', $task);
718 $theme = $taskParts[0];
719 $action = isset($taskParts[1])
723 #-> Retrieve contract.
724 $action = 'contract' . $action;
727 $wf = $this->getServiceLocator()->get($workflow);
728 if ('Route' == $type)
731 ->directRoute($task, $jobId);
735 return new \Zend\View\Model\JsonModel(array(
736 'Status' => 'Exception',
737 'StatusReason' => 'Direct execution only allowed on Routes.'
740 $this->response[$requestId] = array_merge(
741 $this->response[$requestId],
745 catch (\Exception $e)
747 unset($this->response[$requestId]['Hash']);
748 $this->response[$requestId]['Status'] = 'Exception';
749 $this->response[$requestId]['StatusReason'] = $e->getMessage();
752 return new \Zend\View\Model\JsonModel($this->response);
757 * Negotiate task contract(s).
758 * @return \Zend\View\Model\JsonModel
760 public function contractTaskAction()
762 return $this->contract('Task');
766 * Execute task contract(s).
767 * @return \Zend\View\Model\JsonModel
769 public function executeTaskAction()
771 return $this->execute('Task');
775 * Execute direct task(s).
776 * @return \Zend\View\Model\JsonModel
778 public function directTaskAction()
780 return $this->executeDirect('Task');
784 * Negotiate route contract(s).
785 * @return \Zend\View\Model\JsonModel
787 public function contractRouteAction()
789 return $this->contract('Route');
793 * Execute route contract(s).
794 * @return \Zend\View\Model\JsonModel
796 public function executeRouteAction()
798 return $this->execute('Route');
802 * Execute direct route(s).
803 * @return \Zend\View\Model\JsonModel
805 public function directRouteAction()
807 return $this->executeDirect('Route');
811 * Cancel task contract(s).
812 * @return \Zend\View\Model\JsonModel
814 public function negateAction()
818 #-> Input format safety check.
819 if (!is_array($this->request))
821 return new \Zend\View\Model\JsonModel(array(
822 'Status' => 'Exception',
823 'StatusReason' => 'This api call requires an array of Contract Identifiers.'
827 #-> Process requests.
828 foreach ($this->request as $requestId => $hash)
833 $this->response[$requestId]['Status'] = 'Exception';
834 $this->response[$requestId]['StatusReason'] = 'Malformed server request. Contract Identifier required.';
837 if (!isset($this->session->hashLog[$hash]))
839 $this->response[$requestId]['Status'] = 'Exception';
840 $this->response[$requestId]['StatusReason'] = 'Invalid contract request. No such contract found.';
843 $this->response[$requestId] = array();
845 #-> Contract cancelled.
846 unset($this->session->hashLog[$hash]);
847 $this->response[$requestId]['Status'] = 'Success';
849 return new \Zend\View\Model\JsonModel($this->response);
853 * Validate unique value for a specified field.
854 * @return \Zend\View\Model\JsonModel
856 public function validateUniqueFieldAction()
860 #-> Input format safety check.
861 is_array($this->request)
862 && !empty($this->request)
863 && $this->request = $this->request[0];
864 if (!is_array($this->request)
865 || !isset($this->request['Workspace'])
866 || !isset($this->request['Group'])
867 || !isset($this->request['Field'])
868 || !isset($this->request['Value']))
870 return new \Zend\View\Model\JsonModel(array(
871 'Status' => 'Exception',
872 'StatusReason' => 'This api call requires an array with `Workspace`, `Group`, `Field` and `Value` parameters set.'
879 $contract = new \Workspace\Utility\ServiceInput('Contract', array(
880 'Group' => $this->request['Group'],
881 'Field' => $this->request['Field'],
882 'Value' => $this->request['Value'],
883 'Id' => isset($this->request['Id'])
884 ? $this->request['Id']
887 $this->response = $this->getServiceLocator()
888 ->get($this->request['Workspace'])
889 ->fieldIsUnique($contract->pack());
892 catch (\Exception $e)
894 #-> Oops, something went wrong.
895 $this->response['Status'] = 'Exception';
896 $this->response['StatusReason'] = 'Invalid Workflow requested.';
897 $this->response['Exception'] = "$e";
899 return new \Zend\View\Model\JsonModel($this->response);
903 * Validate unique value for a specified field.
904 * @return \Zend\View\Model\JsonModel
906 public function validateUniqueFieldDirectAction()
910 #-> Input format safety check.
911 is_array($this->request)
912 && !empty($this->request)
913 && $this->request = $this->request[0];
914 if (!is_array($this->request)
915 || !isset($this->request['Workspace'])
916 || !isset($this->request['Group'])
917 || !isset($this->request['Field'])
918 || !isset($this->request['Value']))
920 return new \Zend\View\Model\JsonModel(array(
921 'Status' => 'Exception',
922 'StatusReason' => 'This api call requires an array with `Workspace`, `Group`, `Field` and `Value` parameters set.'
929 $contract = new \Workspace\Utility\ServiceInput('Contract', array(
930 'Group' => $this->request['Group'],
931 'Field' => $this->request['Field'],
932 'Value' => $this->request['Value'],
933 'Id' => isset($this->request['Id'])
934 ? $this->request['Id']
937 $this->response = $this->getServiceLocator()
938 ->get($this->request['Workspace'])
939 ->fieldIsUnique($contract->pack());
940 if ('Success' == $this->response['Status'])
942 header('Expires: Fri, 26 Nov 1976 05:00:00 GMT');
943 header('Cache-Control: no-cache, must-revalidate');
944 header("Pragma: no-cache");
945 header('Content-type: application/json; charset=utf-8');
946 echo \Zend\Json\Json::encode(true);
951 catch (\Exception $e)
953 #-> Oops, something went wrong.
954 $this->response['Status'] = 'Exception';
955 $this->response['StatusReason'] = 'Invalid Workflow requested.';
956 $this->response['Exception'] = "$e";
958 return new \Zend\View\Model\JsonModel($this->response);
961 protected function createEntry($entityName, $data)
963 $item = new $entityName();
964 $item->fromArray($data);
965 $this->em->persist($item);
970 protected function updateEntry($entityName, $id, $data)
973 ->getRepository($entityName)
979 public function contactRequestAction()
982 $this->request = isset($this->request[0])
987 'personName' => $this->request['name'],
988 'tradingName' => $this->request['company'],
989 'email' => $this->request['email'],
990 'mobile' => $this->request['mobile'],
991 'telephone' => $this->request['telephone'],
992 'subject' => $this->request['subject'],
993 'message' => $this->request['message']
996 $oNotify = new \Utility\Comms\Notification();
997 $oNotify->sendFromTemplate(
998 null, null, null, null,
999 'info@bid4cars.co.za',
1000 null, null, 'contact-rquest', $params
1002 $oNotify->sendFromTemplate(
1003 null, null, null, null,
1004 'mohau@bid4cars.co.za',
1005 null, null, 'contact-rquest', $params
1007 $oNotify->sendFromTemplate(
1008 null, null, null, null,
1009 'dineo@bid4cars.co.za',
1010 null, null, 'contact-rquest', $params
1012 $oNotify->sendFromTemplate(
1013 null, null, null, null,
1014 'cearahw@hyundai.co.za',
1015 null, null, 'contact-rquest', $params
1018 return new \Zend\View\Model\JsonModel(array('Status' => 'Success'));
1021 public function contactRequestCcAction()
1024 $this->request = isset($this->request[0])
1029 'personName' => $this->request['name'],
1030 'tradingName' => $this->request['company'],
1031 'email' => $this->request['email'],
1032 'mobile' => $this->request['mobile'],
1033 'telephone' => $this->request['telephone'],
1034 'subject' => $this->request['subject'],
1035 'message' => $this->request['message']
1038 $oNotify = new \Utility\Comms\Notification();
1039 // $oNotify->sendFromTemplate(
1040 // null, null, null, null,
1041 // 'info@bid4cars.co.za',
1042 // null, null, 'contact-rquest', $params
1045 if('1'==$this->request['company'] ){
1046 $oNotify->sendFromTemplate(
1047 null, null, null, null,
1048 'thinus@wepay4cars.co.za',
1049 null, null, 'contact-rquest', $params
1052 if('2'==$this->request['company'] ){
1053 $oNotify->sendFromTemplate(
1054 null, null, null, null,
1055 'bronson@wepay4cars.co.za',
1056 null, null, 'contact-rquest', $params
1060 return new \Zend\View\Model\JsonModel(array('Status' => 'Success'));
1063 public function importTuCsvAction()
1066 \Utility\Registry::setServiceManager($this->serviceLocator);
1067 $this->em = \Utility\Registry::getEntityManager();
1068 $categoryMap = array(
1079 for ($y = 1970; $y < 2014; $y++)
1088 #-> Load in csv data, BOORAH!!!!
1089 $csvToFieldMap = array(
1090 'mmCode', 'make', 'model', 'type', 'category',
1091 'cylinders', 'cubicCapacity', 'kilowatts',
1092 'bodyType', 'doors', 'intro_date', 'disc_date'
1094 $numericFields = array('cylinders', 'cubicCapacity', 'kilowatts', 'doors');
1095 $handle = fopen(__DIR__ . '/../../../../../data/Transunion20130624.csv', "r");
1096 $data = fgetcsv($handle);
1099 #-> Handle csv data.
1100 while (($data = fgetcsv($handle)) !== false)
1103 foreach ($csvToFieldMap as $index => $field)
1105 $packet[$field] = $data[$index];
1106 if (in_array($field, $numericFields))
1108 $packet[$field] = ('' == $packet[$field])
1113 $packet['name'] = $packet['type'];
1114 list($imonth, $iyear) = explode('/', $packet['intro_date']);
1120 !empty($packet['disc_date'])
1121 && list($dmonth, $dyear) = explode('/', $packet['disc_date']);
1122 unset($packet['intro_date']);
1123 unset($packet['disc_date']);
1124 $packet['introYear'] = $this->em->getReference(
1125 '\Stock\Entity\Year', $years[$iyear]
1127 $packet['introMonth'] = $imonth;
1130 $packet['discYear'] = $this->em->getReference(
1131 '\Stock\Entity\Year', $years[$dyear]
1133 $packet['discMonth'] = $dmonth;
1136 if (!isset($makes[$packet['make']]))
1138 $makeId = $this->createEntry('\Stock\Entity\Make', array(
1139 'name' => $packet['make']
1141 $makes[$packet['make']] = $makeId;
1145 $makeId = $makes[$packet['make']];
1148 if (!isset($models[$makeId]) || !isset($models[$makeId][$packet['model']]))
1150 isset($models[$makeId])
1151 || $models[$makeId] = array();
1152 $modelId = $this->createEntry('\Stock\Entity\Model', array(
1153 'make' => $this->em->getReference('\Stock\Entity\Make', $makeId),
1154 'name' => $packet['model']
1156 $models[$makeId][$packet['model']] = $modelId;
1160 $modelId = $models[$makeId][$packet['model']];
1162 $packet['category'] = $this->em->getReference(
1163 '\Stock\Entity\Category', $categoryMap[$packet['category']]
1165 $packet['model'] = $this->em->getReference('\Stock\Entity\Model', $modelId);
1166 $this->createEntry('\Stock\Entity\Type', $packet);
1171 public function completeValuationGetCustomerAction()
1175 $this->request = json_decode(file_get_contents('php://input'), true);
1176 if (is_null($this->request))
1182 if('' != $this->request['customerHash'])
1184 \Utility\Registry::setServiceManager($this->serviceLocator);
1185 $this->em = \Utility\Registry::getEntityManager();
1187 $customerPublicValuationEntry = $this->em->getRepository('\\Valuation\\Entity\\CustomerPublicValuation')
1189 'customerHash' => $this->request['customerHash'],
1193 if(!is_null($customerPublicValuationEntry))
1195 return new \Zend\View\Model\JsonModel(array('Success' => array('valuationId' => $customerPublicValuationEntry->valuation->id)));
1202 return new \Zend\View\Model\JsonModel(array('Error' => "Could not find customer hash"));
1205 public function populateCompleteValuationAppointmentTableAction()
1209 $this->request = json_decode(file_get_contents('php://input'), true);
1210 if (is_null($this->request))
1216 \Utility\Registry::setServiceManager($this->serviceLocator);
1217 $this->em = \Utility\Registry::getEntityManager();
1219 $currentPositionDate = \Utility\FileStore::fetchJson('currentPositionDate');
1221 \Utility\Debug::errorLog('$this->request', $this->request);
1223 if('' != $this->request['currentPosition'])
1225 switch ($this->request['currentPosition']) {
1230 $date = date('Y-m-d');
1232 \Utility\FileStore::storeJson('currentPositionDate', $date);
1236 $date = date('Y-m-d', strtotime("previous monday"));
1238 \Utility\FileStore::storeJson('currentPositionDate', $date);
1244 $date = date('Y-m-d', strtotime( $currentPositionDate . "next monday"));
1246 \Utility\FileStore::storeJson('currentPositionDate', $date);
1251 $date = date('Y-m-d', strtotime( $currentPositionDate . "last monday"));
1253 \Utility\FileStore::storeJson('currentPositionDate', $date);
1259 $currentPositionDate = \Utility\FileStore::fetchJson('currentPositionDate');
1261 $appointmentTimeSlotsEntry = $this->em->getRepository('\\Valuation\\Entity\\ValuationTimeSlots')
1267 $appointmentTimeSlotsCount = count($appointmentTimeSlotsEntry);
1269 $valuationEntry = $this->em->getRepository('\\Valuation\\Entity\\Valuation')
1271 'id' => $this->request['valuationId'],
1275 $outputTableBody = 'foc';
1277 if(!is_null($valuationEntry))
1279 $profileEntry = $this->em->getRepository('\\User\\Entity\\Profile')
1281 'company' => $valuationEntry->stock->company->id,
1282 'permissions' => '7',
1286 if(!is_null($profileEntry))
1288 $profileCounter = 1;
1290 foreach($profileEntry as $profile)
1292 $outputTableBody .= '<tr class="handy">';
1294 \Utility\Debug::errorLog('$profile', $profile->id);
1296 if(null != $valuationEntry->valuatedBy)
1298 if(1 == $profileCounter)
1300 $profileCounter = 2;
1303 if($valuationEntry->valuatedBy == $profile->id)
1305 $outputTableBody .= '<td class="valuator no-hover">Valuator 1</td>';
1311 $outputTableBody .= '<td class="valuator no-hover">Valuator ' . $profileCounter . '</td>';
1318 * check appointemtns for monday
1321 $currentDate=date('Ymd');
1324 for($i = 1; $i <= 5; $i++)
1327 $setDate = date('d-m-Y', strtotime( $currentPositionDate . "+$dateCounter days"));
1328 $setDateCheck = date('Ymd', strtotime( $currentPositionDate . "+$dateCounter days"));
1330 $appointmentEntry = $this->em->getRepository('\\Valuation\\Entity\\ValuationAppointments')
1332 'valuator' => $profile->id,
1333 'appointmentDate' => new \DateTime($setDate),
1337 if($currentDate > $setDateCheck)
1339 if(!empty($appointmentEntry))
1342 $appointmentCount = count($appointmentEntry);
1344 $percentageOfAppointments = ($appointmentCount / 100) * $appointmentTimeSlotsCount;
1346 if($percentageOfAppointments <= '100' && $percentageOfAppointments >= '90')
1348 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Full" class="no-hover" style="background: #953b39;color:#ffffff;">Full</td>';
1350 else if($percentageOfAppointments <= '90' && $percentageOfAppointments >= '30')
1352 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Almost Full" class="no-hover" style="background: #953b39;color:#ffffff;">Almost Full</td>';
1356 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Available" class="no-hover" style="background: #953b39;color:#ffffff;">Available</td>';
1361 //its empty so avaliable
1362 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Available" class="no-hover" style="background: #953b39;color:#ffffff;">Available</td>';
1367 if(!is_null($appointmentEntry))
1369 $appointmentCount = count($appointmentEntry);
1371 $percentageOfAppointments = ($appointmentCount / $appointmentTimeSlotsCount) * 100;
1373 if($percentageOfAppointments <= '100' && $percentageOfAppointments >= '90')
1375 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Full" onClick="_w.customercompletevaluation.goToNext(' . $profile->id . ', ' . $dateCounter . ' , '. $profileCounter . ')">Full</td>';
1377 else if($percentageOfAppointments <= '90' && $percentageOfAppointments >= '60')
1379 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Almost Full" onClick="_w.customercompletevaluation.goToNext(' . $profile->id . ', ' . $dateCounter . ' , ' . $profileCounter . ')">Almost Full</td>';
1383 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Available" onClick="_w.customercompletevaluation.goToNext(' . $profile->id . ', ' . $dateCounter . ' , ' . $profileCounter . ')">Available</td>';
1388 //its empty so avaliable
1389 $outputTableBody .= '<td class="' . $profile->id . '_' . $dateCounter . ' " data-content="Available" onClick="_w.customercompletevaluation.goToNext(' . $profile->id . ', ' . $dateCounter . ' , ' . $profileCounter . ')">Available</td>';
1398 $outputTableBody .= '</tr>';
1406 $outputTableHeader = '<th class="">
1407 <div class="table-heading-wrapper">
1412 <div class="table-heading-wrapper" id="date_monday">
1413 ' . $currentPositionDate . '
1417 <div class="table-heading-wrapper" id="date_tuesday">
1418 ' . date('Y-m-d', strtotime( $currentPositionDate . "+1 days")) . '
1422 <div class="table-heading-wrapper" id="date_wednesday">
1423 ' . date('Y-m-d', strtotime( $currentPositionDate . "+2 days")) . '
1427 <div class="table-heading-wrapper" id="date_thursday">
1428 ' . date('Y-m-d', strtotime( $currentPositionDate . "+3 days")) . '
1432 <div class="table-heading-wrapper" id="date_friday">
1433 ' . date('Y-m-d', strtotime( $currentPositionDate . "+4 days")) . '
1439 return new \Zend\View\Model\JsonModel(array('outputTableHeader' => $outputTableHeader,'outputTableBody' => $outputTableBody));
1443 public function populateCompleteValuationAppointmentTimeTableAction()
1447 $this->request = json_decode(file_get_contents('php://input'), true);
1449 if (is_null($this->request)) {
1454 \Utility\Registry::setServiceManager($this->serviceLocator);
1455 $this->em = \Utility\Registry::getEntityManager();
1457 $currentPositionDate = \Utility\FileStore::fetchJson('currentPositionDate');
1459 $dateSentThrough = $this->request['dateNo'];
1461 $setSelected = date('Y-m-d', strtotime( $currentPositionDate . "+$dateSentThrough days"));
1463 $appointmentTimeSlotsEntry = $this->em->getRepository('\\Valuation\\Entity\\ValuationTimeSlots')
1468 $outputTableHeader = '<th class="">
1469 <div class="table-heading-wrapper">
1470 Valuator ' . $this->request['valuatorNo'] . '
1474 <div class="table-heading-wrapper">
1475 ' . $setSelected . '
1479 $outputTableHeader .= '<th class="">
1492 $outputTableBody = '';
1494 $currentTime=date('H:i:s', time());
1495 $currentDate=date('Y-m-d');
1497 if(!is_null($appointmentTimeSlotsEntry))
1499 $outputTableBody .= '<tr class="handy">';
1501 foreach($appointmentTimeSlotsEntry as $appointmentTimeSlot)
1503 // \Utility\Debug::errorLog('$appointmentTimeSlots', $appointmentTimeSlot->id);
1505 $currentTimeMatchArray = explode(' - ',$appointmentTimeSlot->timeSlot);
1507 if($currentTime > $currentTimeMatchArray[1] && $setSelected == $currentDate)
1509 $valuationAppointmentsEntry = $this->em->getRepository('\\Valuation\\Entity\\ValuationAppointments')
1511 'valuator' => $this->em->getReference('\\User\Entity\Profile', $this->request['profileId']),
1512 'timeSlot' => $this->em->getReference('\\Valuation\Entity\ValuationTimeSlots', $appointmentTimeSlot->id),
1513 'appointmentDate' => new \DateTime($setSelected),
1517 if(is_null($valuationAppointmentsEntry) && empty($valuationAppointmentsEntry))
1519 $outputTableBody .= "<td data-content='$appointmentTimeSlot->timeSlot' class='no-hover' style='background: #953b39;color:#ffffff; '> " . $appointmentTimeSlot->timeSlotDisplayName . ' </td>';
1523 $outputTableBody .= "<td data-content='$appointmentTimeSlot->timeSlot' class='no-hover' style='background: #953b39;color:#ffffff; '> " . $appointmentTimeSlot->timeSlotDisplayName . ' </td>';
1528 $valuationAppointmentsEntry = $this->em->getRepository('\\Valuation\\Entity\\ValuationAppointments')
1530 'valuator' => $this->em->getReference('\\User\Entity\Profile', $this->request['profileId']),
1531 'timeSlot' => $this->em->getReference('\\Valuation\Entity\ValuationTimeSlots', $appointmentTimeSlot->id),
1532 'appointmentDate' => new \DateTime($setSelected),
1536 if(is_null($valuationAppointmentsEntry) && empty($valuationAppointmentsEntry))
1538 $outputTableBody .= "<td data-content='$appointmentTimeSlot->timeSlot' onClick='_w.customercompletevaluation.goToFinish(" . '"' . "$appointmentTimeSlot->id" . '"' . "," . '"' . "$appointmentTimeSlot->timeSlotDisplayName" . '"' . " )'> " . $appointmentTimeSlot->timeSlotDisplayName . ' </td>';
1542 $outputTableBody .= "<td data-content='$appointmentTimeSlot->timeSlot' class='no-hover' style='background: #dddddd '> " . $appointmentTimeSlot->timeSlotDisplayName . ' </td>';
1548 $outputTableBody .= '</tr>';
1553 return new \Zend\View\Model\JsonModel(array('dateSelected' => $setSelected, 'outputTableHeader' => $outputTableHeader,'outputTableBody' => $outputTableBody));
1560 * get the calendar events to display for user.
1562 public function getCalendarEventsAction()
1567 $this->request = json_decode(file_get_contents('php://input'), true);
1568 if (is_null($this->request)) {
1573 \Utility\Registry::setServiceManager($this->serviceLocator);
1574 $this->em = \Utility\Registry::getEntityManager();
1576 $profileId = $this->request['userId'];
1578 $limitMonth = new \DateTime('NOW');
1579 $limitMonth->modify( '-1 month' );
1581 $appointmentsEntry = $this->em->createQuery(
1582 "SELECT calendar.id,
1583 calendar.appointmentDate,
1584 calendar.appointmentCompleted,
1585 calendar.appointmentCancelled,
1587 valuation.id as valuationId,
1588 valuation.firstName,
1589 valuation.familyName,
1590 stock.registrationNumber
1592 . "FROM \\Valuation\\Entity\\ValuationAppointments calendar "
1593 . "LEFT JOIN calendar.timeSlot timeSlot "
1594 . "LEFT JOIN calendar.valuator valuator "
1595 . "LEFT JOIN calendar.valuation valuation "
1596 . "LEFT JOIN valuation.stock stock "
1597 . "WHERE calendar.archived = :archived "
1598 . "AND valuation.archived = :archived "
1599 . "AND calendar.appointmentDate > :oneMonth "
1600 . "AND valuator.id = :valuatorId "
1601 . "GROUP BY calendar.id"
1603 ->setParameter('archived', false)
1604 ->setParameter('valuatorId', $profileId)
1605 ->setParameter('oneMonth', $limitMonth)
1608 $returnData = array();
1610 if(!empty($appointmentsEntry))
1612 foreach ($appointmentsEntry as $appointments)
1615 $bookingDate = $appointments['appointmentDate'];
1616 $bookingDate = $bookingDate->format('Y-m-d');
1617 $bookingTimeSlot = $appointments['timeSlot'];
1619 $bookingTimeSlotArray = explode(' - ',$bookingTimeSlot);
1621 $startDate = date($bookingDate . ' ' . $bookingTimeSlotArray[0] . ':00');
1622 $endDate = date($bookingDate . ' ' . $bookingTimeSlotArray[1] . ':00');
1625 array_push($returnData, array(
1626 'title' => $appointments['firstName'] . ' ' . $appointments['familyName'] . ', ' . $appointments['registrationNumber'],
1627 'start' => $startDate,
1629 'appointmentId' => $appointments['id'],
1630 'appointmentCompleted' => $appointments['appointmentCompleted'],
1631 'appointmentCancelled' => $appointments['appointmentCancelled'],
1639 return new \Zend\View\Model\JsonModel(array($returnData));