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

to group id instead of DocumentLine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.