<?php
$PageSecurity = 3;
include('cocoon_config.php');
// error_reporting(0);
// setlocale(LC_MONETARY, 'en_IN');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');
$id = $_REQUEST['id'];


$sql1 = "SELECT * FROM companies where CompanyId='" . $_SESSION['ACGCompanyId'] . "'";
$sqlres = DB_query($sql1, $db);
$CompanyRow = DB_fetch_array($sqlres);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  <title>Purchase Order</title>
  <script type="text/javascript" language="javascript">
    function toggle_visibility(id) {
      var e = document.getElementById(id);
      e.style.display = 'none';
      //alert(e.style.display);
      window.print();
    }
  </script>
  <style type="text/css">
    @print {
      size: A4;
      margin: 20px 20px;
    }

    @media print {
      body {
        margin: 0px;
        padding: 0px;
        font-size: 12px;
        line-height: 18px;
        font-family: Arial, Helvetica, sans-serif;
        color: #000;
        font-weight: normal;
      }

      h1,
      h2,
      h3,
      h4,
      h5,
      p {
        margin: 0px;
        padding: 0px;
      }

      p {
        text-align: left;
      }

      thead {
        display: table-header-group;
      }

      .wrapper {
        width: 100%;
        height: auto;
        float: left;
        border: #000000 1px solid;
        border-bottom: #000000 1px solid;
      }

      h1 {
        font-size: 24px;
        line-height: 28px;
        font-weight: bold;
        font-family: Arial, Helvetica, sans-serif !important;
        /*color:#006699; */
        text-transform: uppercase;
      }

      h2 {
        font-size: 18px;
        line-height: 22px;
        font-weight: normal;
        font-family: Arial, Helvetica, sans-serif !important;
      }

      .div_first,
      .div_first .full {
        width: 100%;
        height: auto;
        /*border-bottom: #000000 1px solid;
         border-top: #000000 1px solid;*/
        /*border-left: #000000 1px solid;
         border-right: #000000 1px solid;*/
        float: left;
        position: relative;
        display: table;
      }

      .div_first .full {
        text-align: center;
        border: 0;
        margin: 10px 0 0;
      }

      .div_first .left,
      .div_first .middle,
      .div_first .right {
        float: left;
        display: table-cell;
        vertical-align: middle;
      }

      .div_first .left {
        width: 16%;
        text-align: center;
        height: auto;
        vertical-align: middle;
        padding: 1% 0;
      }

      .div_first .middle {
        width: 68%;
        text-align: center;
        padding: 1% 0;
        position: relative;
        margin: 0 auto;
      }

      .div_first .right {
        width: 16%;
        text-align: center;
        padding: 1% 0;
      }

      .div_second,
      .div_third,
      .div_forth,
      .div_fifth {
        width: 100%;
        height: auto;
        /*border-bottom: #000000 1px solid;*/
        border-top: #000000 1px solid;
        /*border-left: #000000 1px solid;
         border-right: #000000 1px solid;*/
        float: left;
      }

      .div_second table tr th,
      .div_second table tr td {
        border-right: #000000 1px solid;
        border-bottom: #000000 1px solid;
      }

      .div_second table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_second table tr th:last-child,
      .div_second table tr td:last-child {
        border-right: 0;
      }

      .div_second table tr:last-child td {
        border-bottom: 0;
      }

      .div_second table tr td>table tr td {
        border-right: #000000 1px solid;
        border-bottom: #000000 1px solid;
      }

      .div_second table tr td>table tr td:last-child {
        border-right: 0;
      }

      .div_second table tr td>table tr:last-child td {
        border-bottom: 0;
      }

      .div_third table tr th,
      .div_third table tr td {
        border-bottom: #000 1px solid;
        border-right: #000 1px solid;
      }

      .div_third table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_third table tr th:last-child,
      .div_third table tr td:last-child {
        border-right: none;
      }

      .div_third table tr:last-child td {
        border-bottom: none;
      }

      .div_forth table tr th,
      .div_forth table tr td {
        border-bottom: #000 1px solid;
        border-left: #000 1px solid;
      }

      .div_forth table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_forth table tr td:last-child {
        border-left: none;
      }

      .div_forth table tr:last-child td {
        border-bottom: none;
      }

      .div_fifth table tr th,
      .div_fifth table tr td {
        border-bottom: #000 1px solid;
        border-left: #000 1px solid;
      }

      .div_fifth table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_fifth table tr td:first-child {
        border-left: none;
      }

      .div_fifth table tr:last-child td {
        border-bottom: none;
      }

      .f12 {
        font-weight: bold;
        color: #000;
        font-size: 12px;
      }

      .f11 {
        color: #000;
        font-size: 12px;
        line-height: 18px;
      }

      .f14 {
        color: #000;
        font-size: 18px;
      }

      .mt26 {
        margin-top: 4px;
        width: 96%;
      }

      .mt27 {
        margin-top: 4px;
        width: 56%;
      }

      .border_top {
        border-top: #000 1px solid;
      }

      .brdln {
        border-left: none;
      }

      .wdt1 {
        width: 10%;
      }

      .wdt2 {
        width: 180px;
      }

      .wdt3 {
        width: 66px;
      }

      .wdt4 {
        width: 120px;
      }

      .wdt5 {
        width: 52px;
      }

      .wdt6 {
        width: 70px;
      }
    }

    @media screen {

      /* CSS Document */
      body {
        margin: 0px;
        padding: 0px;
        background-color: #fff;
        font-size: 12px;
        line-height: 18px;
        font-family: Arial, Helvetica, sans-serif;
        color: #000;
        font-weight: normal;
      }

      h1,
      h2,
      h3,
      h4,
      h5,
      p {
        margin: 0px;
        padding: 0px;
      }

      p {
        text-align: left;
      }

      #foo {
        width: 1070px;
        height: auto;
        margin: 0px auto;
      }

      .wrapper {
        width: 1070px;
        height: auto;
        margin: 10px auto;
        border-top: #000000 1px solid;
      }

      h1 {
        font-size: 24px;
        line-height: 28px;
        font-weight: bold;
        font-family: Arial, Helvetica, sans-serif !important;
        /*color:#006699; */
        text-transform: uppercase;
      }

      h2 {
        font-size: 18px;
        line-height: 22px;
        font-weight: normal;
        font-family: Arial, Helvetica, sans-serif !important;
      }

      .div_first,
      .div_first .full {
        width: 100%;
        height: auto;
        /*border-bottom: #000000 1px solid;
         border-top: #000000 1px solid;*/
        border-left: #000000 1px solid;
        border-right: #000000 1px solid;
        float: left;
        position: relative;
        display: table;
      }

      .div_first .full {
        text-align: center;
        border: 0;
        margin: 10px 0 0;
      }

      .div_first .left,
      .div_first .middle,
      .div_first .right {
        float: left;
        display: table-cell;
        vertical-align: middle;
      }

      .div_first .left {
        width: 16%;
        text-align: center;
        height: auto;
        vertical-align: middle;
        padding: 1% 0;
      }

      .div_first .middle {
        width: 68%;
        text-align: center;
        padding: 1% 0;
        position: relative;
        margin: 0 auto;
      }

      .div_first .right {
        width: 16%;
        text-align: center;
        padding: 1% 0;
      }

      .div_second,
      .div_third,
      .div_forth,
      .div_fifth {
        width: 100%;
        height: auto;
        /*border-bottom: #000000 1px solid;*/
        border-top: #000000 1px solid;
        border-left: #000000 1px solid;
        border-right: #000000 1px solid;
        float: left;
      }

      .div_second table tr th,
      .div_second table tr td {
        border-right: #000000 1px solid;
        border-bottom: #000000 1px solid;
      }

      .div_second table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_second table tr th:last-child,
      .div_second table tr td:last-child {
        border-right: 0;
      }

      .div_second table tr:last-child td {
        border-bottom: 0;
      }

      .div_second table tr td>table tr td {
        border-right: #000000 1px solid;
        border-bottom: #000000 1px solid;
      }

      .div_second table tr td>table tr td:last-child {
        border-right: 0;
      }

      .div_second table tr td>table tr:last-child td {
        border-bottom: 0;
      }

      .div_third table tr th,
      .div_third table tr td {
        border-bottom: #000 1px solid;
        border-right: #000 1px solid;
      }

      .div_third table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_third table tr th:last-child,
      .div_third table tr td:last-child {
        border-right: none;
      }

      .div_third table tr:last-child td {
        border-bottom: none;
      }

      .div_forth table tr th,
      .div_forth table tr td {
        border-bottom: #000 1px solid;
        border-left: #000 1px solid;
      }

      .div_forth table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_forth table tr td:last-child {
        border-left: none;
      }

      .div_forth table tr:last-child td {
        border-bottom: none;
      }

      .div_fifth table tr th,
      .div_fifth table tr td {
        border-bottom: #000 1px solid;
        border-left: #000 1px solid;
      }

      .div_fifth table tr th {
        background-color: #ccc;
        text-align: left;
      }

      .div_fifth table tr td:first-child {
        border-left: none;
      }

      .div_fifth table tr:last-child td {
        border-bottom: none;
      }

      .f12 {
        font-weight: bold;
        color: #000;
        font-size: 12px;
      }

      .f11 {
        color: #000;
        font-size: 12px;
        line-height: 18px;
      }

      .f14 {
        color: #000;
        font-size: 18px;
      }

      .mt26 {
        margin-top: 4px;
        width: 96%;
      }

      .mt27 {
        margin-top: 4px;
        width: 56%;
      }

      .border_top {
        border-top: #000 1px solid;
      }

      .brdln {
        border-left: none;
      }

      .wdt1 {
        width: 10%;
      }

      .wdt2 {
        width: 180px;
      }

      .wdt3 {
        width: 66px;
      }

      .wdt4 {
        width: 120px;
      }

      .wdt5 {
        width: 52px;
      }

      .wdt6 {
        width: 70px;
      }
    }
  </style>
  <?php
  function number_to_words($no)
  {
    $string   = null;
    $fraction   = null;
    $decimal    = ' point ';
    $words = array(
      '0' => '',
      '1' => 'one',
      '2' => 'two',
      '3' => 'three',
      '4' => 'four',
      '5' => 'five',
      '6' => 'six',
      '7' => 'seven',
      '8' => 'eight',
      '9' => 'nine',
      '10' => 'ten',
      '11' => 'eleven',
      '12' => 'twelve',
      '13' => 'thirteen',
      '14' => 'fouteen',
      '15' => 'fifteen',
      '16' => 'sixteen',
      '17' => 'seventeen',
      '18' => 'eighteen',
      '19' => 'nineteen',
      '20' => 'twenty',
      '30' => 'thirty',
      '40' => 'fourty',
      '50' => 'fifty',
      '60' => 'sixty',
      '70' => 'seventy',
      '80' => 'eighty',
      '90' => 'ninty',
      '100' => 'hundred AND ',
      '1000' => 'thousand',
      '100000' => 'lakh',
      '10000000' => 'crore'
    );
    if ($no == 0)
      return ' ';
    else {
      if (strpos($no, '.') !== false) {
        list($no, $fraction) = explode('.', $no);
      }

      $novalue = '';
      $highno = $no;
      $remainno = 0;
      $value = 100;
      $value1 = 1000;

      while ($no >= 100) {
        if (($value <= $no) && ($no < $value1)) {
          $novalue = $words["$value"];
          $highno = (int)($no / $value);
          $remainno = $no % $value;
          break;
        }
        $value = $value1;
        $value1 = $value * 100;
      }

      if (null !== $fraction && is_numeric($fraction) && $fraction != 0) {
        $string = $decimal;
        $words1 = array();
        foreach (str_split((string) $fraction) as $number) {
          $words1[] = $words[$number];
        }
        $string .= implode(' ', $words1);
      }

      if (array_key_exists("$highno", $words)) {
        return $words["$highno"] . " " . $novalue . " " . number_to_words($remainno) . $string;
      } else {
        $unit = $highno % 10;
        $ten = (int)($highno / 10) * 10;
        return $words["$ten"] . " " . $words["$unit"] . " " . $novalue . " " . number_to_words($remainno) . $string;
      }
    }
  }


  function getRate($qty, $total, $basicamt, $totalexcise, $rate)
  {
    // echo $qty." <br/> ".$total." <br/> ".$basicamt." <br/>".$totalexcise."<br/> ".$rate;
    //echo "<br/>";
    $x = round(($totalexcise * $total / $basicamt), 2);
    $y = round(($x / $qty), 2);
    return $z = round(($y + $rate), 2);
    //return $rate;

  }


  ?>
</head>

<body>
  <div class="wrapper">
    <div id="header">
      <div class="div_first">
        <?php
        echo $s->print_header();
        ?>
        <h3 style="text-transform:uppercase;text-align:center;padding:5px;">Purchase Order</h3>
      </div>
            
      <?php
      $DetailsIno = DB_query("select * from purchorders where id='" . $_REQUEST['id'] . "'", $db);
      $DetInoRow = DB_fetch_array($DetailsIno);
      ?>
      <div class="div_second">
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr>
            <td colspan="6" class="f12" align="left">Vendor</td>
            <td colspan="2" class="f12" align="left" width="21%">Payment Terms</td>
            <td colspan="2" class="f12" align="left" width="21%">PO No.</td>
          </tr>
          <tr>
            <td colspan="6" height="60" rowspan="2" valign="top" class="f11">
              <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'vendor_name'); ?>
              <br />
              <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'adrress1'); ?>
              &nbsp;
              <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'adrress2'); ?>
              <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'address3'); ?> -
              <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'pincode'); ?>
              <br />
              Ph: <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'extension'); ?> -
              <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'phone1'); ?>,
              Mob: <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'mobile'); ?>,
              Email : <?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'email'); ?>
            <td colspan="2" class="f11"> <?php echo $s->getField('paymentterms', 'termsindicator', $DetInoRow['payment_terms'], 'terms'); ?></td>
            <td colspan="2" class="f11"><?php echo $DetInoRow['purchase_ordNo']; ?></td>
          </tr>
          <tr>
            <td colspan="2" class="f12">Payment Mode</td>
            <td colspan="2" class="f12">PO Date</td>
          </tr>
          <tr>
            <td width="6%" class="f12">CST :</td>
            <td width="12%" class="f11"><?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'cst_no'); ?></td>
            <td width="6%" class="f12">GST :</td>
            <td width="12%" class="f11"><?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'gst_no'); ?></td>
            <td width="6%" class="f12">ECC :</td>
            <td class="f11"><?php echo $s->getField('suppliers', 'id', $DetInoRow['vendorId'], 'excise_no'); ?></td>
            <td class="f11" colspan="2"><?php echo $s->getField('paymentmethods', 'paymentid', $DetInoRow['payment_mod'], 'paymentname'); ?></td>
            <td colspan="2" class="f11"><?php echo ConvertSQLDate($DetInoRow['po_date']); ?></td>
          </tr>
          <tr>
            <td colspan="3" class="f12 brdr_lft">Ship To</td>
            <td align="center" colspan="2" class="f12 brdr_lft">Created Date:</td>
            <td class="f11 brdr_lft"><?php echo $DetInoRow['created_date']; ?></td>
            <td width="12%" class="f12">Quotation No. :</td>
            <td class="f11"><?php echo $DetInoRow['quotationId']; ?></td>
            <td width="12%" class="f12">Quotation Date :</td>
            <td class="f11"><?php echo date('d/m/Y', strtotime($DetInoRow['qutation_date'])); ?></td>
          </tr>
          <tr>
            <td colspan="6" height="60" rowspan="2" valign="top" class="f11">
              <?php
              $ss1 = "Select * from locations where CompanyId='" . $_SESSION['ACGCompanyId'] . "' and loccode ='" . $DetInoRow['site'] . "' ";
              $site_sql = DB_query($ss1, $db);
              $site_row = DB_fetch_array($site_sql);
              ?>
              <?php echo $InoRow['locationname']; ?><br />
              Address: <?php echo $DetInoRow['sippiling_Address'] . ",&nbsp;" . $DetInoRow['sippiling_Address1'] . ",&nbsp;" . $DetInoRow['sippiling_Address2'] ?>,<?php echo $s->getField('city_master', 'id', $DetInoRow['sippiling_City'], 'city'); ?>,<?php echo $s->getField('state_master', 'id', $DetInoRow['sippiling_State'], 'state'); ?>,<?php echo $s->getField('country_master', 'id', $DetInoRow['sippiling_Country'], 'country'); ?><br />
              Fax : <?php echo $site_row['fax']; ?>,
              Phone : <?php echo $site_row['phone1']; ?>
            </td>
            <td class="f12">Delivery Date :</td>
            <td class="f11"> <?php echo ConvertSQLDate($DetInoRow['delivery_date']); ?></td>
            <td class="f12">Valid Upto :</td>
            <td class="f11"><?php echo ConvertSQLDate($DetInoRow['valid_till']); ?></td>
          </tr>
          <tr>
            <td class="f12">Contact :</td>
            <td class="f11"><?php echo $s->getField('contact_information_master', 'id', $DetInoRow['contact_person'], 'person'); ?></td>
            <td class="f12">Mobile:</td>
            <td class="f11"><?php echo $DetInoRow['mobileNo']; ?></td>
          </tr>
          <tr>
            <td class="f12">CST :</td>
            <td class="f11"><?php echo $site_row['lst_cst']; ?></td>
            <td class="f12">GST :</td>
            <td class="f11"><?php echo $site_row['gst_no']; ?></td>
            <td class="f12">ECC :</td>
            <td class="f11"> <?php echo $site_row['eccno'] ?></td>
            <td class="f12" nowrap=""></td>
            <td class="f11"></td>
            <td class="f12"></td>
            <td class="f11"></td>
          </tr>
        </table>
      </div>
    </div>
    <div id="main">
      <div class="div_third">
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr>
            <td width="5%" align="center" class="f12">S. No.</td>
            <td align="left" class="f12">Item Name</td>
            <td width="10%" align="left" class="f12">Item Code</td>
            <td width="10%" align="left" class="f12">Brand</td>
            <td width="7%" align="center" class="f12">QTY</td>
            <td width="7%" align="center" class="f12">Free QTY</td>
            <td width="10%" align="center" class="f12">Rate</td>
            <td width="7%" align="center" class="f12">Total</td>
            <td width="8%" align="center" class="f12">Disc. Type</td>
            <td width="7%" align="center" class="f12">Disc. Amt</td>
            <td width="12%" align="center" class="f12">Basic Amt</td>
          </tr>
          <?php
          $query1 = "SELECT * FROM purchorderdetails where parantId  ='" . $_REQUEST['id'] . "'";
          $sql = DB_query($query1, $db);
          $count = DB_num_rows($sql);
          //echo $query1;

          if (DB_num_rows($sql) > 0) {
            $i = 1;
            $totalamt = 0;
            $unittotal = array();
            $secunittotal = array();
            while ($myrow = DB_fetch_array($sql)) {
              $brndSql = "select id,brand_desc from branditems where id='" . $myrow['brand_id'] . "'";
              $brand_sql = mysqli_query($link1, $brndSql);
              $brand_row = mysqli_fetch_array($brand_sql);
              $brnadName = $brand_row['brand_desc'];
          ?>
              <tr>
                <td align="center" valign="top" class="f11"><?php echo $i; ?></td>
                <td align="left" valign="top" class="f11"><?php echo $s->getField('item_master', 'id', $myrow['mst_itemid'], 'item_name'); ?><br /><?php echo $myrow['remarks'];  ?></td>
                <td align="left" valign="top" class="f11"><?php echo $s->getField('item_master', 'id', $myrow['mst_itemid'], 'StockID'); ?></td>
                <td align="left" valign="top" class="f11"><?php echo $brnadName; ?></td>
                <td align="center" class="f11"><?php echo $qty = round($myrow['Quantity'], 0); ?> <?php $unitid = $s->GetFieldValue('item_master', "id='" . $myrow['mst_itemid'] . "'", 'mst_unitid');
                                                                                                  echo $s->GetFieldValue('unitsofmeasure', "unitid='" . $unitid . "'", 'unitname'); ?>
                <td align="center" class="f11"><?php echo  round($myrow['free_qty'], 0); ?> <?php $unitid = $s->GetFieldValue('item_master', "id='" . $myrow['mst_itemid'] . "'", 'mst_unitid');
                                                                                            echo $s->GetFieldValue('unitsofmeasure', "unitid='" . $unitid . "'", 'unitname'); ?>
                  <?php
                  $unitid = $s->GetFieldValue('item_master', "id='" . $myrow['mst_itemid'] . "'", 'mst_unitid');
                  $unitname = $s->GetFieldValue('unitsofmeasure', "unitid='" . $unitid . "'", 'unitname');

                  //$unitid = $s->getField('item_master','id',$myrow['mst_unitid'],'mst_unitid');
                  // $unitname =$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname');
                  $unittotal[$unitname] = $unittotal[$unitname] + $qty;




                  $unit2 = $s->getField('item_master', 'id', $myrow['mst_itemid'], 'conv_unit');
                  $conv_factor = $s->getField('item_master', 'id', $myrow['mst_itemid'], 'conv_factor');
                  //  echo $conv_factor;
                  $secqty = floatval($myrow['Quantity'] * $conv_factor);
                  //echo " (".$s->getField('unitsofmeasure','unitid',$unit2,'unitname')." ) ";
                  $secunitname = $s->getField('unitsofmeasure', 'unitid', $unit2, 'unitname');
                  //  $unittotal[$unitname]=$unittotal[$unitname]+$qty;
                  $secunittotal[$secunitname] = $secunittotal[$secunitname] + $secqty;


                  ?>
                </td>
                <td align="right" valign="top" class="f11"><?php echo $myrow['Rate'] ?> <br />Per <?php $unitid = $s->GetFieldValue('item_master', "id='" . $myrow['mst_itemid'] . "'", 'mst_unitid');
                                                                                                  echo $s->GetFieldValue('unitsofmeasure', "unitid='" . $unitid . "'", 'unitname'); ?></td>
                <td align="right" valign="top" class="f11"><?php echo money_format('%!i', $myrow['totalPrice']); ?></td>
                <td align="right" valign="top" class="f11"><?php echo $myrow['DiscountType']; ?></td>
                <td align="right" valign="top" class="f11"><?php echo money_format('%!i', $myrow['Discount']); ?></td>
                <td align="right" valign="top" class="f11"><?php echo money_format('%!i', $myrow['basic_Amt']); ?></td>
              </tr>
            <?php
              $i++;
            }
            while ($i < 20) {
            ?>
          <?php
              $i++;
            }
          }

          ?>
        </table>
      </div>
    </div>
    <div class="clr"></div>
    <div id="footer">
      <div class="div_forth">
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr>
            <td width="17%" rowspan="2" class="f12" style="border-left:0;">Total Quantity</td>
            <td rowspan="2" colspan="2" width="29%" class="f11"><?php
                                                                if ($qty != '') {
                                                                  foreach ($unittotal as $key => $value) {
                                                                    echo $value . " " . $key . " ";
                                                                  }
                                                                }

                                                                ?></td>
            <td rowspan="2" colspan="2" class="f11"><?php
                                                    if ($secqty != '') {
                                                      foreach ($secunittotal as $key => $value) {
                                                        echo $value . " " . $key . " ";
                                                      }
                                                    }
                                                    ?></td>
            <td width="12%" class="f11">Basic Amt.</td>
            <td width="13%" class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['total_amount']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11">Discount Amt.</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo $DetInoRow['discount_amt']; ?></span>
            </td>
          </tr>
          <tr>
          </tr>
          <!-- <tr>
                     <td class="f11">GST %</td>
                     <td class="f11"><span style="float:left;">:</span>
                      <span style="float:right;"><?php //echo money_format('%!i',$DetInoRow['excise_amt']); 
                                                  ?></span></td>
                     </tr>  -->
          <tr>
            <td rowspan="2" class="f12" style="border-left:0;">Cheques Enclosed</td>
            <td class="f12">Bank Name</td>
            <td class="f12">Chq No.</td>
            <td class="f12">Date</td>
            <td class="f12">Amount</td>
            <td class="f11">Pkg Charges</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo $DetInoRow['pkg_charges']; ?></span>
            </td>
          </tr>
          <tr class="f11">
            <td><?php echo $DetInoRow['bank_name']; ?></td>
            <td><?php echo $DetInoRow['check_no']; ?></td>
            <td><?php if ($DetInoRow['check_date'] != '') {
                  echo ConvertSQLDate($DetInoRow['check_date']);
                } else {
                  echo "";
                } ?></td>
            <td><?php if ($DetInoRow['check_amt'] != '') {
                  echo money_format('%!i', $DetInoRow['check_amt']);
                } else {
                  echo "";
                } ?></td>
            <td class="f11">Taxable Amt.</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php $tot_tax_amt = $DetInoRow['total_amount'] + $DetInoRow['pkg_charges'] - $DetInoRow['discount_amt'];
                                          echo money_format('%!i', $tot_tax_amt); ?></span>
            </td>
          </tr>
          <tr>
          </tr>
          <tr>
            <td colspan="5" class="f12" style="border-left:0;">Remarks</td>
            <td class="f11">Input Tax</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['vat_amt']); ?></span>
            </td>
          </tr>
          <tr>
            <td colspan="5" rowspan="7" valign="top" class="f11" style="border-left:0;"><?php echo $DetInoRow['remarks']; ?> </td>
            <td class="f11">Surcharge</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['surcharge_amt']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11">Entry tax</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['entry_tax_amt']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11">Insurance</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['insurancecharges_amt']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11">Miscellaneous</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['other_amt']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11">Freight</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['Freight']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11">Other</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['other_amt']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11">Round Off</td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo $DetInoRow['pluMin'] . " " . money_format('%!i', $DetInoRow['roundVal']); ?></span>
            </td>
          </tr>
          <tr>
            <td class="f11" style="border-left:0;">Grand Total (In Words) :</td>
            <td colspan="4" class="f11 upper" style="border-left:0;"><strong><?php echo "RUPEES " . ucfirst(number_to_words($DetInoRow['GrandTotal'])) . " ONLY"; ?></strong></td>
            <td class="f11"><strong>Grand Total</strong></td>
            <td class="f11"><span style="float:left;">:</span>
              <span style="float:right;"><?php echo money_format('%!i', $DetInoRow['GrandTotal']); ?></span>
            </td>
          </tr>
        </table>
      </div>
      <div class="div_fifth">
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr>
            <td colspan="4" align="center" class="f12">Branch Details</td>
            <td rowspan="4" width="25%" align="center" valign="top"><strong>For <?php echo $InoRow['locationname']; ?>.</strong></td>
          </tr>
          <tr>
            <td class="f12" width="15%">TIN/CST/VAT Reg. :</td>
            <td class="f11" width="25%"><?php echo $InoRow['tin_no']; ?></td>
            <td class="f12" width="15%">Range :</td>
            <td class="f11"><?php echo $InoRow['site_range']; ?></td>
          </tr>
          <tr>
            <td class="f12">CST No. :</td>
            <td class="f11"><?php echo $InoRow['lst_cst']; ?></td>
            <td class="f12">Division :</td>
            <td class="f11"><?php echo $InoRow['division']; ?></td>
          </tr>
          <tr>
            <td class="f12">ECC NO.</td>
            <td class="f11"><?php echo $InoRow['eccno']; ?></td>
            <td class="f12">Commisionerate :</td>
            <td class="f11"><?php echo $InoRow['commissionerate']; ?></td>
          </tr>
          <tr>
            <td class="f12">Service Tax Regn. No.</td>
            <td class="f11"><?php echo $InoRow['ce_regn_no']; ?></td>
            <td class="f12">PAN No.</td>
            <td class="f11"><?php echo $InoRow['panno']; ?></td>
            <td align="center" class="f12">Authorized Signatory</td>
          </tr>
          <?php
          $result = DB_query("Select * from companies", $db);
          $data = DB_fetch_array($result);
          ?>
          <tr>
            <td colspan="5" class="f12" align="center">Head Office : <?php echo $data['Address1'] . " , " . $data['Address2'] . " , " . $data['City'] . " , " . $data['State'] . " , " . $data['Country'] . " - " . $data['Zipcode'] . " , Phone - " . $data['Phone'] . " , Fax-" . $data['fax'] . " <br/> Email-" . $data['email']; ?></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</body>

</html>