<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

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

$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');

$formname = "Item Groupwise Sale Register";

if (isset($_POST["view"])) {
    $dtype = $_POST["dtype"];
    if ($dtype == "1") {
        $action = "itemgrp_sale_fr.php";
    } else {
        $action = "itemgrp_dtlsale_fr.php";
    }
}

mysqli_select_db($conn, $zdb);

include("includes/files.php");
include("includes/combo.php");
?>

<form class="form-horizontal" action='<?= $action ?>' method='POST'>
    <div class="row">
        <div class="col-lg-12">
            <div class="box">
                <header>
                    <div class="icons">
                        <i class="fa fa-edit"></i>
                    </div>
                    <h5><?= $formname ?></h5>
                    <div class="toolbar">
                        <ul class="nav pull-right">
                            <li>
                            <li><input id="submit" type='submit' name='view' value='View' class="btn btn-primary"></li>
                            <li>
                                <a class="minimize-box" data-toggle="collapse" href="#div-4">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                            </li>
                        </ul>
                    </div><!-- /.toolbar -->
                </header>
                <div id="div-4" class="accordion-body collapse in body">
                    <div class="form-group">
                        <label class="control-label col-lg-3">Item Group</label>
                        <div class="col-lg-5">
                            <div class="input-group">
                                <select class='form-control' name='itemgrp'  class="itemgrp" style="width:297px;height:33px;" >
                                    <option value=""></option>
                                    <?php
                                    $getitemgrp = mysqli_query($conn, "SELECT code, `name` FROM `itemgrp` ORDER BY `name`") or die(mysqli_error($conn));
                                    while ($igetgrp = mysqli_fetch_array($getitemgrp)) {
                                        echo "<option value='$igetgrp[code]'>$igetgrp[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-lg-3">Item Name</label>
                        <div class="col-lg-5">
                            <div class="input-group">
                                <select class='form-control' name='name' class="item" style="width:297px;height:33px;">
                                    <option value=""></option>
                                    <?php
                                    $getitem = mysqli_query($conn, "SELECT code, `name` FROM `item` ORDER BY `name`") or die(mysqli_error($conn));
                                    while ($iget = mysqli_fetch_array($getitem)) {
                                        echo "<option value='$iget[code]'>$iget[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-lg-3">From Date</label>
                        <div class="col-lg-5">
                            <div class="input-group">
                                <input type="date" id="mfrdt" name="frmdt" class="form-control" value="<?php echo $mfrdate; ?>" />  
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-lg-3">To Date</label>
                        <div class="col-lg-5">
                            <div class="input-group">
                                <input type="date" id="mtodt" name="todt" class="form-control" value="<?php echo $mtodate; ?>" />  
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-lg-3">Report Type</label>
                        <div class="col-lg-5">
                            <div class="input-group">
                                <select name="dtype" id="dtype" class="form-control" style="height:33px;width:297px;">
                                    <option value="1">Summary</option>
                                    <option value="2">Detail</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>