<?php 

use common\models\Account;
use common\models\Discount;
use frontend\assets\ProductSellAsset;
use frontend\components\ReceptionWidget;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use common\components\Helper;

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $currencies common\models\Currency[] */

ProductSellAsset::register($this);

$options = [];

$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
$options['find_product_url'] = Url::toRoute(['product/find']);
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart' , 'number' =>isset($model->card) ? $model->card->number : '']);
$options['url_delete_transaction'] = Url::toRoute(['transfer/delete']);
$options['url_pay_transaction'] = Url::toRoute(['transfer/payout']);
$options['user_cart'] = $userTransfers;
$options['products'] = $model->products;
if ( isset($model->card) ){
	$options['url_pay_customer_card'] = Url::toRoute(['product/payout-customer-cart','number' => $model->card->number]);
	$options['customer_cart'] = $model->customerCart;
}
$options['discounts'] = Discount::modelsToArray($discounts);
$options['id_account'] = Account::readDefault();

$options['product_sale_default_focus'] = Helper::getProductSaleDefaultFocus();
$options['user_cart_on'] = Helper::isUserCartOn();


$this->registerJs ( 'new ProductSell( '. json_encode($options).');' );

$this->params['breadcrumbs'][] =  Yii::t('frontend/product', 'Products') ;
$this->params['breadcrumbs'][] = Yii::t('frontend/product', 'Sale');

?>

<style>
/*
	.product-form input, .product-form select, .product-form textarea{
		width: 100%;
	}
	*/
	.product-count{
		text-align: right;
	}
	
	.form-group{
		margin-bottom: 3px;
	}
	
	.table-transfers thead th{
		text-align: center;
	}
	
	.table-transfers tfoot .product-money,
	.table-transfers tfoot .product-count,
	.table-transfers tbody .product-money,
	.table-transfers tbody .product-count,
	.table-transfers tbody .sale-price
	{
			text-align: right;
	}
	.table-transfers tbody .product-name,
	.table-transfers tbody .product-time
	{
			text-align: left;
	}
	.table-transfers   .product-time{
		width: 140px;
	}
	.table-transfers   .product-count{
		width: 50px;
	}
	.table-transfers   .sale-price{
		width: 80px;
	}
	.table-transfers   .product-money{
		width: 100px;
	}
	.typeahead.dropdown-menu{
	}
	
</style>
	
	<?php echo ReceptionWidget::widget( ['form' => $receptionForm, 'route' => ['customer/reception'] ] )?>

	<div class='row '>
		<div class='col-md-6 product-form'>
			<h1><?php  echo Yii::t('frontend/product','Sell product')?></h1>
			<?php echo $this->render('_sale_form' ,[ 'receptionForm' => $receptionForm, 'model' =>$model , 'lookupModel' =>$lookupModel,  'currencies' => $currencies, 'accounts' => $accounts,'discounts' => $discounts ]) ?>	
		</div>
		<div class='col-md-6'>
			<?php if (  $receptionForm->isCardWithCustomer()  ){ ?>
				<?php echo $this->render('_customer_cart' , ['model' => $model]) ?>
			<?php }?>
			<?php if ( Helper::isUserCartOn()) {?>
			<?php echo $this->render('_user_cart' ) ?>
			<?php }?>
			
		</div>
	</div>
