Ignore:
Timestamp:
Feb 5, 2013, 10:47:05 PM (12 years ago)
Author:
chronos
Message:
  • Opraveno: Přepočet měsíčních plateb.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/finance/finance.php

    r479 r481  
    3232  {
    3333    $this->Tariffs = array();
    34     $DbResult = $this->Database->select('Service', '*', 'ReplaceId IS NULL ORDER BY InternetSpeedMax');
     34    $DbResult = $this->Database->select('Service', '*', '`ReplaceId` IS NULL ORDER BY `InternetSpeedMax`');
    3535    while($Tariff = $DbResult->fetch_array())
    3636    {
     
    5252    foreach($this->Tariffs as $Index => $Tariff)
    5353    {
    54       $DbResult = $this->Database->query('SELECT COUNT(*) FROM Member '.
    55         'LEFT JOIN ServiceCustomerRel ON ServiceCustomerRel.Customer=Member.Id '.
    56         '(ServiceCustomerRel.Service='.$Index.') AND (Member.BillingPeriod > 1) AND (Member.Blocked=0)');
     54      $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member` '.
     55        'LEFT JOIN `ServiceCustomerRel` ON `ServiceCustomerRel`.`Customer`=`Member`.`Id` '.
     56        'WHERE (`ServiceCustomerRel`.`Service`='.$Index.') AND (`Member`.`BillingPeriod` > 1) AND (`Member`.`Blocked`=0)');
    5757      $Row = $DbResult->fetch_row();
    5858      $this->Tariffs[$Index]['CustomerCount'] = $Row[0];
     
    100100  function LoadMonthParameters($Period = 1) // 0 - now, 1 - next month
    101101  {   
    102     $DbResult = $this->Database->query('SELECT * FROM FinanceBillingPeriod');
     102    $DbResult = $this->Database->query('SELECT * FROM `FinanceBillingPeriod`');
    103103    while($BillingPeriod = $DbResult->fetch_assoc())
    104104      $this->BillingPeriods[$BillingPeriod['Id']] = $BillingPeriod;
    105105   
    106     $DbResult = $this->Database->query('SELECT * FROM FinanceCharge WHERE Period='.$Period);
     106    $DbResult = $this->Database->query('SELECT * FROM `FinanceCharge` WHERE `Period`='.$Period);
    107107    $Row = $DbResult->fetch_array();
    108108    $this->kWh = $Row['kWh'];
     
    116116    $this->BaseTariffPrice = $Row['BaseTariffPrice'];
    117117
    118     $DbResult = $this->Database->query('SELECT COUNT(*) FROM Member');
     118    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member`');
    119119    $Row = $DbResult->fetch_row();
    120120    $this->InternetUsers = $Row[0];
    121     $DbResult = $this->Database->query('SELECT COUNT(*) FROM Member WHERE (Blocked=0) AND (BillingPeriod > 1)');
     121    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member` WHERE (`Blocked`=0) AND (`BillingPeriod` > 1)');
    122122    $Row = $DbResult->fetch_row();
    123123    $this->PayingUsers = $Row[0];
     
    125125    $this->SpravaUsers = $this->PayingUsers;
    126126   
    127     $DbResult = $this->Database->query('SELECT SUM(Consumption) FROM NetworkSegment');
     127    $DbResult = $this->Database->query('SELECT SUM(`Consumption`) FROM `NetworkSegment`');
    128128    $TotalConsumption = $DbResult->fetch_array();
    129129    $this->TotalConsumption = $TotalConsumption[0];
    130130
    131     $DbResult = $this->Database->query('SELECT SUM(`MemberPayment`.`MonthlyInternet`) AS `MonthlyInternet`, SUM(`MemberPayment`.`MonthlyTotal`) AS `MonthlyTotal` '.
    132       'FROM MemberPayment JOIN Member ON Member.Id=MemberPayment.Member WHERE Member.Blocked=0');
     131    $DbResult = $this->Database->query('SELECT SUM(`MemberPayment`.`MonthlyInternet`) AS `MonthlyInternet`, '.
     132      'SUM(`MemberPayment`.`MonthlyTotal`) AS `MonthlyTotal` '.
     133      'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` WHERE `Member`.`Blocked`=0');
    133134    $Row = $DbResult->fetch_assoc();
    134135    $this->TotalInternetPaid = $Row['MonthlyInternet'];
     
    148149    {
    149150      // Get latest year
    150       $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY Year DESC LIMIT 1');
     151      $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY `Year` DESC LIMIT 1');
    151152    } else $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$FinanceYear);
    152153    $FinanceYear = $DbResult->fetch_assoc();
    153154   
    154     $DbResult = $this->Database->query('SELECT Shortcut, Id FROM DocumentLine WHERE Id='.$Id);
     155    $DbResult = $this->Database->query('SELECT `Shortcut`, `Id` FROM `DocumentLine` WHERE `Id`='.$Id);
    155156    $DocumentLine = $DbResult->fetch_assoc();
    156157   
    157     $DbResult = $this->Database->query('SELECT * FROM DocumentLineSequence WHERE DocumentLine='.$Id.' AND FinanceYear='.$FinanceYear['Id']);
     158    $DbResult = $this->Database->query('SELECT * FROM `DocumentLineSequence` WHERE '.
     159       '`DocumentLine`='.$Id.' AND `FinanceYear`='.$FinanceYear['Id']);
    158160    $Sequence = $DbResult->fetch_assoc();
    159161   
     
    163165    } else $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'];
    164166       
    165     $this->Database->query('UPDATE DocumentLineSequence SET NextNumber = NextNumber + 1 WHERE DocumentLine='.$Id.' AND FinanceYear='.$FinanceYear['Id']);
     167    $this->Database->query('UPDATE `DocumentLineSequence` SET `NextNumber` = `NextNumber` + 1 '.
     168       'WHERE `DocumentLine`='.$Id.' AND `FinanceYear`='.$FinanceYear['Id']);
    166169    return($Result);
    167170  }
     
    170173  {
    171174    $Output = 'Aktualizuji finance členů...<br />';
    172     $this->Database->query('TRUNCATE TABLE MemberPayment');
    173     $DbResult = $this->Database->query('SELECT * FROM Member');
     175    $this->Database->query('TRUNCATE TABLE `MemberPayment`');
     176    $DbResult = $this->Database->query('SELECT * FROM `Member`');
    174177    while($Member = $DbResult->fetch_assoc())
    175178    {
     
    199202      }
    200203   
     204      $DbResult2 = $this->Database->query('SELECT SUM(`Service`.`Price`) AS `Price` '.
     205         'FROM `ServiceCustomerRel` LEFT JOIN '.
     206         '`Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` WHERE `ServiceCustomerRel`.`Customer`='.
     207         $Member['Id'].' AND `ServiceCustomerRel`.`Period`=1');
     208      $DbRow = $DbResult2->fetch_assoc();     
    201209      $Monthly = 0;
    202       $MonthlyInet = $this->Tariffs[$Member['InternetTariffNextMonth']]['Price'];
     210      $MonthlyInet = $DbRow['Price'];
    203211      //if($Row['inet'] == 1)
    204212      $Monthly += $MonthlyInet;
Note: See TracChangeset for help on using the changeset viewer.