Changeset 165 for www/finance/manage.php


Ignore:
Timestamp:
Mar 5, 2009, 10:16:12 PM (16 years ago)
Author:
george
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • www/finance/manage.php

    r164 r165  
    4747      case 'NewInvoiceForm':
    4848        $Output = $this->ShowNewInvoiceForm();
     49        break;
     50      case 'ConvertData':
     51        $Output = $this->ConvertData();
    4952        break;
    5053      default:
     
    5659        $Output .= '<a href="?Operation=ConvertPDFToFile">Převést data z databáze do souborů</a><br />';
    5760        $Output .= '<a href="?Operation=Bills">Správa dokladů</a><br />';
     61        $Output .= '<a href="?Operation=ConvertData">Převést tabulky</a><br />';
    5862                $Output .= '<a href="prepocet.php">Přepočet financí</a><br />';
    5963                $Output .= '<a href="clenove.php">Seznam subjektů</a><br />';
     
    356360  {
    357361    $DbResult = $this->Database->query('SELECT * FROM FinanceBills');
    358     while($Bill = $DbResult->fetch_array())
     362    while($Bill = $DbResult->fetch_assoc())
    359363    {
    360364      file_put_contents('doklady/doklad_'.$Bill['id'].'.pdf', $Bill['pdf']);
     
    365369  function CheckPDFFiles()
    366370  {
    367     global $Database, $InvoiceGenerator;
     371    global $InvoiceGenerator;
    368372
    369373    $DbResult = $this->Database->query('SELECT * FROM FinanceBills');
    370     while($Bill = $DbResult->fetch_array())
     374    while($Bill = $DbResult->fetch_assoc())
    371375    {
    372376      file_put_contents('doklady2/doklad-'.$Bill['id'].'.pdf', file_get_contents('doklady/doklad-'.$Bill['id'].'.pdf'));
     
    375379  }
    376380
     381  function ConvertData()
     382  {
     383        $Output = '';
     384        $this->Database->query('TRUNCATE TABLE FinanceOperation');
     385
     386    // Move time of device price transformation
     387    $this->Database->query('UPDATE finance_operations SET date="2007-11-30" WHERE comment = "Jednorázový poplatek za společné zařízení"');
     388
     389    // Transform old operations
     390        $DbResult = $this->Database->query('SELECT * FROM finance_operations WHERE finance_operations.date >= "2007-12-01"');
     391        while($DbRow = $DbResult->fetch_assoc())
     392        {
     393          $this->Database->insert('FinanceOperation', array('Id' => $DbRow['id'], 'SourceSubject' => $DbRow['Source'], 'DestinationSubject' => $DbRow['Destination'], 'Value' => abs($DbRow['money']), 'Time' => $DbRow['date'], 'BillCode' => $DbRow['BillCode'], 'Taxable' => $DbRow['Taxable'], 'Text' => $DbRow['comment'], 'Bill' => $DbRow['bill_id']));
     394          $Output .= '.';
     395        }
     396
     397    // Transfer finance before era
     398    $DbResult = $this->Database->query('SELECT * FROM Subject');
     399    while($Subject = $DbResult->fetch_assoc())
     400    {
     401      $DbResult2 = $this->Database->query('SELECT SUM(money) as money FROM finance_operations WHERE user='.$Subject['Id'].' AND date < "2007-12-01"');
     402      $DbRow2 = $DbResult2->fetch_assoc();
     403
     404          if($DbRow2['money'] > 0)
     405          {
     406        $DestinationSubject = $Subject['Id'];
     407                $SourceSubject = 96;
     408                $Comment = 'Přijatá záloha (z období před daňovou evidencí)';
     409          } else
     410          {
     411                $DestinationSubject = 71;
     412                $SourceSubject = $Subject['Id'];
     413                $Comment = 'Připojení k síti (z období před daňovou evidencí)';
     414          }
     415          $DbRow2['date'] = TimeToMysqlDateTime(mktime(0, 0, 0, 12, 1, 2007));
     416          $this->Database->insert('FinanceOperation', array('SourceSubject' => $SourceSubject, 'DestinationSubject' => $DestinationSubject, 'Value' => abs($DbRow2['money']), 'Time' => $DbRow2['date'], 'Taxable' => 1, 'Text' => $Comment));
     417          $Output .= '#';
     418    }
     419
     420        return($Output);
     421  }
    377422}
    378423
Note: See TracChangeset for help on using the changeset viewer.