<script>
	jQuery('body').on('click', '#btn_get_data', function() {
		loc_href();
	});

	function loc_href() {
		var idoutlet = jQuery('#idoutlet').val();
		var duedate = jQuery('#duedate').val();
		location.href = app_url + 'dstb_clean/add/?idoutlet=' + idoutlet + '&duedate=' + duedate;
	}



	jQuery('body').on('click', '.btn-detail-bill', function() {
		var code = jQuery(this).attr('data-code');
        var id = jQuery(this).attr('data-id');

        show_loading();
        jQuery.ajax({
            url: app_url + 'dstb_clean/get_invoice',
            type: 'POST',
            dataType: 'JSON',
            data: {
                code: code,
                id: id
            },
            success: function(response) {
                if (response.err_code == 0) {
                    jQuery('.az-modal-detail .modal-body').html(response.data);
                    show_modal('detail');
                }
                else {
                    bootbox.alert({
                        title: "<?php echo azlang('Error');?>",
                        message: response.message
                    });
                }
                hide_loading();
            },
            error: function(response) {

            }
        });
	});

	jQuery('body').on('click', '.btn-save-dstb', function() {
		show_loading();
		jQuery.ajax({
		    url: app_url + 'dstb_clean/save_dstb',
		    type: 'POST',
		    dataType: 'JSON',
		    data: jQuery('#form_dstb').serialize(),
		    success: function(response) {
		        if (response.err_code == 0) {
		            location.href = app_url + 'dstb_clean';
		        	hide_loading();
		        }
		        else {
		        	hide_loading();
		            bootbox.alert(response.err_message);
		        }
		    },
		    error: function(res){}
		});
		      
	});

	jQuery('body').on('click', '.btn-pending', function() {
		var id = jQuery(this).attr('data-id');
		show_loading();
		jQuery.ajax({
		    url: app_url + 'dstb_clean/get_pending',
		    type: 'POST',
		    dataType: 'JSON',
		    data: {
		    	id: id
		    },
		    success: function(response) {
		        hide_loading();
		        if (response.err_code == 0) {
					show_modal('pending');
					jQuery('#pending_description').val(response.data);
					jQuery('#idpending').val(id);		            
		        }
		        else {
		            bootbox.alert(response.err_message);
		        }
		    },
		    error: function(res){}
		});
		      
	});

	jQuery('body').on('click', '.btn-action-save-pending', function() {
		show_loading();
		jQuery.ajax({
		    url: app_url + 'dstb_clean/save_pending_description',
		    type: 'POST',
		    dataType: 'JSON',
		    data: jQuery('#form_pending').serialize(),
		    success: function(response) {
		        hide_loading();
		        if (response.err_code == 0) {
		            hide_modal('pending');
		        }
		        else {
		            bootbox.alert(response.err_message);
		        }
		    },
		    error: function(res){}
		});
		      
	});

	jQuery('body').on('click', '.chk-bill', function() {
		if (jQuery(this).is(':checked')) {
			jQuery(this).parents('tr').find('.btn-pending').addClass('hide');
		}
		else {
			jQuery(this).parents('tr').find('.btn-pending').removeClass('hide');
		}
	});

	jQuery('body').on('click', '.btn-stock-position', function() {
		var id = jQuery(this).attr('data-id');
		show_loading();
		jQuery.ajax({
		    url: app_url + 'dstb_clean/get_stock_position',
		    type: 'POST',
		    dataType: 'JSON',
		    data: {
		    	id: id
		    },
		    success: function(response) {
		        hide_loading();
		        if (response.err_code == 0) {
					show_modal('stock_position');
					jQuery('#stock_position').val(response.data);
					jQuery('#idstock_position').val(id);
		        }
		        else {
		            bootbox.alert(response.err_message);
		        }
		    },
		    error: function(res){}
		});
		      
	});

	jQuery('body').on('click', '.btn-action-save-stock-position', function() {
		show_loading();
		jQuery.ajax({
		    url: app_url + 'dstb_clean/save_stock_position',
		    type: 'POST',
		    dataType: 'JSON',
		    data: jQuery('#form_stock_position').serialize(),
		    success: function(response) {
		        hide_loading();
		        if (response.err_code == 0) {
		            hide_modal('stock_position');
		        }
		        else {
		            bootbox.alert(response.err_message);
		        }
		    },
		    error: function(res){}
		});
		      
	});

	jQuery('body').on('click', '.chk-bill', function() {
		if (jQuery(this).is(':checked')) {
			jQuery(this).parents('tr').find('.btn-stock-position').addClass('hide');
		}
		else {
			jQuery(this).parents('tr').find('.btn-stock-position').removeClass('hide');
		}
	});