<?php 
$submit_url = $file_name."?page=view_payment_main&action=$action"; 
$submit_url_invoice = $file_name."?page=view_invoice_main&action=$action"; 
$status_submit_url = $file_name."?page=view_payment_main&name=$name";

$submit_url_search = $file_name."?page=view_payment_main"; 
$show_all_page = "page=view_payment_main";
?>
<button data-toggle="collapse" data-target="#booke_appointment_area" type="button" name="" class="btn btn-primary" style="margin:0 0 5px 10px;float:left;clear:right;">Add Payment</button>

<div style="clear:both;"></div>
<div class="panel box box-primary <?=$collapse_payment_area;?>" id="booke_appointment_area">
	<div class="box-header with-border">
		<form action="<?php echo $submit_url;?>" method="post" name="form1" id="form1">
			<div class="col-sm-3">
			<label for="Payment Text" class="control-label">Description</label>
			<textarea class="form-control" rows="4" id="payment_text" name="payment_text" required><?php echo stripslashes($payment_text);?></textarea>
		</div>
		<div class="col-sm-3">
			<label for="Payment Date" class="control-label">Date</label>
			<input type="text" class="form-control datepicker" id="payment_date" name="payment_date" value="<?php (isset($payment_date) && $payment_date !="") ? utility::getFormatedDate($payment_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
			
			<label for="Payment Status" class="control-label">Status</label>
			<? $gsi->getPaymentStatusList("payment_status",$payment_status,"100%",false); ?>
		</div>
		<div class="col-sm-3">
			<label for="Job" class="control-label">Job</label>
			<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2"); ?>
			
			<label for="For Invoice" class="control-label">For Invoice</label>
			<div id="invoice_div">
				<? $gsi->getInvoiceList("invoice_id",$invoice_id,"100%",false,"form-control",$job_id);?>
			</div>
		</div>
		<div class="col-sm-3">
			<label for="Amount" class="control-label">Amount</label>
			<input type="text" class="form-control" id="amount" name="amount" value="<?php echo $amount;?>" required/>
		</div>
			<div class="col-sm-3">
				<div style="clear:both;margin-top:23px;"></div>
				<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
				<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
				<input type="hidden" id="source" name="source" value="<?php echo $source;?>">
				<button type="submit" name="add_master_data" class="btn btn-primary"><?=$button_value?></button>
			</div>
		</form>
	</div>
</div>

<button data-toggle="collapse" data-target="#booke_invoice_area" type="button" name="" class="btn btn-primary" style="margin:0 0 5px 10px;float:left;clear:right;">Add Invoice</button>

<div style="clear:both;"></div>
<div class="panel box box-primary <?=$collapse_invoice_area;?>" id="booke_invoice_area">
	<div class="box-header" >
		<form action="<?php echo $submit_url_invoice;?>" method="post" name="search_form" id="search_form">
			<div class="col-sm-3">
				<label for="Invoice Text" class="control-label">Description</label>
				<textarea class="form-control" rows="4" id="invoice_text" name="invoice_text" required><?php echo stripslashes($invoice_text);?></textarea>
			</div>
			<div class="col-sm-3">
				<label for="Invoice" class="control-label">Date</label>
				<input type="text" class="form-control datepicker" id="invoice_date" name="invoice_date" value="<?php (isset($invoice_date) && $invoice_date !="") ? utility::getFormatedDate($invoice_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
				
				<label for="Invoice Status" class="control-label">Status</label>
				<? $gsi->getInvoiceStatusList("invoice_status",$invoice_status,"100%",false); ?>
			</div>
			<div class="col-sm-3">
				<label for="Amount" class="control-label">Amount</label>
				<input type="text" class="form-control" id="amount" name="amount" value="<?php echo $amount;?>" required/>
				
				<label for="Job" class="control-label">Job</label>
				<? $gsi->getEnqQuoteJobList("job_id_invoice",$job_id_invoice,"100%",false,"form-control select2"); ?>
			</div>
			<div class="col-sm-3">
				<label for="Invoice Number" class="control-label">Invoice Number</label>
				<input type="text" class="form-control" id="invoice_number" name="invoice_number" value="<?php echo $invoice_number;?>"/>
				
				<label for="Due Date" class="control-label">Due Date</label>
				<input type="text" class="form-control datepicker" id="due_date" name="due_date" value="<?php (isset($due_date) && $due_date !="") ? utility::getFormatedDate($due_date) : utility::getFormatedDate(date($config->dateFormat,strtotime("+30 days")));?>" required>
			</div>
			<div style="clear:both;margin-top:23px;"></div>
			<div class="col-sm-3">
				<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
				<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
				<button type="submit" name="add_master_data" class="btn btn-primary"><?=$button_value?></button>
			</div>
		</form>
	</div>
</div>

<div class="box-header" >
<!-- search form -->
<form class="form-horizontal" action="<?php echo $submit_url_search;?>" method="post" name="search_form" id="search_form">
	<div class="form-group">
	  <div class="col-sm-3">
			<label for="Job" class="control-label">Job</label>
			<? $gsi->getEnqQuoteJobList("job_id_search",$job_id_search,"100%",false,"form-control select2"); ?>
		</div>
		<div class="col-sm-2">
			<label for="Consultant" class="control-label">Consultant</label>
			<? Admin::getAdminList("admin_id_search",$admin_id_search,"100%",false,"form-control"); ?>
		</div>
		<div class="col-sm-2">
			<label for="From Appointment Date" class="control-label">From  Date</label>
			<input type="text" class="form-control datepicker" id="from_payment_date" name="from_payment_date" value="<?php (isset($from_payment_date) && $from_payment_date !="") ? utility::getFormatedDate($from_payment_date) : "";?>">
		</div>
		<div class="col-sm-2">
			<label for="Appointment" class="control-label">To Date</label>
			<input type="text" class="form-control datepicker" id="to_payment_date" name="to_payment_date" value="<?php (isset($to_payment_date) && $to_payment_date !="") ? utility::getFormatedDate($to_payment_date) : "";?>">
		</div>
	  <div class="col-sm-3">
		<label for="Postcode" class="control-label">&nbsp;</label><br>
		<button type="submit" class="btn btn-primary">Search</button>
		<button type="button" value="Show All" onclick="javascript:window.location='?<?php echo $show_all_page ?>'" class="btn btn-primary">Show All</button>
	  </div>
	</div>
</form>
<!-- /.search form -->
</div>
<script type="text/javascript">
$(function(){
	$("#job_id").change(function(){	
		var job_id = $(this).val();
		if(job_id != ""){
		var form_data   = {'job_id':job_id};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/payment_management/index.php?page=ajax_actions&action=get_invoice_by_job_id",
				data: form_data,
				success: function(result){
					$("#invoice_div").html(result);
				}
			});
		}else{
			//$("#invoice_div").val("");
		}
	});
	$("#job_id_invoice").change(function(){	
		var job_id = $(this).val();
		if(job_id != ""){
		var form_data   = {'job_id':job_id};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/payment_management/index.php?page=ajax_actions&action=get_invoice_number",
				data: form_data,
				success: function(result){
					$("#invoice_number").val(result);
				}
			});
		}
	});
	//$("#invoice_id").on("change",function(){
	$("#form1").on("change","#invoice_id",function() {	
		var invoice_id = $(this).val();
		if(invoice_id != ""){
		var form_data   = {'invoice_id':invoice_id};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/payment_management/index.php?page=ajax_actions&action=get_invoice_price",
				data: form_data,
				success: function(result){          
					var resultObj = jQuery.parseJSON(result); 
					$("#amount").val(resultObj.invoice_amount);
				}
			});
		}else{
			$("#amount").val("");
		}
	});
});
</script>