Exemple #1
0
def edit_fees_schedule(request , fee_schedule_id):
    ''' edit fees schedule '''

    errors = {}
    ins_obj = None
    try:
        ins_id = request.session['ins_id']
        ins_obj = Institution.objects.get(pk=ins_id)
    except Exception:
        return HttpResponse('<html><body><h3>Broken Session</h3></body></html'
                            '>')
    record_updated = False
    try:
        instance = Fees_schedule.objects.get(pk=fee_schedule_id)
    except Exception:
        errors['object_does_not_exists'] = 'Object Does Not Exist'
        return render(request, 'add_edit_fees_schedule.html', locals())
    if request.method == 'POST':
        form = FeeScheduleForm(request.POST, instance=instance)
        sh_amount = int(request.POST.get('fees_amount'))
        amount = instance.fee.amount
        s_date = request.POST.get('start_date')
        from django.forms.fields import DateField
        d = DateField()
        start_date = d.to_python(request.POST.get('start_date'))
        end_date = d.to_python(request.POST.get('end_date'))
        fee_obj = instance.fee
        results = get_date_for_edit(fee_schedule_id, fee_obj, start_date,
                                    end_date)
        amount = get_basic_amount_edit(fee_schedule_id, fee_obj)
        if results == 'start_date':
            errors['start_date_greater'] = \
                'Start date should not be greater than previous '\
                'installment\'s end date'
            return render(request, 'add_edit_fees_schedule.html', locals())
        if results == 'end_date':
            errors['end_date_greater'] = \
                'end date should not be greater than next installment\'s '\
                'start date'
            return render(request, 'add_edit_fees_schedule.html', locals())
        if sh_amount > amount:
            errors['amount_greater_than_basic_amount'] = \
                ('Fees Amount should not be greater than ' + str(amount)
                + '(basic amount)')
            return render(request, 'add_edit_fees_schedule.html', locals())
        else:
            if form.is_valid():
                form1 = form.save(commit = False)
                form1.institution = ins_obj
                form1.save()

                # [2nd]===if u want to specify which fields to save use:
                # instance.save(update_fields=['name'])

                record_updated = True
    else:
        form = FeeScheduleForm(request.GET, instance=instance)
        form = FeeScheduleForm(instance=instance)

    return render(request , 'add_edit_fees_schedule.html', locals())
Exemple #2
0
 def test_insert_master_data(self):
     department = Department.objects.create(name="agriculture")
     designation = Designation.objects.create(name="jr_teacher")
     skill_type = Skill_Type.objects.create(name = "teaching")
     position_type = Position_Type.objects.create(name = "senior")
     salutions = Salutations.objects.create(name = "Dr")
     maritial_status = Maritial_Status.objects.create(name = "married")
     skill = Skills.objects.create(skill_type = skill_type, name="botany")
     staff_type = Staff_Type.objects.create(name="Worker")
     person = Person.objects.create(position_type=position_type, prefix = salutions, first_name = 'harish',farmer_id = '123',gender = 'male',maritial_status= maritial_status, uuid = 'sdf45')
     d = DateField()
     joining_date = d.to_python('2014-02-02')
     staff = Staff.objects.create(staff_type=staff_type, personal_info=person, date_of_joining=joining_date, work_experience=2)
Exemple #3
0
def manage_staff(request, task=None):

    """ Staff record management funtions """
    response = {}
    success = False
    msg = ''

    if task == "add":
        form = add_staff_form()
        if request.method == "POST":
            form = add_staff_form(request.POST)
            from farmer.models import Position_Type
            if form.is_valid():
                from farmer.models import Maritial_Status
                maritial_status_obj = Maritial_Status.objects.get(id=int(request.POST.get('maritial_status')))

                user_obj = None
                from farmer.models import Salutations
                prefix_obj = Salutations.objects.get(id=int(request.POST.get('prefix')))

                birth_date = ""; leaving_date = ""

                d = DateField()
                joining_date = None;leaving_date = None;birth_date = None
                if request.POST.get('date_of_joining'):
                    joining_date = d.to_python(request.POST.get('date_of_joining',''))
                if request.POST.get('date_of_leaving'):
                    leaving_date = d.to_python(request.POST.get('date_of_leaving',''))
                if request.POST.get('dob'):
                    birth_date = d.to_python(request.POST.get('dob',''))

                from uuid import uuid4
                uuid = uuid4().hex    # generates unique ID

                person_obj = Person.objects.create(first_name=request.POST.get('first_name'),middle_name=request.POST.get('middle_name'),Last_name=request.POST.get('Last_name'),\
                prefix=prefix_obj, farmer_id=request.POST.get('farmer_id'),gender=request.POST.get('gender'),\
                dob= birth_date, maritial_status=maritial_status_obj, uuid=uuid, added_by=request.user)
                from django.template.defaultfilters import slugify

                slug = slugify(str(person_obj.id)+str(person_obj.first_name))
                person_obj.slug = slug
                person_obj.save()

                staff_type_obj = Staff_Type.objects.get(id=int(request.POST.get('staff_type')))
                department_obj = None;designation_obj = None
                if request.POST.get('department'):
                    department_obj = Department.objects.get(id=int(request.POST.get('department')))
                if request.POST.get('designation'):
                    designation_obj = Designation.objects.get(id=int(request.POST.get('designation')))

                staff_obj = Staff.objects.create(staff_type = staff_type_obj, personal_info = person_obj, \
                           department = department_obj, designation=designation_obj, \
                            date_of_joining = joining_date, date_of_leaving = leaving_date, \
                            photo = request.POST.get('photo',''),work_experience = request.POST.get('work_experience','') )

                if request.POST.getlist('skills'):
                    sk_list = [int(i) for i in request.POST.getlist('skills')]
                    for i in sk_list:
                        sk_obj = Skills.objects.get(id= i)
                        staff_obj.skills.add(sk_obj)
                        staff_obj.save()

                from farmer.models import Educational_Qualification
                if request.POST.getlist('qualification'):
                    sk_list = [int(i) for i in request.POST.getlist('qualification')]
                    for i in sk_list:
                        sk_obj = Educational_Qualification.objects.get(id= i)
                        staff_obj.qualification.add(sk_obj)
                        staff_obj.save()
                request.session['staff_id'] = staff_obj.id
                form = add_staff_address_form(staff_obj.id)

                added = True
                msg = "Staff added successfully"
                success = True
                #return  HttpResponseRedirect('/hr/Staff-Address/add/')
                #return render(request, 'hrmanagement/add_edit_staff_address.html', locals())
            else:
                msg = "Error Occurred"
            response = {'msg':msg, 'success':success}
            return HttpResponse(json.dumps(response), mimetype = "application/json")

    elif task =="edit":
        id_edit = request.GET.get('id_edit')
        staff_obj = Staff.objects.get(id=int(id_edit))
        person_obj = Person.objects.get(id = staff_obj.personal_info.id)
        form = add_staff_form(initial = {'prefix':person_obj.prefix, 'first_name':person_obj.first_name, \
        'middle_name':person_obj.middle_name, 'Last_name':person_obj.Last_name, \
        'farmer_id':person_obj.farmer_id, \
        'gender':person_obj.gender, 'dob':person_obj.dob, 'maritial_status':person_obj.maritial_status, 'designation':staff_obj.designation, \
        'staff_type':staff_obj.staff_type, 'personal_info':staff_obj.personal_info, 'skills':staff_obj.skills.all(), 'department':staff_obj.department, \
        'qualification':staff_obj.qualification.all(), 'date_of_joining':staff_obj.date_of_joining, 'date_of_leaving':staff_obj.date_of_leaving, \
        'photo':staff_obj.photo, 'work_experience':staff_obj.work_experience})

        if request.method == 'POST':
            form = add_staff_form(request.POST, request.FILES)
            if form.is_valid():
                from farmer.models import Position_Type, Maritial_Status, Educational_Qualification, Salutations
                maritial_status_obj = Maritial_Status.objects.get(id=int(request.POST.get('maritial_status')))

                prefix_obj = Salutations.objects.get(id=int(request.POST.get('prefix')))

                d = DateField()

                person_obj.prefix = prefix_obj;person_obj.first_name = request.POST.get('first_name','')
                person_obj.middle_name = request.POST.get('middle_name','');person_obj.Last_name = request.POST.get('Last_name','')
                person_obj.farmer_id = request.POST.get('farmer_id','')
                person_obj.gender = request.POST.get('gender','')

                if request.POST.get('dob'):
                    birth_date = d.to_python(request.POST.get('dob',''))
                    person_obj.dob = birth_date
                person_obj.maritial_status = maritial_status_obj;person_obj.uuid = request.POST.get('uuid','')

                if request.POST.get('added_by'):
                    user_obj = User.objects.get(id=int(request.POST.get('added_by')))
                    person_obj.added_by = user_obj

                person_obj.save()

                staff_type_obj = Staff_Type.objects.get(id=int(request.POST.get('staff_type')))

                department_obj = None;designation_obj = None
                if request.POST.get('department'):
                    department_obj = Department.objects.get(id=int(request.POST.get('department')))
                if request.POST.get('designation'):
                    designation_obj = Designation.objects.get(id=int(request.POST.get('designation')))

                staff_obj.staff_type = staff_type_obj;staff_obj.personal_info = person_obj
                staff_obj.department = department_obj
                staff_obj.designation = designation_obj
                if request.POST.get('date_of_joining'):
                    joining_date = d.to_python(request.POST.get('date_of_joining',''))
                    staff_obj.date_of_joining = joining_date
                if request.POST.get('date_of_leaving'):
                    leaving_date = d.to_python(request.POST.get('date_of_leaving',''))
                    staff_obj.date_of_leaving = leaving_date
                staff_obj.photo = request.POST.get('photo','')
                staff_obj.work_experience = request.POST.get('work_experience','')
                staff_obj.save()

                if request.POST.getlist('skills'):
                    sk_list = [int(i) for i in request.POST.getlist('skills')]
                    for i in sk_list:
                        sk_obj = Skills.objects.get(id= i)
                        staff_obj.skills.add(sk_obj)
                        staff_obj.save()

                if request.POST.getlist('qualification'):
                    sk_list = [int(i) for i in request.POST.getlist('qualification')]
                    for i in sk_list:
                        sk_obj = Educational_Qualification.objects.get(id= i)
                        staff_obj.qualification.add(sk_obj)
                        staff_obj.save()
                edit_done = True
                msg = "Staff edited successfully"
                success = True
            else:
                msg = "Invalid Form"
            response = {'msg':msg, 'success':success}
            return HttpResponse(json.dumps(response), mimetype = "application/json")

    elif task =="delete":
        id_del = request.GET.get('id_del')
        staff = Staff.objects.get(id = id_del)
        staff.active = 0
        staff.save()
        msg = "Staff deactivated successfully"
        success = True
        response = {'msg':msg, 'success':success}
        return HttpResponse(json.dumps(response), mimetype = "application/json")

    elif task == "active":
        active = request.GET.get('active')
        staff = Staff.objects.get(id = active)
        staff.active = 2
        staff.save()
        msg = "Staff activated successfully"
        success = True
        response = {'msg':msg, 'success':success}
        return HttpResponse(json.dumps(response), mimetype = "application/json")

    return render_to_response('hrmanagement/add_edit_staff.html', locals(), context_instance = RequestContext(request))
Exemple #4
0
def add_fees_schedule(request, fee_id):
    ''' add a arecord for fee schedule '''

    form = FeeScheduleForm()
    ins_obj = None
    try:
        ins_id = request.session['ins_id']
        ins_obj = Institution.objects.get(pk = ins_id)  # put this in try...catch
    except Exception:
        return HttpResponse('<html><body><h3>Broken Session</h3></body></html'
                            '>')
    fee_obj = Fee.objects.get(id=fee_id)
    record_added = False
    errors = {}
    if request.method == 'POST':
        form = FeeScheduleForm(request.POST)
        if form.is_valid():
            sh_amount = int(request.POST.get('fees_amount'))
            fee_amount = fee_obj.amount
            s_date = request.POST.get('start_date')
            from django.forms.fields import DateField
            date1 = DateField()
            start_date = date1.to_python(s_date)
            fee_obj = Fee.objects.get(id = fee_id)
            max_date = get_date_for_add(fee_obj)
            amount = get_basic_amount(fee_obj)
            if max_date:
                if max_date >= start_date:
                    errors['start_date_greater'] = \
                        ('Start date should not be greater than previous '
                        'installment\'s end date(' + str(max_date) + ') ')
                    return render(request, 'add_edit_fees_schedule.html',
                                  locals())
            if sh_amount > amount:
                errors['amount_greater_than_basic_amount'] = \
                    ('Fees Amount should not be greater than ' + str(amount)
                    + '(basic_amount - installment_amount)')
                return render(request, 'add_edit_fees_schedule.html', locals())
            else:
                form1 = form.save(commit = False)
                form1.fee = fee_obj
                form1.created_by = request.user
                form1.institution = ins_obj
                form1.save()
                record_added = True
                return render(request, 'add_edit_fees_schedule.html',
                              locals())
        else:
            errors['invalid_datails'] = 'Please enter valid data'
            return render(request, 'add_edit_fees_schedule.html',
                          locals())
    else:
        form = FeeScheduleForm()
        fee_sh_list = Fees_schedule.objects.filter(fee = fee_obj , is_active = True)
        if fee_obj.payment_type == "recursive":
            remaining_installments = fee_obj.installments - fee_sh_list.count()
            if remaining_installments == 1:
                amount = 0
                for i in fee_sh_list:
                    amount = amount + i.fees_amount
                remaining_amount =  fee_obj.amount - amount
            if remaining_installments == fee_obj.installments:
                installment_no = 1
    return render(request, 'add_edit_fees_schedule.html', locals())