Ignore:
Timestamp:
Feb 5, 2013, 9:45:44 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Tabulka pro přiřazení více služeb jednomu zákazníkovi. Původní data jsou převedena do nové struktury. Tabulka Service je společná pro všechny typy služeb a pro každou službu se zobrazí nebo vyplní pouze určité použitelné sloupce.
  • Opraveno: Korekce názvů modulů na názvy začínající slovem Module.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/finance/manage.php

    r477 r479  
    355355        if($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)'])
    356356        {
    357           $this->Database->update('Member', 'Id='.$Member['Id'], array('BillingPeriod' => $Member['BillingPeriodNext'], 'InternetTariffCurrentMonth' => $Member['InternetTariffNextMonth']));
     357          $this->Database->update('Member', 'Id='.$Member['Id'],
     358            array('BillingPeriod' => $Member['BillingPeriodNext']));
    358359          $Member['BillingPeriod'] = $Member['BillingPeriodNext'];
    359           $Member['InternetTariffCurrentMonth'] = $Member['InternetTariffNextMonth'];
    360360        }
    361361        $Period = $this->GetBillingPeriod($Member['BillingPeriod']);
    362         $PayPerPeriod = $Member['MonthlyTotal'] * $Period['MonthCount'];
    363362        if(($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']) and ($Member['InternetTariffCurrentMonth'] != TARIFF_FREE) and ($PayPerPeriod > 0) and
    364363        ($Member['Blocked'] == 0))
    365364        {
    366           //echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' ');                 
     365          $BillItems = array();
     366          $MonthlyTotal = 0;
     367          $DbResult2 = $this->Database->query('(SELECT Service.* FROM ServiceCustomerRel LEFT JOIN Service '.
     368            'ON Service.Id=ServiceCustomerRel.Service WHERE ServiceCustomerRel.Customer='.$Member['Id'].') AND (ServiceCustomerRel.Period=0)');
     369          while($Service = $DbResult2->fetch_assoc())
     370          {
     371            $BillItems[] = array('Description' => $Service['Name'], 'Price' => $Service['Price'],
     372            'Quantity' => $Period['MonthCount']);
     373            $MonthlyTotal += $ServicePrice['Price'];
     374            $this->Database->update('ServiceCustomerRel', 'Id='); 
     375          }
     376          if($Member['Hire'] != 0)
     377          {
     378            $Output .= '<tr><td>Nájem</td><td>'.(-$Member['Hire']).'</td></tr>';
     379            $MonthlyTotal -= $Member['Hire'];
     380          }
     381          if($Member['MonthlyPlus'] != 0)
     382          {
     383            $MonthlyTotal -= $Member['MonthlyPlus'];
     384          }
     385          $PayPerPeriod = $MonthlyTotal * $Period['MonthCount'];
     386   
     387//echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' ');                 
    367388          $TimePeriodText = date('j.n.Y', $Period['From']).' - '.date('j.n.Y', $Period['To']);
    368           $Output .= $TimePeriodText.': '.$Member['MonthlyTotal'].' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />';
    369           $BillCode = $Finance->GetNextDocumentLineNumber(6); // Faktury vydané
     389          $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />';
     390          $BillCode = $Finance->GetNextDocumentLineNumber(INVOICE_OUT_DOC_LINE);
    370391          $BillId = $this->System->Modules['Bill']->CreateBill($Member['Subject'],
    371             array(array('Description' => 'Připojení k Internetu', 'Price' => $PayPerPeriod,
    372             'Quantity' => 1)), time(), time() + 3600 * 24 * 15, $BillCode, $Period['From'], $Period['To']);
     392            $BillItems, time(), time() + 3600 * 24 * INVOICE_DUE_DAYS, $BillCode, $Period['From'], $Period['To']);
    373393          $this->Database->insert('FinanceClaimsLiabilities', array('Value' => $PayPerPeriod,
    374394            'Subject' => $Member['Subject'], 'TimeCreation' => 'NOW()',
    375             'TimeDue' => 'DATE_ADD(NOW(), INTERVAL 15 DAY)',
    376             'Text' => 'Připojení k Internetu za období '.$TimePeriodText,
     395            'TimeDue' => 'DATE_ADD(NOW(), INTERVAL '.INVOICE_DUE_DAYS.' DAY)',
     396            'Text' => 'Vyúčtování služeb za období '.$TimePeriodText,
    377397            'Bill' => $BillId, 'BillCode' => $BillCode));
    378398          $Output .= $this->SendPaymentEmail($Member['Id']);
     
    392412      $this->Database->insert('FinanceMonthlyOverall', array('Date' => 'NOW()', 'Money' => $Finance->Internet, 'kWh' => $Finance->kWh, 'Administration' => $Finance->Sprava, 'AdministrationTotal' => $SpravaCelkem, 'ConsumptionTotal' => $TotalConsumptionCost, 'TotalPaid' => $Finance->TotalPaid, 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'], 'MemberCount' => $Finance->InternetUsers));
    393413
    394       // Update tarrifs
     414      // Update services
    395415      $Output .= 'Měním aktuální tarify....<br>';
    396       $DbResult = $this->Database->select('FinanceTariff', '*', '`ReplaceId` IS NOT NULL');
    397       while($Tariff = $DbResult->fetch_array())
     416      $DbResult = $this->Database->select('Service', '*', '`ReplaceId` IS NOT NULL');
     417      while($Service = $DbResult->fetch_array())
    398418      {
    399         $this->Database->update('FinanceTariff', 'Id='.$Tariff['ReplaceId'], array('Name' => $Tariff['Name'],
    400           'UploadAsymmetry' => $Tariff['UploadAsymmetry'], 'MemberCount' => $Tariff['MemberCount'],
    401           'Group' => $Tariff['Group'], 'SpeedMin' => $Tariff['SpeedMin'],
    402           'SpeedMax' => $Tariff['SpeedMax'], 'Price' => $Tariff['Price']));
     419        $Service['Id'] = $Service['ReplaceId'];
     420        $Service['ReplaceId'] = '';
     421        $this->Database->update('Service', 'Id='.$Service['ReplaceId'], $Service);
    403422      }
    404       $this->Database->delete('FinanceTariff', '`ReplaceId` IS NOT NULL');
     423      $this->Database->delete('Service', '`ReplaceId` IS NOT NULL');
    405424
    406425      $Finance->RecalculateMemberPayment();
     
    429448    $DbResult = $this->Database->select('User', '*', 'Id='.$Member['ResponsibleUser']);   
    430449    $User = $DbResult->fetch_assoc();
     450   
     451    $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Config['Finance']['MainSubjectId']);
     452    $MainSubject = $DbResult->fetch_assoc(); 
     453   
     454    $DbResult = $this->Database->select('FinanceBankAccount', '*', '(`Subject`='.
     455      $Config['Finance']['MainSubjectId'].') AND (`Use`=1)');
     456    $MainSubjectAccount = $DbResult->fetch_assoc();
    431457       
    432458    if($User['Email'] != '')
    433459    {
    434460      $Title = 'Pravidelné vyúčtování služeb';
    435       $Content = 'Vyúčtovaní subjektu <strong>'.$Subject['Name'].'</strong> zastoupeného uživatelem <strong>'.$User['Name'].'</strong> ke dni <strong>'.$this->System->HumanDate(time()).'</strong>.<br /><br />'."\n".
    436         'Váš aktuální tarif: <strong>'.$this->System->Modules['Finance']->Tariffs[$Member['InternetTariffCurrentMonth']]['Name'].' '.$this->System->AddPrefixMultipliers($this->System->Modules['Finance']->Tariffs[$Member['InternetTariffCurrentMonth']]['SpeedMax'], 'bit/s', 3, 'Binary').'</strong><br />'."\n".
     461      $Content = 'Vyúčtovaní zákazníka <strong>'.$Subject['Name'].'</strong> zastoupeného uživatelem <strong>'.$User['Name'].'</strong> ke dni <strong>'.$this->System->HumanDate(time()).'</strong>.<br /><br />'."\n".
     462        'Váše aktuální služby: ';
     463      $DbResult = $this->Database->query('SELECT GROUP_CONCAT(Service.Name) AS Name FROM ServiceCustomerRel LEFT JOIN Service '.
     464      'ON Service.Id=ServiceCustomerRel.Service WHERE ServiceCustomerRel.Customer='.$Member['Id'].' AND ServiceCustomerRel.Period=0');
     465        $Service = $DbRow->fetch_assoc();
     466      $Content .= '<strong>'.$Service['Name'].'</strong><br />'."\n".
    437467        'Vaše platební období: <strong>'.$this->System->Modules['Finance']->BillingPeriods[$Member['BillingPeriod']]['Name'].'</strong><br />'."\n".
    438468        'Pravidelná platba za období: <strong>'.$MemberPayment['MonthlyTotal'].' Kč</strong><br />'."\n".
    439         'Bankovní účet: <strong>2600134781 / 2010</strong> (EUR Slovensko 2600134781 / 8330, Fio banka)<br/>'."\n".
     469        'Bankovní účet: <strong>'.$MainSubjectAccount['Number'].'<br/>'."\n".
    440470        'Variabilní symbol: <strong>'.$Member['Subject'].'</strong><br/>'."\n".
    441471        'Stav vašeho účtu: <strong>'.($MemberPayment['Cash'] - $MemberPayment['MonthlyTotal']).' Kč</strong><br /><br />'."\n";
Note: See TracChangeset for help on using the changeset viewer.