<link rel="stylesheet" href="css/new_mxerp.css">
<?php
$PageSecurity = 2;
$title = _('Job Work List');
include('includes/SQL_CommonFunctions.inc');
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];

if($_REQUEST['Id']!='' && $_REQUEST['act']=='del')
{
  $delete1=DB_query("Delete from tpl_work_indent where id='".$_REQUEST['Id']."'",$db);
  $delete2=DB_query("Delete from tpl_work_indent_asset where work_indent_id='".$_REQUEST['Id']."'",$db);
   $delete2=DB_query("Delete from tpl_work_indent_asset_details where work_indent_id='".$_REQUEST['Id']."'",$db);
  prnMsg( _('Record Deleted Successfully'),'success');
  echo "<script>location.href='index.php?route=work_indent_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<?php 
if($_REQUEST['Id']=='' && $_REQUEST['act']==''){
?>  
<style type="text/css">

a{
color: #171717;
text-decoration: none;
}
a:hover{
color: #fff;

text-decoration: none;
}

#wrapper{
width:98%;
margin:auto;
}
.box{
background: #fff;

}
.boxholder{
clear: both;
padding: 5px;
border:#737373 5px solid;
padding-bottom:15px;
}
.tab{
float:left;
height:32px;
width:125px;
margin:0 1px 0 0;
text-align: center;
background:url(images/greentab.jpg) no-repeat;
}
.tabtxt{
margin: 0;
color: #fff;
font-size: 12px;
font-weight: bold;
padding: 9px 0 0 0;d

}
</style>
<style>
.main-dialog-class .ui-widget-header{background: url("/Images/your-background.png") repeat-x scroll 34px 42px #a4cf50;font-size:14px;border:0;text-transform:uppercase}
.main-dialog-class .ui-widget-content{background-image:none;background-color:#fff}

.partially_appr_icon
 {

  background-image:url(images/partially-approve.gif);
  width:118px;
  height:15px;
  border-width:0;
  background-color: transparent;
  cursor: pointer;
 }

.Approved_icon
 {

  background-image:url(images/approved.gif);
  width:61px;
  height:15px;
  border-width:0;
  background-color: transparent;
  cursor: pointer;
 }
</style>
<script type="text/javascript">
 $(function(){
    $('#datepicker').datepicker({
        startDate: '-0m'
        //endDate: '+2d'
    }).on('changeDate', function(ev){
        $('#sDate1').text($('#datepicker').data('date'));
        $('#datepicker').datepicker('hide');
    });

});
</script>
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name"); ?></h1>
<?php if($_SESSION['frmAdd']=='1'){?>
<p align='left'><a href="index.php?route=POModule/work_Indent&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" class="search" value="Add New" /></a>
</p><?php } ?>




<div class="box">
<form method="post" action="">  
<table width="100%" cellpadding="3" cellspacing="0">
<tr class="row1">
  <td width="13%" class="tabledata1"><strong>Branch</strong></td>
  <td width="20%"><select style="width:100%;" name="Site" id="Site">
      <?php
      $SiteName=DB_query("Select * from locations where mst_companyid='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
      while($SiteRow=DB_fetch_array($SiteName))
      { ?>
      <option value="<?php echo $SiteRow['loccode']?>"<?php echo($_REQUEST['Site']==$SiteRow['loccode']?'selected':'');?>><?php echo $SiteRow['locationname']?></option>  
        
    <?php } ?>
    </select>
  </td>
  <td width="13%" class="tabledata1"><strong>From Date</strong></td>
  <td width="20%"><input type="text" name="fdate" id="fdate" value="<?php echo $_REQUEST['fdate']; ?>" style="width:100%;"  class="datepicker" /></td>
  <td width="13%" class="tabledata1"><strong>To Date</strong></td>
  <td><input type="text" name="todate" id="todate" value="<?php echo $_REQUEST['todate']; ?>" style="width:100%;" class="datepicker"  /></td>
  
  
</tr>
<tr class="row1">
  <td colspan="8" style="text-align:center;"><input type="hidden" name="hidsr_no" id="hidsr_no" value="<?php echo $record['seq_no']; ?>" /><input name="Go" type="submit" value="Search" onclick="return frmvalidate()" class="search" /></td>
</tr>
</table>
</form>
<table width="100%" border="1" cellpadding="3" cellspacing="0" align="center" style="border:#808080 1px solid;">
<tr bgcolor="#CCCCCC">
    <td width="20%" rowspan="2" valign="middle"><strong>Branch</strong></td>
    <td rowspan="2" valign="middle"><strong>Indent No. </strong></td>
    <td width="20%" rowspan="2" valign="middle"><strong>Department</strong></td>
    <td width="5%" rowspan="2" valign="middle"><strong>Date</strong></td>
    <td rowspan="2" valign="middle"><strong>Prepared By</strong></td>
    <td width="9%" rowspan="2" valign="middle"><strong>Approval Status</strong></td>
    <td colspan="4" style="text-align:center;"><strong>Action</strong></td>
    </tr>
  <tr bgcolor="#CCCCCC">
    <td width="4%"><strong>View</strong></td>
    <td width="4%"><strong>Edit</strong></td>
    <td width="4%"><strong>Delete</strong></td>
    <td width="4%"><strong>Print</strong></td>
  </tr>
  <?php
         $resultConfig=DB_query("select *  from  conf_work_indent_details",$db);
         $configCount=DB_num_rows($resultConfig);
         $approvedArr=array();
         $resultApproved=DB_query("select work_indent_id,COUNT(*) as app_Count from tpl_work_indent_app where status='Y' group by work_indent_id",$db);
         while($rowApproved=DB_fetch_array($resultApproved))
         {
            $approvedArr[$rowApproved['work_indent_id']]=$rowApproved['app_Count'];
         }
       $subQuery='';
    if($_REQUEST['Site']!='')
      $subQuery.=" and site='".$_REQUEST['Site']."'";
    if($_REQUEST['fdate']!='' && $_REQUEST['todate'])
      $subQuery.=" and work_indent_date between '".FormatDateForSQL($_REQUEST['fdate'])."' and '".FormatDateForSQL($_REQUEST['todate'])."'";
    
  $SQL=DB_query("Select * from tpl_work_indent where CompanyID='".$_SESSION['ACGCompanyId']."' ".$subQuery."  order by id DESC",$db);
   if(DB_num_rows($SQL) >0)
  {
  while($Myrow=DB_fetch_array($SQL))
  {
   
     if($approvedArr[$Myrow['id']] >= $configCount)
    {
  $status1='<input type="button" name="open_add" id="open_edit_'.$k.'" class="Approved_icon" />';  
  }
  else if(($approvedArr[$Myrow['id']] > 0) && ($approvedArr[$Myrow['id']] < $configCount))
  {
  $status1='<input type="button" name="open_add" id="open_edit_'.$k.'" class="partially_appr_icon" />';  
  }
  else
  {
  $status1='<img src="images/status_icon_pending.gif" />'; 
       
    }

   $resultApp=DB_query("select * from tpl_work_indent_app where work_indent_id='".$Myrow['id']."' and status='Y' limit 1",$db);
    $AppCount=DB_num_rows($resultApp);




  ?>
<tr>
<td valign="top"><?php 
  $sitename=$s->getField('locations','loccode',$Myrow['site'],'locationname');
  echo $sitename;?></td>
    <td valign="top"><?php echo $Myrow['work_indent_no'];?></td>
    
    <td valign="top"><?php 
  $vendorname=$s->getField('deptmaster','id',$Myrow['department'],'deptname');
  echo $vendorname;?></td>
    <td valign="top"><?php echo ConvertSQLDate($Myrow['work_indent_date']);?></td>
    <td valign="top"><?php echo $Myrow['prepared_by']?></td>
    <td valign="top"><?php echo  $status1; ?></td>
    <td><?php if($_SESSION['frmView']=='1'){?><a target="_blank" href="index.php?route=POModule/work_Indent_Edit&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&Id=<?php echo $Myrow['id'];?>&act=view"><img src="images/search.gif" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
    <td><?php if($_SESSION['frmEdit']=='1' && $AppCount!=1 ){?><a href="index.php?route=POModule/work_Indent_Edit&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&Id=<?php echo $Myrow['id'];?>&act=Edit"><img src="images/icon-edit.png" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
    <td><?php if($_SESSION['frmDelete']=='1'  && $AppCount!=1){?><a href="index.php?route=work_indent_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&Id=<?php echo $Myrow['id'];?>&act=del" onclick="return confirm('This record will be deleted. Are you sure?')"><img src="images/Icon_Delete.png" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
    <td><?php if($_SESSION['frmDelete']=='1'){?><a target="_blank" href="work_process_print.php?id=<?php echo $Myrow['id'];?>"><img src="images/print.png" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
  </tr>
  <?php }
  }
  else
  {?>
  <tr><td colspan="10">Record Not Found</td></tr>
 <?php  } ?>
</table>
</div>
</div>
  <div style="clear:both;"></div>
  </div>
</div>

</div></div>
<div style="display:none" id="div_id">
weretwtwetwet we wetw twet wete wt wetwtwet
  </div>
 
<?php }

?>

<script language="javascript" type="text/javascript">
//$.noConflict(); 
$(document).ready(function(){ 
    $('input[name=open_add]').click(function(){
     
      $("#div_id").dialog({ 
        title:'Authorized Users',  
        modal: true,
        resizable: false,
        width:350,
        height:200,
        closeText: 'fechar',
        draggable: true,
        show: 'fade',
        hide: 'fade',
        dialogClass: 'main-dialog-class',
        buttons: {
          Exit: function()
          {
            $(this).dialog("close");
          }
        }
      });
      //getapp(finval);
    });
     
    //}  
  });
/*function getapp(val)
{
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
  document.getElementById("div_id").innerHTML=xmlhttp.responseText;
  }
  }
  
  xmlhttp.open("GET","show_users.php?id="+val,false);
  xmlhttp.send();
}*/


function open_items()
{
  window.open("JobWorkItems.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function calculateAmount(a)
{    
  var quantity = document.getElementById("quantity_"+a).value;
  var rate = document.getElementById("rate_"+a).value;
  var total=quantity*rate;
  document.getElementById("totalAmount_"+a).value=total;
}
function calculateBasic()
{
  var basic=0;
  var count=document.getElementById("itemCount").value;
  for(var b=0;b<count;b++)
  {
    var amount=document.getElementById("totalAmount_"+b).value;
    basic=parseFloat(basic)+parseFloat(amount);
  }
  document.getElementById("basicAmount").value=basic.toFixed(2);
}
function calculateServiceTax()
{
  var spercentage=document.getElementById("STaxPerc").value;
  var BasicAmt=document.getElementById("basicAmount").value;
  var totval=BasicAmt*(spercentage/100);
  document.getElementById("STaxValue").value=totval.toFixed(2);
}
function calculateSEdu()
{
  var STaxValue=document.getElementById("STaxValue").value;
  var SEduPerc=document.getElementById("SEduPerc").value;
  var totalval2=STaxValue*(SEduPerc/100);
  document.getElementById("SEduValue").value=totalval2.toFixed(2);
}
function calculateSShe()
{
  var STaxValue=document.getElementById("STaxValue").value;
  var SShePerc=document.getElementById("SShePerc").value;
  var totalval3=STaxValue*(SShePerc/100);
  document.getElementById("SSheValue").value=totalval3.toFixed(2);
}
function calculateTDS()
{
  var TDSPerc=document.getElementById("TDSPerc").value;
  var basicamt=document.getElementById("basicAmount").value;
  var totalval4=basicamt*(TDSPerc/100);
  document.getElementById("TDSValue").value=totalval4.toFixed(2);
} 
function calculateGrandTotal()
{
  var basicAmount=document.getElementById("basicAmount").value;
  var STax=document.getElementById("STaxValue").value;
  var SEdu=document.getElementById("SEduValue").value;
  var SShe=document.getElementById("SSheValue").value;
  var TDS=document.getElementById("TDSValue").value;
  var freight=document.getElementById("freight").value;
  if(basicAmount=='')basicAmount=0;
  if(STax=='')STax=0;
  if(SEdu=='')SEdu=0;
  if(SShe=='')SShe=0;
  if(TDS=='')TDS=0;
  if(freight=='')freight=0;
  var TOTAL=parseFloat(basicAmount)+parseFloat(STax)+parseFloat(SEdu)+parseFloat(SShe)-parseFloat(TDS)+parseFloat(freight);
  document.getElementById("grandTotal").value=TOTAL.toFixed(2);
}
function generateJobNumber(str)
{
  if (str.length==0)
  {
  document.getElementById("jobid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("jobid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","JobNumber.php?q="+str,true);
xmlhttp.send();
}
</script>