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

$formname = "Agents Position";
$file = "agentposn_fr.php";
$grid = "";
$zroot = $_SESSION["zdbroot"];

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];

mysqli_select_db($conn, $zdb);

$seriescond = "";

include("includes/linkshead.php");
include("includes/searchrow.php");

?>
<link href="MyStyle/rep_format.css" type="text/css" >
<style type="text/css">
    #tabital{
        font-style: italic;
    }
    #font1{
        font-style: italic;
    }
    #boldfont{
        font-weight: bold; 
    }
    .mtotclr{
        color:#0098DA;
    }
    .ttotclr{
        color:#ed3237;
    }
    .getdtl{
        font-size: 14px;
    }


    /* CSS */
    .button-1 {
        position: relative;
        border: none;
        background: transparent;
        padding: 0;
        cursor: pointer;
        outline-offset: 4px;
        transition: filter 250ms;
        user-select: none;
        -webkit-user-select: none;
        touch-action: manipulation;
    }

    .button-1-shadow {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 12px;
        background: hsl(0deg 0% 0% / 0.25);
        will-change: transform;
        transform: translateY(2px);
        transition:
            transform
            600ms
            cubic-bezier(.3, .7, .4, 1);
    }

    .button-1-edge {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 12px;
        background: linear-gradient(
            to left,
            hsl(340deg 100% 16%) 0%,
            hsl(340deg 100% 32%) 8%,
            hsl(340deg 100% 32%) 92%,
            hsl(340deg 100% 16%) 100%
            );
    }

    .button-1-front {
        display: block;
        position: relative;
        padding: 12px 27px;
        border-radius: 12px;
        font-size: 15px;
        font-weight: bold;
        color: white;
        background: grey;
        will-change: transform;
        transform: translateY(-4px);
        transition:
            transform
            600ms
            cubic-bezier(.3, .7, .4, 1);
    }

    @media (min-width: 768px) {
        .button-1-front {
            font-size: 25px;
            padding: 6px 23px;
        }
    }

    .button-1:hover {
        filter: brightness(110%);
        -webkit-filter: brightness(110%);
    }

    .button-1:hover .button-1-front {
        transform: translateY(-6px);
        transition:
            transform
            250ms
            cubic-bezier(.3, .7, .4, 1.5);
    }

</style>

</head>
<body>
    <div class="container">
        <div class="row" style="padding-top:1%">
            <div class="col-lg-2 col-md-1 col-sm-2 col-xs-2 pad text-center" >
                <a href="agent.php?mode=true" class="form-control button-1 button-1-front button-1-shadow button-1-edge">Add New</a>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">

                <table class="table1 table-bordered myTable" style="width:100%">
                    <thead class="mySearchTr">
                        <tr>
                            <center>
                                <h3 style="background-color:#963634;color:whitesmoke;border: 1px solid black;">
                                    AGENTS POSITIONS
                                </h3> 
                            </center>
                        </tr>
                        <tr style="height:30px">
                            <th style="color:black;width:20%" colspan="2"><b>Agent</b></th>
                            <th style="color:black;width:9%" class="text-right"><b>RMB</b></th>
                            <th style="color:black;width:5%" class="text-center"><b>View</b></th>
                        </tr>
                    </thead>
                        <tr class='filters noPrint'style="height:30px">
                            <th style="width:20%;" class="filter-container" colspan="2"><input type ="text"  class="filter" name="agent" placeholder="Agent" data-col="agent"></th>
                            <th style="width:9%;"  class="filter-container"><input type ="text"  class="filter text-right" name="rmb" placeholder="RMB" data-col="rmb"></th>
                            <th style="width:5%;"  class="filter-container"></th>
                        </tr>
                    <tbody>
                        <?php
                        $getdata = mysqli_query($conn, "Select * from accmast where grpcode = '044'") or die(mysqli_error($conn));


                        while ($pmain = mysqli_fetch_array($getdata)) {
                            $maccode = $pmain['accode'];
                            $mopbal = $pmain['openbal'];
                            $mdc = $pmain['dc'];
                            $mopenfe = $pmain['openfe'];
                            $mdcfe = $pmain['dcfe'];
                            if ($mdc == "D") {
                                $opbal = $mopbal * -1;
                            } else {
                                $opbal = $mopbal;
                            }
                            if ($mdcfe == "D") {
                                $opbalfe = $mopenfe * -1;
                            } else {
                                $opbalfe = $mopenfe;
                            }


                            $getdep = mysqli_query($conn, "SELECT sum(amount) as tamt, sum(feamt) as tfeamt FROM `actran` where accode = '$maccode'") or die(mysqli_error($conn));
                            $fetdep = mysqli_fetch_array($getdep);

                            $abalamt = $fetdep['tamt'];
                            $abalfe = $fetdep['tfeamt'];

                            $balamt = $opbal + $abalamt;
                            $balamtfe = $opbalfe + $abalfe;
                            $tbal = $balamt + $balamtfe;
                            
                            if ($balamtfe != 0) {
                                $balamtfe = $balamtfe * -1 ;
                            } else {
                                $balamtfe = abs($balamtfe) ;
                            }

                            $file = "agent.php?accode=$maccode&mode=edit";

                            Echo"<tr class='getdtl' style='height:30px;'  >";
                            Echo"<td colspan='2' style ='font-size:13px;font-weight:bold'><a href='agentdet_fr.php?accode=$maccode' target='_blank'>$pmain[name]</a></td>";
                            Echo"<td class='getdtl text-right'>$balamtfe</td>";
                            Echo"<td align='center'><a href='$file' target='_blank'><i class='fa fa-1x fa-desktop'></i></a></td>";
                            Echo"</tr>";

                            $totbalamtfe = $totbalamtfe + $balamtfe;
                        }

                        Echo"<tr class='getdtl' style='height:30px;background-color:#c1c1c1'>";
                        Echo"<td colspan='2' class='getdtl text-right'><b>Total</b></td>";
                        Echo"<td class='getdtl text-right'><b>$totbalamtfe</b></td>";
                        Echo"<td align='center'></td>";
                        Echo"</tr>";
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Name</option>
                                <option value="2">Address</option>
                                <option value="3">City</option>
                                <option value="4">Pin</option>
                                <option value="5">Telephone</option>

                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Name</option>
                                <option value="2">Address</option>
                                <option value="3">City</option>
                                <option value="4">Pin</option>
                                <option value="5">Telephone</option>

                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs">
                                <option value="asc">Asc</option>
                                <option value="desc">Desc</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                        </div>
                        <div class="col-lg-2">
                            <input type="button" class="btn btn-primary sload" value="Search">
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                        <!--<img src="images/search.gif" alt="loading">-->
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th width="20%">Name</th>
                                    <th width="30%">Address</th>
                                    <th width="13%">City</th>
                                    <th width="12%">Pin</th>
                                    <th width="10%">Telephone</th>
                                    <th width="10%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button" class="btn btn-primary sprev" value="Previous">
                            <input type="button" class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php");
    ?>
</body>
</html>