Ignore:
Timestamp:
Jan 2, 2015, 11:16:56 PM (10 years ago)
Author:
chronos
Message:
  • Added: Support for Hidden items in form types values.
  • Added: Support for Filtered items in form types values.
  • Modified: FinanceOperation Value splitted to (Direction * Value). Direction can be +1 or -1 depends on if money goes out or in company.
  • Added: Menu "Incomes and spends" is now splitted to incomes/spends of bank account or treasury. Direction and document line is filled automatically.
File:
1 edited

Legend:

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

    r710 r719  
    66  var $ShortTitle = 'Daňová evidence';
    77  var $ParentClass = 'PageFinance';
    8   var $ExternalSubject = 96;
    98  var $StartEvidence = 0;
    109
     
    1211  {
    1312    $Balance = array();
    14     $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value > 0)');
     13    $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = 1)');
    1514    $Row = $DbResult->fetch_array();
    1615    $Balance['Income']['Start'] = $Row[0] + 0;
    17     $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value > 0)');
     16    $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = 1)');
    1817    //echo('SELECT SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value > 0 AND Taxable = 1'.'<br />');
    1918    $Row = $DbResult->fetch_array();
    2019    $Balance['Income']['End'] = $Row[0] + 0;
    2120
    22     $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value < 0)');
     21    $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = -1)');
    2322    $Row = $DbResult->fetch_array();
    2423    $Balance['Spend']['Start'] = $Row[0] + 0;
    25     $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value < 0)');
     24    $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = -1)');
    2625          //echo('SELECT -SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value < 0 AND Taxable = 1'.'<br />');
    2726    $Row = $DbResult->fetch_array();
     
    147146        $Output .= '<tr><th>Čas</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th><th>Daňový</th><th>Hotovost</th></tr>';       
    148147        $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
    149           'WHERE (Value > 0) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
     148          'WHERE (Direction = 1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    150149        while($Row = $DbResult->fetch_array())
    151150        {
     
    177176        $Output .= '<tr><th>Čas</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th><th>Daňový</th><th>Hotovost</th></tr>';       
    178177        $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
    179           'WHERE (Value < 0) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
     178          'WHERE (Direction = -1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    180179        while($Row = $DbResult->fetch_array())
    181180        {
    182181          $Row['Time'] = explode(' ', $Row['Time']);
    183182          $Row['Time'] = $Row['Time'][0];
    184           $Row['Value'] = $Row['Value'] * -1;
     183          $Row['Value'] = $Row['Value'];
    185184          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].'</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td><td>'.$Table[$Row['Taxable']].'</td><td>'.$Table[$Row['Cash']].'</td></tr>';
    186185          $Total += $Row['Value'];
     
    250249        '(SELECT -SUM(T3.Value) FROM FinanceInvoice AS T3 WHERE (T3.Subject = Subject.Id) AND (T3.Value  < 0)) as Liabilities, '.
    251250        '(SELECT -SUM(T4.Value) FROM FinanceInvoice AS T4 WHERE (T4.Subject = Subject.Id) AND (T4.Value < 0) AND (TimePayment IS NULL)) AS OpenedLiabilities, '.
    252         '(SELECT SUM(T5.Value) FROM FinanceOperation AS T5 WHERE (T5.Subject = Subject.Id) AND (T5.Value > 0)) AS Gains, '.
    253         '(SELECT -SUM(T6.Value) FROM FinanceOperation AS T6 WHERE (T6.Subject = Subject.Id) AND (T6.Value < 0)) AS Spends '.
     251        '(SELECT SUM(T5.Value*T5.Direction) FROM FinanceOperation AS T5 WHERE (T5.Subject = Subject.Id) AND (T5.Direction = 1)) AS Gains, '.
     252        '(SELECT SUM(T6.Value*T6.Direction) FROM FinanceOperation AS T6 WHERE (T6.Subject = Subject.Id) AND (T6.Direction = -1)) AS Spends '.
    254253        'FROM Subject ORDER BY Name');
    255254        while($Row = $DbResult->fetch_assoc())
     
    281280        {
    282281          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['Text'].
    283             '</td><td>'.$Row['Value'].'</td><td>'.$Row['BillCode'].'</td></tr>';
     282            '</td><td>'.($Row['Value']*$Row['Direction']).'</td><td>'.$Row['BillCode'].'</td></tr>';
    284283        }
    285284        $Output .= '</table></td><td style="vertical-align: top;">';
     
    315314          'Liabilities, (SELECT SUM(FinanceInvoice.Value) FROM FinanceInvoice '.
    316315          'WHERE FinanceInvoice.Subject = Subject.Id AND FinanceInvoice.Value < 0 '.
    317           'AND TimePayment IS NULL) as OpenedLiabilities, (SELECT SUM(FinanceOperation.Value) '.
    318           'FROM FinanceOperation WHERE FinanceOperation.Subject = Subject.Id AND FinanceOperation.Value > 0) '.
    319           'AS Gains, (SELECT SUM(FinanceOperation.Value) FROM FinanceOperation WHERE '.
    320           'FinanceOperation.Subject = Subject.Id AND FinanceOperation.Value < 0) as Spends '.
     316          'AND TimePayment IS NULL) as OpenedLiabilities, (SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) '.
     317          'FROM FinanceOperation WHERE FinanceOperation.Subject = Subject.Id AND FinanceOperation.Direction = 1) '.
     318          'AS Gains, (SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) FROM FinanceOperation WHERE '.
     319          'FinanceOperation.Subject = Subject.Id AND FinanceOperation.Direction = -1) as Spends '.
    321320          'FROM Subject WHERE Id='.$_GET['Id']);
    322321        $Row = $DbResult->fetch_array();
Note: See TracChangeset for help on using the changeset viewer.