function add_transaction()
{
    $json_trans = $_GET['trans'];
    $transaction = json_decode($json_trans);
    $total = $transaction->total;
    $phone_number = $transaction->phoneNumber;
    $phone_number = "'" . $phone_number . "'";
    $product_barcodes = $transaction->productBarcode;
    include_once 'transaction.php';
    $obj = new transaction();
    if (!$obj->connect()) {
        $json = "Failed to connect to the database.";
        echo $json;
    }
    if ($obj->add_transaction($phone_number, $total)) {
        include_once 'order.php';
        $order_obj = new order();
        $order_obj->connect();
        $trans_id = $obj->get_insert_id();
        $order_obj->add_orders($trans_id, $product_barcodes);
        if ($total > 500) {
            //            $message = "You have a 10% discount the next time you purchase.";
            //            send_smsgh($phone_number, $message);
        }
        $json = "The transaction was added.";
        echo $json;
    } else {
        $json = "The transaction was not added.";
        echo $json;
    }
}
Example #2
0
    if ($row == null) {
        $objBuyer->add_buyer($num, $name, 1);
    } else {
        //do discount stuff
    }
    $more = TRUE;
    $i = 0;
    $totalcost = 0;
    while ($more) {
        if (isset($_REQUEST['pcode' . $i]) && $_REQUEST['pcode' . $i] != "") {
            //get selling price of product
            $row = $objProduct->get_product($_REQUEST['pcode' . $i]);
            $sp = $row['selling_price'];
            //add to transaction products
            $objTransp->add_transaction_product($_REQUEST['pcode' . $i], $_REQUEST['quant' . $i], $date, $time, $num, "obed.nsiah");
            //reduce product quantity
            $objProduct->decrease_stock_level($_REQUEST['pcode' . $i], $_REQUEST['quant' . $i]);
            $totalcost += $_REQUEST['quant' . $i] * $sp;
        } else {
            $more = FALSE;
        }
        $i++;
    }
    $objTrans->add_transaction($date, $time, $num, "obed.nsiah", $totalcost);
    if ($totalcost > 500) {
        //send sms about 10% discount;
    }
    //header("Location: ../desktop/transaction.html");
}
?>