Changeset 748


Ignore:
Timestamp:
Sep 30, 2015, 11:55:11 PM (9 years ago)
Author:
chronos
Message:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r747 r748  
    11<?php
    22
    3 $Revision = 747; // Subversion revision
    4 $DatabaseRevision = 747; // SQL structure revision
     3$Revision = 748; // Subversion revision
     4$DatabaseRevision = 748; // SQL structure revision
    55$ReleaseTime = strtotime('2015-09-19');
  • trunk/Common/Setup/DefaultConfig.php

    r738 r748  
    4545        array('Name' => 'Finance/MainSubjectId', 'Type' => 'Integer', 'Default' => '1', 'Title' => 'Id hlavního subjektu'),
    4646        array('Name' => 'Finance/DirectoryId', 'Type' => 'Integer', 'Default' => '1', 'Title' => 'Id adresáře souborů dokladů'),
     47        array('Name' => 'Finance/Rounding', 'Type' => 'Integer', 'Default' => '2', 'Title' => 'Počet desetinných míst zaokrouhlování'),
    4748        array('Name' => 'MainRouter/HostName', 'Type' => 'String', 'Default' => 'localhost', 'Title' => 'Hlavní brána'),
    4849        array('Name' => 'MainRouter/UserName', 'Type' => 'String', 'Default' => 'admin', 'Title' => 'Uživatelské jméno'),
  • trunk/Common/Setup/Updates.php

    r747 r748  
    14891489}
    14901490
    1491 function UpdateTo748($Manager)
     1491function UpdateTo747($Manager)
    14921492{
    14931493  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD `ValueUser` FLOAT NOT NULL AFTER `Value`;');
     
    15061506  $Manager->Execute('ALTER TABLE `FinanceInvoice` DROP `Direction`, DROP `ValueSign`;');
    15071507  // Check manual vs. calculated value from items
    1508   // SELECT * FROM (SELECT `FinanceInvoice`.`Id`, ((SELECT SUM(`Price` * `Quantity`) FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice`=`FinanceInvoice`.`Id`) * `FinanceInvoiceGroup`.`ValueSign`) AS `Sum`,`FinanceInvoice`.`Value` FROM `FinanceInvoice` LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group`) AS `T` WHERE `Sum` != `Value`
     1508  // SELECT * FROM (SELECT `FinanceInvoice`.`Id`, ((SELECT SUM(CEIL(`Price` * `Quantity`)) FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice`=`FinanceInvoice`.`Id`) * `FinanceInvoiceGroup`.`ValueSign`) AS `Sum`,`FinanceInvoice`.`Value` FROM `FinanceInvoice` LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group`) AS `T` WHERE `Sum` != `Value`
     1509}
     1510
     1511function UpdateTo748($Manager)
     1512{
     1513  $DbResult = $Manager->Database->query('SELECT * FROM (SELECT `FinanceInvoice`.`Id`, ((SELECT SUM(`Price` * `Quantity`) FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice`=`FinanceInvoice`.`Id`) * `FinanceInvoiceGroup`.`ValueSign`) AS `Sum`,`FinanceInvoice`.`Value` FROM `FinanceInvoice` LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group`) AS `T` WHERE `Sum` != `Value`');
     1514  while($DbRow = $DbResult->fetch_assoc())
     1515  {
     1516    $Manager->Database->query('UPDATE `FinanceInvoiceItem` SET `Price` = -`Price` WHERE `FinanceInvoice`='.$DbRow['Id']);
     1517  }
    15091518}
    15101519
     
    15791588      740 => array('Revision' => 741, 'Function' => 'UpdateTo741'),
    15801589      741 => array('Revision' => 742, 'Function' => 'UpdateTo742'),
    1581       742 => array('Revision' => 748, 'Function' => 'UpdateTo748'),
     1590      742 => array('Revision' => 747, 'Function' => 'UpdateTo747'),
     1591      747 => array('Revision' => 748, 'Function' => 'UpdateTo748'),
    15821592    ));
    15831593  }
  • trunk/Modules/Finance/Bill.php

    r747 r748  
    5252  function GenerateHTML()
    5353  {
    54     $DbResult = $this->Database->query('SELECT `FinanceInvoice`.*, `FinanceInvoiceGroup`.`Direction` FROM `FinanceInvoice` '.
     54    $Finance = &$this->System->Modules['Finance'];
     55    $Finance->LoadMonthParameters(0);
     56
     57    $DbResult = $this->Database->query('SELECT `FinanceInvoice`.*, `FinanceInvoiceGroup`.`Direction`, `DocumentLineCode`.`Name` AS `BillName` FROM `FinanceInvoice` '.
    5558      'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
     59      'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceInvoice`.`BillCode` '.
    5660      'WHERE `FinanceInvoice`.`Id`='.$this->InvoiceId);
    5761    $Invoice = $DbResult->fetch_assoc();
     
    7276    $SubjectFrom['Account'] = $SubjectFromAccount['NumberFull'];
    7377
    74     $Dodavka = array();
    7578    $InvoiceItems = array();
    76     $DbResult = $this->Database->select('FinanceInvoiceItem', '*, CEIL(`Price` * `Quantity`) AS `Total`', '`FinanceInvoice`='.$this->InvoiceId);
     79    $DbResult = $this->Database->select('FinanceInvoiceItem', '*, ROUND(`Price` * `Quantity`, '.$Finance->Rounding.') AS `Total`', '`FinanceInvoice`='.$this->InvoiceId);
    7780    while($Item = $DbResult->fetch_assoc())
    7881    {
     
    108111      '<tr><td width="50%" valign="top">'.
    109112      '<strong>Platební podmínky:</strong><br>'.
    110       'Číslo dokladu: '.$Invoice['BillCode'].'<br>'.
     113      'Číslo dokladu: '.$Invoice['BillName'].'<br>'.
    111114      'Variabilní symbol: '.$VarSym.'<br>'.
    112115      'Specifický symbol: '.$this->SpecificSymbol.'<br>'.
     
    153156  function GenerateHTML()
    154157  {
    155     $DbResult = $this->Database->query('SELECT `FinanceOperation`.*, `FinanceOperationGroup`.`Direction` FROM `FinanceOperation` '.
     158    $DbResult = $this->Database->query('SELECT `FinanceOperation`.*, `FinanceOperationGroup`.`Direction`, `DocumentLineCode`.`Name` AS `BillName` FROM `FinanceOperation` '.
    156159      'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     160      'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceOperation`.`BillCode` '.
    157161      'WHERE `FinanceOperation`.`Id`='.$this->OperationId);
    158162    $Operation = $DbResult->fetch_assoc();
     
    195199      '</td><td width="50%" valign="top">'.
    196200      '<font size="5"><strong>'.$Desc['Type'].' POKLADNÍ DOKLAD</strong></font><br><br>'.
    197       'Číslo dokladu: '.$Operation['BillCode'].'<br>'.
     201      'Číslo dokladu: '.$Operation['BillName'].'<br>'.
    198202      'Datum vystavení: '.HumanDate($Operation['Time']).'<br>'.
    199203      '</td></tr>'.
  • trunk/Modules/Finance/Finance.php

    r747 r748  
    1717define('INVOICE_GROUP_OUT', 2);
    1818define('VAT_TYPE_BASE', 2);
    19 define('FINANCE_DIRECTION_OUT', 0);
    20 define('FINANCE_DIRECTION_IN', 1);
     19define('FINANCE_DIRECTION_OUT', 1);
     20define('FINANCE_DIRECTION_IN', 0);
    2121
    2222class Finance extends Model
     
    3939  var $BillingPeriods;
    4040  var $DirectoryId;
     41  var $Rounding;
    4142
    4243  function LoadMonthParameters($Period = 1) // 0 - now, 1 - next month
     
    7475    $this->TotalInternetPaid = $Row['MonthlyInternet'];
    7576    $this->TotalPaid = $Row['MonthlyTotal'];
     77    $this->Rounding = $this->System->Config['Finance']['Rounding'];
    7678  }
    7779
     
    293295        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
    294296        'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
    295         'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
     297        'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
    296298      ),
    297299    ));
     
    325327        'Value' => array('Type' => 'Integer', 'Caption' => 'Částka absolutní', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
    326328        'ValueUser' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    327           'SQL' => 'SELECT SUM(CEIL(`Price`*`Quantity`)) FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice`=#Id'),
     329          'SQL' => 'SELECT ROUND(SUM(`Price`*`Quantity`), '.$Config['Finance']['Rounding'].') FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice`=#Id'),
     330        'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
    328331        'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
    329332        'PeriodFrom' => array('Type' => 'Date', 'Caption' => 'Období od', 'Default' => '', 'Null' => true),
     
    390393        'VAT' => array('Type' => 'Integer', 'Caption' => 'Daň', 'Default' => '21', 'Suffix' => '%'),
    391394        'Total' => array('Type' => 'Integer', 'Caption' => 'Celkem', 'Default' => '', 'Suffix' => 'Kč',
    392           'ReadOnly' => true, 'SQL' => 'CEIL(`Price` * `Quantity`)'),
     395          'ReadOnly' => true, 'SQL' => 'ROUND(`Price` * `Quantity`, '.$Config['Finance']['Rounding'].')'),
    393396      ),
    394397      'AfterInsert' => array($this, 'AfterInsertFinanceInvoiceItem'),
  • trunk/Modules/Finance/Manage.php

    r747 r748  
    109109    $SumValue = 0;
    110110    foreach($Items as $Item) {
    111       $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']);
    112     }
     111      $SumValue = $SumValue + $Item['Price'] * $Item['Quantity'];
     112    }
     113    $Finance = &$this->System->Modules['Finance'];
     114    $SumValue = round($SumValue, $Finance->Rounding);
    113115    $this->Database->insert('FinanceInvoice', array(
    114116      'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation),
  • trunk/Modules/Finance/UserState.php

    r747 r748  
    99  function ShowFinanceOperation($Subject)
    1010  {
    11     $UserOperationTableQuery = '((SELECT `Text`, `Time`, `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
    12       'FROM `FinanceOperation` WHERE (`Subject`='.$Subject['Id'].')) UNION ALL '.
     11    $UserOperationTableQuery = '((SELECT `Text`, `Time`, `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo`, `DocumentLineCode`.`Name` AS `BillName` '.
     12      'FROM `FinanceOperation` '.
     13      'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceOperation`.`BillCode` '.
     14      'WHERE (`Subject`='.$Subject['Id'].') '.
     15      ') UNION ALL '.
    1316      '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ",") FROM `FinanceInvoiceItem` WHERE `FinanceInvoice`=`FinanceInvoice`.`Id`) AS `Text`, '.
    14       '`Time`, -`Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')))';
     17      '`Time`, -`Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo`, `DocumentLineCode`.`Name` AS `BillName` FROM `FinanceInvoice` '.
     18      'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceInvoice`.`BillCode` '.
     19      'WHERE (`Subject`='.$Subject['Id'].')))';
    1520
    1621    $Output = '<div style="text-align:center">Výpis finančních operací</div>';
     
    4651      if($Row['Value'] == -0) $Row['Value'] = 0;
    4752      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']);
     53      if($Row['BillName'] == '') $Row['BillName'] = 'PDF';
     54      if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/file?id='.$Row['File']).'">'.$Row['BillName'].'</a>';
     55        else $Invoice = NotBlank($Row['BillName']);
    5156      if($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
    52       else $Period = '&nbsp;';
     57        else $Period = '&nbsp;';
    5358      $Output .= '<tr><td style="text-align: right;">'.HumanDate($Row['Time']).'</td>'.
    5459          '<td style="text-align: left;">'.$Row['Text'].'</td>'.
  • trunk/Modules/Finance/Zivnost.php

    r740 r748  
    1111  {
    1212    $Balance = array();
    13     $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (ValueSign = 1)');
     13    $DbResult = $this->Database->query('SELECT SUM(`Value`) FROM `FinanceOperation` '.
     14      'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `FinanceOperation`.`Group` '.
     15      'WHERE (`Time` < "'.TimeToMysqlDateTime($StartTime).'") AND (`Time` >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = 1)');
    1416    $Row = $DbResult->fetch_array();
    1517    $Balance['Income']['Start'] = $Row[0] + 0;
    16     $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (ValueSign = 1)');
     18    $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation '.
     19      'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `FinanceOperation`.`Group` '.
     20      'WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (`FinanceOperationGroup`.`ValueSign` = 1)');
    1721    //echo('SELECT SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value > 0 AND Taxable = 1'.'<br />');
    1822    $Row = $DbResult->fetch_array();
    1923    $Balance['Income']['End'] = $Row[0] + 0;
    2024
    21     $DbResult = $this->Database->query('SELECT -SUM(Value*ValueSign) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (ValueSign = -1)');
     25    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceOperation '.
     26      'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `FinanceOperation`.`Group` '.
     27      'WHERE (`Time` < "'.TimeToMysqlDateTime($StartTime).'") AND (`Time` >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = -1)');
    2228    $Row = $DbResult->fetch_array();
    2329    $Balance['Spend']['Start'] = $Row[0] + 0;
    24     $DbResult = $this->Database->query('SELECT -SUM(Value*ValueSign) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (ValueSign = -1)');
     30    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceOperation '.
     31      'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `FinanceOperation`.`Group` '.
     32      'WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (`FinanceOperationGroup`.`ValueSign` = -1)');
    2533          //echo('SELECT -SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value < 0 AND Taxable = 1'.'<br />');
    2634    $Row = $DbResult->fetch_array();
    2735    $Balance['Spend']['End'] = $Row[0] + 0;
    2836
    29     $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = 1)');
     37    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice '.
     38      'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `FinanceInvoice`.`Group` '.
     39      'WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (`FinanceInvoiceGroup`.`ValueSign` = 1)');
    3040    $Row = $DbResult->fetch_array();
    3141    $Balance['Claims']['Start'] = $Row[0] + 0;
    32     $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = 1)');
     42    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice '.
     43      'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `FinanceInvoice`.`Group` '.
     44      'WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (`FinanceInvoiceGroup`.`ValueSign` = 1)');
    3345    $Row = $DbResult->fetch_array();
    3446    $Balance['Claims']['End'] = $Row[0] + 0;
    3547
    36     $DbResult = $this->Database->query('SELECT -SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = -1)');
     48    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice '.
     49      'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `FinanceInvoice`.`Group` '.
     50      'WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (`FinanceInvoiceGroup`.`ValueSign` = -1)');
    3751    $Row = $DbResult->fetch_array();
    3852    $Balance['Liabilities']['Start'] = $Row[0] + 0;
    39     $DbResult = $this->Database->query('SELECT -SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = -1)');
     53    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice '.
     54      'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `FinanceInvoice`.`Group` '.
     55      'WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (`FinanceInvoiceGroup`.`ValueSign` = -1)');
    4056    $Row = $DbResult->fetch_array();
    4157    $Balance['Liabilities']['End'] = $Row[0] + 0;
     
    5470  function Show()
    5571  {
    56     if(!$this->System->User->CheckPermission('Finance', 'TradingStatus')) return('Nemáte oprávnění');
     72    if(!$this->System->User->CheckPermission('Finance', 'TradingStatus'))
     73      return('Nemáte oprávnění');
     74
     75    $Finance = &$this->System->Modules['Finance'];
    5776
    5877    $Output = '';
     
    143162        $Output .= '<table style="font-size: smaller;" class="WideTable">';
    144163        $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>';
    145         $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
    146           'WHERE (ValueSign = 1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
     164        $DbResult = $this->Database->query('SELECT `FinanceOperation`.*, `DocumentLineCode`.`Name` AS `BillName`, `Subject`.`Name` AS `Name` FROM `FinanceOperation` '.
     165          'LEFT JOIN `Subject` ON `Subject`.`Id` = `FinanceOperation`.`Subject` '.
     166          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `FinanceOperation`.`Group` '.
     167          'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id` = `FinanceOperation`.`BillCode` '.
     168          'WHERE (`ValueSign` = 1) AND (`FinanceOperation`.`Time` >= "'.$Year['DateStart'].'") '.
     169          'AND (`FinanceOperation`.`Time` <= "'.$Year['DateEnd'].'") ORDER BY `Time`');
    147170        while($Row = $DbResult->fetch_array())
    148171        {
    149172          $Row['Time'] = explode(' ', $Row['Time']);
    150173          $Row['Time'] = $Row['Time'][0];
    151           $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>';
     174          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillName'].
     175            '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].
     176            '</td><td>'.$Table[$Row['Taxable']].'</td><td>'.$Table[$Row['Cash']].'</td></tr>';
    152177          $Total += $Row['Value'];
    153178          $TotalTax[$Row['Taxable']] += $Row['Value'];
     
    173198        $Output .= '<table style="font-size: smaller;" class="WideTable">';
    174199        $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>';
    175         $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
    176           'WHERE (ValueSign = -1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
     200        $DbResult = $this->Database->query('SELECT `FinanceOperation`.*, `DocumentLineCode`.`Name` AS `BillName`, `Subject`.`Name` AS `Name` FROM `FinanceOperation` '.
     201          'LEFT JOIN `Subject` ON `Subject`.`Id` = `FinanceOperation`.`Subject` '.
     202          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `FinanceOperation`.`Group` '.
     203          'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id` = `FinanceOperation`.`BillCode` '.
     204          'WHERE (`FinanceOperationGroup`.`ValueSign` = -1) AND (`FinanceOperation`.`Time` >= "'.$Year['DateStart'].'") '.
     205          'AND (`FinanceOperation`.`Time` <= "'.$Year['DateEnd'].'") ORDER BY `Time`');
    177206        while($Row = $DbResult->fetch_array())
    178207        {
     
    180209          $Row['Time'] = $Row['Time'][0];
    181210          $Row['Value'] = $Row['Value'];
    182           $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>';
     211          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillName'].
     212            '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].
     213            '</td><td>'.$Table[$Row['Taxable']].'</td><td>'.$Table[$Row['Cash']].'</td></tr>';
    183214          $Total += $Row['Value'];
    184215          $TotalTax[$Row['Taxable']] += $Row['Value'];
     
    202233        $Output .= '<table style="font-size: smaller;" class="WideTable">';
    203234        $Output .= '<tr><th>Čas vystavení</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th></tr>';
    204         $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '.
     235        $DbResult = $this->Database->query('SELECT `FinanceInvoice`.*, (SELECT GROUP_CONCAT(Description SEPARATOR ",") '.
     236          'FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text, `DocumentLineCode`.`Name` AS `BillName`, `Subject`.`Name` AS `Name` '.
    205237          'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '.
    206           'WHERE (ValueSign = 1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
     238          'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `FinanceInvoice`.`Group` '.
     239          'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id` = `FinanceInvoice`.`BillCode` '.
     240          'WHERE (`FinanceInvoiceGroup`.`ValueSign` = 1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
    207241          '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    208242        while($Row = $DbResult->fetch_array())
    209243        {
    210244          if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = '&nbsp;';
    211           $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].
    212             '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['ValueSign']).'</td></tr>';
     245          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillName'].
     246            '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td></tr>';
    213247          $Total += $Row['Value'];
    214248        }
     
    225259        $Output .= '<table style="font-size: smaller;" class="WideTable">';
    226260        $Output .= '<tr><th>Čas vystavení</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th></tr>';
    227         $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '.
     261        $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") '.
     262          'FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS `Text`, `DocumentLineCode`.`Name` AS `BillName` '.
    228263          'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '.
    229           'WHERE (ValueSign = -1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
     264          'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `FinanceInvoice`.`Group` '.
     265          'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id` = `FinanceInvoice`.`BillCode` '.
     266          'WHERE (`FinanceInvoiceGroup`.`ValueSign` = -1) AND (`FinanceInvoice`.`Time` >= "'.$Year['DateStart'].
    230267          '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    231268        while($Row = $DbResult->fetch_array())
     
    233270          if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = '&nbsp;';
    234271          $Row['Value'] = $Row['Value'] * -1;
    235           $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].
     272          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillName'].
    236273            '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['ValueSign']).'</td></tr>';
    237274          $Total += $Row['Value'];
     
    245282        $Output .= '<tr><th>Jméno</th><th>Závazky [Kč]</th><th>Pohledávky [Kč]</th><th>Příjmy [Kč]</th><th>Výdaje [Kč]</th><th>Stav účtu</th><th>Starý systém</th></tr>';
    246283        $DbResult = $this->Database->query('SELECT Id, Name, 0 AS Cash, '.
    247         '(SELECT SUM(T1.Value*T1.ValueSign) FROM FinanceInvoice AS T1 WHERE (T1.Subject = Subject.Id) AND (T1.ValueSign = 1)) as Claims, '.
    248         '(SELECT SUM(T2.Value*T2.ValueSign) FROM FinanceInvoice AS T2 WHERE (T2.Subject = Subject.Id) AND (T2.ValueSign = 1) AND (TimePayment IS NULL)) as OpenedClaims, '.
    249         '(SELECT -SUM(T3.Value*T3.ValueSign) FROM FinanceInvoice AS T3 WHERE (T3.Subject = Subject.Id) AND (T3.ValueSign = -1)) as Liabilities, '.
    250         '(SELECT -SUM(T4.Value*T4.ValueSign) FROM FinanceInvoice AS T4 WHERE (T4.Subject = Subject.Id) AND (T4.ValueSign = -1) AND (TimePayment IS NULL)) AS OpenedLiabilities, '.
    251         '(SELECT SUM(T5.Value*T5.ValueSign) FROM FinanceOperation AS T5 WHERE (T5.Subject = Subject.Id) AND (T5.ValueSign = 1)) AS Gains, '.
    252         '(SELECT SUM(T6.Value*T6.ValueSign) FROM FinanceOperation AS T6 WHERE (T6.Subject = Subject.Id) AND (T6.ValueSign = -1)) AS Spends '.
     284        '(SELECT SUM(T1.Value) FROM FinanceInvoice AS T1 '.
     285         'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `T1`.`Group` '.
     286         'WHERE (T1.Subject = Subject.Id) AND (`FinanceInvoiceGroup`.ValueSign = 1)) AS `Claims`, '.
     287        '(SELECT SUM(T2.Value) FROM FinanceInvoice AS T2 '.
     288         'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `T2`.`Group` '.
     289         'WHERE (T2.Subject = Subject.Id) AND (`FinanceInvoiceGroup`.`ValueSign` = 1) AND (TimePayment IS NULL)) AS `OpenedClaims`, '.
     290        '(SELECT -SUM(T3.Value) FROM FinanceInvoice AS T3 '.
     291        'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `T3`.`Group` '.
     292        'WHERE (T3.Subject = Subject.Id) AND (`FinanceInvoiceGroup`.`ValueSign` = -1)) AS `Liabilities`, '.
     293        '(SELECT -SUM(T4.Value) FROM FinanceInvoice AS T4 '.
     294        'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id` = `T4`.`Group` '.
     295        'WHERE (T4.Subject = Subject.Id) AND (`FinanceInvoiceGroup`.`ValueSign` = -1) AND (`TimePayment` IS NULL)) AS `OpenedLiabilities`, '.
     296        '(SELECT SUM(T5.Value) FROM FinanceOperation AS T5 '.
     297        'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `T5`.`Group` '.
     298        'WHERE (T5.Subject = Subject.Id) AND (`FinanceOperationGroup`.`ValueSign` = 1)) AS `Gains`, '.
     299        '(SELECT SUM(T6.Value) FROM FinanceOperation AS T6 '.
     300        'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id` = `T6`.`Group` '.
     301        'WHERE (T6.Subject = Subject.Id) AND (`FinanceOperationGroup`.`ValueSign` = -1)) AS `Spends` '.
    253302        'FROM Subject ORDER BY Name');
    254303        while($Row = $DbResult->fetch_assoc())
     
    276325        $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
    277326        $Output .= '<tr><th>Datum</th><th>Název</th><th>Hodnota [Kč]</th><th>Doklad</th></tr>';
    278         $DbResult = $this->Database->select('FinanceOperation', '*', 'Subject='.$_GET['Id'].' ORDER BY Time');
     327        $DbResult = $this->Database->query('SELECT `FinanceOperation`.*, `DocumentLineCode`.`Name` AS `BillName` FROM `FinanceOperation` '.
     328          'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id` = `FinanceOperation`.`BillCode` '.
     329          'WHERE `Subject=`'.$_GET['Id'].' ORDER BY `Time`');
    279330        while($Row = $DbResult->fetch_array())
    280331        {
    281332          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['Text'].
    282             '</td><td>'.($Row['Value']*$Row['ValueSign']).'</td><td>'.$Row['BillCode'].'</td></tr>';
     333            '</td><td>'.($Row['Value']*$Row['ValueSign']).'</td><td>'.$Row['BillName'].'</td></tr>';
    283334        }
    284335        $Output .= '</table></td><td style="vertical-align: top;">';
     
    287338        $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
    288339        $Output .= '<tr><th>Datum vytvoření</th><th>Datum zaplacení</th><th>Název</th><th>Hodnota [Kč]</th><th>Doklad</th></tr>';
    289         $DbResult = $this->Database->select('FinanceInvoice', '*, (SELECT GROUP_CONCAT(Description SEPARATOR ",") '.
    290           'FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text',
    291           'Subject='.$_GET['Id'].' ORDER BY Time');
     340        $DbResult = $this->Database->query('SELECT `FinanceInvoice`.*, (SELECT GROUP_CONCAT(Description SEPARATOR ",") '.
     341          'FROM FinanceInvoiceItem WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`) AS `Text`, `DocumentLineCode`.`Name` AS `BillName` '.
     342          'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id` = `FinanceOperation`.`BillCode` '.
     343          'WHERE `Subject`='.$_GET['Id'].' ORDER BY `Time`');
    292344        while($Row = $DbResult->fetch_array())
    293345        {
    294346          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.HumanDate($Row['TimePayment']).
    295             '</td><td>'.$Row['Text'].'</td><td>'.ceil($Row['Value'] * $Row['ValueSign']).'</td><td>'.$Row['BillCode'].'</td></tr>';
     347            '</td><td>'.$Row['Text'].'</td><td>'.round($Row['Value'] * $Row['ValueSign'], $Finance->Rounding).'</td><td>'.$Row['BillName'].'</td></tr>';
    296348        }
    297349        $Output .= '</table></td></tr></table>';
Note: See TracChangeset for help on using the changeset viewer.