Ignore:
Timestamp:
Jan 5, 2021, 10:30:31 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Further improved models initialization system.
File:
1 edited

Legend:

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

    r893 r894  
    11<?php
    22
     3include_once(dirname(__FILE__).'/FinanceModels.php');
    34include_once(dirname(__FILE__).'/Bill.php');
    45include_once(dirname(__FILE__).'/Manage.php');
     
    67include_once(dirname(__FILE__).'/Import.php');
    78include_once(dirname(__FILE__).'/Trade.php');
    8 
    9 // TODO: Move constants to Finance module configuration
    10 define('TARIFF_FREE', 7);
    11 define('INVOICE_DUE_DAYS', 15);
    12 define('OPERATION_GROUP_TREASURY_IN', 1);
    13 define('OPERATION_GROUP_TREASURY_OUT', 2);
    14 define('OPERATION_GROUP_ACCOUNT_IN', 3);
    15 define('OPERATION_GROUP_ACCOUNT_OUT', 4);
    16 define('INVOICE_GROUP_IN', 1);
    17 define('INVOICE_GROUP_OUT', 2);
    18 define('VAT_TYPE_BASE', 2);
    19 define('FINANCE_DIRECTION_OUT', 1);
    20 define('FINANCE_DIRECTION_IN', 0);
    21 
    22 class Finance extends Model
    23 {
    24   public string $kWh;
    25   public string $Internet;
    26   public string $Sprava;
    27   public string $DatumOdecteni;
    28   public string $InternetUsers;
    29   public string $SpravaUsers;
    30   public string $MaxSpeed;
    31   public string $RealMaxSpeed;
    32   public string $SpeedReserve;
    33   public string $BaseSpeedElement;
    34   public string $BaseTariffPrice;
    35   public string $TopTariffPrice;
    36   public string $TotalPaid;
    37   public string $TotalInternetPaid;
    38   public string $MainSubject;
    39   public array $BillingPeriods;
    40   public string $DirectoryId;
    41   public string $Rounding;
    42 
    43   function LoadMonthParameters(int $Period = 1) // 0 - now, 1 - next month
    44   {
    45     $DbResult = $this->Database->query('SELECT * FROM `FinanceBillingPeriod`');
    46     while ($BillingPeriod = $DbResult->fetch_assoc())
    47       $this->BillingPeriods[$BillingPeriod['Id']] = $BillingPeriod;
    48 
    49     // Period parameter is not used as it have to be determined from item replacement
    50     $DbResult = $this->Database->query('SELECT * FROM `FinanceCharge` WHERE (`ChangeAction` IS NULL) LIMIT 1');
    51     $Row = $DbResult->fetch_array();
    52     $this->kWh = $Row['kWh'];
    53     $this->Internet = $Row['Internet'];
    54     $this->Sprava = $Row['AdministrationPerUser'];
    55     $this->RealMaxSpeed = $Row['InternetSpeed'];
    56     $this->SpeedReserve = $Row['InternetSpeedReserve'];
    57     $this->BaseSpeedElement = $Row['BaseSpeedElement'];
    58     $this->MaxSpeed = $this->RealMaxSpeed - $this->SpeedReserve;
    59     $this->TopTariffPrice = $Row['TopTariffPrice'];
    60     $this->BaseTariffPrice = $Row['BaseTariffPrice'];
    61 
    62     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member`');
    63     $Row = $DbResult->fetch_row();
    64     $this->InternetUsers = $Row[0];
    65     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member` WHERE (`Blocked`=0) AND (`BillingPeriod` > 1)');
    66     $Row = $DbResult->fetch_row();
    67     $this->PayingUsers = $Row[0];
    68 
    69     $this->SpravaUsers = $this->PayingUsers;
    70 
    71     $DbResult = $this->Database->query('SELECT SUM(`MemberPayment`.`MonthlyInternet`) AS `MonthlyInternet`, '.
    72         'SUM(`MemberPayment`.`MonthlyTotal`) AS `MonthlyTotal` '.
    73         'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` WHERE `Member`.`Blocked`=0');
    74     $Row = $DbResult->fetch_assoc();
    75     $this->TotalInternetPaid = $Row['MonthlyInternet'];
    76     $this->TotalPaid = $Row['MonthlyTotal'];
    77     $this->Rounding = $this->System->Config['Finance']['Rounding'];
    78   }
    79 
    80   function W2Kc($Spotreba): string
    81   {
    82     return round($Spotreba * 0.72 * $this->kWh);
    83   }
    84 
    85   function CreateFinanceYear(int $Year)
    86   {
    87     $StartTime = mktime(0, 0, 0, 1, 1, $Year);
    88     $EndTime = mktime(0, 0, 0, 12, 31, $Year);
    89     $this->Database->insert('FinanceYear', array('Year' => $Year,
    90             'DateStart' => TimeToMysqlDate($StartTime), 'DateEnd' => TimeToMysqlDate($EndTime), 'Closed' => 0));
    91           $YearId = $this->Database->insert_id;
    92 
    93     // Create DocumentLineSequence from previous
    94     $DbResult = $this->Database->select('DocumentLine', 'Id', '`Yearly` = 1');
    95     while ($DbRow = $DbResult->fetch_assoc())
    96     {
    97             $this->Database->insert('DocumentLineSequence', array('FinanceYear' => $YearId,
    98               'NextNumber' => 1, 'YearPrefix' => 1, 'DocumentLine' => $DbRow['Id']));
    99           }
    100   }
    101 
    102   function GetFinanceYear(int $Year): array
    103   {
    104     if ($Year == 0)
    105     {
    106       // Get latest year
    107       $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY `Year` DESC LIMIT 1');
    108     } else $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);
    109     if ($DbResult->num_rows == 0)
    110     {
    111             if ($Year == date('Y'))
    112             {
    113                     $this->CreateFinanceYear($Year);
    114         $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);
    115             } else throw new Exception('Rok '.$Year.' nenalezen');
    116           }
    117     $FinanceYear = $DbResult->fetch_assoc();
    118     if ($FinanceYear['Closed'] == 1)
    119       throw new Exception('Rok '.$FinanceYear['Year'].' je již uzavřen. Nelze do něj přidávat položky.');
    120     return $FinanceYear;
    121   }
    122 
    123   function GetNextDocumentLineNumber(string $Id, int $FinanceYear = 0): string
    124   {
    125           $FinanceYear = $this->GetFinanceYear($FinanceYear);
    126 
    127     $DbResult = $this->Database->query('SELECT `Shortcut`, `Id` FROM `DocumentLine` WHERE `Id`='.$Id);
    128     $DocumentLine = $DbResult->fetch_assoc();
    129 
    130     $DbResult = $this->Database->query('SELECT * FROM `DocumentLineSequence` WHERE '.
    131       '`DocumentLine`='.$Id.' AND `FinanceYear`='.$FinanceYear['Id']);
    132     $Sequence = $DbResult->fetch_assoc();
    133 
    134     if ($Sequence['YearPrefix'] == 1)
    135     {
    136       $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'].'/'.$FinanceYear['Year'];
    137     } else $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'];
    138 
    139     $this->Database->query('UPDATE `DocumentLineSequence` SET `NextNumber` = `NextNumber` + 1 '.
    140       'WHERE (`DocumentLine`='.$Id.') AND (`FinanceYear`='.$FinanceYear['Id'].')');
    141     return $Result;
    142   }
    143 
    144   function GetNextDocumentLineNumberId(string $Id, int $FinanceYear = 0): int
    145   {
    146     $Code = $this->GetNextDocumentLineNumber($Id, $FinanceYear);
    147     $this->Database->insert('DocumentLineCode', array('DocumentLine' => $Id, 'Name' => $Code));
    148     return $this->Database->insert_id;
    149   }
    150 
    151   function GetFinanceGroupById(string $Id, string $Table): ?array
    152   {
    153     $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `Id`= '.$Id);
    154     if ($DbResult->num_rows == 1) {
    155       $Group = $DbResult->fetch_assoc();
    156       return $Group;
    157     }
    158     echo('Finance group id '.$Id.' not found in table '.$Table);
    159     return null;
    160   }
    161 
    162   function RecalculateMemberPayment(): string
    163   {
    164     $Output = 'Aktualizuji finance členů...<br />';
    165     $this->Database->query('TRUNCATE TABLE `MemberPayment`');
    166     $DbResult = $this->Database->query('SELECT * FROM `Member`');
    167     while ($Member = $DbResult->fetch_assoc())
    168     {
    169       $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(`Value`), 0) FROM `FinanceOperation` '.
    170           'WHERE `Subject`='.$Member['Subject'].') - (SELECT COALESCE(SUM(`Value`), 0) FROM `FinanceInvoice` '.
    171           'WHERE `Subject`='.$Member['Subject'].')) AS `Cash`');
    172       $Cash = $DbResult2->fetch_row();
    173       $Cash = $Cash[0];
    174 
    175       $DbResult2 = $this->Database->query('SELECT SUM(`Product`.`Consumption`) * `StockSerialNumber`.`Amount` '.
    176           'FROM `StockSerialNumber` JOIN `Product` ON `Product`.`Id` = `StockSerialNumber`.`Product` '.
    177           'WHERE (`StockSerialNumber`.`Location` = '.$Member['Id'].') AND (`StockSerialNumber`.`TimeElimination` IS NULL)');
    178       $ConsumptionPlus = $DbResult2->fetch_row();
    179       $ConsumptionPlus = $ConsumptionPlus[0];
    180 
    181       $DbResult2 = $this->Database->query('SELECT SUM(`Service`.`Price`) AS `Price` '.
    182           'FROM `ServiceCustomerRel` LEFT JOIN '.
    183           '`Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` WHERE (`ServiceCustomerRel`.`Customer`='.
    184           $Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL)');
    185       $DbRow = $DbResult2->fetch_assoc();
    186       $Monthly = 0;
    187       if ($DbRow['Price'] != '') $MonthlyInet = $DbRow['Price'];
    188       else $MonthlyInet = 0;
    189 
    190       $Monthly += $MonthlyInet;
    191       //$Monthly -= $this->W2Kc($ConsumptionPlus);
    192       $Monthly = round($Monthly);
    193 
    194       if ($Member['BillingPeriod'] == 1)
    195       {
    196         // Inactive payer
    197         $MonthlyInet = 0;
    198         $Monthly = 0;
    199         $ConsumptionPlus = 0;
    200         $Consumption = 0;
    201       }
    202       $Consumption = 0;
    203       $this->Database->insert('MemberPayment', array('Member' => $Member['Id'],
    204         'MonthlyInternet' => $MonthlyInet,
    205         'MonthlyTotal' => $Monthly, 'MonthlyConsumption' => $this->W2Kc($Consumption),
    206         'Cash' => $Cash, 'MonthlyPlus' => $this->W2Kc($ConsumptionPlus)));
    207     }
    208     ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('Finance', 'RecalculateMemberPayment');
    209     return $Output;
    210   }
    211 
    212   function GetVATByType(string $TypeId): string
    213   {
    214     $Time = time();
    215     $DbResult = $this->Database->select('FinanceVAT', 'Value', '(Type='.$TypeId.
    216       ') AND (ValidFrom <= "'.TimeToMysqlDate($Time).'") AND ((ValidTo >= "'.
    217       TimeToMysqlDate($Time).'") OR (ValidTo IS NULL)) LIMIT 1');
    218     $Row = $DbResult->fetch_array();
    219     return $Row[0];
    220   }
    221 }
    222 
    223 class FinanceGroup extends Model
    224 {
    225   static function GetDesc(): ModelDesc
    226   {
    227     $Desc = new ModelDesc('FinanceGroup');
    228     $Desc->AddString('Description');
    229     return $Desc;
    230   }
    231 }
    232 
    233 class FinanceOperation extends Model
    234 {
    235   static function GetDesc(): ModelDesc
    236   {
    237     $Desc = new ModelDesc('FinanceOperation');
    238     $Desc->AddReference('Group', 'FinanceGroup');
    239     $Desc->AddDateTime('Time');
    240     $Desc->AddReference('Subject', 'Subject');
    241     $Desc->AddBoolean('Cash');
    242     $Desc->AddFloat('Value');
    243     $Desc->AddFloat('ValueUser');
    244     $Desc->AddReference('BillCode', 'DocumentLineCode');
    245     $Desc->AddBoolean('Taxable');
    246     $Desc->AddReference('File', 'File');
    247     $Desc->AddString('Text');
    248     $Desc->AddBoolean('Network');
    249     $Desc->AddReference('BankAccount', 'FinanceBankAccount');
    250     $Desc->AddReference('Treasury', 'FinanceTreasury');
    251     $Desc->AddBoolean('Generate');
    252     return $Desc;
    253   }
    254 }
    255 
    256 class FinanceOperationGroup extends Model
    257 {
    258   static function GetDesc(): ModelDesc
    259   {
    260     $Desc = new ModelDesc('FinanceOperationGroup');
    261     $Desc->AddString('Name');
    262     $Desc->AddReference('DocumentLine', 'DocumentLine');
    263     $Desc->AddInteger('ValueSign');
    264     $Desc->AddInteger('Direction');
    265     return $Desc;
    266   }
    267 }
    268 
    269 class FinanceInvoice extends Model
    270 {
    271   static function GetDesc(): ModelDesc
    272   {
    273     $Desc = new ModelDesc('FinanceInvoice');
    274     $Desc->AddReference('Group', 'FinanceGroup');
    275     $Desc->AddReference('BillCode', 'DocumentLineCode');
    276     $Desc->AddReference('Subject', 'Subject');
    277     $Desc->AddDateTime('Time');
    278     $Desc->AddDateTime('TimeDue');
    279     $Desc->AddDateTime('TimePayment');
    280     $Desc->AddFloat('Value');
    281     $Desc->AddReference('File', 'File');
    282     $Desc->AddDate('PeriodFrom');
    283     $Desc->AddDate('PeriodTo');
    284     $Desc->AddBoolean('Cash');
    285     $Desc->AddBoolean('Generate');
    286     $Desc->AddBoolean('VisibleToUser');
    287     return $Desc;
    288   }
    289 }
    290 
    291 class FinanceInvoiceGroup extends Model
    292 {
    293   static function GetDesc(): ModelDesc
    294   {
    295     $Desc = new ModelDesc('FinanceInvoiceGroup');
    296     $Desc->AddString('Name');
    297     $Desc->AddReference('DocumentLine', 'DocumentLine');
    298     $Desc->AddInteger('ValueSign');
    299     $Desc->AddInteger('Direction');
    300     return $Desc;
    301   }
    302 }
    303 
    304 class Company extends Model
    305 {
    306   static function GetDesc(): ModelDesc
    307   {
    308     $Desc = new ModelDesc('Company');
    309     $Desc->AddString('Name');
    310     $Desc->AddReference('Subject', 'Subject');
    311     return $Desc;
    312   }
    313 }
    314 
    315 class FinanceInvoiceItem extends Model
    316 {
    317   static function GetDesc(): ModelDesc
    318   {
    319     $Desc = new ModelDesc('FinanceInvoiceItem');
    320     $Desc->AddReference('FinanceInvoice', 'FinanceInvoice');
    321     $Desc->AddString('Description');
    322     $Desc->AddFloat('Price');
    323     $Desc->AddFloat('Quantity');
    324     $Desc->AddInteger('VAT');
    325     return $Desc;
    326   }
    327 }
    328 
    329 class FinanceTreasury extends Model
    330 {
    331   static function GetDesc(): ModelDesc
    332   {
    333     $Desc = new ModelDesc('FinanceTreasury');
    334     $Desc->AddString('Name');
    335     $Desc->AddDate('TimeCreate');
    336     return $Desc;
    337   }
    338 }
    339 
    340 class FinanceTreasuryCheck extends Model
    341 {
    342   static function GetDesc(): ModelDesc
    343   {
    344     $Desc = new ModelDesc('FinanceTreasuryCheck');
    345     $Desc->AddReference('Treasury', 'FinanceTreasury', false);
    346     $Desc->AddDateTime('Time');
    347     $Desc->AddInteger('Value1');
    348     $Desc->AddInteger('Value2');
    349     $Desc->AddInteger('Value5');
    350     $Desc->AddInteger('Value10');
    351     $Desc->AddInteger('Value20');
    352     $Desc->AddInteger('Value50');
    353     $Desc->AddInteger('Value100');
    354     $Desc->AddInteger('Value200');
    355     $Desc->AddInteger('Value500');
    356     $Desc->AddInteger('Value1000');
    357     $Desc->AddInteger('Value2000');
    358     $Desc->AddInteger('Value5000');
    359     return $Desc;
    360   }
    361 }
    362 
    363 class FinanceBankAccount extends Model
    364 {
    365   static function GetDesc(): ModelDesc
    366   {
    367     $Desc = new ModelDesc('FinanceBankAccount');
    368     $Desc->AddReference('Subject', 'Subject');
    369     $Desc->AddString('Comment');
    370     $Desc->AddString('Number');
    371     $Desc->AddReference('Bank', 'FinanceBank');
    372     $Desc->AddDate('TimeCreate');
    373     $Desc->AddDate('TimeEnd');
    374     $Desc->AddReference('Currency', 'Currency');
    375     $Desc->AddString('LoginName');
    376     $Desc->AddString('LoginPassword');
    377     $Desc->AddBoolean('Use');
    378     $Desc->AddDate('LastImportDate');
    379     $Desc->AddString('LastImportId');
    380     $Desc->AddBoolean('AutoImport');
    381     return $Desc;
    382   }
    383 }
    384 
    385 class FinanceBank extends Model
    386 {
    387   static function GetDesc(): ModelDesc
    388   {
    389     $Desc = new ModelDesc('FinanceBank');
    390     $Desc->AddString('Name');
    391     $Desc->AddString('Code');
    392     $Desc->AddString('BIC');
    393     $Desc->AddReference('Country', 'Country');
    394     return $Desc;
    395   }
    396 }
    397 
    398 class Currency extends Model
    399 {
    400   static function GetDesc(): ModelDesc
    401   {
    402     $Desc = new ModelDesc('Currency');
    403     $Desc->AddString('Code');
    404     $Desc->AddString('Name');
    405     $Desc->AddString('Symbol');
    406     return $Desc;
    407   }
    408 }
    409 
    410 class FinanceCharge extends Model
    411 {
    412   static function GetDesc(): ModelDesc
    413   {
    414     $Desc = new ModelDesc('FinanceCharge');
    415     $Desc->AddInteger('Internet');
    416     $Desc->AddInteger('InternetSpeed');
    417     $Desc->AddInteger('InternetSpeedReserve');
    418     $Desc->AddInteger('AdministrationPerUser');
    419     $Desc->AddInteger('kWh');
    420     $Desc->AddInteger('BaseSpeedElement');
    421     $Desc->AddInteger('BaseTariffPrice');
    422     $Desc->AddInteger('TopTariffPrice');
    423     $Desc->AddChangeAction();
    424     return $Desc;
    425   }
    426 }
    427 
    428 class FinanceVat extends Model
    429 {
    430   static function GetDesc(): ModelDesc
    431   {
    432     $Desc = new ModelDesc('FinanceVAT');
    433     $Desc->AddReference('Type', 'FinanceVatType');
    434     $Desc->AddDate('ValidFrom');
    435     $Desc->AddDate('ValidTo');
    436     $Desc->AddInteger('Value');
    437     return $Desc;
    438   }
    439 }
    440 
    441 class FinanceVatType extends Model
    442 {
    443   static function GetDesc(): ModelDesc
    444   {
    445     $Desc = new ModelDesc('FinanceVATType');
    446     $Desc->AddString('Name');
    447     return $Desc;
    448   }
    449 }
    450 
    451 class Contract extends Model
    452 {
    453   static function GetDesc(): ModelDesc
    454   {
    455     $Desc = new ModelDesc('Contract');
    456     $Desc->AddReference('DocumentLine', 'DocumentLine');
    457     $Desc->AddReference('BillCode', 'DocumentLineCode');
    458     $Desc->AddReference('Subject', 'Subject');
    459     $Desc->AddDate('ValidFrom');
    460     $Desc->AddDate('ValidTo');
    461     $Desc->AddReference('File', 'File');
    462     return $Desc;
    463   }
    464 }
    4659
    46610class ModuleFinance extends AppModule
     
    48529  function GetModels(): array
    48630  {
    487     return array(
    488       'FinanceVatType',
    489       'FinanceVat',
    490       'FinanceGroup',
    491       'FinanceOperationGroup',
    492       'FinanceOperation',
    493       'FinanceInvoiceGroup',
    494       'FinanceInvoice',
    495       'FinanceInvoiceItem',
    496       'Company',
    497       'FinanceTreasury',
    498       'FinanceTreasuryCheck',
    499       'Currency',
    500       'FinanceBank',
    501       'FinanceBankAccount',
    502       'FinanceCharge',
    503       'Contract'
    504     );
     31    return array(FinanceBillingPeriod::GetClassName(), FinanceVatType::GetClassName(), FinanceVat::GetClassName(),
     32      FinanceGroup::GetClassName(), FinanceOperationGroup::GetClassName(), FinanceOperation::GetClassName(),
     33      FinanceInvoiceGroup::GetClassName(), FinanceInvoice::GetClassName(), FinanceInvoiceItem::GetClassName(),
     34      Company::GetClassName(), FinanceTreasury::GetClassName(), FinanceTreasuryCheck::GetClassName(),
     35      Currency::GetClassName(), FinanceBank::GetClassName(), FinanceBankAccount::GetClassName(), FinanceCharge::GetClassName(),
     36      Contract::GetClassName(), FinanceInvoiceOperationRel::GetClassName());
    50537  }
    50638
     
    937469      'Filter' => '1',
    938470    ));
     471    $this->System->FormManager->RegisterClass('FinanceYearReport', array(
     472      'Title' => 'Roční výkaz',
     473      'Table' => 'FinanceYearReport',
     474      'SQL' => 'SELECT Id, DateEnd, DateStart FROM FinanceYear',
     475      'DefaultSortColumn' => 'Id',
     476      'Items' => array(
     477        'Id' => array('Type' => 'TFinanceYear', 'Caption' => 'Rok', 'Default' => '',
     478          'ReadOnly' => true),
     479        'Income' => array('Type' => 'Integer', 'Caption' => 'Příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     480          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     481          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     482          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     483          'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
     484        'Spending' => array('Type' => 'Integer', 'Caption' => 'Výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     485          'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     486          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     487          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     488          'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
     489        'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     490          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     491          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     492          'AND (`FinanceOperation`.`Time` >= `DateStart`))'),
     493        'TaxIncome' => array('Type' => 'Integer', 'Caption' => 'Daňové příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     494          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     495          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     496          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     497          'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
     498        'TaxSpending' => array('Type' => 'Integer', 'Caption' => 'Daňové výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     499          'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     500          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     501          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     502          'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
     503        'TaxBase' => array('Type' => 'Integer', 'Caption' => 'Základ daně', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     504          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     505          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     506          'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1))'),
     507        'Claims' => array('Type' => 'Integer', 'Caption' => 'Pohledávky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     508          'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` '.
     509          'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
     510          'WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     511          'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoiceGroup`.`ValueSign` = 1))'),
     512        'Liabilities' => array('Type' => 'Integer', 'Caption' => 'Závazky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     513          'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` '.
     514          'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
     515          'WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     516          'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoiceGroup`.`ValueSign` = -1))'),
     517        'InvoiceBalance' => array('Type' => 'Integer', 'Caption' => 'Fakturační rozdíl', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     518          'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
     519          'AND (`FinanceInvoice`.`Time` >= `DateStart`))'),
     520      ),
     521      //'AfterInsert' => array($this, 'AfterInsertFinanceYear'),
     522    ));
     523    $this->System->FormManager->RegisterClass('FinanceInvoiceOperationRel', array(
     524      'Title' => 'Zaplacení faktůr',
     525      'Table' => 'FinanceInvoiceOperationRel',
     526      'Items' => array(
     527        'Invoice' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Faktura', 'Default' => ''),
     528        'Operation' => array('Type' => 'TFinanceOperation', 'Caption' => 'Platba', 'Default' => ''),
     529      ),
     530    ));
    939531
    940532    $this->Finance->MainSubject = $Config['Finance']['MainSubjectId'];
Note: See TracChangeset for help on using the changeset viewer.