The document contains an SQL query that:
1) Summarizes sales data by calculating the gross value, returns value, and net value from sales transactions in specified date range and for selected document types and user.
2) Joins various tables to retrieve data on sales documents, partners, vendors, users, and document types.
3) Filters the data to include only active documents issued in the current month by the logged in user or users associated with their vendor.
The document contains an SQL query that:
1) Summarizes sales data by calculating the gross value, returns value, and net value from sales transactions in specified date range and for selected document types and user.
2) Joins various tables to retrieve data on sales documents, partners, vendors, users, and document types.
3) Filters the data to include only active documents issued in the current month by the logged in user or users associated with their vendor.
The document contains an SQL query that:
1) Summarizes sales data by calculating the gross value, returns value, and net value from sales transactions in specified date range and for selected document types and user.
2) Joins various tables to retrieve data on sales documents, partners, vendors, users, and document types.
3) Filters the data to include only active documents issued in the current month by the logged in user or users associated with their vendor.
0 ELSE CAB.VLRNOTA END) AS VALOR_BRUTO, SUM(CASE WHEN CAB.TIPMOV = 'D' THEN CAB.VLRNOTA * -1 ELSE 0 END) AS DEVOLUCAO, SUM(CASE WHEN CAB.TIPMOV = 'D' THEN CAB.VLRNOTA * -1 ELSE CAB.VLRNOTA END) AS VALOR_LIQUIDO FROM TGFCAB CAB INNER JOIN TGFPAR PAR ON CAB.CODPARC = PAR.CODPARC INNER JOIN TGFVEN VEN ON CAB.CODVEND = VEN.CODVEND INNER JOIN TGFPAR PAR ON CAB.CODPARC = PAR.CODPARC INNER JOIN TSIUSU USU ON USU.CODVEND = PAR.CODVEND INNER JOIN TGFTOP TOP ON TOP.CODTIPOPER = CAB.CODTIPOPER AND TOP.DHALTER = CAB.DHTIPOPER
WHERE CAB.TIPMOV IN ('V', 'D')
AND CAB.STATUSNOTA = 'L' AND CAB.PENDENTE = 'N' AND TRUNC(CAB.DTFATUR) BETWEEN TRUNC(SYSDATE, 'MM') AND LAST_DAY(TRUNC(SYSDATE)) AND (USU.CODUSU = STP_GET_CODUSULOGADO() OR CAB.CODVEND IN (SELECT GER.CODVEND FROM TGFVEN GER JOIN TSIUSU USU2 ON (USU2.CODVEND = GER.CODGER) WHERE USU2.CODUSU = STP_GET_CODUSULOGADO())) AND CAB.CODTIPOPER IN (3200, 26, 3300, 31, 701, 3301, 2200, 2201)