Esempio n. 1
0
	def setup(self, request, **kwargs):
		super(WorkingTimeRecorderView, self).setup(request, **kwargs)
		self.request, self.kwargs = request, kwargs
		self.employee_id = self.kwargs['employee_id']
		self.worker = get_object_or_404(Employee, pk=self.employee_id)
		initial = {'worker': self.worker}
		employees = Employee.objects.filter(employeedata__end_contract__isnull=True, status=True)
		employees = employees.order_by('surname', 'forename')
		query = Q(worker=self.worker) & (Q(overtime=1)|Q(overtime=2))
		overhours = EmployeeData.objects.filter(query).exists()
		records = employee_records(self.employee_id)
		ctx_data = {'employee_id': self.employee_id, 'employees': employees,
		            'overhours': overhours, 'wtr_flag': True, 'records': records}
		self.context = initial | ctx_data

		if self.request.method == 'GET':
			if 'work_hours' in self.kwargs.keys():
				initial.update(initial_worktime_form(self.kwargs['work_hours']))
				self.form = WorkEvidenceForm(initial=initial)
			else:
				self.form = WorkEvidenceForm(initial=initial)

			employee_total_data(self.employee_id, now().year, now().month, self.context)

		elif self.request.method == 'POST':
			self.form = WorkEvidenceForm(data=self.request.POST)

		self.context.__setitem__('form', self.form)
Esempio n. 2
0
	def setup(self, request, **kwargs):
		super(LeaveTimeRecorderView, self).setup(request, **kwargs)
		self.request, self.kwargs = request, kwargs
		employee_id = self.kwargs['employee_id']
		records = employee_records(employee_id)
		employees = Employee.objects.filter(employeedata__end_contract__isnull=True, status=True)
		employees = employees.order_by('surname', 'forename')
		self.worker = get_object_or_404(Employee, pk=employee_id)
		self.values = {'worker': self.worker, 'leave_date__year': now().year}
		total_leaves = EmployeeLeave.objects.filter(**self.values).order_by('leave_date')
		remaining_leave = 26 - total_leaves.filter(leave_flag='paid_leave').count()
		years = [item.year for item in EmployeeLeave.objects.filter(worker=self.worker).dates('leave_date', 'year', order='DESC')]
		leave_set = {year:EmployeeLeave.objects.filter(worker=self.worker, leave_date__year=year).count() for year in years}

		if self.request.method == 'GET':
			initial = initial_leave_form(employee_id)
			self.form = EmployeeLeaveForm(initial=initial)
		elif self.request.method == 'POST':
			self.form = EmployeeLeaveForm(data=self.request.POST)

		self.context = {'form': self.form, 'remaining_leave': remaining_leave, 'worker': self.worker,
		                'total_leaves': total_leaves.count(), 'ltr_flag': True, 'records': records,
		                'employees': employees, 'employee_id': employee_id, 'leave_set': leave_set, 'year': now().year,}

		flags = {'leaves_pl': 'paid_leave', 'leaves_upl': 'unpaid_leave', 'leaves_ml': 'maternity_leave'}
		for key, value in flags.items():
			self.context.__setitem__(key, total_leaves.filter(leave_flag=value))
Esempio n. 3
0
    def setup(self, request, *args, **kwargs):
        super(EmployeeBasicDataView, self).setup(request, **kwargs)
        self.request, self.kwargs, self.context, employee_id = request, kwargs, dict(
        ), None
        employees = Employee.objects.all()

        if 'employee_id' in self.kwargs.keys():
            employee_id = self.kwargs['employee_id']
            worker = get_object_or_404(Employee, pk=employee_id)
            fields = list(worker.__dict__.keys())[4:]
            initial = Employee.objects.filter(pk=employee_id).values(
                *fields)[0]
            self.context = {'employee_id': employee_id, 'worker': worker}
            extdata = EmployeeData.objects.filter(worker=worker)

            if extdata:
                self.context.__setitem__('extdata', True)
            else:
                self.context.__setitem__('extdata', False)

            if worker.status == False:
                records = employee_records(employee_id)
                self.context |= {'records': records}

        if employees.exists():
            employees_st = employees.filter(status=True)
            employees_sf = employees.filter(status=False)
            self.context.update({
                'employees_st': employees_st,
                'employees_sf': employees_sf
            })

        else:
            messages.warning(request, r'No employee in database...')

        if self.request.method == 'GET':
            if employee_id:
                self.form = EmployeeBasicDataForm(initial=initial)

            else:
                self.form = EmployeeBasicDataForm(initial={'status': 0})
                self.context.update({'extdata': False, 'new_employee': True})

        elif self.request.method == 'POST':
            self.form = EmployeeBasicDataForm(data=self.request.POST)
            if employee_id:
                self.old_values = Employee.objects.filter(
                    pk=employee_id).values(*fields)[0]
            else:
                self.old_values = {'pesel': request.POST['pesel']}

        self.context.update({'form': self.form})
Esempio n. 4
0
	def setup(self, request, **kwargs):
		super(EmployeeCurrentComplexDataView, self).setup(request, **kwargs)
		self.request, self.kwargs = request, kwargs
		employee_id = self.kwargs['employee_id']
		records = employee_records(employee_id)
		worker = get_object_or_404(Employee, pk=employee_id)
		leave_kind = ('unpaid_leave', 'paid_leave', 'maternity_leave')

		if self.request.method == 'GET':
			month, year = self.kwargs['month'], self.kwargs['year']
			choice_date = datetime.strptime(f'{month}/{year}','%m/%Y')
			form = PeriodCurrentComplexDataForm(initial={'choice_date': choice_date})

		elif self.request.method == 'POST':
			choice_date = datetime.strptime(self.request.POST['choice_date'],'%m/%Y')
			month, year = choice_date.month, choice_date.year
			form = PeriodCurrentComplexDataForm(data={'choice_date':choice_date})

		day = calendar.monthrange(year, month)[1]
		q1 = Q(employeedata__end_contract__lt=date(year, month, 1))
		q2 = Q(employeedata__start_contract__gt=date(year, month, day))
		employees = Employee.objects.all()
		employees = employees.exclude(q1|q2).order_by('surname', 'forename')
		query = Q(worker=worker, start_work__year=year, start_work__month=month)
		work_hours = WorkEvidence.objects.filter(query)
		holidays = holiday(year)
		year_leaves = EmployeeLeave.objects.filter(worker=worker, leave_date__year=year)
		query = Q(worker=worker, leave_date__year=year, leave_date__month=month)
		sml = EmployeeLeave.objects.filter(query)
		month_leaves = {kind:sml.filter(leave_flag=kind).count() for kind in leave_kind}
		year_leaves = {kind:year_leaves.filter(leave_flag=kind).count() for kind in leave_kind}
		# data for modal chart
		total_brutto_set = data_modal_chart(employee_id)
		self.context = {'form': form, 'employee_id': employee_id, 'choice_date': choice_date, 'month_leaves': month_leaves,
		                'year_leaves': year_leaves, 'month': month, 'employees': employees, 'holidays' : holidays,
		                'worker': worker, 'total_brutto_set': total_brutto_set, 'year': year, 'records': records,
		                'sml': sml.order_by('leave_date'), 'work_hours': work_hours.order_by('start_work')}
		employee_total_data(employee_id, year, month, self.context)
Esempio n. 5
0
	def setup(self, request, **kwargs):
		super(AccountPaymentView, self).setup(request, **kwargs)
		self.request, self.kwargs = request, kwargs
		self.employee_id = self.kwargs['employee_id']
		records = employee_records(self.employee_id)
		self.month, self.year = now().month, now().year
		self.initial = initial_account_form(self.employee_id)
		self.worker = get_object_or_404(Employee, pk=self.employee_id)
		self.prevmonth, self.prevyear = previous_month_year(self.month, self.year)
		earlier_date = date(self.prevyear, self.prevmonth, 1)
		# set list of valid employees
		q1 = Q(status=1)
		q2 = Q(employeedata__end_contract__gte=earlier_date)
		employees = Employee.objects.filter(q1|q2).order_by('surname', 'forename')

		if self.request.method == 'GET':
			self.form = AccountPaymentForm(initial=self.initial)
		elif self.request.method == 'POST':
			self.form = AccountPaymentForm(data=self.request.POST)

		# seting context
		self.context = {'form': self.form, 'worker': self.worker, 'earlier_date': earlier_date,
		                'month': self.month, 'employee_id': self.employee_id, 'employees': employees,
		                'year': self.year, 'ap_flag': True, 'records': records}