<?php
require "_header.php";
require "data/combo_semester.php";
require "data/combo_student.php";
?>
<div id="main-content">
	<script type="text/javascript" src="jquery/ux/CheckColumn.js"></script>
	<link href="jquery/ux/css/superboxselect.css" rel="Stylesheet" type="text/css" />
	<link href="jquery/ux/css/summary.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="jquery/ux/SuperBoxSelect.js"></script>
	<script type="text/javascript" src="jquery/ux/GroupSummary.js"></script>
	<script type="text/javascript" src="jquery/ux/RowExpander.js"></script>
	<style type="text/css">
		.x-grid3-row-over .x-grid3-cell-inner {
			font-weight: bold;
		}

		.row-preview {
			padding: 2px 2px 5px 25px;
			border-top: dotted 1px #CCCCCC;
		}

		.tplmain {
			width: 170px;
		}

		.tplleft {
			width: 120px;
		}

		.tplright {
			width: 50px;
			text-align: right;
		}

		.tblstyle {
			text-align: center;
			background-color: #CED9E7;
			border: 1px solid #99BBE8;
			color: #000;
		}

		.tblstyle th {
			text-align: center;
			font-weight: bold;
			color: #15428B;
		}

		.tblstyle td {
			padding: 2px;
		}
	</style>
	<script type="text/javascript">
		Ext.onReady(function () {
			Ext.QuickTips.init();

			var student_id, student_name;
			var labelArray;
			labelArray = [
				['Fee Type<span class="comp">*</span> '],
				['Course<span class="comp">*</span> '],
				['Semester<span class="comp">*</span> '],
				['Enrollment No '],
				['Student '],
				['Receipt No '],
				['Receipt Date<span class="comp">*</span> '],
				['Exam Fee '],
				['Late Fee ']

			];

			var branchstore = new Ext.data.ArrayStore({
				fields: ['branch_id', 'branch_name'],
				data: Ext.student.branch
			});

			var semesterstore = new Ext.data.ArrayStore({
				fields: ['branch_id', 'semester_id', 'semester_name'],
				data: Ext.student.semester
			});

			var routenamestore = new Ext.data.ArrayStore({
				fields: ['route_id', 'route_name'],
				data: Ext.semester.route
			});
			var routeareastore = new Ext.data.ArrayStore({
				fields: ['head_id', 'head_name'],
				data: Ext.semester.routearea
			});

			var banknamestore = new Ext.data.ArrayStore({
				fields: ['bank_name'],
				data: Ext.semester.bankname
			});

			var studentstore = new Ext.data.JsonStore({
				url: 'data/getstudent-feesrecive.php',
				root: 'data',
				totalProperty: 'total',
				fields: [{
					name: 'student_id',
					type: 'int'
				}, {
					name: 'student_name',
					type: 'string'
				}, {
					name: 'student_gturegno',
					type: 'int'
				}, {
					name: 'adm_year',
					type: 'string'
				}, {
					name: 'student_techcerti',
					type: 'string'
				}]
			});

			var feetypestore = new Ext.data.ArrayStore({
				fields: ['type_value'],
				data: [['ATKT','PASS']]
			});

			var cheque_id = new Ext.form.TextField({
				name: 'cheque_id',
				id: 'cheque_id',
				hidden: true
			});

			var fees_type = new Ext.form.ComboBox({
				name: 'fees_type',
				allowBlank: true,
				hiddenName: 'fee_typehidden',
				id: 'fees_type',
				fieldLabel: labelArray[0],
				forceSelection: true,
				displayField: 'type_value',
				valueField: 'type_value',
				width: 210,
				tabIndex: 1,
				triggerAction: 'all',
				mode: 'local',
				store: feetypestore,

			});
			var branch = new Ext.form.ComboBox({
				name: 'branch_name',
				id: 'branch_name',
				hiddenName: 'branch_hidden',
				fieldLabel: labelArray[1],
				displayField: 'branch_name',
				valueField: 'branch_id',
				editable: true,
				tabIndex: 2,
				width: 210,
				triggerAction: 'all',
				mode: 'local',
				allowBlank: false,
				store: branchstore,
				lastQuery: '',
				listeners: {
					'select': function (cmb, rec, idx) {

						semesterstore.filter('branch_id', cmb.getValue(), false, true, true);

					}
				}
			});
			var semester = new Ext.form.ComboBox({
				name: 'semester_name',
				id: 'semester_name',
				hiddenName: 'semester_hidden',
				tabIndex: 3,
				width: 210,
				fieldLabel: labelArray[2],
				displayField: 'semester_name',
				valueField: 'semester_id',
				editable: true,
				triggerAction: 'all',
				mode: 'local',
				allowBlank: true,
				store: semesterstore,
				lastQuery: '',
				listeners: {
					'select': function (cmb, rec, idx) {
						var branch = Ext.getCmp('branch_name').getValue();
						var fees_type = Ext.getCmp('fees_type').getValue();

						if (Ext.getCmp('branch_name').getValue() != "" && Ext.getCmp('semester_name').getValue() != "") {
							Ext.getCmp('student_name').reset();
							Ext.getCmp('student_gturegno').reset();
							Ext.getCmp('cheque_no').reset();
							Ext.getCmp('bank_name').reset();
							Ext.getCmp('receipt_date').reset();
							Ext.getCmp('receipt_no').reset();
							studentstore.load({ params: { 'fees_type': Ext.getCmp('fees_type').getValue(), 'branch_id': Ext.getCmp('branch_name').getValue(), 'semester_id': Ext.getCmp('semester_name').getValue() } });
						} else {
							alert('Select Branch And Semester First')
							this.reset();
						}
						get_ReceiptNo();
					}
				}
			});
			var gtuno = new Ext.form.TextField({
				name: 'student_gturegno',
				id: 'student_gturegno',
				tabIndex: 5,
				fieldLabel: labelArray[3],
				editable: true,
				tabIndex: 5,
				width: 210,
				triggerAction: 'all',
				mode: 'local',
				allowBlank: true

			});
			var student = new Ext.form.TextField({
				name: 'student_name',
				id: 'student_name',
				fieldLabel: labelArray[4],
				editable: true,
				tabIndex: 5,
				width: 210,
				triggerAction: 'all',
				mode: 'local',
				allowBlank: true,
			});

			var feesrecno = new Ext.form.NumberField({
				id: 'receipt_no',
				name: 'receipt_no',
				width: 210,
				tabIndex: 6,
				fieldLabel: labelArray[5],
				readOnly: true
			});

			var feesrecdate = new Ext.form.DateField({
				id: 'receipt_date',
				name: 'receipt_date',
				width: 210,
				tabIndex: 7,
				fieldLabel: labelArray[6],
				enableKeyEvents: true,
				allowBlank: true,
				maxValue: new Date(),
				value: new Date()
			});
		
			var receive_amt = new Ext.form.TextField({
				name: 'receive_amt',
				id: 'receive_amt',
				tabIndex: 8,
				fieldLabel:labelArray[7],
				allowNegative: false,
				allowDecimals: false,
				disabled: false,
				width: 210,
				autoCreate: { tag: 'input', type: 'text', maxlength: '15' },
				allowBlank: true
			});
			var latefee = new Ext.form.TextField({
				name: 'latefee',
				id: 'latefee',
				tabIndex: 10,
				fieldLabel:labelArray[8],
				allowNegative: false,
				allowDecimals: false,
				disabled: false,
				width: 210,
				autoCreate: { tag: 'input', type: 'text', maxlength: '15' },
				allowBlank: true
			});
			
			var checkno = new Ext.form.NumberField({
				name: 'cheque_no',
				id: 'cheque_no',
				allowNegative: false,
				allowDecimals: false,
				disabled: false,
				width: 210,
				autoCreate: { tag: 'input', type: 'text', maxlength: '15' },
				allowBlank: true
			});

			var bankname = new Ext.form.ComboBox({
				name: 'bank_name',
				id: 'bank_name',
			
				displayField: 'bank_name',
				triggerAction: 'all',
				hideTrigger: false,
				
				disabled: false,
				store: banknamestore,
				mode: 'local',
				width: 210,
				selectOnFocus: true,
				allowBlank: true
			});

			var ifsc_code = new Ext.form.TextField({
				name: 'ifsc_code',
				id: 'ifsc_code',
				fieldLabel: 'IFSC',
				allowNegative: false,
				allowDecimals: false,
				disabled: false,
				width: 210,
				autoCreate: { tag: 'input', type: 'text', maxlength: '15' },
				allowBlank: true
			});
			
			var DebitDetail = new Ext.form.Label({
				name: 'DebitDetail',
				id: 'DebitDetail'
			});

			var receiveform = new Ext.FormPanel({
				id: 'receiveform',
				frame: true,
				url: 'save-chequefeesrecive.php',
				labelAlign: 'left',
				bodyStyle: 'padding:5px',
				layout: 'column',
				items: [{
					columnWidth: 0.90,
					xtype: 'fieldset',
					id: 'feeshead_add_edit_form',
					labelWidth: 90,
					title: '',
					defaults: { border: false },
					autoHeight: true,
					border: false,
					items: [
						fees_type,
						{
							xtype: 'textfield',
							id: 'adm_year',
							name: 'adm_year',
							hidden: true
						}, {
							xtype: 'textfield',
							id: 'student_techcerti',
							name: 'student_techcerti',
							hidden: true
						},
						branch,
						semester,
						student,
						feesrecno,
						feesrecdate,
						receive_amt,
						latefee,
						cheque_id,
						{ height: 10 },
						DebitDetail
					]
				},]
			});

			function change(val) {
				if (val > 0) {
					return '<span style="color:red;">' + val + '</span>';
				}
				else if (val <= 0) {
					return '<span style="color:green;">' + val + '</span>';
				}
				return val;
			}


			function get_ReceiptNo() {
				var semester_id = Ext.getCmp('semester_name').getValue();
				Ext.Ajax.request({
					loadMask: true,
					sync: true,
					params: { semester_id: semester_id },
					url: 'data/getchequeReceiptno.php',
					success: function (resp) {
						var value = Ext.decode(resp.responseText).count;
						if (value == ',') {
							receiveform.getForm().reset();
							Ext.getCmp('branch_name').focus(true, 500);
							studentstore.removeAll();
							Ext.MessageBox.show({
								title: 'Error',
								msg: 'Recipt No Not Found for this number.',
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.ERROR
							});
						} else {
							var arr_data = new Array();
							arr_data = value.split(",");
							Ext.getCmp('receipt_no').setValue(arr_data[0]);

						}
					}
				});
			}
			function toggleflag(btn) {
				flag = true;
			}
			function deleteallowances(btn) {
				if (btn == 'yes') {
					//window.location='fees-receipt-report.php?receipt_no=' + Ext.getCmp('receipt_no').getValue();
					window.location = 'fees-cheque-receipt-report.php';
				}
				else {
					receiveform.getForm().reset();
					Ext.getCmp("feeshead_add_edit_form").enable();
					//Ext.getCmp('branch_name').focus(true,500);
					Ext.getCmp('fees_type').focus(true, 500);
					Ext.getCmp('fees_type').setValue('Regular');
				}
			}
			var SetupWindow = new Ext.Window({
				title: 'Fees Cheque Receipt Master',
				width: 380,
				height: 390,
				frame: true,
				border: false,
				modal: true,
				layout: 'fit',
				closeAction: 'close',
				collapsible: true,
				items: receiveform,
				buttons: [{
					text: 'Save',
					tabIndex: 13,
					name: 'btnSave',
					iconCls: 'icon-save',
					id: 'btnSave',
					handler: function () {
						receiveform.getForm().submit({
							waitMsg: 'Saving...',
							success: function () {
								Ext.MessageBox.confirm('Confirmation', ' Do U Want To Print Receipt..?', deleteallowances);
							},
							failure: function () {
								Ext.MessageBox.show({
									title: 'Error',
									msg: 'Please fill complete form.',
									buttons: Ext.MessageBox.OK,
									icon: Ext.MessageBox.ERROR
								});
							}
						});
					}
				}, {
					text: 'Reset',
					name: 'btnreset',
					tabIndex: 14,
					iconCls: 'icon-reset',
					id: 'btnreset',
					handler: function () {
						receiveform.getForm().reset();
						Ext.getCmp("feeshead_add_edit_form").enable();
						//get_ReceiptNo();
						if (flgAdd == "true") {
							Ext.getCmp('btnSave').enable();
						}
						Ext.getCmp('fees_type').focus(true, 500);
						Ext.getCmp('fees_type').setValue('Regular');
					}
				}, {
					text: 'Close',
					name: 'btnclose',
					tabIndex: 15,
					iconCls: 'icon-close',
					id: 'btnclose',
					handler: function () {
						SetupWindow.close();
					}
				}]
			});
			Ext.getCmp('receipt_date').on('select', function () {
				if (Ext.getCmp('receipt_no').getValue() != "") {
					Ext.Ajax.request({
						loadMask: true,
						sync: true,
						url: 'data/getfeesreceiptdaterange.php',
						params: {
							semester_id: Ext.getCmp('semester_name').getValue(),
							feesrec_no: Ext.getCmp('receipt_no').getValue(),
							date: Ext.getCmp('receipt_date').getValue(),
						},
						waitMsg: 'Loading',
						success: function (resp) {
							if (Ext.decode(resp.responseText).valid == "true") {
								flag = true;
							}
							else {
								flag = false;
								var date = Ext.decode(resp.responseText).valid;
								var feesrec_no = Ext.getCmp('receipt_no').getValue();
								feesrec_no = feesrec_no - 1;
								Ext.MessageBox.alert("Error", "Recipt Date Should Not Less than " + date + " See Receipt No " + feesrec_no, toggleflag);
								Ext.getCmp('receipt_date').reset();
							}
						}
					});
				}
				else {
					alert("Select Semester First");
					Ext.getCmp('receipt_date').reset();
				}
			});

			var varWidth = (screen.width - SetupWindow.width) / 2;
			SetupWindow.setPosition(varWidth, ((screen.height / 4) - 100));
			SetupWindow.show();
			//get_ReceiptNo();
			if (flgAdd == "true") {
				Ext.getCmp('btnSave').enable();
			}
			else {
				Ext.getCmp('btnSave').disable();
			}
			Ext.getCmp('fees_type').focus(true, 500);
			Ext.getCmp('fees_type').setValue('Exam');
		});
	</script>
</div>
<?php require "_footer.php"; ?>