Changeset 726 for trunk/Modules/Finance/Manage.php
- Timestamp:
- Jan 5, 2015, 10:01:40 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Manage.php
r724 r726 54 54 '(SELECT GROUP_CONCAT(`Service`.`Name`) FROM `ServiceCustomerRel` LEFT JOIN `Service` '. 55 55 'ON `Service`.`Id`=`ServiceCustomerRel`.`Service` WHERE `ServiceCustomerRel`.`Customer`=`Member`.`Id` AND '. 56 '`ServiceCustomerRel`.` Action` IS NULL) AS `ServicesNextMonth`, '.56 '`ServiceCustomerRel`.`ChangeAction` IS NULL) AS `ServicesNextMonth`, '. 57 57 'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`) AS `LastDate`, `Subject`.`Name` AS `SubjectName`, '. 58 58 '`FinanceBillingPeriod`.`Name` AS `BillingPeriodName` '. … … 156 156 'ON `Service`.`Id`=`ServiceCustomerRel`.`Service` '. 157 157 'WHERE (`ServiceCustomerRel`.`Customer`='. 158 $Member['Id'].') AND (`ServiceCustomerRel`.` Action` IS NULL) ');158 $Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL) '); 159 159 while($Service = $DbResult2->fetch_assoc()) 160 160 { … … 192 192 } 193 193 194 function TableUpdatePeriod($Table) 195 { 196 $DbResult = $this->Database->select($Table, '*', '`Action` IS NOT NULL'); 194 function TableUpdateChanges($Table) 195 { 196 $Time = time(); 197 $DbResult = $this->Database->select($Table, '*', '(`ChangeAction` IS NOT NULL) AND '. 198 '(`ChangeTime` <= "'.TimeToMysqlDateTime($Time).'") ORDER BY `ChangeTime` ASC'); 197 199 while($Service = $DbResult->fetch_array()) 198 200 { 199 if($Service[' Action'] == 'add')201 if($Service['ChangeAction'] == 'add') 200 202 { 201 203 unset($Service['Id']); 202 unset($Service[' ReplaceId']);203 unset($Service[' Action']);204 unset($Service['ChangeReplaceId']); 205 unset($Service['ChangeAction']); 204 206 $this->Database->insert($Table, $Service); 205 207 } else 206 if($Service[' Action'] == 'modify')208 if($Service['ChangeAction'] == 'modify') 207 209 { 208 210 unset($Service['Id']); 209 unset($Service[' Action']);210 $ReplaceId = $Service[' ReplaceId'];211 unset($Service[' ReplaceId']);211 unset($Service['ChangeAction']); 212 $ReplaceId = $Service['ChangeReplaceId']; 213 unset($Service['ChangeReplaceId']); 212 214 $this->Database->update($Table, 'Id='.$ReplaceId, $Service); 213 215 } else 214 if($Service[' Action'] == 'delete')216 if($Service['ChangeAction'] == 'delete') 215 217 { 216 218 $this->Database->delete($Table, '`Id`='.$Service['ReplaceId']); 217 219 } 218 220 } 219 $this->Database->delete($Table, '`Action` IS NOT NULL'); 220 } 221 221 $this->Database->delete($Table, '(`ChangeAction` IS NOT NULL) AND (`ChangeTime` <= "'.TimeToMysqlDateTime($Time).'")'); 222 } 223 224 function ProcessTableUpdates() 225 { 226 // Update finance charge 227 $Output = 'Měním aktuální parametry sítě...<br>'; 228 $this->TableUpdateChanges('FinanceCharge'); 229 230 // Update services 231 $Output .= 'Aktualizuji služby....<br>'; 232 $this->TableUpdateChanges('Service'); 233 234 // Update customer service selections 235 $Output .= 'Aktualizuji výběr služeb zákazníků....<br>'; 236 $this->TableUpdateChanges('ServiceCustomerRel'); 237 238 return($Output); 239 } 240 222 241 function ProcessMonthlyPayment() 223 242 { … … 225 244 $Output = ''; 226 245 246 $Output .= $this->ProcessTableUpdates(); 247 227 248 $Finance = &$this->System->Modules['Finance']; 228 249 $Finance->LoadMonthParameters(0); 229 250 230 251 // Načti poslední měsíční přehled a nastavení 231 $DbResult = $this->Database->select('FinanceMonthlyOverall', '*', '1 ORDER BY DateDESC LIMIT 1');252 $DbResult = $this->Database->select('FinanceMonthlyOverall', '*', '1 ORDER BY `Date` DESC LIMIT 1'); 232 253 $Overall = $DbResult->fetch_array(); 233 254 234 $Output -= 'Datum: '.date('j.n.Y').'<br />';255 $Output .= 'Datum: '.date('j.n.Y').'<br />'; 235 256 236 257 $DateParts = explode('-', $Overall['Date']); … … 240 261 $Output .= $Finance->RecalculateMemberPayment(); 241 262 242 $DbResult = $this->Database->query('SELECT SUM(NetworkDevice) FROM MemberPayment'); 243 $Row = $DbResult->fetch_row(); 244 $TotalMemberDeviceCost = $Row[0]; 245 $Output .= '), Členové('.$TotalMemberDeviceCost.')<br />'; 246 247 $DbResult = $this->Database->query('SELECT SUM(Cash) FROM MemberPayment'); 263 $DbResult = $this->Database->query('SELECT SUM(`Cash`) FROM `MemberPayment`'); 248 264 $Row = $DbResult->fetch_row(); 249 265 $TotalMemberCash = $Row[0]; 250 266 $Output .= 'Stav pokladny: Členové('.$TotalMemberCash.')'; 251 267 252 $DbResult = $this->Database->query('SELECT SUM(Product.Consumption) AS Consumption FROM StockSerialNumber '. 253 'JOIN Product ON StockSerialNumber.Product = Product.Id WHERE (StockSerialNumber.TimeElimination IS NULL) '. 254 'AND (StockSerialNumber.Segment IS NOT NULL)'); 268 $DbResult = $this->Database->query('SELECT SUM(`Product`.`Consumption`) AS `Consumption` FROM `StockSerialNumber` '. 269 'JOIN `Product` ON `StockSerialNumber`.`Product` = `Product`.`Id` WHERE (`StockSerialNumber`.`TimeElimination` IS NULL) '); 255 270 $Row = $DbResult->fetch_row(); 256 271 $TotalConsumption = $Row[0]; … … 266 281 $Output .= 'Odečítám měsíční poplatek...<br />'; 267 282 $Output .= $this->ProduceInvoices(); 268 269 // Update finance charge 270 $Output .= 'Měním aktuální parametry sítě...<br>'; 271 $this->TableUpdatePeriod('FinanceCharge'); 272 283 273 284 $Output .= 'Přidávám měsíční přehled...<br />'; 274 $DbResult = $this->Database->query('SELECT * FROM FinanceCharge WHERE Action IS NULLLIMIT 1');285 $DbResult = $this->Database->query('SELECT * FROM `FinanceCharge` WHERE (`ChangeAction` IS NULL) LIMIT 1'); 275 286 $Charge = $DbResult->fetch_assoc(); 276 287 $this->Database->insert('FinanceMonthlyOverall', array('Date' => 'NOW()', … … 281 292 'TopTariffPrice' => $Charge['TopTariffPrice'], 'MemberCount' => $Finance->InternetUsers)); 282 293 283 // Update services284 $Output .= 'Aktualizuji služby....<br>';285 $this->TableUpdatePeriod('Service');286 287 // Update customer service selections288 $Output .= 'Aktualizuji výběr služeb zákazníků....<br>';289 $this->TableUpdatePeriod('ServiceCustomerRel');290 291 294 $Finance->RecalculateMemberPayment(); 292 295 //CreateMonthlyOverallBill(); … … 335 338 $DbResult = $this->Database->query('SELECT GROUP_CONCAT(Service.Name) AS Name FROM ServiceCustomerRel LEFT JOIN Service '. 336 339 'ON Service.Id=ServiceCustomerRel.Service WHERE (ServiceCustomerRel.Customer='.$Member['Id'].') '. 337 'AND ServiceCustomerRel. Action IS NULL');340 'AND ServiceCustomerRel.ChangeAction IS NULL'); 338 341 $Service = $DbResult->fetch_assoc(); 339 342 $Content .= '<strong>'.$Service['Name'].'</strong><br />'."\n".
Note:
See TracChangeset
for help on using the changeset viewer.