Example #1
0
def view_program_reports_manage_report_add_report(request, program_id):
    program = get_object_or_404(Program, id=program_id)
    
    if not permission.access_obj(request.user, 'program report schedule add', program):
        return access_denied(request)
    
    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]
        
        form = ProgramReportForm(request.POST)
        if form.is_valid():
            report_name = form.cleaned_data['name']
            need_checkup = form.cleaned_data['need_checkup']
            need_approval = form.cleaned_data['need_approval']
            
            notify_before = form.cleaned_data['notify_before']
            notify_before_days = form.cleaned_data['notify_before_days'] if notify_before else 0
            if not notify_before_days: notify_before_days = 0
            
            notify_due = form.cleaned_data['notify_due']
            
            report = Report.objects.create(program=program, due_type=report_due_type, name=report_name, need_approval=need_approval, need_checkup=need_checkup, created_by=request.user.get_profile(), notify_days_before=notify_before_days, notify_at_due=notify_due)
            
            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report, due_date=date(int(dyear), int(dmonth), int(ddate)))
                
            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']
                
                schedule_start = report_functions.generate_report_schedule_start(True, monthly_date)
                ReportDueRepeatable.objects.create(report=report, schedule_start=schedule_start, schedule_cycle=3, schedule_cycle_length=cycle_length, schedule_monthly_date=monthly_date)
                
            ReportAssignment.objects.create(report=report, program=program)
            
            messages.success(request, 'เพิ่มหัวเรื่องรายงานเรียบร้อย')
            return redirect('view_program_reports_manage_report', (program.id))

    # To re-populate the form when error occured
        report = Report(due_type=report_due_type)
        if report_due_type == REPORT_DUE_DATES:
            due_dates = []
            for due_date in request.POST.getlist('due_dates'):
                if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        due_dates.append(ReportDueDates(due_date=date(int(dyear), int(dmonth), int(ddate))))
            
            report.due_dates = due_dates
            
    else:
        report = Report(due_type=REPORT_NO_DUE_DATE)
        form = ProgramReportForm()
        
    return render_page_response(request, 'reports', 'page_program/program_reports_modify_report.html', {'program':program, 'form':form, 'report':report})
Example #2
0
def view_master_plan_manage_report_add_report(request, master_plan_ref_no):
    master_plan = get_object_or_404(MasterPlan, ref_no=master_plan_ref_no)
    
    if not permission.access_obj(request.user, 'master_plan manage', master_plan):
        return access_denied(request)
    
    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]
        
        form = MasterPlanReportForm(request.POST)
        if form.is_valid():
            report_name = form.cleaned_data['name']
            need_approval = form.cleaned_data['need_approval']
            
            notify_before = form.cleaned_data['notify_before']
            notify_before_days = form.cleaned_data['notify_before_days'] if notify_before else 0
            if not notify_before_days: notify_before_days = 0
            
            notify_due = form.cleaned_data['notify_due']
            
            report = Report.objects.create(master_plan=master_plan, due_type=report_due_type, name=report_name, need_approval=need_approval, need_checkup=True, created_by=request.user.get_profile(), notify_days_before=notify_before_days, notify_at_due=notify_due)
            
            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report, due_date=date(int(dyear), int(dmonth), int(ddate)))
                
            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']
                
                schedule_start = report_functions.generate_report_schedule_start(True, monthly_date)
                ReportDueRepeatable.objects.create(report=report, schedule_start=schedule_start, schedule_cycle=3, schedule_cycle_length=cycle_length, schedule_monthly_date=monthly_date)
            
            messages.success(request, 'เพิ่มหัวเรื่องรายงานเรียบร้อย')
            return utilities.redirect_or_back('view_master_plan_manage_report', (master_plan.ref_no), request)
        
        # To re-populate the form when error occured
        report = Report(due_type=report_due_type)
        if report_due_type == REPORT_DUE_DATES:
            due_dates = []
            for due_date in request.POST.getlist('due_dates'):
                if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        due_dates.append(ReportDueDates(due_date=date(int(dyear), int(dmonth), int(ddate))))
            
            report.due_dates = due_dates
            
    else:
        report = Report(due_type=REPORT_NO_DUE_DATE)
        form = MasterPlanReportForm()
    
    return render_page_response(request, 'report', 'page_sector/manage_master_plan/manage_report_modify_report.html', {'master_plan':master_plan, 'report':report, 'form':form})
Example #3
0
def view_program_reports_manage_report_edit_report(request, report_id):
    report = get_object_or_404(Report, pk=report_id)
    program = report.program
    
    if not permission.access_obj(request.user, 'program report schedule edit', program):
        return access_denied(request)
    
    if report.master_plan:
        messages.error(request, 'ไม่สามารถแก้ไขรายงานของแผนหลักได้จากหน้านี้')
        return redirect('view_program_reports_manage_report', (program.id))
    
    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]
        
        form = ProgramReportForm(request.POST)
        if form.is_valid():
            report.name = form.cleaned_data['name']
            report.need_checkup = form.cleaned_data['need_checkup']
            report.need_approval = form.cleaned_data['need_approval']
            
            notify_before = form.cleaned_data['notify_before']
            report.notify_before_days = form.cleaned_data['notify_before_days'] if notify_before else 0
            if not report.notify_before_days: report.notify_before_days = 0
            
            report.notify_at_due = form.cleaned_data['notify_due']
            
            ReportDueRepeatable.objects.filter(report=report).delete()
            ReportDueDates.objects.filter(report=report).delete()
            ReportSubmission.objects.filter(report=report, state=NO_ACTIVITY).delete()
            
            report.due_type = report_due_type
            
            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report, due_date=date(int(dyear), int(dmonth), int(ddate)))
                
            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']
                
                schedule_start = report_functions.generate_report_schedule_start(True, monthly_date)
                ReportDueRepeatable.objects.create(report=report, schedule_start=schedule_start, schedule_cycle=3, schedule_cycle_length=cycle_length, schedule_monthly_date=monthly_date)
                
            report.save()
            
            messages.success(request, 'แก้ไขหัวเรื่องรายงานเรียบร้อย')
            return redirect('view_program_reports_manage_report', (program.id))
            
    else:
        if not report.notify_days_before:
            notify_before = False
            notify_days_before = ''
        else:
            notify_before = True
            notify_days_before = report.notify_days_before
        
        if report.due_type == REPORT_REPEAT_DUE:
            report_repeatable = ReportDueRepeatable.objects.get(report=report)
            cycle_length = report_repeatable.schedule_cycle_length
            monthly_date = report_repeatable.schedule_monthly_date
        else:
            cycle_length = ''
            monthly_date = ''
        
        form = ProgramReportForm(initial={
            'name': report.name,
            'need_checkup': report.need_checkup,
            'need_approval': report.need_approval,
            'cycle_length': cycle_length,
            'monthly_date': monthly_date,
            'notify_before': notify_before,
            'notify_before_days': notify_days_before,
            'notify_due': report.notify_at_due,
        })
    
    if report.due_type == REPORT_DUE_DATES:
        report.due_dates = ReportDueDates.objects.filter(report=report).order_by('due_date')
    else:
        report.due_dates = []
    
    return render_page_response(request, 'reports', 'page_program/program_reports_modify_report.html', {'program':program, 'form':form, 'report':report})
Example #4
0
def view_master_plan_manage_report_edit_report(request, report_id):
    report = get_object_or_404(Report, pk=report_id)
    master_plan = report.master_plan
    if not master_plan: raise Http404
    
    if not permission.access_obj(request.user, 'master_plan manage', master_plan):
        return access_denied(request)
    
    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]
        
        form = MasterPlanReportForm(request.POST)
        if form.is_valid():
            report.name = form.cleaned_data['name']
            report.need_approval = form.cleaned_data['need_approval']
            
            notify_before = form.cleaned_data['notify_before']
            report.notify_days_before = form.cleaned_data['notify_before_days'] if notify_before else 0
            if not report.notify_days_before: report.notify_days_before = 0
            
            report.notify_at_due = form.cleaned_data['notify_due']
            
            ReportDueRepeatable.objects.filter(report=report).delete()
            ReportDueDates.objects.filter(report=report).delete()
            ReportSubmission.objects.filter(report=report, state=NO_ACTIVITY).delete()
            
            report.due_type = report_due_type
            
            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report, due_date=date(int(dyear), int(dmonth), int(ddate)))
                
            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']
                
                schedule_start = report_functions.generate_report_schedule_start(True, monthly_date)
                ReportDueRepeatable.objects.create(report=report, schedule_start=schedule_start, schedule_cycle=3, schedule_cycle_length=cycle_length, schedule_monthly_date=monthly_date)
                
            report.save()
            
            messages.success(request, 'แก้ไขหัวเรื่องรายงานเรียบร้อย')
            return redirect('view_master_plan_manage_report', (master_plan.ref_no))

    else:
        if not report.notify_days_before:
            notify_before = False
            notify_days_before = ''
        else:
            notify_before = True
            notify_days_before = report.notify_days_before
        
        if report.due_type == REPORT_REPEAT_DUE:
            report_repeatable = ReportDueRepeatable.objects.get(report=report)
            cycle_length = report_repeatable.schedule_cycle_length
            monthly_date = report_repeatable.schedule_monthly_date
        else:
            cycle_length = ''
            monthly_date = ''
        
        form = MasterPlanReportForm(initial={
            'name': report.name,
            'need_approval': report.need_approval,
            'cycle_length': cycle_length,
            'monthly_date': monthly_date,
            'notify_before': notify_before,
            'notify_before_days': notify_days_before,
            'notify_due': report.notify_at_due,
        })
    
    if report.due_type == REPORT_DUE_DATES:
        report.due_dates = ReportDueDates.objects.filter(report=report).order_by('due_date')
    else:
        report.due_dates = []
    
    return render_page_response(request, 'report', 'page_sector/manage_master_plan/manage_report_modify_report.html', {'master_plan':master_plan, 'report':report, 'form':form})
Example #5
0
def view_program_reports_manage_report_edit_report(request, report_id):
    report = get_object_or_404(Report, pk=report_id)
    program = report.program

    if not permission.access_obj(request.user, 'program report schedule edit',
                                 program):
        return access_denied(request)

    if report.master_plan:
        messages.error(request, 'ไม่สามารถแก้ไขรายงานของแผนหลักได้จากหน้านี้')
        return redirect('view_program_reports_manage_report', (program.id))

    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]

        form = ProgramReportForm(request.POST)
        if form.is_valid():
            report.name = form.cleaned_data['name']
            report.need_checkup = form.cleaned_data['need_checkup']
            report.need_approval = form.cleaned_data['need_approval']

            notify_before = form.cleaned_data['notify_before']
            report.notify_before_days = form.cleaned_data[
                'notify_before_days'] if notify_before else 0
            if not report.notify_before_days: report.notify_before_days = 0

            report.notify_at_due = form.cleaned_data['notify_due']

            ReportDueRepeatable.objects.filter(report=report).delete()
            ReportDueDates.objects.filter(report=report).delete()
            ReportSubmission.objects.filter(report=report,
                                            state=NO_ACTIVITY).delete()

            report.due_type = report_due_type

            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report,
                                                      due_date=date(
                                                          int(dyear),
                                                          int(dmonth),
                                                          int(ddate)))

            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']

                schedule_start = report_functions.generate_report_schedule_start(
                    True, monthly_date)
                ReportDueRepeatable.objects.create(
                    report=report,
                    schedule_start=schedule_start,
                    schedule_cycle=3,
                    schedule_cycle_length=cycle_length,
                    schedule_monthly_date=monthly_date)

            report.save()

            messages.success(request, 'แก้ไขหัวเรื่องรายงานเรียบร้อย')
            return redirect('view_program_reports_manage_report', (program.id))

    else:
        if not report.notify_days_before:
            notify_before = False
            notify_days_before = ''
        else:
            notify_before = True
            notify_days_before = report.notify_days_before

        if report.due_type == REPORT_REPEAT_DUE:
            report_repeatable = ReportDueRepeatable.objects.get(report=report)
            cycle_length = report_repeatable.schedule_cycle_length
            monthly_date = report_repeatable.schedule_monthly_date
        else:
            cycle_length = ''
            monthly_date = ''

        form = ProgramReportForm(
            initial={
                'name': report.name,
                'need_checkup': report.need_checkup,
                'need_approval': report.need_approval,
                'cycle_length': cycle_length,
                'monthly_date': monthly_date,
                'notify_before': notify_before,
                'notify_before_days': notify_days_before,
                'notify_due': report.notify_at_due,
            })

    if report.due_type == REPORT_DUE_DATES:
        report.due_dates = ReportDueDates.objects.filter(
            report=report).order_by('due_date')
    else:
        report.due_dates = []

    return render_page_response(
        request, 'reports', 'page_program/program_reports_modify_report.html',
        {
            'program': program,
            'form': form,
            'report': report
        })
Example #6
0
def view_program_reports_manage_report_add_report(request, program_id):
    program = get_object_or_404(Program, id=program_id)

    if not permission.access_obj(request.user, 'program report schedule add',
                                 program):
        return access_denied(request)

    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]

        form = ProgramReportForm(request.POST)
        if form.is_valid():
            report_name = form.cleaned_data['name']
            need_checkup = form.cleaned_data['need_checkup']
            need_approval = form.cleaned_data['need_approval']

            notify_before = form.cleaned_data['notify_before']
            notify_before_days = form.cleaned_data[
                'notify_before_days'] if notify_before else 0
            if not notify_before_days: notify_before_days = 0

            notify_due = form.cleaned_data['notify_due']

            report = Report.objects.create(
                program=program,
                due_type=report_due_type,
                name=report_name,
                need_approval=need_approval,
                need_checkup=need_checkup,
                created_by=request.user.get_profile(),
                notify_days_before=notify_before_days,
                notify_at_due=notify_due)

            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report,
                                                      due_date=date(
                                                          int(dyear),
                                                          int(dmonth),
                                                          int(ddate)))

            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']

                schedule_start = report_functions.generate_report_schedule_start(
                    True, monthly_date)
                ReportDueRepeatable.objects.create(
                    report=report,
                    schedule_start=schedule_start,
                    schedule_cycle=3,
                    schedule_cycle_length=cycle_length,
                    schedule_monthly_date=monthly_date)

            ReportAssignment.objects.create(report=report, program=program)

            messages.success(request, 'เพิ่มหัวเรื่องรายงานเรียบร้อย')
            return redirect('view_program_reports_manage_report', (program.id))

    # To re-populate the form when error occured
        report = Report(due_type=report_due_type)
        if report_due_type == REPORT_DUE_DATES:
            due_dates = []
            for due_date in request.POST.getlist('due_dates'):
                if due_date:
                    (dyear, dmonth, ddate) = due_date.split('-')
                    due_dates.append(
                        ReportDueDates(due_date=date(int(dyear), int(dmonth),
                                                     int(ddate))))

            report.due_dates = due_dates

    else:
        report = Report(due_type=REPORT_NO_DUE_DATE)
        form = ProgramReportForm()

    return render_page_response(
        request, 'reports', 'page_program/program_reports_modify_report.html',
        {
            'program': program,
            'form': form,
            'report': report
        })
Example #7
0
def view_master_plan_manage_report_edit_report(request, report_id):
    report = get_object_or_404(Report, pk=report_id)
    master_plan = report.master_plan
    if not master_plan: raise Http404

    if not permission.access_obj(request.user, 'master_plan manage',
                                 master_plan):
        return access_denied(request)

    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]

        form = MasterPlanReportForm(request.POST)
        if form.is_valid():
            report.name = form.cleaned_data['name']
            report.need_approval = form.cleaned_data['need_approval']

            notify_before = form.cleaned_data['notify_before']
            report.notify_days_before = form.cleaned_data[
                'notify_before_days'] if notify_before else 0
            if not report.notify_days_before: report.notify_days_before = 0

            report.notify_at_due = form.cleaned_data['notify_due']

            ReportDueRepeatable.objects.filter(report=report).delete()
            ReportDueDates.objects.filter(report=report).delete()
            ReportSubmission.objects.filter(report=report,
                                            state=NO_ACTIVITY).delete()

            report.due_type = report_due_type

            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report,
                                                      due_date=date(
                                                          int(dyear),
                                                          int(dmonth),
                                                          int(ddate)))

            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']

                schedule_start = report_functions.generate_report_schedule_start(
                    True, monthly_date)
                ReportDueRepeatable.objects.create(
                    report=report,
                    schedule_start=schedule_start,
                    schedule_cycle=3,
                    schedule_cycle_length=cycle_length,
                    schedule_monthly_date=monthly_date)

            report.save()

            messages.success(request, 'แก้ไขหัวเรื่องรายงานเรียบร้อย')
            return redirect('view_master_plan_manage_report',
                            (master_plan.ref_no))

    else:
        if not report.notify_days_before:
            notify_before = False
            notify_days_before = ''
        else:
            notify_before = True
            notify_days_before = report.notify_days_before

        if report.due_type == REPORT_REPEAT_DUE:
            report_repeatable = ReportDueRepeatable.objects.get(report=report)
            cycle_length = report_repeatable.schedule_cycle_length
            monthly_date = report_repeatable.schedule_monthly_date
        else:
            cycle_length = ''
            monthly_date = ''

        form = MasterPlanReportForm(
            initial={
                'name': report.name,
                'need_approval': report.need_approval,
                'cycle_length': cycle_length,
                'monthly_date': monthly_date,
                'notify_before': notify_before,
                'notify_before_days': notify_days_before,
                'notify_due': report.notify_at_due,
            })

    if report.due_type == REPORT_DUE_DATES:
        report.due_dates = ReportDueDates.objects.filter(
            report=report).order_by('due_date')
    else:
        report.due_dates = []

    return render_page_response(
        request, 'report',
        'page_sector/manage_master_plan/manage_report_modify_report.html', {
            'master_plan': master_plan,
            'report': report,
            'form': form
        })
Example #8
0
def view_master_plan_manage_report_add_report(request, master_plan_ref_no):
    master_plan = get_object_or_404(MasterPlan, ref_no=master_plan_ref_no)

    if not permission.access_obj(request.user, 'master_plan manage',
                                 master_plan):
        return access_denied(request)

    if request.method == 'POST':
        report_due_type = REPORT_DUE_TYPE[request.POST.get('report_due_type')]

        form = MasterPlanReportForm(request.POST)
        if form.is_valid():
            report_name = form.cleaned_data['name']
            need_approval = form.cleaned_data['need_approval']

            notify_before = form.cleaned_data['notify_before']
            notify_before_days = form.cleaned_data[
                'notify_before_days'] if notify_before else 0
            if not notify_before_days: notify_before_days = 0

            notify_due = form.cleaned_data['notify_due']

            report = Report.objects.create(
                master_plan=master_plan,
                due_type=report_due_type,
                name=report_name,
                need_approval=need_approval,
                need_checkup=True,
                created_by=request.user.get_profile(),
                notify_days_before=notify_before_days,
                notify_at_due=notify_due)

            if report_due_type == REPORT_DUE_DATES:
                for due_date in request.POST.getlist('due_dates'):
                    if due_date:
                        (dyear, dmonth, ddate) = due_date.split('-')
                        ReportDueDates.objects.create(report=report,
                                                      due_date=date(
                                                          int(dyear),
                                                          int(dmonth),
                                                          int(ddate)))

            elif report_due_type == REPORT_REPEAT_DUE:
                cycle_length = form.cleaned_data['cycle_length']
                monthly_date = form.cleaned_data['monthly_date']

                schedule_start = report_functions.generate_report_schedule_start(
                    True, monthly_date)
                ReportDueRepeatable.objects.create(
                    report=report,
                    schedule_start=schedule_start,
                    schedule_cycle=3,
                    schedule_cycle_length=cycle_length,
                    schedule_monthly_date=monthly_date)

            messages.success(request, 'เพิ่มหัวเรื่องรายงานเรียบร้อย')
            return utilities.redirect_or_back('view_master_plan_manage_report',
                                              (master_plan.ref_no), request)

        # To re-populate the form when error occured
        report = Report(due_type=report_due_type)
        if report_due_type == REPORT_DUE_DATES:
            due_dates = []
            for due_date in request.POST.getlist('due_dates'):
                if due_date:
                    (dyear, dmonth, ddate) = due_date.split('-')
                    due_dates.append(
                        ReportDueDates(due_date=date(int(dyear), int(dmonth),
                                                     int(ddate))))

            report.due_dates = due_dates

    else:
        report = Report(due_type=REPORT_NO_DUE_DATE)
        form = MasterPlanReportForm()

    return render_page_response(
        request, 'report',
        'page_sector/manage_master_plan/manage_report_modify_report.html', {
            'master_plan': master_plan,
            'report': report,
            'form': form
        })