//check user account exits
 if (!check_user($userId)) {
     $result["return"] = false;
     $result["message"] = "Invalid user.";
     echo json_encode($result);
     exit;
 }
 //check user is active or not
 if (!check_user_active($userId)) {
     $result["return"] = false;
     $result["message"] = "Dear user! Please pay your bills to reactivate your account.";
     echo json_encode($result);
     exit;
 }
 //check Product is valid and belong to the user
 if (!check_productId_is_valid($productId, $userId)) {
     $result["return"] = false;
     $result["message"] = "Invalid Product Id";
     echo json_encode($result);
     exit;
 }
 //fetch all the product
 $product = Db::fetch("product", array("user_id" => $userId, "id" => $productId), array("=", "="));
 if (!Db::getError()) {
     //create dateTime from time stamp
     $dateTime = date("d/m/y", $product[0]["time"]);
     //fetch Size & quantity
     $q = Db::query("SELECT size,quantity FROM `sq` WHERE user_id=? AND product_id=?", array($userId, $productId));
     $sqResult = $q->fetchAll(PDO::FETCH_ASSOC);
     $sizeArray = array();
     $quantityArray = array();
 //check user id is valid
 if (!check_user($user_id)) {
     $result["message"] = "Invalid user";
     $result["return"] = false;
     json($result);
 }
 /******************************
 		Check if sales is from ListedProduct or NonListedProduct
 		 ************************************/
 if (isset($_POST["salesType"]) && isset($_POST["productId"]) && isset($_POST["productCode"])) {
     /*********************** Listed Product *****************/
     $sales_type = e($_POST["salesType"]);
     $product_id = e($_POST["productId"]);
     $product_code = e($_POST["productCode"]);
     //check product id is valid or not
     if (!check_productId_is_valid($product_id, $user_id)) {
         $result["message"] = "Invalid Product id";
         $result["return"] = false;
         json($result);
     }
     //check size is valid
     $sizeCount = Db::rowCount("sq", array("user_id" => $user_id, "product_id" => $product_id, "size" => $size_stack), array("=", "=", "="));
     if ($sizeCount <= 0) {
         $result["message"] = "Invalid size `{$size_stack}` of product";
         $result["return"] = false;
         json($result);
     }
     //check quantity is not zero
     if ($quantity_stack <= 0) {
         $result["message"] = "Invalid quantity. Quantity cannot be zero";
         $result["return"] = false;