Exemplo n.º 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)
Exemplo n.º 2
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')
Exemplo n.º 3
0
def payroll_download(request, id):
    # Get the payroll record
    payroll_record = get_payroll_record_by_id(id)
    month = payroll_record.month
    year = payroll_record.year
    # Get all the associated Payroll objects
    payrolls = get_ugx_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
    writer.writerow([heading_text.upper()])
    writer.writerow([
        'Name', 'Basic Salary', 'Gross Salary', 'Employee NSSF Contribution',
        'Employer NSSF contribution', 'PAYE', '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,
            payroll.employee.lunch_allowance,
            payroll.overtime,
            payroll.bonus,
            payroll.sacco_deduction,
            payroll.damage_deduction,
            payroll.net_salary,
        ])

    # Return the response
    return response