<?php
use yii\helpers\Html;
use common\models\Account;
use common\models\User;
use common\models\ProductCategory;
use common\models\Product;
use common\models\Transfer;
?>
<style>
td,th{
	padding: 3px;
}
 .table-summary td.count {
	text-align: right;
}

.table-summary td.money {
	text-align: right;
}

.table-filter th{
	text-align: left;
}
</style>
<div class="container">
		<?php
		// ////////////////////////
		// Termék eladás
		// //////////////////////
		?>
		<h3>Termék eladások</h3>
		
		<table class="table-filter">
			<tr>
		  <th><?php echo Html::encode($searchModel->getAttributeLabel('start')) ?></th>
		  <td><?php echo Html::getAttributeValue($searchModel, "start")?></td>
		  <th><?php echo Html::encode($searchModel->getAttributeLabel('end')) ?></th>
		  <td><?php echo Html::getAttributeValue($searchModel, "end")?></td>
		  </tr>
		  <tr>
		  <th><?php echo Html::encode($searchModel->getAttributeLabel('id_account')) ?></th>
		  <td><?php  if (   empty($searchModel->id_account)  ){
		  			 echo"Mind" ;
		  			}else{ 
		  			$account = Account::findOne($searchModel->id_account) ; 
		  				if ( $account != null ){
		  					echo $account->name;
		  				}
		 			 }?></td>
		 <th><?php echo Html::encode($searchModel->getAttributeLabel('id_user')) ?></th>
		  <td><?php  if (   empty($searchModel->id_user)  ){
		  			 echo"Mind" ;
		  			}else{ 
		  			$user = User::findOne($searchModel->id_user) ; 
		  				if ( $user != null ){
		  					echo $user->username;
		  				}
		 			 }?></td>
		 </tr>
		 <tr>
			 <th><?php echo Html::encode($searchModel->getAttributeLabel('category')) ?></th>
			 <td><?php  if (   empty($searchModel->category)  ){
		  			 	echo"Mind" ;
		  			}else{ 
		  			$category = ProductCategory::findOne($searchModel->category) ; 
		  				if ( $category != null ){
		  					echo $category->name;
		  				}
		 			 }?></td>
		 		 
		 <th><?php echo Html::encode($searchModel->getAttributeLabel('id_product')) ?></th>
		  <td><?php  if (   empty($searchModel->id_product)  ){
		  			 	echo"Mind" ;
		  			}else{ 
		  			$product = Product::findOne($searchModel->id_product) ; 
		  				if ( $product != null ){
		  					echo $product->name;
		  				}
		 			 }?></td>
			</tr>
		 	<tr>
		 <th><?php echo Html::encode($searchModel->getAttributeLabel('status')) ?></th>
		  <td><?php  if (   empty($searchModel->status)  ){
		  			 	echo"Mind" ;
		  			}else{ 
		  			$statuses = Transfer::statuses();
		  			$status = "";
		  				if (array_key_exists($searchModel->status, $statuses) ){
		  					echo $statuses[$searchModel->status];
		  				} 
		 			 }?></td>
		 	</tr>
		</table>
		<div class="row">
			<div class="col-md-12 text-right" style="text-decoration: underline;">
			    				Összesen: <?php	echo $searchModel->productMoney;	?> Ft
			</div>
		</div>
		<table class="table table-bordered table-striped table-summary">
			<thead>
				<tr>
					<th>T</th>
					<th>Kiadva</th>
					<th>Fizetve</th>
					<th>Kassza</th>
					<th>Felhasználó</th>
<!-- 					<th>Vásárló</th> -->
					<th>Kategória</th>
					<th>Termék</th>
					<th>Egység ár</th>
					<th>Mennyiség</th>
					<th>Összeg</th>
				</tr>
			</thead>
			<tbody>
		    	<?php foreach ($searchModel->products as $p ){?>
			    	<tr>
						<td><?php echo "#".$p['id_transfer']?> </td>
						<td><?php echo $p['product_created_at']?> </td>
						<td><?php echo $p['product_paid_at']?> </td>
						<td><?php echo $p['account_name']?> </td>
						<td><?php echo $p['user_name']?> </td>
						
						<td><?php echo $p['product_category_name'] ?></td>
						<td><?php echo $p['product_name'] ?></td>
						<td class='money'><?php echo $p['product_item_price']?> Ft</td>
						<td class='count'><?php echo $p['product_count']?> Db</td>
						<td class='money'><?php echo $p['product_money']?> FT</td>
	
					</tr>
		    	<?php } ?>
			</tbody>
		</table>
						<?php
						
				if (count ( $searchModel->products ) == 0) {
											?>
										Nincs találat
										<?php
										} 
							?>
					</div>
