function setTable( tableID, hiddenElement ){ var data=jQuery( tableID ).jqGrid('getRowData'); //this method gets all the data from grid $.each( data, function( key, value ) { value.button = ''; }); var postData = JSON.stringify(data); //using json stringify convert the data in string format document.getElementById( hiddenElement ).value = postData; } function setTableOrdini( tableID, hiddenElement ){ var data=jQuery( tableID ).jqGrid('getRowData'); //this method gets all the data from grid $.each( data, function( key, value ) { value.buttonDuplicate = ''; value.icona = ''; }); var postData = JSON.stringify(data); //using json stringify convert the data in string format document.getElementById( hiddenElement ).value = postData; } //Cell Formatter function formatViewValueMerci(cellvalue, options, rowObject) { if (rowObject.tipologiaConsegna == 'FRANCO DESTINO') return rowObject.destinatarioMerci; else return ''; } function formatViewValueMezzo(cellvalue, options, rowObject) { if (rowObject.tipologiaConsegna == 'FRANCO DESTINO') return rowObject.tipoMezzo; else return ''; } function formatCancButton(cellvalue, options, rowObject) { return ""; } function formatAddButton(cellvalue, options, rowObject) { return ""; } function formatAddDeleteButton(cellvalue, options, rowObject) { if (rowObject.active == 1) return ''; else return ''; } function formatATB(cellvalue, options, rowObject) { return "ATB"; } function formatTodayTomorrowPrice(cellvalue, options, rowObject) { if (rowObject.XWEBPriceVisibility && rowObject.XWEBPriceVisibility == "Y") return cellvalue; else return ""; } function formatTodayTomorrowPriceOK(cellvalue, options, rowObject) { if (rowObject.XWEBPriceVisibility && rowObject.XWEBPriceVisibility == "Y") return new Intl.NumberFormat('it-IT', {style: 'currency', currency: 'EUR',}).format(Number(cellvalue));//Number(cellvalue).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, "$&."); else return ""; } function formatDuplicateButton(cellvalue, options, rowObject) { var titleText = options.colModel.formatoptions.label; var tableId = options.colModel.formatoptions.tableId; var type = options.colModel.formatoptions.type; //lube o cc if( type == 'lube' ) return ""; else //cc return ""; } function duplicateRowCC(rowid, tableId) { var table = $(tableId); var newRowData = table.jqGrid('getRowData', rowid); //Incremento di 1 il maggiore customId - Metodo piu lento var newId = 0; $.each( table.jqGrid('getRowData'), function( key, value ) { if( parseInt(newId) < parseInt(value.customId)){ newId = value.customId; } }); newId = parseInt(newId) + 1; newRowData.customId = newId; newRowData.active = 0; newRowData.qty = newRowData.firstQty; newRowData.dataConsegna = null; newRowData.noteFattura = null; newRowData.noteLogistica = null; newRowData.destMerci = newRowData.destMerciDefault; newRowData.destMerciDUNS = newRowData.destMerciDUNSDefault; newRowData.destMerciSiebelId = newRowData.destMerciSiebelIdDefault; newRowData.destFatt = newRowData.destFattDefault; newRowData.destFattDUNS = newRowData.destFattDUNSDefault; newRowData.destFattSiebelId = newRowData.destFattSiebelIdDefault; newRowData.esecutorePagamento = newRowData.esecutorePagamentoDefault; newRowData.esecutorePagamentoDUNS = newRowData.esecutorePagamentoDUNSDefault; newRowData.esecutorePagamentoSiebelId = newRowData.esecutorePagamentoSiebelIdDefault; newRowData.flagRoutingFrancoBase = null; console.log(newRowData); //Incremento il rowNum var currentRowNum = table.jqGrid( 'getGridParam','rowNum' ); table.jqGrid('setGridParam', {rowNum : currentRowNum + 1} ); var res = table.jqGrid('addRowData', newId, newRowData, "after", rowid ); } function buy(rowid) { jQuery("#gridtable").jqGrid('buy', rowid, { reloadAfterSubmit : true }); } function modifyIcon(image,image) { document.images = 'images/shopping_delete.gif'; } function delRow(rowid) { jQuery("#gridtable").jqGrid('delRowData', rowid, { reloadAfterSubmit : false }); } //function editRow(rowid) { // jQuery("#gridtable").jqGrid('editRow', rowid ); //} //Funzione che esegue il check del proquota // ritorna 0 = ok; 1 = errore limite di orario; 2=errore limite qty proquota function checkProQuota(proQuota, dateSel, quantitaSelValue, noProQuotaStartTime, noProQuotaDate) { var d_sel = $.datepicker.parseDate("dd/mm/yy", dateSel); var array = proQuota.split("-"); var d_noproquota = $.datepicker.parseDate("mm/dd/yy", noProQuotaDate); var check = 0;//ok; for (var i = 0; i < array.length; i++) { var array2 = array[i].split("|"); var d_inizio = $.datepicker.parseDate("dd/mm/yy", array2[0]); var d_fine = $.datepicker.parseDate("dd/mm/yy", array2[1]); var qt = array2[2]; if ((d_inizio <= d_sel) & (d_fine >= d_sel)) { //check orario if( noProQuotaStartTime != '' && noProQuotaDate != ''){ var array3 = noProQuotaStartTime.split(":"); var limitDate = new Date(); limitDate.setHours( parseInt(array3[0]), parseInt(array3[1]), 00, 00 ); if( ( new Date() ) > limitDate ){ d_noproquota.setHours(00, 00, 00, 00); d_sel.setHours(00, 00, 00, 00); if( d_noproquota.getTime() == d_sel.getTime() ){ check = 1; //errore limite di orario; } } } //check quantita var qtyOrdinabileProQuota = parseInt(qt); if (parseInt(quantitaSelValue) > qtyOrdinabileProQuota) { check = 2; //errore limite qty proquota } } } return check; }; function checkPlafond(tableID, id, plafond, qty, dt, customId){ var qtyPlafond = dt in plafond ? Number(plafond[dt]) : -1; var data = jQuery( tableID ).jqGrid('getRowData'); var qtyOrdinata = Number(qty); $.each( data, function( key, value ) { if ((value.id != id || value.customId != customId) && value.active == 1 && value.dataConsegna == dt) qtyOrdinata += Number(value.qty); }); return qtyPlafond == -1 || qtyOrdinata <= qtyPlafond; } function checkPosizioneOrdineGPL(type, tableID, hiddenElement, msgId) { console.log(type); if(type == "PS") return checkPosizioneOrdine(tableID, hiddenElement, msgId); $(".nomultiline").css("display", "none"); $(".ivaerr").css("display", "none"); var data = jQuery( tableID ).jqGrid('getRowData'); var dataConsegnaCurrent = null; var destFattSiebelIdCurrent = null; var destMerciSiebelIdCurrent = null; var esecutorePagamentoSiebelIdCurrent = null; var tipoConsegnaCurrent = null; var quoteIdCurrent = null; var divisioneCurrent = null; var error = false; $.each( data, function( key, value ) { if (value.active == 1){ dataConsegna = value.dataConsegna; destFattSiebelId = value.destFattSiebelId; destMerciSiebelId = value.destMerciSiebelId; esecutorePagamentoSiebelId = value.esecutorePagamentoSiebelId; tipoConsegna = value.tipoConsegna quoteId = value.quoteId; divisione = value.divisione; if(quoteIdCurrent && quoteId != quoteIdCurrent){ error = true; return; } if(dataConsegnaCurrent && dataConsegna != dataConsegnaCurrent){ error = true; return; } else if(destFattSiebelIdCurrent && destFattSiebelId != destFattSiebelIdCurrent){ error = true; return; } else if(destMerciSiebelIdCurrent && destMerciSiebelId != destMerciSiebelIdCurrent){ error = true; return; } else if(esecutorePagamentoSiebelIdCurrent && esecutorePagamentoSiebelId != esecutorePagamentoSiebelIdCurrent){ error = true; return; } else if(tipoConsegnaCurrent && tipoConsegna != tipoConsegnaCurrent){ error = true; return; } else if(type != "CONTRATTO" && divisioneCurrent && divisione != divisioneCurrent){ error = true; return; } dataConsegnaCurrent = dataConsegna; destFattSiebelIdCurrent = destFattSiebelId; destMerciSiebelIdCurrent = destMerciSiebelId; esecutorePagamentoSiebelIdCurrent = esecutorePagamentoSiebelId; quoteIdCurrent = quoteId; tipoConsegnaCurrent = tipoConsegna; divisioneCurrent = divisione; } }); if(error){ $(".nomultiline").css("display", "block"); return false; } if(type == "SF"){ var ivaSel = null; $.each( data, function( key, value ) { if (value.active == 1){ var iva = value.XWEBTipoIva; if(ivaSel != null && ivaSel != iva){ error = true; return; } ivaSel = iva; } }); if(error){ $(".ivaerr").css("display", "block"); return false; } } return checkPosizioneOrdine(tableID, hiddenElement, msgId); } function checkPosizioneOrdineCC(tableID, hiddenElement, msgId) { //var xwebMultiPosition = $("#xwebMultiPosition").val(); $(".nomultiline").css("display", "none"); var data = jQuery( tableID ).jqGrid('getRowData'); var dataConsegnaCurrent = null; var destFattSiebelIdCurrent = null; var destMerciSiebelIdCurrent = null; var esecutorePagamentoSiebelIdCurrent = null; var tipoConsegnaCurrent = null; var quoteIdCurrent = null; var divisioneCurrent = null; var settMerciCurrent = null; var error = false; var fb = 0; var fd = 0; var xwebMultiPosition = null; $.each( data, function( key, value ) { console.log(value); if (value.active == 1){ var settMerci = value.settMerci; if(settMerciCurrent && settMerci != settMerciCurrent){ error = true; return; } settMerciCurrent = settMerci; xwebMultiPosition = value.xwebMultiPosition } }); if(error){ $(".diffsettmerci").css("display", "block"); return false; } $("#xwebMultiPosition").val(xwebMultiPosition); $("#xwebMultiPosition2").val(xwebMultiPosition); $.each( data, function( key, value ) { console.log(value); if (value.active == 1){ dataConsegna = value.dataConsegna; destFattSiebelId = value.destFattSiebelId; destMerciSiebelId = value.destMerciSiebelId; esecutorePagamentoSiebelId = value.esecutorePagamentoSiebelId; tipoConsegna = value.tipoConsegna; quoteId = value.quoteId; divisione = value.divisione; //console.log("tipoConsegna = " + tipoConsegna); //console.log("xwebMultiPosition = " + xwebMultiPosition); if(tipoConsegna == "FRANCO DESTINO") fd++; if(tipoConsegna == "FRANCO BASE") fb++; if(tipoConsegna == "FRANCO DESTINO" || xwebMultiPosition == "Y"){ if(quoteIdCurrent && quoteId != quoteIdCurrent){ error = true; return; } if(dataConsegnaCurrent && dataConsegna != dataConsegnaCurrent){ error = true; return; } else if(destFattSiebelIdCurrent && destFattSiebelId != destFattSiebelIdCurrent){ error = true; return; } else if(destMerciSiebelIdCurrent && destMerciSiebelId != destMerciSiebelIdCurrent){ error = true; return; } else if(esecutorePagamentoSiebelIdCurrent && esecutorePagamentoSiebelId != esecutorePagamentoSiebelIdCurrent){ error = true; return; } else if(tipoConsegnaCurrent && tipoConsegna != tipoConsegnaCurrent){ error = true; return; } else if(divisioneCurrent && divisione != divisioneCurrent){ error = true; return; } } dataConsegnaCurrent = dataConsegna; destFattSiebelIdCurrent = destFattSiebelId; destMerciSiebelIdCurrent = destMerciSiebelId; esecutorePagamentoSiebelIdCurrent = esecutorePagamentoSiebelId; quoteIdCurrent = quoteId; tipoConsegnaCurrent = tipoConsegna; divisioneCurrent = divisione; } }); if(error){ $(".nomultiline").css("display", "block"); return false; } else if(fd > 0 && fb > 0){ $(".nomultiline").css("display", "block"); return false; } console.log($("#xwebMultiPosition").val()); return checkPosizioneOrdine(tableID, hiddenElement, msgId); } //Check Posizione Sumbit Ordine CC function checkPosizioneOrdine(tableID, hiddenElement, msgId) { var data = jQuery( tableID ).jqGrid('getRowData'); var rowPresent = false; $.each( data, function( key, value ) { if (value.active == 1){ //Ne ho trovata almeno una rowPresent = true; } }); if( rowPresent ){ setTableOrdini( tableID, hiddenElement ); return true; } else { $(msgId).css("display", "inline"); $("html, body").animate({ scrollTop: $(document).height() }, 2000); return false; } } //Resetta e nasconde il messaggio di errore delle posizioni mancanti $.subscribe('resetMsgNoPosizioni', function(event, data) { $("#msgNoPosizioni").css("display", "none"); });