<?php
include("db.php");
$start = date("Y-m-d");
$end = date("Y-m-d");

$mony_exp = mysqli_query($db,"SELECT sum(value_exp) as `all_mony` FROM `exp_mony`
where `date_exp` between '$start' and '$end'
");
$mony_exp_row = mysqli_fetch_assoc($mony_exp);
$mony_exp_count = $mony_exp_row['all_mony'];

$mony_cus = mysqli_query($db,"SELECT sum(paid) as `all_mony_stock` FROM `stock_mony`
where `date` between '$start' and '$end'
");
$mony_cus_row = mysqli_fetch_assoc($mony_cus);
$mony_cus_count = $mony_cus_row['all_mony_stock'];

$mo = "select sum(x) as `xx` from `mony` where `date` between '$start' and '$end'";
$m = mysqli_query($db,$mo);
$mm= mysqli_fetch_assoc($m);
$mmm = $mm['xx'];

$txt_tax = "select sum(p_f) as `p_f1` from `sales` where `date` between '$start' and '$end'";
$query_tax = mysqli_query($db,$txt_tax);
$row_tax = mysqli_fetch_assoc($query_tax);
$mony_tax = $row_tax['p_f1'];

$mony_inp = mysqli_query($db,"SELECT sum(value_inp) as `all_mony` FROM `inp_mony`
where `date_inp` between '$start' and '$end'
");
$mony_inp_row = mysqli_fetch_assoc($mony_inp);
$mony_inp_count = $mony_inp_row['all_mony'];

$data['m1'] = $mmm;
$data['m2'] = $mony_cus_count;
$data['m3'] = $mony_exp_count;
$data['m5'] = $mony_tax;
$data['m6'] = $mony_inp_count;

$mony = ($mmm + $mony_cus_count + $mony_tax + $mony_inp_count) - $mony_exp_count;
$data['m4'] = $mony;
echo json_encode($data);
?>
