Changeset 719


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.
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/FormClasses.php

    r712 r719  
    22
    33// TODO: Split all form class definitions to modules
    4 
    5 /*
    6 Item definition:
    7 Type - identifikace typu z podporovaných
    8 Caption - popisek, titulek položky
    9 Default - výchozí hodnota
    10 Null - hodnota nemusí být zadána
    11 NoInList - sloupec viditelný v seznamu
    12 Suffix - text za hodnotou
    13 Description - popis významu položky
    14 ReadOnly - je položky pouze pro čtení
    15 Required - položka je vyžadována
    16 */
    174
    185function RegisterFormClasses($FormManager)
     
    9178        'ReadOnly' => true),
    9279      'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    93         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    94         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Value` > 0))'),
     80        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     81        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Direction` = 1))'),
    9582      'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    96         'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    97         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Value` < 0))'),
     83        'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     84        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Direction` = -1))'),
    9885      'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    99         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     86        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    10087        'AND (`FinanceOperation`.`Time` >= `DateStart`))'),
    10188      'TaxIncome' => array('Type' => 'Integer', 'Caption' => 'Daňové příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    102         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    103         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`Value` > 0))'),
     89        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     90        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`Direction` = 1))'),
    10491      'TaxSpending' => array('Type' => 'Integer', 'Caption' => 'Daňové výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    105         'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    106         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`Value` < 0))'),
     92        'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     93        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`Direction` = -1))'),
    10794      'TaxBase' => array('Type' => 'Integer', 'Caption' => 'Základ daně', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    108         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     95        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    10996        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1))'),
    11097      'Claims' => array('Type' => 'Integer', 'Caption' => 'Pohledávky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
  • trunk/Application/Version.php

    r718 r719  
    11<?php
    22
    3 $Revision = 718; // Subversion revision
    4 $DatabaseRevision = 718; // SQL structure revision
    5 $ReleaseTime = strtotime('2015-01-01');
     3$Revision = 719; // Subversion revision
     4$DatabaseRevision = 719; // SQL structure revision
     5$ReleaseTime = strtotime('2015-01-02');
  • trunk/Common/Form/Form.php

    r706 r719  
    33include_once(dirname(__FILE__).'/../Database.php');
    44include_once(dirname(__FILE__).'/Types/Type.php');
     5
     6/*
     7Form item type definition:
     8Type - identifikace typu z podporovaných
     9Caption - popisek, titulek položky
     10Default - výchozí hodnota
     11Null - hodnota nemusí být zadána
     12NotInList - sloupec neviditelný v seznamu položek
     13Hidden - neviditelný, při přidání nové položky se použije výchozí hodnota.
     14Filter - column is used as filer according default value
     15Suffix - text za hodnotou
     16Description - popis významu položky
     17ReadOnly - je položky pouze pro čtení
     18Required - položka je vyžadována
     19SQL - SQL dotaz pro zjištění hodnoty, #Id bude nahrazeno Id aktuální položky
     20*/
     21
    522
    623class Form
     
    3249    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    3350    {
    34       if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     51      if(!array_key_exists($Index, $this->Values) and isset($Item['Default']))
     52        $this->Values[$Index] = $Item['Default'];
    3553    }
    3654  }
     
    6785    );
    6886    foreach($this->Definition['Items'] as $Index => $Item)
     87    if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
    6988    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    7089    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     
    115134      if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    116135    if($Item['ReadOnly'] == false)
     136    if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
    117137    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    118138    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     
    255275    $Values = array();
    256276    foreach($this->Definition['Items'] as $Index => $Item)
     277    if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
     278    {
    257279    if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    258280    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     
    279301        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad',
    280302          $Parameters);
     303    }
     304    } else
     305    {
     306      if(isset($Item['Default'])) {
     307        if(isset($Item['Null']) and ($Item['Null'] == true))
     308                $Values[$Index] = null;
     309        else $Values[$Index] = $Item['Default'];
     310      }
    281311    }
    282312    return($Values);
  • trunk/Common/Setup/Updates.php

    r718 r719  
    10301030    $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ".
    10311031      "VALUES (NULL , 'Firmy', ".$DbRow['Id'].", '".$ActionId."', '1');");
     1032  }
     1033}
     1034
     1035/*
     1036function UpdateTo719($Manager)
     1037{       
     1038  $Manager->Execute('ALTER TABLE `FinanceOperation` DROP FOREIGN KEY `FinanceOperation_ibfk_1`;');
     1039  $Manager->Execute('ALTER TABLE `FinanceOperation` CHANGE `Subject` `SubjectFrom` INT(11) NULL DEFAULT "";');
     1040  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD `SubjectTo` INT NULL AFTER `SubjectFrom`, ADD INDEX (`SubjectTo`) ;');
     1041  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD FOREIGN KEY (`SubjectFrom`) REFERENCES `Subject`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1042  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD FOREIGN KEY (`SubjectTo`) REFERENCES `Subject`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1043  // Set target subject to 1 = company subject id
     1044  $Manager->Execute('UPDATE `FinanceOperation` SET `SubjectTo` = 1;');
     1045  $Manager->Execute('UPDATE `FinanceOperation` SET `SubjectTo` = `SubjectFrom` WHERE `Value` < 0');
     1046  $Manager->Execute('UPDATE `FinanceOperation` SET `SubjectFrom` = 1,`Value`= -`Value`  WHERE `Value` < 0');
     1047   
     1048}
     1049*/
     1050
     1051function UpdateTo719($Manager)
     1052{       
     1053  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD `Direction` INT NOT NULL AFTER `Cash`;');
     1054  $Manager->Execute('UPDATE `FinanceOperation` SET `Direction` = 1 WHERE `Value` >= 0 ;');
     1055  $Manager->Execute('UPDATE `FinanceOperation` SET `Direction` = -1 WHERE `Value` < 0 ;');
     1056  $Manager->Execute('UPDATE `FinanceOperation` SET `Value` = -`Value` WHERE `Value` < 0 ;');
     1057
     1058  // IS menu item
     1059  $DbResult = $Manager->Execute('SELECT `Id` FROM `MenuItem` WHERE `Name`="Příjmy a výdaje"');
     1060  if($DbResult->num_rows > 0)
     1061  {
     1062        $DbRow = $DbResult->fetch_assoc();
     1063    $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` ,
     1064    `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES (
     1065    NULL , "", "Příjem do pokladny", "1", "/is/?t=FinanceTreasuryIn&a=list", NULL , NULL , NULL , "1");');
     1066    $ActionId = $Manager->Database->insert_id;
     1067        $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ".
     1068      "VALUES (NULL , 'Příjem do pokladny', ".$DbRow['Id'].", '".$ActionId."', '1');");
     1069    $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` ,
     1070    `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES (
     1071    NULL , "", "Výdej z pokladny", "1", "/is/?t=FinanceTreasuryOut&a=list", NULL , NULL , NULL , "1");');
     1072    $ActionId = $Manager->Database->insert_id;
     1073        $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ".
     1074      "VALUES (NULL , 'Výdej z pokladny', ".$DbRow['Id'].", '".$ActionId."', '1');");
     1075    $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` ,
     1076    `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES (
     1077    NULL , "", "Příjem na účet", "1", "/is/?t=FinanceAccountIn&a=list", NULL , NULL , NULL , "1");');
     1078    $ActionId = $Manager->Database->insert_id;
     1079        $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ".
     1080      "VALUES (NULL , 'Příjem na účet', ".$DbRow['Id'].", '".$ActionId."', '1');");
     1081    $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` ,
     1082    `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES (
     1083    NULL , "", "Výdej z účtu", "1", "/is/?t=FinanceAccountOut&a=list", NULL , NULL , NULL , "1");');
     1084    $ActionId = $Manager->Database->insert_id;
     1085        $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ".
     1086      "VALUES (NULL , 'Výdej z účtu', ".$DbRow['Id'].", '".$ActionId."', '1');");
    10321087  }
    10331088}
     
    10861141      696 => array('Revision' => 697, 'Function' => 'UpdateTo697'),
    10871142      697 => array('Revision' => 707, 'Function' => 'UpdateTo707'),
    1088       710 => array('Revision' => 715, 'Function' => 'UpdateTo715'),
     1143      707 => array('Revision' => 710, 'Function' => 'UpdateTo710'),
     1144        710 => array('Revision' => 715, 'Function' => 'UpdateTo715'),
    10891145      715 => array('Revision' => 718, 'Function' => 'UpdateTo718'),
     1146      718 => array('Revision' => 719, 'Function' => 'UpdateTo719'),
    10901147    ));
    10911148  }
  • trunk/Modules/Customer/Customer.php

    r715 r719  
    3030        'BillingPeriodLastDate' => array('Type' => 'Date', 'Caption' => 'Datum poslední fakturace', 'Default' => ''),
    3131        'Blocked' => array('Type' => 'Boolean', 'Caption' => 'Blokování', 'Default' => '0'),
    32         'PayDay' => array('Type' => 'Integer', 'Caption' => 'Den placení', 'Default' => '0', 'Suffix' => 'den'),
     32        'PayDay' => array('Type' => 'Integer', 'Caption' => 'Den placení', 'Default' => '1', 'Suffix' => 'den'),
    3333        'Devices' => array('Type' => 'TDeviceList', 'Caption' => 'Registrovaná zařízení', 'Default' => ''),
    3434        'UserRel' => array('Type' => 'TUserCustomerRelListCustomer', 'Caption' => 'Přiřazení uživatelé', 'Default' => ''),
  • trunk/Modules/Finance/Bill.php

    r680 r719  
    166166    //}
    167167    $BooleanText = array('Ne', 'Ano');
    168     if($Operation['Value'] < 0)
     168    if($Operation['Direction'] == -1)
    169169    $Desc = array(
    170170      'Type' => 'VÝDAJOVÝ',
    171171      'Signature' => 'Vydal',
    172       'Sign' => -1,
    173172      'Target' => 'Vydáno komu',
    174173    );
    175     else $Desc = array(
     174    else if($Operation['Direction'] == 1)
     175    $Desc = array(
    176176      'Type' => 'PŘÍJMOVÝ',
    177177      'Signature' => 'Přijal',
    178       'Sign' => 1,
    179178      'Target' => 'Přijato od',
    180179    );
     180    else throw new Exception('Wrong finance direction');
    181181
    182182    $Output = '<table width="100%" border="1" cellspacing="0" cellpadding="3"><tr><td width="50%">'.
     
    201201    if($Subject['DIC'] != '') $Output .= 'DIČ: '.$Subject['DIC'].'<br>';
    202202    $Description = $Operation['Text'];
    203     $Total = $Operation['Value'] * $Desc['Sign'];
    204203    $Output .= '</td></tr>'.
    205       '<tr><td colspan="2"><strong>Částka:</strong> '.$Total.' Kč<br><br>'.
     204      '<tr><td colspan="2"><strong>Částka:</strong> '.$Operation['Value'].' Kč<br><br>'.
    206205      '</td></tr>'.
    207206      '<tr><td colspan="2"><strong>Účel platby:</strong><br>'.$Description.'</td></tr>'.
  • trunk/Modules/Finance/Finance.php

    r718 r719  
    99define('TARIFF_FREE', 7);
    1010define('INVOICE_DUE_DAYS', 15);
    11 define('DOC_LINE_INVOICE_OUT', 6);
     11define('DOC_LINE_TREASURY_IN', 1);
     12define('DOC_LINE_TREASURY_OUT', 2);
    1213define('DOC_LINE_ACCOUNT_IN', 3);
    1314define('DOC_LINE_ACCOUNT_OUT', 4);
     15define('DOC_LINE_INVOICE_IN', 5);
     16define('DOC_LINE_INVOICE_OUT', 6);
    1417define('VAT_TYPE_BASE', 2);
    1518
     
    2326  var $InternetUsers;
    2427  var $SpravaUsers;
    25   var $InternetSegmentId = 21;
    2628  var $MaxSpeed;
    2729  var $RealMaxSpeed;
    2830  var $SpeedReserve;
    2931  var $BaseSpeedElement;
    30   var $UserIdNetwork = 46;
    3132  var $BaseTariffPrice;
    3233  var $TopTariffPrice;
     
    3435  var $TotalInternetPaid;
    3536  var $Tariffs;
    36   var $ExternalSubject = 96;
    3737  var $MainSubject;
    3838  var $BillingPeriods;
     
    186186    while($Member = $DbResult->fetch_assoc())
    187187    {
    188       $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(Value), 0) FROM FinanceOperation '.
     188      $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(-Value*Direction), 0) FROM FinanceOperation '.
    189189          'WHERE Subject='.$Member['Subject'].') + (SELECT COALESCE(SUM(-Value), 0) FROM FinanceInvoice '.
    190190          'WHERE Subject='.$Member['Subject'].')) as Cash');
     
    277277      'DefaultSortOrder' => 1,
    278278      'Items' => array(
    279         'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
     279        'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '1'),
     280        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
    280281        'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
    281282        'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
     
    293294      ),
    294295      'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
     296    ));
     297   
     298    $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']);
     299    $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy';
     300    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Default'] = 1;
     301    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Hidden'] = true;
     302    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Filter'] = true;
     303    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Default'] = DOC_LINE_TREASURY_IN;
     304    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Hidden'] = true;
     305    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Filter'] = true;
     306    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['BankAccount']['Hidden'] = true;
     307       
     308    $this->System->FormManager->RegisterClass('FinanceTreasuryOut', $this->System->FormManager->Classes['FinanceOperation']);
     309    $this->System->FormManager->Classes['FinanceTreasuryOut']['Title'] = 'Pokladní výdeje';
     310    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Default'] = -1;
     311    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Hidden'] = true;
     312    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Filter'] = true;
     313    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Default'] = DOC_LINE_TREASURY_OUT;
     314    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Hidden'] = true;
     315    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Filter'] = true;
     316    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['BankAccount']['Hidden'] = true;
     317   
     318    $this->System->FormManager->RegisterClass('FinanceAccountIn', $this->System->FormManager->Classes['FinanceOperation']);
     319    $this->System->FormManager->Classes['FinanceAccountIn']['Title'] = 'Příjmy na účet';
     320    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Default'] = 1;
     321    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Hidden'] = true;
     322    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Filter'] = true;
     323    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_IN;
     324    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Hidden'] = true;
     325    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Filter'] = true;
     326    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Treasury']['Hidden'] = true;
     327   
     328   
     329    $this->System->FormManager->RegisterClass('FinanceAccountOut', $this->System->FormManager->Classes['FinanceOperation']);
     330    $this->System->FormManager->Classes['FinanceAccountOut']['Title'] = 'Výdeje z účtu';
     331    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Default'] = -1;
     332    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Hidden'] = true;
     333    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Filter'] = true;
     334    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_OUT;
     335    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Hidden'] = true;
     336    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Filter'] = true;
     337    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true;
     338   
     339    $this->System->FormManager->RegisterFormType('TFinanceDirection', array(
     340      'Type' => 'Enumeration',
     341      'States' => array(-1 => 'Výdej', 1 => 'Příjem'),
    295342    ));
    296343    $this->System->FormManager->RegisterClass('FinanceInvoice', array(
     
    349396        'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
    350397        'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
    351           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
     398          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
    352399          'WHERE `FinanceOperation`.`Treasury`=#Id)'),
    353400        'Operations' => array('Type' => 'TFinanceOperationListTreasury', 'Caption' => 'Operace', 'Default' => ''),
     
    379426        'LastImportId' => array('Type' => 'String', 'Caption' => 'Id posledního importu', 'Default' => ''),
    380427        'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
    381           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
     428          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
    382429          'WHERE `FinanceOperation`.`BankAccount`=#Id)'),
    383430      ),
  • trunk/Modules/Finance/Import.php

    r629 r719  
    120120  }
    121121 
    122   function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine)
     122  function InsertMoney($Subject, $Value, $Direction, $Cash, $Taxable, $Time, $Text, $DocumentLine)
    123123  {
    124124    $Year = date('Y', $Time);
    125125    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
    126     // TODO: Fixed BankAccount=1
     126    // 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,
     128      'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Direction' => $Direction,
    129129      'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode,
    130130      'BankAccount' => 1));
     
    139139    for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
    140140    {
    141       if($_POST['Money'.$I] < 0) $DocumentLine = 4;
    142         else $DocumentLine = 3;
     141        // TODO: Use links to database records instead of contants
     142      if($_POST['Money'.$I] < 0) {
     143        $DocumentLine = 4;
     144        $Direction = -1;
     145      } else {
     146        $DocumentLine = 3;
     147        $Direction = 1;
     148      }
    143149      $Date = explode('-', $_POST['Date'.$I]);
    144150      $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
    145       $this->InsertMoney($_POST['Subject'.$I], $_POST['Money'.$I], 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
     151      $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $Direction, 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
    146152      $Output .= $I.', ';
    147153      $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
  • trunk/Modules/Finance/Manage.php

    r715 r719  
    342342        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Popis</th>'.
    343343        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Částka [Kč]</th></tr>'."\n";
    344       $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, Value AS Value, File FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '.
     344      $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, (Value*Direction) AS Value, File FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '.
    345345        '(SELECT CONCAT(`Text`, (SELECT GROUP_CONCAT(`Description` SEPARATOR "<br/>") FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`)) AS `Text`, Time, -Value as Value, File FROM FinanceInvoice WHERE (Subject='.
    346346        $Member['Subject'].')) ORDER BY Time DESC) AS T1 WHERE (T1.Time > "'.$Member['BillingPeriodLastDate'].'")');
  • trunk/Modules/Finance/UserState.php

    r700 r719  
    99  function ShowFinanceOperation($Subject)
    1010  {
    11         $UserOperationTableQuery = '((SELECT Text, Time, Value AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
     11        $UserOperationTableQuery = '((SELECT Text, Time, (Value*Direction) AS 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, '.
     
    101101
    102102    // Account state
    103     $UserOperationTableQuery = '((SELECT Text, Time, Value AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
     103    $UserOperationTableQuery = '((SELECT Text, Time, (Value*Direction) AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
    104104      'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '.
    105105      '(SELECT (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoice=FinanceInvoice.Id) AS Text, '.
  • 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();
  • trunk/Modules/FinanceBankAPI/FileImport.php

    r637 r719  
    3434        {
    3535          $DbRow2 = $DbResult2->fetch_assoc();
    36           if($DbRow['Value'] >= 0) $DocumentLine = 3; // Receive money
    37             else $DocumentLine = 4; // Send money
     36          // TODO: Replace constants by links to real database numbers
     37          if($DbRow['Value'] >= 0) {
     38                $DocumentLine = 3; // Receive money
     39                $Direction = 1;                 
     40          } else {
     41                $DocumentLine = 4; // Send money
     42                $Direction = -1;
     43          }
    3844          $Year = date('Y', MysqlDateToTime($DbRow['Time']));
    3945          $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
    4046          $DbResult3 = $this->Database->insert('FinanceOperation', array('Subject' => $DbRow2['Id'], 'Cash' => 0,
    41             'Value' => $DbRow['Value'], 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
     47            'Value' => Abs($DbRow['Value']), 'Direction' => $Direction, 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
    4248            'Time' => $DbRow['Time'], 'Text' => $DbRow['Description'], 'BillCode' => $BillCode, 'DocumentLine' => $DocumentLine));
    4349          $this->Database->update('FinanceBankImport', 'Id='.$DbRow['Id'], array('FinanceOperation' => $this->Database->insert_id));
     
    133139  }
    134140 
    135   function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine)
     141  function InsertMoney($Subject, $Value, $Direction, $Cash, $Taxable, $Time, $Text, $DocumentLine)
    136142  {
    137143    $Year = date('Y', $Time);     
    138144    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
    139     $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
     145    $this->Database->insert('FinanceOperation', array('Text' => $Text,
     146        'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Direction' => $Direction,
     147        'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
    140148  }
    141149
     
    147155    for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
    148156    {
    149       if($_POST['Money'.$I] < 0) $DocumentLine = 4;
    150         else $DocumentLine = 3;
    151       $Date = explode('-', $_POST['Date'.$I]);
     157      // TODO: Use links to database records instead of contants
     158      if($_POST['Money'.$I] < 0) {
     159        $DocumentLine = 4;
     160        $Direction = -1;
     161      } else {
     162        $DocumentLine = 3;
     163        $Direction = 1;
     164      }
     165        $Date = explode('-', $_POST['Date'.$I]);
    152166      $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
    153       $this->InsertMoney($_POST['Subject'.$I], $_POST['Money'.$I], 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
     167      $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $Direction, 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
    154168      $Output .= $I.', ';
    155169      $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
  • trunk/Modules/IS/IS.php

    r711 r719  
    2626    $this->System->FormManager->ShowRelation = true;
    2727
     28    // a - action
    2829    if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
    2930      else $Action = '';
     31    // t - table
    3032    if(array_key_exists('t', $_GET)) $Table = $_GET['t'];
    3133      else $Table = '';
     34    // i - index of item
    3235    if(array_key_exists('i', $_GET)) $ItemId = $_GET['i'];
    3336      else $ItemId = 0;
     37    // fc - preset colum
     38    if(array_key_exists('fn', $_GET)) $FilterName = $_GET['fn'];
     39      else $FilterName = '';
     40    if(array_key_exists('fv', $_GET)) $FilterValue = $_GET['fv'];
     41      else $FilterValue = '';
    3442    if(array_key_exists('menutype', $_COOKIE)) $MenuType = $_COOKIE['menutype'];
    3543      else $MenuType = 0;
     
    3745    setcookie('menutype', $MenuType, time() + 60 * 60 * 24 * 365);
    3846
    39     if($Action == 'list') $Content = $this->ShowList($Table);
     47    if($Action == 'list') {
     48        if($FilterName == '') $Content = $this->ShowList($Table);
     49          else $Content = $this->ShowList($Table, '', '', $FilterName, $FilterValue);
     50    }
    4051    else if($Action == 'select') $Content = $this->ShowSelect($Table);
    4152    else if($Action == 'mapselect') $Content = $this->ShowMapSelect($Table);
     
    7081  {
    7182    $Output = '<strong>Nástěnka:</strong><br/>';
    72     $DbResult = $this->Database->select('Task', 'COUNT(*)', 'Progress < 100');
     83    $DbResult = $this->Database->select('Task', 'COUNT(*)', '`Progress` < 100');
    7384    $DbRow = $DbResult->fetch_row();
    7485    $Output .= 'Nedokončených úkolů: '.$DbRow['0'].'<br/>';
     86   
    7587    $DbResult = $this->Database->select('Member', 'COUNT(*)', '1');
    7688    $DbRow = $DbResult->fetch_row();
    7789    $Output .= 'Zákazníků: '.$DbRow['0'].'<br/>';
     90   
    7891    $DbResult = $this->Database->select('Subject', 'COUNT(*)', '1');
    7992    $DbRow = $DbResult->fetch_row();
    8093    $Output .= 'Subjektů: '.$DbRow['0'].'<br/>';
     94   
    8195    $DbResult = $this->Database->select('User', 'COUNT(*)', '1');
    8296    $DbRow = $DbResult->fetch_row();
    8397    $Output .= 'Uživatelů: '.$DbRow['0'].'<br/>';
     98   
    8499    $DbResult = $this->Database->select('NetworkDevice', 'COUNT(*)', '1');
    85100    $DbRow = $DbResult->fetch_row();
    86101    $Output .= 'Registrovaných zařízení: '.$DbRow['0'].'<br/>';
    87     $DbResult = $this->Database->select('FinanceOperation', 'SUM(Value)', '1');
     102   
     103    $DbResult = $this->Database->select('FinanceOperation', 'SUM(`Value` * `Direction`)', '1');
    88104    $DbRow = $DbResult->fetch_row();
    89105    $Output .= 'Stav placení: '.$DbRow['0'].'<br/>';
    90     $DbResult = $this->Database->select('FinanceBankImport', 'COUNT(*)', 'FinanceOperation IS NULL');
     106   
     107    $DbResult = $this->Database->select('FinanceBankImport', 'COUNT(*)', '`FinanceOperation` IS NULL');
    91108    $DbRow = $DbResult->fetch_row();
    92109    $Output .= 'Nezpárovaných plateb: '.$DbRow['0'].'<br/>';
     
    397414      else $SourceTable = '`'.$FormClass['Table'].'` AS `TX`';
    398415
     416    // Build form type filter
     417    $TypeFilter = '';
     418    foreach($FormClass['Items'] as $ItemIndex => $FormItem)   
     419    if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     420    (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     421    ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     422    if(array_key_exists('Filter', $FormItem) and ($FormItem['Filter'] == true))
     423    {
     424        if($TypeFilter != '') $TypeFilter .= ' AND ';           
     425        $TypeFilter .= '('.$ItemIndex.' = "'.$FormItem['Default'].'")';
     426    }     
     427    if($TypeFilter != '')
     428    {
     429        if($Filter != '') $Filter = ' AND';
     430        $Filter .= ' '.$TypeFilter;
     431    }
     432   
    399433    // Build user filter
    400434    $UserFilter = '';
     
    403437    {
    404438      foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     439      if(!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
    405440      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    406441      (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     
    435470    if($Filter != '') $Filter = ' HAVING '.$Filter;
    436471
    437     foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     472    foreach($FormClass['Items'] as $ItemIndex => $FormItem)     
    438473      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    439474      (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     
    441476      {
    442477        if($ExcludeColumn != $ItemIndex)
     478        if(!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
    443479          $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
    444480        $UseType = $UseType = $FormItem['Type'];
     
    499535    $Output .= '<tr><form action="?a='.$_GET['a'].'&amp;t='.$Table.'&amp;filter=1'.$Addition.'" method="post">';
    500536    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     537    if(!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
    501538    if((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    502539    (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     
    520557      $Output .= '<tr>';
    521558      foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     559      if(!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
    522560      if((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    523561      (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
  • trunk/Modules/Subject/Subject.php

    r711 r719  
    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`) FROM `FinanceOperation` '.
     38          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'IFNULL((SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
    3939          'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value`) FROM `FinanceInvoice` '.
    4040          'WHERE `FinanceInvoice`.`Subject`=#Id), 0)'),
     
    4949        'Id' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => '', 'ReadOnly' => true),
    5050        'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    51           'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    52           'AND (`FinanceOperation`.`Value` > 0))'),
     51          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     52          'AND (`FinanceOperation`.`Direction` = 1))'),
    5353        'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    54           'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    55           'AND (`FinanceOperation`.`Value` < 0))'),
     54          'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     55          'AND (`FinanceOperation`.`Direction` = -1))'),
    5656        'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    57           'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     57          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    5858          ')'),
    5959      ),
Note: See TracChangeset for help on using the changeset viewer.