예제 #1
0
파일: course.py 프로젝트: khanafeer/TBAT
class course_info(QWidget, course_info):
    def __init__(self):
        QWidget.__init__(self)
        self.setupUi(self)
        self.setWindowTitle(u'تفاصيل المجموعة')
        self.gp_id = None
        self.db = Model()
        self.pr = print_doc()
        self.bc_num = bc_num()
        self.special_price=Special_Price()
        self.st_gp_switch = st_gp_switch()
        self.centerx(self.st_gp_switch)
        self.centerx(self.bc_num)
        self.stackedWidget.setCurrentIndex(1)
        self.day_select = day_select_dw()
        self.date_select = date_select()
        self.mony_dw = mony_dw()
        self.st_dw = students_dw()
        self.centerx(self.day_select)
        self.centerx(self.date_select)
        self.centerx(self.mony_dw)
        self.centerx(self.st_dw)
        self.start_dt.setDate(datetime.date.today())
        self.date_select.date_edt.setDate(datetime.date.today())
        for i in self.findChildren(QWidget):
            i.setAttribute(Qt.WA_StyledBackground, True)
        self.attend_btn.clicked.connect(self.times_f)
        self.course_time_finish_btn.clicked.connect(self.course_time_finish)
        self.course_time_btn.clicked.connect(self.course_time)
        self.date_select.add_btn.clicked.connect(self.add_course_time)
        self.day_select.add_btn.clicked.connect(self.add_course_time_st)
        self.add_btn_dates.clicked.connect(self.date_select_show)
        self.add_btn_days.clicked.connect(self.day_select_show)
        self.finish_days.clicked.connect(self.convert_days_to_dates)
        self.students_btn.clicked.connect(self.get_st_cs)
        self.st_edt_2.returnPressed.connect(self.get_st)
        self.st_attend_btn.clicked.connect(self.show_st_attend)
        self.st_attend_search_btn.clicked.connect(self.fill_st_attend)
        self.attend_day.currentIndexChanged.connect(self.fill_st_attend)
        self.bill_search_btn.clicked.connect(self.fill_st_mony)
        self.bill_day.currentIndexChanged.connect(self.fill_st_mony)
        self.bill_print_btn.clicked.connect(self.print_mony)
        self.st_attend_print_btn.clicked.connect(self.print_attend)
        self.mony_btn.clicked.connect(self.get_mony)
        self.table_dates.cellClicked.connect(self.del_course_time)
        self.table_days.cellClicked.connect(self.del_course_time_st)
        self.st_cs_table.cellClicked.connect(self.del_st_cs)
        self.bill_table.cellClicked.connect(self.buy_mony)
        self.mony_dw.put_mony_btn.clicked.connect(self.buy_mony_db)
        self.st_dw.add_btn.clicked.connect(self.add_st)
        self.add_student_btn.clicked.connect(self.add_incurrent)
        self.date_select.edt_btn.clicked.connect(self.edite_time)
        self.st_dw.barcode_get_btn.clicked.connect(lambda: self.st_dw.bc_edt.setText(self.db.generate_barcode()))
        self.connect(self.st_attend_table, SIGNAL("doubleClicked(const QModelIndex&)"), self.change_st_status)
        self.print_btn.clicked.connect(lambda :self.bc_num.pre_show(self.get_data()))
        self.st_gp_switch.pushButton.clicked.connect(self.switch)
        self.sw_btn.clicked.connect(self.show_sw)
        self.all_rd.clicked.connect(self.fill_st_attend)
        self.attend_rd.clicked.connect(self.fill_st_attend)
        self.absent_rd.clicked.connect(self.fill_st_attend)
        self.att_btn.clicked.connect(lambda: self.attend_abs_all(True))
        self.abs_btn.clicked.connect(lambda: self.attend_abs_all(False))
        self.print_students.clicked.connect(self.print_f)
        self.special_price.add_btn.clicked.connect(self.update_price)
        self.special_price.close_btn.clicked.connect(self.special_price.close)

    def print_f(self):
        x=[]
        hea=[]
        for i in range(3):
                hea.append(self.st_cs_table.horizontalHeaderItem(i).text())
        x.append(hea)
        for m in range(self.st_cs_table.rowCount()):
            z=[]
            for j in range(3):
                    teext = unicode(self.st_cs_table.item(m, j).text())
                    z.append(teext)
            x.append(z)
        self.pr.print_info(x, u'تقرير الطالب')


    def focusInEvent(self, *args, **kwargs):
        indx = self.stackedWidget.currentIndex()
        if indx == 0:
            self.get_course_times()
        elif indx == 1:
            self.get_st_cs()
        elif indx == 2:
            self.fill_st_attend()
        elif indx == 3:
            self.fill_st_mony()
        self.completer_set()
    def show_sw(self):
        self.st_gp_switch.st_bc = 'all'
        self.st_gp_switch.showNormal()
        self.st_gp_switch.raise_()
        self.st_gp_switch.activateWindow()
        self.st_gp_switch.label_3.setText(self.gp_id)
        self.st_gp_switch.comboBox.clear()
        for i in self.db.get_all_courses():
            if i[1] != self.gp_id:
                self.st_gp_switch.comboBox.addItem(i[1])
    def switch(self):
        if self.st_gp_switch.st_bc == 'all':
            for i in self.db.get_all_stu(self.gp_id):
                self.db.student_group_swift(i[0],self.st_gp_switch.label_3.text(),self.st_gp_switch.comboBox.currentText())
            self.get_st_cs()
            self.st_gp_switch.hide()
        else:
            if self.db.student_group_swift(self.st_gp_switch.st_bc, self.st_gp_switch.label_3.text(),
                                           self.st_gp_switch.comboBox.currentText()):
                self.get_st_cs()
                self.st_gp_switch.hide()
    def get_data(self):
        l =[]
        for  i in range(self.st_cs_table.rowCount()):
            l.append([self.st_cs_table.item(i,2).text(),self.st_cs_table.item(i,1).text()])
        return l
    def color_btn(self):
        if type(self.sender()) is QPushButton:
            try:
                for i in self.widget_4.findChildren(QPushButton):
                    i.setStyleSheet("background:#05B963;")
                self.sender().setStyleSheet("background:#A8B1B2;")
            except:
                self.students_btn.setStyleSheet("background:#A8B1B2;")

    def set_cs_id(self,gp_id):
        self.gp_id = gp_id
    def add_incurrent(self):
        self.st_dw.edite_btn.hide()
        self.st_dw.showNormal()
    def day_select_show(self):
        self.day_select.showNormal()
        self.day_select.activateWindow()
        self.day_select.raise_()
    def date_select_show(self):
        self.date_select.add_btn.show()
        self.date_select.edt_btn.hide()
        self.date_select.showNormal()
        self.date_select.activateWindow()
        self.date_select.raise_()
    def get_mony(self):
        self.color_btn()
        if self.gp_id:
            self.stackedWidget.setCurrentIndex(3)
            self.get_mony_id()
        else:
            self.dialoge_only(u'لا يوجد اسم', u'ادخل الاسم اولا')
    def fill_st_mony(self):
        mony_id = self.bill_day.currentText()
        tottal = 0
        baid = 0
        if mony_id:
            x = self.db.get_st_cs(self.gp_id)
            self.bill_table.setRowCount(0)
            if x:
                for i in x:
                    n = self.bill_table.rowCount()
                    self.bill_table.insertRow(n)
                    self.bill_table.setItem(n, 0, QTableWidgetItem(i[0]))
                    self.bill_table.setItem(n, 1, QTableWidgetItem(i[1]))
                    self.bill_table.setItem(n, 2, QTableWidgetItem(i[2]))
                    self.bill_table.setItem(n, 3, QTableWidgetItem(unicode(i[3])))
                    x = self.db.get_st_mony(i[2],self.gp_id,mony_id)
                    self.bill_table.setItem(n, 4, QTableWidgetItem(unicode(x)))
                    self.bill_table.setItem(n, 5, QTableWidgetItem(unicode(i[3]-x)))
                    self.bill_table.setItem(n, 6, QTableWidgetItem(u'دفع'))
                    self.bill_table.item(n, 6).setBackground(QColor(20, 200, 10))
                    tottal += i[3]
                    baid += x
                self.tottal.setText(unicode(tottal))
                self.baid.setText(unicode(baid))
                self.rest.setText(unicode(tottal-baid))
            else:
                self.bill_table.setRowCount(0)
                self.tottal.setText("0")
                self.baid.setText("0")
                self.rest.setText("0")
    def fill_st_attend(self):
        if self.attend_day.currentText():
            x = self.db.get_st_cs(self.gp_id)
            self.st_attend_table.setRowCount(0)
            info = self.attend_day.currentText().split(" : ")
            if x:
                for i in x:
                    checked = self.db.check_attend(i[2],info[0],info[1],info[2])
                    if self.all_rd.isChecked():
                        self.tbl_checked_add(i,checked)
                    elif self.attend_rd.isChecked() and checked:
                        self.tbl_checked_add(i,checked)
                    elif self.absent_rd.isChecked() and not checked:
                        self.tbl_checked_add(i, checked)
    def tbl_checked_add(self,i,checked):
        n = self.st_attend_table.rowCount()
        self.st_attend_table.insertRow(n)
        self.st_attend_table.setItem(n, 0, QTableWidgetItem(i[0]))
        self.st_attend_table.setItem(n, 1, QTableWidgetItem(i[1]))
        self.st_attend_table.setItem(n, 2, QTableWidgetItem(i[2]))
        if checked:
            self.st_attend_table.setItem(n, 3, QTableWidgetItem(u'حاضر'))
        else:
            self.st_attend_table.setItem(n, 3, QTableWidgetItem(u'غائب'))
    def attend_abs_all(self,attend):
        if self.dialoge_only(u'هل انت متاكد من هذة العملية',u'سيتم تغير حالة الطلاب الحاليين فى هذا اليوم') == QMessageBox.Ok:
            info = self.attend_day.currentText().split(" : ")
            for col in range(self.st_attend_table.rowCount()):
                st = self.st_attend_table.item(col, 2).text()
                dt_st = self.st_attend_table.item(col, 3).text()
                gpid = self.db.get_course_by_name(self.gp_id)[0]
                if attend:
                    self.db.attend_st_gp(st, gpid, info[0], info[1], info[2], u'حضور')
                    self.st_attend_table.setItem(col, 3, QTableWidgetItem(u'حاضر'))
                else:
                    self.db.attend_st_gp(st, gpid, info[0], info[1], info[2], u'غياب')
                    self.st_attend_table.setItem(col, 3, QTableWidgetItem(u'غائب'))
    def change_st_status(self,indx):
        col = indx.row()
        st = self.st_attend_table.item(col,2).text()
        info = self.attend_day.currentText().split(" : ")
        dt_st = self.st_attend_table.item(col,3).text()
        gpid = self.db.get_course_by_name(self.gp_id)[0]
        if dt_st == u'غائب':
            if self.db.attend_st_gp(st,gpid,info[0],info[1],info[2],u'حضور'):
                self.st_attend_table.setItem(col, 3, QTableWidgetItem(u'حاضر'))
        else:
            if self.db.attend_st_gp(st,gpid,info[0],info[1],info[2],u'غياب'):
                self.st_attend_table.setItem(col, 3, QTableWidgetItem(u'غائب'))

    def show_st_attend(self):
        self.color_btn()
        bill = []
        back = []
        index = []
        today = datetime.date.today()
        if self.gp_id:
            self.stackedWidget.setCurrentIndex(2)
            v = self.db.get_course_dates(self.gp_id)
            self.attend_day.clear()
            for i in v:
                self.attend_day.addItem(str(i[0])+" : "+str(i[1])+" : "+str(i[2]))
                bill.append(i[0])
            if v:
                self.fill_st_attend()
            if bill:
                for i in bill:
                    if (i <= today ) :
                        diff = today - i
                        back.append(diff)
                        index.append(bill.index(i))

                target = min(back)
                inx = back.index(target)
                final = bill[inx]
                self.attend_day.setCurrentIndex(inx)
        else:
            self.dialoge_only(u'لا يوجد اسم', u'ادخل الاسم اولا')
    def get_st(self):
        st = self.st_edt_2.text()
        self.st_edt_2.clear()
        if st:
            barcode = self.db.get_student(st) #select * from student
            if barcode:
                course = self.gp_id
                price = self.db.get_course_price(self.gp_id)
                if self.db.st_gp_not_exist(barcode[0], course):
                    if self.db.add_st_gp(barcode[0], course,price):
                        self.get_st_cs()
                        self.st_edt_2.selectAll()
                    else:
                        self.dialoge_only(u'لم تتم عملية الاضافة بنجاح', u'حاول مرة اخرى')
                else:
                    self.dialoge_only(u'الطالب موجود فى المجموعة بالفعل', u'اختر مجموعة اخرى')

            else:
                self.dialoge_only(u'لا توجد بيانات لهذا المتدرب', u'ادخل الاسم الصحيح')

    def convert_days_to_dates(self):
        self.get_times_from_structure()
        self.course_time_finish()
    def get_times_from_structure(self):
        if self.dialoge_only(u'سيتم حذف المواعيد الاخرى واضافة مواعيد جديدة', u'هل انت متاكد من الحذف') == QMessageBox.Ok:
            if self.db.del_course_time_all(self.gp_id):
                st_date = self.start_dt.date().toPython()
                structures = self.db.get_course_structure(self.gp_id)
                num_days = self.db.get_course_num_days(self.gp_id)
                rest_days = 0
                while rest_days < num_days:
                    day = st_date.strftime('%A')
                    for i in structures:
                        if i[1] == day and rest_days < num_days:
                            self.db.add_course_time(self.gp_id, st_date, day, i[2], i[3])
                            rest_days += 1
                    try:
                        st_date = st_date + datetime.timedelta(days=1)
                    except:
                        pass
            else:
                self.dialoge_only(u'لم تتم عملية حذف المواعيد',u'لنن تتم عملية تغير المواعيد')
    def completer_set(self):
        completer2 = QCompleter()
        completer2.setCompletionMode(QCompleter.PopupCompletion)
        completer2.activated.connect(self.get_st)
        m = QStringListModel()
        completer2.setModel(m)
        self.db.get_students(m)
        self.st_edt_2.setCompleter(completer2)
    def times_f(self):
        self.course_time()
        self.color_btn()
        if self.gp_id:
            self.stackedWidget.setCurrentIndex(0)
            self.get_course_times_structure()
            self.fill_days()
        else:
            self.dialoge_only(u'لا يوجد دورة',u'اختر دورة اولا')
    def add_course_time_st(self):
        d = self.day_select.day_cmb.currentText()
        st = self.day_select.t1.time().toString("hh:mm:ss")
        end = self.day_select.t2.time().toString("hh:mm:ss")
        if self.db.add_course_time_structure(self.gp_id,d,st,end):
            self.get_course_times_structure()
            self.day_select.hide()
    def add_course_time(self):
        d = self.date_select.date_edt.date().toString("yyyy-MM-dd")
        day = self.date_select.date_edt.date().toPython().strftime("%A")
        st = self.date_select.t1.time().toString("hh:mm:ss")
        end = self.date_select.t2.time().toString("hh:mm:ss")
        if self.db.add_course_time(self.gp_id,d,day,st,end):
            self.get_course_times()
            self.date_select.hide()
    def get_course_times_structure(self):
        x = self.db.get_course_structure(self.gp_id)
        self.table_days.setRowCount(0)
        for i in x:
            n = self.table_days.rowCount()
            self.table_days.insertRow(n)
            self.table_days.setItem(n, 0, QTableWidgetItem(unicode(i[1])))
            self.table_days.setItem(n, 1, QTableWidgetItem(unicode(i[2])))
            self.table_days.setItem(n, 2, QTableWidgetItem(unicode(i[3])))
            self.table_days.setItem(n, 3, QTableWidgetItem(u'حذف'))
            self.table_days.item(n, 3).setBackground(QColor(231, 76, 62))
    def fill_days(self):
        self.day_select.day_cmb.clear()
        self.day_select.day_cmb.addItems(['Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday'])
    def get_course_times(self):
        x = self.db.get_course(self.gp_id)
        self.table_dates.setRowCount(0)
        if x:
            for i in x:
                n = self.table_dates.rowCount()
                self.table_dates.insertRow(n)
                xx = QTableWidgetItem(unicode(i[2]))
                xx.setStatusTip(unicode(i[0]))
                self.table_dates.setItem(n, 0, xx)
                self.table_dates.setItem(n, 1, QTableWidgetItem(unicode(i[3])))
                self.table_dates.setItem(n, 2, QTableWidgetItem(unicode(i[4])))
                self.table_dates.setItem(n, 3, QTableWidgetItem(unicode(i[5])))
                self.table_dates.setItem(n, 4, QTableWidgetItem(u'حذف'))
                self.table_dates.setItem(n, 5, QTableWidgetItem(u'تعديل'))
                self.table_dates.item(n, 4).setBackground(QColor(231, 76, 62))
                self.table_dates.item(n, 5).setBackground(QColor(45, 136, 45))
        db = Model()
        db.th_course()
    def buy_mony(self, row, column):
        if column == 6:
            self.mony_dw.showNormal()
            self.mony_dw.activateWindow()
            self.mony_dw.raise_()
            self.mony_dw.name_lbl.setText(self.bill_table.item(row, 0).text())
            self.mony_dw.phone_lbl.setText(self.bill_table.item(row, 1).text())
            self.mony_dw.barcode_lbl.setText(self.bill_table.item(row, 2).text())
            index = self.mony_dw.mid.findText(self.bill_day.currentText(), Qt.MatchFixedString)
            if index >= 0:
                self.mony_dw.mid.setCurrentIndex(index)
            self.mony_dw.gp_lbl.setText(self.gp_id)
            self.mony_dw.tottal_lbl.setText(self.bill_table.item(row, 3).text())
            self.mony_dw.baid_spn.setRange(0, float(self.bill_table.item(row, 5).text()))
            self.mony_dw.baid_spn.setValue(float(self.bill_table.item(row, 5).text()))
    def del_course_time_st(self,row, column):
        if column == 3:
            if self.dialoge_only(u'سيتم حذف معاد هذة المجموعة', u'هل انت متاكد من الحذف') == QMessageBox.Ok:
                if self.db.del_course_time_st(self.gp_id,self.table_days.item(row,0).text(), self.table_days.item(row,1).text(), self.table_days.item(row,2).text()):
                    self.get_course_times_structure()
    def del_course_time(self,row, column):
        if column == 4:
            self.del_course_time_func(self.gp_id, self.table_dates.item(row,0).text(), self.table_dates.item(row,2).text(), self.table_dates.item(row,3).text())
        elif column == 5:
            self.date_select.date_id = self.table_dates.item(row,0).statusTip()
            self.date_select.edt_btn.show()
            self.date_select.add_btn.hide()
            self.date_select.showNormal()
            info = self.db.get_time_by_id(self.date_select.date_id)
            if info:
                self.date_select.date_edt.setDate(info[2])
                self.date_select.t1.setTime((datetime.datetime.min + info[4]).time())
                self.date_select.t2.setTime((datetime.datetime.min + info[5]).time())
    def edite_time(self):
        dt = self.date_select.date_edt.date().toPython()
        t1 = self.date_select.t1.time().toString("hh:mm:ss")
        t2 = self.date_select.t2.time().toString("hh:mm:ss")
        self.db.edt_time_course(self.date_select.date_id,dt,t1,t2)
        self.get_course_times()
        self.date_select.hide()
    def del_course_time_func(self,course,date,t1,t2):
        if self.dialoge_only(u'سيتم حذف معاد هذة المجموعة', u'هل انت متاكد من الحذف') == QMessageBox.Ok:
            if self.db.del_course_time(course,date,t1,t2):
                self.get_course_times()
    def course_time(self):
        self.stackedWidget_2.setCurrentIndex(1)
        self.get_course_times_structure()
        self.stackedWidget_2.setStyleSheet('.QWidget{background:#35485F;color:#fff;}.QLabel{color:#fff;}.QPushButton{color:#fff;}')
        self.widget_7.setStyleSheet('.QWidget{background:#35485F;color:#fff;}.QLabel{color:#fff;}.QPushButton{color:#fff;}')
    def course_time_finish(self):
        self.stackedWidget_2.setCurrentIndex(0)
        self.get_course_times()
        self.stackedWidget_2.setStyleSheet('.QWidget{background:#09C18D;color:#fff;}.QLabel{color:#fff;}.QPushButton{color:#fff;}')
        self.widget_7.setStyleSheet('.QWidget{background:#09C18D;color:#fff;}.QLabel{color:#fff;}.QPushButton{color:#fff;}')
    def centerx(self, x):
        frameGm = x.frameGeometry()
        screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos())
        centerPoint = QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        x.move(frameGm.topLeft())
    def dialoge_only(self, x, y):
        msgBox = QMessageBox()
        msgBox.setFixedSize(150, 100)
        msgBox.setWindowTitle(u'تحذير')
        msgBox.setText(unicode(x))
        msgBox.setInformativeText(y)
        msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        return msgBox.exec_()
    def get_course(self):
        name = self.search_edt.text()
        if name:
            self.get_course_fill(name)
        else:
            self.dialoge_only(u'لا يوجد اسم',u'ادخل الاسم اولا')
    def get_course_fill(self,name):
        info = self.db.get_course_by_name(name)
        if info:
            self.id_lbl.setText(unicode(info[0]))

            self.name_lbl.setText(unicode(info[1]))
            self.course_name.setText(unicode(info[1]))
            self.days_lbl.setText(unicode(info[2]))
            self.course_days.setText(unicode(info[2]))
            self.hours_lbl.setText(unicode(info[3]))
            self.course_hours.setText(unicode(info[3]))
            self.price_lbl.setText(unicode(info[4]))
            self.inst_lbl.setText(unicode(info[5]))
            self.course_inst.setText(unicode(info[5]))
            self.details_lbl.setText(unicode(info[6]))
            self.bill_method.setText(unicode(info[7]))
            self.absence_lbl.setText(unicode(info[8]))
            self.allow_lbl.setText(unicode(info[9]))
            self.allow_lbl_2.setText(unicode(info[10]))

            self.get_course_times_structure()
        else:
            self.dialoge_only(u'لا توجد بيانات لهذة المجموعة', u'ادخل الاسم الصحيح')
    def get_st_cs(self):
        self.color_btn()
        if self.gp_id:
            self.stackedWidget.setCurrentIndex(1)
            x = self.db.get_st_cs(self.gp_id)
            self.st_cs_table.setRowCount(0)
            if x:
                for i in x:
                    n = self.st_cs_table.rowCount()
                    self.st_cs_table.insertRow(n)
                    self.st_cs_table.setItem(n, 0, QTableWidgetItem(i[0]))
                    self.st_cs_table.setItem(n, 1, QTableWidgetItem(i[1]))
                    self.st_cs_table.setItem(n, 2, QTableWidgetItem(i[2]))
                    self.st_cs_table.setItem(n,3,QTableWidgetItem(str(i[3])))
                    self.st_cs_table.setItem(n, 4, QTableWidgetItem(u'حذف'))
                    self.st_cs_table.item(n, 4).setBackground(QColor(231, 76, 62))
                    self.st_cs_table.setItem(n, 5, QTableWidgetItem(u'طباعة'))
                    self.st_cs_table.item(n, 5).setBackground(QColor(136, 45, 136))
                    self.st_cs_table.setItem(n, 6, QTableWidgetItem(u'نقل'))
                    self.st_cs_table.item(n, 6).setBackground(QColor(45, 150, 45))
        else:
            self.dialoge_only(u'لا يوجد دورة', u'اختر دورة اولا')
    def del_st_cs(self, row, column):
        if column == 4:
            if self.dialoge_only(u'سيتم حذف الطالب من هذة المجموعة', u'هل انت متاكد من الحذف') == QMessageBox.Ok:
                if self.db.del_st_cs(self.st_cs_table.item(row,2).text(),self.gp_id):
                    self.get_st_cs()
                else:
                    self.dialoge_only(u'لم تتم عملية الحذف', u'راجع الاتصال بالشبكة')
        elif column == 5:
            self.bc_num.pre_show([[self.st_cs_table.item(row,2).text(),self.st_cs_table.item(row,0).text()]])
        elif column == 6:
            self.st_gp_switch.st_bc = self.st_cs_table.item(row,2).text()
            self.st_gp_switch.showNormal()
            self.st_gp_switch.raise_()
            self.st_gp_switch.activateWindow()
            self.st_gp_switch.label_3.setText(self.gp_id)
            self.st_gp_switch.comboBox.clear()
            for i in self.db.get_all_courses():
                if i[1] != self.gp_id:
                    self.st_gp_switch.comboBox.addItem(i[1])
        elif column==3:
            self.special_price.show()
            self.special_price.raise_()
            self.special_price.activateWindow()
            self.barcode = self.st_cs_table.item(row,2).text()
    def update_price(self):
        new_price=self.special_price.price_spn.value()
        self.db.edite_price(new_price,self.gp_id,self.barcode)
        self.get_st_cs()
        self.special_price.close()


    def print_attend(self):
        course = self.cmb.text()
        day = self.attend_day.currentText()
        if course and day:
            self.pr.print_attend(self.get_data_attend(),course,day)
        else:
            self.dialoge_only(u'لا يوجد بيانات للطباعة',u'راجع بيانات البحث')
    def print_mony(self):
        course = self.gp_id
        day = self.bill_day.currentText()
        tottal = self.tottal.text()
        baid = self.baid.text()
        rest = self.rest.text()
        if course and day:
            self.pr.print_attend(self.get_data_attend(),course,day,tottal,baid,rest)
        else:
            self.dialoge_only(u'لا يوجد بيانات للطباعة',u'راجع بيانات البحث')
    def get_data_attend(self):
        s = []
        a = []
        n = self.st_attend_table.columnCount()
        for i in range(n):
            s.append(self.st_attend_table.horizontalHeaderItem(i).text())
        a.append(s)
        x = self.st_attend_table.rowCount()
        for i in range(x):
            s = []
            for j in range(n):
                s.append(self.st_attend_table.item(i,j).text())
            a.append(s)
        return a
    def get_data_mony(self):
        s = []
        a = []
        n = self.bill_table.columnCount()
        for i in range(n):
            s.append(self.bill_table.horizontalHeaderItem(i).text())
        a.append(s)
        x = self.bill_table.rowCount()
        for i in range(x):
            s = []
            for j in range(n):
                s.append(self.bill_table.item(i,j).text())
            a.append(s)
        return a
    def buy_mony_db(self):
        if self.db.put_st_mony(self.mony_dw.barcode_lbl.text(),self.mony_dw.gp_lbl.text(),self.db.get_method_price(self.mony_dw.gp_lbl.text())[0],self.mony_dw.mid.currentText(),self.mony_dw.baid_spn.value()):
            self.mony_dw.hide()
            self.get_mony()
    def get_mony_id(self):
        c = 0
        indx = 0
        course_name = self.db.get_course_bill(self.gp_id)  #method of payment
        if course_name == u'بالحصة':
            v = self.db.get_course_days(self.gp_id)
            self.bill_day.clear()
            d = datetime.date.today()
            self.mony_dw.mid.clear()
            for i in v:
                if d == i[0]:
                    indx = c
                c += 1
                self.bill_day.addItem(str(i[0]) + " : " + str(i[1]) + " : " + str(i[2]))
                self.mony_dw.mid.addItem(str(i[0]) + " : " + str(i[1]) + " : " + str(i[2]))
            self.bill_day.setCurrentIndex(indx)
        elif course_name == u'بالشهر':
            v = self.db.get_course_months(self.gp_id)  #get dates of course
            self.bill_day.clear()
            self.mony_dw.mid.clear()
            self.bill_day.addItems(v)
            self.mony_dw.mid.addItems(v)
            d = datetime.date.today()
            indx = self.bill_day.findText(unicode(d.month) + " - " + unicode(d.year))
            if indx >= 0:
                self.bill_day.setCurrentIndex(indx)
            else:
                self.bill_day.setCurrentIndex(0)
        else:
            self.bill_day.clear()
            self.mony_dw.mid.clear()
            self.bill_day.addItem(self.gp_id)
            self.mony_dw.mid.addItem(self.gp_id)

    def add_st(self):
        barcode = self.st_dw.bc_edt.text()
        nm = self.st_dw.nm_edt.text()
        school = self.st_dw.school_edt.text()
        sph = self.st_dw.ph_edt.text()
        fph = self.st_dw.fphon_edt.text()
        add = self.st_dw.address_edt.text()
        mail = self.st_dw.mail_edt.text()
        det = self.st_dw.details_edt.toPlainText()
        if barcode and nm:
            s_exist = self.db.student_exist(barcode, nm)  #checking the existance of student.  if it exist it will return 2 or 3 and if  it does not exist it will return 1
            if s_exist == 1:  #this is mean that the student does not exist
                if not self.db.add_student(barcode,nm,school,sph,fph,mail,add,det): #insert student info in student table
                    self.dialoge_only(u'خطأ فى اضافة الطالب',u'يرجى اعادة ادخال القيم الصحيحة')
                else:
                    self.get_st_current(barcode)
                    self.clear_st()
                    self.st_dw.hide()
            elif s_exist == 2:
                self.dialoge_only(u'الباركود موجود من قبل', u'راجع البيانات وادخل بيانات جديدة')
            elif s_exist == 3:
                self.dialoge_only(u'الاسم موجود من قبل', u'راجع البيانات وادخل بيانات جديدة')
        else:
            self.dialoge_only(u'البيانات غير كاملة', u'ادخل الاسم والباركود على الاقل')
    def clear_st(self):
        self.st_dw.bc_lbl.clear()
        self.st_dw.ph_lbl.clear()
        self.st_dw.bc_edt.clear()
        self.st_dw.nm_edt.clear()
        self.st_dw.school_edt.clear()
        self.st_dw.ph_edt.clear()
        self.st_dw.fphon_edt.clear()
        self.st_dw.address_edt.clear()
        self.st_dw.mail_edt.clear()
        self.st_dw.details_edt.clear()
    def get_st_current(self ,st ):
        if st:
            barcode = self.db.get_student(st)  #select student info from student table by brcode
            if barcode:
                course = self.gp_id
                price=self.db.get_course_price(course)
                if self.db.st_gp_not_exist(barcode[0], course):
                    if self.db.add_st_gp(barcode[0], course,price):
                        self.get_st_cs()
                        self.st_edt_2.selectAll()
                    else:
                        self.dialoge_only(u'لم تتم عملية الاضافة بنجاح', u'حاول مرة اخرى')
                else:
                    self.dialoge_only(u'الطالب موجود فى المجموعة بالفعل', u'اختر مجموعة اخرى')

            else:
                self.dialoge_only(u'لا توجد بيانات لهذا المتدرب', u'ادخل الاسم الصحيح')
        else:
            self.dialoge_only(u'لا يوجد اسم',u'ادخل الاسم اولا')
예제 #2
0
파일: student.py 프로젝트: khanafeer/TBAT
class student_info(QWidget, st_info):
    BC = 0

    def __init__(self):
        QWidget.__init__(self)
        self.setupUi(self)
        self.setWindowTitle(u'تفاصيل الطالب')
        self.db = Model()
        self.pr = print_doc()
        self.gp_dw = gp_dw()
        self.st_gp_switch = st_gp_switch()
        self.centerx(self.st_gp_switch)
        self.mony_dw = mony_dw()
        self.centerx(self.gp_dw)
        self.centerx(self.mony_dw)
        for i in self.findChildren(QWidget):
            i.setAttribute(Qt.WA_StyledBackground, True)
        self.groups_btn.clicked.connect(self.student_group)
        self.add_group_btn.clicked.connect(self.show_gp_get)
        self.gp_dw.add_btn.clicked.connect(self.add_st_course)
        self.table_st_course.cellClicked.connect(self.del_st_course)
        self.attend_btn.clicked.connect(self.fill_courses_att)
        self.mony_btn.clicked.connect(self.fill_courses_mn)
        self.course_cmb.currentIndexChanged.connect(self.fill_att_months)
        self.att_search_btn.clicked.connect(self.attend_st_fill)
        self.month_cmb.currentIndexChanged.connect(self.attend_st_fill)
        self.mn_search_btn.clicked.connect(self.mony_st_fill)
        self.course_mn_cmb.currentIndexChanged.connect(self.mony_st_fill)
        self.mn_table.cellClicked.connect(self.buy_mony)
        self.mony_dw.put_mony_btn.clicked.connect(self.buy_mony_db)
        self.att_print_btn.clicked.connect(self.print_attend)
        self.mn_print_btn.clicked.connect(self.print_mony)
        self.connect(self.att_table,
                     SIGNAL("doubleClicked(const QModelIndex&)"),
                     self.change_st_status)
        self.color_btn()
        self.st_gp_switch.pushButton.clicked.connect(self.switch)

    def focusInEvent(self, *args, **kwargs):
        indx = self.stackedWidget.currentIndex()
        if indx == 0:
            self.student_group()
        elif indx == 1:
            self.fill_courses_att()
        else:
            self.fill_courses_mn()

    def switch(self):
        if self.db.student_group_swift(
                self.BC, self.st_gp_switch.label_3.text(),
                self.st_gp_switch.comboBox.currentText()):
            self.show_st_courses()
            self.st_gp_switch.hide()

    def color_btn(self):
        try:
            for i in self.widget_4.findChildren(QPushButton):
                i.setStyleSheet("background:#05B963;")
            self.sender().setStyleSheet("background:#A8B1B2;")
        except:
            self.mony_btn.setStyleSheet("background:#A8B1B2;")

    def set_bc(self, bc):
        self.BC = bc

    def buy_mony(self, row, column):
        self.get_mony_id()
        if column == 4:
            self.mony_dw.show()
            self.mony_dw.activateWindow()
            self.mony_dw.raise_()
            self.mony_dw.barcode_lbl.setText(self.BC)
            index = self.mony_dw.mid.findText(
                self.mn_table.item(row, 0).text(), Qt.MatchFixedString)
            if index >= 0:
                self.mony_dw.mid.setCurrentIndex(index)
            self.mony_dw.gp_lbl.setText(self.course_mn_cmb.currentText())
            self.mony_dw.tottal_lbl.setText(self.mn_table.item(row, 1).text())
            self.mony_dw.baid_spn.setValue(
                float(self.mn_table.item(row, 3).text()))
            self.mony_dw.baid_spn.setRange(
                0, float(self.mn_table.item(row, 3).text()))

    def get_mony_id(self):
        cname = self.course_mn_cmb.currentText()
        course_name = self.db.get_course_by_name(cname)[7]
        if course_name == u'بالحصة':  #fill  mony_dw with  the days of the course
            v = self.db.get_course_days(cname)
            self.mony_dw.mid.clear()
            for i in v:
                self.mony_dw.mid.addItem(
                    str(i[0]) + " : " + str(i[1]) + " : " + str(i[2]))
        elif course_name == u'بالشهر':  #fill mony_dw with the monthes of the course
            v = self.db.get_course_months(cname)
            self.mony_dw.mid.clear()
            self.mony_dw.mid.addItems(v)
        else:
            self.mony_dw.mid.clear()
            self.mony_dw.mid.addItem(cname)

    def print_attend(self):
        course = self.course_cmb.currentText()
        month = self.month_cmb.currentText()
        if course and month:
            self.pr.print_attend_st(self.get_data_attend(), course, month,
                                    self.name_lbl.text(), self.ph_lbl.text(),
                                    self.fph_lbl.text())
        else:
            self.dialoge_only(u'لا يوجد بيانات للطباعة', u'راجع بيانات البحث')

    def print_mony(self):
        course = self.course_mn_cmb.currentText()
        if course:
            self.pr.print_mony_st(self.get_data_mony(), course,
                                  self.name_lbl.text(), self.ph_lbl.text(),
                                  self.fph_lbl.text())
        else:
            self.dialoge_only(u'لا يوجد بيانات للطباعة', u'راجع بيانات البحث')

    def get_data_attend(self):
        s = []
        a = []
        n = self.att_table.columnCount()
        for i in range(n):
            s.append(self.att_table.horizontalHeaderItem(i).text())
        a.append(s)
        x = self.att_table.rowCount()
        for i in range(x):
            s = []
            for j in range(n):
                s.append(self.att_table.item(i, j).text())
            a.append(s)
        return a

    def get_data_mony(self):
        s = []
        a = []
        n = self.mn_table.columnCount()
        for i in range(n - 1):
            s.append(self.mn_table.horizontalHeaderItem(i).text())
        a.append(s)
        x = self.mn_table.rowCount()
        for i in range(x):
            s = []
            for j in range(n - 1):
                s.append(self.mn_table.item(i, j).text())
            a.append(s)
        return a

    def buy_mony_db(self):
        self.color_btn()
        if self.db.put_st_mony(
                self.mony_dw.barcode_lbl.text(), self.mony_dw.gp_lbl.text(),
                self.db.get_method_price(self.mony_dw.gp_lbl.text())[0],
                self.mony_dw.mid.currentText(), self.mony_dw.baid_spn.value()):
            self.mony_dw.hide()
            self.mony_st_fill()

    def show_gp_get(self):
        self.gp_dw.show()
        self.gp_dw.activateWindow()
        self.gp_dw.raise_()
        self.gp_dw.course_cmb.clear()
        self.gp_dw.course_cmb.addItems(self.db.get_groups())

    def fill_courses_att(self):
        self.color_btn()
        if self.BC:
            cs = self.db.get_groups_st(self.BC)
            self.course_cmb.clear()
            self.course_cmb.addItems(cs)
            self.stackedWidget.setCurrentIndex(1)
        else:
            self.dialoge_only(u'لا يوجد طالب', u'اختر طالب اولا')

    def fill_courses_mn(self):
        self.color_btn()
        if self.BC:
            cs = self.db.get_groups_st(self.BC)
            self.course_mn_cmb.clear()
            self.course_mn_cmb.addItems(cs)
            self.stackedWidget.setCurrentIndex(2)
        else:
            self.dialoge_only(u'لا يوجد طالب', u'اختر طالب اولا')

    def fill_att_months(self):
        name = self.course_cmb.currentText()
        if name:
            mn = self.db.get_course_months(name)
            self.month_cmb.clear()
            self.month_cmb.addItems(mn)

    def student_group(self):
        self.color_btn()
        if self.BC:
            self.stackedWidget.setCurrentIndex(0)
            self.show_st_courses()
        else:
            self.dialoge_only(u'لا يوجد طالب', u'اختر طالب اولا')

    def show_st_courses(self):
        x = self.db.get_st_gp(self.BC)
        self.table_st_course.setRowCount(0)
        for i in x:
            n = self.table_st_course.rowCount()
            self.table_st_course.insertRow(n)
            self.table_st_course.setItem(n, 0, QTableWidgetItem(unicode(i[0])))
            self.table_st_course.setItem(n, 1, QTableWidgetItem(unicode(i[1])))
            self.table_st_course.setItem(n, 2, QTableWidgetItem(unicode(i[2])))
            self.table_st_course.setItem(n, 3, QTableWidgetItem(u'حذف'))
            self.table_st_course.item(n, 3).setBackground(QColor(231, 76, 62))
            self.table_st_course.setItem(n, 4, QTableWidgetItem(u'تبديل'))
            self.table_st_course.item(n, 4).setBackground(QColor(45, 180, 45))

    def del_st_course(self, row, column):
        if column == 3:
            if self.dialoge_only(u'سيتم حذف الطالب من هذة الدورة',
                                 u'هل انت متاكد من الحذف') == QMessageBox.Ok:
                if self.db.del_st_course(
                        self.BC,
                        self.table_st_course.item(row, 0).text()):
                    self.show_st_courses()
        elif column == 4:
            self.st_gp_switch.st_bc = self.BC
            self.st_gp_switch.showNormal()
            self.st_gp_switch.raise_()
            self.st_gp_switch.activateWindow()
            self.st_gp_switch.setFocus()
            self.st_gp_switch.label_3.setText(
                self.table_st_course.item(row, 0).text())
            self.st_gp_switch.comboBox.clear()
            for i in self.db.get_all_courses():
                if i[1] != self.st_gp_switch.label_3.text():
                    self.st_gp_switch.comboBox.addItem(i[1])

    def add_st_course(self):
        if self.gp_dw.course_cmb.currentText():
            course = self.gp_dw.course_cmb.currentText()
            st_phone = self.BC
            if self.db.st_gp_not_exist(st_phone, course):
                if self.db.add_st_gp(st_phone, course):
                    self.gp_dw.hide()
                    self.show_st_courses()
                else:
                    self.dialoge_only(u'لم تتم عملية الاضافة بنجاح',
                                      u'حاول مرة اخرى')
            else:
                self.dialoge_only(u'الطالب موجود فى المجموعة بالفعل',
                                  u'جرب مجموعة اخرى')

    def centerx(self, x):
        frameGm = x.frameGeometry()
        screen = QApplication.desktop().screenNumber(
            QApplication.desktop().cursor().pos())
        centerPoint = QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        x.move(frameGm.topLeft())

    def dialoge_only(self, x, y):
        msgBox = QMessageBox()
        msgBox.setFixedSize(150, 100)
        msgBox.setWindowTitle(u'تحذير')
        msgBox.setText(unicode(x))
        msgBox.setInformativeText(y)
        msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        return msgBox.exec_()

    def mony_st_fill(self):
        cname = self.course_mn_cmb.currentText()

        method_price = self.db.get_method_price(cname)
        if cname:
            price_for_studetn = self.db.get_course_price_by_name(
                cname, self.BC)

        tottal = 0
        baid = 0
        if method_price:
            self.mn_table.setRowCount(0)
            if method_price[0] == u'بالحصة':
                v = self.db.get_course_days(cname)
                for i in v:
                    n = self.mn_table.rowCount()
                    self.mn_table.insertRow(n)
                    x = self.db.get_st_mony(
                        self.BC, cname,
                        str(i[0]) + " : " + str(i[1]) + " : " + str(i[2]))
                    self.mn_table.setItem(
                        n, 0,
                        QTableWidgetItem(
                            str(i[0]) + " : " + str(i[1]) + " : " + str(i[2])))
                    self.mn_table.setItem(
                        n, 1, QTableWidgetItem(unicode(price_for_studetn)))
                    self.mn_table.setItem(n, 2, QTableWidgetItem(unicode(x)))
                    self.mn_table.setItem(
                        n, 3, QTableWidgetItem(unicode(price_for_studetn - x)))
                    self.mn_table.setItem(n, 4, QTableWidgetItem(u'دفع'))
                    self.mn_table.item(n, 4).setBackground(QColor(20, 200, 10))
                    tottal += method_price[1]
                    baid += x
            elif method_price[0] == u'بالشهر':
                v = self.db.get_course_months(cname)
                for i in v:
                    n = self.mn_table.rowCount()
                    self.mn_table.insertRow(n)
                    x = self.db.get_st_mony(self.BC, cname, i)
                    self.mn_table.setItem(n, 0, QTableWidgetItem(i))
                    self.mn_table.setItem(
                        n, 1, QTableWidgetItem(unicode(price_for_studetn)))
                    self.mn_table.setItem(n, 2, QTableWidgetItem(unicode(x)))
                    self.mn_table.setItem(
                        n, 3, QTableWidgetItem(unicode(price_for_studetn - x)))
                    self.mn_table.setItem(n, 4, QTableWidgetItem(u'دفع'))
                    self.mn_table.item(n, 4).setBackground(QColor(20, 200, 10))
                    tottal += method_price[1]
                    baid += x
            else:
                n = self.mn_table.rowCount()
                self.mn_table.insertRow(n)
                x = self.db.get_st_mony(self.BC, cname, cname)
                self.mn_table.setItem(n, 0, QTableWidgetItem(cname))
                self.mn_table.setItem(
                    n, 1, QTableWidgetItem(unicode(price_for_studetn)))
                self.mn_table.setItem(n, 2, QTableWidgetItem(unicode(x)))
                self.mn_table.setItem(
                    n, 3, QTableWidgetItem(unicode(price_for_studetn - x)))
                self.mn_table.setItem(n, 4, QTableWidgetItem(u'دفع'))
                self.mn_table.item(n, 4).setBackground(QColor(20, 200, 10))
                tottal += method_price[1]
                baid += x
            self.tottal_mony.setText(unicode(tottal))
            self.baid_mony.setText(unicode(baid))
            self.rest_mony.setText(unicode(tottal - baid))
        else:
            self.mn_table.setRowCount(0)
            self.tottal_mony.setText("0")
            self.baid_mony.setText("0")
            self.rest_mony.setText("0")

    def change_st_status(self, indx):
        col = indx.row()
        st = self.BC
        info = self.att_table.item(col, 0).text().split(" : ")
        gpid = self.db.get_course_by_name(self.course_cmb.currentText())[0]
        dt_st = self.att_table.item(col, 1).text()
        if dt_st == u'غائب':
            if self.db.attend_st_gp(st, gpid, info[0], info[1], info[2],
                                    u'حضور'):
                self.att_table.setItem(col, 1, QTableWidgetItem(u'حاضر'))
        else:
            if self.db.attend_st_gp(st, gpid, info[0], info[1], info[2],
                                    u'غياب'):
                self.att_table.setItem(col, 1, QTableWidgetItem(u'غائب'))

    def attend_st_fill(self):
        v = self.db.get_course_dates(self.course_cmb.currentText())
        if self.month_cmb.currentText():
            mon = self.month_cmb.currentText().split(" - ")[0]
            year = self.month_cmb.currentText().split(" - ")[1]
            self.att_table.setRowCount(0)
            att = 0
            aps = 0
            for i in v:
                if str(i[0].month) == mon and str(i[0].year) == year:
                    n = self.att_table.rowCount()
                    self.att_table.insertRow(n)
                    self.att_table.setItem(
                        n, 0,
                        QTableWidgetItem(
                            str(i[0]) + " : " + str(i[1]) + " : " + str(i[2])))
                    if self.db.check_attend(self.BC, i[0], i[1], i[2]):
                        att += 1
                        self.att_table.setItem(n, 1, QTableWidgetItem(u'حاضر'))
                    else:
                        aps += 1
                        self.att_table.setItem(n, 1, QTableWidgetItem(u'غائب'))
            if self.month_cmb.currentText():
                self.att_table.resizeColumnsToContents()
                self.attend.setText(unicode(att))
                self.absent.setText(unicode(aps))
                try:
                    self.ratio.setText(unicode((att / (att + aps)) * 100))
                except:
                    self.ratio.setText(unicode(0))