SELECT SOPLines.sopnumbe,
SOPLines.itemnmbr,
SOPLines.itemdesc,
SOPLines.itmtshid,
SOPLines.xtndprce,
SOPLines.taxamnt,
SOPLines.docdate,
SOPLines.custnmbr,
SOPLines.custname,
SOPLines.posted,
tx00201.txdtlpct,
SOPLines.calctaxpc,
SOPLines.calctaxpc - tx00201.txdtlpct AS TaxDiff,
SOPLines.docid,
SOPLines.soptype,
SOPLines.cstponbr,
SOPLines.orignumb,
SOPLines.prbtadcd AS BillToAddress,
SOPLines.prstadcd AS ShipToAddress,
SOPLines.taxschid AS AddressTaxSchedule
FROM (SELECT sop10200.sopnumbe,
sop10200.itemnmbr,
sop10200.itemdesc,
sop10200.itmtshid,
sop10200.xtndprce,
sop10200.taxamnt,
sop10100.docdate,
sop10100.custnmbr,
sop10100.custname,
'Unposted' AS Posted,
CASE
WHEN xtndprce <> 0 THEN Round(( sop10200.taxamnt / xtndprce ) *
100, 2
)
ELSE 0
END AS CalcTaxPC,
sop10100.docid,
sop10200.soptype,
sop10100.cstponbr,
sop10100.orignumb,
sop10100.prbtadcd,
sop10200.prstadcd,
sop10200.taxschid
FROM sop10200
INNER JOIN sop10100
ON sop10200.soptype = sop10100.soptype
AND sop10200.sopnumbe = sop10100.sopnumbe
WHERE ( sop10200.soptype IN ( 3, 4 ) )
UNION
SELECT sop30300.sopnumbe,
sop30300.itemnmbr,
sop30300.itemdesc,
sop30300.itmtshid,
sop30300.xtndprce,
sop30300.taxamnt,
sop30200.docdate,
sop30200.custnmbr,
sop30200.custname,
'Posted' AS Posted,
CASE
WHEN xtndprce <> 0 THEN Round(( sop30300.taxamnt / xtndprce ) *
100, 2
)
ELSE 0
END AS CalcTaxpc,
sop30200.docid,
sop30300.soptype,
sop30200.cstponbr,
sop30200.orignumb,
sop30200.prbtadcd,
sop30300.prstadcd,
sop30300.taxschid
FROM sop30300
INNER JOIN sop30200
ON sop30300.soptype = sop30200.soptype
AND sop30300.sopnumbe = sop30200.sopnumbe
WHERE ( sop30300.soptype IN ( 3, 4 ) )) AS SOPLines
LEFT OUTER JOIN tx00201
ON SOPLines.itmtshid = tx00201.taxdtlid
WHERE ( NOT ( SOPLines.calctaxpc - tx00201.txdtlpct BETWEEN -0.05 AND 0.05 ) )
No comments:
Post a Comment