
<link rel="stylesheet" href="css/print.css">

<title>Grn Print</title> 
<style>
body {
  background: rgb(204,204,204); 
}
page {
  background: white;
  display: block;
  margin: 0 auto;
  margin-bottom: 0.5cm;
  box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
}
page[size="A4"] {  
  width: 21cm;
/*  height: 29.7cm; */
}
page[size="A4"][layout="landscape"] {
  width: 29.7cm;
  height: 21cm;  
}
page[size="A3"] {
  width: 29.7cm;
  height: 42cm;
}
page[size="A3"][layout="landscape"] {
  width: 42cm;
  height: 29.7cm;  
}
page[size="A5"] {
  width: 14.8cm;
  height: 21cm;
}
page[size="A5"][layout="landscape"] {
  width: 21cm;
  height: 14.8cm;  
}
@media print {
  body, page {
    background: white;
    margin: 0 ;
    box-shadow: 0;

  }

}
 
</style>

<?php
session_start();
require_once ("connection_sql.php");

if ($_SESSION['company'] == "") { 
    exit("Please Login");
}
if ($_SESSION['CURRENT_USER'] == "") { 
    exit("Please Login");
}

$sql_main = "Select * from s_purmas where  REFNO ='" . $_GET["refno"] . "'";
$result_main = $conn->query($sql_main);
$row_main = $result_main->fetch();
   
$sql_para = "select * from invpara where  flag='".$row_main['company']."'"; 
$result_para = $conn->query($sql_para);
$row_para = $result_para->fetch();

$cancell_title="";
if($row_main['CANCEL']=="1"){
  $cancell_title=" - CANCELED";
}

$vat_title="";
if($row_main['VAT']=="1"){
  $vat_title="VAT -";
}else if($row_main['VAT']=="1"){
  $vat_title="SVAT -";
}

 $sql_vendor = "SELECT * from vendor where CODE='" . $row_main['SUP_CODE'] . "'  "; 
 $result_vendor = $conn->query($sql_vendor);
 $row_vendor = $result_vendor->fetch();
 
 $sql_rep = "SELECT * from s_salrep where REPCODE='" . $row_main['SAL_EX'] . "' ";
 $result_rep = $conn->query($sql_rep);
 $row_rep = $result_rep->fetch();

 $sql_sto = "SELECT * from s_stomas where CODE='" . $row_main['DEPARTMENT'] . "' ";
 $result_sto = $conn->query($sql_sto);
 $row_sto = $result_sto->fetch();


?>
<page size="A3">
<div class="container" >

          <div class="row">
              <div class="col-lg-12">
                  <div class="">
                      <div class="card-body">
                         <div class=" col-md-4 col-sm-4 col-xs-12">
                        <a target="_blank" >
                            <img src="../images/logo.jpg" data-holder-rendered="true" style="width: 100%; height: 115px;" class = "img-responsive" />
                            </a>
                          </div>
                           <div class=" col-lg-12 container-fluid" style="margin: -180px 99px -70px" >

                            <h4 class="text-center my-5" >
                             
                              <span style="color: #db0404; "><?php echo $row_para['COMPANY']?><br></span>
                              <p style="margin: 10px 151px 10px "><?php echo $row_para['ADD1']?>  <br>
                              <p style="margin: 10px 151px 10px">TEL : <?php echo $row_para['TELE']?></p>
                              <p style="margin: 10px 151px 10px">E mail  : <?php echo $row_para['EMAIL']?></p>

                                <p style="font-size: 20px;margin: 10px 151px 10px"><?php echo $vat_title ?> GRN <span>  <?php echo $cancell_title ?></span> </p></p>
                             
                            </h4 >
                            
                            
                          </div>
                         
                           <hr style="margin: 79px 2px 17px">
                          <div class="container-fluid d-flex justify-content-between">
                            <div class="col-lg-7 pl-0">
                              <p class="m-1">GRN Date : <?php echo $row_main['SDATE']?></p> 
                              <p class="m-1">GRN No  : <?php echo $row_main['REFNO']?></p>
                              <p class="m-1">Supplier : <?php echo $row_vendor['NAME']?></p>
                              <p class="m-1">Brand : <?php echo $row_main['brand']?></p>
                              <p class="m-1">PI No  : <?php echo $row_main['pi_no']?></p>
                              <p class="m-1">Department : <?php echo $row_sto['DESCRIPTION']?></p>
                              <p class="m-1">Order By : <?php echo $row_rep['Name']?></p>
                            </div>

                            <div class="col-lg-5 pl-0">
                              <p class="m-1" >PO Date : <?php echo $row_main['PUR_DATE']?></p>  
                              <p class="m-1">PO No : <?php echo $row_main['ORDNO']?></p> 
                              <p class="m-1">BL No : <?php echo $row_main['blno']?></p>
                              <p class="m-1">LC/TT No : <?php echo $row_main['LCNO']?></p>
                              <p class="m-1">CI No : <?php echo $row_main['invno']?></p>
                              <p class="m-1">Invoice Date : <?php echo $row_main['indate']?></p>
                              <p class="m-1">P.Debit Value: <?php echo $row_main['DEBITNOTE_BAL']?></p>
                            </div>
                          </div>

                           <div class="container-fluid d-flex justify-content-between" style="margin:2px 5px -50px">
                            <div class="col-lg-12 pl-0" >
                             
                              <p>Note : <?php echo $row_main['REMARK']?></p>
                              
                            </div>
                          </div>
                          <div class="container-fluid mt-5 d-flex justify-content-center w-100">
                            <div class="table-responsive w-100">
                                <table class="table table-bordered">
                                  <thead>
                                    <tr class="bg-dark text-white">
                                       
                                    <th  style="background-color: #f9f2df !important; color: black !important;">Description</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Order Qty</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Received Qty</th> 
                                    <th style="background-color: #f9f2df !important; color: black !important;">Total Qty</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Com Cost</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Dis 1</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Dis 2</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Dis 3</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Actual Cost</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">List Price</th>
                                    <th style="background-color: #f9f2df !important; color: black !important;">Unit Total</th>
                                      
                                    </tr>
                                  </thead>
                                  <tbody>
                   <?php 

                  $sql_get =  "Select * from s_purtrn where  REFNO='" . $row_main["REFNO"] ."' "; 
                  $result_get = $conn->query($sql_get);

                  if ($row_get = $result_get->fetch()) {

                    echo "<item_table><![CDATA[<table class=\"table table-bordered\">";
                      $i=1;
                      $itemtot = 0;
                      $subtot = 0;
                    foreach ($conn->query($sql_get) as $row_get) {
                      $sql_mas = "select * from s_mas where STK_NO='" . $row_get['STK_NO'] . "'";
                        $result_mas = $conn->query($sql_mas);
                        $row_mas = $result_mas->fetch();
                      echo "<tr>
                            <td align=\"left\">" . $row_mas['DESCRIPT'] . "</a></td>
                            <td align=center>".number_format($row_get["O_QTY"], 0, ".", ",")."</td>
                            <td align=center>".number_format($row_get["REC_QTY"], 0, ".", ",")."</td>
                            <td align=center>".number_format($row_get["QTYINHAND"], 0, ".", ",")."</td>
                            <td align=right>".number_format($row_get["rec_cost"], 2, ".", ",")."</td> 
                            <td align=right>".number_format($row_get["dis1"], 2, ".", ",")."</td> 
                            <td align=right>".number_format($row_get["dis2"], 2, ".", ",")."</td> 
                            <td align=right>".number_format($row_get["dis3"], 2, ".", ",")."</td>  
                            <td align=right>".number_format($row_get["acc_cost"], 2, ".", ",")."</td> 
                            <td align=right>".number_format($row_get["SELLING"], 2, ".", ",")."</td> 
                            <td align=right>".number_format(($row_get["acc_cost"]*$row_get["REC_QTY"]), 2, ".", ",")."</td>

                      ";
                      $i = $i + 1;
                      $itemtot += $row_get['ORD_QTY']; 

                         }

                          $t=19;
                    while ($i <$t) {
                         echo "<tr><td colspan='10' style='text-align: right;font-weight: bold;'>&nbsp;</td>
                                          <td style='text-align: right;font-weight: bold; color: black !important;'></td>
                                          </tr>
                    ";
                         $i=$i+1;
                    }

                        
                        echo "
                        <tr><td colspan='10' style='text-align: right;font-weight: bold;'>Sub GRN Value</td>
                        <td style='text-align: right;font-weight: bold;background-color: #fff2cc !important; color: black !important;'>" . number_format($row_main['sub_value'], 2, '.', ',') . "</td>
                        </tr>";

                        echo "
                        <tr><td colspan='10' style='text-align: right;font-weight: bold;'>Total Discount</td>
                        <td style='text-align: right;font-weight: bold;background-color: #fff2cc !important; color: black !important;'>" . number_format($row_main['total_dis'], 2, '.', ',') . "</td>
                        </tr>";

                        echo "
                        <tr><td colspan='10' style='text-align: right;font-weight: bold;'>Total Vat Value</td>
                        <td style='text-align: right;font-weight: bold;background-color: #fff2cc !important; color: black !important;'>" . number_format($row_main['VAT_AMOUNT'], 2, '.', ',') . "</td>
                        </tr>";

                        echo "
                        <tr><td colspan='10' style='text-align: right;font-weight: bold;'>Total GRN Value</td>
                        <td style='text-align: right;font-weight: bold;background-color: #fff2cc !important; color: black !important;'>" . number_format($row_main['AMOUNT'], 2, '.', ',') . "</td>
                        </tr>";

                       echo "
                        <tr>
                        <td colspan='10' style='text-align: right;font-weight: bold;'>Total Order Qty</td>
                        <td style='text-align: right;font-weight: bold;background-color: #fff2cc !important; color: black !important;'>" . number_format($row_main['TOT_OQTY'], 2, '.', ',') . "</td>
                        </tr>";

                        echo "<tr>
                        <td colspan='10' style='text-align: right;font-weight: bold;'>Total Received Qty</td>
                        <td style='text-align: right;font-weight: bold;background-color: #fff2cc !important; color: black !important;'>" . number_format($row_main['TOT_RQTY'], 2, '.', ',') . "</td>
                        </tr> 
                        </tfoot>
                        </table></item_table>";
                       
                }else{
                   echo "<item_table><![CDATA[<table class=\"table table-bordered\"> <tr><td> No Record Found</td></tr> </table></item_table>";
                }



                                    ?>
                                  </tbody>
                                </table>
                              </div>
                          </div>
                          <div class="container-fluid mt-5 w-100">
                            <p class="text-right mb-2">Thank You Come Again !!</p>
                             
                          </div>
                       
                      </div>
                  </div>
              </div>
          </div>
        </div>
      </div>