<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= "") {
    $adminname = $_SESSION["sess_adminname"];
}else {
    header("Location:login.php");
    exit;
}

if(isset($_POST['gotoPage'])) {
    header("Location:".$_SERVER['PHP_SELF']."?page=".$_POST['gotoPage']);
}

if(isset($_POST['btnSubmit'])) {
    $from_date 	= dateFormat($_POST['txtFromDate'],"d-m-Y","Y-m-d");
    $to_date 	= dateFormat($_POST['txtToDate'],"d-m-Y","Y-m-d");
    $query_string = "AND date_marked_for_payment >= ".GetSQLValueString($from_date,"text").
            " AND date_marked_for_payment <= ".GetSQLValueString($to_date,"text").
            " GROUP BY order_id ORDER BY date_marked_for_payment ";
}
else if(isset($_POST['btnSubmitSeller']) && $_POST['sellerName']!="all") {
    $query_string = " AND pay.artist_id = ".$_POST['sellerName'];
}
else {
    $query_string = "";
}

 $sql = " SELECT pay.*,art.first_name,art.last_name   
		  FROM ".$tableprefix."artist_payments pay,".$tableprefix."artists art
		  WHERE pay.artist_id = art.artist_id "; 



if(!(isset($pagenum))) {
    $pagenum = 1;
} 

$limit = getSettingsValue('npagination_limit');

$page = isset($_GET['page'])? trim($_GET['page']):1;


if(empty($page)) {
    $page = 1;
}

$result = mysql_query($sql) or die(mysql_error());						

$totalrows = mysql_num_rows($result);

$limitvalue = ($page - 1) * $limit;

$query_string .= " LIMIT $limitvalue, $limit";

$sql = $sql.$query_string;

$rs = mysql_query($sql) or die(mysql_error());

$numofpages = ceil($totalrows / $limit);


include "../includes/htmltop.php";
?>
<body topmargin="0">
    <script src="../js/calendar1.js"></script>
    <script>
        function checkCommissionForm()
        {

            var form_name = new Array('txtFromDate','txtToDate');
            var display_name = new Array('<?php echo FDATE;?>','<?php echo TDATE;?>');
            var count = 2;

            if(check_fields('frmSellerCommission',form_name,display_name,count))
            {


                smonth = document.frmSellerCommission.txtFromDate.value;
                emonth = document.frmSellerCommission.txtToDate.value;
                flagdate = compareDates(smonth,emonth);

                if(flagdate == 1)
                {

                    alert("<?php echo TO_GT_FROM;?>");
                    return false;

                }
                else
                {

                    return true;


                }


            }
            else
            {

                return false;

            }

        }
    </script>

<body>
    <center>

        <div align="left" id="layout">




            <!--header area start -->
            <?php

            include_once("../includes/topheader_admin.php")

                    ?>

            <!--header area end -->




            <div align="left" class="main_body">
                <!--main body start -->



                <?php
                include_once("../includes/admintopmenu.php")
                        ?>


                <div align="left" class="content_area">

                    <!--content area start -->

                    <div align="left" class="page_title"><?php echo COMM_REPORT;?></div>
                    <div align="center" class="text_information"><?php echo $message?></div>

                    <div align="left">
                        <table><tr><td height="35"><?php include_once("../includes/reportmenu.php")?></td>	</tr></table>
                        <form name="frmSellerCommission" method="post" onSubmit="return checkCommissionForm();">

                            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td colspan="5">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td width="10%" valign="top">&nbsp;<?php echo FDATE;?></td>
                                    <td width="32%" valign="top">
                                        <input type="text" name="txtFromDate" value="<?php echo $_REQUEST['txtFromDate']; ?>" class="textarea" readonly="readonly">
                                        <a href="javascript:cal1.popup();"><img src="../images/cal.gif" width="16" height="16" border="0" Title="Click Here to Pick up From Date"></a>
                                    </td>
                                    <td width="7%" valign="top"><?php echo TDATE;?></td>
                                    <td width="28%" valign="top">
                                        <input type="text" name="txtToDate" value="<?php echo $_REQUEST['txtToDate']; ?>" class="textarea" readonly="readonly">
                                        <a href="javascript:cal2.popup();"><img src="../images/cal.gif" width="16" height="16" border="0" Title="Click Here to Pick up To Date"></a>
                                    </td>
                                    <td width="23%" align="left"><input type="submit" name="btnSubmit" value="<?php echo BTN_GET_REPORT;?>" class="button"></td>
                                </tr>
                            </table>

                        </form>

                        <form name="frmCommissionBySeller" method="post">

                            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td colspan="5">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td width="12%" valign="top">&nbsp;<?php echo SELLER_NAME;?></td>
                                    <td width="17%" valign="top">
                                        <select class="textarea2" name="sellerName">
                                            <option value="all"><?php echo ALL_SELLERS;?></option>

                                            <?php

                                            $select_seller = "SELECT artist_id,first_name,last_name FROM ".$tableprefix."artists WHERE 1";
                                            $result_seller = mysql_query($select_seller);

                                            if(mysql_num_rows($result_seller) > 0) {

                                                while($artist_row = mysql_fetch_array($result_seller)) {

                                                    if($_POST['sellerName'] == $artist_row['artist_id']) {
                                                        $artist_selected = " selected";
                                                    }
                                                    else {
                                                        $artist_selected = "";
                                                    }



                                                    ?>
                                            <option value="<?php echo $artist_row['artist_id']?>" <?php echo $artist_selected?>><?php echo $artist_row['first_name']."&nbsp;".$artist_row['last_name']?></option>
                                                    <?php

                                                }
                                            }
                                            ?>

                                        </select>

                                    </td>

                                    <td width="71%" align="left">
                                        <input type="submit" class="button" name="btnSubmitSeller" value="<?php echo BTN_GET_REPORT;?>">
                                    </td>
                                </tr>
                            </table>

                        </form>


                        <br>
                        <form name="frmCommissionBySeller1" id="frmCommissionBySeller1" method="post">

                            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
                                <tr class="form_header">
                                    <th width="10%"><?php echo ORDER_ID;?></th>
                                    <th width="12%"><?php echo SELLER_NAME;?></th>
                                    <th colspan="4" width="10%"><?php echo ADMIN_COMMISSION;?> (%)</th>
                                    <th width="20%"><?php echo SELLER_OREDR_TOT_AMT;?></th>
                                    <th width="20%"><?php echo AMT_PAID_SELLER;?> </th>
                                    <th width="18%"><?php echo ADMIN_COMM_AMT;?> </th>


                                </tr>
                                <?php

                                if(mysql_num_rows($rs) > 0 ) {

                                    $admin_commision_amount=0;

                                    while($row = mysql_fetch_array($rs)) {

                                              $admin_commision_amount+=$row["admin_commision_amount"]
                                        ?>

                                <tr>
                                    <td align="left">[<?php echo htmlentities($row["order_id"])?>]</td>
                                    <td align="left"><?php echo (stripslashes($row["first_name"]))?>&nbsp;<?php echo (stripslashes($row["last_name"]))?></td>
                                    <td align="left" colspan="4"><?php echo $row["commission_percentage"]?></td>
                                    <td align="left"><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo number_format($row["seller_order_total_amount"], 2, '.', '')?></td>
                                    <td align="left"><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo number_format(round($row["amount_paid"],3),2,".",",")?></td>
                                    <td align="left"><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo number_format(round($row["admin_commision_amount"],3),2,".",",")?></td>
                                </tr>

                                <tr>
                                    <td colspan="10">&nbsp;</td>
                                </tr>

                                        <?php

                                    }

                              ?>
                              <tr>
                                    <td colspan="10"><hr></td>
                                </tr>

                                 <tr>
                                     <td colspan="10" class="amount_clrs" align="right"> <h3><?php echo NET_INCOME_ADMIN;?> : &nbsp;&nbsp; <?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo number_format(round($admin_commision_amount,3),2,".",",")?> </h3></td>
                                </tr>

                                <?php 

                                }
                                else {


                                    ?>





                                <tr>
                                    <td class="text_information" colspan="8" align="center"><?php echo NO_REC_FOUND;?></td>
                                </tr>


                                    <?php
                                }




                                if($page > 1) {
                                    $pageprev = $page-1;

                                    $previous_page = "<a href=".$_SERVER['PHP_SELF']."?page=$pageprev alt='Previous' border='0' class='small_gray_button'>".TEXT_PREV."</a>";

                                }


                                if($page < $numofpages) {
                                    $pagenext = ($page + 1);

                                    $next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_NEXT."</a>";

                                }
                                if($page < $numofpages || $page > 1) {

                                    ?>
                                <tr>
                                    <td colspan="11" align="center">
									
									<table width="100%" border="0" cellspacing="10" cellpadding="0">
										<tr align="left" valign="middle">
											<td width="21%" align="right"><?php echo $previous_page?></td>
											<td width="23%" align="right">
												<?php echo PAGE_TEXT;?> <?php echo $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;
												<?php echo GO_TO;?>
											</td>
											<td width="8%" align="right">
												<select class="textarea2" name="gotoPage" style="padding:4px 5px; margin-bottom:1px;">
													<?php
													for($i=1;$i<=$numofpages;$i++) {
													if($i == $_GET['page']) {
													$page_selected = "selected";
													}
													else {
													$page_selected = "";
													}
													?>
													<option value="<?php echo $i?>" <?php echo $page_selected?>><?php echo $i?></option>
													<?php
													}
													?>
												</select>
											</td>
											<td width="7%">
												<a onClick="Javascript:document.frmCommissionBySeller1.submit();" class="go_button_2"><?php echo GO; ?></a>
											</td>
											<td width="41%" align="center"><?php echo $next?></td>
										</tr>
									</table>
								  </td>
                                </tr>
                                    <?php
                                }
                                ?>
                                <tr>
                                    <td colspan="8" align="center"><input type="button" class="button" name="back" value="<?php echo BACK;?>" onClick="Javascript:history.go(-1)"></td>
                                </tr>
                            </table>

                        </form>

                    </div>


                    <!--content area end-->

                </div>


                <div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
                <!--main body end -->
            </div>





            <script>
                var cal1 = new calendar1(document.forms['frmSellerCommission'].elements['txtFromDate']);
                cal1.year_scroll = true;
                cal1.time_comp = false;

                var cal2 = new calendar1(document.forms['frmSellerCommission'].elements['txtToDate']);
                cal2.year_scroll = true;
                cal2.time_comp = false;
            </script>
            <?php

            include "../includes/footer.php";
            ?>




