<?php
require "_header.php";
require "data/combo_student.php";
require "data/combo_semester.php";
require "data/combo_branchyear.php";
?>
<div id="main-content">
    <script type="text/javascript">

        var labelArray;
        labelArray = [
            ['Course '],
            ['Batch Year '],
            ['Financial Year '],
            ['Course Year '],
            ['Semester '],
            ['Student Name '],
            ['Scholarship Name '],
            ['Formfill Date '],
            ['Scholarship Approve Date '],
            ['Scholarship Recive Date '],
            ['Scholarship Recive Price '],
            ['College Recive Date '],
            ['College Recive Price '],
        ];

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

        var batchyearstore = new Ext.data.ArrayStore({
            fields: ['year_id', 'year_name'],
            data: Ext.semester.yearname
        });

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

        var yearstore = new Ext.data.ArrayStore({
            fields: ['branch_id', 'branchyear_id', 'branchyear_name'],
            data: Ext.year.year
        });
        var scholarshipstore = new Ext.data.ArrayStore({
            fields: ['scholarship_id', 'scholarship_name'],
            data: Ext.student.scholarship
        });

        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' }
            ]
        });



        if (flgDelete == "true") flgDelete1 = true;
        else flgDelete1 = false;
        if (flgAdd == "true") flgAdd1 = true;
        else flgAdd1 = false;
        var flgalert = 0;

        var ScholarshipStore = new Ext.data.JsonStore({
            url: 'data/get-student-scholarship.php',
            root: 'data',
            fields:[{ name: 'studentscholarship_id', type: 'int' },
            {name:'branch_id',type: 'int'},
            {name:'branch_name'},
            {name:'year_id',type: 'int'},
            { name: 'year_name'},
            {name:'branchyear_id',type: 'int'},
            { name: 'branchyear_name' },
            {name:'semester_id',type: 'int'},
            { name: 'semester_name' },
            {name:'scholarship_id',type: 'int'},
            { name: 'scholarship_name'},
            {name:'student_id',type: 'int'},
            { name: 'financial_year' },
            { name: 'student_name' },
            { name: 'formfill_date', type: 'date' },
            { name: 'scholarshipaprove_date', type: 'date' },
            { name: 'scholarshiprecive_date', type: 'date' },
            { name: 'scholarshiprecive_price', type: 'float' },
            { name: 'collegerecive_date', type: 'date' },
            { name: 'collegerecive_price', type: 'float' }
            ],
            autoLoad: false
        })

        function tfwdata(value) {
            if (value == 1) {
                return 'Yes';
            }
            else {
                return 'No';
            }
        }

        Ext.onReady(function () {
            Ext.QuickTips.init();
            var colModel = new Ext.grid.ColumnModel([
                {
                    dataIndex: 'student_name',
                    header: 'Student Name',
                    sortable: true,
                    width: 100
                }, {
                    dataIndex: 'scholarship_name',
                    header: 'Scholarship Name',
                    sortable: true,
                    width: 100
                },
                {
                    dataIndex: 'financial_year',
                    header: 'Financial Year',
                    sortable: true,
                    width: 100
                },
                {
                    dataIndex: 'year_name',
                    header: 'Educational Year',
                    sortable: true,
                    width: 100
                },
                {
                    dataIndex: 'formfill_date',
                    header: 'Formfill Date',
                    sortable: true,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d'),// Format the date as 'YYYY-MM-DD'
                    width: 100
                },
                {
                    dataIndex: 'scholarshipaprove_date',
                    header: 'Scholarship Approve Date',
                    sortable: true,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d'),// Format the date as 'YYYY-MM-DD'
                    width: 100
                },
                {
                    dataIndex: 'scholarshiprecive_date',
                    header: 'Scholarship Recive Date',
                    sortable: true,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d'),// Format the date as 'YYYY-MM-DD'
                    width: 100
                },
                {
                    dataIndex: 'scholarshiprecive_price',
                    header: 'Scholarship Recive Price',
                    sortable: true,
                    width: 120
                },
                {
                    dataIndex: 'collegerecive_date',
                    header: 'College Recive Date',
                    sortable: true,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d'),// Format the date as 'YYYY-MM-DD'
                    width: 100
                },
                {
                    dataIndex: 'collegerecive_price',
                    header: 'College Recive Price',
                    sortable: true,
                    width: 120
                }
            ]);


            var grid = new Ext.grid.GridPanel({
                store: ScholarshipStore,
                cm: colModel,
                columnLines: true,
                loadMask: true,
                stripeRows: true,
                
                sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function (sm, row, rec) {
                            Ext.getCmp("scholarshipform").getForm().loadRecord(rec);
					
					Ext.getCmp('branch_name').setRawValue(rec.data.branch_name);
					Ext.getCmp('branch_name').setValue(rec.data.branch_id);
					
					Ext.getCmp('year_name').setRawValue(rec.data.year_name);
					Ext.getCmp('year_name').setValue(rec.data.year_id);
					
                    Ext.getCmp('branchyear_name').setRawValue(rec.data.branchyear_name);
					Ext.getCmp('branchyear_name').setValue(rec.data.branchyear_id);

					Ext.getCmp('semester_name').setRawValue(rec.data.semester_name);
					Ext.getCmp('semester_name').setValue(rec.data.semester_id);
					
                    Ext.getCmp('student_name').setRawValue(rec.data.student_name);
					Ext.getCmp('student_name').setValue(rec.data.student_id);
                         
                    Ext.getCmp('scholarship_name').setRawValue(rec.data.scholarship_name);
					Ext.getCmp('scholarship_name').setValue(rec.data.scholarship_id);
                         
                            if (flgEdit == "true") {
                                Ext.getCmp('btnSave').enable();
                            }
                            else {
                                Ext.getCmp('btnSave').disable();
                                alert('You do not have access to edit the record.');
                            }
                            if (flgDelete == "true") {
                                Ext.getCmp('btnDelete').enable();
                            }
                        }
                    }
                }),
                height: 285,
                border: true
            });

            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 = "Please click here to edit record.";
                        }
                    }
                });
            });

            var scholarshipform = new Ext.FormPanel({
                id: 'scholarshipform',
                frame: true,
                url: 'save-studentscholarship.php',
                labelAlign: 'left',
                autoHeight: true,
                bodyStyle: 'padding:5px',
                layout: 'column',
                items: [{
                    xtype: 'container',
                    autoEl: {},
                    layout: 'form',
                    columnWidth: .32,
                    labelWidth: 90,
                    items: [
                        {
                            xtype: 'combo',
                            name: 'branch_name',
                            id: 'branch_name',
                            hiddenName: 'branch_hidden',
                            fieldLabel: labelArray[0],
                            displayField: 'branch_name',
                            valueField: 'branch_id',
                            width: 163,
                            tabIndex: 1,
                            triggerAction: 'all',
                            mode: 'local',
                            allowBlank: true,
                            store: branchstore,
                            listeners: {
                                'select': function (cmb, rec, idx) {
                                    Ext.getCmp('year_name').reset();
                                    Ext.getCmp('semester_name').reset();
                                    Ext.getCmp('branchyear_name').reset();
                                    Ext.getCmp('student_name').reset();
                                    studentstore.removeAll();
                                    semesterstore.filter('branch_id', cmb.getValue(), false, true, true);
                                    yearstore.filter('branch_id', cmb.getValue(), false, true, true);
                                    var semesterCombo = Ext.getCmp('semester_name');
                                    if (cmb.getValue() == 3 || cmb.getValue() == 5) {
                                        semesterCombo.enable();
                                    } else {
                                        semesterCombo.disable();
                                        semesterCombo.reset();
                                    }
                                }
                            }
                        },
                        {
                            xtype: 'combo',
                            name: 'year_name',
                            id: 'year_name',
                            hiddenName: 'year_hidden',
                            fieldLabel: labelArray[1],
                            displayField: 'year_name',
                            valueField: 'year_id',
                            lastQuery: '',
                            triggerAction: 'all',
                            mode: 'local',
                            width: 163,
                            tabIndex: 2,
                            allowBlank: true,
                            store: batchyearstore,
                            listeners: {
                                'select': function (cmb, rec, idx) {
                                    if (Ext.getCmp('branch_name').getValue() != "") {
                                        Ext.getCmp('student_name').reset();
                                        studentstore.load({ params: { 'branch_id': Ext.getCmp('branch_name').getValue(), 'year_id': Ext.getCmp('year_name').getValue() } });
                                    } else {
                                        this.reset();
                                    }
                                }
                            }
                        }, {
                            xtype: 'textfield',
                            name: 'financial_year',
                            fieldLabel: labelArray[2],
                            id: 'financial_year',
                            width: 163,
                            tabIndex: 10,
                            allowBlank: true,
                            
                        },{
                            xtype: 'combo',
                            name: 'branchyear_name',
                            id: 'branchyear_name',
                            hiddenName: 'branchyear_hidden',
                            fieldLabel: labelArray[3],
                            displayField: 'branchyear_name',
                            valueField: 'branchyear_id',
                            lastQuery: '',
                            triggerAction: 'all',
                            mode: 'local',
                            width: 163,
                            tabIndex: 3,
                            allowBlank: true,
                            store: yearstore,
                            listeners: {
                                'select': function (cmb, rec, idx) {
                                    if (Ext.getCmp('branch_name').getValue() != "") {
                                        Ext.getCmp('student_name').reset();
                                    } else {
                                        this.reset();
                                    }
                                }
                            }
                        }, {
                            xtype: 'combo',
                            name: 'semester_name',
                            id: 'semester_name',
                            hiddenName: 'semester_hidden',
                            fieldLabel: labelArray[4],
                            displayField: 'semester_name',
                            valueField: 'semester_id',
                            disabled: true,
                            lastQuery: '',
                            triggerAction: 'all',
                            mode: 'local',
                            width: 163,
                            tabIndex: 4,
                            allowBlank: true,
                            store: semesterstore,
                            listeners: {
                                'select': function (cmb, rec, idx) {
                                    if (Ext.getCmp('branch_name').getValue() != "") {
                                        Ext.getCmp('student_name').reset();
                                    } else {
                                        this.reset();
                                    }
                                }
                            }
                        }, {
                            xtype: 'combo',
                            name: 'student_name',
                            id: 'student_name',
                            hiddenName: 'student_hidden',
                            labelSeparator: '',
                            fieldLabel: labelArray[5],
                            displayField: 'student_name',
                            valueField: 'student_id',
                            width: 163,
                            tabIndex: 5,
                            triggerAction: 'all',
                            mode: 'local',
                            allowBlank: true,
                            store: studentstore,
                            listeners: {
                                'select': function (cmb, rec, idx) {
                                    if (Ext.getCmp('branch_name').getValue() != "" && Ext.getCmp('year_name').getValue() != "") {
                                    }
                                    else if (Ext.getCmp('branch_name').getValue() != "" && Ext.getCmp('branchyear_name').getValue() != "") {
                                    }
                                    else if (Ext.getCmp('branch_name').getValue() != "" && Ext.getCmp('semester_name').getValue() != "") {
                                    }
                                    else {
                                        this.reset();
                                    }
                                    var studentId = cmb.getValue();
                                    ScholarshipStore.load({
                                        params: { 'student_id': studentId }
                                    });
                                }
                            }
                        }, {
                            xtype: 'combo',
                            name: 'scholarship_name',
                            id: 'scholarship_name',
                            hiddenName: 'scholarship_hidden',
                            fieldLabel: labelArray[6],
                            displayField: 'scholarship_name',
                            valueField: 'scholarship_id',
                            lastQuery: '',
                            triggerAction: 'all',
                            mode: 'local',
                            width: 163,
                            tabIndex: 6,
                            allowBlank: true,
                            store: scholarshipstore,
                            listeners: {
                                select: function (combo, record, index) {
                                    var formfillDate = Ext.getCmp('formfill_date');
                                    var scholarshipAproveDate = Ext.getCmp('scholarshipaprove_date');
                                    var scholarshipReciveDate = Ext.getCmp('scholarshiprecive_date');
                                    var scholarshipRecivePrice = Ext.getCmp('scholarshiprecive_price');
                                    var collegeRevicedate = Ext.getCmp('collegerecive_date');
                                    var collegeRevicePrice = Ext.getCmp('collegerecive_price');

                                    formfillDate.setDisabled(false);
                                    scholarshipAproveDate.setDisabled(false);
                                    scholarshipReciveDate.setDisabled(false);
                                    scholarshipRecivePrice.setDisabled(false);
                                    collegeRevicedate.setDisabled(false);
                                    collegeRevicePrice.setDisabled(false);

                                },
                                change: function (combo, newValue, oldValue) {
                                    var formfillDate = Ext.getCmp('formfill_date');
                                    var scholarshipAproveDate = Ext.getCmp('scholarshipaprove_date');
                                    var scholarshipReciveDate = Ext.getCmp('scholarshiprecive_date');
                                    var scholarshipRecivePrice = Ext.getCmp('scholarshiprecive_price');
                                    var collegeRevicedate = Ext.getCmp('collegerecive_date');
                                    var collegeRevicePrice = Ext.getCmp('collegerecive_price');
                                    if (!newValue) {
                                        formfillDate.setDisabled(true);
                                        scholarshipAproveDate.setDisabled(true);
                                        scholarshipReciveDate.setDisabled(true);
                                        scholarshipRecivePrice.setDisabled(true);
                                        collegeRevicedate.setDisabled(true);
                                        collegeRevicePrice.setDisabled(true);
                                    }
                                }
                            }
                        },
                        {
                            xtype: 'datefield',
                            name: 'formfill_date',
                            id: 'formfill_date',
                            fieldLabel: labelArray[7],
                            width: 163,
                            format: JSDateFormat,
                            vtype: 'daterange',
                            allowBlank: true,
                            tabIndex: 7,
                            maxValue: new Date(),
                            disabled: true
                        }, {
                            xtype: 'datefield',
                            name: 'scholarshipaprove_date',
                            id: 'scholarshipaprove_date',
                            fieldLabel: labelArray[8],
                            width: 163,
                            format: JSDateFormat,
                            vtype: 'daterange',
                            allowBlank: true,
                            tabIndex: 8,
                            maxValue: new Date(),
                            disabled: true
                        },
                        {
                            xtype: 'datefield',
                            name: 'scholarshiprecive_date',
                            id: 'scholarshiprecive_date',
                            fieldLabel: labelArray[9],
                            width: 163,
                            format: JSDateFormat,
                            vtype: 'daterange',
                            allowBlank: true,
                            tabIndex: 9,
                            maxValue: new Date(),
                            disabled: true
                        },
                        {
                            xtype: 'textfield',
                            name: 'scholarshiprecive_price',
                            fieldLabel: labelArray[10],
                            id: 'scholarshiprecive_price',
                            width: 163,
                            tabIndex: 10,
                            allowBlank: true,
                            disabled: true
                        }, {
                            xtype: 'datefield',
                            name: 'collegerecive_date',
                            id: 'collegerecive_date',
                            fieldLabel: labelArray[11],
                            width: 163,
                            format: JSDateFormat,
                            vtype: 'daterange',
                            allowBlank: true,
                            tabIndex: 11,
                            maxValue: new Date(),
                            disabled: true
                        }, {
                            xtype: 'textfield',
                            name: 'collegerecive_price',
                            fieldLabel: labelArray[12],
                            id: 'collegerecive_price',
                            width: 163,
                            tabIndex: 12,
                            allowBlank: true,
                            disabled: true
                        }, {
                            xtype: 'textfield',
                            name: 'studentscholarship_id',
                            id: 'studentscholarship_id',
                            value: '0',
                            hidden: true
                        }
                    ]
                }, {
                    xtype: 'container',
                    autoEl: {},
                    layout: 'form',
                    columnWidth: .68,
                    items: [grid]
                }]
            });

            var ScholarshipWindow = new Ext.Window({
                title: 'Scholarship Master',
                width: 1050,
                autoHeight: true,
                frame: true,
                border: false,
                modal: true,
                layout: 'fit',
                closeAction: 'close',
                collapsible: true,
                items: scholarshipform,
                buttons: [
                    {
                        text: 'Save',
                        name: 'btnSave',
                        iconCls: 'icon-save',
                        id: 'btnSave',
                        handler: function () {
                            scholarshipform.getForm().submit({
										waitMsg: 'Saving...',
										success: function () {	
											grid.getSelectionModel().clearSelections();
											Ext.getCmp('btnDelete').disable();	
											ScholarshipStore.load();
											scholarshipform.getForm().reset();	
											Ext.getCmp('scholarship_name').focus(true,500);								
										},
										failure: function () {
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Please fill up complete form.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});									
										}
									});		
				                }	
                            
                        
                    },
                    {
                        text: 'Delete',
                        iconCls: 'remove',
                        disabled: true,
                        id: 'btnDelete',
                        tabIndex: 10,
                        name: 'btnDelete',
                        handler: function () {
                            Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record.?', deleterecord);
                        }
                    },
                    {
                        text: 'Reset',
                        tabIndex: 11,
                        name: 'btnreset',
                        iconCls: 'icon-reset',
                        id: 'btnreset',
                        handler: function () {
                            scholarshipform.getForm().reset();
                            grid.stopEditing();
                            ScholarshipStore.removeAll();
                            Ext.getCmp('btnDelete').disable();
                            Ext.getCmp('branch_id').focus(true, 500);
                            if (flgAdd == "true") {
                                Ext.getCmp('btnSave').enable();
                            }
                        }
                    },
                    {
                        text: 'Close',
                        name: 'btnclose',
                        tabIndex: 12,
                        iconCls: 'icon-close',
                        id: 'btnclose',
                        handler: function () {
                            ScholarshipWindow.close();
                        }
                    }
                ]
            });
            function deleterecord(btn) {
                if (btn == 'yes') {
                    scholarshipform.getForm().submit({
                        waitMsg: 'Saving...',
                        params: { act: 'del' },
                        success: function () {
                            Ext.getCmp('branch_name').reset();
                            Ext.getCmp('year_name').reset();
                            Ext.getCmp('branchyear_name').reset();
                            Ext.getCmp('semester_name').reset();
                            Ext.getCmp('student_name').reset();
                            Ext.getCmp('scholarship_name').reset();
                            Ext.getCmp('financial_year').reset();
                            Ext.getCmp('formfill_date').reset();
                            Ext.getCmp('scholarshipaprove_date').reset();
                            Ext.getCmp('scholarshiprecive_date').reset();
                            Ext.getCmp('scholarshiprecive_price').reset();
                            Ext.getCmp('collegerecive_date').reset();
                            Ext.getCmp('collegerecive_price').reset();
                            ScholarshipStore.load();
                            Ext.getCmp('btnDelete').disable();

                          //  Ext.getCmp('studentscholarship_id').setValue('0');
                            Ext.getCmp('scholarship_name').focus(true, 500);
                        }
                    });
                }
            }

            var varWidth = (screen.width - ScholarshipWindow.width) / 2;
            ScholarshipWindow.setPosition(varWidth, ((screen.height / 4) - 85));
            ScholarshipWindow.show();
            Ext.getCmp('studentscholarship_id').focus(true, 500);

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

        });
    </script>
    <div id="abcd"></div>
</div>
<?php require "_footer.php"; ?>