Ignore:
Timestamp:
Jan 5, 2015, 10:01:40 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Added time designation for scheduled table change actions. This applies to tables Service, ServiceCustomerRel and FinanceCharge. Now time of taking effect is not determined just by customer pay period but by more generally by specified time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Finance/UserState.php

    r724 r726  
    99  function ShowFinanceOperation($Subject)
    1010  {
    11         $UserOperationTableQuery = '((SELECT Text, Time, (Value*Direction) AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
    12           'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '.
    13                 '(SELECT (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoice=FinanceInvoice.Id) AS Text, '.
    14                 'Time, -(Value*Direction) as Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')))';
     11        $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`Direction`) AS `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
     12          'FROM `FinanceOperation` WHERE (`Subject`='.$Subject['Id'].')) UNION ALL '.
     13                '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ",") FROM `FinanceInvoiceItem` WHERE `FinanceInvoice`=`FinanceInvoice`.`Id`) AS `Text`, '.
     14                '`Time`, -(`Value`*`Direction`) AS `Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')))';
    1515
    1616    $Output = '<div style="text-align:center">Výpis finančních operací</div>';
    17         $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$UserOperationTableQuery.' AS T1');
     17        $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$UserOperationTableQuery.' AS `T1`');
    1818        $DbRow = $DbResult->fetch_row();
    1919        $PageList = GetPageList($DbRow[0]);
     
    3333        $Output .= $Order['Output'];
    3434
    35         $StateQuery = 'SELECT SUM(T2.Value) FROM '.$UserOperationTableQuery.
    36           ' AS T2 WHERE T2.Time <= T1.Time ';
    37         $Query = 'SELECT *, ('.$StateQuery.') AS State FROM '.$UserOperationTableQuery.' AS T1 '.$Order['SQL'].$PageList['SQLLimit'];
     35        $StateQuery = 'SELECT SUM(`T2`.`Value`) FROM '.$UserOperationTableQuery.
     36          ' AS `T2` WHERE `T2`.`Time` <= `T1`.`Time` ';
     37        $Query = 'SELECT *, ('.$StateQuery.') AS `State` FROM '.$UserOperationTableQuery.' AS `T1` '.$Order['SQL'].$PageList['SQLLimit'];
    3838
    3939        $DbResult = $this->Database->query($Query);
     
    7878      if(!$this->System->User->CheckPermission('Finance', 'DisplaySubjectState')) return('Nemáte oprávnění');
    7979      $UserId = $this->System->User->User['Id'];
    80       $DbResult = $this->Database->query('SELECT Customer FROM UserCustomerRel WHERE User='.$UserId.' LIMIT 1');
     80      $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` WHERE `User`='.$UserId.' LIMIT 1');
    8181      if($DbResult->num_rows > 0)
    8282      {
     
    8787       
    8888    // Load customer info
    89     $DbResult = $this->Database->query('SELECT * FROM Member WHERE Id='.$CustomerId);
     89    $DbResult = $this->Database->query('SELECT * FROM `Member` WHERE `Id`='.$CustomerId);
    9090    if($DbResult->num_rows == 1)
    9191    {
     
    9595   
    9696    // Load subject info
    97     $DbResult = $this->Database->query('SELECT * FROM Subject WHERE Id='.$Customer['Subject']);
     97    $DbResult = $this->Database->query('SELECT * FROM `Subject` WHERE `Id`='.$Customer['Subject']);
    9898    if($DbResult->num_rows == 1)
    9999    {   
     
    105105
    106106    // Account state
    107     $UserOperationTableQuery = '((SELECT Text, Time, (Value*Direction) AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
    108       'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '.
    109       '(SELECT (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoice=FinanceInvoice.Id) AS Text, '.
    110       'Time, -(Value*Direction) as Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')) ORDER BY Time DESC) AS T1';
    111     $DbResult = $this->Database->query('SELECT SUM(T1.Value) AS Total FROM '.$UserOperationTableQuery);
     107    $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`Direction`) AS `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
     108      'FROM `FinanceOperation` WHERE (`Subject`='.$Subject['Id'].')) UNION ALL '.
     109      '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ",") FROM `FinanceInvoiceItem` WHERE `FinanceInvoice`=`FinanceInvoice`.`Id`) AS `Text`, '.
     110      '`Time`, -(`Value`*`Direction`) AS `Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')) ORDER BY `Time` DESC) AS `T1`';
     111    $DbResult = $this->Database->query('SELECT SUM(`T1`.`Value`) AS `Total` FROM '.$UserOperationTableQuery);
    112112    $DbRow = $DbResult->fetch_array();
    113113    $Total = $DbRow['Total'];
     
    133133    $Output .= 'Rozpis měsíčního poplatku:<br><table class="WideTable">'.
    134134      '<tr><th>Služba</th><th>Cena [Kč]</th></tr>';
    135     $DbResult = $this->Database->query('SELECT Service.Name, Service.Price FROM ServiceCustomerRel '.
    136       'LEFT JOIN Service ON Service.Id=ServiceCustomerRel.Service '.
    137       'WHERE (ServiceCustomerRel.Customer='.$Customer['Id'].') AND (ServiceCustomerRel.Action IS NULL)');
     135    $DbResult = $this->Database->query('SELECT `Service`.`Name`, `Service`.`Price` FROM `ServiceCustomerRel` '.
     136      'LEFT JOIN `Service` ON `Service`.`Id`=`ServiceCustomerRel`.`Service` '.
     137      'WHERE (`ServiceCustomerRel`.`Customer`='.$Customer['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL)');
    138138    while($DbRow = $DbResult->fetch_assoc())
    139139    {
Note: See TracChangeset for help on using the changeset viewer.