source: trunk/Modules/Subject/Subject.php

Last change on this file was 951, checked in by chronos, 19 months ago
  • Modified: Improved client contract generation.
  • Fixed: SQL query logging into file.
File size: 8.8 KB
Line 
1<?php
2
3class ModuleSubject extends Module
4{
5 function __construct(System $System)
6 {
7 parent::__construct($System);
8 $this->Name = 'Subject';
9 $this->Version = '1.0';
10 $this->Creator = 'Chronos';
11 $this->License = 'GNU/GPLv3';
12 $this->Description = 'Subject management';
13 $this->Dependencies = array(ModuleUser::GetName(), ModuleMap::GetName());
14 $this->Models = array(Subject::GetClassName(), ContactCategory::GetClassName(),
15 Contact::GetClassName());
16 }
17
18 function DoStart(): void
19 {
20 $this->System->FormManager->RegisterClass('Subject', array(
21 'Title' => 'Subjekty',
22 'Table' => 'Subject',
23 'DefaultSortColumn' => 'Name',
24 'Items' => array(
25 'Id' => array('Type' => 'Integer', 'Caption' => 'Identifikace', 'Default' => '', 'ReadOnly' => true),
26 'Name' => array('Type' => 'String', 'Caption' => 'Celé jméno', 'Default' => '', 'Required' => true),
27 'AddressStreet' => array('Type' => 'String', 'Caption' => 'Ulice', 'Default' => ''),
28 'AddressTown' => array('Type' => 'String', 'Caption' => 'Město', 'Default' => ''),
29 'AddressPSC' => array('Type' => 'Integer', 'Caption' => 'PSČ', 'Default' => '', 'Required' => true),
30 'AddressCountry' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => ''),
31 'IC' => array('Type' => 'String', 'Caption' => 'IČ', 'Default' => ''),
32 'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''),
33 'PayVAT' => array('Type' => 'Boolean', 'Caption' => 'Plátce DPH', 'Default' => 0),
34 'MapPosition' => array('Type' => 'TMapPosition', 'Caption' => 'Pozice na mapě', 'Default' => '', 'Null' => true),
35 'WWW' => array('Type' => 'Hyperlink', 'Caption' => 'WWW', 'Default' => ''),
36 'Note' => array('Type' => 'String', 'Caption' => 'Poznámka', 'Default' => ''),
37 'Customer' => array('Type' => 'TMemberListSubject', 'Caption' => 'Členové', 'Default' => ''),
38 'Operations' => array('Type' => 'TFinanceOperationListSubject', 'Caption' => 'Platby', 'Default' => ''),
39 'Invoices' => array('Type' => 'TFinanceInvoiceListSubject', 'Caption' => 'Faktury', 'Default' => ''),
40 'Payment' => array('Type' => 'Float', 'Caption' => 'Placení', 'Default' => '',
41 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'ROUND(IFNULL((SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
42 'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value`) FROM `FinanceInvoice` '.
43 'WHERE `FinanceInvoice`.`Subject`=#Id), 0))'),
44 'BankAccounts' => array('Type' => 'TFinanceBankAccountListSubject', 'Caption' => 'Bankovní účty', 'Default' => ''),
45 'Contracts' => array('Type' => 'TContractListSubject', 'Caption' => 'Smlouvy', 'Default' => ''),
46 'Contacts' => array('Type' => 'TContactListSubject', 'Caption' => 'Kontakty', 'Default' => ''),
47 ),
48 ));
49 $this->System->FormManager->RegisterFormType('TFinanceBankAccountListSubject', array(
50 'Type' => 'ManyToOne',
51 'Table' => 'FinanceBankAccount',
52 'Id' => 'Id',
53 'Ref' => 'Subject',
54 'Filter' => '1',
55 ));
56 $this->System->FormManager->RegisterFormType('TContractListSubject', array(
57 'Type' => 'ManyToOne',
58 'Table' => 'Contract',
59 'Id' => 'Id',
60 'Ref' => 'Subject',
61 'Filter' => '1',
62 ));
63 $this->System->FormManager->RegisterFormType('TContactListSubject', array(
64 'Type' => 'ManyToOne',
65 'Table' => 'Contact',
66 'Id' => 'Id',
67 'Ref' => 'Subject',
68 'Filter' => '1',
69 ));
70 $this->System->FormManager->RegisterClass('SubjectReport', array(
71 'Title' => 'Přehled subjektů',
72 'Table' => 'SubjectReport',
73 'DefaultSortColumn' => 'Id',
74 'SQL' => '(SELECT Id FROM Subject)',
75 'Items' => array(
76 'Id' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => '', 'ReadOnly' => true),
77 'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
78 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
79 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
80 'WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
81 'AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
82 'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
83 'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
84 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
85 'WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
86 'AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
87 'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
88 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
89 ')'),
90 ),
91 ));
92 $this->System->FormManager->RegisterFormType('TContactCategory', array(
93 'Type' => 'Reference',
94 'Table' => 'ContactCategory',
95 'Id' => 'Id',
96 'Name' => 'Name',
97 'Filter' => '1',
98 ));
99 $this->System->FormManager->RegisterFormType('TContactListCategory', array(
100 'Type' => 'ManyToOne',
101 'Table' => 'Contact',
102 'Id' => 'Id',
103 'Ref' => 'Category',
104 'Filter' => '1',
105 ));
106 $this->System->FormManager->RegisterFormType('TContactListUser', array(
107 'Type' => 'ManyToOne',
108 'Table' => 'Contact',
109 'Id' => 'Id',
110 'Ref' => 'User',
111 'Filter' => '1',
112 ));
113 $this->System->FormManager->RegisterClass('Contact', array(
114 'Title' => 'Kontakty',
115 'Table' => 'Contact',
116 'Items' => array(
117 'Category' => array('Type' => 'TContactCategory', 'Caption' => 'Druh', 'Default' => ''),
118 'Value' => array('Type' => 'String', 'Caption' => 'Hodnota', 'Default' => ''),
119 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => '', 'Null' => true),
120 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subject', 'Default' => '', 'Null' => true),
121 'Description' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
122 'Receive' => array('Type' => 'Boolean', 'Caption' => 'Přijímat zprávy', 'Default' => '0'),
123 ),
124 ));
125 $this->System->FormManager->RegisterClass('ContactCategory', array(
126 'Title' => 'Druh kontaktu',
127 'Table' => 'ContactCategory',
128 'Items' => array(
129 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
130 'Items' => array('Type' => 'TContactListCategory', 'Caption' => 'Kontakty'),
131 ),
132 ));
133 $this->System->FormManager->RegisterFormType('TContact', array(
134 'Type' => 'Reference',
135 'Table' => 'Contact',
136 'Id' => 'Id',
137 'Name' => 'Value',
138 'Filter' => '1',
139 ));
140 $this->System->FormManager->RegisterFormType('TSubject', array(
141 'Type' => 'Reference',
142 'Table' => 'Subject',
143 'Id' => 'Id',
144 'Name' => 'Name',
145 'Filter' => '1',
146 ));
147 ModuleIS::Cast(Core::Cast($this->System)->GetModule('IS'))->RegisterDashboardItem('Subject',
148 array($this, 'ShowDashboardItem'));
149 }
150
151 function ShowDashboardItem(): string
152 {
153 $DbResult = $this->Database->select('Subject', 'COUNT(*)', '1');
154 $DbRow = $DbResult->fetch_row();
155 $Output = 'Subjektů: <a href="'.$this->System->Link('/is/?a=list&amp;t=Subject').'">'.$DbRow['0'].'</a><br/>';
156 return $Output;
157 }
158}
159
160class Subject extends Model
161{
162 static function GetModelDesc(): ModelDesc
163 {
164 $Desc = new ModelDesc(self::GetClassName());
165 $Desc->AddString('Name');
166 $Desc->AddString('AddressStreet');
167 $Desc->AddString('AddressTown');
168 $Desc->AddString('AddressPSC');
169 $Desc->AddReference('AddressCountry', Country::GetClassName(), true);
170 $Desc->AddString('IC');
171 $Desc->AddString('DIC');
172 $Desc->AddBoolean('PayVAT');
173 $Desc->AddReference('MapPosition', MapPosition::GetClassName(), true);
174 $Desc->AddString('WWW');
175 $Desc->AddString('Note');
176 return $Desc;
177 }
178}
179
180class Contact extends Model
181{
182 static function GetModelDesc(): ModelDesc
183 {
184 $Desc = new ModelDesc(self::GetClassName());
185 $Desc->AddReference('Category', ContactCategory::GetClassName(), true);
186 $Desc->AddString('Value');
187 $Desc->AddReference('Subject', Subject::GetClassName(), true);
188 $Desc->AddReference('User', User::GetClassName(), true);
189 $Desc->AddString('Description');
190 $Desc->AddBoolean('Receive');
191 return $Desc;
192 }
193}
194
195class ContactCategory extends Model
196{
197 static function GetModelDesc(): ModelDesc
198 {
199 $Desc = new ModelDesc(self::GetClassName());
200 $Desc->AddString('Name');
201 return $Desc;
202 }
203}
Note: See TracBrowser for help on using the repository browser.