Caros,
Há alguns dias atrás eu postei como chegar ao cálculo de comissões por recebimento, mas agora analisando diferente, eu cheguei a outra query:
SELECT CS.TRANSDATE , SUM(CS.SETTLEAMOUNTCUR) AS SETTLEAMOUNTMST , CT2.INVOICE , C.NAME AS CNAME , CMT.AMOUNTMST AS AMOUNTMST , DT.NAME , CT2.AMOUNTCUR AS INVOICEAMOUNT , CASE WHEN PC.NUMOFPAYMENT = '' THEN '1' WHEN ISNULL(PC.NUMOFPAYMENT, '1') = '1' THEN '1' -- Não sei porque tenho que fazer assim, sei que se comparo com Null ou qualquer outra coisa não funciona. ELSE PC.NUMOFPAYMENT END AS NUMOFPAYMENT , CIT.NAME AS ITEMNAME FROM CUSTTRANS AS CT INNER JOIN CUSTSETTLEMENT CS ON CS.TRANSCOMPANY = CT.DATAAREAID AND CS.TRANSRECID = CT.RECID AND CS.ACCOUNTNUM = CT.ACCOUNTNUM INNER JOIN CUSTTABLE C ON C.ACCOUNTNUM = CT.ACCOUNTNUM AND C.DATAAREAID = CT.DATAAREAID INNER JOIN CUSTTRANS CT2 ON CT2.RECID = CT.OFFSETRECID AND CT2.DATAAREAID = CT.DATAAREAID INNER JOIN COMMISSIONTRANS CMT ON CMT.INVOICEID = CT2.INVOICE AND CMT.DATAAREAID = CT2.DATAAREAID INNER JOIN EMPLTABLE ET ON ET.EMPLID = CMT.EMPLID AND ET.DATAAREAID = CMT.DATAAREAID INNER JOIN DIRPARTYTABLE DT ON DT.PARTYID = ET.PARTYID AND DT.DATAAREAID = ET.DATAAREAID INNER JOIN CUSTINVOICEJOUR CIJ ON CIJ.INVOICEID = CT2.INVOICE AND CIJ.DATAAREAID = CT2.DATAAREAID LEFT OUTER JOIN PAYMSCHED PC ON PC.NAME = CIJ.PAYMENTSCHED AND PC.DATAAREAID = CIJ.DATAAREAID INNER JOIN CUSTINVOICETRANS CIT ON CIT.INVOICEID = CIJ.INVOICEID AND CIT.DATAAREAID = CIJ.DATAAREAID AND CIT.INVENTTRANSID <> '' AND CIT.NUMBERSEQUENCEGROUP = CIJ.NUMBERSEQUENCEGROUP WHERE CT.TRANSTYPE = '15' AND CIJ.RETURNITEMNUM = '' AND CT2.TRANSTYPE = '2' AND CIJ.INVOICEAMOUNT > 0 AND CT.DATAAREAID = 'DAT' GROUP BY CS.TRANSDATE, CT2.INVOICE, C.NAME, CMT.AMOUNTMST, DT.NAME, CT2.AMOUNTCUR, PC.NUMOFPAYMENT, CIT.NAME, CT2.TRANSTYPE |
A mudança mais significativa é que agora parto da CustTrans onde o tipo de transação for igual a 15 (Payment) enquanto na outra versão, eu partia da CustSettlement (liquidação de clientes).
Post inicial: http://www.daxbr.com.br/?p=1834
Obs.: Novamente, isto serve para a minha situação atual, ou seja, use por sua conta e risco!
[]s
Pichler
One Response
calgary web hosting company
20|Mar|2014 1Hi there! I just wiuld like to give you a huge thumbs up for the great information you’ve got here on this post.
I will be returning to your site for more soon.
Leave a reply