AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.216.192
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_apps/leo/application/plugins/modulo_fiscal/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/leo/application/plugins/modulo_fiscal/assets/js/note-in-manual.js
/* global optionsProducts, _list_units, _list_units_int, _L */
var _list_units = [];
var _list_units_int = [];
var optionsProducts;
var ind_decimal = $("#_dec_point").val();
var ind_mil = $("#_mil_point").val();
var curr_code = $("#_curr_code").val();
var _url = $("#_url").val();
var execution=0;
var register=true;
loadProducts();
loadPayee();
$(document).ready(function () {
    $(".progress").hide();
    $("#emsg").hide();
    //não exibe a div de mensagem de erro
   // var editProduct = false;
    var rowNum =  $("#row_items").val();
    var rowNumDuplicates =  $("#row_duplicate").val();
    //carrega o fornecedor selecionado
   
   
    $('.amount').autoNumeric('init', {aSep: ind_mil, aDec: ind_decimal, mDec: 4, aSign: curr_code + ' '});

    //action por ajax
    $("#submit").click(function (e) {
        //valida os registros da duplicata que são obrigatórios
        e.preventDefault();
        
        
        var duplicate = document.getElementsByName('rowDuplicate[]');
        var msgNumberDocument="";
        var msgValue="";
        var msgDueDate="";
        for (i = 0; i < duplicate.length; i++) {
             if($("#document_number_"+duplicate[i].value).val().length==0){
                 msgNumberDocument=_L['module_fiscal Insert value from duplicate number'];
             }
             if($("#value_"+duplicate[i].value).val().length==0){
                 msgValue=  _L['module_fiscal Insert value from duplicate value'];
             }
             if($("#due_date_"+duplicate[i].value).val().length==0){
                 msgDueDate=_L['module_fiscal Insert value from duplicate due date'];
             }
        }
        if(msgNumberDocument.length>0 || msgValue.length>0 || msgDueDate.length>0){
            bootbox.alert(msgNumberDocument+"<br/>"+msgValue+"<br/>"+msgDueDate);
        }else{
            $complemento_url='modulo_fiscal/note_in/add-post';
            //regra para a edição
            if($("#id").val()!=""){
                 $complemento_url='modulo_fiscal/note_in/edit-post';
            }
            $('#rform').block({message: block_msg});
            var _url = $("#_url").val();
            $.ajax(
            {
                type: 'POST',
                url: _url + $complemento_url,
                data: new FormData($("#rform")[0]),
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.status === "OK") {
                      
                      
                        var number_execution=data.duplicates.length;
                        for (var i = 0; i < data.duplicates.length; i++) {
                          
                            //verificaçaõ se o dado pode ser mandado para insert/update do modulo financeiro
                            if(data.duplicates[i].insert_update==true){
                                $.post(_url+"module_billing/billing/add_expense_post/json", 
                                    {
                                        id_account: $("#payee").val(),
                                        expiry: $("#due_date_"+data.duplicates[i].row).val(),
                                        document_number:  $("#document_number_"+data.duplicates[i].row).val(),
                                        id_category: 79,
                                        id: $("#module_billing_records_"+data.duplicates[i].row).val(),
                                        occurrence:"Única",
                                        images:data.duplicates[i].attach,
                                        value:$("#value_"+data.duplicates[i].row).val(),
                                        app_fiscal_nfe_imported_id:data.app_fiscal_nfe_imported_id,
                                        row_duplicata:data.duplicates[i].row,
                                        emission_date:$("#emission_date").val(),
                                        historic:"Duplicata ("+(i+1)+"/"+number_execution+") | NF: "+$("#number_note").val()
                                    })
                                    .done(function (retornoBilling) {
                                        if ($.trim(retornoBilling) != "OK") {
                                           register=false;
                                        }
                                        verificar(number_execution,register,data);
                                    });  
                            }
                        }
                      
                      } else {
                        $('#rform').unblock();
                        var body = $("html, body");
                        body.animate({scrollTop: 0}, '1000', 'swing');
                        $("#emsgbody").html(data.msg);
                        $("#emsg").show("slow");
                    }
                }
            });
        }

    });

   function verificar(number_execution,register,data){
        execution++;
        if(execution==number_execution && register){
            $.post(_url+"modulo_fiscal/note_in/operation-successfull")
                .done(function () {
                location.reload();
            });
        }else if (execution==number_execution && !register){
            $.post(_url+"modulo_fiscal/note_in/operation-error")
                .done(function () {
                window.location = _url+"modulo_fiscal/note_in/edit/"+data.app_fiscal_nfe_imported_id;      
            });
        }
   }

    //tratamento dos itens
    $('.amount').autoNumeric('init');
    var _url = $("#_url").val();
    var $invoice_items = $('#invoice_items');
    var item_remove = $('#item-remove');
    item_remove.hide();

    $('#item-add').on('click', function () {
        $("#modal_add")[0].reset();  
        $("#modal_add_product #update_row").val("");
        $('#modal_add_product').modal('show');
        loadUnitBuy('', '#modal_add_product #note_unit_buy');
        loadUnit('', ' #modal_add_product #note_unit_sale');
        $("#note_item").html('<option disabled="disabled" selected>' + _L['Select'] + '</option>' + loadOptions(""));
        $('#modal_add_product .percent').autoNumeric('init', {aSep: ind_mil, aDec: ind_decimal, mDec: 2, aSign: ''});
        $('#modal_add_product .percent').trigger('blur');
        $('#modal_add_product .amount').autoNumeric('init', {aSep: ind_mil, aDec: ind_decimal, mDec: 2, aSign: curr_code + ' '});
        $('#modal_add_product .amount').trigger('blur');
        $('#modal_add_product #note_qty').autoNumeric('init', {aSep: '', aDec: ind_decimal, mDec: 0, aSign: ' ', pSign: 's'});
        $('#modal_add_product #note_qty').trigger('blur');
        $("#modal_add_product .description").addClass('hide');

    });

//tratamento para a unidade de compra do modal
    $("#modal_add_product #note_unit_buy").on('change', function ()
    {
        if ($(this).val() == '') {
            $('.note_addon-unity').text("un");
            $('#note_qty').autoNumeric('update', {aSep: '', aDec: ind_decimal, mDec: 0, aSign: ' ', pSign: 's'});
        } else {

            $('.note_addon-unity').text(_list_units[$(this).val()]);
            if (_list_units_int[$(this).val()] == 1) {
                $('#note_qty').autoNumeric('update', {aSep: '', aDec: ind_decimal, mDec: 0, aSign: ' ', pSign: 's'});
            } else {
                $('#note_qty').autoNumeric('update', {aSep: '', aDec: ind_decimal, mDec: 3, aSign: ' ', pSign: 's'});
            }
        }
    });
    
    // calculo o preço de custo do produto
    $(".cost_price input").on('change', function ()
    {
        var preco_unitario = parseFloat(valueString($("#modal_add_product #note_price").val())).toFixed(2);
        var quantidade = parseFloat(valueString($("#modal_add_product #note_qty").val())).toFixed(2);
        var desconto = parseFloat(valueString($("#modal_add_product #note_discount").val())).toFixed(2);
        var margem_lucro = parseFloat(valueString($("#modal_add_product #note_margem_lucro").val())).toFixed(2);
        
        var price_percent = (preco_unitario*quantidade)/valueString($("#total_nota_aux").val());
        var frete = price_percent * valueString($("#total_freight").val());
        var seguro = price_percent * valueString($("#total_safe").val());
        var outras_despesas = price_percent * valueString($("#total_other_expense").val());
        
        
        // cálculo dos impostos
        // TODO: calcular o valor do PIS e CONFINS
        var pis = 0;
        var cofins = 0;
        var total_impostos = parseFloat(valueString($("#modal_add_product #note_value_ipi").val())) + parseFloat(valueString($("#modal_add_product #note_value_icms").val())) + pis + cofins;
        
        $("#note_freight").val(formataMoeda(parseFloat(frete).toFixed(2)));
        $("#note_safe").val(formataMoeda(parseFloat(seguro).toFixed(2)));
        $("#note_other_expense").val(formataMoeda(parseFloat(outras_despesas).toFixed(2)));
        
        var custo_item = preco_unitario - desconto + (frete + seguro + outras_despesas + total_impostos)/quantidade;
        $("#note_cost_per_item").val(formataMoeda(parseFloat(custo_item).toFixed(2)));
        
        var preco_sugerido = custo_item + (custo_item * (margem_lucro/100));
        $("#note_preco_sugerido").val(formataMoeda(parseFloat(preco_sugerido).toFixed(2)));
    });
            
    $("#modal_add_product #note_item").on('change', function () {
        if ($(this).val() == 'new') {
            $("#modal_add_product .description").removeClass('hide');
            $("#modal_add_product #note_description").val('');
            $("#modal_add_product #note_code").val('');
            $("#modal_add_product #note_ncm").val('');

        }else{
            $("#modal_add_product .description").addClass('hide');
            $("#modal_add_product #note_description").val('');
            $("#modal_add_product #note_code").val(optionsProducts[$(this).val()].id);
            $("#modal_add_product #note_ncm").val(optionsProducts[$(this).val()].mercosur_nomenclature);
            $("#modal_add_product #note_ncm").trigger('blur');
            $("#modal_add_product #note_preco_atual").val(formataMoeda((optionsProducts[$(this).val()].price)));
            
            // TODO: pegar a unidade de vendo de acordo com o cadastro do produto
            // criar um campo MARGEM DE LUCRO no cadastro do produto
//            $("#modal_add_product #note_unit_sale").val(optionsProducts[$(this).val()].item_unit);
//            $("#modal_add_product #note_margem_lucro").val(optionsProducts[$(this).val()].item_margem_lucro);
        }
    });

 $("#modal_add_product #registerProduct").on('click', function (){
    var description='';
    var msg='';
    if($("#modal_add_product #note_item").val()==null){
        msg+=_L['Item Note']+" "+_L['is required'];
    }else{
        if($("#modal_add_product #note_item").val()=='new'||$("#modal_add_product #note_item").val()==''){
            description=$("#modal_add_product #note_description").val();
            if(description==''){
                msg+=_L['Item Note']+" "+_L['is required'];
            }
        }else{
            description=optionsProducts[$("#modal_add_product #note_item").val()].description;
        }
    }
     
    var unit='un';
    if ($("#modal_add_product #note_unit_buy").val()!=''){
        unit= _list_units[$("#modal_add_product #note_unit_buy").val()];    
    }
    var dados=$("#modal_add").serializeFormJSON();
    //VALIDA REQUIREDS
    if(dados.note_item==''){
        msg+=_L['module_fiscal Select one Option']+"<br/>";
    }
    if(dados.note_unit_buy==''){
        msg+=_L['module_fiscal Select unit buy']+"<br/>";
    }
    if(dados.note_unit_sale==''){
        msg+=_L['module_fiscal Select unit sale']+"<br/>";
    }
   
    if(dados.note_itens_carton==''){
        msg+=_L['module_fiscal items in the carton']+" "+_L['is required'];
    }    
    if(dados.note_qty==''){
        msg+=_L['module_fiscal Qty']+" "+_L['is required'];
    }
    if(dados.note_itens_carton==''){
        msg+=_L['Price']+" "+_L['is required'];
    } 
    if(dados.note_ncm==''){
        msg+=_L['NCM']+" "+_L['is required'];
    }
    
    if(msg!=''){
        bootbox.alert(msg);
    } else {
        // Pego o preço total dos itens
        var total_aux =  (valueString($("#modal_add_product #note_price").val()) -  valueString($("#modal_add_product #note_discount").val())) * parseFloat(valueString($("#modal_add_product #note_qty").val())).toFixed(2);
        console.log(parseFloat($("#modal_add_product #note_qty").val()).toFixed(2));
        if($("#modal_add_product #update_row").val()=='')
        {
            $invoice_items.find('tbody')
                .append(
                        '<tr class="itm_nm_ftura ">\n\
                            <td class="middle">\n\
                            \n\
                            <input type="hidden" id="icms_uf_dest_'+ rowNum + '"  name="icms_uf_dest[]" value="'+dados.note_icms_uf_dest+'">\n\
                            <input type="hidden" id="icms_uf_rem_'+ rowNum + '"  name="icms_uf_rem[]" value="'+dados.note_icms_uf_rem+'">\n\
                            <input type="hidden" id="fcp_'+ rowNum + '"  name="fcp[]" value="'+dados.note_fcp+'">\n\
                            <input type="hidden" id="ii_'+ rowNum + '"  name="ii[]" value="'+dados.note_ii+'">\n\
                            <input type="hidden" id="ncm_'+ rowNum + '"  name="ncm[]" value="'+dados.note_ncm+'">\n\
                            <input type="hidden" id="unit_sale_'+ rowNum + '" name="unit_sale[]" value="'+dados.note_unit_sale+'">\n\
                            <input type="hidden" id="unit_buy_'+ rowNum + '" name="unit_buy[]" value="'+dados.note_unit_buy+'">\n\
                            <input type="hidden" id="itens_carton_'+ rowNum + '" name="itens_carton[]" value="'+dados.note_itens_carton+'">\n\
                            <input type="hidden" id="cfop_'+ rowNum + '"  name="cfop[]" value="'+dados.note_cfop+'">\n\
                            <input type="hidden" id="cst_dest_'+ rowNum + '"  name="cst_dest[]" value="'+dados.note_cst_dest+'">\n\
                            <input type="hidden" id="freight_'+ rowNum + '"  name="freight[]" value="'+dados.note_freight+'">\n\
                            <input type="hidden" id="safe_'+ rowNum + '"  name="safe[]" value="'+dados.note_safe+'">\n\
                            <input type="hidden" id="other_expense_'+ rowNum + '"  name="other_expense[]" value="'+dados.note_other_expense+'">\n\
                            <input type="hidden" id="aliq_ipi_'+ rowNum + '"  name="aliq_ipi[]" value="'+dados.note_aliq_ipi+'">\n\
                            <input type="hidden" id="value_ipi_'+ rowNum + '"  name="value_ipi[]" value="'+dados.note_value_ipi+'">\n\
                            <input type="hidden" id="bbc_icms_value_'+ rowNum + '"  name="bbc_icms_value[]" value="'+dados.note_bbc_icms_value+'">\n\
                            <input type="hidden" id="bbc_icms_'+ rowNum + '" name="bbc_icms[]" value="'+dados.note_bbc_icms+'">\n\
                            <input type="hidden" id="value_icms_'+ rowNum + '" name="value_icms[]" value="'+dados.note_value_icms+'">\n\
                            <input type="hidden" id="aliq_icms_'+ rowNum + '" name="aliq_icms[]" value="'+dados.note_aliq_icms+'">\n\
                            <input type="hidden" id="value_icms_st_'+ rowNum + '" name="value_icms_st[]" value="'+dados.note_value_icms_st+'">\n\
                            <input type="hidden" id="imp_federal_'+ rowNum + '" name="imp_federal[]" value="'+dados.note_imp_federal+'">\n\
                            <input type="hidden" id="aliq_pis_'+ rowNum + '" name="aliq_pis[]" value="'+dados.note_aliq_pis+'">\n\
                            <input type="hidden" id="aliq_cofins_'+ rowNum + '" name="aliq_cofins[]" value="'+dados.note_aliq_cofins+'">\n\
                            <input type="hidden" id="preco_atual_'+ rowNum + '" name="preco_atual[]" value="'+dados.note_preco_atual+'">\n\
                            <input type="hidden" id="margem_lucro_'+ rowNum + '" name="margem_lucro[]" value="'+dados.note_margem_lucro+'">\n\
                            <input type="hidden" id="cost_per_item_'+ rowNum + '" name="cost_per_item[]" value="'+dados.note_cost_per_item+'">\n\
                            <input value="'+ $("#modal_add_product #note_code").val()+'" type="text" readonly class="form-control" name="product_code[]" id="product_code_' + rowNum + '">\n\
                            </td>\n\
                            <td class="middle">\n\
                                <input type="hidden" value="'+($("#modal_add_product #note_item").val()=='new'?'':optionsProducts[$("#modal_add_product #note_item").val()].id)+'"  data-row="' + rowNum + '"  class="id_product" id="id_product_' + rowNum + '"  name="id_product[]">\n\
                                <input data-row="' + rowNum + '" readonly  id="description_' + rowNum + '" name="product[]"  class="form-control " value="'+description+'">\n\
                            </td>  \n\
                            <td class="middle">\n\
                                 <input type="text" id="qty_unit_' + rowNum + '" readonly class="form-control" value="'+ $("#modal_add_product #note_qty").val()+unit +'"> \n\
                                 <input type="hidden"  readonly class="form-control"  value="'+ $("#modal_add_product #note_qty").val()+'"  name="qty[]" id="qty_' + rowNum + '">\n\
                            </td><td class="middle">\n\
                            <input  type="text" readonly id="item_price_' + rowNum + '"  value="'+ $("#modal_add_product #note_price").val()+'" class="form-control item_price_' + rowNum + ' am" name="amount[]" data-row="' + rowNum + '" >\n\
                            </td> \n\\n\
                            <td class="middle">\n\
                            <input type="text" readonly id="item_discount_' + rowNum + '"  value="'+ $("#modal_add_product #note_discount").val()+'" class="form-control item_discount item_discount' + rowNum + ' am" name="item_discount[]"></td>\n\
                            <td class="ltotal middle"><input type="text" value="'+total_aux+'"  id="lvtotal' + rowNum + '" class="form-control lvtotal lvtotal' + rowNum + ' am" readonly ></td>  \n\
                            <td class="middle col-xs-1">    <span class="btn btn-success btn-xs edit_product" id="edit_product' + rowNum + '"  data-row="' + rowNum + '" ><i class="fa fa-edit"></i> </span> <span class="btn btn-danger btn-xs delete_product" data-row="' + rowNum + '" ><i class="fa fa-trash"></i> </span></td></tr>'
                );
                    
                $('#lvtotal' + rowNum + '').autoNumeric('init', {aSep: ind_mil, aDec: ind_decimal, mDec: 2, aSign: curr_code + ' '});
                rowNum++;
            } else {
                var rowUpdate=$("#modal_add_product #update_row").val();
                $("#icms_uf_dest_"+ rowUpdate).val( dados.note_icms_uf_dest);
                $("#icms_uf_rem_"+ rowUpdate).val( dados.note_icms_uf_rem);
                $("#fcp_"+ rowUpdate).val( dados.note_fcp);
                $("#ii_"+ rowUpdate).val( dados.note_ii);
                $("#ncm_"+ rowUpdate).val( dados.note_ncm);
                $("#unit_sale_"+ rowUpdate).val(dados.note_unit_sale);
                $("#unit_buy_"+ rowUpdate).val(dados.note_unit_buy);
                $("#itens_carton_"+ rowUpdate).val(dados.note_itens_carton);
                $("#cfop_"+ rowUpdate).val(dados.note_cfop);
                $("#cst_dest_"+ rowUpdate).val(dados.note_cst_dest);
                $("#freight_"+ rowUpdate).val(dados.note_freight);
                $("#safe_"+ rowUpdate).val(dados.note_safe);
                $("#other_expense_"+ rowUpdate).val(dados.note_other_expense);
                $("#aliq_ipi_"+ rowUpdate).val(dados.note_aliq_ipi);
                $("#value_ipi_"+ rowUpdate).val(dados.note_value_ipi);
                $("#bbc_icms_value_"+ rowUpdate).val(dados.note_bbc_icms_value);
                $("#bbc_icms_"+ rowUpdate).val(dados.note_bbc_icms);
                $("#value_icms_"+ rowUpdate).val(dados.note_value_icms);
                $("#aliq_icms_"+ rowUpdate).val(dados.note_alic_icms);
                $("#value_icms_st_"+ rowUpdate).val(dados.note_value_icms_st);
                $("#imp_federal_"+ rowUpdate).val(dados.note_imp_federal);
                $("#aliq_pis_"+ rowUpdate).val(dados.note_aliq_pis);
                $("#aliq_cofins_"+ rowUpdate).val(dados.note_aliq_cofins);
                $("#product_code_"+ rowUpdate).val(dados.note_code);
                $("#id_product_"+ rowUpdate).val(optionsProducts[$("#modal_add_product #note_item").val()].id);
                $("#description_"+ rowUpdate).val(description);
                $("#qty_unit_"+ rowUpdate).val(dados.note_qty+unit);
                $("#qty_"+ rowUpdate).val(dados.note_qty);
                $("#item_price_"+ rowUpdate).val(dados.note_price);
                $("#item_discount_"+ rowUpdate).val(dados.note_discount);
                $("#lvtotal"+ rowUpdate).val(total_aux);
                $("#lvtotal"+ rowUpdate).autoNumeric('update', {aSep: ind_mil, aDec: ind_decimal, mDec: 2, aSign: curr_code + ' '});
                
            }
                
            $('[data-toggle="tooltip"]').tooltip();
            $('#modal_add_product').modal('hide');
        }
        var products = document.getElementsByName('id_product[]');
        $('#n_itens').val(products.length);
        updateTotais();
 });
            


    $invoice_items.on("click", ".edit_product", function (e) {
        var rowUpdate=$(this).attr('data-row');
        $("#modal_add")[0].reset();        
        $('#modal_add_product').modal('show');
        loadUnitBuy( $("#unit_buy_"+ rowUpdate).val(), '#note_unit_buy');
        loadUnit( $("#unit_sale_"+ rowUpdate).val(), '#note_unit_sale');
        $("#note_item").html('<option disabled="disabled" selected>' + _L['Select'] + '</option>' + loadOptions(""));
        $('#modal_add_product .percent').autoNumeric('init', {aSep: ind_mil, aDec: ind_decimal, mDec: 2, aSign: ''});
        $('#modal_add_product .percent').trigger('blur');
        $('#modal_add_product .amount').autoNumeric('init', {aSep: ind_mil, aDec: ind_decimal, mDec: 2, aSign: curr_code + ' '});
        $('#modal_add_product .amount').trigger('blur');
        $('#modal_add_product #note_qty').autoNumeric('init', {aSep: '', aDec: ind_decimal, mDec: 0, aSign: ' ', pSign: 's'});
        $('#modal_add_product #note_qty').trigger('blur');
        
        if($("#product_code_"+ rowUpdate).val()!=''){
            $("#modal_add_product .description").addClass('hide');
        }
        $("#modal_add_product #update_row").val(rowUpdate);
        
        if($("#icms_uf_dest_"+ rowUpdate).val()!=''){    
            $('#note_icms_uf_dest').val($("#icms_uf_dest_"+ rowUpdate).val());
        }
        if($("#icms_uf_rem_"+ rowUpdate).val()!=''){    
            $('#note_icms_uf_rem').val($("#icms_uf_rem_"+ rowUpdate).val());
        }
        if($("#fcp_"+ rowUpdate).val()!=''){    
            $('#note_fcp').val($("#fcp_"+ rowUpdate).val());
        }
        if($("#ii_"+ rowUpdate).val()!=''){    
            $('#note_ii').val($("#ii_"+ rowUpdate).val());
        }
        if($("#ncm_"+ rowUpdate).val()!=''){    
            $('#note_ncm').val($("#ncm_"+ rowUpdate).val());
        }
        
        if($("#unit_sale_"+ rowUpdate).val()!=''){
            $('#unit_sale').val($("#unit_sale_"+ rowUpdate).val());
        }
        if($("#unit_buy_"+ rowUpdate).val()!=''){
            $('#unit_buy').val($("#unit_buy_"+ rowUpdate).val());
        }
        if($("#itens_carton_"+ rowUpdate).val()!=''){  
            $('#note_itens_carton').val($("#itens_carton_"+ rowUpdate).val());
        }
        if($("#cfop_"+ rowUpdate).val()!=''){
            $('#note_cfop').val($("#cfop_"+ rowUpdate).val());
        }
        if($("#cst_dest_"+ rowUpdate).val()!=''){
           $('#note_cst_dest').val(  $("#cst_dest_"+ rowUpdate).val());
        }
        if($("#freight_"+ rowUpdate).val()!=''){
            $('#note_freight').val(  $("#freight_"+ rowUpdate).val());
        }
        if($("#safe_"+ rowUpdate).val()!=''){
            $('#note_safe').val(   $("#safe_"+ rowUpdate).val());
        }
        if($("#other_expense_"+ rowUpdate).val()!=''){
            $('#note_other_expense').val(   $("#other_expense_"+ rowUpdate).val());
        }
        if($("#aliq_ipi_"+ rowUpdate).val()!=''){
             $('#note_aliq_ipi').val(    $("#aliq_ipi_"+ rowUpdate).val());
        }
        if($("#value_ipi_"+ rowUpdate).val()!=''){
            $('#note_value_ipi').val(   $("#value_ipi_"+ rowUpdate).val());
        }
        if($("#bbc_icms_value_"+ rowUpdate).val()!=''){
            $('#note_bbc_icms_value').val(    $("#bbc_icms_value_"+ rowUpdate).val());
        }
        if($("#bbc_icms_"+ rowUpdate).val()!=''){
            $('#note_bbc_icms').val($("#bbc_icms_"+ rowUpdate).val());
        }
        if($("#value_icms_"+ rowUpdate).val()!=''){
            $('#note_value_icms').val($("#value_icms_"+ rowUpdate).val());
        }
        if($("#aliq_icms_"+ rowUpdate).val()!=''){
            $('#note_aliq_icms').val($("#aliq_icms_"+ rowUpdate).val());
        }
        if($("#value_icms_st_"+ rowUpdate).val()!=''){
            $('#note_value_icms_st').val($("#value_icms_st_"+ rowUpdate).val());
        }
        if($("#imp_federal_"+ rowUpdate).val()!=''){
            $('#note_imp_federal').val($("#imp_federal_"+ rowUpdate).val());
        }
        if($("#aliq_pis_"+ rowUpdate).val()!=''){
            $('#note_aliq_pis').val($("#aliq_pis_"+ rowUpdate).val());
        }
        if($("#aliq_cofins_"+ rowUpdate).val()!=''){
            $('#note_aliq_cofins').val($("#aliq_cofins_"+ rowUpdate).val());
        }
        if($("#product_code_"+ rowUpdate).val()!=''){
            $('#note_code').val($("#product_code_"+ rowUpdate).val());
        }
        
        if($("#id_product_"+ rowUpdate).val()!=''){
            
            if($("#id_product_"+ rowUpdate).val()=='new'){
                 $('#note_item').val('new');
            }else{
            
            for (var i = 0; i < optionsProducts.length; i++) {
                if (optionsProducts[i].id ==  $("#id_product_"+ rowUpdate).val()) {
                    $('#note_item').val(i).trigger('change');
                }
            }
        }
            
           
        }    
        
        
        if($("#description_"+ rowUpdate).val()!=''){
            $('#note_description').val($("#description_"+ rowUpdate).val());
        }
        if($("#qty_"+ rowUpdate).val()!=''){
            $('#note_qty').val(      $("#qty_"+ rowUpdate).val());
        }    
        if($("#item_price_"+ rowUpdate).val()!=''){
            $('#note_price').val(    $("#item_price_"+ rowUpdate).val());
        }    
        if($("#item_discount_"+ rowUpdate).val()!=''){
            $('#note_discount').val(  $("#item_discount_"+ rowUpdate).val());
        }
    });

   

    $invoice_items.on("click", ".delete_product", function (e) {
       // var val = $('.lvtotal' + $(this).attr("data-row")).val().replace(curr_code, "").replace(ind_mil, "").replace(ind_decimal, '.');
        $(this).closest('tr').remove();
        updateTotais();
    });
    updateTotais();
    
    
////DUPLICATAS
     var $tableDuplicatas = $('#table_duplicates');
      $('#item-add-duplicate').on('click', function () {
      $tableDuplicatas.find('tbody')
                .append(
                    '<tr class="">\n\
                    <td class="middle">\n\
                    \n\
                    <input value="'+ rowNumDuplicates+'" type="hidden" class="form-control" name="rowDuplicate[]" id="row_' + rowNumDuplicates + '">\n\
                    <input value="" type="hidden" class="form-control"  id="module_billing_records_' + rowNumDuplicates + '">\n\
                    <input type="text" value=""  data-row="' + rowNumDuplicates + '"  class="form-control" id="document_number_' + rowNumDuplicates + '"  name="document_number[]">\n\
                    </td>\n\
                    <td class="middle">\n\
                        <input type="text" class="form-control" id="due_date_' + rowNumDuplicates + '" name="due_date[]"  data-date-format="'+$("#_config_format_date").val()+'" data-auto-close="true" value="">        </td>  \n\
                    <td class="middle">\n\
                    <input  type="text"  id="value_' + rowNumDuplicates + '"  value="" class="form-control" name="value[]" data-row="' + rowNumDuplicates + '" >\n\
                    </td> \n\
                    <td class="middle">\n\
\n\                         <input type="hidden" id="image_'+rowNumDuplicates+'" name="image_'+rowNumDuplicates+'" value="">\n\
                    <input type="file"   class="form-control" name="attach_'+rowNumDuplicates+'"></td>\n\
                    <td class="middle col-xs-1"><span class="btn btn-danger btn-xs delete_duplicate" data-row="' + rowNumDuplicates + '" ><i class="fa fa-trash"></i> </span></td></tr>'
                );
            $('#due_date_' + rowNumDuplicates).datepicker();
            $('#value_' + rowNumDuplicates).autoNumeric('init', {aSep: ind_mil, aDec: ind_decimal, mDec: 2, aSign: curr_code + ' '});
       
            rowNumDuplicates++;
        });
        
        //remove a linha da duplicata inserida
    $tableDuplicatas.on("click", ".delete_duplicate", function (e) {
        $(this).closest('tr').remove();
    });
    
    $tableDuplicatas.on("click", ".delete_image", function (e) {
        $("#image_"+$(this).attr("data-row")).val("");
        $(".download_"+$(this).attr("data-row")).addClass("hide");
        $("#upload_"+$(this).attr("data-row")).removeClass("hide");
    });

});

function loadOptions(id) {
    var options = '';
    options = '<option value="new">' + _L['Add New'];
    +'</option>';

    for (var i = 0; i < optionsProducts.length; i++) {
        if (optionsProducts[i].id == id) {
            options += '<option value="' + i + '" selected data-product-id="' + optionsProducts[i].id + '">' + optionsProducts[i].description + '</option>';
        } else {
            options += '<option value="' + i + '" data-product-id="' + optionsProducts[i].id + '">' + optionsProducts[i].description + '</option>';
        }
    }
    return options;
}


function loadProducts() {
    $.getJSON($("#_url").val() + 'ps/ajax-list', function (j) {
        optionsProducts = j;
        console.log(optionsProducts);
    });
}
;

function updateTotais(){
  
        var freight = document.getElementsByName('freight[]');
        var safe = document.getElementsByName('safe[]');
        var other_expense = document.getElementsByName('other_expense[]');
        var value_ipi = document.getElementsByName('value_ipi[]');
        var bbc_icms_value = document.getElementsByName('bbc_icms_value[]');
        var value_icms = document.getElementsByName('value_icms[]');
        var value_icms_st = document.getElementsByName('value_icms_st[]');
        var imp_federal = document.getElementsByName('imp_federal[]');
        var aliq_cofins = document.getElementsByName('aliq_cofins[]');
        var aliq_pis = document.getElementsByName('aliq_pis[]');
        var item_discount = document.getElementsByName('item_discount[]');
        var qty = document.getElementsByName('qty[]');
        var amount = document.getElementsByName('amount[]');
        var icms_uf_dest = document.getElementsByName('icms_uf_dest[]');
        var icms_uf_rem = document.getElementsByName('icms_uf_rem[]');
        var fcp = document.getElementsByName('fcp[]');
        var ii = document.getElementsByName('ii[]');
        var products = document.getElementsByName('id_product[]');
        $('#n_itens').val(products.length);
        
        var totalFreight=0;
        var safeTotal =0;
        var other_expenseTotal =0;
        var value_ipiTotal =0;
        var bbc_icms_valueTotal =0;
        var value_icmsTotal =0;
        var value_icms_stTotal =0;
        var imp_federalTotal =0;
        var cofinsTotal =0;
        var pisTotal =0;
        var item_discountTotal =0;
        var procuctTotal =0;
        var icms_uf_destTotal = 0;
        var icms_uf_remTotal =0;
        var fcpTotal = 0;
        var iiTotal = 0; 
        var total_qty = 0; 
         
        for (i = 0; i < freight.length; i++) {
//            totalFreight = (parseFloat(totalFreight)+ value(freight[i])).toFixed(2);
//            safeTotal = (parseFloat(safeTotal)+ value(safe[i])).toFixed(2);
//            other_expenseTotal = (parseFloat(other_expenseTotal)+ value(other_expense[i])).toFixed(2);
            value_ipiTotal = (parseFloat(value_ipiTotal)+ value(value_ipi[i])).toFixed(2);    
            bbc_icms_valueTotal = (parseFloat(bbc_icms_valueTotal)+ value(bbc_icms_value[i])).toFixed(2);
            value_icmsTotal = (parseFloat(value_icmsTotal)+ value(value_icms[i])).toFixed(2);
            value_icms_stTotal = (parseFloat(value_icms_stTotal)+ value(value_icms_st[i])).toFixed(2);
            imp_federalTotal = (parseFloat(imp_federalTotal)+ value(imp_federal[i])).toFixed(2);
            item_discountTotal = (parseFloat(item_discountTotal)+ (value(item_discount[i]) * value(qty[i]))).toFixed(2);
            icms_uf_destTotal = (parseFloat(icms_uf_destTotal)+ value(icms_uf_dest[i])).toFixed(2);
            icms_uf_remTotal = (parseFloat(icms_uf_remTotal)+ value(icms_uf_rem[i])).toFixed(2);
            fcpTotal = (parseFloat(fcpTotal)+ value(fcp[i])).toFixed(2);
            iiTotal = (parseFloat(iiTotal)+ value(ii[i])).toFixed(2);
            total_qty = (parseFloat(total_qty)+ value(qty[i]));
         
            var item=parseFloat(value(qty[i])*(value(amount[i]))).toFixed(2);
        //    alert(item);
            procuctTotal=parseFloat(parseFloat(procuctTotal)+ parseFloat(item)).toFixed(2);
            cofinsTotal = (parseFloat(cofinsTotal)+ parseFloat(item * (value(aliq_cofins[i])/100))).toFixed(2);
            pisTotal = (parseFloat(pisTotal)+ parseFloat(item * (value(aliq_pis[i])/100))).toFixed(2);
        }
//        $("#total_freight").val(formataMoeda(totalFreight));
//        $("#total_safe").val(formataMoeda(safeTotal));
//        $("#total_other_expense").val(formataMoeda(other_expenseTotal));
        $("#total_discount").val(formataMoeda(item_discountTotal));
        $("#total_icms").val(formataMoeda(value_icmsTotal));
        $("#total_icms_st").val(formataMoeda(value_icms_stTotal));
        $("#total_ipi").val(formataMoeda(value_ipiTotal));
        $("#total_products").val(formataMoeda(procuctTotal));
        $("#total_pis").val(formataMoeda(pisTotal));
        $("#total_cofins").val(formataMoeda(cofinsTotal));
        $("#total_icms_uf_dest").val(formataMoeda(icms_uf_destTotal));
        $("#total_icms_uf_rem").val(formataMoeda(icms_uf_remTotal));
        $("#total_fcp").val(formataMoeda(fcpTotal));
        $("#total_ii").val(formataMoeda(iiTotal));
        $("#total_qty").val(total_qty);
        var total_nota=parseFloat((parseFloat(procuctTotal)+parseFloat(totalFreight)+parseFloat(safeTotal)+parseFloat(other_expenseTotal)+parseFloat(iiTotal)+parseFloat(value_icms_stTotal)+parseFloat(value_ipiTotal))-parseFloat(item_discountTotal)).toFixed(2);
        $("#total_nota").val(formataMoeda(total_nota));
       
        var total_tax=parseFloat(parseFloat(cofinsTotal)+parseFloat(icms_uf_destTotal)+parseFloat(icms_uf_remTotal)+parseFloat(fcpTotal)+parseFloat(iiTotal)+parseFloat(value_icmsTotal)+parseFloat(value_icms_stTotal)+parseFloat(value_ipiTotal)+parseFloat(pisTotal)).toFixed(2);
        $("#total_tax").val(formataMoeda(total_tax));

}

function value(input){
    var string=input.value;
    while (string.indexOf(ind_mil) != -1) {
        string = string.replace(ind_mil, "");
    }
    string= string.replace(curr_code, "").replace(ind_decimal,'.');
    if(string==''){
        string=0;
    }
    return parseFloat(string);
}

function valueString(string){
    if(string.length <= 0)
    {
        return 0;
    }
    while (string.indexOf(ind_mil) != -1) {
        string = string.replace(ind_mil, "");
    }
    string= string.replace(curr_code, "").replace(ind_decimal,'.');
    return parseFloat(string);
}

function formataMoeda(v) {
    v=v+"";
    v = v.replace(/\D/g, '');
    v = v.replace(/(\d{1,2})$/, ',$1');
    v = v.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
    v = v != '' && v != ',0'  ? 'R$ ' + v : 'R$ 0,00';
    return v;
}
function loadPayee() {
    //carrega os segmentos
    $.getJSON($("#_url").val() + 'contacts/ajax-listbygroup/Payee', function (j) {
        options = '<option value="">' + _L['Select Payee'];
        +'</option>';

        for (var i = 0; i < j.length; i++) {
            options += '<option value="' + j[i].id + '">' + j[i].account + '</option>';
        }
        $('#payee').html(options);
        $("#payee").val($("#payee_selected").val()).trigger("change");
    });
    
 
}

function loadUnitBuy(val, componente) {
    //carrega os grupos;
    $.getJSON($("#_url").val() + 'unit/ajax-list', function (j) {
        var options = '';
        options += '<option value="">' + _L['Select'] + '</option>';
        for (var i = 0; i < j.length; i++) {
            var selected="";
            if(val==j[i].id){
                selected='selected';
            }
            options += '<option  '+selected+'  value="' + j[i].id + '">' + j[i].initials + " - " + j[i].name + '</option>';
            //atribuo as opções retornadas a lista de unidades
            //utilizzo para mostrar o ítem correto em estoque
            _list_units[j[i].id] = j[i].initials;
            _list_units_int[j[i].id] = j[i].int_value;
        }
        $(componente).html(options);
       
    });
}
function loadUnit(val, componente) {
    //carrega os grupos;
    $.getJSON($("#_url").val() + 'unit/ajax-list', function (j) {
        var options = '';
        options += '<option value="">' + _L['Select'] + '</option>';
        for (var i = 0; i < j.length; i++) {
            var selected="";
            if(val==j[i].id){
                selected='selected';
            }
            options += '<option  '+selected+' value="' + j[i].id + '">' + j[i].initials + " - " + j[i].name + '</option>';
            //atribuo as opções retornadas a lista de unidades
            //utilizzo para mostrar o ítem correto em estoque
        }
        $(componente).html(options);
        
    });
}

Anon7 - 2022
AnonSec Team