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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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      {
Note: See TracChangeset for help on using the changeset viewer.