Beispiel #1
0
def get_receipt(id):
    print(id)
    if current_user.is_authenticated:
        receipt = TuitionReceipt.objects(id=id).first()
        print(receipt, receipt.list_detail)
        if receipt:
            data = list()
            for item in receipt.list_detail:
                print("123")
                ele = {
                    'id': str(item.id),
                    'user_name':
                    item.created_user.first_name + item.created_user.last_name,
                    'tuition': item.tuition,
                    'money_return': item.money_return,
                    'created_date': item.created_date
                }
                data.append(ele)
            response = {
                'status': True,
                'message': 'Get Receipt Success',
                'data': data
            }
    else:
        response = {
            'status': False,
            'message': 'Get Receipt Failed',
            'data': None
        }
    return response
Beispiel #2
0
def update_receipt(id):
    activate = list(range(10))
    activate[1] = "active"
    if current_user.is_authenticated:
        receipt = TuitionReceipt.objects(id=id).first()
        form = UpdateStudentToClass()
        if id is None or receipt is None:
            return redirect(url_for('student.index'))

        if form.validate_on_submit():
            next_tuition = float(form.next_pay.data)

            reservate_tuition = float(form.reservate_tuition.data)
            tuition_left = receipt.course.tuition - (reservate_tuition +
                                                     next_tuition)

            print(receipt.course.tuition, reservate_tuition, next_tuition,
                  tuition_left)
            money_return = 0
            status = False
            if tuition_left <= 0:
                status = True
                money_return = -1 * tuition_left
                tuition_left = 0

            detail_receipt = DetailTuitionReceipt(
                tuition=next_tuition,
                money_return=money_return,
                created_user=current_user.user).save()
            receipt.list_detail.append(detail_receipt)
            receipt.tuition_left = tuition_left
            receipt.reservate_tuition = reservate_tuition + next_tuition
            receipt.status = status
            receipt.updated_date = datetime.utcnow()
            receipt.save()
            flash('Receipt has been updated!', 'success')
            return redirect(
                url_for('student.student_info', id=receipt.student.id))

        form.first_name.data = receipt.student.first_name
        form.last_name.data = receipt.student.last_name
        form.phone.data = receipt.student.phone
        form.email.data = receipt.student.email
        form.address.data = receipt.student.address
        form.birth.data = receipt.student.birth
        form.gender.data = receipt.student.gender
        form.reservate_tuition.data = receipt.reservate_tuition
        form.course.data = receipt.course.id_course
        form.course_name.data = receipt.course.name
        form.shift.data = receipt.course.shift.name
        form.course_tuition.data = receipt.course.tuition
        form.money_return.data = 0

        return render_template('student_update_receipt.html',
                               title='Update Student\'s Receipt',
                               activate=activate,
                               receipt=receipt,
                               form=form)
    return redirect(url_for('users.login'))
Beispiel #3
0
def remove(id):
    activate = list(range(10))
    activate[1] = "active"
    role = Role.objects(name="student").first()
    student = User.objects(role=role, id=id, is_activate=True).first()
    if student:
        receipts = TuitionReceipt.objects(student=student)
        if len(receipts) > 0:
            flash('Student can\'t remove !!', 'danger')
            return redirect(url_for('student.student_info', id=student.id))
        student.is_activate = False
        student.save()
        flash('Student delete success !!', 'success')
    return redirect(url_for('student.index', page=1))
Beispiel #4
0
def educate_info(id):
    if current_user.is_authenticated:
        activate = list(range(10))
        activate[3] = "active"
        form = UpdateCourseForm()
        if id is None:
            return redirect(url_for('educate.index'))
        course = Course.objects(id=id).first_or_404()
        if form.validate_on_submit():
            role_teacher = Role.objects(name='teacher').first()
            list_teacher = User.objects(role=role_teacher, is_activate=True)
            course.name = form.name.data
            course.start_date = form.start_date.data
            course.finish_date = form.finish_date.data
            course.tuition = float(form.tuition.data)
            shift = Shift.objects(name=form.shift.data).first()
            course.shift = shift
            for item in list_teacher:
                if item.first_name + ' ' + item.last_name == form.teacher.data:
                    course.teacher = item
                    break

            if form.status.data == 'True':
                course.status = True
            else:
                course.status = False
            course.save()
            flash('Course has been updated!', 'success')
            return redirect(url_for('educate.educate_info', id=id))
        elif request.method == 'GET':
            form.id_course.data = course.id_course
            form.name.data = course.name
            form.start_date.data = course.start_date
            form.finish_date.data = course.finish_date
            form.tuition.data = course.tuition

            form.shift.data = course.shift.name
            form.teacher.data = course.teacher.first_name + ' ' + course.teacher.last_name

            form.status.data = course.status
            TuitionReceipts = TuitionReceipt.objects(course=course)
        return render_template('educate_info.html',
                               title='Educate Info',
                               activate=activate,
                               form=form,
                               students=course.list_student,
                               id_course=id,
                               TuitionReceipts=TuitionReceipts)
    return redirect(url_for('users.login'))
Beispiel #5
0
def student_info(id):
    activate = list(range(10))
    activate[1] = "active"
    if current_user.is_authenticated:

        user = User.objects(id=id, is_activate=True).first()
        form = UpdateUserForm()
        if id is None or user is None:
            return redirect(url_for('student.index', page=1))

        if form.validate_on_submit():
            if form.picture.data:
                picture_file = save_picture(form.picture.data)
                user.image_file = picture_file
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            user.phone = form.phone.data
            user.email = form.email.data
            user.address = form.address.data
            user.birth = form.birth.data
            user.gender = form.gender.data

            user.save()
            flash('Student has been updated!', 'success')
            return redirect(url_for('student.student_info', id=id))
        elif request.method == 'GET':
            form.first_name.data = user.first_name
            form.last_name.data = user.last_name
            form.phone.data = user.phone
            form.email.data = user.email
            form.address.data = user.address
            form.gender.data = user.gender
            form.birth.data = user.birth

        receipts = TuitionReceipt.objects(student=user)
        return render_template('student_info.html',
                               title='Student Info',
                               activate=activate,
                               student=user,
                               form=form,
                               receipts=receipts)
    return redirect(url_for('users.login'))
Beispiel #6
0
def remove(id): 
    activate = list(range(10))
    activate[4] = "active"  
    role = Role.objects(name="staff").first()
    staff = User.objects(id=id,is_activate=True).first()
    account = Account.objects(user=staff).first()
    
    if staff and account:
        TuitionReceipts = TuitionReceipt.objects(student=staff)
        if len(TuitionReceipts) > 0:
            flash('Staff can\'t remove !!', 'danger')
            return redirect(url_for('staff.staff_info',id=staff.id)) 
        staff.is_activate = False 
        account.is_activate = False
        staff.save()  
        account.save()
        flash('Staff delete success !!', 'success') 
        return redirect(url_for('staff.index',page=1))
    flash('Can\'t find staff !!', 'danger')
    return redirect(url_for('staff.index',page=1))
Beispiel #7
0
def create_receipt(id):
    activate = list(range(10))
    activate[1] = "active"
    if current_user.is_authenticated:
        user = User.objects(id=id, is_activate=True).first()
        form = AddStudentToClass()
        if id is None or user is None:
            return redirect(url_for('student.index'))

        if form.validate_on_submit():
            id_course = form.course.data
            course = Course.objects(id=id_course).first()
            reservate_tuition = float(form.reservate_tuition.data)
            tuition_left = course.tuition - reservate_tuition
            money_return = 0
            status = False
            if tuition_left <= 0:
                status = True
                money_return = -1 * tuition_left
                tuition_left = 0
            if course is None:
                flash('Can\'t find class, please inform to admin!', 'danger')
                return redirect(url_for('student.create_receipt', id=id))
            list_detail_tuition = list()
            course.list_student.append(user)
            if len(course.list_student) > 5:
                course.status = True
            course.save()
            detail_receipt = DetailTuitionReceipt(
                tuition=reservate_tuition,
                money_return=money_return,
                created_user=current_user.user).save()
            list_detail_tuition.append(detail_receipt)
            receipt = TuitionReceipt(student=user,
                                     course=course,
                                     reservate_tuition=reservate_tuition,
                                     tuition_left=tuition_left,
                                     list_detail=list_detail_tuition,
                                     status=status).save()
            flash('Receipt has been created!', 'success')
            return redirect(url_for('student.student_info', id=id))

        # list_course = Course.objects.all()
        # form.course_choices = [(str(c['id']), c['id_course']) for c in list_course if c.finish_date >= datetime.utcnow()]

        # list_shift = Shift.objects.all()
        # form.shift_choices = [(str(c['id']), c['name']) for c in list_shift]

        form.first_name.data = user.first_name
        form.last_name.data = user.last_name
        form.phone.data = user.phone
        form.email.data = user.email
        form.address.data = user.address
        form.birth.data = user.birth
        form.gender.data = user.gender
        form.reservate_tuition.data = 0
        form.money_return.data = 0
        return render_template('student_create_receipt.html',
                               title='Student Info',
                               activate=activate,
                               student=user,
                               form=form)
    return redirect(url_for('users.login'))