Jump to content

Recommended Posts

I've got this:

 

    SUM(postransaction.amount) AS PAYMENTSAMOUNT

 

in this query:

 

SELECT SO.num AS "SO", SO.dateCompleted AS "DateCompleted", SO.dateIssued as "DateIssued",
    COALESCE(SO.totalTax, 0) as "Tax", COALESCE(POSTransaction.Amount, 0) AS "POSAmount",
    POSTransaction.dateTime as "POSDate", PaymentMethod.name AS "PaymentName", Customer.name as "Customer", so.customerpo as "customerpo",
    COALESCE(SUM(SOItem.totalPrice), 0) AS totalPrice, MAX(SOItem.dateScheduledFulfillment) AS DateScheduledFulfillment,
    PaymentTerms.netDays as "NetDays", PaymentTerms.nextMonth as "NextMonth",
    PaymentMethod.Name as "PaymentType", company.name AS company, COALESCE(postcatch.totalpaid, 0) AS totalpaid,
    COALESCE(postcatchcount.countpaid,1) as catchcount, 
    SUM(postransaction.amount) AS PAYMENTSAMOUNT

FROM Customer, SOItem, PaymentTerms, SO
    LEFT JOIN POSTransaction ON POSTransaction.soID = SO.ID
    LEFT JOIN PaymentMethod ON PaymentMethod.ID = POSTransaction.paymentMethodID
    JOIN company ON company.id = 1
    LEFT JOIN (SELECT SUM(amount) AS totalpaid, soid
                 FROM postransaction
                GROUP BY soid) postcatch ON postcatch.soid = so.id
    LEFT JOIN (SELECT Count(amount) AS countpaid, soid
                 FROM postransaction
                GROUP BY soid) postcatchCount ON postcatchCount.soid = so.id



WHERE Customer.ID = SO.customerID
AND SOItem.SOID = SO.ID
AND PaymentTerms.ID = SO.paymentTermsID
AND SOItem.typeID <> 40
AND Customer.ID LIKE $P{customerID}
AND SOItem.statusID <> 70
AND SO.statusID IN($P{ckIssued},$P{ckInProgress},$P{ckFulfilled},$P{ckClosedShort})



GROUP BY SO.num, SO.dateCompleted, SO.dateIssued, SO.statusID, SO.totalTax,
    POSTransaction.amount, POSTransaction.dateTime, PaymentMethod.name, Customer.name,
    PaymentTerms.netDays, PaymentTerms.typeID, PaymentTerms.nextMonth, company.name,
    postcatch.totalpaid, postcatchcount.countpaid, so.customerpo



ORDER BY Customer.name, SO.num, POSTransaction.dateTime

 

I'm attempting to take the payments and add them together to see how much has been payed towards the order. I've made a variable out of the PAYMENTAMOUNTS results. It is giving me odd results though, for example on a specific order that I am looking at. The total is 1809.69. The customer has made a payment of 465.69 which should leave us at 1344. Right now I am just trying to display the total payments made, which is 465.69. So when I call that variable, I am getting 3259.83. I am not sure what is causing this to happen. Does anyone have an idea of what might cause this?

Link to comment
https://forums.phpfreaks.com/topic/187286-odd-query-results/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.