Example #1
0
def addRecord(request):
    
    bhour = int(request.POST['bhour'].split(':')[0])
    ehour = int(request.POST['ehour'].split(':')[0])
    bminutes = int(request.POST['bhour'].split(':')[1])
    eminutes = int(request.POST['ehour'].split(':')[1])
    subtotal = float((ehour-bhour) + float(eminutes-bminutes)/60)
    time_format = "%Y-%m-%d"

    hourly_pay = Employee.gql("WHERE mail = :1", users.get_current_user()).get().hourly_pay
             
    working = WorkingHours()
    result = WorkingHours.gql('ORDER BY id DESC').get();
    working.id = result.id + 1 if result else 1
    working.worker = users.get_current_user()
    working.working_date = datetime.date.fromtimestamp(time.mktime(time.strptime(request.POST['date'], time_format)))
    working.working_bhour = request.POST['bhour']
    working.working_ehour = request.POST['ehour']
    working.working_area = request.POST['area']
    working.working_content = request.POST['content']
    working.subtotal = subtotal
    working.pay = int(subtotal * hourly_pay)
    working.put()
    
    return redirect('/employee/')