Monday, June 30, 2014

PHP CALCULATION FROM MYSQL


PHP CALCULATION FROM MYSQL

    require_once('functions.php');
    $user = new User;
    if (!$user->isLoggedIn) {
        die(header("location: login.php"));
    }
$cid = $_GET['cid'];
$sql11 = "SELECT * FROM customer where cid = '$cid' ";
$result11 = mysqli_query($connect, $sql11);
$rs = mysqli_fetch_object($result11);
$ob = $rs->cob;
// select customer
$sql0 = "SELECT * FROM customer WHERE cid = '$cid'";
$result0 = mysqli_query($connect, $sql0) or die("Error: " . mysqli_error($connect));
$row0 = mysqli_fetch_array($result0);
//select sales num
$result2 = mysqli_query($connect, "SELECT * FROM tran WHERE cid='$cid' AND ssn != 0") or die("Error: " . mysqli_error($connect));
$row2 = mysqli_fetch_array($result2);
$n = mysqli_num_rows($result2);
//select receipt num
$result3 = mysqli_query($connect, "SELECT * FROM tran WHERE cid='$cid' AND rsn != '0'") or die("Error: " . mysqli_error($connect));
$row3 = mysqli_fetch_array($result3);
$n1 = mysqli_num_rows($result3);
$result4 = mysqli_query($connect, "SELECT sum(samt), sum(ramt) FROM tran WHERE cid='$cid'") or die("Error: " . mysqli_error($connect));
$row4 = mysqli_fetch_array($result4);
$TotalSales = $row4['sum(samt)'];
$TotalReceipt = $row4['sum(ramt)'];
$balance = $ob + $TotalSales - $TotalReceipt;
echo "

   
        Date
        Sales No.
        Receipt No.
        Sales
        Receipt
        Balance
   
   
        Opening Balance
        Rs." . number_format(($ob), 2, '.', ',') . "
   
";// select tran
$sql = "SELECT * FROM tran WHERE cid = '$cid' ORDER BY date";
$result = mysqli_query($connect, $sql) or die("Error: " . mysqli_error($connect));
while($row = mysqli_fetch_array($result)) {
echo "
   
        " . $row['date'] . "
        ";
        if ($row['sref'] > 0) {
        echo "" . $row['sref'];
        } else {
            echo " ";
        }
        echo "
       
        ";
        if ($row['rref'] > 0) {
        echo "" . $row['rref'] . "";
        } else {
            echo " ";
        }
        echo "
";        if ($row['samt'] > 0) {
        echo "Rs." . number_format(($row['samt']), 2, '.', ',') . "";
        } else {
            echo "-";
        }
        if ($row['ramt'] > 0) {
        echo "Rs." . number_format(($row['ramt']), 2, '.', ',') . "";
        } else {
            echo "-";
        }
        echo "
        Rs." . // . number_format(($rowbal), 2, '.', ',') . 
        "
   
";    }
echo "
   
        Total:
        " . $n . " Sale(s)
        " . $n1 . " Receipt(s)
        Rs. "  . number_format(($TotalSales), 2, '.', ',') . "
        Rs. "  . number_format(($TotalReceipt), 2, '.', ',') . "
        Rs. "  . number_format(($balance), 2, '.', ',') . "
   

";?>

No comments:

Post a Comment