ALTER PROCEDURE OP_ListarParteDiarioSimple    
(@SITEID         UD_IDSITE = '76  ',    
 @FECHAPROCESO   CHAR(8) = '20080505',    
 @MONEDABASE     UD_CURYID = 'PEN',    
 @MONEDAEXTR     UD_CURYID = 'USD',    
 @USERID         UD_USERID = 'SYSADMIN')    
as    
--Begin    
--USO GENERAL
DECLARE @TOT_TARJ_AJUSTE MONEY    
DECLARE @PAG_DIFERENCIA MONEY 
DECLARE @PAG_ADELANTADO MONEY   
DECLARE @TOT_FALTANTE MONEY    
DECLARE @TOT_SOBRANTE MONEY    
DECLARE @TOT_COBRANZA MONEY  
DECLARE @TELEFONO MONEY    --NO SE USA
DECLARE @OTROS MONEY--NO SE USA 

--VARIABLES PARA PLAYA
DECLARE @TOT_COMBUSTIBLE MONEY    
DECLARE @TOT_GLP MONEY    
DECLARE @TOT_LUBAD MONEY    
DECLARE @TOT_OTROS MONEY    
DECLARE @TOT_CRED_COMBUSTIBLE MONEY    
DECLARE @TOT_CRED_GLP MONEY    
DECLARE @TOT_CRED_LUBAD MONEY    
DECLARE @TOT_CRED_OTROS MONEY    
DECLARE @TOT_TARJ_COMBUSTIBLE MONEY    
DECLARE @TOT_TARJ_GLP MONEY    
DECLARE @TOT_TARJ_LUBAD MONEY    
DECLARE @TOT_TARJ_OTROS MONEY    
DECLARE @TOT_EFEC_COMBUSTIBLE MONEY    
DECLARE @TOT_EFEC_GLP MONEY    
DECLARE @TOT_EFEC_LUBAD MONEY    
DECLARE @TOT_EFEC_OTROS MONEY    
DECLARE @GAS MONEY    
DECLARE @DEPOSITOS_PLAYA MONEY    
DECLARE @AFERICION MONEY    
DECLARE @PROMOCIONES MONEY

--VARIABLES PARA TIENDA
DECLARE @SERVICIOS MONEY    	--CREDITO TIENDA
DECLARE @MOBIL MONEY  --EFECTIVIO TIENDA  
DECLARE @TARJETA_TIENDA MONEY
DECLARE @CREDITO_TIENDA MONEY
DECLARE @DEPOSITOS_TIENDA MONEY  



----------CONTOMETROS-----------------------    
SELECT @TOT_COMBUSTIBLE =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD  (NOLOCK) ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
--INNER JOIN OP_SETUP  SETP ON (S.DATEPROCESALES = SETP.DATEPROCESALES)    
INNER JOIN OP_SALESPOINTSETTING SPS  (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.INVTIDSKU IN ('1001','1002','1003','1004','1005') --FILTRO DE ARTICULOS    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
--AND S.USERID = 'VENDPLAYA'    
-------------------------------------------------SELECT * FROM OP_SALES WHERE USERID <> 'VENDPLAYA'    
----------GLP-----------------------    
SELECT @TOT_GLP =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I (NOLOCK)  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C (NOLOCK)  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.INVTIDSKU IN ('1006','06') --FILTRO DE ARTICULOS    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
--AND S.USERID = 'VENDPLAYA'    
-------------------------------------------------    
----------LUBRICANTES/ADITIVOS-----------------------    
SELECT @TOT_LUBAD =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID IN ('02','04') --FILTRO DE = LUBRICANTES + ADITIVOS    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA     
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------OTROS-----------------------    
SELECT @TOT_OTROS =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I (NOLOCK)  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C (NOLOCK)  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID NOT IN ('02','04','19','1006','05','20') --FILTRO DE OTROS = NO : LUBRICANTES, ADITIVOS, COMPUSTILE, GAS LICUADO    ,GAS DOMESTICO
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------GAS DOMESTICO-----------------------    
-------------------------------------------------    
SELECT @GAS =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I (NOLOCK)  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C (NOLOCK)  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID  IN ('05') --FILTRO DE OTROS = NO : LUBRICANTES, ADITIVOS, COMPUSTILE, GAS LICUADO    ,GAS DOMESTICO
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------PROMOCIONES-----------------------    
-------------------------------------------------    
SELECT @PROMOCIONES =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I (NOLOCK)  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C (NOLOCK)  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID  IN ('20') --FILTRO DE OTROS = NO : LUBRICANTES, ADITIVOS, COMPUSTILE, GAS LICUADO    ,GAS DOMESTICO
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'

-------------------------------------------------    
--*************************************************

-------------------------------------------------    
--*************************************************    
----------CREDITO COMBUSTIBLE-----------------------    
SELECT @TOT_CRED_COMBUSTIBLE =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C (NOLOCK)  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
--INNER JOIN OP_SETUP  SETP ON (S.DATEPROCESALES = SETP.DATEPROCESALES)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.INVTIDSKU IN ('1001','1002','1003','1004','1005') --FILTRO DE ARTICULOS    
AND S.TYPEPAYMENTID = '06' --FILTRO DE FORMA DE PAGO (CREDITO)    
--AND SPS.BUSINESSTYPE in (1,3) -- SOLO LOS TIPO DE NEGOCIO PLAYA  - se le agrego pa' q considere las manuales de OFICINA 3    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------CREDITO GLP-----------------------    
SELECT @TOT_CRED_GLP =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD  (NOLOCK) ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I (NOLOCK)  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.INVTIDSKU IN ('1006','06')--FILTRO DE ARTICULOS    --,'06'
AND S.TYPEPAYMENTID = '06' --FILTRO DE FORMA DE PAGO (CREDITO)    
--AND SPS.BUSINESSTYPE in (1,3) -- SOLO LOS TIPO DE NEGOCIO PLAYA  - se le agrego pa' q considere las manuales de OFICINA 3    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------CREDITO LUBRICANTES/ADITIVOS-----------------------    
SELECT @TOT_CRED_LUBAD =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID IN ('02','04') --FILTRO DE = LUBRICANTES + ADITIVOS    
AND S.TYPEPAYMENTID = '06' --FILTRO DE FORMA DE PAGO (CREDITO)    
--AND SPS.BUSINESSTYPE in (1,3) -- SOLO LOS TIPO DE NEGOCIO PLAYA  - se le agrego pa' q considere las manuales de OFICINA 3    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------CREDITO OTROS-----------------------    
SELECT @TOT_CRED_OTROS =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD  (NOLOCK) ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID NOT IN ('02','04','19','1006') --FILTRO DE OTROS = NO : LUBRICANTES, ADITIVOS, COMPUSTILE, GAS LICUADO    
AND S.TYPEPAYMENTID = '06' --FILTRO DE FORMA DE PAGO (CREDITO)    
--AND SPS.BUSINESSTYPE in (1) -- SOLO LOS TIPO DE NEGOCIO PLAYA  - se le agrego pa' q considere las manuales de OFICINA 3    
--AND SPS.BUSINESSTYPE in (3) -- SOLO OFICINA
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
 OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
--*************************************************    

----------CREDITO MARKET-----------------------    
SELECT @CREDITO_TIENDA =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD  (NOLOCK) ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
--INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
--INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
--INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
--LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND S.TYPEPAYMENTID = '06' --FILTRO DE FORMA DE PAGO (CREDITO)    
AND SPS.BUSINESSTYPE = '3'
AND (S.BUSINESSTYPE <> '1' OR S.SALESPERID = 'MANUELA')
AND S.DOCSTATUSID <> 'AN'
-------------------------------------------------    
--*************************************************   

----------TARJETA CREDITO COMBUSTIBLE-----------------------    
SELECT @TOT_TARJ_COMBUSTIBLE =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C (NOLOCK)  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
--INNER JOIN OP_SETUP  SETP ON (S.DATEPROCESALES = SETP.DATEPROCESALES)    
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.INVTIDSKU IN ('1001','1002','1003','1004','1005') --FILTRO DE ARTICULOS    
AND S.TYPEPAYMENTID = '02' --FILTRO DE FORMA DE PAGO (TARJETA CREDITO)    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    

----------TARJETA CREDITO GLP-----------------------    
SELECT @TOT_TARJ_GLP =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.INVTIDSKU IN ('1006','06') --FILTRO DE ARTICULOS    
AND S.TYPEPAYMENTID = '02' --FILTRO DE FORMA DE PAGO (TARJETA CREDITO)    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    

----------TARJETA CREDITO LUBRICANTES/ADITIVOS-----------------------    
SELECT @TOT_TARJ_LUBAD =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD  (NOLOCK) ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID IN ('02','04') --FILTRO DE = LUBRICANTES + ADITIVOS    
AND S.TYPEPAYMENTID = '02' --FILTRO DE FORMA DE PAGO (TARJETA CREDITO)    
--AND SPS.BUSINESSTYPE = 3 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
--AND SPS.BUSINESSTYPE = 1
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------TARJETA CREDITO OTROS-----------------------    
SELECT @TOT_TARJ_OTROS =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID NOT IN ('02','04','19','1006') --FILTRO DE OTROS = NO : LUBRICANTES, ADITIVOS, COMPUSTILE, GAS LICUADO    
AND S.TYPEPAYMENTID = '02' --FILTRO DE FORMA DE PAGO (TARJETA CREDITO)    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
--AND SPS.BUSINESSTYPE = 3 --TIPO OFICINA
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
----------TARJETA MARKET-----------------------    
SELECT @TARJETA_TIENDA =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    (NOLOCK) 
INNER JOIN OP_SALESDET  SD  (NOLOCK) ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND S.TYPEPAYMENTID = '02' --FILTRO DE FORMA DE PAGO (TARJETA)    
AND SPS.BUSINESSTYPE = '3'
AND S.BUSINESSTYPE <> '1'
AND S.DOCSTATUSID <> 'AN'
-------------------------------------------------    
--*************************************************
-------------------------------------------------    
-----------AHI QUE AGREGAR UN CONCEPTO POR TARJETA DE CREDITO. AJUSTES MANUALES----    
--SELECT SUM(TOTALPENSALES) FROM OP_CARD_MONTSALES    
--SOLO TOMA VALOR EN SOLES    
SELECT @TOT_TARJ_AJUSTE = SUM(ISNULL(TOTALPENSALES,0)) FROM OP_CARD_MONTSALES (NOLOCK)    
WHERE DATEPROCE =@FECHAPROCESO AND SITEID = @SITEID
--WHERE DATEPROCE = (RIGHT('20080601',2) + '/' + RIGHT(LEFT('20080601',6),2) + '/' + LEFT('20080601',4))    
    
--SET @TOT_TARJ_AJUSTE = ISNULL(@TOT_TARJ_AJUSTE,0) - ISNULL(@TOT_TARJ_OTROS,0) - ISNULL(@TOT_TARJ_LUBAD,0) - ISNULL(@TOT_TARJ_GLP,0) - ISNULL(@TOT_TARJ_COMBUSTIBLE,0)    
--PRINT RIGHT(LEFT('20080601',6),2)    
--PRINT RIGHT('20080601',2) + '/' + RIGHT(LEFT('20080601',6),2) + '/' + LEFT('20080601',4)    
--*************************************************     


----------EFECTIVO COMBUSTIBLE-----------------------    
SELECT @TOT_EFEC_COMBUSTIBLE =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S   (NOLOCK)  
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I (NOLOCK)  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
--INNER JOIN OP_SETUP  SETP ON (S.DATEPROCESALES = SETP.DATEPROCESALES)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND S.TYPEPAYMENTID = '01' --FILTRO DE FORMA DE PAGO (EFECTIVO)    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------EFECTIVO GLP-----------------------    
SELECT @TOT_EFEC_GLP =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD (NOLOCK)  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I (NOLOCK)  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C (NOLOCK)  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP (NOLOCK)  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.INVTIDSKU IN ('1006','06') --FILTRO DE ARTICULOS    
AND S.TYPEPAYMENTID = '01' --FILTRO DE FORMA DE PAGO (EFECTIVO)    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------    
----------EFECTIVO LUBRICANTES/ADITIVOS-----------------------    
SELECT @TOT_EFEC_LUBAD =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S     (NOLOCK)
INNER JOIN OP_SALESDET  SD  (NOLOCK) ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  (NOLOCK) ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  (NOLOCK) ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  (NOLOCK) ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC (NOLOCK) ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID IN ('02','04') --FILTRO DE = LUBRICANTES + ADITIVOS    
AND S.TYPEPAYMENTID = '01' --FILTRO DE FORMA DE PAGO (EFECTIVO)    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------   
/* 
----------EFECTIVO OTROS-----------------------    
SELECT @TOT_EFEC_OTROS =    
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END    
FROM OP_SALES   S    
INNER JOIN OP_SALESDET  SD  ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)    
INNER JOIN IN_INVENTORY I  ON (SD.INVTIDSKU = I.INVTIDSKU)     
INNER JOIN IN_CATEGORY  C  ON (I.CLASSID = C.CLASSID)    
INNER JOIN OP_SALESPERSON SP  ON (S.SALESPERID = SP.SALESPERID)     
INNER JOIN OP_SALESPOINTSETTING SPS ON (S.SALESPOINT = SPS.SALESPOINT)    
LEFT JOIN OP_SALESCARD  SC ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)    
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
AND I.CLASSID NOT IN ('02','04','19','1006') --FILTRO DE OTROS = NO : LUBRICANTES, ADITIVOS, COMPUSTILE, GAS LICUADO    
AND S.TYPEPAYMENTID = '01' --FILTRO DE FORMA DE PAGO (EFECTIVO)    
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
AND SPS.BUSINESSTYPE = 3 --OFICINA */
----------EFECTIVO OTROS-----------------------

SELECT @TOT_EFEC_OTROS =
CASE @MONEDABASE WHEN 'PEN' THEN SUM(SD.TOTALPEN) ELSE SUM(SD.TOTALUSD) END
FROM OP_SALES 		S (NOLOCK)
INNER JOIN OP_SALESDET 	SD  (NOLOCK)	ON (S.DOCTYPEID = SD.DOCTYPEID AND S.NBRDOCUMENT = SD.NBRDOCUMENT AND S.SITEID = SD.SITEID)
INNER JOIN IN_INVENTORY I  (NOLOCK)	ON (SD.INVTIDSKU = I.INVTIDSKU) 
INNER JOIN IN_CATEGORY  C  (NOLOCK)	ON (I.CLASSID = C.CLASSID)
INNER JOIN OP_SALESPERSON SP  (NOLOCK)	ON (S.SALESPERID = SP.SALESPERID) 
INNER JOIN OP_SALESPOINTSETTING SPS (NOLOCK) ON (S.SALESPOINT = SPS.SALESPOINT)
LEFT JOIN OP_SALESCARD 	SC (NOLOCK)	ON (S.NBRDOCUMENT = SC.NBRDOCUMENT AND S.SITEID = SC.SITEID AND S.DOCTYPEID = SC.DOCTYPEID)
WHERE S.SITEID = @SITEID AND S.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO
AND I.CLASSID NOT IN ('02','04','19','1006') --FILTRO DE OTROS = NO : LUBRICANTES, ADITIVOS, COMPUSTILE, GAS LICUADO
AND S.TYPEPAYMENTID = '01' --FILTRO DE FORMA DE PAGO (EFECTIVO)
--AND SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA
AND (SPS.BUSINESSTYPE = 1 -- SOLO LOS TIPO DE NEGOCIO PLAYA    
OR S.BUSINESSTYPE = '1') --O HAYA SIDO INGRESADO MANUALMENTE
AND S.DOCSTATUSID <> 'AN'
AND S.SALESPERID <> 'MANUELA'
-------------------------------------------------
-------------------------------------------------    
--*************************************************    
--COBRANZAS
SELECT  @TOT_COBRANZA = SUM(CD.PAIDMENTPEN )
--D.MINDES,A.NBRDOCUMENT,C.CUSTNAME,CD.DATEPROCEPAIDMENT AS DOCDATE,A.DUEDATE,A.TOTALPEN AS TOTAL,CD.PAIDMENTPEN AS PAGADO,A.DOCVALPEN AS SALDO,CASE A.DOCSTATUSID WHEN 'CA' THEN '  CA' ELSE '  PE' END AS DOCSTATUSID 
FROM AR_CCDOC A  (NOLOCK)
LEFT JOIN AR_CCDOCDET CD (NOLOCK) ON (A.SITEID = CD.SITEID AND A.DOCTYPEID = CD.DOCTYPEID AND A.NBRDOCUMENT = CD.NBRDOCUMENT) 
--INNER JOIN DOCTYPE D ON (A.DOCTYPEID=D.DOCTYPEID) 
--INNER JOIN CUSTOMER C ON (C.CUSTIDSS = A.CUSTIDSS) 
WHERE A.DOCSTATUSID NOT IN ('AN') 
AND A.DOCTYPEID = '01' AND LEFT(A.NBRDOCUMENT,2) <> '17' 
AND CD.DATEPROCEPAIDMENT = @FECHAPROCESO
AND A.SITEID = @SITEID
--And CONVERT(DATETIME,LEFT(CD.DATEPROCEPAIDMENT,11),3) BETWEEN '20090325' AND '20090325'
-------------------------------------------------    
--*************************************************  
-------------------------------------------------    
--*************************************************  
--JALANDO TARJETA MANUALES
/*
SELECT @TARJETA_MANUAL_PLAYA = SUM (ISNULL(TOTALCARD,0))
FROM OP_CARD_MONT (NOLOCK)
WHERE DATEPROCE =  @FECHAPROCESO AND BUSINESSTYPE = '1'

SELECT @TARJETA_MANUAL_TIENDA = SUM (ISNULL(TOTALCARD,0))
FROM OP_CARD_MONT (NOLOCK)
WHERE DATEPROCE =  @FECHAPROCESO AND BUSINESSTYPE = '3'
*/
--*************************************************  
-------------------------------------------------    
------------@MOBIL/MARKET/TIENDA----------
SELECT @MOBIL = SUM(D.TOTALPEN)
FROM OP_SALESDET D (NOLOCK)
INNER JOIN OP_SALES C (NOLOCK) ON D.NBRDOCUMENT = C.NBRDOCUMENT AND D.DOCTYPEID = C.DOCTYPEID AND D.SITEID = C.SITEID
INNER JOIN OP_SALESPOINTSETTING P (NOLOCK) ON C.SALESPOINT = P.SALESPOINT 
WHERE C.SITEID = @SITEID AND C.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO
AND C.DOCSTATUSID <> 'AN'
AND P.BUSINESSTYPE = '3'
AND C.BUSINESSTYPE <> '1'
AND C.TYPEPAYMENTID IN ('01','02') --SOLO EFECTIVO Y TARJETA DE CREDITO
AND C.DOCSTATUSID <> 'AN' --Q NO ESTEN ANULADAS
AND C.SITEID = @SITEID
--*************************************************  
-----------------------------@SERVICIOS /CREDITO TIENDA--------------------  
SELECT @SERVICIOS = SUM(D.TOTALPEN)
FROM OP_SALESDET D (NOLOCK)
INNER JOIN OP_SALES C (NOLOCK) ON D.NBRDOCUMENT = C.NBRDOCUMENT AND D.DOCTYPEID = C.DOCTYPEID AND D.SITEID = C.SITEID
INNER JOIN OP_SALESPOINTSETTING P (NOLOCK) ON C.SALESPOINT = P.SALESPOINT 
WHERE C.SITEID = @SITEID AND C.DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO
AND C.DOCSTATUSID <> 'AN'
AND P.BUSINESSTYPE = '3'
AND (C.BUSINESSTYPE <> '1' OR C.SALESPERID = 'MANUELA')
AND C.TYPEPAYMENTID = '06' --SOLO EFECTIVO Y TARJETA DE CREDITO
AND C.DOCSTATUSID <> 'AN' --Q NO ESTEN ANULADAS
AND C.SITEID = @SITEID
------------------------------------------------------

--CONCEPTOS MANUALES    
SELECT     
--@SERVICIOS = SERVICIOS,    
--@GAS = GAS,    
--@MOBIL = MOBIL,    
@TELEFONO = TELEFONO,    
@OTROS = OTROS,    
@PAG_DIFERENCIA = PAG_DIFERENCIA,    
@PAG_ADELANTADO = PAG_ADELANTADO,    
@AFERICION = AFERICION--,    
--@TOT_COBRANZA = COBRANZAS--,    
--@DEPOSITO_TIENDA = DEPOSITO_TIENDA --POR MIENTRAS--**********************************************************<<--------------------------    
FROM OP_PD_MANUAL (NOLOCK)--SELECT * FROM OP_PD_MANUAL    
WHERE SITEID = @SITEID AND DATEPROCESALES = @FECHAPROCESO--FECHA DE PROCESO    
    
--DEPOSITO PLAYA    
SELECT @DEPOSITOS_PLAYA =CASE @MONEDABASE WHEN 'PEN' THEN SUM(D.TOTALPEN) ELSE SUM(D.TOTALUSD) END    
FROM OP_DEPOSITSITEDET D (NOLOCK)
INNER JOIN OP_DEPOSITSITE C (NOLOCK) ON D.BATNBRDEPOSITSITE = C.BATNBRDEPOSITSITE AND D.SITEID = C.SITEID
WHERE D.SITEID=@SITEID AND D.DATEPROCE=@FECHAPROCESO  AND C.BUSINESSTYPE = 1   

--DEPOSITOS_TIENDA
SELECT @DEPOSITOS_TIENDA = CASE @MONEDABASE WHEN 'PEN' THEN SUM(D.TOTALPEN) ELSE SUM(D.TOTALUSD) END    
FROM OP_DEPOSITSITEDET D (NOLOCK)
INNER JOIN OP_DEPOSITSITE C (NOLOCK)  ON D.BATNBRDEPOSITSITE = C.BATNBRDEPOSITSITE AND D.SITEID = C.SITEID
WHERE D.SITEID=@SITEID AND D.DATEPROCE=@FECHAPROCESO  AND C.BUSINESSTYPE = 3


--SOBRANTE/FALTANTE    
SELECT @TOT_FALTANTE=
	CASE @MONEDABASE WHEN 'PEN' 
		THEN SUM(CASE CCSALESPERSONTYPEID WHEN 'F' THEN TOTALPEN ELSE 0 END)     
		ELSE SUM(CASE CCSALESPERSONTYPEID WHEN 'F' THEN TOTALUSD ELSE 0 END) END,    
       @TOT_SOBRANTE=
	CASE @MONEDABASE WHEN 'PEN' 
		THEN SUM(CASE CCSALESPERSONTYPEID WHEN 'S' THEN TOTALPEN ELSE 0 END)    
		ELSE SUM(CASE CCSALESPERSONTYPEID WHEN 'S' THEN TOTALPEN ELSE 0 END) END    
       FROM OP_CCSALESPERSONDET (NOLOCK)    
       WHERE SITEID=@SITEID AND DATEPROCE=@FECHAPROCESO     
--COBRANZAS    
--antes estaba bloqueada  
/*  
SELECT @TOT_COBRANZA=CASE @MONEDABASE WHEN 'PEN' THEN SUM(A.PAIDMENTPEN) ELSE SUM(A.PAIDMENTUSD) END    
 FROM AR_CCDOC A      
 LEFT JOIN AR_CCDOCDET CD (NOLOCK) ON (A.SITEID = CD.SITEID AND A.DOCTYPEID = CD.DOCTYPEID AND A.NBRDOCUMENT = CD.NBRDOCUMENT)     
 INNER JOIN DOCTYPE D (NOLOCK) ON (A.DOCTYPEID=D.DOCTYPEID)     
 INNER JOIN CUSTOMER C (NOLOCK) ON (C.CUSTIDSS = A.CUSTIDSS)     
 WHERE A.DOCSTATUSID NOT IN ('AN')     
 AND A.DOCTYPEID = '01' AND LEFT(A.NBRDOCUMENT,2) <> '17'     
 AND A.SITEID = @SITEID AND --A.DATEPROCESALES=@FECHAPROCESO     
 CD.DATEPROCEPAIDMENT=@FECHAPROCESO    
   */ 
    
SELECT ISNULL(@TOT_COMBUSTIBLE,0) AS TOT_COMBUSTIBLE,    
ISNULL(@TOT_GLP,0) AS TOT_GLP,    
ISNULL(@TOT_LUBAD,0) AS TOT_LUBAD,    
ISNULL(@TOT_OTROS,0) AS TOT_OTROS,    
ISNULL(@TOT_CRED_COMBUSTIBLE,0) AS TOT_CRED_COMBUSTIBLE,    
ISNULL(@TOT_CRED_GLP,0) AS TOT_CRED_GLP,    
ISNULL(@TOT_CRED_LUBAD,0) AS TOT_CRED_LUBAD,    
ISNULL(@TOT_CRED_OTROS,0) AS TOT_CRED_OTROS,    
ISNULL(@TOT_TARJ_COMBUSTIBLE,0) AS TOT_TARJ_COMBUSTIBLE,    
ISNULL(@TOT_TARJ_GLP,0) AS TOT_TARJ_GLP,    
ISNULL(@TOT_TARJ_LUBAD,0) AS TOT_TARJ_LUBAD,    
ISNULL(@TOT_TARJ_OTROS,0) AS TOT_TARJ_OTROS,    
ISNULL(@TOT_TARJ_AJUSTE,0) AS TOT_TARJ_AJUSTE,    
ISNULL(@TOT_EFEC_COMBUSTIBLE,0) AS TOT_EFEC_COMBUSTIBLE,    
ISNULL(@TOT_EFEC_GLP,0) AS TOT_EFEC_GLP,    
ISNULL(@TOT_EFEC_LUBAD,0) AS TOT_EFEC_LUBAD,    
ISNULL(@TOT_EFEC_OTROS,0) AS TOT_EFEC_OTROS,    
ISNULL(@SERVICIOS,0) AS SERVICIOS,    
ISNULL(@GAS,0) AS GAS,    
ISNULL(@MOBIL,0) AS MOBIL,    
ISNULL(@TELEFONO,0) AS TELEFONO,    
ISNULL(@OTROS,0) AS OTROS,    
ISNULL(@PAG_DIFERENCIA,0) AS PAG_DIFERENCIA,    
ISNULL(@PAG_ADELANTADO,0) AS PAG_ADELANTADO,    
ISNULL(@TOT_FALTANTE,0) AS TOT_FALTANTE,    
ISNULL(@TOT_SOBRANTE,0) AS TOT_SOBRANTE,    
ISNULL(@TOT_COBRANZA,0) AS TOT_COBRANZA,    
ISNULL(@DEPOSITOS_PLAYA,0) AS DEPOSITOS,    
ISNULL(@DEPOSITOS_TIENDA,0) AS DEPOSITO_TIENDA,
ISNULL(@AFERICION,0) AS AFERICION,    
ISNULL(@TOT_COBRANZA,0)  AS TOT_COBRANZA,
ISNULL(@PROMOCIONES,0) AS PROMOCIONES,
ISNULL(@CREDITO_TIENDA,0) AS CREDITO_TIENDA,
ISNULL(@TARJETA_TIENDA,0) AS TARJETA_TIENDA
--ISNULL(@TARJETA_MANUAL_PLAYA,0) AS TARJETA_MANUAL_PLAYA,
--ISNULL(@TARJETA_MANUAL_TIENDA,0) AS TARJETA_MANUAL_TIENDA
    
    
    
    
    
    
    
  
