1 | <?php
|
---|
2 |
|
---|
3 | class ModuleSubject extends AppModule
|
---|
4 | {
|
---|
5 | function __construct($System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Name = 'Subject';
|
---|
9 | $this->Version = '1.0';
|
---|
10 | $this->Creator = 'Chronos';
|
---|
11 | $this->License = 'GNU/GPL';
|
---|
12 | $this->Description = 'Subject management';
|
---|
13 | $this->Dependencies = array('User', 'Map');
|
---|
14 | }
|
---|
15 |
|
---|
16 | function DoStart()
|
---|
17 | {
|
---|
18 | $this->System->FormManager->RegisterClass('Subject', array(
|
---|
19 | 'Title' => 'Subjekty',
|
---|
20 | 'Table' => 'Subject',
|
---|
21 | 'DefaultSortColumn' => 'Name',
|
---|
22 | 'Items' => array(
|
---|
23 | 'Id' => array('Type' => 'Integer', 'Caption' => 'Identifikace', 'Default' => '', 'ReadOnly' => true),
|
---|
24 | 'Name' => array('Type' => 'String', 'Caption' => 'Celé jméno', 'Default' => ''),
|
---|
25 | 'AddressStreet' => array('Type' => 'String', 'Caption' => 'Ulice', 'Default' => ''),
|
---|
26 | 'AddressTown' => array('Type' => 'String', 'Caption' => 'Město', 'Default' => ''),
|
---|
27 | 'AddressPSC' => array('Type' => 'String', 'Caption' => 'PSČ', 'Default' => ''),
|
---|
28 | 'AddressCountry' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => ''),
|
---|
29 | 'IC' => array('Type' => 'String', 'Caption' => 'IČ', 'Default' => ''),
|
---|
30 | 'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''),
|
---|
31 | 'MapPosition' => array('Type' => 'TMapPosition', 'Caption' => 'Pozice na mapě', 'Default' => '', 'Null' => true),
|
---|
32 | 'WWW' => array('Type' => 'Hyperlink', 'Caption' => 'WWW', 'Default' => ''),
|
---|
33 | 'Note' => array('Type' => 'String', 'Caption' => 'Poznámka', 'Default' => ''),
|
---|
34 | 'Customer' => array('Type' => 'TMemberListSubject', 'Caption' => 'Členové', 'Default' => ''),
|
---|
35 | 'Operations' => array('Type' => 'TFinanceOperationListSubject', 'Caption' => 'Platby', 'Default' => ''),
|
---|
36 | 'Invoices' => array('Type' => 'TFinanceInvoiceListSubject', 'Caption' => 'Faktury', 'Default' => ''),
|
---|
37 | 'Payment' => array('Type' => 'Float', 'Caption' => 'Placení', 'Default' => '',
|
---|
38 | 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'IFNULL((SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
|
---|
39 | 'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value`) FROM `FinanceInvoice` '.
|
---|
40 | 'WHERE `FinanceInvoice`.`Subject`=#Id), 0)'),
|
---|
41 | 'BankAccounts' => array('Type' => 'TFinanceBankAccountListSubject', 'Caption' => 'Bankovní účety', 'Default' => ''),
|
---|
42 | ),
|
---|
43 | ));
|
---|
44 | $this->System->FormManager->RegisterFormType('TFinanceBankAccountListSubject', array(
|
---|
45 | 'Type' => 'ManyToOne',
|
---|
46 | 'Table' => 'FinanceBankAccount',
|
---|
47 | 'Id' => 'Id',
|
---|
48 | 'Ref' => 'Subject',
|
---|
49 | 'Filter' => '1',
|
---|
50 | ));
|
---|
51 | $this->System->FormManager->RegisterClass('SubjectReport', array(
|
---|
52 | 'Title' => 'Přehled subjektů',
|
---|
53 | 'Table' => 'SubjectReport',
|
---|
54 | 'DefaultSortColumn' => 'Id',
|
---|
55 | 'SQL' => '(SELECT Id FROM Subject)',
|
---|
56 | 'Items' => array(
|
---|
57 | 'Id' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => '', 'ReadOnly' => true),
|
---|
58 | 'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
|
---|
59 | 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
|
---|
60 | 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
|
---|
61 | 'WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
|
---|
62 | 'AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
|
---|
63 | 'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
|
---|
64 | 'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
|
---|
65 | 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
|
---|
66 | 'WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
|
---|
67 | 'AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
|
---|
68 | 'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
|
---|
69 | 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
|
---|
70 | ')'),
|
---|
71 | ),
|
---|
72 | ));
|
---|
73 | $this->System->FormManager->RegisterFormType('TContactCategory', array(
|
---|
74 | 'Type' => 'Reference',
|
---|
75 | 'Table' => 'ContactCategory',
|
---|
76 | 'Id' => 'Id',
|
---|
77 | 'Name' => 'Name',
|
---|
78 | 'Filter' => '1',
|
---|
79 | ));
|
---|
80 | $this->System->FormManager->RegisterFormType('TContactListCategory', array(
|
---|
81 | 'Type' => 'ManyToOne',
|
---|
82 | 'Table' => 'Contact',
|
---|
83 | 'Id' => 'Id',
|
---|
84 | 'Ref' => 'Category',
|
---|
85 | 'Filter' => '1',
|
---|
86 | ));
|
---|
87 | $this->System->FormManager->RegisterFormType('TContactListUser', array(
|
---|
88 | 'Type' => 'ManyToOne',
|
---|
89 | 'Table' => 'Contact',
|
---|
90 | 'Id' => 'Id',
|
---|
91 | 'Ref' => 'User',
|
---|
92 | 'Filter' => '1',
|
---|
93 | ));
|
---|
94 | $this->System->FormManager->RegisterClass('Contact', array(
|
---|
95 | 'Title' => 'Kontakty',
|
---|
96 | 'Table' => 'Contact',
|
---|
97 | 'Items' => array(
|
---|
98 | 'Category' => array('Type' => 'TContactCategory', 'Caption' => 'Druh', 'Default' => ''),
|
---|
99 | 'Value' => array('Type' => 'String', 'Caption' => 'Hodnota', 'Default' => ''),
|
---|
100 | 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => '', 'Null' => true),
|
---|
101 | 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subject', 'Default' => '', 'Null' => true),
|
---|
102 | 'Description' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
|
---|
103 | 'Receive' => array('Type' => 'Boolean', 'Caption' => 'Přijímat zprávy', 'Default' => '0'),
|
---|
104 | ),
|
---|
105 | ));
|
---|
106 | $this->System->FormManager->RegisterClass('ContactCategory', array(
|
---|
107 | 'Title' => 'Druh kontaktu',
|
---|
108 | 'Table' => 'ContactCategory',
|
---|
109 | 'Items' => array(
|
---|
110 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
111 | 'Items' => array('Type' => 'TContactListCategory', 'Caption' => 'Kontakty'),
|
---|
112 | ),
|
---|
113 | ));
|
---|
114 | $this->System->FormManager->RegisterFormType('TContact', array(
|
---|
115 | 'Type' => 'Reference',
|
---|
116 | 'Table' => 'Contact',
|
---|
117 | 'Id' => 'Id',
|
---|
118 | 'Name' => 'Value',
|
---|
119 | 'Filter' => '1',
|
---|
120 | ));
|
---|
121 | $this->System->FormManager->RegisterFormType('TSubject', array(
|
---|
122 | 'Type' => 'Reference',
|
---|
123 | 'Table' => 'Subject',
|
---|
124 | 'Id' => 'Id',
|
---|
125 | 'Name' => 'Name',
|
---|
126 | 'Filter' => '1',
|
---|
127 | ));
|
---|
128 | $this->System->ModuleManager->Modules['IS']->RegisterDashboardItem('Subject',
|
---|
129 | array('ModuleSubject', 'ShowDashboardItem'));
|
---|
130 | }
|
---|
131 |
|
---|
132 | function DoInstall()
|
---|
133 | {
|
---|
134 | $this->Database->query("CREATE TABLE IF NOT EXISTS `Subject` (
|
---|
135 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
136 | `Name` varchar(64) NOT NULL DEFAULT '',
|
---|
137 | `AddressStreet` varchar(64) NOT NULL DEFAULT '',
|
---|
138 | `AddressTown` varchar(64) NOT NULL DEFAULT '',
|
---|
139 | `AddressPSC` int(11) NOT NULL DEFAULT '0',
|
---|
140 | `AddressCountry` int(11) NOT NULL,
|
---|
141 | `IC` varchar(32) NOT NULL,
|
---|
142 | `DIC` varchar(32) NOT NULL DEFAULT '',
|
---|
143 | `PayVAT` int(11) NOT NULL,
|
---|
144 | `MapPosition` int(11) DEFAULT NULL,
|
---|
145 | `WWW` varchar(255) NOT NULL,
|
---|
146 | `Note` varchar(255) NOT NULL,
|
---|
147 | PRIMARY KEY (`Id`)
|
---|
148 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
|
---|
149 | $this->Database->query("CREATE TABLE IF NOT EXISTS `Contact` (
|
---|
150 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
151 | `Category` int(11) NOT NULL,
|
---|
152 | `Value` varchar(255) NOT NULL,
|
---|
153 | `Subject` int(11) DEFAULT NULL,
|
---|
154 | `User` int(11) DEFAULT NULL,
|
---|
155 | `Description` varchar(255) NOT NULL,
|
---|
156 | `Receive` tinyint(1) NOT NULL,
|
---|
157 | PRIMARY KEY (`Id`)
|
---|
158 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
|
---|
159 | $this->System->Database->query("CREATE TABLE IF NOT EXISTS `ContactCategory` (
|
---|
160 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
161 | `Name` varchar(255) NOT NULL,
|
---|
162 | PRIMARY KEY (`Id`)
|
---|
163 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
|
---|
164 |
|
---|
165 | $this->Database->query("ALTER TABLE `Subject`
|
---|
166 | ADD CONSTRAINT `Subject_ibfk_1` FOREIGN KEY (`AddressCountry`) REFERENCES `Country` (`Id`),
|
---|
167 | ADD CONSTRAINT `Subject_ibfk_2` FOREIGN KEY (`MapPosition`) REFERENCES `MapPosition` (`Id`);");
|
---|
168 | $this->Database->query("ALTER TABLE `Contact`
|
---|
169 | ADD CONSTRAINT `Contact_ibfk_1` FOREIGN KEY (`Category`) REFERENCES `ContactCategory` (`Id`),
|
---|
170 | ADD CONSTRAINT `Contact_ibfk_2` FOREIGN KEY (`Subject`) REFERENCES `Subject` (`Id`),
|
---|
171 | ADD CONSTRAINT `Contact_ibfk_3` FOREIGN KEY (`User`) REFERENCES `User` (`Id`);");
|
---|
172 | }
|
---|
173 |
|
---|
174 | function DoUninstall()
|
---|
175 | {
|
---|
176 | $this->Database->query('DROP TABLE `Contact`');
|
---|
177 | $this->Database->query('DROP TABLE `ContactCategory`');
|
---|
178 | $this->Database->query('DROP TABLE `Subject`');
|
---|
179 | }
|
---|
180 |
|
---|
181 | function ShowDashboardItem()
|
---|
182 | {
|
---|
183 | $DbResult = $this->Database->select('Subject', 'COUNT(*)', '1');
|
---|
184 | $DbRow = $DbResult->fetch_row();
|
---|
185 | $Output = 'Subjektů: '.$DbRow['0'].'<br/>';
|
---|
186 | return($Output);
|
---|
187 | }
|
---|
188 | }
|
---|