<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Обработчик добавления/редактирования сделки.
 * 
 * Файл: /admin/shop/action/add_transaction.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$param = array();

$shop = & singleton('shop');

$DateTime = new DateClass();

$shop_shops_id = to_int($_REQUEST['shop_shops_id']);

$site_users_id = to_int($_REQUEST['site_users_id']);

// Получаем переданные параметры
$shop_site_users_account_description = quote_smart($_REQUEST['shop_site_users_account_description']);

$shop_site_users_account_active = (isset($_REQUEST['shop_site_users_account_active']))?1:0;

$shop_site_users_account_datetime = quote_smart($_REQUEST['shop_site_users_account_datetime']);

$shop_site_users_account_sum = to_float($_REQUEST['shop_site_users_account_sum']);

$shop_site_users_account_type = to_int($_REQUEST['shop_site_users_account_type']);

$shop_currency_id = to_int($_REQUEST['shop_currency_id']);

$shop_order_id = to_int($_REQUEST['shop_order_id']);

$shop_row = $shop->GetShop($shop_shops_id);

$shop = new shop();

if ($shop_row)
{
	// Рассчитываем коэффициент пересчета из переданной валюты в валюту магазина
	$currency_coefficient = $shop->GetCurrencyCoefficientToShopCurrency($shop_currency_id, $shop_row['shop_currency_id']);

	$shop_site_users_account_sum_in_base_currency = $shop_site_users_account_sum * $currency_coefficient;

	$param = array();

	if (isset($_REQUEST['transaction_id']))
	{
		$param['shop_site_users_account_id'] = to_int($_REQUEST['transaction_id']);
	}

	$param['shop_shops_id'] = $shop_shops_id;

	$param['site_users_id'] = $site_users_id;

	$param['shop_site_users_account_active'] = $shop_site_users_account_active;

	$param['shop_site_users_account_datetime'] = $shop_site_users_account_datetime;

	$param['shop_site_users_account_sum'] = $shop_site_users_account_sum;

	$param['shop_currency_id'] = $shop_currency_id;

	$param['shop_site_users_account_sum_in_base_currency'] = $shop_site_users_account_sum_in_base_currency;

	$param['shop_order_id'] = $shop_order_id;

	$param['shop_site_users_account_description'] = $shop_site_users_account_description;
	
	$param['shop_site_users_account_type'] = $shop_site_users_account_type;

	if($shop->InsertSiteUserAccountTransaction($param))
	{
		if (isset($_REQUEST['transaction_id']))
		{
			show_message($GLOBALS['MSG_shops']['transaction_update_success']);
		}
		else 
		{
			show_message($GLOBALS['MSG_shops']['transaction_insert_success']);
		}
	}
	else
	{
		show_error_message($GLOBALS['MSG_shops']['transaction_insert_error']);
	}
}
else
{
	// Показать ошибку "Магазин отсутствует"
	show_error_message($GLOBALS['MSG_shops']['transaction_insert_error_undef_shop']);
}
?>