Changeset 4 for www/finance/prepocet.php


Ignore:
Timestamp:
Jan 14, 2008, 9:48:39 PM (17 years ago)
Author:
george
Message:

Upraveno: Změna přístupu k databázi na třídu rozšířenou mysqli.
Upraveno: Sjednocení
Upraveno: Změna kódování všech stránek na UTF-8.
Odstraňeno: Staré nepotřebné soubory.

Location:
www
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • www

    • Property svn:ignore set to
      config.php
      php_script_error.log
  • www/finance/prepocet.php

    r1 r4  
    1 <?
    2 include('../db.php');
    3 include('../is/error.php');
    4 DB_Init('localhost','root','','is');
    5 DB_Query('SET CHARACTER SET latin2');
     1<?php
     2include('../global.php');
    63include('include.php');
    74
     
    107  global $InternetSegmentId, $Tarify, $Sprava;
    118
    12   DB_Query("SELECT * FROM users WHERE role=0");  // Select network members only
    13   while($Row = DB_Row())
     9  $DbResult = $Database->query("SELECT * FROM users WHERE role=0");  // Select network members only
     10  while($Row = $DbResult->fetch_array())
    1411  {
    15     DB_Save();
    16     DB_Query("SELECT SUM(money) FROM finance_operations WHERE user=".$Row['id']);  // Account state
    17     $Row3 = DB_Row();
    18     DB_Query("SELECT SUM(consumption) FROM network_devices WHERE user=".$Row['id']." AND used=1");
    19     $Row4 = DB_Row();
     12    $DbResult2 = $Database->query("SELECT SUM(money) FROM finance_operations WHERE user=".$Row['id']);  // Account state
     13    $Row3 = $DbResult2->fetch_array();
     14    $DbResult2 = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE user=".$Row['id']." AND used=1");
     15    $Row4 = $DbResult2->fetch_array();
    2016    //DB_Update('users','id='.$Row['id'], array());
    2117
     
    2521    while($ID != 0)
    2622    {
    27       DB_Query("SELECT * FROM network_segments WHERE id=".$ID);
    28       $Row2 = DB_Row();
     23      $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID);
     24      $Row2 = $DbResult2->fetch_array();
    2925      if(!(($Row['inet_hw'] == 0) and ($ID == $InternetSegmentId)))
    3026      {
     
    4238    $Monthly = round($Monthly);
    4339    //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>');
    44     DB_Update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => W2Kc($Consumption), 'cash' => ($Row3[0]-$Row['network_device']), 'plus' => W2Kc($Row4[0])));
    45     DB_Load();
     40    $Database->update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => W2Kc($Consumption), 'cash' => ($Row3[0]-$Row['network_device']), 'plus' => W2Kc($Row4[0])));
    4641  }
    4742}
    4843
    4944
    50 DB_Select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1');
    51 $Overall = DB_Row();
     45$DbResult = $Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1');
     46$Overall = $DbResult->fetch_array();
    5247
    5348echo('Datum: '.date('j.n.Y')."\n");
    54 $Mesice = array('','Leden','Únor','Bøezen','Duben','Kvìten','Èerven','Èervenec','Srpen','Záøí','Øíjen','Listopad','Prosinec');
     49$Mesice = array('','Leden','Únor','Březen','Duben','Květen','Červen','Červenec','Srpen','Září','Říjen','Listopad','Prosinec');
    5550$Datum = explode('-', $Overall['date']);
    5651$Mesic = date("m")+0;
    5752
    58 // Spoèítat ceny segmentù
     53// Spočítat ceny segmentů
    5954echo("Prepocitavam ceny");
    60 DB_Query("UPDATE network_segments SET users=0");  // Vynulovat poèty poèítaèù
    61 DB_Query("UPDATE network_segments SET users_overheads=0");  // Vynulovat poèty poèítaèù
    62 DB_Query("SELECT * FROM network_segments");
    63 while($Row = DB_Row())
     55$Database->query("UPDATE network_segments SET users=0");  // Vynulovat počty počítačů
     56$Database->query("UPDATE network_segments SET users_overheads=0");  // Vynulovat počty počítačů
     57$DbResult = $Database->query("SELECT * FROM network_segments");
     58while($Row = $DbResult->fetch_array())
    6459{
    6560  //echo('Segment '.$Row['name'].'<br>');
    66   DB_Save();
    67   DB_Query("SELECT users FROM network_segments WHERE id=".$Row['id']);
    68   $RowP = DB_Row();
    69   DB_Query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']);
    70   $RowP2 = DB_Row();
    71   DB_Query("SELECT SUM(price),SUM(consumption) FROM network_devices WHERE segment=".$Row['id']." AND used=1");
    72   $Row2 = DB_Row();
    73   DB_Query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1');
    74   $Row3 = DB_Row();
    75   DB_Query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1');
    76   $Row5 = DB_Row();
     61  $DbResult2 = $Database->query("SELECT users FROM network_segments WHERE id=".$Row['id']);
     62  $RowP = $DbResult2->fetch_array();
     63  $DbResult2 = $Database->query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']);
     64  $RowP2 = $DbResult2->fetch_array();
     65  $DbResult2 = $Database->query("SELECT SUM(price),SUM(consumption) FROM network_devices WHERE segment=".$Row['id']." AND used=1");
     66  $Row2 = $DbResult2->fetch_array();
     67  $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1');
     68  $Row3 = $DbResult2->fetch_array();
     69  $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1');
     70  $Row5 = $DbResult2->fetch_array();
    7771  $ID = $Row['parent'];
    78   while($ID!=0)
     72  while($ID != 0)
    7973  {
    8074    //echo($ID.', ');
    81     DB_Query("SELECT * FROM network_segments WHERE id=".$ID);
    82     $Row4 = DB_Row();
    83     DB_Update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users']+$Row3[0]), 'users_overheads' => ($Row4['users_overheads']+$Row5[0])));
     75    $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID);
     76    $Row4 = $DbResult2->fetch_array();
     77    $Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users']+$Row3[0]), 'users_overheads' => ($Row4['users_overheads']+$Row5[0])));
    8478    $ID = $Row4['parent'];
    8579  }
    8680  //echo('Pocet '.$Row3[0].','.$Row['hosts'].'<br>');
    87   DB_Update('network_segments','id='.$Row['id'],array('price' => $Row2[0], 'users' => ($Row3[0]+$RowP['users']), 'consumption' => $Row2[1], 'users_overheads' => ($Row5[0]+$RowP2['users_overheads'])));
    88   DB_Load();
     81  $Database->update('network_segments','id='.$Row['id'],array('price' => $Row2[0], 'users' => ($Row3[0]+$RowP['users']), 'consumption' => $Row2[1], 'users_overheads' => ($Row5[0]+$RowP2['users_overheads'])));
    8982}
    9083
    9184// Zkorigovat segment Internet
    92 DB_Select('users', 'COUNT(*)', 'inet_hw=1');
    93 $Row = DB_Row();
    94 DB_Select('users', 'COUNT(*)', 'inet=1');
    95 $Row2 = DB_Row();
    96 DB_Update('network_segments','id='.$InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0]));
     85$DbResult = $Database->select('users', 'COUNT(*)', 'inet_hw=1');
     86$Row = $DbResult->fetch_array();
     87$DbResult = $Database->select('users', 'COUNT(*)', 'inet=1');
     88$Row2 = $DbResult->fetch_array();
     89$DbResult = $Database->update('network_segments','id='.$InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0]));
    9790
    9891RecalculateTariffs();
     
    10396
    10497// Celkovy prehled
    105 DB_Query("SELECT SUM(price) FROM network_devices WHERE used=1");
    106 $Row4 = DB_Row();
    107 echo("Celkova cena zaøízení: Zaøízení(".$Row4[0]);
    108 DB_Query("SELECT SUM(price) FROM network_segments");
    109 $Row = DB_Row();
     98$DbResult = $Database->query("SELECT SUM(price) FROM network_devices WHERE used=1");
     99$Row4 = $DbResult->fetch_array();
     100echo("Celkova cena zařízení: Zařízení(".$Row4[0]);
     101$DbResult = $Database->query("SELECT SUM(price) FROM network_segments");
     102$Row = $DbResult->fetch_array();
    110103echo("), Segmenty(".$Row[0]);
    111 DB_Query("SELECT SUM(network_device) FROM users");
    112 $Row5 = DB_Row();
    113 echo("), U¾ivatelé(".$Row5[0].")\n");
    114 DB_Query("SELECT SUM(cash) FROM users WHERE role=0");
    115 $Row6 = DB_Row();
    116 echo("Stav pokladny: U¾ivatelé(".$Row6[0].")");
    117 DB_Query("SELECT SUM(money) FROM finance_operations");
    118 $Row = DB_Row();
    119 DB_Query("SELECT SUM(price) FROM network_devices WHERE used=1");
    120 $Row2 = DB_Row();
    121 echo(", Operace-Zaøízení(".($Row[0]-$Row2[0]).")<br>\n");
     104$DbResult = $Database->query("SELECT SUM(network_device) FROM users");
     105$Row5 = $DbResult->fetch_array();
     106echo("), Uľivatelé(".$Row5[0].")\n");
     107$DbResult = $Database->query("SELECT SUM(cash) FROM users WHERE role=0");
     108$Row6 = $DbResult->fetch_array();
     109echo("Stav pokladny: Uľivatelé(".$Row6[0].")");
     110$DbResult = $Database->query("SELECT SUM(money) FROM finance_operations");
     111$Row = $DbResult->fetch_array();
     112$DbResult = $Database->query("SELECT SUM(price) FROM network_devices WHERE used=1");
     113$Row2 = $DbResult->fetch_array();
     114echo(", Operace-Zařízení(".($Row[0]-$Row2[0]).")<br>\n");
    122115
    123 DB_Query("SELECT SUM(money) FROM finance_operations");
     116$DbResult = $Database->query("SELECT SUM(money) FROM finance_operations");
    124117$Row3 = DB_Row();
    125 echo("Rozdíl penìz v operacích: ".($Row3[0]-$Row6[0] - $Row4[0])." <br>\n");
     118echo("Rozdíl peněz v operacích: ".($Row3[0]-$Row6[0] - $Row4[0])." <br>\n");
    126119
    127120
    128 DB_Query("SELECT SUM(consumption) FROM network_devices WHERE used=1");
    129 $Row = DB_Row();
     121$DbResult = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1");
     122$Row = $DbResult->fetch_array();
    130123$CelkemSpotreba = W2Kc($Row[0]);
    131124
    132 DB_Query("SELECT SUM(plus-monthly) FROM users WHERE role=0");
    133 $Row = DB_Row();
     125$DbResult = $Database->query("SELECT SUM(plus-monthly) FROM users WHERE role=0");
     126$Row = $DbResult->fetch_array();
    134127$CelkemZaplaceno = $Row[0];
    135128$SpravaCelkem = $Sprava*$SpravaUsers;
    136129echo("Kontrola placení (Zaplaceno-Sprava-Internet): ".(-$CelkemZaplaceno)."-".$SpravaCelkem."-".$Internet."=".(-$CelkemZaplaceno-$SpravaCelkem-$Internet)."<br>\n\n");
    137130
    138 // Zkontrolovat odeètení mìsíèního poplatku
     131// Zkontrolovat odečtení měsíčního poplatku
    139132//$Mesic = '1';
    140 echo('Kontrola odeètení poplatkù: Poslední mìsíc-'.round($Datum[1]).' Aktuální mìsíc-'.$Mesic."<br>\n");
     133echo('Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic."<br>\n");
    141134if($Mesic != $Datum[1])
    142135{
    143   echo("Odeèítám mìsíèní poplatek: ");
     136  echo("Odečítám měsíční poplatek: ");
    144137
    145   DB_Query("SELECT * FROM users WHERE role=0");
    146   while($Row = DB_Row())
     138  $DbResult = $Database->query("SELECT * FROM users WHERE role=0");
     139  while($Row = $DbResult->fetch_array())
    147140  {
    148141    echo($Row['fullname'].': '.($Row['plus']-$Row['monthly']).'<br>');
    149     DB_Save();
    150     DB_Insert('finance_operations',array('money' => $Row['plus']-$Row['monthly'], 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatek za mìsíc '.$Mesice[$Mesic]));
    151     DB_Load();
     142    $Database->insert('finance_operations',array('money' => $Row['plus']-$Row['monthly'], 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatek za měsíc '.$Mesice[$Mesic]));
    152143  }
    153   DB_Insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Internet, 'kWh' => $kWh, 'administration' => $Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $CelkemZaplaceno));
     144  $Database->insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Internet, 'kWh' => $kWh, 'administration' => $Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $CelkemZaplaceno));
    154145
    155146  echo('Menim aktualni parametry site.');
    156147
    157148  // Update finance charge
    158   DB_Delete('finance_charge', 'period=0');
    159   DB_Select('finance_charge', '*', 'period=1');
    160   $Charge = DB_Row();
     149  $Database->delete('finance_charge', 'period=0');
     150  $DbResult = $Database->select('finance_charge', '*', 'period=1');
     151  $Charge = $DbResult->fetch_array();
    161152  //print_r($Charge);
    162   DB_Insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'],
     153  $DbResult = $Database->insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'],
    163154    'internet_speed' => $Charge['internet_speed'], 'internet_speed_reserve' => $Charge['internet_speed_reserve'],
    164155    'administration_per_user' => $Charge['administration_per_user'], 'kWh' => $Charge['kWh']));
     
    168159
    169160  // Update tarrifs
    170   DB_Delete('finance_tariffs', 'period=0');
    171   DB_Select('finance_tariffs', '*', 'period=1');
    172   while($Tariff = DB_Row())
     161  $Database->delete('finance_tariffs', 'period=0');
     162  $DbResult = $Database->elect('finance_tariffs', '*', 'period=1');
     163  while($Tariff = $DbResult->fetch_array())
    173164  {
    174     DB_Save();
    175     DB_Insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'],
     165    $Database->insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'],
    176166      'speed_factor' => $Tariff['speed_factor'], 'price_units' => $Tariff['price_units']));
    177     DB_Load();
    178167  }
    179168 
     
    181170
    182171  // Update tariff user selection
    183   DB_Query("SELECT id,inet_tarif_next FROM users WHERE role=0");
    184   while($User = DB_Row())
     172  $DbResult = $Database->query("SELECT id,inet_tarif_next FROM users WHERE role=0");
     173  while($User = $DbResult->fetch_array())
    185174  {
    186     DB_Save();
    187     DB_Update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next']));
    188     DB_Load();
     175    $Database->update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next']));
    189176  }
    190177
     
    193180 
    194181  // Restart traffic shaping
    195   DB_Update('services_restart', 'id=3', array('changed' => 1));
     182  $Database->update('services_restart', 'id=3', array('changed' => 1));
    196183}
    197184?>
Note: See TracChangeset for help on using the changeset viewer.