<?php
ob_start();
session_name('CAKEPHP'); session_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('cocoon_config.php');
date_default_timezone_set('Asia/Calcutta');
$s = new db_query();
?>

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

$GetRecord = $_SESSION['gst_output_register'];
$Compamies = DB_query("select * from companies", $db);
$CompamiesRow = DB_fetch_array($Compamies);
//unset($_SESSION['trf_req_rep']);
?>

<!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>GST Register Report</title>

  <style type="text/css" media="print">
    @page port {
      size: portrait;
    }

    @page land {
      size: landscape;
    }

    .portrait {
      page: port;
    }

    .wrapper {
      page: land;
    }
  </style>

  <style type="text/css">
    @print {
      size: portrait;
      margin: 10px;
    }

    @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;
      }

      h1 {
        font-size: 20px;
        line-height: 24px;
        font-weight: normal;
        font-family: Arial, Helvetica, sans-serif !important;
      }

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

      thead {
        display: table-header-group;
      }

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

      .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;
      }

      .div_first .left {
        width: 18%;
        text-align: left;
        height: auto;
        vertical-align: middle;
        height: auto;
        padding: 1%;
        float: left;
      }

      .div_first .middle {
        width: 58%;
        text-align: center;
        padding: 1%;
        margin: 0 auto;
        float: left;
      }

      .div_first .right {
        width: 18%;
        text-align: right;
        padding: 1%;
        float: left;
      }

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

      .div_second,
      .div_third,
      .div_forth {
        width: 100%;
        height: auto;
        border-top: #000000 1px solid;
        /*border-bottom: #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 0px solid;
        border-bottom: #000000 1px solid;
      }

      .div_second table tr th {
        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: transparent;
        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-right: #000 1px solid;
      }

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

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

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

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

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

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

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

      .mt27 {
        margin-top: 0px;
        width: 70%;
      }

      .mt28 {
        margin-top: 0px;
        width: 100%;
      }

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

      .border_bottom {
        border-bottom: #000 1px solid;
      }

      .wdt1 {
        width: 8%;
      }

      .wdt2 {
        width: 100px;
      }

      .wdt3 {
        width: 66px;
      }

      .wdt4 {
        width: 80px;
      }

      .wdt5 {
        width: 52px;
      }

      .wdt6 {
        width: 60px;
      }
    }

    @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;
      }

      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: 18%;
        text-align: center;
        height: auto;
        vertical-align: middle;
        padding: 1%;
      }

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

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

      .div_second,
      .div_third,
      .div_forth {
        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 0px 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 {
        border-bottom: #000000 1px solid;
      }

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

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

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

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

      .mt27 {
        margin-top: 0px;
        width: 100%;
      }

      .mt28 {
        margin-top: 0px;
        width: 90%;
      }

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

      .border_bottom {
        border-bottom: #000 1px solid;
      }

      .wdt1 {
        width: 10%;
      }

      .wdt2 {
        width: 180px;
      }

      .wdt3 {
        width: 66px;
      }

      .wdt4 {
        width: 120px;
      }

      .wdt5 {
        width: 52px;
      }

      .wdt6 {
        width: 70px;
      }
    }
  </style>

  <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>

</head>

<body>
  <div id="foo">
    <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
  </div>

  <div class="wrapper">
    <div class="div_first">
      <?php $logoImage = ($CompamiesRow['CompanyLogo'] == '') ? 'electra.jpg' : $CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>
      <div class="middle"><?php
                          if ($CompamiesRow['CompanyName'] != "") {
                            echo "<h1>" . $CompamiesRow['CompanyName'] . "</h1>";
                          } else {
                            echo "";
                          }

                          if ($InoRow['deladd1'] != "") {
                            echo $InoRow['deladd1'];
                          } else {
                            echo "";
                          }
                          if ($InoRow['deladd2'] != "") {
                            echo ", " . $InoRow['deladd2'];
                          } else {
                            echo "";
                          }
                          if ($InoRow['deladd3'] != "") {
                            echo ", " . $InoRow['deladd3'];
                          } else {
                            echo "";
                          }
                          if ($InoRow['city'] != "") {
                            echo ", " . $s->getFieldValue("city_master", "id='" . $InoRow['city'] . "'", "city");
                          } else {
                            echo "";
                          }
                          if ($InoRow['pincode'] != "") {
                            echo " - " . $InoRow['pincode'];
                          } else {
                            echo "";
                          }
                          if ($InoRow['state'] != "") {
                            echo ", " . $s->getFieldValue("state_master", "id='" . $InoRow['state'] . "'", "state");
                          } else {
                            echo "";
                          }
                          if ($InoRow['country'] != "") {
                            echo ", " . $s->getFieldValue("country_master", "id='" . $InoRow['country'] . "'", "country");
                          } else {
                            echo "";
                          }
                          ?>
        <div class="full"><span class="f11"><?php echo "Phone No.:" . $CompamiesRow['Phone'] . ",   Fax No.: " . $CompamiesRow['fax'] . ", Email ID.: " . $CompamiesRow['email'] . ",   Website: " . $CompamiesRow['website']; ?><br>
            <?php echo $_SESSION['mess']; ?>
          </span>
          <span class="f11"><span class="f12">From:</span> <?php echo $_SESSION['gst_from_date'] ?> - <span class="f12">To:</span> <?php echo $_SESSION['gst_to_date']; ?></span>
          <div class="cdate f11"><span class="f12">Date:</span><?php echo date('d/m/Y'); ?> | <span class="f12">Time:</span> <?php echo date('h:i:s a'); ?></div>
        </div>
        <h2>GST Output Register</h2>
      </div>
      <div class="right"></div>
    </div>

    <div class="div_second">
      <div class="panel">
        <table width="100%" cellpadding="3" cellspacing="0" border="0">
          <thead>
            <tr class="f12">
              <th width="2%">S. No.</th>
              <!-- <th width="4%">CIN No.</th>
    <th width="4%">GSTIN</th> -->
              <th width="4%">Bill No.</th>
              <!-- <th width="4%">Line Item</th> -->
              <th width="4%">Date</th>
              <th width="4%">Patient Code</th>
              <th>Patient Name</th>
              <th width="4%">State Code</th>
              <th width="4%">State</th>
              <th width="4%">Product Code</th>
              <th width="4%">Part Name</th>
              <th width="4%">HSN Code</th>
              <th width="4%" style="text-align:center;">Qty.</th>
              <th width="4%" style="text-align:center;">Rate</th>
              <th width="4%" style="text-align:center;">Product Value</th>
              <th width="4%" style="text-align:center;">Discount(Amt.)</th>
              <th width="4%" style="text-align:center;">Product Value after Discount</th>
              <th width="4%" style="text-align:center;">Tax %</th>
              <th width="4%" style="text-align:center;">Tax Amt.</th>
              <th width="4%" style="text-align:center;">SGST</th>
              <th width="4%" style="text-align:center;">CGST</th>
              <th width="4%" style="text-align:center;">IGST</th>
              <th width="4%" style="text-align:center;">UGST</th>
              <th width="4%" style="text-align:center;">Total Value on Invoice</th>
            </tr>
          </thead>
          <tbody>
            <?php
            $GetRecord = $_SESSION['gst_output_register'];
            $result = mysqli_query($link1, $GetRecord);
            $i = 1;
            while ($in_fetch = mysqli_fetch_array($result)) {
              $sql_outpatients = mysqli_fetch_array(mysqli_query($link1, "select mrno,state,state_code from outpatients inner join addresses on outpatients.registration_id=addresses.registration_id  where op_number='" . $in_fetch['patient_no'] . "'"));
              $hsn = DB_fetch_array(DB_query("select hsn_code from item_master where item_name='" . $in_fetch['item_name'] . "'", $db));

            ?>
              <tr class="f11">
                <td><?php echo $i; ?></td>
                <!-- <td><?php echo $sql_outpatients[0]; ?></td>
      <td><?php //echo $s->GetFieldValue('suppliers',"id='".$in_fetch['vendor']."'",'gst_no'); 
          ?></td> -->
                <td><?php echo $in_fetch['voucher_no']; ?></td>
                <!--<td></td> -->
                <td><?php
                    $date = strtotime($in_fetch['issue_date']);
                    echo date('Y-m-d', $date);
                    ?></td>
                <td><?php echo $in_fetch['patient_no']; ?></td>
                <td><?php echo $in_fetch['patient_name']; ?></td>
                <td style="text-align:center;"><?php
                                                $stateCode = DB_fetch_array(DB_query("select * from state_master where state='" . $sql_outpatients[1] . "'", $db));
                                                echo $stateCode['state_code'];
                                                ?>
                </td>
                <td><?php echo $sql_outpatients[1]; ?></td>
                <td><?php echo $in_fetch['item_code']; ?></td>
                <td><?php echo $in_fetch['item_name']; ?></td>
                <td><?php echo $hsn['hsn_code']; ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['issue_qty']; ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['rate']; ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['pre_discount_amount'];
                                              $basic[] = $in_fetch['pre_discount_amount']; ?></td>
                <td style="text-align:right;"><?php

                                              /* $discount_amount=$in_fetch['discount_actual_amount'];
                             if($in_fetch['pre_discount_amount']!='0' && $in_fetch['pre_discount_amount']!='')
                             {
                                $dis_perc1=$discount_amount*100;
                                echo $dis_per=number_format((float)$dis_perc1/$in_fetch['pre_discount_amount'],2);
                                //echo $dis_perc1."#####".$in_fetch['pre_discount_amount'];

                             }   
                             else
                             {
                               $dis_per='0.00';
                             } */

                                              echo $in_fetch['discount_amount_tot'];



                                              ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['pre_discount_amount'] - $in_fetch['discount_amount_tot'];
                                              $val_after_disc = $in_fetch['pre_discount_amount'] - $in_fetch['discount_amount_tot'];
                                              $disc_arr[] = $in_fetch['pre_discount_amount'] - $in_fetch['discount_amount_tot']; ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['tax_rate']; ?>
                </td>
                <td style="text-align:right;"><?php echo $in_fetch['tax_rate_amount'];
                                              $vat_arr[] = $in_fetch['vat_amt']; ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['sgst'];
                                              $sgst_arr[] = $in_fetch['sgst']; ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['cgst'];
                                              $cgst_arr[] = $in_fetch['cgst']; ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['igst'];
                                              $igst_arr[] = $in_fetch['igst'];  ?></td>
                <td style="text-align:right;"><?php echo $in_fetch['utgst'];
                                              $ugst_arr[] = $in_fetch['ugst']; ?></td>
                <td style="text-align:right;">
                  <?php
                  /*   if($in_fetch['vat_amt']!='0.00')
           {
              $total_invoice=$val_after_disc+$in_fetch['vat_amt'];
              echo number_format((float)$total_invoice,2,'.',',');
           }
           else
           { */
                  $total_invoice = $val_after_disc + $in_fetch['sgst'] + $in_fetch['cgst'] + $in_fetch['igst'] + $in_fetch['utgst'];
                  echo number_format((float)$total_invoice, 2, '.', ',');
                  // }
                  $tot_inv[] = $total_invoice;

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

            <tr class="f12">
              <td colspan="12" style="text-align:right;">Total</td>
              <td style="text-align:right;"><?php if (!empty($basic)) {
                                              echo number_format((float)array_sum($basic), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
              <td style="text-align:right;"></td>
              <td style="text-align:right;"><?php if (!empty($disc_arr)) {
                                              echo number_format((float)array_sum($disc_arr), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
              <td style="text-align:right;"></td>
              <td style="text-align:right;"><?php if (!empty($vat_arr)) {
                                              echo number_format((float)array_sum($vat_arr), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
              <td style="text-align:right;"><?php if (!empty($sgst_arr)) {
                                              echo number_format((float)array_sum($sgst_arr), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
              <td style="text-align:right;"><?php if (!empty($cgst_arr)) {
                                              echo number_format((float)array_sum($cgst_arr), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
              <td style="text-align:right;"><?php if (!empty($igst_arr)) {
                                              echo number_format((float)array_sum($igst_arr), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
              <td style="text-align:right;"><?php if (!empty($ugst_arr)) {
                                              echo number_format((float)array_sum($ugst_arr), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
              <td style="text-align:right;"><?php if (!empty($tot_inv)) {
                                              echo number_format((float)array_sum($tot_inv), 2, '.', ',');
                                            } else {
                                              echo "0.00";
                                            } ?></td>
            </tr>

          </tbody>
        </table>
      </div>

    </div>
  </div>

</body>

</html>