Changeset 185 for trunk/finance/finance.php
- Timestamp:
- Apr 3, 2009, 10:32:35 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/finance/finance.php
r171 r185 23 23 var $ExternalSubject = 96; 24 24 var $MainSubject = 71; 25 var $BillingPeriods; 25 26 26 27 function RecalculateTariffs($Period = 1) … … 98 99 function LoadMonthParameters($Period = 1) // 0 - now, 1 - next month 99 100 { 100 $DbResult = $this->Database->query("SELECT * FROM finance_charge WHERE period=".$Period); 101 $DbResult = $this->Database->query('SELECT * FROM FinanceBillingPeriod'); 102 while($BillingPeriod = $DbResult->fetch_assoc()) 103 $this->BillingPeriods[$BillingPeriod['Id']] = $BillingPeriod; 104 105 $DbResult = $this->Database->query('SELECT * FROM finance_charge WHERE period='.$Period); 101 106 $Row = $DbResult->fetch_array(); 102 107 $this->kWh = $Row['kWh']; … … 140 145 return($Result); 141 146 } 147 148 function RecalculateMemberPayment() 149 { 150 $Output = 'Aktualizuju finance členů...<br />'; 151 $this->Database->query('TRUNCATE TABLE MemberPayment'); 152 $DbResult = $this->Database->query('SELECT * FROM Member'); 153 while($Member = $DbResult->fetch_assoc()) 154 { 155 $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(Value), 0) FROM FinanceOperation WHERE Subject='.$Member['Subject'].') + (SELECT COALESCE(SUM(-Value), 0) FROM FinanceClaimsLiabilities WHERE Subject='.$Member['Subject'].')) as Cash'); 156 $Cash = $DbResult2->fetch_row(); 157 $Cash = $Cash[0]; 158 159 $DbResult2 = $this->Database->query('SELECT SUM(consumption) FROM network_devices WHERE (user='.$Member['Id'].') AND (used = 1)'); 160 $ConsumptionPlus = $DbResult2->fetch_row(); 161 $ConsumptionPlus = $ConsumptionPlus[0]; 162 163 $NetworkDevice = 0; 164 $Consumption = 0; 165 $ID = $Member['NetworkSegment']; 166 while($ID != 0) 167 { 168 $DbResult2 = $this->Database->query('SELECT * FROM network_segments WHERE id='.$ID); 169 $Device = $DbResult2->fetch_assoc(); 170 $NetworkDevice += $Device['price'] / $Device['users']; 171 $Consumption += $Device['consumption'] / $Device['users_overheads']; 172 //echo($ID.' '.$InternetSegment.' '.$InternetSegmentId.' '.$Row['inet_hw'].' '.$Price.'<br>'); 173 $ID = $Device['parent']; 174 } 175 176 $Monthly = 0; 177 $MonthlyInet = $this->Tarify[$Member['InternetTariffNextMonth']]['price']; 178 //if($Row['inet'] == 1) 179 $Monthly += $MonthlyInet; 180 $Monthly -= $this->W2Kc($ConsumptionPlus); 181 //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption); 182 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>'); 183 $Monthly = round($Monthly); 184 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>'); 185 186 $this->Database->insert('MemberPayment', array('Member' => $Member['Id'], 'NetworkDevice' => $NetworkDevice, 'MonthlyInternet' => $MonthlyInet, 'MonthlyTotal' => $Monthly, 'MonthlyConsumption' => $this->W2Kc($Consumption), 'Cash' => $Cash, 'MonthlyPlus' => $this->W2Kc($ConsumptionPlus))); 187 } 188 $this->System->Modules['Log']->NewRecord('Finance', 'RecalculateMemberPayment'); 189 return($Output); 190 } 191 192 function RecalculateSegmentParameters() 193 { 194 $Output = 'Aktualizuju parametry segmentů...<br />'; 195 $this->Database->query('UPDATE network_segments SET users = 0, users_overheads = 0'); // Vynulovat počty uživatelů 196 $DbResult = $this->Database->query('SELECT * FROM network_segments'); 197 while($NetworkSegment = $DbResult->fetch_array()) 198 { 199 //echo('Segment '.$Row['name'].'<br>'); 200 $DbResult2 = $this->Database->query('SELECT users FROM network_segments WHERE id='.$NetworkSegment['id']); 201 $RowP = $DbResult2->fetch_array(); 202 $DbResult2 = $this->Database->query('SELECT users_overheads FROM network_segments WHERE id='.$NetworkSegment['id']); 203 $RowP2 = $DbResult2->fetch_array(); 204 205 $DbResult2 = $this->Database->query('SELECT SUM(price) as Price, SUM(consumption) as Consumption FROM network_devices WHERE segment='.$NetworkSegment['id'].' AND used=1'); 206 $Row2 = $DbResult2->fetch_array(); 207 $DbResult2 = $this->Database->query('SELECT COUNT(*) FROM Member WHERE NetworkSegment='.$NetworkSegment['id']); 208 $Row3 = $DbResult2->fetch_array(); 209 $ID = $NetworkSegment['parent']; 210 while($ID != 0) 211 { 212 //echo($ID.', '); 213 $DbResult2 = $this->Database->query('SELECT * FROM network_segments WHERE id='.$ID); 214 $Row4 = $DbResult2->fetch_array(); 215 $this->Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users'] + $Row3[0]), 'users_overheads' => ($Row4['users_overheads'] + $Row3[0]))); 216 $ID = $Row4['parent']; 217 } 218 //echo('Pocet '.$Row3[0].','.$Row['hosts'].'<br>'); 219 $this->Database->update('network_segments', 'id='.$NetworkSegment['id'], array('price' => $Row2['Price'], 'users' => ($Row3[0] + $RowP['users']), 'consumption' => $Row2['Consumption'], 'users_overheads' => ($Row3[0] + $RowP2['users_overheads']))); 220 } 221 222 // Zkorigovat segment Internet 223 $DbResult = $this->Database->select('Member', 'COUNT(*)'); 224 $Row = $DbResult->fetch_array(); 225 $DbResult = $this->Database->update('network_segments','id='.$this->InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row[0])); 226 $this->System->Modules['Log']->NewRecord('Finance', 'RecalculateSegmentParameters'); 227 return($Output); 228 } 142 229 } 143 230
Note:
See TracChangeset
for help on using the changeset viewer.