Git Repository Public Repository

namibia

URLs

Copy to Clipboard
 
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<?php
namespace Company\Service;



use PriceGuide;
/**
 * Manage Company data.
 * @author andre.fourie
 */
class Company extends \Company\DataBin\Company
{


	/**
	 * ExecuteAfter: Update.
	 * Send welcome notification with new pin for user just registered/created on system.
	 * @param array $meta
	 * @param object|null $jobRecord
	 * @param object|null $record
	 * @param \Workspace\Utility\ServiceInputParams $contract
	 * @return array
	 */
	public function updateAuthSession($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
	{
		#-> Do we need to update session data?
		$auth = \Utility\Registry::getAuthData();
		if ($auth['company']['id'] == $record->id)
		{
			$companyData = $record->toArray(array(
						'city', 'region', 'contact'
			));
			\Utility\Registry::setAuthParam('company', $companyData);
		}
	}

	public function linkPublicCentreClubs($companyId)
	{
		set_time_limit(0);
		ini_set('memory_limit','1024M');

		$record = $this->em->find('Company\\Entity\\Company', $companyId);
		$dealershipName = $record->name;
		$companyId = $record->id;
		$isPublicCentre = $record->publicCentre;
		$today = new \DateTime ();
		$em = \Utility\Registry::getEntityManager ();

		$dealershipName = $dealershipName . ' Traders Club';

		//\Utility\Debug::errorLog ( 'New dealer updated $dealershipName', $dealershipName );
		//\Utility\Debug::errorLog ( 'New dealer updated company id', $companyId );
		//\Utility\Debug::errorLog ( 'New dealer updated is publicCentre', $isPublicCentre );

		// create an new price guide club (dealership name Traders Club)
		// Do a check for club
		$club = $em->getRepository ( '\PriceGuide\Entity\Club' )->findOneBy ( array (
				'name' => $dealershipName
		) );
		// > Create entry.

		// Create if nothing is found
		if (is_null ( $club ))
		{
			//\Utility\Debug::errorLog ( 'New dealer wasnt found', $dealershipName );

			$publicClub = new \PriceGuide\Entity\Club ();
			$publicClubData = array (
					'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companyId ),
					'name' => $dealershipName,
					'status' => 'Active',
					'created' => $today
			)
			;

			$publicClub->fromArray ( $publicClubData );
			$em->persist ( $publicClub );
			$em->flush ();

			// Get id back
			$publicClubId = $publicClub->id;

			//\Utility\Debug::errorLog ( 'New dealer created club id', $publicClubId );
		}
		else
		{
			//\Utility\Debug::errorLog ( 'New dealer updated is $club', $club->id );
			$publicClubId = $club->id;
		}

		// Select from company where where dealer_type = "Trader"
		$traderSearch = "Trader";
		$result = $this->em->createQuery ( 'SELECT company ' . 'FROM \Company\Entity\Company company ' . 'WHERE company.dealerType = :trader ' )
			->setParameter ( 'trader', $traderSearch )->getArrayResult ();

		//\Utility\Debug::errorLog ( 'add this club', $publicClubId );

		foreach ( $result as $companys )
		{

			//\Utility\Debug::errorLog ( 'all the $companys', $companys );

			// get all the profiles $override
			$overridePgSearch = '1';
			$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 ' )

			->setParameter ( 'companyID', $companys ['id'] )->setParameter ( 'overridePG', $overridePgSearch )->

			getArrayResult ();

			foreach ( $profileResult as $clubProfiles ) {

				//\Utility\Debug::errorLog ( 'all the profiles found', $clubProfiles );

				$existingClubMember = $em->getRepository ( '\PriceGuide\Entity\Member' )->findOneBy ( array (
						'club' => $em->getRepository ( '\PriceGuide\Entity\Club' )->find ( $publicClubId ),
						'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companys ['id'] ),
						'profile' => $em->getRepository ( '\User\Entity\Profile' )->find ( $clubProfiles ['id'] )
				)
				 );
				// Set all listed traders as active members with email notifications on and sms off
				if (is_null ( $existingClubMember )) {
					// add new member
					//\Utility\Debug::errorLog ( 'add this trader', $companys );

					$publicClubMember = new \PriceGuide\Entity\Member ();
					$publicClubMemberData = array (
							'club' => $em->getRepository ( '\PriceGuide\Entity\Club' )->find ( $publicClubId ),
							'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companys ['id'] ),

							'profile' => $em->getRepository ( '\User\Entity\Profile' )->find ( $clubProfiles ['id'] ),

							'allMakes' => '1',
							'emailNotification' => '1',
							'smsNotification' => '0',
							'status' => 'Active',
							'created' => $today
					)
					;

					$publicClubMember->fromArray ( $publicClubMemberData );
					$em->persist ( $publicClubMember );
					$em->flush ();
				}
			} // ProfileClub
		} // For each company found

	}

	/**
	 * ExecuteAfter: Update.
	 * Link all the trade center clubs for this dealer that is a public centre.
	 * @param array $meta
	 * @param object|null $jobRecord
	 * @param object|null $record
	 * @param \Workspace\Utility\ServiceInputParams $contract
	 * @return array
	 */
	public function PublicCentreClubs($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
	{
		if ($record->publicCentre == 'True' || $record->publicCentre == '1')
		{
			exec("php /var/www/B4C2/public/index.php publicclubs process "
				. $record->id
				. " >>/log/php.log &");
		}// if is public centre
	}

	public function directRouteMoveToPending($jobRecord)
	{
		$profile = $this->em->getRepository('\User\Entity\Profile')
			->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC'));
		$oNotify = new \Utility\Comms\Notification();
		$oNotify->sendFromTemplate(
				null, null,
				$jobRecord->id, $profile->id,
				$profile->email, null,
				null,
				'registration-pending',
				array(
					'firstName'     => $profile->firstName,
					'familyName'    => $profile->familyName,
					'status_reason' => $jobRecord->statusReason
				)
		);
	}

	public function directRouteMoveToActive($jobRecord)
	{
		$profile = $this->em->getRepository('\User\Entity\Profile')
			->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC'));
		$oNotify = new \Utility\Comms\Notification();
		$oNotify->sendFromTemplate(
				null, null,
				$jobRecord->id, $profile->id,
				$profile->email, null,
				null,
				'registration-success',
				array(
					'firstName'  => $profile->firstName,
					'familyName' => $profile->familyName,
					'email'      => $profile->email
				)
		);
	}

	public function directRouteMoveToDeclined($jobRecord)
	{
		$profile = $this->em->getRepository('\User\Entity\Profile')
			->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC'));
		$oNotify = new \Utility\Comms\Notification();
		$oNotify->sendFromTemplate(
				null, null,
				$jobRecord->id, $profile->id,
				$profile->email, null,
				null,
				'registration-declined',
				array(
					'firstName'     => $profile->firstName,
					'familyName'    => $profile->familyName,
					'status_reason' => $jobRecord->statusReason
				)
		);
	}

	/**
	 * List of companies that can be invited.
	 * @param object|null $jobRecord
	 * @param array $input
	 * @return \Workspace\Contract\UseOnce
	 */
	public function contractInviteSelectList($jobRecord, array $input = array())
	{
		$options = new \Workspace\UseCase\Options();
		$requirement = new \Workspace\UseCase\Requirement();
		$requirement->addRequiredInput(array(
				'Filter' => array(
						'club' 	=> 'Id'
				)
		));
		return new \Workspace\Contract\Recurring($options, $requirement);
	}

	/**
	 * Reset pin for user.
	 * @param object|null $jobRecord
	 * @param \Workspace\Utility\ServiceInputParams $contract
	 * @return array
	 */
	public function executeInviteSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
	{
		$em = \Utility\Registry::getEntityManager();
		$authData = \Utility\Registry::getAuthData();
		$companyId = $authData['company']['id'];
		$clubId = $contract->data->Filter['club'];
		$memberslistdrop = $em->createQuery('
 				SELECT c.id, c.name AS companyName
				FROM \Company\Entity\Company c
		 		WHERE c.id NOT IN (
					SELECT IDENTITY(m.company)
					FROM PriceGuide\Entity\Member m
					WHERE IDENTITY(m.club) = :clubId
				)
				AND c.priceGuide = :activeid
				AND c.id != :company
				ORDER BY c.name'
		);
		$memberslistdrop->setParameter('clubId', $clubId);
		$memberslistdrop->setParameter('activeid', '1');
		$memberslistdrop->setParameter('company', $companyId);
		$memberslistu = $memberslistdrop->getArrayResult();
		$datax = array();
		foreach ( $memberslistu as $data ) {


			$datax[] = array(
				'value' => $data['id'],
				'label' => $data['companyName']
				);
		}
		return $contract->success('List Retrieved.', $datax);
	}



	/**
	 * Contract to remove a document from a company.
	 * @param object|null $jobRecord
	 * @param array $input
	 * @return \Workspace\Contract\UseOnce
	 */
	public function contractRemoveDocument($jobRecord, array $input = array())
	{
		$options = new \Workspace\UseCase\Options();
		$requirement = new \Workspace\UseCase\Requirement();
		$requirement->addOptionalInput(array(
				'Company' => array(
						'docStockCertificate' 		=> 'Boolean',
						'docAddressProof' 			=> 'Boolean',
						'docCopyOfId' 				=> 'Boolean',
						'docCopyOfDirectorId' 		=> 'Boolean',
						'docCompanyRegistration' 	=> 'Boolean'
				)
		));
		return new \Workspace\Contract\Recurring($options, $requirement);
	}

	/**
	 * Remove a document from a company.
	 * @param object|null $jobRecord
	 * @param \Workspace\Utility\ServiceInputParams $contract
	 * @return array
	 */
	public function executeRemoveDocument($jobRecord, \Workspace\Utility\ServiceInputParams $contract)
	{
		$fields = array(
				'docStockCertificate',
				'docAddressProof',
				'docCopyOfId',
				'docCopyOfDirectorId',
				'docCompanyRegistration'
		);
		$folder = \Utility\Registry::getConfigParam('DocumentPath');
		foreach ($fields as $field)
		{
			if (isset($contract->data->Company[$field])
				&& $contract->data->Company[$field])
			{
				if (file_exists($folder . '/' . $jobRecord->$field->filename))
				{
					unlink($folder . '/' . $jobRecord->$field->filename);
				}
				$this->em->remove($jobRecord->$field);
				$jobRecord->$field = null;
			}
		}
		$this->em->flush();
		return $contract->success('Document removed.', array());
	}

	/**
	 * List of companies that can be invited.
	 * @param object|null $jobRecord
	 * @param array $input
	 * @return \Workspace\Contract\UseOnce
	 */
	public function checkDocuments()
	{


		$result = $this->em->createQuery(
				'SELECT company, docStockCertificate, docAddressProof, docCopyOfId, docCopyOfDirectorId, docCompanyRegistration  '
				. 'FROM \Company\Entity\Company company '
				. 'LEFT JOIN company.docStockCertificate docStockCertificate '
				. 'LEFT JOIN company.docAddressProof docAddressProof '
				. 'LEFT JOIN company.docCopyOfId docCopyOfId '
				. 'LEFT JOIN company.docCopyOfDirectorId docCopyOfDirectorId '
				. 'LEFT JOIN company.docCompanyRegistration docCompanyRegistration '
				. 'WHERE docStockCertificate != :null '
				. 'OR docAddressProof != :null '
				. 'OR docCopyOfId != :null '
				. 'OR docCopyOfDirectorId != :null '
				. 'OR docCompanyRegistration != :null '

		)
		->setParameter('null', 'null')
		->getArrayResult();


		$folder = \Utility\Registry::getConfigParam('DocumentPath');


		$missingDocs = array();
		$docs = array(
				'docStockCertificate',
				'docAddressProof',
				'docCopyOfId',
				'docCopyOfDirectorId',
				'docCompanyRegistration',
		);

		foreach ($result as $companies)
		{
			$companyId = $companies['id'];
			$missingDocs[$companyId] = array(
					'company' 					=>  $companies['name'] . ' / ' . $companies['businessName'],
					'docStockCertificate' 		=> false,
					'docAddressProof' 			=> false,
					'docCopyOfId' 				=> false,
					'docCopyOfDirectorId' 		=> false,
					'docCompanyRegistration' 	=> false
			);
			$missing = 0;
			foreach ($docs as $doc)
			{
				if (is_array($companies[$doc]) && !is_null($companies[$doc]['id']) )
				{
					if (!file_exists($folder . '/' . $companies[$doc]['filename']))
					{
						$missing++;
						$missingDocs[$companyId][$doc] = $companies[$doc]['filename'];
					}
				}
			}
			if (0 == $missing)
			{
				unset($missingDocs[$companyId]);
			}

		}

		$fp = fopen($folder . '/missingDocsFilelist.csv', 'w');
		fputcsv($fp, array(
				'Company name',
				'Stock Certificate',
				'Document Address Proof',
				'Document Copy Of Id',
				'Document Copy Of DirectorId',
				'Document Company Registration'
		));
		foreach ($missingDocs as $companyId => $fields) {
			fputcsv($fp, $fields);
		}

		fclose($fp);

	}




}

Commits for namibiamodule/Company/src/Company/Service/Company.php

Diff revisions: vs.
Revision Author Commited Message
df0489 ... Mark Fri 14 Oct, 2016 10:01:00 +0000

initial commit