templates/invoices.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% set currentPath = path(app.request.attributes.get('_route')) %}
  3. {% block body %}
  4. <div class="container">
  5.   <div class="row">
  6.       <div id="loader" class="col s12 progress" style="display:none"><div class="indeterminate"></div></div>
  7.       <div class="col s12">
  8.       <div class="card">
  9.           <div class="card-content">
  10.               <!-- <span class="card-title">Filters</span> -->
  11.               <div class="row">
  12.                   <h5>Gestione Ordini</h5>
  13.                   <hr/>
  14.                   <div class="row">
  15.                       <!-- ><div class="col s2">
  16.                           <select id="filter-year" name="filter-year">
  17.                               <option value="">-- Anno --</option>
  18.                             <option value="2020" selected>Anno 2020</option>
  19.                             <option value="2021">Anno 2021</option>
  20.                             <option value="2022">Anno 2022</option>
  21.                           </select>
  22.                       </div> -->
  23.                       <div class="col s3">
  24.                           <select id="filter-type" name="filter-type">
  25.                             <option value="">-- Filtra per --</option>
  26.                             <option value="invoices">Fatture</option>
  27.                             <option value="corrispettivi">Corrispettivi</option>
  28.                             <option value="not managed">Non gestiti</option>
  29.                           </select>
  30.                       </div>
  31.                       <div class="col s3">
  32.                           <label></label>
  33.                           <div id="filter-orders-ids" class="chips chips-placeholder">
  34.                               <input name="filter-orders-ids" placeholder="Filtro ID Ordini">
  35.                           </div>
  36.                       </div>
  37.                     <div class="col s3">
  38.                           <label></label>
  39.                           <div id="filter-fatture-ids" class="chips chips-placeholder">
  40.                               <input name="filter-fatture-ids" placeholder="Filtro ID Fatture">
  41.                           </div>
  42.                       </div>
  43.                   </div>
  44.                   <div class="row">
  45.                       <div class="col s2">
  46.                           <label>Da:</label>
  47.                           <input type="text" name="filter-date-from" class="datepicker">
  48.                       </div>
  49.                       <div class="col s2">
  50.                           <label>A:</label>
  51.                           <input type="text" name="filter-date-to" class="datepicker">
  52.                       </div>
  53.                       <div class="col s2">
  54.                           <button type="button" onclick="Manebi.getInvoices()" name="submit-filter" class="btn waves-effect waves-light">RECUPERA</button>
  55.                       </div>
  56.                   </div>
  57.               </div>
  58.           </div>
  59.          </div>
  60.       </div>
  61.   </div>
  62.   <div class="row">
  63.       <div class="col s12">
  64.       <div class="card">
  65.           <div class="card-content">
  66.               <div id="invoices-table-results">
  67.                   <div class="row">
  68.                       <div class="col s4">Risultati: <span id="invoices-table-results-total"></span></div>
  69.                       <div id="invoices-table-results-actions" class="col s8"></div>
  70.                   </div>
  71.               </div>
  72.               <div class="row">
  73.                   <div class="col s10"><div class="invoices-table-pagination"></div></div>
  74.               </div>
  75.               <table id="invoices-table" class="striped fixed_header">
  76.                   <thead></thead>
  77.                   <tbody></tbody>
  78.               </table>
  79.               
  80.               <div class="row">
  81.                   <div class="col s10"><div class="invoices-table-pagination"></div></div>
  82.                   <div class="col s2"><label for="invoices-table-page-size-list">Per pagina: <select class="invoices-table-page-size-list" name="invoices-table-page-size-list" after-render="initMaterializeSelect"></select></label></div>
  83.               </div>
  84.           </div>
  85.          </div>
  86.       </div>
  87.   </div>
  88.   <div class="row">
  89.       <div class="col s12">
  90.       <div class="card">
  91.           <div class="card-content">
  92.               {% if ordiniSenzaIncassiERimborsi %}
  93.                   <ul class="collapsible">
  94.                       <li>
  95.                           <div class="collapsible-header"><b>ATTENZIONE: ci sono {{ ordiniSenzaIncassiERimborsi|length }} Ordini che non possiedono alcun tipo di transazione (Incassi / Rimborsi)</b></div>
  96.                           <div class="collapsible-body">
  97.                               <table class="table">
  98.                                   <thead><tr><th>Ordine</th><th>Tipo</th><th>Numero</th><th>Payment Reference</th><th>Payment Method</th><th>Total</th><th>Data creazione</th></tr></thead>
  99.                                   <tbody>
  100.                                   {% for o in ordiniSenzaIncassiERimborsi %}
  101.                                       <tr>
  102.                                           <td>{{ o.Order }}</td>
  103.                                           <td>{{ o['Tipo'] }}</td>
  104.                                         <td>{{ o['Numero'] }}</td>
  105.                                           <td>{{ o['Payment Reference'] }}</td>
  106.                                           <td>{{ o['Payment Method'] }}</td>
  107.                                           <td>{{ o['Total'] }}</td>
  108.                                           <td>{{ o['Created at'] }}</td>
  109.                                       </tr>
  110.                                   {% endfor %}
  111.                                   </tbody>
  112.                               </table>
  113.                           </div>
  114.                       </li>
  115.                   </ul> 
  116.               {% endif %}
  117.           </div>
  118.       </div>
  119.   </div>
  120. </div>
  121. <!-- Modal Structure -->
  122. <div id="viewInvoiceModal" class="modal modal-fixed-footer modal-fixed-header" style="width:100%">
  123.   <div class="modal-header"></div>
  124.   <div class="modal-content"></div>
  125.   <div class="modal-footer">
  126.     <a href="#!" class="modal-close waves-effect waves-green btn btn-small">OK</a>
  127.   </div>
  128. </div>
  129. <div id="genericPopup" class="modal modal-fixed-footer modal-fixed-header">
  130.     <div class="modal-header"></div>
  131.     <div class="modal-content">
  132.         <p class="alert alert-warning">Queste sono le righe associate a questa integrazione. Verificare  dati che saranno rimossi prima di procedere alla rimozione.</p>
  133.         <hr/>
  134.         <div id="invoices-table-results">
  135.             <div class="row">
  136.                 <div class="col s4">Risultati: <span id="invoices-table-results-total"></span></div>
  137.                 <div id="invoices-table-results-actions" class="col s8"></div>
  138.             </div>
  139.         </div>
  140.         <table id="invoices-table" class="striped fixed_header">
  141.             <thead></thead>
  142.             <tbody></tbody>
  143.         </table>
  144.     </div>
  145.     <div class="modal-footer">
  146.         <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>
  147.         <a href="#!" class="modal-close waves-effect waves-green btn btn-small">CHIUDI</a>
  148. </div>
  149. {% block javascripts %}
  150. <script src="{{ asset('tmb-data-table.v1_0.min.js') }}"></script>
  151. <script>
  152. var Manebi = {};
  153. var urlAjax = "{{ currentPath }}";
  154. var filterInstances = {'collapsible': {}, 'dates': {}, 'chips': {}, 'modals': {}, 'selects': {}};
  155. var tableInvoices = null;
  156. var tableColumns =  {
  157.                     'Ordine': {'headerName': 'Order', 'value': function(data){ return '<b>' + data['Order'] + '</b>'}, 'sortable': true, 'sort-by-value': 'Order'}, 
  158.                     'Numero Fattura': {'headerName': 'Fattura', 'value': function(data){ return '<b>' + data['Numero Fattura'] + '</b>'}, 'sortable': true}, 
  159.                     'Corrispettivo': {'headerName': 'Corrispettivo', 'value': function(data){ return '<b>' + (data['Corrispettivo'] == null ? '-' : data['Corrispettivo']) + '</b>'}, 'sortable': true}, 
  160.                     'Incassi':{'headerName': 'Incassi', 'value': 'Incassi'},
  161.                     'Rimborsi':{'headerName': 'Rimborsi', 'value': 'Rimborsi'},
  162.                     'Shipping Country': {'headerName': 'Paese Sped.', 'value': 'Shipping Country', 'sortable': true},
  163.                     'Created at': {'headerName': 'Creato il', 'value': 'Created at', 'sortable': true},
  164.                     'Total Amount': {'headerName': 'Totale', 'value': function(data){ return getPrice(data.Total,2) + ' '+ getCurrencySymbol(data.Currency)}, 'type': 'float', 'sortable': true, 'sort-by-value': 'Total'},
  165.                     'Payment': {'headerName': 'Payment', 'value': 'Payment Method', 'sortable': true}, 
  166.                     'Shipping  Name': {'headerName': 'Cliente', 'value': 'Shipping Name', 'sortable': true},
  167.                     'Export': {'headerName': 'Export', 'value': function(data){
  168.                             var o = '';
  169.                             
  170.                             if(data['ftp_export_status'] == 0)
  171.                             {
  172.                                 o += '<b style="color:#00F">IN ATTESA</b>';
  173.                             }
  174.                             
  175.                             if(data['ftp_export_status'] == 100)
  176.                             {
  177.                                 o += '<b style="color:#0F0">OK</b>';
  178.                             }
  179.                             
  180.                             if(data['ftp_export_status'] == 200)
  181.                             {
  182.                                 o += '<b style="color:#F00">ERROR - '+data['ftp_export_message']+'</b>';
  183.                             }
  184.                             
  185.                             return o;
  186.                     }, 'sortable': true, 'sort-by-value': 'ftp_export_status'},
  187.                     'Actions': {'headerName': 'Actions', 
  188.                                 'value': function(data){
  189.                                             var o = '<div style="width: 100px;">\
  190.                                             <button type="button" class="btn-floating btn-small waves-effect waves-light" onclick="Manebi.getInvoice(\''+ data.Order +'\')"><i class="material-icons">search</i></button>&nbsp;&nbsp;';
  191.                                             o += '<button type="button" class="btn-floating btn-small waves-effect waves-light red" style="width: 25px;height: 25px;padding: 0px;line-height: normal;" onclick="Manebi.deleteOrder(\''+ data.Order.replace('#','') +'\')" data-id-order="'+data.Order.replace('#','')+'" >X</button>&nbsp;&nbsp;';
  192.                                             o += (data['Numero Fattura'] != '' ? ('<a href="/admin/pdf/invoices/'+ data.Order.replace('#','') +'" target="blank" class="btn-floating btn-small waves-effect waves-light red"><i class="material-icons">picture_as_pdf</i></a>') : '');
  193.                                             o += (data['Numero Fattura'] != '' ? ('<a href="/admin/pdf/invoices/'+ data.Order.replace('#','') +'?proforma_return=1" target="blank" class="btn-floating btn-small waves-effect waves-light blue"><i class="material-icons">picture_as_pdf</i></a>') : '');
  194.                                             o += '</div>';
  195.                                             
  196.                                             return o;
  197.                                         }
  198.                                 }
  199.                 };
  200. function getPrice(price, decimal)
  201. {
  202.     var price =  parseFloat(price);
  203.     return price.toFixed(decimal);
  204. }
  205. function getCurrencySymbol(cur)
  206. {
  207.     switch(cur){
  208.         case 'EUR': return '€';
  209.         case 'USD': return '$';
  210.         default: return '';
  211.     }
  212. }
  213. function toggleElement(elId){
  214.   var x = document.getElementById(elId);
  215.   
  216.   if (x.style.display === "none") {
  217.     x.style.display = "block";
  218.   } else {
  219.     x.style.display = "none";
  220.   }
  221. }
  222. function initMaterializeSelect(el) {
  223.     M.FormSelect.init(el, {});
  224. }
  225. document.addEventListener('DOMContentLoaded', function() {
  226.     //Initialize Collapsible
  227.     var elems = document.querySelectorAll('.collapsible');
  228.     
  229.     for(var i = 0; i < elems.length; i++)
  230.     {
  231.       key = typeof(elems[i].getAttribute('id')) !== "undefined" ? elems[i].getAttribute('id') : i;
  232.       filterInstances.collapsible[key] = M.Collapsible.init(elems[i]);
  233.     }
  234.   
  235.     // Initialize DatePicker
  236.     var elems = document.querySelectorAll('.datepicker');
  237.     
  238.     for(var i = 0; i < elems.length; i++)
  239.     {
  240.         key = elems[i].getAttribute('name');
  241.         filterInstances.dates[key] = M.Datepicker.init(elems[i], {autoClose: true, format: "yyyy-mm-dd", showClearBtn: true});
  242.     }
  243.     // Initialize Chips
  244.     var elems = document.querySelectorAll('.chips');
  245.     
  246.     for(var i = 0; i < elems.length; i++)
  247.     {
  248.         key = elems[i].getAttribute('id');
  249.         filterInstances.chips[key] = M.Chips.init(elems[i]);
  250.     }
  251.     // Initialize Modals
  252.     var elems = document.querySelectorAll('.modal');
  253.     
  254.     for(var i = 0; i < elems.length; i++)
  255.     {
  256.         key = elems[i].getAttribute('id');
  257.         filterInstances.modals[key] = M.Modal.init(elems[i], {'startingTop': '0%', 'endingTop': '0%', 'endingBottom': '10%'});
  258.     }
  259.     
  260.     var elems = document.querySelectorAll('select');
  261.     
  262.     for(var i = 0; i < elems.length; i++)
  263.     {
  264.         key = elems[i].getAttribute('name');
  265.         filterInstances.selects[key] = M.FormSelect.init(elems[i]);
  266.     }
  267.     
  268.     //Get Invoices
  269.     Manebi.getInvoices = function(){
  270.                             window.toggleElement('loader');
  271.                             
  272.                             filter_type = filterInstances.selects['filter-type'].el.value;
  273.                             
  274.                             $.ajax({
  275.                                 url: urlAjax,
  276.                                 dataType: "json",
  277.                                 data: {
  278.                                     'filter': 1,
  279.                                     'filter-date-from': filterInstances.dates['filter-date-from'].toString(),
  280.                                     'filter-date-to': filterInstances.dates['filter-date-to'].toString(),
  281.                                     'filter-type': filter_type,
  282.                                     'filter-fatture-ids': filterInstances.chips['filter-fatture-ids'].chipsData,
  283.                                     'filter-orders-ids': filterInstances.chips['filter-orders-ids'].chipsData
  284.                                 }
  285.                             }).then(function(data){
  286.                                 tableInvoices = new TmbDataTable('invoices-table', tableColumns, {'pageSize': 50, 'selectable': true});
  287.                                 tableInvoices.setData(data.data).generateTable();
  288.                                 
  289.                                 actions = '';
  290.                                 actions += '<button type="button" class="btn btn-small waves-effect waves-light" style="float:right;background-color:#36a700" onclick=\'Manebi.exportFile(\"' + filter_type + '\", \"exportCSVDetails\")\'><i class="material-icons">file_download</i> <span>CSV  - Dettagli</span></button>&nbsp;';
  291.                                 actions += '<button type="button" class="btn btn-small waves-effect waves-light" style="float:right;background-color:#36a700" onclick=\'Manebi.exportFile(\"' + filter_type + '\", \"exportCSV\")\'><i class="material-icons">file_download</i> <span>CSV</span></button>&nbsp;';
  292.                                 
  293.                                 if(filter_type != "")
  294.                                     actions += '<button type="button" class="btn btn-small waves-effect waves-light" style="float:right;background-color:#36a700" onclick=\'Manebi.exportFile(\"' + filter_type + '\", \"exportProfis\")\' ><i class="material-icons">import_export</i>XML PROFIS</button>&nbsp;';
  295.                                 actions += '<button type="button" class="btn btn-small waves-effect waves-light" style="float:right;background-color:#36a700;" onclick=\'Manebi.exportFile(\"' + filter_type + '\", \"exportFatturaElettronica\")\' ><i class="material-icons">import_export</i>Fattura Elettronica</button>';
  296.                                 tableInvoices.setAction(actions);
  297.                                 
  298.                                 window.toggleElement('loader');
  299.                             });
  300.                         }
  301.     // Get Invoice
  302.     Manebi.getInvoice = function(id) {
  303.         window.toggleElement('loader');
  304.         
  305.         $.ajax({
  306.                 url: urlAjax + '/' + id.replace('#',''), 
  307.                 dataType: "json"
  308.                }).then(function(data){
  309.                
  310.                        if(data.status == 'OK' && (data.data.length > 0)){
  311.                            var invoice = data.data[0];
  312.                            Manebi.viewInvoice(invoice);
  313.                        }
  314.                     
  315.                    window.toggleElement('loader');
  316.                });
  317.     }
  318.     
  319.     Manebi.viewInvoice = function(data){
  320.         var o = '<table class="table"><tbody>';
  321.         
  322.         for(var i in data)
  323.         {
  324.             if(typeof(data[i]) !== 'object')
  325.             {
  326.                 o += '<tr><td><b>'+i+'</b></td><td>'+data[i]+'</td></tr>';
  327.             }
  328.         
  329.         }
  330.         o += '</tbody></table>'; 
  331.         
  332.         if(typeof(data.products) !== "undefined")
  333.         {
  334.             o += '<div><h5>Ordered products</h5>'+'<table class="table"><tbody>';
  335.             for(var i in data.products)
  336.             {
  337.                 o += '<tr><td><b>'+i+'</b></td></tr>';
  338.             }
  339.             
  340.             o += '</tbody></table></div>'; 
  341.         }
  342.         
  343.         filterInstances.modals['viewInvoiceModal'].el.querySelector('.modal-header').innerHTML = '<h4>Dettagli ordine ('+data.Order+')</h4>';
  344.         filterInstances.modals['viewInvoiceModal'].el.querySelector('.modal-content').innerHTML = o;
  345.         filterInstances.modals['viewInvoiceModal'].open();
  346.     }
  347.     Manebi.deleteOrder = function(id_order) {
  348.         var choice;
  349.         choice = confirm("Sei sicuro di voler rimuovere l'Ordine " + id_order + " e i suoi relativi prodotti?");
  350.         if(choice) {
  351.             $.ajax({
  352.                 url: urlAjax + "/" + id_order + "/delete",
  353.                 type: "POST",
  354.                 dataType: "json",
  355.                 }).then(function(data) {
  356.                     if(data.status == "OK") {
  357.                         alert('Ordine eliminato!');
  358.                     }else{
  359.                         alert(data.message);
  360.                     }
  361.                      Manebi.getInvoices(); 
  362.                 });
  363.         }
  364.     }
  365.     
  366.     // Export Invoices in Profis XML
  367.     Manebi.exportFile = function(filter_type, export_type) {
  368.             var form = document.createElement("form");
  369.             
  370.             form.setAttribute("id", "export-profis");
  371.             form.method = "POST";
  372.             form.action = urlAjax;
  373.             form.target = '_blank';    
  374.             
  375.             document.body.appendChild(form);
  376.             
  377.             f = document.createElement("input");f.type='hidden';
  378.             f.setAttribute('name', export_type);f.setAttribute('value', 1);
  379.             form.appendChild(f);
  380.             
  381.             f = document.createElement("input");f.type='hidden';
  382.             f.setAttribute('name', 'filter');f.setAttribute('value', 1);
  383.             form.appendChild(f);
  384.             
  385.             f = document.createElement("input");f.type='hidden';
  386.             f.setAttribute('name', 'filter-date-from');f.setAttribute('value', filterInstances.dates['filter-date-from'].toString());
  387.             form.appendChild(f);
  388.             
  389.             f = document.createElement("input");f.type='hidden';
  390.             f.setAttribute('name', 'filter-date-to');f.setAttribute('value', filterInstances.dates['filter-date-to'].toString());
  391.             form.appendChild(f);
  392.             
  393.             filter_type = filterInstances.selects['filter-type'].el.value;
  394.             
  395.             f = document.createElement("input");f.type='hidden';
  396.             f.setAttribute('name', 'filter-type');f.setAttribute('value', filter_type);
  397.             form.appendChild(f);
  398.             
  399.             chips = filterInstances.chips['filter-orders-ids'].chipsData;
  400.             
  401.             for(var i=0; i < chips.length; i++){
  402.                 f = document.createElement("input");f.type='hidden';
  403.                 f.setAttribute('name', 'filter-orders-ids['+i+'][tag]');f.setAttribute('value', chips[i].tag);
  404.                 form.appendChild(f);
  405.             }
  406.             
  407.             chips = filterInstances.chips['filter-fatture-ids'].chipsData;
  408.             
  409.             for(var i=0; i < chips.length; i++){
  410.                 f = document.createElement("input");f.type='hidden';
  411.                 f.setAttribute('name', 'filter-fatture-ids['+i+'][tag]');f.setAttribute('value', chips[i].tag);
  412.                 form.appendChild(f);
  413.             }
  414.             form.appendChild(f);            
  415.             form.submit();
  416.     }                
  417.   });
  418. </script>
  419. {% endblock %}
  420. <style>
  421. td, th {
  422.     padding: 2px 5px;
  423.     font-size: 0.9rem;
  424. }
  425. th.sortable {
  426.     text-decoration: underline;
  427. }
  428. th.sortable.asc::after {
  429.     content: '\2b61';
  430. }
  431. th.sortable.desc::after {
  432.     content: '\2b63';
  433. }
  434. table.striped > thead > tr{
  435.     background-color: #e4e4e4;
  436.     border-bottom: 1px solid #CCC !important;
  437. }
  438. tbody > tr > td:first-child{
  439.     background-color: #e4e4e4;
  440. }
  441. tr.selectable:hover > td{
  442.     cursor: pointer;
  443.     background-color: #BBB;
  444. }
  445. .modal {
  446.    max-height: 100%;
  447.    width:95%;
  448. }
  449. .moda.modal-header {
  450.    box-shadow: 1px 1px 5px #DDD;
  451.    padding: 3px;
  452. }
  453. .modal.modal-fixed-footer {
  454.    height: 90%;
  455. }
  456. .invoices-table-pagination {
  457.     text-align: center;
  458. }
  459. .invoices-table-pagination .page {
  460.     display: inline;
  461.     padding: 8px;
  462. }
  463. .invoices-table-pagination .page a {
  464.     color: #000;
  465. }
  466. .invoices-table-pagination .page.active a {
  467.     font-weight: bold;
  468.     padding: 5px;
  469.     text-decoration: underline;
  470. }
  471. div.select-wrapper{
  472.     display:inline-block;
  473. }
  474. </style>
  475. {% endblock %}