Skip to content

Commit

Permalink
Refactoring plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-it committed May 11, 2017
1 parent 5fde183 commit f9eabc8
Showing 1 changed file with 42 additions and 32 deletions.
74 changes: 42 additions & 32 deletions inc/plugins/my_callrates.inc.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
<?php

function my_callrates() {
global $dbh, $db_name, $db_table_name, $group_by_field, $where, $result_limit, $graph_col_title, $callrate_csv_fileName;
global
$dbh,
$db_name,
$db_table_name,
$group_by_field,
$where,
$result_limit,
$graph_col_title,
$callrate_csv_fileName;

/**************************** Config ****************************************************/
$my_call_rates = array(
"Городские" => "(dst LIKE '2%' OR dst LIKE '7%') and (LENGTH(dst)=7)",
"Мобильные" => "(dst LIKE '89%') and (LENGTH(dst)=11)",
"Область" => "(dst LIKE '8351%') and (LENGTH(dst)=11)",
"Столицы" => "(dst LIKE '8495%' OR dst LIKE '8499%' OR dst LIKE '8812%') and (LENGTH(dst)=11)",
"Россия" => "(dst LIKE '8%') and (dst NOT LIKE '89%' and dst NOT LIKE '79%' and dst NOT LIKE '8351%' and dst NOT LIKE '8495%' and dst NOT LIKE '8499%' and dst NOT LIKE '8812%' and dst NOT LIKE '8800%') and (LENGTH(dst)=11)",
"Городские" => "(dst LIKE '2%' OR dst LIKE '7%') and (LENGTH(dst)=7)",
"Мобильные" => "(dst LIKE '89%') and (LENGTH(dst)=11)",
"Область" => "(dst LIKE '8351%') and (LENGTH(dst)=11)",
"Столицы" => "(dst LIKE '8495%' OR dst LIKE '8499%' OR dst LIKE '8812%') and (LENGTH(dst)=11)",
"Россия" => "(dst LIKE '8%') and (dst NOT LIKE '89%' and dst NOT LIKE '79%' and dst NOT LIKE '8351%' and dst NOT LIKE '8495%' and dst NOT LIKE '8499%' and dst NOT LIKE '8812%' and dst NOT LIKE '8800%') and (LENGTH(dst)=11)",
);

$my_callrates_csv_file = dirname(__FILE__) . '/' . $callrate_csv_fileName;

/****************************************************************************************/

$my_bill_tototal_q = "SELECT $group_by_field AS group_by_field FROM $db_table_name $where GROUP BY group_by_field ORDER BY group_by_field ASC LIMIT $result_limit";


$my_callrates_total = array();
foreach ( array_keys($my_call_rates) as $key ) {
$my_call_rates_total["$key"] = 0;
$my_call_rates_total[$key] = 0;
}
$my_call_rates_total["summ"] = 0;

echo '<p class="center title">Детализация звонков - Расход денежных средств</p><table class="cdr">
<tr>
<th>'.$graph_col_title.'</th>
<th colspan=5>Направление</th>
</tr>
<tr><th>&nbsp;</th>';
$my_call_rates_total['summ'] = 0;

echo '
<p class="center title">Детализация звонков - Расход денежных средств</p>
<table class="cdr">
<tr>
<th>'.$graph_col_title.'</th>
<th colspan="5">Направление</th>
</tr>
<tr><th>&nbsp;</th>
';

foreach ( array_keys($my_call_rates) as $key ) {
echo "<th>$key</th>";
}

echo "<th>Итого</th></tr>";
echo '<th>Итого</th></tr>';

try {
$sth = $dbh->query($my_bill_tototal_q);
Expand All @@ -50,46 +60,46 @@ function my_callrates() {

foreach ( $result as $row ) {
$summ = 0;
echo "<tr class=\"record\">";
echo '<td style="text-align:center;">'. $row[0] ."</td>";
echo '<tr class="record">';
echo '<td style="text-align:center;">'. $row[0] .'</td>';
foreach ( array_keys($my_call_rates) as $key ) {
$my_bill_ch_q = "SELECT dst, billsec FROM $db_table_name $where and $group_by_field = '". $row[0] ."' and " . $my_call_rates["$key"];
$my_bill_ch_q = "SELECT dst, billsec FROM $db_table_name $where and $group_by_field = '". $row[0] ."' and " . $my_call_rates[$key];
$summ_local = 0;

$sth2 = $dbh->query($my_bill_ch_q);
if (!$sth2) {
if ( !$sth2 ) {
echo "\nPDO::errorInfo():\n";
print_r($dbh->errorInfo());
}

while ($bill_row = $sth2->fetch(PDO::FETCH_NUM)) {
while ( $bill_row = $sth2->fetch(PDO::FETCH_NUM) ) {
$rates = callrates( $bill_row[0], $bill_row[1], $my_callrates_csv_file );
$summ_local += $rates[4];
}
$sth2 = NULL;

$my_call_rates_total["$key"] += $summ_local;
$my_call_rates_total[$key] += $summ_local;
$summ += $summ_local;
formatMoney($summ_local);
}
$my_call_rates_total["summ"] += $summ;
$my_call_rates_total['summ'] += $summ;
formatMoney($summ);
echo "</tr>";
echo '</tr>';

}
}
catch (PDOException $e) {
print $e->getMessage();
}

echo "<tr class=\"chart_data total\">";
echo "<td>Всего</td>";
echo '<tr class="chart_data total">';
echo '<td>Всего</td>';
foreach ( array_keys($my_call_rates_total) as $key ) {
formatMoney($my_call_rates_total["$key"]);
formatMoney($my_call_rates_total[$key]);
}
echo "</tr>";
echo '</tr>';

echo "</table>";
echo '</table>';
}

?>

0 comments on commit f9eabc8

Please sign in to comment.