Ignore:
Timestamp:
Apr 14, 2015, 10:20:16 PM (10 years ago)
Author:
chronos
Message:
  • Removed: Spaces on end of line.
  • Modified: Tabs converted to spaces.
File:
1 edited

Legend:

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

    r728 r738  
    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`');
    18         $DbRow = $DbResult->fetch_row();
    19         $PageList = GetPageList($DbRow[0]);
     17    $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$UserOperationTableQuery.' AS `T1`');
     18    $DbRow = $DbResult->fetch_row();
     19    $PageList = GetPageList($DbRow[0]);
    2020
    21         $Output .= $PageList['Output'];
    22         $Output .= '<table class="WideTable" style="font-size: small;">';
     21    $Output .= $PageList['Output'];
     22    $Output .= '<table class="WideTable" style="font-size: small;">';
    2323
    24         $TableColumns = array(
    25                         array('Name' => 'Time', 'Title' => 'Datum'),
    26                         array('Name' => 'Text', 'Title' => 'Popis'),
    27                         array('Name' => 'Value', 'Title' => 'Změna [Kč]'),
    28                         array('Name' => 'State', 'Title' => 'Zůstatek [Kč]'),
    29                         array('Name' => 'PeriodFrom', 'Title' => 'Období'),
    30                         array('Name' => 'BillCode', 'Title' => 'Doklad'),
    31         );
    32         $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
    33         $Output .= $Order['Output'];
     24    $TableColumns = array(
     25        array('Name' => 'Time', 'Title' => 'Datum'),
     26        array('Name' => 'Text', 'Title' => 'Popis'),
     27        array('Name' => 'Value', 'Title' => 'Změna [Kč]'),
     28        array('Name' => 'State', 'Title' => 'Zůstatek [Kč]'),
     29        array('Name' => 'PeriodFrom', 'Title' => 'Období'),
     30        array('Name' => 'BillCode', 'Title' => 'Doklad'),
     31    );
     32    $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
     33    $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
    39         $DbResult = $this->Database->query($Query);
     39    $DbResult = $this->Database->query($Query);
    4040    $SumValue = 0;
    41         while($Row = $DbResult->fetch_assoc())
    42         {
    43                 $Row['State'] = round($Row['State'], 2);
    44                 if($Row['State'] > 0) $Row['State'] = '<span style="color:green;">'.$Row['State'].'</span>';
    45                 if($Row['State'] < 0) $Row['State'] = '<span style="color:red;">'.$Row['State'].'</span>';
    46                 if($Row['Value'] == -0) $Row['Value'] = 0;
    47                 if($Row['Value'] > 0) $Row['Value'] = '+'.$Row['Value'];
    48                 if($Row['BillCode'] == '') $Row['BillCode'] = 'PDF';
    49                 if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/file?id='.$Row['File']).'">'.$Row['BillCode'].'</a>';
    50                 else $Invoice = NotBlank($Row['BillCode']);
    51                 if($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
    52                 else $Period = '&nbsp;';
    53                 $Output .= '<tr><td style="text-align: right;">'.HumanDate($Row['Time']).'</td>'.
    54                                 '<td style="text-align: left;">'.$Row['Text'].'</td>'.
    55                                 '<td style="text-align: right;">'.round($Row['Value'], 2).'</td>'.
    56                                 '<td style="text-align: right;">'.$Row['State'].'</td>'.
    57                                 '<td>'.$Period.'</td>'.
    58                                 '<td>'.$Invoice.'</td></tr>';
    59                 $SumValue = $SumValue + $Row['Value'];
    60         }
    61         $Output .= '</table>';
    62         $Output .= $PageList['Output'];
    63         return($Output);
     41    while($Row = $DbResult->fetch_assoc())
     42    {
     43      $Row['State'] = round($Row['State'], 2);
     44      if($Row['State'] > 0) $Row['State'] = '<span style="color:green;">'.$Row['State'].'</span>';
     45      if($Row['State'] < 0) $Row['State'] = '<span style="color:red;">'.$Row['State'].'</span>';
     46      if($Row['Value'] == -0) $Row['Value'] = 0;
     47      if($Row['Value'] > 0) $Row['Value'] = '+'.$Row['Value'];
     48      if($Row['BillCode'] == '') $Row['BillCode'] = 'PDF';
     49      if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/file?id='.$Row['File']).'">'.$Row['BillCode'].'</a>';
     50      else $Invoice = NotBlank($Row['BillCode']);
     51      if($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
     52      else $Period = '&nbsp;';
     53      $Output .= '<tr><td style="text-align: right;">'.HumanDate($Row['Time']).'</td>'.
     54          '<td style="text-align: left;">'.$Row['Text'].'</td>'.
     55          '<td style="text-align: right;">'.round($Row['Value'], 2).'</td>'.
     56          '<td style="text-align: right;">'.$Row['State'].'</td>'.
     57          '<td>'.$Period.'</td>'.
     58          '<td>'.$Invoice.'</td></tr>';
     59      $SumValue = $SumValue + $Row['Value'];
     60    }
     61    $Output .= '</table>';
     62    $Output .= $PageList['Output'];
     63    return($Output);
    6464  }
    6565
     
    8585      } else return($this->SystemMessage('Chyba', 'Nejste zákazníkem'));
    8686    }
    87        
     87
    8888    // Load customer info
    8989    $DbResult = $this->Database->query('SELECT * FROM `Member` WHERE `Id`='.$CustomerId);
    9090    if($DbResult->num_rows == 1)
    9191    {
    92         $Customer = $DbResult->fetch_assoc();     
     92      $Customer = $DbResult->fetch_assoc();
    9393    } else return($this->SystemMessage('Položka nenalezena', 'Zákazník nenalezen'));
    94    
    95    
     94
     95
    9696    // Load subject info
    9797    $DbResult = $this->Database->query('SELECT * FROM `Subject` WHERE `Id`='.$Customer['Subject']);
    9898    if($DbResult->num_rows == 1)
    99     {   
    100       $Subject = $DbResult->fetch_assoc();     
     99    {
     100      $Subject = $DbResult->fetch_assoc();
    101101    } else return($this->SystemMessage('Položka nenalezena', 'Subjekt nenalezen'));
    102    
    103    
    104     $Output = '<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td valign="top">';       
     102
     103
     104    $Output = '<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td valign="top">';
    105105
    106106    // Account state
     
    120120
    121121    $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '.
    122                 'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
    123                 'WHERE (FinanceBankAccount.`Subject`='.$this->System->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
     122        'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
     123        'WHERE (FinanceBankAccount.`Subject`='.$this->System->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
    124124    $SubjectFromAccount = $DbResult->fetch_assoc();
    125125    $Account = $SubjectFromAccount['NumberFull'];
     
    138138    while($DbRow = $DbResult->fetch_assoc())
    139139    {
    140             $Output .= '<tr><td>'.$DbRow['Name'].'</td><td>'.$DbRow['Price'].'</td></tr>';
     140      $Output .= '<tr><td>'.$DbRow['Name'].'</td><td>'.$DbRow['Price'].'</td></tr>';
    141141      $Total += $DbRow['Price'];
    142142    }
Note: See TracChangeset for help on using the changeset viewer.