Ignore:
Timestamp:
Jan 5, 2015, 10:01:40 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Added time designation for scheduled table change actions. This applies to tables Service, ServiceCustomerRel and FinanceCharge. Now time of taking effect is not determined just by customer pay period but by more generally by specified time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Finance/Manage.php

    r724 r726  
    5454      '(SELECT GROUP_CONCAT(`Service`.`Name`) FROM `ServiceCustomerRel` LEFT JOIN `Service` '.
    5555      'ON `Service`.`Id`=`ServiceCustomerRel`.`Service` WHERE `ServiceCustomerRel`.`Customer`=`Member`.`Id` AND '.
    56       '`ServiceCustomerRel`.`Action` IS NULL) AS `ServicesNextMonth`, '.
     56      '`ServiceCustomerRel`.`ChangeAction` IS NULL) AS `ServicesNextMonth`, '.
    5757      'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`) AS `LastDate`, `Subject`.`Name` AS `SubjectName`, '.
    5858      '`FinanceBillingPeriod`.`Name` AS `BillingPeriodName` '.
     
    156156          'ON `Service`.`Id`=`ServiceCustomerRel`.`Service` '.
    157157          'WHERE (`ServiceCustomerRel`.`Customer`='.
    158           $Member['Id'].') AND (`ServiceCustomerRel`.`Action` IS NULL) ');
     158          $Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL) ');
    159159        while($Service = $DbResult2->fetch_assoc())
    160160        {
     
    192192  }
    193193
    194   function TableUpdatePeriod($Table)
    195   {
    196     $DbResult = $this->Database->select($Table, '*', '`Action` IS NOT NULL');
     194  function TableUpdateChanges($Table)
     195  {
     196        $Time = time();
     197    $DbResult = $this->Database->select($Table, '*', '(`ChangeAction` IS NOT NULL) AND '.
     198        '(`ChangeTime` <= "'.TimeToMysqlDateTime($Time).'") ORDER BY `ChangeTime` ASC');
    197199    while($Service = $DbResult->fetch_array())
    198200    {
    199       if($Service['Action'] == 'add')
     201      if($Service['ChangeAction'] == 'add')
    200202      {
    201203        unset($Service['Id']);
    202         unset($Service['ReplaceId']);
    203         unset($Service['Action']);
     204        unset($Service['ChangeReplaceId']);
     205        unset($Service['ChangeAction']);
    204206        $this->Database->insert($Table, $Service);
    205207      } else
    206       if($Service['Action'] == 'modify')
     208      if($Service['ChangeAction'] == 'modify')
    207209      {
    208210        unset($Service['Id']);
    209         unset($Service['Action']);
    210         $ReplaceId = $Service['ReplaceId'];
    211         unset($Service['ReplaceId']);
     211        unset($Service['ChangeAction']);
     212        $ReplaceId = $Service['ChangeReplaceId'];
     213        unset($Service['ChangeReplaceId']);
    212214        $this->Database->update($Table, 'Id='.$ReplaceId, $Service);
    213215      } else
    214       if($Service['Action'] == 'delete')
     216      if($Service['ChangeAction'] == 'delete')
    215217      {
    216218        $this->Database->delete($Table, '`Id`='.$Service['ReplaceId']);
    217219      }
    218220    }
    219     $this->Database->delete($Table, '`Action` IS NOT NULL');
    220   }
    221 
     221    $this->Database->delete($Table, '(`ChangeAction` IS NOT NULL) AND (`ChangeTime` <= "'.TimeToMysqlDateTime($Time).'")');
     222  }
     223
     224  function ProcessTableUpdates()
     225  {
     226        // Update finance charge
     227        $Output = 'Měním aktuální parametry sítě...<br>';
     228        $this->TableUpdateChanges('FinanceCharge');
     229       
     230        // Update services
     231        $Output .= 'Aktualizuji služby....<br>';
     232        $this->TableUpdateChanges('Service');
     233       
     234        // Update customer service selections
     235        $Output .= 'Aktualizuji výběr služeb zákazníků....<br>';
     236        $this->TableUpdateChanges('ServiceCustomerRel');
     237
     238        return($Output);
     239  }
     240 
    222241  function ProcessMonthlyPayment()
    223242  {
     
    225244    $Output = '';
    226245
     246    $Output .= $this->ProcessTableUpdates();
     247   
    227248    $Finance = &$this->System->Modules['Finance'];
    228249    $Finance->LoadMonthParameters(0);
    229250
    230251    // Načti poslední měsíční přehled a nastavení
    231     $DbResult = $this->Database->select('FinanceMonthlyOverall', '*', '1 ORDER BY Date DESC LIMIT 1');
     252    $DbResult = $this->Database->select('FinanceMonthlyOverall', '*', '1 ORDER BY `Date` DESC LIMIT 1');
    232253    $Overall = $DbResult->fetch_array();
    233254
    234     $Output -= 'Datum: '.date('j.n.Y').'<br />';
     255    $Output .= 'Datum: '.date('j.n.Y').'<br />';
    235256
    236257    $DateParts = explode('-', $Overall['Date']);
     
    240261    $Output .= $Finance->RecalculateMemberPayment();
    241262
    242     $DbResult = $this->Database->query('SELECT SUM(NetworkDevice) FROM MemberPayment');
    243     $Row = $DbResult->fetch_row();
    244     $TotalMemberDeviceCost = $Row[0];
    245     $Output .= '), Členové('.$TotalMemberDeviceCost.')<br />';
    246 
    247     $DbResult = $this->Database->query('SELECT SUM(Cash) FROM MemberPayment');
     263    $DbResult = $this->Database->query('SELECT SUM(`Cash`) FROM `MemberPayment`');
    248264    $Row = $DbResult->fetch_row();
    249265    $TotalMemberCash = $Row[0];
    250266    $Output .= 'Stav pokladny: Členové('.$TotalMemberCash.')';
    251267
    252     $DbResult = $this->Database->query('SELECT SUM(Product.Consumption) AS Consumption FROM StockSerialNumber '.
    253       'JOIN Product ON StockSerialNumber.Product = Product.Id WHERE (StockSerialNumber.TimeElimination IS NULL) '.
    254         'AND (StockSerialNumber.Segment IS NOT NULL)');
     268    $DbResult = $this->Database->query('SELECT SUM(`Product`.`Consumption`) AS `Consumption` FROM `StockSerialNumber` '.
     269      'JOIN `Product` ON `StockSerialNumber`.`Product` = `Product`.`Id` WHERE (`StockSerialNumber`.`TimeElimination` IS NULL) ');
    255270    $Row = $DbResult->fetch_row();
    256271    $TotalConsumption = $Row[0];
     
    266281      $Output .= 'Odečítám měsíční poplatek...<br />';
    267282      $Output .= $this->ProduceInvoices();
    268 
    269       // Update finance charge
    270       $Output .= 'Měním aktuální parametry sítě...<br>';
    271       $this->TableUpdatePeriod('FinanceCharge');
    272 
     283     
    273284      $Output .= 'Přidávám měsíční přehled...<br />';
    274       $DbResult = $this->Database->query('SELECT * FROM FinanceCharge WHERE Action IS NULL LIMIT 1');
     285      $DbResult = $this->Database->query('SELECT * FROM `FinanceCharge` WHERE (`ChangeAction` IS NULL) LIMIT 1');
    275286      $Charge = $DbResult->fetch_assoc();
    276287      $this->Database->insert('FinanceMonthlyOverall', array('Date' => 'NOW()',
     
    281292        'TopTariffPrice' => $Charge['TopTariffPrice'], 'MemberCount' => $Finance->InternetUsers));
    282293
    283       // Update services
    284       $Output .= 'Aktualizuji služby....<br>';
    285       $this->TableUpdatePeriod('Service');
    286      
    287       // Update customer service selections
    288       $Output .= 'Aktualizuji výběr služeb zákazníků....<br>';
    289       $this->TableUpdatePeriod('ServiceCustomerRel');
    290 
    291294      $Finance->RecalculateMemberPayment();
    292295      //CreateMonthlyOverallBill();
     
    335338      $DbResult = $this->Database->query('SELECT GROUP_CONCAT(Service.Name) AS Name FROM ServiceCustomerRel LEFT JOIN Service '.
    336339        'ON Service.Id=ServiceCustomerRel.Service WHERE (ServiceCustomerRel.Customer='.$Member['Id'].') '.
    337         'AND ServiceCustomerRel.Action IS NULL');
     340        'AND ServiceCustomerRel.ChangeAction IS NULL');
    338341      $Service = $DbResult->fetch_assoc();
    339342      $Content .= '<strong>'.$Service['Name'].'</strong><br />'."\n".
Note: See TracChangeset for help on using the changeset viewer.