Exemple #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))
Exemple #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))
Exemple #3
0
def userlist(request):
    if request.user.roles != 'MA':
        messages.info(request, 'Sorry, you are not allowed to view this page.')
        return HttpResponseRedirect(reverse('root'))
    template = 'auth/userlist.djhtml'
    users = UserProfiles.objects.all()
    title = "User Staff List"
    if request.POST:
        try:
            id = request.POST['id']
        except:
            pass
        if id:
            instance = get_object_or_404(UserProfiles, id=id)
            if instance.is_active:
                instance.is_active = False
                log = "disabled %s %s\'s account." % (instance.first_name.title(), instance.last_name.title())
                mail = """
                        The manager has been deactivated your account from expense tracker app,
                        Please contact your manager to get more clear info regarding your account.
                        """
            else:
                instance.is_active = True
                log = "reactivated %s %s\'s account." % (instance.first_name.title(), instance.last_name.title())
                mail = "Your account is now activated, You may now sign in to expense tracker app."
            instance.save()
            logs = """%s %s %s""" % (request.user.first_name.title(),
                                    request.user.last_name.title(),
                                    log,
                                    )
            logger = Translog(log=logs)
            logger.save()
            mailer = MailMan(msg=mail, subj=title)
            mailer.send_to_user(request, instance.id)
    context = {'users': users, 'title': title}
    return render_to_response(template, context, RequestContext(request))
Exemple #4
0
def create_category(request):
    if request.POST:
        name = request.POST["category"]
        desc = request.POST["category_desc"]
        next = request.POST["next"]
        items = [name, desc, next]
        for i in items:
            if i == "":
                messages.error(request, "You can not send an empty form")
                return HttpResponseRedirect(next)
        instance = Catergory(name=name, description=desc)
        log_msg = "%s %s added a new reports category." % (
            request.user.first_name.title(),
            request.user.last_name.title(),
        )
        log = Translog(log=log_msg)
        try:
            instance.save()
            log.save()
            messages.info(request, "You have successfully created a new category")
        except Exception as e:
            messages.info(request, "Unable to submit this form, Please contact web admin: %s" % e)

        return HttpResponseRedirect(next)
Exemple #5
0
def questioned(request, id):
    title = "Questioned Expenditures"
    instance = get_object_or_404(Expense, id=id)
    if request.POST:
        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
        method = request.POST["method"]
        if method == "question":
            instance.is_questioned = True
            instance.is_evaluated = True
            log_msg = """
                  %s %s questioned %s %s expenditure record with reference uuid: <strong>%s</strong>
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.recorded_by.first_name.title(),
                instance.recorded_by.last_name.title(),
                instance.uuid,
            )
            msg = """
                  %s %s questioned your expenditure record.<br />
                  Reference uuid #: <strong>%s</strong><br />
                  <i>Note: A expenditure record on a questioned state will not be treat as our companies official expenditure.</i><br /><br />
                  Please check <a href="http://%s">http://%s</a> and justify the record.<br />
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.uuid,
                request.META["HTTP_HOST"],
                request.META["HTTP_HOST"],
            )
            messages.info(
                request,
                """You have successfully sent <strong>%s</strong> for questioning,
                                       The recorder will be notified thru email to justify this expense report. 
                                       """
                % instance.uuid,
            )
        elif method == "resolved":
            instance.is_questioned = False
            log_msg = """
                  %s %s resolved %s %s questioned expenditure record with reference uuid: <strong>%s</strong>
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.recorded_by.first_name.title(),
                instance.recorded_by.last_name.title(),
                instance.uuid,
            )
            msg = """
                  %s %s resolved your expenditure record.<br />
                  Reference uuid #: <strong>%s</strong><br />
                  It will now be setback to our companies official expenditure.
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.uuid,
            )
            messages.info(
                request,
                """You have successfully resolved <strong>%s</strong>,
                                       The recorder will be notified thru email. 
                                       """
                % instance.uuid,
            )

        elif method == "justify":
            log_msg = """
                  %s %s have answered the questioned expenditure record with reference uuid: <strong>%s</strong>
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.uuid,
            )
            msg = """
                  %s %s justified his/her questioned expenditure record.<br />
                  Reference uuid #: <strong>%s</strong><br /><br />
                  <p>
                      %s
                  </p>
                  <br />
                  <br />
                  You might want to check it and set it to resolved if necessary.<br /><br />
                  Please login to <a href="http://%s">http://%s</a> and justify the record.<br />
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.uuid,
                request.POST["remarks"],
                request.META["HTTP_HOST"],
                request.META["HTTP_HOST"],
            )
            messages.info(
                request,
                """You have successfully justified <strong>%s</strong>,
                                       Your manager have sent an email regarding your justification. 
                                       """
                % instance.uuid,
            )
        try:
            instance.save()
            mailer = MailMan(msg=msg, subj=title)
            if method == "justify":
                mailer.send_to_manager(request)
            else:
                mailer.send_to_user(request, instance.recorded_by.id)
            log = Translog(log=log_msg)
            log.save()
        except Exception as e:
            messages.error(request, "Unable to submit this form, Please contact the admin: %s" % e)

    return HttpResponseRedirect(reverse("questioned_report"))
Exemple #6
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)
Exemple #7
0
def approve(request, id):
    title = "Reimbursement Approval"
    if request.user.roles != "MA":
        messages.info(request, "You do not have enought permission to perform this action")
        HttpResponseRedirect(reverse("root"))
    instance = get_object_or_404(Reimbursement, id=id)
    if request.POST:
        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.evaluate_by = request.user
        method = request.POST["method"]

        if method == "approved":
            instance.is_approved = True
            instance.is_disapproved = False
            msg = """%s has approved your reimbursement with reference uuid: %s <br /><br />
                     The accountant is tend to pay your reimbursement before to be classified as official company expenditures.
                  """ % (
                request.user,
                instance.uuid,
            )
            msg_ac = """%s has approved %s %s reimbursement with reference uuid: %s <br /><br />
                             You are now able to do payment procedure and mark this record paid. <br /><br />
                             Please make sure you have support docs like receipt when setting a reimbursement record paid.
                     """ % (
                request.user,
                instance.recorded_by.first_name.title(),
                instance.recorded_by.last_name.title(),
                instance.uuid,
            )
            log_msg = """
                  %s %s disapproved %s %s reimbursement with reference uuid: <strong>%s</strong>
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.recorded_by.first_name.title(),
                instance.recorded_by.last_name.title(),
                instance.uuid,
            )
        else:
            instance.is_approved = False
            instance.is_disapproved = True
            msg = """%s has disapproved your reimbursement with reference uuid %s for the following reason: <br /><br />
                     %s. <br /><br />
                     This record will be deleted after a week, however you can still repost this reimbursement for further evaluation.\n\n
                     Note: Please add "-repost" at the end of the receipt or check # when reposting.
                  """ % (
                request.user,
                instance.uuid,
                request.POST["remarks"],
            )
            msg_ac = None
            log_msg = """
                  %s %s disapproved %s %s reimbursement with reference uuid: <strong>%s</strong>
                  """ % (
                request.user.first_name.title(),
                request.user.last_name.title(),
                instance.recorded_by.first_name.title(),
                instance.recorded_by.last_name.title(),
                instance.uuid,
            )
        try:
            log = Translog(log=log_msg)
            log.save()
            mailer = MailMan(msg=msg, subj=title)
            mailer.send_to_user(request, instance.recorded_by.id)
            if msg_ac is not None:
                mailer = MailMan(msg=msg_ac, subj=title)
                mailer.send_to_accountant(request)
            instance.save()
            messages.info(request, "You have successfully evaluated <strong>%s</strong>" % instance.uuid)
        except Exception as e:
            messages.error(
                request, "Unable to submit this form, Please contact the web admin for further assistance: %s" % e
            )

    return HttpResponseRedirect(reverse("reimbursement"))