public function postRefund() { $postdata = Input::all(); $panIDPK = Input::get('pan_id_pk'); $currenttime = Commonmodel::dateandtime(); if (!$panIDPK) { return Response::json(array('status' => "failed", 'message' => 'Please send a PAN ID')); } else { $findrefuncid = Panoffiline::find($panIDPK); if ($findrefuncid) { $getcurrentuser = Panoffiline::where('pan_id_pk', '=', $panIDPK)->pluck('pan_created_by'); $response = Panoffiline::where('pan_id_pk', $panIDPK)->get(); if ($response) { foreach ($response as $res) { $userfinID = $res->pan_created_by; $panCoupenNo = $res->pan_coupon_no; $mainBalance = Userfinance::where('ufin_user_id', $userfinID)->pluck('ufin_main_balance'); $panTotBal = $mainBalance + 106; $balanceDebit = array('ufin_main_balance' => $panTotBal); if ($panCoupenNo != '0') { Userfinance::where('ufin_user_id', '=', $userfinID)->update($balanceDebit); $coupenReset = array('pan_coupon_no' => ''); Panoffiline::where('pan_id_pk', '=', $panIDPK)->update($coupenReset); $panCoupenUpdate = array('pc_coupon_no' => $panCoupenNo); $procode = Products::where('prod_short_name', '=', 'PANM')->pluck('prod_code'); $panledger = array('lr_date' => $currenttime, 'lr_trans_type' => 'CR', 'lr_comment' => 'Pan Refund', 'lr_credit_amount' => '106', 'lr_post_balance' => $panTotBal, 'lr_created_by' => $getcurrentuser, 'lr_prod_code' => $procode); $panlegcreta = new Ledgerreport(); $panlegcreta->create($panledger); $coupen = new Coupons(); $coupen->create($panCoupenUpdate); return Response::json(array('status' => "success", 'message' => 'Amount debited successfully')); } else { return Response::json(array('status' => "failure", 'message' => 'PAN Card has been already applied for refund')); } } } } else { return Response::json(array('status' => "failure", 'message' => 'No User found for this ID')); } } }
public function postUserbalanceadd() { $postdata = file_get_contents("php://input"); if (!empty($postdata)) { $currentdate = Commonmodel::dateandtime(); $userIdPk = Input::get('userIdPk'); $userId = Input::get('userId'); $currentUserId = Input::get('currentUserId'); $currentUserIdPk = Input::get('currentUserIdPk'); $parentId = Input::get('parentId'); $parentIdPk = Input::get('parentIdPk'); $clientIP = Input::get('clientIP'); $amount = Input::get('amount'); $feePerc = Input::get('feePerc'); $balancefromuser = Userfinance::where('ufin_user_id', '=', $currentUserId)->get(); $balancetouser = Userfinance::where('ufin_user_id', '=', $userId)->get(); if (count($balancefromuser) > 0) { foreach ($balancefromuser as $balancefromusers) { $formuserbalance = $balancefromusers->ufin_main_balance; $formusercurrenttotalcredited = $balancefromusers->ufin_total_credited; } if ($formuserbalance > $amount) { if (count($balancetouser) > 0) { foreach ($balancetouser as $balancetouser) { $btcurrentmainbal = $balancetouser->ufin_main_balance; $btcurrenttotalcredited = $balancetouser->ufin_total_credited; } if ($feePerc > 0) { $newper = $feePerc / 100; $finalper = $amount * $newper; $amount = $amount - $finalper; } else { $finalper = $feePerc; } $updateuserbalance = array('ufin_main_balance' => $btcurrentmainbal + $amount, 'ufin_total_credited' => $btcurrenttotalcredited + $amount); Userfinance::where('ufin_user_id', '=', $userId)->update($updateuserbalance); $newbalupdatecr = 0; $newbalupdatecr = $formuserbalance - $amount; $updateuserbalance = array('ufin_main_balance' => $newbalupdatecr); Userfinance::where('ufin_user_id', '=', $currentUserId)->update($updateuserbalance); $creditcharge = array('cr_user_id' => $userId, 'cr_type' => 'CR', 'cr_open_bal' => $btcurrentmainbal, 'cr_amount' => $amount, 'cr_fee' => $finalper, 'cr_new_bal' => $btcurrentmainbal + $amount, 'cr_created_by' => $currentUserId, 'cr_created_at' => $currentdate); $getcurrentuserid = Userfinance::where('ufin_user_id', '=', $currentUserId)->pluck('ufin_main_balance'); $newbalcenaces = 0; $newbalcenaces = $formuserbalance - $amount; $ledgercreditdb = array('lr_date' => $currentdate, 'lr_trans_type' => 'DB', 'lr_comment' => 'Balance Transfer', 'lr_debit_amount' => $amount, 'lr_post_balance' => $newbalcenaces, 'lr_created_by' => $currentUserId); $addnewledger = new Ledgerreport(); $addnewledger->create($ledgercreditdb); $newbalcenaces1 = 0; $newbalcenaces1 = $btcurrentmainbal + $amount; $ledgercreditcr = array('lr_date' => $currentdate, 'lr_trans_type' => 'CR', 'lr_comment' => "Balance Transfer", 'lr_credit_amount' => $amount, 'lr_post_balance' => $newbalcenaces1, 'lr_created_by' => $currentUserId); $addnewledger = new Ledgerreport(); $addnewledger->create($ledgercreditcr); $creditchargeinsert = new Usercreditrecharge(); $creditchargeinsert->create($creditcharge); return Response::json(array('status' => 'success', 'message' => 'User Credit Added Successfully')); } else { return Response::json(array('status' => 'failure', 'message' => 'No User With This ID')); } } else { return Response::json(array('status' => 'failure', 'message' => 'You do not have sufficient balance to transfer the amount')); } } } else { return Response::json(array('status' => 'failure', 'message' => 'Fill All Manditary Fields')); } }
public function postDailycomission() { $postdata = file_get_contents("php://input"); if (!empty($postdata)) { $userIdPk = Input::get('userIdPk'); $userId = Input::get('userId'); $date = Input::get('lr_date'); $statdate = $date . " 00:00:00"; $enddate = $date . " 23:59:59"; if ($userIdPk != '' || $userId != '') { $legcount = Ledgerreport::where('lr_created_by', '=', $userId)->whereBetween('lr_date', array($statdate, $enddate))->get(); if (count($legcount) > 0) { $dbamout = 0; $cramout = 0; $pbamout = 0; foreach ($legcount as $legcount) { $dbamout = $dbamout + $legcount->lr_debit_amount; $cramout = $cramout + $legcount->lr_credit_amount; $pbamout = $pbamout + $legcount->lr_post_balance; } $input = array('debitamount' => $dbamout, 'creditamount' => $cramout, 'postbalance' => $pbamout); return Response::json($input); } else { return Response::json(array('status' => 'failure', 'message' => 'No Ledger Reports for this ID')); } } else { return Response::json(array('status' => 'failure', 'message' => 'Fill All Manditary Fields')); } } else { return Response::json(array('status' => 'failure', 'message' => 'Fill All Manditary Fields')); } }
public function postDashboard() { $userID = Input::get('created_by'); $userIDPK = Input::get('userIDPK'); $userRole = User::where('UD_USER_ID', '=', $userID)->get(); foreach ($userRole as $ur) { $userType = $ur->UD_USER_TYPE; } if ($userType == "SA" || $userType == "SAS") { $successRecAmount = 0; $failureRecAmount = 0; $startDate = date('Y-m-d') . " 00:00:00"; $endDate = date('Y-m-d') . " 23:59:59"; //recharge stats $successRechargeRecords = Ledgerreport::where('lr_comment', '=', 'Recharge')->where('lr_status', '=', 'success')->whereBetween('lr_date', array($startDate, $endDate))->get(); foreach ($successRechargeRecords as $srr) { $successRecAmount = $successRecAmount + $srr->lr_debit_amount; } $failureRechargeRecords = Ledgerreport::where('lr_comment', '=', 'Recharge')->where('lr_status', '=', 'failure')->whereBetween('lr_date', array($startDate, $endDate))->get(); foreach ($failureRechargeRecords as $srr) { $failureRecAmount = $failureRecAmount + $srr->lr_debit_amount; } //icash balance $icashBalance = Userfinance::where('ufin_user_id', '=', $userID)->get(); $icashBal = 0; foreach ($icashBalance as $bal) { $icashBal = $icashBal + $bal->ufin_icash_balance; } //User count $SA = count(User::where('UD_USER_TYPE', '=', 'SA')->get()); $SAS = count(User::where('UD_USER_TYPE', '=', 'SAS')->get()); $SP = count(User::where('UD_USER_TYPE', '=', 'SP')->get()); $SPS = count(User::where('UD_USER_TYPE', '=', 'SPS')->get()); $SD = count(User::where('UD_USER_TYPE', '=', 'SD')->get()); $SDS = count(User::where('UD_USER_TYPE', '=', 'SDS')->get()); $D = count(User::where('UD_USER_TYPE', '=', 'D')->get()); $DS = count(User::where('UD_USER_TYPE', '=', 'DS')->get()); $FR = count(User::where('UD_USER_TYPE', '=', 'FR')->get()); $FRS = count(User::where('UD_USER_TYPE', '=', 'FRS')->get()); $SFR = count(User::where('UD_USER_TYPE', '=', 'SFR')->get()); $SFRS = count(User::where('UD_USER_TYPE', '=', 'SFRS')->get()); //User Balance $SAbalance = Commonmodel::fetchUserdetails('SA'); $SASbalance = Commonmodel::fetchUserdetails('SAS'); $SPbalance = Commonmodel::fetchUserdetails('SP'); $SPSbalance = Commonmodel::fetchUserdetails('SPS'); $SDbalance = Commonmodel::fetchUserdetails('SD'); $SDSbalance = Commonmodel::fetchUserdetails('SDS'); $Dbalance = Commonmodel::fetchUserdetails('D'); $DSbalance = Commonmodel::fetchUserdetails('DS'); $FRbalance = Commonmodel::fetchUserdetails('FR'); $FRSbalance = Commonmodel::fetchUserdetails('FRS'); $SFRbalance = Commonmodel::fetchUserdetails('SFR'); $SFRSbalance = Commonmodel::fetchUserdetails('SFRS'); //Ezypay $getbalance = Rechargeurl::balance(); $ezbalance = $getbalance[0]; $output = array('Success_Recharge_Amount' => $successRecAmount, 'Failure_Recharge_Amount' => $failureRecAmount, 'SA' => $SA, 'SAS' => $SAS, 'SP' => $SP, 'SPS' => $SPS, 'SD' => $SD, 'SDS' => $SDS, 'D' => $D, 'DS' => $DS, 'FR' => $FR, 'FRS' => $FRS, 'SFR' => $SFR, 'SFRS' => $SFRS, 'Ezpay_Balance' => $ezbalance, 'icash_Balance' => $icashBal, 'SA_Balance' => $SAbalance, 'SAS_Balance' => $SASbalance, 'SP_Balance' => $SPbalance, 'SPS_Balance' => $SPSbalance, 'SD_Balance' => $SDbalance, 'SDS_Balance' => $SDSbalance, 'D_Balance' => $Dbalance, 'DS_Balance' => $DSbalance, 'FR_Balance' => $FRbalance, 'FRS_Balance' => $FRSbalance, 'SFR_Balance' => $SFRbalance, 'SFRS_Balance' => $SFRSbalance); } elseif ($userType == "SP") { $SPbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_PARENT_ID', '=', $userIDPK)->get(); $spartBalance = 0; if ($SPbalance) { foreach ($SPbalance as $sp) { $spaBalance = $sp->ufin_main_balance; } $Daccounts = count(User::where('UD_PARENT_ID', '=', $userIDPK)->get()); $SDbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_PARENT_ID', '=', $userIDPK)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); $disbal = 0; if ($SDbalance) { foreach ($SDbalance as $frs) { $disbal = $disbal + $frs->ufin_main_balance; } $output = array('Statepartner_Balance' => $spaBalance, 'Distributor_accounts' => $Daccounts, 'Distributor_balance' => $disbal); } else { $output = array('Statepartner_Balance' => $spaBalance, 'Distributor_accounts' => $Daccounts, 'Distributor_balance' => '0'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "SPS") { $SPbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_ID_PK', '=', $userIDPK)->get(); $spartBalance = 0; if ($SPbalance) { foreach ($SPbalance as $sp) { $spaBalance = $sp->ufin_main_balance; $parentid = $sp->UD_PARENT_ID; } $Daccounts = count(User::where('UD_PARENT_ID', '=', $parentid)->get()); $SDbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_finance.ufin_user_id_pk_fk', '=', $parentid)->get(); $disbal = 0; if ($SDbalance) { foreach ($SDbalance as $frs) { $disbal = $disbal + $frs->ufin_main_balance; } $output = array('Statepartner_Balance' => $spaBalance, 'Distributor_accounts' => $Daccounts, 'Distributor_balance' => $disbal); } else { $output = array('Statepartner_Balance' => $spaBalance, 'Distributor_accounts' => $Daccounts, 'Distributor_balance' => '0'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "SD") { $SDbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $sdiBalance = 0; if ($SDbalance) { foreach ($SDbalance as $sp) { $sdiBalance = $sp->ufin_main_balance; } $Daccounts = count(User::where('UD_PARENT_ID', '=', $userIDPK)->get()); $Disbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_PARENT_ID', '=', $userIDPK)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); $disbal = 0; if ($Disbalance) { foreach ($Disbalance as $frs) { $disbal = $disbal + $frs->ufin_main_balance; } $output = array('Super_Distributer_Balance' => $sdiBalance, 'Distributor_accounts' => $Daccounts, 'Distributor_balance' => $disbal); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "SDS") { $SDbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $sdiBalance = 0; if ($SDbalance) { foreach ($SDbalance as $sp) { $sdiBalance = $sp->ufin_main_balance; $parentid = $sp->UD_PARENT_ID; } $Daccounts = count(User::where('UD_PARENT_ID', '=', $parentid)->get()); $Disbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_finance.ufin_user_id_pk_fk', '=', $parentid)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); $disbal = 0; if ($Disbalance) { foreach ($Disbalance as $frs) { $disbal = $disbal + $frs->ufin_main_balance; } $output = array('Super_Distributer_Balance' => $sdiBalance, 'Distributor_accounts' => $Daccounts, 'Distributor_balance' => $disbal); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "D") { $SDbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $sdiBalance = 0; if ($SDbalance) { foreach ($SDbalance as $sp) { $sdiBalance = $sp->ufin_main_balance; } $Daccounts = count(User::where('UD_PARENT_ID', '=', $userIDPK)->get()); $Disbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_PARENT_ID', '=', $userIDPK)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); $disbal = 0; if ($Disbalance) { foreach ($Disbalance as $frs) { $disbal = $disbal + $frs->ufin_main_balance; } $output = array('Distributer_Balance' => $sdiBalance, 'Franchise_accounts' => $Daccounts, 'Franchise_balance' => $disbal); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "DS") { $SDbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $sdiBalance = 0; if ($SDbalance) { foreach ($SDbalance as $sp) { $sdiBalance = $sp->ufin_main_balance; $parentid = $sp->UD_PARENT_ID; } $Daccounts = count(User::where('UD_PARENT_ID', '=', $parentid)->get()); $Disbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_finance.ufin_user_id', '=', $parentid)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); $disbal = 0; if ($Disbalance) { foreach ($Disbalance as $frs) { $disbal = $disbal + $frs->ufin_main_balance; } $output = array('Distributer_Balance' => $sdiBalance, 'Franchise_accounts' => $Daccounts, 'Franchise_balance' => $disbal); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "FR") { $FRbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $fraBalance = 0; if ($FRbalance) { foreach ($FRbalance as $fr) { $fraBalance = $fr->ufin_main_balance; $icashBalance = $fr->ufin_icash_balance; } $FRSaccounts = count(User::where('UD_PARENT_ID', '=', $userIDPK)->get()); $SFRbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_finance.ufin_user_id', '=', $userID)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); $sfrbal = 0; if ($FRbalance) { foreach ($SFRbalance as $frs) { $sfrbal = $sfrbal + $frs->ufin_main_balance; } $output = array('Franchise_Balance' => $fraBalance, 'icash_Balance' => $icashBalance, 'Sub_franchise_accounts' => $FRSaccounts, 'Sub_franchise_balance' => $sfrbal, 'Total_recharge_amount' => $FRtotalregamount); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "FRS") { $FRbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $fraBalance = 0; if ($FRbalance) { foreach ($FRbalance as $fr) { $fraBalance = $fr->ufin_main_balance; $icashBalance = $fr->ufin_icash_balance; $parentid = $fr->UD_PARENT_ID; } $FRSaccounts = count(User::where('UD_PARENT_ID', '=', $parentid)->get()); $SFRbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_finance.ufin_user_id', '=', $parentid)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); $sfrbal = 0; if ($SFRbalance) { foreach ($SFRbalance as $frs) { $sfrbal = $sfrbal + $frs->ufin_main_balance; } $output = array('Franchise_Balance' => $fraBalance, 'icash_Balance' => $icashBalance, 'Sub_franchise_accounts' => $FRSaccounts, 'Sub_franchise_balance' => $sfrbal, 'Total_recharge_amount' => $FRtotalregamount); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "SFR") { $FRbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $fraBalance = 0; if ($FRbalance) { $FRtotalregamount = Commonmodel::fetchRechargedetails($userID); foreach ($FRbalance as $fr) { $fraBalance = $fr->ufin_main_balance; $icashBalance = $fr->ufin_icash_balance; } $output = array('Franchise_Balance' => $fraBalance, 'icash_Balance' => $icashBalance, 'Total_recharge_amount' => $FRtotalregamount); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } elseif ($userType == "SFRS") { $FRbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_details.UD_USER_ID', '=', $userID)->get(); $fraBalance = 0; if ($FRbalance) { foreach ($FRbalance as $fr) { $fraBalance = $fr->ufin_main_balance; $icashBalance = $fr->ufin_icash_balance; $parentid = $fr->UD_PARENT_ID; } $parentIDname = User::where('UD_ID_PK', '=', $parentid)->get(); foreach ($parentIDname as $prntname) { $parent_name = $prntname->UD_USER_ID; } $SFRbalance = DB::table('adt_user_finance')->leftjoin('adt_user_details', 'adt_user_finance.ufin_user_id', '=', 'adt_user_details.UD_USER_ID')->where('adt_user_finance.ufin_user_id_pk_fk', '=', $parentid)->get(); $FRtotalregamount = Commonmodel::fetchRechargedetails($parent_name); $sfrbal = 0; if ($SFRbalance) { foreach ($SFRbalance as $frs) { $sfrbal = $sfrbal + $frs->ufin_main_balance; } $output = array('Franchise_Balance' => $sfrbal, 'icash_Balance' => $icashBalance, 'Total_recharge_amount' => $FRtotalregamount); } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } else { $output = array('status' => 'failure', 'message' => 'No results found'); } } return Response::json($output); }