{% extends 'base.html.twig' %}
{% block body %}
<div class="container">
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">Importa CSV Shopify</span>
<form action="{{ path('invoices_shopify_import') }}" method="POST" enctype="multipart/form-data">
<p>Da questa sezione hai la possibilità di importare un file CSV di Shopify, ed ottenere un file da importare in Dashboard.</p>
<div class="file-field input-field">
<div class="btn">
<span>Seleziona un file</span>
<input type="file" name="file-shopify-csv">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<button class="btn waves-effect waves-light" type="submit" name="action">Carica CSV</button>
</form>
</div>
<div class="card-content">
<span class="card-title">Importa Ordini da file CSV</span>
<form action="{{ path('invoices_import') }}" method="POST" enctype="multipart/form-data">
<p>Da questa sezione hai la possibilità di importare un file CSV delle fatture/corrispettivi, verificare quali sono gli ordini nuovi o esistenti, e confermare l'importazione.</p>
<div class="file-field input-field">
<div class="btn">
<span>Seleziona un file</span>
<input type="file" name="file-csv">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<button class="btn waves-effect waves-light" type="submit" name="action">Carica CSV</button>
</form>
</div>
</div>
</div>
</div>
{% if checkNumerazioneFatture|length > 0 %}
<div id="checkNumerazioneFatture" class="card">
<div class="card-content" style="color:#F00">
<p class="alert alert-danger">ATTENZIONE! Il check sulla numerazione delle fatture per l'anno in corso ha restituito un errore:</p>
<hr/>
<p><b>Ultima fattura corretta: </b> {{ checkNumerazioneFatture['ultima_fattura_ok'] }} (Ordine {{ checkNumerazioneFatture['ultimo_ordine_ok'] }} del {{ checkNumerazioneFatture['ultima_fattura_ok_data']|date('Y-m-d') }})</p>
<p><b>Fattura errata: </b> {{ checkNumerazioneFatture['error_fattura'] }} (Ordine {{ checkNumerazioneFatture['error_order'] }} del {{ checkNumerazioneFatture['error_fattura_data']|date('Y-m-d') }})</p>
</div>
</div>
{% endif %}
{% if stats is not empty %}
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">Anteprima Importazione CSV</span>
<table class="striped">
<thead>
<tr><th></th><th>Total</th><th>IDs</th></tr>
</thead>
<tbody>
<tr>
<td><b style="color:#DD0">Nuovi</b></td>
<td><b>{{ stats.new }}</b></td>
<td>
{% for s in stats.new_ids %}
<i>{{ s }}</i>
{% endfor %}
</td>
</tr>
<tr>
<td><b style="color:#880">Esistenti</b></td>
<td><b>{{ stats.exist }}</b></td>
<td>
{% for s in stats.exist_ids %}
<i>{{ s }}</i>
{% endfor %}
</td>
</tr>
</tbody>
</table>
<hr/>
{% if check_vat_errors|length > 0 %}
<h4> Verifica Aliquote IVA</h4>
{% for check in check_vat_errors %}
<div class="card-content" style="border: 1px solid">
<table>
<thead>
<tr>
<th>Ordine</th>
<th>Tax Rate Shopify</th>
<th>Tax Rate Paese (Dashboard) </th>
<th>Tax Rate Provincia (Dashboard) </th>
<th>Order Vat Rate (File) </th>
<th>Stato</th>
</tr>
</thead>
<tbody>
<tr class="{% if check['IsError'] != "OK" %}error{% endif %}">
<td>{{ check['Order'] }}</td>
<td>{{ check['Country'] }} {{ check['Shopify Country Rate'] }}%</td>
<td>{{ check['Shipping Country'] }} {{ check['Manebi Country Rate'] }}%</td>
<td>{{ check['Shipping Country'] }} {{ check['Province Tax Rate'] }}%</td>
<td>{{ check['OrderVatRate'] }}%</td>
<td><span class="">
{% if check['IsError'] == 'ERROR-ORDERVATRATE-DIFF-PROVINCETAXRATE' %}Order Vat Rate specificato ({{ check['OrderVatRate'] }}%) è diverso da quello della Provincia ({{ check['Province Tax Rate'] }}%){% endif %}
{% if check['IsError'] == 'ERROR-ORDERVATRATE-NULL' %}Order Vat Rate non è specificato{% endif %}
{% if check['IsError'] == 'ERROR-PROVINCETAXRATE-NULL' %}Vat Rate della Provincia non specificata in Dashboard{% endif %}
{% if check['IsError'] == 'OK' %}OK{% endif %}
</td>
</tr>
</tbody>
</table>
</div>
{% endfor %}
{% endif %}
{% if has_vat_errors %}
<p class="alert alert-danger"> <b>ATTENZIONE! Alcuni ordini presentano un Tax Rate su Shopify diverso da quello presente sulla piattaforma</b> </p>
<hr />
<p>Il paese potrebbe aver cambiato la propria aliquota IVA, si prega di controllare e segnalare a Tembo il nuovo valore del tax rate per il Paese o la Provincia.
</div>
{% else %}
<form action="{{ path('invoices_import') }}?loadInvoices=1" method="POST">
<button class="waves-effect waves-light btn-large" style="background-color:#bd352e" type="submit" name="action">Conferma e Carica i dati</button>
</form>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}
{% if load_results is not empty %}
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">Risultati del caricamento</span>
<table class="striped">
<thead>
<tr><th></th><th>Total</th><th>IDs</th></tr>
</thead>
<tbody>
<tr>
<td><b style="color:#DD0">Inserite</b></td>
<td><b>{{ load_results.inserted }}</b></td>
<td>
{% for s in load_results.inserted_ids %}
<i>{{ s }}</i>
{% endfor %}
</td>
</tr>
<tr>
<td><b style="color:#880">Modificate</b></td>
<td><b>{{ load_results.modified }}</b></td>
<td>
{% for s in load_results.modified_ids %}
<i>{{ s }}</i>
{% endfor %}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endif %}
<div class="row">
<hr />
</div>
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">Log importazioni Fatture/Corrispettivi</span>
<p>Da questa sezione puoi annullare l'ultima importazione.</p>
<table class="table table-striped">
<thead>
<tr>
<th>ID Importazione</th>
<th>File</th>
<th>Righe caricate</th>
<th>Righe importate</th>
<th>Data Upload File</th>
<th>Data Conferma Importazione</th>
<th>Data Eliminazione Importazione</th>
<th></th>
</tr>
</thead>
<tbody>
{% for i in importazioni %}
<tr>
<td>{{ i.id }}</td>
<td>{{ i.filename }}</td>
<td>{{ i.rows_loaded }}</td>
<td>{{ i.rows_processed }}</td>
<td>{{ i.date_upload }}</td>
<td>{{ i.date_import }}</td>
<td>{{ i.date_delete }}</td>
<td> {% if i.date_delete == NULL %}<button type="button" class="btn btn-red" style="background-color:#F00" onclick="Manebi.getInvoices({{ i. id }})"> X </button>{% endif %} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div id="genericPopup" class="modal modal-fixed-footer modal-fixed-header">
<div class="modal-header"></div>
<div class="modal-content">
<p class="alert alert-warning">Queste sono le righe associate a questa integrazione. Verificare dati che saranno rimossi prima di procedere alla rimozione.</p>
<hr/>
<div id="invoices-table-results">
<div class="row">
<div class="col s4">Risultati: <span id="invoices-table-results-total"></span></div>
<div id="invoices-table-results-actions" class="col s8"></div>
</div>
</div>
<table id="invoices-table" class="striped fixed_header">
<thead></thead>
<tbody></tbody>
</table>
</div>
<div class="modal-footer">
<a id="button-delete-log-imports" href="#!" class="waves-effect waves-red btn btn-small" style="background-color: #F00" onclick="deleteLogImports(this)" data-id-log-imports="">CONFERMA ELIMINAZIONE DEI DATI DI QUESTA INTEGRAZIONE</a>
<a href="#!" class="modal-close waves-effect waves-green btn btn-small">CHIUDI</a>
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('tmb-data-table.v1_0.min.js') }}"></script>
<script>
var Manebi = {};
var urlAjax = "{{ path('invoices_main') }}";
var invoicesTableColumns = {
'Order': {'headerName': 'Ordine', 'value': 'Order', 'sortable': true},
'Numero Fattura': {'headerName': 'Numero Fattura', 'value': 'Numero Fattura', 'sortable': true},
'Corrispettivo': {'headerName': 'Corrispettivo', 'value': 'Corrispettivo', 'sortable': true},
'Pagato il': {'headerName': 'Pagato il', 'value': 'Paid at', 'sortable': true},
}
//Get Invoices
Manebi.getInvoices = function(id_log_imports)
{
$.ajax({
url: urlAjax,
dataType: "json",
data: {
'filter': 1,
'filter-id-log-imports': id_log_imports
}
}).then(function(data) {
var actions = '';
tableIncassiPos = new TmbDataTable('invoices-table', invoicesTableColumns, {'pageSize': 100, 'selectable': true});
tableIncassiPos.setData(data.data).generateTable();
popup = M.Modal.init(document.getElementById('genericPopup'), {'startingTop': '0%', 'endingTop': '0%', 'endingBottom': '10%'});
$("#button-delete-log-imports").attr("data-id-log-imports", id_log_imports);
popup.open();
//window.toggleElement('loader');
});
}
function deleteLogImports(el)
{
var id_log_imports = $(el).attr('data-id-log-imports');
$.ajax({
url: "{{ path('invoices_import') }}/delete",
type: "POST",
dataType: "json",
data: {
'id_log_imports': id_log_imports,
}
}).then(function(data) {
var actions = '';
alert('Fatture/Corrispettivi eliminati!');
window.location = window.location.href.replace(/\#.*/, '');
});
}
</script>
{% endblock javascripts %}