initial commit
[namibia] / module / Company / src / Company / DataBin / Company.php
1 <?php
2 namespace Company\DataBin;
3
4
5
6 /**
7  * Manage Company data.
8  * @author andre.fourie
9  */
10 class Company extends \Workspace\Service\DataBin
11 {
12
13         /**
14          * @var array
15          */
16         protected $meta = array(
17                         'Base'        => 'Company',
18                         'DatasetName' => 'models',
19                         'Entity'      => '\Company\Entity\Company',
20                         'References'  => array(
21                                         'region'                 => '\Location\Entity\Region',
22                                         'city'                   => '\Location\Entity\Town',
23                                         'billingCity'            => '\Location\Entity\Town',
24                                         'auctionCity'            => '\Location\Entity\Town',
25                                         'tradeCenter'            => '\Company\Entity\Company',
26                                         'group'                  => '\Company\Entity\Group',
27                                         'groupDivision'          => '\Company\Entity\GroupDivision',
28                                         'regionalManager'        => '\Config\Entity\RegionalManager',
29                                         'contact'                => '\Person\Entity\Contact',
30                                         'billingContact'         => '\Person\Entity\Contact',
31                                         'foundMethod'            => '\Company\Entity\FoundMethod',
32                                         'foundMethodDetail'      => '\Company\Entity\FoundMethodDetail',
33                                         'dealershipPhoto'        => '\Utility\Entity\Image',
34                                         'docStockCertificate'    => '\Utility\Entity\Document',
35                                         'docAddressProof'        => '\Utility\Entity\Document',
36                                         'docCopyOfId'            => '\Utility\Entity\Document',
37                                         'docCopyOfDirectorId'    => '\Utility\Entity\Document',
38                                         'docCompanyRegistration' => '\Utility\Entity\Document'
39                         ),
40                         'Dependants'  => array()
41         );
42         /**
43          * @var array
44         */
45         protected $metaSelectList = array(
46                         'Type'          => 'SelectList',
47                         'Contract'      => 'Recurring',
48                         'RequiredInput' => array(),
49                         'OptionalInput' => array(
50                                         'Filter' => array(
51                                                         'company'       => 'Id',
52                             'id'       => 'Id',
53                                                         'name'          => 'String50',
54                                                         'group'         => 'Id',
55                                                         'groupDivision' => 'Id',
56                                                         'region'                => 'Id',
57                                                         'publicCentre'  => 'Boolean',
58                                                         'regionalManager' => 'Array'
59                                         )
60                         ),
61                         'Filter'   => array(),
62                         'Label'    => array(
63                                 'Format' => '[name]',
64                                 'Fields' => array('name')
65                         )
66         );
67         /**
68          * @var array
69         */
70         /* protected $metaInviteSelectList = array(
71                         'Type'          => 'SelectList',
72                         'Contract'      => 'Recurring',
73                         'RequiredInput' => array(),
74                         'OptionalInput' => array(
75                                         'Filter' => array(
76                                                         'company'       => 'Id',
77                                                         'name'          => 'String50',
78                                                         'group'         => 'Id',
79                                                         'groupDivision' => 'Id'
80                                         )
81                         ),
82                         'Filter'   => array(
83                                 'priceGuide' => true
84                         ),
85                         'Label'    => array(
86                                 'Format' => '[name]',
87                                 'Fields' => array('name')
88                         )
89         ); */
90         /**
91          * @var array
92         */
93         protected $metaTradeCenterSelectList = array(
94                         'Type'          => 'SelectList',
95                         'Contract'      => 'Recurring',
96                         'RequiredInput' => array(),
97                         'OptionalInput' => array(
98                                         'Filter' => array(
99                                                         'company'       => 'Id',
100                                                         'name'          => 'String50',
101                                                         'group'         => 'Id',
102                                                         'groupDivision' => 'Id'
103                                         )
104                         ),
105                         'Filter'   => array(
106                                         'dealerType' => \Company\Entity\Company::DEALERTYPE_TRADE_CENTER
107                         ),
108                         'Label'    => array(
109                                 'Format' => '[name]',
110                                 'Fields' => array('name')
111                         )
112         );
113         /**
114          * @var array
115         */
116         protected $metaTcDealerSelectList = array(
117                         'Type'          => 'SelectList',
118                         'Contract'      => 'Recurring',
119                         'RequiredInput' => array(),
120                         'OptionalInput' => array(
121                                         'Filter' => array(
122                                                         'tradeCenter'   => 'Id'
123                                         )
124                         ),
125                         'Filter'   => array(),
126                         'Label'    => array(
127                                 'Format' => '[name]',
128                                 'Fields' => array('name')
129                         )
130         );
131
132     /**
133      * @var array
134      */
135     protected $metaStockAuctionReportSelectList = array(
136         'Type'          => 'SelectList',
137         'Contract'      => 'Recurring',
138         'RequiredInput' => array(),
139         'OptionalInput' => array(
140             'Filter' => array(
141                 'tradeCenter'   => 'Id'
142             )
143         ),
144         'Filter'   => array(),
145         'Label'    => array(
146             'Format' => '[name]',
147             'Fields' => array('name')
148         )
149     );
150         /**
151          * @var array
152         */
153         protected $metaSelectGrid = array(
154                         'Type'          => 'Grid',
155                         'Contract'      => 'Recurring',
156                         'Options'       => array(),
157                         'RequiredInput' => array(),
158                         'OptionalInput' => array(
159                                         'Grid' => array(
160                                                         'NumberOfRecords' => 'Integer',
161                                                         'Page'            => 'Integer',
162                                                         'Filter'          => 'Array',
163                                                         'OrderBy'         => 'Array',
164                                         )
165                         ),
166                         'Base'            => 'company',
167                         'NumberOfRecords' => 1000,
168                         'Query'           => 'SELECT [SELECTION]
169                                                                 FROM \Company\Entity\Company company
170                                                                 JOIN company.city city
171                                                                 JOIN city.region region
172                                                                 [WHERE] [ORDER]',
173                         'Selection'       => 'company, city, region',
174                         'Filter'          => array(
175                                                                         'company.archived' => false,
176                                                                         'company.publicCentre' => true
177                                                                 ),
178                         'OrderBy'         => array('company.name' => 'ASC'),
179                         'Fields'          => array(
180                                                                         'id',
181                                                                         'name',
182                                                                         'city' => array(
183                                                                                 'name',
184                                                                                 'region' => array(
185                                                                                         'id',
186                                                                                         'name'
187                                                                                 )
188                                                                         )
189                                                                 )
190         );
191         /**
192          * @var array
193         */
194         protected $metaGrid = array(
195                         'Type'          => 'Grid',
196                         'Contract'      => 'Recurring',
197                         'Export'        => true,
198                         'Builder'       => '\Company\Report\CompanyGrid',
199                         'Writer'        => '\Utility\Export\ExcelReport',
200                         'Output'        => 'Download',
201                         'Options'       => array(
202                                         'Boolean' => array(
203                                                         'ExportToExcel' => false
204                                         )
205                         ),
206                         'RequiredInput' => array(),
207                         'OptionalInput' => array(
208                                         'Grid' => array(
209                                                         'NumberOfRecords' => 'Integer',
210                                                         'Page'            => 'Integer',
211                                                         'Filter'          => 'Array',
212                                                         'OrderBy'         => 'Array',
213                                         )
214                         ),
215                         'Base'            => 'company',
216                         'NumberOfRecords' => 10,
217                         'Query'           => 'SELECT [SELECTION]
218                                                                 FROM \Company\Entity\Company company
219                                                                 JOIN company.contact contact
220                                                                 LEFT JOIN company.group grp
221                                                                 LEFT JOIN company.groupDivision division
222                                                                 LEFT JOIN company.tradeCenter tradeCenter
223                                                                 LEFT JOIN company.city city
224                                                                 LEFT JOIN city.region region
225                                                                 [WHERE] [ORDER]',
226                         'Selection'       => 'company, grp, division, contact, tradeCenter, city, region',
227                         'Filter'          => array(
228                                                                         'company.archived' => false
229                                                                 ),
230                         'OrderBy'         => array('company.name' => 'ASC'),
231                         'Fields'          => array(
232                                                                         'id',
233                                                                         'name',
234                                                                         'jobState',
235                                                                         'created' => 'DateTime',
236                                                                         'group' => array(
237                                                                                 'name'
238                                                                         ),
239                                                                         'groupDivision' => array(
240                                                                                 'name'
241                                                                         ),
242                                                                         'contact' => array(
243                                                                                 'firstName',
244                                                                                 'familyName',
245                                                                                 'email',
246                                                                                 'office',
247                                                                                 'mobile',
248                                                                                 'fax'
249                                                                         ),
250                                                                         'tradeCenter' => array(
251                                                                                 'name'
252                                                                         )
253                                                                 )
254         );
255         /**
256          * @var array
257         */
258         protected $metaUpdate = array(
259                         'Type'          => 'Update',
260                         'Contract'      => 'UseOnce',
261                         'ExecuteAfter'  => array(
262                                         'updateAuthSession',
263                                         'PublicCentreClubs'
264                         ),
265                         'Expand'        => array(
266                                         'contact',
267                                         'city',
268                                         'region',
269                                         'country',
270                                         'tradeCenter',
271                                         'group',
272                                         'groupDivision',
273                                         'regionalManager',
274                                         'docStockCertificate',
275                                         'docAddressProof',
276                                         'docCopyOfId',
277                                         'docCopyOfDirectorId',
278                                         'docCompanyRegistration'
279                         ),
280                         'RelatedEntityFromInput' => array(
281                                         'Contact' => array(
282                                                         'Workflow'  => '\Person\Workflow',
283                                                         'Service'   => '\Person\Service\Contact',
284                                                         'Field'     => 'contact'
285                                         )
286                         ),
287                         'RequiredInput' => array(
288                                         'Company' => array(
289                                                         'name'         => 'String100',
290                                                         'region'       => 'Id',
291                                                         'city'         => 'Id',
292                                                         'street'       => 'String75',
293                                                         'postalCode'   => 'String10'
294                                         ),
295                                         'Contact' => array(
296                                                         'firstName'  => 'String50',
297                                                         'familyName' => 'String50',
298                                                         'mobile'     => 'String20',
299                                                         'office'     => 'String20',
300                                                         'email'      => 'Email'
301                                         )
302                         ),
303                         'OptionalInput' => array(
304                                         'Company' => array(
305                                                         'owners'                                        => 'Array',
306                                                         'businessName'                          => 'String100',
307                                                         'group'                                 => 'Id',
308                                                         'groupDivision'                         => 'Id',
309               'regionalManager'     => 'Id',
310                                                         'companyRegistrationNumber' => 'String50',
311                                                         'vatNumber'                             => 'String20',
312                                                         'dealerStockNumber'             => 'String50',
313                                                         'companyType'                           => 'String25',
314                                                         'docStockCertificate'           => 'Id',
315                                                         'docAddressProof'                       => 'Id',
316                                                         'docCopyOfId'                           => 'Id',
317                                                         'docCopyOfDirectorId'           => 'Id',
318                                                         'docCompanyRegistration'        => 'Id',
319                                                         'dealerType'                            => 'String50',
320                                                         'tradeCenter'                           => 'String20',
321                                                         'priceGuide'                            => 'Boolean',
322                                                         'statusReason'                          => 'String250',
323                                                         'automateFile'                          => 'String64',
324                                                         'automateDealerCode'            => 'String20',
325                                                         'autolineFile'                          => 'String64',
326                                                         'autolineDealerCode'            => 'String20',
327                                                         'amhgroupFile'                          => 'String64',
328                                                         'amhgroupDealerCode'            => 'String20',
329                                                         'publicCentre'                          => 'Boolean',
330                                         ),
331                                         'Contact' => array(
332                                                         'fax'                                           => 'String20'
333                                         )
334                         )
335         );
336         /**
337          * @var array
338         */
339         protected $metaAdminUpdate = array(
340                         'Type'          => 'Update',
341                         'Contract'      => 'UseOnce',
342                         'ExecuteAfter'  => array(
343                                         'updateAuthSession',
344                                         'PublicCentreClubs'
345                         ),
346                         'Expand'        => array(
347                                         'contact',
348                                         'city',
349                                         'region',
350                                         'country',
351                                         'tradeCenter',
352                                         'group',
353                                         'groupDivision',
354                                         'regionalManager',
355                                         'docStockCertificate',
356                                         'docAddressProof',
357                                         'docCopyOfId',
358                                         'docCopyOfDirectorId',
359                                         'docCompanyRegistration'
360                         ),
361                         'RelatedEntityFromInput' => array(
362                                         'Contact' => array(
363                                                         'Workflow'  => '\Person\Workflow',
364                                                         'Service'   => '\Person\Service\Contact',
365                                                         'Field'     => 'contact'
366                                         )
367                         ),
368                         'RequiredInput' => array(
369                                         'Company' => array(
370                                                         'name'         => 'String100',
371                                                         'region'       => 'Id',
372                                                         'city'         => 'Id',
373                                                         'street'       => 'String75',
374                                                         'postalCode'   => 'String10'
375                                         ),
376                                         'Contact' => array(
377                                                         'firstName'  => 'String50',
378                                                         'familyName' => 'String50',
379                                                         'mobile'     => 'String20',
380                                                         'office'     => 'String20',
381                                                         'email'      => 'Email'
382                                         )
383                         ),
384                         'OptionalInput' => array(
385                                         'Company' => array(
386                                                         'owners'                                        => 'Array',
387                                                         'businessName'                          => 'String100',
388                                                         'group'                                 => 'Id',
389                                                         'groupDivision'                         => 'Id',
390                                                         'regionalManager'               => 'Id',
391                                                         'companyRegistrationNumber' => 'String50',
392                                                         'vatNumber'                             => 'String20',
393                                                         'dealerStockNumber'             => 'String50',
394                                                         'companyType'                           => 'String25',
395                                                         'docStockCertificate'           => 'Id',
396                                                         'docAddressProof'                       => 'Id',
397                                                         'docCopyOfId'                           => 'Id',
398                                                         'docCopyOfDirectorId'           => 'Id',
399                                                         'docCompanyRegistration'        => 'Id',
400                                                         'dealerType'                            => 'String50',
401                                                         'tradeCenter'                           => 'String20',
402                                                         'priceGuide'                            => 'Boolean',
403                                                         'statusReason'                          => 'String250',
404                                                         'automateFile'                          => 'String64',
405                                                         'automateDealerCode'            => 'String20',
406                                                         'autolineFile'                          => 'String64',
407                                                         'autolineDealerCode'            => 'String20',
408                                                         'amhgroupFile'                          => 'String64',
409                                                         'amhgroupDealerCode'            => 'String20',
410                                                         'publicCentre'                          => 'Boolean',
411                                         ),
412                                         'Contact' => array(
413                                                         'fax'                                           => 'String20'
414                                         )
415                         )
416         );
417
418
419
420         /**
421          * Add some dynamic filtering to our grids.
422          */
423         public function __construct()
424         {
425                 $authData = \Utility\Registry::getAuthData();
426                 switch (\Utility\Registry::getUserType())
427                 {
428                         case 'B4C User':
429                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
430                                 //$divisionFilter
431                                 //      && $this->metaInviteSelectList['Filter']['groupDivision'] = $divisionFilter;
432                                 $companyFilter = \Utility\Registry::getSudo('Company', $authData['company']['id']);
433                                 //$companyFilter
434                                 //      && $this->metaInviteSelectList['Filter']['id'] = '!=' . $companyFilter;
435                                 $companyFilter
436                                         && $this->metaTcDealerSelectList['Filter']['tradeCenter'] = $companyFilter;
437
438                 $companyFilter
439                 && $this->metaStockAuctionReportSelectList['Filter']['tradeCenter'] = $companyFilter;
440                                 break;
441                         case 'Group User':
442                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
443                                 //$divisionFilter
444                                 //      && $this->metaInviteSelectList['Filter']['groupDivision'] = $divisionFilter;
445                                 $companyFilter = \Utility\Registry::getSudo('Company', $authData['company']['id']);
446                                 //$companyFilter
447                                 //      && $this->metaInviteSelectList['Filter']['id'] = '!=' . $companyFilter;
448                                 $companyFilter
449                                         && $this->metaTcDealerSelectList['Filter']['tradeCenter'] = $companyFilter;
450                 $companyFilter
451                 && $this->metaStockAuctionReportSelectList['Filter']['tradeCenter'] = $companyFilter;
452                                 break;
453                         default:
454                                 //$this->metaInviteSelectList['Filter']['groupDivision'] = $authData['company']['groupDivision']['id'];
455                                 //$this->metaInviteSelectList['Filter']['id'] = '!=' . $authData['company']['id'];
456                                 $this->metaTcDealerSelectList['Filter']['tradeCenter'] = $authData['company']['id'];
457                 $this->metaStockAuctionReportSelectList['Filter']['tradeCenter'] = $authData['company']['id'];
458                                 break;
459                 }
460         }
461
462 }