def costrecord_list(request): """ 描述:费用记录列表 作者:凯伦kevin 参数 : 无 返回 : 无 """ #当前操作对应的权限 EVENT_RIGHT = 1178 ##来源application #验证是否登录 try: Mine = request.session['mine_object'] ## 取当前用户登录的对象 未登录取值为空对对象 Mine.reload() except: Mine = MineManager() print request.GET.get('id', '') opera = Mine.auth(EVENT_RIGHT) #系统开发功能的操作,必须是超级管理员 if type(opera) == type(''): return HttpResponse(opera) try: querys = CostRecord.objects.filter(un_id=Mine.Unit.id).order_by('-addtime') except Exception,e: pass
def car_list(request): """ 描述:车辆信息列表 作者:凯伦kevin 参数 : 无 返回 : 无 """ #当前操作对应的权限 EVENT_RIGHT = 1122 ##来源application #验证是否登录 try: Mine = request.session['mine_object'] ## 取当前用户登录的对象 未登录取值为空对对象 Mine.reload() except: Mine = MineManager() opera = Mine.auth(EVENT_RIGHT) #系统开发功能的操作,必须是超级管理员 if type(opera) == type(''): return HttpResponse(opera) try: querys = Cars.objects.filter(un_id=Mine.Unit.id, status=200) except Exception,e: pass
def car_del(request): """ 描述:删除车辆信息 作者:凯伦kevin 参数 : 无 返回 : 无 """ #当前操作对应的权限 EVENT_RIGHT = 875 ##来源application #验证是否登录 try: Mine = request.session['mine_object'] ## 取当前用户登录的对象 未登录取值为空对对象 Mine.reload() except: Mine = MineManager() opera = Mine.auth(EVENT_RIGHT) #系统开发功能的操作,必须是超级管理员 if type(opera) == type(''): return HttpResponse(opera) if request.method == 'POST': try: ids = request.POST.getlist('id') Cars.objects.filter(id__in = ids,status = 200).update(status = 0) RePath = '<a href="%s">%s</a>' %('/office/cars/list/', u'返回列表') return render_to_response('xopera.html', {'RePath':RePath}) except: return HttpResponseRedirect('/message/dialog/error-0001') ids = request.GET['id'] cars = Cars.objects.filter(id__in=ids.split(','),status = 200) context={ 'cars': cars, 'request': request, } return render_to_response('cars_del.html', context)
def car_add(request): """ 描述:添加车辆信息 作者:凯伦kevin 参数 : 无 返回 : 无 """ #当前操作对应的权限 EVENT_RIGHT = 873 ##来源application #验证是否登录 try: Mine = request.session['mine_object'] ## 取当前用户登录的对象 未登录取值为空对对象 Mine.reload() except: Mine = MineManager() opera = Mine.auth(EVENT_RIGHT) #系统开发功能的操作,必须是超级管理员 if type(opera) == type(''): return HttpResponse(opera) units = Units.objects.all() if request.method == 'POST': car = request.POST['car'] brand = request.POST['brand'] site = request.POST['site'] time = request.POST['time'] person = request.POST['person'] un_id = request.POST['unit'] statu = request.POST['statu'] form = CarsForm(request.POST) if form.is_valid: try: #保存提交的文件 image = request.FILES.get('file', None) dir = 'm/pact/' newcar = form.save(commit=False) if image is not None: path = upload(image, dir) else: path = None newcar.car = car newcar.brand = brand newcar.site = site newcar.path = path newcar.time = time newcar.person = person newcar.un_id = un_id newcar.statu = statu newcar.adder = Mine.to_adder() #添加人(id)姓名 newcar.adderip = Mine.get_ipaddress(request) newcar.save() OPERA_ITEMS = [] OPERA_ITEMS.append('<a href="%s">%s</a>'%('/office/cars/add', u'继续添加')) RePath = '<a href="%s">%s</a>' %('/office/cars/list/', u'返回列表') return render_to_response('xopera.html', {'OPERA_ITEMS':OPERA_ITEMS, 'RePath':RePath}) except Exception, e: return HttpResponseRedirect('/message/dialog/error-0001') else: return HttpResponseRedirect('/message/dialog/error-0002')
def costrecord_edit(request): """ 描述:添加、修改费用记录 作者:凯伦kevin 参数 : 无 返回 : 无 """ #当前操作对应的权限 EVENT_RIGHT = 1128 ##来源application EVENT_TYPE_INSERT = True instance = None id = request.GET.get('id',None) if id is not None: #表示修改操作 instance = get_object_or_404(CostRecord, pk=id) EVENT_RIGHT = 1129 EVENT_TYPE_INSERT = False #验证是否登录 try: Mine = request.session['mine_object'] Mine.reload() except: Mine = MineManager() opera = Mine.auth(EVENT_RIGHT) if type(opera) == type(''): return HttpResponse(opera) ###权限验证结束### departs = Departs.objects.filter(status=200, Unit_id__in=Mine.get_unit(format='ID_LIST')).order_by('orders') cars = Cars.objects.filter(status=200, un_id=Mine.Unit.id) if request.method == 'POST': user = request.POST.get('user',None) stype = request.POST.get('stype',None) stime = request.POST.get('stime',None) car = request.POST.get('car',None) cost = request.POST.get('cost',None) remarks = request.POST.get('cost',None) depart = request.POST.get('depart',None) OPERA_ITEMS = [] if id: cr = CostRecord.objects.get(id=id) cr.user_id = user cr.depart_id = depart cr.stype = stype cr.stime = stime cr.car_id = car cr.cost = cost cr.remarks = remarks cr.un_id = Mine.Unit.id cr.adder = Mine.to_adder() #添加人(id)姓名 cr.adderip = Mine.get_ipaddress(request) cr.save() OPERA_ITEMS.append('<a href="%s">%s</a>'%('/office/cars/cedit?id=%s'%id, u'继续修改')) RePath = '<a href="%s">%s</a>' %('/office/cars/clist/', u'返回列表') return render_to_response('xopera.html', {'OPERA_ITEMS':OPERA_ITEMS, 'RePath':RePath}) form = CostRecordForm(request.POST, instance = instance) if form.is_valid: try: cr = form.save(commit=False) cr.user_id = user cr.depart_id = depart cr.stype = stype cr.stime = stime cr.car_id = car cr.cost = cost cr.remarks = remarks cr.un_id = Mine.Unit.id cr.adder = Mine.to_adder() #添加人(id)姓名 cr.adderip = Mine.get_ipaddress(request) cr.save() OPERA_ITEMS = [] OPERA_ITEMS.append('<a href="%s">%s</a>'%('/office/cars/cedit', u'继续添加')) RePath = '<a href="%s">%s</a>' %('/office/cars/clist/', u'返回列表') return render_to_response('xopera.html', {'OPERA_ITEMS':OPERA_ITEMS, 'RePath':RePath}) except Exception, e: return HttpResponseRedirect('/message/dialog/error-0001') else: return HttpResponseRedirect('/message/dialog/error-0002')
def userecord_edit(request): """ 描述:添加、修改车辆使用记录 作者:凯伦kevin 参数 : 无 返回 : 无 """ #当前操作对应的权限 EVENT_RIGHT = 1125 ##来源application EVENT_TYPE_INSERT = True instance = None id = request.GET.get('id',None) if id is not None: #表示修改操作 instance = get_object_or_404(UseRecord, pk=id) EVENT_RIGHT = 1126 EVENT_TYPE_INSERT = False #验证是否登录 try: Mine = request.session['mine_object'] Mine.reload() except: Mine = MineManager() opera = Mine.auth(EVENT_RIGHT) if type(opera) == type(''): return HttpResponse(opera) ###权限验证结束### departs = Departs.objects.filter(status=200, Unit_id__in=Mine.get_unit(format='ID_LIST')).order_by('orders') carid=UseRecord.objects.filter(ltime__isnull=True).values_list('car') cars = Cars.objects.filter(status=200, un_id=Mine.Unit.id).exclude(id__in=carid) if request.method == 'POST': depart = request.POST.get('depart',None) user = request.POST.get('user',None) car = request.POST.get('car',None) stime = request.POST.get('stime',None) ltime = request.POST.get('ltime',None) use = request.POST.get('use',None) mileage = request.POST.get('mileage',None) oilwear = request.POST.get('oilwear',None) remarks = request.POST.get('remarks',None) OPERA_ITEMS = [] if id: ur = UseRecord.objects.get(id=id) ur.ltime = ltime ur.mileage = mileage ur.oilwear = oilwear ur.remarks = remarks ur.un_id = Mine.Unit.id ur.adder = Mine.to_adder() #添加人(id)姓名 ur.adderip = Mine.get_ipaddress(request) ltime_timetuple=time.strptime(ur.ltime,'%Y-%m-%d %H:%M:%S') stime_time=time.strftime('%Y-%m-%d %H:%M:%S',ur.stime.timetuple()) stime_timetuple=time.strptime(stime_time,'%Y-%m-%d %H:%M:%S') if(time.mktime(ltime_timetuple)<time.mktime(stime_timetuple)): return HttpResponseRedirect('/message/dialog/error-0001') ur.save() OPERA_ITEMS.append('<a href="%s">%s</a>'%('/office/cars/uedit?id=%s'%id, u'继续修改')) RePath = '<a href="%s">%s</a>' %('/office/cars/ulist/', u'返回列表') return render_to_response('xopera.html', {'OPERA_ITEMS':OPERA_ITEMS, 'RePath':RePath}) form = UseRecordForm(request.POST, instance = instance) if form.is_valid: try: ur = form.save(commit=False) ur.depart_id = depart ur.user_id = user ur.car_id = car ur.stime = stime #ur.ltime = ltime ur.use = use #ur.mileage = mileage #ur.oilwear = oilwear ur.remarks = remarks ur.un_id = Mine.Unit.id ur.adder = Mine.to_adder() #添加人(id)姓名 ur.adderip = Mine.get_ipaddress(request) ur.save() OPERA_ITEMS = [] OPERA_ITEMS.append('<a href="%s">%s</a>'%('/office/cars/uedit', u'继续添加')) RePath = '<a href="%s">%s</a>' %('/office/cars/ulist/', u'返回列表') return render_to_response('xopera.html', {'OPERA_ITEMS':OPERA_ITEMS, 'RePath':RePath}) except Exception, e: return HttpResponseRedirect('/message/dialog/error-0001') else: return HttpResponseRedirect('/message/dialog/error-0002')
def wstat_ssyxyjtj(request, context): """ 描述:搜索营销业绩统计 作者:凯伦kevin 2014年1月21日 """ EVENT_RIGHT = 1456 try: Mine = request.session['mine_object'] Mine.reload() except: Mine = MineManager() opera = Mine.auth(EVENT_RIGHT) if type(opera) == type(''): return HttpResponse(opera) ''' 权限验证结束 ''' yy = int(request.GET.get('year', int(datetime.datetime.now().strftime('%Y')))) mm = int(request.GET.get('month', int(datetime.datetime.now().strftime('%m')))) q = (mm+2)/3 q = int(request.GET.get('quarter', q)) statype = int(request.GET.get('statype', 1)) year1 = str(yy-1) year2 = str(yy+1) if str(yy) == '2017': year2 = '2017' if str(mm) == '1': mm1 = 12 yy1 = int(yy) - 1 else: mm1 = int(mm) - 1 yy1 = int(yy) if str(mm) == '12': mm2 = 1 yy2 = int(yy) + 1 else: mm2 = int(mm) + 1 yy2 = int(yy) if str(q) == '1': q1 = 4 y1 = int(yy)-1 else: q1 = int(q)-1 y1 = int(yy) if str(q) == '4': q2 = 1 y2 = int(yy)+1 else: q2 = int(q)+1 y2 = int(yy) time = '' if statype == 1: time = "and mm = {1}".format(yy, mm) elif statype == 2: time = "and mm in ({1},{2},{3})".format(yy, q*3-2,q*3-1,q*3 ) unit = Mine.Unit.id unit_list ='2,5,7,8,9,10' province=u'辽宁' if Mine.Unit.id in [3,11,12,13,14]: unit_list = '3,11,12,13,14' province=u'吉林' elif Mine.Unit.id in [4,15,16,17,18,19,20,21,22,23,24]: unit_list = '4,15,16,17,18,19,20,21,22,23,24' province=u'河北' cursor = connections['default'].cursor() sql1 = u''' SELECT aaa.id,aaa.name,bbb.员工人数,bbb.单数任务,bbb.预存款完成,bbb.单数完成, round(DECODE(bbb.单数任务,0,NULL,bbb.单数完成*100/bbb.单数任务),2), ROUND(bbb.预存款完成/bbb.单数完成,2), round(DECODE(bbb.员工人数,0,NULL,bbb.单数完成/bbb.员工人数),2), round(DECODE(bbb.员工人数,0,NULL,bbb.预存款完成/bbb.员工人数),2) FROM units aaa LEFT JOIN (select unid,sum(tasknums) as 单数任务,sum(money_done) as 预存款完成,avg(pcount) as 员工人数,sum(num_done) as 单数完成 from sta_ssyxyjtj where yyyy = {0} {1} group by unid) bbb ON aaa.id=bbb.unid where id in ({2}) ORDER BY id '''.format(yy, time, unit_list) sql = u''' with sql1 as ({0}) (select * from sql1) union all (select 100,N'{1}省总计', sum(员工人数),sum(单数任务),sum(预存款完成),sum(单数完成), round(DECODE(sum(单数任务),0,NULL,sum(单数完成)*100/sum(单数任务)),2), ROUND(DECODE(sum(单数完成),0,NULL,SUM(预存款完成)/SUM(单数完成)),2), round(DECODE(sum(员工人数),0,NULL,sum(单数完成)/sum(员工人数)),2), round(DECODE(sum(员工人数),0,NULL,sum(预存款完成)/sum(员工人数)),2) from sql1 where id in ({2})) '''.format(sql1, province,unit_list) print sql cursor.execute(sql) row = cursor.fetchall() cursor.close() connection.close() querys = row context = { 'yy': str(yy), 'mm': str(mm), 'q': str(q), 'yy1': str(yy1), 'mm1': str(mm1), 'yy2': str(yy2), 'mm2': str(mm2), 'y1': str(y1), 'y2': str(y2), 'year1': str(year1), 'year2': str(year2), 'statype': str(statype), 'querys': querys, 'opera': opera, 'q1': str(q1), 'q2': str(q2) } return render_to_response('bi_sales_ssyxyjtj.html', context)
def wstat_wxrwwc(request, context): """ 描述:网销任务完成情况统计 作者:凯伦kevin 2014年1月20日 """ EVENT_RIGHT = 1453 try: Mine = request.session['mine_object'] Mine.reload() except: Mine = MineManager() opera = Mine.auth(EVENT_RIGHT) if type(opera) == type(''): return HttpResponse(opera) ''' 权限验证结束 ''' yy = int(request.GET.get('year', int(datetime.datetime.now().strftime('%Y')))) mm = int(request.GET.get('month', int(datetime.datetime.now().strftime('%m')))) # wd = calendar.weekday(yy, 1, 1) # if wd: # ww = int(datetime.datetime.now().strftime('%W'))+1 # else: # ww = int(datetime.datetime.now().strftime('%W')) # if ww > 52: # ww = 1 # q = range(1, 53) # # ww = request.GET.get('week', ww) # wd = calendar.weekday(int(yy), 1, 1) # start = datetime.datetime(int(yy), 1, 1)+datetime.timedelta(days=(int(ww)-2)*7+(7-wd)) # over = datetime.datetime(int(yy), 1, 1)+datetime.timedelta(days=(int(ww)-2)*7+(7-wd)+6) # start = start.strftime("%Y-%m-%d") # over = over.strftime("%Y-%m-%d") # statype = int(request.GET.get('statype', 1)) # if statype == 1: # a = 'M'+str.rjust(str(mm), 2, '0')+'CY'+str(yy) # else: # a = 'WK'+str.rjust(str(ww), 2, '0')+'CY'+str(yy) if str(mm) == '1': mm1 = 12 yy1 = int(yy) - 1 else: mm1 = int(mm) - 1 yy1 = int(yy) if str(mm) == '12': mm2 = 1 yy2 = int(yy) + 1 else: mm2 = int(mm) + 1 yy2 = int(yy) # if str(ww) == '1': # w1 = 52 # y1 = int(yy)-1 # else: # w1 = int(ww)-1 # y1 = int(yy) # if str(ww) == '52': # w2 = 1 # y2 = int(yy)+1 # else: # w2 = int(ww)+1 # y2 = int(yy) sql = u''' select t.UNIT,u.SHORT_DESCRIPTION,t.ZDC,t.PC_MONEY,t.YD_MONEY,t.TASKMONEY,t.WCXSE,t.YJWCL,t.RJXSE,t.PCAVG,t.YDAVG, u.LEVEL_NAME from WXRWWC_CUBE_VIEW t LEFT JOIN UNIT_STATISTICS_VIEW u on t.UNIT=u.dim_key WHERE t.TIME='M{0}CY{1}' AND u.LEVEL_NAME='UNIT' AND u.SYSTEM='{2}' ORDER BY u.HIER_ORDER DESC '''.format(str.rjust(str(mm), 2, '0'), yy,settings.SYSTEM_KEY) cursor = connections['bi'].cursor() cursor.execute(sql) querys = cursor.fetchall() cursor.close() connection.close() context = { 'yy': str(yy), 'mm': str(mm), 'yy1': str(yy1), 'mm1': str(mm1), 'yy2': str(yy2), 'mm2': str(mm2), 'querys': querys, 'opera': opera, } return render_to_response('bi_sales_wxrwwc.html', context)