<?
define("PARTNER_AUTHORIZATION",1);

include("../../../includes/common.php");
/*
$params = array(partner_id => "1",
								amount => 200,
								currency_id => 3,
								comments => "dfffff");
								
if (MakePartnerTransaction($params))
{
	echo "OK!!";
}
exit;*/


/*PAGE TITLE*/
$page_title = "Операции с аккаунтом";

$header = "Операции с аккаунтом";

$table = "partner_transactions";
/* pager start */
$params['tables'] = $table;
$params['nocheckfield']=true;
$params['s_prefix'] = $table;
$params['query'] = "select count(*) from $table where partner_id=$PARTNER_ID";

$pager = GetPagerParams($params);
/* pager end */


$table_headers = Array(
	"itter"=>Array("№","width=20 align=center"),
	"id"=>Array("<a href='".$pager['new_sort']."$table".".id' title='Sort'>ID</a>","width=30 align=center"),
	"desc"=>Array("<a href='".$pager['new_sort']."$table".".description' title='Sort'>Описание</a>",""),
	"order"=>Array("<a href='".$pager['new_sort']."$table".".order_id' title='Sort'><nobr>ID обмена</nobr></a>","align=center width=60"),
	"amount"=>Array("<a href='".$pager['new_sort']."$table".".amount' title='Sort'>Количество</a>","align=center"),
	"rest"=>Array("<a href='".$pager['new_sort']."$table".".rest_amount' title='Sort'>Остаток</a>","align=center"),
	"date"=>Array("<a href='".$pager['new_sort']."$table".".regdate' title='Sort'>Дата</a>","align=center"),
);

$query = "select $table.*, r_curr.symbol as rest_curr_symbol, curr.symbol as currency_symbol from ($table inner join currencies r_curr on r_curr.id = $table.currency_id) inner join currencies curr on curr.id = $table.currency_id where partner_id=$PARTNER_ID ORDER BY ".$pager['sort_by']." ".$pager['sort_ord']
  ." LIMIT ".$SETTINGS['admin_items_per_page']." OFFSET ".($pager['start_item']-1);

$res = mysql_query($query);
//echo mysql_error();
//echo $query;
$table_items=Array();
$itter =$pager['start_item'];
$i=0;

while ($row = mysql_fetch_object($res)){

   	  $amount = MoneyToStr($row->amount);
	  $amount = ($row->amount>0?"<font color=green>+":"<font color=red>").$amount." ".$row->currency_symbol."</font>";
	  $rest = ($row->rest_amount>0?"<font color=green>+":"<font color=red>").MoneyToStr(round($row->rest_amount,2))." ".$row->rest_curr_symbol."</font>";


	$table_items[$itter] = Array(
		"id"=>array($row->id,"align=center"),
		"itter"=>array($itter,"align=center"),
		"desc"=>Array(stripslashes($row->description)),
		"order"=>Array($row->order_id>0?$row->order_id:"-","align=center"),
		"amount"=>Array($amount,"align=center"),
		"rest"=>Array($rest,"align=center"),
		"date"=>Array(strftime("%d %b %Y<br><small>%H:%M:%S</small>",$row->regdate),"align=center"),
);
	$itter++;
}

$smarty->assign('page_title',"Операции с аккаунтом");

$smarty->assign('error',$error);

/* table template */
$smarty->assign('pager',$pager);
$smarty->assign('table_headers',$table_headers);
$smarty->assign('table_items',$table_items);
$smarty->assign('table_width',"90%");
$smarty->assign('top_menu_tpl',"partner_trans_menu.tpl");
$smarty->assign('main_tpl',"admin_list_table.tpl");
$smarty->assign('use_group_funcs',array_key_exists("group_funcs",$table_headers));

/* display content */
$smarty->display('partner_index.tpl');
?>