source: trunk/Modules/Finance/UserState.php@ 888

Last change on this file since 888 was 888, checked in by chronos, 4 years ago
  • Modified: More static types added.
File size: 7.8 KB
Line 
1<?php
2
3class PageFinanceUserState extends Page
4{
5 function __construct(System $System)
6 {
7 parent::__construct($System);
8 $this->FullTitle = 'Stav financí účastníka';
9 $this->ShortTitle = 'Stav financí';
10 $this->ParentClass = 'PageUser';
11 }
12
13 function ShowFinanceOperation(int $Subject): string
14 {
15 $UserOperationTableQuery = '((SELECT `Text`, `Time`, `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo`, `DocumentLineCode`.`Name` AS `BillName` '.
16 'FROM `FinanceOperation` '.
17 'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceOperation`.`BillCode` '.
18 'WHERE (`Subject`='.$Subject['Id'].') '.
19 ') UNION ALL '.
20 '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ",") FROM `FinanceInvoiceItem` WHERE `FinanceInvoice`=`FinanceInvoice`.`Id`) AS `Text`, '.
21 '`Time`, -`Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo`, `DocumentLineCode`.`Name` AS `BillName` FROM `FinanceInvoice` '.
22 'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceInvoice`.`BillCode` '.
23 'WHERE (`Subject`='.$Subject['Id'].') AND (`VisibleToUser` = 1)))';
24
25 $Output = '<div style="text-align:center">Výpis finančních operací</div>';
26 $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$UserOperationTableQuery.' AS `T1`');
27 $DbRow = $DbResult->fetch_row();
28 $PageList = GetPageList('FinanceOperation', $DbRow[0]);
29
30 $Output .= $PageList['Output'];
31 $Output .= '<table class="WideTable" style="font-size: small;">';
32
33 $TableColumns = array(
34 array('Name' => 'Time', 'Title' => 'Datum'),
35 array('Name' => 'Text', 'Title' => 'Popis'),
36 array('Name' => 'Value', 'Title' => 'Změna [Kč]'),
37 array('Name' => 'State', 'Title' => 'Zůstatek [Kč]'),
38 array('Name' => 'PeriodFrom', 'Title' => 'Období'),
39 array('Name' => 'BillCode', 'Title' => 'Doklad'),
40 );
41 $Order = GetOrderTableHeader('FinanceOperation', $TableColumns, 'Time', 1);
42 $Output .= $Order['Output'];
43
44 $StateQuery = 'SELECT SUM(`T2`.`Value`) FROM '.$UserOperationTableQuery.
45 ' AS `T2` WHERE `T2`.`Time` <= `T1`.`Time` ';
46 $Query = 'SELECT *, ('.$StateQuery.') AS `State` FROM '.$UserOperationTableQuery.' AS `T1` '.$Order['SQL'].$PageList['SQLLimit'];
47
48 $DbResult = $this->Database->query($Query);
49 $SumValue = 0;
50 while ($Row = $DbResult->fetch_assoc())
51 {
52 $Row['State'] = round($Row['State'], 2);
53 if ($Row['State'] > 0) $Row['State'] = '<span style="color:green;">'.$Row['State'].'</span>';
54 if ($Row['State'] < 0) $Row['State'] = '<span style="color:red;">'.$Row['State'].'</span>';
55 if ($Row['Value'] == -0) $Row['Value'] = 0;
56 if ($Row['Value'] > 0) $Row['Value'] = '+'.$Row['Value'];
57 if ($Row['BillName'] == '') $Row['BillName'] = 'PDF';
58 if ($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/file?id='.$Row['File']).'">'.$Row['BillName'].'</a>';
59 else $Invoice = NotBlank($Row['BillName']);
60 if ($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
61 else $Period = '&nbsp;';
62 $Output .= '<tr><td style="text-align: right;">'.HumanDate($Row['Time']).'</td>'.
63 '<td style="text-align: left;">'.$Row['Text'].'</td>'.
64 '<td style="text-align: right;">'.round($Row['Value'], 2).'</td>'.
65 '<td style="text-align: right;">'.$Row['State'].'</td>'.
66 '<td>'.$Period.'</td>'.
67 '<td>'.$Invoice.'</td></tr>';
68 $SumValue = $SumValue + $Row['Value'];
69 }
70 $Output .= '</table>';
71 $Output .= $PageList['Output'];
72 return $Output;
73 }
74
75 function Show(): string
76 {
77 $Finance = &ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance;
78 $Finance->LoadMonthParameters(0);
79
80 // Determine which customer should be displayed
81 if (array_key_exists('i', $_GET))
82 {
83 if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Finance', 'Manage')) return 'Nemáte oprávnění';
84 $CustomerId = $_GET['i'];
85 } else
86 {
87 if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Finance', 'DisplaySubjectState')) return 'Nemáte oprávnění';
88 $UserId = ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'];
89 $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` WHERE `User`='.$UserId.' LIMIT 1');
90 if ($DbResult->num_rows > 0)
91 {
92 $CustomerUserRel = $DbResult->fetch_assoc();
93 $CustomerId = $CustomerUserRel['Customer'];
94 } else return $this->SystemMessage('Chyba', 'Nejste zákazníkem');
95 }
96
97 // Load customer info
98 $DbResult = $this->Database->query('SELECT * FROM `Member` WHERE `Id`='.$CustomerId);
99 if ($DbResult->num_rows == 1)
100 {
101 $Customer = $DbResult->fetch_assoc();
102 } else return $this->SystemMessage('Položka nenalezena', 'Zákazník nenalezen');
103
104
105 // Load subject info
106 $DbResult = $this->Database->query('SELECT * FROM `Subject` WHERE `Id`='.$Customer['Subject']);
107 if ($DbResult->num_rows == 1)
108 {
109 $Subject = $DbResult->fetch_assoc();
110 } else return $this->SystemMessage('Položka nenalezena', 'Subjekt nenalezen');
111
112
113 $Output = '<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td valign="top">';
114
115 // Account state
116 $UserOperationTableQuery = '((SELECT `Text`, `Time`, `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
117 'FROM `FinanceOperation` WHERE (`Subject`='.$Subject['Id'].')) UNION ALL '.
118 '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ",") FROM `FinanceInvoiceItem` WHERE `FinanceInvoice`=`FinanceInvoice`.`Id`) AS `Text`, '.
119 '`Time`, -`Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')) ORDER BY `Time` DESC) AS `T1`';
120 $DbResult = $this->Database->query('SELECT SUM(`T1`.`Value`) AS `Total` FROM '.$UserOperationTableQuery);
121 $DbRow = $DbResult->fetch_array();
122 $Total = $DbRow['Total'];
123 $Output .= 'Stav účtu: <strong>'.round($Total, 2).' Kč</strong><br /><br />';
124
125 // Tabulka operaci
126 $Output .= $this->ShowFinanceOperation($Subject);
127
128 $Output .= '</td><td valign="top">';
129
130 $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '.
131 'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
132 'WHERE (FinanceBankAccount.`Subject`='.$this->System->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
133 $SubjectFromAccount = $DbResult->fetch_assoc();
134 $Account = $SubjectFromAccount['NumberFull'];
135
136 $Output .= 'Účet pro platby: <strong>'.$Account.'</strong><br/>';
137 $Output .= 'Variabilní symbol pro platby: <strong>'.$Subject['Id'].'</strong><br/>';
138 $Output .= 'Subjekt: <strong>'.$Subject['Name'].'</strong><br/>';
139 $Output .= '<br/>';
140
141 $Total = 0;
142 $Output .= 'Rozpis měsíčního poplatku:<br><table class="WideTable">'.
143 '<tr><th>Služba</th><th>Cena [Kč]</th></tr>';
144 $DbResult = $this->Database->query('SELECT `Service`.`Name`, `Service`.`Price` FROM `ServiceCustomerRel` '.
145 'LEFT JOIN `Service` ON `Service`.`Id`=`ServiceCustomerRel`.`Service` '.
146 'WHERE (`ServiceCustomerRel`.`Customer`='.$Customer['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL)');
147 while ($DbRow = $DbResult->fetch_assoc())
148 {
149 $Output .= '<tr><td>'.$DbRow['Name'].'</td><td>'.$DbRow['Price'].'</td></tr>';
150 $Total += $DbRow['Price'];
151 }
152
153 $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$Total.'</strong></td></tr></table>';
154 //echo('Tarif pro příští měsíc: '.$Tarify[$Row2['inet_tarif_next']]['name'].'<br><br>');
155 $Output .= '<br />';
156
157 $Output .= '</td></tr></table>';
158 return $Output;
159 }
160}
Note: See TracBrowser for help on using the repository browser.