<?php

	include 'header.php';
	include 'navbar.php';
	include 'includes/admin_API_Config.php';

	error_reporting(0);

?>

	 <div class="card">
		<div class="card-body">
		   <form id="frmPaymentInfo" method="post" enctype="multipart/form-data">
				<div class="row">
					<div class="form-group offset-md-3 col-md-4">
		   				<h4 class="card-title">Enter Payment Information</h4>
					</div>
				</div>
				<div class="row">
					<div class="form-group offset-md-3 col-md-3">
					  <label>Order ID:</label>
					  <input type="text" name="order_id" id="order_id" class="form-control" value="<?php echo $_GET['order_id'];?>" readonly/>
					  <small id="old_idHelp" class="form-text text-muted"></small>
					</div>
					<div class="form-group col-md-2">
					<div class="form-radio form-radio-flat">
					  <label class="form-check-label">
					  <input type="radio" class="form-check-input" name="paymentType" id="paymentType1" value="1" checked>
						Whole Payment
					  <i class="input-helper"></i></label>
					</div>
				   </div>
				   <div class="form-group col-md-2">
					<div class="form-radio form-radio-flat">
					  <label class="form-check-label">
					  <input type="radio" class="form-check-input" name="paymentType" id="paymentType2" value="2">
					    EMI Payment
					  <i class="input-helper"></i></label>
					</div>
				   </div>
				</div>
				<div class="row">
				   <div class="form-group offset-md-3 col-md-2">
					  <label>Amount Received:*</label>
					  <input type="text" name="txtAmount" id="txtAmount" class="form-control"  required/>
					  <small id="txtAmountHelp" class="form-text text-muted"></small>
				    </div>
				    <div class="form-group col-md-2">
					  <label>Processing Fees:*</label>
					  <input type="text" name="processingFees" id="processingFees" class="form-control"  value="0" required/>
					  <small id="txtProcessingFeesHelp" class="form-text text-muted"></small>
				    </div>
				    <div class="form-group col-md-2">
						<label>Mode of Payment:</label>
						<select name="cmbPaymentMode" id="cmbPaymentMode" class="form-control" required>
							<option value="Online">Online</option>
							<option value="Razor Pay">Razor Pay</option>
							<option value="Cheque">Cheque</option>
							<option value="Cash">Cash</option>
						</select>
					</div>
				</div>
				<div class="row" id="chequeDepositRow" hidden>
				   <div class="form-group  offset-md-3 col-md-3">
					<div class="form-radio form-radio-flat">
					  <label class="form-check-label">
					  <input type="radio" class="form-check-input" name="chequeDeposit" id="chequeDeposit1" value="1" checked>
						Deposited at Bank
					  <i class="input-helper"></i></label>
					</div>
				   </div>
				   <div class="form-group col-md-2">
					<div class="form-radio form-radio-flat">
					  <label class="form-check-label">
					  <input type="radio" class="form-check-input" name="chequeDeposit" id="chequeDeposit2" value="2">
					    Submitted at office
					  <i class="input-helper"></i></label>
					</div>
				   </div>
				</div>
				<div class="row">
				   <div class="form-group offset-md-3 col-md-3"  id="txnNo">
					  <label>Transaction Number:*</label>
					  <input type="text" name="txtTransactionNo" id="txtTransactionNo" class="form-control" required/>
					  <small id="txtTransactionNoHelp" class="form-text text-muted"></small>
					</div>
				    <div class="form-group col-md-3" id="chequeNoRow" hidden>
					  <label>Cheque Number:*</label>
					  <input type="text" name="txtChequeNo" id="txtChequeNo" class="form-control"  />
					  <small id="txtChequeNoHelp" class="form-text text-muted"></small>
					</div>
				</div>
				<div class="row" id="bankDetails" hidden>
				   <div class="form-group offset-md-3 col-md-3">
					  <label>Bank Name:</label>
						<select name="cmbBankName" id="cmbBankName" class="form-control" required>
							<option value="Abhyudaya Co-operative Bank">Abhyudaya Co-operative Bank</option>
							<option value="Allahabad Bank">Allahabad Bank</option>
							<option value="Andhra Bank">Andhra Bank</option>
							<option value="Axis Bank">Axis Bank</option>
							<option value="Bandhan Bank">Bandhan Bank</option>
							<option value="Bank Of Baroda">Bank Of Baroda</option>
							<option value="Bank of India">Bank of India</option>
							<option value="Bank of Maharashtra">Bank of Maharashtra</option>
							<option value="Canara Bank">Canara Bank</option>
							<option value="Central Bank of India">Central Bank of India</option>
							<option value="Citibank">Citibank</option>
							<option value="City Union Bank">City Union Bank</option>
							<option value="Corporation Bank">Corporation Bank</option>
							<option value="DBS Bank">DBS Bankk</option>
							<option value="Deutsche Bank">Deutsche Bank</option>
							<option value="DCB Bank">DCB Bank</option>
							<option value="Federal Bank">Federal Bank</option>
							<option value="HSBC">HSBC</option>
							<option value="ICICI">ICICI</option>
							<option value="IDBI">IDBI</option>
							<option value="Indian Bank">Indian Bank</option>
							<option value="Indian Overseas Bank">Indian Overseas Bank</option>
							<option value="IndusInd">IndusInd</option>
							<option value="ING Vysya Bank">ING Vysya</option>
							<option value="Jammu and Kashmir Bank">Jammu and Kashmir Bank</option>
							<option value="Karnataka Bank Ltd">Karnataka Bank Ltd</option>
							<option value="Karur Mahindra">Kotak Mahindra</option>
							<option value="Laxmi Vilas Bank">Laxmi Vilas Bank</option>
							<option value="Karnataka Bank Ltd">Karnataka Bank Ltd</option>
							<option value="Punjab National Bank">Punjab National Bank</option>
							<option value="Punjab & Sind Bank">Punjab & Sind Bank</option>
							<option value="RBL Bank">RBL Bank</option>
							<option value="Saraswat Co-operative Bank">Saraswat Co-operative Bank</option>
							<option value="Shamrao Vitthal Co-operative Bank">Shamrao Vitthal Co-operative Bank</option>
							<option value="South Indian Bank">South Indian Bank</option>
							<option value="Standard Chartered">Standard Chartered</option>
							<option value="State Bank of Bikaner & Jaipur">State Bank of Bikaner & Jaipur</option>
							<option value="State Bank of Hyderabad">State Bank of Hyderabad</option>
							<option value="State Bank of India">State Bank of India</option>
							<option value="State Bank of Mysore">State Bank of Mysore</option>
							<option value="State Bank of Patiala">State Bank of Patiala</option>
							<option value="State Bank of Travancore">State Bank of Travancore</option>
							<option value="State Bank of Mysore">State Bank of Mysore</option>
							<option value="Syndicate Bank">Syndicate Bank</option>
							<option value="Tamilnad Mercantile Bank Ltd">Tamilnad Mercantile Bank Ltd.</option>
							<option value="UCO Bank">UCO Bank</option>
							<option value="Union Bank of India">Union Bank of India</option>
							<option value="United Bank of India">United Bank of India</option>
							<option value="Vijaya Bank">Vijaya Bank</option>
							<option value="Yes Bank Ltd">Yes Bank Ltd</option>
							<option value="Others">Others</option>
						</select>
					</div>
					<div class="form-group col-md-3" id="bankNameRow" hidden>
					  <label>Enter Bank Name:*</label>
					  <input type="text" name="txtBankName" id="txtBankName" class="form-control"  />
					  <small id="txtBankNameHelp" class="form-text text-muted"></small>
					</div>
					
				</div>
				<div class="row">
					<div class="form-group offset-md-3 col-md-3">
					  <label>Date of Payment:*</label>
					  <input class="form-control" id="paymentDate" name="paymentDate" data-inputmask="'alias': 'date'" value="" required>
					</div>
					<div class="form-group col-md-4">
					  <label>Enter any further info:</label>
					  <textarea class="form-control"  name="paymentRemark" id="paymentRemark" rows="6"></textarea>
					</div>
				</div>

    		    <div class="row">
					<div class="form-group offset-md-4 col-md-4">
						<button type="submit" class="btn btn-primary btn-fw" id="btnPaymentInfo">Submit</button>
						<input type="text" name="refer_id" id="refer_id" class="form-control" value="<?php echo $_SESSION['refer_id'];?>" hidden/>
					</div>
			    </div>
			    <div class="dot-opacity-loader" id="profileloader">
				  <span></span>
				  <span></span>
				  <span></span>
			    </div>
		   </form>
		</div>
	  </div>

  <script src="../js/formpickers.js"></script>
  <script src="../js/formpickers.js"></script>
  <script src="../js/form-addons.js"></script>
  <script src="../js/x-editable.js"></script>
  <?php
		include 'footer.php';
   ?>




	  <script type="text/javascript">

			$("#btnPaymentInfo").click(function(){



				$("#frmPaymentInfo").validate({
				  rules: {
					txtAmount: {
					  required: true,
					  number:true
					},
				    processingFees: {
					  required: true,
					  number:true
					},
					order_id: {
					  required: true,
					},
				    txtTransactionNo: {
					  required: true,
					}
				  },
				  messages: {
					txtAmount: {
					  required: "Please enter the payment amount!",
  					  number: "Please enter a valid amount!",
					},
					processingFees: {
					  required: "Please enter the processing fees!",
  					  number: "Please enter a valid processing fees!",
					},
					order_id: {
					  required: "Order ID is missing!",
					},
					txtTransactionNo: {
					  required: "Please enter the transaction number!",
					}
				  },
				  errorPlacement: function(label, element) {
					label.addClass('mt-2 text-danger');
					label.insertAfter(element);
				  },
				  highlight: function(element, errorClass) {
					$(element).parent().addClass('has-danger')
					$(element).addClass('form-control-danger')
				  }

			   });

			   if($("#frmPaymentInfo").valid())
			   {
					$("#frmPaymentInfo").submit();
			   }

			   else
				   return false;

			});


			

			$("#cmbPaymentMode").change(function(){

				if($(this).val()=="Cheque")
				{
					$("#chequeDepositRow").removeAttr("hidden");
					$("#chequeNoRow").removeAttr("hidden");
					$("#txtChequeNo").attr("required", "required");
				}

				else if($(this).val()=="Cash")
				{
					$("#chequeDepositRow").attr("hidden", "hidden");
					$("#chequeNoRow").attr("hidden", "hidden");
					$("#txnNo").attr("hidden", "hidden");

					$("#txtChequeNo").removeAttr("required");
					$("#txtTransactionNo").removeAttr("required");
				
				}


				else
				{
					$("#chequeDepositRow").attr("hidden", "hidden");
					$("#chequeNoRow").attr("hidden", "hidden");
					$("#txtChequeNo").removeAttr("required");


					$("#txnNo").removeAttr("hidden");
					$("#txtTransactionNo").attr("required", "required");

				}
			
			});



			$("#cmbBankName").change(function(){

				if($(this).val()=="Others")
				{
					$("#bankNameRow").removeAttr("hidden");
    				$("#txtBankName").attr("required", "required");
				}

				else
				{
					$("#bankNameRow").attr("hidden", "hidden");
	   				$("#txtBankName").removeAttr("required");
    			}
			
			});


		
			
		
		$("#frmPaymentInfo").on('submit',(function(event){

    	   $("#txtBankName").val($("#cmbBankName").val());
 		   event.preventDefault();
		   $("btnPaymentInfo").hide();
		   $("#profileloader").show();

		  $.ajax({
			type        : 'POST', 
			url         : '../API/API_addPaymentInfo.php', 
			data        : new FormData(this),
			dataType    : 'json', 
			encode      : true,
			cache		: false,
			contentType : false,
			processData : false,
		  })

		  .done(function(data){
		
			if (data.success) { 
				alert(data.message);
				location.href = "http://localhost/MyBooster/admin-panel/panel/order-list.php";


			}

			else{
				//location.reload();
				alert(data.message);
			} 

		  }) 

		 .fail(function(data){
			  //location.reload();
 			  $("#btnPaymentInfo").show();
			  $("#profileloader").hide();
			  alert(data.message);
		  });

	}));





	  </script>




</script>

