2 namespace Company\Service;
11 class Company extends \Company\DataBin\Company
16 * ExecuteAfter: Update.
17 * Send welcome notification with new pin for user just registered/created on system.
19 * @param object|null $jobRecord
20 * @param object|null $record
21 * @param \Workspace\Utility\ServiceInputParams $contract
24 public function updateAuthSession($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
26 #-> Do we need to update session data?
27 $auth = \Utility\Registry::getAuthData();
28 if ($auth['company']['id'] == $record->id)
30 $companyData = $record->toArray(array(
31 'city', 'region', 'contact'
33 \Utility\Registry::setAuthParam('company', $companyData);
37 public function linkPublicCentreClubs($companyId)
40 ini_set('memory_limit','1024M');
42 $record = $this->em->find('Company\\Entity\\Company', $companyId);
43 $dealershipName = $record->name;
44 $companyId = $record->id;
45 $isPublicCentre = $record->publicCentre;
46 $today = new \DateTime ();
47 $em = \Utility\Registry::getEntityManager ();
49 $dealershipName = $dealershipName . ' Traders Club';
51 //\Utility\Debug::errorLog ( 'New dealer updated $dealershipName', $dealershipName );
52 //\Utility\Debug::errorLog ( 'New dealer updated company id', $companyId );
53 //\Utility\Debug::errorLog ( 'New dealer updated is publicCentre', $isPublicCentre );
55 // create an new price guide club (dealership name Traders Club)
56 // Do a check for club
57 $club = $em->getRepository ( '\PriceGuide\Entity\Club' )->findOneBy ( array (
58 'name' => $dealershipName
62 // Create if nothing is found
63 if (is_null ( $club ))
65 //\Utility\Debug::errorLog ( 'New dealer wasnt found', $dealershipName );
67 $publicClub = new \PriceGuide\Entity\Club ();
68 $publicClubData = array (
69 'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companyId ),
70 'name' => $dealershipName,
76 $publicClub->fromArray ( $publicClubData );
77 $em->persist ( $publicClub );
81 $publicClubId = $publicClub->id;
83 //\Utility\Debug::errorLog ( 'New dealer created club id', $publicClubId );
87 //\Utility\Debug::errorLog ( 'New dealer updated is $club', $club->id );
88 $publicClubId = $club->id;
91 // Select from company where where dealer_type = "Trader"
92 $traderSearch = "Trader";
93 $result = $this->em->createQuery ( 'SELECT company ' . 'FROM \Company\Entity\Company company ' . 'WHERE company.dealerType = :trader ' )
94 ->setParameter ( 'trader', $traderSearch )->getArrayResult ();
96 //\Utility\Debug::errorLog ( 'add this club', $publicClubId );
98 foreach ( $result as $companys )
101 //\Utility\Debug::errorLog ( 'all the $companys', $companys );
103 // get all the profiles $override
104 $overridePgSearch = '1';
105 $profileResult = $this->em->createQuery ( 'SELECT profile, override ' . 'FROM User\Entity\Profile profile ' . 'LEFT JOIN profile.override override ' . 'WHERE IDENTITY(profile.company) = :companyID ' . 'AND override.pgMakeOffer = :overridePG ' )
107 ->setParameter ( 'companyID', $companys ['id'] )->setParameter ( 'overridePG', $overridePgSearch )->
111 foreach ( $profileResult as $clubProfiles ) {
113 //\Utility\Debug::errorLog ( 'all the profiles found', $clubProfiles );
115 $existingClubMember = $em->getRepository ( '\PriceGuide\Entity\Member' )->findOneBy ( array (
116 'club' => $em->getRepository ( '\PriceGuide\Entity\Club' )->find ( $publicClubId ),
117 'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companys ['id'] ),
118 'profile' => $em->getRepository ( '\User\Entity\Profile' )->find ( $clubProfiles ['id'] )
121 // Set all listed traders as active members with email notifications on and sms off
122 if (is_null ( $existingClubMember )) {
124 //\Utility\Debug::errorLog ( 'add this trader', $companys );
126 $publicClubMember = new \PriceGuide\Entity\Member ();
127 $publicClubMemberData = array (
128 'club' => $em->getRepository ( '\PriceGuide\Entity\Club' )->find ( $publicClubId ),
129 'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companys ['id'] ),
131 'profile' => $em->getRepository ( '\User\Entity\Profile' )->find ( $clubProfiles ['id'] ),
134 'emailNotification' => '1',
135 'smsNotification' => '0',
136 'status' => 'Active',
141 $publicClubMember->fromArray ( $publicClubMemberData );
142 $em->persist ( $publicClubMember );
146 } // For each company found
151 * ExecuteAfter: Update.
152 * Link all the trade center clubs for this dealer that is a public centre.
154 * @param object|null $jobRecord
155 * @param object|null $record
156 * @param \Workspace\Utility\ServiceInputParams $contract
159 public function PublicCentreClubs($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
161 if ($record->publicCentre == 'True' || $record->publicCentre == '1')
163 exec("php /var/www/namibia/public/index.php publicclubs process "
165 . " >>/log/php.log &");
166 }// if is public centre
169 public function directRouteMoveToPending($jobRecord)
171 $profile = $this->em->getRepository('\User\Entity\Profile')
172 ->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC'));
173 $oNotify = new \Utility\Comms\Notification();
174 $oNotify->sendFromTemplate(
176 $jobRecord->id, $profile->id,
177 $profile->email, null,
179 'registration-pending',
181 'firstName' => $profile->firstName,
182 'familyName' => $profile->familyName,
183 'status_reason' => $jobRecord->statusReason
188 public function directRouteMoveToActive($jobRecord)
190 $profile = $this->em->getRepository('\User\Entity\Profile')
191 ->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC'));
192 $oNotify = new \Utility\Comms\Notification();
193 $oNotify->sendFromTemplate(
195 $jobRecord->id, $profile->id,
196 $profile->email, null,
198 'registration-success',
200 'firstName' => $profile->firstName,
201 'familyName' => $profile->familyName,
202 'email' => $profile->email
207 public function directRouteMoveToDeclined($jobRecord)
209 $profile = $this->em->getRepository('\User\Entity\Profile')
210 ->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC'));
211 $oNotify = new \Utility\Comms\Notification();
212 $oNotify->sendFromTemplate(
214 $jobRecord->id, $profile->id,
215 $profile->email, null,
217 'registration-declined',
219 'firstName' => $profile->firstName,
220 'familyName' => $profile->familyName,
221 'status_reason' => $jobRecord->statusReason
227 * List of companies that can be invited.
228 * @param object|null $jobRecord
229 * @param array $input
230 * @return \Workspace\Contract\UseOnce
232 public function contractInviteSelectList($jobRecord, array $input = array())
234 $options = new \Workspace\UseCase\Options();
235 $requirement = new \Workspace\UseCase\Requirement();
236 $requirement->addRequiredInput(array(
241 return new \Workspace\Contract\Recurring($options, $requirement);
245 * Reset pin for user.
246 * @param object|null $jobRecord
247 * @param \Workspace\Utility\ServiceInputParams $contract
250 public function executeInviteSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
252 $em = \Utility\Registry::getEntityManager();
253 $authData = \Utility\Registry::getAuthData();
254 $companyId = $authData['company']['id'];
255 $clubId = $contract->data->Filter['club'];
256 $memberslistdrop = $em->createQuery('
257 SELECT c.id, c.name AS companyName
258 FROM \Company\Entity\Company c
260 SELECT IDENTITY(m.company)
261 FROM PriceGuide\Entity\Member m
262 WHERE IDENTITY(m.club) = :clubId
264 AND c.priceGuide = :activeid
268 $memberslistdrop->setParameter('clubId', $clubId);
269 $memberslistdrop->setParameter('activeid', '1');
270 $memberslistdrop->setParameter('company', $companyId);
271 $memberslistu = $memberslistdrop->getArrayResult();
273 foreach ( $memberslistu as $data ) {
277 'value' => $data['id'],
278 'label' => $data['companyName']
281 return $contract->success('List Retrieved.', $datax);
287 * Contract to remove a document from a company.
288 * @param object|null $jobRecord
289 * @param array $input
290 * @return \Workspace\Contract\UseOnce
292 public function contractRemoveDocument($jobRecord, array $input = array())
294 $options = new \Workspace\UseCase\Options();
295 $requirement = new \Workspace\UseCase\Requirement();
296 $requirement->addOptionalInput(array(
298 'docStockCertificate' => 'Boolean',
299 'docAddressProof' => 'Boolean',
300 'docCopyOfId' => 'Boolean',
301 'docCopyOfDirectorId' => 'Boolean',
302 'docCompanyRegistration' => 'Boolean'
305 return new \Workspace\Contract\Recurring($options, $requirement);
309 * Remove a document from a company.
310 * @param object|null $jobRecord
311 * @param \Workspace\Utility\ServiceInputParams $contract
314 public function executeRemoveDocument($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
317 'docStockCertificate',
320 'docCopyOfDirectorId',
321 'docCompanyRegistration'
323 $folder = \Utility\Registry::getConfigParam('DocumentPath');
324 foreach ($fields as $field)
326 if (isset($contract->data->Company[$field])
327 && $contract->data->Company[$field])
329 if (file_exists($folder . '/' . $jobRecord->$field->filename))
331 unlink($folder . '/' . $jobRecord->$field->filename);
333 $this->em->remove($jobRecord->$field);
334 $jobRecord->$field = null;
338 return $contract->success('Document removed.', array());
342 * List of companies that can be invited.
343 * @param object|null $jobRecord
344 * @param array $input
345 * @return \Workspace\Contract\UseOnce
347 public function checkDocuments()
351 $result = $this->em->createQuery(
352 'SELECT company, docStockCertificate, docAddressProof, docCopyOfId, docCopyOfDirectorId, docCompanyRegistration '
353 . 'FROM \Company\Entity\Company company '
354 . 'LEFT JOIN company.docStockCertificate docStockCertificate '
355 . 'LEFT JOIN company.docAddressProof docAddressProof '
356 . 'LEFT JOIN company.docCopyOfId docCopyOfId '
357 . 'LEFT JOIN company.docCopyOfDirectorId docCopyOfDirectorId '
358 . 'LEFT JOIN company.docCompanyRegistration docCompanyRegistration '
359 . 'WHERE docStockCertificate != :null '
360 . 'OR docAddressProof != :null '
361 . 'OR docCopyOfId != :null '
362 . 'OR docCopyOfDirectorId != :null '
363 . 'OR docCompanyRegistration != :null '
366 ->setParameter('null', 'null')
370 $folder = \Utility\Registry::getConfigParam('DocumentPath');
373 $missingDocs = array();
375 'docStockCertificate',
378 'docCopyOfDirectorId',
379 'docCompanyRegistration',
382 foreach ($result as $companies)
384 $companyId = $companies['id'];
385 $missingDocs[$companyId] = array(
386 'company' => $companies['name'] . ' / ' . $companies['businessName'],
387 'docStockCertificate' => false,
388 'docAddressProof' => false,
389 'docCopyOfId' => false,
390 'docCopyOfDirectorId' => false,
391 'docCompanyRegistration' => false
394 foreach ($docs as $doc)
396 if (is_array($companies[$doc]) && !is_null($companies[$doc]['id']) )
398 if (!file_exists($folder . '/' . $companies[$doc]['filename']))
401 $missingDocs[$companyId][$doc] = $companies[$doc]['filename'];
407 unset($missingDocs[$companyId]);
412 $fp = fopen($folder . '/missingDocsFilelist.csv', 'w');
416 'Document Address Proof',
417 'Document Copy Of Id',
418 'Document Copy Of DirectorId',
419 'Document Company Registration'
421 foreach ($missingDocs as $companyId => $fields) {
422 fputcsv($fp, $fields);