<?php require "_header.php";
include "Numbers/Words.php"; ?>
<div id="main-report" align="center">

  <?php

  if ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {
    $customerinvoice_id = Escape($_POST["customerinvoice_id"]);
    $customerinvoice_no = Escape($_REQUEST["customerinvoice_no"]);

    $height = 300;
    $nw = new Numbers_Words();

    $agencyid = $_SESSION["cCompany_id"];

    $headerflag = $_REQUEST['headerflag'];

    $qry = " SELECT * FROM lms_customerinvoice lci,lms_customer lc
where lci.customer_id=lc.customer_id and lci.customerinvoice_no = " . $customerinvoice_no . " and lci.company_id=" . $_SESSION['cCompany_id'] . " and lc.company_id=" . $_SESSION['cCompany_id'];

    //$ObjagencymasterMgmt = new agencymasterMgmt(); ".$_REQUEST['nro_no']. "
  
    $rs = dbQuery($qry);
    $rs1 = dbQuery($qry);
    $count = dbRows($rs);
    $j = 0;
    $custome_height = 240;
    ///extract($row);
    ob_start();

    $i = 0;
    $sno = 1;
    $net_amount = 0;
    if ($count > 0) {
      $row = dbArray($rs);


      ?>
      <div style="height:160px;">
        <?php if ($_SESSION['cCompany_id'] == 5) { ?>
          <span style="font-size:26px; font-weight:bold"><u>Aum Infotech</u></span><br />
          <span style="font-size:14px;"><br />
            B/A/5, Gold Coin Complex,3rd Floor,<br />
            Jodhapur Cross Road,Satellite,<br />
            Ahmedabad – 380015,Gujarat – India <br />
          </span>
        <?php } else { ?>
          <img src="head.jpg" height="140" width="100%" />
        <?php } ?>
      </div>

      <?php if ($_SESSION['cCompany_id'] == 5) { ?>
        <table width="100%" align="center" class="report">
        <?php } else { ?>
          <table width="100%" align="center" class="report"
            style="background-image:url(back.jpg);background-position:center; background-repeat:no-repeat;">
          <?php } ?>

          <tr style="height:35px">
            <td colspan="2" style="vertical-align:middle;border:none;" align="center">
              <span style="font-size:18px; font-weight:bold">INVOICE</span>
            </td>
          </tr>
          <tr>
            <td align="left" width="35%" style="text-align:left">
              <b>Customer Name & Address :</b>
              <br /><?php echo $row['customer_orgname'] . "<br/>" . $row['customer_address']; ?>
            </td>
            <td width="100%" style="text-align:left;border:none">
              <b>Invoice No :&nbsp;&nbsp;</b><?php echo $row['customerinvoice_no'] ?><br />
              <b>Date :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> <?php
              if ($customerinvoice_date == '31/3/1900')
                echo '-';
              else
                echo $customerinvoice_date;
              ?><br />
              <b>Remark :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><?php echo $row['remark'] ?>
            </td>

          </tr>


          <tr>
            <th style="text-align:center" colspan="2">Product Details</th>

          </tr>

          <tr>
            <td colspan="2">
              <table width="100%" align="center" class="report">

                <tr>
                  <td style="text-align:center;" width="6%">
                    <b> Sr.</b>
                  </td>
                  <td style="text-align:center;" width="40%">
                    <b> Description </b>
                  </td>
                  <td style="text-align:center;" width="10%">
                    <b> Qty. </b>
                  </td>
                  <td style="text-align:center;" width="15%">
                    <b> Rate </b>
                  </td>


                  <td style="text-align:center;" width="22%">
                    <b> Amount(Rs) </b>
                  </td>
                </tr>


                <?php
                $qry = "Select lcp.product_id,lcp.product_qty,lcp.product_rate,lp.product_name
                    from
                        lms_customerinvoiceproduct lcp,
                        lms_productmaster lp
                    Where
                        lcp.product_id=lp.product_id
                    And
                    customerinvoice_id='" . $customerinvoice_id . "'";

                $finalout = dbQuery($qry);
                while ($finalrow = dbArray($finalout)) {
                  //print_r($finalrow); 
                  $Amount = $finalrow["product_qty"] * $finalrow["product_rate"];
                  $totalproduct += $Amount;
                  ?>
                  <tr>
                    <td style="text-align:center"><?php echo $sno; ?></td>
                    <td><?php echo $finalrow["product_name"]; ?></td>
                    <td style="text-align:center"><?php echo $finalrow["product_qty"]; ?></td>
                    <td style="text-align:center"><?php echo $finalrow["product_rate"]; ?></td>
                    <td style="text-align:right"><?php echo number_format($Amount, 2); ?></td>
                  </tr>
                  <?php $sno++;
                  $height = $height - 25;
                } ?>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td style="text-align:right"><?php echo number_format($totalproduct, 2); ?></td>
                </tr>
                <?php

                $qry = "Select lt.tax_name,lct.tax_percentage
	 	FROM
			lms_customerinvoicetax lct,
			lms_taxmaster lt
		WHERE
			lt.tax_id= lct.tax_id
		AND
			customerinvoice_id='" . $customerinvoice_id . "'";

                $finalTax = dbQuery($qry);
                while ($finalTaxrow = dbArray($finalTax)) {
                  //print_r($finalTaxrow); 
                  $taxamount = (($totalproduct * $finalTaxrow["tax_percentage"]) / 100);
                  $totaltax += $taxamount;
                  ?>
                  <tr>
                    <td></td>
                    <td style="text-align:right"><?php echo $finalTaxrow["tax_name"]; ?></td>
                    <td></td>
                    <td style="text-align:right"><?php echo $finalTaxrow["tax_percentage"]; ?>%</td>
                    <td style="text-align:right"><?php echo number_format($taxamount, 2); ?></td>
                  </tr>
                  <?php
                  $height = $height - 25;
                }
                $grandtotal = $totaltax + $totalproduct; ?>
                <tr style="height:<?php echo $height . "px" ?>">
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
              </table>

            </td>
          </tr>
          <tr style="height:35px;vertical-align:middle">

            <td align="left" width="71%">
              <b>Final Payable Amount in Words : </b><br />
              <?php echo strtoupper($nw->toWords($grandtotal) . " Rupees Only"); ?>
            </td>
            <td align="left">
              <b>Final Payable :</b>
              <?php echo ' Rs. ' . number_format(round($grandtotal), 2); ?>
            </td>
          </tr>

          <tr>
            <td colspan="2">
              <u> <b>Terms & Condition:</b> </u>
              <div width="100%" style="vertical-align:top;font-size:9px" align="left">



                01. 100% Payment against delivery by Cheque/Draft in favour of
                <?php echo $_SESSION['cCompany_name'] ?>,Ahmedabad.<br>
                02. Goods once sold will not be taken back or exchange in any case.<br>
                03. One Year Warranty.<br>
                04. Subject to Ahmedabad Jurisdiction.<br>

              </div>
              <br><br> <br><br><br><br />
              <b>Received the above goods in good condition</b>
              <span style="font-size:12px;float:right;margin-right:30px"><b>For,
                  <?php echo $_SESSION['cCompany_name'] ?></b> </span><br /> &nbsp;
              <br /><br />
              <span style="margin-left:50px; font-size:12px; float:left"><b>Receiver's Sign with Stamp</b></span><span
                style="font-size:12px; float:right; margin-right:20px"><b>Authorized Signatory</b> </span>

            </td>
          </tr>
        </table>


      <?php
    } else { ?>
        <div style="height:160px;">
          <?php if ($_SESSION['cCompany_id'] == 5) { ?>
            <span style="font-size:26px; font-weight:bold"><u>Aum Infotech</u></span><br />
            <span style="font-size:14px;"><br />
              B/A/5, Gold Coin Complex,3rd Floor,<br />
              Jodhapur Cross Road,Satellite,<br />
              Ahmedabad – 380015,Gujarat – India <br />
            </span>
          <?php } else { ?>
            <img src="head.jpg" height="140" width="100%" />
          <?php } ?>

        </div>
        <?php if ($_SESSION['cCompany_id'] == 5) { ?>
          <table width="100%" align="center" class="report">
          <?php } else { ?>
            <table width="100%" align="center" class="report"
              style="background-image:url(back.jpg);background-position:center; background-repeat:no-repeat;">
            <?php } ?>

            <tr style="height:35px">
              <td colspan="2" style="vertical-align:middle;border:none;" align="center">
                <span style="font-size:18px; font-weight:bold">INVOICE</span>
              </td>
            </tr>
            <tr>
              <td align="left" width="35%" style="text-align:left">
                <b>Customer Name & Address :</b>
                <br />
              </td>
              <td width="100%" style="text-align:left;border:none">
                <b>Invoice No :&nbsp;&nbsp;</b><br />
                <b>Date :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> <br />
                <b>Remark :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
              </td>

            </tr>


            <tr>
              <th style="text-align:center" colspan="2">Product Details</th>

            </tr>

            <tr>
              <td colspan="2">
                <table width="100%" align="center" class="report">

                  <tr>
                    <td style="text-align:center;" width="6%">
                      <b> Sr.</b>
                    </td>
                    <td style="text-align:center;" width="40%">
                      <b> Description </b>
                    </td>
                    <td style="text-align:center;" width="10%">
                      <b> Qty. </b>
                    </td>
                    <td style="text-align:center;" width="15%">
                      <b> Rate </b>
                    </td>


                    <td style="text-align:center;" width="22%">
                      <b> Amount(Rs) </b>
                    </td>
                  </tr>

                  <tr style="height:350px">
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>

                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                </table>

              </td>
            </tr>
            <tr style="height:35px;vertical-align:middle">

              <td align="left" width="71%">
                <b>Final Payable Amount in Words : </b><br />

              </td>
              <td align="left">
                <b>Final Payable :</b>

              </td>
            </tr>

            <tr>
              <td colspan="2">
                <u> <b>Terms & Condition:</b> </u>
                <div width="100%" style="vertical-align:top;font-size:9px" align="left">



                  01. 100% Payment against delivery by Cheque/Draft in favour of
                  <?php echo $_SESSION['cCompany_name'] ?>,Ahmedabad.<br>
                  02. Goods once sold will not be taken back or exchange in any case.<br>
                  03. One Year Warranty.<br>
                  04. Subject to Ahmedabad Jurisdiction.<br>

                </div>
                <br><br> <br><br><br><br />
                <b>Received the above goods in good condition</b>
                <span style="font-size:12px;float:right;margin-right:30px"><b>For,
                    <?php echo $_SESSION['cCompany_name'] ?></b> </span><br /> &nbsp;
                <br /><br />
                <span style="margin-left:50px; font-size:12px; float:left"><b>Receiver's Sign with Stamp</b></span><span
                  style="font-size:12px; float:right; margin-right:20px"><b>Authorized Signatory</b> </span>

              </td>
            </tr>
          </table>
        <?php }


    ?>



        <?php
        $HtmlCode = ob_get_contents();
        ob_end_flush();
        $HtmlUrl = "customerbill-report-" . $_SESSION["eAgencyId"] . ".html";
        $HtmlPath = "report/" . $HtmlUrl;
        createHTMLReportPage($header_row_string, $HtmlUrl, $HtmlPath, $HtmlCode, true);
        ?>
        <br />
        <br /><br />
        <form name="frm" id="frm" action="" method="post">
          <input type="hidden" name="txtFile" id="txtFile" value="<?php echo $HtmlUrl; ?>" />
          <input type="button" name="btnPdf" id="btnPdf" value="Print" onClick="SetPageAction('PRINT');" />
          <input type="button" name="btnPdf" id="btnPdf" value="Create PDF" onClick="SetPageAction('PDF');" />
          <input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onClick="SetPageAction('HTML');" />
          <input type="button" name="btnWord" id="btnWord" value="Create WORD" onClick="SetPageAction('WORD');" />
          <input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onClick="SetPageAction('Excel');" />
        </form>
        <script language="javascript" type="text/javascript">
          function SetPageAction(varAction) {

            if (varAction == "PRINT") {
              document.frm.action = "print/create-print.php";
              document.frm.target = "_blank";
              document.frm.submit();
            }
            else if (varAction == "PDF") {
              document.frm.action = "convertpdf/create-pdf.php";
              document.frm.target = "_blank";
              document.frm.submit();
            }
            else if (varAction == "HTML") {
              document.frm.action = "<?php echo $HtmlPath; ?>";
              document.frm.target = "_blank";
              document.frm.submit();
            }
            else if (varAction == "WORD") {
              document.frm.action = "convertword/create-word.php";
              document.frm.target = "_blank";
              document.frm.submit();
            }
            else if (varAction == "Excel") {
              document.frm.action = "convertword/create-excel.php";
              document.frm.target = "_blank";
              document.frm.submit();
            }
          }
        </script>
      <?php } else {
    echo "Session Expired";
  }
  ?>

      <?php require "_footer.php"; ?>