rebiller = {};
rebiller.Invoked = false;

rebiller.ViewInvoiceReminders = function(){
    // Prevent this from being called twice
    if(document.getElementById('pendingitems') == null || rebiller.Invoked){
        return;
    }
    
    rebiller.gridstore = new Ext.data.JsonStore({
        id:             "rebiller",
        root:           'data',
        totalProperty:  'totalcount',
        idProperty:     'ticketid',
        remoteSort:     true,
        fields:         [
            'customer',
			'customer_id',
            'invoice_number',
			'amount',
			'balance_due',
			'days'
        ],
        proxy:          new Ext.data.HttpProxy({
            url:  'index.php?fuse=billing&action=getInvoiceReminderList'
        })
    });
    
    rebiller.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);
    }
	
	rebiller.renderInvoice = function(value, p, record){
        return String.format('<a href="index.php?fuse=clients&amp;view=Admin_Profile_Invoices&amp;frmClientID={0}">{1}</a>', record.data.customer_id, record.data.invoice_number);
    }

	rebiller.grid = new Ext.grid.GridPanel({
        el:               'pendingitems',
        autoHeight:       true,
        store:            rebiller.gridstore,
        trackMouseOver:   true,
        disableSelection: true,
        loadMask:         true,
        columns:          [
			{
                id:         'customer',
                header:     "Customer",
                width:      175,
				renderer:	rebiller.renderName,
                dataIndex:  "customer"
            },
            {
                id:         'invoice_id',
                header:     "Invoice #",
                width:      50,
				renderer:	rebiller.renderInvoice,
                dataIndex:  "invoice_number"
            },
			{
                id:         'amount',
                header:    	"Amount",
                width:      50,
                dataIndex:  "amount"
            },
			{
                id:         'balance',
                header:    	"Balance Due",
                width:      50,
                dataIndex:  "balance_due"
            },
			{
                id:         'days',
                header:    	"Days Overdue",
                width:      50,
                dataIndex:  "days"
            }
        ],
        stripeRows:       true,
        viewConfig:       {
            forceFit:       true,
            enableRowBody:  true,
            emptyText:      lang("There are no invoices reminders pending."),
            scrollOffset:   1
        }
    });

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