Ignore:
Timestamp:
Mar 3, 2013, 6:02:17 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Přepracováno generování PDF dokladů. Nyní pro každý typ dokladu se definuje samostatná třída odvozená ze třídy Bill. Údaje se načítají přímo ze zdrojových tabulek namísto vytváření duplicitních dat v tabulce FinanceBills. Doklady jsou identifikovány jako soubor dle tabulky File.
  • Upraveno: Fronta emailů a seznam síťových služeb lze nyní upravovat přímo ze sekce Správa dat.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/finance/manage.php

    r497 r498  
    357357   
    358358    // 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');
    360364    while($Member = $DbResult->fetch_assoc())
    361365    {
     
    365369      {
    366370        $this->Database->update('Member', 'Id='.$Member['Id'],
    367             array('BillingPeriod' => $Member['BillingPeriodNext']));
     371          array('BillingPeriod' => $Member['BillingPeriodNext']));
    368372        $Member['BillingPeriod'] = $Member['BillingPeriodNext'];
    369373      }
     
    374378        $InvoiceItems = array();
    375379        $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) ');
    379386        while($Service = $DbResult2->fetch_assoc())
    380387        {
    381388          $InvoiceItems[] = array('Description' => $Service['Name'], 'Price' => $Service['Price'],
    382               'Quantity' => $Period['MonthCount'], 'VAT' => 21);
     389            'Quantity' => $Period['MonthCount'], 'VAT' => $Service['VAT']);
    383390          $MonthlyTotal += $Service['Price'];
    384391        }
     
    396403        $TimePeriodText = date('j.n.Y', $Period['From']).' - '.date('j.n.Y', $Period['To']);
    397404        $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,
    399406          $InvoiceItems, INVOICE_OUT_DOC_LINE, $Period['From'], $Period['To']);
    400407   
    401408        $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'])));
    403411      } else $Output .= '<br />';
    404412    } 
     
    491499    {
    492500      $Output .= 'Odečítám měsíční poplatek...<br />';
    493       $this->ProduceInvoices();   
     501      $Output .= $this->ProduceInvoices();   
    494502     
    495503      // Update finance charge
     
    498506
    499507      $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();
    500510      $this->Database->insert('FinanceMonthlyOverall', array('Date' => 'NOW()',
    501511        'Money' => $Finance->Internet, 'kWh' => $Finance->kWh,
     
    553563        'Váše aktuální služby: ';
    554564      $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();
    557568      $Content .= '<strong>'.$Service['Name'].'</strong><br />'."\n".
    558569        'Vaše platební období: <strong>'.$this->System->Modules['Finance']->BillingPeriods[$Member['BillingPeriod']]['Name'].'</strong><br />'."\n".
     
    563574      $Content .= 'Nové finanční operace:<br/>'.
    564575        '<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'].'")');
    568578      while($DbRow = $DbResult->fetch_assoc())
    569579      {
     
    584594  function GenerateBills()
    585595  {
     596    $Output = '';
     597   
    586598    // 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)');
    588601    while($Row = $DbResult->fetch_assoc())
    589602    {
    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 .= '.';
    596615    }
    597616
    598617    // FinanceOperations
     618    return($Output);
    599619  }
    600620}
Note: See TracChangeset for help on using the changeset viewer.