let billstoreceiver = {

	searchClientBy:(where, text, showresult) => {
		$.ajax({
			url: BASE_URL+'searchclientby',
			type:'POST',
			data: {
				text:text,
				where:where
			},
			dataType:'json',
			success:function(json) {
				if(json != '') {
					$('div.'+showresult).html(json);
					$('div.'+showresult).show(100);
				} else {
					$('div.'+showresult).hide(100);
				}
			}
		});		
	},
	verifyDate:(date, ref) => {
		$.ajax({
            url: BASE_URL+'verifydates',
            type: 'POST',
            data:{date:date},
            dataType: 'json',
            success:function(json) {
                if(json == false) {
                    $('#confirm_date, #confirm_expirate').hide(100);
                    $('#'+ref).attr('data-status', false);
                    utils.showAlerts('.message-add', 'Data não é válida!');

                } else {
                    $('#'+ref).attr('data-status', true);
                    $('#confirm_date, #confirm_expirate').show(100);
                }
            }
        });
	},
	getValueToPay:(main, advance, type = false) => {
		$.ajax({
            url: BASE_URL+'getvaluetopay',
            type: 'POST',
            data:{
            	value:main,
            	advance:advance
            },
            dataType: 'json',
            success:function(json) {
            	if(!type) {
            		$('#value_to_pay').val(json);
					$('#residual_value').val(json);
            	}

				if(type) {
					$('#residual_value').val(json);

					if(parseFloat(json) > 0) {
						$('select[name="situation"]').val(3);
					} else if(parseFloat(json) <= 0) {
						$('select[name="situation"]').val(4);
					}
				}

            }
        });
	},
    deleteAtt:(ref) => {
        $.ajax({
            url:BASE_URL+'deleteattbtr',
            type:'POST',
            data:{
                ref:ref
            },
            dataType:'json',
            success:function(json) {
                if(json == true) {
                    $('div.attachment a, div.attachment label').hide();
                }
            }
        });
    },
    updateStatus:(ref, value) => {
        $.ajax({
            url:BASE_URL+'updatestatusbtr',
            type:'POST',
            data:{
                ref:ref,
                value:value
            },
            dataType:'json',
            success:function(json) {
                if(json == true) {
                    location.replace(location.pathname);
                }
            }
        });
    },
    paymentAccounts:(accountsList, payment_form, payment_date, note_number, deduceir) => {
        $.ajax({
            url:BASE_URL+'setbtrpaidout',
            type:'POST',
            data:{
                refs:accountsList,
                payform:payment_form,
                paydate:payment_date,
                notenumber:note_number,
                ir:deduceir
            },
            dataType:'json',
            success:function(json) {
                if(json == true) {
                    location.replace(location.pathname);
                }
            }
        });
    },
    getTotalValueSelected:(accountsList) => {
        $.ajax({
            url:BASE_URL+'getvalueselectedbtr',
            type:'POST',
            data:{
                refs:accountsList
            },
            dataType:'json',
            success:function(json) {
                if(json.status == true) {                    
                    $('input[name="total_selected"]').val(json.value);
                } else {
                    $('input[name="total_selected"]').val('0,00');
                }
            }
        });
    }
	
}