<div class="breadcrumb-area mb-50">

        <div class="container">

            <div class="row">

                <div class="col">

                    <div class="breadcrumb-container">

                        <ul>

                            <li><a href="<?php echo base_url();?>"><i class="fa fa-home"></i> Home</a></li>

                            <li class="active">Checkout</li>

                        </ul>

                    </div>

                </div>

            </div>

        </div>

    </div>

    

	

	<div class="page-section section mb-50">

		<div class="container">

			<div class="row">

				<div class="col-12">
					<form action="<?php echo base_url();?>home/place_order" method="post" class="checkout-form">
                    <input type="hidden" name="del_type" id="del_type" value="Delivery" />
                    <input type="hidden" name="old_add" id="old_add" value="" />
						<div class="row row-40">
							<div class="col-lg-8 mb-20" style="background:#FFF; padding:20px;">
								<?php 
								$this->db->select("*");
								$this->db->from("city_stores");
								$this->db->join("cities","cities.city_id=city_stores.city_id");
								$this->db->where("city_stores.city_id",$this->session->userdata("city"));
								$city=$this->db->get()->row();
								//print_r($city);?>
                                <div class="wells store_pickup" style="display:none;">
                <button type="button" id="home_delivery" class="btn-sm btn btn-warning pull-right">Home Delivery</button>
                                <h5 class="text-info">Store Pickup</h5>
                                <h3 class="text-success"><?php echo $city->city_name;?> </h3>
                                <h4><?php echo $city->store_name.' '.$city->store_pincode;?></h4>
                                </div>
								<?php $chk=$this->db->get_where("user_adds",array("userid"=>$this->session->userdata("user")));
								$oldadds=$chk->num_rows();
								if($oldadds>0){ ?>
								<div class="existing_address">
					<button type="button" id="store_pickup" class="btn-sm btn btn-info pull-right">Store Pickup</button>
					<button type="button" id="add_new_address" class="add_new_address btn-sm btn btn-warning pull-right">Add New Address</button>
					<h4 class="text-warning">Select Address</h4><?php 	
								$adds=$chk->result();
								//print_r($adds);
								foreach($adds as $add){?>
								<div class="well" id="address<?php echo $add->user_add_id;?>" style="background:#bfbfbf; padding:10px; border-radius:10; margin-bottom:10px;">
				  <button type="button" id="<?php echo $add->user_add_id;?>" class="select_address btn-sm btn btn-success pull-right">Select</button>
			<h4 style="color:#fff;"><?php echo $add->add_name.' '.$add->add_phone;?></h4>
			<p style="color:#fff;"><?php echo $add->add_address.'<br/>'.$add->add_landmark.' '.$add->add_city.' '.$add->add_state.' '.$add->add_pin;?></p>
								</div>
								<?php }?></div>
								<?php }?>

								<div id="billing-form" class="mb-40" <?php if($oldadds>0){echo 'style="display:none;"';}?>>
                                
                <button type="button" id="store_pickup2" class="btn-sm btn btn-info pull-right">Store Pickup</button>
                <?php if($oldadds>0){?>
<button type="button" id="select_existing_address" class="select_existing_address btn-sm btn btn-warning pull-right">Select Existing Address</button>
									<?php }?><h4 class="checkout-title">Shipping Address</h4>

	

									<div class="row">

                    <input type="hidden" name="add_type" id="add_type" value="<?php if($oldadds>0){echo "old";}else{echo "new";}?>" />
	

										<div class="col-md-6 col-12 ">

											<label>First Name*</label>

											<input type="text" name="bfname" class="form-control" required placeholder="First Name">

										</div>

	

										<div class="col-md-6 col-12 ">

											<label>Last Name*</label>

											<input type="text" name="blname" class="form-control" required placeholder="Last Name">

										</div>

	

										<div class="col-md-6 col-12 ">

											<label>Email Address*</label>

											<input type="email" name="bemail" class="form-control" required value="<?php echo $this->session->userdata("email");?>" readonly="readonly" placeholder="Email Address">

										</div>

	

										<div class="col-md-6 col-12 ">

											<label>Phone no*</label>

											<input type="text" placeholder="Phone number" class="form-control" name="bphone" required>

										</div>

	

										<div class="col-12 mb-20">

											<label>Address*</label>

										<textarea name="baddress" class="form-control" placeholder="Type Your Complete Address" style="border-radius:0px; border:1px solid grey;" required rows="2"></textarea>
                                        
<br/>
											<input type="text" name="blandmark" class="form-control" required placeholder="Near By Landmark">


										</div>

										<div class="col-md-4 col-12 ">

											<label>Town/City*</label>

											<!--<input type="text" name="bcity" required class="form-control" placeholder="Town/City">-->
											<select class="form-control" readonly name="bcity">
                            	<option value="">Select City</option>
                                <?php   $this->db->select("*");
										$this->db->from("cities");
										$this->db->join("city_stores","city_stores.city_id=cities.city_id");
										$this->db->order_by("cities.city_name","asc");
										$cities=$this->db->get()->result();
									  foreach($cities as $ct){?>
                                      <option value="<?php echo $ct->city_id;?>" <?php if($this->session->userdata("city")==$ct->city_id){echo "selected";}?>><?php echo $ct->city_name;?></option><?php }?>
                            </select>
										</div>

	

										<div class="col-md-4 col-12 ">

											<label>State*</label>

											<input type="text" name="bstate" class="form-control" required placeholder="State">

										</div>

	

										<div class="col-md-4 col-12 ">

											<label>Pin Code*</label>

											<input type="text" name="bpincode" class="form-control" required placeholder="Zip Code">

										</div>

	

									</div>

	

								</div>

								

								<!-- Shipping Address -->

								

								

							</div>

							

							<div class="col-lg-4">

								<div class="row">

									

									<!-- Cart Total -->

									<div class="col-12 mb-20">

									

										<h4 class="checkout-title">Order Total</h4>

								

										<div class="checkout-cart-total">

											<p>Sub Total <span><i class="fa fa-inr"></i><?php echo $total=$this->cart->total();?></span></p>

											<p>Shipping Fee <span>0</span></p>

											<h4>Grand Total <span><?php echo $total;?></span></h4>

										</div>

									</div>

									

									<!-- Payment Method -->
                                    <div class="col-12">
                                    	<h5 class="checkout-title">Select Delivery Slot</h5>
                                        <div class="checkout-payment-method">	
                                        <?php $dts=$this->db->get("delivery_times")->result_array();
										//print_r($dts);
											 $i=1; foreach($dts as $dt){
				    if($this->db->get_where("orders",array("del_time"=>$dt['dtid']))->num_rows()<$dt['max_del']){?>
                    <div class="single-method">
<input type="radio" id="delivery_time<?php echo $dt['dtid'];?>" <?php if($i==1){echo 'checked';}?> name="del_time" value="<?php echo $dt['dtid'];?>">
<label for="delivery_time<?php echo $dt['dtid'];?>"><?php echo $dt['dt_slot'];?></label>
<p data-method="check"><?php echo $dt['dt_slot'];?></p>
                    </div>
                                       	
                                        <?php $i++;}}?></div>
                                    </div>

									<div class="col-12">

										<h4 class="checkout-title">Payment Method</h4>

										<div class="checkout-payment-method">											

            <div class="single-method">

                <input type="radio" id="payment_check" checked="checked" name="payment_method" value="PayU">

                <label for="payment_check">PayU Money</label>

                <p data-method="check">Pay online with PayU Money</p>

            </div>

            <div class="single-method">

                <input type="radio" id="payment_cash" name="payment_method" value="COD">

                <label for="payment_cash">Cash on Delivery</label>

                <p data-method="cash">Please send a Check to Store name with Store Street, Store Town, Store State, Store Postcode, Store Country.</p>

            </div>

										<button class="btn btn-success place_order" type="submit">Place order</button>

										</div>

									</div>

									

								</div>

							</div>

							

						</div>

					</form>
				</div>

			</div>

		</div>

	</div>
    <script>
	$(document).ready(function(){
		<?php if($oldadds>0){?>
		$(".form-control").removeAttr("required");
		<?php }?>
		$("#store_pickup").click(function(e){e.preventDefault();
			$("#del_type").val("Store Pickup");
			$(".form-control").removeAttr("required");
			$(".store_pickup").slideDown();
			$("#billing-form").slideUp();
			$(".existing_address").slideUp();
		});
		$("#store_pickup2").click(function(e){e.preventDefault();
			$("#del_type").val("Store Pickup");
			$(".form-control").removeAttr("required");
			$(".store_pickup").slideDown();
			$("#billing-form").slideUp();
			$(".existing_address").slideUp();
		});
		$("#home_delivery").click(function(e){e.preventDefault();
			$("#del_type").val("Delivery");
			$(".store_pickup").slideUp();
			$("#billing-form").slideUp();
			$(".existing_address").slideDown();
		});
		$(".add_new_address").click(function(e){e.preventDefault();
			$("#billing-form").slideDown();
			$(".existing_address").slideUp();
			$(".form-control").attr("required",true);
			$("#add_type").val("new");
		});
		$(".select_existing_address").click(function(e){e.preventDefault();
			$(".existing_address").slideDown();
			$("#billing-form").slideUp();
			$(".form-control").removeAttr("required");
			$("#add_type").val("old");
		});
		$(".select_address").click(function(e){e.preventDefault();
			var id=$(this).attr("id");
			$(".well").css("background","#bfbfbf");
			$("#address"+id).css("background","#025802");
			$("#old_add").val(id);
		});
		$(".place_order").click(function(){
			if($("#old_add").val()=="" && $("#add_type").val()=="old" && $("#del_type").val()=="Delivery"){
				alert("Please Select Address");	return false;
			}
		});
	});
	</script>