3 -- Notes: used by arWorkBench, dspAROpenItems
4 -- Copyright (c) 1999-2011 by OpenMFG LLC, d/b/a xTuple.
5 -- See www.xtuple.com/CPAL for the full text of the software license.
7 -- Get unposted invoices
30 SELECT aropen_id AS id,
31 CASE WHEN (aropen_doctype='I') THEN 0
32 WHEN (aropen_doctype='C') THEN 1
33 WHEN (aropen_doctype='D') THEN 2
34 WHEN (aropen_doctype='R') THEN 3
37 aropen_docnumber AS docnumber,
38 COALESCE(invchead_id,cmhead_id,-1) AS docnumber_xtidrole,
40 aropen_docdate AS docdate,
42 aropen_ordernumber AS ordernumber,
43 COALESCE(cohead_id,-1) AS ordernumber_xtidrole,
44 CASE WHEN (aropen_doctype='I') THEN 'invoice'
45 WHEN (aropen_doctype='C') THEN 'creditMemo'
46 WHEN (aropen_doctype='D') THEN 'debitMemo'
47 WHEN (aropen_doctype='R') THEN 'cashdeposit'
51 CASE WHEN (aropen_doctype='C') THEN 'emphasis'
52 ELSE CASE WHEN(aropen_doctype='R')THEN 'altemphasis'
54 END AS doctype_qtforegroundrole,
56 aropen_amount AS amount,
57 (aropen_amount/aropen_curr_rate * CASE WHEN (aropen_doctype='I') THEN 1
58 WHEN (aropen_doctype='C') THEN -1
59 WHEN (aropen_doctype='D') THEN 1
60 WHEN (aropen_doctype='R') THEN -1
66 (aropen_paid - (COALESCE(SUM(arapply_target_paid),0))) AS paid,
67 (aropen_paid - (COALESCE(SUM(arapply_target_paid),0))/aropen_curr_rate) AS base_paid,
69 (((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0))) *
70 CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END)
73 currConcat(aropen_curr_id) AS currAbbr,
74 (((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0)))/aropen_curr_rate *
75 CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END) AS base_balance,
77 cust_id, cust_number, cust_name,
78 COALESCE(invchead_recurring_invchead_id IS NOT NULL, false) AS recurring,
81 'curr' AS amount_xtnumericrole,
82 'curr' AS base_amount_xtnumericrole,
83 0 AS base_amount_xttotalrole,
84 'curr' AS paid_xtnumericrole,
85 'curr' AS base_paid_xtnumericrole,
86 0 AS base_paid_xttotalrole,
87 'curr'AS balance_xtnumericrole,
88 'curr' AS base_balance_xtnumericrole,
89 0 AS base_balance_xttotalrole,
90 NULL AS aropen_docnumber_qtdisplayrole,
91 NULL AS aropen_docdate_qtdisplayrole,
94 CASE WHEN ((COALESCE(aropen_duedate,current_date) < current_date) AND COALESCE(aropen_open,FALSE)) THEN 'error'
95 END AS aropen_duedate_qtforegroundrole,
97 ccpay_id AS ccard_number_xtidrole,
98 firstLine(aropen_notes) AS notes
103 JOIN custinfo ON (aropen_cust_id=cust_id)
104 JOIN custtype ON (cust_custtype_id=custtype_id)
105 LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)
106 LEFT OUTER JOIN invchead ON ((aropen_docnumber=invchead_invcnumber)
107 AND (aropen_doctype='I'))
108 LEFT OUTER JOIN cohead ON (invchead_ordernumber=cohead_number)
109 LEFT OUTER JOIN cmhead ON ((aropen_docnumber=cmhead_number)
110 AND (aropen_doctype='C'))
111 LEFT OUTER JOIN arapply ON (((aropen_id=arapply_source_aropen_id)
112 OR (aropen_id=arapply_target_aropen_id))
113 AND (arapply_distdate>COALESCE(<? valueor("asofDate", "NULL") ?>,current_date)))
114 LEFT OUTER JOIN payaropen ON (payaropen_aropen_id=aropen_id)
115 LEFT OUTER JOIN ccpay ON (payaropen_ccpay_id=ccpay_id)
116 LEFT OUTER JOIN ccard ON (ccpay_ccard_id=ccard_id)
118 --<? if not exists("showClosed") ?>
119 -- AND (aropen_docdate <= COALESCE(<? value("asofDate") ?>, current_date))
120 -- AND (COALESCE(aropen_closedate, DATE(<? value("asofDate") ?>) + 1, current_date + 1) > COALESCE(<? value("asofDate") ?>, current_date))
123 --<? if exists("debitsOnly") ?>
124 -- AND (aropen_doctype IN ('D','I'))
125 --<? elseif exists("creditsOnly") ?>
126 -- AND (aropen_doctype IN ('C', 'R'))
129 --<? if ! exists("showPaid") ?>
130 -- AND ABS(aropen_amount - aropen_paid) != 0.0
134 <? if exists("cust_id") ?>
135 AND (aropen_cust_id=<? value("cust_id") ?>)
138 <? if exists("startDate") ?>
139 AND (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
142 <? if exists("startDueDate") ?>
143 AND (aropen_duedate >= <? value("startDueDate") ?>)
146 <? if exists("endDueDate") ?>
147 AND (aropen_duedate <= <? value("endDueDate") ?>)
150 GROUP BY id, altId, invchead_id,
151 aropen_docdate, aropen_duedate, aropen_doctype,
152 aropen_docnumber, aropen_amount,
153 aropen_notes, aropen_posted, aropen_ordernumber,
154 aropen_paid, aropen_open, aropen_curr_id,
155 aropen_closedate, aropen_curr_rate, cmhead_id,
156 cust_id, cust_number, cust_name,
157 cohead_id, ccpay_id, ccard_number,
158 invchead_recurring_invchead_id
162 docdate DESC, docnumber DESC, xtindentrole