<script type="text/javascript">
    // ACTION EDIT
    function edit(e){
        var actionDiv = $(e).closest('.div_action');
        actionDiv.find('.btn_edit').hide();
        actionDiv.find('.btn_save').show();
        actionDiv.find('.btn_batal').show();
        
        var id = $(e).attr('id');
        var nominalDiv = $('div#' + id).closest('.div_nominal');
        nominalDiv.find('.nominal_value').hide();
        nominalDiv.find('.nominal_edit').show();

        $('.btn_edit').prop("disabled", true).attr("onclick", null);
    }

    // ACTION BATAL
    function batal(e){
        var actionDiv = $(e).closest('.div_action');
        actionDiv.find('.btn_edit').show();
        actionDiv.find('.btn_save').hide();
        actionDiv.find('.btn_batal').hide();
        
        var id = $(e).attr('id');
        var nominalDiv = $('div#' + id).closest('.div_nominal');
        nominalDiv.find('.nominal_value').show();
        nominalDiv.find('.nominal_edit').hide();

        $('.btn_edit').prop("disabled", false).attr("onclick", "edit(this)");
    }

    // ACTION SIMPAN
    function save(e){
        var id            = $(e).attr('id');
        var status        = $(e).attr('data-status');
        var id_karyawan   = $(e).attr('data-id-karyawan');
        var tahun         = $(e).attr('data-tahun');
        var bulan         = $(e).attr('data-bulan');
        var id_group_m    = $(e).attr('data-id_group_m');
        var nominalDiv    = $('div#' + id).closest('.div_nominal');
        var nominal_input = nominalDiv.find('#nominal_input').val();

        var param             = {};
            param.id          = id;
            param.status      = status;
            param.id_karyawan = id_karyawan;
            param.tahun       = tahun;
            param.bulan       = bulan;
            param.id_group_m  = id_group_m;
            param.nominal     = nominal_input;

        $.ajax({
            type: 'POST',
            url: "<?= route('sales_activity.master.target.personil.save') ?>",
            data: param,
            dataType: 'JSON',
            success: function(result) {
                showMsg(result.message);
            },
            error: function() {
                showMsg("<?= $this->lang->line('error') ?>");
            }
        });
    }
</script>