Changeset 720 for trunk/Modules/Finance/Manage.php
- Timestamp:
- Jan 3, 2015, 5:55:34 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Manage.php
r719 r720 50 50 { 51 51 if(!$this->System->User->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění'); 52 $SQL = 'SELECT Member.*, MemberPayment.MonthlyTotal AS Monthly, '.53 ' MemberPayment.Cash AS Cash, '.54 '(SELECT GROUP_CONCAT( Service.Name) FROM ServiceCustomerRel LEFT JOIN Service'.55 'ON Service.Id=ServiceCustomerRel.Service WHERE ServiceCustomerRel.Customer=Member.IdAND '.56 ' ServiceCustomerRel.Action IS NULL) AS ServicesNextMonth, '.57 'UNIX_TIMESTAMP( Member.BillingPeriodLastDate) AS LastDate, Subject.Name AS SubjectName, '.58 ' FinanceBillingPeriod.Name AS BillingPeriodName'.59 'FROM MemberPayment JOIN Member ON Member.Id=MemberPayment.Member JOIN Subject'.60 'ON Subject.Id=Member.Subject LEFT JOIN FinanceBillingPeriodON '.61 ' FinanceBillingPeriod.Id=Member.BillingPeriodNext WHERE (Member.Blocked= 0)'.62 'AND ( Member.BillingPeriodNext > 1) AND (MemberPayment.MonthlyTotal!= 0)';52 $SQL = 'SELECT `Member`.*, `MemberPayment`.`MonthlyTotal` AS `Monthly`, '. 53 '`MemberPayment`.`Cash` AS `Cash`, '. 54 '(SELECT GROUP_CONCAT(`Service`.`Name`) FROM `ServiceCustomerRel` LEFT JOIN `Service` '. 55 'ON `Service`.`Id`=`ServiceCustomerRel`.`Service` WHERE `ServiceCustomerRel`.`Customer`=`Member`.`Id` AND '. 56 '`ServiceCustomerRel`.`Action` IS NULL) AS `ServicesNextMonth`, '. 57 'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`) AS `LastDate`, `Subject`.`Name` AS `SubjectName`, '. 58 '`FinanceBillingPeriod`.`Name` AS `BillingPeriodName` '. 59 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` JOIN `Subject` '. 60 'ON `Subject`.`Id`=`Member`.`Subject` LEFT JOIN `FinanceBillingPeriod` ON '. 61 '`FinanceBillingPeriod`.`Id`=`Member`.`BillingPeriodNext` WHERE (`Member`.`Blocked` = 0)'. 62 'AND (`Member`.`BillingPeriodNext` > 1) AND (`MemberPayment`.`MonthlyTotal` != 0)'; 63 63 64 64 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$SQL.') AS T'); … … 100 100 } 101 101 102 function InsertInvoice($Subject, $TimeCreation, $TimeDue, $ Items,102 function InsertInvoice($Subject, $TimeCreation, $TimeDue, $Direction, $Items, 103 103 $DocumentLine, $PeriodFrom, $PeriodTo) 104 104 { … … 109 109 $SumValue = 0; 110 110 foreach($Items as $Item) 111 $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']);111 $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']); 112 112 $this->Database->insert('FinanceInvoice', array( 113 'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation), 114 'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue, 'BillCode' => $BillCode, 115 'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo), 116 'Generate' => 1, 'DocumentLine' => $DocumentLine)); 113 'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation), 114 'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue, 115 'Direction' => $Direction, 'BillCode' => $BillCode, 116 'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo), 117 'Generate' => 1, 'DocumentLine' => $DocumentLine)); 117 118 $InvoiceId = $this->Database->insert_id; 118 119 foreach($Items as $Item) … … 130 131 131 132 // Generuj účetní položky 132 $DbResult = $this->Database->query('SELECT Member.*, MemberPayment.MonthlyTotal AS MonthlyTotal, '.133 'UNIX_TIMESTAMP( Member.BillingPeriodLastDate), Subject.Name AS SubjectName,'.134 ' MemberPayment.MonthlyPlus AS MonthlyPlus'.135 'FROM MemberPayment JOIN Member ON Member.Id=MemberPayment.Member'.136 'JOIN Subject ON Subject.Id=Member.Subject');133 $DbResult = $this->Database->query('SELECT `Member`.*, `MemberPayment`.`MonthlyTotal` AS `MonthlyTotal`, '. 134 'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`), `Subject`.`Name` AS `SubjectName`,'. 135 '`MemberPayment`.`MonthlyPlus` AS `MonthlyPlus` '. 136 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` '. 137 'JOIN `Subject` ON `Subject`.`Id`=`Member`.`Subject`'); 137 138 while($Member = $DbResult->fetch_assoc()) 138 139 { … … 163 164 } 164 165 $PayPerPeriod = $MonthlyTotal * $Period['MonthCount']; 166 // We can't produce negative invoice except storno invoice. 167 // 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 if($MonthlyTotal >= 0) 170 $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 177 165 178 if($PayPerPeriod != 0) 166 179 { … … 168 181 $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />'; 169 182 $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS, 170 $ InvoiceItems, DOC_LINE_INVOICE_OUT, $Period['From'], $Period['To']);183 $Direction, $InvoiceItems, DOC_LINE_INVOICE_OUT, $Period['From'], $Period['To']); 171 184 172 185 $Output .= $this->SendPaymentEmail($Member['Id']); … … 227 240 $Output .= $Finance->LoadTariffs(); 228 241 $Output .= $Finance->RecalculateMemberPayment(); 229 230 // Celkovy prehled231 $DbResult = $this->Database->query('SELECT SUM(Product.SellPrice) AS Price FROM StockSerialNumber '.232 'JOIN Product ON StockSerialNumber.Product = Product.Id WHERE (StockSerialNumber.TimeElimination IS NULL) AND (StockSerialNumber.Segment IS NOT NULL)');233 $Row = $DbResult->fetch_row();234 $TotalDeviceCost = $Row[0];235 $Output .= 'Celková cena zařízení: Zařízení('.$TotalDeviceCost;236 242 237 243 $DbResult = $this->Database->query('SELECT SUM(NetworkDevice) FROM MemberPayment'); … … 279 285 $Output .= 'Aktualizuji služby....<br>'; 280 286 $this->TableUpdatePeriod('Service'); 287 281 288 // Update customer service selections 282 289 $Output .= 'Aktualizuji výběr služeb zákazníků....<br>'; … … 343 350 '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Částka [Kč]</th></tr>'."\n"; 344 351 $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, (Value*Direction) AS Value, File FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '. 345 '(SELECT CONCAT(`Text`, (SELECT GROUP_CONCAT(`Description` SEPARATOR "<br/>") FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`)) AS `Text`, Time, - Valueas Value, File FROM FinanceInvoice WHERE (Subject='.352 '(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='. 346 353 $Member['Subject'].')) ORDER BY Time DESC) AS T1 WHERE (T1.Time > "'.$Member['BillingPeriodLastDate'].'")'); 347 354 while($DbRow = $DbResult->fetch_assoc())
Note:
See TracChangeset
for help on using the changeset viewer.