Changeset 185 for trunk/finance/manage.php
- Timestamp:
- Apr 3, 2009, 10:32:35 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/finance/manage.php
r182 r185 48 48 $Output = $this->ShowNewInvoiceForm(); 49 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; 50 57 default: 51 58 $Output = '<a href="?Operation=NewDeviceForm">Přidat nové zařízení</a><br />'; … … 53 60 $Output .= '<a href="?Operation=NewPaymentForm">Přidat novou platbu</a><br />'; 54 61 $Output .= '<a href="?Operation=NewInvoiceForm">Přidat novou fakturu</a><br />'; 55 $Output .= '<a href="?Operation=ImportOldData">Importovat stará data</a><br />';62 //$Output .= '<a href="?Operation=ImportOldData">Importovat stará data</a><br />'; 56 63 $Output .= '<a href="?Operation=ConvertPDFToFile">Převést data z databáze do souborů</a><br />'; 57 64 $Output .= '<a href="?Operation=Bills">Správa dokladů</a><br />'; 58 65 //$Output .= '<a href="?Operation=ConvertData">Převést tabulky</a><br />'; 59 $Output .= '<a href="prepocet.php">Přepočet financí</a><br />'; 60 $Output .= '<a href="clenove.php">Seznam členů</a><br />'; 61 $Output .= '<a href="zivnost.php">Živnost</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.php">Seznam členů</a><br />'; 69 $Output .= '<a href="zivnost.php">Živnost</a><br />'; 62 70 } 63 71 return($Output); … … 229 237 } 230 238 239 /* 231 240 function ImportOldData() 232 241 { 233 die();234 235 242 $Output = ''; 236 243 $this->Database->query('TRUNCATE TABLE FinanceCashFlow'); … … 355 362 return($Output); 356 363 } 357 364 */ 365 358 366 function ConvertPDFDataToFiles() 359 367 { … … 378 386 } 379 387 388 /* 380 389 function ConvertData() 381 390 { 382 die();383 384 391 $Finance = $this->System->Modules['Finance']; 385 392 $Output = ''; … … 440 447 return($Output); 441 448 } 449 */ 450 451 452 function GetBillingPeriod($Period) 453 { 454 $MonthCount = $this->System->Modules['Finance']->BillingPeriods[$Period]['MonthCount']; 455 $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y')); 456 $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y')); 457 return(array('From' => $PeriodFrom, 'To' => $PeriodTo, 'MonthCount' => $MonthCount)); 458 } 459 460 function ShowMonthlyPayment() 461 { 462 if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění'); 463 $Output = ''; 464 465 $Finance = &$this->System->Modules['Finance']; 466 467 // Načti poslední měsíční přehled a nastavení 468 $DbResult = $this->Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1'); 469 $Overall = $DbResult->fetch_array(); 470 471 $Output -= 'Datum: '.date('j.n.Y').'<br />'; 472 473 $Datum = explode('-', $Overall['date']); 474 $Mesic = date('m') + 0; 475 476 $Output .= $Finance->RecalculateSegmentParameters(); 477 $Output .= $Finance->RecalculateTariffs(); 478 //$InvoiceGenerator->CustomGenerate(); 479 $Output .= $Finance->RecalculateMemberPayment(); 480 481 // Celkovy prehled 482 $DbResult = $this->Database->query('SELECT SUM(price) FROM network_devices WHERE used = 1'); 483 $Row = $DbResult->fetch_row(); 484 $TotalDeviceCost = $Row[0]; 485 $Output .= 'Celková cena zařízení: Zařízení('.$TotalDeviceCost; 486 487 $DbResult = $this->Database->query('SELECT SUM(price) FROM network_segments'); 488 $Row = $DbResult->fetch_row(); 489 $TotalSegmentDeviceCost = $Row[0]; 490 $Output .= '), Segmenty('.$TotalSegmentDeviceCost; 491 492 $DbResult = $this->Database->query('SELECT SUM(NetworkDevice) FROM MemberPayment'); 493 $Row = $DbResult->fetch_row(); 494 $TotalMemberDeviceCost = $Row[0]; 495 $Output .= '), Členové('.$TotalMemberDeviceCost.')<br />'; 496 497 $DbResult = $this->Database->query('SELECT SUM(Cash) FROM MemberPayment'); 498 $Row = $DbResult->fetch_row(); 499 $TotalMemberCash = $Row[0]; 500 $Output .= 'Stav pokladny: Členové('.$TotalMemberCash.')'; 501 502 $DbResult = $this->Database->query('SELECT SUM(consumption) FROM network_devices WHERE used=1'); 503 $Row = $DbResult->fetch_row(); 504 $TotalConsumption = $Row[0]; 505 $TotalConsumptionCost = $Finance->W2Kc($TotalConsumption); 506 507 $SpravaCelkem = $Finance->Sprava * $Finance->SpravaUsers; 508 $Output .= 'Kontrola placení (Zaplaceno-Sprava-Internet): '.$Finance->TotalPaid.'-'.$SpravaCelkem.'-'.$Finance->Internet.'='.($Finance->TotalPaid - $SpravaCelkem - $Finance->Internet).'<br />'; 509 510 // Zkontrolovat odečtení měsíčního poplatku 511 //$Mesic = '1'; 512 $Output .= 'Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic.'<br />'; 513 //if($Mesic != $Datum[1]) 514 { 515 $Output .= 'Odečítám měsíční poplatek...<br />'; 516 517 // Generuj účetní položky 518 $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'); 519 while($Member = $DbResult->fetch_array()) 520 { 521 $Output .= $Member['SubjectName'].': '; 522 $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']); 523 if($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']) 524 { 525 $this->Database->update('Member', 'Id='.$Member['Id'], array('BillingPeriod' => $Member['BillingPeriodNext'], 'InternetTariffCurrentMonth' => $Member['InternetTariffNextMonth'])); 526 $Member['BillingPeriod'] = $Member['BillingPeriodNext']; 527 } 528 $Period = $this->GetBillingPeriod($Member['BillingPeriod']); 529 $PayPerPeriod = $Member['MonthlyTotal'] * $Period['MonthCount']; 530 if(($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']) and ($Member['InternetTariffCurrentMonth'] != 6) and ($PayPerPeriod > 0)) 531 { 532 //echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' '); 533 $TimePeriodText = date('j.n.Y', $Period['From']).' - '.date('j.n.Y', $Period['To']); 534 $Output .= $TimePeriodText.': '.$Member['MonthlyTotal'].' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />'; 535 $BillCode = $Finance->GetNextDocumentLineNumber(6); // Faktury vydané 536 $BillId = $this->System->Modules['Bill']->CreateBill($Member['Subject'], array(array('Description' => 'Připojení k síti', 'Price' => $PayPerPeriod, 'Quantity' => 1)), $Period['From'], $Period['To'], $BillCode); 537 $this->Database->insert('FinanceClaimsLiabilities', array('Value' => $PayPerPeriod, 'Subject' => $Member['Subject'], 'TimeCreation' => 'NOW()', 'Text' => 'Připojení k síti za období '.$TimePeriodText, 'Bill' => $BillId, 'BillCode' => $BillCode)); 538 $this->Database->update('Member', 'Id='.$Member['Id'], array('BillingPeriodLastDate' => TimeToMysqlDateTime($Period['To']))); 539 } else $Output .= '<br />'; 540 } 541 542 // Update finance charge 543 $Output .= 'Měním aktuální parametry sítě...<br>'; 544 $this->Database->delete('finance_charge', 'period = 0'); 545 $DbResult = $this->Database->select('finance_charge', '*', 'period = 1'); 546 $Charge = $DbResult->fetch_assoc(); 547 //print_r($Charge); 548 $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'])); 549 550 $Output .= 'Přidávám měsíční přehled...<br />'; 551 $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)); 552 553 $Output .= 'Měním aktuální tarify....<br>'; 554 // Update tarrifs 555 $this->Database->delete('finance_tariffs', 'period=0'); 556 $DbResult = $this->Database->select('finance_tariffs', '*', 'period = 1'); 557 while($Tariff = $DbResult->fetch_array()) 558 { 559 $this->Database->insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'],'speed_factor' => $Tariff['speed_factor'], 'price_units' => $Tariff['price_units'], 'group_id' => $Tariff['group_id'], 'min_speed' => $Tariff['min_speed'], 'max_speed' => $Tariff['max_speed'], 'price' => $Tariff['price'])); 560 } 561 562 $Output .= $Finance->RecalculateTariffs(); 563 $Finance->RecalculateMemberPayment(); 564 //CreateMonthlyOverallBill(); 565 //$Finance->RecalculateUsersFinance(); 566 567 // Restart traffic shaping 568 $this->Database->update('services_restart', 'id = 3', array('changed' => 1)); 569 } 570 return($Output); 571 } 442 572 } 443 573
Note:
See TracChangeset
for help on using the changeset viewer.