public function postProductentry()
 {
     $postdata = file_get_contents("php://input");
     if (!empty($postdata)) {
         $inputid = Input::get('userId');
         $userlink = Input::get('userlink');
         $currenttime = Commonmodel::dateandtime();
         $getimage = explode("/", $userlink);
         $stroreimage = $getimage[6];
         $productcode = Input::get('prodcode');
         if ($inputid != '' && $userlink != '' && $productcode != '') {
             $getrecords = Userproductaccess::where('upa_ud_user_id', $inputid)->where('upa_prod_code', $productcode)->get();
             if (count($getrecords) > 0) {
                 return Response::json(array('status' => 'failure', 'message' => 'Already You have This Products'));
             } else {
                 $checkbalance = Userfinance::where('ufin_user_id', '=', $inputid)->where('ufin_main_balance', '<', '100')->get();
                 $getbalance = Userfinance::where('ufin_user_id', '=', $inputid)->pluck('ufin_main_balance');
                 if (count($checkbalance) > 0) {
                     return Response::json(array('status' => 'failure', 'message' => 'You Do not Have Sufficient Balance'));
                 } else {
                     $input = array('upa_ud_user_id' => $inputid, 'upa_prod_code' => $productcode, 'upa_created_at' => $currenttime, 'upa_photo' => $stroreimage);
                     $getbalance = $getbalance - 99;
                     $product = new Userproductaccess();
                     $product->create($input);
                     $balance = array('ufin_main_balance' => $getbalance);
                     Userfinance::where('ufin_user_id', $inputid)->update($balance);
                     return Response::json(array('status' => 'Success', 'message' => 'Request Product Have Been Added'));
                 }
             }
         } else {
             return Response::json(array('status' => 'failure', 'message' => 'Fill All Manditary Field'));
         }
     }
 }
 public function postUpdateuser()
 {
     $postdata = file_get_contents("php://input");
     if (!empty($postdata)) {
         $userName = Input::get('userName');
         $userEmail = Input::get('userEmail');
         $userMobile = Input::get('userMobile');
         $currentUserId = Input::get('currentUserId');
         $currentUserIdPk = Input::get('currentUserIdPk');
         $parentId = Input::get('parentId');
         $parentIdPk = Input::get('parentIdPk');
         $userIdPk = Input::get('userIdPk');
         $userAddress1 = Input::get('userAddress1');
         $userAddress2 = Input::get('userAddress2');
         $userCity = Input::get('userCity');
         $userState = Input::get('userState');
         $userPincode = Input::get('userPincode');
         $userStatus = Input::get('userStatus');
         $userType = Input::get('userType');
         $products = Input::get('products');
         $userKey = Input::get('userKey');
         $usercount = Input::get('user_count');
         $editeddate = Commonmodel::dateandtime();
         if ($userName != "" && $userEmail != "" && $userMobile != "" && $currentUserId != "" && $currentUserIdPk != "" && $parentId != "" && $parentIdPk != "" && $userIdPk != "" && $userAddress1 != "" && $userAddress2 != "" && $userCity != "" && $userState != "" && $userState != "" && $userPincode != "" && $userStatus != "" && $userType != '') {
             $checkueremail = User::where('UD_ID_PK', '!=', $userIdPk)->where('UD_USER_EMAIL', '=', $userEmail)->get();
             if (count($checkueremail) > 0) {
                 return Response::json(array('status' => 'failure', 'message' => 'Email ID Already Exist'));
             } else {
                 $checkmobile = User::where('UD_ID_PK', '!=', $userIdPk)->where('UD_USER_MOBILE', '=', $userMobile)->get();
                 if (count($checkmobile) > 0) {
                     return Response::json(array('status' => 'failure', 'message' => 'Mobile Number Already Exist'));
                 } else {
                     $checkuser = User::where('UD_ID_PK', '!=', $userIdPk)->get();
                     if (count($checkuser) == 0) {
                         return Response::json(array('status' => 'failure', 'message' => 'User ID Already Exist'));
                     } else {
                         if ($userKey) {
                             if (empty($usercount)) {
                                 $usercount = 0;
                             }
                             $input = array('UD_USER_NAME' => Input::get('userName'), 'UD_USER_KEY' => md5(Input::get('userKey')), 'UD_PARENT_ID' => Input::get('parentIdPk'), 'UD_USER_TYPE' => Input::get('userType'), 'UD_USER_EMAIL' => Input::get('userEmail'), 'UD_USER_MOBILE' => Input::get('userMobile'), 'UD_USER_ADDRESS1' => Input::get('userAddress1'), 'UD_USER_ADDRESS2' => Input::get('userAddress2'), 'UD_USER_CITY' => Input::get('userCity'), 'UD_USER_STATE' => Input::get('userState'), 'UD_USER_PINCODE' => Input::get('userPincode'), 'UD_USER_STATUS' => Input::get('userStatus'), 'UD_EDITED_AT' => $editeddate, 'UD_EDITED_BY' => Input::get('currentUserId'), 'UD_USER_CREATE_COUNT' => $usercount);
                             User::where('UD_ID_PK', '=', $userIdPk)->update($input);
                             $getnewuserid = User::where('UD_ID_PK', '=', $userIdPk)->pluck('UD_USER_ID');
                             if (count($products) > 0) {
                                 Userproductaccess::where('UD_ID_PK', '=', $userIdPk)->delete();
                                 $len = count($products);
                                 for ($j = 0; $j < $len; $j++) {
                                     $productinput = array('upa_prod_code' => $products[$j]['prodCode'], 'upa_ud_user_id' => $products[$j]['prodStatus'], 'upa_access_status' => $getnewuserid, 'upa_created_at' => $editeddate, 'upa_created_by' => $currentUserId);
                                     $newproduct = new Userproductaccess();
                                     $newproduct->create($productinput);
                                 }
                             }
                             return Response::json(array('status' => 'success', 'message' => 'User updated Successfully'));
                         } else {
                             $input = array('UD_USER_NAME' => Input::get('userName'), 'UD_PARENT_ID' => Input::get('parentIdPk'), 'UD_USER_TYPE' => Input::get('userType'), 'UD_USER_EMAIL' => Input::get('userEmail'), 'UD_USER_MOBILE' => Input::get('userMobile'), 'UD_USER_ADDRESS1' => Input::get('userAddress1'), 'UD_USER_ADDRESS2' => Input::get('userAddress2'), 'UD_USER_CITY' => Input::get('userCity'), 'UD_USER_STATE' => Input::get('userState'), 'UD_USER_PINCODE' => Input::get('userPincode'), 'UD_USER_STATUS' => Input::get('userStatus'), 'UD_EDITED_AT' => $editeddate, 'UD_EDITED_BY' => Input::get('currentUserId'), 'UD_USER_CREATE_COUNT' => $usercount);
                             User::where('UD_ID_PK', '=', $userIdPk)->update($input);
                             $getnewuserid = User::where('UD_ID_PK', '=', $userIdPk)->pluck('UD_USER_ID');
                             if (count($products) > 0) {
                                 Userproductaccess::where('upa_ud_user_id', '=', $getnewuserid)->delete();
                                 $len = count($products);
                                 for ($j = 0; $j < $len; $j++) {
                                     $productinput = array('upa_prod_code' => $products[$j]['prodCode'], 'upa_ud_user_id' => $getnewuserid, 'upa_access_status' => $products[$j]['prodStatus'], 'upa_created_at' => $editeddate, 'upa_created_by' => $currentUserId);
                                     $newproduct = new Userproductaccess();
                                     $newproduct->create($productinput);
                                 }
                             }
                             return Response::json(array('status' => 'success', 'message' => 'User updated Successfully'));
                         }
                     }
                 }
             }
         } else {
             return Response::json(array('status' => 'failure', 'message' => 'Fill All Manditary Fields'));
         }
     } else {
         return Response::json(array('status' => 'failure', 'message' => 'Fill All Manditary Fields'));
     }
 }