PHP Code:
Ext.onReady(function(){
var tbView = new Ext.Toolbar({
layout: 'cluster',
cls: "x-cluster-backgrnd",
items: [{
text:'Categories',
slotId:'switchButton',
cls: 'btn_32',
icon: 'images/view_window_switch_32.png', // <-- icon
rowspan: 3,
handler: newcategories
},{
text:'Settings',
slotId:'switchButton',
cls: 'btn_32',
icon: 'images/process.png', // <-- icon
rowspan: 3,
handler: billsetting
},{
text:'Calculator',
slotId:'arrangeButton',
cls: 'btn_32',
icon: 'images/view_window_arrange_32.png', // <-- icon
rowspan: 3,
xtype: 'calculator'
}]
});
var tbClip = new Ext.Toolbar({
layout: 'cluster',
cls: "x-cluster-backgrnd",
items: [{
text:' Add ',
slotId:'pasteButton',
cls: 'btn_32',
iconCls: 'addbig', // <-- icon
rowspan: 3,
tooltip: 'Add Bills',
handler: function(){ addbillform() }
},{
text:'Delete',
slotId:'cutButton',
iconCls: 'remove', // <-- icon
id:'deletebill',
tooltip: 'Delete Selected Bill',
handler: function(){ deleteContextMenu() }
},{
text:'Edit',
slotId:'copyButton',
iconCls: 'edit', // <-- icon
tooltip: 'Edit Selected Bill',
id:'editbill',
handler: function(){ editbill() }
}]
});
var tbPrint = new Ext.Toolbar({
layout: 'cluster',
cls: "x-cluster-backgrnd",
items: [{
text:' Print ',
slotId:'pasteButton',
cls: 'btn_32',
iconCls: 'print', // <-- icon
rowspan: 3,
tooltip: 'Print bills',
handler: function(){ createreportgrid() }
}]
});
billdue = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'php/database1.php'
}),
baseParams:{task: "BILLDUE"},
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
id: 'id'
},['id','name','amount','due'])
});
billdue.load();
billdue.on('load',function() {
var bill = '';
for(i = 0; i< billdue.getCount(); i++){
bill += billdue.getAt(i).data.name + ' - $' + billdue.getAt(i).data.amount + '<br>';
Ext.MessageBox.alert('Bills Due !!','the following bills are due: <br><br><b>' + bill + '</b>');
}
});
billstore = new Ext.data.Store({
id:'store',
//autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: 'php/database1.php',
method: 'POST'
}),
baseParams:{task: "LISTING"},
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
id: 'id'
},[
{name:'id', type:'string', mapping:'id'},
{name: 'name', type: 'string', mapping: 'name'},
{name: 'due', type: 'date', mapping: 'due',dateFormat: 'Y-m-d'},
{name: 'amount', type:'string',mapping: 'amount'},
{name: 'paid', type:'boolean',mapping: 'paid'},
{name: 'paid_when', type:'date',mapping: 'paid_when',dateFormat: 'Y-m-d'},
{name: 'amount_paid', type:'string',mapping: 'amount_paid'},
{name: 'difference', type:'float',mapping: 'difference'}
]),
// turn on remote sorting
sortInfo:{field: 'due', direction: "ASC"}
});
Ext.grid.CheckColumn = function(config){
Ext.apply(this, config);
if(!this.id){
this.id = Ext.id();
}
this.renderer = this.renderer.createDelegate(this);
};
Ext.grid.CheckColumn.prototype ={
init : function(grid){
this.grid = grid;
this.grid.on('render', function(){
var view = this.grid.getView();
view.mainBody.on('mousedown', this.onMouseDown, this);
}, this);
},
onMouseDown : function(e, t){
if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
e.stopEvent();
var index = this.grid.getView().findRowIndex(t);
var record = this.grid.store.getAt(index);
record.set(this.dataIndex, !record.data[this.dataIndex]);
}
},
renderer : function(v, p, record){
p.css += ' x-grid3-check-col-td';
return '<div class="x-grid3-check-col'+(v?'-on':'')+' x-grid3-cc-'+this.id+'"> </div>';
}
};
action = new Ext.ux.grid.RowActions({
header:'Actions',
autoWidth:false,
actions:[{
iconCls:'remove',
tooltip:'Delete Bill'
}//,{
// iconCls:'money',
// tooltip:'Pay Bill'
//}
,
{
iconCls:'icon-edit-record'
,tooltip:'Edit Record'
}],callbacks:{
//'money':function(grid, record, action, row, col) {
// paidbillform()
// },
'remove':function(grid, record, action, row,col){
deleteContextMenu()
},
'icon-edit-record':function(grid,record,action,row,col){
editbill();
}
}
});
var sm = new Ext.grid.CheckboxSelectionModel();
var checkColumn = new Ext.grid.CheckColumn({
header: "Paid",
dataIndex: 'paid',
width: 55
});
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
sm,
{
id:'name',
header: "Name",
dataIndex: 'name',
summaryType: 'count',
summaryRenderer: function(v, params, data){
return ((v === 0 || v > 1) ? '# of Bills: ' + v +'' : '(1 Bill)');
},
width: 120
},{
header: "Due",
dataIndex: 'due',
width: 100,
renderer: function (data, cell, record, rowIndex, columnIndex, store){
return data ? data.dateFormat('Y-m-d') : '';
}
},{
header: "Amount",
dataIndex: 'amount',
renderer: Ext.util.Format.usMoney,
width: 80
},checkColumn,{
header: "Paid When",
dataIndex: 'paid_when',
width: 100,
renderer: function (data, cell, record, rowIndex, columnIndex, store){
return data ? data.dateFormat('Y-m-d') : '';
}
},{
header: "Amount Paid",
dataIndex: 'amount_paid',
renderer: Ext.util.Format.usMoney,
summaryRenderer: function(v, params, data){
return ((v === 0 || v > 1) ? 'Total' : 'Total');
},
width: 100
},{
header: "Yet to Pay",
id:'difference',
dataIndex: 'difference',
renderer: Ext.util.Format.usMoney,
width: 100,
summaryType:'sum',
summaryRenderer: Ext.util.Format.usMoney
}, action]
);
cm.defaultSortable = true;
summary = new Ext.grid.GridSummary();
var grid = new Ext.grid.GridPanel({
id:'lol',
enableColLock:false,
// sm: new Ext.grid.RowSelectionModel({singlerow:true}),
width:700,
height:500,
ds: billstore,
cm: cm,
sm:sm,
plugins: [summary, action ,new Ext.ux.grid.Search({
iconCls:'icon-zoom'
,readonlyIndexes:['all']
,disableIndexes:['amount'],
mode:'local',
position:'top',
align:'right'
})],
trackMouseOver:false,
loadMask: true,
frame:false,
viewConfig: {
forceFit:true
},
bbar: new Ext.PagingToolbar({
pageSize: 15,
store: billstore,
displayInfo: true,
emptyMsg:'No bills to display'
}),
tbar:[{
xtype:"panel"
//,title:"Home"
,layout:"auto"
,items:[{
xtype:"panel"
//,title:"Home"
,layout:"auto"
,items:[{
layout:"cluster"
,cls:"x-cluster-tb-bckgrnd"
,id:"tb"
,layoutConfig:{
rows:2
}
,defaults:{
style:"margin-left:3px;"
,border:false
}
,items:[
tbClip
,{html:"Add/Delete/Edit"
,cls:"cluster-label"
}
,tbView
,{html:"Other"
,cls:"cluster-label"
}
,tbPrint
,{html:"Print"
,cls:"cluster-label"
}
]
}]
}]
}],
listeners:{
click: function(){
if (Ext.getCmp('lol').selModel.getCount() > 0){
Ext.getCmp('deletebill').setDisabled(false);
Ext.getCmp('editbill').setDisabled(false);
} else {
Ext.getCmp('deletebill').setDisabled(true);
Ext.getCmp('editbill').setDisabled(true);
}
}
}
});
var win = new Ext.Window({
id: 'bills-win',
title:'Bills',
width:740,
height:480,
closable:false,
draggable:false,
renderTo: document.body,
iconCls: 'money',
shim:false,
animCollapse:false,
constrainHeader:true,
layout: 'fit',
listeners:{
show: function(win){
Ext.getCmp('lol').el.show();
Ext.getCmp('lol').getStore().load();
},
beforedestroy: function(){
var autoDestroyIt = false;
var grid = Ext.getCmp('lol');
document.body.appendChild(Ext.getDom(grid.el));
grid.el.hide();
this.remove(grid , autoDestroyIt ); //save our grid from destruction!
}
},
items: grid
});
win.show();
billstore.on('load', function() {
if (Ext.getCmp('lol').selModel.getCount() == 0) {
Ext.getCmp('deletebill').setDisabled(true);
Ext.getCmp('editbill').setDisabled(true);
}
})
function createreportgrid(){
storex = new Ext.data.Store({
url:'php/database1.php',
baseParams:{
task:'LISTING'
},
reader: new Ext.data.JsonReader({
root:'records',
id: 'cve',
totalProperty: 'totalCount'
},
[{name:'id', mapping: 'id', type: 'int'},
{name:'name', mapping:'name', type: 'string'},
{name:'due',mapping:'due', type: 'string'},
{name:'amount',mapping:'amount', type: 'string'}]
),
remoteSort: false
})
report_pbar = new Ext.PagingToolbar({
pageSize: 3,
store: storex,
displayInfo: true,
displayMsg: 'Showing Records {0} - {1} of {2}',
emptyMsg: "Theres no data to display"
})
global_printer = new Ext.grid.XPrinter({
grid: grid,
pathPrinter:'./printer',
logoURL: 'companylogo.jpg',
pdfEnable:true,
paperOrientation:'p',
localeData:{
Title:'Employees catalog with Adress',
subTitle:'your subtitle here',
footerText:' footer text here',
pageNo:'Page # ',
printText:' Print ',
closeText:' Close ',
pdfText:' download PDF '
},
useCustom:{
custom:true,
customStore:storex,
columns:['Name','Due','Amount'],
alignCols:['center','left','left'],
pageToolbar:report_pbar,
useIt: false,
showIt: true,
location: 'bbar'
},
showdate:true,
showdateFormat:'Y-F-d H:i:s',
showFooter:true,
styles:'default'
});
storex.on('load', function(){
if (global_printer.flagdatachange){
global_printer.newPage();
}
});
storex.load();
global_printer.prepare();
}
function printmygridGO(obj){
global_printer.printGrid(obj);
}
})////END LAST END LAST END LAST
regards,