{% extends "common/auth_page.twig" %}

{% block contentTitle %}Pre carga de transacciones{% endblock %}

{% block content %}

<div class="container-fluid">
	{% if errors|length > 1 %}
	<div class="row">
		<div class="col-md-12 alert alert-warning">
			Ha existido un problema al importar los siguientes registros :
				<table class="table table-hover mt-3" style="font-size:10px;">
					<thead>
						<tr>
							<th>{{'date'|trans}}</th>
							<th>{{'payer'|trans}}</th>
							<th>{{'comments'|trans}}</th>
							<th></th>
							<th>{{'value'|trans}}</th>
							<th></th>
							<th>{{'operation-number'|trans}}</th>							
						</tr>
					</thead>
					<tbody>
						{% for error in errors %}
							<tr>
							{% for field in error %}
								<td>{{field}}</td>
							{% endfor %}
							</tr>
						{% endfor %}
					</tbody>
				</table>
			
		</div>
	</div>
	{% endif %}
	<form action="{{path_for(constant('GestionComedor\\Configuration\\Routers\\TransactionsBanksRouters::TRANSACTIONS_BANKS_COMPLETE'))}}" method="POST">
	<div class="row">
		<table class="table table-hover" id="paymentsTable" style="font-size: 12px;">
			<thead>
				<tr>
					<th>{{'date'|trans}}</th>
					<th>{{'payer'|trans}}</th>
					<th>{{'comments'|trans}}</th>
					<th>{{'value'|trans}}</th>
					<th>Usuario asignado</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
			{% for transaction in transactions %}
				<tr class={% if transaction.tempLevel == 1 %}"alert alert-warning"{% else %}{% if transaction.user %}"alert alert-success"{% else %}"alert alert-danger"{% endif %}{% endif %} >			  		
					<td>{{transaction.datePayment|date("d-m-Y")}}</td>
					<td>
						{{transaction.payer}}
						
					</td>
					<td>{{transaction.comments}}</td>
					<td>{{transaction.amount}} €</td>
					<td id="user-assign-transaction-{{transaction.id}}">
						{% if transaction.user %}
						{{transaction.user.name}} {{transaction.user.surname}}
						{% endif %}
					</td>
					<td>
						
						{% if not transaction.completed %}
						<input type="hidden" name="transactions[]" value="{{transaction.id}}">
						<input type="hidden" id="user-id-assign-transaction-{{transaction.id}}" name="users[]" value="{{transaction.userId}}">
	  				<div class="btn btn-outline-primary btn-sm btn-block mw-100 assignTransactionBankModal" style="font-size: 12px;" id="assignTransactionUserModal" data-toggle="modal" data-target="#assignTransaction" data-transaction-id="{{transaction.id}}" data-payer="{{transaction.payer}}" data-comments="{{transaction.comments}}" data-amount="{{transaction.amount}}" >{{'assign-transaction'|trans}}
	  				</div>
	  				{% else %}
	  					Ya asignada {{transaction.completed}}
	  				{% endif %}
					</td>
					<td>
					
					</td>
				</tr>
			{% endfor %}
			</tbody>
		</table>
	</div>
	<div class="row">
		<div class="col-md-12">
			
			<button class="btn btn-success btn-block mw-100 ">Confirmar transacciones</button>
			
		</div>
	</div>
	</form>
</div>

<div class="modal fade" id="assignTransaction" tabindex="-1" role="dialog" aria-labelledby="assignTransactionUser" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="assignTransactionUser">{{'assign-transaction'|trans}}</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      	<!--<form action="{{path_for(constant('GestionComedor\\Configuration\\Routers\\TransactionsBanksRouters::TRANSACTIONS_BANKS_ASSIGN_USER'))}}" method="POST">-->
	      	<div class="row">
	      		<div class="col-sm-12">
	      			<label class="font-weight-bold">{{'payer'|trans}}</label> <span id="transaction-payer"></span>
	      		</div>
	      		<div class="col-sm-12">
	      			<label class="font-weight-bold">{{'comments'|trans}}</label> <span id="transaction-comments"></span>
	      		</div>
	      		<div class="col-sm-12">
	      			<label class="font-weight-bold">{{'amount'|trans}}</label> <span id="transaction-amount"></span>
	      		</div>
	    		  <div class="col-sm-12 mt-2">
			  			<label for="userNameTransaction" class="font-weight-bold" >{{'user-select'|trans}}</label>
	            <input type="search" class="form-control" name="userNameTransaction" id="userNameTransaction" />
	            <input type="hidden" id="userTransactionModal" name="userTransactionModal">
	            <input type="hidden" id="transactionBankIdModal" name="transactionBankIdModal">
	          </div>
	      	</div>
	      	<div class="row">
	      		<div class="col-sm-10 pt-5">
	      			<button class="btn btn-outline-primary setUserInTransaction" autocomplete="false" >{{'assign'|trans}}</button>
	      		</div>
	      	</div>
      	<!--</form>-->
      </div>
    </div>
  </div>
</div>

{% endblock %}