<html>
<head>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<?

 session_start();
 include("test.php");
 include ("opendb.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='index.php' </script>";
  return;
}
?>
<STYLE>
#popup {

  
position: fixed; top: 50%; left: 60%; width: 200px; height: 100px; margin-left: -300px; margin-top: -200px;
  display:none;
}
</STYLE>
<style>
.cont
	{


       background-color:#3b5998;

	//background:url(images/bg-inner.jpg) #e9e0c3 repeat-x;
  	width: 100%;position: absolute ;
	height:99%;
    	/* Optional - just for DIV)*/
    	//border: solid 1px #000000;
	-moz-box-shadow: 0px 5px 5px #888;
	-webkit-box-shadow: 0px 5px 5px #888;
	box-shadow: 0px 5px 10px #888;
    
	}









        #conf_panel,#csh_panel{  

        width:250px;
        margin-top:200px;
        position:fixed; 
        top: 1px;  
        left: 450px;  
        text_align:center;
        
        -moz-box-shadow: 0 0 2px 2px #888;
        -webkit-box-shadow: 0 0 2px 2px#888;
         box-shadow: 0 0 2px 2px #888;
     
        background-color: white;  
      
        color: black;  
        display: none; 
        border:1px solid #C2DFFF; 

    }  

.conf_tbl th{
  
    font-weight: bold;  
    color: white; 
    border:1px solid #D7D7D1;
    height:45px;
    border-collapse:collapse;

   

background: rgb(181,189,200); /* Old browsers */
background: -moz-linear-gradient(top, rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,189,200,1)), color-stop(36%,rgba(130,140,149,1)), color-stop(100%,rgba(40,52,59,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* W3C */
//filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */

 }




.conf_tbl td{

    height:32px;
    border: 1px solid #A9A9A9;
  
  text-align:left;
    // font-size:4 px;  
    color: black; 
background: -moz-linear-gradient(top, rgba(246,248,249,1) 0%, rgba(229,235,238,0.94) 50%, rgba(215,222,227,0.94) 51%, rgba(233,237,240,0.91) 81%, rgba(245,247,249,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(246,248,249,1)), color-stop(50%,rgba(229,235,238,0.94)), color-stop(51%,rgba(215,222,227,0.94)), color-stop(81%,rgba(233,237,240,0.91)), color-stop(100%,rgba(245,247,249,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* W3C */
//filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f6f8f9', endColorstr='#f5f7f9',GradientType=0 ); /* IE6-9 */



 }

.conf_tbl input[type="text"]  {
   // padding: 0px 5px 0px 5px;
    border-style:none;
    border-color: white;//transparent;
    background-color: transparent;
   // font-size:12px;

}
</style>

<script>

/** code below for drag the confirmation div */
window.onload = function(){
    draggable('conf_panel');
};

var dragObj = null;
function draggable(id)
{
    var obj = document.getElementById(id);
    obj.style.position = "absolute";
    obj.onmousedown = function(){
            dragObj = obj;
    }
}

document.onmouseup = function(e){
    dragObj = null;
};

document.onmousemove = function(e){
    var x = e.pageX;
    var y = e.pageY;

    if(dragObj == null)
        return;

    dragObj.style.left = x +"px";
    dragObj.style.top= y +"px";
};


 function downpayment(){

    var e = document.getElementById('conf_panel');
    if(e.style.display == 'block') {
        e.style.display = 'none';
    } else {
        e.style.display = 'block';
    }
 }


</script>

<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>

<script type="text/javascript">
	window.onload = function(){
		new JsDatePick({
			useMode:2,
			target:"inputField",
			dateFormat:"%Y-%m-%d"
			
		});
		new JsDatePick({
			useMode:2,
			target:"inputField1",
			dateFormat:"%Y-%m-%d"
			
		});
		new JsDatePick({
			useMode:2,
			target:"inputField2",
			dateFormat:"%Y-%m-%d"
			
		});
		
              
	};
</script>


</head>
<body>
<?php include('includes/top.php'); ?>
   <center>

<h3><font color='white'>Down Payment Receipt</H3>
<form action='<?Print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>
<table class=noprint>	
<tr><td> RO Settled<input type='radio' name='flag' value='1'/></td> <td>UNSETTLED RO <input type='radio' name='flag' value='2'/></td><td>ADVANCED DPR <input type='radio' name='flag' value='3'/></td></tr>

<tr><th colspan=3 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'></th></tr>
<tr><td colspan=8><input type='button' name='view_downpayment' value='Add Payment' onclick='downpayment()' /></td></tr>
</table>
</td></tr>
</table>
</form>


<div id="popup" class="alist" style="display:none;">
<form name='form1'>
<table height='100%' width='100%' class='report' >
  <tr><th colspan=2>Add Bank &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value='X' id='close' onclick='close_div();'/></th></tr>
   <tr> <td>Select Bank:</td><td><select name='bnk_name' id='bnk_name'>
 <?
   $select=mysqli_query($db,"select * from ledger where grp='Bank accounts' or grp='Bank O/d' and brcode='$brcode' order by led") or die("ERR6:".mysqli_error($db));
    print "<option></script>";
   while($row=mysqli_fetch_array($select)){

         print "<option>$row[0]</script>";
    }
  ?>
    </select>
  </td> </tr>
  <tr> <td>Date:</td> <td><input type="text" id="inputField1" value="<?echo date('Y-m-d');?>" name="dt" readonly  ></td></tr>
    <tr> <td>Narration:</td> <td><input type="text" id="narrt" name="narrt"><input id="dpr_id" type="hidden"/></td></tr>
    <tr> <th colspan=2>
	<input type='button' name='btbnk' value='Post' onclick="acc_fun1('bank')">
   </th></tr>   </table>
</form>
</div>

<?

$flag1='cash';
$flag2='bank';

if($flag==1)

{
	$i=1;
 	print "<table border=1 style='border-collapse:collapse;border 1px solid black;'  bgcolor='white'>";

 	print "<tr bgcolor='steelblue'><th colspan='8' > <h2>RO Settled</h2></th></tr>";

 	print "<tr bgcolor='steelblue'><th>Dpr No <th>Dpr Date<th>Dpr Amt <th>Jobno<th>Customer<th>Regno<th>vehicle name<th>Action</tr>";
	
 	$sql=mysqli_query($db,"select distinct(down_payment.jcno),sum(down_payment.amt) from down_payment INNER JOIN gateentry ON down_payment.jcno=gateentry.jcno where  down_payment.brcode='$brcode' and gateentry.invno >'0' group by down_payment.jcno order by down_payment.jcno");

 	while($res=mysqli_fetch_array($sql))
        {

           $sql1=mysqli_query($db,"select sum(jcardparts.gtot) from jcardparts INNER JOIN gateentry ON jcardparts.jcno=gateentry.jcno where jcardparts.jcno='$res[0]' and jcardparts.brcode='$brcode'");
   	    $res1=mysqli_fetch_array($sql1);

   	    $sql2=mysqli_query($db,"select sum(jcardserv.servamt) from jcardserv INNER JOIN gateentry ON jcardserv.jcno=gateentry.jcno where jcardserv.jcno='$res[0]' and jcardserv.brcode='$brcode'");
   	    $res2=mysqli_fetch_array($sql2);
 			
   	    $tot_payment=$res1[0]+$res2[0];

   	    if( ((mysqli_num_rows($sql1)<=0)&&(mysqli_num_rows($sql2)<=0))||(($res1[0]=='')&&($res2[0]=='')) )

      			$tot_payment=0;
                 
           if(($tot_payment>0)&&($res[1]>=$tot_payment))
               {
  				
                     $sql1=mysqli_query($db,"select * from down_payment where  brcode='$brcode' and jcno='$res[0]' and jvno=0 order by jcno");

    			 while($res1=mysqli_fetch_array($sql1))
     				 {
				      $typ=$res1['typ'];

                                 if(strlen($typ)<=0){

       			         print "<tr><td>$res1[0]</td><td>$res1[5]</td><td>$res1[4]</td><td>$res1[1]</td><td>$res1[3]</td><td>$res1[2]</td><td></td><td id='acc_bttn'><input type='button' name='cash' value='Cash' onclick='fun_csh( $res1[0])'/> <input type='button' name='bank' value='bank' onclick='showPopup( $res1[0])'/><input type='button' name='lpo' value='LPO' onclick='fun_lpo($res1[1])' /> </td></tr>";
                                  }
     				 }

  			$i++;
               }

  	   } 

 	print "</table>";
}



if($flag==2)

{
	$i=1;

 	print "<table border=1 style='border-collapse:collapse;'  bgcolor='white'>";

 	print "<tr bgcolor='steelblue'><th colspan='8' > <h2>UNSETTLED RO</h2></th></tr>";

 	print "<tr bgcolor='steelblue'><th>Dpr No <th>Dpr Date <th>Dpr Amt<th>Jobno<th>Customer<th>Regno<th>vehicle name<th>Action</tr>";
	
 	$sql=mysqli_query($db,"select distinct(down_payment.jcno) ,sum(down_payment.amt) from down_payment INNER JOIN gateentry ON down_payment.jcno=gateentry.jcno where  down_payment.brcode='$brcode' and gateentry.invno >'0' group by down_payment.jcno order by down_payment.jcno");

       while($res=mysqli_fetch_array($sql))
         {
            $sql1=mysqli_query($db,"select sum(jcardparts.gtot) from jcardparts INNER JOIN gateentry ON jcardparts.jcno=gateentry.jcno where jcardparts.jcno='$res[0]' and jcardparts.brcode='$brcode'");
   	     $res1=mysqli_fetch_array($sql1);

   	     $sql2=mysqli_query($db,"select sum(jcardserv.servamt) from jcardserv INNER JOIN gateentry ON jcardserv.jcno=gateentry.jcno where jcardserv.jcno='$res[0]' and jcardserv.brcode='$brcode'");
   	     $res2=mysqli_fetch_array($sql2);

            $tot_payment=$res1[0]+$res2[0];
             
            if(((mysqli_num_rows($sql1)<=0)&&(mysqli_num_rows($sql2)<=0))||(($res1[0]=='')&&($res2[0]=='')) )
      				
                 $tot_payment=0;
                 
           if(($tot_payment>0)&&($res[1]<$tot_payment))
               {
  				
                 $sql1=mysqli_query($db,"select * from down_payment where  brcode='$brcode' and jcno='$res[0]' and jvno=0 order by jcno");

    		   while($res1=mysqli_fetch_array($sql1))
     		    {
     
       	     print "<tr><td>$res1[0]</td><td>$res1[5]</td><td>$res1[4]</td><td>$res1[1]</td><td>$res1[3]</td><td>$res1[2]</td><td></td><td id='acc_bttn'><input type='button' name='cash' value='Cash' onclick='fun_csh( $res1[0])'/> <input type='button' name='bank' value='bank' onclick='showPopup( $res1[0])'/> </td></tr>";

     	           }

  		   $i++;
  		} 

         }

 	print "</table>";
 }


if($flag==3)

{
	$i=1;
 	print "<table border=1 style='border-collapse:collapse;' bgcolor='white'>";

 	print "<tr bgcolor='steelblue'><th colspan='8' > <h2>ADVANCED DPR </h2></th></tr>";

 	print "<tr bgcolor='steelblue'><th>Dpr No <th>Dpr Date <th>Dpr Amt<th>Jobno<th>Customer<th>Regno<th>vehicle name<th>Action</tr>";
	
 	$sql=mysqli_query($db,"select distinct(down_payment.jcno) from down_payment INNER JOIN gateentry ON down_payment.jcno=gateentry.jcno where  down_payment.brcode='$brcode' and gateentry.invno=0 order by down_payment.jcno");

 	while($res=mysqli_fetch_array($sql))
         {
              $sql1=mysqli_query($db,"select * from down_payment where  brcode='$brcode' and jcno='$res[0]' and jvno=0 order by jcno");

    	       while($res1=mysqli_fetch_array($sql1))
     		  {

                   print "<tr><td>$res1[0]</td><td>$res1[5]</td><td>$res1[4]</td><td>$res1[1]</td><td>$res1[3]</td><td>$res1[2]</td><td></td><td id='acc_bttn'><input type='button' name='cash' value='Cash' onclick='fun_csh( $res1[0])'/> <input type='button' name='bank' value='bank' onclick='showPopup( $res1[0])'/> </td></tr>";

     		  }

  	       $i++;
  	  } 

 	print "</table>";
}

?>
 
</center>

<div id="conf_panel" class="alist" style="display:none;">
  
   <form name='form2'>
          <table  border='1' class='conf_tbl' style="border_collpase:collapse;background-color:white;  " width='100%'>
  
 	  <tr><th colspan=2>Add LPO Remarks  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value='X' id='close'  onclick='close_div();'/></th></tr>
  
           <tr> <td> Type:</td> <td><select name='sett_typ' id='sett_typ' /><option >LPO</OPTION><option >OTHERS</OPTION></select></td></tr>

  	  <tr> <td> JobNo:</td> <td><input type='text' name='jobno' id='jobno' readonly  size=8/></td></tr>

 	  <tr>  <td>Remarks:</td><td> <textarea name='rmk' id='rmk'> </textarea></td></tr>
        
         <tr> <td>Date:</td> <td><input type="text" id="inputField" value="<?echo date('Y-m-d');?>" name="dt" readonly  ></td></tr>

  	 <tr>  <th colspan=2><input type='button' name='add_amt' value='Save' onclick="upd_lpo()"/> </td></tr>

  
  </table>
 </form>

</div>
<!-- below div for get cash date-->
<div id="csh_panel" class="alist" style="display:none;">
  
   <form name='form3'>
          <table  border='1' class='conf_tbl' style="border_collpase:collapse;background-color:white;  " width='100%'>
  
         <tr><th colspan=2>Add Date  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value='X' id='close'  onclick='close_div();'/></th></tr>
  	  
  	  <tr> <td> JobNo:</td> <td><input type='text' name='id1' id='dpr_id_csh' readonly  size=8/></td></tr>

 	  
         <tr> <td>Date:</td> <td><input type="text" id="inputField2" value="<?echo date('Y-m-d');?>" name="dt" readonly  ></td></tr>

  	 <tr>  <th colspan=2><input type='button' name='add_amt' value='Save' onclick="acc_fun('Cash')"/> </td></tr>

  
  </table>
 </form>

</div>



</body>

<script>

 function acc_fun(flag){

 var id=  document.getElementById('dpr_id_csh').value;
 var dt=document.getElementById('inputField2').value;
 var r=confirm("Do you want to save cash receipt");

 if (r==true)
  {

    document.getElementById('acc_bttn').innerHTML="Loading...";

 	 if (window.XMLHttpRequest)
  		{
  		xmlhttp=new XMLHttpRequest();
 		 }
		else
 		 {
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  	 		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	 		{
            			alert(xmlhttp.responseText);

                            window.open('accounts/dpr_voucher.php?id='+id);

                            document.location='downpayment_repo.php';

       
        		}

      		}
    
 xmlhttp.open("GET","ajaxupd_acc_down_amt.php?id="+id+"&&flag="+flag+"&&dt="+dt,true);
 xmlhttp.send(); 

  }//close confirm box
  
 }//close fun



function acc_fun1(flag){

 var r=confirm("Do you want to save bank receipt");

 if (r==true)
  {
 	document.getElementById("popup").style.display = "none";
 	var id=document.getElementById('dpr_id').value;
       var bnk_name=document.getElementById('bnk_name').value;
	var dt=document.getElementById('inputField1').value;
	var narrat=document.getElementById('narrt').value;
	document.getElementById('acc_bttn').innerHTML="Loading...";

 	 if (window.XMLHttpRequest)
  		{
  		xmlhttp=new XMLHttpRequest();
 		}
		else
 		{
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  	 		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	 		{
            			
                         
                            window.open('accounts/dpr_voucher.php?id='+id);

                            document.location='downpayment_repo.php';
                            
        		}

      		}
	
		var url="ajaxupd_acc_down_amt.php?id="+id+"&&flag="+flag+"&&dr="+bnk_name+"&&dt="+dt+"&&narratn="+narrat;
	
    
 xmlhttp.open("GET","ajaxupd_acc_down_amt.php?id="+id+"&&flag="+flag+"&&dr="+bnk_name+"&&dt="+dt+"&&narratn="+narrat,true);
 xmlhttp.send(); 


  }//close confirmation 

}//close fun..





function showPopup(id) {
   document.getElementById("popup").style.display = "block";
     document.getElementById("dpr_id").value=id;

}


/**  below function for get div while LPO button click... ****/

function fun_lpo(id1){

    var e = document.getElementById('conf_panel');

    document.getElementById('jobno').value=id1;

    if(e.style.display == 'block') {
        e.style.display = 'none';
    } else {
        e.style.display = 'block';
    }
 }

/**  below function for get date while cash savings... ****/
function fun_csh(id1){

    var e = document.getElementById('csh_panel');

    document.getElementById('dpr_id_csh').value=id1;

    if(e.style.display == 'block') {
        e.style.display = 'none';
    } else {
        e.style.display = 'block';
    }
 }




function close_div(){
   var list = document.getElementsByClassName("alist");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('conf_panel');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }



function upd_lpo(){

 var r=confirm("Do you want to save Lpo");
 
 if (r==true)
  {
 	document.getElementById("conf_panel").style.display = "none";
 	var jno=document.getElementById('jobno').value;
       var rmk=document.getElementById('rmk').value;
       var flag=document.getElementById('sett_typ').value;

 	 if (window.XMLHttpRequest)
  		{
  		xmlhttp=new XMLHttpRequest();
 		 }
		else
 		 {
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  	 		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	 		{
            			 alert(xmlhttp.responseText);
                         
                  	}

      		}
    
 xmlhttp.open("GET","ajaxupd_acc_down_amt.php?id="+jno+"&&flag="+flag+"&&rmk="+rmk,true);
 xmlhttp.send(); 


  }//close confirmation 

}//close fun..




 </script>

