Add employee paystub generation API route

This commit is contained in:
Tanner Collin 2017-07-02 23:52:46 +00:00
parent 80cc811049
commit 870e48a516
2 changed files with 48 additions and 1 deletions

View File

@ -309,3 +309,17 @@ class RecordSheetSerializer(serializers.Serializer):
phone_number = serializers.CharField()
sin = serializers.CharField()
record = RecordSerializer(many=True)
class PayStubSerializer(serializers.Serializer):
management = serializers.CharField()
client = serializers.CharField()
provider = serializers.CharField()
payday = serializers.DateField()
reg_pay = serializers.DecimalField(max_digits=10, decimal_places=2)
vac_pay = serializers.DecimalField(max_digits=10, decimal_places=2)
earnings = serializers.DecimalField(max_digits=10, decimal_places=2)
cpp = serializers.DecimalField(max_digits=10, decimal_places=2)
ei = serializers.DecimalField(max_digits=10, decimal_places=2)
income_tax = serializers.DecimalField(max_digits=10, decimal_places=2)
total_deductions = serializers.DecimalField(max_digits=10, decimal_places=2)
net_pay = serializers.DecimalField(max_digits=10, decimal_places=2)

View File

@ -12,7 +12,7 @@ from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.renderers import StaticHTMLRenderer
from caremyway.api.serializers import UserSerializer, UserInfoSerializer, ClientSerializer, ProviderSerializer, WorkTypeSerializer, EmployeeSerializer, EmployerSerializer, PriceSerializer, CShiftSerializer, PShiftSerializer, TimeSheetSerializer, RecordSheetSerializer
from caremyway.api.serializers import UserSerializer, UserInfoSerializer, ClientSerializer, ProviderSerializer, WorkTypeSerializer, EmployeeSerializer, EmployerSerializer, PriceSerializer, CShiftSerializer, PShiftSerializer, TimeSheetSerializer, RecordSheetSerializer, PayStubSerializer
class UserViewSet(viewsets.ModelViewSet):
lookup_field = 'username'
@ -415,6 +415,31 @@ def gen_recordsheets(user, payday, manage):
return list(recordsheets)
def gen_paystubs(user, payday, manage):
recordsheets = gen_recordsheets(user, payday, manage)
print(recordsheets)
paystubs = []
for recordsheet in recordsheets:
lastrecord = recordsheet['record'][-1]
paystub = {}
paystub['management'] = recordsheet['management']
paystub['client'] = recordsheet['client']
paystub['provider'] = recordsheet['provider']
paystub['payday'] = lastrecord['payday']
paystub['reg_pay'] = lastrecord['reg_pay']
paystub['vac_pay'] = lastrecord['vac_pay']
paystub['earnings'] = lastrecord['earnings']
paystub['cpp'] = lastrecord['cpp']
paystub['ei'] = lastrecord['ei']
paystub['income_tax'] = lastrecord['income_tax']
paystub['total_deductions'] = lastrecord['total_deductions']
paystub['net_pay'] = lastrecord['net_pay']
paystubs.append(paystub)
return list(paystubs)
class ReportView(APIView):
def get(self, request, *args, **kwargs):
response = []
@ -438,6 +463,14 @@ class ReportView(APIView):
response = RecordSheetSerializer(recordsheets, many=True).data
elif report_type == 'paystub':
payday = validate_param(qp.get('payday'), serializers.DateField())
manage = validate_param(qp.get('manage'), serializers.UUIDField(allow_null=True))
paystubs = gen_paystubs(request.user, payday, manage)
response = PayStubSerializer(paystubs, many=True).data
return Response(response, status=status.HTTP_200_OK)
@api_view()