{% extends 'back.html.twig' %}
{% block title %}
Détails facture
{% endblock %}
{% block body %}
<div class="row">
<div class="col-md-12">
<h3>Info Rechnung</h3>
<hr>
</div>
</div>
<div class="row">
<div class="col-md-6 m_t_20">
<ul class="ul_action">
<li>
<a href="{{ path('piece_index') }}" class="btn btn-sm btn-info"> <span class="fa fa-list-ul"></span>
Rechnungen Liste</a>
</li>
<li>
<a href="{{ path('piece_print',{'id':piece.id}) }}"
class="btn btn-secondary btn-sm" target="_blank">
<span class="fa fa-print"></span> Drücken
</a>
</li>
{% if app.user.isSuperAdmin or getParam('param_title') != 'IRON-APP' %}
<li>
<a href="{{ path('piece_edit',{'id':piece.id}) }}"
class="btn btn-warning btn-sm">
<span class="fa fa-edit"></span> Andern
</a>
</li>
{% elseif app.user.isSuperAdmin %}
<li>
<a href="{{ path('piece_delete_confirmation',{'id':piece.id}) }}"
class="btn btn-danger btn-sm">
<span class="fa fa-trash-alt"></span> Löschen
</a>
</li>
{% endif %}
</ul>
</div>
</div>
<div class="row">
<div class="col-12">
<b>Facture: </b>{{ piece.numero }}
</div>
<div class="col-12 m_t_10">
<b>Date: </b>{{ piece.date ? piece.date|date('d/m/Y') : '' }}
</div>
<div class="col-12 m_t_10">
<b>Kunde: </b><a href="{{ path('client_show',{'id':piece.client.id}) }}">{{ piece.client ? piece.client.nomComplet : '' }}</a>
</div>
<div class="col-12 m_t_10">
<b>Solde: </b> {% if piece.solde == 0 %} <span class="badge badge-success">{{ piece.solde }}</span>{% else %}<span class="badge badge-danger">{{ piece.solde }}</span>{% endif %}
</div>
<div class="col-12 m_t_10">
<b>vous Sie wurden serviert von: </b> {{ piece.user ? piece.user.nomComplet : '' }}
</div>
</div>
<div class="row m_t_10">
<div class="col-12">
<div class="table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<th>Code</th>
<th>Barcode</th>
<th>Produkt</th>
{% if app.user.isSuperAdmin %}
<th class="text-right">Einkaufpreis</th>
{% endif %}
<th class="text-right">Preis Ohne Mwst</th>
<th class="text-center">Qté</th>
<th class="text-right">Rabatt</th>
<th class="text-right">Mwst</th>
<th class="text-right">Total Ohne Mwst %</th>
<th class="text-right">Total Ohne Mwst</th>
</tr>
</thead>
<tbody>
{% for ligne_piece in piece.pieceLines %}
<tr>
<td>{{ ligne_piece.product ? ligne_piece.product.code : '' }}</td>
<td>{{ ligne_piece.product ? ligne_piece.product.barecode : '' }}</td>
<td>{{ ligne_piece.product ? ligne_piece.product.nomComplet : '' }}</td>
{% if app.user.isSuperAdmin %}
<td class="text-right">{{ ligne_piece.priceBuyHT }}</td>
{% endif %}
<td class="text-right">{{ ligne_piece.priceHT }}</td>
<td class="text-center">{{ ligne_piece.qty }}</td>
<td class="text-right">{{ ligne_piece.rabais!='' ? ligne_piece.rabais : '0.00' }}%</td>
<td class="text-right">{{ ligne_piece.tva!='' ? ligne_piece.tva : '0.00' }}%</td>
<td class="text-right">{{ ligne_piece.totalHT }}</td>
<td class="text-right">{{ ligne_piece.rabais!='' ? (ligne_piece.totalHT *(1-(ligne_piece.rabais/100)))|number_format(2,'.','') : ligne_piece.totalHT }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-md-7 m_t_20">
{% if piece.client.getAvailablePoints() > 0 and piece.solde > 0 %}
<span
class="btn btn-outline-info" data-amount="{{ piece.amountTTC }}" data-available="{{ piece.client.getAvailablePoints() }}"
data-toggle="collapse" data-target="#collapseAffectationPoints" aria-expanded="{% if app.request.get('col') == 'gift' %}true{% else %}false{% endif %}" aria-controls="collapseAffectationPoints"
>
({{ piece.client.getAvailablePoints() }}) points fidélité disponible
</span>
{% endif %}
{% if piece.client.getNotAffectedPayement() is not null and piece.solde > 0 %}
<span
class="btn btn-outline-primary" data-amount="{{ piece.amountTTC }}" data-available="{{ piece.client.getNotAffectedPayement().getRest() }}"
data-toggle="collapse" data-target="#collapseAffectationPaiement" aria-expanded="{% if app.request.get('col') == 'affect' %}true{% else %}false{% endif %}" aria-controls="collapseAffectationPaiement"
>
({{ piece.client.getNotAffectedPayement().getRest()|number_format(2, '.', ' ') }}) paiement enregistré mais non affecté
</span>
{% endif %}
{% if piece.solde > 0 %}
<span
class="btn btn-outline-dark"
data-toggle="collapse" data-target="#collapseAjouterPaiement" aria-expanded="{% if app.request.get('col') == 'new' %}true{% else %}false{% endif %}" aria-controls="collapseAjouterPaiement"
><span class="fa fa-plus"></span> Zahlung machen</span>
{% endif %}
{% if piece.client.getAvailablePoints() > 0 and piece.solde > 0 %}
<div class="collapse collapse-afectation bg-info m_t_20 p-4 {% if app.request.get('col') == 'gift' %}show{% endif %}" id="collapseAffectationPoints">
<form action="{{ path('affect_payment_piece',{'id':piece.id}) }}" method="POST">
<div class="row">
<div class="col-12">
<h4>Affectation de points fidélité</h4>
</div>
</div>
<div class="row">
<div class="col-6">
<input type="text" class="form-control" name="affectation" value="{% if app.request.get('affectation') is not null %}{{ app.request.get('affectation') }}{% else %}{{ min(piece.solde,piece.client.getAvailablePoints()) }}{% endif %}">
<input type="hidden" name="type" value="gift">
</div>
<div class="col-6">
<input type="submit" value="Speichern" class="btn btn-danger">
</div>
</div>
</form>
</div>
{% endif %}
{% if piece.client.getNotAffectedPayement() is not null and piece.solde > 0 %}
<div class="collapse bg-primary collapse-afectation m_t_20 p-4 {% if app.request.get('col') == 'affect' %}show{% endif %}" id="collapseAffectationPaiement">
<form action="{{ path('affect_payment_piece',{'id':piece.id}) }}" method="POST">
<div class="row">
<div class="col-12">
<h4>Affectation de paiement</h4>
</div>
</div>
<div class="row">
<div class="col-6">
<input type="text" class="form-control" name="affectation" value="{% if app.request.get('affectation') is not null %}{{ app.request.get('affectation') }}{% else %}{{ min(piece.solde,piece.client.getNotAffectedPayement().getRest()) }}{% endif %}">
<input type="hidden" name="type" value="affect">
</div>
<div class="col-6">
<input type="submit" value="Speichern" class="btn btn-danger">
</div>
</div>
</form>
</div>
{% endif %}
{% if piece.solde > 0 %}
<div class="collapse bg-dark collapse-afectation m_t_20 p-4 {% if app.request.get('col') == 'new' %}show{% endif %}" id="collapseAjouterPaiement">
<form action="{{ path('affect_payment_piece',{'id':piece.id}) }}" method="POST">
<div class="row">
<div class="col-12">
<h4>Zahlung Machen</h4>
</div>
</div>
<div class="row">
<div class="col-3">
<label for="typePayment">Mode de paiement</label>
<select type="text" class="form-control" id="typePayment" name="typePayment">
<option></option>
{% for mode,k in modes %}
<option value="{{ k }}" {% if k == app.request.get('typePayment') %}selected{% endif %}>{{ mode }}</option>
{% endfor %}
</select>
<input type="hidden" name="type" value="new">
</div>
<div class="col-3">
<label for="typePayment">Montant</label>
<input type="text" class="form-control" id="amountPayment" name="amountPayment" value="{% if app.request.get('amountPayment') is not null %}{{ app.request.get('amountPayment') }}{% else %}{{ piece.solde }}{% endif %}">
</div>
<div class="col-3">
<label for="datePayment">Date</label>
<input type="date" class="form-control" id="datePayment" name="datePayment" value="{% if app.request.get('datePayment') is not null %}{{ app.request.get('datePayment') }}{% else %}{{ "now"|date("Y-m-d") }}{% endif %}">
</div>
<div class="col-3">
<span class="d-block m_t_30"></span>
<input type="submit" value="Enregistrer" class="btn btn-danger">
</div>
</div>
</form>
</div>
{% endif %}
{% if piece.affectations|length > 0 %}
<table class="table table-bordered table-striped m_t_20">
<tr>
<th>N°</th>
<th>Date</th>
<th>Type</th>
<th>Montant affecté</th>
<th>Action</th>
</tr>
{% for affectation in piece.affectations %}
<tr>
<td>{{ affectation.payment.id }}</td>
<td>{{ affectation.payment.date|date('d/m/Y') }}</td>
<td>{{ affectation.payment.getTypeText() }}</td>
<td>{{ affectation.amount|number_format(2, '.', ' ') }}</td>
<td>
<a href="{{ path('payment_show',{'id':affectation.payment.id}) }}" class="btn btn-secondary"><span class="fa fa-info"></span></a>
<a href="{{ path('payment_delete_affectation',{'id':affectation.id}) }}" class="btn btn-danger confirm-button" data-message="Voulez-vous vraiment supprimer cette affectation?"><span class="fa fa-trash"></span></a>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<div class="alert alert-info m_t_20">Aucun paiement affecté pour cette facture</div>
{% endif %}
</div>
<div class="offset-lg-1 col-lg-4">
<div class="table-responsive">
<table class="table table-condensed">
{% if app.user.isSuperAdmin %}
<tr>
<th>Montant Achat</th>
<td class="text-right">{{ piece.amountBuyHT }}</td>
</tr>
<tr>
<th>Montant Marge</th>
<td class="text-right">{{ piece.amountMarge }}</td>
</tr>
{% endif %}
<tr>
<th>Montant HT</th>
<td class="text-right">{{ piece.amountHT }}</td>
</tr>
<tr>
<th>Montant Remise</th>
<td class="text-right">{{ piece.amountDiscount }}</td>
</tr>
<tr>
<th>Montant TVA</th>
<td class="text-right">{{ piece.amountTVA }}</td>
</tr>
<tr>
<th>Bon réduction</th>
<td class="text-right">{{ piece.amountDiscountTotal }}</td>
</tr>
<tr>
<th>Montant TTC</th>
<td class="text-right">{{ piece.amountTTC }}</td>
</tr>
</table>
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('js/collection_piece_line.js') }}"></script>
<script>
$('#piece_client').select2();
</script>
{% endblock %}