source: trunk/finance/manage.php@ 340

Last change on this file since 340 was 340, checked in by chronos, 13 years ago
  • Přidáno: Moduk pro správu projektů.
  • Některé staré moduly přesunuty do podsložky Modules.
File size: 22.4 KB
Line 
1<?php
2include_once('../global.php');
3
4class FinanceManagePage extends Page
5{
6 var $FullTitle = 'Správa financí';
7 var $ShortTitle = 'Správa financí';
8
9 function Show()
10 {
11 if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');
12
13 if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
14 //$Operation = 'ImportOldData';
15 switch($Operation)
16 {
17 case 'Bills':
18 $Output = $this->BillManage();
19 break;
20 case 'ConvertPDFToFile':
21 $Output = $this->ConvertPDFDataToFiles();
22 break;
23 //case 'ImportOldData':
24 // $Output = $this->ImportOldData();
25 // break;
26 case 'NewDeviceForm':
27 $Output = $this->ShowNewDeviceForm();
28 break;
29 case 'NewDeviceInsert':
30 $Output = $this->ShowNewDeviceInsert();
31 break;
32 case 'NewDeviceHistoryForm':
33 $Output = $this->ShowNewDeviceHistoryForm();
34 break;
35 case 'NewDeviceHistoryInsert':
36 $Output = $this->ShowNewDeviceHistoryInsert();
37 break;
38 case 'NewPaymentInsert':
39 $Output = $this->ShowNewPaymentInsert();
40 break;
41 case 'NewPaymentForm':
42 $Output = $this->ShowNewPaymentForm();
43 break;
44 case 'NewInvoiceInsert':
45 $Output = $this->ShowNewInvoiceInsert();
46 break;
47 case 'NewInvoiceForm':
48 $Output = $this->ShowNewInvoiceForm();
49 break;
50 case 'Recalculate':
51 $Output = $this->System->Modules['Finance']->RecalculateSegmentParameters();
52 $Output .= $this->System->Modules['Finance']->RecalculateMemberPayment();
53 break;
54 case 'MonthlyPayment':
55 $Output = $this->ShowMonthlyPayment();
56 break;
57 case 'GenerateBills':
58 $Output = $this->GenerateBills();
59 break;
60 default:
61 $Output = '<a href="?Operation=NewDeviceForm">Přidat nové zařízení</a><br />';
62 $Output .= '<a href="?Operation=NewDeviceHistoryForm">Přidat nový záznam historie zařízení</a><br />';
63 $Output .= '<a href="?Operation=NewPaymentForm">Přidat novou platbu</a><br />';
64 $Output .= '<a href="?Operation=NewInvoiceForm">Přidat novou fakturu</a><br />';
65 $Output .= '<a href="?Operation=ConvertPDFToFile">Převést data z databáze do souborů</a><br />';
66 $Output .= '<a href="?Operation=Bills">Správa dokladů</a><br />';
67 $Output .= '<a href="?Operation=Recalculate">Přepočet financí</a><br />';
68 $Output .= '<a href="?Operation=MonthlyPayment">Měsíční vyúčtování</a><br />';
69 $Output .= '<a href="clenove.php">Seznam členů</a><br />';
70 $Output .= '<a href="zivnost.php">Živnost</a><br />';
71 $Output .= '<a href="?Operation=GenerateBills">Generovat chybějící doklady</a><br />';
72 $Output .= '<a href="import.php">Import plateb</a><br />';
73 }
74 return($Output);
75 }
76
77 function BillManage()
78 {
79 $Output = '';
80 if(array_key_exists('subject', $_GET))
81 {
82 $DbResult = $this->Database->select('FinanceBills', '*', 'Subject='.$_GET['subject']);
83 while($Item = $DbResult->fetch_array())
84 {
85 $Output .= '<a href="?Operation=Bills&amp;bill='.$Item['Id'].'">faktura '.$Item['Id'].'</a> <a href="?Operation=Bills&amp;billpdf='.$Item['Id'].'">Uložené PDF</a> <a href="?Operation=Bills&amp;billpdf2='.$Item['Id'].'">Generované PDF</a> <a href="?Operation=Bills&amp;regenerate='.$Item['Id'].'">Přegenerovat</a><br />';
86 }
87 } else
88 if(array_key_exists('billpdf', $_GET))
89 {
90 $Output .= $this->System->Modules['Bill']->ShowStoredBill($_GET['billpdf']);
91 } else
92 if(array_key_exists('billpdf2', $_GET))
93 {
94 $Output .= $this->System->Modules['Bill']->ShowGeneratedBill($_GET['billpdf2']);
95 } else
96 if(array_key_exists('regenerate', $_GET))
97 {
98 $Output .= $this->System->Modules['Bill']->RegeneratePDF($_GET['regenerate']);
99 } else
100 if(array_key_exists('bill', $_GET))
101 {
102 $Output .= $this->System->Modules['Bill']->GenerateBill($_GET['bill']);
103 } else
104 if(array_key_exists('generate', $_GET))
105 {
106 $Output .= $this->System->Modules['Bill']->CreateBill(1, array(array('Description' => 'Poplatek za služby', 'Price' => 1000, 'Quantity' => 1)), time(), time());
107 } else
108 {
109 //ShowHeader('Faktury', 'Faktury');
110 $Output .= 'Faktury:<br />';
111 $DbResult = $this->Database->select('Subject', '*', '1 ORDER BY Name');
112 while($Subject = $DbResult->fetch_array())
113 {
114 $Output .= '<a href="?Operation=Bills&amp;subject='.$Subject['Id'].'">'.$Subject['Name'].'</a><br />';
115 }
116 //ShowFooter();
117 }
118 return($Output);
119 }
120
121 function CheckAdvancesAndLiabilities($Subject)
122 {
123 global $LastInsertTime;
124
125 do {
126 $DbResult = $this->Database->select('FinanceAdvances', 'SUM(Value)', 'Subject='.$Subject.' AND Direction = "In"');
127 $DbRow = $DbResult->fetch_array();
128 $Advances = $DbRow[0];
129 $DbResult = $this->Database->select('FinanceClaimsLiabilities', '*', 'Subject='.$Subject.' AND TimePayment IS NULL AND Value > 0 ORDER BY TimeCreation LIMIT 1');
130 //echo($Database->error);
131 if($DbResult->num_rows > 0)
132 {
133 $OpenedClaim = $DbResult->fetch_array();
134 if($Advances > $OpenedClaim['Value'])
135 {
136 $this->Database->update('FinanceClaimsLiabilities', 'Id='.$OpenedClaim['Id'], array('TimePayment' => TimeToMysqlDateTime($LastInsertTime)));
137 $this->Database->insert('FinanceAdvances', array('Subject' => $OpenedClaim['Subject'], 'Value' => -$OpenedClaim['Value'], 'TimeCreation' => TimeToMysqlDateTime($LastInsertTime), 'CashFlowId' => $OpenedClaim['Id'], 'Direction' => 'In'));
138 //echo($Database->LastQuery);
139 } else break;
140 } else break;
141 } while(($Advances > $OpenedClaim['Value']));
142 }
143
144 function InsertLiability($Subject, $Value, $TimeCreation, $TimeDue, $Text, $DocumentLine)
145 {
146 global $LastInsertTime;
147
148 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
149 $this->Database->insert('FinanceClaimsLiabilities', array('Text' => $Text, 'Subject' => $Subject, 'TimeCreation' => TimeToMysqlDateTime($TimeCreation), 'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $Value, 'BillCode' => $BillCode));
150 $Output = '.'; //$this->Database->LastQuery.'<br />';
151 $LastInsertTime = $Time;
152 //$this->CheckAdvancesAndLiabilities($Subject);
153 return($Output);
154 }
155
156 function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine)
157 {
158 global $LastInsertTime;
159
160 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
161 $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
162 /*if($Value >= 0)
163 {
164 $this->Database->insert('FinanceAdvances', array('Subject' => $Subject, 'Value' => $Value, 'TimeCreation' => TimeToMysqlDateTime($Time), 'CashFlowId' => $this->Database->insert_id, 'Direction' => 'In'));
165 }
166 $LastInsertTime = $Time;
167 */
168 //$this->CheckAdvancesAndLiabilities($Subject);
169 }
170
171 function ShowNewDeviceForm()
172 {
173 $Form = new Form('NewNetworkDevice');
174 $Form->OnSubmit = '?Operation=NewDeviceInsert';
175 $Output = $Form->ShowEditForm();
176 return($Output);
177 }
178
179 function ShowNewDeviceInsert()
180 {
181 $Form = new Form('NewNetworkDevice');
182 $Form->LoadValuesFromForm();
183 $Form->SaveValuesToDatabase(0);
184 $Output = $this->SystemMessage('Finance', 'Zařízení vloženo.');
185 $this->System->Modules['Log']->NewRecord('Finance', 'NewDeviceInserted');
186 return($Output);
187 }
188
189 function ShowNewDeviceHistoryForm()
190 {
191 $Form = new Form('NewNetworkDeviceHistory');
192 $Form->OnSubmit = '?Operation=NewDeviceHistoryInsert';
193 $Output = $Form->ShowEditForm();
194 return($Output);
195 }
196
197 function ShowNewDeviceHistoryInsert()
198 {
199 $Form = new Form('NewNetworkDeviceHistory');
200 $Form->LoadValuesFromForm();
201 $Form->SaveValuesToDatabase(0);
202 $Output = $this->SystemMessage('Finance', 'Záznam historie zařízení vložen.');
203 $this->System->Modules['Log']->NewRecord('Finance', 'NewDeviceHistoryInserted');
204 return($Output);
205 }
206
207 function ShowNewPaymentForm()
208 {
209 $Form = new Form('NewPayment');
210 $Form->OnSubmit = '?Operation=NewPaymentInsert';
211 $Output = $Form->ShowEditForm();
212 return($Output);
213 }
214
215 function ShowNewPaymentInsert()
216 {
217 $Form = new Form('NewPayment');
218 $Form->LoadValuesFromForm();
219 $this->InsertMoney($Form->Values['Subject'], $Form->Values['Value'], $Form->Values['Cash'], $Form->Values['Taxable'], $Form->Values['Time'], $Form->Values['Text'], $Form->Values['DocumentLine']);
220 $Output = $this->SystemMessage('Finance', 'Platba vložena.');
221 $this->System->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
222 return($Output);
223 }
224
225 function ShowNewInvoiceForm()
226 {
227 $Form = new Form('NewInvoice');
228 $Form->OnSubmit = '?Operation=NewInvoiceInsert';
229 $Output = $Form->ShowEditForm();
230 return($Output);
231 }
232
233 function ShowNewInvoiceInsert()
234 {
235 $Form = new Form('NewInvoice');
236 $Form->LoadvaluesFromForm();
237 //print_r($Form->Values);
238 $this->InsertLiability($Form->Values['Subject'], $Form->Values['Value'], $Form->Values['TimeCreation'], $Form->Values['TimeDue'], $Form->Values['Text'], $Form->Values['DocumentLine']);
239 $Output = $this->SystemMessage('Finance', 'Faktura vložena..');
240 $this->System->Modules['Log']->NewRecord('Finance', 'NewInvoiceInserted');
241 return($Output);
242 }
243
244 function ConvertPDFDataToFiles()
245 {
246 $DbResult = $this->Database->query('SELECT * FROM FinanceBills');
247 while($Bill = $DbResult->fetch_assoc())
248 {
249 file_put_contents('doklady/doklad_'.$Bill['id'].'.pdf', $Bill['pdf']);
250 echo($Bill['id'].',');
251 }
252 }
253
254 function CheckPDFFiles()
255 {
256 global $InvoiceGenerator;
257
258 $DbResult = $this->Database->query('SELECT * FROM FinanceBills');
259 while($Bill = $DbResult->fetch_assoc())
260 {
261 file_put_contents('doklady2/doklad-'.$Bill['id'].'.pdf', file_get_contents('doklady/doklad-'.$Bill['id'].'.pdf'));
262 //echo($InvoiceGenerator->HasPDFFile($Bill['id']).',');
263 }
264 }
265
266 function GetBillingPeriod($Period)
267 {
268 $MonthCount = $this->System->Modules['Finance']->BillingPeriods[$Period]['MonthCount'];
269 $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y'));
270 $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y'));
271 return(array('From' => $PeriodFrom, 'To' => $PeriodTo, 'MonthCount' => $MonthCount));
272 }
273
274 function ShowMonthlyPayment()
275 {
276 if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');
277 $Output = '';
278
279 $Finance = &$this->System->Modules['Finance'];
280
281 // Načti poslední měsíční přehled a nastavení
282 $DbResult = $this->Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1');
283 $Overall = $DbResult->fetch_array();
284
285 $Output -= 'Datum: '.date('j.n.Y').'<br />';
286
287 $Datum = explode('-', $Overall['date']);
288 $Mesic = date('m') + 0;
289
290 $Output .= $Finance->RecalculateSegmentParameters();
291 $Output .= $Finance->LoadTariffs();
292 //$InvoiceGenerator->CustomGenerate();
293 $Output .= $Finance->RecalculateMemberPayment();
294
295 // Celkovy prehled
296 $DbResult = $this->Database->query('SELECT SUM(price) FROM network_devices WHERE used = 1');
297 $Row = $DbResult->fetch_row();
298 $TotalDeviceCost = $Row[0];
299 $Output .= 'Celková cena zařízení: Zařízení('.$TotalDeviceCost;
300
301 $DbResult = $this->Database->query('SELECT SUM(price) FROM network_segments');
302 $Row = $DbResult->fetch_row();
303 $TotalSegmentDeviceCost = $Row[0];
304 $Output .= '), Segmenty('.$TotalSegmentDeviceCost;
305
306 $DbResult = $this->Database->query('SELECT SUM(NetworkDevice) FROM MemberPayment');
307 $Row = $DbResult->fetch_row();
308 $TotalMemberDeviceCost = $Row[0];
309 $Output .= '), Členové('.$TotalMemberDeviceCost.')<br />';
310
311 $DbResult = $this->Database->query('SELECT SUM(Cash) FROM MemberPayment');
312 $Row = $DbResult->fetch_row();
313 $TotalMemberCash = $Row[0];
314 $Output .= 'Stav pokladny: Členové('.$TotalMemberCash.')';
315
316 $DbResult = $this->Database->query('SELECT SUM(consumption) FROM network_devices WHERE used=1');
317 $Row = $DbResult->fetch_row();
318 $TotalConsumption = $Row[0];
319 $TotalConsumptionCost = $Finance->W2Kc($TotalConsumption);
320
321 $SpravaCelkem = $Finance->Sprava * $Finance->SpravaUsers;
322 $Output .= 'Kontrola placení (Zaplaceno-Sprava-Internet): '.$Finance->TotalPaid.'-'.$SpravaCelkem.'-'.$Finance->Internet.'='.($Finance->TotalPaid - $SpravaCelkem - $Finance->Internet).'<br />';
323
324 // Zkontrolovat odečtení měsíčního poplatku
325 //$Mesic = '1';
326 $Output .= 'Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic.'<br />';
327 if($Mesic != $Datum[1])
328 {
329 $Output .= 'Odečítám měsíční poplatek...<br />';
330
331 // Generuj účetní položky
332 $DbResult = $this->Database->query('SELECT Member.*, MemberPayment.MonthlyTotal, UNIX_TIMESTAMP(Member.BillingPeriodLastDate), Subject.Name AS SubjectName FROM MemberPayment JOIN Member ON Member.Id=MemberPayment.Member JOIN Subject ON Subject.Id=Member.Subject');
333 while($Member = $DbResult->fetch_assoc())
334 {
335 $Output .= $Member['SubjectName'].': ';
336 //$Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)'] = MysqlDateTimeToTime('2009-04-01 1:1:1');
337 $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']);
338 if($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)'])
339 {
340 $this->Database->update('Member', 'Id='.$Member['Id'], array('BillingPeriod' => $Member['BillingPeriodNext'], 'InternetTariffCurrentMonth' => $Member['InternetTariffNextMonth']));
341 $Member['BillingPeriod'] = $Member['BillingPeriodNext'];
342 $Member['InternetTariffCurrentMonth'] = $Member['InternetTariffNextMonth'];
343 }
344 $Period = $this->GetBillingPeriod($Member['BillingPeriod']);
345 $PayPerPeriod = $Member['MonthlyTotal'] * $Period['MonthCount'];
346 if(($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']) and ($Member['InternetTariffCurrentMonth'] != 6) and ($PayPerPeriod > 0) and
347 ($Member['Blocked'] == 0))
348 {
349 //echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' ');
350 $TimePeriodText = date('j.n.Y', $Period['From']).' - '.date('j.n.Y', $Period['To']);
351 $Output .= $TimePeriodText.': '.$Member['MonthlyTotal'].' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />';
352 $BillCode = $Finance->GetNextDocumentLineNumber(6); // Faktury vydané
353 $BillId = $this->System->Modules['Bill']->CreateBill($Member['Subject'], array(array('Description' => 'Připojení k síti', 'Price' => $PayPerPeriod, 'Quantity' => 1)), time(), time() + 3600 * 24 * 15, $BillCode);
354 $this->Database->insert('FinanceClaimsLiabilities', array('Value' => $PayPerPeriod, 'Subject' => $Member['Subject'], 'TimeCreation' => 'NOW()', 'TimeDue' => 'DATE_ADD(NOW(), INTERVAL 15 DAY)', 'Text' => 'Služby za období '.$TimePeriodText, 'Bill' => $BillId, 'BillCode' => $BillCode));
355 $Output .= $this->SendPaymentEmail($Member['Id']);
356 $this->Database->update('Member', 'Id='.$Member['Id'], array('BillingPeriodLastDate' => TimeToMysqlDateTime($Period['To'])));
357 } else $Output .= '<br />';
358 }
359
360 // Update finance charge
361 $Output .= 'Měním aktuální parametry sítě...<br>';
362 $this->Database->delete('finance_charge', 'period = 0');
363 $DbResult = $this->Database->select('finance_charge', '*', 'period = 1');
364 $Charge = $DbResult->fetch_assoc();
365 //print_r($Charge);
366 $DbResult = $this->Database->insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'], 'internet_speed' => $Charge['internet_speed'], 'internet_speed_reserve' => $Charge['internet_speed_reserve'], 'administration_per_user' => $Charge['administration_per_user'], 'kWh' => $Charge['kWh'], 'base_speed_element' => $Charge['base_speed_element'], 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice']));
367
368 $Output .= 'Přidávám měsíční přehled...<br />';
369 $this->Database->insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Finance->Internet, 'kWh' => $Finance->kWh, 'administration' => $Finance->Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $TotalConsumptionCost, 'total_paid' => $Finance->TotalPaid, 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'], 'member_count' => $Finance->InternetUsers));
370
371 // Update tarrifs
372 $Output .= 'Měním aktuální tarify....<br>';
373 $DbResult = $this->Database->select('FinanceTariff', '*', '`ReplaceId` IS NOT NULL');
374 while($Tariff = $DbResult->fetch_array())
375 {
376 $this->Database->update('FinanceTariff', 'Id='.$Tariff['ReplaceId'], array('Name' => $Tariff['Name'],
377 'UploadAsymmetry' => $Tariff['UploadAsymmetry'], 'MemberCount' => $Tariff['MemberCount'],
378 'Group' => $Tariff['Group'], 'SpeedMin' => $Tariff['SpeedMin'],
379 'SpeedMax' => $Tariff['SpeedMax'], 'Price' => $Tariff['Price']));
380 }
381 $this->Database->delete('FinanceTariff', '`ReplaceId` IS NOT NULL');
382
383 $Finance->RecalculateMemberPayment();
384 //CreateMonthlyOverallBill();
385 //$Finance->RecalculateUsersFinance();
386
387 // Restart traffic shaping
388 //$this->Database->update('NetworkConfiguration', 'Id = 3', array('Changed' => 1));
389 }
390 return($Output);
391 }
392
393 function SendPaymentEmail($MemberId)
394 {
395 global $Config;
396
397 $DbResult = $this->Database->select('Member', '*', 'Id='.$MemberId);
398 $Member = $DbResult->fetch_assoc();
399
400 $DbResult = $this->Database->select('MemberPayment', '*', 'Member='.$MemberId);
401 $MemberPayment = $DbResult->fetch_assoc();
402
403 $DbResult = $this->Database->select('Subject', 'Name', 'Id='.$Member['Subject']);
404 $Subject = $DbResult->fetch_assoc();
405
406 $DbResult = $this->Database->select('User', '*', 'Id='.$Member['ResponsibleUser']);
407 $User = $DbResult->fetch_assoc();
408
409 if($User['Email'] != '')
410 {
411 $Title = 'Pravidelné vyúčtování služeb';
412 $Content = 'Vyúčtovaní subjektu <strong>'.$Subject['Name'].'</strong> zastoupeného uživatelem <strong>'.$User['Name'].'</strong> ke dni <strong>'.$this->System->HumanDate(time()).'</strong>.<br /><br />'."\n".
413 'Váš aktuální tarif: <strong>'.$this->System->Modules['Finance']->Tariffs[$Member['InternetTariffCurrentMonth']]['Name'].' '.$this->System->AddPrefixMultipliers($this->System->Modules['Finance']->Tariffs[$Member['InternetTariffCurrentMonth']]['SpeedMax'], 'bit/s', 3, 'Binary').'</strong><br />'."\n".
414 'Vaše platební období: <strong>'.$this->System->Modules['Finance']->BillingPeriods[$Member['BillingPeriod']]['Name'].'</strong><br />'."\n".
415 'Pravidelná platba za období: <strong>'.$MemberPayment['MonthlyTotal'].' Kč</strong><br />'."\n".
416 'Stav vašeho účtu: <strong>'.($MemberPayment['Cash'] - $MemberPayment['MonthlyTotal']).' Kč</strong><br /><br />'."\n";
417 $Content .= 'Nové finanční operace:<br/>'.
418 '<table style="margin-left: auto; margin-right: auto; border-style: solid; border-width: 1px; border-collapse: collapse;"><tr><th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Čas</th><th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center;; font-weight: bold;">Popis</th><th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center;; font-weight: bold;">Částka [Kč]</th></tr>'."\n";
419 //$Member['BillingPeriodLastDate'] = '2009-04-01';
420 $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, Value AS Value, Bill FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '.
421 '(SELECT Text, TimeCreation as Time, -Value as Value, Bill FROM FinanceClaimsLiabilities WHERE (Subject='.$Member['Subject'].')) ORDER BY Time DESC) AS T1 WHERE (T1.Time > "'.$Member['BillingPeriodLastDate'].'")');
422 while($DbRow = $DbResult->fetch_assoc())
423 {
424 $Content .= '<tr><td style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center;">'.HumanDate($DbRow['Time']).'</td>'.
425 '<td style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center;">'.$DbRow['Text'].'</td>'.
426 '<td style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center;">'.$DbRow['Value'].'</td></tr>'."\n";
427 }
428 $Content .= '</table><br />'."\n".
429 'Pro aktuální informace, prohlížení elektronických dokladů a možnost změny údajů se prosím přihlašte na stránkách <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'</a>.<br /><br />'."\n";
430
431 $Content .= '<br />Tento email je generován automaticky. V případě zjištění nesrovnalostí napište zpět.';
432 $AdditionalHeaders = 'To: =?UTF-8?B?'.base64_encode($User['Name']).'?= <'.$User['Email'].">\n".'From: =?UTF-8?B?'.base64_encode($Config['Web']['Title']).'?='." <".$Config['Web']['AdminEmail'].">\n";
433 $this->System->AddEmailToQueue($User['Email'], $Title, $Content, $AdditionalHeaders);
434 $Output = '';
435 } else $Output = 'Uživatel '.$User['Name'].' nemá email.';
436 }
437
438 function GenerateBills()
439 {
440 // FinanceClaimsLiablities
441 $DbResult = $this->Database->query('SELECT * FROM FinanceClaimsLiabilities WHERE (BillCode <> "") AND (Value >= 0) AND (Bill = 0)');
442 while($Row = $DbResult->fetch_assoc())
443 {
444 $BillId = $this->System->Modules['Bill']->CreateBill($Row['Subject'], array(array('Description' => $Row['Text'], 'Price' => $Row['Value'], 'Quantity' => 1)), MysqlDateTimeToTime($Row['TimeCreation']), MysqlDateTimeToTime($Row['TimeDue']), $Row['BillCode']);
445 $this->Database->update('FinanceClaimsLiabilities', 'Id='.$Row['Id'], array('Bill' => $BillId));
446 echo('.');
447 }
448
449 // FinanceOperations
450 }
451}
452
453$System->AddModule(new FinanceManagePage());
454$System->Modules['FinanceManagePage']->GetOutput();
455
456?>
Note: See TracBrowser for help on using the repository browser.