-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_sales.php
More file actions
32 lines (32 loc) · 1.51 KB
/
graph_sales.php
File metadata and controls
32 lines (32 loc) · 1.51 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
<?php
include("db.php");
$result = '';
$diff = 'month';
$date_to = date('Y-m').'-01';
$date = $date_to;
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. ' -6 '.$diff.''));
}
$i=0;
$tot = '0';
$sql = "SELECT `name`, `name_id`, `id`, (SELECT SUM(total) FROM `transaction` WHERE `name_id` = t1.name_id AND (`entry_type` = 'create sales invoice' OR `entry_type` = 'create sales Receipt') AND `company_email` = '$company_email' AND `date` BETWEEN '$date_from' AND '$date_to') AS `add`, (SELECT SUM(total) FROM `transaction` WHERE `name_id` = t1.name_id AND `entry_type` = 'create sales return' AND `company_email` = '$company_email' AND `date` BETWEEN '$date_from' AND '$date_to') AS `less` FROM `transaction` t1 WHERE (`entry_type` = 'create sales invoice' OR `entry_type` = 'create sales Receipt' OR `entry_type` = 'create sales return') AND `company_email` = '$company_email' AND `date` BETWEEN '$date_from' AND '$date_to' GROUP BY `name`";
$new = $conn->query($sql);
while($row = $new->fetch_assoc()){
$id = $row['name_id'];
$total = $row['add'] - $row['less'];
$result[$i][0]=$row['name'];
$result[$i][1]=$total;
$i++;
$tot += $total;
}
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($result);
?>