Changeset 727


Ignore:
Timestamp:
Jan 6, 2015, 12:02:36 AM (10 years ago)
Author:
chronos
Message:
  • Fixed: Errors with periodic finance invoice generation.
  • Fixed: In case of generating of incoming invoice wrong outgoing DocumentLine was used.
  • Added: Show related bank accounts in Subject view.
  • Added: Check if htmldoc is installed in OS.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r726 r727  
    11<?php
    22
    3 $Revision = 726; // Subversion revision
     3$Revision = 727; // Subversion revision
    44$DatabaseRevision = 726; // SQL structure revision
    55$ReleaseTime = strtotime('2015-01-05');
  • trunk/Common/Global.php

    r705 r727  
    385385}
    386386
     387function CommandExist($Command)
     388{
     389  $Result = shell_exec('which '.$Command);
     390  return(!empty($Result));
     391}
     392
    387393function RemoveDiacritic($Text)
    388394{
  • trunk/Modules/Customer/Customer.php

    r726 r727  
    4848        'MonthlyInternet' => array('Type' => 'Integer', 'Caption' => 'Internet měsíčně', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
    4949        'MonthlyConsumption' => array('Type' => 'Integer', 'Caption' => 'Spotřeba měsíčně', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
    50         'NetworkDevice' => array('Type' => 'Integer', 'Caption' => 'Podíl na zařízení', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
    5150        'MonthlyPlus' => array('Type' => 'Integer', 'Caption' => 'Měsíčně plus', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
    5251        'Cash' => array('Type' => 'Integer', 'Caption' => 'Kredit', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true),
  • trunk/Modules/Finance/Bill.php

    r720 r727  
    44{
    55  var $SpecificSymbol = 1; // počítačová sít
    6 
     6  var $Checked; 
     7 
    78  function GenerateHTML()
    89  {
     
    2122  {
    2223        $Encoding = new Encoding();
     24        if($this->Checked == false) {
     25                if(CommandExist('htmldoc')) {
     26                        $this->Checked = true;
     27                } else throw new Exception('htmldoc is not installed.');
     28        }
    2329    $Output = shell_exec('echo "'.addslashes($Encoding->FromUTF8($HtmlCode)).
    2430      '"|htmldoc --no-numbered --webpage --no-embedfonts --charset 8859-2 -t pdf -');
  • trunk/Modules/Finance/Manage.php

    r726 r727  
    132132    // Generuj účetní položky
    133133    $DbResult = $this->Database->query('SELECT `Member`.*, `MemberPayment`.`MonthlyTotal` AS `MonthlyTotal`, '.
    134       'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`), `Subject`.`Name` AS `SubjectName`,'.
     134      'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`) AS `BillingPeriodLastUnixTime`, `Subject`.`Name` AS `SubjectName`,'.
    135135      '`MemberPayment`.`MonthlyPlus` AS `MonthlyPlus` '.
    136136      'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` '.
     
    140140      $Output .= $Member['SubjectName'].': ';
    141141      $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']);
    142       if($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)'])
     142      if($Period['From'] > $Member['BillingPeriodLastUnixTime'])
    143143      {
    144144        $this->Database->update('Member', 'Id='.$Member['Id'],
     
    148148      $Period = $this->GetBillingPeriod($Member['BillingPeriod']);
    149149      if(($Period['MonthCount'] > 0) and ($Member['Blocked'] == 0) and
    150         ($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']))
     150        ($Period['From'] > $Member['BillingPeriodLastUnixTime']))
    151151      {
    152152        $InvoiceItems = array();
     
    163163          $MonthlyTotal += $Service['Price'];
    164164        }
    165         $PayPerPeriod = $MonthlyTotal * $Period['MonthCount'];
     165        $PayPerPeriod = $MonthlyTotal * $Period['MonthCount'];               
    166166        // We can't produce negative invoice except storno invoice.
    167167        // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction 
    168168        // Other subject should invoice only possitive items. Negative items should be somehow removed.
    169         if($MonthlyTotal >= 0)
     169        if($MonthlyTotal >= 0) {
     170                $DocumentLine = DOC_LINE_INVOICE_OUT;       
    170171                $Direction = 1; // Standard out invoice
    171           else {
    172                 $Direction = -1; // In case of negative total value generate reverse invoice for other subject
    173                 foreach($InvoiceItems as $Index => $Item)
    174                         $InvoiceItems[$Index]['Price'] = -$Item['Price'];
    175           }
    176        
     172        } else {
     173                $DocumentLine = DOC_LINE_INVOICE_IN;
     174          $Direction = -1; // In case of negative total value generate reverse invoice for other subject
     175          foreach($InvoiceItems as $Index => $Item)
     176                $InvoiceItems[$Index]['Price'] = -$Item['Price'];
     177        }       
    177178       
    178179        if($PayPerPeriod != 0)
     
    181182          $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />';
    182183          $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS,
    183             $Direction, $InvoiceItems, DOC_LINE_INVOICE_OUT, $Period['From'], $Period['To']);
     184            $Direction, $InvoiceItems, $DocumentLine, $Period['From'], $Period['To']);
    184185
    185186          $Output .= $this->SendPaymentEmail($Member['Id']);
     
    308309    global $Config;
    309310
    310     $DbResult = $this->Database->select('Member', '*', 'Id='.$MemberId);
     311    $DbResult = $this->Database->select('Member', '*', '`Id`='.$MemberId);
    311312    $Member = $DbResult->fetch_assoc();
    312313
    313     $DbResult = $this->Database->select('MemberPayment', '*', 'Member='.$MemberId);
     314    $DbResult = $this->Database->select('MemberPayment', '*', '`Member`='.$MemberId);
    314315    $MemberPayment = $DbResult->fetch_assoc();
    315316
    316     $DbResult = $this->Database->select('Subject', 'Name', 'Id='.$Member['Subject']);
     317    $DbResult = $this->Database->select('Subject', 'Name', '`Id`='.$Member['Subject']);
    317318    $Subject = $DbResult->fetch_assoc();
    318319
    319     $DbResult = $this->Database->select('User', '*', 'Id='.$Member['ResponsibleUser']);
     320    $DbResult = $this->Database->select('User', '*', '`Id`='.$Member['ResponsibleUser']);
    320321    $User = $DbResult->fetch_assoc();
    321322
     
    325326    $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']);
    326327
    327     $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '.
    328       'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
    329       'WHERE (FinanceBankAccount.`Subject`='.$Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
     328    $DbResult = $this->Database->query('SELECT `FinanceBankAccount`.*, '.
     329                'CONCAT(`FinanceBankAccount`.`Number`, "/", `FinanceBank`.`Code`) AS `NumberFull` FROM `FinanceBankAccount` '.
     330      'JOIN `FinanceBank` ON `FinanceBank`.`Id`=`FinanceBankAccount`.`Bank` '.
     331      'WHERE (`FinanceBankAccount`.`Subject`='.$Config['Finance']['MainSubjectId'].') '.
     332        'AND (`FinanceBankAccount`.`Use`=1)');
    330333    $MainSubjectAccount = $DbResult->fetch_assoc();
    331334
     
    336339        $User['Name'].'</strong> ke dni <strong>'.$this->System->HumanDate(time()).'</strong>.<br /><br />'."\n".
    337340        'Váše aktuální služby: ';
    338       $DbResult = $this->Database->query('SELECT GROUP_CONCAT(Service.Name) AS Name FROM ServiceCustomerRel LEFT JOIN Service '.
    339         'ON Service.Id=ServiceCustomerRel.Service WHERE (ServiceCustomerRel.Customer='.$Member['Id'].') '.
    340         'AND ServiceCustomerRel.ChangeAction IS NULL');
     341      $DbResult = $this->Database->query('SELECT GROUP_CONCAT(`Service`.`Name`) AS `Name` FROM `ServiceCustomerRel` LEFT JOIN `Service` '.
     342        'ON `Service`.`Id`=`ServiceCustomerRel`.`Service` WHERE (`ServiceCustomerRel`.`Customer`='.$Member['Id'].') '.
     343        'AND (`ServiceCustomerRel`.`ChangeAction` IS NULL)');
    341344      $Service = $DbResult->fetch_assoc();
    342345      $Content .= '<strong>'.$Service['Name'].'</strong><br />'."\n".
     
    351354        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Popis</th>'.
    352355        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Částka [Kč]</th></tr>'."\n";
    353       $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, (Value*Direction) AS Value, File FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '.
    354         '(SELECT CONCAT(`Text`, (SELECT GROUP_CONCAT(`Description` SEPARATOR "<br/>") FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`)) AS `Text`, Time, -(Value*Direction) as Value, File FROM FinanceInvoice WHERE (Subject='.
    355         $Member['Subject'].')) ORDER BY Time DESC) AS T1 WHERE (T1.Time > "'.$Member['BillingPeriodLastDate'].'")');
     356      $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT `Text`, `Time`, (`Value`*`Direction`) AS `Value`, `File` FROM `FinanceOperation` WHERE (`Subject`='.$Member['Subject'].')) UNION ALL '.
     357        '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ", ") FROM `FinanceInvoiceItem` '.
     358        'WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`) AS `Text`, '.
     359        '`Time`, -(`Value`*`Direction`) AS `Value`, `File` FROM `FinanceInvoice` WHERE (`Subject`='.
     360        $Member['Subject'].')) ORDER BY `Time` DESC) AS `T1` WHERE (`T1`.`Time` > "'.$Member['BillingPeriodLastDate'].'")');
    356361      while($DbRow = $DbResult->fetch_assoc())
    357362      {
  • trunk/Modules/Subject/Subject.php

    r720 r727  
    2828        'AddressCountry' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => ''),
    2929        'IC' => array('Type' => 'String', 'Caption' => 'IČ', 'Default' => ''),
    30         'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''),
     30        'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''),       
    3131        'MapPosition' => array('Type' => 'TMapPosition', 'Caption' => 'Pozice na mapě', 'Default' => '', 'Null' => true),
    3232        'WWW' => array('Type' => 'Hyperlink', 'Caption' => 'WWW', 'Default' => ''),
     
    3939          'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`) FROM `FinanceInvoice` '.
    4040          'WHERE `FinanceInvoice`.`Subject`=#Id), 0)'),
     41        'BankAccounts' => array('Type' => 'TFinanceBankAccountListSubject', 'Caption' => 'Bankovní účety', 'Default' => ''),
    4142      ),
     43    ));
     44    $this->System->FormManager->RegisterFormType('TFinanceBankAccountListSubject', array(
     45      'Type' => 'ManyToOne',
     46      'Table' => 'FinanceBankAccount',
     47      'Id' => 'Id',
     48      'Ref' => 'Subject',
     49      'Filter' => '1',
    4250    ));
    4351    $this->System->FormManager->RegisterClass('SubjectReport', array(
Note: See TracChangeset for help on using the changeset viewer.