<style>
	.pText{
		display: inline-block;
		padding: 5px 31px 0px;
		margin: 0;
		border-radius: 7%;
	}

	.pAmount{
		display: inline-block;
		padding: 5px 10px 0px;
		margin: 0;
		border-radius: 15%;
	}

	#personal{
		opacity:1 !important;
	}

</style>
<?php $user_data = get_user_data($this->session->user_id) ?>
<div class="page-header">
	<h3 class="page-title">
		<span class="page-title-icon bg-gradient-danger text-white mr-2">
			<i class="mdi mdi-cash-multiple"></i>
		</span>
		Cash Withdraw
	</h3>
</div>

<div class="row p-0 ">
	<div class="col-md-12 border10 m-0 p-0">
		<div class="card bg-white text-dark border10">
			<div class="card-body">
				<div class="row">
					<div class="col-12 border20 text-center p-2 mb-3" style="color: #0e6c5e;background: rgba(255,224,0,0.20)">
						<?php if($withdraw_allow->withdraw_allow == 0): ?>
							প্রিয় গ্রাহক, আপনি এখন শুধু মাএ Refer,Affiliate,Digital marketing,freelancing income withdraw করতে পারবেন 12pm থেকে রাত 12am পর্যন্ত ধন্যবাদ	
						<?php else:?>
							প্রিয় গ্রাহক, আপনি এখন শুধু মাএ ppc work এর  ইনকাম withdraw করতে পারবেন 12am থেকে দুপুর 12pm পর্যন্ত ধন্যবাদ
						<?php endif?>
					</div>
					<div class="col-lg-12">
						<h5 class="font-weight-normal mb-3">Your Current Balance
							<i class="mdi mdi-chart-line mdi-36px float-right"></i>
						</h5>
					</div>

					<div class="col-lg-6">
						<p class="pText bg-warning"> Refer Income </p>
						<p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳ <?= number_format($myReferIncome ? ($myReferIncome-($myPaidReferIncome ? $myPaidReferIncome : 0)) : 0,2) ?>
						</p>
						<hr>
						<p class="pText bg-warning"> Refer Bonus </p> <p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳ <?= number_format($myReferBonus ? ($myReferBonus-($myPaidReferBonus ? $myPaidReferBonus : 0)) : 0,0) ?>
						</p>
						<hr>
						<!-- <p class="pText bg-warning"> PPC Income </p> <p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳ <?= number_format( $withdraw_history->work_earn_amount ? $withdraw_history->work_earn_amount : 0,2) ?>
						</p> -->
						<hr>
						<p class="pText bg-warning"> Affiliate Income </p> <p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳ <?=number_format( $myAffiliate ? ($myAffiliate-($myPaidAffiliate ? $myPaidAffiliate : 0)) : 0,0) ?>
						</p>
						<hr>
						<p class="pText bg-warning"> Freelance Income </p>&nbsp;
						<p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">

							<?php


							$fIncome = 0;
							if($freelanceNewIncome)
							{
								$encodeFreelance = json_decode($freelanceNewIncome);

								foreach($encodeFreelance as $key=>$incomeValue)
								{
									$fIncome+=$incomeValue->amount;
								}
							}

							?>
							৳ <?= number_format($fIncome,0) ?>
						</p>
						<hr>
						<p class="pText bg-warning"> Product Sell Income </p>&nbsp;
						<p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳ <?= number_format( $marketing_earn->product_sell,0) ?></p>
						<hr>

						<p class="pText bg-warning"> Flexiload Income </p>&nbsp;
						<p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳ <?= number_format( $marketing_earn->flexiincome,0) ?>
						</p>
						<hr>
						<p class="pText bg-warning"> Digital Marketing Income </p> <p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳ <?= number_format($marketing_earn->marketing_earn,2) ?><br>
						</p
						<br>
						<hr>
						<?php
						$totalOtherEarn = $withdraw_history->refer_earn_amount+$withdraw_history->refer_work_earn_amount+$withdraw_history->other_earn_amount+$fIncome+$marketing_earn->marketing_earn+$marketing_earn->product_sell;
						?>
						
							
						<p class="pText bg-warning"> Total Income </p>&nbsp;
						
						<p class="page-title-icon bg-gradient-danger pAmount text-white mr-2">
							৳  <?=number_format($user_data->balance+$fIncome,2)?>
						</p>
						
						<br>
						<br>

					</div>
					<div class="col-lg-6"></div>

					<!-- Form Start -->
					<div class="col-lg-12">
						<?php $alw=0; if($withdraw_allow->withdraw_allow){ $alw=1; }?>
						<?= $withdraw_pending ? "<h4 class='text-danger'>Your One Withdraw Request is Pending, You Can Request Again After Proceed this request. </h4>" :"" ?>
						<?php
						$maxAmount = number_format($refer_earn->refer_work_earn_amount+$refer_bonus_earn->refer_earn_amount+$other_earn->other_earn_amount,2);
						$withdraw_options = json_decode($withdraw_amount_options);
						?>

						<h5>Cash-Out</h5>
						<b>
							<?php
							$sl=0;
							foreach ($withdraw_options as $key=>$option)
							{
								if ($sl == 0){
									echo "Minimum cash-out amount is : ".$option->amount ;
								}
								++$sl;
							}
							?>
						</b>
						<br>

						<?php
						/* Current Available Amounts start */
						// Job Earn Start
						$currentPPC = $withdraw_history->work_earn_amount ? $withdraw_history->work_earn_amount : 0;
						$currentDigitalMark = $marketing_earn->marketing_earn ? $marketing_earn->marketing_earn : 0;
						// Job Earn End

						// Other Earn Start
						$currentReferIncome = $myReferIncome ? ($myReferIncome-($myPaidReferIncome ? $myPaidReferIncome : 0)) : 0;
						$currentReferBonus = $myReferBonus ? ($myReferBonus-($myPaidReferBonus ? $myPaidReferBonus : 0)) : 0;
						$currentAffiliate  = $myAffiliate ? ($myAffiliate-($myPaidAffiliate ? $myPaidAffiliate : 0)) : 0;
						$currentFreelance = $fIncome;
						$currentProductSell = $marketing_earn->product_sell ? $marketing_earn->product_sell : 0;
						// Other Earn End

						/* Current Available Amounts End */
						?>

						<form id="withdraw" method="post">
							<div class="row d-flex align-items-center">
								<div class="col-sm-12 col-md-4 form-group">
									<label for="rcv_num">&nbsp Receive Number</label>
									<input <?= !$withdraw_pending ?: 'disabled'?> name="rcv_num" type="number" min="1000000000" class="form-control" id="rcv_num" placeholder="Receive Number" required>
								</div>

								<?php if($alw === 1):?>
									<div class="col-sm-12 col-md-4 form-group <?=$alw === 1 ? '' : 'd-none'?>">
										<label for="amnt">&nbsp Job Earn Amount Only <br> (2% bKash fee will Charge)</label>

										<select name="amnt" class="form-control" id="<?=$alw==1 ? 'amnt':''?>">
											<?php
											foreach ($withdraw_options as $key=>$option)
											{
												if ($option->amount <=$currentPPC || $option->amount <=$currentDigitalMark)
												{
													echo '<option value="'.$option->amount.'">'.$option->amount.'</option> ';
												}
												else{
													echo ' <option value="'.$option->amount.'" disabled>'.$option->amount.'</option> ';
												}
											}
											?>
										</select>
									</div>
								<?php endif ?>


								<div class="col-sm-12 col-md-4 form-group <?=$alw ? 'd-none':''?>">
									<label for="amnt">Personal <br> (2% bKash fee will Charge)</label>

									<select name="amnt" class="form-control" id="<?=$alw==0 ? 'amnt':''?>">
										<?php
										foreach ($withdraw_options as $key=>$option)
										{
											if ($option->amount <= $currentReferIncome || $option->amount <= $currentReferBonus || $option->amount <= $currentAffiliate || $option->amount <= $currentFreelance || $option->amount <= $currentProductSell)
											{
												echo '<option value="'.$option->amount.'">'.$option->amount.'</option> ';
											}
											else{
												echo '<option value="'.$option->amount.'" disabled>'.$option->amount.'</option>';
											}
										}
										?>
									</select>

									<!--<input <?/*= !$withdraw_pending ?: 'disabled'*/?> name="amnt" type="Number" min="500" max="<?/*= number_format($refer_earn->refer_work_earn_amount+$refer_bonus_earn->refer_earn_amount+$other_earn->other_earn_amount,0,",","") */?>" class="form-control" id="<?/*=$alw==0 ? 'amnt':''*/?>" placeholder="Refer / Bonus / Other Earn Amount"
									>-->
								</div>
								<div class="col-sm-12 col-md-4 form-group">
									<label for="pass">&nbsp Password</label>
									<input <?= !$withdraw_pending ?: 'disabled'?>  name="pass" type="Password" class="form-control" id="pass" placeholder="Password" required>
								</div>

								<h5 class="col-12">Payment Method</h5>

								<!-- <div class=" d-none col-sm-6 col-md-3  form-check form-check-light ml-4">
									<label class="form-check-label mr-3" for="agent">&nbsp bKash Agent Number
										<input <?= !$withdraw_pending ?: 'disabled'?> type="checkbox" name="pay_method" value="bkash-agent" class="form-check-input bg-warning" id="agent" required>
									</label>
								</div> -->

								<div class="col-sm-6 col-md-3 form-check ml-4">
									<label class="form-check-label" for="personal">&nbsp bKash Personal Number
										<input <?= !$withdraw_pending ?: 'disabled'?> type="checkbox" name="pay_method" value="bkash-personal" class="form-check-input" id="personal" required>
									</label>
								</div>

								<div id="snd" class="align-self-center ml-4">
									<button <?= !$withdraw_pending ? : 'disabled'?> class="btn btn-warning btn-rounded btn-block" type="submit">Send <i class="mdi mdi-sync mdi-spin loading"></i> </button>
									<div id="conf">

									</div>
								</div>

								<div id="loader" class="ml-2"><i class="mdi mdi-spin mdi-loading mdi-36px"></i></div>
								<div id="result" class="ml-2"></div>
							</div>
						</form>
					</div>
					<!-- Form End -->
				</div>


				<?php /* <p>Job Earn :&nbsp <span class="font_medium_lg pull-right">৳ 
						<?= number_format($work_earn->work_earn_amount,2) ?></span></p> 

				<p>Refer Commission Earn :&nbsp <span class="font_medium_lg pull-right">৳ 
						<?= number_format($refer_earn->refer_work_earn_amount,2) ?></span></p>
				<p>Refer Bonus Earn :&nbsp <span class="font_medium_lg pull-right">৳ 
						<?= number_format($refer_bonus_earn->refer_earn_amount,2) ?></span></p> */ ?>


				<br>
				<br>
				<br>



			</div>
		</div>
	</div>
</div>


<script>
	$(document).on("click","#personal",function(){
		if($(this).is(":checked")){
			$(this).attr("checked",true);
		}
		else if($(this).is(":not(:checked)")){
			$(this).attr("checked",false);
		}
	});
</script>

<script type="text/javascript" src="<?=base_url('app-assets/js/ajax/withdraw.js')?>">
</script>
