示例#1
0
def addReportView(request):
    title = "Adding Expense Report"
    template = "finance/add_report.djhtml"
    form = ExpenseForm()
    if request.POST:
        form = ExpenseForm(request.POST, request.FILES)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.recorded_by = request.user
            subject = "Expenditure Report"
            user = get_user_by_role(request, role="MA")
            try:
                instance.save()
                msg = "%s %s has added a new expenditures with reference uuid: %s" % (
                    request.user.first_name,
                    request.user.last_name,
                    instance.uuid,
                )
                mailer = MailMan(msg=msg, subj=title)
                mailer.send_to_manager(request)
                log = Translog(log=msg)
                log.save()
                messages.info(request, "You have successfully added a new expenses record.")
                return HttpResponseRedirect(reverse("report"))
            except Exception as e:
                messages.error(
                    request, "Unable to submit this form, Please contact web admin for further assistance: %s" % e
                )
    context = {"title": title, "form": form}
    logman = LogMan(context)
    context = logman.get_logs()
    return render_to_response(template, context, context_instance=RequestContext(request))
示例#2
0
def addReimbursementView(request):
    title = "Adding Reimbursement Report"
    template = "finance/add_reimbursement.djhtml"
    form = ReimbursementForm()
    if request.POST:
        form = ReimbursementForm(request.POST, request.FILES)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.recorded_by = request.user
            try:
                instance.save()
                messages.info(request, "You have successfully added a new reimbursement record.")
                msg = """%s %s has added a new reimbursement with reference uuid: %s <br /><br />
                         The Manager is tend to approve this record before be classified as official company expenditures.
                      """ % (
                    request.user.first_name.title(),
                    request.user.last_name.title(),
                    instance.uuid,
                )
                mailer = MailMan(msg=msg, subj=title)
                mailer.send_to_manager(request)
                mailer.send_to_admin(request)
                log = Translog(log=msg)
                log.save()
                return HttpResponseRedirect(reverse("reimbursement"))
            except Exception as e:
                messages.error(request, "Unable to submit form, Please contact web admin: %s" % e)
    context = {"title": title, "form": form}
    logman = LogMan(context)
    context = logman.get_logs()
    return render_to_response(template, context, context_instance=RequestContext(request))
示例#3
0
def questionedExpenseView(request):
    if request.user.roles == "MA":
        expenses = Expense.objects.filter(is_questioned=True)
    else:
        expenses = Expense.objects.filter(is_questioned=True).filter(recorded_by=request.user)
    template = "finance/questioned.djhtml"
    title = "Questioned Expenses"
    context = {"expenses": expenses, "title": title}
    logman = LogMan(context)
    context = logman.get_logs()
    return render_to_response(template, context, context_instance=RequestContext(request))
示例#4
0
def registration(request):
    if request.user.roles != 'MA':
        messages.info(request, '<strong>Notice</strong>: Only Managers are allowed to add users.')
        return HttpResponseRedirect(reverse('root'))
    title = 'Staff Account Creation'
    form = UserProfileForm()
    template = 'auth/registration.djhtml'
    context = {'form': form, 'title': title}
    if request.POST:
        form = UserProfileForm(request.POST)
        context['form'] = form
        if form.is_valid():
            form.save()
            messages.info(request, 'You have successfuly added %s %s as a new staff.' % (form.cleaned_data['first_name'], form.cleaned_data['last_name']))
            return HttpResponseRedirect(reverse('userlist'))
    logman = LogMan(context)
    context = logman.get_logs()
    return render_to_response(template, context, context_instance=RequestContext(request))
示例#5
0
def summary(request):
    expenses = Expense.objects.all()
    reimbursement = Reimbursement.objects.all()
    template = "finance/summary.djhtml"
    title = "Report Summary"
    today = date.today()
    this_year_cost = get_total_year_cost(Expense, today.year, request.user.local)
    this_month_cost = get_total_month_cost(Expense, today.month, today.year, request.user.local)

    context = {
        "title": title,
        "expenses": expenses,
        "reimbursement": reimbursement,
        "this_year_cost": this_year_cost,
        "this_month_cost": this_month_cost,
    }

    data = {}
    year_list = []
    for exp in expenses:
        if exp.creation_date.year not in year_list:
            year_list.append(exp.creation_date.year)

    for y in year_list:
        expense = expenses.filter(creation_date__year=y)
        monthly_data = {}
        month_range = range(1, 13)
        for m in month_range:
            if request.user.local == "HK":
                exp = expense.filter(creation_date__month=m).aggregate(Sum("hkd_total_price"))
                for k, v in exp.items():
                    monthly_data[m] = v
            else:
                exp = expense.filter(creation_date__month=m).aggregate(Sum("php_total_price"))
                for k, v in exp.items():
                    monthly_data[m] = v
        data[str(y)] = monthly_data
    context["data"] = data
    logman = LogMan(context)
    context = logman.get_logs()

    return render_to_response(template, context, context_instance=RequestContext(request))
示例#6
0
def reimbursementView(request):
    title = "Reimbursement and Statistics"
    template = "finance/reimbursement.djhtml"
    today = date.today()
    fr = get_first_day(today).strftime("%Y-%m-%d")
    to = get_last_day(today).strftime("%Y-%m-%d")
    raw_range = "%s to %s" % (fr, to)
    if request.POST:
        raw_range = request.POST["time-range"]
        try:
            rlist = raw_range.split(" ")
            r_fr = rlist[0].split("/")
            fr = "%s-%s-%s" % (r_fr[2], r_fr[0], r_fr[1])
            r_to = rlist[2].split("/")
            to = "%s-%s-%s" % (r_to[2], r_to[0], r_to[1])
        except:
            pass
    reimbursement = Reimbursement.objects.filter(creation_date__range=[fr, to])
    context = {"title": title, "reimbursement": reimbursement, "range": raw_range}
    logman = LogMan(context)
    context = logman.get_logs()
    return render_to_response(template, context, context_instance=RequestContext(request))
示例#7
0
def reimbursement_process(request):
    if request.user.roles != "AC":
        return HttpResponseRedirect(reverse("root"))
    instance = Reimbursement.objects.filter(set_paid_by=None).filter(is_approved=True).filter(local=request.user.local)
    title = "Processing Reimbursement Payment"
    template = "finance/process.djhtml"
    context = {"title": title, "reimbursement": instance}
    logman = LogMan(context)
    context = logman.get_logs()

    if request.POST and request.FILES:
        id = request.POST["instance"]
        docs = request.FILES["receipt"]
        serial = request.POST["receipt_or_check_number"]
        instance = get_object_or_404(Reimbursement, id=id)
        remarks = instance.remarks
        new_remarks = """
                      %s
                      <br />
                      :::::::::::::::::%s %s::::::::::::::::::
                      <br />
                      %s
                      """ % (
            remarks,
            request.user.first_name.title(),
            request.user.last_name.title(),
            request.POST["remarks"],
        )
        instance.remarks = new_remarks
        instance.set_paid_by = request.user
        expense = Expense(
            category=instance.category,
            item=instance.item,
            description=instance.description,
            quantity=instance.quantity,
            price=instance.price,
            hkd_price=instance.hkd_price,
            php_price=instance.php_price,
            hkd_total_price=instance.hkd_total_price,
            php_total_price=instance.php_total_price,
            recorded_by=request.user,
            receipt_or_check_number=serial,
            receipt=docs,
            local=instance.local,
            reimbursement_uuid=instance.uuid,
            remarks="This report is already been processed via reimbursement.<br /> Reimbursement uuid: %s"
            % instance.uuid,
            is_questioned=False,
            is_evaluated=True,
        )
        msg = """
              %s %s set <strong>%s</strong> paid.<br />
              """ % (
            request.user.first_name.title(),
            request.user.last_name.title(),
            instance.uuid,
        )
        msg1 = """
              Your reimbursement has been set paid by %s %s with the reference uuid <strong>%s</strong>.
              """ % (
            request.user.first_name.title(),
            request.user.last_name.title(),
            instance.uuid,
        )

        try:
            instance.save()
            expense.save()
            mailer = MailMan(msg=msg, subj=title)
            mailer.send_to_manager(request)
            mailer = MailMan(msg=msg1, subj=title)
            mailer.send_to_user(request, instance.recorded_by.id)
            log = Translog(log=msg)
            log.save()
            messages.info(request, "You have successfuly set <strong>%s</strong> paid." % instance.uuid)
        except Exception, e:
            messages.error(request, "Unable to submit this form, Please contanct the web admin: %s" % e)