Changeset 688


Ignore:
Timestamp:
Sep 7, 2014, 2:48:21 PM (10 years ago)
Author:
chronos
Message:
  • Upraveno: Spotřeba se dále bude zákazníkům evidovat jako samostatná přiřazená služba namísto pevného vkládání položky a dopočtu z tabulky "Placení zákazníků".
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r687 r688  
    11<?php
    22
    3 $Revision = 687; // Subversion revision
    4 $DatabaseRevision = 679; // SQL structure revision
     3$Revision = 688; // Subversion revision
     4$DatabaseRevision = 688; // SQL structure revision
    55$ReleaseTime = strtotime('2014-09-07');
  • trunk/Common/Setup/Updates.php

    r679 r688  
    885885}
    886886
     887function UpdateTo688($Manager)
     888{
     889        // Convert monthly plus payment for consumption to regular service
     890  $DbResult = $Manager->Execute('SELECT `MonthlyPlus`, `Member` FROM `MemberPayment` WHERE `MonthlyPlus` > 0');
     891  while($DbResult->num_rows > 0)
     892  {
     893        $DbRow = $DbResult->fetch_assoc();
     894    $Manager->Execute("INSERT INTO `Service` (`Id` ,`Name` ,`Category` ,`Price` ,`VAT`) ".
     895      "VALUES (NULL , 'Spotřeba energie', 3, -".$DbRow['MonthlyPlus'].", 2);");
     896    $ServiceId = $Manager->Database->insert_id;
     897    $Manager->Execute("INSERT INTO `ServiceCustomerRel` (`Id` ,`Service` ,`Customer`) ".
     898      "VALUES (NULL , ".$ServiceId.', '.$DbRow['Member'].");");
     899  }
     900}
     901
    887902class Updates
    888903{
     
    933948      676 => array('Revision' => 678, 'Function' => 'UpdateTo678'),
    934949      678 => array('Revision' => 679, 'Function' => 'UpdateTo679'),
     950      679 => array('Revision' => 688, 'Function' => 'UpdateTo688'),
    935951    ));
    936952  }
  • trunk/Modules/Finance/Manage.php

    r680 r688  
    162162            'Quantity' => $Period['MonthCount'], 'VAT' => $this->System->Modules['Finance']->GetVATByType($Service['VAT']));
    163163          $MonthlyTotal += $Service['Price'];
    164         }
    165         if($Member['MonthlyPlus'] != 0)
    166         {
    167           $InvoiceItems[] = array('Description' => 'Spotřeba energie', 'Price' => -$Member['MonthlyPlus'],
    168             'Quantity' => $Period['MonthCount'], 'VAT' => $this->System->Modules['Finance']->GetVATByType(VAT_TYPE_BASE));
    169           $MonthlyTotal -= $Member['MonthlyPlus'];
    170164        }
    171165        $PayPerPeriod = $MonthlyTotal * $Period['MonthCount'];
  • trunk/Modules/Finance/UserState.php

    r627 r688  
    66  var $ShortTitle = 'Stav financí';
    77  var $ParentClass = 'PageFinance';
     8
     9  function ShowFinanceOperation($Subject)
     10  {
     11        $UserOperationTableQuery = '((SELECT Text, Time, Value AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
     12          'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '.
     13                '(SELECT (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoice=FinanceInvoice.Id) AS Text, '.
     14                'Time, -Value as Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')) ORDER BY Time DESC) AS T1';
     15
     16    $Output = '<div style="text-align:center">Výpis finančních operací</div>';
     17        $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$UserOperationTableQuery.'');
     18        $DbRow = $DbResult->fetch_row();
     19        $PageList = GetPageList($DbRow[0]);
     20
     21        $Output .= $PageList['Output'];
     22        $Output .= '<table class="WideTable" style="font-size: small;">';
     23
     24        $TableColumns = array(
     25                        array('Name' => 'Time', 'Title' => 'Datum'),
     26                        array('Name' => 'Description', 'Title' => 'Popis'),
     27                        array('Name' => 'Value', 'Title' => 'Částka [Kč]'),
     28                        array('Name' => 'Period', 'Title' => 'Období'),
     29                        array('Name' => 'Bill', 'Title' => 'Doklad'),
     30        );
     31        $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
     32        $Output .= $Order['Output'];
     33
     34        $Query = 'SELECT * FROM '.$UserOperationTableQuery.' '.$Order['SQL'].$PageList['SQLLimit'];
     35
     36        $DbResult = $this->Database->query($Query);
     37    $SumValue = 0;
     38        while($Row = $DbResult->fetch_assoc())
     39        {
     40                if($Row['Value'] == -0) $Row['Value'] = 0;
     41                if($Row['Value'] > 0) $Row['Value'] = '+'.$Row['Value'];
     42                if($Row['BillCode'] == '') $Row['BillCode'] = 'PDF';
     43                if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/file?id='.$Row['File']).'">'.$Row['BillCode'].'</a>';
     44                else $Invoice = NotBlank($Row['BillCode']);
     45                if($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
     46                else $Period = '&nbsp;';
     47                $Output .= '<tr><td style="text-align: right;">'.HumanDate($Row['Time']).'</td>'.
     48                                '<td style="text-align: left;">'.$Row['Text'].'</td>'.
     49                                '<td style="text-align: right;">'.round($Row['Value'], 2).'</td>'.
     50                                '<td>'.$Period.'</td>'.
     51                                '<td>'.$Invoice.'</td></tr>';
     52                $SumValue = $SumValue + $Row['Value'];
     53        }
     54        $Output .= '</table>';
     55        $Output .= $PageList['Output'];
     56        return($Output);
     57  }
    858
    959  function Show()
     
    3080      } else return($this->SystemMessage('Chyba', 'Nejste zákazníkem'));
    3181    }
    32    
     82
    3383    if(!array_key_exists('show', $_GET)) $_GET['show'] = '';
    34     $DbResult = $this->Database->query('SELECT Member.*, MemberPayment.MonthlyPlus AS MonthlyPlus '.
     84    $DbResult = $this->Database->query('SELECT Member.* '.
    3585      'FROM Member LEFT JOIN MemberPayment ON MemberPayment.Member=Member.Id WHERE Member.Subject='.$Subject['Id']);
    36     if($DbResult->num_rows == 0) 
     86    if($DbResult->num_rows == 0)
    3787    {
    38       return($this->SystemMessage('Položka nenalezena', 'Zákazník nenalezen'));     
     88      return($this->SystemMessage('Položka nenalezena', 'Zákazník nenalezen'));
    3989    }
    4090    $Member = $DbResult->fetch_assoc();
    4191    $Output = '<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td valign="top">';
    4292
    43     if(array_key_exists('year', $_GET))
    44     {
    45       $DbResult = $this->Database->query('SELECT * FROM FinanceYear WHERE Id='.addslashes($_GET['year'] * 1));
    46     } else
    47     {
    48       $DbResult = $this->Database->query('SELECT * FROM FinanceYear ORDER BY Year DESC LIMIT 1');
    49     }
    50     $FinanceYearSelected = $DbResult->fetch_assoc();
    51     $YearWhere = ' WHERE (Time >= "'.$FinanceYearSelected['DateStart'].'") AND (Time <= "'.$FinanceYearSelected['DateEnd'].'")';
    52    
    53     // Year list
    54     if(array_key_exists('Subject', $_GET)) $SubjectParam = '&amp;Subject='.($_GET['Subject'] * 1);
    55       else $SubjectParam = '';
    56     $Output .= 'Roky: ';
    57     $DbResult = $this->Database->query('SELECT * FROM FinanceYear WHERE Year >= '.
    58       substr($Member['MembershipDate'], 0, strpos($Member['MembershipDate'], '-')));
    59     while($FinanceYear = $DbResult->fetch_assoc())
    60     {
    61       $Year = '<a href="?year='.$FinanceYear['Id'].$SubjectParam.'">'.$FinanceYear['Year'].'</a> ';
    62       if($FinanceYear['Id'] == $FinanceYearSelected['Id']) $Output .= '<strong>'.$Year.'</strong>';
    63         else $Output .= $Year;
    64     }
    65     $Output .= '<br/><br/>';   
    66    
    67     // Account state   
     93    // Account state
    6894    $UserOperationTableQuery = '((SELECT Text, Time, Value AS Value, File, BillCode, NULL AS PeriodFrom, NULL AS PeriodTo '.
    6995      'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '.
     
    7399    $DbRow = $DbResult->fetch_array();
    74100    $Total = $DbRow['Total'];
    75     $Output .= 'Stav účtu: <strong>'.round($Total, 2).' Kč</strong<br /><br /><br/>';
    76    
     101    $Output .= 'Stav účtu: <strong>'.round($Total, 2).' Kč</strong><br /><br />';
     102
    77103    // Tabulka operaci
    78     $Output .= 'Výpis operací pro subjekt '.$Subject['Name'].':<br />';
    79     $Output .= '<table style="font-size: smaller;" class="WideTable"><tr>'.
    80     '<th>Datum</th><th>Popis</th><th>Částka</th><th>Období</th><th>Doklad</th></tr>';
    81     $Operations = array();
    82     $DbResult = $this->Database->query('SELECT T1.* FROM '.$UserOperationTableQuery.$YearWhere);
    83     while($DbRow = $DbResult->fetch_array())
    84       $Operations[] = $DbRow;
    85     $SumValue = 0;
    86     foreach($Operations as $Row)
    87     {
    88       if($Row['Value'] == -0) $Row['Value'] = 0;
    89       if($Row['Value'] > 0) $Row['Value'] = '+'.$Row['Value'];
    90       if($Row['BillCode'] == '') $Row['BillCode'] = 'PDF';
    91       if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/file?id='.$Row['File']).'">'.$Row['BillCode'].'</a>';
    92         else $Invoice = NotBlank($Row['BillCode']);
    93       if($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
    94         else $Period = '&nbsp;';
    95       $Output .= '<tr><td style="text-align: right;">'.HumanDate($Row['Time']).'</td>'.
    96       '<td style="text-align: left;">'.$Row['Text'].'</td>'.
    97       '<td style="text-align: right;">'.round($Row['Value'], 2).'</td>'.
    98       '<td style="text-align: center;">'.$Period.'</td>'.
    99       '<td style="text-align: center;">'.$Invoice.'</td></tr>';
    100       $SumValue = $SumValue + $Row['Value'];
    101     }
    102     $Output .= '<tr><td style="text-align: right;" colspan="2"><strong>Celkem za rok</strong></td>'.
    103     '<td style="text-align: right;"><strong>'.round($SumValue, 2).'</strong></td>'.
    104     '<td style="text-align: center;">&nbsp;</td>'.
    105     '<td style="text-align: center;">&nbsp;</td></tr>';
    106    
    107     $Output .= '</table>';
     104    $Output .= $this->ShowFinanceOperation($Subject);
     105
    108106    $Output .= '</td><td valign="top">';
    109107
    110     $Output .= 'Variabilní symbol pro platby: <strong>'.$Subject['Id'].'</strong><br><br>';
     108    $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '.
     109                'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
     110                'WHERE (FinanceBankAccount.`Subject`='.$this->System->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
     111    $SubjectFromAccount = $DbResult->fetch_assoc();
     112    $Account = $SubjectFromAccount['NumberFull'];
     113
     114    $Output .= 'Účet pro platby: <strong>'.$Account.'</strong><br/>';
     115    $Output .= 'Variabilní symbol pro platby: <strong>'.$Subject['Id'].'</strong><br/>';
     116    $Output .= 'Subjekt: <strong>'.$Subject['Name'].'</strong><br/>';
     117    $Output .= '<br/>';
    111118
    112119    $Total = 0;
     
    121128      $Total += $DbRow['Price'];
    122129    }
    123    
    124     if($Member['MonthlyPlus'] != 0)
    125     {
    126       $Output .= '<tr><td>Příjem za spotřebu</td><td>'.(-$Member['MonthlyPlus']).'</td></tr>';
    127       $Total -= $Member['MonthlyPlus'];
    128     }
     130
    129131    $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$Total.'</strong></td></tr></table>';
    130132    //echo('Tarif pro příští měsíc: '.$Tarify[$Row2['inet_tarif_next']]['name'].'<br><br>');
    131133    $Output .= '<br />';
    132    
    133     if($Member['MonthlyPlus'] != 0)
    134     {
    135       $Output .= 'Měsíční příjem za spotřebu zařízení umístěných u uživatele:<br>';
    136       $Output .= '<table class="WideTable"><tr><th>Název zařízení</th><th>Spotřeba [W]</th><th>Příjem [Kč]</th></tr>';
    137       $DbResult = $this->Database->query('SELECT Product.Name AS Name, Product.Consumption AS Consumption '.
    138         'FROM StockItem JOIN Product ON Product.Id = StockItem.Product '.
    139         'WHERE (StockItem.Location='.$Member['Id'].') AND (StockItem.TimeElimination IS NULL)');
    140       $TotalW = 0;
    141       $TotalPrice = 0;
    142       while($Row = $DbResult->fetch_assoc())
    143       {
    144         $Output .= '<tr><td>'.$Row['Name'].'</td><td>'.$Row['Consumption'].'</td><td>'.$this->System->Modules['Finance']->W2Kc($Row['Consumption']).'</td></tr>';
    145         $TotalW += $Row['Consumption'];
    146         $TotalPrice += $this->System->Modules['Finance']->W2Kc($Row['Consumption']);
    147       }
    148       $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$TotalW.'</strong></td><td><strong>'.$TotalPrice.'</strong></td></tr>';
    149       $Output .= '</table>';
    150   }
     134
    151135    $Output .= '</td></tr></table>';
    152136    return($Output);
Note: See TracChangeset for help on using the changeset viewer.