var corporategifthistory_obj 	= null ;

var C_FILTER_GIFT_HISTORY_LIST = "731";

function filterCorporateGiftHistory() {
	LoadingScreen("show");
	var data = { 
				"type"			: C_FILTER_GIFT_HISTORY_LIST,
				"customer_id"	: $('#cobCorporateGiftHistoryCustomerName').val(),
				"contact_id"	: $('#cobCorporateGiftHistoryContactName').val(),
				"delivery_from"	: $('#txtCorporateGiftHistoryDeliveryDateFrom').val(),
				"delivery_to"	: $('#txtCorporateGiftHistoryDeliveryDateTo').val(),
				"gift"			: $('#cobCorporateGiftHistoryGift').val(),
			};

	var url  = "request.pzx?c=" + corporate_gift_history_url + "&d=" + new Date().getTime() ;
	callServer(url,"json",data,onCorporateGiftHistoryResponse,null) ;
	return false;
}

//=====================================
            
function onCorporateGiftHistoryResponse(obj,resp) {
	LoadingScreen("hide");

    if (resp.status != C_OK) {
		swal.fire("Warning", resp.mesg, "warning")
        return false;
    }

    if(resp.type == C_FILTER_GIFT_HISTORY_LIST) {
       	$('#corporategifthistory-table').html('');
	   	$('#corporategifthistory-table').html(resp.data);
	   	filterRow('corporategifthistory-row-filter',this,false);
    } 

	// conflict with same function in corporategiftsummaryreport.js
	// if(resp.type == "C_GET_GIFT_ITEM"){
    //     $('#cobCorporateGiftHistoryGiftType').html(resp.data);
    //     $('#cobCorporateGiftHistoryGiftType').select2({
    //         width: '100%'
    //     });
    // }

	if(resp.type == "C_GET_CUSTOMER_CONTACTS"){
        $('#cobCorporateGiftHistoryContactName').html(resp.data);
        $('#cobCorporateGiftHistoryContactName').select2({
            width: '100%'
        });
    }
}

// conflict with same function in corporategiftsummaryreport.js
// function changeGiftItem(){
//     data = {
//         "type"  : "C_GET_GIFT_ITEM",
//         "id"    : $('#cobCorporateGiftHistoryGift').val()
//     }
//     var url = "index.pzx?c=" + corporate_gift_history_url + "&d=" + new Date().getTime();
//     callServer(url, "json", data, onCorporateGiftHistoryResponse, null);
//     return false;
// }

function changeCustomerName(){
    data = {
        "type"  : "C_GET_CUSTOMER_CONTACTS",
        "id"    : $('#cobCorporateGiftHistoryCustomerName').val()
    }
    var url = "index.pzx?c=" + corporate_gift_history_url + "&d=" + new Date().getTime();
    callServer(url, "json", data, onCorporateGiftHistoryResponse, null);
    return false;
}


