Changeset 498 for trunk/finance/manage.php
- Timestamp:
- Mar 3, 2013, 6:02:17 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/finance/manage.php
r497 r498 357 357 358 358 // Generuj účetní položky 359 $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'); 359 $DbResult = $this->Database->query('SELECT Member.*, MemberPayment.MonthlyTotal AS MonthlyTotal, '. 360 'UNIX_TIMESTAMP(Member.BillingPeriodLastDate), Subject.Name AS SubjectName,'. 361 'MemberPayment.MonthlyPlus AS MonthlyPlus '. 362 'FROM MemberPayment JOIN Member ON Member.Id=MemberPayment.Member '. 363 'JOIN Subject ON Subject.Id=Member.Subject'); 360 364 while($Member = $DbResult->fetch_assoc()) 361 365 { … … 365 369 { 366 370 $this->Database->update('Member', 'Id='.$Member['Id'], 367 371 array('BillingPeriod' => $Member['BillingPeriodNext'])); 368 372 $Member['BillingPeriod'] = $Member['BillingPeriodNext']; 369 373 } … … 374 378 $InvoiceItems = array(); 375 379 $MonthlyTotal = 0; 376 $DbResult2 = $this->Database->query('SELECT Service.* FROM ServiceCustomerRel LEFT JOIN Service '. 377 'ON Service.Id=ServiceCustomerRel.Service WHERE (ServiceCustomerRel.Customer='. 378 $Member['Id'].') AND (ServiceCustomerRel.Action IS NULL)'); 380 $DbResult2 = $this->Database->query('SELECT Service.*, FinanceVAT.Value AS VAT '. 381 'FROM ServiceCustomerRel LEFT JOIN Service '. 382 'ON Service.Id=ServiceCustomerRel.Service '. 383 'LEFT JOIN FinanceVAT ON FinanceVAT.Id=Service.VAT '. 384 'WHERE (ServiceCustomerRel.Customer='. 385 $Member['Id'].') AND (ServiceCustomerRel.Action IS NULL) '); 379 386 while($Service = $DbResult2->fetch_assoc()) 380 387 { 381 388 $InvoiceItems[] = array('Description' => $Service['Name'], 'Price' => $Service['Price'], 382 'Quantity' => $Period['MonthCount'], 'VAT' => 21);389 'Quantity' => $Period['MonthCount'], 'VAT' => $Service['VAT']); 383 390 $MonthlyTotal += $Service['Price']; 384 391 } … … 396 403 $TimePeriodText = date('j.n.Y', $Period['From']).' - '.date('j.n.Y', $Period['To']); 397 404 $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />'; 398 $this->InsertInvoice($Member['Subject'], 'NOW()', 'DATE_ADD(NOW(), INTERVAL '.INVOICE_DUE_DAYS.' DAY)',405 $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS, 399 406 $InvoiceItems, INVOICE_OUT_DOC_LINE, $Period['From'], $Period['To']); 400 407 401 408 $Output .= $this->SendPaymentEmail($Member['Id']); 402 $this->Database->update('Member', 'Id='.$Member['Id'], array('BillingPeriodLastDate' => TimeToMysqlDateTime($Period['To']))); 409 $this->Database->update('Member', 'Id='.$Member['Id'], 410 array('BillingPeriodLastDate' => TimeToMysqlDateTime($Period['To']))); 403 411 } else $Output .= '<br />'; 404 412 } … … 491 499 { 492 500 $Output .= 'Odečítám měsíční poplatek...<br />'; 493 $ this->ProduceInvoices();501 $Output .= $this->ProduceInvoices(); 494 502 495 503 // Update finance charge … … 498 506 499 507 $Output .= 'Přidávám měsíční přehled...<br />'; 508 $DbResult = $this->Database->query('SELECT * FROM FinanceCharge WHERE Action IS NULL LIMIT 1'); 509 $Charge = $DbResult->fetch_assoc(); 500 510 $this->Database->insert('FinanceMonthlyOverall', array('Date' => 'NOW()', 501 511 'Money' => $Finance->Internet, 'kWh' => $Finance->kWh, … … 553 563 'Váše aktuální služby: '; 554 564 $DbResult = $this->Database->query('SELECT GROUP_CONCAT(Service.Name) AS Name FROM ServiceCustomerRel LEFT JOIN Service '. 555 'ON Service.Id=ServiceCustomerRel.Service WHERE ServiceCustomerRel.Customer='.$Member['Id'].' AND ServiceCustomerRel.Period=0'); 556 $Service = $DbRow->fetch_assoc(); 565 'ON Service.Id=ServiceCustomerRel.Service WHERE (ServiceCustomerRel.Customer='.$Member['Id'].') '. 566 'AND ServiceCustomerRel.Action IS NULL'); 567 $Service = $DbResult->fetch_assoc(); 557 568 $Content .= '<strong>'.$Service['Name'].'</strong><br />'."\n". 558 569 'Vaše platební období: <strong>'.$this->System->Modules['Finance']->BillingPeriods[$Member['BillingPeriod']]['Name'].'</strong><br />'."\n". … … 563 574 $Content .= 'Nové finanční operace:<br/>'. 564 575 '<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"; 565 //$Member['BillingPeriodLastDate'] = '2009-04-01'; 566 $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, Value AS Value, Bill FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '. 567 '(SELECT Text, TimeCreation as Time, -Value as Value, Bill FROM FinanceInvoice WHERE (Subject='.$Member['Subject'].')) ORDER BY Time DESC) AS T1 WHERE (T1.Time > "'.$Member['BillingPeriodLastDate'].'")'); 576 $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, Value AS Value, File FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '. 577 '(SELECT Text, TimeCreation as Time, -Value as Value, File FROM FinanceInvoice WHERE (Subject='.$Member['Subject'].')) ORDER BY Time DESC) AS T1 WHERE (T1.Time > "'.$Member['BillingPeriodLastDate'].'")'); 568 578 while($DbRow = $DbResult->fetch_assoc()) 569 579 { … … 584 594 function GenerateBills() 585 595 { 596 $Output = ''; 597 586 598 // FinanceInvoice 587 $DbResult = $this->Database->query('SELECT * FROM FinanceInvoice WHERE (BillCode <> "") AND (Value != 0) AND (Bill = 0)'); 599 $DbResult = $this->Database->query('SELECT * FROM `FinanceInvoice` WHERE (`BillCode` <> "") '. 600 'AND (`Value` != 0) AND (`File` IS NULL)'); 588 601 while($Row = $DbResult->fetch_assoc()) 589 602 { 590 $BillId = $this->System->Modules['Bill']->CreateBill($Row['Subject'], 591 array(array('Description' => $Row['Text'], 'Price' => $Row['Value'], 'Quantity' => 1)), 592 MysqlDateTimeToTime($Row['TimeCreation']), MysqlDateTimeToTime($Row['TimeDue']), 593 $Row['BillCode'], 'invoice', MysqlDateToTime($Row['PeriodFrom']), MysqlDateToTime($Row['PeriodTo'])); 594 $this->Database->update('FinanceInvoice', 'Id='.$Row['Id'], array('Bill' => $BillId)); 595 echo('.'); 603 $DbResult2 = $this->Database->insert('File', array('Name' => '', 'Size' => 0)); 604 $FileId = $this->Database->insert_id; 605 $FileName = 'doklad-'.$FileId.'.pdf'; 606 $Bill = new BillInvoice(); 607 $Bill->Database = &$this->System->Database; 608 $Bill->System = &$this->System; 609 $Bill->InvoiceId = $Row['Id']; 610 $FullFileName = $this->System->FilesDir.$FileName; 611 $Bill->SaveToFile($FullFileName); 612 $this->Database->update('File', 'Id='.$FileId, array('Name' => $FileName, 'Size' => filesize($FullFileName))); 613 $this->Database->update('FinanceInvoice', 'Id='.$Row['Id'], array('File' => $FileId)); 614 $Output .= '.'; 596 615 } 597 616 598 617 // FinanceOperations 618 return($Output); 599 619 } 600 620 }
Note:
See TracChangeset
for help on using the changeset viewer.