<?php
require "_header.php";
require "includeGridFilters.php";
require "data/combo_student.php";
require "data/combo_semester.php";
require "data/combo_branchyear.php";
$username = $_SESSION["VedantnrUserName"];
?>
<div id="main-content">
	<!-- start custom CSS/JS -->
	<script src="js/login-confirm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var loadingMask = new Ext.LoadMask(Ext.getBody(), { msg: "Loading data, please wait...", id: "loadingMask" });
		var username = '<?php echo $username; ?>';
		function deletedata() {
			var grid = Ext.getCmp('grid');
			var selections = grid.selModel.getSelections();
			var prez = [];
			for (i = 0; i < grid.selModel.getCount(); i++) {
				prez.push(selections[i].json.feesreceive_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'data/feesreceipt-grid-delete.php',
				params: {
					task: "DELETESTU",
					ids: encoded_array
				},
				success: function (response) {
					var result = eval(response.responseText);
					switch (result) {
						case 1:
							store.reload();
							break;
						default:
							Ext.MessageBox.alert('Warning', 'Could not delete the entire selection.');
							break;
					}
				},
				failure: function (response) {
					var result = response.responseText;
					Ext.MessageBox.alert('error', 'could not connect to the database. retry later');
				}
			});
		}
		Ext.onReady(function () {
			loadingMask.show();
			Ext.QuickTips.init();
			var xg = Ext.grid;
			var sm2 = new xg.CheckboxSelectionModel({
				listeners: {
					selectionchange: function (sm) {
						if (sm.getCount()) {
							if (flgDelete == "true") {
								grid.removeButton.enable();
							}
						} else {
							grid.removeButton.disable();
						}
					}
				}
			});
			var url = {
				local: 'grid-filter.json',
				remote: 'data/student-grid-filter.php'
			};
			var branchstore = new Ext.data.ArrayStore({
				fields: ['branch_id', 'branch_name'],
				data: Ext.semester.branch
			});

			var labelArray;
		labelArray = [['Course :<span class="comp">*</span>']];

			var encode = false;
			var local = false;
			function confirmDeleteStudents() {
				var selections = grid.selModel.getSelections();
				var prez = [];
				for (i = 0; i < grid.selModel.getCount(); i++) {
					prez.push(selections[i].json.feesreceive_id);
				}
				var encoded_array = Ext.encode(prez);
				Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record.?', deleteStudents);
			}
			function deleteStudents(btn) {
				if (btn == 'yes') {
					loginWindow.show();
				}
			}
			function formatDate(value) {
				var temp = value.dateFormat('d/m/Y');
				if (temp == "28/02/1900") {
					return '';
				} else {
					return temp;
				}
			}
			var sec;
			store = new Ext.data.JsonStore({
				autoDestroy: true,
				url: 'data/feesreceipt-grid-filter.php',
				remoteSort: true,
				storeId: 'myStore',
				idProperty: 'feesreceive_id',
				root: 'data',
				totalProperty: 'total',
				fields: [{
					name: 'feesreceive_id',
					type: 'int'
				}, {
					name: 'receipt_no'
					
				}, {
					name: 'receipt_date',
					type: 'date',
					dateFormat: 'Y-m-d'
				}, {
					name: 'receive_amt',
					type: 'int'
				}, {
					name: 'student_name'
				}, {
					name: 'student_gturegno',
					type: 'double'
				}, {
					name: 'branch_id'
				}, {
					name: 'year_id'
				}, {
					name: 'branchyear_id'
				}, {
					name: 'semester_id'
				}, {
					name: 'branch_name'
				}, {
					name: 'year_name'
				}, {
					name: 'branchyear_name'
				}, {
					name: 'semester_name'
				}]
			});

			var filters = new Ext.ux.grid.GridFilters({
				encode: encode,
				local: false,
				filters: [{
					type: 'numeric',
					dataIndex: 'feesreceive_id'
				}, {
					type: 'string',
					dataIndex: 'receipt_no'
				}, {
					type: 'date',
					dataIndex: 'receipt_date'
				}, {
					type: 'numeric',
					dataIndex: 'receive_amt'
				}, {
					type: 'string',
					dataIndex: 'student_name'
				}, {
					type: 'numeric',
					dataIndex: 'student_gturegno'
				}, {
					type: 'int',
					dataIndex: 'branch_id'
				},{
					type: 'int',
					dataIndex: 'year_id'
				},{
					type: 'int',
					dataIndex: 'branchyear_id'
				},{
					type: 'int',
					dataIndex: 'semester_id'
				},{
					type: 'string',
					dataIndex: 'branch_name'
				},{
					type: 'string',
					dataIndex: 'year_name'
				},{
					type: 'string',
					dataIndex: 'branchyear_name'
				},{
					type: 'string',
					dataIndex: 'semester_name'
				}]
			});

			var createColModel = function (finish, start) {
				var columns = [
					sm2,
					{
						dataIndex: 'feesreceive_id',
						header: 'feesreceive_id',
						width: 80,
						hidden: true,
						filterable: true
					},
					{
						header: "Edit",
						width: 30,
						renderer: function (value, metaData, record, rowIndex, colIndex, store) {
							return '<a href="addedit-feesreceive.php?ID=' + record.get('feesreceive_id') + '">Edit</a>';
						}
					},
					{
						header: "Print",
						width: 40,
						
						renderer: function (value, metaData, record, rowIndex, colIndex, store) {
							var branchId = record.get('branch_id');
							var feesreceive_id = record.get('feesreceive_id');
							var branchYearId = record.get('branchyear_id');
							var yearId = record.get('year_id');
							var semesterId = record.get('semester_id');
							return '<a href="fees-receipt-report.php?branch_id=' + branchId +  '&year_id=' + yearId +  '&branchyear_id=' + branchYearId + '&semester_id=' + semesterId + '&feesreceive_id=' + feesreceive_id + '">Print</a>';
						}
					},
				/*	{
			header: "Edit",	
			width:30,
		    renderer: function(value, metaData, record, rowIndex, colIndex, store) {
    	   		return '<a href="addedit-feesreceive.php?ID='+ record.get('feesreceive_id') +'">Edit</a>';
			}
		},*/
					 {
						dataIndex: 'receipt_no',
						header: 'Receipt No',
						width: 80,
						filterable: true
					}, {
						dataIndex: 'receipt_date',
						header: 'Receipt Date',
						width: 90,
						renderer: formatDate,
						filter: {
						}
					}, {
						dataIndex: 'receive_amt',
						header: 'Amt',
						width: 90,
						filterable: true
					}, {
						dataIndex: 'student_gturegno',
						header: 'Enrl No',
						width: 90,
						filterable: true
					}, {
						dataIndex: 'student_name',
						header: 'Student Name',
						filter: { type: 'string' },
						width: 200
					}, {
						dataIndex: 'branch_name',
						header: 'Course',
						width: 100
					},
					{
						dataIndex: 'year_name',
						header: 'Batch',
						width: 70
					},
					{
						dataIndex: 'branchyear_name',
						header: 'Course Year',
						width: 70
					}, {
						dataIndex: 'semester_name',
						header: 'Semester',
						width: 70
					}];

				return new Ext.grid.ColumnModel({
					columns: columns.slice(start || 0, finish),
					defaults: {
						sortable: true
					}
				});
			};

			var grid = new Ext.grid.GridPanel({
				id: 'grid',
				name: 'grid',
				store: store,
				colModel: createColModel(40),
				loadMask: true,
				frame: true,
				enableColLock: false,
				columnLines: true,
				height: 460,
				width: 900,
				layout: 'fit',
				selModel: new Ext.grid.RowSelectionModel({ singleSelect: false }),
				plugins: [filters],
				sm: sm2,
				listeners: {
					render: {
						fn: function () {
							if (Ext.getCmp('branch_id').getValue() != "") {
								store.reload({
								params: {
									start: 0,
									limit: 10
								}
							});
							}
						}
					}
				},
				tbar: [{
					iconCls: 'icon-add',
					text: 'Add Fees Receipt',
					id: 'btnAdd',
					handler: function () {
						location.href = 'addedit-feesreceive.php';
					}
				}, '-', {
					text: 'Delete Fees Receipt',
					id: 'btnDelete',
					handler: confirmDeleteStudents,
					iconCls: 'remove',
					ref: '../removeButton',
					disabled: true
				},{ xtype: 'tbtext', text: labelArray[0] }, ' ', {
					xtype: 'combo',
					id: 'branch_id',
					displayField: 'branch_name',
					valueField: 'branch_id',
					editable: false,
					tabIndex: 4,
					width: 210,
					triggerAction: 'all',
					mode: 'local',
					forceSelection: true,
					selectOnFocus: true,
					store: branchstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							sec = this.getValue(),
								store.load({
									params: { 'branch': this.getValue(), start: 0, limit: 10 }

								});
						}
					}
				}],
				bbar: new Ext.PagingToolbar({
					store: store,
					pageSize: 10,
					displayInfo: true,
					plugins: [filters]
				})
			});

			grid.getBottomToolbar().add([
				'->', {
					text: 'Clear Filter Data',
					handler: function () {
						grid.filters.clearFilters();
					}
				}
			]);

			grid.on('render', function () {
				grid.tip = new Ext.ToolTip({
					view: grid.getView(),
					target: grid.getView().mainBody,
					delegate: '.x-grid3-row',
					trackMouse: true,
					renderTo: document.body,
					listeners: {
						beforeshow: function updateTipBody(tip) {
							tip.body.dom.innerHTML = "Click on Edit Link To Edit Record.";
						}
					}
				});
			});

			store.on({
				'beforeload': {
					fn: function (store, options) {
						options.params || (options.params = {});
						Ext.apply(options.params, {
							pageNo: this.pageNumber,
							branch: sec
						});
					},
					scope: this
				}
			});

			var FeesWindow = new Ext.Window({
				title: 'View Fees Receipt Information',
				height: 380,
				width: 950,
				layout: 'fit',
				modal: true,
				border: false,
				closeAction: 'close',
				collapsible: 'true',
				items: grid
			})


			var varWidth = (screen.width - FeesWindow.width) / 2;
			FeesWindow.setPosition(varWidth, ((screen.height / 4) - 85));
			FeesWindow.show();
			loadingMask.hide();

			if (flgAdd == "true") {
				Ext.getCmp('btnAdd').enable();
			} else {
				Ext.getCmp('btnAdd').disable();
			}

			if (flgEdit == "false") {
				grid.getColumnModel().setHidden(1, true);
			}

		});
	</script>

	<!-- end custom CSS/JS -->
	<div id="abcd" align="center"></div>
</div>
<?php require "_footer.php"; ?>