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

$maindb = "actran";

$formname = "Daily Cash Report";
$file = "dailycashrp_fr.php";

$zroot = 'apps4rea_msp_root';

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

if (isset($_POST["view"])) {
    
    $date = $_POST["date"];

    $dtypecond = "";

    $mdate = trim($_POST["date"]);

    if (empty($_POST["date"])) {
        browse(" Date Cannot Be Empty");
        header("refresh:1; dailycashrp.php");
    }

    $getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`date`, '%d-%m-%Y') as mydt FROM `$maindb` WHERE `date` = '$date'")or die(mysqli_error($conn));
    $get = mysqli_num_rows($getpmain);
    include("includes/linkshead.php");
    ?>
    <style type="text/css">
        #tabital{
            font-style: italic;
        }
        #font1{
            font-style: italic;
        }
        #boldfont{
            font-weight: bold; 
        }
    </style>

    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-lg-6">
                    <label class="label-control marg">Date - </label>
                    <label class="label-control marg"><?php Echo Date("d-m-Y"); ?></label>
                </div>
                <div class="col-lg-5">
                    <label class="label-control marg">Print - </label>
                    <label class="label-control marg"><?php Echo $formname; ?></label>
                </div>
                <div class="col-lg-1">
                    <a onclick="window.close()" class="btn btn-primary">GO Back</a>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12 pad">
                    <table style="background: white;width: 100%" class="table table-condensed table-hover">
                        <thead class="mySearchTr">
                            <tr>
                                <th style="width:5%"> Date</th>
                                <th style="width:10%"> Voucher No</th>
                                <th style="width:10%"> Name</th>
                                <th style="width:10%;" class="text-right">Debit</th>
                                <th style="width:15%"  class="text-right">Credit</th>
                                <th style="width:15%"  class="text-right">Balance</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                $ctr = 0;
                                $mtqty = 0;
                                $mgtot = 0;

                            while ($pmain = mysqli_fetch_array($getpmain)) {

                                $ctr++;
                                Echo "<tr id='boldfont'>";
                                Echo "<td>$ctr</td>";
                                Echo "<td>$pmain[vouchno]</td>";
                                Echo "<td>$pmain[vouchdt]</td>";
                                Echo "<td class='text-right' >$pmain[qty]</td>";
                                Echo "<td class='text-right'>$pmain[total]</td>";
                                Echo "<td style='padding-left:20px;'>$pmain[remark] &nbsp;   &nbsp;  $pmain[remark2]</td>";
                                $mtqty = $pmain[qty]  + $mtqty;
                                $mgtot = $pmain[total] + $mgtot;
                               
                                Echo "</tr>";

//                                $tottopay = $tottopay + $pmain[total];
//                                $paidtot = $paidtot + $pmain[totpaid];
//                                $totnet = $totnet + $pmain[finalamt];
//                                if ($_POST["dtype"] == 2) {

                                Echo "<tr style='height:10px;'>";
                                Echo "<td colspan='25'>";
                                Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-hover table-bordered'>";
                                Echo "<th style='background-color: #cccccc;width:5%;'>Sr</th>";
                                Echo "<th style='background-color: #cccccc;width:10%; class='numeric''>Barcode</th>";
                                Echo "<th style='background-color: #cccccc';width:6%; >Itemname</th>";
                                Echo "<th style='background-color: #cccccc;width:6%;' class='numeric'>Qty</th>";
                                Echo "<th style='background-color: #cccccc;width:6%;'>Unit</th>";
                                Echo "<th style='background-color: #cccccc;width:6%;' class='numeric'>Mrp</th>";
                                Echo "<th style='background-color: #cccccc;width:6%;' class='numeric'>Rate</th>";
                                Echo "<th style='background-color: #cccccc;width:6%;' class='numeric'>Amount</th>";
                                Echo "<th style='background-color: #cccccc;width:6%;' class='numeric'>Msp</th>";
                                Echo "<tr>";

//
                                    $ctr2 = 0;
                                    $tqty = 0;
                                    $tamt = 0;
                                
                                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]' $itemcond $itemnamecond  ")or die(mysqli_error($conn));
                                while ($tran = mysqli_fetch_array($gettran)) {

                                    $getitem = mysqli_query($conn, "SELECT `code`,`name` FROM `item` WHERE `code`='$tran[itemcode]'")or die(mysqli_error($conn));
                                    $item = mysqli_fetch_array($getitem);

                                    $ctr2++;
                                    Echo "<tr>";
                                    Echo "<td>$ctr2</td>";
                                    Echo "<td>$tran[itemcode]</td>";
                                    Echo "<td>$item[name]</td>";
                                    Echo "<td class='numeric'>$tran[trqty]</td>";
                                    Echo "<td>$tran[unit]</td>";
                                    Echo "<td class='numeric'>$tran[mrp]</td>";
                                    Echo "<td class='numeric'>$tran[rate]</td>";
                                    Echo "<td class='numeric'>$tran[amount]</td>";
                                    Echo "<td class='numeric'>$tran[msp]</td>";
                                    Echo "</tr>";

                                    $tqty = $tran[trqty] + $tqty;
                                    $tamt = $tran[amount] + $tamt;
                                }

                                Echo "<tr style=' '>";
                                Echo "<td style=' '></td>";
                                Echo "<td style=' '></td>";
                                Echo "<th style='text-align:right;color:blue;'>Total</th>";
                                Echo "<th style='text-align:right;color:blue; '>$tqty</th>";
                                Echo "<td style=' 'class='numeric'></td>";
                                Echo "<td style=' 'class='numeric'></td>";
                                Echo "<td style=' 'class='numeric'></td>";
                                Echo "<th style='text-align:right;color:blue; '>$tamt</td>";
                                Echo "<td style=' '></td>";
                                Echo "</tr>";
                                Echo "</table>";
                                Echo "</td>";
//                                }
//                                if ($_POST["dtype"] == 2) {
//                                    echo "<tr> ";
//                                    $colr1 = "blue";
//                                    echo "<td style='color:$colr1;' align='right' id='font1' colspan='6' ><h5><b>Total :</b></h5></td>";
//                                    echo "<td style='color:$colr1;' align='right' id='font1'><h5><b>$topaytot1</b></h5></td>";
//                                    echo "<td style='color:$colr1;' align='center' id='font1'><h5><b>$totweight</b></h5></td>";
//                                    echo "<td style='color:$colr1;'  id='font1'><h5><b>$totpaid</b></h5></td>";
//                                    echo "</tr>";
//                                }
                            }

                            echo "<tr> ";
                            echo "<td></td>";
                            echo "<td></td>";
                            echo "<th class='text-right' style='color: red;'>Grand Total</td>";
                            echo "<th class='text-right' style='color: red;'>$mtqty</td>";
                            echo "<th class='text-right' style='color: red;'>$mgtot</td>";
                            echo "<td></td>";
                            echo "</tr>";
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <?php include("includes/linksfoot.php");
        ?>
    </body>
    </html>
    <?php
}



//
//if (isset($_POST["excel"])) {
//    
//    $accode = $_POST[accode];
//    $vehno = $_POST[vehno];
//    $branch = $_POST[branch];
//    $frmplace = $_POST[frmplace];
//    $toplace = $_POST[toplace];
//
//    $dtype = $_POST[dtype];
//    $mtype = $_POST[mtype];
////    browse($mtype);
//    $accodecond = "";
//    $dtypecond = "";
//    $mtypecond = "";
//
//    if (!empty($accode)) {
//        $accodecond = " AND `accode`='$accode' ";
//    }
//
//    if (!empty($vehno)) {
//        $vehnocond = " AND `vehno`='$vehno' ";
//    }
//
//    if (!empty($branch)) {
//        $branchcond = " AND `branch`='$branch' ";
//    }
//
//    if (!empty($frmplace)) {
//        $frmplacecond = " AND `frmplace`='$frmplace' ";
//    }
//
//    if (!empty($toplace)) {
//        $toplacecond = " AND `toplace`='$toplace' ";
//    }
//
//    if (!empty($frmdt)) {
//        $frmdtcond = " AND `frmdt`='$frmdt' ";
//    }
//
//    if (!empty($todt)) {
//        $todtcond = " AND `todt`='$todt' ";
//    }
//
//    if (!empty($dtype)) {
//        $dtypecond = " AND `dtype`='$dtype' ";
//    }
//
//    if (!empty($mtype)) {
//        $mtypecond = " AND `stype`='$mtype' ";
//    }
//
//    if (empty($_POST["frmdt"])) {
//        browse("From Date Cannot Be Empty");
//        header("refresh:1; invreg.php");
//    }
//    if (empty($_POST["todt"])) {
//        browse("To Date Cannot Be Empty");
//        header("refresh:1; invreg.php");
//    }
//    $mfrmdate = trim($_POST["frmdt"]);
//    $mtodate = trim($_POST["todt"]);
//
//    $getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM `$maindb` WHERE `vouchdt` >= '$mfrmdate' 
//                            AND `vouchdt` <= '$mtodate' $accodecond $vehnocond $branchcond $frmplacecond $toplacecond")or die(mysqli_error($conn));
//    $get = mysqli_num_rows($getpmain);
//
//
//    $contents.="Sr,Voucher,Invoice No.,Date,Vehicle No.,Branch,From Place,To Place,Topay,Paid,Final Amount\n";
//
//    $ctr = 0;
//    $totamt = 0;
//    $topaytot = 0;
//    $paidtot = 0;
//    $totnet = 0;
//
//    while ($pmain = mysqli_fetch_array($getpmain)) {
//        
//
//        $getfrom = mysqli_query($conn, "SELECT * FROM `cepheisy_gujtran_root`.`place` WHERE `code`='$pmain[frmplace]'")or die(mysqli_error($conn));
//        $mfrom = mysqli_fetch_array($getfrom);
//
//        $getto = mysqli_query($conn, "SELECT * FROM `cepheisy_gujtran_root`.`place` WHERE `code`='$pmain[toplace]'")or die(mysqli_error($conn));
//        $mto = mysqli_fetch_array($getto);
//
//        $gettruck = mysqli_query($conn, "SELECT * FROM `cepheisy_gujtran_root`.`vehicle` WHERE `code`='$pmain[vehno]'")or die(mysqli_error($conn));
//        $mtruck = mysqli_fetch_array($gettruck);
//
//        $getbranch = mysqli_query($conn, "SELECT * FROM `cepheisy_gujtran_root`.`branch` WHERE `code`='$pmain[branch]'")or die(mysqli_error($conn));
//        $mbranch = mysqli_fetch_array($getbranch);
//
////        $getmqty = mysqli_query($conn, "SELECT SUM(qty)as totqty FROM `$trandb` WHERE `vouchno`='$pmain[VOUCHNO]'")or die(mysqli_error($conn));
////        $mqty = mysqli_fetch_array($getmqty);
//
//        $ctr++;
//        $vouchno = $pmain[vouchno];
//        $invno = $pmain[invno];
//        $mydt = $pmain[mydt];
//        $vehno = $mtruck[vehno];
//        $branch = $mbranch[name];
//        $frmplace = $mfrom[name];
//        $toplace = $mto[name];
//        $topay = $pmain[total];
//        $paid = $pmain[totpaid];
//        $finalamt = $pmain[finalamt];
//
//        $topaytot = $topaytot + $pmain[total];
//        $paidtot = $paidtot + $pmain[totpaid];
//        $totnet = $totnet + $pmain[finalamt];
//
//        $contents.=$ctr . ",";
//        $contents.=$vouchno . ",";
//        $contents.=$invno . ",";
//        $contents.=$mydt . ",";
//        $contents.=$vehno . ",";
//        $contents.=$branch . ",";
//        $contents.=$frmplace . ",";
//        $contents.=$toplace . ",";
//        $contents.=$topay . ",";
//        $contents.=$paid . ",";
//        $contents.=$finalamt . "\n";
//
//
//        if ($_POST["dtype"] == 2) {
//
//            $contents.="Sr,L.R.No,Art/Qty,Packages,Description,Consignee,To.Pay,Weight,Paid,Remark\n";
//
//
//            $ctr2 = 0;
//            $topaytot1 = 0;
//            $totweight = 0;
//            $totpaid = 0;
//            $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
//            while ($tran = mysqli_fetch_array($gettran)) {
//
//                $getpack = mysqli_query($conn, "SELECT * FROM `cepheisy_gujtran_root`.`packing` WHERE `code`='$tran[package]'")or die(mysqli_error($conn));
//                $mpack = mysqli_fetch_array($getpack);
//
//                $getdescrip = mysqli_query($conn, "SELECT * FROM `cepheisy_gujtran_root`.`descrip` WHERE `code`='$tran[descrip]'")or die(mysqli_error($conn));
//                $mdescrip = mysqli_fetch_array($getdescrip);
//
//                $ctr2++;
//                $lrno = $tran[lrno];
//                $art = $tran[art];
//                $pack = $mpack[name];
//                $descrip = $mdescrip[name];
//                $consig = $tran[consignee];
//                $topay = $tran[topay];
//                $weight = $tran[weight];
//                $paid = $tran[paid];
//                $remark = $tran[remark];
//
//                $contents.=$ctr2 . ",";
//                $contents.=$lrno . ",";
//                $contents.=$art . ",";
//                $contents.=$pack . ",";
//                $contents.=$descrip . ",";
//                $contents.=$consig . ",";
//                $contents.=$topay . ",";
//                $contents.=$weight . ",";
//                $contents.=$paid . ",";
//                $contents.=$remark . "\n";
//
//                $topaytot1 = $topaytot1 + $tran[topay];
//                $totweight = $totweight + $tran[weight];
//                $totpaid = $totpaid + $tran[paid];
//
//                $contents.=" " . ",";
//                $contents.=" " . ",";
//                $contents.=" " . ",";
//                $contents.=" " . ",";
//                $contents.=" " . ",";
//                $contents.="TOTAL" . ",";
//                $contents.=$topaytot1 . ",";
//                $contents.=$totweight . ",";
//                $contents.=$totpaid . "\n";
//            }
//        }
//    }
//
//
//    $contents.=" " . ",";
//    $contents.=" " . ",";
//    $contents.=" " . ",";
//    $contents.=" " . ",";
//    $contents.=" " . ",";
//    $contents.=" " . ",";
//    $contents.="Grand Total" . ",";
//    $contents.=" " . ",";
//    $contents.=$topaytot . ",";
//    $contents.=$paidtot . ",";
//    $contents.=$totnet . "\n";
//
//    $contents = strip_tags($contents);
//
//    if ($_POST["dtype"] == 1) {
//        header("Content-Disposition: attachment; filename=$formname" . "_Summary" . date('d-m-Y') . ".csv");
//    } else {
//        header("Content-Disposition: attachment; filename=$formname" . "_Detail" . date('d-m-Y') . ".csv");
//    }
//    print $contents;
//}
?>   
