Commit f5794157 authored by Cosimo Antonio Volpicelli's avatar Cosimo Antonio Volpicelli
Browse files

calcolo totale prezzo acquisto e obiettivi funzione

parent 94b84e2d
Loading
Loading
Loading
Loading
+132 −20
Original line number Diff line number Diff line
@@ -301,7 +301,9 @@
                                                    <div class="col-md-4">Descrizione</div>
                                                    <div class="col-md-2">Prezzo Unitario (IVA esclusa )</div>

                                                    <div class="col-md-1 " ><button title="Aggiungi un nuovo Articolo" class="btn btn-success btn-xs add-form-row float-right"><i class="fa fa-plus-square-o"></i></button></div>
                                                    <div class="col-md-1 " >
                                                    <button title="Aggiungi un nuovo Articolo" class="btn btn-success btn-xs add-form-row float-right"><i class="fa fa-plus-square-o"></i></button>
                                                    </div>

                                             </div>
                                            <div class="row form-row added-row">
@@ -339,34 +341,65 @@
                                            </div>
                                        </div>
                                        <div class="row form-row">
                                        <div class="col-md-5"></div>
                                        <div class="col-md-4"></div>
                                            <div class="col-md-2"> <b>Prezzo Totale </b> </div>
                                            <div class="col-md-2">
                                            <div class="input-group">
                                                <span class="input-group-addon"></span>
                                                <input id="prezzototaleacquisto" type="text" name="totale" value="143,23"  class="form-control " readonly />               
                                                <input id="prezzototaleacquisto" type="text" name="totale"  readonly  min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="form-control currency"  />               
                                            </div>
                                            </div>
                                            <div class="col-md-3"></div>
                                        </div>
                                        <div class="row form-row">

                                            <div class="col-md-3">Capitolo</div>
                                            <div class="col-md-4">Obiettivo Funzione </div>
                                            <div class="col-md-2">Capitolo</div>
                                            <div class="col-md-4">Scegli Obiettivo Funzione </div>
                                            <div class="col-md-2">Prezzo (IVA esclusa )</div>
                                            <div class="col-md-3">Responsabile Fondi</div>


                                        </div> <br/>
                                        <div id="addsome" class="d-flex flex-column overflow-auto"></div>
                                        <div id="addsome" class="d-flex flex-column overflow-auto">
                                        <div class="row ofitem">
    <input type="hidden" name="idobiettivofunzione" value="ID_OB_FUN" >                     
    <div class="col-md-2"><input  type="text" name="capitolo" readonly value="CAPITOLO" class="form-control" ></div>
    <div class="col-md-4"><div class="input-group mb-3">
  <label class="input-group-text" for="inputGroupSelect01">Seleziona</label> 
  <select class="form-select" id="inputGroupSelect01">
    <option selected>Obiettivo Funzione</option>
    {% for one in ob_fun %}
        j={'id':{{one.id}},'of':'{{one.obiettivofunzione}}','descr': '{{one.descrizione}}',
        'responsabile':'{{one.emailresponsabile}}'};
        <option value="{{one.id}}">{{one.descrizione}}</option>
        obiettivifun[{{one.id}}]=j;

    {% endfor %}
    
  </select>
</div>
    <!-- <input type="text" name="obiettivofunzione" readonly value="DESCRIZIONE" class="form-control" >
    -->
    </div>
    <div class="col-md-2"> <div class="input-group"> 
        <span class="input-group-addon"></span>
        <input  type="number" name="prezzoobfun" value="0" min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="form-control currency parzialeobfun"  />
    </div>
    </div>
    <div class="col-md-3"><input type="text" name="responsabilefondiobfun" readonly value="RESPONSABILEFONDI" class="form-control" ></div>
    
    <div class="col-md-1 " >
    <button title="Aggiungi un nuovo Obiettivo" class="btn btn-success btn-xs add-obiettivo-row float-right"><i class="fa fa-plus-square-o"></i></button>
    </div>
</div> </div>
                                        <br/>
                                        <div class="row form-row">
                                        <div class="col-md-5"></div>
                                        <div class="col-md-4"></div>
                                            <div class="col-md-2"> <b>Somma dei capitoli </b> </div>
                                            <div class="col-md-2">
                                            <div class="input-group">
                                                <span class="input-group-addon"></span>
                                                <input id="sommacapitoli" type="number" name="sommacapitoli" readonly value="0.0" min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="form-control currency"  />                                            </div>
                                                <input id="sommacapitoli" type="number" name="sommacapitoli" readonly value="0.0" min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="form-control currency" style="background-color:  red!important;" />                                            </div>
                                            </div>
                                            <div class="col-md-3"></div>
                                        </div>
@@ -409,16 +442,37 @@
-->
    <script id="hidden-template" type="text/x-custom-template" >

<div class="row ">
<div class="row ofitem">
    <input type="hidden" name="idobiettivofunzione" value="ID_OB_FUN" >                     
    <div class="col-md-3"><input type="text" name="capitolo" readonly value="CAPITOLO" class="form-control" ></div>
    <div class="col-md-4"><input type="text" name="obiettivofunzione" readonly value="DESCRIZIONE" class="form-control" ></div>
    <div class="col-md-2"><input  type="text" name="capitolo" readonly value="CAPITOLO" class="form-control" ></div>
    <div class="col-md-4"><div class="input-group mb-3">
  <label class="input-group-text" for="inputGroupSelect01">Seleziona</label>
  <select class="form-select" id="inputGroupSelect01">
    <option selected>Obiettivo Funzione</option>
    {% for one in ob_fun %}
        j={'id':{{one.id}},'of':'{{one.obiettivofunzione}}','descr': '{{one.descrizione}}',
        'responsabile':'{{one.emailresponsabile}}'};
        <option value="{{one.id}}">{{one.descrizione}}</option>
        obiettivifun[{{one.id}}]=j;

    {% endfor %}
    
  </select>
</div>
    <!-- <input type="text" name="obiettivofunzione" readonly value="DESCRIZIONE" class="form-control" >
    -->
    </div>
    <div class="col-md-2"> <div class="input-group"> 
        <span class="input-group-addon"></span>
        <input  type="number" name="prezzoobfun" value="0" min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="form-control currency parzialeobfun"  />
    </div>
    </div>
    <div class="col-md-3"><input type="text" name="responsabilefondiobfun" readonly value="RESPONSABILEFONDI" class="form-control" ></div>
    <div class="col-md-1 " >
    <button title="Elimina questo Obiettivo" class=" btn btn-danger btn-xs remove-obiettivo-row float-right"><i class="fa fa-minus-square-o"></i></button>
    <button title="Aggiungi un nuovo Obiettivo" class="btn btn-success btn-xs add-obiettivo-row float-right"><i class="fa fa-plus-square-o"></i></button>

    </div>
    
</div> 
      </script>
@@ -454,7 +508,27 @@ var app3 = new Vue({

            });  
 
function sommaCapitoli(){
    tot=0;
    $('.parzialeobfun').each(function() { 
        console.log('CAMBIO',$(this).val());
        //ptot=$('#sommacapitoli').val();
        //tot = parseFloat(ptot) + ( $(this).val().length > 0  ? parseFloat($(this).val()) : 0.0 )
        tot = tot+ ( $(this).val().length > 0  ? parseFloat($(this).val()) : 0.0 );
    })
    $('#sommacapitoli').val(tot);
            console.log(parseFloat($('#prezzototaleacquisto').val()), parseFloat($('#sommacapitoli').val()) );

    if ( parseFloat($('#prezzototaleacquisto').val()) == parseFloat($('#sommacapitoli').val() ) ) {
        $('#sommacapitoli').css("background-color",'#66ff00')
    } else {
         $('#sommacapitoli').css("background-color",'red')
       
    }
}
$(document).on('keyup','.parzialeobfun'   , function(event){
    sommaCapitoli();
    /*
    tot=0;
    $('.parzialeobfun').each(function() { 
        console.log('CAMBIO',$(this).val());
@@ -463,8 +537,19 @@ $(document).on('keyup','.parzialeobfun' , function(event){
        tot = tot+ ( $(this).val().length > 0  ? parseFloat($(this).val()) : 0.0 );
    })
    $('#sommacapitoli').val(tot);
            console.log(parseFloat($('#prezzototaleacquisto').val()), parseFloat($('#sommacapitoli').val()) );

    if ( parseFloat($('#prezzototaleacquisto').val()) == parseFloat($('#sommacapitoli').val() ) ) {
        $('#sommacapitoli').css("background-color",'#66ff00')
    } else {
         $('#sommacapitoli').css("background-color",'red')
       
    }
    
    console.log('Totale',tot)
})
    */
});

var app = new Vue({
       delimiters: ['[[', ']]'],
        el: '#app',
@@ -477,6 +562,25 @@ $(document).on('click', '.add-form-row', function(e){
    cloneMore('.added-row:first');
    return false;
});
function addObiettivoFunzione(){
        neww = $("#hidden-template").html();//clone(true);
        $("#addsome").append(neww);
    }
$(document).on('click', '.add-obiettivo-row', function(e){
    e.preventDefault();
    addObiettivoFunzione();
    return false;
});
$(document).on('click', '.remove-obiettivo-row', function(e){
    e.preventDefault();
    deleteObiettivo($(this));
    return false;
}); 
function deleteObiettivo( btn) {
        btn.closest('.ofitem').remove();
        sommaCapitoli();
    return false;
};
           function cloneMore(selector) {
        var newElement = $(selector).clone(true);
        //newElement.find('.remove-form-row').parent().remove();
@@ -584,16 +688,14 @@ $('#smartwizard').smartWizard({
                $.each($("#obiettivo option:selected"), function(){  
                        indx =   $(this).val()   ;
                        neww = $("#hidden-template").html();//clone(true);
                        //alert(neww);
                        //alert(obiettivifun[indx].descr);
                        
                        //neww.find("input[name='descrizione']").val(obiettivifun[indx].descrizione);

                        oooo = neww.replace('DESCRIZIONE',obiettivifun[indx].descr);
                        ooo1 = oooo.replace('CAPITOLO',obiettivifun[indx].of);
                        ooo = ooo1.replace('RESPONSABILEFONDI',obiettivifun[indx].responsabile);
                        oo = ooo.replace('ID_OB_FUN',indx); 
                        $("#addsome").append(oo);
                        //oooo = neww.replace('DESCRIZIONE',obiettivifun[indx].descr);
                        //ooo1 = oooo.replace('CAPITOLO',obiettivifun[indx].of);
                        //ooo = ooo1.replace('RESPONSABILEFONDI',obiettivifun[indx].responsabile);
                        //oo = ooo.replace('ID_OB_FUN',indx); 
                        $("#addsome").append(neww);
                        
                        //alert($(this).val());
                        //countries.push($(this).val());
@@ -601,6 +703,16 @@ $('#smartwizard').smartWizard({
    
   
        });
    
    $( document ).on('change',"#inputGroupSelect01",function(e) {
        console.log($(this).val());
        console.log(obiettivifun[$(this).val()]);
        console.log(obiettivifun[$(this).val()].of);
        console.log($(this).closest(".ofitem").find("input[name='capitolo']")) ; //.closest("input")); //[name='capitolo'").val('pollo'); //find("input[name='idobiettivofunzione'").val('POLLO');
        $(this).closest(".ofitem").find("input[name='capitolo']").val(obiettivifun[$(this).val()].of);
        $(this).closest(".ofitem").find("input[name='responsabilefondiobfun']").val(obiettivifun[$(this).val()].responsabile);
        
    })
});
    </script>
{% endblock javascripts %}