def obtener_zonas(self): query_manzanas = """ SELECT * FROM sde.TB_ZONA WHERE UBIGEO = '{ubigeo}' """.format(ubigeo=self.distrito['UBIGEO']) self.zonas = to_dict(self.cursor.execute(query_manzanas))
def obtener_operacion(self,cod_oper='01'): query_operacion = """ begin select * from [SDE].[TB_OPERACION] where isnull(COD_OPER,'01')='{cod_oper}' end """.format(cod_oper=cod_oper) operacion = to_dict(self.cursor.execute(query_operacion)) return operacion[0]
def obtener_manzanas(self, zona): query_manzanas = """ select b.UBIGEO,b.ZONA , b.MANZANA, b.IDMANZANA,b.COD_OPER ,b.MARCO_FIN CANT_EST ,b.MARCO_FIN + b.PUESTO TOTAL_EST, b.MERCADO MERCADO, b.PUESTO PUESTO ,b.FALSO_COD FALSO_COD from sde.TB_OPER_MANZANA b where b.UBIGEO = '{ubigeo}' and b.ZONA = '{zona}' and b.COD_OPER = '{cod_oper}' ORDER BY b.UBIGEO,b.ZONA,b.FALSO_COD """.format(ubigeo=zona['UBIGEO'], zona=zona['ZONA'], cod_oper=self.cod_oper) self.manzanas = to_dict(self.cursor.execute(query_manzanas))
def obtener_emp_ruta_periodo(self, cod_oper, codsede='07'): query = """ SELECT A.*,B.SEDE_OPERATIVA FROM sde.SEGM_RUTA_EMP_PERIODO A INNER JOIN sde.TB_SEDE_OPERATIVA B ON A.CODSEDE=B.CODSEDE where A.COD_OPER='{cod_oper}' and A.CODSEDE = '{codsede}' --AND ISNULL(A.PROC_CROQUIS,0)=0 order by COD_OPER,CODSEDE,BRIGADA,RUTA,EMPADRONADOR DESC """.format(cod_oper=cod_oper, codsede=codsede) empadronadores = to_dict(self.cursor.execute(query)) return empadronadores
def obtener_programacion_brigada_sede(self, sede): query = """ begin SELECT b.SEDE_OPERATIVA,b.DEPARTAMENTO,b.PROVINCIA,b.DISTRITO,SUBSTRING(CODCCPP,7,5)CODCCPP,b.NOMCCPP,a.*, 0 ADICIONAL FROM SDE.SEGM_PROGRAMACION_BRIGADAS A INNER JOIN TB_ZONA B ON A.UBIGEO+ A.ZONA = B.UBIGEO+B.ZONA where a.codsede='{codsede}' and a.cod_oper='{cod_oper}' order by a.brigada,a.ruta,a.periodo,a.orden end """.format(codsede=sede["CODSEDE"], cod_oper=sede["COD_OPER"]) programacion = to_dict(self.cursor.execute(query)) return programacion
def obtener_rutas_manzanas_por_brigada(self, brigada): query_rutas_manzanas_por_brigada = """ begin SELECT B.*, (B.MARCO_FIN + B.PUESTO) CANT_EST ,isnull(A.ORDEN,0)ORDEN FROM dbo.SEGM_U_RUTA_MANZANA B left join [sde].[SEGM_PROGRAMACION_RUTAS] A ON A.PK_AEU = B.Z_AE and A.COD_OPER = B.COD_OPER where B.CODSEDE = '{codsede}' AND B.BRIGADA ='{brigada}' AND B.COD_OPER = '{cod_oper}' ORDER BY B.BRIGADA,B.RUTA,B.PERIODO,A.ORDEN,B.UBIGEO,B.ZONA,B.FALSO_COD end """.format(codsede=brigada["CODSEDE"], brigada=brigada["BRIGADA"], cod_oper=brigada["COD_OPER"]) #print 'query_rutas_manzanas_por_brigada>>>', query_rutas_manzanas_por_brigada rutas_manzanas = to_dict(self.cursor.execute(query_rutas_manzanas_por_brigada)) return rutas_manzanas
def obtener_programacion_ruta_sede(self, sede): query_p = '' for count, p in enumerate(self.periodos): if count > 0: query_p = '{},{}'.format(query_p, p) else: query_p = '{}'.format(p) query = """ begin SELECT b.SEDE_OPERATIVA,b.DEPARTAMENTO,b.PROVINCIA,b.DISTRITO,SUBSTRING(CODCCPP,7,5)CODCCPP,b.NOMCCPP,a.*, 0 ADICIONAL FROM SDE.SEGM_PROGRAMACION_RUTAS A INNER JOIN TB_ZONA B ON A.UBIGEO+ A.ZONA = B.UBIGEO+B.ZONA where A.codsede='{codsede}' and A.cod_oper='{cod_oper}' and A.periodo in ({periodos}) order by a.brigada,a.ruta,a.periodo,a.orden end """.format(codsede=sede["CODSEDE"], cod_oper=sede["COD_OPER"], periodos=query_p) programacion = to_dict(self.cursor.execute(query)) print 'query>>>', query return programacion
def obtener_programacion_ruta(self, ruta): query_p = '' for count, p in enumerate(self.periodos): if count > 0: query_p = '{},{}'.format(query_p, p) else: query_p = '{}'.format(p) query = """ begin SELECT b.DEPARTAMENTO,b.PROVINCIA,b.DISTRITO,SUBSTRING(CODCCPP,7,5)CODCCPP,b.NOMCCPP,a.* FROM SDE.SEGM_PROGRAMACION_RUTAS A INNER JOIN TB_ZONA B ON A.UBIGEO + A.ZONA = B.UBIGEO+B.ZONA where A.codsede='{codsede}' and A.ruta ={ruta} and A.cod_oper='{cod_oper}' and a.periodo in ({periodos}) order by a.periodo,a.orden end """.format(codsede=ruta["CODSEDE"], ruta=int(ruta["RUTA"]), cod_oper=ruta["COD_OPER"], periodos=query_p) empadronadores = to_dict(self.cursor.execute(query)) return empadronadores