Changeset 747


Ignore:
Timestamp:
Sep 21, 2015, 12:12:26 AM (9 years ago)
Author:
chronos
Message:

This solves problem with inconsistency between invoice and invoice items values and inconsistency between selected document line and incorrect positive or negative values.

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/FormClasses.php

    r742 r747  
    5252    'Items' => array(
    5353      'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
    54       'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),     
     54      'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
    5555    ),
    5656  ),
     
    7878        'ReadOnly' => true),
    7979      'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    80         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    81         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`ValueSign` = 1))'),
     80        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     81        'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     82        'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     83        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
    8284      'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    83         'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    84         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`ValueSign` = -1))'),
     85        'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     86        'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     87        'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     88        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
    8589      'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    86         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     90        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     91        'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    8792        'AND (`FinanceOperation`.`Time` >= `DateStart`))'),
    8893      'TaxIncome' => array('Type' => 'Integer', 'Caption' => 'Daňové příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    89         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    90         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`ValueSign` = 1))'),
     94        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     95        'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     96        'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     97        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
    9198      'TaxSpending' => array('Type' => 'Integer', 'Caption' => 'Daňové výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    92         'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    93         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`ValueSign` = -1))'),
     99        'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     100        'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     101        'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     102        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
    94103      'TaxBase' => array('Type' => 'Integer', 'Caption' => 'Základ daně', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    95         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     104        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     105        'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    96106        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1))'),
    97107      'Claims' => array('Type' => 'Integer', 'Caption' => 'Pohledávky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    98         'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
    99         'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`ValueSign` = 1))'),
     108        'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` '.
     109        'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
     110        'WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     111        'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoiceGroup`.`ValueSign` = 1))'),
    100112      'Liabilities' => array('Type' => 'Integer', 'Caption' => 'Závazky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    101         'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
    102         'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`ValueSign` = -1))'),
     113        'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` '.
     114        'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
     115        'WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     116        'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoiceGroup`.`ValueSign` = -1))'),
    103117      'InvoiceBalance' => array('Type' => 'Integer', 'Caption' => 'Fakturační rozdíl', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    104         'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     118        'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
    105119        'AND (`FinanceInvoice`.`Time` >= `DateStart`))'),
    106120    ),
  • trunk/Application/System.php

    r744 r747  
    2020  /** @var AppModuleManager */
    2121  var $ModuleManager;
     22  /** @var FormManager */
     23  var $FormManager;
     24  /** @var Config */
     25  var $ConfigManager;
    2226  var $PathItems;
    2327  var $RootURLFolder;
  • trunk/Application/Version.php

    r742 r747  
    11<?php
    22
    3 $Revision = 742; // Subversion revision
    4 $DatabaseRevision = 742; // SQL structure revision
    5 $ReleaseTime = strtotime('2015-07-05');
     3$Revision = 747; // Subversion revision
     4$DatabaseRevision = 747; // SQL structure revision
     5$ReleaseTime = strtotime('2015-09-19');
  • trunk/Common/Form/Form.php

    r738 r747  
    11<?php
    22
    3 include_once(dirname(__FILE__).'/../Database.php');
    43include_once(dirname(__FILE__).'/Types/Type.php');
    54
     
    232231    foreach($this->Definition['Items'] as $Index => $Item)
    233232    {
    234       if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    235       if($Item['ReadOnly'] == false)
     233      if(array_key_exists($Index, $this->Values))
    236234      if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    237235      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
  • trunk/Common/Setup/Updates.php

    r743 r747  
    14891489}
    14901490
     1491function UpdateTo748($Manager)
     1492{
     1493  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD `ValueUser` FLOAT NOT NULL AFTER `Value`;');
     1494  $Manager->Execute('UPDATE `FinanceOperation` SET `ValueUser`=`Value`');
     1495  $Manager->Execute('UPDATE `FinanceOperation` SET `Value`=`ValueUser`*`ValueSign`');
     1496  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=1 WHERE (`ValueSign`=1) AND (`Cash`=1)');
     1497  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=2 WHERE (`ValueSign`=-1) AND (`Cash`=1)');
     1498  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=3 WHERE (`ValueSign`=1) AND (`Cash`=0)');
     1499  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=4 WHERE (`ValueSign`=-1) AND (`Cash`=0)');
     1500  $Manager->Execute('ALTER TABLE `FinanceOperation` DROP `Direction`, DROP `ValueSign`;');
     1501
     1502  // SELECT FinanceInvoice.* FROM `FinanceInvoice` LEFT JOIN FinanceInvoiceGroup ON FinanceInvoiceGroup.Id=FinanceInvoice.Group WHERE FinanceInvoice.ValueSign != FinanceInvoiceGroup.ValueSign
     1503  $Manager->Execute('UPDATE `FinanceInvoice` SET `Group`=1 WHERE (`ValueSign`=-1)');
     1504  $Manager->Execute('UPDATE `FinanceInvoice` SET `Group`=2 WHERE (`ValueSign`=1)');
     1505  $Manager->Execute('UPDATE `FinanceInvoice` SET `Value`=`Value`*`ValueSign`');
     1506  $Manager->Execute('ALTER TABLE `FinanceInvoice` DROP `Direction`, DROP `ValueSign`;');
     1507  // 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`
     1509}
    14911510
    14921511class Updates
     
    15571576      735 => array('Revision' => 736, 'Function' => 'UpdateTo736'),
    15581577      736 => array('Revision' => 739, 'Function' => 'UpdateTo739'),
    1559           739 => array('Revision' => 740, 'Function' => 'UpdateTo740'),
     1578      739 => array('Revision' => 740, 'Function' => 'UpdateTo740'),
    15601579      740 => array('Revision' => 741, 'Function' => 'UpdateTo741'),
    15611580      741 => array('Revision' => 742, 'Function' => 'UpdateTo742'),
     1581      742 => array('Revision' => 748, 'Function' => 'UpdateTo748'),
    15621582    ));
    15631583  }
  • trunk/Modules/Finance/Bill.php

    r741 r747  
    5252  function GenerateHTML()
    5353  {
    54     $DbResult = $this->Database->select('FinanceInvoice', '*', '`Id`='.$this->InvoiceId);
     54    $DbResult = $this->Database->query('SELECT `FinanceInvoice`.*, `FinanceInvoiceGroup`.`Direction` FROM `FinanceInvoice` '.
     55      'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
     56      'WHERE `FinanceInvoice`.`Id`='.$this->InvoiceId);
    5557    $Invoice = $DbResult->fetch_assoc();
    5658
     
    7981
    8082    // If direction is in => switch sides
    81     if($Invoice['Direction'] == FINANCE_DIRECTION_OUT) 
    82     {           
     83    if($Invoice['Direction'] == FINANCE_DIRECTION_OUT)
     84    {
    8385    }
    8486    else if($Invoice['Direction'] == FINANCE_DIRECTION_IN)
     
    151153  function GenerateHTML()
    152154  {
    153     $DbResult = $this->Database->select('FinanceOperation', '*', '`Id`='.$this->OperationId);
     155    $DbResult = $this->Database->query('SELECT `FinanceOperation`.*, `FinanceOperationGroup`.`Direction` FROM `FinanceOperation` '.
     156      'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     157      'WHERE `FinanceOperation`.`Id`='.$this->OperationId);
    154158    $Operation = $DbResult->fetch_assoc();
    155159
  • trunk/Modules/Finance/Finance.php

    r742 r747  
    109109  }
    110110
     111  function GetNextDocumentLineNumberId($Id, $FinanceYear = 0)
     112  {
     113    $Code = $this->GetNextDocumentLineNumber($Id, $FinanceYear);
     114    $this->Database->insert('DocumentLineCode', array('DocumentLine' => $Id, 'Name' => $Code));
     115    return $this->Database->insert_id;
     116  }
     117
    111118  function GetFinanceGroupById($Id, $Table)
    112119  {
     
    125132    while($Member = $DbResult->fetch_assoc())
    126133    {
    127       $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(`Value` * `ValueSign`), 0) FROM `FinanceOperation` '.
    128           'WHERE `Subject`='.$Member['Subject'].') - (SELECT COALESCE(SUM(`Value` * `ValueSign`), 0) FROM `FinanceInvoice` '.
     134      $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(`Value`), 0) FROM `FinanceOperation` '.
     135          'WHERE `Subject`='.$Member['Subject'].') - (SELECT COALESCE(SUM(`Value`), 0) FROM `FinanceInvoice` '.
    129136          'WHERE `Subject`='.$Member['Subject'].')) AS `Cash`');
    130137      $Cash = $DbResult2->fetch_row();
     
    220227        'Cash' => array('Type' => 'Boolean', 'Caption' => 'Hotově', 'Default' => ''),
    221228        'Taxable' => array('Type' => 'Boolean', 'Caption' => 'Zdanitelné', 'Default' => ''),
    222         'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
    223         'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko', 'Default' => '1'),
    224         'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
     229        'Value' => array('Type' => 'Integer', 'Caption' => 'Částka absolutní', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
     230        'ValueUser' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
    225231        'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
    226232        'Text' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
     
    232238      ),
    233239      'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
     240      'AfterInsert' => array($this, 'AfterInsertFinanceOperation'),
     241      'BeforeModify' => array($this, 'BeforeModifyFinanceOperation'),
    234242    ));
    235243
     
    243251    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    244252    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['BankAccount']['Hidden'] = true;
     253    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Value']['Hidden'] = true;
    245254
    246255    $this->System->FormManager->RegisterClass('FinanceTreasuryOut', $this->System->FormManager->Classes['FinanceOperation']);
     
    253262    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    254263    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['BankAccount']['Hidden'] = true;
     264    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Value']['Hidden'] = true;
    255265
    256266    $this->System->FormManager->RegisterClass('FinanceAccountIn', $this->System->FormManager->Classes['FinanceOperation']);
     
    263273    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    264274    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Treasury']['Hidden'] = true;
     275    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Value']['Hidden'] = true;
    265276
    266277    $this->System->FormManager->RegisterClass('FinanceAccountOut', $this->System->FormManager->Classes['FinanceOperation']);
     
    273284    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    274285    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true;
     286    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Value']['Hidden'] = true;
    275287
    276288    $this->System->FormManager->RegisterClass('FinanceOperationGroup', array(
     
    311323        'TimeDue' => array('Type' => 'Date', 'Caption' => 'Čas splatnosti', 'Default' => ''),
    312324        'TimePayment' => array('Type' => 'Date', 'Caption' => 'Čas zaplacení', 'Default' => '', 'Null' => true),
    313         'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
    314         'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko', 'Default' => '1'),
    315         'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
    316         'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
     325        'Value' => array('Type' => 'Integer', 'Caption' => 'Částka absolutní', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
     326        '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'),
    317328        'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
    318329        'PeriodFrom' => array('Type' => 'Date', 'Caption' => 'Období od', 'Default' => '', 'Null' => true),
     
    325336          'WHERE `FinanceInvoiceOperationRel`.`Invoice`=#Id)'),
    326337      ),
    327       'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
     338      'BeforeInsert' => array($this, 'BeforeInsertFinanceInvoice'),
     339      'AfterInsert' => array($this, 'AfterInsertFinanceInvoice'),
     340      'BeforeModify' => array($this, 'BeforeModifyFinanceInvoice'),
    328341    ));
    329342    $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']);
     
    332345    $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Hidden'] = true;
    333346    $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Filter'] = true;
     347    $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Value']['Hidden'] = true;
    334348
    335349    $this->System->FormManager->RegisterClass('FinanceInvoiceOut', $this->System->FormManager->Classes['FinanceInvoice']);
     
    338352    $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Hidden'] = true;
    339353    $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Filter'] = true;
     354    $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Value']['Hidden'] = true;
    340355
    341356    $this->System->FormManager->RegisterClass('FinanceInvoiceGroup', array(
     
    346361        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
    347362        'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
    348         'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
     363        'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
    349364      ),
    350365    ));
     
    377392          'ReadOnly' => true, 'SQL' => 'CEIL(`Price` * `Quantity`)'),
    378393      ),
     394      'AfterInsert' => array($this, 'AfterInsertFinanceInvoiceItem'),
     395      'AfterModify' => array($this, 'AfterModifyFinanceInvoiceItem'),
     396      'AfterDelete' => array($this, 'AfterModifyFinanceInvoiceItem'),
    379397    ));
    380398    $this->System->FormManager->RegisterClass('FinanceTreasury', array(
     
    386404        'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
    387405        'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
    388           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '.
     406          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
    389407          'WHERE `FinanceOperation`.`Treasury`=#Id)'),
    390408        'Operations' => array('Type' => 'TFinanceOperationListTreasury', 'Caption' => 'Operace', 'Default' => ''),
     
    417435        'LastImportId' => array('Type' => 'String', 'Caption' => 'Id posledního importu', 'Default' => ''),
    418436        'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
    419           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '.
     437          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
    420438          'WHERE `FinanceOperation`.`BankAccount`=#Id)'),
    421439        'AutoImport' => array('Type' => 'Boolean', 'Caption' => 'Automaticky stahovat z banky', 'Default' => ''),
     
    551569      else $Year = date("Y", $Form->Values['ValidFrom']);
    552570    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
    553     $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($FinanceGroup['DocumentLine'], $Year);
     571    $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
     572    return($Form->Values);
     573  }
     574
     575  function AfterInsertFinanceOperation($Form, $Id)
     576  {
     577    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
     578    $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
     579      ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
     580    return($Form->Values);
     581  }
     582
     583  function BeforeModifyFinanceOperation($Form, $Id)
     584  {
     585    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
     586    $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
     587      ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
     588    return($Form->Values);
     589  }
     590
     591  function BeforeInsertFinanceInvoice($Form)
     592  {
     593    if(array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
     594      else $Year = date("Y", $Form->Values['ValidFrom']);
     595    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
     596    $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
     597    return($Form->Values);
     598  }
     599
     600  function AfterInsertFinanceInvoice($Form, $Id)
     601  {
     602    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
     603    $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL']));
     604    $DbRow = $DbResult->fetch_row();
     605    $Sum = $DbRow[0];
     606
     607    $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
     608      ($Sum * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
     609    return($Form->Values);
     610  }
     611
     612  function BeforeModifyFinanceInvoice($Form, $Id)
     613  {
     614    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
     615    $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL']));
     616    $DbRow = $DbResult->fetch_row();
     617    $Sum = $DbRow[0];
     618    $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
     619      ($Sum * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
     620    return($Form->Values);
     621  }
     622
     623  function AfterInsertFinanceInvoiceItem($Form, $Id)
     624  {
     625    $ParentForm = new Form($this->System->FormManager);
     626    $ParentForm->SetClass('FinanceInvoice');
     627    $ParentForm->LoadValuesFromDatabase($Form->Values['FinanceInvoice']);
     628    $this->AfterInsertFinanceInvoice($ParentForm, $Form->Values['FinanceInvoice']);
     629    return($Form->Values);
     630  }
     631
     632  function AfterModifyFinanceInvoiceItem($Form, $Id)
     633  {
     634    $ParentForm = new Form($this->System->FormManager);
     635    $ParentForm->SetClass('FinanceInvoice');
     636    $ParentForm->LoadValuesFromDatabase($Form->Values['FinanceInvoice']);
     637    $this->BeforeModifyFinanceInvoice($ParentForm, $Form->Values['FinanceInvoice']);
    554638    return($Form->Values);
    555639  }
  • trunk/Modules/Finance/Import.php

    r740 r747  
    120120  }
    121121
    122   function InsertMoney($Subject, $Value, $ValueSign, $Cash, $Taxable, $Time, $Text, $Group)
     122  function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $Group)
    123123  {
    124124    $Year = date('Y', $Time);
    125     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($Group['DocumentLine'], $Year);
     125    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year);
    126126    // TODO: Fixed BankAccount=1, allow to select bank account for import
    127127    $this->Database->insert('FinanceOperation', array('Text' => $Text,
    128       'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'ValueSign' => $ValueSign,
     128      'Subject' => $Subject, 'Cash' => $Cash, 'ValueUser' => $Value, 'Value' => $Value * $Group['ValueSign'],
    129129      'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode,
    130130      'BankAccount' => 1, 'Group' => $Group['Id']));
     131    // TODO: Update Value
    131132  }
    132133
     
    146147      $Date = explode('-', $_POST['Date'.$I]);
    147148      $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
    148       $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $FinanceGroup['ValueSign'],
     149      $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]),
    149150        0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $FinanceGroup);
    150151      $Output .= $I.', ';
  • trunk/Modules/Finance/Manage.php

    r741 r747  
    100100  }
    101101
    102   function InsertInvoice($Subject, $TimeCreation, $TimeDue, $ValueSign, $Items,
    103   $Group, $PeriodFrom, $PeriodTo, $Direction)
     102  function InsertInvoice($Subject, $TimeCreation, $TimeDue, $Items,
     103    $Group, $PeriodFrom, $PeriodTo)
    104104  {
    105105    global $LastInsertTime;
    106106
    107107    $Year = date('Y', $TimeCreation);
    108     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($Group['DocumentLine'], $Year);
     108    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year);
    109109    $SumValue = 0;
    110110    foreach($Items as $Item) {
     
    113113    $this->Database->insert('FinanceInvoice', array(
    114114      'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation),
    115       'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue,
    116       'ValueSign' => $ValueSign, 'BillCode' => $BillCode, 'Direction' => $Direction,
     115      'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue * $Group['ValueSign'],
     116      'BillCode' => $BillCode,
    117117      'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo),
    118       'Generate' => 1, 'Group' => $FinanceGroup['Id']));
     118      'Generate' => 1, 'Group' => $Group['Id']));
    119119    $InvoiceId = $this->Database->insert_id;
    120120    foreach($Items as $Item)
     
    185185          $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />';
    186186          $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS,
    187             $FinanceGroup['ValueSign'], $InvoiceItems, $FinanceGroup, $Period['From'],
    188                 $Period['To'], $FinanceGroup['Direction']);
     187            $InvoiceItems, $FinanceGroup, $Period['From'],
     188            $Period['To']);
    189189
    190190          $Output .= $this->SendPaymentEmail($Member['Id']);
     
    358358        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Popis</th>'.
    359359        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Částka [Kč]</th></tr>'."\n";
    360       $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT `Text`, `Time`, (`Value`*`ValueSign`) AS `Value`, `File` FROM `FinanceOperation` WHERE (`Subject`='.$Member['Subject'].')) UNION ALL '.
     360      $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT `Text`, `Time`, `Value`, `File` FROM `FinanceOperation` WHERE (`Subject`='.$Member['Subject'].')) UNION ALL '.
    361361        '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ", ") FROM `FinanceInvoiceItem` '.
    362362        'WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`) AS `Text`, '.
    363         '`Time`, -(`Value`*`ValueSign`) AS `Value`, `File` FROM `FinanceInvoice` WHERE (`Subject`='.
     363        '`Time`, -`Value`, `File` FROM `FinanceInvoice` WHERE (`Subject`='.
    364364        $Member['Subject'].')) ORDER BY `Time` DESC) AS `T1` WHERE (`T1`.`Time` > "'.$Member['BillingPeriodLastDate'].'")');
    365365      while($DbRow = $DbResult->fetch_assoc())
  • trunk/Modules/Finance/UserState.php

    r740 r747  
    99  function ShowFinanceOperation($Subject)
    1010  {
    11     $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`ValueSign`) AS `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
     11    $UserOperationTableQuery = '((SELECT `Text`, `Time`, `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
    1212      'FROM `FinanceOperation` WHERE (`Subject`='.$Subject['Id'].')) UNION ALL '.
    1313      '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ",") FROM `FinanceInvoiceItem` WHERE `FinanceInvoice`=`FinanceInvoice`.`Id`) AS `Text`, '.
    14       '`Time`, -(`Value`*`ValueSign`) AS `Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')))';
     14      '`Time`, -`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>';
     
    105105
    106106    // Account state
    107     $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`ValueSign`) AS `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
     107    $UserOperationTableQuery = '((SELECT `Text`, `Time`, `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
    108108      'FROM `FinanceOperation` WHERE (`Subject`='.$Subject['Id'].')) UNION ALL '.
    109109      '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ",") FROM `FinanceInvoiceItem` WHERE `FinanceInvoice`=`FinanceInvoice`.`Id`) AS `Text`, '.
    110       '`Time`, -(`Value`*`ValueSign`) AS `Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')) ORDER BY `Time` DESC) AS `T1`';
     110      '`Time`, -`Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')) ORDER BY `Time` DESC) AS `T1`';
    111111    $DbResult = $this->Database->query('SELECT SUM(`T1`.`Value`) AS `Total` FROM '.$UserOperationTableQuery);
    112112    $DbRow = $DbResult->fetch_array();
  • trunk/Modules/FinanceBankAPI/FileImport.php

    r740 r747  
    4040          }
    4141          $Year = date('Y', MysqlDateToTime($DbRow['Time']));
    42           $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($FinanceGroup['DocumentLine'], $Year);
     42          $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
    4343          $DbResult3 = $this->Database->insert('FinanceOperation', array('Subject' => $DbRow2['Id'], 'Cash' => 0,
    44             'Value' => Abs($DbRow['Value']), 'ValueSign' => $FinanceGroup['ValueSign'], 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
     44            'Value' => Abs($DbRow['Value']), 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
    4545            'Time' => $DbRow['Time'], 'Text' => $DbRow['Description'], 'BillCode' => $BillCode, 'Group' => $FinanceGroup['Id']));
    4646          $this->Database->update('FinanceBankImport', 'Id='.$DbRow['Id'], array('FinanceOperation' => $this->Database->insert_id));
     
    136136  }
    137137
    138   function InsertMoney($Subject, $Value, $ValueSign, $Cash, $Taxable, $Time, $Text, $Group)
     138  function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $Group)
    139139  {
    140140    $Year = date('Y', $Time);
    141     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($Group['DocumentLine'], $Year);
     141    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumberId(
     142      $Group['DocumentLine'], $Year);
    142143    $this->Database->insert('FinanceOperation', array('Text' => $Text,
    143       'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'ValueSign' => $ValueSign,
     144      'Subject' => $Subject, 'Cash' => $Cash, 'ValueUser' => $Value, 'Value' => $Value * $Group['ValueSign'],
    144145      'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
    145146  }
     
    153154    {
    154155      if($_POST['Money'.$I] >= 0) {
    155         $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup');
     156        $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN,
     157          'FinanceOperationGroup');
    156158      } else {
    157         $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup');
     159        $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT,
     160          'FinanceOperationGroup');
    158161      }
    159162      $Date = explode('-', $_POST['Date'.$I]);
    160163      $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
    161       $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $FinanceGroup['ValueSign'],
     164      $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]),
    162165        0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $FinanceGroup);
    163166      $Output .= $I.', ';
  • trunk/Modules/IS/IS.php

    r740 r747  
    101101    $Output .= 'Registrovaných zařízení: '.$DbRow['0'].'<br/>';
    102102
    103     $DbResult = $this->Database->select('FinanceOperation', 'SUM(`Value` * `ValueSign`)', '1');
     103    $DbResult = $this->Database->select('FinanceOperation', 'SUM(`Value`)', '1');
    104104    $DbRow = $DbResult->fetch_row();
    105105    $Output .= 'Stav placení: '.$DbRow['0'].'<br/>';
     
    187187        try {
    188188          $Form->Validate();
     189          if(array_key_exists('BeforeModify', $Form->Definition))
     190          {
     191            $Class = $Form->Definition['BeforeModify'][0];
     192            $Method = $Form->Definition['BeforeModify'][1];
     193            $Form->Values = $Class->$Method($Form, $Id);
     194          }
    189195          $this->LogChange($Form, 'Edit', $Id, $Id);
    190196          $Form->SaveValuesToDatabase($Id);
    191197          $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
    192198          $Output .= $this->ShowView($Table, $Id);
     199          if(array_key_exists('AfterModify', $Form->Definition))
     200          {
     201            $Class = $Form->Definition['AfterModify'][0];
     202            $Method = $Form->Definition['AfterModify'][1];
     203            $Form->Values = $Class->$Method($Form, $Id);
     204          }
    193205        } catch (Exception $E)
    194206        {
     
    237249      try {
    238250        $Form = new Form($this->System->FormManager);
     251        $Form->SetClass($Table);
     252        $Form->LoadValuesFromDatabase($Id);
    239253        $this->ShortTitle .= ' - '.$Form->Definition['Title'].' odstranění';
    240         $Form->SetClass($Table);
    241254        $this->LogChange($Form, 'Delete', 0, $Id);
    242255        $this->Database->delete($Table, '`Id`='.$Id);
    243256        $Output .= $this->SystemMessage('Smazání položky', 'Položka odstraněna');
     257        if(array_key_exists('AfterDelete', $Form->Definition))
     258        {
     259          $Class = $Form->Definition['AfterDelete'][0];
     260          $Method = $Form->Definition['AfterDelete'][1];
     261          $Class->$Method($Form, $Id);
     262        }
    244263      } catch (Exception $E)
    245264      {
    246         $Output .= $this->SystemMessage('Smazání položky', 'Položku se nepodařilo smazat. Pravděpodobně na ni závisejí další položky.');
     265        $Output .= $this->SystemMessage('Smazání položky', 'Položku se nepodařilo smazat. Pravděpodobně na ni závisejí další položky.<br/>'.$E->getMessage());
    247266      }
    248267    } else $Output .= $this->SystemMessage('Smazání položky', 'Položka nenalezena');
     
    270289            $Class = $Form->Definition['BeforeInsert'][0];
    271290            $Method = $Form->Definition['BeforeInsert'][1];
    272             $this->Values = $Class->$Method($Form);
     291            $Form->Values = $Class->$Method($Form);
    273292          }
    274293          $Form->Validate();
     
    282301            $Class = $Form->Definition['AfterInsert'][0];
    283302            $Method = $Form->Definition['AfterInsert'][1];
    284             $this->Values = $Class->$Method($Form);
     303            $Form->Values = $Class->$Method($Form, $Id);
    285304          }
    286305          // Add action to update caller form
  • trunk/Modules/Meteostation/Meteostation.php

    r738 r747  
    11<?php
    2 
    3 include_once(dirname(__FILE__).'/../../Common/Image.php');
    4 include_once(dirname(__FILE__).'/../../Common/Global.php');
    52
    63class PageMeteo extends Page
  • trunk/Modules/NetworkConfigRouterOS/Generators/Common.php

    r738 r747  
    11<?php
    2 
    3 include_once(dirname(__FILE__).'/../../../Common/NetworkAddress.php');
    42
    53function GetMarkByComment($Comment)
  • trunk/Modules/News/NewsPage.php

    r738 r747  
    11<?php
    2 
    3 include_once(dirname(__FILE__).'/../../Common/RSS.php');
    42
    53class PageNews extends Page
  • trunk/Modules/Subject/Subject.php

    r745 r747  
    3636        'Invoices' => array('Type' => 'TFinanceInvoiceListSubject', 'Caption' => 'Faktury', 'Default' => ''),
    3737        'Payment' => array('Type' => 'Float', 'Caption' => 'Placení', 'Default' => '',
    38           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'IFNULL((SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '.
    39           'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`) FROM `FinanceInvoice` '.
     38          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'IFNULL((SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
     39          'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value`) FROM `FinanceInvoice` '.
    4040          'WHERE `FinanceInvoice`.`Subject`=#Id), 0)'),
    4141        'BankAccounts' => array('Type' => 'TFinanceBankAccountListSubject', 'Caption' => 'Bankovní účety', 'Default' => ''),
     
    5757        'Id' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => '', 'ReadOnly' => true),
    5858        'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    59           'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    60           'AND (`FinanceOperation`.`ValueSign` = 1))'),
     59          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     60            'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     61            'WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     62            'AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
    6163        'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    62           'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    63           'AND (`FinanceOperation`.`ValueSign` = -1))'),
     64          'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     65            'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     66            'WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     67            'AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
    6468        'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    65           'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     69          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    6670          ')'),
    6771      ),
Note: See TracChangeset for help on using the changeset viewer.