Changeset 152 for www/finance/manage.php


Ignore:
Timestamp:
Feb 16, 2009, 2:09:57 PM (15 years ago)
Author:
george
Message:
  • Upraveno: Další soubory přepracované do nového systému zobrazování.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • www/finance/manage.php

    r144 r152  
    11<?php
    2 
    3 include('finance.php');
    4 include('bills.php');
    5 
    6 /*
    7 if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
    8 switch($Operation)
     2include_once('../global.php');
     3include_once('include.php');
     4
     5class FinanceManagePage extends Page
    96{
    10   case 'NewPaymentInsert':
    11     $Output = ShowNewPaymentInsert(); 
    12     break;
    13   case 'NewPaymentForm':
    14     $Output = ShowNewPaymentForm(); 
    15     break;
    16   case 'NewInvoiceForm':
    17     $Output = ShowNewInvoiceForm(); 
    18     break;
    19   default:
    20     $Output = '<a href="?Operation=NewPaymentForm">Přidat novou platbu</a><br>';
    21     $Output .= '<a href="?Operation=NewInvoiceForm">Přidat novou fakturu</a><br>';
    22 }
    23 echo(FormatOutput($Output));
    24 */
    25 
    26 function CheckAdvancesAndLiabilities($Subject)
    27 {
    28   global $Database, $LastInsertTime;
    29   do {
    30     $DbResult = $Database->select('FinanceAdvances', 'SUM(Value)', 'Subject='.$Subject.' AND Direction = "In"');
    31     $DbRow = $DbResult->fetch_array();
    32     $Advances = $DbRow[0];
    33     $DbResult = $Database->select('FinanceClaimsLiabilities', '*', 'Subject='.$Subject.' AND TimePayment IS NULL AND Value > 0 ORDER BY TimeCreation LIMIT 1');
    34     //echo($Database->error);
    35     if($DbResult->num_rows > 0)
    36     {
    37       $OpenedClaim = $DbResult->fetch_array();
    38       if($Advances > $OpenedClaim['Value'])
    39       {
    40         $Database->update('FinanceClaimsLiabilities', 'Id='.$OpenedClaim['Id'], array('TimePayment' => TimeToMysqlDateTime($LastInsertTime)));
    41         $Database->insert('FinanceAdvances', array('Subject' => $OpenedClaim['Subject'], 'Value' => -$OpenedClaim['Value'], 'TimeCreation' => TimeToMysqlDateTime($LastInsertTime), 'CashFlowId' => $OpenedClaim['Id'], 'Direction' => 'In'));
    42         //echo($Database->LastQuery);
     7  var $FullTitle = 'Správa financí';
     8  var $ShortTitle = 'Správa financí';
     9
     10  function Show()
     11  {
     12    //if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');
     13
     14    if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
     15    switch($Operation)
     16    {
     17      case 'Bills':
     18        $Output = $this->BillManage();
     19        break;
     20      case 'ConvertPDFToFile':
     21        $Output = $this->ConvertPDFDataToFiles();
     22        break;
     23      case 'ImportOldData':
     24        $Output = $this->ImportOldData();
     25        break;
     26      case 'NewDeviceForm':
     27        $Output = $this->ShowNewDeviceForm();
     28        break;
     29      case 'NewDeviceInsert':
     30        $Output = $this->ShowNewDeviceInsert();
     31        break;
     32      case 'NewDeviceHistoryForm':
     33        $Output = $this->ShowNewDeviceHistoryForm();
     34        break;
     35      case 'NewDeviceHistoryInsert':
     36        $Output = $this->ShowNewDeviceHistoryInsert();
     37        break;
     38      case 'NewPaymentInsert':
     39        $Output = $this->ShowNewPaymentInsert();
     40        break;
     41      case 'NewPaymentForm':
     42        $Output = $this->ShowNewPaymentForm();
     43        break;
     44      case 'NewInvoiceInsert':
     45        $Output = $this->ShowNewInvoiceInsert();
     46        break;
     47      case 'NewInvoiceForm':
     48        $Output = $this->ShowNewInvoiceForm();
     49        break;
     50      default:
     51        $Output = '<a href="?Operation=NewDeviceForm">Přidat nové zařízení</a><br>';
     52        $Output .= '<a href="?Operation=NewDeviceHistoryForm">Přidat nový záznam historie zařízení</a><br>';
     53        $Output .= '<a href="?Operation=NewPaymentForm">Přidat novou platbu</a><br>';
     54        $Output .= '<a href="?Operation=NewInvoiceForm">Přidat novou fakturu</a><br>';
     55        $Output .= '<a href="?Operation=ImportOldData">Importovat stará data</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>';
     58    }
     59    return($Output);
     60  }
     61
     62  function BillManage()
     63  {
     64    $Output = '';
     65    if(array_key_exists('user', $_GET))
     66    {
     67      $DbResult = $this->Database->select('finance_bills', '*', 'user_id='.$_GET['user']);
     68      while($Item = $DbResult->fetch_array())
     69      {
     70        $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 />';
     71      }
     72    } else
     73    if(array_key_exists('billpdf', $_GET))
     74    {
     75      $Output .= $this->System->Modules['Bill']->ShowStoredBill($_GET['billpdf']);
     76    } else
     77    if(array_key_exists('billpdf2', $_GET))
     78    {
     79      $Output .= $this->System->Modules['Bill']->ShowGeneratedBill($_GET['billpdf2']);
     80    } else
     81    if(array_key_exists('regenerate', $_GET))
     82    {
     83      $Output .= $this->System->Modules['Bill']->RegeneratePDF($_GET['regenerate']);
     84    } else
     85    if(array_key_exists('bill', $_GET))
     86    {
     87      $Output .= $this->System->Modules['Bill']->GenerateBill($_GET['bill']);
     88    } else
     89    if(array_key_exists('generate', $_GET))
     90    {
     91      $Output .= $this->System->Modules['Bill']->CreateBill(1, array(array('description' => 'Poplatek za připojení k síti', 'price' => 1000, 'quantity' => 1)), time(), time());
     92    } else
     93    {
     94      //ShowHeader('Faktury', 'Faktury');
     95      $Output .= 'Faktury:<br />';
     96      $DbResult = $this->Database->select('users', '*, CONCAT(second_name," ", first_name)  as fullname', '1 ORDER BY fullname');
     97      while($User = $DbResult->fetch_array())
     98      {
     99        $Output .= '<a href="?Operation=Bills&amp;user='.$User['id'].'">'.$User['fullname'].'</a><br />';
     100      }
     101      //ShowFooter();
     102    }
     103    return($Output);
     104  }
     105
     106  function CheckAdvancesAndLiabilities($Subject)
     107  {
     108    global $LastInsertTime;
     109
     110    do {
     111      $DbResult = $this->Database->select('FinanceAdvances', 'SUM(Value)', 'Subject='.$Subject.' AND Direction = "In"');
     112      $DbRow = $DbResult->fetch_array();
     113      $Advances = $DbRow[0];
     114      $DbResult = $this->Database->select('FinanceClaimsLiabilities', '*', 'Subject='.$Subject.' AND TimePayment IS NULL AND Value > 0 ORDER BY TimeCreation LIMIT 1');
     115      //echo($Database->error);
     116      if($DbResult->num_rows > 0)
     117      {
     118        $OpenedClaim = $DbResult->fetch_array();
     119        if($Advances > $OpenedClaim['Value'])
     120        {
     121          $this->Database->update('FinanceClaimsLiabilities', 'Id='.$OpenedClaim['Id'], array('TimePayment' => TimeToMysqlDateTime($LastInsertTime)));
     122          $this->Database->insert('FinanceAdvances', array('Subject' => $OpenedClaim['Subject'], 'Value' => -$OpenedClaim['Value'], 'TimeCreation' => TimeToMysqlDateTime($LastInsertTime), 'CashFlowId' => $OpenedClaim['Id'], 'Direction' => 'In'));
     123          //echo($Database->LastQuery);
     124        } else break;
    43125      } else break;
    44     } else break;
    45   } while(($Advances > $OpenedClaim['Value']));
    46 }
    47 
    48 function InsertLiability($Subject, $Value, $Time, $BillId, $Text, $TimePayment = '')
    49 {
    50   global $Database, $LastInsertTime;
    51   if($TimePayment != '') $TimePayment = TimeToMysqlDateTime($TimePayment);
    52   $Database->insert('FinanceClaimsLiabilities', array('Text' => $Text, 'Subject' => $Subject, 'TimeCreation' => TimeToMysqlDateTime($Time), 'TimeDue' => TimeToMysqlDateTime($Time + 3600*24*15), 'TimePayment' => $TimePayment, 'Value' => $Value, 'Bill' => $BillId));
    53   echo($Database->LastQuery.'<br>');
    54   $LastInsertTime = $Time;
    55   CheckAdvancesAndLiabilities($Subject);
    56 }
    57 
    58 function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text)
    59 {
    60   global $Database, $LastInsertTime;
    61   $Database->insert('FinanceCashFlow', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable));
    62   if($Value >= 0)
    63   {
    64     $Database->insert('FinanceAdvances', array('Subject' => $Subject, 'Value' => $Value, 'TimeCreation' => TimeToMysqlDateTime($Time), 'CashFlowId' => $Database->insert_id, 'Direction' => 'In'));
    65   }
    66   $LastInsertTime = $Time;
    67   CheckAdvancesAndLiabilities($Subject);
    68 }
    69 
    70 function ShowNewPaymentForm()
    71 {
    72   global $Database;
    73   $Values = array();
    74   $Output = '<form action="?Operation=NewPaymentInsert" method="post">'.ShowEditTable('NewPayment', $Values);
    75   $Output .= '<input type="submit" value="Vložit"></form>';
    76   return($Output);
    77 }
    78 
    79 function ShowNewPaymentInsert()
    80 {
    81   global $Database;
    82   $Values = LoadSubmitedData('NewPayment');
    83   InsertMoney($Values['Subject'], $Values['Value'], $Values['Cash'], $Value['Taxable'], $Values['Text'], time());
    84   echo('Nová platba vložena');
    85   //echo(phpinfo());
    86 }
    87 
    88 function ShowNewInvoiceForm()
    89 {
    90   global $Database;
    91   $Values = array();
    92   $Output = '<form action="?Operation=NewInvoiceInsert" method="post">'.ShowEditTable('NewInvoice', $Values);
    93   $Output .= '<input type="submit" value="Vložit"></form>';
    94   return($Output);
    95 }
    96 
    97 function ImportOldData()
    98 {
    99   global $Database, $InvoiceGenerator;
    100 
    101   $Database->query('TRUNCATE TABLE FinanceCashFlow');
    102   $Database->query('TRUNCATE TABLE FinanceClaimsLiabilities');
    103   $Database->query('TRUNCATE TABLE FinanceAdvances');
    104   $Database->query('TRUNCATE TABLE FinanceSmallAssets');
    105 
    106   // Move time of device price transformation
    107   $Database->query('UPDATE finance_operations SET date="2007-11-30" WHERE comment = "Jednorázový poplatek za společné zařízení"');
    108 
    109   // Transfer finance before era
    110   $DbResult = $Database->query('SELECT * FROM users WHERE role=2');
    111   while($User = $DbResult->fetch_array())
    112   {
    113     $DbResult2 = $Database->query('SELECT SUM(money) FROM finance_operations WHERE user='.$User['id'].' AND date < "2007-12-01"');
    114     $Row = $DbResult2->fetch_array();
    115     $TotalAdvance = $Row[0];
    116     //echo($User['second_name'].' '.$User['first_name'].' '.$TotalAdvance.'<br>');
    117     // Záloha
    118     if($TotalAdvance > 0)
    119     {
    120       InsertMoney($User['id'], $TotalAdvance, 0, 1, mktime(0, 0, 0, 12, 1, 2007), 'Přijatá záloha (z období před daňovou evidencí)');
    121     }
    122     // Dluh
    123     if($TotalAdvance < 0)
    124     { 
    125       InsertLiability($User['id'], (-$Row[0]), mktime(0, 0, 0, 12, 1, 2007), 0, 'Připojení k síti (z období před daňovou evidencí)');
    126       //echo($Database->LastQuery.'<br>');
    127     }
    128   } 
    129 
    130   // Transfer finance after era
    131 //  $DbResult = $Database->query('SELECT * FROM users WHERE role=2');
    132 //  while($User = $DbResult->fetch_array())
    133 //  {
    134     $DbResult2 = $Database->query('SELECT finance_operations.*, users.role as role FROM finance_operations JOIN users ON users.id = finance_operations.user WHERE finance_operations.date >= "2007-12-01"');
     126    } while(($Advances > $OpenedClaim['Value']));
     127  }
     128
     129  function InsertLiability($Subject, $Value, $Time, $BillId, $Text, $TimePayment = '')
     130  {
     131    global $LastInsertTime;
     132
     133    if($TimePayment != '') $TimePayment = TimeToMysqlDateTime($TimePayment);
     134    $this->Database->insert('FinanceClaimsLiabilities', array('Text' => $Text, 'Subject' => $Subject, 'TimeCreation' => TimeToMysqlDateTime($Time), 'TimeDue' => TimeToMysqlDateTime($Time + 3600*24*15), 'TimePayment' => $TimePayment, 'Value' => $Value, 'Bill' => $BillId));
     135    $Output = $this->Database->LastQuery.'<br />';
     136    $LastInsertTime = $Time;
     137    $this->CheckAdvancesAndLiabilities($Subject);
     138    return($Output);
     139  }
     140
     141  function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text)
     142  {
     143    global $LastInsertTime;
     144
     145    $this->Database->insert('FinanceCashFlow', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable));
     146    if($Value >= 0)
     147    {
     148      $this->Database->insert('FinanceAdvances', array('Subject' => $Subject, 'Value' => $Value, 'TimeCreation' => TimeToMysqlDateTime($Time), 'CashFlowId' => $this->Database->insert_id, 'Direction' => 'In'));
     149    }
     150    $LastInsertTime = $Time;
     151    $this->CheckAdvancesAndLiabilities($Subject);
     152  }
     153
     154  function ShowNewDeviceForm()
     155  {
     156    $Form = new Form('NewNetworkDevice');
     157    $Form->OnSubmit = '?Operation=NewDeviceInsert';
     158    $Output = $Form->ShowEditForm();
     159    return($Output);
     160  }
     161
     162  function ShowNewDeviceInsert()
     163  {
     164    $Form = new Form('NewNetworkDevice');
     165    $Form->LoadValuesFromForm();
     166    $Form->SaveValuesToDatabase(0);
     167    $Output = $this->SystemMessage('Finance', 'Zařízení vloženo.');
     168    $this->System->Modules['Log']->NewRecord('Finance', 'NewDeviceInserted');
     169    return($Output);
     170  }
     171
     172  function ShowNewDeviceHistoryForm()
     173  {
     174    $Form = new Form('NewNetworkDeviceHistory');
     175    $Form->OnSubmit = '?Operation=NewDeviceHistoryInsert';
     176    $Output = $Form->ShowEditForm();
     177    return($Output);
     178  }
     179
     180  function ShowNewDeviceHistoryInsert()
     181  {
     182    $Form = new Form('NewNetworkDeviceHistory');
     183    $Form->LoadValuesFromForm();
     184    $Form->SaveValuesToDatabase(0);
     185    $Output = $this->SystemMessage('Finance', 'Záznam historie zařízení vložen.');
     186    $this->System->Modules['Log']->NewRecord('Finance', 'NewDeviceHistoryInserted');
     187    return($Output);
     188  }
     189
     190  function ShowNewPaymentForm()
     191  {
     192    $Form = new Form('NewPayment');
     193    $Form->OnSubmit = '?Operation=NewPaymentInsert';
     194    $Output = $Form->ShowEditForm();
     195    return($Output);
     196  }
     197
     198  function ShowNewPaymentInsert()
     199  {
     200    $Form = new Form('NewPayment');
     201    $Form->LoadValuesFromForm();
     202    $this->InsertMoney($Form->Values['Subject'], $Form->Values['Value'], $Form->Values['Cash'], $Form->Values['Taxable'], $Form->Values['Time'], $Form->Values['Text']);
     203    $Output = $this->SystemMessage('Finance', 'Platba vložena.');
     204    $this->System->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
     205    return($Output);
     206  }
     207
     208  function ShowNewInvoiceForm()
     209  {
     210    $Form = new Form('NewInvoice');
     211    $Form->OnSubmit = '?Operation=NewInvoiceInsert';
     212    $Output = $Form->ShowEditForm();
     213    return($Output);
     214  }
     215
     216  function ShowNewInvoiceInsert()
     217  {
     218    $Form = new Form('NewInvoice');
     219    $Form->LoadvaluesFromForm();
     220    //print_r($Form->Values);
     221    //$this->InsertLiability($Form->Values['Subject'], $Form->Values['Value'], $Form->Values['Time'], $BillId, $Text, $TimePayment = '')
     222    $Output = $this->SystemMessage('Finance', 'Faktura vložena..');
     223    $this->System->Modules['Log']->NewRecord('Finance', 'NewInvoiceInserted');
     224    return($Output);
     225  }
     226
     227  function ImportOldData()
     228  {
     229    global $InvoiceGenerator;
     230
     231    $Output = '';
     232    $this->Database->query('TRUNCATE TABLE FinanceCashFlow');
     233    $this->Database->query('TRUNCATE TABLE FinanceClaimsLiabilities');
     234    $this->Database->query('TRUNCATE TABLE FinanceAdvances');
     235    $this->Database->query('TRUNCATE TABLE FinanceSmallAssets');
     236
     237    // Move time of device price transformation
     238    $this->Database->query('UPDATE finance_operations SET date="2007-11-30" WHERE comment = "Jednorázový poplatek za společné zařízení"');
     239
     240    // Transfer finance before era
     241    $DbResult = $this->Database->query('SELECT * FROM users WHERE role=2');
     242    while($User = $DbResult->fetch_array())
     243    {
     244      $DbResult2 = $this->Database->query('SELECT SUM(money) FROM finance_operations WHERE user='.$User['id'].' AND date < "2007-12-01"');
     245      $Row = $DbResult2->fetch_array();
     246      $TotalAdvance = $Row[0];
     247      //echo($User['second_name'].' '.$User['first_name'].' '.$TotalAdvance.'<br>');
     248      // Záloha
     249      if($TotalAdvance > 0)
     250      {
     251        $this->InsertMoney($User['id'], $TotalAdvance, 0, 1, mktime(0, 0, 0, 12, 1, 2007), 'Přijatá záloha (z období před daňovou evidencí)');
     252      }
     253      // Dluh
     254      if($TotalAdvance < 0)
     255      {
     256        $this->InsertLiability($User['id'], (-$Row[0]), mktime(0, 0, 0, 12, 1, 2007), 0, 'Připojení k síti (z období před daňovou evidencí)');
     257        //echo($Database->LastQuery.'<br>');
     258      }
     259    }
     260
     261    // Transfer finance after era
     262    //  $DbResult = $Database->query('SELECT * FROM users WHERE role=2');
     263    //  while($User = $DbResult->fetch_array())
     264    //  {
     265    $DbResult2 = $this->Database->query('SELECT finance_operations.*, users.role as role FROM finance_operations JOIN users ON users.id = finance_operations.user WHERE finance_operations.date >= "2007-12-01"');
    135266    while($Operation = $DbResult2->fetch_array())
    136267    {
     
    138269      if(substr($Operation['comment'], 0, 19) == 'Poplatek za měsíc')
    139270      {
    140         InsertLiability($Operation['user'], -$Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], 'Připojení k síti');
    141         echo($Operation['user'].' '.$Operation['money'].' Připojení k síti<br>');
     271        $this->InsertLiability($Operation['user'], -$Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], 'Připojení k síti');
     272        $Output .= $Operation['user'].' '.$Operation['money'].' Připojení k síti<br />';
    142273      } else
    143274      if($Operation['comment'] == 'Vklad')
    144275      {
    145         InsertMoney($Operation['user'], $Operation['money'], 0, 1, MysqlDateToTime($Operation['date']), 'Přijatá záloha');
     276        $this->InsertMoney($Operation['user'], $Operation['money'], 0, 1, MysqlDateToTime($Operation['date']), 'Přijatá záloha');
    146277        //echo($Operation['user'].' '.$Operation['money'].' Přijatá záloha<br>');
    147278      } else
    148279      if($Operation['comment'] == 'Internet')
    149280      {
    150         InsertLiability($Operation['user'], $Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], 'Měsíční paušál za Internet', MysqlDateToTime($Operation['date']));
    151         InsertMoney($Operation['user'], $Operation['money'], 0, 1, MysqlDateToTime($Operation['date']), 'Měsíční paušál za Internet');
     281        $this->InsertLiability($Operation['user'], $Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], 'Měsíční paušál za Internet', MysqlDateToTime($Operation['date']));
     282        $this->InsertMoney($Operation['user'], $Operation['money'], 0, 1, MysqlDateToTime($Operation['date']), 'Měsíční paušál za Internet');
    152283      } else
    153284      if($Operation['comment'] == 'Sociální pojištění')
    154285      {
    155         InsertLiability($Operation['user'], $Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], $Operation['comment'], MysqlDateToTime($Operation['date']));
    156         InsertMoney($Operation['user'], $Operation['money'], 0, 1, MysqlDateToTime($Operation['date']), $Operation['comment']);
     286        $this->InsertLiability($Operation['user'], $Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], $Operation['comment'], MysqlDateToTime($Operation['date']));
     287        $this->InsertMoney($Operation['user'], $Operation['money'], 0, 1, MysqlDateToTime($Operation['date']), $Operation['comment']);
    157288      } else
    158289      {
    159         $DbResult = $Database->query('SELECT role FROM users WHERE id='.$Operation['user']);
     290        $DbResult = $this->Database->query('SELECT role FROM users WHERE id='.$Operation['user']);
    160291        while($User = $DbResult->fetch_array())
    161        
    162         InsertLiability($Operation['user'], -$Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], $Operation['comment'], MysqlDateToTime($Operation['date']));
    163         echo($Operation['user'].' '.$Operation['comment'].' '.MysqlDateToTime($Operation['date']).'<br>');
     292        $this->InsertLiability($Operation['user'], -$Operation['money'], MysqlDateToTime($Operation['date']), $Operation['bill_id'], $Operation['comment'], MysqlDateToTime($Operation['date']));
     293        $Output .= $Operation['user'].' '.$Operation['comment'].' '.MysqlDateToTime($Operation['date']).'<br />';
    164294
    165295        if(($Operation['role'] == 2))
    166         { 
    167           echo('A');
    168           $Database->insert('FinanceAdvances', array('Subject' => $Operation['user'], 'Value' => $Operation['money'], 'TimeCreation' => MysqlDateToTime($Operation['date']), 'CashFlowId' => 0, 'Direction' => 'In'));
    169           CheckAdvancesAndLiabilities($Operation['user']);
     296        {
     297          $Output .= 'A';
     298          $this->Database->insert('FinanceAdvances', array('Subject' => $Operation['user'], 'Value' => $Operation['money'], 'TimeCreation' => MysqlDateToTime($Operation['date']), 'CashFlowId' => 0, 'Direction' => 'In'));
     299          $this->CheckAdvancesAndLiabilities($Operation['user']);
    170300        } else InsertMoney($Operation['user'], $Operation['money'], 0, 1, MysqlDateToTime($Operation['date']), $Operation['comment']);
    171301      }
    172302    }
    173 //  }
    174 
    175   // Import small asset
    176   $Subject = 1;
    177 
    178   // Převod pro minulý rok
    179   $Time = mktime(0, 0, 0, 12, 10, 2007);
    180   $DbResult = $Database->query('SELECT * FROM network_devices WHERE used <> 0 AND date < "'.TimeToMysqlDateTime($Time).'" AND (id <> 73)');
    181   $Items = array();
    182   $TotalPrice = 0;
    183   while($Device = $DbResult->fetch_array())
    184   {
    185     //$Database->insert('FinanceSmallAsset', array());
    186     $Items[] = array('description' => $Device['name'], 'quantity' => $Device['count'], 'price' => 0); //$Device['price']);
    187     $LastId = $Device['id'];
    188     $TotalPrice += $Device['price'] * $Device['count'];
    189     if($TotalPrice > 55000) break;
    190   }
    191   //print_r($Items);
    192   $BillId = $InvoiceGenerator->CreateBill($Subject, $Items, $Time, $Time);
    193   $DbResult = $Database->query('UPDATE network_devices SET TimeEnlistment = "'.TimeToMysqlDateTime($Time).'" WHERE used <> 0 AND date < "'.TimeToMysqlDateTime($Time).'" AND (id <> 73) AND (id <= '.$LastId.')');
    194   //echo($Database->error);
    195   InsertLiability($Subject, 0, $Time, $BillId, 'Nákup infrastruktury', $Time);
    196   //InsertMoney($Subject, 0, 0, 1, $Time, 'Nákup infrastruktury');
    197 
    198   //echo($LastId);
    199 
    200   // Převod tento rok
    201   $Time = mktime(0, 0, 0, 1, 14, 2008);
    202   $DbResult = $Database->query('SELECT * FROM network_devices WHERE (used <> 0) AND (id > '.$LastId.') AND date < "'.TimeToMysqlDateTime($Time).'"');
    203   $Items = array();
    204   $TotalPrice = 0;
    205   while($Device = $DbResult->fetch_array())
    206   {
    207     //$Database->insert('FinanceSmallAsset', array());
    208     $Items[] = array('description' => $Device['name'], 'quantity' => $Device['count'], 'price' => 0); //$Device['price']);
    209     $TotalPrice += $Device['price'] * $Device['count'];
    210   }
    211   //print_r($Items);
    212   $BillId = $InvoiceGenerator->CreateBill($Subject, $Items, $Time, $Time);
    213   $DbResult = $Database->query('UPDATE network_devices SET TimeEnlistment = "'.TimeToMysqlDateTime($Time).'" WHERE used <> 0 AND date < "'.TimeToMysqlDateTime($Time).'" AND (id > '.$LastId.')');
    214   InsertLiability($Subject, 0, $Time, $BillId, 'Nákup infrastruktury', $Time);
    215   //InsertMoney($Subject, 0, 0, 1, $Time, 'Nákup infrastruktury');
    216 
    217 
    218   // Make absolute value in monthly overall 
    219   //$Database->query('UPDATE finance_monthly_overall SET total_paid = ABS(total_paid)');
    220   //$Database->query('UPDATE finance_monthly_overall SET member_count = (SELECT COUNT(*) FROM users WHERE users.role=2 AND users.membership_date < finance_monthly_overall.date)');
     303    //  }
     304
     305    // Import small asset
     306    $Subject = 1;
     307
     308    // Převod pro minulý rok
     309    $Time = mktime(0, 0, 0, 12, 10, 2007);
     310    $DbResult = $this->Database->query('SELECT * FROM network_devices WHERE used <> 0 AND date < "'.TimeToMysqlDateTime($Time).'" AND (id <> 73)');
     311    $Items = array();
     312    $TotalPrice = 0;
     313    while($Device = $DbResult->fetch_array())
     314    {
     315      //$Database->insert('FinanceSmallAsset', array());
     316      $Items[] = array('description' => $Device['name'], 'quantity' => $Device['count'], 'price' => 0); //$Device['price']);
     317      $LastId = $Device['id'];
     318      $TotalPrice += $Device['price'] * $Device['count'];
     319      if($TotalPrice > 55000) break;
     320    }
     321    //print_r($Items);
     322    $BillId = $InvoiceGenerator->CreateBill($Subject, $Items, $Time, $Time);
     323    $DbResult = $this->Database->query('UPDATE network_devices SET TimeEnlistment = "'.TimeToMysqlDateTime($Time).'" WHERE used <> 0 AND date < "'.TimeToMysqlDateTime($Time).'" AND (id <> 73) AND (id <= '.$LastId.')');
     324    //echo($Database->error);
     325    $this->InsertLiability($Subject, 0, $Time, $BillId, 'Nákup infrastruktury', $Time);
     326    //InsertMoney($Subject, 0, 0, 1, $Time, 'Nákup infrastruktury');
     327
     328    //echo($LastId);
     329
     330    // Převod tento rok
     331    $Time = mktime(0, 0, 0, 1, 14, 2008);
     332    $DbResult = $this->Database->query('SELECT * FROM network_devices WHERE (used <> 0) AND (id > '.$LastId.') AND date < "'.TimeToMysqlDateTime($Time).'"');
     333    $Items = array();
     334    $TotalPrice = 0;
     335    while($Device = $DbResult->fetch_array())
     336    {
     337      // $Database->insert('FinanceSmallAsset', array());
     338      $Items[] = array('description' => $Device['name'], 'quantity' => $Device['count'], 'price' => 0); //$Device['price']);
     339      $TotalPrice += $Device['price'] * $Device['count'];
     340    }
     341    //print_r($Items);
     342    $BillId = $InvoiceGenerator->CreateBill($Subject, $Items, $Time, $Time);
     343    $DbResult = $this->Database->query('UPDATE network_devices SET TimeEnlistment = "'.TimeToMysqlDateTime($Time).'" WHERE used <> 0 AND date < "'.TimeToMysqlDateTime($Time).'" AND (id > '.$LastId.')');
     344    $this->InsertLiability($Subject, 0, $Time, $BillId, 'Nákup infrastruktury', $Time);
     345    //InsertMoney($Subject, 0, 0, 1, $Time, 'Nákup infrastruktury');
     346
     347
     348    // Make absolute value in monthly overall 
     349    //$Database->query('UPDATE finance_monthly_overall SET total_paid = ABS(total_paid)');
     350    //$Database->query('UPDATE finance_monthly_overall SET member_count = (SELECT COUNT(*) FROM users WHERE users.role=2 AND users.membership_date < finance_monthly_overall.date)');
     351    return($Output);
     352  }
     353
     354  function ConvertPDFDataToFiles()
     355  {
     356    $DbResult = $this->Database->query('SELECT * FROM finance_bills');
     357    while($Bill = $DbResult->fetch_array())
     358    {
     359      file_put_contents('doklady/doklad_'.$Bill['id'].'.pdf', $Bill['pdf']);
     360      echo($Bill['id'].',');
     361    }
     362  }
     363
     364  function CheckPDFFiles()
     365  {
     366    global $Database, $InvoiceGenerator;
     367
     368    $DbResult = $this->Database->query('SELECT * FROM finance_bills');
     369    while($Bill = $DbResult->fetch_array())
     370    {
     371      file_put_contents('doklady2/doklad-'.$Bill['id'].'.pdf', file_get_contents('doklady/doklad-'.$Bill['id'].'.pdf'));
     372      //echo($InvoiceGenerator->HasPDFFile($Bill['id']).',');
     373    }
     374  }
     375
    221376}
    222377
    223 function ConvertPDFDataToFiles()
    224 {
    225   global $Database;
    226   $DbResult = $Database->query('SELECT * FROM finance_bills');
    227   while($Bill = $DbResult->fetch_array())
    228   {
    229     file_put_contents('doklady/doklad-'.$Bill['id'].'.pdf', $Bill['pdf']);
    230     echo($Bill['id'].',');
    231   }
    232 
    233 }
    234 
    235 function CheckPDFFiles()
    236 {
    237   global $Database, $InvoiceGenerator;
    238 
    239   $DbResult = $Database->query('SELECT * FROM finance_bills');
    240   while($Bill = $DbResult->fetch_array())
    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   }
    245 
    246 }
    247 
    248 //ConvertPDFDataToFiles();
    249 
    250 //CheckPDFFiles();
    251 ImportOldData();
     378$System->AddModule(new FinanceManagePage());
     379$System->Modules['FinanceManagePage']->GetOutput();
    252380
    253381?>
Note: See TracChangeset for help on using the changeset viewer.