<?php

ob_start();

require("includes/check_auth_user.php");

require("includes/dbconnect.php");

include ('includes/function.php');



$admin = $_SESSION["admin_" . $dbname];

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

$myyear = $_SESSION[$myyear];

mysqli_select_db($conn, $zdb);

$zroot = $_SESSION["zdbroot"]; 



$maindb = 'accmast';

$trandb = 'actran';

$formname = 'Expense Register';



$file = 'expreg_fr.php';

$entfile = "expense.php";



$expense = $_GET["expense"];

$amount = $_GET["amount"];

$source = $_GET["source"];



$location = $_POST["location"];

$godown = $_POST["godown"];

$item = $_POST["item"];



$dtype = $_POST["dtype"];



if (!empty($godown)) {

    $godowncond = " AND `godown` = '$godown' ";

}



if (!empty($location)) {

    $locationcond = " AND `location` = '$location'";

}



$itemcond = "";

if (!empty($item)) {

    $itemcond = " AND b.`itemcode` = '$item' ";

}



$expcond = '';

if (!empty($expense)) {

    $expcond = " AND `accode`='$expense' ";

}



$paytypecond = '';

if (!empty($source)) {

    $paytypecond = " AND `source`='$source' ";

}





$mfrmdate = trim($_GET["frmdt"]);

$mtodate = trim($_GET["todt"]);



$mfdt = date("d-m-Y", strtotime($mfrmdate));

$mtdt = date("d-m-Y", strtotime($mtodate));





$mainqry = mysqli_query($conn, "Select *,DATE_FORMAT(`date`,'%d-%m-%Y') as mydt from `actran` where `accode` = '$expense' AND date >= '$mfrmdate' AND date <= '$mtodate' $paytypecond")or die(mysqli_error($conn));



$getexp = mysqli_query($conn, "Select * from accmast where accode = '$expense' ")or die(mysqli_error($conn));

$fgetexp = mysqli_fetch_array($getexp);



$expname = $fgetexp['name'];







//$getno = mysqli_num_rows($getpmain);



include("includes/linkshead.php");

?>

<style type="text/css">

    #tabital{

        font-style: italic;

    }

    #font1{

        font-style: italic;

    }

    #bold{

        font-weight: bold; 

    }

    .colr{

        background: #26A69A;

        font-size: 17px;

        color:white;



    }



</style>

</head>

<body>

    <div class="container">

        <?php include("includes/head_rep.php"); ?>

        <div class="row">                

            <div class="col-lg-8 pad" style="margin-left:18%">

                <table class="table table-bordered table-condensed">

                    <tr class="mySearchTr">

                        <th style="width:6%" class="bold">Name</th>

                        <th style="width:10%" class="bold"><u><?= $expname ?></u></th>

                    <th style="width:10%" class="bold"> From Date</th>

                    <th style="width:8%" class="bold"><?= $mfdt ?></th> 

                    <th style="width:8%" class="bold">To Date</th> 

                    <th style="width:8%" class="bold"><?= $mtdt ?></th>

                    <th style="width:7%" class="bold">Amount</th>

                    <th style="width:11%" class="bold"><?= number_format($amount, 2); ?></th>

                    </tr>

                </table>

                <table style="background: white; width: 100%;" class="table table-bordered table-condensed table-hover">                        

                    <thead style="background-color: #FF91AE !important;">                            

                        <tr>                                

                            <th style="width:1%">Sr</th>

                            <th style="width:15%">Date</th>

                            <th style="width:15%">Pay Type</th>

                            <th style="width:5%">Voucher No.</th>

                            <th style="width:15%" class='text-right'>Amount</th>

                        </tr>         

                    </thead>              

                    <tbody> 

                        <?php

                        $ctr = 0;

                        $totamount = 0;



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

                            $source = $pmain['source'];

                            $payname = "";

                            if ($source == 'BP') {

                                $payname = "Bank";

                            } elseif ($source == 'CP') {

                                $payname = "Cash";

                            }



                            $ctr++;

                            $mydt = $pmain['mydt'];

                            $vouchno = $pmain['vouchno'];

                            $amt = abs($pmain['amount']);

                            $namt = number_format($amt,2);



                            Echo "<td>$ctr</td>";

                            Echo "<td>$mydt</td>";

                            Echo "<td>$payname</td>";

                            Echo "<td>$vouchno</td>";

                            Echo "<td class='text-right dth'>$namt</td>";

                            echo "</tr>";

                            $totamt = $totamt + $amt;

                        }

                        

                       $totnamt = number_format($totamt,2);     

                        Echo "<tr>";

                        Echo "<td colspan='3'></td>";

                        Echo "<td class='text-right'><b>Total</b></td>";

                        Echo "<td class='text-right'><b>$totnamt</b></td>";

                        Echo "</tr>";

                        ?>

                    </tbody>             

                </table>                

            </div>       

        </div>

    </div>

    <?php include("includes/linksfoot.php");

    ?>

</body>

</html>