<?php

/* FIRESHOP: Advanced Content Market System                         */

/* ============================================                         */

/*                                                                      */

/* Copyright (c) 2012 by Mohamad Porhaji                                */

/* http://Firedesign.ir                                                   */

/*                                                                      */

/* This program is free software.  */

/************************************************************************/

/* $Id: invoice.php,v 1.0.0.1 2012/02/18 By Mohamad Porhaji $ */
require_once("mainfile.php");
global $db;
if(isset($_POST['view_invoice'])){
$id=$_POST['id'];

$datasql = $db->sql_query("SELECT * FROM fireshop_order WHERE  id='$id'") or die(mysql_error());
$mydata = $db->sql_fetchrow($datasql);
$id  	= $mydata['id'];
$ip 	= $mydata['ip'];
$date  	= $mydata['date'];
$subtotal=  number_format($mydata['subtotal'], 0);
$total_price_send= number_format($mydata['total_price_send'], 0);
$total_price_send_r =$mydata['total_price_send'];
$name= $mydata['name'];
$kar_tel= $mydata['kar_tel'];
$home_tel= $mydata['home_tel'];
$mobile= $mydata['mobile'];
$email= $mydata['email'];
$ostan_id= $mydata['ostan_id'];
$code_post= $mydata['code_post'];
$adress= $mydata['adress'];
$des= $mydata['des'];
$pay_id= $mydata['pay_id'];
$status= $mydata['status'];

$is_payed= $mydata['is_payed'];
$payway_id= $mydata['payway'];
$sendway_id= $mydata['sendway'];

$datasql = $db->sql_query("SELECT * FROM fireshop_zone WHERE `id`='$ostan_id'") or die(mysql_error());
$mydata = $db->sql_fetchrow($datasql);
$ostan_title= $mydata['title'];

$datasql = $db->sql_query("SELECT * FROM fireshop_sendway WHERE `id`='$sendway_id'") or die(mysql_error());
$mydata = $db->sql_fetchrow($datasql);

$sendway_title= $mydata['title'];
$maliyat = number_format($mydata['maliyat'], 0);
$hazine= number_format($mydata['hazine'], 0);

$datasql = $db->sql_query("SELECT * FROM fireshop_payway WHERE `id`='$payway_id'") or die(mysql_error());
$mydata = $db->sql_fetchrow($datasql);
$payway_title= $mydata['title'];

$sql = $db->sql_query("SELECT * FROM fireshop_general where id='1'");
$row = $db->sql_fetchrow($sql);
$site_title=$row['site_title'];
$site_url = $row['site_url'];
$tel  = $row['tel'];
$adress   = $row['adress'];

if($status==NULL){$status="انتظار";}else{$status=$status;}

if($kar_tel==NULL){$kar_tel="ندارد";}else{$kar_tel=$kar_tel;}
if($email==NULL){$email="ندارد";}else{$email=$email;}
if($des==NULL){$des="ندارد";}else{$des=$des;}

echo"

<link href=\"template/fireshop_default/style/invoice.css\" rel=\"stylesheet\" type=\"text/css\" >
<body dir='rtl'>
<table  id='wrapper' cellspacing='1' cellpadding='10' bgcolor='#cccccc' align='center'><tr><td bgcolor='#ffffff'>

<table width='100%'><tr>
<td width='50%' align='right'>";
if(@$_SESSION['LogedIn_fireshop_ADMIN'] == true)
{
echo"
رسيد فروشنده
";
}else{
echo"
رسيد مشتري 
";
}

echo"<br/>
<p><strong>شماره سفارش : $id</strong><br />
تاريخ ثبت سفارش :  $date<br /></p>

</td>
<td width='50%' align='dight'>

<font class='paid'>";
if(@$_SESSION['LogedIn_fireshop_ADMIN'] == true)
{echo"
وضعيت : $status";
}else{


echo"
$site_title";
}

echo"</font><br />
نحوه پرداخت : $payway_title <br />
</td></tr></table>

<br />


<table width='100%' id='invoicetoptables' cellspacing='0'><tr>
<td width='50%' id='invoicecontent' style='border:1px solid #cccccc;border-left:0px;'>

<table width='100%'  cellspacing='0' cellpadding='10' id='invoicetoptables'><tr><td id='invoicecontent' valign='top' style='border:1px solid #cccccc'>

<strong>مشخصات مشتري</strong><br />
نام و نام خانوادگي : $name<br />
تلفن محل كار : $kar_tel | 
تلفن منزل : $home_tel | 
تلفن همراه : $mobile | ايميل : $email<br />
استان : $ostan_title | كد پستي : $code_post <br />
آدرس پستي : $adress <br />
توضيحات داده شده توسط مشتري : $des <br/>
</td></tr></table>

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

<table cellspacing='0' id='invoiceitemstable' align='center'><tr><td id='invoiceitemsheading' align='center' width='60%' style='border:1px solid #cccccc;border-bottom:0px;'><strong>عنوان كالا</strong></td>
<td id='invoiceitemsheading' align='center' width='15%' style='border:1px solid #cccccc;border-bottom:0px;'><strong>قيمت جزء</strong></td>
<td id='invoiceitemsheading' align='center' width='5%' style='border:1px solid #cccccc;border-bottom:0px;'><strong>تعداد</strong></td>
<td id='invoiceitemsheading' align='center' width='20%' style='border:1px solid #cccccc;border-left:0px;border-bottom:0px;'><strong>مبلغ</strong></td></tr>";





$query = $db->sql_query("SELECT * FROM `fireshop_buy_session` WHERE order_id='$id'");
while($row=$db->sql_fetchrow($query)){
$id_i= $row['id'];
$pro_id= $row['pro_id'];
$num_pro= $row['num_pro'];
$pro_title= $row['pro_title'];
$pro_price= $row['pro_price'];
$pro_price_s= number_format($pro_price, 0);
$total_price_num = ($pro_price*$num_pro);
$total_price_num_s  = number_format($total_price_num, 0);




echo"<tr bgcolor=#ffffff><td id='invoiceitemsrow' style='border:1px solid #cccccc;border-bottom:0px;'>$pro_title</td>
<td id='invoiceitemsrow' align='center' style='border:1px solid #cccccc;border-bottom:0px;'>$pro_price_s تومان</td>
<td id='invoiceitemsrow' align='center' style='border:1px solid #cccccc;border-bottom:0px;'>$num_pro</td>
<td align='center' id='invoiceitemsrow' style='border:1px solid #cccccc;border-bottom:0px;border-left:0px;'>$total_price_num_s تومان</td></tr>";
}



echo"
</table>
<table cellspacing='0' id='invoiceitemstable' align='center'>
<tr><td id='invoiceitemsheading' width='80%' style='border:1px solid #cccccc;border-bottom:0px;'><div align='right'>جمع مبلغ كالاها</div></td><td id='invoiceitemsheading' width='20%' align='center' style='border:1px solid #cccccc;border-bottom:0px;border-left:0px;'><strong>$subtotal  تومان</strong></td></tr>
<tr><td id='invoiceitemsheading' style='border:1px solid #cccccc;border-bottom:0px;'><div align='right'>ماليات و هزينه هاي متفرقه</div></td><td id='invoiceitemsheading' align='center' style='border:1px solid #cccccc;border-bottom:0px;border-left:0px;'><strong>$maliyat  تومان</strong></td></tr>
<tr><td id='invoiceitemsheading' style='border:1px solid #cccccc;'><div align='right'>هزينه پستي</div></td><td id='invoiceitemsheading' align='center' style='border:1px solid #cccccc;border-left:0px;'><strong>$hazine تومان</strong></td></tr>
<tr><td id='invoiceitemsheading' style='border:1px solid #cccccc;'><div align='right'>جمع كل + ماليات و هزينه پستي</div></td><td id='invoiceitemsheading' align='center' style='border:1px solid #cccccc;border-left:0px;'><strong>$total_price_send تومان</strong></td></tr>
</table>


<p><strong>طريقه ارسال انتخاب شده : </strong>$sendway_title</p>";



if($is_payed==1){


$query = $db->sql_query("SELECT * FROM `fireshop_pay` WHERE id='$pay_id'");
$row=$db->sql_fetchrow($query);
$id= $row['id'];
$date_pay= $row['date_pay'];
$price_fish= $row['price_fish'];
$price_fish_s= number_format($row['price_fish'], 0);
$num_fish= $row['num_fish'];

$baghi= ($total_price_send_r-$price_fish);

echo"
<p><strong>مشخصات پرداخت</strong></p>

<table cellspacing='' id='invoiceitemstable' align='center'><tr><td id='invoiceitemsheading' align='center' width='30%' style='border:1px solid #cccccc'><strong>تاریخ پرداخت</strong></td><td id='invoiceitemsheading' align='center' width='25%' style='border:1px solid #cccccc;border-left:0px;'><strong>شماره پرداخت</strong></td><td id='invoiceitemsheading' align='center' width='25%' style='border:1px solid #cccccc;border-left:0px;'><strong>شماره فيش بانكي</strong></td><td id='invoiceitemsheading' align='center' width='20%' style='border:1px solid #cccccc;border-left:0px;'><strong>مبلغ</strong></td></tr>
<tr bgcolor=#ffffff><td id='invoiceitemsrow' align='center' style='border:1px solid #cccccc;border-top:0px;'>$date_pay</td><td align='center' id='invoiceitemsrow' style='border:1px solid #cccccc;border-left:0px;border-top:0px;'>$id</td><td align='center' id='invoiceitemsrow' style='border:1px solid #cccccc;border-left:0px;border-top:0px;'>$num_fish</td><td align='center' id='invoiceitemsrow' style='border:1px solid #cccccc;border-left:0px;border-top:0px;'>$price_fish_s تومان</td></tr>
<tr><td id='invoiceitemsheading' width='30%' style='border:1px solid #cccccc;border-top:0px;' colspan=3><DIV ALIGN='right'><strong>باقي مانده حساب</strong></DIV></td><td id='invoiceitemsheading' align='center' width='20%' style='border:1px solid #cccccc;border-left:0px;border-top:0px;'><strong>$baghi تومان</strong></td></tr>
</table>

";

}

echo"<br />

<table width='100%' id='invoicetoptables' cellspacing='0'><tr>
<td width='50%' id='invoicecontent' style='border:1px solid #cccccc;border-left:0px;'>

<table width='100%'  cellspacing='0' cellpadding='10' id='invoicetoptables'><tr><td id='invoicecontent' valign='top' style='border:1px solid #cccccc'>

<strong>مشخصات فروشگاه</strong><br />
آدرس فروشگاه : $adress<br />
تلفن : $tel | 
آدرس اينترنتي : $site_url   
</td></tr></table>

</td></tr></table>
</td></tr></table>
<div align='center'><br/>
<a href='javascript:history.go(-1)'>بازگشت</a> | <a href='index.php'>صفحه اصلي</a> | كليد تركيبي براي چاپ فاكتور : Ctrl + p
</div>
</body>
";
}else{echo"ورودي نا معتبر";}


?>