source: trunk/Modules/Subject/Subject.php@ 745

Last change on this file since 745 was 745, checked in by chronos, 10 years ago
  • Added: More appmodule install/uninstallation.
File size: 7.9 KB
Line 
1<?php
2
3class 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` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '.
39 'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`) 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` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
60 'AND (`FinanceOperation`.`ValueSign` = 1))'),
61 'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
62 'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
63 'AND (`FinanceOperation`.`ValueSign` = -1))'),
64 'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
65 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
66 ')'),
67 ),
68 ));
69 $this->System->FormManager->RegisterFormType('TContactCategory', array(
70 'Type' => 'Reference',
71 'Table' => 'ContactCategory',
72 'Id' => 'Id',
73 'Name' => 'Name',
74 'Filter' => '1',
75 ));
76 $this->System->FormManager->RegisterFormType('TContactListCategory', array(
77 'Type' => 'ManyToOne',
78 'Table' => 'Contact',
79 'Id' => 'Id',
80 'Ref' => 'Category',
81 'Filter' => '1',
82 ));
83 $this->System->FormManager->RegisterFormType('TContactListUser', array(
84 'Type' => 'ManyToOne',
85 'Table' => 'Contact',
86 'Id' => 'Id',
87 'Ref' => 'User',
88 'Filter' => '1',
89 ));
90 $this->System->FormManager->RegisterClass('Contact', array(
91 'Title' => 'Kontakty',
92 'Table' => 'Contact',
93 'Items' => array(
94 'Category' => array('Type' => 'TContactCategory', 'Caption' => 'Druh', 'Default' => ''),
95 'Value' => array('Type' => 'String', 'Caption' => 'Hodnota', 'Default' => ''),
96 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => '', 'Null' => true),
97 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subject', 'Default' => '', 'Null' => true),
98 'Description' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
99 'Receive' => array('Type' => 'Boolean', 'Caption' => 'Přijímat zprávy', 'Default' => '0'),
100 ),
101 ));
102 $this->System->FormManager->RegisterClass('ContactCategory', array(
103 'Title' => 'Druh kontaktu',
104 'Table' => 'ContactCategory',
105 'Items' => array(
106 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
107 'Items' => array('Type' => 'TContactListCategory', 'Caption' => 'Kontakty'),
108 ),
109 ));
110 $this->System->FormManager->RegisterFormType('TSubject', array(
111 'Type' => 'Reference',
112 'Table' => 'Subject',
113 'Id' => 'Id',
114 'Name' => 'Name',
115 'Filter' => '1',
116 ));
117 }
118
119 function DoInstall()
120 {
121 $this->Database->query("CREATE TABLE IF NOT EXISTS `Subject` (
122 `Id` int(11) NOT NULL AUTO_INCREMENT,
123 `Name` varchar(64) NOT NULL DEFAULT '',
124 `AddressStreet` varchar(64) NOT NULL DEFAULT '',
125 `AddressTown` varchar(64) NOT NULL DEFAULT '',
126 `AddressPSC` int(11) NOT NULL DEFAULT '0',
127 `AddressCountry` int(11) NOT NULL,
128 `IC` varchar(32) NOT NULL,
129 `DIC` varchar(32) NOT NULL DEFAULT '',
130 `PayVAT` int(11) NOT NULL,
131 `MapPosition` int(11) DEFAULT NULL,
132 `WWW` varchar(255) NOT NULL,
133 `Note` varchar(255) NOT NULL,
134 PRIMARY KEY (`Id`)
135) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
136 $this->Database->query("CREATE TABLE IF NOT EXISTS `Contact` (
137 `Id` int(11) NOT NULL AUTO_INCREMENT,
138 `Category` int(11) NOT NULL,
139 `Value` varchar(255) NOT NULL,
140 `Subject` int(11) DEFAULT NULL,
141 `User` int(11) DEFAULT NULL,
142 `Description` varchar(255) NOT NULL,
143 `Receive` tinyint(1) NOT NULL,
144 PRIMARY KEY (`Id`)
145) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
146 $this->System->Database->query("CREATE TABLE IF NOT EXISTS `ContactCategory` (
147 `Id` int(11) NOT NULL AUTO_INCREMENT,
148 `Name` varchar(255) NOT NULL,
149 PRIMARY KEY (`Id`)
150) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
151
152 $this->Database->query("ALTER TABLE `Subject`
153ADD CONSTRAINT `Subject_ibfk_1` FOREIGN KEY (`AddressCountry`) REFERENCES `Country` (`Id`),
154ADD CONSTRAINT `Subject_ibfk_2` FOREIGN KEY (`MapPosition`) REFERENCES `MapPosition` (`Id`);");
155 $this->Database->query("ALTER TABLE `Contact`
156 ADD CONSTRAINT `Contact_ibfk_1` FOREIGN KEY (`Category`) REFERENCES `ContactCategory` (`Id`),
157 ADD CONSTRAINT `Contact_ibfk_2` FOREIGN KEY (`Subject`) REFERENCES `Subject` (`Id`),
158 ADD CONSTRAINT `Contact_ibfk_3` FOREIGN KEY (`User`) REFERENCES `User` (`Id`);");
159 }
160
161 function DoUninstall()
162 {
163 $this->Database->query('DROP TABLE `Contact`');
164 $this->Database->query('DROP TABLE `ContactCategory`');
165 $this->Database->query('DROP TABLE `Subject`');
166 }
167}
Note: See TracBrowser for help on using the repository browser.