Changeset 639 for trunk/Modules/Finance/Manage.php
- Timestamp:
- Mar 16, 2014, 1:33:22 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Manage.php
r629 r639 6 6 var $ShortTitle = 'Správa financí'; 7 7 var $ParentClass = 'PageFinance'; 8 8 9 9 function Show() 10 10 { 11 11 $Output = ''; 12 if(!$this->System->User->CheckPermission('Finance', 'Manage')) 12 if(!$this->System->User->CheckPermission('Finance', 'Manage')) 13 13 return('Nemáte oprávnění'); 14 14 15 if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; 15 if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; 16 16 else $Operation = ''; 17 17 switch($Operation) … … 39 39 return($Output); 40 40 } 41 41 42 42 function GetBillingPeriod($Period) 43 43 { … … 46 46 $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y')); 47 47 return(array('From' => $PeriodFrom, 'To' => $PeriodTo, 'MonthCount' => $MonthCount)); 48 } 48 } 49 49 50 50 function ShowMonthlyPayment() … … 62 62 'FinanceBillingPeriod.Id=Member.BillingPeriodNext WHERE (Member.Blocked = 0)'. 63 63 'AND (Member.BillingPeriodNext > 1) AND (MemberPayment.MonthlyTotal != 0)'; 64 64 65 65 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$SQL.') AS T'); 66 66 $DbRow = $DbResult->fetch_row(); 67 $PageList = GetPageList($DbRow[0]); 67 $PageList = GetPageList($DbRow[0]); 68 68 69 69 $Output = $PageList['Output']; 70 70 $Output .= '<table class="WideTable" style="font-size: small;">'; 71 71 72 72 $TableColumns = array( 73 array('Name' => 'SubjectName', 'Title' => 'Jméno'), 74 array('Name' => 'Monthly', 'Title' => 'Platba'), 75 array('Name' => 'Cash', 'Title' => 'Kredit'), 76 array('Name' => 'LastDate', 'Title' => 'Poslední fakturace'), 77 array('Name' => 'ServicesNextMonth', 'Title' => 'Služby'), 78 array('Name' => 'BillingPeriodName', 'Title' => 'Perioda'), 73 array('Name' => 'SubjectName', 'Title' => 'Jméno'), 74 array('Name' => 'Monthly', 'Title' => 'Platba'), 75 array('Name' => 'Cash', 'Title' => 'Kredit'), 76 array('Name' => 'LastDate', 'Title' => 'Poslední fakturace'), 77 array('Name' => 'ServicesNextMonth', 'Title' => 'Služby'), 78 array('Name' => 'BillingPeriodName', 'Title' => 'Perioda'), 79 79 ); 80 80 $Order = GetOrderTableHeader($TableColumns, 'SubjectName', 0); … … 82 82 83 83 $Query = $SQL.' '.$Order['SQL'].$PageList['SQLLimit']; 84 84 85 85 $DbResult = $this->Database->query($Query); 86 while($Row = $DbResult->fetch_assoc()) 87 { 86 while($Row = $DbResult->fetch_assoc()) 87 { 88 88 $Output .= '<tr>'. 89 89 '<td>'.$Row['SubjectName'].'</td>'. … … 100 100 return($Output); 101 101 } 102 102 103 103 function InsertInvoice($Subject, $TimeCreation, $TimeDue, $Items, 104 104 $DocumentLine, $PeriodFrom, $PeriodTo) 105 105 { 106 106 global $LastInsertTime; 107 107 108 108 $Year = date('Y', $TimeCreation); 109 109 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year); … … 124 124 return($InvoiceId); 125 125 } 126 126 127 127 function ProduceInvoices() 128 128 { 129 129 $Output = ''; 130 130 131 131 // Generuj účetní položky 132 132 $DbResult = $this->Database->query('SELECT Member.*, MemberPayment.MonthlyTotal AS MonthlyTotal, '. … … 169 169 $MonthlyTotal -= $Member['MonthlyPlus']; 170 170 } 171 $PayPerPeriod = $MonthlyTotal * $Period['MonthCount']; 171 $PayPerPeriod = $MonthlyTotal * $Period['MonthCount']; 172 172 if($PayPerPeriod != 0) 173 173 { 174 174 $TimePeriodText = date('j.n.Y', $Period['From']).' - '.date('j.n.Y', $Period['To']); 175 175 $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />'; 176 $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS, 177 $InvoiceItems, INVOICE_OUT_DOC_LINE, $Period['From'], $Period['To']);178 176 $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS, 177 $InvoiceItems, DOC_LINE_INVOICE_OUT, $Period['From'], $Period['To']); 178 179 179 $Output .= $this->SendPaymentEmail($Member['Id']); 180 180 } else $Output .= '<br />'; 181 $this->Database->update('Member', 'Id='.$Member['Id'], 181 $this->Database->update('Member', 'Id='.$Member['Id'], 182 182 array('BillingPeriodLastDate' => TimeToMysqlDateTime($Period['To']))); 183 183 } else $Output .= '<br />'; 184 } 184 } 185 185 return($Output); 186 186 } 187 187 188 188 function TableUpdatePeriod($Table) 189 189 { … … 212 212 } 213 213 $this->Database->delete($Table, '`Action` IS NOT NULL'); 214 } 215 214 } 215 216 216 function ProcessMonthlyPayment() 217 217 { … … 221 221 $Finance = &$this->System->Modules['Finance']; 222 222 $Finance->LoadMonthParameters(0); 223 223 224 224 // Načti poslední měsíční přehled a nastavení 225 225 $DbResult = $this->Database->select('FinanceMonthlyOverall', '*', '1 ORDER BY Date DESC LIMIT 1'); … … 227 227 228 228 $Output -= 'Datum: '.date('j.n.Y').'<br />'; 229 229 230 230 $DateParts = explode('-', $Overall['Date']); 231 231 $MonthLast = $DateParts[1]; … … 242 242 $TotalDeviceCost = $Row[0]; 243 243 $Output .= 'Celková cena zařízení: Zařízení('.$TotalDeviceCost; 244 244 245 245 $DbResult = $this->Database->query('SELECT SUM(Price) FROM NetworkSegment'); 246 246 $Row = $DbResult->fetch_row(); 247 247 $TotalSegmentDeviceCost = $Row[0]; 248 248 $Output .= '), Segmenty('.$TotalSegmentDeviceCost; 249 249 250 250 $DbResult = $this->Database->query('SELECT SUM(NetworkDevice) FROM MemberPayment'); 251 251 $Row = $DbResult->fetch_row(); 252 252 $TotalMemberDeviceCost = $Row[0]; 253 253 $Output .= '), Členové('.$TotalMemberDeviceCost.')<br />'; 254 254 255 255 $DbResult = $this->Database->query('SELECT SUM(Cash) FROM MemberPayment'); 256 256 $Row = $DbResult->fetch_row(); 257 257 $TotalMemberCash = $Row[0]; 258 $Output .= 'Stav pokladny: Členové('.$TotalMemberCash.')'; 258 $Output .= 'Stav pokladny: Členové('.$TotalMemberCash.')'; 259 259 260 260 $DbResult = $this->Database->query('SELECT SUM(Product.Consumption) AS Consumption FROM StockItem '. … … 272 272 { 273 273 $Output .= 'Odečítám měsíční poplatek...<br />'; 274 $Output .= $this->ProduceInvoices(); 275 274 $Output .= $this->ProduceInvoices(); 275 276 276 // Update finance charge 277 277 $Output .= 'Měním aktuální parametry sítě...<br>'; … … 281 281 $DbResult = $this->Database->query('SELECT * FROM FinanceCharge WHERE Action IS NULL LIMIT 1'); 282 282 $Charge = $DbResult->fetch_assoc(); 283 $this->Database->insert('FinanceMonthlyOverall', array('Date' => 'NOW()', 284 'Money' => $Finance->Internet, 'kWh' => $Finance->kWh, 285 'Administration' => $Finance->Sprava, 'AdministrationTotal' => $SpravaCelkem, 286 'ConsumptionTotal' => $TotalConsumptionCost, 'TotalPaid' => $Finance->TotalPaid, 287 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 283 $this->Database->insert('FinanceMonthlyOverall', array('Date' => 'NOW()', 284 'Money' => $Finance->Internet, 'kWh' => $Finance->kWh, 285 'Administration' => $Finance->Sprava, 'AdministrationTotal' => $SpravaCelkem, 286 'ConsumptionTotal' => $TotalConsumptionCost, 'TotalPaid' => $Finance->TotalPaid, 287 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 288 288 'TopTariffPrice' => $Charge['TopTariffPrice'], 'MemberCount' => $Finance->InternetUsers)); 289 289 290 290 // Update services 291 291 $Output .= 'Aktualizuji služby....<br>'; 292 $this->TableUpdatePeriod('Service'); 292 $this->TableUpdatePeriod('Service'); 293 293 // Update customer service selections 294 294 $Output .= 'Aktualizuji výběr služeb zákazníků....<br>'; 295 $this->TableUpdatePeriod('ServiceCustomerRel'); 296 295 $this->TableUpdatePeriod('ServiceCustomerRel'); 296 297 297 $Finance->RecalculateMemberPayment(); 298 298 //CreateMonthlyOverallBill(); … … 300 300 301 301 // Restart traffic shaping 302 //$this->Database->update('NetworkConfiguration', 'Id = 3', array('Changed' => 1)); 302 //$this->Database->update('NetworkConfiguration', 'Id = 3', array('Changed' => 1)); 303 303 //flush(); 304 304 //$this->GenerateBills(); … … 306 306 return($Output); 307 307 } 308 308 309 309 function SendPaymentEmail($MemberId, $FileId = '') 310 310 { 311 311 global $Config; 312 312 313 313 $DbResult = $this->Database->select('Member', '*', 'Id='.$MemberId); 314 314 $Member = $DbResult->fetch_assoc(); 315 315 316 316 $DbResult = $this->Database->select('MemberPayment', '*', 'Member='.$MemberId); 317 $MemberPayment = $DbResult->fetch_assoc(); 317 $MemberPayment = $DbResult->fetch_assoc(); 318 318 319 319 $DbResult = $this->Database->select('Subject', 'Name', 'Id='.$Member['Subject']); 320 $Subject = $DbResult->fetch_assoc(); 321 322 $DbResult = $this->Database->select('User', '*', 'Id='.$Member['ResponsibleUser']); 320 $Subject = $DbResult->fetch_assoc(); 321 322 $DbResult = $this->Database->select('User', '*', 'Id='.$Member['ResponsibleUser']); 323 323 $User = $DbResult->fetch_assoc(); 324 324 325 325 $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Config['Finance']['MainSubjectId']); 326 $MainSubject = $DbResult->fetch_assoc(); 327 326 $MainSubject = $DbResult->fetch_assoc(); 327 328 328 $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '. 329 329 'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '. 330 330 'WHERE (FinanceBankAccount.`Subject`='.$Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)'); 331 331 $MainSubjectAccount = $DbResult->fetch_assoc(); 332 332 333 333 if($User['Email'] != '') 334 334 { … … 357 357 while($DbRow = $DbResult->fetch_assoc()) 358 358 { 359 $Text = $DbRow['Text']; 359 $Text = $DbRow['Text']; 360 360 $Content .= '<tr><td style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center;">'.HumanDate($DbRow['Time']).'</td>'. 361 361 '<td style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center;">'.$Text.'</td>'. … … 364 364 $Content .= '</table><br />'."\n". 365 365 '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"; 366 366 367 367 $Content .= '<br />Tento email je generován automaticky. V případě zjištění nesrovnalostí napište zpět.'; 368 $this->System->ModuleManager->Modules['EmailQueue']->AddItem($User['Name'].' <'.$User['Email'].'>', $Title, $Content, 368 $this->System->ModuleManager->Modules['EmailQueue']->AddItem($User['Name'].' <'.$User['Email'].'>', $Title, $Content, 369 369 $Config['Web']['Admin'].' <'.$Config['Web']['AdminEmail'].'>'); 370 370 $Output = ''; 371 371 } else $Output = 'Uživatel '.$User['Name'].' nemá email.'; 372 372 } 373 373 374 374 function GenerateBills() 375 375 { 376 376 $Output = ''; 377 377 378 378 // FinanceInvoice 379 379 $DbResult = $this->Database->query('SELECT * FROM `FinanceInvoice` WHERE (`BillCode` <> "") '. … … 420 420 $Output .= '.'; 421 421 } else $Output .= 'Soubor "'.$FullFileName.'" se nepodařilo uložit.'; 422 } 422 } 423 423 return($Output); 424 424 }
Note:
See TracChangeset
for help on using the changeset viewer.