Changeset 740 for trunk/Modules/Finance/Manage.php
- Timestamp:
- Jul 3, 2015, 11:36:07 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Manage.php
r738 r740 100 100 } 101 101 102 function InsertInvoice($Subject, $TimeCreation, $TimeDue, $ Direction, $Items,103 $ DocumentLine, $PeriodFrom, $PeriodTo)102 function InsertInvoice($Subject, $TimeCreation, $TimeDue, $ValueSign, $Items, 103 $Group, $PeriodFrom, $PeriodTo) 104 104 { 105 105 global $LastInsertTime; 106 106 107 107 $Year = date('Y', $TimeCreation); 108 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($ DocumentLine, $Year);108 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($Group['DocumentLine'], $Year); 109 109 $SumValue = 0; 110 foreach($Items as $Item) 110 foreach($Items as $Item) { 111 111 $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']); 112 } 112 113 $this->Database->insert('FinanceInvoice', array( 113 114 'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation), 114 115 'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue, 115 ' Direction' => $Direction, 'BillCode' => $BillCode,116 'ValueSign' => $ValueSign, 'BillCode' => $BillCode, 116 117 'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo), 117 'Generate' => 1, ' DocumentLine' => $DocumentLine));118 'Generate' => 1, 'Group' => $FinanceGroup['Id'])); 118 119 $InvoiceId = $this->Database->insert_id; 119 120 foreach($Items as $Item) … … 166 167 // We can't produce negative invoice except storno invoice. 167 168 // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction 168 // Other subject should invoice only pos sitive items. Negative items should be somehow removed.169 // Other subject should invoice only positive items. Negative items should be somehow removed. 169 170 if($MonthlyTotal >= 0) { 170 $DocumentLine = DOC_LINE_INVOICE_OUT; 171 $Direction = 1; // Standard out invoice 171 $InvoiceGroupId = INVOICE_GROUP_OUT; 172 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']; 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']; 177 180 } 178 181 … … 182 185 $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />'; 183 186 $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']); 185 188 186 189 $Output .= $this->SendPaymentEmail($Member['Id']); … … 354 357 '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Popis</th>'. 355 358 '<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 '. 357 360 '(SELECT (SELECT GROUP_CONCAT(`Description` SEPARATOR ", ") FROM `FinanceInvoiceItem` '. 358 361 '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`='. 360 363 $Member['Subject'].')) ORDER BY `Time` DESC) AS `T1` WHERE (`T1`.`Time` > "'.$Member['BillingPeriodLastDate'].'")'); 361 364 while($DbRow = $DbResult->fetch_assoc())
Note:
See TracChangeset
for help on using the changeset viewer.