#NEWLINE# @ permission_required ( 'entries.view_payroll_summary' ) #NEWLINE# def report_payroll_summary( request ) : #NEWLINE# #INDENT# date = ( timezone . now ( ) - relativedelta ( months = 1 ) ) #NEWLINE# from_date = utils . get_month_start ( date ) . date ( ) #NEWLINE# to_date = ( from_date + relativedelta ( months = 1 ) ) #NEWLINE# year_month_form = PayrollSummaryReportForm ( ( request . GET or None ) , initial = { #NEWLINE# #INDENT# 'month' : from_date . month , #NEWLINE# 'year' : from_date . year , #NEWLINE# #UNINDENT# } ) #NEWLINE# if year_month_form . is_valid ( ) : #NEWLINE# #INDENT# ( from_date , to_date ) = year_month_form . save ( ) #NEWLINE# #UNINDENT# last_billable = utils . get_last_billable_day ( from_date ) #NEWLINE# projects = utils . get_setting ( 'TIMEPIECE_PAID_LEAVE_PROJECTS' ) #NEWLINE# weekQ = Q ( end_time__gt = utils . get_week_start ( from_date ) , end_time__lt = ( last_billable + relativedelta ( days = 1 ) ) ) #NEWLINE# monthQ = Q ( end_time__gt = from_date , end_time__lt = to_date ) #NEWLINE# workQ = ( ~ Q ( project__in = projects . values ( ) ) ) #NEWLINE# statusQ = ( Q ( status = Entry . INVOICED ) | Q ( status = Entry . APPROVED ) ) #NEWLINE# week_entries = Entry . objects . date_trunc ( 'week' ) . filter ( weekQ , statusQ , workQ ) #NEWLINE# date_headers = generate_dates ( from_date , last_billable , by = 'week' ) #NEWLINE# weekly_totals = list ( get_project_totals ( week_entries , date_headers , 'total' , overtime = True ) ) #NEWLINE# leave = Entry . objects . filter ( monthQ , ( ~ workQ ) ) #NEWLINE# leave = leave . values ( 'user' , 'hours' , 'project__name' ) #NEWLINE# extra_values = ( 'project__type__label' , ) #NEWLINE# month_entries = Entry . objects . date_trunc ( 'month' , extra_values ) #NEWLINE# month_entries_valid = month_entries . filter ( monthQ , statusQ , workQ ) #NEWLINE# ( labels , monthly_totals ) = get_payroll_totals ( month_entries_valid , leave ) #NEWLINE# entries = Entry . objects . filter ( monthQ ) . order_by ( ) #NEWLINE# user_values = [ 'user__pk' , 'user__first_name' , 'user__last_name' ] #NEWLINE# unverified = entries . filter ( status = Entry . UNVERIFIED , user__is_active = True ) . values_list ( * user_values ) . distinct ( ) #NEWLINE# unapproved = entries . filter ( status = Entry . VERIFIED ) . values_list ( * user_values ) . distinct ( ) #NEWLINE# return render ( request , 'timepiece/reports/payroll_summary.html' , { #NEWLINE# #INDENT# 'from_date' : from_date , #NEWLINE# 'year_month_form' : year_month_form , #NEWLINE# 'date_headers' : date_headers , #NEWLINE# 'weekly_totals' : weekly_totals , #NEWLINE# 'monthly_totals' : monthly_totals , #NEWLINE# 'unverified' : unverified , #NEWLINE# 'unapproved' : unapproved , #NEWLINE# 'labels' : labels , #NEWLINE# #UNINDENT# } )