var purchaseInvoice_view = {
    settings: {
        purchaseInvoice_id: null,
        sendUrl: ''
    },
    init: function() {
        purchaseInvoice_view.initDataTable();
        purchaseInvoice_view.bindHrefPurchaseInvoiceSend();
    },
    bindHrefPurchaseInvoiceSend: function() {

        jQ('#btn-send-ask-modal-continue').unbind('click').bind('click', function(){

            var requestName = 'purchaseInvoiceSend',
                modal = jQ('#modal'),
                modalContent = jQ('#modal-content');

            global.ajaxCancel(requestName);

            var settings = {
                url: purchaseInvoice_view.settings.sendUrl,
                type: 'POST',
                data: {
                    purchaseInvoice_id: purchaseInvoice_view.settings.purchaseInvoice_id
                },
                beforeSend: function() {
                    modalContent.html('').addClass('has-loading');
                    modal.foundation('open');
                },
                success: function(json) {
                    if(json.success) {
                        location.reload();
                    } else {
                        global.parseFlashMessages(global.settings.vars.flashMessagesContentId, 'alert', json.errorMessages);
                        modal.foundation('close');
                    }
                }
            };

            global.ajax(settings, requestName);
        });
    },
    initDataTable: function() {

        var callBack = function() {
        };

        var datalist = jQ('#purchaseInvoicePayment-datalist').DataTable({
            'ordering': false,
            'searching': false,
            'paging': false,
            order: [[0, 'desc']],
            drawCallback: function() {
                callBack();
            },
            responsive: {
                details: {
                    renderer: function( api,rowIdx ) {
                        return global.dataTableResponsiveCallBack(api, rowIdx, callBack);
                    }
                }
            }
        });

        jQ('#purchaseOrderBreakdownItem-datalist').DataTable({
            paging: false,
            searching: false,
            ordering: false,
            info: false
        });

        jQ('#purchaseOrderBreakdownItemDelivery-datalist').DataTable({
            paging: false,
            searching: false,
            ordering: false,
            info: false
        });

        var datalistCredit = jQ('#purchaseInvoiceCreditPayment-datalist').DataTable({
            'ordering': false,
            'searching': false,
            'paging': false,
            order: [[0, 'desc']],
            drawCallback: function() {
                callBack();
            },
            responsive: {
                details: {
                    renderer: function( api,rowIdx ) {
                        return global.dataTableResponsiveCallBack(api, rowIdx, callBack);
                    }
                }
            }
        });

        jQ('.content-container').removeClass('has-loading'); jQ('.content-container-content').removeClass('hide');
    }
};