These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | $no_refresh = true; |
||
4 | |||
5 | if ($_POST['addbill'] == 'yes') { |
||
6 | if ($_SESSION['userlevel'] < 10) { |
||
7 | include 'includes/error-no-perm.inc.php'; |
||
8 | exit; |
||
9 | } |
||
10 | |||
11 | $updated = '1'; |
||
12 | |||
13 | View Code Duplication | if (isset($_POST['bill_quota']) or isset($_POST['bill_cdr'])) { |
|
14 | if ($_POST['bill_type'] == 'quota') { |
||
15 | if (isset($_POST['bill_quota_type'])) { |
||
16 | if ($_POST['bill_quota_type'] == 'MB') { |
||
17 | $multiplier = (1 * $config['billing']['base']); |
||
18 | } |
||
19 | |||
20 | if ($_POST['bill_quota_type'] == 'GB') { |
||
21 | $multiplier = (1 * $config['billing']['base'] * $config['billing']['base']); |
||
22 | } |
||
23 | |||
24 | if ($_POST['bill_quota_type'] == 'TB') { |
||
25 | $multiplier = (1 * $config['billing']['base'] * $config['billing']['base'] * $config['billing']['base']); |
||
26 | } |
||
27 | |||
28 | $bill_quota = (is_numeric($_POST['bill_quota']) ? $_POST['bill_quota'] * $config['billing']['base'] * $multiplier : 0); |
||
29 | $bill_cdr = 0; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | if ($_POST['bill_type'] == 'cdr') { |
||
34 | if (isset($_POST['bill_cdr_type'])) { |
||
35 | if ($_POST['bill_cdr_type'] == 'Kbps') { |
||
36 | $multiplier = (1 * $config['billing']['base']); |
||
37 | } |
||
38 | |||
39 | if ($_POST['bill_cdr_type'] == 'Mbps') { |
||
40 | $multiplier = (1 * $config['billing']['base'] * $config['billing']['base']); |
||
41 | } |
||
42 | |||
43 | if ($_POST['bill_cdr_type'] == 'Gbps') { |
||
44 | $multiplier = (1 * $config['billing']['base'] * $config['billing']['base'] * $config['billing']['base']); |
||
45 | } |
||
46 | |||
47 | $bill_cdr = (is_numeric($_POST['bill_cdr']) ? $_POST['bill_cdr'] * $multiplier : 0); |
||
48 | $bill_quota = 0; |
||
49 | } |
||
50 | } |
||
51 | }//end if |
||
52 | |||
53 | $insert = array( |
||
54 | 'bill_name' => $_POST['bill_name'], |
||
55 | 'bill_type' => $_POST['bill_type'], |
||
56 | 'bill_cdr' => $bill_cdr, |
||
57 | 'bill_day' => $_POST['bill_day'], |
||
58 | 'bill_quota' => $bill_quota, |
||
59 | 'bill_custid' => $_POST['bill_custid'], |
||
60 | 'bill_ref' => $_POST['bill_ref'], |
||
61 | 'bill_notes' => $_POST['bill_notes'], |
||
62 | 'rate_95th_in' => 0, |
||
63 | 'rate_95th_out' => 0, |
||
64 | 'rate_95th' => 0, |
||
65 | 'dir_95th' => 'in', |
||
66 | 'total_data' => 0, |
||
67 | 'total_data_in' => 0, |
||
68 | 'total_data_out' => 0, |
||
69 | 'rate_average' => 0, |
||
70 | 'rate_average_in' => 0, |
||
71 | 'rate_average_out' => 0, |
||
72 | 'bill_last_calc' => array('NOW()'), |
||
73 | 'bill_autoadded' => 0, |
||
74 | ); |
||
75 | |||
76 | $bill_id = dbInsert($insert, 'bills'); |
||
77 | |||
78 | if (is_numeric($bill_id) && is_numeric($_POST['port'])) { |
||
79 | dbInsert(array('bill_id' => $bill_id, 'port_id' => $_POST['port']), 'bill_ports'); |
||
80 | } |
||
81 | |||
82 | header('Location: /' . generate_url(array('page' => 'bill', 'bill_id' => $bill_id, 'view' => 'edit'))); |
||
83 | exit(); |
||
84 | } |
||
85 | |||
86 | $pagetitle[] = 'Billing'; |
||
87 | |||
88 | echo "<meta http-equiv='refresh' content='10000'>"; |
||
89 | |||
90 | if ($vars['view'] == 'history') { |
||
91 | include 'pages/bills/search.inc.php'; |
||
92 | include 'pages/bills/pmonth.inc.php'; |
||
93 | } |
||
94 | else { |
||
95 | include 'pages/bills/search.inc.php'; |
||
96 | include 'includes/modal/new_bill.inc.php'; |
||
97 | ?> |
||
98 | <table class="table table-striped"> |
||
99 | <thead> |
||
100 | <th>Billing name</th> |
||
101 | <th></th> |
||
102 | <th>Type</th> |
||
103 | <th>Allowed</th> |
||
104 | <th>Used</th> |
||
105 | <th>Overusage</th> |
||
106 | <th></th> |
||
107 | <th></th> |
||
108 | </thead> |
||
109 | <tbody> |
||
110 | <?php |
||
111 | $wheres = array(); |
||
112 | $params = array(); |
||
113 | |||
114 | View Code Duplication | if (!empty($_GET['search'])) { |
|
0 ignored issues
–
show
|
|||
115 | $wheres[] = 'bills.bill_name LIKE ?'; |
||
116 | $params[] = '%'.$_GET['search'].'%'; |
||
117 | } |
||
118 | View Code Duplication | if (!empty($_GET['bill_type'])) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
119 | $wheres[] = 'bill_type = ?'; |
||
120 | $params[] = $_GET['bill_type']; |
||
121 | } |
||
122 | View Code Duplication | if ($_GET['state'] === 'under') { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
123 | $wheres[] = "((bill_type = 'cdr' AND rate_95th <= bill_cdr) OR (bill_type = 'quota' AND total_data <= bill_quota))"; |
||
124 | } else if ($_GET['state'] === 'over') { |
||
125 | $wheres[] = "((bill_type = 'cdr' AND rate_95th > bill_cdr) OR (bill_type = 'quota' AND total_data > bill_quota))"; |
||
126 | } |
||
127 | |||
128 | $query = 'SELECT * |
||
129 | FROM `bills` |
||
130 | '; |
||
131 | View Code Duplication | if (sizeof($wheres) > 0) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
132 | $query .= 'WHERE ' . implode(' AND ', $wheres) . "\n"; |
||
133 | } |
||
134 | $query .= 'ORDER BY bills.bill_name'; |
||
135 | |||
136 | foreach (dbFetchRows($query, $params) as $bill) { |
||
137 | if (bill_permitted($bill['bill_id'])) { |
||
138 | unset($class); |
||
139 | $day_data = getDates($bill['bill_day']); |
||
140 | $datefrom = $day_data['0']; |
||
141 | $dateto = $day_data['1']; |
||
142 | $rate_data = $bill; |
||
143 | $rate_95th = $rate_data['rate_95th']; |
||
144 | $dir_95th = $rate_data['dir_95th']; |
||
145 | $total_data = $rate_data['total_data']; |
||
146 | $rate_average = $rate_data['rate_average']; |
||
147 | |||
148 | if ($bill['bill_type'] == 'cdr') { |
||
149 | $type = 'CDR'; |
||
150 | $allowed = format_si($bill['bill_cdr']).'bps'; |
||
151 | $used = format_si($rate_data['rate_95th']).'bps'; |
||
152 | $percent = round((($rate_data['rate_95th'] / $bill['bill_cdr']) * 100), 2); |
||
153 | $background = get_percentage_colours($percent); |
||
154 | $overuse = ($rate_data['rate_95th'] - $bill['bill_cdr']); |
||
155 | $overuse = (($overuse <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_si($overuse).'bps</span>'); |
||
156 | } |
||
157 | else if ($bill['bill_type'] == 'quota') { |
||
158 | $type = 'Quota'; |
||
159 | $allowed = format_bytes_billing($bill['bill_quota']); |
||
160 | $used = format_bytes_billing($rate_data['total_data']); |
||
161 | $percent = round((($rate_data['total_data'] / ($bill['bill_quota'])) * 100), 2); |
||
162 | $background = get_percentage_colours($percent); |
||
163 | $overuse = ($rate_data['total_data'] - $bill['bill_quota']); |
||
164 | $overuse = (($overuse <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_bytes_billing($overuse).'</span>'); |
||
165 | } |
||
166 | |||
167 | $right_background = $background['right']; |
||
168 | $left_background = $background['left']; |
||
169 | ?> |
||
170 | <tr> |
||
171 | <td> |
||
172 | <a href='<?php echo generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'])) ?>'><span style='font-weight: bold;' class=interface><?php echo $bill['bill_name'] ?></span></a> |
||
173 | <br /> |
||
174 | <?php echo strftime('%F', strtotime($datefrom)) ?> to <?php echo strftime('%F', strtotime($dateto)) ?> |
||
175 | </td> |
||
176 | <td><?php echo $notes ?></td> |
||
177 | <td><?php echo $type ?></td> |
||
178 | <td><?php echo $allowed ?></td> |
||
179 | <td><?php echo $used ?></td> |
||
180 | <td style="text-align: center;"><?php echo $overuse ?></td> |
||
181 | <td><?php echo print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right'])?></td> |
||
182 | <td> |
||
183 | <?php if ($_SESSION['userlevel'] >= 10) { ?> |
||
184 | <a href='<?php echo generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'edit')) ?>'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a> |
||
185 | <?php } ?> |
||
186 | </td> |
||
187 | </tr> |
||
188 | <?php } |
||
189 | }?> |
||
190 | </tbody> |
||
191 | </table> |
||
192 | <?php |
||
193 | if ($vars['view'] == 'add') { |
||
194 | ?> |
||
195 | <script type="text/javascript"> |
||
196 | $(function() { |
||
197 | $('#create-bill').modal('show'); |
||
198 | }); |
||
199 | </script> |
||
200 | <?php |
||
201 | } |
||
202 | } |
||
203 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.