-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_financial.php
More file actions
68 lines (66 loc) · 2 KB
/
graph_financial.php
File metadata and controls
68 lines (66 loc) · 2 KB
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
<?php
include("db.php");
$i = '0';
$total = '0';
$subtotal = '0';
if(isset($_GET['date_from'])){
$date_from = $_GET['date_from'];
$date_to = $_GET['date_to'];
$date_from = date('Y-m-d', strtotime($date_from));
$date_to = date('Y-m-d', strtotime($date_to));
}else{
$date_to = date('Y-m-d');
$date_from = date('Y-m-d', strtotime($date_to. ' -180 days'));
}
$s = " CALL PROC_FINANCIAL_PL('PROFIT', '$date_from', '$date_to', '$company_email')";
$sql = $conn->query($s);
$ia = 0;
$new = array();
$n = array();
while($row = $sql->fetch_assoc()){
if($row['group'] == "Income"){
$account_id = $row['group'];
if(!isset($new[$account_id])){
$new[$account_id] = array();
$new[$account_id][1] = 0;
}
$income = $row['credit_tot'] - $row['debit_tot'];
$new[$account_id][0] = $row['group'];
$new[$account_id][1] += $income;
$total += $income;
$subtotal += $income;
}
if($row['group'] == "Cost of Goods Sold"){
$account_id = $row['group'];
if(!isset($new[$account_id])){
$new[$account_id] = array();
$new[$account_id][1] = 0;
}
$debit_tot = $row['debit_tot'];
$credit_tot = $row['credit_tot'];
$income = $debit_tot - $credit_tot;
$new[$account_id][0] = $row['group'];
$new[$account_id][1] += $income;
$total -= $income;
$subtotal += $income;
}
if($row['group'] == "Expenses"){
$account_id = $row['group'];
if(!isset($new[$account_id])){
$new[$account_id] = array();
$new[$account_id][1] = 0;
}
$debit_tot = $row['debit_tot'];
$credit_tot = $row['credit_tot'];
$income = $debit_tot - $credit_tot;
$new[$account_id][0] = $row['group'];
$new[$account_id][1] += $income;
$total -= $income;
$subtotal += $income;
}
}
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($new);
?>