<?php

require("includes/check_auth_user.php");

require("includes/dbconnect.php");

include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];

mysqli_select_db($conn, $zdb);

$maindb = 'rawmat';

if (isset($_POST["submit"])) {

//browse("$_POST[dtype]");

    $cond = "";

    $ccond = "";

    $cocond = "";

    $stcond = "";

    if (!empty($_POST["name"])) {

        $pname = trim($_POST["name"]);

        $cond = "AND `name` LIKE '%$pname%'";

    }



    if (!empty($_POST["group"])) {

        $country = trim($_POST["group"]);

        $cocond = "AND `itemgrp` = '$country'";

    }





    $get = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `name`!='' $cond $cocond ORDER by `name`") or die(mysqli_error($conn));

    $getno = mysqli_num_rows($get);







    /* Normal Browser View Part */

    ?>    

    <!DOCTYPE HTML>

    <html lang="en-US">





        <?php

        include ('includes/files.php');

        ?>

    </head>



    <script>

        (function (i, s, o, g, r, a, m) {

            i['GoogleAnalyticsObject'] = r;

            i[r] = i[r] || function () {

                (i[r].q = i[r].q || []).push(arguments)

            }, i[r].l = 1 * new Date();

            a = s.createElement(o),

                    m = s.getElementsByTagName(o)[0];

            a.async = 1;

            a.src = g;

            m.parentNode.insertBefore(a, m)

        })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');



        ga('create', 'UA-1669764-16', 'onokumus.com');

        ga('send', 'pageview');



    </script>



    <script src="assets/lib/modernizr-build.min.js"></script>

    <script type="text/javascript" src="../js/jquery.js"></script>



    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



    </head>

    <body>



        <?php

        require("includes/dbconnect.php");

        $comp = mysqli_query($conn, "SELECT * FROM `company`") or die(mysql_errno());

        $zcomp = mysqli_fetch_assoc($comp);

        echo "<font size='4px'><b>$zcomp[compname]</font></b></font><br />";

        echo "<font size='2px'><b> $zcomp[add1]. $zcomp[add2].  $zcomp[add3] </b></font><br /><br />";

        echo "<b><font>Item List &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='3px'>Date : " . date("M-d-Y") . "</b><br />";

        echo "<b>" . "Total Records - $getno</b><br />";

        echo "<br />";

        ?>  

        <table class="table table-bordered sortableTable responsive-table" width="100%">



            <thead>

                <tr>

                    <th style="text-align:left;" scope="col" width="6%"><b>Sr.</b></th>

                    <th style="text-align:left;" scope="col" width="30%"><b>Name</b></th>              
                    
                    <th style="text-align:left;" scope="col" width="25%"><b>Raw Material Group</b></th>
                    
                    <th style="text-align:right;" scope="col" width="15%"><b>Cost Price</b></th>
                    
                    <th style="text-align:right;" scope="col" width="15%"><b>Selling Price</b></th>
                    
                    <!--<th style="text-align:right;" scope="col" width="15%"><b>Tans. Chgs</b></th>-->

                </tr>

            </thead>

            <tbody>

                <?php

                $ctr = 0;

                while ($row = mysqli_fetch_object($get)) {



                    $zdb = $_SESSION["zdbyear_" . $dbname];

                    mysqli_select_db($conn, $zdb);


                    $getgrp = mysqli_query($conn, "SELECT * FROM `rawmatgrp` WHERE code ='$row->itemgrp'") or die(mysqli_error($conn));

                    $grp = mysqli_fetch_object($getgrp);



                    $ctr++;

                    echo "<tr> \n";

                    echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $ctr </span> \n </td> \n";
                    echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $row->name</span> \n </td> \n";
                    echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $grp->name </span> \n </td> \n";
                    echo "<td style=\"text-align:right;\" width=\"6\" valign='top'> \n <span> $row->cost</span> \n </td> \n";
                    echo "<td style=\"text-align:right;\" width=\"6\" valign='top'> \n <span> $row->rate</span> \n </td> \n";
//                    echo "<td style=\"text-align:right;\" width=\"6\" valign='top'> \n <span> $row->trans</span> \n </td> \n";
                    echo "</tr> \n";

                    $ctdtl = "0";



                }

                ?>

            </tbody>

            <tfoot>

                <tr>

                    <td colspan="9">

                        <hr/>

                    </td>

                </tr>

            </tfoot>

        </table>



        <script src="assets/lib/jquery.min.js"></script>

        <script src="assets/lib/bootstrap/js/bootstrap.min.js"></script>



        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

        <script src="assets/lib/datatables/jquery.dataTables.js"></script>

        <script src="assets/lib/datatables/DT_bootstrap.js"></script>

        <script src="assets/lib/tablesorter/js/jquery.tablesorter.min.js"></script>

        <script src="assets/lib/touch-punch/jquery.ui.touch-punch.min.js"></script>

        <script src="assets/js/main.min.js"></script>

        <script>

        $(function () {

            metisTable();

            metisSortable();

        });

        </script>

    </body>

    </html>



    <?php

}

?>