<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 4;
$PageName = 'Finished Material';
include('includes/DefinePOClass.php');
include('includes/stockcalculation.php');
$PageName='Material Conversion';
if(isset($_POST['Save']))
{
   //echo "<pre>";print_r($_REQUEST); exit();
    $financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
                       // $prefixcode="ISS";
                        //$prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."' and module_id='".$_REQUEST['modid']."' ",$db);
    //$prefix_row=DB_fetch_array($prefix_sql);
    //$prefixf=explode("/",$prefix_row['prefix_code']);

        $Prefix_SQL = "Select prefix_id,prefix_code,prefix_name from prefix_tbl Where prefix_name ='".$PageName."'";
        $Prefix_Result = DB_query($Prefix_SQL,$db);
        $Prefix_Row = DB_fetch_array($Prefix_Result);

    $prefixcode=$prefix_row['prefix_code'];
                //$year=$_SESSION['financialYearStart'];
                //$year_after=$_SESSION['financialYearEnd'];
                $site_code=substr($_REQUEST['site'],0,3);
                $sql="select mat_con_slip_no from mat_conversion where site = '".$_REQUEST['site']."'
               ORDER BY ID DESC LIMIT 0,1";
              $result =DB_query($sql,$db);
              $myrow=DB_fetch_array($result);
              $numrows = DB_num_rows($result);
              $sqldata=DB_query("select locationname from locations where loccode='".$_REQUEST['site']."'",$db);
              $sqltext=DB_fetch_array($sqldata);
              $sitename=$sqltext['locationname'];
              $siteCode = $sitename;
                $strdata=substr($myrow['mat_con_slip_no'],14,6);
          
   if($numrows>0)
   {
       $i=0;
       $strmax = "";
       $myrow=DB_Fetch_array($result);
       
           if($siteCode!='')
              if($numrows>0)
              {                  
                  
                $maxval = $strdata;
              }
            else
              {
                $maxval=0;
              }
      {
        $strChar = $site_code."/".$financial."/".$prefixcode."/";
      }
    }
    else
    {
      $strChar = $site_code."/".$financial."/".$prefixcode."/";
    }
    
   $strFinal = $maxval+1;
     $strBothFinal = $strChar.str_pad($strFinal,6,"0",STR_PAD_LEFT);

         $sql="insert into mat_conversion set 
                      site='".$_REQUEST['site']."',
                      mat_con_slip_no='".$strBothFinal."',
                      store='".$_REQUEST['store']."',
                      mat_con_date='".FormatDateForSQL($_REQUEST['MTC_date'])."',
                      transaction_time='".date("Y-m-d H:i:s")."',
                      created_by='".$_SESSION['UserID']."',
                      created_date='".date('Y-m-d')."',
                      remarks='".$_REQUEST['remarks']."',
                      item_from='".$_REQUEST['first_item']."',
                      item_to='".$_REQUEST['second_item']."',
                      conv_type='".$_REQUEST['type']."'
                      ";
                    $insertResult = DB_query($sql,$db,$ErrMsg);
           $Last_id=DB_Last_Insert_ID($db,'mat_conversion','id');

       
      if($Last_id!='')
     {
      if($_REQUEST['type']!='B')
      {
        $sql_detl="insert into mat_conversion_details (parent_id,item_id,trnx_type,pre_qty,size_id,gread_id,batch_no) values('".$Last_id."','".$_REQUEST['first_item']."','issue','".$_REQUEST['convert_stock']."','".$_REQUEST['sizesp1']."','".$_REQUEST['gradesp1']."','".$_REQUEST['item_batch']."'),('".$Last_id."','".$_REQUEST['second_item']."','received','".$_REQUEST['new_item_stock_convert']."','".$_REQUEST['sizesp2']."','".$_REQUEST['gradesp2']."','".$_REQUEST['new_item_batch']."','".$_REQUEST['rate1']."','".$_REQUEST['total_value1']."')";
       }
       else
       {
        $sql_detl="insert into mat_conversion_details (parent_id,item_id,trnx_type,pre_qty,size_id,gread_id,batch_no,rate,amount) values('".$Last_id."','".$_REQUEST['first_item']."','issue','".$_REQUEST['item_stock']."','".$_REQUEST['sizesp1']."','".$_REQUEST['gradesp1']."','".$_REQUEST['item_batch']."','".$_REQUEST['rate1']."','".$_REQUEST['total_value1']."')";

       } 
       DB_query($sql_detl,$db);


          $dtls_Lastreq_id=DB_Last_Insert_ID($db,'mat_conversion_details',$ErrMsg);  
         
          $primary_unit=$s->getField('item_master','id',$_REQUEST['second_item'],'mst_unitid');
          $secondary_unit=$s->getField('item_master','id',$_REQUEST['second_item'],'conv_unit');
          $conv_factor=$s->getField('item_master','id',$_REQUEST['second_item'],'conv_factor');
          
          if($_REQUEST['type']!='B')
          {
                $data_stock['site']                     =$_REQUEST['site'];
                $data_stock['store']                    =$_REQUEST['store'];
                $data_stock['mst_itemid']               =$_REQUEST['second_item'];
                $data_stock['primary_unit']             =$primary_unit;
                $data_stock['secondary_unit']           =$secondary_unit;
                $data_stock['against_voucher_main_id']  =$Last_id;
                $data_stock['against_voucher_dtls_id']  =$dtls_Lastreq_id;
                $data_stock['type']                     ='MCT';    
                //$data_stock['pending_qty']              =$_REQUEST['reciveqty'][$i];
                
                $data_stock['inwardqty_primary']        =$_REQUEST['new_item_stock_convert'];
                $data_stock['inwardqty_secondary']      =$_REQUEST['new_item_stock_convert']*$conv_factor;  
                
                $data_stock['trasaction']               =FormatDateForSQL($_REQUEST['MTC_date'])." ".date('H:i:s', time());
                $s->RecordInsert('stock_valuation_tbl', $data_stock);
                //print_r($data_stock);
                unset($data_stock);

                $primary_unit=$s->getField('item_master','id',$_REQUEST['first_item'],'mst_unitid');
                $secondary_unit=$s->getField('item_master','id',$_REQUEST['first_item'],'conv_unit');
                $conv_factor=$s->getField('item_master','id',$_REQUEST['first_item'],'conv_factor');
                $data_stock['site']                     =$_REQUEST['site'];
                $data_stock['store']                    =$_REQUEST['store'];
                $data_stock['mst_itemid']               =$_REQUEST['first_item'];
                $data_stock['primary_unit']             =$primary_unit;
                $data_stock['secondary_unit']           =$secondary_unit;
                $data_stock['against_voucher_main_id']  =$Last_id;
                $data_stock['against_voucher_dtls_id']  =$dtls_Lastreq_id;
                $data_stock['type']                     ='MCT';    
                //$data_stock['pending_qty']              =$_REQUEST['reciveqty'][$i];
                
                $data_stock['outwardqty_primary']        =$_REQUEST['convert_stock'];
                $data_stock['outwardqty_secondary']      =$_REQUEST['convert_stock']*$conv_factor;  
                
                $data_stock['trasaction']               =FormatDateForSQL($_REQUEST['MTC_date'])." ".date('H:i:s', time());
                $data_stock['outwardqty_secondary']      =$_REQUEST['convert_stock']*$conv_factor; 
                //print_r($data_stock);
                $s->RecordInsert('stock_valuation_tbl', $data_stock);
             }
             else
             {
                $primary_unit=$s->getField('item_master','id',$_REQUEST['first_item'],'mst_unitid');
                $secondary_unit=$s->getField('item_master','id',$_REQUEST['first_item'],'conv_unit');
                $conv_factor=$s->getField('item_master','id',$_REQUEST['first_item'],'conv_factor');
                $data_stock['site']                     =$_REQUEST['site'];
                $data_stock['store']                    =$_REQUEST['store'];
                $data_stock['mst_itemid']               =$_REQUEST['first_item'];
                $data_stock['primary_unit']             =$primary_unit;
                $data_stock['secondary_unit']           =$secondary_unit;
                $data_stock['against_voucher_main_id']  =$Last_id;
                $data_stock['against_voucher_dtls_id']  =$dtls_Lastreq_id;
                $data_stock['type']                     ='MCT';    
                //$data_stock['pending_qty']              =$_REQUEST['reciveqty'][$i];
                
                $data_stock['outwardqty_primary']        =$_REQUEST['item_stock'];
                $data_stock['outwardqty_secondary']      =$_REQUEST['item_stock']*$conv_factor;  
                
                $data_stock['trasaction']               =FormatDateForSQL($_REQUEST['MTC_date'])." ".date('H:i:s', time());
               // $data_stock['outwardqty_secondary']      =$_REQUEST['convert_stock']*$conv_factor;
                 $data_stock['outward_rate']            =$_REQUEST['rate1']; 
                  $data_stock['outward_value']          =$_REQUEST['total_value1'];  
                  $data_stock['batch_no']              =$_REQUEST['item_batch'];
                //print_r($data_stock);
                $s->RecordInsert('stock_valuation_tbl', $data_stock);
             }   

      }
//exit('j');

      prnMsg( _('Record saved Successfully'),'success');
                echo "<script>location.href='index.php?route=Inventory/transation/material_conversion_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";


   }


 //For User Store
$sql_user_store="select hmis_storeid,StoreCode from www_users left join storetype on storetype.id=www_users.hmis_storeid where www_users.id='".$_SESSION['UserID']."'";
$result_user_store=DB_query($sql_user_store,$db);
$rs_user_store=DB_fetch_array($result_user_store);
$main_store=$rs_user_store[0];


$sql_other_store="select store_id,StoreCode from www_users_dtls left join storetype on storetype.id=www_users_dtls.store_id where user_id='".$_SESSION['UserID']."'";
$result_other_store=DB_query($sql_other_store,$db);
while($rs_other_store=DB_fetch_array($result_other_store))
{
  $store[]=$rs_other_store['store_id'];
}

if(!empty($store))
{
  $get_store_id=implode(",",$store);
}


if($main_store!=0 && $get_store_id!='')
{
  $all_store=$main_store.",".$get_store_id;
}
else
{
  $all_store=$main_store;
}

 ?>
<div class="body_contain">
<div class="tab_div">
 <h1><strong>Material Conversion</strong></h1>
<form name="form1" onsubmit="return chkValidate();" method="post">
<div align="center">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td width="13%"><strong>Branch</strong></td>
    <td width="20%">
  <?php
  if($_SESSION['AssignedBranch']!='')
    {     
  $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
       $site_sql=DB_query($ss,$db);
    }
    else
    {
    $ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
    $site_sql=DB_query($ss,$db);
    }
  ?>
  <select name="site" id="site" onchange="get_store_by_site();" style="width:98%;" >
     <option value="0">Select</option>
               <?php 
      while ($myrow=DB_fetch_array($site_sql))
        {
          $p='';
         if($myrow['loccode']==$site)
         $p='selected';
        
        ?>
      <option value="<?php echo $myrow['loccode']; ?>"  <?php  echo $p;?>><?php echo $myrow['locationname'];?></option>
      <?  } ?>                                
    </select></td>
    <td width="13%"><strong>MTC Slip No.</strong></th>
    <td width="20%" id="ISSUE"><input name="MCT_slip" type="text" id="MCT_slip" value="Auto generated" size="15" style="width:98%;" readonly /></td>
    <td width="13%"><strong>Date</strong></th>
    <td id="ISSUE"><input name="MTC_date" type="text" class="datepicker" id="MTC_date" value="<?php echo date('d/m/Y'); ?>"  size="15" style="width:98%;" readonly /> 
  </tr>
  <tr class="row1">
    <td><strong>Godown</strong></th>
    <td><div id='hid-Godown-div'>
  <?php
       $sql_store ="select distinct id,StoreCode, StoreName from storetype where Store_Site in('".$_SESSION['AssignedBranch']."') ";
     $resultStkLocs = DB_query($sql_store,$db);
    ?>
      <select name="store" id="store" style="width:98%;">
        <option value="0">Select</option>
        <?php 
    while ($myrow=DB_fetch_array($resultStkLocs))
    { ?>
        <option value="<?php echo $myrow['id'];?>"<?php echo($row['store']==$myrow['id']?'selected':'')?>><?php echo $myrow['StoreName'];?></option>
        <?php 
    }
    ?>
      </select></div></td>
    <td><strong>Type</strong></td>
    <td><select name="type" id="type" onchange="hide_div(this.value);">
       <option value="0">Select</option>
       <option value="B">Breakage</option>
       <option value="N">Non Breakage</option>
    </td>
    <td><strong></strong></td>
    <td id="work_or_date"></td>
  </tr>
</table>
</div>
<br />


  
<table width="100%" id="" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#808080 solid 1px;">
  <tr>
    <th width="8%">Pick Item</th>
    <th>Item Description</th>
    <th width="10%">Item Code</th>
    <th width="10%">Batch No.</th> 
   <!-- <th colspan="2"><center>Specification</center></th> -->
   <th width="6%">Stock Qty</th> 
    <th width="6%">UOM</th>
   <th width="6%">Qty.</td> 
    <th width="6%">Alt. UOM</th>
    <th width="6%">Sec Stock QTY</th>   
    <th width="6%">Rate</th>  
    <th width="6%">Total Value</th>   
    <th width="1%"></th>
  </tr>
  <tbody id="dataTable">   
    <tr>
    <td><input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items('1')" accesskey="I" class="search" /></td>
    <td><input type="hidden" name="first_item" id="first_item"><input type="text" id="item_desc" name="item_desc" style="width:98%;" readonly /></td>
    <td><input type="text" id="item_code" name="item_code" readonly ></td>
    <td><input type="text" id="item_batch" name="item_batch" placeholder="Double Click to Get Batch" ondblclick="displayBatch(this.value,this.id);" ></td> 
    <!-- <td width="7%"><select name="sizesp1" id="sizesp1" style="width:98%;">
    <option value="0">select</option>
    <?php
     //$resultSize=DB_query("select * from size_master",$db);
    // while($rowSize=DB_fetch_array($resultSize))
     //{ ?>
    <option value="<?php //echo $rowSize['id']; ?>"><?php //echo $rowSize['size']; ?></option>
     <?php //}
     ?>
   </select></td>
   <td width="7%"><select  id="gradesp1" name="gradesp1" style="width:98%;">
    <option value="0">select</option>
    <?php
     // $resultGrade=DB_query("select * from product_grade",$db);
     // while($rowGrade=DB_fetch_array($resultGrade))
     // { ?>
     <option value="<?php //echo $rowGrade['id']; ?>"><?php //echo $rowGrade['grade']; ?></option>
       <?php //}
     ?>   
   </select></td>    -->
   <td><input type="text" id="item_stock_hidden" readonly></input></td>
   <td><input type="text" id="item_unit" name="item_unit" style="width:98%;" readonly ></td>
   <td>
    <input type="text" id="item_stock" name="item_stock" style="width:98%;"  onkeyup="get_value();" >
  </td>   
   <td><input type="text" id="item_unit1" name="item_unit1" style="width:98%;" readonly ></td>
   <td><input type="text" id="item_stock1" name="item_stock1" style="width:98%;" readonly ></td> 
   <td><input type="text" id="rate1" name="rate1" style="width:98%;" readonly ></td> 
   <td><input type="text" id="total_value1" name="total_value1" style="width:98%;" readonly ></td>
   <td><input type="hidden" name="con_factor" value="" id="con_factor"></td> 
  </tr>
  <tr id="type_hid">
    <td></td>
    <td></td>
    <!-- <td></td> -->
    <th colspan="3"><center>Convert into </center></th>
    <td><input type="text" id="convert_unit" name="convert_unit" style="width:98%;"></td>
    <td><input type="text" id="convert_stock" onkeyup="convert_s_unit(this.value)" style="width:98%;" name="convert_stock"></td>
    <td><input type="text" id="convert_unit1" name="convert_unit1" style="width:98%;"></td>
    <td><input type="text" id="convert_stock1" name="convert_stock1" style="width:98%;"><input type="hidden" name="con_factor" value="" id="con_factor"></td>
    <td></td>
    <td></td>
  </tr>
  <tr id="type_hid1">
    <td><input type="button" style="" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items('2')" accesskey="I" class="search" /></td>
    <td><input type="hidden" name="second_item" id="second_item"><input type="text" id="new_item_name" name="new_item_name" style="width:98%;"></td>
    <td><input type="text" id="new_item_code" name="new_item_code" style="width:98%;"></td>
     <td><input type="text" id="new_item_batch" name="new_item_batch" style="width:98%;"></td> 
   <!-- <td><select name="sizesp2" id="sizesp2" style="width:98%;">
    <option value="0">select</option>
    <?php
     //$resultSize=DB_query("select * from size_master",$db);
    // while($rowSize=DB_fetch_array($resultSize))
     //{ ?>
    <option value="<?php //echo $rowSize['id']; ?>"><?php //echo $rowSize['size']; ?></option>
     <?php //}
     ?>
    </select></td>
    <td><select name="gradesp2" id="gradesp2" style="width:98%;">
    <option value="0">select</option>
    <?php
     // $resultGrade=DB_query("select * from product_grade",$db);
    //  while($rowGrade=DB_fetch_array($resultGrade))
     // { ?>
     <option value="<?php// echo $rowGrade['id']; ?>"><?php //echo $rowGrade['grade']; ?></option>
       <?php //}
     ?>   
    </select></td> -->
    <td><input type="text" id="new_item_stock_hidden" readonly></td>
    <td><input type="hidden" id="con_factor_second"><input type="text" id="new_item_unit" name="new_item_unit" style="width:98%;"><input type="hidden" id="second_item_old_stock" ></td>
    <td>
      <input type="text" size="8" style="width:48%; float:left; margin-right:2px;" id="new_item_stock"  readonly name="new_item_stock">
      <input type="text" size="8" id="new_item_stock_convert" onkeyup="set_new_stock(this.value);" name="new_item_stock_convert" style="width:48%; float:left;" >
      
    </td>
    <td><input type="text" id="new_item_unit1" name="new_item_unit1" style="width:98%;"></td>
    <td><input type="text" id="new_item_stock1" name="new_item_stock1" style="width:98%;"></td> 
    <td colspan="4"></td>
  </tr>
  </div>
  </tbody>
</table>

<div class="body_lightbox1" id="lightbox1" style="overflow:auto; width:100%; height:250px; display:none;"></div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i; ?>" />
  <input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
  <input type="hidden" name="" value="<?php echo $i; ?>" id="rowcount1" />

  <br/><br />
<table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr class="row1">
    <td><strong>Remarks:</strong></td>
    <td><textarea name="remarks" id="remarks" cols="" rows="" style="width:100%; height:60px;"><?php echo $row['remarks']; ?></textarea></td>
  </tr>
</table>



<p align="center"><input type="submit" class="search" name="Save" value="Save" /></p>

</form>
</div>
</div>
<div id="PickedItems1"></div>
<script type="text/javascript">
function open_items(num)
{
  //alert(num);
    if($('#site').val()==0)
    {
      alert('Please select site.');
      return false;
    }
    if($('#store').val()==0)
    {
      alert('Please select store.');
      return false;
    }
    if($('#type').val()==0)
    {
      alert('Please select Type.');
      return false;
    }
 var site=$('#site').val();
 var store=$('#store').val();

window.open("popup_conversion_items.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&num="+num+"&site="+site+"&store="+store,"item_popup_window","height=500,width=500,left=1111px,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}


function set_new_stock(str)
{ 
  if(str!='' && parseInt(str)>0){
      $('#new_item_stock').val(parseFloat($('#new_item_stock_hidden').val()) + parseFloat(str));
      $('#new_item_stock1').val((parseFloat(parseFloat($('#new_item_stock_hidden').val()) + parseFloat(str)) * parseFloat($('#con_factor_second').val())).toFixed(2));
 } else {
    $('#new_item_stock').val($('#new_item_stock_hidden').val());
    $('#new_item_stock1').val(($('#new_item_stock_hidden').val()*parseFloat($('#con_factor_second').val())).toFixed(2));

 }
// new_item_stock  new_item_stock_convert  new_item_stock1
}
function get_store_by_site()
{//getStore
     if($('#site').val()=='0')
     {
       alert('Please select site .');
       return false;
     }
      $.ajax({
            url : "get_mrn_by_site.php",
            type : "POST",
            data : {
              action:'getStore',
              site:$('#site').val()
            },
            success : function(data) {//alert(data);
                    $('#store').html(data);
                         }
                 });
}
function convert_s_unit(str)
{ 
  
  var curStk=$('#item_stock_hidden').val();
  if(str=='' || parseInt(str)==0 || parseInt(curStk)<parseInt(str)){
    alert('Cconvert Quantity can not be less current stock or zero.');
    $('#item_stock').val($('#item_stock_hidden').val());
    $('#item_stock1').val(($('#item_stock_hidden').val()*$('#con_factor').val()).toFixed(2));
    $('#convert_stock').val('');
    $('#convert_stock1').val('');

  } else {
    var newStock=$('#item_stock_hidden').val()-str;
    var newStock1=($('#item_stock_hidden').val()-str)*$('#con_factor').val();
    $('#item_stock').val(newStock);
    $('#item_stock1').val(newStock1.toFixed(2));    
    $('#convert_stock1').val((parseFloat(str) * parseFloat($('#con_factor').val())).toFixed(2));    
  }



/*    if( parseFloat($('#convert_stock').val()) > parseFloat($('#item_stock_hidden').val()))
    {
       alert('To convert Quantity should be less current stock.');
       //$('#convert_stock').val($('#item_stock').val());
       $('#convert_stock').val('0');
       $('#convert_stock1').val('0');
       $('#item_stock').val('0');
       $('#item_stock1').val('0');

    }

    var con_stock=0;
   if($('#convert_stock').val()=='' || parseInt()<1){
    con_stock=0;
  }    
   else{
    con_stock=$('#convert_stock').val();
     $('#convert_stock1').val(parseFloat(con_stock) * parseFloat($('#con_factor').val()));    
    change_st_unit();    
   }*/

    
     
}

function change_st_unit()
{ 
    var item_stock=$('#item_stock_hidden').val();
    if(item_stock>0){
      var bal=$('#item_stock_hidden').val()-$('#convert_stock').val();
      $('#item_stock').val(bal);
      $('#item_stock1').val(parseFloat(bal) * parseFloat($('#con_factor').val()));
    } else {
      $('#item_stock').val($('#item_stock_hidden').val());
      var newConv=$('#item_stock_hidden').val()*$('#con_factor').val();
      $('#convert_stock').val('0');

    }

     
}

function chkValidate()
{
    if($('#site').val()==0)
    {
      alert('Please select branch.');
      document.getElementById("site").focus();
      return false;
    }
     if($('#MTC_date').val()=='')
     {
      alert('Please select date');
      document.getElementById("MTC_date").focus();
      return false;
     }
       if($('#store').val()==0)
       {
        alert('Please select godown.');
        document.getElementById("store").focus();
        return false;
       }
        if($('#first_item').val()=='')
        {
          alert('Please select first item');
          document.getElementById("first_item").focus();
          return false;
        }
        if($("#type").val=='N')
        {
            if($('#second_item').val()=='')
            {
              alert('Please select second item');
              document.getElementById("second_item").focus();
              return false;
            }
            if($('#convert_stock').val()=='' || $('#convert_stock').val()==0)
            {
               alert('Please enter convert quantity.');
               document.getElementById("convert_stock").focus();
               return false;
            }
            if(($('#new_item_stock_convert').val()=='') || ($('#new_item_stock_convert').val()==0))
            {
              alert('Please enter converted quantity of second item.');
              document.getElementById("new_item_stock_convert").focus();
              return false;
            }
         }   
         /* if(($('sizesp1').val()==0) || ($('#gradesp1').val()==0))
         {
          alert('Please select Specification of first item.');
          return false;
         }
         if(($('sizesp2').val()==0) || ($('#gradesp2').val()==0))
         {
          alert('Please select Specification of second item.');
          return false;
         }
 */
         return true;

}

function displayBatch(value,id)
 {
  //alert("The paragraph was double-clicked."); 
  //alert(value+"  "+id);
 //alert(id);
  var itemcode='';
  var itemname='';
  var unit='';
  var item_ids='';

  
    itemcode = document.getElementById('item_code').value;
    itemname = document.getElementById('item_desc').value;
    unit = document.getElementById('item_unit').value;
    item_ids = document.getElementById('first_item').value;
    //alert("asdas"+item_ids);
    

 // alert(itemcode+"/"+itemname+"/"+unit+"/"+item_ids);

  if(itemcode=='')
  {
    alert("Please select items");
  }
  else if(itemname=='')
  {
    alert("Please enter itemname");
  }
  else if(unit=='')
  {
    alert("Please enter unit");
  }
  else
  {
    //var LeaveType=document.getElementById("LeaveType_"+tt2).value;
    $("#PickedItems1").dialog({
        title:'Batch List',
        modal: true,
        resizable: false,
        width:900,
        height:400,
        closeText: 'fechar',
        draggable: true,
        show: 'fade',
        hide: 'fade',
        dialogClass: 'main-dialog-class',
        buttons: {
          Exit: function()
          {
            $(this).dialog("close");
          }
        }
      });
    
    var site=document.getElementById("site").value;
   var store=document.getElementById("store").value;
    //var invoiceTime=$('#invoiceTime').val();
    //alert('Getstock_items_store.php?site='+site+'&invoicedate='+invoicedate+'&invoiceTime='+invoiceTime);
    $.ajax({url:'getItemBatch_mat.php?item_id='+item_ids+'&batch_id='+id+'&site='+site+'&store='+store,success:function(result)
      {
        $('#PickedItems1').html(result);
        }
         });
  }
}

function addBatchData(id,value,unit,batch,mfg,expiry,rate)
{
  
  
        //$(thisRow).clone().insertAfter( thisRow ).find( 'input:text' );
        $('#item_stock_hidden').val(value);
        $('#item_batch').val(batch);
         $('#rate1').val(rate);
     
    }
     
function get_value()
{
  var qty=document.getElementById("item_stock").value;
  var conv=document.getElementById("con_factor").value;
  if(conv=='') { conv=0; }
  if(qty=='') { qty=0; }

  var sec_qty=parseFloat(qty)*parseFloat(conv);
  var rate=document.getElementById("rate1").value;
  document.getElementById("item_stock1").value=parseFloat(sec_qty);
  var amt=parseFloat(qty)*parseFloat(rate);
  document.getElementById("total_value1").value=parseFloat(amt).toFixed(2);

}


function hide_div(str)
{
  if(str==0)
  {
    alert("Please Select Type");
    return false;
  }
  else if(str=='B')
  {
    document.getElementById("type_hid").style.visibility='hidden';
    document.getElementById("type_hid1").style.visibility='hidden';
  }
  else
  {
     document.getElementById("type_hid").style.visibility='visible';
    document.getElementById("type_hid1").style.visibility='visible';
  }

}
</script>


<style type="text/css">
.body_lightbox1 {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
