<?php
include('cocoon_config.php');


if (isset($_POST['Save'])) {




  $financial = substr($_SESSION['YearStart'], -2) . "-" . substr($_SESSION['YearEnd1'], -2);
  $sql = "Select slip_no from hr_incentive_cal where 
         INSTR(`slip_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);
    $ExplBill = explode("/", $myrow['slip_no']);
    $maxval = $ExplBill[2];
    //echo $req_part1;
    $req_final = $maxval + 1;
    //echo "<br>".$req_final;
  } else {
    $req_final = "1";
  }

  $string = $financial . "/" . 'INC/';
  $final_string = $string . str_pad($req_final, 4, "0", STR_PAD_LEFT);
  $data['slip_no']             = $final_string;
  $data['month']               = $_REQUEST['month'];
  $data['year']                = $_REQUEST['year'];
  $data['description']         = $_REQUEST['desc'];
  $data['total_incentive_amt'] = $_REQUEST['total_amt'];
  $data['reverse_amt']         = $_REQUEST['reverseded'];
  $data['created_date']        = date('Y-m-d');
  $data['created_by']          = $_SESSION['UserID'];
  $data['companyid']           = $_SESSION['ACGCompanyId'];
  $insert = $s->RecordInsert('hr_incentive_cal', $data);
  $lastid = DB_Last_Insert_ID($db, 'hr_incentive_cal', 'id');
  for ($i = 0; $i < count($_REQUEST['dedid']); $i++) {

    $data1['hr_incentive_cal_id']        = $lastid;
    $data1['other_deduction_master_id']  = $_REQUEST['dedid'][$i];
    $data1['amt']                        = $_REQUEST['ded_amount'][$i];
    $data1['total_amt']                  = $_REQUEST['deddisamount'][$i];
    $insert = $s->RecordInsert('hr_incentive_cal_dtls', $data1);
  }
  for ($cnt = 0; $cnt < count($_REQUEST['services']); $cnt++) {
    $data_array['hr_incentive_cal_id']    = $lastid;
    $data_array['smajors_id']             = $_REQUEST['major'][$cnt];
    $data_array['majerminer_masters_id']  = $_REQUEST['minor'][$cnt];
    $data_array['percentage']             = $_REQUEST['percentage'][$cnt];
    $data_array['services_id']            = $_REQUEST['services'][$cnt];
    $data_array['distributed_amt']        = $_REQUEST['disamount'][$cnt];
    $data_array['amount']                 = $_REQUEST['amount'][$cnt];
    $s->RecordInsert('hr_incentive_cal_dtls_main', $data_array);
  }

  for ($cnt1 = 1; $cnt1 <= count($_REQUEST['gradeid']); $cnt1++) {
    $data2['hr_incentive_cal_id'] = $lastid;
    $data2['gradeid'] = $_REQUEST['gradeid'][$cnt1];
    $data2['grade_basic'] = $_REQUEST['totalbasic'][$cnt1];
    $data2['employee_count'] = $_REQUEST['employeecount'][$cnt1];
    $data2['incentive_perc'] = $_REQUEST['incentivepercentage'][$cnt1];
    $data2['incentive_amt'] = $_REQUEST['incentiveamount'][$cnt1];
    $data2['total_distribution_amount'] = $_REQUEST['amountdistribution'][$cnt1];
    $s->RecordInsert('cal_incentive_grade_wise', $data2);
  }

  $sql_update_staff_status = "update staff_fund_payouts set payroll_status='Y' where month(from_date)='" . $_REQUEST['month'] . "' and month(to_date)='" . $_REQUEST['month'] . "' and year(from_date)='" . $_REQUEST['year'] . "' and year(to_date)='" . $_REQUEST['year'] . "' ";
  $result_update_staff_status = mysqli_query($link1, $sql_update_staff_status);
}
?>

<style type="text/css">
  .modal22 {
    display: none;
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: rgba(105, 105, 105, .4)50% 50%no-repeat;
  }
</style>

<?php
$month = array("01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr", "05" => "May", "06" => "June", "07" => "July", "08" => "Aug", "09" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dec")
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
  <div id="PickedItems" style="display:none"></div>
  <div class="modal22">
    <center>
      <div style="font-size:50px;margin-top:200px;">Loading...</div>
    </center>
  </div>
  <div class="tab_div">
    <form action="" method="post">
      <h1>Incentive Calculations</h1>

      <table width="100%" border="0" cellspacing="0" cellpadding="3">
        <tr class="row1">
          <td width="13%" align="right">Month &amp; Year</td>
          <td width="20%"><select style="width:48%;" name="month" id="month">

              <?php foreach ($month as $key => $value) {
                $jj = '';
                if ($_REQUEST['month'] == $key)
                  $jj = "selected";
              ?>
                <option value="<?php echo $key; ?>" <?php echo $jj; ?>><?php echo $value; ?></option>
              <?php } ?>
            </select>
            <select style="width:48%;" name="year" id="year">
              <?php for ($j = date('Y'); $j > 2000; $j--) {
                $jj1 = '';
                if ($_REQUEST['year'] == $j)
                  $jj1 = "selected";
              ?>
                <option value="<?php echo $j; ?>" <?php echo $jj1; ?>><?php echo $j; ?></option>
              <?php } ?>
            </select>
          </td>
          <td width="13%" style="text-align:right;">Descriptions</td>
          <td width="20%"><input type="text" name="desc" value="" /></td>
        </tr>
        <tr class="row1">
          <td colspan="4" style="text-align:center"><input type="submit" name="Search" class="search" value="Search">
            <!-- <input type="button" name="Cal" value="Calculate" class="search" onclick="calamt()"> -->
          </td>
        </tr>
      </table>
      <br>
      <?php
      if ($_REQUEST['month'] == '1') {
        $monthprivious = '12';
        $yearprivious = $_REQUEST['year'] - 1;
      } else {
        $monthprivious = $_REQUEST['month'] - 1;
        $yearprivious = $_REQUEST['year'];
      }

      $privious_reverseamt = DB_fetch_array(DB_query("select sum(reverse_amt) as amt,sum(other_cal_reserve) as other_cal_reserve ,sum(sal_reserve) as sal_reserve from hr_incentive_cal  where month='" . $monthprivious . "' 
                              and year<='" . $yearprivious . "' order by id desc limit 0,1 ", $db));


      $sql_check = DB_query("select id from hr_incentive_cal where month='" . $_REQUEST['month'] . "' and year='" . $_REQUEST['year'] . "'", $db);

      if (DB_num_rows($sql_check) <= 0) {



        $sql_tbl = DB_query("select B.*  from hr_incentive A inner join hr_incentive_dtls B on A.id=B.parent_id
                               where B.status='A'", $db);
        $amount_total = '';
        while ($row2 = DB_fetch_array($sql_tbl)) {
          $row1[] = $row2;


          $sql_check = mysqli_query($link1, "select balance_quantity,rate,discount_indicator,discount_amount from voucher_details
                                            where service_code='" . $row2['services_id'] . "' and month(created_date)='" . $_REQUEST['month'] . "' and year(created_date)='" . $_REQUEST['year'] . "' group by service_code");

          while ($row1 = mysqli_fetch_array($sql_check)) {
            $amt = $row1['balance_quantity'] * $row1['rate'];
            if ($row1['discount_indicator'] == 'P')
              $amount_total[$row2['services_id']][] = $amt - ($amt * $row1['discount_amount'] / 100);
            else
              $amount_total[$row2['services_id']][] = $amt - $row1['discount_amount'];
          }
        }

        if (!empty($amount_total)) {
      ?>

          <table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
            <tr>
              <th width="20">S. No.</th>
              <th>Name of the Ledgers</th>
              <th width="100">Amount</th>
              <th width="100">Staff share (in %)</th>
              <th width="100">Distribution Amount</th>
            </tr>
            <tr>
              <td colspan="5" valign="top" style="padding:0;">
                <div style="height:250px; overflow:auto;">
                  <div id="amc-tab">
                    <table width="100%" border="0" cellspacing="0" cellpadding="3">
                      <tbody id="dataTable">
                        <?php
                        $sql_staff_fund = "select sum(amount) from staff_fund_payouts where month(from_date)='" . $_REQUEST['month'] . "' and month(to_date)='" . $_REQUEST['month'] . "' and year(from_date)='" . $_REQUEST['year'] . "' and year(to_date)='" . $_REQUEST['year'] . "' and payroll_status='N' ";
                        $result_staff_fund = mysqli_query($link1, $sql_staff_fund);
                        $rs_staff_fund = mysqli_fetch_array($result_staff_fund);
                        // echo "<pre>";
                        // print_r($amount_total);  
                        $i = 1;
                        foreach ($row1 as $key => $row) {
                          if ($row['majerminer_masters_id'] != '0') {
                            $minor_sql = mysqli_fetch_array(mysqli_query($link1, "select B.desc from services B where B.service_code='" . $row['services_id'] . "'"));
                            $minordes = $minor_sql['desc'];
                          } else {
                            $minordes = $row['services_id'];
                          }


                          if (!empty($amount_total)) {
                            if ($row['services_id'] != 'Staff Fund') {
                              if (count($amount_total[$row['services_id']]) > 1)
                                $amttotal = array_sum($amount_total[$row['services_id']]);
                              else
                                $amttotal = $amount_total[$row['services_id']][0];
                            } else {
                              $amttotal = $rs_staff_fund[0];
                            }
                        ?>
                            <tr>
                              <td width="20"><?php echo $i; ?></td>
                              <td><?php echo $minordes; ?></td>
                              <td width="100"><input type="text" style="width:98%;" name="amount[]" id="amount_<?php echo $i; ?>" value="<?php echo $amttotal; ?>" onkeyup="cal_distribution_amt(this.value,this.id)" />
                                <input type="hidden" name="major[]" id="major_<?php echo $i; ?>" value="<?php echo $row['smajors_id'] ?>">
                              </td>
                              <td width="100"><input type="text" style="width:98%;" readonlyname="percentage[]" id="percentage_<?php echo $i; ?>" value="<?php echo $row['percentage']; ?>" />
                                <input type="hidden" name="minor[]" id="minor_<?php echo $i; ?>" value="<?php echo $row['majerminer_masters_id'] ?>">
                              </td>
                              <td width="100"><input type="text" style="width:98%;" name="disamount[]" readonly id="disamount_<?php echo $i; ?>" /><input type="hidden" name="services[]" id="services_<?php echo $i; ?>" value="<?php echo $row['services_id'] ?>"></td>


                            </tr>
                        <?php $i++;
                          }
                        } ?>


                        <tr>
                          <td colspan="4" style="text-align:right"><b>Total</b></td>
                          <td><input type="text" name="total_amt" id="total_amt" tabindex="1" style="width:98%;" readonly></td>

                        </tr>

                        <input type="hidden" name="count" id="count" value="<?php echo  $i; ?>">
                      </tbody>
                    </table>
                  </div>

                </div>
              </td>
            </tr>
          </table>
          <br>
          <table width="100%" border="0" cellspacing="0" cellpadding="3" id="tableDataProduction" class="thborder">
            <tr>
              <th width="6%">S. No.</th>
              <th>Particulars</th>
              <th width="20%">Amount</th>
              <th width="20%">Distribution Amount</th>
            </tr>
            <?php

            $t = 1;

            /*    $sql_ded=DB_query("select * from other_deduction_master where status='A' 
                        and type='A' and code!='Inc'",$db);  */
            $sql_ded = DB_query("select * from allowmaster where incentive_check='Y' 
                         and allowcode!='Inc' group by id ", $db);
            while ($row_ded = DB_fetch_array($sql_ded)) {
              $bonus_amt1 = 0;

              $sql_emp = "select distinct(employee) from daily_attendance where month(attendance_date)='" . $_REQUEST['month'] . "' and year(attendance_date)='" . $_REQUEST['year'] . "' ";
              $result_emp = DB_query($sql_emp, $db);
              while ($rs_emp = DB_fetch_array($result_emp)) {


                /* $bonus_amt=DB_fetch_array(DB_query("select sum(allowance_amt) as allowance_amt from  emp_allowance_dtls where allowance_id='".$row_ded['id']."'",$db)); */

                $sql_att_count = "select count(*) from daily_attendance where employee='" . $rs_emp['employee'] . "' and month(attendance_date)='" . $_REQUEST['month'] . "' and year(attendance_date)='" . $_REQUEST['year'] . "' and pres_abs in('WL','P') ";
                $result_att_count = DB_query($sql_att_count, $db);
                $rs_att_count = DB_fetch_array($result_att_count);
                $total_present = $rs_att_count[0];
                $d = cal_days_in_month(CAL_GREGORIAN, $_REQUEST['month'], $_REQUEST['year']);

                if ($total_present >= 25) {



                  $bonus_amt = DB_query("select sum(percentage_value) as allowance_amt from  emp_salary where allowance_deduction='" . $row_ded['id'] . "' and emp_id='" . $rs_emp['employee'] . "' and all_ded_prefix='A' ", $db);
                  while ($rs_bonus = DB_fetch_array($bonus_amt)) {

                    $totamt = $total_present * $rs_bonus[0];
                    $totamt1 = $totamt / $d;

                    // $bonus_amt1+=$rs_bonus[0];
                    $bonus_amt1 += $totamt1;

                    if ($bonus_amt1 != '0') {
                      $amt5 = $bonus_amt1;
                    } else {
                      $amt5 = 0;
                    }
                  }
                }
                // $bonusamt[$row_ded['id']]=$bonus_amt['allowance_amt'];

                // if(isset($bonusamt[$row_ded['id']])) $amt=$bonusamt[$row_ded['id']];
                // else $amt=0;

              }
            ?>
              <tr>
                <td><input type="hidden" name="dedid[]" value="<?php echo $row_ded['id']; ?>" ?><?php echo $t; ?></td>
                <td><?php echo $row_ded['allowname']; ?></td>
                <td><input type="text" style="width:98%;" name="ded_amount[]" id="dedamount_<?php echo $t; ?>" onkeyup="showcalamt(this.value,'<?php echo $t; ?>')"
                    value="<?php echo round($amt5, 2); ?>" /></td>
                <td><input type="text" style="width:98%;" name="deddisamount[]" id="deddisamount_<?php echo $t; ?>" value="<?php echo round($amt5, 2); ?>" class="sum1" /></td>
              </tr>
            <?php $t++;
            } ?>
            <tr>
              <td><?php echo $t; ?></td>
              <td>Reserve Value</td>
              <td><input type="text" style="width:98%;" name="reverse_amt" id="reverseamt_<?php echo $t; ?>" value="<?php echo $row_ded['name']; ?>" onkeyup="showcalamt(this.value,'<?php echo $t; ?>')" /></td>

              <td><input type="text" style="width:98%;" name="reverseded" id="deddisamount_<?php echo $t; ?>" class="sum1" /></td>
            </tr>
            <tr>
              <td><?php echo $t; ?></td>
              <td>Reserve Value(Previous)</td>
              <td></td>
              <td><input type="text" style="width:98%;" name="privious_reverse" id="privious_reverse" class="sum" value="<?php echo (($privious_reverseamt['amt'] + $privious_reverseamt['other_cal_reserve']) - $privious_reverseamt['sal_reserve']); ?>" /></td>
            </tr>

            <?php
            $sql_ded = DB_query("select * from other_deduction_master where status='A' and type='A' and code='Inc'", $db);
            while ($row_ded = DB_fetch_array($sql_ded)) { ?>
              <tr>
                <td><input type="hidden" name="dedid[]" value="<?php echo $row_ded['id']; ?>" ?><?php echo $t; ?></td>
                <td><?php echo $row_ded['name']; ?></td>
                <td></td>
                <td><input type="text" style="width:98%;" name="deddisamount[]" id="qtytotal" class="sum" /></td>
              </tr>
            <?php $t++;
            } ?>

          </table>


          <table width="100%" border="0" cellspacing="0" cellpadding="3" id="tableDataProduction1" class="thborder">
            <tr>
              <th>Grade</th>
              <th>Total</th>
              <th>No. Of Employee</th>
              <th>Percentage Of Incentive</th>
              <th>Incentive Amount</th>
              <th>Total Amount Distributed</th>
            </tr>

            <?php $counter = 1;
            $total = 0;
            $count12 = 0;
            $sql_grade = "select * from emp_grade group by grade_name";
            $result_grade = DB_query($sql_grade, $db);
            while ($rs_grade = DB_fetch_array($result_grade)) {
              /****************************** Get Basic,DA,HRA Starts Here ***********************************/
              $sql_basic = "select basic_salary from emp_grade where id='" . $rs_grade['id'] . "' ";
              $result_basic = DB_query($sql_basic, $db);
              $rs_basic = DB_fetch_array($result_basic);
              $basic = $rs_basic[0];

              // $sql_allowance=" ";
              // $result_allowance=DB_query($sql_allowance,$db);
              // while($rs_allowance=DB_fetch_array($result_allowance))
              // {
              //echo $rs_allowance['id']."<br>";
              $sql_allow_amount = "select sum(percentage_value) from emp_salary_grade where emp_grade_id='" . $rs_grade['id'] . "' and allowance_deduction in(select id from allowmaster where allowcode in('DA','HRA')) and all_ded_prefix='A' ";
              $result_allow_amount = DB_query($sql_allow_amount, $db);
              $rs_allow_amount = DB_fetch_array($result_allow_amount);
              $hra = $rs_allow_amount[0];
              //}
              $total = $basic + $hra;

        //  echo $total."##".$basic;
          //echo $basic."##".$hra."<br>";


              /****************************** Get Basic,DA,HRA Ends Here ****************************************/

              /************************************ Get Employee Count Starts Here  ********************************/
              $count12 = 0;
              $sql_att = "select distinct employee from daily_attendance where month(attendance_date)='" . $_REQUEST['month'] . "' and year(attendance_date)='" . $_REQUEST['year'] . "' and employee in(select id from empmaster where grade='" . $rs_grade['id'] . "'  ) group by employee ";
              $result_att = DB_query($sql_att, $db);
              while ($rs_att = DB_fetch_array($result_att)) {
                $sql_count_att = "select count(*) from daily_attendance where month(attendance_date)='" . $_REQUEST['month'] . "' and year(attendance_date)='" . $_REQUEST['year'] . "' and employee='" . $rs_att[0] . "' and pres_abs in('P','WL') ";
                $result_count_att = DB_query($sql_count_att, $db);
                while ($rs_count_att = DB_fetch_array($result_count_att)) {
                  // echo $rs_count_att[0]."<br>";
                  if ($rs_count_att[0] >= 25) {
                    $count12 += 1;
                  }
                }
              }

              /************************************ Get Employee Count Ends Here  ********************************/

            ?>
              <tr>
                <td><input type="text" name="grade[<?php echo $counter; ?>]" id="grade_<?php echo $counter; ?>" value="<?php echo $rs_grade['grade_name']; ?>" readonly />
                  <input type="hidden" name="gradeid[<?php echo $counter; ?>]" id="gradeid_<?php echo $counter; ?>" value="<?php echo $rs_grade['id']; ?>" />
                </td>
                <td><input type="text" name="totalbasic[<?php echo $counter; ?>]" id="totalbasic_<?php echo $counter; ?>" class="basic" value="<?php echo $total; ?>" readonly /></td>
                <td><input type="text" name="employeecount[<?php echo $counter; ?>]" id="employeecount_<?php echo $counter; ?>" value="<?php echo $count12; ?>" readonly /></td>
                <td><input type="text" name="incentivepercentage[<?php echo $counter; ?>]" readonly id="incentivepercentage_<?php echo $counter; ?>" onkeypress="return isNumberKey(event);" onfocus="cal_incentive();" /></td>
                <td><input type="text" name="incentiveamount[<?php echo $counter; ?>]" id="incentiveamount_<?php echo $counter; ?>" readonly /></td>
                <td><input type="text" name="amountdistribution[<?php echo $counter; ?>]" id="amountdistribution_<?php echo $counter; ?>" readonly /></td>

              </tr>
            <?php $counter++;
            } ?>

          </table>
          <input type="hidden" name="counter_grade" id="counter_grade" value="<?php echo $counter; ?>">

          <?php if (isset($_REQUEST['id']) && !empty($_REQUEST['id']))
            $button_name = "Update";
          else $button_name = "Save"; ?>

          <p align="center"><input type="submit" class="search" name="<?php echo $button_name; ?>" value="<?php echo $button_name; ?>"></p>
        <?php } else {
          echo "<p align='center' style='font-size:13px;'>No Records</p>";
        }
      } else { ?>
        <p align="center" style='font-size:13px;'>Already Posted</p>

      <?php } ?>

    </form>
  </div>
</div>
<script type="text/javascript">
  function calamt() {
    var count = document.getElementById("count").value;
    var total_dis = 0;
    for (var j = 1; j < count; j++) {
      var per = document.getElementById("percentage_" + j).value;
      var amt = document.getElementById("amount_" + j).value;
      if (per == '') per = 0;
      if (amt == '') amt = 0;
      var dis = parseFloat(amt) * parseFloat(per) / 100;
      document.getElementById("disamount_" + j).value = dis.toFixed(4);
      var total_dis = parseFloat(total_dis) + parseFloat(dis);
    }
    document.getElementById("total_amt").value = total_dis.toFixed(4);
    var privious_amt = document.getElementById("privious_reverse").value;
    if (privious_amt == '') privious_amt = 0;
    var sumOfArea = 0;
    var sumOfArea1 = parseFloat(total_dis) + parseFloat(privious_amt);
    $('#tableDataProduction').find('input[type="text"][class="sum1"]').each(function() {
      if ($(this).val() != '')
        sumOfArea = sumOfArea + parseFloat($(this).val());
      else
        sumOfArea = sumOfArea;
    });

    var amttotal = parseFloat(sumOfArea1) - parseFloat(sumOfArea);
    if (parseFloat(amttotal) >= 0) {
      $('#qtytotal').val(amttotal.toFixed(4));
    } else {
      $('#qtytotal').val(0);
    }


  }

  function showcalamt(str, str1) {
    if (str == '')
      var str = 0;

    document.getElementById("deddisamount_" + str1).value = str;
    calamt();
  }

  $(document).ready(function() {
    calamt();

  });

  function cal_distribution_amt(val, str) {
    id = str.split("_");

    var amount = document.getElementById("percentage_" + id[1]).value;
    var amt = parseFloat(amount) * parseFloat(val);
    var peramt = parseFloat(amt / 100).toFixed(2);

    document.getElementById("disamount_" + id[1]).value = parseFloat(peramt);
    calamt();

  }

  function get_total_basic(str) {
    var month = $("#month").val();
    var year = $("#year").val();
    $.post("get_basic_grade.php", {
      "id": str,
      "type": 'basic'
    }, function(data) {
      document.getElementById("total_basic").value = data;
    });
    employee_count(str, month, year);
  }

  function employee_count(str, month, year) {
    $.post("get_basic_grade.php", {
      "id": str,
      "month": month,
      "year": year,
      "type": 'employee_count'
    }, function(data) {
      document.getElementById("employee_count").value = data;
    });
  }


  function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode != 46 && charCode > 31 &&
      (charCode < 48 || charCode > 57))
      return false;

    return true;
  }


  function cal_incentive() {
    var basic_sum = 0;
    var sumOfArea = 0;
    $('#tableDataProduction1').find('input[type="text"][class="basic"]').each(function() {
      if ($(this).val() != '')
        sumOfArea = sumOfArea + parseFloat($(this).val());
      else
        sumOfArea = sumOfArea;
    });
    //alert(sumOfArea);

    var incentive = document.getElementById("qtytotal").value;
    var count = document.getElementById("counter_grade").value;

    for (var i = 1; i < count; i++) {


      var basic = document.getElementById("totalbasic_" + i).value;
      var empcount = document.getElementById("employeecount_" + i).value;
      //  if(empcount!='0')


      var inv_percentage = parseFloat(basic) * parseFloat(empcount);
      basic_sum += parseFloat(inv_percentage);


    }

    if (!isNaN(basic_sum)) {
      var peramt = parseFloat(incentive) / parseFloat(basic_sum);
      var per = parseFloat(peramt) * 100;
    } else {
      var per = 0;
    }


    for (var j = 1; j < count; j++) {
      //alert(basic_sum);
      if (document.getElementById("employeecount_" + j).value != '0') {
        document.getElementById("incentivepercentage_" + j).value = parseFloat(per).toFixed(2);
      } else {
        document.getElementById("incentivepercentage_" + j).value = 0.00;
      }

      var basic1 = document.getElementById("totalbasic_" + j).value;
      var incamt = parseFloat(basic1) * parseFloat(per);
      var incamt1 = parseFloat(incamt) / 100;
      if (document.getElementById("employeecount_" + j).value != '0') {
        document.getElementById("incentiveamount_" + j).value = parseFloat(incamt1).toFixed(2);
      } else {
        document.getElementById("incentiveamount_" + j).value = 0.00;
      }

      var empcount1 = document.getElementById("employeecount_" + j).value;
      var distributedamt = parseFloat(incamt1) * parseFloat(empcount1);
      document.getElementById("amountdistribution_" + j).value = parseFloat(distributedamt).toFixed(2);

    }

    /* for(var i=1;i<count;i++)
  {   
     
     
  } */




  }
</script>