@extends('layouts.app')
@section('title')
Book - {{$ebook->title}}
@parent
@stop
@section('content')
<!----Banner Section Starts----> 
@include('layouts.ebook_volume_form_header_section')
<!----Banner Section Ends----> 

<!----Main Section Starts (where all content bodies exist)----> 
<main>
<section>
<div class="container">
  <div class="row">
	<div class="col-md-12">
	  <h2 class="h4">Book Print-on-Demand Order</h2>
		<hr>
		 <div class="card bigbox-hvr-slow">
			  <div class="card-body">
			  
   
		   @if ($errors->any())
					
						
						<div class="card border-0">
						
						<div class="form-row">
						<div class="form-group col-md-12">				
				   
							<div class="alert alert-danger m-0">	
							  <strong>Whoops!</strong> There were some problems with your input.
							  <ul>
									@foreach ($errors->all() as $error)
										<li>{{ $error }}</li>
									@endforeach
								</ul>
							</div>
							
						
						</div>	
						</div>
						</div>
					
					@endif
	
					
				 
				 
@if (isset($preview_billing))
{{ Form::open(array('url' => 'submit_order_print_version/'.$ebook_volume_details[0]->ebook_volume_id.'/'.$copy)) }}


   <div class="row">	
   
  

	<div class="col-md-6">
		<h4>Billing Address:</h4>
		<hr>
		<div class="table-responsive">	
			<table class="table table-striped border">
			<tbody>
				<tr><td width="170" class="border-top-0"><b>First Name:</b></td><td class="border-top-0">{{$preview_billing['fname']}}</td></tr>
				<tr><td width="170"><b>Last Name:</b></td><td>{{$preview_billing['lname']}}</td></tr>
				<tr><td width="170"><b>Address:</b></td><td>{{$preview_billing['address']}}</td></tr>
				<tr><td width="170"><b>City:</b></td><td>{{$preview_billing['city']}}</td></tr>
				<tr><td width="170"><b>State/Province:</b></td><td>{{$preview_billing['state']}}</td></tr>
				<tr><td width="170"><b>Zip/Postal Code:</b></td><td>{{$preview_billing['zip']}}</td></tr>
				<tr><td width="170"><b>Country:</b></td><td>{{$preview_billing['country']}}</td></tr>
				<tr><td width="170"><b>Phone:</b></td><td>{{$preview_billing['phone']}}</td></tr>
				<tr><td width="170"><b>Email:</b></td><td>{{$preview_billing['email']}}</td></tr>
				@if(!empty($preview_billing['promo_code']))
					
					@if (!empty($preview_billing['print_discount_rate']))
						<tr><td width="170"><b>Promo Code:</b></td><td>{{$preview_billing['promo_code']}}</td></tr>
					@else
						<tr><td width="170"><b>Promo Code:</b></td><td><font color="red"><i>Invalid Promo Code</i></font></td></tr>
					@endif
				
				@endif
				
				@if ($preview_billing['order_type'] == 'POD')
				<tr><td width="170"><b>Order Type:</b></td><td>Print On Demand</td></tr>
				@elseif($preview_billing['order_type'] == 'PODandPDF')
				<tr><td width="170"><b>Order Type:</b></td><td>Print On Demand and Web Price</td></tr>
				@endif
				<tr><td width="170"><b>No. of Print Copies:</b></td><td>{{$preview_billing['print_copies']}}</td></tr>
				@if (!empty($preview_billing['ebook_actual_price']) && $preview_billing['print_copies']!='More than 5')
				<tr><td width="170"><b>Ebook Actual Price:</b></td><td>{{$preview_billing['ebook_actual_price']}}<strong> $</strong></td></tr>
				@endif
				
				@if (!empty($preview_billing['print_discount_rate']))
				<tr><td width="170"><b>Discount Percentage:</b></td><td>{{$preview_billing['print_discount_rate']}}<strong> %</strong></td></tr>
				<tr><td width="170"><b>Discounted Price:</b></td><td>{{$preview_billing['grand_total_print']}}<strong> $</strong></td></tr>
			
				@endif
				
				@if (!empty($preview_billing['shipment_price']))
				<tr><td width="170"><b>Shipment Price:</b></td><td>{{$preview_billing['shipment_price']}}<strong> $</strong></td></tr>
				@endif
				@if (!empty($preview_billing['total_amount']))
				<tr><td width="170"><b>Total Amount:</b></td><td>{{$preview_billing['total_amount']}}<strong> $</strong></td></tr>
				@endif
			</tbody>
			</table>
		</div>
  	</div>
	<div class="col-md-6">
		<h4>Shipping Address:</h4>
		<hr>
		<div class="table-responsive">	
			<table class="table table-striped border">
			<tbody >
				<tr><td class="border-top-0" width="150"><b>First Name:</b></td><td class="border-top-0">{{$preview_shipping['fname']}}</td></tr>
				<tr><td width="150"><b>Last Name:</b></td><td>{{$preview_shipping['lname']}}</td></tr>
				<tr><td width="150"><b>Address:</b></td><td>{{$preview_shipping['address']}}</td></tr>
				<tr><td width="150"><b>City:</b></td><td>{{$preview_shipping['city']}}</td></tr>
				<tr><td width="150"><b>State/Province:</b></td><td>{{$preview_shipping['state']}}</td></tr>
				<tr><td width="150"><b>Zip/Postal Code:</b></td><td>{{$preview_shipping['zip']}}</td></tr>
				<tr><td width="150"><b>Country:</b></td><td>{{$preview_shipping['country']}}</td></tr>
				<tr><td width="150"><b>Phone:</b></td><td>{{$preview_shipping['phone']}}</td></tr>
				<tr><td width="150"><b>Email:</b></td><td>{{$preview_shipping['email']}}</td></tr>
				@if (!empty($preview_shipping['comments']))
				<tr><td width="150"><b>Comments:</b></td><td>{{$preview_shipping['comments']}}</td></tr>
				@endif
			</tbody>
			</table>
		</div>
  	</div>


	<input type="hidden" name="billing_fname" value="{{$preview_billing['fname']}}" />
	<input type="hidden" name="billing_lname" value="{{$preview_billing['lname']}}" />
	<input type="hidden" name="billing_address" value="{{$preview_billing['address']}}" />
	<input type="hidden" name="billing_city" value="{{$preview_billing['city']}}" />
	<input type="hidden" name="billing_state" value="{{$preview_billing['state']}}" />
	<input type="hidden" name="billing_zip" value="{{$preview_billing['zip']}}" />
	<input type="hidden" name="billing_country" value="{{ $preview_billing['country'] }}" />
	<input type="hidden" name="billing_phone" value="{{$preview_billing['phone']}}" />
	<input type="hidden" name="billing_email" value="{{$preview_billing['email']}}" />
	<input type="hidden" name="billing_promo_code" value="{{$preview_billing['promo_code']}}" />
	<input type="hidden" name="billing_order_type" value="{{$preview_billing['order_type']}}" />
	<input type="hidden" name="billing_print_copies" value="{{$preview_billing['print_copies']}}" />
	<input type="hidden" name="billing_ebook_actual_price" value="{{$preview_billing['ebook_actual_price']}}" />
	<input type="hidden" name="billing_shipment_price" value="{{$preview_billing['shipment_price']}}" />
	<input type="hidden" name="billing_discount_rate" value="{{$preview_billing['print_discount_rate']}}" />
	<input type="hidden" name="billing_total_amount" value="{{$preview_billing['total_amount']}}" />
	
	
	<input type="hidden" name="shipping_fname" value="{{$preview_shipping['fname']}}" />
	<input type="hidden" name="shipping_lname" value="{{$preview_shipping['lname']}}" />
	<input type="hidden" name="shipping_address" value="{{$preview_shipping['address']}}" />
	<input type="hidden" name="shipping_city" value="{{$preview_shipping['city']}}" />
	<input type="hidden" name="shipping_state" value="{{$preview_shipping['state']}}" />
	<input type="hidden" name="shipping_zip" value="{{$preview_shipping['zip']}}" />
	<input type="hidden" name="shipping_country" value="{{$preview_shipping['country']}}" />
	<input type="hidden" name="shipping_phone" value="{{$preview_shipping['phone']}}" />
	<input type="hidden" name="shipping_email" value="{{$preview_shipping['email']}}" />
	<input type="hidden" name="shipping_comments" value="{{$preview_shipping['comments']}}" />
	
	<div class="col-md-6">
		
		{{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
		</div>
	
{{ Form::close() }}		

</div>
</div>

@else
	   
  
{{ Form::open(array('url' => 'preview_order_print_version/'.$ebook_volume_details[0]->ebook_volume_id.'/'.$copy)) }}
				  
<a id="printtopscroll"></a>

<div class="card ">
			  <div class="card-body">
	<h5>Billing Address</h5>
	<hr>			
 <div class="form-row">	
	<div class="form-group col-md-6">
 <label for="edit-fname">First Name: *</label>
	
 <input type="text" maxlength="50" name="fname" id="edit-fname" size="60" value="{{ old('fname', isset($pre_order->first_name) ? $pre_order->first_name : '') }}" class="form-control" required = 'required'>
	@if ($errors->has('fname'))															
		<label class="control-label text-danger">{{ $errors->first('fname') }} </label>
	@endif	
</div>
<div class="form-group col-md-6" >
 <label for="edit-lname">Last Name: *</label>
 <input type="text" maxlength="50" name="lname" id="edit-lname" size="60" value="{{ old('lname', isset($pre_order->last_name) ? $pre_order->last_name : '') }}" class="form-control" required = 'required'>
 @if ($errors->has('lname'))															
<label class="control-label text-danger">{{ $errors->first('lname') }} </label>
@endif	
</div>
 </div>
 
  <div class="form-row">	
 <div class="form-group col-md-6">
 <label for="edit-email">Email: *</label>
 <input type="text" maxlength="150" name="email" id="edit-email-billing" size="60"  value="{{ old('email', isset($pre_order->email) ? $pre_order->email : '') }}" class="form-control" required = 'required'>
@if ($errors->has('email'))															
<label class="control-label text-danger">The email must be a valid email address.</label>
@endif													
</div>

<div class="form-group col-md-6">
 <label for="edit-address">Address: *</label>
 <input type="text" maxlength="200" name="address" id="edit-address" size="60" value="{{ old('address', isset($pre_order->address) ? $pre_order->address : '') }}" class="form-control" required = 'required'>
 </div> 
  </div>
  
<div class="form-row">	  
	 <div class="form-group col-md-6">
	 <label for="edit-city">City/Town: *</label>
	 <input type="text" maxlength="50" name="city" id="edit-city" size="60" value="{{ old('city', isset($pre_order->city) ? $pre_order->city : '') }}" class="form-control" required = 'required'>
	</div>
	<div class="form-group col-md-6">
	 <label for="edit-state">State/Province: *</label>
	 <input type="text" maxlength="50" name="state" id="edit-state" size="60" value="{{ old('state', isset($pre_order->province) ? $pre_order->province : '') }}" class="form-control" required = 'required'>
	</div>
</div>

<div class="form-row">	  
	<div class="form-group col-md-6">
	 <label for="edit-zip">Zip/Postal Code: *</label>
	 <input type="text" maxlength="50" name="zip" id="edit-zip" size="60" value="{{ old('zip', isset($pre_order->zip) ? $pre_order->zip : '') }}" class="form-control" required = 'required'>
	</div>
	<div class="form-group col-md-6">
	 <label for="edit-country">Select Country: *</label>
	   <select class="form-control" id="billing_country" name="billing_country" required = 'required'>
					<option value="">Country</option>
				 @foreach ($country as $countries)
					<option value="{{$countries->printable_name}}"  @if(request('billing_country') == $countries->printable_name) {{ 'selected' }}
					@elseif(isset($selected_authors->country) and ($selected_authors->country == $countries->printable_name)) {{ 'selected' }} 
					@elseif(isset($pre_order->country) and ($pre_order->country == $countries->printable_name)) {{ 'selected' }} @endif> {{$countries->printable_name}}</option>
				@endforeach
				</select>
	</div>
</div>

<div class="form-row">	
	<div class="form-group col-md-6">
	 <label for="edit-phone">Phone: *</label>
	 <input type="text" maxlength="50" name="phone" id="edit-phone" size="60" value="{{ old('phone', isset($pre_order->phone) ? $pre_order->phone : '') }}" class="form-control" required = 'required'>
	</div>

	<div class="form-group col-md-6">
	 <label for="edit-order-type">Order Type: *</label>
	 <select name="order_type" class="form-control" id="edit-order-type" required = 'required'>
	 
		 <option title="Print On Demand" value="POD" @if($copy=="POD") selected="selected" @endif>Print On Demand</option>
		 <option title="Print On Demand and Web Price" value="PODandPDF"  @if($copy=="PODandPDF") selected="selected" @endif>Print On Demand and Web Price</option>
	 </select>
	</div>
</div>	

<div class="form-row">	
	<div class="form-group col-md-6">
		 <label for="edit-printcopies">No. of Print Copies: *</label>
		 <select name="printcopies" class="form-control" id="edit-printcopies"  required = 'required'>
		 <option title="1" value="1" @if(isset($pre_order->no_of_copies) and ($pre_order->no_of_copies == 1)) {{ 'selected' }} @endif>1</option>
		 <option title="2" value="2" @if(isset($pre_order->no_of_copies) and ($pre_order->no_of_copies == 2)) {{ 'selected' }} @endif>2</option>
		 <option title="3" value="3" @if(isset($pre_order->no_of_copies) and ($pre_order->no_of_copies == 3)) {{ 'selected' }} @endif>3</option>
		 <option title="4" value="4" @if(isset($pre_order->no_of_copies) and ($pre_order->no_of_copies == 4)) {{ 'selected' }} @endif>4</option>
		 <option title="5" value="5" @if(isset($pre_order->no_of_copies) and ($pre_order->no_of_copies == 5)) {{ 'selected' }} @endif>5</option>
		 <option title="More than 5" value="0" @if(isset($pre_order->no_of_copies) and ($pre_order->no_of_copies == 0)) {{ 'selected' }} @endif>More than 5</option>
		 </select>
	</div>
	<div class="form-group col-md-6" id="validate_promocode">
	 <label for="edit-promocode">Promo Code: </label>
	 <input type="text" maxlength="80" id="promo_code" name="promo_code" size="60" value="{{request('promo_code')}}" class="form-control">
	 <span id="promo_code_message"></span>
	</div>
</div>	
	





<div class="form-group py-4"> 
 <label class="option" for="edit-chk-shipping">
 <input type="checkbox" name="chk_shipping" id="edit-chk-shipping" value="1" onclick="javascript:UpdateShippingInfo()" class="form-checkbox mr-3"> If Shipping Address is Same as Billing Address Check on Box</label>
</div>




<h5>Shipping Address</h5>
<hr>
<div class="form-row">
	<div class="form-group col-md-6">
	 <label for="edit-sfname">First Name: *</label>
	 <input type="text" maxlength="50" name="sfname" id="edit-sfname" size="60" value="{{request('sfname')}}" class="form-control" required = 'required'>
	   @if ($errors->has('sfname'))															
<label class="control-label text-danger">{{ $errors->first('sfname') }} </label>
@endif	
	</div>
	<div class="form-group col-md-6" >
	 <label for="edit-slname">Last Name: *</label>
	 <input type="text" maxlength="50" name="slname" id="edit-slname" size="60" value="{{request('slname')}}" class="form-control" required = 'required'>
	  @if ($errors->has('slname'))															
<label class="control-label text-danger">{{ $errors->first('slname') }} </label>
@endif	
	</div>
</div>
<div class="form-row">
	<div class="form-group col-md-6">
	 <label for="edit-saddress">Address: *</label>
	 <input type="text" maxlength="200" name="saddress" id="edit-saddress" size="60" value="{{request('saddress')}}" class="form-control" required = 'required'>
	</div>
	<div class="form-group col-md-6">
	 <label for="">Email: *</label>
	 <input type="text" maxlength="150" name="semail" id="edit-email-shipping" size="60" value="{{request('semail')}}" class="form-control" required = 'required'>
	  @if ($errors->has('semail'))															
<label class="control-label text-danger">The email must be a valid email address.</label>
@endif	
	</div>
	
</div>

<div class="form-row">
	<div class="form-group col-md-6">
	 <label for="edit-sstate">State/Province: *</label>
	 <input type="text" maxlength="50" name="sstate" id="edit-sstate" size="60" value="{{request('sstate')}}" class="form-control" required = 'required'>
	</div>
	<div class="form-group col-md-6">
	 <label for="edit-szip">Zip/Postal Code: *</label>
	 <input type="text" maxlength="50" name="szip" id="edit-szip" size="60" value="{{request('szip')}}" class="form-control" required = 'required'>
	</div>
</div>

<div class="form-row">
	<div class="form-group col-md-6">
	 <label for="edit-scountry">Select Country: *</label>
		<select class="form-control" id="shipping_country" name="shipping_country" required = 'required'>
					<option value="">Country</option>
				 @foreach ($country as $countries)
					<option value="{{$countries->printable_name}}"  @if(request('shipping_country') == $countries->printable_name) {{ 'selected' }}
					@elseif(isset($selected_authors->country) and ($selected_authors->country == $countries->printable_name))) {{ 'selected' }} @endif> {{$countries->printable_name}}</option>
				@endforeach
				</select>
	</div>
	<div class="form-group col-md-6">
	 <label for="edit-sphone">Phone: *</label>
	 <input type="text" maxlength="50" name="sphone" id="edit-sphone" size="60" value="{{request('sphone')}}" class="form-control" required = 'required'>
	</div>
</div>

<div class="form-row">
	
	<div class="form-group col-md-6">
	 <label for="edit-scity">City/Town: *</label>
	 <input type="text" maxlength="50" name="scity" id="edit-scity" size="60" value="{{request('scity')}}" class="form-control" required = 'required'>
	</div>

	<div class="form-group col-md-6">
	 <label for="">Comments:</label>
	 <textarea type="text" rows="3" name="comments" size="60" class="form-control" >{{request('comments')}}</textarea>
	</div>
</div>

			<div class="form-group col-md-12">
	              <!--label for="password" class="col-md-4  col-form-label text-md-right">Captcha</label-->
	              
              <div class="form-group row mt-3 w-100"> 
                    
              <div class="form-group row mt-3 w-100"> 
                    
                      <div class="col-auto mx-auto w-100 d-flex ">
                          <div class="col-md-6 text-right">
                              <div class="captcha">                                       
                                  <span>{!! captcha_img() !!}</span>             
                              </div>
                          </div>
                          <div class="col-md-6">                                        
                              <button type="button" class="btn btn-danger" class="refresh-captcha" id="refresh-captcha">
                                  &#x21bb;
                              </button> 
                          </div>
                      </div>
                      <div class="form-group my-2 mx-auto">
                          <input id="captcha" type="text" class="form-control" placeholder="Enter Captcha" name="captcha">
                          @if ($errors->has('captcha'))

                            <span class="invalid-feedback" style="display: block;">

                                <strong>{{ $errors->first('captcha') }}</strong>

	                      </span>
	                  @endif
                      </div>
              </div>                      
              </div>	              
	        </div>

		
        </div>
    
      </div>

<div class="form-group text-center mt-3">
<input class="btn btn-primary" id="preview" type="submit" value="Preview">
</div>
				  
		{{ Form::close() }}			
   
   @endif
				  
				
		
    </div>
  </section>
  
  
  <script>
  
  function UpdateShippingInfo()
  {
	  
	  
	  if (document.getElementById('edit-chk-shipping').checked == true)
	  {
		  document.getElementById('edit-sfname').value = document.getElementById('edit-fname').value;
		  document.getElementById('edit-slname').value = document.getElementById('edit-lname').value;
		  document.getElementById('edit-saddress').value = document.getElementById('edit-address').value;
		  document.getElementById('edit-email-shipping').value = document.getElementById('edit-email-billing').value;
		  document.getElementById('edit-scity').value = document.getElementById('edit-city').value;
		  document.getElementById('edit-sstate').value = document.getElementById('edit-state').value;
		  document.getElementById('edit-szip').value = document.getElementById('edit-zip').value;
		  document.getElementById('edit-sphone').value = document.getElementById('edit-phone').value;
		  document.getElementById('shipping_country').value = document.getElementById('billing_country').value;
		  
		  
	  }
	else
	{
		 document.getElementById('edit-sfname').value = '';
		  document.getElementById('edit-slname').value = '';
		  document.getElementById('edit-saddress').value = '';
		  document.getElementById('edit-scity').value = '';
		  document.getElementById('edit-sstate').value = '';
		  document.getElementById('edit-szip').value = '';
		  document.getElementById('edit-sphone').value = '';
		  document.getElementById('edit-email-shipping').value ='';
	}	
	  
  }
	
	$(document).ready(function(){	  

		@if(!empty($promo_code))
			validate_promo_code();
		@endif

	  $('html, body').animate({
        scrollTop: $("#topscroll").offset().top
    }, 200);
	});
 	
	$(document).ready(function(){	  
	  $("html, body").animate({
        scrollTop: $("#printtopscroll").offset().top
    }, 200);
	
	});	
	
$( "#promo_code" ).keyup(function(e) 
{
		setTimeout( function(){response = validate_promo_code();}, 2000);
	
});

function validate_promo_code()
{
	var promo_code = $( "#promo_code" ).val();
	var response = 0;
	
	$.ajax({
        type: "POST",
		data: 
		{
			"_token": "{{ csrf_token() }}",
			"promo_code": promo_code,
			ajax: true
		},
        success: function (data) 
		{	console.log(data);
			$( "#promo_code_message" ).html(data[1]);
			if(data[0])
			{
				$( "#validate_promocode" ).removeClass('alert alert-danger');
				$( "#validate_promocode" ).removeClass('alert alert-warning');
				$( "#validate_promocode" ).addClass('alert alert-success');
			}
			else
			{
				$( "#validate_promocode" ).removeClass('alert alert-success');
				$( "#validate_promocode" ).removeClass('alert alert-warning');
				$( "#validate_promocode" ).addClass('alert alert-danger');
			}
        },
		error: function () 
		{	
			$( "#validate_promocode" ).removeClass('alert alert-success');
			$( "#validate_promocode" ).removeClass('alert alert-warning');
			$( "#validate_promocode" ).addClass('alert alert-danger');
		},
		beforeSend: function () 
		{
			//console.log(data);
			$( "#validate_promocode" ).removeClass('alert alert-success');
			$( "#validate_promocode" ).removeClass('alert alert-danger');
			$( "#validate_promocode" ).addClass('alert alert-warning');
			
		}
       
    });    
   
}	

$('#edit-printcopies').change(function () {
    $("#promo_code").attr("disabled", $("#edit-printcopies").val() == "0");
});
</script>

  
</main>
@endsection


