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í".
File:
1 edited

Legend:

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