Changeset 740


Ignore:
Timestamp:
Jul 3, 2015, 11:36:07 PM (9 years ago)
Author:
chronos
Message:

to group id instead of DocumentLine.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/FormClasses.php

    r738 r740  
    6868        'ReadOnly' => true),
    6969      'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    70         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    71         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Direction` = 1))'),
     70        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     71        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`ValueSign` = 1))'),
    7272      'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    73         'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    74         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Direction` = -1))'),
     73        'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     74        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`ValueSign` = -1))'),
    7575      'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    76         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     76        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    7777        'AND (`FinanceOperation`.`Time` >= `DateStart`))'),
    7878      'TaxIncome' => array('Type' => 'Integer', 'Caption' => 'Daňové příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    79         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    80         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`Direction` = 1))'),
     79        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     80        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`ValueSign` = 1))'),
    8181      'TaxSpending' => array('Type' => 'Integer', 'Caption' => 'Daňové výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    82         'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    83         'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`Direction` = -1))'),
     82        'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     83        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperation`.`ValueSign` = -1))'),
    8484      'TaxBase' => array('Type' => 'Integer', 'Caption' => 'Základ daně', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    85         'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     85        'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
    8686        'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1))'),
    8787      'Claims' => array('Type' => 'Integer', 'Caption' => 'Pohledávky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    88         'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
    89         'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`Direction` = 1))'),
     88        'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     89        'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`ValueSign` = 1))'),
    9090      'Liabilities' => array('Type' => 'Integer', 'Caption' => 'Závazky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    91         'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
    92         'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`Direction` = -1))'),
     91        'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     92        'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`ValueSign` = -1))'),
    9393      'InvoiceBalance' => array('Type' => 'Integer', 'Caption' => 'Fakturační rozdíl', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    94         'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     94        'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`ValueSign`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
    9595        'AND (`FinanceInvoice`.`Time` >= `DateStart`))'),
    9696    ),
  • trunk/Common/Setup/Updates.php

    r739 r740  
    13541354  `Address` varchar(255) NOT NULL,
    13551355  `Domain` int(11) NOT NULL,
    1356   `Sequence` int(11) NOT NULL
     1356  `Sequence` int(11) NOT NULL,
    13571357) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;');
    13581358
     
    13621362  $Manager->Execute('ALTER TABLE `NetworkDomainServer`
    13631363ADD CONSTRAINT `NetworkDomainServer_ibfk_1` FOREIGN KEY (`Domain`) REFERENCES `NetworkDomain` (`Id`);');
    1364 
     1364}
     1365
     1366function UpdateTo740($Manager)
     1367{
     1368  $Manager->Execute('CREATE TABLE IF NOT EXISTS `FinanceInvoiceGroup` (
     1369  `Id` int(11) NOT NULL AUTO_INCREMENT,
     1370  `Name` varchar(255) NOT NULL,
     1371  `DocumentLine` int(11) NOT NULL,
     1372  `ValueSign` int(11) NOT NULL,
     1373  PRIMARY KEY (`Id`),
     1374  KEY `DocumentLine` (`DocumentLine`)
     1375) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;');
     1376  $Manager->Execute('ALTER TABLE `FinanceInvoiceGroup`
     1377ADD CONSTRAINT `FinanceInvoiceGroup_ibfk_1` FOREIGN KEY (`DocumentLine`) REFERENCES `DocumentLine` (`Id`);');
     1378  $Manager->Execute('INSERT INTO `FinanceInvoiceGroup` (`Id`, `Name`, `DocumentLine`, `ValueSign`) VALUES
     1379(1, "Přijaté faktury", 5, -1),
     1380(2, "Vydané faktury", 6, 1);');
     1381
     1382  // Transform FinanceInvoice.DocumentLine reference to FinanceInvoiceGroup
     1383  $Manager->Execute('ALTER TABLE `FinanceInvoice` ADD `Group` INT NULL AFTER `Id`;');
     1384  $Manager->Execute('ALTER TABLE `FinanceInvoice` ADD INDEX(`Group`);');
     1385  $Manager->Execute('ALTER TABLE `FinanceInvoice` ADD FOREIGN KEY (`Group`) REFERENCES `FinanceInvoiceGroup`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1386  $Manager->Execute('UPDATE `FinanceInvoice` SET `Group`=1 WHERE `DocumentLine`=5');
     1387  $Manager->Execute('UPDATE `FinanceInvoice` SET `Group`=2 WHERE `DocumentLine`=6');
     1388  $Manager->Execute('ALTER TABLE `FinanceInvoice` DROP FOREIGN KEY `FinanceInvoice_ibfk_3`;');
     1389  $Manager->Execute('ALTER TABLE `FinanceInvoice` DROP `DocumentLine`;');
     1390
     1391  $Manager->Execute('CREATE TABLE IF NOT EXISTS `FinanceOperationGroup` (
     1392  `Id` int(11) NOT NULL AUTO_INCREMENT,
     1393  `Name` varchar(255) NOT NULL,
     1394  `DocumentLine` int(11) NOT NULL,
     1395  `ValueSign` int(11) NOT NULL,
     1396  PRIMARY KEY (`Id`),
     1397  KEY `DocumentLine` (`DocumentLine`)
     1398) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;');
     1399  $Manager->Execute('ALTER TABLE `FinanceOperationGroup`
     1400ADD CONSTRAINT `FinanceOperationGroup_ibfk_1` FOREIGN KEY (`DocumentLine`) REFERENCES `DocumentLine` (`Id`);');
     1401  $Manager->Execute('INSERT INTO `FinanceOperationGroup` (`Id`, `Name`, `DocumentLine`, `ValueSign`) VALUES
     1402(1, "Příjem do pokladny", 1, 1),
     1403(2, "Výdej z pokladny", 2, -1),
     1404(3, "Příjem na účet", 3, 1),
     1405(4, "Výdej z účtu", 4, -1),
     1406(5, "Nezařazené (ručně vyčistit)", 1, 1);');
     1407
     1408  // Transform FinanceOperation.DocumentLine reference to FinanceOperationGroup
     1409  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD `Group` INT NULL AFTER `Id`;');
     1410  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD INDEX (`Group`);');
     1411  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD FOREIGN KEY (`Group`) REFERENCES `FinanceOperationGroup`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1412  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=1 WHERE `DocumentLine`=1');
     1413  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=2 WHERE `DocumentLine`=2');
     1414  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=3 WHERE `DocumentLine`=3');
     1415  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=4 WHERE `DocumentLine`=4');
     1416  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=5 WHERE `DocumentLine`=10');
     1417  $Manager->Execute('UPDATE `FinanceOperation` SET `Group`=5 WHERE `DocumentLine`=5');
     1418  $Manager->Execute('ALTER TABLE `FinanceOperation` DROP FOREIGN KEY `FinanceOperation_ibfk_6`;');
     1419  $Manager->Execute('ALTER TABLE `FinanceOperation` DROP `DocumentLine`;');
     1420
     1421  $Manager->Execute('ALTER TABLE `FinanceInvoice` CHANGE `Direction` `ValueSign` INT(11) NOT NULL;');
     1422  $Manager->Execute('ALTER TABLE `FinanceOperation` CHANGE `Direction` `ValueSign` INT(11) NOT NULL;');
    13651423}
    13661424
  • trunk/Modules/Finance/Bill.php

    r738 r740  
    7979
    8080    // If negative value => switch sides
    81     if($Invoice['Direction'] == -1)
     81    if($Invoice['ValueSign'] == -1)
    8282    {
    8383      $Subject = $SubjectTo;
     
    162162
    163163    $BooleanText = array('Ne', 'Ano');
    164     if($Operation['Direction'] == -1)
     164    if($Operation['ValueSign'] == -1)
    165165    $Desc = array(
    166166      'Type' => 'VÝDAJOVÝ',
     
    168168      'Target' => 'Vydáno komu',
    169169    );
    170     else if($Operation['Direction'] == 1)
     170    else if($Operation['ValueSign'] == 1)
    171171    $Desc = array(
    172172      'Type' => 'PŘÍJMOVÝ',
  • trunk/Modules/Finance/Finance.php

    r738 r740  
    1010define('TARIFF_FREE', 7);
    1111define('INVOICE_DUE_DAYS', 15);
    12 define('DOC_LINE_TREASURY_IN', 1);
    13 define('DOC_LINE_TREASURY_OUT', 2);
    14 define('DOC_LINE_ACCOUNT_IN', 3);
    15 define('DOC_LINE_ACCOUNT_OUT', 4);
    16 define('DOC_LINE_INVOICE_IN', 5);
    17 define('DOC_LINE_INVOICE_OUT', 6);
     12define('OPERATION_GROUP_TREASURY_IN', 1);
     13define('OPERATION_GROUP_TREASURY_OUT', 2);
     14define('OPERATION_GROUP_ACCOUNT_IN', 3);
     15define('OPERATION_GROUP_ACCOUNT_OUT', 4);
     16define('INVOICE_GROUP_IN', 1);
     17define('INVOICE_GROUP_OUT', 2);
    1818define('VAT_TYPE_BASE', 2);
    1919
     
    108108  }
    109109
     110  function GetFinanceGroupById($Id, $Table)
     111  {
     112    $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `Id`= '.$Id);
     113    if($DbResult->num_rows == 1) {
     114      $Group = $DbResult->fetch_assoc();
     115      return($Group);
     116    } else die('Finance group not found');
     117  }
     118
    110119  function RecalculateMemberPayment()
    111120  {
     
    115124    while($Member = $DbResult->fetch_assoc())
    116125    {
    117       $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(Value*Direction), 0) FROM FinanceOperation '.
    118           'WHERE Subject='.$Member['Subject'].') - (SELECT COALESCE(SUM(Value*Direction), 0) FROM FinanceInvoice '.
    119           'WHERE Subject='.$Member['Subject'].')) AS Cash');
     126      $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(`Value` * `ValueSign`), 0) FROM `FinanceOperation` '.
     127          'WHERE `Subject`='.$Member['Subject'].') - (SELECT COALESCE(SUM(`Value` * `ValueSign`), 0) FROM `FinanceInvoice` '.
     128          'WHERE `Subject`='.$Member['Subject'].')) AS `Cash`');
    120129      $Cash = $DbResult2->fetch_row();
    121130      $Cash = $Cash[0];
     
    204213      'DefaultSortOrder' => 1,
    205214      'Items' => array(
    206         'Direction' => array('Type' => 'TFinanceOperationDirection', 'Caption' => 'Směr', 'Default' => '1'),
    207         'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
    208         'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
     215        'Group' => array('Type' => 'TFinanceOperationGroup', 'Caption' => 'Skupina', 'Default' => ''),
     216        'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true),
    209217        'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
    210218        'Time' => array('Type' => 'Date', 'Caption' => 'Čas realizace', 'Default' => ''),
    211219        'Cash' => array('Type' => 'Boolean', 'Caption' => 'Hotově', 'Default' => ''),
    212220        'Taxable' => array('Type' => 'Boolean', 'Caption' => 'Zdanitelné', 'Default' => ''),
     221        'ValueSign' => array('Type' => 'TFinanceOperationValueSign', 'Caption' => 'Znaménko', 'Default' => '1'),
    213222        'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
    214223        'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
     
    225234    $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']);
    226235    $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy';
    227     $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Default'] = 1;
    228     $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Hidden'] = true;
    229     $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Filter'] = true;
    230     $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Default'] = DOC_LINE_TREASURY_IN;
    231     $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Hidden'] = true;
    232     $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Filter'] = true;
     236    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_IN;
     237    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Hidden'] = true;
     238    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Filter'] = true;
     239    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1;
     240    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
     241    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    233242    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['BankAccount']['Hidden'] = true;
    234243
    235244    $this->System->FormManager->RegisterClass('FinanceTreasuryOut', $this->System->FormManager->Classes['FinanceOperation']);
    236245    $this->System->FormManager->Classes['FinanceTreasuryOut']['Title'] = 'Pokladní výdeje';
    237     $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Default'] = -1;
    238     $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Hidden'] = true;
    239     $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Filter'] = true;
    240     $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Default'] = DOC_LINE_TREASURY_OUT;
    241     $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Hidden'] = true;
    242     $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Filter'] = true;
     246    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_OUT;
     247    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Hidden'] = true;
     248    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Filter'] = true;
     249    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1;
     250    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
     251    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    243252    $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['BankAccount']['Hidden'] = true;
    244253
    245254    $this->System->FormManager->RegisterClass('FinanceAccountIn', $this->System->FormManager->Classes['FinanceOperation']);
    246255    $this->System->FormManager->Classes['FinanceAccountIn']['Title'] = 'Příjmy na účet';
    247     $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Default'] = 1;
    248     $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Hidden'] = true;
    249     $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Filter'] = true;
    250     $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_IN;
    251     $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Hidden'] = true;
    252     $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Filter'] = true;
     256    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_IN;
     257    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Hidden'] = true;
     258    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Filter'] = true;
     259    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0;
     260    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
     261    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    253262    $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Treasury']['Hidden'] = true;
    254 
    255263
    256264    $this->System->FormManager->RegisterClass('FinanceAccountOut', $this->System->FormManager->Classes['FinanceOperation']);
    257265    $this->System->FormManager->Classes['FinanceAccountOut']['Title'] = 'Výdeje z účtu';
    258     $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Default'] = -1;
    259     $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Hidden'] = true;
    260     $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Filter'] = true;
    261     $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_OUT;
    262     $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Hidden'] = true;
    263     $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Filter'] = true;
     266    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_OUT;
     267    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Hidden'] = true;
     268    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Filter'] = true;
     269    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0;
     270    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
     271    $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
    264272    $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true;
    265273
    266     $this->System->FormManager->RegisterFormType('TFinanceOperationDirection', array(
     274    $this->System->FormManager->RegisterClass('FinanceOperationGroup', array(
     275      'Title' => 'Skupina finančních operací',
     276      'Table' => 'FinanceOperationGroup',
     277      'Items' => array(
     278        'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
     279        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
     280        'ValueSign' => array('Type' => 'TFinanceInvoiceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
     281      ),
     282    ));
     283    $this->System->FormManager->RegisterFormType('TFinanceOperationGroup', array(
     284      'Type' => 'Reference',
     285      'Table' => 'FinanceOperationGroup',
     286      'Id' => 'Id',
     287      'Name' => 'Name',
     288      'Filter' => '1',
     289    ));
     290    $this->System->FormManager->RegisterFormType('TFinanceOperationValueSign', array(
    267291      'Type' => 'Enumeration',
    268       'States' => array(-1 => 'Výdej', 1 => 'Příjem'),
     292      'States' => array(-1 => 'Mínus', 1 => 'Plus'),
    269293    ));
    270294    $this->System->FormManager->RegisterClass('FinanceInvoice', array(
     
    274298      'DefaultSortOrder' => 1,
    275299      'Items' => array(
    276         'Direction' => array('Type' => 'TFinanceInvoiceDirection', 'Caption' => 'Směr', 'Default' => '1'),
    277         'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
    278         'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
     300        'Group' => array('Type' => 'TFinanceInvoiceGroup', 'Caption' => 'Skupina', 'Default' => ''),
     301        'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true),
    279302        'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
    280303        'Time' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
    281304        'TimeDue' => array('Type' => 'Date', 'Caption' => 'Čas splatnosti', 'Default' => ''),
    282305        'TimePayment' => array('Type' => 'Date', 'Caption' => 'Čas zaplacení', 'Default' => '', 'Null' => true),
     306        'ValueSign' => array('Type' => 'TFinanceInvoiceValueSign', 'Caption' => 'Znaménko', 'Default' => '1'),
    283307        'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
    284308        'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
     
    297321    $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']);
    298322    $this->System->FormManager->Classes['FinanceInvoiceIn']['Title'] = 'Přijaté faktury';
    299     $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Default'] = -1;
    300     $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Hidden'] = true;
    301     $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Filter'] = true;
    302     $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_IN;
    303     $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Hidden'] = true;
    304     $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Filter'] = true;
     323    $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Default'] = INVOICE_GROUP_IN;
     324    $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Hidden'] = true;
     325    $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Filter'] = true;
    305326
    306327    $this->System->FormManager->RegisterClass('FinanceInvoiceOut', $this->System->FormManager->Classes['FinanceInvoice']);
    307328    $this->System->FormManager->Classes['FinanceInvoiceOut']['Title'] = 'Vydané faktury';
    308     $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Default'] = 1;
    309     $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Hidden'] = true;
    310     $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Filter'] = true;
    311     $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_OUT;
    312     $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Hidden'] = true;
    313     $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Filter'] = true;
    314 
    315     $this->System->FormManager->RegisterFormType('TFinanceInvoiceDirection', array(
     329    $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Default'] = INVOICE_GROUP_OUT;
     330    $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Hidden'] = true;
     331    $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Filter'] = true;
     332
     333    $this->System->FormManager->RegisterFormType('TFinanceInvoiceValueSign', array(
    316334        'Type' => 'Enumeration',
    317         'States' => array(-1 => 'Příjem', 1 => 'Výdej'),
     335        'States' => array(-1 => 'Mínus', 1 => 'Plus'),
     336    ));
     337
     338    $this->System->FormManager->RegisterClass('FinanceInvoiceGroup', array(
     339      'Title' => 'Skupina faktur',
     340      'Table' => 'FinanceInvoiceGroup',
     341      'Items' => array(
     342        'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
     343        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
     344        'ValueSign' => array('Type' => 'TFinanceInvoiceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
     345      ),
     346    ));
     347    $this->System->FormManager->RegisterFormType('TFinanceInvoiceGroup', array(
     348        'Type' => 'Reference',
     349        'Table' => 'FinanceInvoiceGroup',
     350        'Id' => 'Id',
     351        'Name' => 'Name',
     352        'Filter' => '1',
    318353    ));
    319354
     
    347382        'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
    348383        'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
    349           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
     384          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '.
    350385          'WHERE `FinanceOperation`.`Treasury`=#Id)'),
    351386        'Operations' => array('Type' => 'TFinanceOperationListTreasury', 'Caption' => 'Operace', 'Default' => ''),
     
    378413        'LastImportId' => array('Type' => 'String', 'Caption' => 'Id posledního importu', 'Default' => ''),
    379414        'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
    380           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
     415          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '.
    381416          'WHERE `FinanceOperation`.`BankAccount`=#Id)'),
    382417        'AutoImport' => array('Type' => 'Boolean', 'Caption' => 'Automaticky stahovat z banky', 'Default' => ''),
     
    511546    if(array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
    512547      else $Year = date("Y", $Form->Values['ValidFrom']);
    513     $DocumentLine = $Form->Values['DocumentLine'];
    514     $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
     548    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
     549    $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($FinanceGroup['DocumentLine'], $Year);
    515550    return($Form->Values);
    516551  }
  • trunk/Modules/Finance/Import.php

    r738 r740  
    120120  }
    121121
    122   function InsertMoney($Subject, $Value, $Direction, $Cash, $Taxable, $Time, $Text, $DocumentLine)
     122  function InsertMoney($Subject, $Value, $ValueSign, $Cash, $Taxable, $Time, $Text, $Group)
    123123  {
    124124    $Year = date('Y', $Time);
    125     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
     125    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($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, 'Direction' => $Direction,
     128      'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'ValueSign' => $ValueSign,
    129129      'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode,
    130       'BankAccount' => 1));
     130      'BankAccount' => 1, 'Group' => $Group['Id']));
    131131  }
    132132
     
    139139    for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
    140140    {
    141       // TODO: Use links to database records instead of contants
    142141      if($_POST['Money'.$I] < 0) {
    143         $DocumentLine = 4;
    144         $Direction = -1;
     142        $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup');
    145143      } else {
    146         $DocumentLine = 3;
    147         $Direction = 1;
     144        $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup');
    148145      }
    149146      $Date = explode('-', $_POST['Date'.$I]);
    150147      $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
    151       $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $Direction, 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
     148      $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $FinanceGroup['ValueSign'],
     149        0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $FinanceGroup);
    152150      $Output .= $I.', ';
    153151      $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
  • trunk/Modules/Finance/Manage.php

    r738 r740  
    100100  }
    101101
    102   function InsertInvoice($Subject, $TimeCreation, $TimeDue, $Direction, $Items,
    103   $DocumentLine, $PeriodFrom, $PeriodTo)
     102  function InsertInvoice($Subject, $TimeCreation, $TimeDue, $ValueSign, $Items,
     103  $Group, $PeriodFrom, $PeriodTo)
    104104  {
    105105    global $LastInsertTime;
    106106
    107107    $Year = date('Y', $TimeCreation);
    108     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
     108    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($Group['DocumentLine'], $Year);
    109109    $SumValue = 0;
    110     foreach($Items as $Item)
     110    foreach($Items as $Item) {
    111111      $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']);
     112    }
    112113    $this->Database->insert('FinanceInvoice', array(
    113114      'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation),
    114115      'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue,
    115       'Direction' => $Direction, 'BillCode' => $BillCode,
     116      'ValueSign' => $ValueSign, 'BillCode' => $BillCode,
    116117      'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo),
    117       'Generate' => 1, 'DocumentLine' => $DocumentLine));
     118      'Generate' => 1, 'Group' => $FinanceGroup['Id']));
    118119    $InvoiceId = $this->Database->insert_id;
    119120    foreach($Items as $Item)
     
    166167        // We can't produce negative invoice except storno invoice.
    167168        // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction
    168         // Other subject should invoice only possitive items. Negative items should be somehow removed.
     169        // Other subject should invoice only positive items. Negative items should be somehow removed.
    169170        if($MonthlyTotal >= 0) {
    170           $DocumentLine = DOC_LINE_INVOICE_OUT;
    171           $Direction = 1; // Standard out invoice
     171          $InvoiceGroupId = INVOICE_GROUP_OUT;
    172172        } else {
    173           $DocumentLine = DOC_LINE_INVOICE_IN;
    174           $Direction = -1; // In case of negative total value generate reverse invoice for other subject
    175           foreach($InvoiceItems as $Index => $Item)
    176           $InvoiceItems[$Index]['Price'] = -$Item['Price'];
     173          $InvoiceGroupId = INVOICE_GROUP_IN;
     174        }
     175
     176        // Load invoice group
     177        $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($InvoiceGroupId, 'FinanceInvoice');
     178        foreach($InvoiceItems as $Index => $Item) {
     179          $InvoiceItems[$Index]['Price'] = $Item['Price'] * $FinanceGroup['ValueSign'];
    177180        }
    178181
     
    182185          $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />';
    183186          $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS,
    184             $Direction, $InvoiceItems, $DocumentLine, $Period['From'], $Period['To']);
     187            $FinanceGroup['ValueSign'], $InvoiceItems, $FinanceGroup, $Period['From'], $Period['To']);
    185188
    186189          $Output .= $this->SendPaymentEmail($Member['Id']);
     
    354357        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Popis</th>'.
    355358        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Částka [Kč]</th></tr>'."\n";
    356       $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT `Text`, `Time`, (`Value`*`Direction`) AS `Value`, `File` FROM `FinanceOperation` WHERE (`Subject`='.$Member['Subject'].')) UNION ALL '.
     359      $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT `Text`, `Time`, (`Value`*`ValueSign`) AS `Value`, `File` FROM `FinanceOperation` WHERE (`Subject`='.$Member['Subject'].')) UNION ALL '.
    357360        '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ", ") FROM `FinanceInvoiceItem` '.
    358361        'WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`) AS `Text`, '.
    359         '`Time`, -(`Value`*`Direction`) AS `Value`, `File` FROM `FinanceInvoice` WHERE (`Subject`='.
     362        '`Time`, -(`Value`*`ValueSign`) AS `Value`, `File` FROM `FinanceInvoice` WHERE (`Subject`='.
    360363        $Member['Subject'].')) ORDER BY `Time` DESC) AS `T1` WHERE (`T1`.`Time` > "'.$Member['BillingPeriodLastDate'].'")');
    361364      while($DbRow = $DbResult->fetch_assoc())
  • trunk/Modules/Finance/UserState.php

    r738 r740  
    99  function ShowFinanceOperation($Subject)
    1010  {
    11     $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`Direction`) AS `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
     11    $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`ValueSign`) 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`, '.
    14       '`Time`, -(`Value`*`Direction`) AS `Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')))';
     14      '`Time`, -(`Value`*`ValueSign`) AS `Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')))';
    1515
    1616    $Output = '<div style="text-align:center">Výpis finančních operací</div>';
     
    105105
    106106    // Account state
    107     $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`Direction`) AS `Value`, `File`, `BillCode`, NULL AS `PeriodFrom`, NULL AS `PeriodTo` '.
     107    $UserOperationTableQuery = '((SELECT `Text`, `Time`, (`Value`*`ValueSign`) AS `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`*`Direction`) AS `Value`, `File`, `BillCode`, `PeriodFrom`, `PeriodTo` FROM `FinanceInvoice` WHERE (`Subject`='.$Subject['Id'].')) ORDER BY `Time` DESC) AS `T1`';
     110      '`Time`, -(`Value`*`ValueSign`) AS `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/Finance/Zivnost.php

    r738 r740  
    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 (Direction = 1)');
     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)');
    1414    $Row = $DbResult->fetch_array();
    1515    $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 (Direction = 1)');
     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)');
    1717    //echo('SELECT SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value > 0 AND Taxable = 1'.'<br />');
    1818    $Row = $DbResult->fetch_array();
    1919    $Balance['Income']['End'] = $Row[0] + 0;
    2020
    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)');
     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)');
    2222    $Row = $DbResult->fetch_array();
    2323    $Balance['Spend']['Start'] = $Row[0] + 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)');
     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)');
    2525          //echo('SELECT -SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value < 0 AND Taxable = 1'.'<br />');
    2626    $Row = $DbResult->fetch_array();
    2727    $Balance['Spend']['End'] = $Row[0] + 0;
    2828
    29     $DbResult = $this->Database->query('SELECT SUM(Value*Direction) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = 1)');
     29    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = 1)');
    3030    $Row = $DbResult->fetch_array();
    3131    $Balance['Claims']['Start'] = $Row[0] + 0;
    32     $DbResult = $this->Database->query('SELECT SUM(Value*Direction) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = 1)');
     32    $DbResult = $this->Database->query('SELECT SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = 1)');
    3333    $Row = $DbResult->fetch_array();
    3434    $Balance['Claims']['End'] = $Row[0] + 0;
    3535
    36     $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = -1)');
     36    $DbResult = $this->Database->query('SELECT -SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = -1)');
    3737    $Row = $DbResult->fetch_array();
    3838    $Balance['Liabilities']['Start'] = $Row[0] + 0;
    39     $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = -1)');
     39    $DbResult = $this->Database->query('SELECT -SUM(Value*ValueSign) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (ValueSign = -1)');
    4040    $Row = $DbResult->fetch_array();
    4141    $Balance['Liabilities']['End'] = $Row[0] + 0;
     
    144144        $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>';
    145145        $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
    146           'WHERE (Direction = 1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
     146          'WHERE (ValueSign = 1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    147147        while($Row = $DbResult->fetch_array())
    148148        {
     
    174174        $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>';
    175175        $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
    176           'WHERE (Direction = -1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
     176          'WHERE (ValueSign = -1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    177177        while($Row = $DbResult->fetch_array())
    178178        {
     
    204204        $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '.
    205205          'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '.
    206           'WHERE (Direction = 1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
     206          'WHERE (ValueSign = 1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
    207207          '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    208208        while($Row = $DbResult->fetch_array())
     
    210210          if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = '&nbsp;';
    211211          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].
    212             '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['Direction']).'</td></tr>';
     212            '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['ValueSign']).'</td></tr>';
    213213          $Total += $Row['Value'];
    214214        }
     
    227227        $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '.
    228228          'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '.
    229           'WHERE (Direction = -1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
     229          'WHERE (ValueSign = -1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
    230230          '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
    231231        while($Row = $DbResult->fetch_array())
     
    234234          $Row['Value'] = $Row['Value'] * -1;
    235235          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].
    236             '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['Direction']).'</td></tr>';
     236            '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['ValueSign']).'</td></tr>';
    237237          $Total += $Row['Value'];
    238238        }
     
    245245        $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>';
    246246        $DbResult = $this->Database->query('SELECT Id, Name, 0 AS Cash, '.
    247         '(SELECT SUM(T1.Value*T1.Direction) FROM FinanceInvoice AS T1 WHERE (T1.Subject = Subject.Id) AND (T1.Direction = 1)) as Claims, '.
    248         '(SELECT SUM(T2.Value*T2.Direction) FROM FinanceInvoice AS T2 WHERE (T2.Subject = Subject.Id) AND (T2.Direction = 1) AND (TimePayment IS NULL)) as OpenedClaims, '.
    249         '(SELECT -SUM(T3.Value*T3.Direction) FROM FinanceInvoice AS T3 WHERE (T3.Subject = Subject.Id) AND (T3.Direction = -1)) as Liabilities, '.
    250         '(SELECT -SUM(T4.Value*T4.Direction) FROM FinanceInvoice AS T4 WHERE (T4.Subject = Subject.Id) AND (T4.Direction = -1) AND (TimePayment IS NULL)) AS OpenedLiabilities, '.
    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 '.
     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 '.
    253253        'FROM Subject ORDER BY Name');
    254254        while($Row = $DbResult->fetch_assoc())
     
    280280        {
    281281          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['Text'].
    282             '</td><td>'.($Row['Value']*$Row['Direction']).'</td><td>'.$Row['BillCode'].'</td></tr>';
     282            '</td><td>'.($Row['Value']*$Row['ValueSign']).'</td><td>'.$Row['BillCode'].'</td></tr>';
    283283        }
    284284        $Output .= '</table></td><td style="vertical-align: top;">';
     
    293293        {
    294294          $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.HumanDate($Row['TimePayment']).
    295             '</td><td>'.$Row['Text'].'</td><td>'.ceil($Row['Value'] * $Row['Direction']).'</td><td>'.$Row['BillCode'].'</td></tr>';
     295            '</td><td>'.$Row['Text'].'</td><td>'.ceil($Row['Value'] * $Row['ValueSign']).'</td><td>'.$Row['BillCode'].'</td></tr>';
    296296        }
    297297        $Output .= '</table></td></tr></table>';
     
    303303        while($Row = $DbResult->fetch_array())
    304304        {
    305           $Output .= '<tr><td>'.$Row['Time'].'</td><td>'.$Row['TimePass'].'</td><td>'.$Row['Direction'].'</td><td>'.($Row['Value']).'</td><td>'.$Row['CashFlowId'].'</td></tr>';
     305          $Output .= '<tr><td>'.$Row['Time'].'</td><td>'.$Row['TimePass'].'</td><td>'.$Row['ValueSign'].'</td><td>'.($Row['Value']).'</td><td>'.$Row['CashFlowId'].'</td></tr>';
    306306        }
    307307        $Output .= '</table>';*/
    308308
    309         $DbResult = $this->Database->query('SELECT Id, 0 AS Cash, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) '.
     309        $DbResult = $this->Database->query('SELECT Id, 0 AS Cash, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.ValueSign) '.
    310310          'FROM FinanceInvoice WHERE (FinanceInvoice.Subject = Subject.Id) AND '.
    311           '(FinanceInvoice.Direction = 1)) as Claims, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) '.
     311          '(FinanceInvoice.ValueSign = 1)) as Claims, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.ValueSign) '.
    312312          'FROM FinanceInvoice WHERE (FinanceInvoice.Subject = Subject.Id) AND ('.
    313           'FinanceInvoice.Direction = 1) AND (TimePayment IS NULL)) as OpenedClaims, '.
    314           '(SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) FROM FinanceInvoice '.
    315           'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.Direction = -1)) AS '.
     313          'FinanceInvoice.ValueSign = 1) AND (TimePayment IS NULL)) as OpenedClaims, '.
     314          '(SELECT SUM(FinanceInvoice.Value * FinanceInvoice.ValueSign) FROM FinanceInvoice '.
     315          'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.ValueSign = -1)) AS '.
    316316          'Liabilities, (SELECT SUM(FinanceInvoice.Value) FROM FinanceInvoice '.
    317           'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.Direction = -1) '.
     317          'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.ValueSign = -1) '.
    318318          'AND (TimePayment IS NULL)) AS OpenedLiabilities, '.
    319           '(SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) '.
    320           'FROM FinanceOperation WHERE FinanceOperation.Subject = Subject.Id AND FinanceOperation.Direction = 1) '.
    321           'AS Gains, (SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) FROM FinanceOperation WHERE '.
    322           'FinanceOperation.Subject = Subject.Id AND FinanceOperation.Direction = -1) as Spends '.
     319          '(SELECT SUM(FinanceOperation.Value*FinanceOperation.ValueSign) '.
     320          'FROM FinanceOperation WHERE FinanceOperation.Subject = Subject.Id AND FinanceOperation.ValueSign = 1) '.
     321          'AS Gains, (SELECT SUM(FinanceOperation.Value*FinanceOperation.ValueSign) FROM FinanceOperation WHERE '.
     322          'FinanceOperation.Subject = Subject.Id AND FinanceOperation.ValueSign = -1) as Spends '.
    323323          'FROM Subject WHERE Id='.$_GET['Id']);
    324324        $Row = $DbResult->fetch_array();
  • trunk/Modules/FinanceBankAPI/FileImport.php

    r738 r740  
    3434        {
    3535          $DbRow2 = $DbResult2->fetch_assoc();
    36           // TODO: Replace constants by links to real database numbers
    3736          if($DbRow['Value'] >= 0) {
    38             $DocumentLine = 3; // Receive money
    39             $Direction = 1;
     37            $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup');
    4038          } else {
    41             $DocumentLine = 4; // Send money
    42             $Direction = -1;
     39            $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup');
    4340          }
    4441          $Year = date('Y', MysqlDateToTime($DbRow['Time']));
    45           $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
     42          $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($FinanceGroup['DocumentLine'], $Year);
    4643          $DbResult3 = $this->Database->insert('FinanceOperation', array('Subject' => $DbRow2['Id'], 'Cash' => 0,
    47             'Value' => Abs($DbRow['Value']), 'Direction' => $Direction, 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
    48             'Time' => $DbRow['Time'], 'Text' => $DbRow['Description'], 'BillCode' => $BillCode, 'DocumentLine' => $DocumentLine));
     44            'Value' => Abs($DbRow['Value']), 'ValueSign' => $FinanceGroup['ValueSign'], 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
     45            'Time' => $DbRow['Time'], 'Text' => $DbRow['Description'], 'BillCode' => $BillCode, 'Group' => $FinanceGroup['Id']));
    4946          $this->Database->update('FinanceBankImport', 'Id='.$DbRow['Id'], array('FinanceOperation' => $this->Database->insert_id));
    5047        }
     
    139136  }
    140137
    141   function InsertMoney($Subject, $Value, $Direction, $Cash, $Taxable, $Time, $Text, $DocumentLine)
     138  function InsertMoney($Subject, $Value, $ValueSign, $Cash, $Taxable, $Time, $Text, $Group)
    142139  {
    143140    $Year = date('Y', $Time);
    144     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
     141    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($Group['DocumentLine'], $Year);
    145142    $this->Database->insert('FinanceOperation', array('Text' => $Text,
    146       'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Direction' => $Direction,
     143      'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'ValueSign' => $ValueSign,
    147144      'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
    148145  }
     
    155152    for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
    156153    {
    157       // TODO: Use links to database records instead of contants
    158       if($_POST['Money'.$I] < 0) {
    159         $DocumentLine = 4;
    160         $Direction = -1;
     154      if($_POST['Money'.$I] >= 0) {
     155        $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup');
    161156      } else {
    162         $DocumentLine = 3;
    163         $Direction = 1;
     157        $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup');
    164158      }
    165159      $Date = explode('-', $_POST['Date'.$I]);
    166160      $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
    167       $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $Direction, 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
     161      $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), $FinanceGroup['ValueSign'],
     162        0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $FinanceGroup);
    168163      $Output .= $I.', ';
    169164      $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
  • trunk/Modules/FinanceBankAPI/FinanceBankAPI.php

    r738 r740  
    6969  {
    7070    $Preset = array();
    71     if($Item['Value'] < 0) $DocumentLine = DOC_LINE_ACCOUNT_OUT;
    72        else $DocumentLine = DOC_LINE_ACCOUNT_IN;
     71    if($Item['Value'] < 0) $OperationGroupId = OPERATION_GROUP_ACCOUNT_OUT;
     72       else $OperationGroupId = OPERATION_GROUP_ACCOUNT_IN;
     73    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($OperationGroupId, 'FinanceOperationGroup');
     74
    7375    $Preset = array(
    7476      'presetTime' => $Item['Time'],
     
    7880      'presetNetwork' => 1,
    7981      'presetBankAccount' => $Item['BankAccount'],
    80       'presetDocumentLine' => $DocumentLine);
     82      'presetDocumentLine' => $FinanceGroup['DocumentLine']);
    8183    return($Preset);
    8284  }
  • trunk/Modules/IS/IS.php

    r738 r740  
    101101    $Output .= 'Registrovaných zařízení: '.$DbRow['0'].'<br/>';
    102102
    103     $DbResult = $this->Database->select('FinanceOperation', 'SUM(`Value` * `Direction`)', '1');
     103    $DbResult = $this->Database->select('FinanceOperation', 'SUM(`Value` * `ValueSign`)', '1');
    104104    $DbRow = $DbResult->fetch_row();
    105105    $Output .= 'Stav placení: '.$DbRow['0'].'<br/>';
     
    423423    {
    424424      if($TypeFilter != '') $TypeFilter .= ' AND ';
    425       $TypeFilter .= '('.$ItemIndex.' = "'.$FormItem['Default'].'")';
     425      $TypeFilter .= '(`'.$ItemIndex.'` = "'.$FormItem['Default'].'")';
    426426    }
    427427    if($TypeFilter != '')
  • trunk/Modules/NetworkConfigLinux/Generators/DNS.php

    r738 r740  
    11<?php
     2
     3/* This is script for configuration of BIND DNS server.
     4 * Use "sudo aptitude install bind9" to install server under Ubuntu
     5 */
    26
    37if(isset($_SERVER['REMOTE_ADDR'])) die();
  • trunk/Modules/Subject/Subject.php

    r738 r740  
    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`.`Direction`) FROM `FinanceOperation` '.
    39           'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`) FROM `FinanceInvoice` '.
     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` '.
    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`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    60           'AND (`FinanceOperation`.`Direction` = 1))'),
     59          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     60          'AND (`FinanceOperation`.`ValueSign` = 1))'),
    6161        'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    62           'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    63           'AND (`FinanceOperation`.`Direction` = -1))'),
     62          'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     63          'AND (`FinanceOperation`.`ValueSign` = -1))'),
    6464        'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
    65           'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
     65          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`)) FROM `FinanceOperation` WHERE (`FinanceOperation`.`Subject` = TX.`Id`) '.
    6666          ')'),
    6767      ),
Note: See TracChangeset for help on using the changeset viewer.