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

    <?php
    /*echo "<pre>";
    print_r($_SESSION);
    exit;*/
    if ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {
        $customerinvoice_id = Escape($_POST["customerinvoice_id"]);
        $customerinvoice_no = Escape($_REQUEST["customerinvoice_no"]);

        if ($customerinvoice_no == '') {
            ?>
            <script language="javascript" type="text/javascript">
                location.href = 'addedit-customerinvoice.php';
            </script>
            <?php
        }
        $height = 300;
        $nw = new Numbers_Words();

        $agencyid = $_SESSION["cCompany_id"];

        $headerflag = $_REQUEST['headerflag'];

        $qry = " SELECT *,u.name 
			FROM lms_customerinvoice lci,lms_customer lc,`lms_usermaster` u 
			where lci.customer_id=lc.customer_id and 
			lci.createdby= u.user_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']. "
        // echo $qry;
        $rs = 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);


            ?>


            <?php if ($_SESSION['cCompany_id'] == 5) { ?>
                <span style="font-size:26px; font-weight:bold"><u>Aum Imagineering Pvt. Ltd.</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 }

            //echo "ddd";
            ?>



            <table width="100%" align="center">
                <tr align="center">
                    <td style="border:none"><b>INVOICE</b></td>
                </tr>
                <tr>
                    <td>
                        <table width="100%" class="report">
                            <tr>
                                <td>
                                    <table width="100%" class="report">
                                        <tr>
                                            <td width="60%" height="20%">
                                                <b>
                                                    <font size="+1"><?php echo $_SESSION['cCompany_name']; ?></font>
                                                </b><br />
                                                <?php echo str_replace("\n", "<br/>", $_SESSION['cCompany_address']); ?><br />
                                                E-Mail:&nbsp;jatin@auminfosys.com , &nbsp; info@auminfosys.com
                                            </td>
                                            <td width="40%" style="vertical-align:text-top;">
                                                <table width="100%" class="report" height="60%">
                                                    <tr>
                                                        <td width="50%" height="5%">Invoice No
                                                            :<br /><b><?php echo $row['customerinvoice_no'] ?></b>
                                                        </td>
                                                        <td width="50%" height="5%">
                                                            Dated :<br /> <?php
                                                            $customerinvoice_date = date("d-m-Y", strtotime($row['customerinvoice_date']));
                                                            if ($customerinvoice_date == '31/3/1900')
                                                                echo '-';
                                                            else
                                                                echo $customerinvoice_date;

                                                            ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td height="5%" colspan="2">Invoice Generated
                                                            By<br /><b><?php echo $row['name'] ?></b></td>
                                                    </tr>
                                                    <tr>
                                                        <td height="5%" width="50%">Buyer's Order No<br />&nbsp;
                                                        </td>
                                                        <td height="5%" width="50%">Dated<br />&nbsp;
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="100" style="vertical-align:text-top;" width="60%"><b>Buyer</b>
                                                <br />
                                                <?php echo "<b>" . $row['customer_orgname'] . "</b><br/>" . $row['customer_address'] . "<br/>Contact NO. &nbsp; " . $row['customer_phone1'] . "&nbsp;&nbsp;" . $row['customer_phone2'];
                                                ?>

                                            </td>
                                            <td height="100" width="40%" colspan="2">&nbsp;
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td width="100%" style="vertical-align:text-top">
                                    <table class="report" width="100%">
                                        <tr align="center">
                                            <td width="5%"><b>SRNo.</b>
                                            </td>
                                            <td width="35%"><b>Perticulars</b>
                                            </td>
                                            <td width="15%"><b>Quantity</b>
                                            </td>
                                            <td width="15%"><b>Rate</b>
                                            </td>
                                            <td width="20%"><b>Amount</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><b><?php echo $finalrow["product_name"]; ?></b>
                                                </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>






                                        <tr>
                                            <td>&nbsp;
                                            </td>
                                            <td style="text-align:right">Total&nbsp;
                                            </td>
                                            <td>&nbsp;
                                            </td>
                                            <td>&nbsp;
                                            </td>
                                            <td style="text-align:right"><b><?php echo number_format($totalproduct, 2); ?></b>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <table width="100%">
                                        <tr>
                                            <td colspan="2" style="border-bottom:none; border-right:none;border-top:none">
                                                <table width="100%">
                                                    <tr>
                                                        <td align="left" width="90%"
                                                            style="border-bottom:none; border-right:none;border-top:none">Amount
                                                            Chargable (inwords)<br />
                                                            <b><?php echo strtoupper($nw->toWords($grandtotal) . " Rupees Only"); ?></b>
                                                        </td>
                                                        <td align="right" width="10%"
                                                            style="border-bottom:none; border-right:none;border-top:none">E. &
                                                            O. E.
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr height="50" style="vertical-align:text-top">
                                            <td colspan="2" style="border-bottom:none; border-right:none;border-top:none">
                                                <b>Remarks</b> - <?php echo $row["remark"]; ?>
                                            </td>
                                        </tr>
                                        <!--<tr >
                    <td colspan="2" style="border-bottom:none; border-right:none;border-top:none">Remarks:<br/>
                    Being Provided To Automation Syatem Erp Ref<br/>
                    no:-606
                    </td>
                </tr>-->
                                        <tr>
                                            <td width="50%" style="border-bottom:none; border-top:none" align="left">
                                                <u> <b>Terms & Condition:</b> </u>
                                                <div width="100%" style="vertical-align:top;font-size:10px" align="left">
                                                    01. 100% Payment against delivery by Cheque/Draft in favour of
                                                    <?php echo $_SESSION['cCompany_name'] ?>&nbsp;,&nbsp;Ahmedabad.<br>
                                                    02. Goods once sold will not be taken back or exchange in any case.<br>
                                                    03. One Year Service Support.<br>
                                                    04. Subject to Ahmedabad Jurisdiction.<br>
                                                </div>
                                            </td>
                                            <td align="right" width="50%">
                                                <table width="100%" height="100">
                                                    <tr>
                                                        <td
                                                            style="text-align:right; border-bottom:none; border-right:none;border-top:none">
                                                            For <?php echo $_SESSION['cCompany_name']; ?></td>
                                                    </tr>
                                                    <tr>
                                                        <td style="border-bottom:none; border-right:none;border-top:none">&nbsp;
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td
                                                            style="text-align:right ;border-bottom:none; border-right:none;border-top:none">
                                                            Authorized Signatory</td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:center">
                        SUBJECT TO AHMEDABAD JURISDICTION<br />
                        This is a Computer Genrated Invoice
                    </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"; ?>