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))
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))
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"))
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)