source: trunk/Modules/Finance/Manage.php@ 370

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