<?php
error_reporting(0);
$PageSecurity = 15;
$title = _('Apprisal Policy Master') ;

if(isset($_POST['add']))
{
 $month_data=array("1"=>"January","2"=>"February","3"=>"March","4"=>"April","5"=>"May","6"=>"June","7"=>"July","8"=>"August","9"=>"September","10"=>"October","11"=>"November","12"=>"December");



  date_default_timezone_set('Asia/Calcutta'); 
  $prefix=$s->getField('companies','CompanyId',$_SESSION['ACGCompanyId'],'company_code');
  $prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."'",$db);
  $prefix_row=DB_fetch_array($prefix_sql);
  $prefix1=$prefix_row['prefix_code'];
  
  $financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
    $sql="Select voucher_no from hr_post_month where site='".$_REQUEST['site']."' 
  and INSTR(`voucher_no`, '$financial') > 0 order by id desc limit 0,1";

  $result=DB_query($sql,$db);
  $myrow=DB_fetch_array($result);
  //echo DB_num_rows($result);
  if(DB_num_rows($result)>0)
  {
  //$Reqno=$myrow['Reqno'];
  //$req_part1=substr($Reqno,-4);
         if($prefix!='')
      {
      $ExplBill=explode("/",$myrow['voucher_no']);
      $maxval = $ExplBill[4];
        }
        else
        {
        $ExplBill=explode("/",$myrow['voucher_no']);
      $maxval = $ExplBill[3];
        }     
  //$ExplBill=explode("/",$myrow['Reqno']);
  //$maxval = $ExplBill[3];
  //echo $req_part1;
  $req_final=$maxval+1;
  }else
  {
  $req_final="1";
  }
          if($prefix!='')
       $string=$prefix."/".$_REQUEST['site']."/".$financial."/".$prefix1."/";
         else
         $string=$_REQUEST['site']."/".$financial."/".$prefix1."/";

  //$string=$prefix."/".$_REQUEST['site']."/".$financial."/";
   $final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);

   $data1['site']=$_REQUEST['site'];
   $data1['voucher_no']=$final_string;
   $data1['posting_date']=FormatDateForSQL($_REQUEST['doc_date']);
   $data1['month']=$_REQUEST['month'];
   $data1['year']=$_REQUEST['year'];
   $data1['net_payable']=$_REQUEST['netpayable_ledger_amt'];
   $data1[created_date]=date('Y-m-d');
   $data1['created_by']=$_SESSION['UserID'];
   $data1['company_id']=$_SESSION['ACGCompanyId'];
$s->RecordInsert('hr_post_month',$data1);
$lastid=DB_Last_Insert_ID($db,'hr_post_month',$ErrMsg);

       
       

        foreach($_REQUEST['hr_posting_master_dtl'] as $key=>$value)
        {
          if($_REQUEST['amt'][$value]!='')
          {
          $data['hr_post_month_id']=$lastid;
          $data['hr_post_master_dtls_id']=$value;
          //$data['month']=$_REQUEST['month'];
          //$data['year']=$_REQUEST['year'];
          $data['hr_post_value']=$_REQUEST['amt'][$value];
          $s->RecordInsert('hr_posting_month_details',$data);
                if($_REQUEST['actype'][$value]=='DR')
                {
                $data2[]=array("ledgerid"=>$_REQUEST['ledger'][$value],"amount"=>$_REQUEST['amt'][$value],"amount_type"=>$_REQUEST['actype'][$value]);
                }
                else  if($_REQUEST['actype'][$value]=='CR')
                {
                $data2[]=array("ledgerid"=>$_REQUEST['ledger'][$value],"amount"=>$_REQUEST['amt'][$value],"amount_type"=>$_REQUEST['actype'][$value]); 
                }
          }
        }

        $sql_emp=DB_query("select A.loan_ledger,B.loan from empmaster A inner join master_process_salary B
           on A.id=B.emp_id where B.payslip_month='".$_REQUEST['month']."' and payslip_year='".$_REQUEST['year']."'
           and  B.loan!='0.00'",$db);
            while($row1=DB_fetch_array($sql_emp))
            {
          $data2[]=array("ledgerid"=>$row1['loan_ledger'],"amount"=>$row1['loan'],"amount_type"=>'CR');
            }   

           $sql_emp1=DB_query("select A.advance_ledger,B.advance_balance from empmaster A inner join master_process_salary B
             on A.id=B.emp_id where B.payslip_month='".$_REQUEST['month']."' and payslip_year='".$_REQUEST['year']."'
             and B.advance_balance!='0.00'",$db);
            while($row2=DB_fetch_array($sql_emp1))
            {
           $data2[]=array("ledgerid"=>$row2['advance_ledger'],"amount"=>$row2['advance_balance'],"amount_type"=>'CR');   
            }   
      
       $data2[]=array("ledgerid"=>$_REQUEST['netpayable_ledger'],"amount"=>$_REQUEST['netpayable_ledger_amt'],"amount_type"=>'CR');   


// Generate prefix code for journal voucher

    $voucher_id=DB_query("select Voucher_NO as ID from account_book where Vprefix='8' and Branch='".$_REQUEST['site']."' 
      AND dates BETWEEN '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."'   order by id desc limit 0,1",$db);
      if(DB_num_rows($voucher_id)>0)
      {
      $row=DB_fetch_array($voucher_id);
      $voucher_no=$row['ID'];
      
      $XEP=explode("-",$voucher_no);
      
      $new=$XEP[2]+1;
      }
      else
      {
      $new='1';
      }
      
      $location=$s->getField('locations','loccode', $_REQUEST['site'],'prefix');
      $location1=$s->getField('voucher_master','VoucherType','8','VPrefix');
      $string=$location.'-'.$location1.'-';
      $final_string1=$string.str_pad($new,5,"0",STR_PAD_LEFT);


 //  End of Prefix code generation       


        $dataArray['Branch']= $_REQUEST['site'] ;
        $dataArray['VPrefix']= '8' ;
        $dataArray['Voucher_NO']= $final_string1;  
        $dataArray['voucher_type']='Auto';     
        $dataArray['Dates']= FormatDateForSQL($_REQUEST['doc_date']); 
        $dataArray['conv_rate']='1' ;  
        $dataArray['posted_date']= date('Y-m-d');
        $dataArray['AccountBookType']= 'voucher';   
        $dataArray['created_date']= date('Y-m-d');
        $dataArray['created_by']= $_SESSION['UserID'];   
        $dataArray['narration']=$_REQUEST['narration'].$month_data[$_REQUEST['month']];  
        $s->RecordInsert('account_book', $dataArray);
       $getlastid=DB_Last_Insert_ID($db,'account_book', 'id');


   //    print_r($data2);
   $total_credit='';
   $total_debit='';
      foreach($data2 as $key=>$value1)
      {
              if($value1[amount]!='0.00')
              {
                $data3['account_bookid']=$getlastid;
                $data3['ledgerid']=$value1[ledgerid];
                $data3['amount']=$value1[amount];
                $data3['converted_amount']=$value1[amount];
                $data3['currency']=$s->getField('currency_master','abbreviation','INR','id');
                $data3['conv_currency']=$s->getField('currency_master','abbreviation','INR','id');
                $data3['amount_type']=$value1[amount_type];
                if($value1[amount_type]=='DR')
                {  $total_debit[]=$value1[amount];  }
                else if($value1[amount_type]=='CR')
                {  $total_credit[]=$value1[amount]; }      
              $s->RecordInsert('account_book_details', $data3);
             }
      }

      if(!empty($total_credit)) $credit=array_sum($total_credit); else $credit=0;
      if(!empty($total_debit)) $debit=array_sum($total_debit); else $debit=0;

      $update=DB_query("update account_book set total_cramount='".$credit."',total_dramount='".$debit."',total_cramount_conv='".$credit."',total_dramount_conv='".$debit."' where id='".$getlastid."'",$db);
    

}

?>
<script>

</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<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>
<form method="post" action="">
<div class="box">
	<table width="100%" border="0" cellpadding="3" cellspacing="0">
	<tr class="row1">
	<td width="12%" align="right">Branch</td>
	<td width="20%"><select name="site" id="site"  >
	<!--onclick="show_employee();"-->
	<?php $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' 
    and loccode in('".$_SESSION['AssignedBranch']."')",$db);
			while($site_row=DB_fetch_array($site_sql)){?>
			<option value="<?php echo $site_row['loccode'];?>" <?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
			<?php } ?>
		</select></td>
	<td width="12%" align="right">Voucher No.</td>
  <td width="20%"><input type="text" name="doc_no" value="Auto Number" readonly=""  /></td>
  <td width="12%" align="right">Narration</td>
  <td><input readonly type="text" name="narration"  value="Salary Payable For Month"  /></td>
	</tr>
	<tr class="row1">
  <td align="right">Post Date</td>
  <td><input type="text" name="doc_date" readonly="" class="datepicker" value="<?php echo ($_REQUEST['bk_advice_date']!=''?$_REQUEST['bk_advice_date']:date('d/m/Y'))?>"></td>
	<td align="right">Month</td>
	<td><select name="month" id="month"  >
    <!--<option value="">--Select--</option>-->
    <?php  $arr=array(1=>"January","February","March","April","May","June","July","August","September","October","November","December");
        if($arr){
        foreach ($arr as $key => $value) {
        $p='';
        if( $key==$_REQUEST['month'])
        $p='selected';?>
      <option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
    <?php } } ?>
    </select></td>
	<td align="right">Year</td>
	<td><select name="year" id="year" onchange="chk_type_employee();" >
 	<?php
	for($i=date('Y');$i>2000;$i--)
 	{
 		$p='';
 		if( $i==$_REQUEST['payyear'])
			$p='selected';
 	?>
		<option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
 	<?php 
 	}
 	?>
	</select></td>
  </tr>
  <tr class="row1">
    <td colspan="6" align="center"><input type="submit" name="Search" class="search" value="Search"/></td>
	</tr>
  </table>
  <br>
<?php if($_REQUEST['Search'])
{
  $sql_check=DB_query("select id from hr_post_month where site='".$_REQUEST['site']."'
  and month='".$_REQUEST['month']."' and year='".$_REQUEST['year']."'",$db);
 if(DB_num_rows($sql_check)==0)
 {
    if($srchA['site']=='All'){
    $srch_dt=DB_fetch_array(DB_query("select id,net_payable from hr_posting_master",$db));
    }
    else{
	$srch_dt=DB_fetch_array(DB_query("select id,net_payable from hr_posting_master ",$db));
    }
    if($srch_dt['id']!=''){
    $net_payable=$srch_dt['net_payable'];
   
    }
    $idArr='';$salArr='';
    $empRow=DB_query("Select * from empmaster WHERE emp_site='".$_REQUEST['site']."' and blocked!='1'",$db);
   		while($empData = DB_fetch_array($empRow))
   	  	{
   	  		$emparr[]=$empData['id'];
   	  	}       
   	  	if(!empty($emparr)){
		$empid1=implode("','",$emparr);
	    }

   $getRecordArr = DB_query("SELECT id,basic_salary,emp_id ,gross_salary,loan,advance_balance FROM master_process_salary
    WHERE emp_id IN ('".$empid1."')    AND payslip_month='".$_REQUEST['month']."' AND payslip_year='".$_REQUEST['year']."'",$db);
	while($getData = DB_fetch_array($getRecordArr))
   	  	{
   	  		$idArr[]=$getData['id'];
   	  		$salArr[]=$getData['basic_salary'];
   	  		$empArr[]=$getData['emp_id'];
          $netsalary[]=$getData['gross_salary'];
          $loan[]=$getData['loan'];
          $advance[]=$getData['advance_balance'];
   	  	}
   	  if(!empty($idArr)){
   	  	$idArray=implode("','",$idArr);
   	    }else{
   	   	$idArray='';
   	    }
   	  if(!empty($empArr)){
   	  	$empArray=implode("','",$empArr);
   	  }else{
   	  	$empArray='';
   	  }
      $srch_dtls2=DB_fetch_array(DB_query("SELECT parameter_val,id FROM hr_posting_master_details
       WHERE hr_posting_id='".$srch_dt['id']."' AND  parameter_type='Basic'",$db));
     $basic_ledger=$srch_dtls2['parameter_val'];
     $basic_id=$srch_dtls2['id'];
      $srch_dtls1=DB_fetch_array(DB_query("SELECT parameter_val,id FROM hr_posting_master_details
       WHERE hr_posting_id='".$srch_dt['id']."' AND  parameter_type='Special_allow'",$db));
    $spalw_ledger=$srch_dtls1['parameter_val'];
     $spalw_id=$srch_dtls1['id'];
   	  	?>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
  <td valign="top" width="50%">
  <h3>Allowances Part</h3>
		<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
		  <tr>
			<th>Description</th>
			<th width="40%">Ledger</th>
			<th width="40%">Amount</th>
		  </tr>
		  <tr>
		  <td align="right">BASIC</td>
		  <td>
     <select name="ledger[<?php echo $basic_id; ?>]" id="basic_ledger" >
     <?php $dr_sql=DB_query("SELECT AccountsID,AccountName FROM accountledger 
      WHERE AccountsID='".$basic_ledger."'  ",$db);?>
	<option value="0">-- Select --</option>
	<?php while($dr_row=DB_fetch_array($dr_sql)){?>
	<option value="<?php echo $dr_row['AccountsID'];?>" <?php echo ($basic_ledger==$dr_row['AccountsID']?'selected':'')?>><?php echo $dr_row['AccountName'];?></option>
	<?php } ?>
	</select>
	</td>
  <input type="hidden" name="hr_posting_master_dtl[]" value="<?php echo $basic_id; ?>">
  <input type="hidden" name="actype[<?php echo $basic_id; ?>]" value="DR">
	<td><input type="text" name="amt[<?php echo $basic_id; ?>]" value="<?php if(!empty($salArr)){echo array_sum($salArr);}?>" ></td>
		  </tr><?php
		  $all_sql=DB_query("Select * from allowmaster",$db); 
		  $i=1;
		 	 while($all_row=DB_fetch_array($all_sql))
		  	 {
	if($srch_dt['id']!=''){
    $srch_dtls=DB_fetch_array(DB_query("SELECT parameter_val,id FROM hr_posting_master_details WHERE hr_posting_id='".$srch_dt['id']."' AND parameter_id='".$all_row['id']."' AND parameter_type='A'",$db));
    $alwVal=$srch_dtls['parameter_val'];
    }
    $getAllow = DB_fetch_array(DB_query("SELECT sum(allowance_amount) AS awn_amt FROM payslip_salary WHERE mst_prosal IN ('".$idArray."') 
      AND allowance_type='A' AND allowance_id='".$all_row['id']."'",$db));
		  ?>
		  <tr>
			<td align="right"><?php echo $all_row['allowname'];?>
	<input type="hidden" name="allid[<?php echo $i;?>]" id="allid_<?php echo $i;?>" value="<?php echo $all_row['id'];?>" />
		</td>
	<td><select name="ledger[<?php echo $srch_dtls['id']; ?>]" id="allowanceledger_<?php echo $i;?>" >
     <?php $dr_sql=DB_query("SELECT AccountsID,AccountName FROM accountledger 
     WHERE  AccountsID='".$alwVal."'",$db);?>
	<option value="0">-- Select --</option>
	<?php while($dr_row=DB_fetch_array($dr_sql)){?>
	<option value="<?php echo $dr_row['AccountsID'];?>"<?php echo ($alwVal==$dr_row['AccountsID']?'selected':'')?>><?php echo $dr_row['AccountName'];?></option>
	<?php } ?>
	</select></td>
	<td><input type="text" name="amt[<?php echo $srch_dtls['id']; ?>]" value="<?php echo $getAllow['awn_amt'] ?>" ></td>
			<!--onfocus="reversecal_allvalue(this.value,<?php //echo $i; ?>)" -->
		  </tr>
       <input type="hidden" name="actype[<?php echo $srch_dtls['id']; ?>]" value="DR">
      <input type="hidden" name="hr_posting_master_dtl[]" value="<?php echo $srch_dtls['id']; ?>">
		  <?php $i++;} ?>
		 <input type="hidden" name="alwcnt" id="alwcnt" value="<?php echo $i;?>" />
		 <tr>
		 <td align="right">Special Allowance</td>
		 <td>
      <input type="hidden" name="actype[<?php echo $spalw_id; ?>]" value="DR">
       <input type="hidden" name="hr_posting_master_dtl[]" value="<?php echo $spalw_id; ?>">
		 <?php
    //echo "SELECT sum(allowance_amount) AS spcawn_amt FROM payslip_salary WHERE mst_prosal IN ('".$idArray."') 
    // AND allowance_type='A' AND allowance_id='100'";
		 $getspcAllow = DB_fetch_array(DB_query("SELECT sum(allowance_amount) AS spcawn_amt FROM payslip_salary WHERE mst_prosal IN ('".$idArray."') 
     AND allowance_type='A' AND allowance_id='100'",$db));?>
		 <select name="ledger[<?php echo $spalw_id; ?>]" id="spalw_ledger" >
     <?php $dr_sql=DB_query("SELECT AccountsID,AccountName FROM accountledger WHERE  AccountsID='".$spalw_ledger."' ",$db);?>
	<option value="0">-- Select --</option>
	<?php while($dr_row=DB_fetch_array($dr_sql)){?>
	<option value="<?php echo $dr_row['AccountsID'];?>"<?php echo ($spalw_ledger==$dr_row['AccountsID']?'selected':'')?>><?php echo $dr_row['AccountName'];?></option>
	<?php } ?>
	</select></td>
	<td><input type="text" name="amt[<?php echo $spalw_id; ?>]" value="<?php echo $getspcAllow['spcawn_amt']?>" ></td>
		 </tr>
		</table>
		</td>

		<td valign="top">
    <h3>Deduction Part</h3>
		<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
			  <input type="hidden" name="prefix2" id="prefix2" value="D" />
		  <tr>
			<th>Description</th>
			<th width="40%">Value</th>
			<th width="40%">Amount</th>
      </tr>
		 <?php
		  $ded_sql=DB_query("Select * from deduction_master",$db); 
		 $j=1;
		  while($ded_row=DB_fetch_array($ded_sql))
		  {
		  	if($srch_dt['id']!=''){
    $srch_dtls=DB_fetch_array(DB_query("SELECT parameter_val,id FROM hr_posting_master_details WHERE hr_posting_id='".$srch_dt['id']."' AND parameter_id='".$ded_row['id']."' AND parameter_type='D'",$db));
    $dedVal=$srch_dtls['parameter_val'];
    }

    $getDeduct = DB_fetch_array(DB_query("SELECT sum(allowance_amount) AS awn_amt FROM payslip_salary
     WHERE mst_prosal IN ('".$idArray."') AND allowance_type='D' AND allowance_id='".$ded_row['id']."'",$db));
		  ?>
	<tr>
			<td align="right"><?php echo $ded_row['name'];?>
		<input type="hidden" name="dedid[<?php echo $j;?>]" id="dedid_<?php echo $j;?>" value="<?php echo $ded_row['id'];?>" />	  </td>
		<td><select name="ledger[<?php echo $srch_dtls['id']; ?>]" id="deductionledger_<?php echo $j;?>" >
     <?php $dr_sql=DB_query("SELECT AccountsID,AccountName FROM accountledger WHERE   AccountsID='".$dedVal."' ",$db);?>
	<option value="0">-- Select --</option>
	<?php while($dr_row=DB_fetch_array($dr_sql)){?>
	<option value="<?php echo $dr_row['AccountsID'];?>"<?php echo ($dedVal==$dr_row['AccountsID']?'selected':'')?>><?php echo $dr_row['AccountName'];?></option>
	<?php }
$dedamt[]=$getDeduct['awn_amt'];
   ?>
	</select></td>
	<td><input type="text" name="amt[<?php echo $srch_dtls['id']; ?>]" value="<?php echo $getDeduct['awn_amt']?>" ></td>
		  </tr>
       <input type="hidden" name="actype[<?php echo $srch_dtls['id']; ?>]" value="CR">
       <input type="hidden" name="hr_posting_master_dtl[]" value="<?php echo $srch_dtls['id']; ?>">
		  <?php $j++;} ?>
		  <input type="hidden" name="ddtcnt" id="ddtcnt" value="<?php echo $j;?>" />		  
		</table>
		</td>
	 </tr>
</table>	 
<br>
   <table width="100%" border="0" cellpadding="3" cellspacing="0"> 
	  <tr>
		<td valign="top" width="50%">
    <h3>Other Addition Part</h3>
	 <table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
      <input type="hidden" name="prefix2" id="prefix2" value="D" />
		  <tr>
			<th>Description</th>
			<th width="40%">Value</th>
			<th width="40%">Amount</th>
			</tr>
		 <?php
		 $GetOther_Amaster = DB_query("SELECT id,name FROM other_deduction_master WHERE status='A' and type='A' AND CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
		 $oa=1;
		while($RecOthr_A=DB_fetch_array($GetOther_Amaster))
		  {
	if($srch_dt['id']!=''){
    $srch_dtls=DB_fetch_array(DB_query("SELECT parameter_val,id FROM hr_posting_master_details WHERE hr_posting_id='".$srch_dt['id']."' AND parameter_id='".$RecOthr_A['id']."' AND parameter_type='OA'",$db));
    $othaddVal=$srch_dtls['parameter_val'];
    }
    $GetOther_Ddd = DB_query("SELECT sum(B.amount) AS amount FROM monthly_other_deducation AS A
				INNER JOIN monthly_other_deducation_details AS B
				ON A.id=B.parentid
				WHERE B.other_ded_type='A' AND A.empid IN ('".$empArray."') AND A.MONTH='".$_REQUEST['month']."' AND A.YEAR='".$_REQUEST['year']."' AND B.other_ded='".$RecOthr_A['id']."'",$db);
	 $RecOther_Ddd=DB_fetch_array($GetOther_Ddd);
		  ?>
	<tr>
			<td align="right"><?php echo $RecOthr_A['name'];?>
		<input type="hidden" name="othaddid[<?php echo $oa;?>]" id="othaddid_<?php echo $oa;?>" value="<?php echo $RecOthr_A['id'];?>" /></td>
		<td><select name="ledger[<?php echo $srch_dtls['id']; ?>]" id="othraddledger_<?php echo $oa;?>" >
     <?php $dr_sql=DB_query("SELECT AccountsID,AccountName FROM accountledger where AccountsID='".$othaddVal."'  ",$db);?>
	<option value="0">-- Select --</option>
	<?php while($dr_row=DB_fetch_array($dr_sql)){?>
	<option value="<?php echo $dr_row['AccountsID'];?>"<?php echo ($othaddVal==$dr_row['AccountsID']?'selected':'')?>><?php echo $dr_row['AccountName'];?></option>
	<?php } 
$addamt[]=$RecOther_Ddd['amount'];
  ?>
	</select></td>
	<td><input type="text" name="amt[<?php echo $srch_dtls['id']; ?>]" value="<?php echo $RecOther_Ddd['amount']?>" ></td>
		  </tr> <input type="hidden" name="hr_posting_master_dtl[]" value="<?php echo $srch_dtls['id']; ?>">
       <input type="hidden" name="actype[<?php echo $srch_dtls['id']; ?>]" value="DR">
		  <?php $oa++;} ?>
		  <input type="hidden" name="oaddcnt" id="oaddcnt" value="<?php echo $oa;?>" />
		</table>
		</td>
		<td valign="top">
      <h3>Other Deduction Part</h3>
			<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
			  <input type="hidden" name="prefix2" id="prefix2" value="D" />
		  <tr>
			<th>Description</th>
			<th width="40%">Value</th>
			<th width="40%">Amount</th>
      </tr>
		 <?php
		 $GetOther_Ddmaster = DB_query("SELECT id,name FROM other_deduction_master WHERE status='A' and type='D' AND CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
		 $od=1;
		while($RecOthr_Dd=DB_fetch_array($GetOther_Ddmaster))
		  {
		  	if($srch_dt['id']!=''){
    $srch_dtls=DB_fetch_array(DB_query("SELECT parameter_val,id FROM hr_posting_master_details WHERE hr_posting_id='".$srch_dt['id']."' AND parameter_id='".$RecOthr_Dd['id']."' AND parameter_type='OD'",$db));
    $othdedVal=$srch_dtls['parameter_val'];
    }
    $GetOther_Dd = DB_query("SELECT sum(B.amount) AS amount FROM monthly_other_deducation AS A
				INNER JOIN monthly_other_deducation_details AS B
				ON A.id=B.parentid
				WHERE B.other_ded_type='D' AND A.empid IN ('".$empArray."') AND A.MONTH='".$_REQUEST['month']."' AND A.YEAR='".$_REQUEST['year']."' AND B.other_ded='".$RecOthr_Dd['id']."'",$db);
	  				$RecOther_Dd=DB_fetch_array($GetOther_Dd);
		  ?>
	<tr>
			<td align="right"><?php echo $RecOthr_Dd['name'];?>
		<input type="hidden" name="othdedid[<?php echo $od;?>]" id="othdedid_<?php echo $j;?>" value="<?php echo $RecOthr_Dd['id'];?>" /></td>
		<td><select name="ledger[<?php echo $srch_dtls['id']; ?>]" id="othrdedledger_<?php echo $od;?>" >
     <?php $dr_sql=DB_query("SELECT AccountsID,AccountName FROM accountledger WHERE  AccountsID='".$othdedVal."' ",$db);?>
	<option value="0">-- Select --</option>
	<?php while($dr_row=DB_fetch_array($dr_sql)){?>
	<option value="<?php echo $dr_row['AccountsID'];?>"<?php echo ($othdedVal==$dr_row['AccountsID']?'selected':'')?>><?php echo $dr_row['AccountName'];?></option>
	<?php }
$dedamt[]=$RecOther_Dd['amount'];
   ?>
	</select></td>
	<td><input type="text" name="amt[<?php echo $srch_dtls['id']; ?>]" value="<?php echo $RecOther_Dd['amount']?>"  ></td>
   <input type="hidden" name="actype[<?php echo $srch_dtls['id']; ?>]" value="CR">
		  </tr><input type="hidden" name="hr_posting_master_dtl[]" value="<?php echo $srch_dtls['id']; ?>">
		  <?php $od++;} ?>
		  <input type="hidden" name="oddcnt" id="oddcnt" value="<?php echo $od;?>" />
		  <tr>
        <td align="right">Loan</td>
        <td></td>
        <td><input type="text"   value="<?php if(!empty($loan)) echo $dedamt[]= array_sum($loan);  ?>"></td>     
      </tr>
      <tr>
        <td align="right">Advance</td>
        <td></td>
        <td><input type="text"   value="<?php if(!empty($advance)) echo  $dedamt[]=array_sum($advance);  ?>"></td>
      </tr>
       <tr>
     <td align="right">Net Payable</th>
     <td> 
     <select name="netpayable_ledger" id="netpayable_ledger" >
     <?php $dr_sql=DB_query("SELECT AccountsID,AccountName FROM accountledger 
     WHERE   AccountsID='".$net_payable."'",$db);?>
  <option value="0">-- Select --</option>
  <?php while($dr_row=DB_fetch_array($dr_sql)){?>
  <option value="<?php echo $dr_row['AccountsID'];?>"<?php echo ($net_payable==$dr_row['AccountsID']?'selected':'')?>><?php echo $dr_row['AccountName'];?></option>
  <?php } ?>
  </select></td>
  <?php if(!empty($addamt)) $Addition_amt=array_sum($addamt); else $Addition_amt=0;
  if(!empty($dedamt)) $Deduction_amt=array_sum($dedamt); else $Deduction_amt=0;

  $netsalary1=array_sum($netsalary)+$Addition_amt-$Deduction_amt; ?>
  <td><input type="text" name="netpayable_ledger_amt" value="<?php echo round($netsalary1); ?>"  ></td>
     </tr>
		</table>
		</td>
		</tr>
</table>
<p style="text-align:center;">
<?php if($_SESSION['frmAdd']=='1'){?>
<input type="submit" name="add" class="search"  value="Submit" onclick="return chkdatavalid();"/>
<?php }?>
</p>

<?php } else {?>
<p align="center">Posting Already done for this month and year</p>
<?php } } ?>

</form>
<style type="text/css" >
.button{ background-color:#666666;
color: #FFFFFF;
height:25px;
margin:0px 5px 0px 5px;
border:1px solid #359CA2;
}
.link{ color:#9900CC; font-family:"Comic Sans MS"; letter-spacing:1px
}
</style>