0% found this document useful (0 votes)
20 views4 pages

Relatório Pedido de Compra Ajuste

The document appears to be an SQL query that selects and joins data from various tables to retrieve information for a sales document. Specifically, it selects data for document number 1 including details about items, customers, taxes, addresses and more. The query returns this aggregated data from tables related to documents, items, customers, taxes, addresses and users to provide a comprehensive view of the selected sales document.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Relatório Pedido de Compra Ajuste

The document appears to be an SQL query that selects and joins data from various tables to retrieve information for a sales document. Specifically, it selects data for document number 1 including details about items, customers, taxes, addresses and more. The query returns this aggregated data from tables related to documents, items, customers, taxes, addresses and users to provide a comprehensive view of the selected sales document.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

SELECT DISTINCT

T1."Rate",
T0."PayToCode",
T5."Address",
T0."DocNum",
T0."DocDate",
T0."DocDueDate",
T0."ObjType",
T0."DocEntry",
T0."DocTotal",
T0."TotalExpns",
T0."CardCode",
T0."CardName",
CASE WHEN IFNULL(T7."TaxId0",'') = '' THEN T7."TaxId4" ELSE T7."TaxId0" END AS
"TaxId0",
CASE WHEN IFNULL(T7."TaxId1",'') = '' THEN 'Isento' ELSE T7."TaxId1" END AS
"TaxId1",
T8."Fax",
T8."Phone1",
T8."Phone2",
T15."SlpName",
IFNULL(T0."ImportEnt",0) "PedidoCliente",
T0."Comments",
T17."U_NAME" "Comprador",
T17."E_Mail",
T18."BPLName",
IFNULL(T18."BPLId",1) AS "BPLId",
T18."AddrType",
T18."Street",
T18."StreetNo",
T18."Block",
T18."City",
T18."ZipCode",
T18."State",
T18."Country",
T18."TaxIdNum",
T18."TaxIdNum2",
T18."Building",
--T1."U_SPS_PTAX" ,
T7."AddrTypeB",
T7."StreetB",
T7."StreetNoB",
T7."BlockB",
T7."CityB",
T7."StateB",
T7."ZipCodeB",
T7."AddrTypeS",
T7."StreetS",
T7."StreetNoS",
T7."BlockS",
T7."CityS",
T7."StateS",
T7."ZipCodeS",
T1."Currency" ,
T1."LineNum",
T1."ItemCode" AS "ItemCode",
T1."Dscription" AS "Descrição do Item",
T9."SuppCatNum",
T1."Quantity",
T1."ShipDate",
T1."Price",
T1."LineTotal",
T12."CodeBars",
T9."BuyUnitMsr" AS "InvntryUom",
T14."CardCode" AS "CodTransp",
T14."CardName" AS "Transportadora",
T7."Incoterms",
T7."QoP",
T7."PackDesc",
T7."NetWeight",
T7."GrsWeight",
T144."AddrType" AS "AddrtypeT",
T144."Street" AS "StreetT",
T144."StreetNo" AS "StreetNoT",
T144."Block" AS "BlockT",
T144."City" AS "CItyT",
T144."State" AS "StateT",
T144."ZipCode" AS "ZipCodeT",
T16."TaxId0" AS "TaxId0T",
T16."TaxId1" AS "TaxId1T",
T14."Phone1" AS "Phone1T",
T14."Phone2" AS "Phone2T",
T0."TotalExpns" AS "Frete",
--Local de Entrega
"T0"."Address2",
T4."PymntGroup",
T1."Currency",
T1."DiscPrcnt",
T0."DiscSum",
IFNULL((SELECT "Price" FROM ITM1 WHERE "ItemCode" = T1."ItemCode" AND "PriceList" =
T8."ListNum"),0) "Preço Lista",
T1."TaxCode",
T13."NcmCode",
T1."CSTCode",
T1."CSTfPIS",
T1."CSTfCOFINS",
T1."CSTfIPI",
T1."CFOPCode",
T6."Usage",
IFNULL((SELECT SUM(X0."BaseSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 10 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"BaseICMS",
IFNULL((SELECT SUM(X0."BaseSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 16 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"BaseIPI",
IFNULL((SELECT SUM(X0."BaseSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 13 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"BaseICMS-ST",
IFNULL((SELECT SUM(X0."BaseSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 19 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"BasePis",
IFNULL((SELECT SUM(X0."BaseSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 21 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"BaseCofins",
IFNULL((SELECT AVG(X0."TaxRate") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 10 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"AliqICMS",
IFNULL((SELECT AVG(X0."TaxRate") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 16 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"AliqIPI",
IFNULL((SELECT AVG(X0."TaxRate") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 13 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"AliqICMS-ST",
IFNULL((SELECT AVG(X0."TaxRate") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 19 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0) +
IFNULL((SELECT AVG(X0."TaxRate") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 21 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"AliqPisCofins",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 10 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"ICMS",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 16 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"IPI",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 13 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"ICMS-ST",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 25 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"ICMS-Difal",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 26 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"ICMS-Difal-ST",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 27 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"FCP-ST",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 28 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"SimplesNac",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 19 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"Pis",
IFNULL((SELECT SUM(X0."TaxSum") FROM POR4 X0 WHERE X0."DocEntry" = T0."DocEntry"
AND X0."staType" = 21 AND X0."LineNum" = T1."LineNum" AND X0."ExpnsCode" = -1),0)
"Cofins"
FROM OPOR T0
INNER JOIN POR1 T1 ON T0."DocEntry" = T1."DocEntry"
LEFT JOIN OOCR T3 ON T1."OcrCode" = T3."OcrCode"
LEFT JOIN OCTG T4 ON T0."GroupNum" = T4."GroupNum"
LEFT JOIN CRD1 T5 ON T0."PayToCode"= T5."Address" AND T0."CardCode" = T5."CardCode"
--AND T5."AdresType" = 'B'
--LEFT JOIN CRD1 T55 ON T0."PayToCode" = T55."Address" AND T0."CardCode" =
T55."CardCode" --AND T55."AdresType" = 'S'
LEFT JOIN OUSG T6 ON T1."Usage" = T6."ID"
LEFT JOIN POR12 T7 ON T0."DocEntry" = T7."DocEntry"
INNER JOIN OCRD T8 ON T0."CardCode" = T8."CardCode"
INNER JOIN OITM T9 ON T1."ItemCode" = T9."ItemCode"
LEFT JOIN POR3 T10 ON T0."DocEntry" = T10."DocEntry"
LEFT JOIN OUSR T11 ON T0."UserSign" = T11."USERID"
INNER JOIN OITM T12 ON T1."ItemCode" = T12."ItemCode"
LEFT JOIN ONCM T13 ON T12."NCMCode" = T13."AbsEntry"
LEFT JOIN OCRD T14 ON T7."Carrier" = T14."CardCode"
LEFT JOIN CRD1 T144 ON T14."CardCode" = T144."CardCode" --AND T144."AdresType" =
'S'
LEFT JOIN OSLP T15 ON T0."SlpCode" = T15."SlpCode"
LEFT JOIN CRD7 T16 ON T14."CardCode" = T16."CardCode" --AND T16."Address" = 'S'
INNER JOIN OUSR T17 ON T0."UserSign" = T17."USERID"
LEFT JOIN OBPL T18 ON T0."BPLId" = T18."BPLId"

WHERE
T0."DocEntry" = '1'
AND
T1."TreeType" <> 'I'

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy