Changeset 786 for trunk/Modules/Finance/Manage.php
- Timestamp:
- Jan 11, 2016, 12:06:08 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Manage.php
r773 r786 39 39 } 40 40 41 /* Get first day and last day of given billing period. Periods are aligned with year start/end. */ 41 42 function GetBillingPeriod($Period) 42 43 { 44 $Time = time(); 45 $Year = date('Y', $Time); 46 43 47 $MonthCount = $this->System->Modules['Finance']->BillingPeriods[$Period]['MonthCount']; 44 $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y')); 45 $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y')); 48 if($MonthCount <= 0) return(array('From' => NULL, 'To' => NULL, 'MonthCount' => 0)); 49 $MonthCurrent = date('n', $Time); 50 51 /* Get start and end of aligned period */ 52 $MonthFrom = floor(($MonthCurrent - 1) / $MonthCount) + 1; 53 $MonthTo = $MonthFrom + $MonthCount - 1; 54 55 /* Use period from current month to end month so months before current month are cut out */ 56 $MonthCount = $MonthTo - $MonthCurrent + 1; 57 $MonthFrom = $MonthCurrent; 58 59 /* Get first and last day of period */ 60 $PeriodFrom = mktime(0, 0, 0, $MonthFrom, 1, $Year); 61 $PeriodTo = mktime(0, 0, 0, $MonthTo, date('t', mktime(0, 0, 0, $MonthTo, 1, $Year)), $Year); 62 46 63 return(array('From' => $PeriodFrom, 'To' => $PeriodTo, 'MonthCount' => $MonthCount)); 47 64 } … … 59 76 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` JOIN `Subject` '. 60 77 'ON `Subject`.`Id`=`Member`.`Subject` LEFT JOIN `FinanceBillingPeriod` ON '. 61 '`FinanceBillingPeriod`.`Id`=`Member`.`BillingPeriod Next` WHERE (`Member`.`Blocked` = 0)'.62 'AND (`Member`.`BillingPeriod Next` > 1) AND (`MemberPayment`.`MonthlyTotal` != 0)';78 '`FinanceBillingPeriod`.`Id`=`Member`.`BillingPeriod` WHERE (`Member`.`Blocked` = 0)'. 79 'AND (`Member`.`BillingPeriod` > 1) AND (`MemberPayment`.`MonthlyTotal` != 0)'; 63 80 64 81 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$SQL.') AS T'); … … 133 150 $Output = ''; 134 151 135 // Generuj účetní položky152 // Produce accounting items 136 153 $DbResult = $this->Database->query('SELECT `Member`.*, `MemberPayment`.`MonthlyTotal` AS `MonthlyTotal`, '. 137 154 'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`) AS `BillingPeriodLastUnixTime`, `Subject`.`Name` AS `SubjectName`,'. … … 142 159 { 143 160 $Output .= $Member['SubjectName'].': '; 144 $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']);145 if($Period['From'] > $Member['BillingPeriodLastUnixTime'])146 {147 $this->Database->update('Member', 'Id='.$Member['Id'],148 array('BillingPeriod' => $Member['BillingPeriodNext']));149 $Member['BillingPeriod'] = $Member['BillingPeriodNext'];150 }151 161 $Period = $this->GetBillingPeriod($Member['BillingPeriod']); 162 163 /* Check if need to produce new invoice for customer */ 152 164 if(($Period['MonthCount'] > 0) and ($Member['Blocked'] == 0) and 153 165 ($Period['From'] > $Member['BillingPeriodLastUnixTime'])) … … 170 182 // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction 171 183 // Other subject should invoice only positive items. Negative items should be somehow removed. 172 if($MonthlyTotal >= 0) { 184 if($MonthlyTotal >= 0) 185 { 173 186 $InvoiceGroupId = INVOICE_GROUP_OUT; 174 187 } else { … … 178 191 // Load invoice group 179 192 $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($InvoiceGroupId, 'FinanceInvoiceGroup'); 180 foreach($InvoiceItems as $Index => $Item) { 193 foreach($InvoiceItems as $Index => $Item) 194 { 181 195 $InvoiceItems[$Index]['Price'] = $Item['Price'] * $FinanceGroup['ValueSign']; 182 196 } … … 191 205 192 206 $Output .= $this->SendPaymentEmail($Member['Id']); 193 } else $Output .= '<br />'; 194 $this->Database->update('Member', 'Id='.$Member['Id'], 207 } 208 /* Update last billing day */ 209 $this->Database->update('Member', '`Id`='.$Member['Id'], 195 210 array('BillingPeriodLastDate' => TimeToMysqlDateTime($Period['To']))); 196 } else $Output .= '<br />'; 211 } 212 $Output .= '<br />'; 197 213 } 198 214 return($Output); … … 233 249 function ProcessTableUpdates() 234 250 { 251 // Update customers 252 $Output = 'Měním zákazníky...<br>'; 253 $this->TableUpdateChanges('Member'); 254 235 255 // Update finance charge 236 256 $Output = 'Měním aktuální parametry sítě...<br>'; … … 288 308 if($MonthCurrent != $MonthLast) 289 309 { 290 $Output .= 'Odečítám měsíčnípoplatek...<br />';310 $Output .= 'Odečítám pravidelný poplatek...<br />'; 291 311 $Output .= $this->ProduceInvoices(); 292 312 … … 302 322 303 323 $Finance->RecalculateMemberPayment(); 304 //CreateMonthlyOverallBill();305 //$Finance->RecalculateUsersFinance();306 324 307 325 // Restart traffic shaping … … 309 327 //flush(); 310 328 //$this->GenerateBills(); 329 $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'ProcessMonthlyPayment', $Output); 311 330 } 312 331 return($Output); … … 332 351 $MainSubject = $DbResult->fetch_assoc(); 333 352 334 $Period = $this->GetBillingPeriod($Member['BillingPeriod Next']);353 $Period = $this->GetBillingPeriod($Member['BillingPeriod']); 335 354 336 355 $DbResult = $this->Database->query('SELECT `FinanceBankAccount`.*, '. … … 382 401 $Output = ''; 383 402 } else $Output = 'Uživatel '.$User['Name'].' nemá email.'; 403 return $Output; 384 404 } 385 405
Note:
See TracChangeset
for help on using the changeset viewer.