Ejemplo n.º 1
0
def report_team_stat_week(request, team, year, week, excel=0): 
	team = get_object_or_404(Teams, slug=team)
	agents = Agent.objects.filter(teamid=team).filter(haveleft=0).filter(agenttype=0)
	targets = Targets.objects.get(name=team.targets)
	title = team.name + " Week Breakdown: Week " + week + " - " + year

	teams = {}
	stats = Dstats.objects.filter(team=team).filter(isoyear=year).filter(isoweek=week)
	teamtotals = stats.aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours'), Sum('innovhours'))
	totalhours = teamtotals['prodhours__sum']+teamtotals['sickhours__sum']+teamtotals['innovhours__sum']
	if totalhours > 0:
		teamcalltime = teamtotals['calltime__sum'] / (teamtotals['prodhours__sum']/targets.hours)
		teamcallattempts = teamtotals['callattempts__sum'] / (teamtotals['prodhours__sum']/targets.hours)
		teamfte = teamtotals['totalapps__sum'] / ((teamtotals['prodhours__sum'] + teamtotals['sickhours__sum'])/targets.hours)

	teams['Totals'] = (teamtotals['totalapps__sum'], humantime(teamtotals['calltime__sum']), teamtotals['callattempts__sum'])
	teams['Average'] = (teamfte, humantime(int(teamcalltime)), int(teamcallattempts))

	agentstatlist = {}
	agentaveragelist = {}
	for agent in agents:
		daylist = []
		agentstats = stats.filter(agent=agent)
		totals = agentstats.aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours'), Sum('holhours'), Sum('innovhours'))
		for stat in agentstats:
			daylist.append([stat.date, stat.calltime, stat.callattempts, stat.totalapps, stat.prodhours, stat.sickhours, stat.holhours])

		totalhours = 0
		if totals['prodhours__sum'] >= 0 and totals['sickhours__sum'] >= 0 and totals['innovhours__sum'] >= 0:
			totalhours = totals['prodhours__sum'] + totals['sickhours__sum'] + totals['innovhours__sum']
			calltime = 0
			callattempts = 0
			fteapplications = 0
			applications = 0

		if totalhours > 0 and totals['prodhours__sum'] > 0:
			calltime = totals['calltime__sum'] / (totals['prodhours__sum']/targets.hours)
			callattempts = totals['callattempts__sum'] / (totals['prodhours__sum']/targets.hours)
			fteapplications = totals['totalapps__sum'] / ((totals['prodhours__sum'] + totals['sickhours__sum'] + totals['innovhours__sum'])/targets.hours)
		else:
			calltime = 0
			callattempts = 0
			fteapplications = 0
		applications = totals['totalapps__sum']

		daylist.append(["Totals", int(calltime), callattempts, applications, fteapplications, "", "", "FTE"])
		agentaveragelist[agent.name] = (humantime(int(calltime)), int(callattempts), applications, fteapplications)

		agentstatlist[agent.name] = daylist

	if excel > 0:
		template = 'reports/excel/breakdown.html'
		context = RequestContext(request, {"title":title, 'agentstats':agentstatlist, 'team':teams, 'agentaveragelist':agentaveragelist})

		response = render_to_response(template, context)

		filename = "%sbreakdown%s%s.xls" % (team.slug, year, week)
		response['Content-Disposition'] = 'attachment; filename='+filename
		response['Content-Type'] = 'application/vnd.ms-excel; charset=utf-8'

		return response
	else:
		url = "/reports/team/excel/"+team.slug+"/"+year+"/"+week
		template = 'reports/breakdown.html'
		context = RequestContext(request, {'url':url, "title":title, 'agentstats':agentstatlist, 'team':teams, 'agentaveragelist':agentaveragelist})
    
		response = render_to_response(template, context)
    
		return response
Ejemplo n.º 2
0
def agent_month_review(request, agent, year, month): #done
    user = request.user.get_profile()
    type = int(user.agenttype)
    agent = get_object_or_404(Agent, slug=agent)
    if not request.user.has_perm('agents.super'):
        if not user.name == agent.name:
            slug = user.slug
            url = "/agent/" + slug
            return HttpResponseRedirect(url) 

    response = HttpResponse(mimetype='application/pdf')
    filename = "%s-AgentMonthReport-%s-%s.pdf" % (agent.slug, month, year)
    response['Content-Disposition'] = 'attachment; filename='+filename

    team = Teams.objects.get(name=agent.teamid)
    target = Targets.objects.get(name=team.targets)
    globalstats = Dstats.objects.filter(agent=agent).filter(isoyear=year).filter(month=month)
    sick = globalstats.filter(sickhours__gt = 0).count()
    working = globalstats.filter(prodhours__gt = 0).count()
    holiday = globalstats.filter(holhours__gt = 0).count()
    monthtotals = globalstats.aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours'))
    if monthtotals['calltime__sum'] > 0:
        calltime = monthtotals['calltime__sum'] / (monthtotals['prodhours__sum'] / target.hours)
        calltime = int(calltime)
        realcalltime = humantime(calltime)

    qappsum = QualifiedApps.objects.filter(agent=agent).filter(month=month).filter(year=year).aggregate(Sum('qualifiedapps'),)
    qappsum = qappsum['qualifiedapps__sum']
    qapptarget = (target.commission3 / target.days) * agent.parttimedays

    volsum = WeeklyStats.objects.filter(agent=agent).filter(isomonth=month).filter(isoyear=year).aggregate(Sum('volume'), Avg('drawcust'))

    targetct = humantime(target.calltime)
    targetapps = int(((monthtotals['prodhours__sum'] + monthtotals['sickhours__sum']) / target.hours) * Decimal(target.applications))
    targetbuying = str(target.drawingcust) + "%"

    p = canvas.Canvas(response)

    p.setFont("Helvetica", 16)
    titlestring = agent.name + " - Monthly Report: " + month_display(month) + "/" + year
    p.drawString(50,800, titlestring)

    p.setFont("Helvetica-Bold", 16)
    p.drawString(50, 820, team.name)

    p.setFont("Helvetica", 14)

    workingtext = "Working Days: " + str(working)
    sicktext = "Sick Days: " + str(sick)
    holidaytext = "Holiday Days: " + str(holiday)
    p.drawString(50, 770, workingtext)

    p.drawString(450, 770, holidaytext)

    p.drawString(50, 750, "Academy Position: ")

    p.drawString(250, 770, sicktext)

    p.drawString(250, 750, "Academy Year to Date: ")

    p.setFont("Helvetica-Bold", 14)
    p.drawString(50, 720, "MONTHLY")
    p.rect(50,710,500,-125,fill=0)
    
    p.drawString(50, 560, "Review of last months objectives")
    p.rect(50,540,500,-125,fill=0)

    p.drawString(50, 400, "Team and Environment")
    p.rect(50,390,500,-80,fill=0)

    p.drawString(50, 290, "Action Plan")
    p.rect(50,280,500,-140,fill=0)

    p.drawString(50, 120, "Calls")
    p.rect(50,110,500,-50,fill=0)

    p.line(50,685,550,685)
    p.line(50,665,550,665)
    p.line(50,645,550,645)
    p.line(50,625,550,625)
    p.line(50,605,550,605)

    p.line(150,710,150,585)
    p.line(200,710,200,585)
    p.line(250,710,250,585)
    p.line(300,710,300,585)
    p.line(350,710,350,585)

    p.line(295,110,295,60)

    p.setFont("Helvetica", 8)
    p.drawString(155, 700, "Target")
    p.drawString(205, 700, "Actual")
    p.drawString(205, 690, "Month")
    p.drawString(255, 700, "Previous")
    p.drawString(255, 690, "Month")
    p.drawString(305, 700, "Target")
    p.drawString(305, 690, "Met?")
    p.drawString(355, 700, "Comments")

    p.drawString(55, 670, "Average Daily Call Time")
    p.drawString(155, 670, targetct)
    p.drawString(205, 670, realcalltime)
    if calltime >= target.calltime:
        p.drawString(305, 670, "Yes")
    else:
        p.drawString(305, 670, "No")

    p.drawString(55, 650, "New Applications")
    p.drawString(155, 650, str(targetapps))
    p.drawString(205, 650, str(monthtotals['totalapps__sum']))

    if monthtotals['totalapps__sum'] >= targetapps:
        p.drawString(305, 650, "Yes")
    else:
        p.drawString(305, 650, "No")

    p.drawString(55, 630, "Qualified Applications")
    p.drawString(155, 630, str(qapptarget))
    p.drawString(205, 630, str(qappsum))

    if qappsum >= qapptarget:
        p.drawString(305, 630, "Yes")
    else:
        p.drawString(305, 630, "No")

    p.drawString(55, 610, "Monthly Volume")
    p.drawString(155, 610, "")
    p.drawString(205, 610, str(volsum['volume__sum']))

    p.drawString(55, 590, "Buying Customers")
    p.drawString(155, 590, str(targetbuying))
    p.drawString(205, 590, str(volsum['drawcust__avg']))

    p.setFont("Helvetica", 8)
    p.drawString(50, 545, "Please rate your performance:")

    p.setFont("Helvetica", 10)
    p.drawString(170, 545, "Excellent -")
    p.rect(220,545,10,10,fill=0)

    p.drawString(235, 545, "Very Good -")
    p.rect(293,545,10,10,fill=0)

    p.drawString(308, 545, "Good -")
    p.rect(343,545,10,10,fill=0)

    p.drawString(358, 545, "Average -")
    p.rect(405,545,10,10,fill=0)

    p.drawString(420, 545, "Below average -")
    p.rect(495,545,10,10,fill=0)

    p.drawString(510, 545, "Poor -")
    p.rect(540,545,10,10,fill=0)

    p.setFont("Helvetica", 8)
    p.drawString(55, 530, "What went well for you last month?")
    p.drawString(55, 500, "What could you have improved on?")
    p.drawString(55, 470, "How do you feel your performance compares to last month?")
    p.drawString(55, 440, "Would you like any additional training to improve your performance?")

    p.drawString(55, 380, "Do you have any suggestions for improving either the office environment or working procedures?")
    p.drawString(55, 345, "Is there anything else you would like to discuss?")

    p.drawString(55, 270, "Objectives and Goals for next month:")
    p.drawString(55, 220, "How do you intend to achieve this?")
    p.drawString(55, 170, "Additional Comments:")

    p.drawString(450, 270, "FU Date:")
    p.drawString(450, 220, "FU Date:")
    p.drawString(450, 170, "FU Date:")

    p.drawString(55, 100, "Two things to Continue")
    p.drawString(300, 100, "Two things to implement")

    p.drawString(50, 35, "Signed(Agent)")
    p.line(150,34,400,34)
    p.drawString(50, 15, "Signed(Supervisor)")
    p.line(150,14,400,14)

    p.drawString(450, 35, "Date:")
    p.line(480,34,550,34)
    p.drawString(450, 15, "Date")
    p.line(480,14,550,14)

    p.showPage()
    p.save()

    return response