{% include 'App/Kanban/Approvisionnement/_js/kanban_graph.js.twig' %} kbId = {{ kanban.id }} console.log(kbId); const arrayId = [] arrayId.push(kbId) $('#valid_cmj_update').click(function(e) { url = '{{ url("app_update_maj_cmj") }}'; $.ajax({ url: url, method: "POST", data: { token : "{{ csrf_token('app_update_maj_cmj') }}", data: arrayId }, success: function (response) { document.getElementById("valid_cmj_update").style.visibility = "hidden"; if (response.hasOwnProperty('result')){ if (response.result){ let url = "{{ url('app_kanban_board_redirect_to_kanban_type', {'kanbanid': '__00__'}) }}"; window.location = url.replace('__00__', kbId); } } }, error: function () { console.log("error") } }) }); nbJours = {{ kanban.familleCmj.nbJours }}; consoPeriode = {{ kanban.consoPeriode }} activeCmjQuantity = {{ kanban.activeCmjQuantity }}; cmj_calc = {{ kanban.cmj }}; if ((nbJours == null) ? "0" : parseFloat(Math.abs(((activeCmjQuantity / nbJours * 100) / cmj_calc - 100)), 2, ',', '') > 20) { document.getElementById("activeCmj").style.color = "red"; document.getElementById("valid_cmj_update").style.visibility = "visible"; } console.log(parseFloat(Math.abs(((activeCmjQuantity / nbJours * 100) / cmj_calc - 100)), 2, ',', '')); let input_valeur_kaban = $('#edit_prog_kanban_fab_valeurKanban'), //OK input_appro_mini = $('#edit_prog_kanban_fab_approMini'), input_sm_valeur = $('#edit_prog_kanban_fab_stockMiniValeur'), //OK input_kanban_decide = $('#edit_prog_kanban_fab_nombreKanbanDecide'), //OK input_kanban_calc = $('#edit_prog_kanban_fab_nombreKanbanTotal'), input_cost = $('#edit_prog_kanban_fab_prix'), //OK input_conso = $('#edit_prog_kanban_fab_consoPeriode'), //OK input_period =$('#edit_prog_kanban_fab_nombreJoursPeriode'), //OK input_kb_gap = $('#edit_prog_kanban_fab_ecart'), input_ta_total = $('#edit_prog_kanban_fab_delaiTotal'), input_le_kb_max = $('#edit_prog_kanban_fab_leKanban'), input_section_four_printer = $('#edit_prog_kanban_fab_sectionFournisseurPrinter'), input_printed_on_sticker = $('#edit_prog_kanban_fab_isPrintedOnSticker'), input_is_kanban_elec = $('#edit_prog_kanban_fab_isKanbanElectronique'), form_prog = $('#form_prog'), span_cmj = $('#cmj'), stock_table = $('#stock_table'), stock_table_body = $('#stock_table tbody'), btn_submit = $('#submit_form_prog'), data_has_change = false; ; let translators = { 'mini': "{{ 'kanban.stock_table.mini'|trans }}", 'avg': "{{ 'kanban.stock_table.avg'|trans }}", 'maxi': "{{ 'kanban.stock_table.maxi'|trans }}", 'ta_sm': "{{ 'kanban.stock_table.ta_sm'|trans }}" }; $(btn_submit).prop('disabled',true); function set_data_has_change() { data_has_change = true; $(btn_submit).removeAttr('disabled'); refresh_display(); } $('.input_group_select').change(function () { $("#edit_prog_kanban_fab_stockMiniBase input").each(function () { $(this).prop('checked', false); }); if ($(this).val() === "ue"){ $("#edit_prog_kanban_fab_stockMiniBase_0").prop('checked', true); }else if ($(this).val() === "ta"){ $("#edit_prog_kanban_fab_stockMiniBase_1").prop('checked', true); } else { $("#edit_prog_kanban_fab_stockMiniBase_2").prop('checked', true); } set_data_has_change(); }); $('#edit_prog_kanban_fab_familleCmj').change(function () { refresh_display(); $(btn_submit).removeAttr('disabled'); data_has_change = true; }); $('#edit_prog_kanban_fab_manager').change(function () { set_data_has_change(); }); $('#form_prog input').change(function(){ set_data_has_change(); }); $('#edit_prog_kanban_fab_sectionFournisseurPrinter').change(function () { refresh_display(); $(btn_submit).removeAttr('disabled'); data_has_change = true; }) let form_parsley = $(form_prog).parsley(parsley_options); $(btn_submit).click(function(){ if(data_has_change) { //let form_parsley = $(form_prog).parsley(parsley_options); $('#kanban_line_prototype').remove(); form_parsley.validate(); form_parsley.whenValid().then(function () { $(btn_submit).html(btn_spin); $(form_prog).submit(); }); } }); $(input_valeur_kaban).change(function () { // Function to recalculate all lines let vk = $(this).val(); $('#lines_collections tr').each(function () { let le_qte = $(this).data('leq'); let new_le_kb = Math.round10(parseFloat(le_qte) / vk, 0); $(this).find('.line_le_kb').html(new_le_kb); }); }); $('#edit_prog_kanban_fab_stockMiniBase input[type="radio"]').click(function () { let current_label_input = $('#stockMiniValeur_input_group_label'), obj_translator = { day: "{{ 'kanban.tab.general.select.stock_mini.days'|trans }}", ta: "{{ 'kanban.tab.general.select.stock_mini.percent'|trans }}", ue: "{{ 'kanban.tab.general.select.stock_mini.unit'|trans }}" }, value = $(this).val() if (value === 'day') $(current_label_input).html(obj_translator.day); if (value === 'ta') $(current_label_input).html(obj_translator.ta); if (value === 'ue') $(current_label_input).html(obj_translator.ue); }); {# Collection Line #} let div_prototype = $('#kanban_line_prototype'); let prototype = $(div_prototype).data('prototype'), counter = $(div_prototype).data('widget-counter'), modal_form_lines_body = $('#modal_form_lines_body'); function initModalAddLine(){ $(modal_form_lines_body).html(''); const regex = /__name__/gm; let addLineForm = prototype.replace(regex,counter); $(modal_form_lines_body).html(addLineForm); gammeCalcLeKbVal(counter); form_parsley = $(form_prog).parsley(parsley_options); } initModalAddLine(); $('#btn_confirm_add_line').click(function () { checkLineForm('edit_prog_kanban_fab_lignes_'+ counter, function (valid) { if (valid){ createLineInGammeTable(); initModalAddLine(); set_data_has_change(); handleRemoveItemCollection(); move_item(); } }); }); function createLineInGammeTable() { let section_fournisseur_code = $('#edit_prog_kanban_fab_lignes_'+counter+'_sectionFournisseur option:selected').html().split('-')[0], section_client_code = $('#edit_prog_kanban_fab_lignes_'+counter+'_sectionClient option:selected').html().split('-')[0]; if (section_fournisseur_code.codePointAt(1) === 56550) section_fournisseur_code = section_fournisseur_code.substr(2); if (section_client_code.codePointAt(1) === 56550) section_client_code = section_client_code.substr(2); let input_poste = $('#edit_prog_kanban_fab_lignes_'+ counter +'_poste'), input_delai = $('#edit_prog_kanban_fab_lignes_'+ counter +'_delai'), input_nombreLEDecide = $('#edit_prog_kanban_fab_lignes_'+ counter +'_nombreLEDecide'), input_nombreLEQuantite = $('#edit_prog_kanban_fab_lignes_'+ counter +'_nombreLEQuantite'), input_nombreLEKanban = $('#edit_prog_kanban_fab_lignes_'+ counter +'_nombreLEKanban'), input_sectionFournisseur = $('#edit_prog_kanban_fab_lignes_'+ counter +'_sectionFournisseur'), input_sectionClient = $('#edit_prog_kanban_fab_lignes_'+ counter +'_sectionClient'); let delay = parseFloat($(input_delai).val().replace(',','.')); let obj = { 'sectionFournisseur': section_fournisseur_code, 'sectionClient': section_client_code, 'poste': $(input_poste).val(), 'delai': delay, 'nombreLEDecide': $(input_nombreLEDecide).val(), 'nombreLEQuantite': $(input_nombreLEQuantite).val(), 'nombreLEKanban': $(input_nombreLEKanban).val(), 'fournisseur_val': $(input_sectionFournisseur).val(), 'client_val': $(input_sectionClient).val() }; let html_form = $(modal_form_lines_body).html(); let red_text_class = ''; if (obj.nombreLEKanban != obj.nombreLEDecide) red_text_class = ' text-red'; let html_line = ''+ ''+obj.poste+''+ ''+obj.sectionFournisseur+''+ ''+obj.sectionClient+''+ ''+obj.delai+''+ ''+obj.nombreLEKanban+''+ ''+obj.nombreLEDecide+''+ '\n' + ' \n' + ' '+ '
\n' + '
'+ ''+ html_form + '
'+ '
'+ ''+ ''; $('#lines_collections').append(html_line); $(modal_form_lines_body).html(''); // must be reload input_poste = $('#edit_prog_kanban_fab_lignes_'+ counter +'_poste'); input_delai = $('#edit_prog_kanban_fab_lignes_'+ counter +'_delai'); input_nombreLEDecide = $('#edit_prog_kanban_fab_lignes_'+ counter +'_nombreLEDecide'); input_nombreLEQuantite = $('#edit_prog_kanban_fab_lignes_'+ counter +'_nombreLEQuantite'); input_nombreLEKanban = $('#edit_prog_kanban_fab_lignes_'+ counter +'_nombreLEKanban'); input_sectionFournisseur = $('#edit_prog_kanban_fab_lignes_'+ counter +'_sectionFournisseur'); input_sectionClient = $('#edit_prog_kanban_fab_lignes_'+ counter +'_sectionClient'); $(input_poste).val(obj.poste); $(input_delai).val(obj.delai); $(input_nombreLEDecide).val(obj.nombreLEDecide); $(input_nombreLEQuantite).val(obj.nombreLEQuantite); $(input_sectionFournisseur).val(obj.fournisseur_val); $(input_sectionClient).val(obj.client_val); $(input_nombreLEKanban).val(obj.nombreLEKanban); $('#edit_prog_kanban_fab_lignes_'+counter+'_numeroOrdre').val(parseInt(counter)+1); counter++; $('#modal_form_lines').foundation('close'); return true; } //TODO Modify bc don't work function checkLineForm(div_container_id, callback){ let error = 0; const reg = /[\d+\.\,]/; $('#'+div_container_id+' input').each(function () { let attempted_type = $(this).data('parsleyType'), value = $(this).val(); if (attempted_type && attempted_type === "number" && value){ if (!value.match(reg)) { error++; $(this).addClass('is-invalid-input'); } else { $(this).removeClass('is-invalid-input'); } } if ($(this).prop('required')) { if (!value){ error++; $(this).addClass('is-invalid-input'); } else if (!$(this).hasClass('is-invalid-input')) { $(this).removeClass('is-invalid-input'); } } }) $('#'+div_container_id+' select').each(function () { let value = $(this).val(); if ($(this).prop('required')) { if (!value){ error++; $(this).addClass('is-invalid-input'); } else { $(this).removeClass('is-invalid-input'); } } }) return callback((error === 0)); } function refresh_display(){ let cmj = parseFloat({{ (kanban.consoPeriode / kanban.nombreJoursPeriode)|number_format(4,'.','') }}), kb_val = 0, appro_mini = 0, ta_total = 0, le_ue = 0, le_day = 0, le_kb = 0, le_decide = 0, sm_value = 0, sm_base = $("input:radio[name='edit_prog_kanban_fab[stockMiniBase]']:checked").val(), sm_day = 0, sm_ue = 0, sm_ta = 0, kb_start = $("input:radio[name='edit_prog_kanban_fab[renvoiEtiquetteDebut]']:checked").val(), kb_nb_calc = 0, nb_decide = 0; if($(input_conso).val()) { let conso =parseFloat($(input_conso).val().replace(',','.')); let period = 1; if($(input_period).val()){ period = parseFloat($(input_period).val().replace(',','.')); } else $(input_period).val(1); d_cmj = new Decimal(conso).dividedBy(period); cmj = d_cmj.valueOf(); } $(span_cmj).html(Math.round10(cmj, -4)); let lines_values = parseTableItems(); // update LE KB Max input $(input_le_kb_max).val(lines_values.le_decide); ta_total = lines_values.ta_total; le_kb = lines_values.le_kb; le_decide = lines_values.le_decide; kb_val = parseInt($(input_valeur_kaban).val()); if(cmj > 0) { let d_le_decide = new Decimal(lines_values.le_decide * kb_val); le_day = d_le_decide.dividedBy(cmj).valueOf(); } if(ta_total === 0 ) ta_total = 1; $(input_ta_total).val(ta_total); if($(input_sm_valeur).val()){ sm_value = parseFloat($(input_sm_valeur).val().replace(',','.')); if(sm_value && sm_base === 'ta' && ta_total ){ sm_percent = new Decimal(sm_value / 100); sm_ta = sm_value; d_sm_day = sm_percent.times(ta_total); sm_day = d_sm_day.valueOf(); if(d_sm_day && cmj){ d_sm_ue = d_sm_day.times(cmj); sm_ue = d_sm_ue.valueOf(); } } else if(sm_value && sm_base === 'ue' && cmj){ sm_ue = sm_value; d_sm_day = new Decimal(sm_value).dividedBy(cmj); sm_day = d_sm_day.valueOf(); if(ta_total){ d_sm_ta = d_sm_day.dividedBy(ta_total).times(100); sm_ta = d_sm_ta.valueOf(); } } else if(sm_value && sm_base === 'day' && ta_total){ sm_day = sm_value; d_sm_ta = new Decimal(sm_value).dividedBy(ta_total); sm_ta = d_sm_ta.times(100).valueOf(); if(cmj){ d_sm_ue = new Decimal(sm_value).times(cmj); sm_ue = d_sm_ue.valueOf(); } } } {# kanban #} if(le_day > 0 && kb_val > 0 && ta_total > 0 && cmj > 0){ d_kb_calc = new Decimal(sm_day).plus(le_day).plus(ta_total).times(cmj).dividedBy(kb_val); if(kb_start !== 'undefined') d_kb_calc = d_kb_calc.minus(parseInt(kb_start)); kb_nb_calc = d_kb_calc.valueOf(); if(kb_nb_calc >= 0) { $(input_kanban_calc).val(Math.round10(kb_nb_calc,-2)); if($(input_kanban_decide).val()){ nb_decide = parseInt($(input_kanban_decide).val()); if(nb_decide >= 0) { $(input_kb_gap).val(nb_decide-Math.round10(kb_nb_calc,0)); let ta_cmj = ta_total * cmj; let d_sm_q_mini = new Decimal(nb_decide).minus(le_decide).plus(parseInt(kb_start)).times(kb_val).minus(ta_cmj); let d_sm_q_maxi = new Decimal(d_sm_q_mini.valueOf()).plus(kb_val*le_decide); let decimals = { 'mini' : d_sm_q_mini, 'maxi' : d_sm_q_maxi, 'avg' : new Decimal(d_sm_q_mini.valueOf()).plus(d_sm_q_maxi.valueOf()).dividedBy(2), 'ta_sm' : new Decimal(ta_cmj).plus(d_sm_q_mini.valueOf()) }; let cost = ($(input_cost).val()) ? parseFloat($(input_cost).val().replace(',','.')) : 0; $(stock_table_body).html(''); ['mini','avg','maxi','ta_sm'].map(function(key){ let tr = ''; tr = tr + ''+translators[key]+''; tr = tr + ''+numberFormat(decimals[key].dividedBy(cmj).valueOf(),2)+''; tr = tr + ''+numberFormat(decimals[key].valueOf(),0)+''; tr = tr + ''+numberFormat(decimals[key].times(cost).valueOf(),2)+''; tr = tr + ''+numberFormat(decimals[key].dividedBy(kb_val).valueOf(),2)+''; tr = tr + ''; $(stock_table_body).append(tr); }); $(stock_table).show(); {# --- GRAPH --- #} if (decimals && le_day > 0 && kb_val > 0 && ta_total > 0 && cmj > 0 && kb_nb_calc > 0 && $(input_kanban_decide).val() > 0) { //refreshGraph(stocks,cmj, cost,appro_mini, ta_total, sm_day, le_ue, le_day, le_kb, ta_cmj, kb_nb_decide, kb_val, d_gap); let kanban_values = { cmj : parseFloat(cmj), kb_val : parseInt(kb_val), appro_mini : parseInt(le_day), ta : parseInt(ta_total), le_ue : parseFloat(le_ue.valueOf()), le_kb : parseFloat(le_kb), le_decide: parseFloat(le_decide), le_day : parseFloat(le_day), sm_day : parseFloat(sm_day), sm_ue : parseFloat(sm_ue), sm_ta : parseFloat(sm_ta), kb_calc : parseFloat(kb_nb_calc), kb_decide : parseInt(nb_decide), cost: parseFloat(cost), kb_start: (parseInt(kb_start) === 1) } refreshGraph(kanban_values, decimals, "FAB"); } } } } } else $(stock_table).hide(); } refresh_display(); function parseTableItems(){ let response = { 'le_q' : 0, 'le_decide' : 0, 'le_kb' : 0, 'ta_total' : 0 }; $('#lines_collections tr').each(function(){ let tr = this; let line_ta = parseFloat($(tr).find('.line_ta').html()), line_le_q = parseFloat($(tr).data('leq')), line_le_kb = parseFloat($(tr).find('.line_le_kb').html()), line_le_decide = parseFloat($(tr).find('.line_le_dcd').html()); if(typeof line_ta == 'number') response.ta_total = response.ta_total + line_ta; if(typeof line_le_kb == 'number' && line_le_kb > response.le_kb ) response.le_kb = line_le_kb; if(typeof line_le_decide == 'number' && line_le_decide > response.le_decide ) response.le_decide = line_le_decide; if(typeof line_le_q == 'number' && line_le_q > response.le_q ) response.le_q = line_le_q; }); return response; } $('.graph-container').css({opacity:1}); {#gammeCalcLeKbVal(counter);#} function gammeCalcLeKbVal(key) { let input_le_qte = $('#edit_prog_kanban_fab_lignes_'+key+'_nombreLEQuantite'), input_le_kb = $('#edit_prog_kanban_fab_lignes_'+key+'_nombreLEKanban'), input_le_dcd = $('#edit_prog_kanban_fab_lignes_'+key+'_nombreLEDecide'), vk = parseFloat($(input_valeur_kaban).val())||1; const reg = /^\d+$/; let value_le_qte = $(input_le_qte).val(); if(value_le_qte.match(reg)){ let le_kb_value = Math.round10(parseFloat($(input_le_qte).val()) / vk, 0); $(input_le_kb).val(le_kb_value); if(!$(input_le_dcd).val()) $(input_le_dcd).val(le_kb_value); } $(input_le_qte).unbind('change'); $(input_le_qte).bind('change', function(){ gammeCalcLeKbVal(key); }); } let modal_confirm_delete_line = $('#modal_confirm_delete_line'), btn_confirm_delete_line = $('#btn_confirm_delete_line'); function handleRemoveItemCollection(){ $('.remove-item-collection').click(function(){ let tr = $(this).closest('tr'); $(modal_confirm_delete_line).foundation('open'); $(btn_confirm_delete_line).unbind('click'); $(btn_confirm_delete_line).bind('click', function(){ tr.remove(); $(modal_confirm_delete_line).foundation('close'); set_data_has_change(); }); }); } handleRemoveItemCollection(); let modal_form_edit_line = $('#modal_form_edit_line'), modal_form_edit_line_body = $('#modal_form_edit_line_body') btn_confirm_edit_line = $('#btn_confirm_edit_line'), current_line_order = '_name_', current_tr = null, current_row = null, current_form_edit = null item_proto_container = null; $('.edit-item-collection').click(function () { // todo get the proto of this element $(this).closest('td').find("div.hide"); current_row = $(this).closest('td').find("div.hide"); current_line_order = $(current_row).data('lineIndex'); current_form_edit = $('#edit_prog_kanban_fab_lignes_'+current_line_order); current_tr = $(this).closest('tr'); $(modal_form_edit_line_body).html(current_form_edit); gammeCalcLeKbVal(current_line_order); $(modal_form_edit_line).foundation('open'); }); $(btn_confirm_edit_line).click(function () { checkLineForm('edit_prog_kanban_fab_lignes_'+ current_line_order, function (valid) { if (valid){ let section_fournisseur_code = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_sectionFournisseur option:selected').html().split('-')[0], section_client_code = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_sectionClient option:selected').html().split('-')[0]; if (section_fournisseur_code.codePointAt(1) === 56550) section_fournisseur_code = section_fournisseur_code.substr(2); if (section_client_code.codePointAt(1) === 56550) section_client_code = section_client_code.substr(2); let input_poste = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_poste'), input_delai = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_delai'), input_nombreLEDecide = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_nombreLEDecide'), input_nombreLEQuantite = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_nombreLEQuantite'), input_nombreLEKanban = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_nombreLEKanban'), input_sectionFournisseur = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_sectionFournisseur'), input_sectionClient = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_sectionClient'); let delay = parseFloat($(input_delai).val().replace(',','.')); let obj = { 'sectionFournisseur': section_fournisseur_code, 'sectionClient': section_client_code, 'poste': $(input_poste).val(), 'delai': delay, 'nombreLEDecide': $(input_nombreLEDecide).val(), 'nombreLEQuantite': $(input_nombreLEQuantite).val(), 'nombreLEKanban': $(input_nombreLEKanban).val(), 'fournisseur_val': $(input_sectionFournisseur).val(), 'client_val': $(input_sectionClient).val() }; cleanHtmlTrAfterEditLine(current_tr) // Construct table line let red_text_class = ''; if (obj.nombreLEKanban != obj.nombreLEDecide) red_text_class = ' text-red'; let modified_html_line = ''+obj.poste+''+ ''+obj.sectionFournisseur+''+ ''+obj.sectionClient+''+ ''+obj.delai+''+ ''+obj.nombreLEKanban+''+ ''+obj.nombreLEDecide+''; current_tr.prepend(modified_html_line); $(current_row).children().append($(modal_form_edit_line_body).html()); $(modal_form_edit_line_body).html(''); //current_form_edit.html($(modal_form_edit_line_body).html()); input_poste = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_poste'); input_delai = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_delai'); input_nombreLEDecide = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_nombreLEDecide'); input_nombreLEQuantite = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_nombreLEQuantite'); input_nombreLEKanban = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_nombreLEKanban'); input_sectionFournisseur = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_sectionFournisseur'); input_sectionClient = $('#edit_prog_kanban_fab_lignes_'+ current_line_order +'_sectionClient'); $(input_poste).val(obj.poste); $(input_delai).val(parseFloat(obj.delai)); $(input_nombreLEDecide).val(obj.nombreLEDecide); $(input_nombreLEQuantite).val(obj.nombreLEQuantite); $(input_sectionFournisseur).val(obj.fournisseur_val); $(input_sectionClient).val(obj.client_val); $(input_nombreLEKanban).val(obj.nombreLEKanban); set_data_has_change(); $(modal_form_edit_line).foundation('close'); } }); }); function cleanHtmlTrAfterEditLine(tr) { $(tr).find('td').each(function () { if (!$(this).hasClass('action')){ $(this).remove(); } }); } function move_item(){ $('.move-down').unbind('click'); $('.move-down').bind('click', function () { let current_tr = $(this).closest("tr"); let next_tr = $(current_tr).next(); let order_index_current = $(current_tr).find("input.input_numero_ordre").val(); let order_index_next = $(next_tr).find("input.input_numero_ordre").val(); // update indexes $(next_tr).find("input.input_numero_ordre").val(order_index_current); $(current_tr).find("input.input_numero_ordre").val(order_index_next); $(next_tr).after($(current_tr)); set_data_has_change(); }); $('.move-up').unbind('click'); $('.move-up').bind('click', function () { let current_tr = $(this).closest("tr"); let before_tr = $(current_tr).prev(); let order_index_current = parseInt($(current_tr).find("input.input_numero_ordre").val()); let order_index_before = parseInt($(before_tr).find("input.input_numero_ordre").val()); // update indexes $(before_tr).find("input.input_numero_ordre").val(order_index_current); $(current_tr).find("input.input_numero_ordre").val(order_index_before); $(before_tr).before($(current_tr)); set_data_has_change(); }); } move_item();