Ignore:
Timestamp:
Jul 3, 2015, 11:36:07 PM (9 years ago)
Author:
chronos
Message:

to group id instead of DocumentLine.

File:
1 edited

Legend:

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

    r738 r740  
    100100  }
    101101
    102   function InsertInvoice($Subject, $TimeCreation, $TimeDue, $Direction, $Items,
    103   $DocumentLine, $PeriodFrom, $PeriodTo)
     102  function InsertInvoice($Subject, $TimeCreation, $TimeDue, $ValueSign, $Items,
     103  $Group, $PeriodFrom, $PeriodTo)
    104104  {
    105105    global $LastInsertTime;
    106106
    107107    $Year = date('Y', $TimeCreation);
    108     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
     108    $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($Group['DocumentLine'], $Year);
    109109    $SumValue = 0;
    110     foreach($Items as $Item)
     110    foreach($Items as $Item) {
    111111      $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']);
     112    }
    112113    $this->Database->insert('FinanceInvoice', array(
    113114      'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation),
    114115      'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue,
    115       'Direction' => $Direction, 'BillCode' => $BillCode,
     116      'ValueSign' => $ValueSign, 'BillCode' => $BillCode,
    116117      'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo),
    117       'Generate' => 1, 'DocumentLine' => $DocumentLine));
     118      'Generate' => 1, 'Group' => $FinanceGroup['Id']));
    118119    $InvoiceId = $this->Database->insert_id;
    119120    foreach($Items as $Item)
     
    166167        // We can't produce negative invoice except storno invoice.
    167168        // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction
    168         // Other subject should invoice only possitive items. Negative items should be somehow removed.
     169        // Other subject should invoice only positive items. Negative items should be somehow removed.
    169170        if($MonthlyTotal >= 0) {
    170           $DocumentLine = DOC_LINE_INVOICE_OUT;
    171           $Direction = 1; // Standard out invoice
     171          $InvoiceGroupId = INVOICE_GROUP_OUT;
    172172        } 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'];
     173          $InvoiceGroupId = INVOICE_GROUP_IN;
     174        }
     175
     176        // Load invoice group
     177        $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($InvoiceGroupId, 'FinanceInvoice');
     178        foreach($InvoiceItems as $Index => $Item) {
     179          $InvoiceItems[$Index]['Price'] = $Item['Price'] * $FinanceGroup['ValueSign'];
    177180        }
    178181
     
    182185          $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />';
    183186          $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS,
    184             $Direction, $InvoiceItems, $DocumentLine, $Period['From'], $Period['To']);
     187            $FinanceGroup['ValueSign'], $InvoiceItems, $FinanceGroup, $Period['From'], $Period['To']);
    185188
    186189          $Output .= $this->SendPaymentEmail($Member['Id']);
     
    354357        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Popis</th>'.
    355358        '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Částka [Kč]</th></tr>'."\n";
    356       $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT `Text`, `Time`, (`Value`*`Direction`) AS `Value`, `File` FROM `FinanceOperation` WHERE (`Subject`='.$Member['Subject'].')) UNION ALL '.
     359      $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT `Text`, `Time`, (`Value`*`ValueSign`) AS `Value`, `File` FROM `FinanceOperation` WHERE (`Subject`='.$Member['Subject'].')) UNION ALL '.
    357360        '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ", ") FROM `FinanceInvoiceItem` '.
    358361        'WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`) AS `Text`, '.
    359         '`Time`, -(`Value`*`Direction`) AS `Value`, `File` FROM `FinanceInvoice` WHERE (`Subject`='.
     362        '`Time`, -(`Value`*`ValueSign`) AS `Value`, `File` FROM `FinanceInvoice` WHERE (`Subject`='.
    360363        $Member['Subject'].')) ORDER BY `Time` DESC) AS `T1` WHERE (`T1`.`Time` > "'.$Member['BillingPeriodLastDate'].'")');
    361364      while($DbRow = $DbResult->fetch_assoc())
Note: See TracChangeset for help on using the changeset viewer.