Example #1
0
def payroll_record_page(request, id):
    # Get the payroll record
    payroll_record = PayrollRecord.objects.get(pk=id)

    month = payroll_record.month
    year = payroll_record.year

    # Get all the associated payslip objects
    payslips = get_payslips(payroll_record=payroll_record)
    ugx_payslips = get_ugx_payslips(payroll_record)
    usd_payslips = get_usd_payslips(payroll_record)
    # Get all employees
    ugx_employees = get_employees_paid_in_ugx()

    context = {
        "payroll_page": "active",
        "month": month,
        "year": year,
        "payslips": payslips,
        "ugx_payslips": ugx_payslips,
        "usd_payslips": usd_payslips,
        "payroll_record": payroll_record,
        "total_nssf_contribution": get_total_nssf(ugx_payslips),
        "total_paye": get_total_paye(ugx_payslips),
        "total_gross_pay": get_total_gross_pay(ugx_payslips),
        "total_basic_pay": get_total_basic_pay(ugx_payslips),
        "total_net_pay": get_total_net_pay(ugx_payslips),
    }
    return render(request, 'payroll/payroll_record.html', context)
Example #2
0
def payroll_download_usd(request, id):
    # Get the payroll record
    payroll_record = PayrollRecord.objects.get(pk=id)
    month = payroll_record.month
    year = payroll_record.year
    # Get all the associated Payroll objects
    payrolls = get_usd_payslips(payroll_record)
    response = HttpResponse(content_type='text/csv')
    # Name the csv file
    filename = "payroll_" + month + "_" + year + ".csv"
    response['Content-Disposition'] = 'attachment; filename=' + filename
    writer = csv.writer(response, delimiter=',')
    # Writing the first row of the csv
    heading_text = "Payroll for " + month + " " + year + "(USD)"
    writer.writerow([heading_text.upper()])
    writer.writerow([
        'Name', 'Basic Salary', 'Gross Salary', 'Employee NSSF Contribution',
        'Employer NSSF contribution', 'PAYE(UGX)', 'Lunch Allowance',
        'Overtime', 'Bonus', 'Sacco Deduction', 'Damage Deduction',
        'Net Salary'
    ])
    # Writing other rows
    for payroll in payrolls:
        name = payroll.employee.first_name + " " + payroll.employee.last_name
        writer.writerow([
            name, payroll.employee.basic_salary, payroll.gross_salary,
            payroll.employee_nssf, payroll.employer_nssf, payroll.paye_ugx,
            payroll.employee.lunch_allowance, payroll.overtime, payroll.bonus,
            payroll.sacco_deduction, payroll.damage_deduction,
            payroll.net_salary
        ])

    # Return the response
    return response
Example #3
0
def generate_payroll_ugx_pdf(request, id):
    # Get the payroll
    payroll_record = PayrollRecord.objects.get(pk=id)

    month = payroll_record.month
    year = payroll_record.year

    # Get all the associated payslip objects
    payslips = get_payslips(payroll_record=payroll_record)
    ugx_payslips = get_ugx_payslips(payroll_record)
    usd_payslips = get_usd_payslips(payroll_record)

    context = {
        "payroll_page": "active",
        "month": month,
        "year": year,
        "payslips": payslips,
        "ugx_payslips": ugx_payslips,
        "usd_payslips": usd_payslips,
        "payroll_record": payroll_record,
        "total_nssf_contribution": get_total_nssf(ugx_payslips),
        "total_paye": get_total_paye(ugx_payslips),
        "total_lst_deduction": get_total_lst_deduction(ugx_payslips),
        "total_lst_allowance": get_total_lst_allowance(ugx_payslips),
        "total_sacco": get_total_sacco(ugx_payslips),
        "total_gross_pay": get_total_gross_pay(ugx_payslips),
        "total_basic_pay": get_total_basic_pay(ugx_payslips),
        "total_net_pay": get_total_net_pay(ugx_payslips),
        "base_dir": BASE_DIR,
    }
    pdf = render_to_pdf('solitonems/payroll.html', context)
    return HttpResponse(pdf, content_type='application/pdf')
Example #4
0
def payroll_record_page_usd(request, id):
    usd_employees = get_employees_paid_in_usd()
    payroll_record = PayrollRecord.objects.get(pk=id)
    # Get the payroll record
    if usd_employees:
        month = payroll_record.month
        year = payroll_record.year
        # Get all the associated payslip objects
        usd_currency = get_usd_currency()
        usd_currency_cost = float(usd_currency.cost)
        usd_payslips = get_usd_payslips(payroll_record)
        # Get all employees
        total_paye = get_total_paye(usd_payslips)
        total_nssf_contribution = get_total_nssf(usd_payslips)
        total_paye_ugx = total_paye * usd_currency_cost
        context = {
            "payroll_page":
            "active",
            "month":
            month,
            "year":
            year,
            "usd_payslips":
            usd_payslips,
            "payroll_record":
            payroll_record,
            "total_nssf_contribution":
            total_nssf_contribution,
            "total_paye":
            total_paye,
            "total_gross_pay":
            get_total_gross_pay(usd_payslips),
            "total_basic_pay":
            get_total_basic_pay(usd_payslips),
            "total_net_pay":
            get_total_net_pay(usd_payslips),
            "total_paye_ugx":
            total_paye_ugx,
            "total_nssf_contribution_ugx":
            total_nssf_contribution * usd_currency_cost,
        }
        return render(request, 'payroll/payroll_record_usd.html', context)
    else:
        return HttpResponseRedirect(reverse(payroll_record_page, args=[id]))
Example #5
0
def generate_payroll_usd_pdf(request, id):
    usd_employees = get_employees_paid_in_usd()
    payroll_record = PayrollRecord.objects.get(pk=id)
    # Get the payroll record
    if usd_employees:
        month = payroll_record.month
        year = payroll_record.year
        # Get all the associated payslip objects
        usd_currency = get_usd_currency()
        usd_currency_cost = float(usd_currency.cost)
        usd_payslips = get_usd_payslips(payroll_record)
        # Get all employees
        total_paye = get_total_paye(usd_payslips)
        total_nssf_contribution = get_total_nssf(usd_payslips)
        total_paye_ugx = total_paye * usd_currency_cost

        context = {
            "payroll_page": "active",
            "month": month,
            "year": year,
            "usd_payslips": usd_payslips,
            "payroll_record": payroll_record,
            "total_nssf_contribution": total_nssf_contribution,
            "total_paye": total_paye,
            "total_sacco": get_total_sacco(usd_payslips),
            "total_gross_pay": get_total_gross_pay(usd_payslips),
            "total_basic_pay": get_total_basic_pay(usd_payslips),
            "total_net_pay": get_total_net_pay(usd_payslips),
            "total_paye_ugx": total_paye_ugx,
            "total_lst_deduction": get_total_lst_deduction(usd_payslips),
            "total_lst_allowance": get_total_lst_allowance(usd_payslips),
            "total_nssf_contribution_ugx":
            total_nssf_contribution * usd_currency_cost,
            "base_dir": BASE_DIR,
        }
        pdf = render_to_pdf('solitonems/payroll_usd.html', context)
        return HttpResponse(pdf, content_type='application/pdf')
    else:
        return HttpResponseRedirect(reverse(payroll_record_page, args=[id]))