Esempio n. 1
0
def new_employee(request):
    names = [
        'Create New Employee', 'Attendance', 'Pay to Employee', 'List Employee'
    ]
    links = [
        reverse('new_employee'),
        reverse('attendance'),
        reverse('emp_payments'),
        reverse('employee')
    ]
    submenus = create_sub(names, links)
    if len(request.POST) <= 0:
        form = EmployeeForm()
        return render(request, "new.html", {
            'form': form,
            'entity': 'Employee',
            'submenus': submenus
        })
    else:
        form = EmployeeForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            url = reverse('employee')
            return HttpResponseRedirect("%s?success=1" % (url))
        else:
            return render(
                request, "new.html", {
                    'title': 'Create New Project',
                    'form': form,
                    'entity': 'Employee',
                    'errors': 'Invalid Entry or required fields not filled'
                })
Esempio n. 2
0
def new_employee(request) :
    names= ['Create New Employee','Attendance','Pay to Employee','List Employee']
    links = [reverse('new_employee'),reverse('attendance'),reverse('emp_payments'),reverse('employee')]
    submenus = create_sub(names,links)
    if len(request.POST) <= 0:
        form = EmployeeForm()
        return render(request , "new.html", {'form':form,'entity':'Employee','submenus':submenus})
    else :
        form = EmployeeForm(request.POST)
        if form.is_valid() :
            form.save(commit=True)
            url = reverse('employee')
            return HttpResponseRedirect("%s?success=1"%(url))
        else :
            return render(request, "new.html", {'title':'Create New Project','form': form,'entity':'Employee','errors':'Invalid Entry or required fields not filled'})
Esempio n. 3
0
def edit_employee(request, empid):
    names = [
        'Create New Employee', 'Attendance', 'Pay to Employee', 'List Employee'
    ]
    links = [
        reverse('new_employee'),
        reverse('attendance'),
        reverse('emp_payments'),
        reverse('employee')
    ]
    submenus = create_sub(names, links)
    emp = get_object_or_404(Employee, pk=empid)
    if len(request.POST) <= 0:
        data = {
            "name": emp.name,
            "designation": emp.designation,
            "category_id": format(emp.category_id.id),
            "salary": emp.salary,
            "phone_number": emp.phone_number,
            "joined_date": emp.joined_date,
            "status": emp.status,
            "outstanding": emp.outstanding
        }
        form = EmployeeForm(data)
        return render(request, "edit.html", {
            'title': 'Update Employee Details',
            'form': form,
            'submenus': submenus
        })
    else:
        form = EmployeeForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            for key in cd:
                setattr(emp, key, cd.get(key))
            emp.save()
            url = reverse('employee')
            return HttpResponseRedirect("%s?success=2" % (url))
        else:
            return render(request, "edit.html", {
                'title': 'Update Employee Details',
                'form': form
            })
Esempio n. 4
0
def edit_employee(request,empid):
    names= ['Create New Employee','Attendance','Pay to Employee','List Employee']
    links = [reverse('new_employee'),reverse('attendance'),reverse('emp_payments'),reverse('employee')]
    submenus = create_sub(names,links)
    emp = get_object_or_404(Employee, pk=empid)
    if len(request.POST) <= 0:
        data = {"name":emp.name,"designation":emp.designation,	"category_id":format(emp.category_id.id),"salary":emp.salary,"phone_number":emp.phone_number,
                "joined_date":emp.joined_date,"status":emp.status,"outstanding":emp.outstanding}
        form = EmployeeForm(data)
        return render(request, "edit.html",{'title':'Update Employee Details','form':form,'submenus':submenus})
    else:
        form = EmployeeForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            for key in cd:
                setattr(emp, key, cd.get(key))
            emp.save();
            url = reverse('employee')
            return HttpResponseRedirect("%s?success=2"%(url))
        else:
            return render(request, "edit.html",{'title':'Update Employee Details','form':form})