{% extends 'Master/MenuBgTemplate.html.twig' %}

{% block body %}
    <div class="container-fluid">
        <div class="row">
            <div class="col">
                <h1 class="h3">
                    <i class="fa-solid fa-cut me-2"></i> {{ fsc.title }}
                </h1>
                <p>{{ trans('copy-p') }}</p>
                <form method="post" onsubmit="animateSpinner('add')">
                    {{ formToken() }}
                    <input type="hidden" name="action" value="save"/>
                    <input type="hidden" name="code" value="{{ fsc.modelCode }}"/>
                    <input type="hidden" name="model" value="{{ fsc.modelClass }}"/>
                    <div class="card shadow mb-4">
                        <div class="card-body">
                            <div class="row g-2">
                                {% if fsc.empresa.count() > 1 %}
                                    <div class="col-sm-2">
                                        {{ trans('company') }}
                                        <div class="mb-3">
                                            <select name="idempresa" class="form-select" required>
                                                {% for item in fsc.codeModel.all('empresas','idempresa','nombrecorto',false) %}
                                                    {% if item.code == fsc.model.idempresa %}
                                                        <option value="{{ item.code }}"
                                                                selected>{{ item.description }}</option>
                                                    {% else %}
                                                        <option value="{{ item.code }}">{{ item.description }}</option>
                                                    {% endif %}
                                                {% endfor %}
                                            </select>
                                        </div>
                                    </div>
                                {% endif %}
                                <div class="col-sm-2">
                                    {{ trans('date') }}
                                    <div class="mb-3">
                                        <input type="date" name="fecha" value="{{ "now" | date('Y-m-d') }}"
                                               class="form-control" required/>
                                    </div>
                                </div>
                                <div class="col-sm">
                                    {{ trans('concept') }}
                                    <div class="mb-3">
                                        <input type="text" name="concepto" value="{{ fsc.model.concepto }}"
                                               class="form-control" required/>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    {{ trans('daily') }}
                                    <div class="mb-3">
                                        <select name="iddiario" class="form-select">
                                            {% for item in fsc.codeModel.all('diarios','iddiario','descripcion') %}
                                                {% if item.code == fsc.model.iddiario %}
                                                    <option value="{{ item.code }}" selected>
                                                        {{ item.description }}
                                                    </option>
                                                {% else %}
                                                    <option value="{{ item.code }}">{{ item.description }}</option>
                                                {% endif %}
                                            {% endfor %}
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    {{ trans('channel') }}
                                    <div class="mb-3">
                                        <input type="number" name="canal" value="{{ fsc.model.canal }}"
                                               class="form-control"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-hover mb-0">
                                <thead>
                                <tr>
                                    <th>{{ trans('subaccount') }}</th>
                                    <th>{{ trans('counterpart') }}</th>
                                    <th>{{ trans('concept') }}</th>
                                    <th class="text-end">{{ trans('debit') }}</th>
                                    <th class="text-end">{{ trans('credit') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for line in fsc.model.getLines() %}
                                    <tr>
                                        <td>{{ line.codsubcuenta }}</td>
                                        <td>{{ line.codcontrapartida }}</td>
                                        <td>{{ line.concepto }}</td>
                                        <td class="text-end">{{ money(line.debe) }}</td>
                                        <td class="text-end">{{ money(line.haber) }}</td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                        <div class="card-footer">
                            <div class="row">
                                <div class="col">
                                    <a href="{{ asset(fsc.model.url()) }}" class="btn btn-spin-action btn-secondary">
                                        <i class="fa-solid fa-arrow-left me-1"></i> {{ trans('back') }}
                                    </a>
                                </div>
                                <div class="col-auto">
                                    <button type="submit" class="btn btn-spin-action btn-primary">
                                        <i class="fa-solid fa-save me-1"></i> {{ trans('save') }}
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}