batchnotifier = {};
batchnotifier.Invoked = false;

batchnotifier.ViewEntries = function(){
    // Prevent this from being called twice
    if(document.getElementById('pendingitems') == null || batchnotifier.Invoked){
        return;
    }
    
    batchnotifier.gridstore = new Ext.data.JsonStore({
        id:             "batchnotifier",
        root:           'data',
        totalProperty:  'totalcount',
        idProperty:     'ticketid',
        remoteSort:     true,
        fields:         [
            'customer',
			'customer_id',
			'amount',
			'date'
        ],
        proxy:          new Ext.data.HttpProxy({
            url:  'index.php?fuse=billing&action=getBatchNotifierList'
        })
    });
    
    batchnotifier.renderName = function(value, p, record){
        return String.format('<a href="index.php?fuse=clients&amp;view=Admin_Profile_Contact&amp;frmClientID={0}">{1}</a>', record.data.customer_id, record.data.customer);
    }
	
	batchnotifier.grid = new Ext.grid.GridPanel({
        el:               'pendingitems',
        autoHeight:       true,
        store:            batchnotifier.gridstore,
        trackMouseOver:   true,
        disableSelection: true,
        loadMask:         true,
        columns:          [
			{
                id:         'customer',
                header:     "Customer",
                width:      175,
				renderer:	batchnotifier.renderName,
                dataIndex:  "customer"
            },
			{
                id:         'amount',
                header:    	"Amount",
                width:      50,
                dataIndex:  "amount"
            },
			{
                id:         'days',
                header:    	"Due Date",
                width:      50,
                dataIndex:  "date"
            }
        ],
        stripeRows:       true,
        viewConfig:       {
            forceFit:       true,
            enableRowBody:  true,
            emptyText:      lang("There batch notifier queue is empty."),
            scrollOffset:   1
        }
    });

    batchnotifier.grid.render();
    batchnotifier.gridstore.load({params:{start:0, limit:0}});
    batchnotifier.Invoked = true;
}