Changeset 727 for trunk/Modules/Finance/Manage.php
- Timestamp:
- Jan 6, 2015, 12:02:36 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Manage.php
r726 r727 132 132 // Generuj účetní položky 133 133 $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`,'. 135 135 '`MemberPayment`.`MonthlyPlus` AS `MonthlyPlus` '. 136 136 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` '. … … 140 140 $Output .= $Member['SubjectName'].': '; 141 141 $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']); 142 if($Period['From'] > $Member[' UNIX_TIMESTAMP(Member.BillingPeriodLastDate)'])142 if($Period['From'] > $Member['BillingPeriodLastUnixTime']) 143 143 { 144 144 $this->Database->update('Member', 'Id='.$Member['Id'], … … 148 148 $Period = $this->GetBillingPeriod($Member['BillingPeriod']); 149 149 if(($Period['MonthCount'] > 0) and ($Member['Blocked'] == 0) and 150 ($Period['From'] > $Member[' UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']))150 ($Period['From'] > $Member['BillingPeriodLastUnixTime'])) 151 151 { 152 152 $InvoiceItems = array(); … … 163 163 $MonthlyTotal += $Service['Price']; 164 164 } 165 $PayPerPeriod = $MonthlyTotal * $Period['MonthCount']; 165 $PayPerPeriod = $MonthlyTotal * $Period['MonthCount']; 166 166 // We can't produce negative invoice except storno invoice. 167 167 // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction 168 168 // 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; 170 171 $Direction = 1; // Standard out invoice 171 172 $Direction = -1; // In case of negative total value generate reverse invoice for other subject173 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 } 177 178 178 179 if($PayPerPeriod != 0) … … 181 182 $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />'; 182 183 $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']); 184 185 185 186 $Output .= $this->SendPaymentEmail($Member['Id']); … … 308 309 global $Config; 309 310 310 $DbResult = $this->Database->select('Member', '*', ' Id='.$MemberId);311 $DbResult = $this->Database->select('Member', '*', '`Id`='.$MemberId); 311 312 $Member = $DbResult->fetch_assoc(); 312 313 313 $DbResult = $this->Database->select('MemberPayment', '*', ' Member='.$MemberId);314 $DbResult = $this->Database->select('MemberPayment', '*', '`Member`='.$MemberId); 314 315 $MemberPayment = $DbResult->fetch_assoc(); 315 316 316 $DbResult = $this->Database->select('Subject', 'Name', ' Id='.$Member['Subject']);317 $DbResult = $this->Database->select('Subject', 'Name', '`Id`='.$Member['Subject']); 317 318 $Subject = $DbResult->fetch_assoc(); 318 319 319 $DbResult = $this->Database->select('User', '*', ' Id='.$Member['ResponsibleUser']);320 $DbResult = $this->Database->select('User', '*', '`Id`='.$Member['ResponsibleUser']); 320 321 $User = $DbResult->fetch_assoc(); 321 322 … … 325 326 $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']); 326 327 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)'); 330 333 $MainSubjectAccount = $DbResult->fetch_assoc(); 331 334 … … 336 339 $User['Name'].'</strong> ke dni <strong>'.$this->System->HumanDate(time()).'</strong>.<br /><br />'."\n". 337 340 '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)'); 341 344 $Service = $DbResult->fetch_assoc(); 342 345 $Content .= '<strong>'.$Service['Name'].'</strong><br />'."\n". … … 351 354 '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Popis</th>'. 352 355 '<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'].'")'); 356 361 while($DbRow = $DbResult->fetch_assoc()) 357 362 {
Note:
See TracChangeset
for help on using the changeset viewer.