<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ListView;
use yii\base\Widget;
use yii\helpers\Url;
use common\components\Helper;

/* @var $this yii\web\View */
/* @var $searchModel common\models\TransferListSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t ( 'frontend/transfer', 'Daily transfers' );
$this->params ['breadcrumbs'] [] = $this->title;
?>
<style>
.dl-transfer {
	margin-bottom: 0px;
}

.item-transfer {
	border: 1px solid #b4b4b4;
	margin-top: 12px;
	padding-top: 6px;
	padding-bottom: 6px;
}

td.count, td.money{
text-align: right;
}

td.name{
	width: 600px;
}

.table-category-product td.name{
	width: 600px;
}

.table-category-product td.count{
	text-align: right;
}

.table-category-product td.money{
	text-align: right;
}
</style>

<?php 

	
	
	
	
?>

<div class="transfer-index">

	<h1><?= Html::encode($this->title) ?></h1>
    <?php   echo $this->render('_search_list', ['model' => $searchModel]); ?>


	<div>

		<!-- Nav tabs -->
		<ul class="nav nav-tabs" role="tablist">
			<li role="presentation" class="active"><a href="#big"
				aria-controls="big" role="tab" data-toggle="tab">Egyszerű összesítő</a></li>
			<li role="presentation"><a href="#medium" aria-controls="medium"
				role="tab" data-toggle="tab">Közepes összesítő</a></li>
			<li role="presentation"><a href="#detailed" aria-controls="detailed"
				role="tab" data-toggle="tab">Részletes összesítő</a></li>
		</ul>

		<!-- Tab panes -->
		<div class="tab-content">
			<div role="tabpanel" class="tab-pane active" id="big">
				<h2>Egyszerű összesítés</h2>
				<table class="table table-bordered table-striped table-summary">
					<tbody>
						<tr>
							<th>Bérletek</th>
							<td class="money"><?php echo $searchModel->ticketMoney?> FT</td>
						</tr>
						<tr>
							<th>Termékek</th>
							<td class="money"><?php echo $searchModel->productMoney?> FT</td>
						</tr>
						<tr>
							<th>Pénzmozgások</th>
							<td class="money"><?php echo $searchModel->moneyMovementMoneis?> FT</td>
						</tr>
						<tr>
							<th>Végösszeg</th>
							<td class="money"><span style='border-bottom: 1px solid black'><?php echo \Yii::$app->formatter->asInteger($searchModel->total)?> FT</span></td>
						</tr>
					</tbody>
				</table>
				<?php if ( $searchModel->isModeReception()  &&  Helper::isAccountStateClosePreloadMoney()){?>
				<h2>Aktuális záró összeg</h2>
				<table class="table table-bordered table-striped table-summary">
					<tbody>
						<tr>
							<th>Kasszanyitás</th>
							<td class="money"><span style=' '><?php echo isset($searchModel->cassaOpen) ?  \Yii::$app->formatter->asInteger( $searchModel->cassaOpen->money ) : ""?> FT</span></td>
						</tr>
						<tr>
							<th>Végösszeg</th>
							<td class="money"><span style=' '><?php echo \Yii::$app->formatter->asInteger($searchModel->total)?> FT</span></td>
						</tr>
						<tr>
							<th>Kasszában lévő összeg</th>
							<td class="money"><span style='border-bottom: 1px solid black'><?php echo    \Yii::$app->formatter->asInteger( $searchModel->totalWithCassa ) ?> FT</span></td>
						</tr>
					</tbody>
				</table>
				<?php echo Html::a("Ugrás kassza zárásra",Url::toRoute([ 'account-state/close', 'money' =>  $searchModel->totalWithCassa ]), ['class' =>'btn btn-primary'])?>
				<?php }?>
				
			</div>
			<div role="tabpanel" class="tab-pane" id="medium">
				<h2>Közepes összesítés</h2>

				<h3>Bérletek típus szerint</h3>
				<table class="table table-bordered table-striped table-summary">
					<thead>
						<tr>
							<th>Bérlet típus</th>
							<th>Mennyiség</th>
							<th>Összeg</th>
						</tr>
					</thead>
					<tbody>
    		<?php
						foreach ( $searchModel->ticketStats as $ticketStat ) {
							?>
						<tr>
    						<td class="name"><?php echo $ticketStat['ticket_type_name'] ?></td>
							<td class="count"><?php echo $ticketStat['ticket_count']?> Db</td>
							<td class="money"><?php echo $ticketStat['ticket_money']?> FT</td>
					    </tr>
    		<?php } ?>
					</tbody>
				</table>
			
				<div class="row">
	    			<div class="col-md-12 text-right" style="text-decoration: underline;">
	    				Összesen: <?php	echo $searchModel->ticketMoney;	?> Ft
	    				
	    			</div>
	    		</div>
				<h3>Termékek kategória szerint</h3>
				<table class="table table-bordered table-striped table-summary">
					<thead>
						<tr>
							<th>Termék kategória</th>
							<th>Mennyiség</th>
							<th>Összeg</th>
						</tr>
					</thead>
					<tbody>
    		<?php
						foreach ( $searchModel->productMoneies as $pm ) {
							?>
						<tr>
    						<td class="name"><?php echo $pm['category_name'] ?></td>
							<td class="count"><?php echo $pm['category_count']?> Db</td>
							<td class="money"><?php echo $pm['product_money']?> FT</td>
				    	</tr>
    		<?php } ?>
					</tbody>
				</table>
				<div class="row">
	    			<div class="col-md-12 text-right" style="text-decoration: underline;">
	    				Összesen: <?php	echo $searchModel->productMoney;	?> Ft
	    				
	    			</div>
	    		</div>
				
				<h3>Termékek kategória szerint részletes</h3>
				
				<?php 
				
				
				foreach($searchModel->productsByCategory['categories'] as $categoryHolder ){
					
					$products = $categoryHolder['products'];
				?>
				<h4><?php echo $categoryHolder['category']['name']?></h4>
				
				<table class="table table-bordered table-striped table-summary table-category-product">
					<thead>
						<tr>
							<th>Termék</th>
							<th>Mennyiség</th>
							<th>Összeg</th>
						</tr>
					</thead>
					<tbody>
						<?php foreach ( $products as $p){?>
							
							<tr>
	    						<td class='name'><?php echo $p['product_name'] ?></td>
	    						<td class='count'><?php echo $p['product_count'] ?> Db</td>
								<td class='money'><?php echo $p['product_money']?> FT</td>
					    	</tr>
						
						<?php }?>
						<tr class="warning">
	    						<td><?php echo "Összesen" ?></td>
	    						<td><?php  ?></td>
								<td class='money'><?php echo $categoryHolder['total']?> FT</td>
					    	</tr>
					</tbody>
				</table>
	    		<?php
				}
				
	    		?>
	    		<div class="row">
	    			<div class="col-md-12 text-right" style="text-decoration: underline;">
	    				Összesen:
	    				<?php 
		    				echo $searchModel->productsByCategory['total'];
	    				?>
	    			</div>
	    		</div>
	    		
				<h3>Pénzmozgások típus szerint</h3>
				<table class="table table-bordered table-striped table-summary">
					<thead>
						<tr>
							<th>Pénzmozgás típus</th>
							<th>Mennyiség</th>
							<th>Összeg</th>
						</tr>
					</thead>
					<tbody>
	    		<?php
							foreach ( $searchModel->moneyMovementsByType as $mmStat ) {
								?>
						<tr>
				    		<td class="name"><?php echo $mmStat['name'] ?></td>
							<td class="count"><?php echo $mmStat['money_movement_count']?> Db</td>
							<td class="money"><?php echo $mmStat['money_movement_money']?> FT</td>
			    	</tr>
	    		<?php } ?>
					</tbody>
				</table>
			<div class="row">
			    			<div class="col-md-12 text-right" style="text-decoration: underline;">
			    				Összesen: <?php	echo $searchModel->moneyMovementMoneis;	?> Ft
			    				
			    			</div>
			    		</div>
			    		
			    		<div class="row">
			    			<div class="col-md-12 text-right" style="text-decoration: underline; font-weight: bold;">
			    				Végösszeg: <?php	echo $searchModel->total;	?> Ft
			    				
			    			</div>
			    		</div>
			</div>
			<div role="tabpanel" class="tab-pane" id="detailed">
				<h2>Részletes összesítés</h2>
				<?php 
					//////////////////////////
					// Bérletek
					////////////////////////
				?>
				<h3>Bérletek</h3>
				<table class="table table-bordered table-striped table-summary">
					<thead>
						<tr>
							<th>Kiadva</th>
							<th>Fizetve</th>
							<th>Kassza</th>
							<th>Felhasználó</th>
							<th>Vendég</th>
							<th>Bérlet típus</th>
							<th>Egység ár</th>
							<th>Mennyiség</th>
							<th>Összeg</th>
						</tr>
					</thead>
					<tbody>
				    	<?php foreach ($searchModel->tickets as $t ){?>
				    	<tr>
	    						<td><?php echo $t['ticket_created_at']?> </td>
	    						<td><?php echo $t['ticket_paid_at']?> </td>
	    						<td><?php echo $t['account_name']?> </td>
	    						<td><?php echo $t['user_name']?> </td>
	    						<td><?php echo $t['customer_name']?> </td>
	    						<td><?php echo $t['ticket_type_name'] ?></td>
								<td class='money'><?php echo $t['ticket_item_price']?> Ft</td>
								<td class='count'><?php echo $t['ticket_count']?> Db</td>
								<td class='money'><?php echo $t['ticket_money']?> FT</td>
				    		
					    </tr>
				    	<?php } ?>
				</tbody>
				</table>
				<?php if ( count($searchModel->tickets ) == 0 ) {
						?>
						Nincs találat
						<?php 
						}else{?>
						
						<div class="row">
			    			<div class="col-md-12 text-right" style="text-decoration: underline;">
			    				Összesen: <?php	echo $searchModel->ticketMoney;	?> Ft
			    				
			    			</div>
			    		</div>
						<?php 
						}
						?>
						<?php 
					//////////////////////////
					// Termék eladás
					////////////////////////
				?>
				<h3>Termék eladások</h3>
				<table class="table table-bordered table-striped table-summary">
					<thead>
						<tr>
							<th>Kiadva</th>
							<th>Fizetve</th>
							<th>Kassza</th>
							<th>Felhasználó</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['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 
						}else{?>
						
						<div class="row">
			    			<div class="col-md-12 text-right" style="text-decoration: underline;">
			    				Összesen: <?php	echo $searchModel->productMoney;	?> Ft
			    				
			    			</div>
			    		</div>
						<?php 
						}
						?>
				<?php 
					//////////////////////////
					// Pénzmozgások
					////////////////////////
				?>
				<h3>Pénzmozgások</h3>
				<table class="table table-bordered table-striped table-summary">
					<thead>
						<tr>
							<th>Dátum</th>
							<th>Kassza</th>
							<th>Felhasználó</th>
							<th>Név</th>
							<th>Típus</th>
							<th>Összeg</th>
							<th>Megjegyzés</th>
						</tr>
					</thead>
					<tbody>
				    	<?php foreach ($searchModel->moneyMovements as $p ){?>
				    	<tr>
			    						<td><?php echo $p['money_movement_created_at']?> </td>
			    						<td><?php echo $p['account_name']?> </td>
			    						<td><?php echo $p['user_name']?> </td>
			    						<td><?php echo $p['money_movement_name'] ?></td>
			    						<td><?php echo $p['money_movement_type_name'] ?></td>
										<td class='money'><?php echo $p['signed_money']?> Ft</td>
			    						<td><?php echo $p['money_movement_comment'] ?></td>
				    		
					    </tr>
				    	<?php } ?>
				</tbody>
				</table>
						<?php if ( count($searchModel->moneyMovements ) == 0 ) {
						?>
						Nincs találat
							<?php 
						}else{?>
						
						<div class="row">
			    			<div class="col-md-12 text-right" style="text-decoration: underline;">
			    				Összesen: <?php	echo $searchModel->moneyMovementMoneis;	?> Ft
			    				
			    			</div>
			    		</div>
						<?php 
						}
						?>
						
						<div class="row">
			    			<div class="col-md-12 text-right" style="text-decoration: underline; font-weight: bold;">
			    				Végösszeg: <?php	echo $searchModel->total;	?> Ft
			    				
			    			</div>
			    		</div>
			</div>
		</div>

	</div>





</div>
