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

<?php
$PageSecurity = 2;
$title = _('Site to Site Transfer Issue');
include('cocoon_config.php');
function getFieldvalue_cake($table, $condition, $val, $field)
{
  global $db;
  //echo "select ".$field." from ".$table." where ".$condition." ='".$val."'";
  $sql = mysqli_query($db, "select " . $field . " from " . $table . " where " . $condition . " ='" . $val . "'");
  $r = mysqli_fetch_array($sql);
  //echo "select ".$field." from ".$table." where ".$condition." ='".$val."'"; 
  return ($r[$field]);
}

if ($_REQUEST['action'] == 'Delete' && $_REQUEST['id'] != '') {
  $issueid = $s->getField('transfer_receipt', 'id', $_REQUEST['id'], 'issue_slipno');

  $query_hmis_batch = DB_query("select * from transfer_receipt_details where transfer_receipt_id='" . $_REQUEST['id'] . "'", $db);
  while ($result_hmis_batch = DB_fetch_array($query_hmis_batch)) {
    $storeid = $s->getField('transfer_receipt', 'id', $_REQUEST['id'], 'store_to');
    $storecode = $s->getField('storetype', 'id', $storeid, 'StoreCode');
    $itemcode = $s->getField('item_master', 'id', $result_hmis_batch['itemid'], 'StockID');
    $item_name = $s->getField('item_master', 'id', $result_hmis_batch['itemid'], 'item_name');
    $majorid = $s->getField('item_master', 'id', $result_hmis_batch['itemid'], 'CategoryID');
    $majormainid = $s->getField('stockmaincategory', 'id', $majorid, 'ref_major_id');
    $majorcode = getFieldvalue_cake('majors', 'id', $majormainid, 'major_code');

    // echo "update batchdetails set qty =qty-".$result_hmis_batch['reciveqty']." where item_code='".$itemcode."' and store_code='".$storecode."' and batch_no='".$result_hmis_batch['batch_no']."'";
    //echo "update storeitems set stock_level =stock_level-".$result_hmis_batch['reciveqty']." where item='".$itemcode."' and store_code='".$storecode."' and major_code='".$majorcode."'";
    // exit;



    $update_batch = mysqli_query($link1, "update batchdetails set qty =qty-" . $result_hmis_batch['reciveqty'] . " where item_code='" . $itemcode . "' and store_code='" . $storecode . "' and batch_no='" . $result_hmis_batch['batch_no'] . "'");

    $update = mysqli_query($link1, "update storeitems set stock_level =stock_level-" . $result_hmis_batch['reciveqty'] . " where item='" . $itemcode . "' and store_code='" . $storecode . "' and major_code='" . $majorcode . "'");
  }


  DB_query("update transfer_issue_details set status=0 where transfer_issue_id='" . $issueid . "'", $db);
  DB_query("update transfer_issue set status='Pending' where id='" . $issueid . "'", $db);

  DB_query("delete from transfer_receipt where id='" . $_REQUEST['id'] . "' ", $db);
  DB_query("delete from transfer_receipt_details where transfer_receipt_id='" . $_REQUEST['id'] . "' ", $db);
  DB_query("delete from stock_valuation_tbl where against_voucher_main_id='" . $_REQUEST['id'] . "' and type='STR'", $db);
  echo "<script>location.href='index.php?route=Inventory/transation/site_transfer_receipt_index&modid=" . $_REQUEST['modid'] . "&frmid=" . $_REQUEST['frmid'] . "'</script>";
}
?>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
  <div class="tab_div">
    <h1><?php echo $s->getField('modules_form', 'id', $_REQUEST['frmid'], 'frm_name'); ?></h1>

    <p align="left"><a href="index.php?route=Inventory/transation/site_transfer_receipt&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&NewIssue=yes"><input type="button" class="search" value="Transfer Issue Receipt" /></a></p>

    <table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
      <tr>
        <th width="15%" rowspan="2">Received Slip No.</th>
        <th width="9%" rowspan="2">Date</th>
        <th rowspan="2">From Store</th>
        <th width="20%" rowspan="2">To Store</th>
        <th colspan="2" style="text-align:center;">Action</th>
      </tr>
      <tr>
        <th width="5%" style="text-align:center;">View</th>
        <!-- <th width="5%" style="text-align:center;">Edit</th> -->
        <!-- <th width="5%" style="text-align:center;">Delete</th> -->
        <th width="5%" style="text-align:center;">Print</th>
      </tr>
      <?php

      $sql = DB_query("Select * from transfer_receipt where site in('" . $_SESSION['AssignedBranch'] . "') and received_date between '" . $_SESSION['financialYrStart'] . "' and '" . $_SESSION['financialYrEnd'] . "' order by id desc", $db);

      $i = 0;
      if (DB_num_rows($sql) > 0) {
        while ($myrow = DB_fetch_array($sql)) {
      ?>
          <tr>
            <td><?php echo $myrow['received_slip_no']; ?></td>
            <td><?php echo ConvertSQLDate($myrow['received_date']); ?></td>
            <td><?php echo $s->getField('storetype', 'id', $myrow['store_to'], 'StoreName'); ?></td>
            <td><?php echo $s->getField('storetype', 'id', $myrow['site_from'], 'StoreName'); ?></td>
            <td style="text-align:center;"><?php if ($_SESSION['frmView'] == '1') { ?>
                <a href="index.php?route=Inventory/transation/site_transfer_received_edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=view&id=<?php echo $myrow['id']; ?>"><img src='images/search.gif' height='15' width='15' title="View" /></a><?php } else { ?><img src='images/search.gif' height='15' width='15' title="No Permission" style="opacity:0.5;" /><?php } ?>
            </td>
            <!-- <td style="text-align:center;"><?php if ($_SESSION['frmEdit'] == '1') { ?>
	<a href="index.php?route=Inventory/transation/site_transfer_received_edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=Edit&id=<?php echo $myrow['id']; ?>"><img src='images/icon-edit.png' height='15' width='15' title="Edit" /></a><?php } else { ?><img src='images/icon-edit.png' height='15' width='15' title="No Permission" style="opacity:0.5;" /><?php } ?>
	</td> -->
            <!--<td style="text-align:center;"><?php //if($_SESSION['frmDelete']=='1'){
                                                ?>
	<a href="index.php?route=Inventory/transation/site_transfer_receipt_index&modid=<? php // echo $_REQUEST['modid'];
                                                                                  ?>&frmid=<?php //echo $_REQUEST['frmid'];
                                                                                            ?>&action=Delete&id=<?php //echo $myrow['id']; 
                                                                                                                ?>" onclick="return confirm('Are you sure you want to delete?')"><img src='images/Icon_Delete.png' height='15' width='15' title="Delete" /></a><?php //}else{ 
                                                                                                                                                                                                                                                                ?><img src='images/Icon_Delete.png' height='15' width='15' title="No Permission" style="opacity:0.5;" /><?php //}
                                                                                                                                                                                                                                                                                                                                                                        ?>
	</td> -->
            <td style="text-align:center;"><a target="_blank" href="srn_print.php?modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=Report&id=<?php echo $myrow['id']; ?>"><img src="images/icon_print.jpg" height="18" width="18" title="Print" /></a></td>
          </tr>
        <?php $i++;
        }
      } else { ?>
        <tr>
          <td colspan="12"><strong>No Record Found</strong></td>
        </tr>
      <?php
      }
      ?>
    </table>

  </div>
</div>



<?php
include('includes/footer.inc');
?>
<?php //if(isset($_SESSION['success_msg']))
//{ 
?>
<!-- <script> alert("<?php //echo ($_SESSION['success_msg']);
                      ?>");</script> -->
<?php
//}	unset($_SESSION['success_msg']);
?>