Changeset 551


Ignore:
Timestamp:
Jul 7, 2013, 9:26:44 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: Automatické generování kódu dokladu při vytváření nové položky v IS a při importu z Fio banky.
  • Odstraněno: Staré akce na stránce "Správa financí".
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Form/Form.php

    r548 r551  
    172172      if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    173173      if($Item['ReadOnly'] == false)
    174     if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    175     (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    176     ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    177     {
    178       if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
    179       $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index,
     174      if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     175      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     176      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     177      {
     178        if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     179        $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index,
    180180          'Type' => $Item['Type'], 'Values' => $this->Values);
    181181     
     
    194194        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);
    195195        if(($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]);
    196     }
     196      }
    197197    }
    198198    if($Id == 0)
  • trunk/Common/Version.php

    r550 r551  
    11<?php
    22
    3 $Revision = 550; // Subversion revision
    4 $DatabaseRevision = 550; // SQL structure revision
     3$Revision = 551; // Subversion revision
     4$DatabaseRevision = 551; // SQL structure revision
    55$ReleaseTime = '2013-07-07';
    66
  • trunk/Modules/Finance/Finance.php

    r550 r551  
    356356      'DefaultSortColumn' => 'Time',
    357357      'Items' => array(
     358        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
     359        'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
     360        'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
    358361        'Time' => array('Type' => 'Date', 'Caption' => 'Čas realizace', 'Default' => ''),
    359         'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
    360362        'Cash' => array('Type' => 'Boolean', 'Caption' => 'Hotově', 'Default' => ''),
    361363        'Taxable' => array('Type' => 'Boolean', 'Caption' => 'Zdanitelné', 'Default' => ''),
    362364        'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
    363         'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
    364365        'Text' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
    365366        'Network' => array('Type' => 'Boolean', 'Caption' => 'Týkající sítě', 'Default' => ''),
     
    368369        'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
    369370      ),
     371      'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
    370372    ));
    371373    $this->System->FormManager->RegisterClass('FinanceInvoice', array(
     
    374376      'DefaultSortColumn' => 'TimeCreation',
    375377      'Items' => array(
     378        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
    376379        'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
    377380        'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
     
    384387        'Items' => array('Type' => 'TFinanceInvoiceItemListInvoice', 'Caption' => 'Položky', 'Default' => ''),
    385388      ),
     389      'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
    386390    ));
    387391    $this->System->FormManager->RegisterClass('FinanceInvoiceItem', array(
     
    473477  {
    474478  }
     479 
     480  function BeforeInsertFinanceOperation($Form)
     481  {
     482    $DocumentLine = $Form->Values['DocumentLine'];
     483    $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
     484    return($Form->Values);
     485  } 
    475486}
  • trunk/Modules/Finance/Manage.php

    r549 r551  
    99  function Show()
    1010  {
     11    $Output = '';
    1112    if(!$this->System->User->CheckPermission('Finance', 'Manage'))
    1213      return('Nemáte oprávnění');
     
    1415    if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation'];
    1516      else $Operation = '';
    16     //$Operation = 'ImportOldData';
    1717    switch($Operation)
    1818    {
    19       case 'Bills':
    20         $Output = $this->BillManage();
    21         break;
    22       case 'ConvertPDFToFile':
    23         $Output = $this->ConvertPDFDataToFiles();
    24         break;
    25       //case 'ImportOldData':
    26       //  $Output = $this->ImportOldData();
    27       //  break;
    28       case 'NewPaymentInsert':
    29         $Output = $this->ShowNewPaymentInsert();
    30         break;
    31       case 'NewPaymentForm':
    32         $Output = $this->ShowNewPaymentForm();
    33         break;
    34       case 'NewInvoiceInsert':
    35         $Output = $this->ShowNewInvoiceInsert();
    36         break;
    37       case 'NewInvoiceForm':
    38         $Output = $this->ShowNewInvoiceForm();
    39         break;
    4019      case 'Recalculate':
    4120        $Output = $this->System->Modules['Finance']->RecalculateSegmentParameters();
     
    5231        break;
    5332      default:
    54         $Output = '<a href="?Operation=NewPaymentForm">Přidat novou platbu</a><br />';
    55         $Output .= '<a href="?Operation=NewInvoiceForm">Přidat novou fakturu</a><br />';
    56         $Output .= '<a href="?Operation=ConvertPDFToFile">Převést data z databáze do souborů</a><br />';
    57         $Output .= '<a href="?Operation=Bills">Správa dokladů</a><br />';
    5833        //$Output .= '<a href="?Operation=Recalculate">Přepočet financí</a><br />';
    5934        $Output .= '<a href="?Operation=ShowMonthlyPayment">Měsíční vyúčtování</a><br />';
    60         //$Output .= '<a href="clenove.php">Seznam členů</a><br />';
    6135        $Output .= '<a href="'.$this->System->Link('/finance/zivnost/').'">Živnost</a><br />';
    6236        $Output .= '<a href="?Operation=GenerateBills">Generovat chybějící doklady</a><br />';
     
    6438    }
    6539    return($Output);
    66   }
    67 
    68   function BillManage()
    69   {
    70     $Output = '';
    71     if(array_key_exists('subject', $_GET))
    72     {
    73       $DbResult = $this->Database->select('FinanceBills', '*', 'Subject='.$_GET['subject']);
    74       while($Item = $DbResult->fetch_array())
    75       {
    76         $Output .= '<a href="?Operation=Bills&amp;bill='.$Item['Id'].'">faktura '.$Item['Id'].'</a> <a href="?Operation=Bills&amp;billpdf='.$Item['Id'].'">Uložené PDF</a> <a href="?Operation=Bills&amp;billpdf2='.$Item['Id'].'">Generované PDF</a> <a href="?Operation=Bills&amp;regenerate='.$Item['Id'].'">Přegenerovat</a><br />';
    77       }
    78     } else
    79     if(array_key_exists('billpdf', $_GET))
    80     {
    81       $Output .= $this->System->Modules['Bill']->ShowStoredBill($_GET['billpdf']);
    82     } else
    83     if(array_key_exists('billpdf2', $_GET))
    84     {
    85       $Output .= $this->System->Modules['Bill']->ShowGeneratedBill($_GET['billpdf2']);
    86     } else
    87     if(array_key_exists('regenerate', $_GET))
    88     {
    89       $Output .= $this->System->Modules['Bill']->RegeneratePDF($_GET['regenerate']);
    90     } else
    91     if(array_key_exists('bill', $_GET))
    92     {
    93       $Output .= $this->System->Modules['Bill']->GenerateBill($_GET['bill']);
    94     } else
    95     if(array_key_exists('generate', $_GET))
    96     {
    97       $Output .= $this->System->Modules['Bill']->CreateBill(1, array(array('Description' => 'Poplatek za připojení k Internetu', 'Price' => 1000, 'Quantity' => 1)), time(), time());
    98     } else
    99     {
    100       //ShowHeader('Faktury', 'Faktury');
    101       $Output .= 'Faktury:<br />';
    102       $DbResult = $this->Database->select('Subject', '*', '1 ORDER BY Name');
    103       while($Subject = $DbResult->fetch_array())
    104       {
    105         $Output .= '<a href="?Operation=Bills&amp;subject='.$Subject['Id'].'">'.$Subject['Name'].'</a><br />';
    106       }
    107       //ShowFooter();
    108     }
    109     return($Output);
    110   }
    111 
    112   function CheckAdvancesAndLiabilities($Subject)
    113   {
    114     global $LastInsertTime;
    115 
    116     do {
    117       $DbResult = $this->Database->select('FinanceAdvances', 'SUM(Value)', 'Subject='.$Subject.' AND Direction = "In"');
    118       $DbRow = $DbResult->fetch_array();
    119       $Advances = $DbRow[0];
    120       $DbResult = $this->Database->select('FinanceInvoice', '*', 'Subject='.$Subject.
    121       ' AND TimePayment IS NULL AND Value > 0 ORDER BY TimeCreation LIMIT 1');
    122       if($DbResult->num_rows > 0)
    123       {
    124         $OpenedClaim = $DbResult->fetch_array();
    125         if($Advances > $OpenedClaim['Value'])
    126         {
    127           $this->Database->update('FinanceInvoice', 'Id='.$OpenedClaim['Id'],
    128             array('TimePayment' => TimeToMysqlDateTime($LastInsertTime)));
    129           $this->Database->insert('FinanceAdvances', array('Subject' =>
    130             $OpenedClaim['Subject'], 'Value' => -$OpenedClaim['Value'],
    131             'TimeCreation' => TimeToMysqlDateTime($LastInsertTime),
    132             'CashFlowId' => $OpenedClaim['Id'], 'Direction' => 'In'));
    133         } else break;
    134       } else break;
    135     } while(($Advances > $OpenedClaim['Value']));
    136   }
    137 
    138   function InsertInvoice($Subject, $TimeCreation, $TimeDue, $Items,
    139     $DocumentLine, $PeriodFrom, $PeriodTo)
    140   {
    141     global $LastInsertTime;
    142 
    143     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
    144     $SumValue = 0;
    145     foreach($Items as $Item)
    146       $SumValue = $SumValue + $Item['Price'];
    147     $this->Database->insert('FinanceInvoice', array(
    148       'Subject' => $Subject, 'TimeCreation' => TimeToMysqlDateTime($TimeCreation),
    149       'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue, 'BillCode' => $BillCode,
    150       'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo),
    151       'Generate' => 1));
    152     $InvoiceId = $this->Database->insert_id;
    153     foreach($Items as $Item)
    154     $this->Database->insert('FinanceInvoiceItem', array('FinanceInvoice' => $InvoiceId,
    155       'Description' => $Item['Description'], 'Price' => $Item['Price'], 'Quantity' => $Item['Quantity'], 'VAT' => $Item['VAT']));
    156     //$LastInsertTime = $Time;
    157     //$this->CheckAdvancesAndLiabilities($Subject);
    158     return($InvoiceId);
    159   }
    160 
    161   function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine)
    162   {
    163     global $LastInsertTime;
    164 
    165     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
    166     $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
    167     /*if($Value >= 0)
    168     {
    169       $this->Database->insert('FinanceAdvances', array('Subject' => $Subject, 'Value' => $Value, 'TimeCreation' => TimeToMysqlDateTime($Time), 'CashFlowId' => $this->Database->insert_id, 'Direction' => 'In'));
    170     }
    171     $LastInsertTime = $Time;
    172     */
    173     //$this->CheckAdvancesAndLiabilities($Subject);
    174   }
    175 
    176     function ShowNewPaymentForm()
    177   {
    178     $Form = new Form($this->System->FormManager);
    179     $Form->SetClass('NewPayment');
    180     $Form->OnSubmit = '?Operation=NewPaymentInsert';
    181     $Output = $Form->ShowEditForm();
    182     return($Output);
    183   }
    184 
    185   function ShowNewPaymentInsert()
    186   {
    187     $Form = new Form($this->System->FormManager);
    188     $Form->SetClass('NewPayment');
    189     $Form->LoadValuesFromForm();
    190     $this->InsertMoney($Form->Values['Subject'], $Form->Values['Value'], $Form->Values['Cash'], $Form->Values['Taxable'], $Form->Values['Time'], $Form->Values['Text'], $Form->Values['DocumentLine']);
    191     $LastId = $this->Database->insert_id;
    192     $DbResult = $this->Database->select('FinanceOperation', 'BillCode', 'Id='.$LastId);
    193     $DbRow = $DbResult->fetch_assoc();
    194     $Output = $this->SystemMessage('Finance', 'Platba vložena '.$DbRow['BillCode'].'.');
    195     $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
    196     return($Output);
    197   }
    198 
    199   function ShowNewInvoiceForm()
    200   {
    201     $Form = new Form($this->System->FormManager);
    202     $Form->SetClass('NewInvoice');
    203     $Form->OnSubmit = '?Operation=NewInvoiceInsert';
    204     $Output = $Form->ShowEditForm();
    205     return($Output);
    206   }
    207 
    208   function ShowNewInvoiceInsert()
    209   {
    210     $Form = new Form($this->System->FormManager);
    211     $Form->SetClass('NewInvoice');
    212     $Form->LoadvaluesFromForm();
    213     $Items = array(array('Price' => $Form->Values['Value'],
    214       'Description' => $Form->Values['Text'], 'Quantity' => 1, 'VAT' => 21));
    215     $LastId = $this->InsertInvoice($Form->Values['Subject'], 
    216       $Form->Values['TimeCreation'], $Form->Values['TimeDue'], $Items,
    217       $Form->Values['DocumentLine'], NULL, NULL);
    218     $DbResult = $this->Database->select('FinanceInvoice', 'BillCode', 'Id='.$LastId);
    219     $DbRow = $DbResult->fetch_assoc();
    220     $Output = $this->SystemMessage('Finance', 'Faktura vložena '.$DbRow['BillCode'].'.');
    221     $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewInvoiceInserted');
    222     return($Output);
    223   }
    224  
    225   function ConvertPDFDataToFiles()
    226   {
    227     $DbResult = $this->Database->query('SELECT * FROM FinanceBills');
    228     while($Bill = $DbResult->fetch_assoc())
    229     {
    230       file_put_contents('doklady/doklad_'.$Bill['id'].'.pdf', $Bill['pdf']);
    231       echo($Bill['id'].',');
    232     }
    233   }
    234 
    235   function CheckPDFFiles()
    236   {
    237     global $InvoiceGenerator;
    238 
    239     $DbResult = $this->Database->query('SELECT * FROM FinanceBills');
    240     while($Bill = $DbResult->fetch_assoc())
    241     {
    242       file_put_contents('doklady2/doklad-'.$Bill['id'].'.pdf', file_get_contents('doklady/doklad-'.$Bill['id'].'.pdf'));
    243       //echo($InvoiceGenerator->HasPDFFile($Bill['id']).',');
    244     }
    24540  }
    24641 
  • trunk/Modules/FinanceBankAPI/FileImport.php

    r550 r551  
    55class BankImport
    66{
     7  var $System;
    78  var $Database;
    89  var $BankAccount;
    910 
    10   function __construct($Database)
     11  function __construct($System)
    1112  {
    12     $this->Database = &$Database;
     13    $this->Database = &$System->Database;
     14    $this->System = &$System;
    1315  }
    1416     
     
    2628    while($DbRow = $DbResult->fetch_assoc())
    2729    {
     30      echo($DbRow['Id'].',');
    2831      if(is_numeric($DbRow['VariableSymbol']))
    2932      {
     
    3235        {
    3336          $DbRow2 = $DbResult2->fetch_assoc();
     37          if($DbRow['Value'] >= 0) $DocumentLine = 3; // Receive money
     38            else $DocumentLine = 4; // Send money
     39          $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
    3440          $DbResult3 = $this->Database->insert('FinanceOperation', array('Subject' => $DbRow2['Id'], 'Cash' => 0,
    3541            'Value' => $DbRow['Value'], 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
    36             'Time' => $DbRow['Time'], 'Text' => $DbRow['Description']));
     42            'Time' => $DbRow['Time'], 'Text' => $DbRow['Description'], 'BillCode' => $BillCode));
    3743          $this->Database->update('FinanceBankImport', 'Id='.$DbRow['Id'], array('FinanceOperation' => $this->Database->insert_id));
    3844        }
     
    6066    $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')';
    6167   
    62     if($Bank['Code'] == '2010') $Import = new ImportFio($this->Database);
    63       else if($Bank['Code'] == '0300') $Import = new ImportPS($this->Database);
     68    if($Bank['Code'] == '2010') $Import = new ImportFio($this->System);
     69      else if($Bank['Code'] == '0300') $Import = new ImportPS($this->System);
    6470      else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován');
    6571    if(isset($Import))
     
    118124    $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')';
    119125   
    120     if($Bank['Code'] == '2010') $Import = new ImportFio($this->Database);
    121       else if($Bank['Code'] == '0300') $Import = new ImportPS($this->Database);
     126    if($Bank['Code'] == '2010') $Import = new ImportFio($this->System);
     127      else if($Bank['Code'] == '0300') $Import = new ImportPS($this->System);
    122128      else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován');
    123129    $Import->BankAccount = $BankAccount;
  • trunk/Modules/FinanceBankAPI/ImportFio.php

    r550 r551  
    4343    }
    4444    $Output .= '</table>';   
    45     $this->Database->Update('FinanceBankAccount', 'Id='.$this->BankAccount['Id'], array('LastImportDate' => TimeToMysqlDate($PeriodEnd)));
     45    $this->Database->update('FinanceBankAccount', 'Id='.$this->BankAccount['Id'], array('LastImportDate' => TimeToMysqlDate($PeriodEnd)));
    4646    return($Output);
    4747  }
  • trunk/Modules/IS/IS.php

    r548 r551  
    6565    $DbRow = $DbResult->fetch_row();
    6666    $Output .= 'Stav placení: '.$DbRow['0'].'<br/>';
     67    $DbResult = $this->Database->select('FinanceBankImport', 'COUNT(*)', 'FinanceOperation IS NULL');
     68    $DbRow = $DbResult->fetch_row();
     69    $Output .= 'Nezpárovaných plateb: '.$DbRow['0'].'<br/>';
    6770    return($Output);
    6871  }
     
    136139        $Form->LoadValuesFromForm();
    137140        try {
     141          if(array_key_exists('BeforeInsert', $Form->Definition))
     142          {
     143            $Class = $Form->Definition['BeforeInsert'][0];
     144            $Method = $Form->Definition['BeforeInsert'][1];
     145            $this->Values = $Class->$Method($Form);
     146          }
    138147          $Form->SaveValuesToDatabase(0);       
    139148          $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
  • trunk/admin/Updates.php

    r550 r551  
    329329}
    330330
     331function UpdateTo551($Manager)
     332
     333  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD `DocumentLine` INT NULL AFTER `Value` ,
     334ADD INDEX ( `DocumentLine` ) ;');
     335  $Manager->Execute('ALTER TABLE `FinanceOperation` ADD FOREIGN KEY ( `DocumentLine` ) REFERENCES `DocumentLine` (
     336`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT ;');
     337  $Manager->Execute('ALTER TABLE `FinanceInvoice` ADD `DocumentLine` INT NULL AFTER `Id` ,
     338ADD INDEX ( `DocumentLine` ) ;');
     339  $Manager->Execute('ALTER TABLE `FinanceInvoice` ADD FOREIGN KEY ( `DocumentLine` ) REFERENCES `DocumentLine` (
     340`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT ;');
     341  $Manager->Execute('DROP TABLE `FinanceBillsOld`');
     342  $Manager->Execute('DROP TABLE `FinanceBillsItemsOld`');
     343}
     344
     345
    331346$Updates = array(
    332347  491 => array('Revision' => 493, 'Function' => 'UpdateTo493'),
     
    347362  535 => array('Revision' => 549, 'Function' => 'UpdateTo549'),
    348363  549 => array('Revision' => 550, 'Function' => 'UpdateTo550'),
     364  550 => array('Revision' => 551, 'Function' => 'UpdateTo551'),
    349365);
Note: See TracChangeset for help on using the changeset viewer.