Ejemplo n.º 1
0
def send_inform_approve_payment(req_pay):
    content = render_to_string("admin/email/student/payment_approve.html",
                               {"data": req_pay})
    subject = "[ODIN] Phê duyệt thông tin thanh toán"

    attach_file = None
    # Attach receipt
    student_debts = StudentDebt.objects.filter(
        centre=req_pay.centre,
        course=req_pay.course,
        student__user__email=req_pay.email)
    if student_debts.count() > 0:
        receipt = create_receipt_info(student_debts[0])
        receipt.paid_amount = currency(req_pay.paid_amount)
        pdf = html_to_pdf(template='admin/student_receipt.html', data=receipt)
        attach_file = {
            "name": "Hoá đơn thanh toán.pdf",
            "content": pdf,
            "mimetype": "application/pdf"
        }
    send_inform_change_payment_status(to_name=req_pay.full_name,
                                      to_email=req_pay.email,
                                      subject=subject,
                                      content=content,
                                      attach_files=[attach_file])
    # Nếu đã tạo công nợ và là lần đầu thanh toán => gửi hợp đồng công nợ cho sinh viên
    if attach_file and Payment.objects.filter(
            student_debt__id__in=student_debts.values_list(
                "id", flat=True)).count() == 1:
        send_email_create_contract(req_pay=req_pay)
Ejemplo n.º 2
0
def get_must_pay_amount_api(request):
    if request.method == 'GET':
        course_id = None
        shift_select = None
        reward_code = None
        if 'course_id' in request.GET and request.GET['course_id']:
            course_id = request.GET['course_id']

        if 'reward_code' in request.GET and request.GET['reward_code']:
            reward_code = request.GET['reward_code'].strip()

        if 'shift_select' in request.GET and request.GET['shift_select']:
            shift_select = int(request.GET['shift_select'].strip())

        must_pay_amount = calculate_must_pay_amount(course_id=course_id, shift_select=shift_select, reward_code=reward_code)

        return JsonResponse({'result': "success", 'must_pay_amount': currency(must_pay_amount)})
Ejemplo n.º 3
0
def get_dashboard_header_data(request):
    if request.method == 'GET':
        count_users = currency(AuthUser.objects.all().count())
        count_students = currency(Student.objects.all().count())
        count_teachers = currency(Teacher.objects.all().count())
        count_classes = currency(Classes.objects.all().count())
        count_contracts = currency(StudentDebt.objects.all().count())
        sum_revenues = Payment.objects.aggregate(Sum('paid_amount'))['paid_amount__sum']
        sum_remain_amount = StudentDebt.objects.aggregate(Sum('rest_amount'))['rest_amount__sum']

        # Tổng SV/Tổng SV hoàn phí/Tổng SV chờ lớp/Tổng SV đang học/Tổng SV tốt nghiệp
        # Tổng sv hoàn phí
        count_back_amount_students = currency(StudentDebt.objects.filter(back_amount__gt=0).count())
        # Tổng sv chờ lớp (tổng sv trong lớp chờ)
        count_waiting_cls_students = currency(ClassesStudents.objects.filter(state=1).count())
        # Tổng sv đang học
        number_students_students = currency(ClassesStudents.objects.filter(state=2).count())
        # Tổng sv tốt nghiệp
        number_graduated_students = currency(ClassesStudents.objects.filter(state=3).count())
        number_students_statics = "%s/%s/%s/%s%s" % (str(count_students), str(count_back_amount_students),
                                                     str(count_waiting_cls_students), str(number_students_students),
                                                     str(number_graduated_students))
        # Tổng lớp đã khai giảng
        number_started_classes = currency(Classes.objects.filter(start_date__lte=date.today()).count())

        # Tổng buổi học đã hoàn thành
        number_study_shift_complete = StudyShift.objects.filter(Q(session_date__lt=date.today())).count() \
                                      + StudyShift.objects.filter(Q(session_date=date.today()),
                                                                  Q(to_time__lt=datetime.datetime.now().time())).count()
        number_study_shift = StudyShift.objects.all().count()

        # Tổng buổi học đã hoàn thành/Tổng buổi học còn phải hoàn thành
        number_study_shift_statics = "%s/%s" % (str(currency(number_study_shift_complete)),
                                                str(currency(number_study_shift - number_study_shift_complete)))

        sum_discount = StudentDebt.objects.all().values('origin_amount', 'discount_percent').annotate(
            discount=F('origin_amount') * F('discount_percent') / 100).aggregate(Sum('discount'))['discount__sum']

        return JsonResponse({'number_users': count_users,
                             'number_students': count_students,
                             'number_teachers': count_teachers,
                             'number_classes': count_classes,
                             'number_contracts': count_contracts,
                             'number_revenues': currency(sum_revenues),
                             'sum_remain_amount': currency(sum_remain_amount),
                             'number_students_statics': number_students_statics,
                             'number_started_classes': number_started_classes,
                             'number_study_shift_statics': number_study_shift_statics,
                             'sum_discount': currency(sum_discount)})
Ejemplo n.º 4
0
 def get_paid_amount_total(self, obj):
     paid_amount = Payment.objects.filter(student_debt=obj).aggregate(
         Sum('paid_amount'))['paid_amount__sum']
     if not paid_amount:
         paid_amount = 0
     return currency(paid_amount)
Ejemplo n.º 5
0
 def get_origin_amount(self, obj):
     return currency(obj.origin_amount)
Ejemplo n.º 6
0
 def get_paid_amount(self, obj):
     return currency(obj.paid_amount)
Ejemplo n.º 7
0
 def get_rest_amount(self, obj):
     return currency(obj.rest_amount)