source: trunk/finance/user_state.php@ 498

Last change on this file since 498 was 498, checked in by chronos, 12 years ago
  • Upraveno: Přepracováno generování PDF dokladů. Nyní pro každý typ dokladu se definuje samostatná třída odvozená ze třídy Bill. Údaje se načítají přímo ze zdrojových tabulek namísto vytváření duplicitních dat v tabulce FinanceBills. Doklady jsou identifikovány jako soubor dle tabulky File.
  • Upraveno: Fronta emailů a seznam síťových služeb lze nyní upravovat přímo ze sekce Správa dat.
File size: 7.9 KB
Line 
1<?php
2
3include_once('../Common/Global.php');
4
5class FinanceUserState extends Page
6{
7 var $FullTitle = 'Stav financí účastníka';
8 var $ShortTitle = 'Stav financí';
9
10 function Show()
11 {
12 $Finance = &$this->System->Modules['Finance'];
13 $this->System->Modules['Finance']->LoadTariffs(1);
14
15 if(array_key_exists('Subject', $_GET))
16 {
17 if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');
18 $DbResult = $this->Database->query('SELECT * FROM Subject WHERE Id='.$_GET['Subject']);
19 $Subject = $DbResult->fetch_assoc();
20 } else
21 {
22 if(!$this->System->Modules['User']->CheckPermission('Finance', 'DisplaySubjectState')) return('Nemáte oprávnění');
23 $UserId = $this->System->Modules['User']->User['Id'];
24 $DbResult = $this->Database->query('SELECT Customer FROM UserCustomerRel WHERE User='.$UserId.' LIMIT 1');
25 if($DbResult->num_rows > 0)
26 {
27 $CustomerUserRel = $DbResult->fetch_assoc();
28 $DbResult = $this->Database->query('SELECT * FROM Subject WHERE Id=(SELECT Subject FROM Member WHERE Id='.$CustomerUserRel['Customer'].')');
29 $Subject = $DbResult->fetch_assoc();
30 } else return($this->SystemMessage('Chyba', 'Nejste zákazníkem'));
31 }
32
33 if(!array_key_exists('show', $_GET)) $_GET['show'] = '';
34 $DbResult = $this->Database->query('SELECT Member.*, MemberPayment.MonthlyPlus AS MonthlyPlus '.
35 'FROM Member LEFT JOIN MemberPayment ON MemberPayment.Member=Member.Id WHERE Member.Subject='.$Subject['Id']);
36 $Member = $DbResult->fetch_assoc();
37 $Output = '<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td valign="top">';
38
39 if(array_key_exists('year', $_GET))
40 {
41 $DbResult = $this->Database->query('SELECT * FROM FinanceYear WHERE Id='.addslashes($_GET['year'] * 1));
42 } else
43 {
44 $DbResult = $this->Database->query('SELECT * FROM FinanceYear ORDER BY Year DESC LIMIT 1');
45 }
46 $FinanceYearSelected = $DbResult->fetch_assoc();
47 $YearWhere = ' WHERE (Time >= "'.$FinanceYearSelected['DateStart'].'") AND (Time <= "'.$FinanceYearSelected['DateEnd'].'")';
48
49
50 // Year list
51 if(array_key_exists('Subject', $_GET)) $SubjectParam = '&amp;Subject='.($_GET['Subject'] * 1);
52 else $SubjectParam = '';
53 $Output .= 'Roky: ';
54 $DbResult = $this->Database->query('SELECT * FROM FinanceYear WHERE Year >= '.
55 substr($Member['MembershipDate'], 0, strpos($Member['MembershipDate'], '-')));
56 while($FinanceYear = $DbResult->fetch_assoc())
57 {
58 $Year = '<a href="?year='.$FinanceYear['Id'].$SubjectParam.'">'.$FinanceYear['Year'].'</a> ';
59 if($FinanceYear['Id'] == $FinanceYearSelected['Id']) $Output .= '<strong>'.$Year.'</strong>';
60 else $Output .= $Year;
61 }
62 $Output .= '<br/><br/>';
63
64 // Account state
65 $UserOperationTableQuery = '((SELECT Text, Time, Value AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
66 'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '.
67 '(SELECT (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoice=FinanceInvoice.Id) AS Text, '.
68 'TimeCreation as Time, -Value as Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')) ORDER BY Time DESC) AS T1';
69 $DbResult = $this->Database->query('SELECT SUM(T1.Value) AS Total FROM '.$UserOperationTableQuery);
70 $DbRow = $DbResult->fetch_array();
71 $Total = $DbRow['Total'];
72 $Output .= 'Stav účtu: <strong>'.$Total.' Kč</strong<br /><br /><br/>';
73
74
75 // Tabulka operaci
76 $Output .= 'Výpis operací pro subjekt '.$Subject['Name'].':<br />';
77 $Output .= '<table style="font-size: smaller;" class="WideTable"><tr>'.
78 '<th>Datum</th><th>Popis</th><th>Částka</th><th>Období</th><th>Doklad</th></tr>';
79 $Operations = array();
80 $DbResult = $this->Database->query('SELECT T1.* FROM '.$UserOperationTableQuery.$YearWhere);
81 while($DbRow = $DbResult->fetch_array())
82 $Operations[] = $DbRow;
83 $SumValue = 0;
84 foreach($Operations as $Row)
85 {
86 if($Row['Value'] == -0) $Row['Value'] = 0;
87 if($Row['Value'] > 0) $Row['Value'] = '+'.$Row['Value'];
88 if($Row['BillCode'] == '') $Row['BillCode'] = 'PDF';
89 if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/FileDownload.php?id='.$Row['File']).'">'.$Row['BillCode'].'</a>';
90 else $Invoice = '&nbsp;';
91 if($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
92 else $Period = '&nbsp;';
93 $Output .= '<tr><td style="text-align: right;">'.HumanDate($Row['Time']).'</td>'.
94 '<td style="text-align: left;">'.$Row['Text'].'</td>'.
95 '<td style="text-align: right;">'.$Row['Value'].'</td>'.
96 '<td style="text-align: center;">'.$Period.'</td>'.
97 '<td style="text-align: center;">'.$Invoice.'</td></tr>';
98 $SumValue = $SumValue + $Row['Value'];
99 }
100 $Output .= '<tr><td style="text-align: right;" colspan="2"><strong>Celkem za rok</strong></td>'.
101 '<td style="text-align: right;"><strong>'.$SumValue.'</strong></td>'.
102 '<td style="text-align: center;">&nbsp;</td>'.
103 '<td style="text-align: center;">&nbsp;</td></tr>';
104
105
106 //echo('<tr><td>&nbsp;</td><td>-'.$Row2['network_device'].'</td><td>Proměnná cena za zařízení</td></tr>
107 $Output .= '</table>';
108 $Output .= '</td><td valign="top">';
109
110 $Output .= 'Variabilní symbol pro platby: <strong>'.$Subject['Id'].'</strong><br><br>';
111
112 $Total = 0;
113 $Output .= 'Rozpis měsíčního poplatku:<br><table class="WideTable">'.
114 '<tr><th>Služba</th><th>Cena [Kč]</th></tr>';
115 $DbResult = $this->Database->query('SELECT Service.Name, Service.Price FROM ServiceCustomerRel '.
116 'LEFT JOIN Service ON Service.Id=ServiceCustomerRel.Service '.
117 'WHERE (ServiceCustomerRel.Customer='.$Member['Id'].') AND (ServiceCustomerRel.Action IS NULL)');
118 while($DbRow = $DbResult->fetch_assoc())
119 {
120 $Output .= '<tr><td>'.$DbRow['Name'].'</td><td>'.$DbRow['Price'].'</td></tr>';
121 $Total += $DbRow['Price'];
122 }
123
124 if($Member['Hire'] != 0)
125 {
126 $Output .= '<tr><td>Nájem</td><td>'.(-$Member['Hire']).'</td></tr>';
127 $Total -= $Member['Hire'];
128 }
129 if($Member['MonthlyPlus'] != 0)
130 {
131 $Output .= '<tr><td>Příjem za spotřebu</td><td>'.(-$Member['MonthlyPlus']).'</td></tr>';
132 $Total -= $Member['MonthlyPlus'];
133 }
134 $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$Total.'</strong></td></tr></table>';
135 //echo('Tarif pro příští měsíc: '.$Tarify[$Row2['inet_tarif_next']]['name'].'<br><br>');
136 $Output .= '<br />';
137
138 if($Member['MonthlyPlus'] != 0)
139 {
140 $Output .= 'Měsíční příjem za spotřebu zařízení umístěných u uživatele:<br>';
141 $Output .= '<table class="WideTable"><tr><th>Název zařízení</th><th>Spotřeba [W]</th><th>Příjem [Kč]</th></tr>';
142 $DbResult = $this->Database->query('SELECT Product.Name AS Name, Product.Consumption AS Consumption '.
143 'FROM StockItem JOIN Product ON Product.Id = StockItem.Product '.
144 'WHERE (StockItem.Location='.$Member['Id'].') AND (StockItem.TimeElimination IS NULL)');
145 $TotalW = 0;
146 $TotalPrice = 0;
147 while($Row = $DbResult->fetch_assoc())
148 {
149 $Output .= '<tr><td>'.$Row['Name'].'</td><td>'.$Row['Consumption'].'</td><td>'.$this->System->Modules['Finance']->W2Kc($Row['Consumption']).'</td></tr>';
150 $TotalW += $Row['Consumption'];
151 $TotalPrice += $this->System->Modules['Finance']->W2Kc($Row['Consumption']);
152 }
153 $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$TotalW.'</strong></td><td><strong>'.$TotalPrice.'</strong></td></tr>';
154 $Output .= '</table>';
155 }
156 $Output .= '</td></tr></table>';
157 return($Output);
158 }
159}
160
161$System->AddModule(new FinanceUserState());
162$System->Modules['FinanceUserState']->GetOutput();
163
164?>
Note: See TracBrowser for help on using the repository browser.