
<?php 
//echo "OUTIF";
if(empty($Status))
{
	//echo "INIF";
 //print_r($Status); 
}
?>

<style>
            .table-bordered>thead>tr>th, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>tbody>tr>td, .table-bordered>tfoot>tr>td {border: 1px solid #333;}
			.modal-content {
				width:1000px  ! important;
			}
			
			.modal
{
    padding-right:25% ! important;
}
            </style>
<div class="content-wrapper">
    
 
	 <section class="content">
	 
	 
	 
	 
	 <div>
         <center><b><h2>Purchase Order Approval List </h2></b></center>
	<table id="Requisition" class="table table-bordered table-hover" style="background-color:#fff;font-size:12px;">
  <div align="right" style="padding-right:10px">
     <div id="content" > </div> 
  <div class="modal fade"  role="dialog">
		
   <thead style="background-color:#ddf">
      <tr>
	     
         <th>Purchase Order Number</th>
		 <th>Purchase Order Type</th>
		 <th>Cost Center Name</th>
		 <th>Available Budget Amount</th>
		 <th>Total Order Value</th>
         <th>Created By</th>
         <th>Created Date</th>
		 <th>Status</th>         
         <th>Action</th>
		 <th>Remarks</th>
      </tr>
    </thead>
    <tbody id="ApprovalList">
     
	    <?php
                    if(!empty($AppList))
                    {
						$index = 0;
                        foreach($AppList as $record)
                        {
							$index = $index +1;
							//echo $index;
                    ?> 
					    <tr id="<?php echo $index ?>" >
						
						
						<td><a target="_blank"  href="<?php echo base_url() ?>purchaseorder/CreatePOPrint?PONO=<?php echo $record->PONO ?>&ReqType=<?php echo $record->ReqType ?>"  data-id="<%=index%>" data-userid="<?php echo $record->PONO ?>" ><u><?php echo $record->PONO ?> </td>	
						
						
					
						
						<td><?php echo $record->ReqType ?> </td>
						<td><?php echo $record->CostCenterName ?> </td>
						<td align="right"><?php echo $record->BudgetAmount ?> </td>
						
						<td align="right"><?php echo $record->TotalOrderValue ?></td>
						<td><?php echo $record->FirstName ?></td>
						<td align="right"><?php $Cdt =	new DateTime($record->CreatedDate);
						$CreatedDate =  $Cdt->format('d-m-Y');
						echo  $CreatedDate;
						?></td>
						<td><?php echo $record->StatusName ?></td>
						<?php 
						if($record->StatusName == 'PO APPROVED' or $record->StatusName == 'PO RELEASED')
						{
						
						?>
						
						
						<td>
					
					<select disabled name="selectId" id="selectId" title="You Can't Select Here">        				        
    					        <option value="-1" >Select Option</option>
        				        <option value="1">Approve</option>
        				        <option value="2">OnHold</option>
						    </select>
							</td>  
							
						<?php 
						}elseif($record->StatusName == 'ON HOLD' or $record->StatusName == 'PO CREATED' or $record->StatusName == 'EMERGENCY PO'){
						?>
						<td>
					
					<select name="selectId" id="selectId" title="Select Your Option" onchange="showvalue('<?php echo $record->PONO ?>','<?php echo $index ; ?>',this.options[this.selectedIndex].value,'<?php echo $record->Remarks ?>');">        				        
    					        <option value="-1" >Select Option</option>
        				        <option value="1">Approve</option>
        				        <option value="2">OnHold</option>
						    </select>
							</td> 
						
						<?php }?>
						     <td contenteditable="true" id="remarks<?php echo $index ; ?>"> <?php echo $record->Remarks ?> </td>
						
							</tr>
							
							
							
						<?php
                        }
                    }
                    ?>
    
     
    </tbody>
	
  </table>
 <script>
	function showvalue(PONO,value,Status,Remarks)
	{
		//alert(value);
		var curtremarks=document.getElementById('remarks'+value+'').innerHTML;
		//alert(curtremarks);
		//var curtremarks="CUR"
		var PO=PONO;
		//var val=value;
		var Status=Status;
		
		var Remarks=Remarks+'||'+curtremarks;
		//alert(Remarks);
		var StatusCode='';
		var srtMsg='';
		//alert(PO+"-"+Status+"-"+StatusCode+"-"+Remarks);
		if(Status != '-1'){
		if(Status == '1'){
		var strMsg='Do you want to Approve this Purchase Order?'
		var StatusCode='ST025';
         //alert(StatusCode);
		}
		else if(Status == '2')
		{
	    var strMsg='Do you want to put Hold this Purchase Order?';
		var StatusCode='ST020';
		//alert(StatusCode);
		}
		
		/* MSG*/
		var answer = confirm(strMsg);
		if (answer) 
		{ 	
			$('#content').loader('show');
		    $.ajax({ 
			data:{PONO:PO,SCode:StatusCode,NewRemarks:Remarks},
			type:"POST",
			url:"<?php echo base_url() ?>purchaseorder/ApprovePO",
			success:function(data) {
			if(data)
			{
				$('#content').loader('hide'); 
				 alert(data);
				 location.reload();		 
			}
			else
			{
				alert("Error");	
			}			
		
		}

  
}); 

}
else
{
return;
}
		
	
		/* MSG*/
		
	}
	else
{
alert('please Select Status!');
}

	
	} //End of showvalue function for approve/hold po status
</script> 
         
 
         <br>
	 </div>
         </div>
         
        </section>
</div>

<script> 
	var startDate = '';
	 var endDate = '';
 
function Reset()
{
	 $('#RequisitionStatus').val("-1");
	 $('#SearchDate').val('');
}
<!-- JQuery For POP UP and Getting all relevant Data -->
$("#myModal").on("shown.bs.modal", function(e) {
    var  ReqId = $(e.relatedTarget).data('userid');
	$("#RequistionNo").val('');
	$("#drpSupplier").val('');
	$("#POType").val('');
	$("#Tax Range").val(''); //not conform
	$("#SupAddress").val('');
	$("#DeliveryAddr").val('');
    $("#PODate").val('');
	$("#Deliverydt").val('');
	$("#tbleAppend").empty();
	 $("#txtTotBasicAmount").val('');
	 $("#txtTotalDiscount").val('');
	 $("#txtTotalVat").val('');
	 $("#txtTotCST").val('');
	 $("#txtTotalPackaing").val('');
	 $("#txtTotExciseDuty").val('');
	 $("#txtTotalGST").val('');
	 $("#txtTotalInsurance").val('');
	 $("#txtTotalFreight").val('');
	  $("#txtTotalOtherTaxes").val('');
	   $("#txtTotalOrderValueSummary").val('');
	    $("#txtSpcialInstruction").val('');
	 $('#AlertImg').attr("style","display:none;");
	
	$('#content').loader('show');
		    $.ajax({ 
			data:{id:ReqId},
			type:"POST",
			dataType: 'json',
			url:"<?php echo base_url() ?>requisitionform/ViewRequest",
			success:function(json) {
			//	success:function(data) {
				$('#content').loader('hide');
				//alert(data);
				$("#ReqType").val(json.Requist[0]['ReqType']);	
				$("#ReqBy").val(json.Requist[0]['Requestedby']);
				 $("#ReqDate").val(json.Requist[0]['CreatedDate']);
		        $("#Desigination").val(json.Requist[0]['Designation']);
				$("#CostCenter").val(json.Requist[0]['CostCenterCode']);
				 $("#AvlBudgetAmount").val(json.AvilBudAmount);
					
				$("#tbleAppend").append(json.Items);		
		
		}
  
}); 
	
});

<!-- End of JQuery For POP UP and Getting all relevant Data -->

function printpdf(PONO,value,Status) {
	
	
	var PONO =PONO;
	var Status = Status;
	var value = value;
	alert(PONO+Status+value);
	
	 if(PONO != '' && Status != '' && value != ''){
         	alert('inside if '+PONO+Status+value);
			
			$.ajax({ 
			data:{PONO1:PONO,Status1:Status},
			type:"POST",
			url:"<?php echo base_url() ?>purchaseorder/Poprintpdf",
			/*success:function(data) {
			if(data)
			{
				alert(data);
			}
			else
			{
				alert("Error");	
			}			
		
		}*/

  
});
			 
	 }
	 else{
		 alert('inside else '+PONO+Status+value);
	 }
}

	
$(function() {	
	var d = new Date();

	var month = d.getMonth();
	var day = d.getDate();
	var year = d.getFullYear()  ;
	var SIAStartYear = year - 2015;
	var mindt = year-70;
	var maxdt =  year-15;
    $( ".datePicker" ).datepicker(
	{ 
	 	minDate : new Date(year-SIAStartYear,1,1),
		maxDate :'now',
		dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,	  
	}
	);
    //$('#SearchDate').daterangepicker(  	);
    //Initialize Select2 Elements
    $(".select2").select2();
	//$('#SearchDate').val('');
	$('#SearchDate').daterangepicker(
{
    locale: {
      format: 'DD-MM-YYYY'
    },
   
	 showDropdowns: true
}, 
function(start, end, label) {
	
	 startDate = start.format('DD-MM-YYYY');
	  endDate = end.format('DD-MM-YYYY');
	    $('#FromDate').val(startDate);
	   $('#ToDate').val(endDate);
	 
	
    //alert("A new date range was chosen: " + start.format('DD-MM-YYYY') + ' to ' + end.format('DD-MM-YYYY'));
});


	
});
$(function () {
   
   $('#Items').DataTable({
      "paging": false,
      "lengthChange": true,
      "searching": false,
      "ordering": false,
      "info": false,
      "autoWidth": false
	   
    }); 
    $('#Requisition').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": true
	   
    }); 
  });
	</script>
