1 | <?php
|
---|
2 |
|
---|
3 | class ModuleCustomer extends AppModule
|
---|
4 | {
|
---|
5 | function __construct(System $System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Name = 'Customer';
|
---|
9 | $this->Version = '1.0';
|
---|
10 | $this->Creator = 'Chronos';
|
---|
11 | $this->License = 'GNU/GPL';
|
---|
12 | $this->Description = 'Customer management';
|
---|
13 | $this->Dependencies = array('User', 'Finance');
|
---|
14 | }
|
---|
15 |
|
---|
16 | function DoStart(): void
|
---|
17 | {
|
---|
18 | $this->System->FormManager->RegisterClass('Member', array(
|
---|
19 | 'Title' => 'Zákazníci',
|
---|
20 | 'Table' => 'Member',
|
---|
21 | 'DefaultSortColumn' => 'Name',
|
---|
22 | 'Items' => array(
|
---|
23 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
24 | 'ResponsibleUser' => array('Type' => 'TUser', 'Caption' => 'Zodpovědný uživatel', 'Default' => ''),
|
---|
25 | 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
|
---|
26 | 'FamilyMemberCount' => array('Type' => 'String', 'Caption' => 'Bydlících osob', 'Default' => '0', 'Suffix' => 'osob'),
|
---|
27 | 'MembershipDate' => array('Type' => 'Date', 'Caption' => 'Datum členství', 'Default' => ''),
|
---|
28 | 'BillingPeriod' => array('Type' => 'TFinanceBillingPeriod', 'Caption' => 'Fakturační období aktuální', 'Default' => ''),
|
---|
29 | 'BillingPeriodLastDate' => array('Type' => 'Date', 'Caption' => 'Datum poslední fakturace', 'Default' => ''),
|
---|
30 | 'Blocked' => array('Type' => 'Boolean', 'Caption' => 'Blokování', 'Default' => '0'),
|
---|
31 | 'PayDay' => array('Type' => 'Integer', 'Caption' => 'Den placení', 'Default' => '1', 'Suffix' => 'den'),
|
---|
32 | 'Devices' => array('Type' => 'TDeviceList', 'Caption' => 'Registrovaná zařízení', 'Default' => ''),
|
---|
33 | 'UserRel' => array('Type' => 'TUserCustomerRelListCustomer', 'Caption' => 'Přiřazení uživatelé', 'Default' => ''),
|
---|
34 | 'ServiceRel' => array('Type' => 'TServiceCustomerRelListCustomer', 'Caption' => 'Placené služby', 'Default' => ''),
|
---|
35 | 'SupportActivity' => array('Type' => 'TSupportActivityListCustomer', 'Caption' => 'Zákaznická podpora', 'Default' => ''),
|
---|
36 | 'Consumption' => array('Type' => 'TCustomerStockSerialNumber', 'Caption' => 'Spotřeba zařízení', 'Default' => ''),
|
---|
37 | 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true),
|
---|
38 | 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true),
|
---|
39 | 'ChangeReplaceId' => array('Type' => 'TMember', 'Caption' => 'Změna - položka', 'Default' => '0', 'Null' => true, 'NotInList' => true),
|
---|
40 | ),
|
---|
41 | 'ItemActions' => array(
|
---|
42 | array('Caption' => 'Klientská sekce', 'URL' => '/finance/platby/?i=#RowId'),
|
---|
43 | ),
|
---|
44 | ));
|
---|
45 | $this->System->FormManager->RegisterClass('MemberPayment', array(
|
---|
46 | 'Title' => 'Placení zákazníků',
|
---|
47 | 'Table' => 'MemberPayment',
|
---|
48 | 'Items' => array(
|
---|
49 | 'Member' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => '', 'ReadOnly' => true),
|
---|
50 | 'MonthlyTotal' => array('Type' => 'Integer', 'Caption' => 'Celkem měsíčně', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
|
---|
51 | 'MonthlyInternet' => array('Type' => 'Integer', 'Caption' => 'Internet měsíčně', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
|
---|
52 | 'MonthlyConsumption' => array('Type' => 'Integer', 'Caption' => 'Spotřeba měsíčně', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
|
---|
53 | 'MonthlyPlus' => array('Type' => 'Integer', 'Caption' => 'Měsíčně plus', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
|
---|
54 | 'Cash' => array('Type' => 'Integer', 'Caption' => 'Kredit', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
|
---|
55 | ),
|
---|
56 | 'Actions' => array(
|
---|
57 | array('Caption' => 'Přepočítat', 'URL' => '/finance/sprava/?Operation=Recalculate'),
|
---|
58 | ),
|
---|
59 | ));
|
---|
60 | $this->System->FormManager->RegisterFormType('TMember', array(
|
---|
61 | 'Type' => 'Reference',
|
---|
62 | 'Table' => 'Member',
|
---|
63 | 'Id' => 'Id',
|
---|
64 | 'Name' => 'Name',
|
---|
65 | 'Filter' => '1',
|
---|
66 | ));
|
---|
67 | $this->System->FormManager->RegisterClass('Service', array(
|
---|
68 | 'Title' => 'Služby',
|
---|
69 | 'Table' => 'Service',
|
---|
70 | 'DefaultSortColumn' => 'Name',
|
---|
71 | 'Items' => array(
|
---|
72 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
73 | 'Category' => array('Type' => 'TServiceCategory', 'Caption' => 'Skupina', 'Default' => '', 'Null' => true),
|
---|
74 | 'Price' => array('Type' => 'Integer', 'Caption' => 'Cena', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
75 | 'VAT' => array('Type' => 'TFinanceVATType', 'Caption' => 'Sazba DPH', 'Default' => '0', 'Suffix' => ''),
|
---|
76 | 'CustomerCount' => array('Type' => 'Integer', 'Caption' => 'Počet zákazníků', 'Default' => '', 'ReadOnly' => true,
|
---|
77 | 'SQL' => '(SELECT COUNT(*) FROM `ServiceCustomerRel` LEFT JOIN `Member` ON `Member`.`Id`=`ServiceCustomerRel`.`Customer` WHERE (`ServiceCustomerRel`.`Service`=#Id) AND (`Member`.`Blocked`=0))'),
|
---|
78 | 'Public' => array('Type' => 'Boolean', 'Caption' => 'Veřejné', 'Default' => ''),
|
---|
79 | 'InternetSpeedMin' => array('Type' => 'Integer', 'Caption' => 'Min. rychlost internetu', 'Default' => '0', 'Suffix' => 'bit/s'),
|
---|
80 | 'InternetSpeedMax' => array('Type' => 'Integer', 'Caption' => 'Max. rychlost internetu', 'Default' => '0', 'Suffix' => 'bit/s'),
|
---|
81 | 'UploadAsymmetry' => array('Type' => 'Integer', 'Caption' => 'Asymetrie odesílání', 'Default' => '1'),
|
---|
82 | 'Memory' => array('Type' => 'Integer', 'Caption' => 'Paměť', 'Default' => '0', 'Suffix' => 'GB'),
|
---|
83 | 'MemorySwap' => array('Type' => 'Integer', 'Caption' => 'Odkládací oddíl', 'Default' => '0', 'Suffix' => 'GB'),
|
---|
84 | 'Storage' => array('Type' => 'Integer', 'Caption' => 'Úložiště', 'Default' => '0', 'Suffix' => 'GB'),
|
---|
85 | 'CPUCount' => array('Type' => 'Integer', 'Caption' => 'Počet jader', 'Default' => '0', 'Suffix' => ''),
|
---|
86 | 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true),
|
---|
87 | 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true),
|
---|
88 | 'ChangeReplaceId' => array('Type' => 'TService', 'Caption' => 'Změna - položka', 'Default' => '', 'Null' => true),
|
---|
89 | 'CustomerRel' => array('Type' => 'TServiceCustomerRelListService', 'Caption' => 'Placení zákazníky', 'Default' => ''),
|
---|
90 | ),
|
---|
91 | ));
|
---|
92 | $this->System->FormManager->RegisterClass('ServiceCategory', array(
|
---|
93 | 'Title' => 'Kategorie služeb',
|
---|
94 | 'Table' => 'ServiceCategory',
|
---|
95 | 'Items' => array(
|
---|
96 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
97 | 'Items' => array('Type' => 'TServiceListServiceCategory', 'Caption' => 'Služby', 'Default' => ''),
|
---|
98 | ),
|
---|
99 | ));
|
---|
100 | $this->System->FormManager->RegisterClass('ServiceCustomerRel', array(
|
---|
101 | 'Title' => 'Služby zákazníka',
|
---|
102 | 'Table' => 'ServiceCustomerRel',
|
---|
103 | 'Items' => array(
|
---|
104 | 'Service' => array('Type' => 'TService', 'Caption' => 'Služba', 'Default' => ''),
|
---|
105 | 'Customer' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => ''),
|
---|
106 | 'SpeedLimit' => array('Type' => 'TNetworkSpeedLimit', 'Caption' => 'Omezení rychlosti', 'Default' => null, 'Null' => true),
|
---|
107 | 'Devices' => array('Type' => 'TNetworkDeviceListService', 'Caption' => 'Zařízení', 'Default' => ''),
|
---|
108 | 'Subnets' => array('Type' => 'TNetworkSubnetListService', 'Caption' => 'Podsítě', 'Default' => ''),
|
---|
109 | 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true),
|
---|
110 | 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true),
|
---|
111 | 'ChangeReplaceId' => array('Type' => 'TServiceCustomerRel', 'Caption' => 'Změna - položka', 'Default' => '', 'Null' => true, 'NotInList' => true),
|
---|
112 | ),
|
---|
113 | ));
|
---|
114 | $this->System->FormManager->RegisterFormType('TServiceCategory', array(
|
---|
115 | 'Type' => 'Reference',
|
---|
116 | 'Table' => 'ServiceCategory',
|
---|
117 | 'Id' => 'Id',
|
---|
118 | 'Name' => 'Name',
|
---|
119 | 'Filter' => '1',
|
---|
120 | ));
|
---|
121 | $this->System->FormManager->RegisterFormType('TService', array(
|
---|
122 | 'Type' => 'Reference',
|
---|
123 | 'Table' => 'Service',
|
---|
124 | 'Id' => 'Id',
|
---|
125 | 'Name' => 'Name',
|
---|
126 | 'Filter' => '1',
|
---|
127 | ));
|
---|
128 | $this->System->FormManager->RegisterFormType('TServiceCustomerRel', array(
|
---|
129 | 'Type' => 'Reference',
|
---|
130 | 'Table' => 'ServiceCustomerRel',
|
---|
131 | 'Id' => 'Id',
|
---|
132 | 'Name' => 'Id',
|
---|
133 | 'Filter' => '1',
|
---|
134 | ));
|
---|
135 | $this->System->FormManager->RegisterFormType('TServiceCustomerRelListCustomer', array(
|
---|
136 | 'Type' => 'ManyToOne',
|
---|
137 | 'Table' => 'ServiceCustomerRel',
|
---|
138 | 'Id' => 'Id',
|
---|
139 | 'Ref' => 'Customer',
|
---|
140 | 'Filter' => '1',
|
---|
141 | ));
|
---|
142 | $this->System->FormManager->RegisterFormType('TNetworkDeviceListService', array(
|
---|
143 | 'Type' => 'ManyToOne',
|
---|
144 | 'Table' => 'NetworkDevice',
|
---|
145 | 'Id' => 'Id',
|
---|
146 | 'Ref' => 'Service',
|
---|
147 | 'Filter' => '1',
|
---|
148 | ));
|
---|
149 | $this->System->FormManager->RegisterFormType('TNetworkSubnetListService', array(
|
---|
150 | 'Type' => 'ManyToOne',
|
---|
151 | 'Table' => 'NetworkSubnet',
|
---|
152 | 'Id' => 'Id',
|
---|
153 | 'Ref' => 'Service',
|
---|
154 | 'Filter' => '1',
|
---|
155 | ));
|
---|
156 | $this->System->FormManager->RegisterFormType('TServiceCustomerRelListService', array(
|
---|
157 | 'Type' => 'ManyToOne',
|
---|
158 | 'Table' => 'ServiceCustomerRel',
|
---|
159 | 'Id' => 'Id',
|
---|
160 | 'Ref' => 'Service',
|
---|
161 | 'Filter' => '1',
|
---|
162 | ));
|
---|
163 | $this->System->FormManager->RegisterFormType('TServiceListServiceCategory', array(
|
---|
164 | 'Type' => 'ManyToOne',
|
---|
165 | 'Table' => 'Service',
|
---|
166 | 'Id' => 'Id',
|
---|
167 | 'Ref' => 'Category',
|
---|
168 | 'Filter' => '1',
|
---|
169 | ));
|
---|
170 | $this->System->FormManager->RegisterClass('SupportActivity', array(
|
---|
171 | 'Title' => 'Zákaznická podpora',
|
---|
172 | 'Table' => 'SupportActivity',
|
---|
173 | 'DefaultSortColumn' => 'Time',
|
---|
174 | 'Items' => array(
|
---|
175 | 'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
|
---|
176 | 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''),
|
---|
177 | 'Customer' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => ''),
|
---|
178 | 'User' => array('Type' => 'TUser', 'Caption' => 'Pracovník', 'Default' => ''),
|
---|
179 | ),
|
---|
180 | ));
|
---|
181 | $this->System->FormManager->RegisterFormType('TSupportActivityListCustomer', array(
|
---|
182 | 'Type' => 'ManyToOne',
|
---|
183 | 'Table' => 'SupportActivity',
|
---|
184 | 'Id' => 'Id',
|
---|
185 | 'Ref' => 'Customer',
|
---|
186 | 'Filter' => '1',
|
---|
187 | ));
|
---|
188 |
|
---|
189 | ModuleIS::Cast($this->System->GetModule('IS'))->RegisterDashboardItem('Customer',
|
---|
190 | array($this, 'ShowDashboardItem'));
|
---|
191 | }
|
---|
192 |
|
---|
193 | function DoInstall(): void
|
---|
194 | {
|
---|
195 | $this->InstallModel(Member::GetDesc());
|
---|
196 | $this->InstallModel(MemberPayment::GetDesc());
|
---|
197 | $this->InstallModel(SupportActivity::GetDesc());
|
---|
198 | $this->InstallModel(ServiceCategory::GetDesc());
|
---|
199 | $this->InstallModel(Service::GetDesc());
|
---|
200 | $this->InstallModel(ServiceCustomerRel::GetDesc());
|
---|
201 | }
|
---|
202 |
|
---|
203 | function Uninstall(): void
|
---|
204 | {
|
---|
205 | $this->UninstallModel(ServiceCustomerRel::GetDesc());
|
---|
206 | $this->UninstallModel(Service::GetDesc());
|
---|
207 | $this->UninstallModel(ServiceCategory::GetDesc());
|
---|
208 | $this->UninstallModel(SupportActivity::GetDesc());
|
---|
209 | $this->UninstallModel(MemberPayment::GetDesc());
|
---|
210 | $this->UninstallModel(Member::GetDesc());
|
---|
211 | }
|
---|
212 |
|
---|
213 | function ShowDashboardItem(): string
|
---|
214 | {
|
---|
215 | $DbResult = $this->Database->select('Member', 'COUNT(*)', '1');
|
---|
216 | $DbRow = $DbResult->fetch_row();
|
---|
217 | $Output = 'Zákazníků: registrovaných:'.$DbRow['0'];
|
---|
218 |
|
---|
219 | $DbResult = $this->Database->select('Member', 'COUNT(*)', '`Blocked`=0 AND `BillingPeriod`<>1');
|
---|
220 | $DbRow = $DbResult->fetch_row();
|
---|
221 | $Output .= ' platících:'.$DbRow['0'].'<br/>';
|
---|
222 |
|
---|
223 | return $Output;
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | class Member extends Model
|
---|
228 | {
|
---|
229 | static function GetDesc(): ModelDesc
|
---|
230 | {
|
---|
231 | $Desc = new ModelDesc('Member');
|
---|
232 | $Desc->AddString('Name');
|
---|
233 | $Desc->AddReference('Subject', 'Subject');
|
---|
234 | $Desc->AddReference('ResponsibleUser', 'User');
|
---|
235 | $Desc->AddInteger('FamilyMemberCount');
|
---|
236 | $Desc->AddDate('MembershipDate');
|
---|
237 | $Desc->AddInteger('MemberState');
|
---|
238 | $Desc->AddInteger('GPS');
|
---|
239 | $Desc->AddReference('BillingPeriod', 'FinanceBillingPerios');
|
---|
240 | $Desc->AddDate('BillingPeriodLastDate');
|
---|
241 | $Desc->AddBoolean('Blocked');
|
---|
242 | $Desc->AddInteger('PayDay');
|
---|
243 | $Desc->AddChangeAction();
|
---|
244 | return $Desc;
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | class MemberPayment extends Model
|
---|
249 | {
|
---|
250 | static function GetDesc(): ModelDesc
|
---|
251 | {
|
---|
252 | $Desc = new ModelDesc('MemberPayment');
|
---|
253 | $Desc->AddReference('Member', 'Member');
|
---|
254 | $Desc->AddFloat('MonthlyTotal');
|
---|
255 | $Desc->AddFloat('MonthlyInternet');
|
---|
256 | $Desc->AddFloat('MonthlyConsumption');
|
---|
257 | $Desc->AddFloat('MonthlyPlus');
|
---|
258 | $Desc->AddFloat('Cash');
|
---|
259 | return $Desc;
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | class Service extends Model
|
---|
264 | {
|
---|
265 | static function GetDesc(): ModelDesc
|
---|
266 | {
|
---|
267 | $Desc = new ModelDesc('Service');
|
---|
268 | $Desc->AddString('Name');
|
---|
269 | $Desc->AddReference('Category', 'ServiceCategory');
|
---|
270 | $Desc->AddInteger('Price');
|
---|
271 | $Desc->AddInteger('VAT');
|
---|
272 | $Desc->AddChangeAction();
|
---|
273 | $Desc->AddBoolean('Public');
|
---|
274 | $Desc->AddInteger('InternetSpeedMax');
|
---|
275 | $Desc->AddInteger('InternetSpeedMin');
|
---|
276 | $Desc->AddInteger('InternetUploadAsymmetry');
|
---|
277 | $Desc->AddInteger('Memory');
|
---|
278 | $Desc->AddInteger('MemorySwap');
|
---|
279 | $Desc->AddInteger('Storage');
|
---|
280 | $Desc->AddInteger('CPUCount');
|
---|
281 | return $Desc;
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | class ServiceCategory extends Model
|
---|
286 | {
|
---|
287 | static function GetDesc(): ModelDesc
|
---|
288 | {
|
---|
289 | $Desc = new ModelDesc('ServiceCategory');
|
---|
290 | $Desc->AddString('Name');
|
---|
291 | return $Desc;
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | class SupportActivity extends Model
|
---|
296 | {
|
---|
297 | static function GetDesc(): ModelDesc
|
---|
298 | {
|
---|
299 | $Desc = new ModelDesc('SupportActivity');
|
---|
300 | $Desc->AddDateTime('Time');
|
---|
301 | $Desc->AddString('Description');
|
---|
302 | $Desc->AddReference('Customer', 'Member');
|
---|
303 | $Desc->AddReference('User', 'User');
|
---|
304 | return $Desc;
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | class ServiceCustomerRel extends Model
|
---|
309 | {
|
---|
310 | static function GetDesc(): ModelDesc
|
---|
311 | {
|
---|
312 | $Desc = new ModelDesc('ServiceCustomerRel');
|
---|
313 | $Desc->AddReference('Service', 'Service');
|
---|
314 | $Desc->AddReference('Customer', 'Member');
|
---|
315 | $Desc->AddChangeAction();
|
---|
316 | $Desc->AddInteger('SpeedLimit');
|
---|
317 | return $Desc;
|
---|
318 | }
|
---|
319 | }
|
---|