-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetreturntoequity.php
142 lines (127 loc) · 3.81 KB
/
getreturntoequity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/* get the data for the Return to Equity Ratio chart
query:
net_income = income_totals->net_income
equity = equity_totals->total_capital
Ratio = net_income * 100 / equity
author: 76East
last modified on: 150506 for rounding of y-axis
*/
include("db_connect.php");
$q=$_GET["q"];
$t=$_GET["d"];
$array=array();
$banks=explode(",",$q);
$dates=explode(",",$t);
$countdates=count($dates);
$countbanks=count($banks);
if($countbanks > '1' && $countdates=='1' ){
for($bank=0;$bank<count($banks);$bank++){
$arr = "";
$arr1=array();
$sql_query = "select b.bank_name , eq.total_capital , it.net_income from income_totals it LEFT JOIN equity_totals eq on
(eq.transaction_date=it.transaction_date and eq.bank_id='".$banks[$bank]."') left join banks b on
(b.bank_id='".$banks[$bank]."')
where it.transaction_date='".$t."' and it.bank_id='".$banks[$bank]."'";
$result = mysql_query($sql_query);
$num_rows = mysql_num_rows($result);
if($num_rows>0){
while($res = mysql_fetch_array($result)){
$netincome= floatval($res['net_income']/1000);
$equity= floatval($res['total_capital']/1000);
if($equity==null || $equity==0 || $equity==''){
$ratio=null;
}
else{
$ratio=($netincome*100)/$equity;
}
$ty= $res['bank_name'];
array_push($arr1,round($ratio, 2));
}
}
else{
array_push($arr1,null);
$ty=null;
}
$stack=array($ty);
foreach($arr1 as $s){
array_push($stack,$s);
}
array_push($array,$stack);
}
echo (json_encode($array));
}
else if($countbanks=='1' && $countdates > '1'){
for($date=0;$date<count($dates);$date++){
$arr = "";
$arr1=array();
$sql_query = "select it.transaction_date,eq.total_capital,it.net_income from income_totals it LEFT JOIN equity_totals eq on
(eq.transaction_date=it.transaction_date and eq.bank_id=it.bank_id)
where it.transaction_date='".$dates[$date]."' and it.bank_id='".$q."'";
$result = mysql_query($sql_query);
$num_rows = mysql_num_rows($result);
if($num_rows>0){
while($res = mysql_fetch_array($result)){
$netincome= floatval($res['net_income']/1000);
$equity= floatval($res['total_capital']/1000);
if($equity==null || $equity==0 || $equity==''){
$ratio=null;
}
else{
$ratio=($netincome*100)/$equity;
}
$ty= $res['transaction_date'];
array_push($arr1,round($ratio, 2));
}
}
else{
array_push($arr1,null);
$ty=$dates[$date];
}
$stack=array($ty);
foreach($arr1 as $s){
array_push($stack,$s);
}
array_push($array,$stack);
}
echo (json_encode($array));
}
else if($countbanks > '1' && $countdates > '1'){
for($i=0;$i<count($dates);$i++){
$arr = "";
$arr1=array();
for($j=0;$j<count($banks);$j++){
$sql_query = "select it.transaction_date,eq.total_capital,it.net_income from income_totals it LEFT JOIN equity_totals eq on
(eq.transaction_date=it.transaction_date and eq.bank_id=it.bank_id) left join banks b on
(b.bank_id=eq.bank_id)
where it.transaction_date='".$dates[$i]."' and it.bank_id='".$banks[$j]."'";
$result = mysql_query($sql_query);
$num_rows = mysql_num_rows($result);
if($num_rows>0){
while($res = mysql_fetch_array($result)){
$netincome= floatval($res['net_income']/1000);
$equity= floatval($res['total_capital']/1000);
if($equity==null || $equity==0 || $equity==''){
$ratio=null;
}
else{
$ratio=($netincome*100)/$equity;
}
$ty= $res['transaction_date'];
array_push($arr1,round($ratio, 2));
}
}
else{
array_push($arr1,null);
$ty=$dates[$i];
}
}
$stack=array($ty);
foreach($arr1 as $s){
array_push($stack,$s);
}
array_push($array,$stack);
}
echo (json_encode($array));
}
?>