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






$sql = " SELECT ord.order_id,ord.order_date,ord.order_total_price,ord.vorder_currency,
				usr.first_name,usr.last_name   
		  FROM ".$tableprefix."orders ord,".$tableprefix."users usr
		  WHERE ord.user_id = usr.user_id
		   AND  ord.vpayment_status IN('C','')";
		   
$sql = $sql.stripslashes($_GET['qstring']);		   
		   

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

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

		
		
<STYLE>
.PB { page-break-after: always }
</STYLE>
<?php /* 
<script language="javascript" type="text/javascript">
<!--
  var gAutoPrint = true; // Flag for whether or not to automatically call the print function

  //document.oncontextmenu=new Function("return false");
function printSpecial()
{
    var left = 100;
        var top = 100;
        if (document.getElementById != null)
        {
                var html = '<HTML>\n<HEAD>\n<link href=\"./style/style.css\" rel=\"stylesheet\" type=\"text/css\">\n';
						html += '<script>function printclick(){ document.getElementById("printing").style.display="none";window.print(); }</script>';
                if (document.getElementsByTagName != null)
                {
                        var headTags = document.getElementsByTagName("head");
                        if (headTags.length > 0)
                          ;//   html += headTags[0].innerHTML;
                }

                html += '\n</HEAD>\n<BODY>\n';
//                html +="<table><tr style=\"attachband\"><td  colspan=5 align=\"center\"><a  href=\"javascript:window.print();\">Print</a></td></tr></table>\n";

                var printReadyElem = document.getElementById("printReady");

                if (printReadyElem != null)
                {
                                html += printReadyElem.innerHTML;
                }
                else
                {
                        alert("Could not find the printReady section in the HTML");
                        return;
                }
                html +="<table align=\"center\"><tr style=\"listingmaintext\" id=\"printing\"><td  colspan=4 align=\"center\"><a href=\"javascript:printclick();\">Print</a></td><td  colspan=4 align=\"center\"><a href=\"javascript:window.close();\">Close</a></td></tr></table>\n";
                html += '\n</BODY>\n</HTML>';

                var printWin = window.open("","printSpecial","top=" + top + ",left=" + left + ",toolbars=no,maximize=yes,resize=no,width=850,height=650,location=no,directories=no,scrollbars=yes,border=thin,caption=no,titlebar=no");
                printWin.document.open();
                printWin.document.write(html);
                printWin.document.close();
               if (gAutoPrint)
                       printWin.print();
        }
        else
        {
                alert("Sorry, the print ready feature is only available in modern browsers.");
        }
}

   
-->
</script>*/?>



		<body onLoad="printSpecial();">
		
		<div id="printReady">
		
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
			<tr>
				<td colspan="3" align="center"><b><?php echo PRO_SALES_REPORT;?></b></td>
			</tr>
			<tr>
				<td colspan="3" align="center"><hr></td>
			</tr>
		</table>
		<br>
<?php

	$i = 1;
	
	$total_income = 0;
	
	if(mysql_num_rows($result) > 0 ) // start of first if loop
	{
	
		while($row = mysql_fetch_array($rs)) // start of first while loop
		{
		
?>		
			<div style="padding:5px; border:1px solid #CCCCCC; margin:5px 5px 10px 5px; ">
								
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
								
							
		<tr>
			<th width="20%" align="left"><?php echo ORDER_NUM;?></th>
			<th width="12%"><?php echo CUSTOMER;?></th>
			<th colspan="6"><?php echo ORDER_DATE;?></th>
		</tr>
							
<?php									
		
		
/*------selecting the product details-------*/		
	
			$select_product_details = "SELECT det.product_name,det.product_price,det.product_quantity,det.product_discount,det.artist_id,
											  det.order_id,SUM((det.product_price-(det.product_price * det.product_discount/100)) * det.product_quantity) as total,
											  art.artist_name,art.first_name,art.last_name
										FROM ".$tableprefix."order_details det,".$tableprefix."artists art,".$tableprefix."products prd
										WHERE det.order_id = ".$row["order_id"].
										" AND art.artist_id = prd.product_artist_id
										 AND prd.product_id = det.product_id  
										 GROUP BY det.product_id ";
										
			$result_product_details = mysql_query($select_product_details) or die(mysql_error());									 
																													
?>
								<tr>
									<td align="left">[<?php echo htmlentities($row["order_id"])?>]</td>
									<td align="center"><?php echo (stripslashes($row["first_name"]))?>&nbsp;<?php echo (stripslashes($row["last_name"]))?></td>
									<td align="center" colspan="6"><?php echo dateFormat($row["order_date"],"Y-m-d","m/d/Y")?></td>
								</tr>




<!--Product Details Section--->
					
												
							
								<tr>
									<td colspan="8">&nbsp;</td>
								</tr>
								
								<tr>
									<td colspan="8">
										<table cellpadding="0" cellspacing="0" width="100%" border="0">
										<tr>
											<td colspan="7" style="border-top:2px dotted #E9E9E9;">&nbsp;</td>
										</tr>
										<tr>
											<td colspan="7" ><b><?php echo PRO_DETAILS;?></b></td>
										</tr>
										<tr class="grey_tr">
											<td width="28%"><?php echo PRODUCT_NAME;?>&nbsp;/&nbsp;<?php echo SELLER;?></td>
											<td width="18%"><?php echo PRO_PRICE;?></td>
											<td width="17%"><?php echo PRO_QTY;?></td>
											<td width="13%"><?php echo PRO_DISCOUNT;?></td>
											<td width="7%">&nbsp;</td>
											<td width="3%">&nbsp;</td>
											<td width="14%" colspan="4"><?php echo TOT_AMT;?></td>
										</tr>
											
		  		
<?php	

					
			if(mysql_num_rows($result_product_details) > 0) // start of product if loop
			{
			
				$product_grant_total = 0;
			
				while($product_details_row = mysql_fetch_array($result_product_details)) // start of product while loop
				{
				
				
					$product_grant_total = $product_grant_total + $product_details_row['total'];
					
?>

												
												
												<tr>
													<td><?php echo $product_details_row['product_name']?>&nbsp;/&nbsp;<b>[<?php echo ucwords($product_details_row['artist_name'])?>]</b></td>
													<td align="center"><?php echo $product_details_row['product_price']?></td>
													<td align="center"><?php echo $product_details_row['product_quantity']?></td>
													<td align="center"><?php echo $product_details_row['product_discount']?>&nbsp;%</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td colspan="4"><?php echo $product_details_row['total']?></td>
												</tr>			
												<tr>
													<td colspan="8" style="border-bottom:2px dotted #E9E9E9;">&nbsp;</td>
												</tr>	
																				
					
<?php		

/* seller commission details starts--*/

					/*$select_seller_details = "SELECT art.first_name,art.last_name,ap.commission_percentage,ap.total_amount,ap.amount_paid
											  FROM ".$tableprefix."artists art,".$tableprefix."artist_payments ap
											   WHERE art.artist_id = ap.artist_id
												AND ap.order_id = ".$product_details_row["order_id"].
												" AND ap.artist_id = ".$product_details_row["artist_id"] ;*/
												
					$select_seller_details = "SELECT art.artist_name,art.first_name,art.last_name,ap.commission_percentage,ap.total_amount,ap.amount_paid
											  FROM ".$tableprefix."artists art,".$tableprefix."artist_payments ap
											   WHERE art.artist_id = ap.artist_id
												AND ap.order_id = ".$product_details_row["order_id"];
																								
					$result_seller_details = mysql_query($select_seller_details) or die(mysql_error());	
					$numrows = mysql_num_rows($result_seller_details);
				
	} // end of product if loop
	
} // end of product while loop	
	
				
?>					
					
<!--End of product table-->					
					
					<tr>
						<td colspan="7" style="border-top:2px dotted #E9E9E9;"></td>
					</tr>
					<tr>
						<td><b><?php echo PRO_TOTAL;?>&nbsp;:</b></td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td><font color="#FF0000"><?php echo $product_grant_total?></font>&nbsp;<b>USD</b></td>
					</tr>
					</table>
					</td>
					</tr>
					<tr>
						<td colspan="8">&nbsp;</td>
					</tr>
					
<!--End of product table-->				


					<tr>
					
					<td colspan="8">
												
<!--Seller Commission table starts-->				

<?php				
		
	if($numrows > 0) // start of seller if loop
	{
	
?>	

								<table cellpadding="0" cellspacing="0" width="100%" border="0">
									<tr>
										<td colspan="8"><b><?php echo COM_DETAILS;?></b></td>
									</tr>
									<tr class="grey_tr">
										<td width="20%"><?php echo SELLER_NAME;?></td>
										<td width="30%"><?php echo COM_PERCENT;?></td>
										
										<td width="33%"><?php echo TOT_AMT;?></td>
										<td colspan="3"><?php echo COMMISSION;?></td>
									</tr>				
				
<?php				
		
		while($seller_details_row = mysql_fetch_array($result_seller_details)) // start of seller while loop
		{
?>			
			
								<tr>
									<td><?php echo ucwords($seller_details_row["artist_name"])?></td>
									<td align="center"><?php echo $seller_details_row["commission_percentage"]?>&nbsp;%</td>
									<td><?php echo $seller_details_row["total_amount"]?></td>
									<td colspan="3" align="center"><?php echo ($seller_details_row["total_amount"] - $seller_details_row["amount_paid"])?></td>
								</tr>
								<tr>
									<td colspan="7">&nbsp;</td>
								</tr>
				
<?php

			$total_seller_commission = $total_seller_commission + ($seller_details_row["total_amount"] - $seller_details_row["amount_paid"]);
			$total_income += ($seller_details_row["total_amount"] - $seller_details_row["amount_paid"]);
						

		} // end commission while loop
		
	
?>							
				
								<tr>
									<td colspan="7" style="border-top:2px dotted #E9E9E9;"></td>
								</tr>
								<tr>
									<td><b><?php echo COMMISSION_TOTAL;?>&nbsp;:</b></td>
									<td>&nbsp;</td>
									<td>&nbsp;</td>
									<td width="17%" align="center"><font color="#FF0000"><?php echo $total_seller_commission?></font>&nbsp;<b>USD</b></td>
								</tr>
<!--								
								<tr>
									<td colspan="7">&nbsp;</td>
								</tr>
								<tr>
									<td><b>Total Income&nbsp;:</b></td>
									<td>&nbsp;</td>
									<td>&nbsp;</td>
									<td width="17%" align="center"><font color="#FF0000"><?php echo $total_income?></font>&nbsp;<b>USD</b></td>
								</tr>
-->								
								<tr>
									<td colspan="7" >&nbsp;</td>
								</tr>
				
<!--End of commission table-->					
					
					</table>
					</td>
					</tr>
					
<?php

		} // end commission if loop		
?>					
					
<!--End of commission table-->						
	
					
<?php					
					
					
/*--Shipping Details Section Starts--*/
			
			
				$select_shipping_details = "SELECT shipping.vshipping_name,shipping.nshipping_cost,shipping.nshipping_weight,
												   shipping.vshipping_currency,prd.product_name,cm.nexchange_price
											FROM ".$tableprefix."shipping_details shipping,".$tableprefix."products prd,
												 ".$tableprefix."currency_master cm	
											WHERE shipping.norder_id = ".$row["order_id"].
											" AND shipping.vshipping_currency = cm.vcurrency_code 
											 AND shipping.nshp_productid = prd.product_id";	
				$result_shipping_details = mysql_query($select_shipping_details) or die(mysql_error());							
			
				if(mysql_num_rows($result_shipping_details) > 0) // start of shipping if statement
				{
?>
					<tr>
									<td colspan="8" style="border-top:2px dotted #E9E9E9;">&nbsp;</td>
								</tr>
		
						<tr>
							<td colspan="8">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">
									<tr>
										<td colspan="3"><b><?php echo SHIPPING_DETAILS;?></b></td>
									</tr>
									<tr class="grey_tr">
										<td width="26%"><?php echo SHPNG_NAME;?>&nbsp;/&nbsp;<?php echo PRODUCT;?></td>
										<td width="60%"><?php echo SW;?></td>
										<td width="14%"><?php echo SHIPPING_COST;?></td>
									</tr>				
<?php					

					while($shipping_details_row = mysql_fetch_array($result_shipping_details))
					{ // start while shipping
		
?>					
					
									<tr>
											<td><?php echo ($shipping_details_row['vshipping_name'])?>&nbsp;/&nbsp;<b>[<?php echo ($shipping_details_row['product_name'])?>]</b></td>
											<td><?php echo htmlentities($shipping_details_row['nshipping_weight'])?>&nbsp;LBS</td>
											<td colspan="3"><?php echo htmlentities($shipping_details_row['nshipping_cost']/$shipping_details_row['nexchange_price'])?></td>
									 </tr>	
									 <tr>
										<td colspan="3">&nbsp;</td>
									</tr>
									 
<?php
					
					$total_ups_shipping_cost += $shipping_details_row['nshipping_cost'];
					
					$shipped_currency = $shipping_details_row['vshipping_currency'];
					
					} // end while shipping

?>									 
									 
								<tr>
										<td colspan="7" style="border-top:2px dotted #E9E9E9;"></td>
								</tr>
								<tr>
									<td><b><?php echo SHIPPING_TOTAL;?>&nbsp;:</b></td>
									<td>&nbsp;</td>
									<td width="12%"><font color="#FF0000"><?php echo $total_ups_shipping_cost?></font>&nbsp;<b><?php echo $shipped_currency?></b></td>
								</tr>
								<tr>
									<td colspan="7">&nbsp;</td>
								</tr>		 			
							
							 </table>
							</td>
						</tr>
					
<?php	
	

				} // end of shipping if statement
	
/*--Shipping Details Section Ends--*/			
						
						
$grand_total_amount = $product_grant_total + $total_seller_commission + $total_ups_shipping_cost		
						
						
?>

<!-- Details of one order ends-->

				
				<tr>
					<td colspan="8" style="border-top:2px dotted #E9E9E9;" >&nbsp;</td>
				</tr>
				<tr>
					<td><b><?php echo GRAND_OT;?>&nbsp;:</b></td>
					<td>&nbsp;</td>
					<td width="20%">&nbsp;</td>
					<td>&nbsp;</td>
					<td width="3%">&nbsp;</td>
					<td width="9%">&nbsp;</td>
					<td width="11%" align="right"><font color="#FF0000"><?php echo $grand_total_amount?></font>&nbsp;<b>USD</b></td>
					<td width="3%">&nbsp;</td>
				</tr>
<!--				
				
				<tr>
					<td colspan=""><b>Seller Commission&nbsp;:</b></td>
					<td>&nbsp;</td>
					<td width="23%">&nbsp;</td>
					<td>&nbsp;</td>
					<td width="1%">&nbsp;</td>
					<td width="2%">&nbsp;</td>
					<td width="5%" align="left"><?php //echo round($total_seller_commission,2)?></td>
					<td width="9%">&nbsp;</td>
				</tr>
				
				
				
				<tr>
					<td colspan="8"><hr></td>
				</tr>
				
-->				
				
	
				
				
				<tr>
					<td><b><?php echo NET_INCOME1;?>&nbsp;:</b></td>
					<td>&nbsp;</td>
					<td width="20%">&nbsp;</td>
					<td>&nbsp;</td>
					<td width="3%">&nbsp;</td>
					<td width="9%">&nbsp;</td>
					<td width="11%" align="right"><font color="#FF0000"><?php echo $total_income?></font>&nbsp;<b>USD</b></td>
					<td width="3%">&nbsp;</td>
				</tr>
				
			</table>	</div>
			
<?php

	
	
	
	} // end of first while loop
	
	
}	// end of first if loop

?>							
</div>


