<?php
use yii\data\ArrayDataProvider;
use yii\widgets\ListView;
use yii\base\Widget;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\models\Transfer;
use yii\grid\CheckboxColumn;
use frontend\assets\TransferUserCartAsset;
use frontend\assets\TransferCustomerCartAsset;
use frontend\components\CustomerTabWidget;
?>
<?php 
TransferCustomerCartAsset::register($this);

$options = [];

$this->registerJs ( 'new TransferCustomerCart( '. json_encode($options).');' );
	$dp = new ArrayDataProvider(
			[
					'allModels' => $model->transfers,
					'pagination' => false
					
			]
			);
	$this->params['breadcrumbs'][] = "Vendég Kosár";

?>

<?php echo CustomerTabWidget::widget(['card' => $model->customer->card])?>

<div class="transfer-form">
<?php $form = ActiveForm::begin(); ?>
<?php  echo $form->field($model, 'payment_method')->dropDownList( ['' => 'Aktuális'] + Transfer::paymentMethods())->label("Fizetése mód") ?>
<div class="row">
	<div class="col-md-4">
		<span style="font-weight: bold;">Összesen:</span>
		<span class="selected-money"><?php echo $model->money ?></span>
		<span> Ft</span>
		<?php  echo $form->field($model, "money" , [ ])->hiddenInput()->label(false); ?>
	</div> 
	
</div>
<div style="margin-bottom: 6px;">
<?php 
echo Html::a("Összes kiválasztása",null, ['class' => 'btn btn-primary select-all' ,'style' => 'margin-right: 6px;']);
echo Html::a("Egyiket sem",null, ['class' => 'btn btn-primary deselect-all']);

?>
</div>

<?php 


$formModel = $model;
echo GridView::widget([
		"dataProvider" => $dp,
		'columns' =>[
			[
				'label' => '',
				'value' => function ($model, $key, $index, $column)  use (&$form, &$formModel){
						
						return   Html::checkbox(Html::getInputName($formModel, 'selected[]') ,  in_array($model->id_transfer, $formModel->selected) , [ 'data-money' => $model->money, 'class' => 'cart-item', 'value'  => $model->id_transfer] );
					},
				 'format' => 'raw'
			],
			[
				'value' => 'created_at',
				'label' => 'Kiadva',
				'format' => 'datetime'
			],			
			[
				'value' => 'user.username',
				'label' => 'Kiadta',
			],			
			[
				'value' => 'transferTypeName',
				'label' => 'Típus'
			],			
			[
				'value' => 'objectName',
				'label' => 'Megnevezés'
			],			
			[
				'value' => 'item_price',
				'label' => 'Egység ár'
			],			
			[
				'value' => 'count',
				'label' => 'Mennyiség'
			],			
			[
				'value' => 'money',
				'label' => 'Összesen'
			],			
			[
				'value' => 'paymentMethodName',
				'label' => 'Fizetési mód'
			],			
		]
]);

 
?>
  	<div class="form-group">
        <?= Html::submitButton(  "Kiválasztott elemek fizetve", ['class' =>  'btn btn-primary']) ?>
    </div>
    <p>
    	A kifizetés az alapértelmezett kasszához lesz elszámolva
    </p>

    <?php ActiveForm::end(); ?>
</div>