<?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";
include_once('../api/pemfile/iphonepush.php');

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

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

if(isset($_GET["txtSearch"]) and $_GET["txtSearch"]!=""){
	$txtSearch = $_GET["txtSearch"];
	$cmbSearchType = $_GET["cmbSearchType"];
}else if(isset($_POST["txtSearch"]) and $_POST["txtSearch"]!=""){
	$txtSearch = $_POST["txtSearch"];
	$cmbSearchType = $_POST["cmbSearchType"];
}


if(isset($_GET["msg"]) and $_GET["msg"]!=""){
	$msg = $_GET["msg"];
	switch($msg){
		case "deleted": $message = FEEDBACK_DEL_SUCC."!";break;
		default:
			;
	} // switch
	
}

$chkorders = $_POST["chkorders"];

$orderlist = $_POST["orderlist"];
$artist = $_POST["artist"];
$artistcommission = $_POST["artistcommission"];
//print_r($chkorders);

if(isset($_POST["btnMakePayment"])){
	$message = "";
	if(!isNotNull($orderlist)){
		$message .= "* ".PLS_SEL_ORDERS."! <br>";
	}
	if(!isNotNull($artist)){
		$message .= "* ".ERROR_RETRY."! <br>";
	}
	//$ordersselected = true;
	$arrorders = explode(",",$orderlist );
       
	for($i=0;$i<count($arrorders);$i++){
		$orderid = $arrorders[$i];
		  $sql=" SELECT o.*, sum(od.product_commission_amount) as commission,sum(((od.product_price-(od.product_price*product_discount/100)) * od.product_quantity)+od.product_tax
		 	) as order_total_price,sum((od.product_price-(od.product_price*product_discount/100)) * od.product_quantity) as item_total,s.first_name,s.last_name,s.email
                        FROM ".$tableprefix."orders o 
			LEFT JOIN " . $tableprefix . "order_details od ON o.order_id = od.order_id  
                        LEFT JOIN " . $tableprefix . "shipping_details sd ON sd.nproduct_option_id = od.product_option_id AND sd.norder_id = od.order_id 
			LEFT JOIN " . $tableprefix . "artists s ON od.artist_id = s.artist_id 
			WHERE od.item_status = '4'
			AND od.artist_payment_status <= 1 AND (od.artist_id = '".addslashes($artist)."') AND (o.order_id = '".addslashes($orderid)."' )
			GROUP BY od.artist_id, o.order_id ";

            
		$res = mysql_query($sql);
		$rw4 = mysql_fetch_array($res);
		$total  = $rw4["item_total"];

		$ship_seller_amt = getSellerWiseShipping($artist,$rw4["order_id"]);
               
             
        $orderAmount = $rw4["order_total_price"] + $ship_seller_amt;
            
       if($rw4['vgiftcertificate_code']!='' && $rw4['nused_gift_amount']!=0 ){

            $giftDiscountAmount         =   $rw4['nused_gift_amount'];

            $orderAmount                =   $orderAmount - $giftDiscountAmount;

            //$itemTotal                  =   $itemTotal - $giftDiscountAmount;

        }
                $totalpaid = $orderAmount - $rw4["commission"] ;

                $sellerordertotal = number_format($orderAmount,2,".","");
              
                $adminCommissionamount = number_format($rw4["commission"],2,".","");
                $totalpaid = number_format($totalpaid,2,".","");
             
		//$commissiontaken = ($total * $artistcommission)/100;
		//$totalpaid = $total - $commissiontaken;
		 $sqlpayment = "INSERT INTO " . $tableprefix . "artist_payments
			(
			artist_id,
			order_id,
			commission_percentage,
			total_amount,
			amount_paid,
			date_marked_for_payment,
                        seller_order_total_amount,
                        admin_commision_amount
			)
			VALUES
			(
			'".addslashes($artist)."',
			'".addslashes($orderid)."',
			'".addslashes($artistcommission)."',
			'".addslashes($total)."',
			'".addslashes($totalpaid)."',
			now(),
                        '".$sellerordertotal."',
                         '".$adminCommissionamount."'
			) ";			
		//die($sqlpayment);
		mysql_query($sqlpayment);
		$paymentid = mysql_insert_id();
		$sql = "UPDATE " . $tableprefix . "order_details SET artist_payment_status = '3', artist_payment_id = '".addslashes($paymentid)."' WHERE order_id  = '".addslashes($orderid)."' AND artist_id = '".addslashes($artist)."'  ";
		mysql_query($sql);   
                
                //Send push notification to seller APP
                $devicesql = "Select device_id from " . $tableprefix . "artists where artist_id ='$artist'"; //Get seller device ID                      
                $result = mysql_query($devicesql);
                $device_row = mysql_fetch_assoc($result);
                $msg = "Payment settled for order number - '".$orderid."' at ".SITE_NAME. ", please check.";            
                send_push_nofication($msg,SITE_NAME,"armia",$device_row['device_id'],"Payment");//Message,From,passphrase,device token,type-->product,order...
                //-------------------------//
		
/********************** Send email to seller ****************************/
		
		$to = $rw4["email"];
		
		$subject = MAIL_SETTLE_PAYMENT_TO_SELLER_SUBJECT." ".stripslashes(SITE_NAME);
		
/*-------Email Template Reading Fuction Call--------*/				
		$adminCurrency	= GetAdminCurrency();
		$mailcontent = readEmailTemplate('settle_artist_payment');
				
		$mailcontent = str_replace('[amount]',  formatChar($adminCurrency['currency_symbol'])." " .$totalpaid,$mailcontent);					
		$mailcontent = str_replace('[site_name]',SITE_NAME,$mailcontent);			
		$mailcontent = str_replace('[seller_name]',$rw4["first_name"]." ".$rw4["last_name"],$mailcontent);	
		
		
/*---------------Seller Login Url-------------------*/		
		
		
//********************HEADERS*************************
$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Reply-To: ".SITE_NAME."<".SITE_EMAIL.">" . "\r\n";
$headers .= "Return-Path:  ".SITE_NAME."<noreply@".SITE_EMAIL.">" . "\r\n";
$headers .= "From: ".SITE_EMAIL."<".SITE_EMAIL.">" . "\r\n";
$headers .= "Organization: ".SITE_NAME."\r\n"; 
$headers .= "Content-Type: text/html;charset=utf-8\r\n"; 

//**************************************************** 
		
		$mailcontent = nl2br($mailcontent);
				
		
		$mail_send_details = '<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title >'.SITE_NAME.'</title>
  <link href="./themes/'. $active_template[4].' rel="stylesheet" type="text/css">
</head>
<body>

<table width="103%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA">
   <tr>
     <td align="center" valign="top">
         
         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td  bgcolor="#EAEAEA" > <img src='.SITE_URL.'/banners/'.getSettingsValue('site_logo').' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
            <tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left"><p>'.$mailcontent.'</p>
                  </td>
                </tr>
              </table></td>
            </tr>
            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>


</body>
</html>';
		
		$mailsent = mail($to, $subject, $mail_send_details, $headers);

		
		/********************** End sending email ********************************/
		
	}
	
	
}

//print_r($_POST);


if(isset($_POST["btnSettlePayments"])){


	$message = "";
	if(!isNotNull($chkorders)){
		$message .= "* ".PLS_SEL_ORDERS."! <br>";
	}        
	if(is_array($chkorders)){
		$artist= array();
		$orders =  array();
		for($i=0;$i<count($chkorders);$i++){
			$tmp = $chkorders[$i];
			$artmp = explode("`",$tmp );
			$artist[$i] = $artmp[1];
			$orders[$i] = $artmp[0];
		}
		$artist = array_unique(array_values($artist));
		if(count($artist) > 1){
			$message .= "* ".PLS_SEL_SINGLESELLER."! <br>";
		}else{
			$artist = $artist[0];
		}
		//echo "<BR>Orders/:<br>";
		//print_r($orders);
		$orders = array_unique(array_values($orders));
		$orderlist = implode("," ,$orders);
		
	}
	
	
	if($message != ""){
		$message = "<br>".MSG_CORRECT_THE_ERRORS."!<br>" . $message;
	}else{
		$ordersselected = true;
		$sql = "UPDATE " . $tableprefix . "order_details SET artist_payment_status = '1' WHERE order_id IN (".addslashes($orderlist).") AND artist_id = '".addslashes($artistid)."'  ";
		//echo $sql;
		//mysql_query($sql);
		/************** Send Email to seller ************/
		foreach($orders as $ord)
		{
			//fetch seller email
			//create template
			//send email
		}
		
	}
}

if(isset($_POST['gotoPage']))
{

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

$qryopt="";
if($txtSearch != ""){
   if($cmbSearchType == "username"){
   		$qryopt .= "  AND  u.user_name like '" . addslashes($txtSearch) . "%'";
   }else if($cmbSearchType == "dateordered"){
   		$dt = $txtSearch;
		$arrdt = explode("/",$dt) ;
		$day = $arrdt[1];
		$month = $arrdt[0];
		$year = $arrdt[2];
		$dt = $year."-". $month ."-".$day;
		$qryopt .= "  AND  o.order_date like '" . addslashes($dt) . "%'";
   }else if($cmbSearchType == "artistname"){
            $qryopt .= "  AND  s.artist_name like '" . addslashes($txtSearch) . "%'";
   }else if($cmbSearchType == "ordernumber"){
            $qryopt .= "  AND  o.order_id = '" . addslashes($txtSearch) . "'";
   }else if($cmbSearchType == "requested"){
   			if(strtoupper($txtSearch) == "Y"){
				$stat = 1;
			}else{
				$stat = 0;
			}
            $qryopt .= "  AND  od.artist_payment_status = '" . addslashes($stat) . "'";
   }
}

     $sql=" SELECT s.artist_name,od.artist_payment_status,od.artist_id,o.*, u.user_name, u.email,sum((od.product_price-(od.product_price*product_discount/100)) * od.product_quantity) as item_total, sum((od.product_price-(od.product_price*product_discount/100)) * od.product_quantity) as total,od.artist_payment_status,sum(od.product_commission_amount)as adminamount,sum(od.product_tax) as taxtotal 
		FROM ".$tableprefix."orders o 
		INNER JOIN " . $tableprefix . "users u ON o.user_id = u.user_id 
		INNER JOIN " . $tableprefix . "order_details od ON o.order_id = od.order_id 
                LEFT JOIN " . $tableprefix . "shipping_details sd ON sd.nproduct_option_id = od.product_option_id AND sd.norder_id = od.order_id 
		INNER JOIN " . $tableprefix . "artists s ON od.artist_id = s.artist_id 
		WHERE od.item_status = '4' AND od.artist_payment_status!=3
		" . $qryopt . " GROUP BY od.artist_id, o.order_id ORDER BY od.order_id   DESC";
	
		
	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	} 
	
	$limit = getSettingsValue('npagination_limit');
	
	$page = isset($_GET['page'])? trim($_GET['page']):1;

	
	$page = $_GET['page'];
	
	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";
?>
<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmPayments.submit();
}
function changeStatus(id){
	var frm = document.frmPayments;
	if(Confirm("<?php echo ARE_YOU_SURE;?>?")){
		document.frmPayments.submit();
	}
}

function confirmCheckbox()
{
    var haschecked=false;

    	//if($('.checkbox:checked').length>0)
        if($('input:checkbox:checked').length > 0)
	{
		haschecked=true;
	}
         if($('input:checkbox:checked').length > 1)
	{
                haschecked=true;
		alert("<?php echo SETTLE_ORDER;?>");
              return false;
	}
	if(haschecked==false)
        {
            alert("<?php echo SEL_AN_ORDER;?>");
            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 SETTLE_SELLER_PAY;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">			
					
<?php

if($ordersselected)
{
	  $sql= "SELECT s.artist_name,od.artist_id,o.*, u.user_name, u.email, sum(((od.product_price-(od.product_price*product_discount/100)) * od.product_quantity)+od.product_tax+sd.nshipping_cost) as totalamt,sum((od.product_price-(od.product_price*product_discount/100)) * od.product_quantity) as item_total,od.artist_payment_status,sum(od.product_commission_amount) as product_commission_amount,
                sum(od.product_tax)as producttax  FROM ".$tableprefix."orders o
           INNER JOIN " . $tableprefix . "users u ON o.user_id = u.user_id 
           INNER JOIN " . $tableprefix . "order_details od ON o.order_id = od.order_id 
           LEFT JOIN " . $tableprefix . "shipping_details sd ON (sd.nshp_productid =od.product_id  AND sd.nproduct_option_id = od.product_option_id AND sd.norder_id=od.order_id)                
           INNER JOIN " . $tableprefix . "artists s ON od.artist_id = s.artist_id 
		WHERE od.item_status = '4'
		  AND od.artist_payment_status <= 1 AND (od.artist_id = '".addslashes($artist)."') AND (o.order_id IN (".addslashes($orderlist)."))
             GROUP BY od.artist_id, o.order_id ORDER BY od.artist_id    ";
		
	$res = mysql_query($sql);
	
?>
																									
			
				<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="frmPayments">
				<input type="hidden" name="artist" value="<?php echo $artist; ?>" >
				<input type="hidden" name="orderlist" value="<?php echo $orderlist;?>" >

			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
				
			<tr align="center">
			
<?php
			$sqls = "SELECT artist_name, email, commission FROM " . $tableprefix . "artists WHERE artist_id = '".addslashes($artist)."' ";
			$res2= mysql_query($sqls);
			if(mysql_num_rows($res2)>0)
			{
				$rw2 = mysql_fetch_array($res2);
				$artistname = $rw2["artist_name"];
				$artistemail = 	$rw2["email"];
				$artistcommission = $rw2["commission"];
			}
?>
			<input type="hidden" name="artistcommission" value="<?php echo $artistcommission; ?>" >
			<tr><td align="left" colspan="2" ><?php echo SELLER_NAME;?>: </td><td colspan="3" align="left" class="innertextCopy2"><?php echo $artistname; ?></td></tr>
			<tr><td align="left" colspan="2" ><?php echo SELLER_EMAIL;?>: </td><td colspan="3"  align="left" class="innertextCopy2"><?php echo $artistemail; ?></td></tr>
			<tr><td align="left" colspan="2" ><?php echo SELLER_COMMISSION;?>: </td><td colspan="3"  align="left" class="innertextCopy2"><?php echo number_format($artistcommission,2,".","");?>&nbsp;%</td></tr>
			<tr align="center"><td align="center" colspan="5" class="infomessage">&nbsp;</td></tr>
			<tr>
                            <td colspan=5 width="100%">
					<table width="100%" border="0" cellpadding="4" cellspacing="0" class="manage_table">
                                            
                              <tr align="left"><td  colspan="8" class="specialmessage"><?php echo ORDER_TOTAL_NOTE;?></td></tr> 
                              <tr align="left"><td  colspan="8" class="specialmessage"><?php echo ADMIN_COMMISION_AMOUNT;?></td></tr> 
                              
                            <tr align="left"><td  colspan="8" class="specialmessage"><?php echo SELLER_COST_NOTE;?></td></tr>  
                            <tr align="left"><td  colspan="8" class="specialmessage">&nbsp;</td></tr>  

                                            
			<tr align="left" class="form_header">
				<th align="left"><?php echo ORDER;?> #</th>
                                <th align="left"><?php echo PRO_TOTAL;?></th>
                                <th align="left"><?php echo GIFT_CERTIFICATE_DISCOUNT;?></th>
                                <th align="left"><?php echo SHIPPING_TOTAL;?></th>
                                <th align="left"><?php echo TAX_TOTAL;?></th>
                                <th align="left"><?php echo ORDER_TOTAL;?></th>
				<th align="left"><?php echo COMMISSION_AMT;?>(<?php echo number_format($artistcommission,2,".","") ?>&nbsp;%)</th>
				<th align="left"><?php echo SELLER_AMOUNT;?> &nbsp;</th>
			</tr>
<?php
			
			$i = 1;
			$totalamount = 0;
			$totalcommission = 0;
			$totalaftercommission = 0;
                        $tota_tax       = 0;


			
			if(mysql_num_rows($result) > 0 )
			{
			
				while($row = mysql_fetch_array($res))
				{
					$link = "<a class=links href='vieworder.php?orderid=".$row["order_id"]."' target='_blank'>";
					$check = "<input type='checkbox' name='chkorders[]' value='".$row["order_id"]."`".$row["artist_id"]."' class='checkbox' > ";
					$amount = $row["taxrate"]+$row["totalamt"];
                                        $tota_tax = $row["producttax"];
					
					// added for including the shipping total
					$totalshippingcost = 0;
					
                             $select_shipping_cost = "SELECT sd.vshipping_name, sd.nshipping_cost,sd.nshp_productname
                             FROM ".$tableprefix."shipping_details sd
                             INNER JOIN ".$tableprefix."order_details  od ON (od.product_id=sd.nshp_productid AND od.product_option_id=sd.nproduct_option_id AND od.order_id=sd.norder_id)
                             WHERE sd.norder_id = ".$row['order_id']." AND od.artist_id = '".addslashes($row['artist_id'])."' AND  sd.nshp_status = 'C' order by sd.nshp_productname";

						
										$result_shipping_cost = mysql_query($select_shipping_cost);
										if(mysql_num_rows($result_shipping_cost) > 0)
										{
											$totalshippingcost = 0;
											while($shipping_row=mysql_fetch_array($result_shipping_cost))
											{
                                                                                                $totalshippingcost+=$shipping_row['nshipping_cost'];
												$amount+=$shipping_row['nshipping_cost'];
											}
										}
										
					$totalamount          += $amount;
					$totalamount_new      += $row["item_total"];
					$commission            = $row["product_commission_amount"];
					$totalcommission      += $commission;
					
                                        
                                       $orderTotalAmount          =    $row["totalamt"];
                                        
                                        $itemTotal                  =   $row["item_total"];

                                        $ship_seller_amt = getSellerWiseShipping($row["artist_id"],$row["order_id"]);
                                        
                                        $giftDiscountAmount         =   0;
                                        
                                         if($row['vgiftcertificate_code']!='' && $row['nused_gift_amount']!=0 ){
                                                    
                                                    $giftDiscountAmount         =   $row['nused_gift_amount'];
                                                    
                                                    $orderTotalAmount                 =   $orderTotalAmount - $giftDiscountAmount;
                                                    
                                                   $itemTotal                  =   $itemTotal - $giftDiscountAmount;
                                                    
                                                }
                                                $seller_order_total_amt = $itemTotal + $ship_seller_amt + $row['producttax'];
                                                
                                        $amountaftercommission = (($itemTotal - $commission) + $ship_seller_amt + $row['producttax']);
					$totalaftercommission += $amountaftercommission;
?>
																														
																														
																														
				<tr align="left">
					<td><?php  echo $link.htmlentities($row["order_id"])."</a>";?></td>
					<td><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($row["item_total"], 2, '.', ''));?>
                                        <td><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($giftDiscountAmount, 2, '.', ''));?>
                                        <td><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($ship_seller_amt, 2, '.', ''));?></td>
                                       <td><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($row['producttax'], 2, '.', ''));?></td>
                                       <td class=boxalternatecolor2><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo number_format($seller_order_total_amt, 2, '.', '');?></td>
			              <td><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($commission, 2, '.', ''));?></td>
                                      <td><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($amountaftercommission,2 ,".",""));?></td>
				</tr>
<?php
				$i++;
				
			}
			
		}		
		else
		{
										
?>					
			<tr>
					<td align="center" valign="middle" colspan="7"  class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
			</tr>					
<?php										

		}

?>
						
						<tr>
							<td colspan="7">&nbsp;</td>
						</tr>

                                                <tr>
							<td colspan="7">

                                                            <table width="100%" border="0" cellpadding="0" cellspacing="0" >

                                                                <tr>
                                                    <td align='left' class="" colspan=2><b>[<?php echo PRO_TOTAL;?>] <br><br> <?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo number_format($totalamount_new, 2, '.', '');?></b></td>
                                                    <td align="left" class="" colspan=2><b>[<?php echo COMMISSION_TOTAL;?>] <br><br> <?php echo $adminCurrency['currency_symbol'];?>&nbsp; <?php echo number_format($totalcommission, 2, '.', '');?></b></td>
                                                    <td align="left" colspan=3><b> [ <?php echo SELLER_AMOUNT_TOTAL;?>] <br><br><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo number_format($totalaftercommission, 2, '.', '');?></b></td></tr>
                                                            </table>

                                                        </td>
						</tr>
						
				  </table></td></tr>
						<tr class=""><td colspan=7 align="center">&nbsp;</td></tr>
						<tr><td colspan="7" align="center"><input type='submit' value='<?php echo MAKE_PAY;?>' name='btnMakePayment'  class="button">&nbsp;&nbsp;<input type="button" name="btnBack"  class="button" value="Back" onClick="history.go(-1)" > </td></tr>
						
					</table>
				</td>
			</tr>
		</table>
		
		</form>
<?php

}
else
{

?>
						
			<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="frmPayments">			
			
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
	<tr><td colspan="11" class="specialmessage"> <?php echo ORDER_TOTAL_SETTLE_NOTE ;?> </td></tr>
						
						<tr><td colspan="11" class="specialmessage"> <?php echo ADMIN_COMMISION_AMOUNT ;?> </td></tr>
						<tr><td colspan="11" class="specialmessage"> <?php echo SELLER_COST_SETTLE_NOTE ;?> </td></tr>

			<tr>
				<td>
					<table width="100%"  border="0" cellpadding="2" cellspacing="1" class="maintext">
					<tr class="" valign="top">
					<td align="right" colspan="7" valign="top" >
						<table width="100%" border="0">
						 <tr>
							
								<td width="100%" align=left valign="top" class=''><?php echo SEARCH;?> ::
									<select name="cmbSearchType" class="textarea">
										<option value="artistname"  <?php if(($cmbSearchType == "artistname") || ($cmbSearchType == "")){ echo("selected"); } ?>><?php echo SELLER;?></option>
										<option value="username"  <?php if($cmbSearchType == "username" ){ echo("selected"); } ?>><?php echo USER_NAME;?></option>
										<option value="ordernumber"  <?php if($cmbSearchType == "ordernumber" ){ echo("selected"); } ?>><?php echo ORDER;?> #</option>
										<option value="requested"  <?php if($cmbSearchType == "requested" ){ echo("selected"); } ?>><?php echo REQUESTED;?></option>
										<option value="dateordered"  <?php if($cmbSearchType == "dateordered"){ echo("selected"); } ?>><?php echo ORDER_DATE;?>(mm/dd/yyyy)</option>
									</select> &nbsp;
									<input type="text" name="txtSearch" size="20" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>"  onKeyPress="if(window.event.keyCode == '13'){ return false; }" class="textarea">
									
									<a href="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>&nbsp;
						   </td>
						  </tr>
						</table>
					
					</td>
				</tr>
				<tr>
					<td colspan="5">
						<table border="0" width="100%" cellpadding="0" cellspacing="0" class='manage_table'>

						<tr class="form_header">
							<th width="2%" align="left">#</th>
							<th width="4%" align="left">&nbsp;</th>
							<th width="10%" align="left"><?php echo SELLER_NAME;?></th>
							<th width="7%" align="left"><?php echo ORDER;?> #</th>
							<th width="11%" align="left"><?php echo USER_NAME;?></th>
							<th width="20%" align="left"><?php echo DATE_ADDED;?>(<?php echo MM."-".DD."-".YYYY;?>)</th>
							<th width="12%" align="left"><?php echo SELLER_ORDER_TOTAL;?> </th>
                                                        <th width="20%" align="left"><?php echo ADMIN_AMOUNT;?> </th>
							<th width="22%" align="left"><?php echo AMOUNT_RECEIVABLE;?></th>
							<th width="10%" align="left"><?php echo REQUESTED;?>?</th>
						</tr>
<?php
				
				if(mysql_num_rows($rs) > 0)
				{
				
					$i = 1;
					$seller_order_total_amt = 0;
					$orderTotal = 0;
					while($row = mysql_fetch_array($rs))
					{ //echo "<pre>";print_r($row);exit;
						$link = "<a class=links href='vieworder.php?orderid=".$row["order_id"]."' target='_blank'>";
						$check = "<input type='checkbox' class='' name='chkorders[]' value='" . $row["order_id"]."`".$row["artist_id"] . "' > ";
						$requested = ($row["artist_payment_status"] == 1 ? YES : NO1);
                                                
                                                //$orderTotal     =  $row["total"]; changed on Version 2.6
                                                $orderTotal     =  $row["namount_paid"]; 
                                                //echo "<br>ordertotal---".$orderTotal."Gift Amount----".$row['nused_gift_amount'];

                                                $seller_item_total = $row["item_total"]; 

                                                $tax_amt			= $row['taxtotal'];

                                                $ship_seller_amt = getSellerWiseShipping($row["artist_id"],$row["order_id"]);

                                                $seller_order_total_amt = $seller_item_total + $tax_amt + $ship_seller_amt;

                                                
                                                if($row['vgiftcertificate_code']!='' && $row['nused_gift_amount']!=0 ){
                                                    
                                                    $giftDiscountAmount         =   $row['nused_gift_amount'];
                                                    
                                                    //$orderTotal                 =   $orderTotal - $giftDiscountAmount;
                                                    
                                                }
						
						//$totalAmt=$orderTotal+$row["total"];
						// added for including the shipping total
						/*$totalshippingcost = 0;
						$select_shipping_cost = "SELECT sd.vshipping_name, sd.nshipping_cost,od.product_name
												   FROM ".$tableprefix."shipping_details sd,".$tableprefix."order_details  od
												  WHERE od.product_id=sd.nshp_productid
													AND norder_id = ".$row['order_id']."
													AND nshp_status = 'C'
													AND od.artist_id = '".addslashes($row['artist_id'])."'
											   GROUP BY sd.nshp_productid order by  od.product_name";
						
										$result_shipping_cost = mysql_query($select_shipping_cost);
										if(mysql_num_rows($result_shipping_cost) > 0)
										{
											$totalshippingcost = 0;
											while($shipping_row=mysql_fetch_array($result_shipping_cost))
											{
												$totalAmt+=$shipping_row['nshipping_cost'];
											}
										}*/
										
							$adminAmount    =   $row['adminamount'];
                                                        
                                                        $amountReceivable   =   $seller_order_total_amt - $adminAmount;
                                                                                

?>
				<tr> 
					<td><?php echo (($page*$limit)+$i-$limit)?></td>
					<td><?php echo $check;?></td>
					<td><?php echo ($row["artist_name"]);?></td>
					<td><?php echo $link .htmlentities($row["order_id"])."</a>";?></td>
					<td><?php echo ($row["user_name"]);?></td>
					<td><?php echo dateFormat($row["order_date"], "Y-m-d", "m/d/Y");?></td>
					<td align="center"><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($seller_order_total_amt,2,".",""));?></td>
                                        <td align="center"><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($adminAmount,2,".",""));?></td>
                                        <td><?php echo $adminCurrency['currency_symbol'];?>&nbsp;<?php echo htmlentities(number_format($amountReceivable,2,".",""));?></td>
					<td><?php echo ($requested);?></td>
				</tr>
<?php
					$i++;
					}
				}
				else
				{	
?>
				
				<tr>
					<td colspan="9" align="center" class="text_information"><?php echo NO_RECORDS_FOUND;?>!!</td>
				</tr>	
				
				
<?php
				}

?>				
				</table>
				</td>
				</tr>
				<tr>
					<td colspan="7" align="center">
<?php 
				if(isNotNull($check))
				{
						
?>
                                            <input type="submit" name="btnSettlePayments" value="<?php echo SETTLE_PAY;?>" class="button" onclick="return confirmCheckbox();">
<?php					
				}
?>
						&nbsp;&nbsp;<input type="button" class="button" name="btnBack" value="<?php echo BACK;?>" onClick="history.go(-1)" > 
					</td>
				</tr>
				</table>
				</td>
				</tr>
				</table>
				
				</form>				
				
				
				<form action="#" method="post" name="frmPayments1">
				
				<table cellpadding="0" cellspacing="0" width="100%">
								
				

				
								
<?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>";
		
	}	



?>

								
					 <?php
							  if($numofpages)
							  {
							  ?><tr>
						<td  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."(".S.")";?> <?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.frmPayments1.submit();" class="go_button_2"><?php echo GO; ?></a>
									</td>
									<td width="41%" align="center"><?php echo $next?></td>
								</tr>
							</table>
							</td>
						</tr><?php
				  }
				  ?>
									</table>
									
					  </form>
<?php
}

?>			
		
				</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>
				
				
<?php
	include "../includes/footer.php";
?>