-- Data for Name: itemlocpost; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemlocpost (itemlocpost_id, itemlocpost_itemlocseries, itemlocpost_glseq) FROM stdin;
\.


--
-- Name: itemlocpost_itemlocpost_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemlocpost_itemlocpost_id_seq', 1, false);


--
-- Name: itemopn_itemopn_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemopn_itemopn_id_seq', 39, true);


--
-- Data for Name: itemsite; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemsite (itemsite_id, itemsite_item_id, itemsite_warehous_id, itemsite_qtyonhand, itemsite_reorderlevel, itemsite_ordertoqty, itemsite_cyclecountfreq, itemsite_datelastcount, itemsite_datelastused, itemsite_loccntrl, itemsite_safetystock, itemsite_minordqty, itemsite_multordqty, itemsite_leadtime, itemsite_abcclass, itemsite_issuemethod, itemsite_controlmethod, itemsite_active, itemsite_plancode_id, itemsite_costcat_id, itemsite_eventfence, itemsite_sold, itemsite_stocked, itemsite_freeze, itemsite_location_id, itemsite_useparams, itemsite_useparamsmanual, itemsite_soldranking, itemsite_createpr, itemsite_location, itemsite_location_comments, itemsite_notes, itemsite_perishable, itemsite_autoabcclass, itemsite_ordergroup, itemsite_disallowblankwip, itemsite_maxordqty, itemsite_mps_timefence, itemsite_createwo, itemsite_warrpurc, itemsite_autoreg, itemsite_costmethod, itemsite_value, itemsite_ordergroup_first, itemsite_supply_itemsite_id, itemsite_planning_type, itemsite_wosupply, itemsite_posupply, itemsite_lsseq_id, itemsite_cosdefault, itemsite_createsopr, itemsite_createsopo, itemsite_dropship, itemsite_recvlocation_id, itemsite_issuelocation_id, itemsite_location_dist, itemsite_recvlocation_dist, itemsite_issuelocation_dist) FROM stdin;
\.


--
-- Name: itemsite_itemsite_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemsite_itemsite_id_seq', 292, true);


--
-- Data for Name: itemsrc; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemsrc (itemsrc_id, itemsrc_item_id, itemsrc_vend_id, itemsrc_vend_item_number, itemsrc_vend_item_descrip, itemsrc_comments, itemsrc_vend_uom, itemsrc_invvendoruomratio, itemsrc_minordqty, itemsrc_multordqty, itemsrc_leadtime, itemsrc_ranking, itemsrc_active, itemsrc_manuf_name, itemsrc_manuf_item_number, itemsrc_manuf_item_descrip, itemsrc_default, itemsrc_upccode, itemsrc_effective, itemsrc_expires, itemsrc_contrct_id, itemsrc_contrct_max, itemsrc_contrct_min) FROM stdin;
\.


--
-- Name: itemsrc_itemsrc_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemsrc_itemsrc_id_seq', 83, true);


--
-- Data for Name: itemsrcp; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemsrcp (itemsrcp_id, itemsrcp_itemsrc_id, itemsrcp_qtybreak, itemsrcp_price, itemsrcp_updated, itemsrcp_curr_id, itemsrcp_dropship, itemsrcp_warehous_id, itemsrcp_type, itemsrcp_discntprcnt, itemsrcp_fixedamtdiscount) FROM stdin;
\.


--
-- Name: itemsrcp_itemsrcp_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemsrcp_itemsrcp_id_seq', 84, true);


--
-- Data for Name: itemsub; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemsub (itemsub_id, itemsub_parent_item_id, itemsub_sub_item_id, itemsub_uomratio, itemsub_rank) FROM stdin;
\.


--
-- Name: itemsub_itemsub_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemsub_itemsub_id_seq', 16, true);


--
-- Data for Name: itemtax; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemtax (itemtax_id, itemtax_item_id, itemtax_taxtype_id, itemtax_taxzone_id) FROM stdin;
\.


--
-- Name: itemtax_itemtax_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemtax_itemtax_id_seq', 1, false);


--
-- Data for Name: itemtrans; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemtrans (itemtrans_id, itemtrans_source_item_id, itemtrans_target_item_id) FROM stdin;
\.


--
-- Name: itemtrans_itemtrans_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemtrans_itemtrans_id_seq', 1, false);


--
-- Data for Name: itemuom; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemuom (itemuom_id, itemuom_itemuomconv_id, itemuom_uomtype_id) FROM stdin;
\.


--
-- Name: itemuom_itemuom_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemuom_itemuom_id_seq', 1, false);


--
-- Data for Name: itemuomconv; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY itemuomconv (itemuomconv_id, itemuomconv_item_id, itemuomconv_from_uom_id, itemuomconv_from_value, itemuomconv_to_uom_id, itemuomconv_to_value, itemuomconv_fractional, itemuomconv_active) FROM stdin;
\.


--
-- Name: itemuomconv_itemuomconv_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('itemuomconv_itemuomconv_id_seq', 1, false);


--
-- Name: journal_number_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('journal_number_seq', 2274, true);


--
-- Data for Name: jrnluse; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY jrnluse (jrnluse_id, jrnluse_date, jrnluse_number, jrnluse_use) FROM stdin;
\.


--
-- Name: jrnluse_jrnluse_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('jrnluse_jrnluse_id_seq', 280, true);


--
-- Data for Name: labeldef; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY labeldef (labeldef_id, labeldef_name, labeldef_papersize, labeldef_columns, labeldef_rows, labeldef_width, labeldef_height, labeldef_start_offset_x, labeldef_start_offset_y, labeldef_horizontal_gap, labeldef_vertical_gap) FROM stdin;
1	Avery 5263	Letter	2	5	400	200	25	50	0	0
2	Avery 5264	Letter	2	3	400	333	25	75	0	0
3	Avery 8460	Letter	3	10	262	100	32	50	0	0
4	CILS ALP1-9200-1	Letter	3	7	200	100	62	62	81	50
\.


--
-- Name: labeldef_labeldef_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('labeldef_labeldef_id_seq', 4, true);


--
-- Data for Name: labelform; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY labelform (labelform_id, labelform_name, labelform_report_id, labelform_perpage, labelform_report_name) FROM stdin;
\.


--
-- Name: labelform_labelform_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('labelform_labelform_id_seq', 6, true);


--
-- Data for Name: lang; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY lang (lang_id, lang_qt_number, lang_abbr3, lang_abbr2, lang_name) FROM stdin;
1	3	\N	\N	Afan
2	156	\N	\N	Atsam
3	16	\N	\N	Bhutani
4	22	\N	\N	Byelorussian
5	23	\N	\N	Cambodian
6	158	\N	\N	Jju
7	154	\N	\N	Koro
8	68	\N	\N	Kurundi
9	69	\N	\N	Laothian
10	101	\N	\N	SerboCroatian
11	102	\N	\N	Sesotho
12	103	\N	\N	Setswana
13	107	\N	\N	Siswati
14	164	\N	\N	Tyap
15	\N	ace	\N	Achinese
16	\N	ach	\N	Acoli
17	\N	ada	\N	Adangme
18	\N	ady	\N	Adyghe; Adygei
19	\N	afa	\N	Afro-Asiatic.(Other)
20	\N	afh	\N	Afrihili
21	\N	ain	\N	Ainu
22	\N	akk	\N	Akkadian
23	\N	ale	\N	Aleut
24	\N	alg	\N	Algonquian languages
25	\N	alt	\N	Southern Altai
26	\N	ang	\N	English, Old (ca.450-1100)
27	\N	anp	\N	Angika
28	\N	apa	\N	Apache languages
29	\N	arc	\N	Official Aramaic (700-300 BCE); Imperial Aramaic (700-300 BCE)
30	\N	arn	\N	Mapudungun; Mapuche
31	\N	arp	\N	Arapaho
32	\N	art	\N	Artificial (Other)
33	\N	arw	\N	Arawak
34	\N	ast	\N	Asturian; Bable; Leonese; Asturleonese
35	\N	ath	\N	Athapascan languages
36	\N	aus	\N	Australian languages
37	\N	awa	\N	Awadhi
38	\N	bad	\N	Banda languages
39	\N	bai	\N	Bamileke languages
40	\N	bal	\N	Baluchi
41	\N	ban	\N	Balinese
42	\N	bas	\N	Basa
43	\N	bat	\N	Baltic (Other)
44	\N	bej	\N	Beja; Bedawiyet
45	\N	bem	\N	Bemba
46	\N	ber	\N	Berber (Other)
47	\N	bho	\N	Bhojpuri
48	\N	bik	\N	Bikol
49	\N	bin	\N	Bini; Edo
50	\N	bla	\N	Siksika
51	\N	bnt	\N	Bantu (Other)
52	\N	bra	\N	Braj
53	\N	btk	\N	Batak languages
54	\N	bua	\N	Buriat
55	\N	bug	\N	Buginese
56	152	byn	\N	Blin; Bilin
57	\N	cad	\N	Caddo
58	\N	cai	\N	Central American Indian (Other)
59	\N	car	\N	Galibi Carib
60	\N	cau	\N	Caucasian (Other)
61	\N	ceb	\N	Cebuano
62	\N	cel	\N	Celtic (Other)
63	\N	chb	\N	Chibcha
64	\N	chg	\N	Chagatai
65	\N	chk	\N	Chuukese
66	\N	chm	\N	Mari
67	\N	chn	\N	Chinook jargon
68	\N	cho	\N	Choctaw
69	\N	chp	\N	Chipewyan; Dene Suline
70	\N	chr	\N	Cherokee
71	\N	chy	\N	Cheyenne
72	\N	cmc	\N	Chamic languages
73	\N	cop	\N	Coptic
74	\N	cpe	\N	Creoles and pidgins, English-based (Other)
75	\N	cpf	\N	Creoles and pidgins, French-based (Other)
76	\N	cpp	\N	Creoles and pidgins, Portuguese-based (Other)
77	\N	crh	\N	Crimean Tatar; Crimean Turkish
78	\N	crp	\N	Creoles and pidgins (Other)
79	\N	csb	\N	Kashubian
80	\N	cus	\N	Cushitic (Other)
81	\N	dak	\N	Dakota
82	\N	dar	\N	Dargwa
83	\N	day	\N	Land Dayak languages
84	\N	del	\N	Delaware
85	\N	den	\N	Slave (Athapascan)
86	\N	dgr	\N	Dogrib
87	\N	din	\N	Dinka
88	\N	doi	\N	Dogri
89	\N	dra	\N	Dravidian (Other)
90	\N	dsb	\N	Lower Sorbian
91	\N	dua	\N	Duala
92	\N	dum	\N	Dutch, Middle (ca.1050-1350)
93	\N	dyu	\N	Dyula
94	\N	efi	\N	Efik
95	\N	egy	\N	Egyptian (Ancient)
96	\N	eka	\N	Ekajuk
97	\N	elx	\N	Elamite
98	\N	enm	\N	English, Middle (1100-1500)
99	\N	ewo	\N	Ewondo
100	\N	fan	\N	Fang
101	\N	fat	\N	Fanti
102	\N	fil	\N	Filipino; Pilipino
103	\N	fiu	\N	Finno-Ugrian (Other)
104	\N	fon	\N	Fon
105	\N	frm	\N	French, Middle (ca.1400-1600)
106	\N	fro	\N	French, Old (842-ca.1400)
107	38	frr	\N	Northern Frisian
108	38	frs	\N	Eastern Frisian
109	159	fur	\N	Friulian
110	148	gaa	\N	Ga
111	\N	gay	\N	Gayo
112	\N	gba	\N	Gbaya
113	\N	gem	\N	Germanic (Other)
114	153	gez	\N	Geez
115	\N	gil	\N	Gilbertese
116	\N	gmh	\N	German, Middle High (ca.1050-1500)
117	\N	goh	\N	German, Old High (ca.750-1050)
118	\N	gon	\N	Gondi
119	\N	gor	\N	Gorontalo
120	\N	got	\N	Gothic
121	\N	grb	\N	Grebo
122	\N	grc	\N	Greek, Ancient (to 1453)
123	\N	gsw	\N	Swiss German; Alemannic; Alsatian
124	\N	gwi	\N	Gwich'in
125	\N	hai	\N	Haida
126	163	haw	\N	Hawaiian
127	\N	hil	\N	Hiligaynon
128	\N	him	\N	Himachali
129	\N	hit	\N	Hittite
130	\N	hmn	\N	Hmong
131	\N	hsb	\N	Upper Sorbian
132	\N	hup	\N	Hupa hupa
133	\N	iba	\N	Iban
134	\N	ijo	\N	Ijo languages
135	\N	ilo	\N	Iloko
136	\N	inc	\N	Indic (Other)
137	\N	ine	\N	Indo-European (Other)
138	\N	inh	\N	Ingush
139	\N	ira	\N	Iranian (Other)
140	\N	iro	\N	Iroquoian languages
141	\N	jbo	\N	Lojban
142	\N	jpr	\N	Judeo-Persian
143	\N	jrb	\N	Judeo-Arabic
144	\N	kaa	\N	Kara-Kalpak
145	\N	kab	\N	Kabyle
146	\N	kac	\N	Kachin; Jingpho
147	150	kam	\N	Kamba
148	\N	kar	\N	Karen languages
149	\N	kaw	\N	Kawi
150	\N	kbd	\N	Kabardian
151	\N	kha	\N	Khasi
152	\N	khi	\N	Khoisan (Other)
153	\N	kho	\N	Khotanese
154	\N	kmb	\N	Kimbundu
155	147	kok	\N	Konkani
156	\N	kos	\N	Kosraean
157	\N	kpe	\N	Kpelle
158	\N	krc	\N	Karachay-Balkar
159	\N	krl	\N	Karelian
160	\N	kro	\N	Kru languages
161	\N	kru	\N	Kurukh
162	\N	kum	\N	Kumyk
163	\N	kut	\N	Kutenai
164	\N	lad	\N	Ladino
165	\N	lah	\N	Lahnda
166	\N	lam	\N	Lamba
167	\N	lez	\N	Lezghian
168	\N	lol	\N	Mongo
169	\N	loz	\N	Lozi
170	\N	lua	\N	Luba-Lulua
171	\N	lui	\N	Luiseno
172	\N	lun	\N	Lunda
173	\N	luo	\N	Luo (Kenya and Tanzania)
174	\N	lus	\N	Lushai
175	\N	mad	\N	Madurese
176	\N	mag	\N	Magahi
177	\N	mai	\N	Maithili
178	\N	mak	\N	Makasar
179	\N	man	\N	Mandingo
180	\N	map	\N	Austronesian (Other)
181	\N	mas	\N	Masai
182	\N	mdf	\N	Moksha
183	\N	mdr	\N	Mandar
184	\N	men	\N	Mende
185	\N	mga	\N	Irish, Middle (900-1200)
186	\N	mic	\N	Mi'kmaq; Micmac
187	\N	min	\N	Minangkabau
188	\N	mis	\N	Uncoded languages
189	\N	mkh	\N	Mon-Khmer (Other)
190	\N	mnc	\N	Manchu
191	\N	mni	\N	Manipuri
192	\N	mno	\N	Manobo languages
193	\N	moh	\N	Mohawk
194	\N	mos	\N	Mossi
195	\N	mul	\N	Multiple languages
196	\N	mun	\N	Munda languages
197	\N	mus	\N	Creek
198	\N	mwl	\N	Mirandese
199	\N	mwr	\N	Marwari
200	\N	myn	\N	Mayan languages
201	\N	myv	\N	Erzya
202	\N	nah	\N	Nahuatl languages
203	\N	nai	\N	North American Indian
204	\N	nap	\N	Neapolitan
205	\N	nds	\N	Low German; Low Saxon; German, Low; Saxon, Low
206	\N	new	\N	Nepal Bhasa; Newari
207	\N	nia	\N	Nias
208	\N	nic	\N	Niger-Kordofanian (Other)
209	\N	niu	\N	Niuean
210	\N	nog	\N	Nogai
211	\N	non	\N	Norse, Old
212	\N	nqo	\N	N'Ko
213	\N	nso	\N	Pedi; Sepedi; Northern Sotho
214	\N	nub	\N	Nubian languages
215	\N	nwc	\N	Classical Newari; Old Newari; Classical Nepal Bhasa
216	\N	nym	\N	Nyamwezi
217	\N	nyn	\N	Nyankole
218	\N	nyo	\N	Nyoro
219	\N	nzi	\N	Nzima
220	\N	osa	\N	Osage
221	\N	ota	\N	Turkish, Ottoman (1500-1928)
222	\N	oto	\N	Otomian languages
223	\N	paa	\N	Papuan (Other)
224	\N	pag	\N	Pangasinan
225	\N	pal	\N	Pahlavi
226	\N	pam	\N	Pampanga; Kapampangan
227	\N	pap	\N	Papiamento
228	\N	pau	\N	Palauan
229	\N	peo	\N	Persian, Old (ca.600-400 B.C.)
230	\N	phi	\N	Philippine (Other)
231	\N	phn	\N	Phoenician
232	\N	pon	\N	Pohnpeian
233	\N	pra	\N	Prakrit languages
234	\N	pro	\N	Provencal, Old (to 1500)
235	\N	raj	\N	Rajasthani
236	\N	rap	\N	Rapanui
237	\N	rar	\N	Rarotongan; Cook Islands Maori
238	\N	roa	\N	Romance (Other)
239	\N	rom	\N	Romany
240	\N	rup	\N	Aromanian; Arumanian; Macedo-Romanian
241	\N	sad	\N	Sandawe
242	\N	sah	\N	Yakut
243	\N	sai	\N	South American Indian (Other)
244	\N	sal	\N	Salishan languages
245	\N	sam	\N	Samaritan Aramaic
246	\N	sas	\N	Sasak
247	\N	sat	\N	Santali
248	\N	scn	\N	Sicilian
249	\N	sco	\N	Scots
250	\N	sel	\N	Selkup
251	\N	sem	\N	Semitic (Other)
252	\N	sga	\N	Irish, Old (to 900)
253	\N	sgn	\N	Sign languages
254	\N	shn	\N	Shan
255	155	sid	\N	Sidamo
256	\N	sio	\N	Siouan languages
257	\N	sit	\N	Sino-Tibetan (Other)
258	\N	sla	\N	Slavic (Other)
259	\N	sma	\N	Southern Sami
260	\N	smi	\N	Sami languages (Other)
261	\N	smj	\N	Lule Sami
262	\N	smn	\N	Inari Sami
263	\N	sms	\N	Skolt Sami
264	\N	snk	\N	Soninke
265	\N	sog	\N	Sogdian
266	\N	son	\N	Songhai languages
267	\N	srn	\N	Sranan Tongo
268	\N	srr	\N	Serer
269	\N	ssa	\N	Nilo-Saharan (Other)
270	\N	suk	\N	Sukuma
271	\N	sus	\N	Susu
272	\N	sux	\N	Sumerian
273	\N	syc	\N	Classical Syriac
274	151	syr	\N	Syriac
275	\N	tai	\N	Tai (Other)
276	\N	tem	\N	Timne
277	\N	ter	\N	Tereno
278	\N	tet	\N	Tetum
279	157	tig	\N	Tigre
280	\N	tiv	\N	Tiv
281	\N	tkl	\N	Tokelau
282	\N	tlh	\N	Klingon
283	\N	tli	\N	Tlingit
284	\N	tmh	\N	Tamashek
285	\N	tog	\N	Tonga (Nyasa)
286	\N	tpi	\N	Tok Pisin
287	\N	tsi	\N	Tsimshian
288	\N	tum	\N	Tumbuka
289	\N	tup	\N	Tupi languages
290	\N	tut	\N	Altaic (Other)
291	\N	tvl	\N	Tuvalu
292	\N	tyv	\N	Tuvinian
293	\N	udm	\N	Udmurt
294	\N	uga	\N	Ugaritic
295	\N	umb	\N	Umbundu
296	\N	und	\N	Undetermined
297	\N	vai	\N	Vai
298	\N	vot	\N	Votic
299	\N	wak	\N	Wakashan languages
300	162	wal	\N	Walamo
301	\N	war	\N	Waray
302	\N	was	\N	Washo
303	\N	wen	\N	Sorbian languages
304	\N	xal	\N	Kalmyk; Oirat
305	\N	yao	\N	Yao
306	\N	yap	\N	Yapese
307	\N	ypk	\N	Yupik languages
308	\N	zap	\N	Zapotec
309	\N	zbl	\N	Blissymbols; Blissymbolics; Bliss
310	\N	zen	\N	Zenaga
311	\N	znd	\N	Zande languages
312	\N	zun	\N	Zuni
313	\N	zxx	\N	No linguistic content
314	\N	zza	\N	Zaza; Dimili; Dimli; Kirdki; Kirmanjki; Zazaki
315	4	aar	aa	Afar
316	2	abk	ab	Abkhazian
317	\N	ave	ae	Avestan
318	5	afr	af	Afrikaans
319	146	aka	ak	Akan
320	7	amh	am	Amharic
321	\N	arg	an	Aragonese
322	8	ara	ar	Arabic
323	10	asm	as	Assamese
324	\N	ava	av	Avaric
325	11	aym	ay	Aymara
326	12	aze	az	Azerbaijani
327	13	bak	ba	Bashkir
328	\N	bel	be	Belarusian
329	20	bul	bg	Bulgarian
330	17	bih	bh	Bihari
331	18	bis	bi	Bislama
332	\N	bam	bm	Bambara
333	15	ben	bn	Bengali
334	121	bod	bo	Tibetan
335	19	bre	br	Breton
336	142	bos	bs	Bosnian
337	24	cat	ca	Catalan; Valencian
338	\N	che	ce	Chechen
339	\N	cha	ch	Chamorro
340	26	cos	co	Corsican
341	\N	cre	cr	Cree
342	28	ces	cs	Czech
343	\N	chu	cu	Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic
344	\N	chv	cv	Chuvash
345	134	cym	cy	Welsh
346	29	dan	da	Danish
347	42	deu	de	German
348	143	div	dv	Divehi; Dhivehi; Maldivian
349	\N	dzo	dz	Dzongkha
350	161	ewe	ee	Ewe
351	42	ell	el	Greek, Modern (1453-)
352	31	eng	en	English
353	32	epo	eo	Esperanto
354	111	spa	es	Spanish; Castilian
355	33	est	et	Estonian
356	14	eus	eu	Basque
357	89	fas	fa	Persian
358	\N	ful	ff	Fulah
359	36	fin	fi	Finnish
360	35	fij	fj	Fijian
361	34	fao	fo	Faroese
362	37	fra	fr	French
363	38	fry	fy	Western Frisian
364	57	gle	ga	Irish
365	39	gla	gd	Gaelic; Scottish Gaelic
366	40	glg	gl	Galician
367	45	grn	gn	Guarani
368	46	guj	gu	Gujarati
369	144	glv	gv	Manx
370	47	hau	ha	Hausa
371	48	heb	he	Hebrew
372	49	hin	hi	Hindi
373	\N	hmo	ho	Hiri Motu
374	27	hrv	hr	Croatian
375	\N	hat	ht	Haitian; Haitian Creole
376	50	hun	hu	Hungarian
377	9	hye	hy	Armenian
378	\N	her	hz	Herero
379	53	ina	ia	Interlingua (International Auxiliary language Association)
380	52	ind	id	Indonesian
381	54	ile	ie	Interlingue; Occidental
382	149	ibo	ig	Igbo
383	\N	iii	ii	Sichuan Yi; Nuosu
384	56	ipk	ik	Inupiaq
385	\N	ido	io	Ido
386	51	isl	is	Icelandic
387	58	ita	it	Italian
388	55	iku	iu	Inuktitut
389	59	jpn	ja	Japanese
390	60	jav	jv	Javanese
391	41	kat	ka	Georgian
392	\N	kon	kg	Kongo
393	\N	kik	ki	Kikuyu; Gikuyu
394	\N	kua	kj	Kuanyama; Kwanyama
395	63	kaz	kk	Kazakh
396	44	kal	kl	Kalaallisut; Greenlandic
397	\N	khm	km	Central Khmer
398	61	kan	kn	Kannada
399	66	kor	ko	Korean
400	\N	kau	kr	Kanuri
401	62	kas	ks	Kashmiri
402	67	kur	ku	Kurdish
403	\N	kom	kv	Komi
404	145	cor	kw	Cornish
405	65	kir	ky	Kirghiz; Kyrgyz
406	70	lat	la	Latin
407	\N	ltz	lb	Luxembourgish; Letzeburgesch
408	\N	lug	lg	Ganda
409	\N	lim	li	Limburgan; Limburger; Limburgish
410	72	lin	ln	Lingala
411	\N	lao	lo	Lao
412	73	lit	lt	Lithuanian
413	\N	lub	lu	Luba-Katanga
414	71	lav	lv	Latvian
415	75	mlg	mg	Malagasy
416	\N	mah	mh	Marshallese
417	79	mri	mi	Maori
418	74	mkd	mk	Macedonian
419	77	mal	ml	Malayalam
420	82	mon	mn	Mongolian
421	81	mol	mo	Moldavian
422	80	mar	mr	Marathi
423	76	msa	ms	Malay
424	78	mlt	mt	Maltese
425	21	mya	my	Burmese
426	83	nau	na	Nauru
427	85	nob	nb	Bokmal, Norwegian; Norwegian Bokmal
428	\N	nde	nd	Ndebele, North; North Ndebele
429	84	nep	ne	Nepali
430	\N	ndo	ng	Ndonga
431	30	nld	nl	Dutch; Flemish
432	141	nno	nn	Norwegian Nynorsk; Nynorsk, Norwegian
433	141	nor	no	Norwegian
434	\N	nbl	nr	Ndebele, South; South Ndebele
435	\N	nav	nv	Navajo; Navaho
436	165	nya	ny	Chichewa; Chewa; Nyanja
437	86	oci	oc	Occitan (post 1500); Provencal
438	\N	oji	oj	Ojibwa
439	\N	orm	om	Oromo
440	87	ori	or	Oriya
441	\N	oss	os	Ossetian; Ossetic
442	92	pan	pa	Panjabi; Punjabi
443	\N	pli	pi	Pali
444	90	pol	pl	Polish
445	88	pus	ps	Pushto; Pashto
446	91	por	pt	Portuguese
447	93	que	qu	Quechua
448	94	roh	rm	Romansh
449	\N	run	rn	Rundi
450	95	ron	ro	Romanian
451	96	rus	ru	Russian
452	64	kin	rw	Kinyarwanda
453	99	san	sa	Sanskrit
454	\N	srd	sc	Sardinian
455	105	snd	sd	Sindhi
456	\N	sme	se	Northern Sami
457	98	sag	sg	Sango
458	106	sin	si	Sinhala; Sinhalese
459	108	slk	sk	Slovak
460	109	slv	sl	Slovenian
461	97	smo	sm	Samoan
462	104	sna	sn	Shona
463	110	som	so	Somali
464	6	sqi	sq	Albanian
465	100	srp	sr	Serbian
466	\N	ssw	ss	Swati
467	\N	sot	st	Sotho, Southern
468	112	sun	su	Sundanese
469	114	swe	sv	Swedish
470	113	swa	sw	Swahili
471	117	tam	ta	Tamil
472	119	tel	te	Telugu
473	116	tgk	tg	Tajik
474	120	tha	th	Thai
475	122	tir	ti	Tigrinya
476	126	tuk	tk	Turkmen
477	115	tgl	tl	Tagalog
478	\N	tsn	tn	Tswana
479	123	ton	to	Tonga (Tonga Islands)
480	125	tur	tr	Turkish
481	124	tso	ts	Tsonga
482	118	tat	tt	Tatar
483	127	twi	tw	Twi
484	\N	tah	ty	Tahitian
485	128	uig	ug	Uighur; Uyghur
486	129	ukr	uk	Ukrainian
487	130	urd	ur	Urdu
488	131	uzb	uz	Uzbek
489	160	ven	ve	Venda
490	132	vie	vi	Vietnamese
491	133	vol	vo	Volapak
492	\N	wln	wa	Walloon
493	135	wol	wo	Wolof
494	136	xho	xh	Xhosa
495	137	yid	yi	Yiddish
496	138	yor	yo	Yoruba
497	139	zha	za	Zhuang; Chuang
498	25	zho	zh	Chinese
499	140	zul	zu	Zulu
\.


--
-- Name: lang_lang_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('lang_lang_id_seq', 499, true);


--
-- Data for Name: locale; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY locale (locale_id, locale_code, locale_descrip, locale_lang_file, locale_dateformat, locale_currformat, locale_qtyformat, locale_comments, locale_qtyperformat, locale_salespriceformat, locale_extpriceformat, locale_timeformat, locale_timestampformat, local_costformat, locale_costformat, locale_purchpriceformat, locale_uomratioformat, locale_intervalformat, locale_lang_id, locale_country_id, locale_error_color, locale_warning_color, locale_emphasis_color, locale_altemphasis_color, locale_expired_color, locale_future_color, locale_curr_scale, locale_salesprice_scale, locale_purchprice_scale, locale_extprice_scale, locale_cost_scale, locale_qty_scale, locale_qtyper_scale, locale_uomratio_scale, locale_percent_scale, locale_weight_scale) FROM stdin;
3	Default	Default Locale		DD Mon YYYY	999,999,990.00	.-		999,999,990.0000	999,999,990.0000	999,999,990.00	HH:MI:SS	DD Mon YYYY HH:MI:SS	\N	999,999,990.0000	999,999,990.0000	999,999,990.00000	HH:MI:SS	-1	-1							2	4	4	2	4	2	4	5	2	2
4	Spanish	Locale for Mexican Spanish	OpenMFG.mx.sp	DD Mon YYYY	999999990.00	.-		999999990.0000	999999990.0000	999999990.00	HH:MI:SS	DD Mon YYYY HH:MI:SS	\N	999999990.0000			HH:MI:SS	-1	-1							2	4	0	2	4	2	4	0	2	2
\.


--
-- Name: locale_locale_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('locale_locale_id_seq', 27, true);


--
-- Data for Name: location; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY location (location_id, location_warehous_id, location_name, location_descrip, location_restrict, location_netable, location_whsezone_id, location_aisle, location_rack, location_bin, location_formatname, location_usable) FROM stdin;
\.


--
-- Name: location_location_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('location_location_id_seq', 121, true);


--
-- Data for Name: locitem; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY locitem (locitem_id, locitem_location_id, locitem_item_id) FROM stdin;
\.


--
-- Name: locitem_locitem_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('locitem_locitem_id_seq', 21, true);


--
-- Name: log_log_id_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('log_log_id_seq', 747, true);


--
-- Data for Name: metasql; Type: TABLE DATA; Schema: public; Owner: admin
--

COPY metasql (metasql_id, metasql_group, metasql_name, metasql_notes, metasql_query, metasql_lastuser, metasql_lastupdate, metasql_grade) FROM stdin;
2	enterPoReceipt	poItemReceivingsFillList		-- Group:enterPoReceipt\n-- Name:poItemReceivingsFillList\n-- Notes:\n\n<? if exists("pohead_id") ?>\nSELECT poitem_id, poitem_linenumber,\n       formatDate(poitem_duedate),\n       COALESCE(item_number, <? value("nonInventory") ?>),\n       COALESCE(uom_name, <? value("na") ?>),\n       warehous_code,\n       poitem_vend_item_number,\n       poitem_vend_uom,\n       formatQty(poitem_qty_ordered),\n       formatQty(poitem_qty_received),\n       formatQty(qtyToReceive(<? value("ordertype") ?>, poitem_id))\nFROM poitem \n  LEFT OUTER JOIN \n     ( itemsite \n<? if exists("selectedOnly") ?>\n       JOIN usrsite ON (itemsite_warehous_id=usrsite_warehous_id) \n<? endif ?>\n       JOIN item ON (itemsite_item_id=item_id) \n       JOIN uom ON (item_inv_uom_id=uom_id)\n       JOIN whsinfo ON (itemsite_warehous_id=warehous_id)\n     ) ON (poitem_itemsite_id=itemsite_id) \nWHERE ( (poitem_status <> 'C')\n<? if exists("selectedOnly") ?>\n AND (usrsite_username=current_user) \n<? endif ?>\n AND (poitem_pohead_id=<? value("pohead_id") ?>) )\nORDER BY poitem_linenumber;\n<? elseif exists("rahead_id") ?>\nSELECT raitem_id, raitem_linenumber,\n       formatDate(rahead_expiredate),\n       COALESCE(item_number, <? value("nonInventory") ?>),\n       COALESCE(iu.uom_name, <? value("na") ?>),\n       warehous_code,\n       '' AS vend_item_number,\n       ru.uom_name,\n       formatQty(raitem_qtyauthorized),\n       formatQty(raitem_qtyreceived),\n       formatQty(qtyToReceive(<? value("ordertype") ?>, raitem_id))\nFROM rahead, raitem \n  LEFT OUTER JOIN \n     ( itemsite \n<? if exists("selectedOnly") ?>\n       JOIN usrsite ON (itemsite_warehous_id=usrsite_warehous_id) \n<? endif ?>\n       JOIN item ON (itemsite_item_id=item_id) \n       JOIN uom iu ON (item_inv_uom_id=uom_id)\n       JOIN whsinfo ON (itemsite_warehous_id=warehous_id)\n     ) ON (raitem_itemsite_id=itemsite_id), uom ru\nWHERE ( (raitem_status <> 'C')\n AND (raitem_qtyauthorized > 0)\n AND (raitem_disposition IN ('R','P','V'))\n AND (raitem_rahead_id=rahead_id)\n AND (raitem_qty_uom_id=ru.uom_id)\n<? if exists("selectedOnly") ?>\n AND (usrsite_username=current_user) \n<? endif ?>\n AND (rahead_id=<? value("rahead_id") ?>) )\nORDER BY raitem_linenumber;\n<? elseif exists("tohead_id") ?>\nSELECT toitem_id, toitem_linenumber,\n       formatDate(toitem_duedate),\n       COALESCE(item_number, <? value("nonInventory") ?>),\n       COALESCE(uom_name, <? value("na") ?>),\n       warehous_code,\n       '',\n       toitem_uom,\n       formatQty(toitem_qty_ordered),\n       formatQty(toitem_qty_received),\n       formatQty(qtyToReceive(<? value("ordertype") ?>, toitem_id))\nFROM tohead, itemsite\n<? if exists("selectedOnly") ?>\n       JOIN usrsite ON (itemsite_warehous_id=usrsite_warehous_id) \n<? endif ?>\n, whsinfo, toitem, item JOIN uom ON (item_inv_uom_id=uom_id)\nWHERE ((toitem_item_id=item_id)\n  AND  (tohead_id=toitem_tohead_id)\n  AND  (tohead_dest_warehous_id=itemsite_warehous_id)\n  AND  (tohead_dest_warehous_id=warehous_id)\n  AND  (toitem_item_id=itemsite_item_id)\n  AND  (toitem_status <> 'C')\n<? if exists("selectedOnly") ?>\n AND (usrsite_username=current_user) \n<? endif ?>\n  AND  (toitem_tohead_id=<? value("tohead_id") ?>) )\nORDER BY toitem_linenumber;\n<? endif ?>\n	admin	2008-09-03	0
43	breederDistributionVariance	detail	used by dspBreederDistributionVarianceByItem, dspBreederDistributionVarianceByWarehouse	-- Group: breederDistributionVariance\n-- Name: detail\n-- Notes: used by dspBreederDistributionVarianceByItem, dspBreederDistributionVarianceByWarehouse\n\nSELECT brdvar_id, brdvar_postdate,\n       pi.item_number AS pitem_number,\n       ci.item_number AS citem_number,\n       brdvar_stdqtyper,\n       brdvar_stdqtyper * brdvar_wo_qty AS stdqty,\n       brdvar_actqtyper,\n       brdvar_actqtyper * brdvar_wo_qty AS actqty,\n       brdvar_actqtyper-brdvar_stdqtyper AS qtypervariance,\n       (brdvar_actqtyper-brdvar_stdqtyper) / brdvar_stdqtyper AS percentvariance,\n       'qtyper'   AS brdvar_stdqtyper_xtnumericrole,\n       'qty'     AS stdqty_xtnumericrole,\n       'qtyper'  AS brdvar_actqtyper_xtnumericrole,\n       'qty'     AS actqty_xtnumericrole,\n       'qtyper'  AS qtypervariance_xtnumericrole,\n       'percent' AS percentvariance_xtnumericrole \nFROM brdvar, itemsite AS ps, itemsite AS cs, item AS ci, item AS pi\nWHERE ( (brdvar_parent_itemsite_id=ps.itemsite_id)\n    AND (brdvar_itemsite_id=cs.itemsite_id)\n<? if exists("item_id") ?>\n    AND (ps.itemsite_item_id=<? value("item_id") ?>)\n    AND (pi.item_id=ci.item_id)\n<? else ?>\n    AND (ps.itemsite_item_id=pi.item_id)\n<? endif ?>\n    AND (cs.itemsite_item_id=ci.item_id)\n    AND (brdvar_postdate BETWEEN <? value("startDate") ?>\n                             AND <? value("endDate") ?>)\n<? if exists("warehous_id") ?>\n    AND (ps.itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n) \nORDER BY brdvar_postdate, pitem_number\n<? if not exists("item_id") ?>\n     , citem_number \n<? endif ?>\n;\n	admin	2008-11-07	0
61	manufacture	laborvariance	shared by dspLaborVarianceBy*	-- Group: manufacture\n-- Name:  laborvariance\n-- Notes: shared by dspLaborVarianceBy*\n\nSELECT woopervar.*,\n       item_number, wrkcnt_code,\n       (woopervar_sutime - woopervar_stdsutime) AS suvar,\n       (woopervar_rntime - woopervar_stdrntime) AS rnvar,\n       'qty' AS woopervar_qtyord_xtnumericrole,\n       'qty' AS woopervar_qtyrcv_xtnumericrole,\n       '1'   AS woopervar_stdsutime_xtnumericrole,\n       '1'   AS woopervar_stdrntime_xtnumericrole,\n       '1'   AS woopervar_sutime_xtnumericrole,\n       '1'   AS woopervar_rntime_xtnumericrole,\n       '1'   AS suvar_xtnumericrole,\n       '1'   AS rnvar_xtnumericrole\nFROM woopervar\n<? if exists("wo_id") ?>\n     JOIN wo ON ((woopervar_number=wo_number)\n             AND (woopervar_subnumber=wo_subnumber))\n<? endif ?>\n     JOIN itemsite ON (woopervar_parent_itemsite_id=itemsite_id)\n     JOIN item ON (itemsite_item_id=item_id)\n     LEFT OUTER JOIN wrkcnt ON (woopervar_wrkcnt_id=wrkcnt_id)\nWHERE (true\n<? if exists("startDate") ?>\n   AND (woopervar_posted BETWEEN <? value("startDate") ?>\n                             AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n   AND (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("booitem_id") ?>\n   AND (woopervar_booitem_id=<? value("booitem_id") ?>)\n<? endif ?>\n<? if exists("wrkcnt_id") ?>\n   AND (wrkcnt_id=<? value("wrkcnt_id") ?>)\n<? endif ?>\n<? if exists("wo_id") ?>\n   AND (wo_id=<? value("wo_id") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n   AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n)\nORDER BY woopervar_posted DESC, woopervar_seqnumber;\n	admin	2008-11-07	0
248	gleries	checkeditable		-- Group: gleries\n-- Name:  checkeditable\n-- Notes: \nSELECT gltrans_id \nFROM accnt, gltrans \n  LEFT OUTER JOIN period ON (gltrans_date BETWEEN period_start AND period_end) \nWHERE ( (gltrans_accnt_id=accnt_id) \n  AND (gltrans_sequence=<? value("glSequence") ?>) \n  AND ( (gltrans_deleted) \n     OR (period_freeze) \n     OR (gltrans_rec) \n     OR (period_closed AND NOT accnt_closedpost) ) )\nLIMIT 1;	admin	2010-09-10	0
484	assessFinanceCharges	detail	 Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. See www.xtuple.com/CPAL for the full text of the software license.	-- Group: assessFinanceCharges\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT aropen_id, aropen_docnumber, aropen_duedate, aropen_docdate,\n       aropen_amount, aropen_paid, balance, aropen_fincharg_date, aropen_fincharg_amount,\n       cust_number, cust_name,\n       CASE WHEN (currToLocal(aropen_curr_id, fincharg_mincharg, aropen_distdate) >\n                  (CASE WHEN (fincharg_assessoverdue)\n                        THEN (balance + prevfincharge)\n                        ELSE balance END * fincharg_air / 100.0 / 365 * CASE WHEN (fincharg_calcfrom=1)\n                                                                             THEN duedateoverdue\n                                                                             ELSE docdateoverdue END))\n            THEN currToLocal(aropen_curr_id, fincharg_mincharg, aropen_distdate)\n            ELSE (CASE WHEN (fincharg_assessoverdue)\n                       THEN (balance + prevfincharge)\n                       ELSE balance END * fincharg_air / 100.0 / 365 * CASE WHEN (fincharg_calcfrom=1)\n                                                                            THEN duedateoverdue\n                                                                            ELSE docdateoverdue END)\n       END AS fincharge\nFROM fincharg,\n     (SELECT *,\n             (aropen_amount - aropen_paid) AS balance,\n             COALESCE(aropen_fincharg_amount, 0.0) AS prevfincharge,\n             (<? value("assessmentDate") ?> - COALESCE(aropen_fincharg_date, aropen_duedate)) AS duedateoverdue,\n             (<? value("assessmentDate") ?> - COALESCE(aropen_fincharg_date, aropen_docdate)) AS docdateoverdue\n      FROM aropen JOIN custinfo ON (cust_id=aropen_cust_id)\n                  LEFT OUTER JOIN terms ON (terms_id=aropen_terms_id)\n                  LEFT OUTER JOIN custtype ON (cust_custtype_id=custtype_id)\n                  LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\n      WHERE ((aropen_doctype='I')\n        AND  (aropen_open)\n        AND  (COALESCE(terms_fincharg, FALSE))\n        AND  (COALESCE(cust_financecharge, TRUE))\n      <? if exists("cust_id") ?>\n        AND   (aropen_cust_id=<? value("cust_id") ?>)\n      <? endif ?>\n      <? if exists("custtype_id") ?>\n        AND   (custtype_id=<? value("custtype_id") ?>)\n      <? endif ?>\n      <? if exists("custtype_pattern") ?>\n        AND   (custtype_code~<? value("custtype_pattern") ?>)\n      <? endif ?>\n      <? if exists("custgrp_id") ?>\n        AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n      <? endif ?>\n      )) AS data\nWHERE ((COALESCE(aropen_fincharg_date, aropen_duedate) + COALESCE(cust_gracedays, fincharg_graceperiod)) < <? value("assessmentDate") ?>)\nORDER BY cust_number, aropen_docnumber;\n	admin	2014-03-20	0
481	contrct	itemsources	Selection of Contract Related Item Sources	-- Group: contrct\n-- Name:  itemsources\n-- Notes: Selection of Contract Related Item Sources\nSELECT itemsrc_id,\n\t-1 AS pohead_id, \n\t' ' AS seq,\n\t' ' AS poitem_ordnumber, \n        item_number,\n\titem_descrip1,\n\titemsrc_vend_uom,\n\titemsrc_vend_item_number,\n\tmin(contisrc_min) AS contisrc_min,\n\tsum(poitem_qty_unreleased) AS poitem_qty_unreleased,\n\tsum(poitem_qty_ordered)    AS poitem_qty_ordered,\n\tsum(poitem_qty_received)   AS poitem_qty_received,\n\tsum(poitem_qty_returned)   AS poitem_qty_returned,\n\tnull AS poitem_duedate,\n\tnull AS poitem_status,\n\t0 AS xtindentrole \n\tFROM (SELECT contrct_id, \n\t\titemsrc_id,\n\t\tpohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, \n\t\titem_number,\n\t\titem_descrip1,\n\t\titemsrc_vend_uom,\n\t\titemsrc_vend_item_number,\n\t\tcontisrc_min,\n\t\tCASE WHEN poitem_status = 'U' THEN poitem_qty_ordered\n\t\t  ELSE 0\n\t\tEND AS poitem_qty_unreleased,\n\t\tCASE WHEN poitem_status = 'O' THEN poitem_qty_ordered\n\t\t     WHEN poitem_status = 'C' THEN poitem_qty_ordered\n                  ELSE 0\n\t\tEND AS poitem_qty_ordered,\n\t\tpoitem_qty_received,\n\t\tpoitem_qty_returned,\n\t\tpoitem_duedate, \n\t\tpoitem_status\n\t\tFROM contrct JOIN itemsrc  ON (itemsrc_contrct_id  = contrct_id)\n\t\t  LEFT OUTER JOIN contisrc ON (contisrc_itemsrc_id = itemsrc_id)\n\t\t  LEFT OUTER JOIN poitem   ON (poitem_itemsrc_id   = itemsrc_id)\n\t\t  LEFT OUTER JOIN pohead   ON (pohead_id           = poitem_pohead_id)\n\t\t\t     JOIN item     ON (itemsrc_item_id     = item_id)\n\t\tWHERE (contrct_id = <? value("contrct_id") ?>)) AS dummy1\n\tWHERE (contrct_id = <? value("contrct_id") ?>)\n\tGROUP BY itemsrc_id, itemsrc_vend_item_number, itemsrc_vend_uom, item_number, item_descrip1\n\nUNION  -- PO Line Items\n\nSELECT itemsrc_id,\n\tpohead_id, \n\tpohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS seq,\n        pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber,  \n        null AS item_number,\n\tnull AS item_descrip1,\n\tnull AS itemsrc_vend_uom,\n\tnull AS itemsrc_vend_item_number,\n\tnull AS contisrc_min,\n\tCASE WHEN poitem_status = 'U' THEN poitem_qty_ordered\n\t  ELSE 0\n\tEND AS poitem_qty_unreleased,\n\tCASE WHEN poitem_status = 'O' THEN poitem_qty_ordered\n\t     WHEN poitem_status = 'C' THEN poitem_qty_ordered\n          ELSE 0\n\tEND AS poitem_qty_ordered,\n\tpoitem_qty_received,\n\tpoitem_qty_returned,\n\tpoitem_duedate, \n\tCASE WHEN poitem_status = 'O' THEN 'Open'\n\t     WHEN poitem_status = 'C' THEN 'Closed'\n\t     ELSE 'Unreleased'\n\tEND AS poitem_status,\n\t1 AS xtindentrole \n\tFROM contrct JOIN itemsrc  ON (itemsrc_contrct_id  = contrct_id)\n\t  LEFT OUTER JOIN contisrc ON (contisrc_itemsrc_id = itemsrc_id)\n\t\t     JOIN poitem   ON (poitem_itemsrc_id   = itemsrc_id)\n\t\t     JOIN pohead   ON (pohead_id           = poitem_pohead_id)\n\t\t     JOIN itemsite ON (poitem_itemsite_id  = itemsite_id)\n\t\t     JOIN item     ON (itemsite_item_id    = item_id)\n\tWHERE (contrct_id = <? value("contrct_id") ?>)\n\nUNION -- Receipts\n\nSELECT itemsrc_id,\n\tpohead_id,  \n\tpoitem_ordnumber || 'R' || to_char(recv_date, 'YYYYMMDDHH24:MI:SS') AS seq,\n\t'Receipt' AS poitem_ordnumber,\n\tnull AS item_number,\n\tnull AS item_descrip1,\n\trecv_vend_uom AS vend_uom,\n\tnull AS itemsrc_vend_item_number,\n\tnull AS contisrc_min,\n\tnull AS poitem_qty_unreleased,\n\tnull AS poitem_qty_ordered,\n\trecv_qty AS poitem_qty_received,\n\tnull AS poitem_qty_returned,\n\trecv_date AS poitem_duedate,\n\trecv_trans_usr_name AS username,\n\t2 AS xtindentrole\n  FROM recv JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, \n\t\t\t    poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id, \n\t\t\t    poitem_itemsrc_id\n\t\t\tFROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id   = recv_orderitem_id)\n               JOIN itemsite ON (itemsite_id = recv_itemsite_id)\n               JOIN item     ON (item_id     = itemsite_item_id)\n               JOIN itemsrc  ON (poitem_itemsrc_id = itemsrc_id)\n  WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>) \n\nUNION -- Returns\n\nSELECT itemsrc_id, \n\tpohead_id,  \n\tpoitem_ordnumber || 'R' || to_char(poreject_date, 'YYYYMMDDHH24:MI:SS') AS seq,\n\t'Return' AS poitem_ordnumber,\n\tnull AS item_number,\n\tnull AS item_descrip1,\n\tporeject_vend_uom AS vend_uom,\n\tnull AS itemsrc_vend_item_number,\n\tnull AS contisrc_min,\n\tnull AS poitem_qty_unreleased,\n\tnull AS poitem_qty_ordered,\n\tnull AS poitem_qty_received,\n\tporeject_qty AS poitem_qty_returned,\n\tporeject_date AS poitem_duedate,\n\tporeject_trans_username AS username,\n\t2 AS xtindentrole \n  FROM poreject JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, \n\t\t\t    poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id, \n\t\t\t    poitem_itemsrc_id\n\t\t\tFROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id   = poreject_poitem_id)\n               JOIN itemsite ON (itemsite_id = poreject_itemsite_id)\n               JOIN item     ON (item_id     = itemsite_item_id)\n               JOIN itemsrc  ON (poitem_itemsrc_id = itemsrc_id)\n  WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>) \n\nORDER BY itemsrc_id, seq, poitem_ordnumber, poitem_duedate, xtindentrole;\n	admin	2013-11-11	0
417	bookings	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bookings\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT   coitem_id AS id, coitem_cohead_id AS altId,\n         formatSoLineNumber(coitem_id) AS f_linenumber,\n         getSoSchedDate(cohead_id) AS sort_scheddate,\n         coitem.*, cohead.*,\n         cust_number, cust_name,\n         item_number, item_descrip1, (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n         uom_name,\n         warehous_code,\n         qtyAtShipping(coitem_id) AS qtyatshipping,\n-- TODO - not needed, remove? (very slow)\n--         qtyAvailable(itemsite_id, coitem_scheddate) AS qtyavailable,\n--         (qtyAvailable(itemsite_id, coitem_scheddate) < 0.0) AS stockout,\n--         CASE WHEN (itemsite_useparams) THEN (qtyAvailable(itemsite_id, coitem_scheddate) <= itemsite_reorderlevel)\n--              ELSE (qtyAvailable(itemsite_id, coitem_scheddate) <= 0.0)\n--         END AS reorder,\n         noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS qtybalance,\n         currtobase(cohead_curr_id, coitem_price, cohead_orderdate) AS baseunitprice,\n         round((coitem_qtyord * coitem_qty_invuomratio) *\n                     (coitem_price / coitem_price_invuomratio), 2) AS extprice,\n         round((coitem_qtyord * coitem_qty_invuomratio) *\n                     (currtobase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio), 2) AS baseextprice,\n         round((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n                     (coitem_price / coitem_price_invuomratio), 2) AS extpricebalance,\n         round((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n                     (currtobase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio), 2) AS baseextpricebalance,\n         round((coitem_qtyord * coitem_qty_invuomratio) *\n                     (coitem_unitcost / coitem_price_invuomratio), 2) AS extcost,\n         CASE WHEN (coitem_price = 0.0) THEN 0.0\n              ELSE ROUND(coitem_qtyord * coitem_qty_invuomratio * (coitem_price - coitem_unitcost) / coitem_price_invuomratio,2)\n         END AS margin,\n         CASE WHEN (coitem_price = 0.0) THEN 0.0\n              ELSE ((coitem_price - coitem_unitcost) / coitem_price)\n         END AS marginpercent,\n         curr_abbr AS currAbbr,\n<? foreach("char_id_text_list") ?>\n         charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n         charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n         charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,\n<? endforeach ?>\n-- TODO - not needed, remove? (very slow)\n--         CASE WHEN (qtyAvailable(itemsite_id, coitem_scheddate) < 0.0) THEN 'error'\n--              WHEN itemsite_useparams AND (qtyAvailable(itemsite_id, coitem_scheddate) <= itemsite_reorderlevel) THEN 'warning'\n--              WHEN NOT itemsite_useparams AND (qtyAvailable(itemsite_id, coitem_scheddate) <= 0.0) THEN 'warning'\n--         END AS qtyavailable_qtforegroundrole,\n       'qty' AS coitem_qtyord_xtnumericrole,\n       'qty' AS coitem_qtyshipped_xtnumericrole,\n       'qty' AS coitem_qtyreturned_xtnumericrole,\n       'qty' AS qtyatshipping_xtnumericrole,\n       'qty' AS qtybalance_xtnumericrole,\n       'qty' AS qtyavailable_xtnumericrole,\n       'salesprice' AS coitem_price_xtnumericrole,\n       'salesprice' AS baseunitprice_xtnumericrole,\n       'cost' AS coitem_unitcost_xtnumericrole,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS extcost_xtnumericrole,\n       'curr' AS margin_xtnumericrole,\n       'percent' AS marginpercent_xtnumericrole,\n       'curr' AS baseextprice_xtnumericrole,\n       'curr' AS extpricebalance_xtnumericrole,\n       'curr' AS baseextpricebalance_xtnumericrole,\n       0 AS coitem_qtyord_xttotalrole,\n       0 AS coitem_qtyshipped_xttotalrole,\n       0 AS coitem_qtyreturned_xttotalrole,\n       0 AS qtybalance_xttotalrole,\n       0 AS baseextprice_xttotalrole,\n       0 AS baseextpricebalance_xttotalrole\n  FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)\n              JOIN custinfo ON (cust_id=cohead_cust_id)\n              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n              JOIN site() ON (warehous_id=itemsite_warehous_id)\n              JOIN item ON (item_id=itemsite_item_id)\n              JOIN uom ON (uom_id=coitem_qty_uom_id)\n              JOIN curr_symbol ON (curr_id=cohead_curr_id)\n<? foreach("char_id_text_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> \n          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> \n          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> \n          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> \n          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> \n          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> \n          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\n  WHERE ( (coitem_status<>'X')\n  <? if exists("cohead_id") ?>\n    AND  (coitem_cohead_id=<? value("cohead_id") ?>)\n  <? endif ?>\n  <? if exists("openOnly") ?>\n    AND  (coitem_status<>'C')\n  <? endif ?>\n  <? if exists("startDate") ?>\n    AND  (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n  <? endif ?>\n\n  <? if exists("salesrep_id") ?>\n    AND  (cohead_salesrep_id=<? value("salesrep_id") ?>)\n  <? endif ?>\n  <? if exists("shipto_id") ?>\n    AND  (cohead_shipto_id=<? value("shipto_id") ?>)\n  <? endif ?>\n  <? if exists("cust_id") ?>\n    AND  (cohead_cust_id=<? value("cust_id") ?>)\n  <? elseif exists("custtype_id") ?>\n    AND  (cust_custtype_id=<? value("custtype_id") ?>)\n  <? elseif exists("custtype_pattern") ?>\n    AND  (cust_custtype_id IN (SELECT DISTINCT custtype_id\n                               FROM custtype\n                               WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n  <? elseif exists("custgrp") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem))\n  <? elseif exists("custgrp_id") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem\n                     WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n  <? elseif exists("custgrp_pattern") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrp, custgrpitem\n                     WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                       AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n  <? endif ?>\n\n  <? if exists("item_id") ?>\n    AND  (itemsite_item_id=<? value("item_id") ?>)\n  <? elseif exists("prodcat_id") ?>\n    AND (item_prodcat_id=<? value("prodcat_id") ?>)\n  <? elseif exists("prodcat_pattern") ?>\n    AND (item_prodcat_id IN (SELECT DISTINCT prodcat_id\n                             FROM prodcat\n                             WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n  <? endif ?>\n\n  <? if exists("warehous_id") ?>\n    AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n  <? literal("charClause") ?>\n        )\n\n<? if exists("orderByScheddate") ?>\n  ORDER BY sort_scheddate, cohead_number, coitem_linenumber, coitem_subnumber\n<? elseif exists("orderByOrderdate") ?>\n  ORDER BY cohead_orderdate, cohead_number, coitem_linenumber, coitem_subnumber\n<? else ?>\n  ORDER BY cohead_number, coitem_linenumber, coitem_subnumber\n<? endif ?>\n;\n	admin	2015-10-01	0
425	contactmerge	restore	 Restore a contact that was previously merged\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: restore\n-- Notes: Restore a contact that was previously merged\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntctrestore(cntctmrgd_cntct_id) AS result\nFROM cntctmrgd\n<? if exists("cntct_id") ?>\nWHERE (cntctmrgd_cntct_id=<? value("cntct_id") ?>)\n<? endif ?>\n;\n	admin	2015-10-01	0
446	bankrec	receipts	 used by reconcileBankaccount\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bankrec\n-- Name: receipts\n-- Notes: used by reconcileBankaccount\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("summary") ?>\nSELECT COALESCE(SUM(amount),0.0) AS cleared_amount\n  FROM ( SELECT COALESCE( bankrecitem_amount,\n                          (currToLocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) * -1.0) ) AS amount\n           FROM (bankaccnt CROSS JOIN gltrans)\n                      JOIN bankrecitem ON ((bankrecitem_source='GL')\n                                       AND (bankrecitem_source_id=gltrans_id)\n                                       AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                                       AND (bankrecitem_cleared))\n          WHERE ((gltrans_accnt_id=bankaccnt_accnt_id)\n            AND (NOT gltrans_deleted)\n            AND (NOT gltrans_rec)\n            AND (gltrans_amount < 0)\n            AND (gltrans_doctype != 'JP')\n            AND (bankaccnt_id=<? value("bankaccntid") ?>) )\n          UNION ALL\n         SELECT COALESCE( bankrecitem_amount,\n                          (currToLocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) * -1.0) ) AS amount\n           FROM (bankaccnt CROSS JOIN sltrans)\n                      JOIN bankrecitem ON ((bankrecitem_source='SL')\n                                       AND (bankrecitem_source_id=sltrans_id)\n                                       AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                                       AND (bankrecitem_cleared))\n          WHERE ((sltrans_accnt_id=bankaccnt_accnt_id)\n            AND (NOT sltrans_rec)\n            AND (sltrans_amount < 0)\n            AND (bankaccnt_id=<? value("bankaccntid") ?>) )\n          UNION ALL\n         SELECT CASE WHEN(bankadjtype_iscredit=true) THEN (bankadj_amount * -1) ELSE bankadj_amount END AS amount\n           FROM bankrecitem, bankadj, bankadjtype\n          WHERE ( (bankrecitem_source='AD')\n            AND (bankrecitem_source_id=bankadj_id)\n            AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n            AND (bankrecitem_cleared)\n            AND (bankadj_bankadjtype_id=bankadjtype_id)\n            AND (NOT bankadj_posted)\n            AND (((bankadjtype_iscredit=false) AND (bankadj_amount > 0)) OR (bankadjtype_iscredit=true AND (bankadj_amount < 0)))\n            AND (bankadj_bankaccnt_id=<? value("bankaccntid") ?>) ) ) AS data;\n<? else ?>\nSELECT gltrans_id AS id, 1 AS altid,\n       jrnluse_use AS use, gltrans_journalnumber AS jrnlnum,\n       COALESCE(date(jrnluse_date), gltrans_date) AS f_jrnldate,\n       COALESCE(bankrecitem_cleared, FALSE) AS cleared,\n       COALESCE(bankrecitem_effdate, gltrans_date) AS f_date,\n       gltrans_doctype AS doc_type,\n       gltrans_docnumber AS docnumber,\n       gltrans_notes AS notes,\n       currConcat(COALESCE(cashrcpt_curr_id, baseCurrId())) AS doc_curr,\n       CASE WHEN (fetchMetricValue('CurrencyExchangeSense') = 1) THEN\n         ROUND(1.0 / COALESCE(bankrecitem_curr_rate, cashrcpt_curr_rate, currRate(bankaccnt_curr_id, gltrans_date)),6)\n            ELSE\n         ROUND(COALESCE(bankrecitem_curr_rate, cashrcpt_curr_rate, currRate(bankaccnt_curr_id, gltrans_date)),6)\n       END AS doc_exchrate,\n       (gltrans_amount * -1.0) AS base_amount,\n       CASE WHEN (bankaccnt_curr_id=cashrcpt_curr_id) THEN\n         COALESCE( bankrecitem_amount,\n                   cashrcpt_amount,\n                   (currToLocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) * -1.0) )\n            ELSE\n         COALESCE( bankrecitem_amount,\n                   (currToLocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) * -1.0) )\n       END AS amount,\n       COALESCE(date(jrnluse_date), gltrans_date) AS jrnldate,\n       gltrans_date AS sortdate,\n       'uomratio' AS doc_exchrate_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       'curr' AS amount_xtnumericrole\n  FROM bankaccnt\n  JOIN gltrans ON (bankaccnt_accnt_id=gltrans_accnt_id)\n  LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='GL')\n                              AND (bankrecitem_source_id=gltrans_id)\n                              AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                              AND (bankrecitem_cleared))\n  LEFT OUTER JOIN jrnluse ON (jrnluse_number=gltrans_journalnumber AND jrnluse_use='C/R')\n  LEFT OUTER JOIN cashrcpt  ON ((gltrans_source='A/R')\n                            AND (gltrans_doctype='CR')\n                            AND (gltrans_misc_id=cashrcpt_id))\n  LEFT OUTER JOIN checkhead ON ((gltrans_doctype='CK')\n                            AND (gltrans_misc_id=checkhead_id))\n WHERE ((NOT gltrans_deleted)\n   AND (NOT gltrans_rec)\n   AND (NOT COALESCE(checkhead_void, false))\n   AND (gltrans_amount < 0)\n   AND (gltrans_doctype != 'JP')\n   AND (bankaccnt_id=<? value("bankaccntid") ?>)\n<? if exists("source") ?>\n   AND ('GL' = <? value("source") ?>)\n<? endif ?>\n<? if exists("sourceid") ?>\n   AND (gltrans_id = <? value("sourceid") ?>)\n<? endif ?>\n )\n UNION ALL\nSELECT sltrans_id AS id, 2 AS altid,\n       jrnluse_use AS use, sltrans_journalnumber AS jrnlnum,\n       COALESCE(date(jrnluse_date), sltrans_date) AS f_jrnldate,\n       COALESCE(bankrecitem_cleared, FALSE) AS cleared,\n       COALESCE(bankrecitem_effdate, sltrans_date) AS f_date,\n       sltrans_doctype AS doc_type,\n       sltrans_docnumber AS docnumber,\n       sltrans_notes AS notes,\n       currConcat(COALESCE(cashrcpt_curr_id, baseCurrId())) AS doc_curr,\n       CASE WHEN (fetchMetricValue('CurrencyExchangeSense') = 1) THEN\n         ROUND(1.0 / COALESCE(bankrecitem_curr_rate, cashrcpt_curr_rate, currRate(bankaccnt_curr_id, sltrans_date)),6)\n            ELSE\n         ROUND(COALESCE(bankrecitem_curr_rate, cashrcpt_curr_rate, currRate(bankaccnt_curr_id, sltrans_date)),6)\n       END AS doc_exchrate,\n       (sltrans_amount * -1.0) AS base_amount,\n       CASE WHEN (bankaccnt_curr_id=cashrcpt_curr_id) THEN\n         COALESCE( bankrecitem_amount,\n                   cashrcpt_amount,\n                   (currToLocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) * -1.0) )\n            ELSE\n         COALESCE( bankrecitem_amount,\n                   (currToLocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) * -1.0) )\n       END AS amount,\n       COALESCE(date(jrnluse_date), sltrans_date) AS jrnldate,\n       sltrans_date AS sortdate,\n       'uomratio' AS doc_exchrate_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       'curr' AS amount_xtnumericrole\n  FROM bankaccnt\n  JOIN sltrans ON (bankaccnt_accnt_id=sltrans_accnt_id)\n  LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='SL')\n                              AND (bankrecitem_source_id=sltrans_id)\n                              AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                              AND (bankrecitem_cleared))\n  LEFT OUTER JOIN jrnluse ON (jrnluse_number=sltrans_journalnumber AND jrnluse_use='C/R')\n  LEFT OUTER JOIN cashrcpt  ON ((sltrans_source='A/R')\n                            AND (sltrans_doctype='CR')\n                            AND (sltrans_misc_id=cashrcpt_id))\n  LEFT OUTER JOIN checkhead ON ((sltrans_doctype='CK')\n                            AND (sltrans_misc_id=checkhead_id))\n WHERE ((NOT sltrans_rec)\n   AND (NOT COALESCE(checkhead_void, false))\n   AND (sltrans_amount < 0)\n   AND (bankaccnt_id=<? value("bankaccntid") ?>)\n<? if exists("source") ?>\n   AND ('SL' = <? value("source") ?>)\n<? endif ?>\n<? if exists("sourceid") ?>\n   AND (sltrans_id = <? value("sourceid") ?>)\n<? endif ?>\n )\n UNION ALL\nSELECT bankadj_id AS id, 3 AS altid,\n       '' AS use, NULL AS jrnlnum, bankadj_date AS f_jrnldate,\n       COALESCE(bankrecitem_cleared, FALSE) AS cleared,\n       COALESCE(bankrecitem_effdate, bankadj_date) AS f_date,\n       'ADJ' AS doc_type,\n       bankadj_docnumber AS docnumber,\n       bankadjtype_name AS notes,\n       currConcat(bankadj_curr_id) AS doc_curr,\n       1.0 AS doc_exchrate,\n       CASE WHEN(bankadjtype_iscredit=true) THEN (bankadj_amount * -1.0) ELSE bankadj_amount END AS base_amount,\n       CASE WHEN(bankadjtype_iscredit=true) THEN (bankadj_amount * -1.0) ELSE bankadj_amount END AS amount,\n       bankadj_date AS jrnldate,\n       bankadj_date AS sortdate,\n       'uomratio' AS doc_exchrate_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       'curr' AS amount_xtnumericrole\n  FROM (bankadjtype CROSS JOIN bankadj)\n               LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='AD')\n                                           AND (bankrecitem_source_id=bankadj_id)\n                                           AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>))\n WHERE ( (((bankadjtype_iscredit=false) AND (bankadj_amount > 0)) OR ((bankadjtype_iscredit=true) AND (bankadj_amount < 0)))\n   AND (bankadj_bankadjtype_id=bankadjtype_id)\n   AND (NOT bankadj_posted)\n   AND (bankadj_bankaccnt_id=<? value("bankaccntid") ?>)\n<? if exists("source") ?>\n   AND ('AD' = <? value("source") ?>)\n<? endif ?>\n<? if exists("sourceid") ?>\n   AND (bankadj_id = <? value("sourceid") ?>)\n<? endif ?>\n )\nORDER BY jrnldate, jrnlnum, sortdate;\n<? endif ?>\n	admin	2015-10-01	0
419	contactmerge	delete	 Delete a contact\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: delete\n-- Notes: Delete a contact\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nDELETE FROM cntct WHERE (cntct_id=<? value("cntct_id") ?>);\n	admin	2015-10-01	0
361	glseries	checkeditable	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: glseries\n-- Name:  checkeditable\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT gltrans_id \nFROM accnt, gltrans \n  LEFT OUTER JOIN period ON (gltrans_date BETWEEN period_start AND period_end) \nWHERE ( (gltrans_accnt_id=accnt_id) \n  AND (gltrans_sequence=<? value("glSequence") ?>) \n  AND ( (gltrans_deleted) \n     OR (period_closed) \n     OR (gltrans_rec) \n     OR (period_freeze AND NOT checkPrivilege('PostFrozenPeriod')) ) )\nLIMIT 1;\n	admin	2015-10-01	0
482	contract	itemsources	Selection of Contract Related Item Sources	-- Group: contract\n-- Name:  itemsources\n-- Notes: Selection of Contract Related Item Sources\nSELECT itemsrc_id,\n\t-1 AS pohead_id, \n\t' ' AS seq,\n\t' ' AS poitem_ordnumber, \n        item_number,\n\titem_descrip1,\n\titemsrc_vend_uom,\n\titemsrc_vend_item_number,\n\titemsrc_contrct_min,\n\tsum(poitem_qty_unreleased) AS poitem_qty_unreleased,\n\tsum(poitem_qty_ordered)    AS poitem_qty_ordered,\n\tsum(poitem_qty_received)   AS poitem_qty_received,\n\tsum(poitem_qty_returned)   AS poitem_qty_returned,\n\tnull AS poitem_duedate,\n\tnull AS poitem_status,\n\t0 AS xtindentrole \n\tFROM (SELECT contrct_id, \n\t\titemsrc_id,\n\t\tpohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, \n\t\titem_number,\n\t\titem_descrip1,\n\t\titemsrc_vend_uom,\n\t\titemsrc_vend_item_number,\n\t\titemsrc_contrct_min,\n\t\tCASE WHEN poitem_status = 'U' THEN poitem_qty_ordered\n\t\t  ELSE 0\n\t\tEND AS poitem_qty_unreleased,\n\t\tCASE WHEN poitem_status = 'O' THEN poitem_qty_ordered\n\t\t     WHEN poitem_status = 'C' THEN poitem_qty_ordered\n                  ELSE 0\n\t\tEND AS poitem_qty_ordered,\n\t\tpoitem_qty_received,\n\t\tpoitem_qty_returned,\n\t\tpoitem_duedate, \n\t\tpoitem_status\n\t\tFROM contrct JOIN itemsrc  ON (itemsrc_contrct_id  = contrct_id)\n\t\t  LEFT OUTER JOIN poitem   ON (poitem_itemsrc_id   = itemsrc_id)\n\t\t  LEFT OUTER JOIN pohead   ON (pohead_id           = poitem_pohead_id)\n\t\t\t     JOIN item     ON (itemsrc_item_id     = item_id)\n\t\tWHERE (contrct_id = <? value("contrct_id") ?>)) AS dummy1\n\tWHERE (contrct_id = <? value("contrct_id") ?>)\n\tGROUP BY itemsrc_id, itemsrc_vend_item_number, itemsrc_vend_uom, itemsrc_contrct_min,\n                item_number, item_descrip1\n\nUNION  -- PO Line Items\n\nSELECT itemsrc_id,\n\tpohead_id, \n\tpohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS seq,\n        pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber,  \n        null AS item_number,\n\tnull AS item_descrip1,\n\tnull AS itemsrc_vend_uom,\n\tnull AS itemsrc_vend_item_number,\n\tnull AS itemsrc_contrct_min,\n\tCASE WHEN poitem_status = 'U' THEN poitem_qty_ordered\n\t  ELSE 0\n\tEND AS poitem_qty_unreleased,\n\tCASE WHEN poitem_status = 'O' THEN poitem_qty_ordered\n\t     WHEN poitem_status = 'C' THEN poitem_qty_ordered\n          ELSE 0\n\tEND AS poitem_qty_ordered,\n\tpoitem_qty_received,\n\tpoitem_qty_returned,\n\tpoitem_duedate, \n\tCASE WHEN poitem_status = 'O' THEN 'Open'\n\t     WHEN poitem_status = 'C' THEN 'Closed'\n\t     ELSE 'Unreleased'\n\tEND AS poitem_status,\n\t1 AS xtindentrole \n\tFROM contrct JOIN itemsrc  ON (itemsrc_contrct_id  = contrct_id)\n\t\t     JOIN poitem   ON (poitem_itemsrc_id   = itemsrc_id)\n\t\t     JOIN pohead   ON (pohead_id           = poitem_pohead_id)\n\t\t     JOIN itemsite ON (poitem_itemsite_id  = itemsite_id)\n\t\t     JOIN item     ON (itemsite_item_id    = item_id)\n\tWHERE (contrct_id = <? value("contrct_id") ?>)\n\nUNION -- Receipts\n\nSELECT itemsrc_id,\n\tpohead_id,  \n\tpoitem_ordnumber || 'R' || to_char(recv_date, 'YYYYMMDDHH24:MI:SS') AS seq,\n\t'Receipt' AS poitem_ordnumber,\n\tnull AS item_number,\n\tnull AS item_descrip1,\n\trecv_vend_uom AS vend_uom,\n\tnull AS itemsrc_vend_item_number,\n\tnull AS itemsrc_contrct_min,\n\tnull AS poitem_qty_unreleased,\n\tnull AS poitem_qty_ordered,\n\trecv_qty AS poitem_qty_received,\n\tnull AS poitem_qty_returned,\n\trecv_date AS poitem_duedate,\n\trecv_trans_usr_name AS username,\n\t2 AS xtindentrole\n  FROM recv JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, \n\t\t\t    poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id, \n\t\t\t    poitem_itemsrc_id\n\t\t\tFROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id   = recv_orderitem_id)\n               JOIN itemsite ON (itemsite_id = recv_itemsite_id)\n               JOIN item     ON (item_id     = itemsite_item_id)\n               JOIN itemsrc  ON (poitem_itemsrc_id = itemsrc_id)\n  WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>) \n\nUNION -- Returns\n\nSELECT itemsrc_id, \n\tpohead_id,  \n\tpoitem_ordnumber || 'R' || to_char(poreject_date, 'YYYYMMDDHH24:MI:SS') AS seq,\n\t'Return' AS poitem_ordnumber,\n\tnull AS item_number,\n\tnull AS item_descrip1,\n\tporeject_vend_uom AS vend_uom,\n\tnull AS itemsrc_vend_item_number,\n\tnull AS itemsrc_contrct_min,\n\tnull AS poitem_qty_unreleased,\n\tnull AS poitem_qty_ordered,\n\tnull AS poitem_qty_received,\n\tporeject_qty AS poitem_qty_returned,\n\tporeject_date AS poitem_duedate,\n\tporeject_trans_username AS username,\n\t2 AS xtindentrole \n  FROM poreject JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, \n\t\t\t    poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id, \n\t\t\t    poitem_itemsrc_id\n\t\t\tFROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id   = poreject_poitem_id)\n               JOIN itemsite ON (itemsite_id = poreject_itemsite_id)\n               JOIN item     ON (item_id     = itemsite_item_id)\n               JOIN itemsrc  ON (poitem_itemsrc_id = itemsrc_id)\n  WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>) \n\nORDER BY itemsrc_id, seq, poitem_ordnumber, poitem_duedate, xtindentrole;\n	admin	2014-03-20	0
433	salesOrderItems	list	 used by salesOrder\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: salesOrderItems\n-- Name: list\n-- Notes: used by salesOrder\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT coitem_id, coitem_altid, groupby,\n       coitem_linenumber, coitem_subnumber, f_linenumber,\n       warehous_code, item_number, item_type, description,\n       item_number_cust, item_descrip1_cust, item_descrip2_cust, item_barcode,\n       prodweight, packweight,\n       enhanced_status, coitem_firm,\n       qty_uom, price_uom, ship_uom,\n       coitem_memo,\n-- always create formatted columns for scheduled reports\n       formatDate(coitem_scheddate) AS f_scheddate,\n       formatSalesPrice(coitem_price) AS f_price,\n       formatSalesPrice(coitem_custprice) AS f_custprice,\n       formatPrcnt(discountfromcust / 100) AS f_discountfromcust,\n       formatQty(coitem_qtyord) AS f_qtyord,\n       CASE WHEN (qtyshipped > 0.0) THEN formatQty(qtyshipped) ELSE NULL END AS f_qtyshipped,\n       CASE WHEN (qtyshipped > 0.0) THEN formatQty(balance) ELSE NULL END AS f_balance,\n       CASE WHEN (qtyatshipping > 0.0) THEN formatQty(qtyatshipping) ELSE NULL END AS f_qtyatshipping,\n       formatMoney(extprice) AS f_extprice,\n       CASE WHEN (extprice_shipped > 0.0) THEN formatMoney(extprice_shipped) ELSE NULL END AS f_extprice_shipped,\n-- end formatted columns\n       coitem_scheddate, coitem_price, coitem_custprice, discountfromcust,\n       coitem_unitcost, margin, marginpercent,\n       coitem_qtyord, qtyshipped, balance, qtyatshipping,\n       extprice, extprice_shipped,\n       CASE WHEN (discountfromcust=100.0) THEN 'N/A' END AS discountfromcust_qtdisplayrole,\n       CASE WHEN (margin=0.0) THEN 'N/A' END AS margin_qtdisplayrole,\n       CASE WHEN (marginpercent=0.0) THEN 'N/A' END AS marginpercent_qtdisplayrole,\n       'qty' AS coitem_qtyord_xtnumericrole,\n       'qty' AS qtyshipped_xtnumericrole,\n       'qty' AS balance_xtnumericrole,\n       'qty' AS qtyatshipping_xtnumericrole,\n       'qty' AS prodweight_xtnumericrole,\n       'qty' AS packweight_xtnumericrole,\n       'salesprice' AS coitem_price_xtnumericrole,\n       'salesprice' AS coitem_custprice_xtnumericrole,\n       'cost' AS coitem_unitcost_xtnumericrole,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS extprice_shipped_xtnumericrole,\n       'curr' AS margin_xtnumericrole,\n       'percent' AS marginpercent_xtnumericrole,\n       CASE WHEN fetchMetricBool('EnableSOShipping') AND\n                 coitem_scheddate > CURRENT_DATE AND\n                 (noNeg(coitem_qtyord) <> qtyAtShipping('SO', coitem_id)) THEN 'future'\n            WHEN fetchMetricBool('EnableSOShipping') AND\n                 (noNeg(coitem_qtyord) <> qtyAtShipping('SO', coitem_id)) THEN 'expired'\n            WHEN (coitem_status NOT IN ('C', 'X') AND\n                  EXISTS(SELECT coitem_id\n                         FROM coitem\n                         WHERE ((coitem_status='C')\n                           AND  (coitem_cohead_id=<? value("cohead_id") ?>)))) THEN 'error'\n       END AS coitem_scheddate_qtforegroundrole,\n       CASE WHEN coitem_subnumber = 0 THEN 0\n            ELSE 1\n       END AS xtindentrole,\n       spplytype, ordrnumbr,\n       availableqoh,\n       'qty' AS availableqoh_xtnumericrole\n<? if exists("includeReservations") ?>\n       ,\n       reserved,\n       reservable,\n       'qty' AS reserved_xtnumericrole,\n       'qty' AS reservable_xtnumericrole\n<? endif?>\nFROM (\nSELECT coitem_id,\n       CASE WHEN (coitem_status='C') THEN 1\n            WHEN (coitem_status='X') THEN 4\n            WHEN ( (coitem_status='O') AND ( (qtyAtShipping('SO', coitem_id) > 0) OR (coitem_qtyshipped > 0) ) ) THEN 2\n            ELSE 3\n       END AS coitem_altid, 1 AS groupby,\n       coitem_linenumber, coitem_subnumber, formatSoLineNumber(coitem_id) AS f_linenumber,\n       warehous_code, item_number, item_type,\n       (item_descrip1 || ' ' || item_descrip2) AS description,\n       CASE WHEN (coitem_custpn != '') THEN coitem_custpn\n            ELSE item_number\n       END AS item_number_cust,\n       CASE WHEN (coitem_custpn != '' AND itemalias_usedescrip=TRUE) THEN itemalias_descrip1\n            ELSE item_descrip1\n       END AS item_descrip1_cust,\n       CASE WHEN (coitem_custpn != '' AND itemalias_usedescrip=TRUE) THEN itemalias_descrip2\n            ELSE item_descrip2\n       END AS item_descrip2_cust,\n       formatitemsitebarcode(itemsite_id) AS item_barcode,\n       (coitem_qtyord * coitem_qty_invuomratio * item_prodweight) AS prodweight,\n       (coitem_qtyord * coitem_qty_invuomratio * item_packweight) AS packweight,\n       coitem_status, coitem_firm,\n       getSoitemStatus(coitem_id) AS enhanced_status,\n       quom.uom_name AS qty_uom, puom.uom_name AS price_uom,\n       itemSellingUOM(item_id) AS ship_uom,\n       coitem_memo,\n       coitem_scheddate, coitem_price, coitem_custprice, coitem_qtyord,\n       CASE WHEN (coitem_custprice = 0.0) THEN 100.0\n            ELSE ((1.0 - (coitem_price / coitem_custprice)) * 100.0)\n       END AS discountfromcust,\n       coitem_unitcost,\n       CASE WHEN (coitem_price = 0.0) THEN 0.0\n            ELSE ROUND(coitem_qtyord * coitem_qty_invuomratio * (coitem_price - coitem_unitcost) / coitem_price_invuomratio,2)\n       END AS margin,\n       CASE WHEN (coitem_price = 0.0) THEN 0.0\n            ELSE ((coitem_price - coitem_unitcost) / coitem_price)\n       END AS marginpercent,\n       noNeg(coitem_qtyshipped - coitem_qtyreturned) AS qtyshipped,\n       noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS balance,\n       qtyAtShipping('SO', coitem_id) AS qtyatshipping,\n       ROUND((coitem_qtyord * coitem_qty_invuomratio) *\n             (coitem_price / coitem_price_invuomratio),2) AS extprice,\n       ROUND(((coitem_qtyshipped - coitem_qtyreturned) * coitem_qty_invuomratio) *\n              (coitem_price / coitem_price_invuomratio),2) AS extprice_shipped,\n       CASE WHEN coitem_order_type='W' THEN TEXT( 'WO')\n            WHEN coitem_order_type='P' THEN TEXT('PO' )\n            WHEN coitem_order_type='R' THEN TEXT('PR')\n            ELSE TEXT (' ')\n       END AS spplytype,\n       CASE WHEN coitem_order_type='W' THEN (wo_number || '-' || wo_subnumber)\n            WHEN coitem_order_type='P' THEN (pohead_number || '-' || poitem_linenumber)\n            WHEN coitem_order_type='R' THEN (pr_number || '-' || pr_subnumber)\n            ELSE TEXT (' ')\n       END AS ordrnumbr,\n       qtyAvailable(itemsite_id) AS availableqoh\n<? if exists("includeReservations") ?>\n       ,\n       coitem_qtyreserved AS reserved,\n       qtyAvailable(itemsite_id) - qtyReserved(itemsite_id) AS reservable\n<? endif?>\n  FROM cohead\n       JOIN coitem ON (coitem_cohead_id=cohead_id)\n       JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n       JOIN item ON (item_id=itemsite_item_id)\n       JOIN whsinfo ON (warehous_id=itemsite_warehous_id)\n       JOIN uom AS quom ON (quom.uom_id=coitem_qty_uom_id)\n       JOIN uom AS puom ON (puom.uom_id=coitem_price_uom_id)\n       LEFT OUTER JOIN itemalias ON ((itemalias_item_id=item_id) AND (itemalias_number=coitem_custpn))\n       LEFT OUTER JOIN wo ON (coitem_order_id = wo_id)\n       LEFT OUTER JOIN pr ON (coitem_order_id = pr_id)\n       LEFT OUTER JOIN (pohead JOIN poitem ON (pohead_id = poitem_pohead_id))\n         ON (coitem_order_id = poitem_id)\n WHERE (cohead_id=<? value("sohead_id") ?>)\n\n<? if exists("excludeCancelled") ?>\n AND (coitem_status != 'X')\n<? endif?>\n\n<? if exists("excludeClosed") ?>\n AND (coitem_status != 'C')\n<? endif?>\n\n<? if exists("excludeKits") ?>\n AND (item_type != 'K')\n<? endif?>\n\n) AS data\nORDER BY coitem_linenumber, coitem_subnumber;	admin	2015-10-01	0
420	contactmerge	deselect	 Removes contact selection\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: deselect\n-- Notes: Removes contact selection\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nDELETE FROM cntctsel\nWHERE (cntctsel_cntct_id=<? value("cntct_id") ?>);\n	admin	2015-10-01	0
104	taxHistory	detail	\n---------BEGIN SUMMARY----------\n Notes:\n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: taxHistory\n-- Name: detail\n-- Notes:\n-----------BEGIN SUMMARY----------\n-- Notes:\n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("summary") ?>\nSELECT <? literal("groupBy") ?>, \n  <? literal("groupBy") ?>_descrip AS description, \n  SUM(salesbase) AS salesbase,\n  SUM(freightbase) AS freightbase, \n  CASE WHEN (SUM(freighttax) > 0) THEN true ELSE false END AS freighttax, \n  SUM(salestaxbase) AS salestaxbase,\n  SUM(purchasebase) AS purchasebase,\n  SUM(purchasetaxbase) * -1 AS purchasetaxbase, \n  SUM(salestaxbase) + SUM(purchasetaxbase) AS nettaxbase,\n  'curr' AS salesbase_xtnumericrole,\n  'curr' AS freightbase_xtnumericrole,\n  'curr' AS salestaxbase_xtnumericrole,\n  'curr' AS purchasebase_xtnumericrole,\n  'curr' AS purchasetaxbase_xtnumericrole,\n  'curr' AS nettaxbase_xtnumericrole,\n  0 AS salestaxbase_xttotalrole,\n  0 AS purchasetaxbase_xttotalrole,\n  0 AS nettaxbase_xttotalrole\nFROM (\n<? endif ?>\n------------END SUMMARY--------------\n<? if exists("showSales") ?>\n------------BEGIN SALES--------------\n-- All sales tax history including memos \nSELECT \n  COALESCE(taxpay_distdate, taxhist_distdate) AS taxhist_distdate,\n  taxhist_journalnumber, tax_code AS tax, tax_descrip,\n  COALESCE(taxtype_name,<? value("none") ?>) AS taxtype, taxtype_descrip,\n  COALESCE(taxclass_code,<? value("none") ?>) AS taxclass, taxclass_descrip,\n  COALESCE(taxauth_code,<? value("none") ?>) AS taxauth, taxauth_name AS taxauth_descrip,\n  COALESCE(taxzone_code,<? value("none") ?>) AS taxzone, taxzone_descrip, curr_abbr, \n  cohist_invcnumber AS docnumber, \n  <? value("sales") ?> AS source,\n  CASE\n    WHEN (cohist_doctype='I') THEN\n      <? value("invoice") ?>\n    WHEN (cohist_doctype='C') THEN\n      <? value("creditmemo") ?> \n    WHEN (cohist_doctype='D') THEN\n      <? value("debitmemo") ?>\n    ELSE\n      <? value("other") ?>\n  END AS doctype,\n  item_number, COALESCE(item_descrip1,cohist_misc_descrip) AS description,\n  CASE\n    WHEN (cohist_doctype != 'C') THEN\n      cohist_ordernumber \n  END AS ordernumber, cohist_invcdate AS docdate,\n  cust_name AS name,\n  cohist_qtyshipped AS qty, \n  cohist_unitprice AS unitprice, (cohist_qtyshipped * cohist_unitprice) AS amount,\n  CASE\n    WHEN (cohist_misc_type IS NULL OR cohist_misc_type IN ('M','F')) THEN\n      currToBase(cohist_curr_id, cohist_qtyshipped * cohist_unitprice, cohist_invcdate) \n    ELSE 0\n  END AS salesbase,\n  CASE\n    WHEN (cohist_misc_type = 'F') THEN\n      currToBase(cohist_curr_id, cohist_qtyshipped * cohist_unitprice, cohist_invcdate) \n    ELSE 0\n  END AS freightbase,\n  CASE\n    WHEN (cohist_misc_type = 'F') THEN\n      COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate\n    ELSE 0\n  END AS freighttax,\n  0 AS purchasebase,\n  COALESCE(taxpay_tax, taxhist_tax) AS taxlocal,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS taxbase,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS salestaxbase,\n  0 AS purchasetaxbase,\n  'qty' AS qty_xtnumericrole,\n  'saleprice' AS unitprice_xtnumericrole,\n  'extprice' AS amount_xtnumericrole,\n  'curr' AS taxhist_tax_xtnumericrole,\n  'curr' AS taxbase_xtnumericrole,\n   0 AS taxbase_xttotalrole\nFROM cohisttax\n JOIN cohist ON (cohist_id=taxhist_parent_id)\n JOIN custinfo ON (cohist_cust_id=cust_id)\n JOIN taxtype ON (taxtype_id=taxhist_taxtype_id)\n JOIN tax ON (tax_id=taxhist_tax_id)\n JOIN curr_symbol ON (curr_id=taxhist_curr_id)\n LEFT OUTER JOIN taxclass ON (tax_taxclass_id=taxclass_id)\n LEFT OUTER JOIN taxauth ON (tax_taxauth_id=taxauth_id)\n LEFT OUTER JOIN taxzone ON (cohist_taxzone_id=taxzone_id)\n LEFT OUTER JOIN itemsite ON (cohist_itemsite_id=itemsite_id)\n LEFT OUTER JOIN item ON (itemsite_item_id=item_id)\n LEFT OUTER JOIN taxpay ON (taxpay_taxhist_id=taxhist_id)\nWHERE ((true)\n<? if exists("distDate") ?>\n AND (taxhist_distdate BETWEEN <? value("startDate") ?>\n                           AND <? value("endDate") ?>)\n<? else ?>\n AND (taxhist_docdate BETWEEN <? value("startDate") ?>\n                          AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("tax_id") ?>\n AND (taxhist_tax_id=<? value("tax_id") ?>)\n<? endif ?>\n<? if exists("taxtype_id") ?>\n AND (taxhist_taxtype_id=<? value("taxtype_id") ?>)\n<? endif ?>\n<? if exists("taxclass_id") ?>\n AND (taxclass_id=<? value("taxclass_id") ?>)\n<? endif ?>\n<? if exists("taxauth_id") ?>\n AND (taxauth_id=<? value("taxauth_id") ?>)\n<? endif ?>\n<? if exists("taxzone_id") ?>\n AND (taxzone_id=<? value("taxzone_id") ?>)\n<? endif ?>\n<? if exists("cashbasedtax") ?>\n AND (taxpay_id IS NOT NULL)\n<? endif ?>\n)\n<? endif ?>\n--------------END SALES--------------------\n<? if exists("showPurchases") ?>\n<? if exists("showSales") ?>\n-- Union because sales and purchase shown together\nUNION ALL\n<? endif ?>\n<? endif ?>\n------------BEGIN PURCHASE----------------\n<? if exists("showPurchases") ?>\n-- A/P Memo history\nSELECT \n  COALESCE(taxpay_distdate, taxhist_distdate) AS taxhist_distdate,\n  taxhist_journalnumber, tax_code AS tax, tax_descrip,\n  COALESCE(taxtype_name,<? value("none") ?>) AS taxtype, taxtype_descrip,\n  COALESCE(taxclass_code,<? value("none") ?>) AS taxclass, taxclass_descrip,\n  COALESCE(taxauth_code,<? value("none") ?>) AS taxauth, taxauth_name AS taxauth_descrip,\n  <? value("none") ?> AS taxzone,'' AS taxzone_descrip, curr_abbr, \n  apopen_docnumber AS docnumber, \n  <? value("purchase") ?> AS source,\n  CASE\n    WHEN (apopen_doctype='C') THEN\n      <? value("creditmemo") ?> \n    WHEN (apopen_doctype='D') THEN\n      <? value("debitmemo") ?>\n    ELSE\n      <? value("other") ?>\n  END AS doctype,\n  '' AS item_number, apopen_notes AS description,\n  apopen_ponumber AS ordernumber, apopen_docdate AS docdate,\n  vend_name AS name, \n  1 AS qty, \n  apopen_amount AS unitprice, \n  apopen_amount - ABS(COALESCE(taxpay_tax, taxhist_tax)) AS amount,\n  0 AS salesbase,\n  0 AS freightbase,\n  0 AS freighttax,\n  (apopen_amount / apopen_curr_rate) - ABS(COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate) AS purchasebase,\n  COALESCE(taxpay_tax, taxhist_tax) AS taxlocal,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS taxbase,\n  0 AS salestaxbase,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS purchasetaxbase,\n  'qty' AS qty_xtnumericrole,\n  'purchaseprice' AS unitprice_xtnumericrole,\n  'extprice' AS extension_xtnumericrole,\n  'curr' AS taxhist_tax_xtnumericrole,\n  'curr' AS taxbase_xtnumericrole,\n   0 AS taxbase_xttotalrole\nFROM apopentax\n JOIN apopen ON (apopen_id=taxhist_parent_id)\n JOIN vendinfo ON (apopen_vend_id=vend_id)\n JOIN taxtype ON (taxtype_id=taxhist_taxtype_id)\n JOIN tax ON (tax_id=taxhist_tax_id)\n JOIN curr_symbol ON (curr_id=taxhist_curr_id)\n LEFT OUTER JOIN taxclass ON (tax_taxclass_id=taxclass_id)\n LEFT OUTER JOIN taxauth ON (tax_taxauth_id=taxauth_id)\n LEFT OUTER JOIN taxpay ON (taxpay_taxhist_id=taxhist_id)\nWHERE ((true)\n<? if exists("distDate") ?>\n AND (taxhist_distdate BETWEEN <? value("startDate") ?>\n                           AND <? value("endDate") ?>)\n<? else ?>\n AND (taxhist_docdate BETWEEN <? value("startDate") ?>\n                          AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("tax_id") ?>\n AND (taxhist_tax_id=<? value("tax_id") ?>)\n<? endif ?>\n<? if exists("taxtype_id") ?>\n AND (taxhist_taxtype_id=<? value("taxtype_id") ?>)\n<? endif ?>\n<? if exists("taxclass_id") ?>\n AND (taxclass_id=<? value("taxclass_id") ?>)\n<? endif ?>\n<? if exists("taxauth_id") ?>\n AND (taxauth_id=<? value("taxauth_id") ?>)\n<? endif ?>\n<? if exists("taxzone_id") ?>\n AND (false)\n<? endif ?>\n AND (taxhist_distdate IS NOT NULL)\n<? if exists("cashbasedtax") ?>\n AND (taxpay_id IS NOT NULL)\n<? endif ?>\n)\nUNION ALL\n--Voucher Header History\nSELECT \n  COALESCE(taxpay_distdate, taxhist_distdate) AS taxhist_distdate,\n  taxhist_journalnumber, tax_code AS tax, tax_descrip,\n  COALESCE(taxtype_name,<? value("none") ?>) AS taxtype, taxtype_descrip,\n  COALESCE(taxclass_code,<? value("none") ?>) AS taxclass, taxclass_descrip,\n  COALESCE(taxauth_code,<? value("none") ?>) AS taxauth, taxauth_name AS taxauth_descrip,\n  COALESCE(taxzone_code,<? value("none") ?>) AS taxzone, taxzone_descrip, curr_abbr, \n  vohead_number AS docnumber, \n  <? value("purchase") ?> AS source,\n  <? value("voucher") ?>  AS doctype,\n  '', vohead_notes AS description,\n  pohead_number AS ordernumber, vohead_docdate AS docdate,\n  vend_name AS name, \n  1 AS qty, \n  0 AS unitprice, \n  vohead_amount - ABS(COALESCE(taxpay_tax, taxhist_tax)) AS amount,\n  0 AS salesbase,\n  0 AS freightbase,\n  0 AS freighttax,\n  (vohead_amount / taxhist_curr_rate) - ABS(COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate) AS purchasebase,\n  COALESCE(taxpay_tax, taxhist_tax) AS taxlocal,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS taxbase,\n  0 AS salestaxbase,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS purchasetaxbase,\n  'qty' AS qty_xtnumericrole,\n  'purchaseprice' AS unitprice_xtnumericrole,\n  'extprice' AS amount_xtnumericrole,\n  'curr' AS taxhist_tax_xtnumericrole,\n  'curr' AS taxbase_xtnumericrole,\n   0 AS taxbase_xttotalrole\nFROM voheadtax\n JOIN vohead ON (vohead_id=taxhist_parent_id)\n LEFT OUTER JOIN pohead ON (vohead_pohead_id=pohead_id)\n JOIN vendinfo ON (vohead_vend_id=vend_id)\n JOIN taxtype ON (taxtype_id=taxhist_taxtype_id)\n JOIN tax ON (tax_id=taxhist_tax_id)\n JOIN curr_symbol ON (curr_id=taxhist_curr_id)\n LEFT OUTER JOIN taxclass ON (tax_taxclass_id=taxclass_id)\n LEFT OUTER JOIN taxauth ON (tax_taxauth_id=taxauth_id)\n LEFT OUTER JOIN taxzone ON (vohead_taxzone_id=taxzone_id)\n LEFT OUTER JOIN taxpay ON (taxpay_taxhist_id=taxhist_id)\nWHERE ((true)\n<? if exists("distDate") ?>\n AND (taxhist_distdate BETWEEN <? value("startDate") ?>\n                           AND <? value("endDate") ?>)\n<? else ?>\n AND (taxhist_docdate BETWEEN <? value("startDate") ?>\n                          AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("tax_id") ?>\n AND (taxhist_tax_id=<? value("tax_id") ?>)\n<? endif ?>\n<? if exists("taxtype_id") ?>\n AND (taxhist_taxtype_id=<? value("taxtype_id") ?>)\n<? endif ?>\n<? if exists("taxclass_id") ?>\n AND (taxclass_id=<? value("taxclass_id") ?>)\n<? endif ?>\n<? if exists("taxauth_id") ?>\n AND (taxauth_id=<? value("taxauth_id") ?>)\n<? endif ?>\n<? if exists("taxzone_id") ?>\n AND (taxzone_id=<? value("taxzone_id") ?>)\n<? endif ?>\n AND (taxhist_distdate IS NOT NULL)\n<? if exists("cashbasedtax") ?>\n AND (taxpay_id IS NOT NULL)\n<? endif ?>\n)\nUNION ALL\n--Voucher Line Item\nSELECT \n  COALESCE(taxpay_distdate, taxhist_distdate) AS taxhist_distdate,\n  taxhist_journalnumber, tax_code AS tax, tax_descrip,\n  COALESCE(taxtype_name,<? value("none") ?>) AS taxtype, taxtype_descrip,\n  COALESCE(taxclass_code,<? value("none") ?>) AS taxclass, taxclass_descrip,\n  COALESCE(taxauth_code,<? value("none") ?>) AS taxauth, taxauth_name AS taxauth_descrip,\n  COALESCE(taxzone_code,<? value("none") ?>) AS taxzone, taxzone_descrip, curr_abbr, \n  vohead_number AS docnumber, \n  <? value("purchase") ?> AS source,\n  <? value("voucher") ?>  AS doctype,\n  COALESCE(item_number,expcat_code), COALESCE(item_descrip1,expcat_descrip) AS description,\n  pohead_number AS ordernumber, vohead_docdate AS docdate,\n  vend_name AS name, \n  voitem_qty AS qty, \n  COALESCE(SUM(vodist_amount),0)/voitem_qty AS unitprice, COALESCE(SUM(vodist_amount),0) AS amount,\n  0 AS salesbase,\n  0 AS freightbase,\n  0 AS freighttax,\n  currToBase(vohead_curr_id, COALESCE(SUM(vodist_amount),0), vohead_distdate)  AS purchasebase,\n  COALESCE(taxpay_tax, taxhist_tax) AS taxlocal,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS taxbase,\n  0 AS salestaxbase,\n  COALESCE(taxpay_tax, taxhist_tax) / taxhist_curr_rate AS purchasetaxbase,\n  'qty' AS qty_xtnumericrole,\n  'purchaseprice' AS unitprice_xtnumericrole,\n  'extprice' AS amount_xtnumericrole,\n  'curr' AS taxhist_tax_xtnumericrole,\n  'curr' AS taxbase_xtnumericrole,\n   0 AS taxbase_xttotalrole\nFROM voitemtax\n JOIN voitem ON (voitem_id=taxhist_parent_id)\n JOIN vohead ON (vohead_id=voitem_vohead_id)\n JOIN pohead ON (vohead_pohead_id=pohead_id)\n JOIN poitem ON (voitem_poitem_id=poitem_id)\n JOIN vodist ON ((vodist_poitem_id=poitem_id)\n            AND  (vodist_vohead_id=vohead_id))\n JOIN vendinfo ON (vohead_vend_id=vend_id)\n JOIN taxtype ON (taxtype_id=taxhist_taxtype_id)\n JOIN tax ON (tax_id=taxhist_tax_id)\n JOIN curr_symbol ON (curr_id=taxhist_curr_id)\n LEFT OUTER JOIN taxclass ON (tax_taxclass_id=taxclass_id)\n LEFT OUTER JOIN taxauth ON (tax_taxauth_id=taxauth_id)\n LEFT OUTER JOIN taxzone ON (vohead_taxzone_id=taxzone_id)\n LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)\n LEFT OUTER JOIN item ON (itemsite_item_id=item_id)\n LEFT OUTER JOIN expcat ON (expcat_id=poitem_expcat_id)\n LEFT OUTER JOIN taxpay ON (taxpay_taxhist_id=taxhist_id)\nWHERE ((true)\n<? if exists("distDate") ?>\n AND (taxhist_distdate BETWEEN <? value("startDate") ?>\n                           AND <? value("endDate") ?>)\n<? else ?>\n AND (taxhist_docdate BETWEEN <? value("startDate") ?>\n                          AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("tax_id") ?>\n AND (taxhist_tax_id=<? value("tax_id") ?>)\n<? endif ?>\n<? if exists("taxtype_id") ?>\n AND (taxhist_taxtype_id=<? value("taxtype_id") ?>)\n<? endif ?>\n<? if exists("taxclass_id") ?>\n AND (taxclass_id=<? value("taxclass_id") ?>)\n<? endif ?>\n<? if exists("taxauth_id") ?>\n AND (taxauth_id=<? value("taxauth_id") ?>)\n<? endif ?>\n<? if exists("taxzone_id") ?>\n AND (taxzone_id=<? value("taxzone_id") ?>)\n<? endif ?>\n AND (taxhist_distdate IS NOT NULL)\n<? if exists("cashbasedtax") ?>\n AND (taxpay_id IS NOT NULL)\n<? endif ?>\n)\nGROUP BY taxhist_id, taxpay_distdate,taxhist_distdate,tax_code,tax_descrip,\n  taxtype_name,taxtype_descrip,taxclass_code,taxclass_descrip,\n  taxauth_code,taxauth_descrip,taxzone,taxzone_descrip,curr_abbr,\n  vohead_number,pohead_number,item_number,item_descrip1,\n  vohead_curr_id,vohead_distdate,vohead_docdate,vend_name,\n  expcat_code,expcat_descrip,taxhist_tax,taxhist_curr_rate,\n  voitem_qty, taxhist_journalnumber, taxpay_tax\n<? endif ?>\n-------------END PURCHASE--------------\nORDER BY docdate DESC, docnumber DESC\n\n<? if exists("summary") ?>\n) AS data\nGROUP BY <? literal("groupBy") ?>, <? literal("groupBy") ?>_descrip\nORDER BY <? literal("groupBy") ?>\n<? endif ?>\n\n	admin	2015-10-01	0
415	glseries	postjournal	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: glseries\n-- Name:  postjournal\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT postJournals(<? value("sequence") ?>) AS result;\n	admin	2015-10-01	0
429	invoices	print	 used by printInvoices\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: invoices\n-- Name: print\n-- Notes: used by printInvoices\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT invchead_id,          invchead_id         AS docid,\n       invchead_invcnumber,  invchead_invcnumber AS docnumber,\n       invchead_ordernumber, invchead_posted     AS posted,\n       findCustomerForm(invchead_cust_id, 'I')   AS reportname\n  FROM invchead\n  WHERE (NOT invchead_printed)\n    AND (NOT invchead_posted)\n    AND (checkInvoiceSitePrivs(invchead_id))\n<? if exists("shipvia") ?>\n    AND (invchead_shipvia=<? value("shipvia") ?>) \n<? endif ?>\nORDER BY invchead_ordernumber;\n	admin	2015-10-01	0
51	inventoryAvailability	byCustOrSO	 query to get item availability by either customer id/type/pattern\n        or by cohead_id\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: inventoryAvailability\n-- Name:  byCustOrSO\n-- Notes: query to get item availability by either customer id/type/pattern\n--        or by cohead_id\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT id, altid, cohead_id,\n       item_number, descrip, uom_name,\n       qoh, sobalance, allocated, ordered,\n       atshipping,\n       CASE WHEN (xtindentrole=1) THEN\n<? if exists("useReservationNetting") ?>\n                  coitem_qtyreserved\n<? else ?>\n                  (qoh + ordered - sobalance)\n<? endif ?>\n            WHEN (xtindentrole=2) THEN (qoh + ordered - sobalance)\n       END AS orderavail,\n       (qoh + ordered - allocated) AS totalavail,\n       orderdate, duedate,\n       reorderlevel,\n<? if exists("sohead_id") ?> (xtindentrole - 1) AS <? endif ?> xtindentrole, \n       'qty' AS qoh_xtnumericrole,\n       'qty' AS sobalance_xtnumericrole,\n       'qty' AS allocated_xtnumericrole,\n       'qty' AS ordered_xtnumericrole,\n       'qty' AS orderavail_xtnumericrole,\n       'qty' AS totalavail_xtnumericrole,\n       'qty' AS atshipping_xtnumericrole,\n       CASE WHEN (pack_id IS NOT NULL) THEN 'altemphasis'\n       END AS qtforegroundrole,\n       CASE WHEN (qoh < 0) THEN 'error'\n            WHEN (qoh < reorderlevel) THEN 'warning'\n       END AS qoh_qtforegroundrole,\n       CASE WHEN (\n<? if exists("useReservationNetting") ?>\n                  coitem_qtyreserved < 0\n<? else ?>\n                  (qoh + ordered - sobalance) < 0\n<? endif ?>\n                 ) THEN 'error'\n            WHEN ((qoh + ordered - sobalance) <= reorderlevel) THEN 'warning'\n       END AS orderavail_qtforegroundrole,\n       CASE WHEN ((qoh + ordered - allocated) < 0) THEN 'error'\n            WHEN ((qoh + ordered - allocated) <= reorderlevel) THEN 'warning'\n       END AS totalavail_qtforegroundrole,\n       CASE WHEN (xtindentrole = 2 AND (orderdate <= CURRENT_DATE)\n              AND (descrip IN ('O','E','S','R'))) THEN 'error'\n       END AS atshipping_qtforegroundrole,\n       CASE WHEN (xtindentrole = 2 AND duedate<=CURRENT_DATE) THEN 'error'\n       END AS orderdate_qtforegroundrole,\n       CASE WHEN (xtindentrole = 2 AND duedate<=CURRENT_DATE) THEN 'error'\n       END AS duedate_qtforegroundrole,\n<? if exists("useReservationNetting") ?>\n       CASE WHEN (coitem_qtyreserved > 0\n              AND sobalance > coitem_qtyreserved) THEN 'emphasis'\n            WHEN ((sobalance <> 0)\n              AND ((sobalance - coitem_qtyreserved) = 0)) THEN 'altemphasis'\n       END AS qtforegroundrole,\n<? endif ?>\n       CASE WHEN (xtindentrole = 2) THEN ''\n       END AS sobalance_qtdisplayrole\nFROM (\n<? if not exists("sohead_id") ?>\n    SELECT cohead_id AS id, -2 AS altid, cohead_id, cohead_number,\n           cohead_number AS item_number,\n           '' AS trueitem_number,\n           (cust_number||'-'||cust_name) AS descrip,\n           '' AS uom_name, CAST(NULL AS NUMERIC) AS qoh,\n           CAST(NULL AS NUMERIC) AS sobalance,\n           CAST(NULL AS NUMERIC) AS allocated,\n           CAST(NULL AS NUMERIC) AS ordered,\n           CAST(NULL AS NUMERIC) AS atshipping,\n           CAST(NULL AS NUMERIC) AS coitem_qtyreserved,\n           cohead_orderdate AS orderdate, MIN(coitem_scheddate) AS duedate,\n           pack_id,\n           CAST(NULL AS NUMERIC) AS reorderlevel,\n           0 AS xtindentrole\n     FROM cohead\n     LEFT OUTER JOIN pack ON (pack_head_type='SO' AND pack_head_id=cohead_id)\n     JOIN custinfo ON (cohead_cust_id=cust_id)\n     JOIN coitem   ON (coitem_cohead_id=cohead_id)\n     JOIN itemsite ON (coitem_itemsite_id=itemsite_id)\n     WHERE ((coitem_status NOT IN ('C', 'X'))\n  <? if exists("custtype_id") ?>\n        AND (cust_custtype_id=<? value("custtype_id") ?>)\n  <? elseif exists("custtype_pattern") ?>\n        AND (cust_custtype_id IN (SELECT custtype_id\n                                  FROM custtype\n                                  WHERE(custtype_code ~ <? value("custtype_pattern") ?>)))\n  <? endif ?>\n      )\n      GROUP BY cohead_id, item_number, cust_number,\n               cust_name, cohead_orderdate, pack_id, coitem_scheddate\n  <? if exists("onlyShowShortages") ?>\n      HAVING (MIN(noNeg(qtyAvailable(itemsite_id)) +\n                  qtyOrdered(itemsite_id, coitem_scheddate) -\n                  qtyAllocated(itemsite_id, coitem_scheddate)) < 0\n              OR MIN(noNeg(qtyAvailable(itemsite_id)) +\n                  qtyOrdered(itemsite_id, coitem_scheddate) -\n                  noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned)) < 0\n           )\n  <? endif ?>\n    UNION\n<? endif ?>\n    SELECT itemsite_id AS id, coitem_id AS altid, cohead_id, cohead_number,\n            item_number,\n            item_number AS trueitem_number,\n            (item_descrip1 || ' ' || item_descrip2) AS descrip,\n            uom_name, noNeg(qtyAvailable(itemsite_id)) AS qoh,\n            noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS sobalance,\n            qtyAllocated(itemsite_id, coitem_scheddate) AS allocated,\n            qtyOrdered(itemsite_id, coitem_scheddate) AS ordered,\n            qtyatshipping(coitem_id) AS atshipping,\n            itemuomtouom(item_id, coitem_qty_uom_id, null, coitem_qtyreserved) AS coitem_qtyreserved,\n            CAST(NULL AS DATE) AS orderdate, coitem_scheddate AS duedate,\n            CAST(NULL AS INTEGER) AS pack_id,\n            CASE WHEN(itemsite_useparams) THEN itemsite_reorderlevel\n                 ELSE 0.0 END AS reorderlevel,\n            1 AS xtindentrole\n     FROM cohead\n<? if not exists("sohead_id") ?> JOIN custinfo ON (cohead_cust_id=cust_id)<? endif ?>\n          , itemsite, item, uom, site(), coitem\n     WHERE ((coitem_cohead_id=cohead_id)\n        AND (coitem_itemsite_id=itemsite_id)\n        AND (itemsite_warehous_id=warehous_id)\n        AND (itemsite_item_id=item_id)\n        AND (item_inv_uom_id=uom_id)\n        AND (coitem_status NOT IN ('C', 'X'))\n<? if exists("sohead_id") ?>\n        AND (cohead_id=<? value("sohead_id") ?>)\n<? elseif exists("custtype_id") ?>\n        AND (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n        AND (cust_custtype_id IN (SELECT custtype_id\n                                  FROM custtype\n                                  WHERE(custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n<? if exists("onlyShowShortages") ?>\n        AND ((noNeg(qtyAvailable(itemsite_id)) + qtyOrdered(itemsite_id, coitem_scheddate) - qtyAllocated(itemsite_id, coitem_scheddate) < 0)\n          OR (noNeg(qtyAvailable(itemsite_id)) + qtyOrdered(itemsite_id, coitem_scheddate) - noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) < 0))\n<? endif ?>\n    )\n<? if exists("showWoSupply") ?>\n    UNION\n    SELECT  itemsite_id, -1, cohead_id, cohead_number,\n            formatwonumber(wo_id),\n            item_number AS trueitem_number,\n            wo_status,\n            NULL, NULL,\n            noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS sobalance,\n            NULL,\n            noNeg((wo_qtyord-wo_qtyrcv)) AS ordered,\n            NULL,\n            NULL,\n            wo_startdate, wo_duedate,\n            NULL AS pack_id,\n            CASE WHEN(itemsite_useparams) THEN itemsite_reorderlevel\n                 ELSE 0.0 END AS reorderlevel,\n            2 AS xtindentrole\n     FROM cohead\n<? if not exists("sohead_id") ?> JOIN custinfo ON (cohead_cust_id=cust_id)<? endif ?>\n          , itemsite, item, uom, site(), coitem\n          LEFT OUTER JOIN wo\n           ON ((coitem_itemsite_id=wo_itemsite_id)\n           AND (wo_status IN ('E','R','I'))\n           AND (wo_qtyord-wo_qtyrcv > 0)\n           AND (noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned-qtyatshipping(coitem_id)) >\n            (SELECT qtyAvailable(itemsite_id) FROM itemsite WHERE (itemsite_id=coitem_itemsite_id))))\n     WHERE ((coitem_cohead_id=cohead_id)\n        AND (coitem_itemsite_id=itemsite_id)\n        AND (itemsite_warehous_id=warehous_id)\n        AND (itemsite_item_id=item_id)\n        AND (item_inv_uom_id=uom_id)\n        AND (coitem_status NOT IN ('C', 'X'))\n  <? if exists("sohead_id") ?>\n        AND (cohead_id=<? value("sohead_id") ?>)\n  <? elseif exists("custtype_id") ?>\n        AND (cust_custtype_id=<? value("custtype_id") ?>)\n  <? elseif exists("custtype_pattern") ?>\n        AND (cust_custtype_id IN (SELECT custtype_id\n                                  FROM custtype\n                                  WHERE(custtype_code ~ <? value("custtype_pattern") ?>)))\n  <? endif ?>\n  <? if exists("onlyShowShortages") ?>\n        AND ((noNeg(qtyAvailable(itemsite_id)) + qtyOrdered(itemsite_id, coitem_scheddate) - qtyAllocated(itemsite_id, coitem_scheddate) < 0)\n          OR (noNeg(qtyAvailable(itemsite_id)) + qtyOrdered(itemsite_id, coitem_scheddate) - noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) < 0))\n  <? endif ?>\n  )\n<? endif ?>\n) AS data\nORDER BY duedate, cohead_number, trueitem_number,\n         xtindentrole;\n	admin	2015-10-01	0
54	inventoryHistory	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: inventoryHistory\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT invhist_id, invdetail_id, invhist_transdate AS sortdate,\n       formatDateTime(invhist_transdate) AS transdate,\n       CASE WHEN (level=0) THEN invhist_transdate END AS invhist_transdate,\n       CASE WHEN (level=0) THEN invhist_created END AS invhist_created,\n       CASE WHEN (level=0) THEN invhist_user END AS invhist_user,\n       CASE WHEN (level=0) THEN invhist_transtype END AS invhist_transtype,\n       CASE WHEN (level=0) THEN warehous_code END AS warehous_code,\n       CASE WHEN (level=0) THEN ordernumber\n            ELSE locationname\n       END AS orderlocation,\n       CASE WHEN (level=0) THEN item_number END AS item_number,\n       CASE WHEN (level=0) THEN invhist_invuom END AS invhist_invuom,\n       CASE WHEN (level=0 AND invhist_transtype IN ('EX','IM','SH','SI')) THEN (invhist_invqty * -1.0)\n            WHEN (level=0) THEN invhist_invqty\n            ELSE invdetail_qty\n       END AS transqty,\n       CASE WHEN (level=0) THEN invhist_value_after - invhist_value_before\n       END AS transvalue,\n       CASE WHEN (level=0) THEN locfrom END AS locfrom,\n       CASE WHEN (level=0) THEN invhist_qoh_before\n            ELSE invdetail_qty_before\n       END AS qohbefore,\n       CASE WHEN (level=0) THEN locto END AS locto,\n       CASE WHEN (level=0) THEN invhist_qoh_after\n            ELSE invdetail_qty_after\n       END AS qohafter,\n       CASE WHEN (level=0) THEN costmethod END AS costmethod,\n       CASE WHEN (level=0) THEN invhist_value_before END AS invhist_value_before,\n       CASE WHEN (level=0) THEN invhist_value_after END AS invhist_value_after,\n       'qty' AS transqty_xtnumericrole,\n       'curr' AS transvalue_xtnumericrole,\n       0 AS transvalue_xttotalrole,\n       'qty' AS qohbefore_xtnumericrole,\n       'qty' AS qohafter_xtnumericrole,\n       'curr' AS invhist_value_before_xtnumericrole,\n       'curr' AS invhist_value_after_xtnumericrole,\n       CASE WHEN (NOT invhist_posted) THEN NULL END AS qohbefore_qtdisplayrole,\n       CASE WHEN (NOT invhist_posted) THEN NULL END AS qohafter_qtdisplayrole,\n       CASE WHEN (NOT invhist_posted) THEN NULL END AS invhist_value_before_qtdisplayrole,\n       CASE WHEN (NOT invhist_posted) THEN NULL END AS invhist_value_after_qtdisplayrole,\n       CASE WHEN (NOT invhist_posted) THEN NULL END AS costmethod_qtdisplayrole,\n       CASE WHEN (NOT invhist_posted) THEN NULL END AS locto_qtdisplayrole,\n       CASE WHEN (NOT invhist_posted) THEN NULL END AS locfrom_qtdisplayrole,\n       CASE WHEN (NOT invhist_posted) THEN 'warning' END AS qtforegroundrole,\n       level AS xtindentrole\nFROM (\nSELECT invhist.*, 0 AS level,\n       whs1.warehous_code AS warehous_code, item_number,\n       CASE WHEN (invhist_ordtype NOT LIKE '') THEN (invhist_ordtype || '-' || invhist_ordnumber)\n            ELSE invhist_ordnumber\n       END AS ordernumber,\n       CASE WHEN (invhist_costmethod='A') THEN <? value("average") ?>\n            WHEN (invhist_costmethod='S') THEN <? value("standard") ?>\n            WHEN (invhist_costmethod='J') THEN <? value("job") ?>\n            WHEN (invhist_costmethod='N') THEN <? value("none") ?>\n            ELSE <? value("unknown") ?>\n       END AS costmethod,\n       0 AS invdetail_id, '' AS locationname,\n       0 AS invdetail_qty, 0 AS invdetail_qty_before, 0 AS invdetail_qty_after,\n       CASE WHEN (invhist_transtype='TW' AND invhist_invqty < 0) THEN whs1.warehous_code\n            WHEN (invhist_transtype='TW') THEN whs2.warehous_code\n            WHEN (invhist_transtype='AD' AND invhist_invqty < 0) THEN whs1.warehous_code\n            WHEN (invhist_transtype='AD') THEN 'ADJ'\n            WHEN (invhist_transtype='EX') THEN whs1.warehous_code\n            WHEN (invhist_transtype='IB') THEN whs1.warehous_code\n            WHEN (invhist_transtype='IM' AND invhist_invqty < 0) THEN 'WIP'\n            WHEN (invhist_transtype='IM') THEN whs1.warehous_code\n            WHEN (invhist_transtype='IT') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RB') THEN 'WIP'\n            WHEN (invhist_transtype='RM') THEN 'WIP'\n            WHEN (invhist_transtype='RP') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RR') THEN 'CUST'\n            WHEN (invhist_transtype='RS') THEN 'SHIP'\n            WHEN (invhist_transtype='SH') THEN whs1.warehous_code\n            WHEN (invhist_transtype='SI') THEN whs1.warehous_code\n            WHEN (invhist_transtype='SV') THEN whs1.warehous_code\n\t WHEN (invhist_transtype='TR') THEN whs2.warehous_code\n\t WHEN (invhist_transtype='TS') THEN whs1.warehous_code\n\t WHEN (invhist_transtype='RI') THEN whs1.warehous_code\n            ELSE ''\n       END AS locfrom,\n       CASE WHEN (invhist_transtype='TW' AND invhist_invqty < 0) THEN whs2.warehous_code\n            WHEN (invhist_transtype='TW') THEN whs1.warehous_code\n            WHEN (invhist_transtype='AD' AND invhist_invqty < 0) THEN 'ADJ'\n            WHEN (invhist_transtype='AD') THEN whs1.warehous_code\n            WHEN (invhist_transtype='CC') THEN whs1.warehous_code\n            WHEN (invhist_transtype='EX') THEN 'EXPENSE'\n            WHEN (invhist_transtype='IB') THEN 'WIP'\n            WHEN (invhist_transtype='IM' AND invhist_invqty < 0) THEN whs1.warehous_code\n            WHEN (invhist_transtype='IM') THEN 'WIP'\n            WHEN (invhist_transtype='NN') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RB') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RM') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RP') THEN 'PURCH'\n            WHEN (invhist_transtype='RR') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RS') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RT') THEN whs1.warehous_code\n            WHEN (invhist_transtype='RX') THEN whs1.warehous_code\n            WHEN (invhist_transtype='SH') THEN 'SHIP'\n            WHEN (invhist_transtype='SI') THEN 'SCRAP'\n            WHEN (invhist_transtype='SV') THEN 'SHIP'\n            WHEN (invhist_transtype='TR') THEN whs1.warehous_code\n            WHEN (invhist_transtype='TS') THEN whs2.warehous_code\n            WHEN (invhist_transtype='RI') THEN 'WIP'\n            ELSE ''\n       END AS locto \nFROM itemsite, item, whsinfo AS whs1, invhist\n  LEFT OUTER JOIN whsinfo AS whs2 ON (invhist_xfer_warehous_id=whs2.warehous_id)\nWHERE ( (invhist_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id) \n  AND  (itemsite_warehous_id=whs1.warehous_id)\n  AND  (DATE(invhist_transdate) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?> )\n  AND  (transType(invhist_transtype, <? value("transType") ?>))\n<? if exists("orderNumber") ?>\n  AND  (invhist_ordnumber ~ <? value("orderNumber") ?>)\n<? endif ?>\n<? if exists("cohead_id") ?>\n  AND  (invhist_ordtype='SO')\n  AND  (invhist_ordnumber ~ (\n    SELECT cohead_number \n    FROM cohead \n    WHERE cohead_id=<? value("cohead_id") ?>))\n<? endif ?>\n<? if exists("pohead_id") ?>\n  AND  (invhist_ordtype='PO')\n  AND  (invhist_ordnumber ~ (\n    SELECT pohead_number \n    FROM pohead \n    WHERE pohead_id=<? value("pohead_id") ?>))\n<? endif ?>\n<? if exists("tohead_id") ?>\n  AND  (invhist_ordtype='TO')\n  AND  (invhist_ordnumber ~ (\n    SELECT tohead_number \n    FROM tohead \n    WHERE tohead_id=<? value("tohead_id") ?>))\n<? endif ?>\n<? if exists("wo_id") ?>\n  AND  (invhist_ordtype='WO')\n  AND  (invhist_ordnumber ~ formatWoNumber(<? value("wo_id") ?>))\n<? endif ?>\n<? if exists("warehous_id") ?>\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("classcode_id") ?>\n  AND  (item_classcode_id=<? value("classcode_id") ?>)\n<? endif ?>\n<? if exists("itemgrp_id") ?>\n  AND (item_id IN (SELECT itemgrpitem_item_id\n\t\t   FROM itemgrpitem\n\t\t   WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))\n<? endif ?>\n<? if exists("plancode_id") ?>\n  AND  (itemsite_plancode_id=<? value("plancode_id") ?>)\n<? endif ?>\n<? if exists("classcode_pattern") ?>\n  AND  (item_classcode_id IN (SELECT classcode_id\n\t\t\t      FROM classcode\n\t\t\t      WHERE (classcode_code ~ <? value ("classcode_pattern") ?>)))\n<? endif ?>\n<? if exists("itemgrp_pattern") ?>\n  AND (item_id IN (SELECT itemgrpitem_item_id\n\t\t   FROM itemgrpitem, itemgrp\n\t\t   WHERE ( (itemgrpitem_itemgrp_id=itemgrp_id)\n\t\t     AND  (itemgrp_name ~ <? value ("itemgrp_pattern") ?>))))\n<? endif ?>\n<? if exists("plancode_pattern") ?>\n  AND (itemsite_plancode_id IN (SELECT plancode_id\n\t\t\t\tFROM plancode\n\t\t\t\tWHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n<? endif ?>\n<? if exists("itemgrp") ?>\n  AND (item_id IN (SELECT DISTINCT itemgrpitem_item_id FROM itemgrpitem))\n<? endif ?>\n) \nUNION SELECT invhist.*, 1 AS level,\n             '' AS warehous_code, '' AS item_number,\n             '' AS ordernumber,\n             '' AS costmethod,\n             invdetail_id,\n             CASE WHEN (invdetail_location_id=-1) THEN formatlotserialnumber(invdetail_ls_id)\n                  WHEN (invdetail_ls_id IS NULL) THEN formatLocationName(invdetail_location_id)\n                  ELSE (formatLocationName(invdetail_location_id) || '-' || formatlotserialnumber(invdetail_ls_id))\n             END AS locationname,\n             invdetail_qty, invdetail_qty_before, invdetail_qty_after,\n             '' AS locfrom,\n             '' AS locto \nFROM itemsite, item, whsinfo AS whs1, invdetail, invhist LEFT OUTER JOIN\n     whsinfo AS whs2 ON (invhist_xfer_warehous_id=whs2.warehous_id)\nWHERE ((invhist_hasdetail)\n  AND (invhist_itemsite_id=itemsite_id)\n  AND (itemsite_item_id=item_id)\n  AND (itemsite_warehous_id=whs1.warehous_id)\n  AND (invdetail_invhist_id=invhist_id)\n  AND  (DATE(invhist_transdate) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?> )\n  AND (transType(invhist_transtype, <? value("transType") ?>))\n<? if exists("orderType") ?>\n  AND  (invhist_ordtype=<? value("orderType") ?>)\n<? endif ?>\n<? if exists("orderNumber") ?>\n  AND  (invhist_ordnumber ~ <? value("orderNumber") ?>)\n<? endif ?>\n<? if exists("cohead_id") ?>\n  AND  (invhist_ordtype='SO')\n  AND  (invhist_ordnumber ~ (\n    SELECT cohead_number \n    FROM cohead \n    WHERE cohead_id=<? value("cohead_id") ?>))\n<? endif ?>\n<? if exists("pohead_id") ?>\n  AND  (invhist_ordtype='PO')\n  AND  (invhist_ordnumber ~ (\n    SELECT pohead_number \n    FROM pohead \n    WHERE pohead_id=<? value("pohead_id") ?>))\n<? endif ?>\n<? if exists("tohead_id") ?>\n  AND  (invhist_ordtype='TO')\n  AND  (invhist_ordnumber ~ (\n    SELECT tohead_number \n    FROM tohead \n    WHERE tohead_id=<? value("tohead_id") ?>))\n<? endif ?>\n<? if exists("wo_id") ?>\n  AND  (invhist_ordtype='WO')\n  AND  (invhist_ordnumber ~ formatWoNumber(<? value("wo_id") ?>))\n<? endif ?>\n<? if exists("warehous_id") ?>\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("classcode_id") ?>\n  AND  (item_classcode_id=<? value("classcode_id") ?>)\n<? endif ?>\n<? if exists("itemgrp_id") ?>\n  AND (item_id IN (SELECT itemgrpitem_item_id\n\t\t   FROM itemgrpitem\n\t\t   WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))\n<? endif ?>\n<? if exists("plancode_id") ?>\n  AND  (itemsite_plancode_id=<? value("plancode_id") ?>)\n<? endif ?>\n<? if exists("classcode_pattern") ?>\n  AND  (item_classcode_id IN (SELECT classcode_id\n\t\t\t      FROM classcode\n\t\t\t      WHERE (classcode_code ~ <? value ("classcode_pattern") ?>)))\n<? endif ?>\n<? if exists("itemgrp_pattern") ?>\n  AND (item_id IN (SELECT itemgrpitem_item_id\n\t\t   FROM itemgrpitem, itemgrp\n\t\t   WHERE ( (itemgrpitem_itemgrp_id=itemgrp_id)\n\t\t     AND  (itemgrp_name ~ <? value ("itemgrp_pattern") ?>))))\n<? endif ?>\n<? if exists("plancode_pattern") ?>\n  AND (itemsite_plancode_id IN (SELECT plancode_id\n\t\t\t\tFROM plancode\n\t\t\t\tWHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n<? endif ?>\n<? if exists("itemgrp") ?>\n  AND (item_id IN (SELECT DISTINCT itemgrpitem_item_id FROM itemgrpitem))\n<? endif ?>\n)\n\n   ) AS data\nORDER BY sortdate DESC, invhist_id, level;\n	admin	2015-10-01	0
59	maintainShipping	detail	 used by maintainShipping\n        order header info\n        Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: maintainShipping\n-- Name: detail\n-- Notes: used by maintainShipping\n--        order header info\n--        Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\n-- order header info\nSELECT shiphead_id AS parent_id, cohead_id AS child_id,\n       shiphead_number, cohead_number AS linenumber,\n       'SO' AS ordertype,\n       CASE WHEN (shiphead_sfstatus='N') THEN <? value("notPrinted") ?>\n            WHEN (shiphead_sfstatus='D') THEN <? value("dirty") ?>\n            WHEN (shiphead_sfstatus='P') THEN <? value("printed") ?>\n            ELSE <? value("error") ?>\n       END AS sfstatus,\n       cust_number AS dest, cust_name AS description,\n       shiphead_shipvia, NULL AS uom_name,\n       NULL AS shipqty, NULL AS shipvalue,\n<? if exists("includeFormatted") ?>\n       NULL AS f_shipqty, NULL AS f_shipvalue,\n<? endif ?>\n       cohead_holdtype AS holdtype,\n       shiphead_notes AS notes,\n       shiphead_number AS shiphead_number_qtdisplayrole,\n       'SO' AS ordertype_qtdisplayrole,\n       'qty' AS shipqty_xtnumericrole,\n       'cost' AS shipvalue_xtnumericrole,\n       0 AS shipvalue_xttotalrole,\n       0 AS xtindentrole,\n       shiphead_id AS seq1, shiphead_order_id AS seq2,\n       0 AS seq3, 0 AS seq4\nFROM shiphead, custinfo, cohead\n <? if exists("warehous_id") ?>\n      JOIN coitem ON (coitem_cohead_id=cohead_id)\n      JOIN itemsite ON ((coitem_itemsite_id=itemsite_id)\n                    AND (itemsite_warehous_id=<? value("warehous_id") ?>))\n <? endif ?>\nWHERE ((NOT shiphead_shipped)\n AND (shiphead_order_type='SO')\n AND (shiphead_order_id=cohead_id)\n AND (cohead_cust_id=cust_id)\n<? if exists("cust_id") ?>\n AND (cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("cohead_id") ?>\n AND (cohead_id=<? value("cohead_id") ?>)\n<? endif ?>\n) \n-- order line info\nUNION ALL\nSELECT cohead_id AS parent_id, coitem_id AS child_id,\n       '' AS shiphead_number, CAST(coitem_linenumber AS TEXT) AS linenumber,\n       'SO Item' AS ordertype,\n       NULL AS sfstatus,\n       item_number AS dest, (item_descrip1 || ' ' || item_descrip2) AS description,\n       NULL AS shiphead_shipvia, uom_name,\n       qtyAtShipping('SO', coitem_id) AS shipqty,\n       valueAtShipping('SO', coitem_id) AS shipvalue,\n<? if exists("includeFormatted") ?>\n       formatQty(qtyAtShipping('SO', coitem_id)) AS f_shipqty,\n       formatCost(valueAtShipping('SO', coitem_id)) AS f_shipvalue,\n<? endif ?>\n       cohead_holdtype AS holdtype,\n       '' as notes,\n       NULL AS shiphead_number_qtdisplayrole,\n       NULL AS ordertype_qtdisplayrole,\n       'qty' AS shipqty_xtnumericrole,\n       'cost' AS shipvalue_xtnumericrole,\n       0 AS shipvalue_xttotalrole,\n       1 AS xtindentrole,\n       shiphead_id AS seq1, shiphead_order_id AS seq2,\n       coitem_id AS seq3, 0 AS seq4\nFROM shiphead, cohead, coitem, uom, itemsite, item\nWHERE ((NOT shiphead_shipped)\n AND (shiphead_order_type='SO')\n AND (shiphead_order_id=cohead_id)\n AND (cohead_id=coitem_cohead_id)\n AND (coitem_qty_uom_id=uom_id)\n AND (coitem_itemsite_id=itemsite_id)\n AND (itemsite_item_id=item_id)\n <? if exists("warehous_id") ?>\n AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n <? endif ?>\n<? if exists("cust_id") ?>\n AND (cohead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("cohead_id") ?>\n AND (cohead_id=<? value("cohead_id") ?>)\n<? endif ?>\n) \n-- shipitem info\nUNION ALL\nSELECT shiphead_id AS parent_id, shipitem_id AS child_id,\n       '' AS shiphead_number, '' AS linenumber,\n       'SO Ship' AS ordertype,\n       NULL AS sfstatus,\n       '' AS dest,\n       formatDate(shipitem_transdate) || ' by ' || shipitem_trans_username AS description,\n       '' AS shiphead_shipvia, '' AS uom_name,\n       shipitem_qty AS shipqty,\n       NULL AS shipvalue,\n<? if exists("includeFormatted") ?>\n       formatQty(shipitem_qty) AS f_shipqty,\n       NULL AS f_shipvalue,\n<? endif ?>\n       '' AS holdtype,\n       '' AS notes,\n       NULL AS shiphead_number_qtdisplayrole,\n       NULL AS ordertype_qtdisplayrole,\n       'qty' AS shipqty_xtnumericrole,\n       'cost' AS shipvalue_xtnumericrole,\n       0 AS shipvalue_xttotalrole,\n       2 AS xtindentrole,\n       shiphead_id AS seq1, shiphead_order_id AS seq2,\n       shipitem_orderitem_id AS seq3, shipitem_id AS seq4\nFROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)\n              JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)\n <? if exists("warehous_id") ?>\n      JOIN coitem ON ((shipitem_orderitem_id=coitem_id)\n                  AND (shiphead_order_type='SO'))\n      JOIN itemsite ON ((coitem_itemsite_id=itemsite_id)\n                    AND (itemsite_warehous_id=<? value("warehous_id") ?>))\n <? endif ?>\nWHERE ((NOT shiphead_shipped)\n AND (shiphead_order_type='SO')\n<? if exists("cust_id") ?>\n AND (cohead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("cohead_id") ?>\n AND (cohead_id=<? value("cohead_id") ?>)\n<? endif ?>\n) \n<? if exists("includeDistributions") ?>\n-- distribution info\nUNION ALL\nSELECT shiphead_id AS parent_id, shipitem_id AS child_id,\n       '' AS shiphead_number, '' AS linenumber,\n       'SO Dist' AS ordertype,\n       NULL AS sfstatus,\n       formatLocationName(invdetail_location_id) AS dest,\n       formatLotSerialNumber(invdetail_ls_id) AS description,\n       formatDate(invdetail_expiration) AS shiphead_shipvia, '' AS uom_name,\n       invdetail_qty AS shipqty,\n       NULL AS shipvalue,\n<? if exists("includeFormatted") ?>\n       formatQty(invdetail_qty) AS f_shipqty,\n       NULL AS f_shipvalue,\n<? endif ?>\n       '' AS holdtype,\n       '' AS notes,\n       NULL AS shiphead_number_qtdisplayrole,\n       NULL AS ordertype_qtdisplayrole,\n       'qty' AS shipqty_xtnumericrole,\n       'cost' AS shipvalue_xtnumericrole,\n       0 AS shipvalue_xttotalrole,\n       3 AS xtindentrole,\n       shiphead_id AS seq1, shiphead_order_id AS seq2,\n       shipitem_orderitem_id AS seq3, shipitem_id AS seq4\nFROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)\n              JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)\n              LEFT OUTER JOIN invhist ON (invhist_id=shipitem_invhist_id)\n              LEFT OUTER JOIN invdetail ON (invdetail_invhist_id=invhist_id)\n <? if exists("warehous_id") ?>\n      JOIN coitem ON ((shipitem_orderitem_id=coitem_id)\n                  AND (shiphead_order_type='SO'))\n      JOIN itemsite ON ((coitem_itemsite_id=itemsite_id)\n                    AND (itemsite_warehous_id=<? value("warehous_id") ?>))\n <? endif ?>\nWHERE ((NOT shiphead_shipped)\n AND (shiphead_order_type='SO')\n<? if exists("cust_id") ?>\n AND (cohead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("cohead_id") ?>\n AND (cohead_id=<? value("cohead_id") ?>)\n<? endif ?>\n) \n<? endif ?>\n\n<? if exists("MultiWhs") ?>\nUNION ALL\n-- order header info\nSELECT shiphead_id AS parent_id, tohead_id AS child_id,\n       shiphead_number, tohead_number AS linenumber,\n       'TO' AS ordertype,\n       CASE WHEN (shiphead_sfstatus='N') THEN <? value("notPrinted") ?>\n            WHEN (shiphead_sfstatus='D') THEN <? value("dirty") ?>\n            WHEN (shiphead_sfstatus='P') THEN <? value("printed") ?>\n            ELSE <? value("error") ?>\n       END AS sfstatus,\n       tohead_destname AS dest, tohead_destcntct_name AS description,\n       shiphead_shipvia, NULL AS uom_name,\n       NULL AS shipqty, NULL AS shipvalue,\n<? if exists("includeFormatted") ?>\n       NULL AS f_shipqty, NULL AS f_shipvalue,\n<? endif ?>\n       'TO' AS holdtype,\n       shiphead_notes AS notes,\n       shiphead_number AS shiphead_number_qtdisplayrole,\n       'TO' AS ordertype_qtdisplayrole,\n       'qty' AS shipqty_xtnumericrole,\n       'cost' AS shipvalue_xtnumericrole,\n       0 AS shipvalue_xttotalrole,\n       0 AS xtindentrole,\n       shiphead_id AS seq1, shiphead_order_id AS seq2,\n       0 AS seq3, 0 AS seq4\nFROM shiphead, tohead\n <? if exists("warehous_id") ?>\n      JOIN toitem ON (toitem_tohead_id=tohead_id)\n      JOIN itemsite ON ((toitem_item_id=itemsite_item_id)\n                    AND (itemsite_warehous_id=<? value("warehous_id") ?>))\n <? endif ?>\nWHERE ((NOT shiphead_shipped)\n AND (shiphead_order_type='TO')\n AND (shiphead_order_id=tohead_id)\n<? if exists("cust_id") ?>\n AND FALSE\n<? endif ?>\n<? if exists("cohead_id") ?>\n AND FALSE\n<? endif ?>\n) \n-- order line info\nUNION ALL\nSELECT tohead_id AS parent_id, toitem_id AS child_id,\n       '' AS shiphead_number, CAST(toitem_linenumber AS TEXT) AS linenumber,\n       'TO' AS ordertype,\n       NULL AS sfstatus,\n       item_number AS dest, (item_descrip1 || ' ' || item_descrip2) AS description,\n       NULL AS shiphead_shipvia, toitem_uom AS uom_name,\n       qtyAtShipping('TO', toitem_id) AS shipqty,\n       valueAtShipping('TO', toitem_id) AS shipvalue,\n<? if exists("includeFormatted") ?>\n       formatQty(qtyAtShipping('TO', toitem_id)) AS f_shipqty,\n       formatCost(valueAtShipping('TO', toitem_id)) AS f_shipvalue,\n<? endif ?>\n       'TO' AS holdtype,\n       '' AS notes,\n       NULL AS shiphead_number_qtdisplayrole,\n       NULL AS ordertype_qtdisplayrole,\n       'qty' AS shipqty_xtnumericrole,\n       'cost' AS shipvalue_xtnumericrole,\n       0 AS shipvalue_xttotalrole,\n       1 AS xtindentrole,\n       shiphead_id AS seq1, shiphead_order_id AS seq2,\n       toitem_id AS seq3, 0 AS seq4\nFROM shiphead, tohead, item, toitem\n <? if exists("warehous_id") ?>\n      JOIN itemsite ON ((toitem_item_id=itemsite_item_id)\n                    AND (itemsite_warehous_id=<? value("warehous_id") ?>))\n <? endif ?>\nWHERE ((NOT shiphead_shipped)\n AND (shiphead_order_type='TO')\n AND (shiphead_order_id=tohead_id)\n AND (tohead_id=toitem_tohead_id)\n AND (toitem_item_id=item_id)\n<? if exists("cust_id") ?>\n AND FALSE\n<? endif ?>\n<? if exists("cohead_id") ?>\n AND FALSE\n<? endif ?>\n) \n-- shipitem info\nUNION\nSELECT shiphead_id AS parent_id, shipitem_id AS child_id,\n       '' AS shiphead_number, '' AS linenumber,\n       'TO' AS ordertype,\n       NULL AS sfstatus,\n       '' AS dest,\n       formatDate(shipitem_transdate) || ' by ' || shipitem_trans_username AS description,\n       '' AS shiphead_shipvia, '' AS uom_name,\n       shipitem_qty AS shipqty,\n       NULL AS shipvalue,\n<? if exists("includeFormatted") ?>\n       formatQty(shipitem_qty) AS f_shipqty,\n       NULL AS f_shipvalue,\n<? endif ?>\n       '' AS holdtype,\n       '' AS notes,\n       NULL AS shiphead_number_qtdisplayrole,\n       NULL AS ordertype_qtdisplayrole,\n       'qty' AS shipqty_xtnumericrole,\n       'cost' AS shipvalue_xtnumericrole,\n       0 AS shipvalue_xttotalrole,\n       2 AS xtindentrole,\n       shiphead_id AS seq1, shiphead_order_id AS seq2,\n       shipitem_orderitem_id AS seq3, shipitem_id AS seq4\nFROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)\n <? if exists("warehous_id") ?>\n      JOIN toitem ON ((shipitem_orderitem_id=toitem_id)\n                  AND (shiphead_order_type='TO'))\n      JOIN itemsite ON ((toitem_item_id=itemsite_item_id)\n                    AND (itemsite_warehous_id=<? value("warehous_id") ?>))\n <? endif ?>\nWHERE ((NOT shiphead_shipped)\n AND (shiphead_order_type='TO')\n<? if exists("cust_id") ?>\n AND FALSE\n<? endif ?>\n<? if exists("cohead_id") ?>\n AND FALSE\n<? endif ?>\n) \n\n<? endif ?>\nORDER BY seq1, seq2, seq3, seq4, xtindentrole;\n	admin	2015-10-01	0
426	contactmerge	search	 Search for contacts\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: search\n-- Notes: Search for contacts\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntct_id,\n  CASE\n    WHEN (cntctsel_cntct_id IS NOT NULL AND cntctsel_target) THEN\n      1 -- Selected as target contact\n    WHEN (cntctsel_cntct_id IS NOT NULL AND NOT cntctsel_target) THEN\n      2 -- Selected as contact to merge\n    WHEN (cntctmrgd_cntct_id IS NOT NULL AND cntctUsed(cntctmrgd_cntct_id)=false) THEN\n      3 -- Already merged contact\n    WHEN (cntctmrgd_cntct_id IS NOT NULL) THEN\n      4 -- Already merged contact, but still has relationships\n    ELSE\n      0 -- No status\n  END AS status,\n  cntctdups.*, \n  cntctdup_level AS xtindentrole,\n  CASE\n    WHEN (cntctsel_cntct_id IS NOT NULL AND cntctsel_target) THEN\n      'altemphasis' -- Selected as target contact\n    WHEN (cntctsel_cntct_id IS NOT NULL AND NOT cntctsel_target) THEN\n      'emphasis' -- Selected as contact to merge\n    WHEN (cntctmrgd_cntct_id IS NOT NULL AND cntctUsed(cntctmrgd_cntct_id)=false) THEN\n      'warning' -- Already merged contact\n    WHEN (cntctmrgd_cntct_id IS NOT NULL) THEN\n      'error' -- Already merged contact, but still has relationships\n  END AS qtforegroundrole\nFROM cntctdups(\n  <? value("searchText") ?>, \n  <? value("searchContactName") ?>, \n  <? value("searchPhone") ?>, \n  <? value("searchEmail") ?>, \n  <? value("searchNumber") ?>, \n  <? value("searchName") ?>, \n  <? value("showInactive") ?>, \n  <? value("ignoreBlanks") ?>,\n  <? value("IndentedDups") ?>, \n  <? value("CheckHnfc") ?>, \n  <? value("CheckFirst") ?>, \n  <? value("CheckMiddle") ?>, \n  <? value("CheckLast") ?>, \n  <? value("CheckSuffix") ?>, \n  <? value("CheckPhone") ?>, \n  <? value("CheckEmail") ?>)\n  LEFT OUTER JOIN cntctsel ON (cntct_id=cntctsel_cntct_id)\n  LEFT OUTER JOIN cntctmrgd ON (cntct_id=cntctmrgd_cntct_id);\n	admin	2015-10-01	0
428	contactmerge	select	 Processes contact selections\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: select\n-- Notes: Processes contact selections\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntctselect(\n  <? value("cntct_id") ?>, \n  <? value("target") ?>) AS result;\n	admin	2015-10-01	0
479	salesAccounts	detail	 Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. See www.xtuple.com/CPAL for the full text of the software license.	-- Group: salesAccounts\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT salesaccnt_id,\n       CASE WHEN (salesaccnt_warehous_id=-1) THEN <? value("any") ?>\n            ELSE (SELECT warehous_code FROM whsinfo WHERE (warehous_id=salesaccnt_warehous_id))\n       END AS warehouscode,\n       CASE WHEN ((salesaccnt_custtype_id=-1) AND (salesaccnt_custtype='.*')) THEN <? value("any") ?>\n            WHEN (salesaccnt_custtype_id=-1) THEN salesaccnt_custtype\n            ELSE (SELECT custtype_code FROM custtype WHERE (custtype_id=salesaccnt_custtype_id))\n       END AS custtypecode,\n       CASE WHEN (salesaccnt_shipzone_id=-1) THEN <? value("any") ?>\n            ELSE (SELECT shipzone_name FROM shipzone WHERE (shipzone_id=salesaccnt_shipzone_id))\n       END AS shipzonecode,\n       CASE WHEN (salesaccnt_saletype_id=-1) THEN <? value("any") ?>\n            ELSE (SELECT saletype_code FROM saletype WHERE (saletype_id=salesaccnt_saletype_id))\n       END AS saletypecode,\n       CASE WHEN ((salesaccnt_custtype_id=-1) AND (salesaccnt_custtype='.*')) THEN <? value("any") ?>\n            WHEN (salesaccnt_custtype_id=-1) THEN salesaccnt_custtype\n            ELSE (SELECT custtype_code FROM custtype WHERE (custtype_id=salesaccnt_custtype_id))\n       END AS custtypecode,\n       CASE WHEN ((salesaccnt_prodcat_id=-1) AND (salesaccnt_prodcat='.*')) THEN <? value("any") ?>\n            WHEN (salesaccnt_prodcat_id=-1) THEN salesaccnt_prodcat\n            ELSE (SELECT prodcat_code FROM prodcat WHERE (prodcat_id=salesaccnt_prodcat_id))\n       END AS prodcatcode,\n       CASE WHEN (salesaccnt_sales_accnt_id IS NULL) THEN <? value("notapplicable") ?>\n            WHEN (salesaccnt_sales_accnt_id = -1) THEN <? value("notapplicable") ?>\n            ELSE formatGLAccount(salesaccnt_sales_accnt_id) END AS salesaccount,\n       CASE WHEN (salesaccnt_credit_accnt_id IS NULL) THEN <? value("notapplicable") ?>\n            WHEN (salesaccnt_credit_accnt_id = -1) THEN <? value("notapplicable") ?>\n            ELSE formatGLAccount(salesaccnt_credit_accnt_id) END AS creditaccount,\n       CASE WHEN (salesaccnt_cos_accnt_id IS NULL) THEN <? value("notapplicable") ?>\n            WHEN (salesaccnt_cos_accnt_id = -1) THEN <? value("notapplicable") ?>\n            ELSE formatGLAccount(salesaccnt_cos_accnt_id) END AS cosaccount,\n       CASE WHEN (salesaccnt_returns_accnt_id IS NULL) THEN <? value("notapplicable") ?>\n            WHEN (salesaccnt_returns_accnt_id = -1) THEN <? value("notapplicable") ?>\n            ELSE formatGLAccount(salesaccnt_returns_accnt_id) END AS returnsaccount,\n       CASE WHEN (salesaccnt_cor_accnt_id IS NULL) THEN <? value("notapplicable") ?>\n            WHEN (salesaccnt_cor_accnt_id = -1) THEN <? value("notapplicable") ?>\n            ELSE formatGLAccount(salesaccnt_cor_accnt_id) END AS coraccount,\n       CASE WHEN (salesaccnt_cow_accnt_id IS NULL) THEN <? value("notapplicable") ?>\n            WHEN (salesaccnt_cow_accnt_id = -1) THEN <? value("notapplicable") ?>\n            ELSE formatGLAccount(salesaccnt_cow_accnt_id) END AS cowaccount\nFROM salesaccnt\nORDER BY warehouscode, custtypecode, prodcatcode\n;\n	admin	2014-03-20	0
427	contactmerge	selectcol	 Selects a specific column\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: selectcol\n-- Notes: Selects a specific column\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntctselectcol(<? value("cntct_id") ?>, <? value("col_number") ?>);\n	admin	2015-10-01	0
286	summarizedBankrecHistory	detail	 used by dspSummarizedBankrecHistory\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: summarizedBankrecHistory\n-- Name: detail\n-- Notes: used by dspSummarizedBankrecHistory\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       'curr' AS bankrec_openbal_xtnumericrole,\n       'curr' AS bankrec_endbal_xtnumericrole\nFROM bankrec\nWHERE (bankrec_bankaccnt_id=<? value("bankaccntid") ?>)\nORDER BY bankrec_created;\n	admin	2015-10-01	0
103	taxBreakdown	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: taxBreakdown\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("invchead_id") ?>\n  SELECT head.*, linetax.*, freighttax.*, adjtax.* \n  FROM\n  (SELECT \n      invchead_invcnumber AS number, invchead_taxzone_id AS taxzone_id, \n      invchead_curr_id AS curr_id, invchead_curr_id AS tax_curr_id, invchead_invcdate AS date, \n      SUM(ROUND(((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price) / \n      (CASE WHEN(item_id IS NULL) THEN 1 ELSE invcitem_price_invuomratio END)), 2)) AS line, \n      invchead_freight AS freight, \n      getFreightTaxTypeId() AS freightTax, getAdjustmentTaxTypeId() AS adjTax \n  FROM invchead\n      LEFT OUTER JOIN invcitem ON (invcitem_invchead_id=invchead_id)  \n      LEFT OUTER JOIN item ON (invcitem_item_id=item_id) \n  WHERE (invchead_id=<? value("invchead_id") ?>) \n  GROUP BY number, taxzone_id, curr_id, tax_curr_id, date, freight, freightTax, adjTax) head, \n  (SELECT ROUND(SUM(group_tax), 2) AS total_tax FROM\n    (SELECT ROUND(SUM(invcitemtax.taxhist_tax),2) AS group_tax \n     FROM invcitemtax \n     LEFT OUTER JOIN invcitem ON (taxhist_parent_id = invcitem_id) \n     WHERE (invcitem_invchead_id=<? value("invchead_id") ?>)\n     GROUP BY taxhist_tax_id) AS data\n  ) linetax,\n  (SELECT ROUND(SUM(group_tax), 2) AS freighttaxamt FROM\n    (SELECT ROUND(SUM(taxhist_tax),2) AS group_tax \n     FROM invchead \n     LEFT OUTER JOIN invcheadtax ON (taxhist_parent_id = invchead_id \n     AND taxhist_taxtype_id = getfreighttaxtypeid()) \n     WHERE (invchead_id=<? value("invchead_id") ?>)\n     GROUP BY taxhist_tax_id) AS data\n  ) freighttax,  \n  (SELECT ROUND(SUM(group_tax), 2) AS adjtaxamt FROM\n    (SELECT  ROUND(SUM(taxhist_tax),2) AS group_tax \n     FROM invchead \n     LEFT OUTER JOIN invcheadtax ON (taxhist_parent_id = invchead_id \n                                 AND taxhist_taxtype_id = getadjustmenttaxtypeid()) \n     WHERE (invchead_id=<? value("invchead_id") ?>)\n     GROUP BY taxhist_tax_id) AS data\n  ) adjtax;\n<? elseif exists("cmhead_id") ?>\n  SELECT head.*, linetax.*, freighttax.*, adjtax.* \n  FROM\n  (SELECT \n      cmhead_number AS number, cmhead_taxzone_id AS taxzone_id, \n      cmhead_curr_id AS curr_id, cmhead_curr_id AS tax_curr_id, cmhead_docdate AS date, \n      SUM(ROUND(((cmitem_qtycredit * cmitem_qty_invuomratio) * (cmitem_unitprice) / \n      cmitem_price_invuomratio), 2)) AS line, \n      cmhead_freight AS freight, \n      getFreightTaxTypeId() AS freightTax, getAdjustmentTaxTypeId() AS adjTax \n  FROM cmhead \n      LEFT OUTER JOIN cmitem ON (cmitem_cmhead_id=cmhead_id) \n  WHERE (cmhead_id=<? value("cmhead_id") ?>) \n  GROUP BY number, taxzone_id, curr_id, tax_curr_id, date, freight, freightTax, adjTax) head, \n  (SELECT ROUND(SUM(group_tax), 2) AS total_tax FROM\n    (SELECT ROUND(SUM(cmitemtax.taxhist_tax * -1),2) AS group_tax \n     FROM cmitemtax \n     LEFT OUTER JOIN cmitem ON (taxhist_parent_id = cmitem_id) \n     WHERE (cmitem_cmhead_id=<? value("cmhead_id") ?>)\n     GROUP BY taxhist_tax_id) AS data\n  ) linetax,\n  (SELECT ROUND(SUM(group_tax), 2) AS freighttaxamt FROM\n    (SELECT ROUND(SUM(taxhist_tax * -1),2) AS group_tax \n     FROM cmhead \n     LEFT OUTER JOIN cmheadtax ON (taxhist_parent_id = cmhead_id \n                               AND taxhist_taxtype_id = getfreighttaxtypeid()) \n     WHERE (cmhead_id=<? value("cmhead_id") ?>)\n     GROUP BY taxhist_tax_id) AS data\n  ) freighttax, \n  (SELECT ROUND(SUM(group_tax), 2) AS adjtaxamt FROM\n    (SELECT  ROUND(SUM(taxhist_tax * -1),2) AS group_tax \n     FROM cmhead \n     LEFT OUTER JOIN cmheadtax ON (taxhist_parent_id = cmhead_id \n                               AND taxhist_taxtype_id = getadjustmenttaxtypeid()) \n     WHERE (cmhead_id=<? value("cmhead_id") ?>)\n     GROUP BY taxhist_tax_id) AS data\n  ) adjtax;\n<? elseif exists("cobmisc_id") ?>\n SELECT head.*, linetax.*, frighttax.*, adjtax.*   \n FROM \n   (SELECT cohead_number AS number, cobmisc_taxzone_id AS taxzone_id, \n      cobmisc_curr_id AS curr_id, cobmisc_curr_id AS tax_curr_id, \n     cobmisc_invcdate AS date, SUM(ROUND((cobill_qty * coitem_price) / \n     (CASE WHEN(item_id IS NULL) THEN 1 ELSE coitem_price_invuomratio END), 2)) AS line, \n     cobmisc_freight AS freight, \n     getFreightTaxTypeId() AS freightTax, getAdjustmentTaxTypeId() AS adjTax \t         \n    FROM cobmisc\n     JOIN cohead  ON (cobmisc_cohead_id=cohead_id) \n     LEFT OUTER JOIN cobill ON (cobill_cobmisc_id=cobmisc_id) \n     LEFT OUTER JOIN coitem ON (cobill_coitem_id=coitem_id) \n     LEFT OUTER JOIN itemsite ON (coitem_itemsite_id=itemsite_id) \n     LEFT OUTER JOIN item ON (itemsite_item_id=item_id) \n    WHERE (cobmisc_id=<? value("cobmisc_id") ?>) \n    GROUP BY number, cobmisc_taxzone_id, curr_id, tax_curr_id, \n      date, freight, freightTax,adjTax) head, \n   (SELECT ROUND(SUM(group_tax), 2) AS total_tax FROM\n     (SELECT ROUND(SUM(cobilltax.taxhist_tax),2) AS group_tax\n      FROM cobilltax\n      LEFT OUTER JOIN cobill ON (cobill_id=taxhist_parent_id) \n      WHERE (cobill_cobmisc_id=<? value("cobmisc_id") ?>)\n      GROUP BY taxhist_tax_id) AS data\n   ) linetax, \n   (SELECT ROUND(SUM(group_tax), 2) AS freighttaxamt FROM\n     (SELECT ROUND(SUM(taxhist_tax),2) AS group_tax\n      FROM cobmisctax\n      LEFT OUTER JOIN cobmisc ON (taxhist_parent_id = cobmisc_id AND taxhist_taxtype_id = getfreighttaxtypeid()) \n      WHERE (cobmisc_id=<? value("cobmisc_id") ?>)\n      GROUP BY taxhist_tax_id) AS data\n   ) frighttax, \n   (SELECT ROUND(SUM(group_tax), 2) AS adjtaxamt FROM\n     (SELECT  ROUND(SUM(taxhist_tax),2) AS group_tax\n      FROM cobmisctax\n      LEFT OUTER JOIN cobmisc ON (taxhist_parent_id = cobmisc_id AND taxhist_taxtype_id = getadjustmenttaxtypeid()) \n      WHERE (cobmisc_id=<? value("cobmisc_id") ?>)\n      GROUP BY taxhist_tax_id) AS data\n   ) adjtax;\n<? elseif exists("cohead_id") ?>\n  SELECT cohead_number AS number,\n         cohead_taxzone_id AS taxzone_id,\n         cohead_curr_id AS curr_id,\n         cohead_curr_id AS tax_curr_id,\n         cohead_orderdate AS date,\n         SUM(ROUND((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio),\n                    2)) AS line,\n         ROUND(SUM(calculateTax(cohead_taxzone_id, coitem_taxtype_id, cohead_orderdate, cohead_curr_id, ROUND((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price /\n                        coitem_price_invuomratio), 2))),2) as total_tax,   \n         cohead_freight AS freight,\n         getFreightTaxTypeId() AS freightTax, \n         ROUND(calculateTax(cohead_taxzone_id, getfreighttaxtypeid(), cohead_orderdate, cohead_curr_id, cohead_freight), 2) AS freighttaxamt\n  FROM coitem, item, itemsite, cohead \n  LEFT OUTER JOIN taxzone ON (cohead_taxzone_id=taxzone_id) \n  LEFT OUTER JOIN taxtype ON (taxtype_id=getFreightTaxTypeId())\n  WHERE ((coitem_cohead_id=<? value("cohead_id") ?>)\n    AND  (coitem_cohead_id=cohead_id)\n    AND  (coitem_status != 'X')\n    AND  (coitem_itemsite_id=itemsite_id)\n    AND  (itemsite_item_id=item_id))\n  GROUP BY number, cohead_taxzone_id, curr_id, tax_curr_id,\n         date, freight, freightTax,freighttaxamt;\n<? elseif exists("quhead_id") ?>\n  SELECT quhead_number AS number,\n         quhead_taxzone_id AS taxzone_id,\n         quhead_curr_id AS curr_id,\n         quhead_curr_id AS tax_curr_id,\n         quhead_quotedate AS date,\n         SUM(ROUND((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio),\n                    2)) AS line,\n         ROUND(SUM(calculateTax(quhead_taxzone_id, quitem_taxtype_id, quhead_quotedate, quhead_curr_id, ROUND((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price /\n                        quitem_price_invuomratio), 2))),2) as total_tax,  \n         quhead_freight AS freight,\n         taxtype_id AS freightTax,\n         ROUND(calculateTax(quhead_taxzone_id, getfreighttaxtypeid(), quhead_quotedate, quhead_curr_id, quhead_freight), 2) AS freighttaxamt\n  FROM quitem, item, quhead \n    LEFT OUTER JOIN taxzone ON (quhead_taxzone_id=taxzone_id) \n    LEFT OUTER JOIN taxtype ON (taxtype_id=getFreightTaxTypeId())\n  WHERE ((quitem_quhead_id=<? value("quhead_id") ?>)\n    AND  (quitem_quhead_id=quhead_id)\n    AND  (quitem_item_id=item_id))\n  GROUP BY number, quhead_taxzone_id, curr_id, tax_curr_id,\n         date, freight, freightTax,freighttaxamt;\n<? elseif exists("rahead_id") ?>\n  SELECT rahead_number AS number,\n         rahead_taxzone_id AS taxzone_id,\n         rahead_curr_id AS curr_id,\n         rahead_curr_id AS tax_curr_id,\n         rahead_authdate AS date,\n         COALESCE(SUM(ROUND((raitem_qtyauthorized * raitem_qty_invuomratio) * (raitem_unitprice / raitem_price_invuomratio),\n                    2)),0) AS line,\n         COALESCE(ROUND(SUM(calculateTax(rahead_taxzone_id, raitem_taxtype_id, rahead_authdate, rahead_curr_id, ROUND((raitem_qtyauthorized * raitem_qty_invuomratio) * (raitem_unitprice /\n                        raitem_price_invuomratio), 2))),2),0) as total_tax,   \n         rahead_freight AS freight,\n         taxtype_id AS freightTax,\n         ROUND(calculateTax(rahead_taxzone_id, getfreighttaxtypeid(), rahead_authdate, rahead_curr_id, rahead_freight), 2) AS freighttaxamt\n  FROM rahead \n    LEFT OUTER JOIN raitem ON (raitem_rahead_id=rahead_id)\n    LEFT OUTER JOIN taxzone ON (rahead_taxzone_id=taxzone_id) \n    LEFT OUTER JOIN taxtype ON (taxtype_id=getFreightTaxTypeId())\n  WHERE (raitem_rahead_id=<? value("rahead_id") ?>)\n  GROUP BY number, rahead_taxzone_id, curr_id, tax_curr_id,\n         date, freight, freightTax;\n<? elseif exists("tohead_id") ?>\n  SELECT tohead_number AS number,\n         tohead_taxzone_id AS taxzone_id,\n         tohead_freight_curr_id AS curr_id,\n         tohead_freight_curr_id AS tax_curr_id,\n         tohead_orderdate AS date,\n-------- SUM(ROUND(toitem_freight, 2)) AS line,\n-------- COALESCE(ROUND(SUM(calculateTax(tohead_taxzone_id, getfreighttaxtypeid(), tohead_orderdate, baseCurrId(), toitem_freight)),2),0) as total_tax,\n         0.0 AS line, 0.0 AS total_tax,  \n         tohead_freight +  SUM(ROUND(toitem_freight, 2)) AS freight,\n         getFreightTaxTypeId() AS freightTax,\n         COALESCE(ROUND(SUM(calculateTax(tohead_taxzone_id, getfreighttaxtypeid(), tohead_orderdate, baseCurrId(), toitem_freight)),2),0) +\n         COALESCE(ROUND(calculateTax(tohead_taxzone_id, getfreighttaxtypeid(), tohead_orderdate, baseCurrId(), tohead_freight),2),0) AS freighttaxamt \n  FROM toitem, tohead \n  WHERE ((toitem_tohead_id=<? value("tohead_id") ?>)\n    AND  (toitem_tohead_id=tohead_id)\n    AND  (toitem_status!='X')) \n  GROUP BY number, taxzone_id, curr_id, tax_curr_id,\n         date,\t\ttohead_freight,\tfreightTax\n<? elseif exists("pohead_id") ?>\n  SELECT pohead_number AS number,\n         pohead_taxzone_id AS taxzone_id,\n         pohead_curr_id AS curr_id,\n         pohead_curr_id AS tax_curr_id,\n         pohead_orderdate AS date,\n         COALESCE(SUM(ROUND(poitem_unitprice * poitem_qty_ordered, 2)),0) AS line,\n         (SELECT SUM(tax) AS tax \n          FROM (\n            SELECT ROUND(SUM(taxdetail_tax),2) AS tax \n            FROM tax \n              JOIN calculateTaxDetailSummary('PO', <? value("pohead_id") ?>, 'T') ON (taxdetail_tax_id=tax_id)\n            GROUP BY tax_id) data\n         ) as total_tax,\n         (COALESCE(SUM(poitem_freight),0)+COALESCE(pohead_freight,0)) AS freight,\n         taxtype_id AS freightTax,\n         0 AS freighttaxamt\n  FROM pohead \n    LEFT OUTER JOIN poitem ON (poitem_pohead_id=pohead_id)\n    LEFT OUTER JOIN taxzone ON (pohead_taxzone_id=taxzone_id) \n    LEFT OUTER JOIN taxtype ON (taxtype_id=getFreightTaxTypeId())\n  WHERE (poitem_pohead_id=<? value("pohead_id") ?>)\n  GROUP BY number, pohead_taxzone_id, curr_id, tax_curr_id,\n         date, pohead_freight, freightTax;\n<? elseif exists("vohead_id") ?>\n  SELECT head.*, linetax.*, adjtax.* \n  FROM\n  (SELECT \n      vohead_number AS number, vohead_taxzone_id AS taxzone_id, \n      vohead_curr_id AS curr_id, vohead_curr_id AS tax_curr_id, vohead_docdate AS date, \n      COALESCE(SUM(ROUND(voitem_qty * poitem_unitprice, 2)), 0) AS line, \n      COALESCE(SUM(voitem_freight), 0) AS freight,  \n      getAdjustmentTaxTypeId() AS adjTax \n  FROM voitem \n      LEFT OUTER JOIN poitem ON (voitem_poitem_id=poitem_id) \n      LEFT OUTER JOIN vohead ON (voitem_vohead_id=vohead_id) \n  WHERE (voitem_vohead_id=<? value("vohead_id") ?>) \n  GROUP BY number, taxzone_id, curr_id, tax_curr_id, date, adjTax) head, \n  (SELECT SUM(voitemtax.taxhist_tax * -1) AS total_tax \n   FROM voitemtax \n    LEFT OUTER JOIN voitem ON (taxhist_parent_id = voitem_id) \n   WHERE (voitem_vohead_id=<? value("vohead_id") ?>)) linetax,\n  (SELECT  SUM(taxhist_tax * -1) AS adjtaxamt \n   FROM vohead \n    LEFT OUTER JOIN voheadtax ON (taxhist_parent_id = vohead_id \n                                AND taxhist_taxtype_id = getadjustmenttaxtypeid()) \n   WHERE vohead_id=<? value("vohead_id") ?>) adjtax;\n<? endif ?>;\n	admin	2015-10-01	0
102	todolist	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: todolist\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT * FROM (\n/*        ---------TO DO-------------- */\n  SELECT todoitem_id AS id, \n         1 AS altId, \n         <? value("todo") ?> AS type, \n         CAST(incdt_number AS text) AS number,\n         todoitem_name AS name,\n         CASE WHEN (todoitem_active AND todoitem_status != 'C') THEN TRUE\n              ELSE FALSE\n         END AS active,\n         CASE WHEN (todoitem_status='C') THEN <? value("complete") ?>\n              WHEN (todoitem_status='D') THEN <? value("deferred") ?>\n              WHEN (todoitem_status='P') THEN <? value("pending") ?>\n              WHEN (todoitem_status='I') THEN <? value("inprocess") ?>\n              WHEN (todoitem_status='N') THEN <? value("new") ?>\n              ELSE '?'\n         END AS stage,\n         incdtpriority_name AS priority, \n         incdtpriority_order AS seq,\n         todoitem_owner_username AS owner, \n         todoitem_username AS assigned, \n         firstLine(todoitem_description) AS notes, \n         todoitem_start_date as start, \n         todoitem_due_date AS due, \n         formatDate(todoitem_due_date) AS f_due, \n         todoitem_start_date is not null AS hasStartDate,\n         todoitem_due_date is not null AS hasDueDate,\n         crmacct_id,\n         crmacct_number, \n         crmacct_name, \n         CASE WHEN (todoitem_ophead_id IS NOT NULL) THEN\n           'OPP'\n              WHEN (todoitem_incdt_id IS NOT NULL) THEN\n           'INCDT'\n         END AS parent,\n         CASE WHEN (todoitem_ophead_id IS NOT NULL) THEN\n           <? value("opportunity") ?> || '-' || ophead_number\n              WHEN (todoitem_incdt_id IS NOT NULL) THEN\n           <? value("incident") ?> || '-' || incdt_number\n         END AS parent_qtdisplayrole,\n         CASE WHEN (todoitem_ophead_id IS NOT NULL) THEN\n           <? value("opportunity") ?> || '-' || ophead_number\n              WHEN (todoitem_incdt_id IS NOT NULL) THEN\n           <? value("incident") ?> || '-' || incdt_number\n         END AS f_parent,\n         COALESCE(todoitem_ophead_id, todoitem_incdt_id) AS parent_xtidrole,\n         COALESCE(crmacct_cust_id,-1) > 0 AS cust_qtdisplayrole,\n         crmacct_cust_id AS cust,\n         CASE WHEN (todoitem_active AND todoitem_due_date < CURRENT_DATE) THEN 'expired'\n              WHEN (todoitem_active AND todoitem_due_date > CURRENT_DATE) THEN 'future'\n         END AS due_qtforegroundrole \n<? if exists("hasContext") ?>\n    FROM todoitem\n<? else ?>\n    FROM todoitem() \n<? endif ?>\n      LEFT OUTER JOIN incdt ON (incdt_id=todoitem_incdt_id) \n      LEFT OUTER JOIN ophead ON (ophead_id=todoitem_ophead_id)\n      LEFT OUTER JOIN crmacct ON (crmacct_id=todoitem_crmacct_id) \n      LEFT OUTER JOIN incdtpriority ON (incdtpriority_id=todoitem_priority_id) \n<? if not exists("todoList")?>\n    WHERE false\n<? else ?>\n    WHERE true\n<? endif ?>\n<? if exists("startStartDate") ?>\n  AND (todoitem_start_date <= <? value("startStartDate") ?>)\n<? endif ?>\n<? if exists("startEndDate") ?>\n  AND (todoitem_start_date >= <? value("startEndDate") ?>)\n<? endif ?>\n<? if exists("dueStartDate") ?>\n  AND (todoitem_due_date <= <? value("dueStartDate") ?>)\n<? endif ?>\n<? if exists("dueEndDate") ?>\n  AND (todoitem_due_date >= <? value("dueEndDate") ?>)\n<? endif ?>\n<? if exists("crmacct_id") ?>\n  AND (crmacct_id =<? value("crmacct_id") ?>)\n<? endif ?>\n<? if exists("completedonly") ?>\n  AND (todoitem_status = 'C')\t\t\t\n<? elseif not exists("completed") ?>\n  AND (todoitem_status != 'C')\t\t\t\n<? endif ?>\n<? if exists("username") ?>\n  AND (<? value("username") ?> IN (todoitem_username, todoitem_owner_username))\n<? endif ?>\n<? if exists("assigned_username") ?> \n  AND (todoitem_username=<? value("assigned_username") ?>) \n<? elseif exists("assigned_usr_pattern") ?>\n  AND (todoitem_username ~ <? value("assigned_usr_pattern") ?>) \n<? endif ?>\n<? if exists("owner_username") ?> \n  AND (todoitem_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (todoitem_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\nUNION ALL\n/*        ---------INCIDENT-------------- */\n  SELECT incdt_id AS id, \n         2 AS altId, \n         <? value("incident") ?> AS type, \n         CAST(incdt_number AS text) AS number,\n         incdt_summary AS name, \n         incdt_status != 'L' AS active,\n         CASE WHEN (incdt_status='N') THEN <? value("new") ?>\n              WHEN (incdt_status='F') THEN <? value("feedback") ?>\n              WHEN (incdt_status='C') THEN <? value("confirmed") ?>\n              WHEN (incdt_status='A') THEN <? value("assigned") ?>\n              WHEN (incdt_status='R') THEN <? value("resolved") ?>\n              WHEN (incdt_status='L') THEN <? value("closed") ?>\n              ELSE '?'\n         END AS stage,\n         incdtpriority_name AS priority,\n         incdtpriority_order AS seq,\n         incdt_owner_username AS owner, \n         incdt_assigned_username AS assigned,\n         firstLine(incdt_descrip) AS notes, \n         CAST(incdt_timestamp AS date) AS start, \n         null AS due, \n         null AS f_due, \n         false AS hasStartDate,\n         false AS hasDueDate,\n         crmacct_id,\n         crmacct_number, \n         crmacct_name,\n         '' AS parent,\n         '' AS parent_qtdisplay_role,\n         '' AS f_parent,\n         NULL AS parent_xtidrole,\n         COALESCE(crmacct_cust_id,-1) > 0 AS cust_qtdisplayrole,\n         COALESCE(crmacct_cust_id,-1) AS cust,\n         NULL AS due_qtforegroundrole \n<? if exists("hasContext") ?>\n         FROM incdt\n<? else ?>\n         FROM incdt()\n<? endif ?>\n           LEFT OUTER JOIN crmacct ON (crmacct_id=incdt_crmacct_id) \n           LEFT OUTER JOIN custinfo ON (cust_id=crmacct_cust_id)\n           LEFT OUTER JOIN incdtpriority ON (incdtpriority_id=incdt_incdtpriority_id) \n<? if not exists("incidents")?>\n    WHERE false\n<? else ?>\n    WHERE true\n<? endif ?>\n<? if exists("startStartDate") ?>\n  AND (incdt_timestamp::date <= <? value("startStartDate") ?>)\n<? endif ?>\n<? if exists("startEndDate") ?>\n  AND (incdt_timestamp::date >= <? value("startEndDate") ?>)\n<? endif ?>\n<? if exists("dueStartDate") ?>\n  AND false\n<? endif ?>\n<? if exists("dueEndDate") ?>\n  AND false\n<? endif ?>\n<? if exists("crmacct_id") ?>\n  AND (crmacct_id =<? value("crmacct_id") ?>)\n<? endif ?>\n<? if exists("completedonly") ?>\n  AND (incdt_status = 'L')\t\t\t\n<? elseif not exists("completed") ?>\n  AND (incdt_status != 'L')\t\t\t\n<? endif ?>\n<? if exists("username") ?>\n  AND (<? value("username") ?> IN (incdt_assigned_username, incdt_owner_username))\n<? endif ?>\n<? if exists("assigned_username") ?> \n  AND (incdt_assigned_username=<? value("assigned_username") ?>) \n<? elseif exists("assigned_usr_pattern") ?>\n  AND (incdt_assigned_username ~ <? value("assigned_usr_pattern") ?>) \n<? endif ?>\n<? if exists("owner_username") ?> \n  AND (incdt_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (incdt_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\nUNION ALL\n/*        ---------PROJECT TASK-------------- */\n    SELECT prjtask_id AS id, \n           3 AS altId, \n           <? value("task") ?> AS type,\n           prjtask_number AS number,\n           prjtask_name AS name, \n           prjtask_status != 'C' AS active,\n           CASE WHEN (prjtask_status='P') THEN <? value("concept") ?>\n                WHEN (prjtask_status='O') THEN <? value("inprocess") ?>\n                WHEN (prjtask_status='C') THEN <? value("complete") ?>\n                ELSE '?'\n           END AS stage,\n           NULL AS priority, \n           NULL AS seq, \n           prjtask_owner_username AS owner, \n           prjtask_username AS assigned, \n           firstLine(prjtask_descrip) AS notes, \n           prjtask_start_date AS start, \n           prjtask_due_date AS due, \n           formatDate(prjtask_due_date) AS f_due, \n           prjtask_start_date is not null AS hasStartDate,\n           prjtask_due_date is not null AS hasDueDate,\n           NULL AS crmacct_id,\n           '' AS crmacct_number, \n           '' AS crmacct_name,\n           'PRJ' AS parent,\n           <? value("project") ?> || '-' || prj_number AS parent_qtdisplay_role,\n           <? value("project") ?> || '-' || prj_number AS f_parent,\n           prjtask_prj_id AS parent_xtidrole,\n           false AS cust_qtdisplayrole, \n           null AS cust,\n           CASE WHEN (prjtask_status != 'C' AND prjtask_due_date < CURRENT_DATE) THEN 'expired'\n                WHEN (prjtask_status != 'C' AND prjtask_due_date > CURRENT_DATE) THEN 'future'\n           END AS due_qtforegroundrole \n<? if exists("hasContext") ?>\n     FROM prjtask\n<? else ?>\n     FROM prjtask()\n<? endif ?>\n       JOIN prj ON (prj_id=prjtask_prj_id)\n<? if not exists("projects")?>\n    WHERE false\n<? else ?>\n    WHERE true\n<? endif ?>\n<? if exists("startStartDate") ?>\n  AND (prjtask_start_date <= <? value("startStartDate") ?>)\n<? endif ?>\n<? if exists("startEndDate") ?>\n  AND (prjtask_start_date >= <? value("startEndDate") ?>)\n<? endif ?>\n<? if exists("dueStartDate") ?>\n  AND (prjtask_due_date <= <? value("dueStartDate") ?>)\n<? endif ?>\n<? if exists("dueEndDate") ?>\n  AND (prjtask_due_date >= <? value("dueEndDate") ?>)\n<? endif ?>\n<? if exists("completedonly") ?>\n  AND (prjtask_status = 'C')\t\t\t\n<? elseif not exists("completed") ?>\n  AND (prjtask_status != 'C')\t\t\t\n<? endif ?>\n<? if exists("username") ?>\n  AND (<? value("username") ?> IN (prjtask_username, prjtask_owner_username))\n<? endif ?>\n<? if exists("assigned_username") ?> \n  AND (prjtask_username=<? value("assigned_username") ?>) \n<? elseif exists("assigned_usr_pattern") ?>\n  AND (prjtask_username ~ <? value("assigned_usr_pattern") ?>) \n<? endif ?>\n<? if exists("owner_username") ?> \n  AND (prjtask_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (prjtask_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\nUNION ALL\n/*        ---------PROJECT-------------- */\n    SELECT prj_id AS id, \n           4 AS altId, \n           <? value("project") ?> AS type,\n           prj_number AS number,\n           prj_name AS name, \n           prj_status != 'C' AS active,\n           CASE WHEN (prj_status='P') THEN <? value("concept") ?>\n                WHEN (prj_status='O') THEN <? value("inprocess") ?>\n                WHEN (prj_status='C') THEN <? value("complete") ?>\n                ELSE '?'\n           END AS stage,\n           NULL AS priority, \n           NULL AS seq,\n           prj_owner_username AS owner, \n           prj_username AS assigned,\n           firstLine(prj_descrip) AS notes, \n           prj_start_date AS start, \n           prj_due_date AS due, \n           formatDate(prj_due_date) AS f_due, \n           prj_start_date IS NOT NULL AS hasStartDate,\n           prj_due_date IS NOT NULL AS hasDueDate,\n           null AS crmacct_id,\n           '' AS crmacct_number, \n           '' AS crmacct_name,\n           '' AS parent,\n           '' AS parent_qtdisplayrole,\n           '' AS f_parent,\n           NULL AS parent_xtidrole,\n           false AS cust_qtdisplayrole, \n           null AS cust,\n           CASE WHEN (prj_status != 'C'AND prj_due_date < CURRENT_DATE) THEN 'expired'\n                WHEN (prj_status != 'C'AND prj_due_date > CURRENT_DATE) THEN 'future'\n           END AS due_qtforegroundrole \n<? if exists("hasContext") ?>\n       FROM prj\n<? else ?>\n       FROM prj()\n<? endif ?>\n<? if not exists("projects")?>\n    WHERE false\n<? else ?>\n    WHERE true\n<? endif ?>\n<? if exists("startStartDate") ?>\n  AND (prj_start_date <= <? value("startStartDate") ?>)\n<? endif ?>\n<? if exists("startEndDate") ?>\n  AND (prj_start_date >= <? value("startEndDate") ?>)\n<? endif ?>\n<? if exists("dueStartDate") ?>\n  AND (prj_due_date <= <? value("dueStartDate") ?>)\n<? endif ?>\n<? if exists("dueEndDate") ?>\n  AND (prj_due_date >= <? value("dueEndDate") ?>)\n<? endif ?>\n<? if exists("completedonly") ?>\n  AND (prj_status = 'C')\t\t\t\n<? elseif not exists("completed") ?>\n  AND (prj_status != 'C')\t\t\t\n<? endif ?>\n<? if exists("username") ?>\n  AND (<? value("username") ?> IN (prj_username, prj_owner_username))\n<? endif ?>\n<? if exists("assigned_username") ?> \n  AND (prj_username=<? value("assigned_username") ?>) \n<? elseif exists("assigned_usr_pattern") ?>\n  AND (prj_username ~ <? value("assigned_usr_pattern") ?>) \n<? endif ?>\n<? if exists("owner_username") ?> \n  AND (prj_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (prj_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\nUNION ALL\n/*        ---------OPPORTUNITY-------------- */\n  SELECT ophead_id AS id, \n         5 AS altId, \n         <? value("opportunity") ?> AS type, \n         ophead_number AS number,\n         ophead_name AS name, \n         ophead_active AS active,\n         opstage_descrip AS stage,         \n         incdtpriority_name AS priority, \n         incdtpriority_order AS seq,\n         ophead_owner_username AS owner, \n         ophead_username AS assigned, \n         firstLine(ophead_notes) AS notes, \n         ophead_start_date AS start, \n         ophead_target_date AS due, \n         formatDate(ophead_target_date) AS f_due,\n         ophead_start_date is not null AS hasStartDate,\n         ophead_target_date is not null AS hasDueDate,\n         crmacct_id,\n         crmacct_number, \n         crmacct_name, \n         '' AS parent,\n         '' AS parent_qtdisplayrole,\n         '' AS f_parent,\n         NULL AS parent_xtidrole,\n         COALESCE(crmacct_cust_id,-1) > 0 AS cust_qtdisplayrole,\n         crmacct_cust_id AS cust,\n         CASE WHEN (ophead_active AND ophead_target_date < CURRENT_DATE) THEN 'expired'\n              WHEN (ophead_active AND ophead_target_date > CURRENT_DATE) THEN 'future'\n         END AS due_qtforegroundrole \n<? if exists("hasContext") ?>\n    FROM ophead\n<? else ?>\n    FROM ophead()\n<? endif ?>\n      JOIN opstage ON (ophead_opstage_id=opstage_id)\n      LEFT OUTER JOIN crmacct ON (crmacct_id=ophead_crmacct_id) \n      LEFT OUTER JOIN incdtpriority ON (incdtpriority_id=ophead_priority_id) \n<? if not exists("opportunities")?>\n    WHERE false\n<? else ?>\n    WHERE true\n<? endif ?>\n<? if exists("startStartDate") ?>\n  AND (ophead_start_date <= <? value("startStartDate") ?>)\n<? endif ?>\n<? if exists("startEndDate") ?>\n  AND (ophead_start_date >= <? value("startEndDate") ?>)\n<? endif ?>\n<? if exists("dueStartDate") ?>\n  AND (ophead_target_date <= <? value("dueStartDate") ?>)\n<? endif ?>\n<? if exists("dueEndDate") ?>\n  AND (ophead_target_date >= <? value("dueEndDate") ?>)\n<? endif ?>\n<? if exists("crmacct_id") ?>\n  AND (crmacct_id =<? value("crmacct_id") ?>)\n<? endif ?>\n<? if exists("completedonly") ?>\n  AND (NOT ophead_active)\t\t\t\n<? elseif not exists("completed") ?>\n  AND (ophead_active)\t\t\t\n<? endif ?>\n<? if exists("username") ?>\n  AND (<? value("username") ?> IN (ophead_username, ophead_owner_username))\n<? endif ?>\n<? if exists("assigned_username") ?> \n  AND (ophead_username=<? value("assigned_username") ?>) \n<? elseif exists("assigned_usr_pattern") ?>\n  AND (ophead_username ~ <? value("assigned_usr_pattern") ?>) \n<? endif ?>\n<? if exists("owner_username") ?> \n  AND (ophead_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (ophead_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\n) AS data\nORDER BY hasDueDate desc, due, hasStartDate desc, start\n	admin	2015-10-01	0
434	accountNumbers	detail	 used by accountNumbers\n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: accountNumbers\n-- Name: detail\n-- Notes: used by accountNumbers\n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT accnt_id, *,\n       CASE WHEN(accnt_type='A') THEN <? value("asset") ?>\n            WHEN(accnt_type='E') THEN <? value("expense") ?>\n            WHEN(accnt_type='L') THEN <? value("liability") ?>\n            WHEN(accnt_type='Q') THEN <? value("equity") ?>\n            WHEN(accnt_type='R') THEN <? value("revenue") ?>\n            ELSE accnt_type\n       END AS accnt_type_qtdisplayrole,\n       accnt_active \n  FROM (ONLY accnt LEFT OUTER JOIN\n             company ON (accnt_company=company_number)) \n       LEFT OUTER JOIN subaccnttype ON (accnt_type=subaccnttype_accnt_type AND accnt_subaccnttype_code=subaccnttype_code)\n WHERE true\n<? if not exists("showExternal") ?>\n  AND (NOT COALESCE(company_external, false)) \n<? endif ?>\n<? if not exists("showInactive") ?>\n  AND COALESCE(accnt_active, false)\n<? endif ?>\n<? if exists("accnt_type") ?>\n  AND accnt_type = <? value("accnt_type") ?>\n<? endif ?>\n<? if exists("subaccnt_type") ?>\n  AND subaccnttype_id = <? value("subaccnt_type") ?>\n<? endif ?>\nORDER BY accnt_number, accnt_sub, accnt_profit;\n	admin	2015-10-01	0
486	address	uses	 used by address\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: address\n-- Name: uses\n-- Notes: used by address\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntct_id, 1, <? value("contact") ?> AS type, cntct_first_name,\n       cntct_last_name, crmacct_number, cntct_phone,\n       cntct_phone2, cntct_fax, cntct_email, cntct_webaddr\nFROM cntct LEFT OUTER JOIN crmacct ON (cntct_crmacct_id=crmacct_id)\nWHERE (cntct_addr_id=<? value("addr_id") ?>)\nUNION\nSELECT shipto_id, 2, <? value("shipto") ?>, shipto_name,\n       shipto_name, crmacct_number, '',\n       '', '', '', ''\nFROM shiptoinfo LEFT OUTER JOIN crmacct ON (shipto_cust_id=crmacct_cust_id)\nWHERE (shipto_addr_id=<? value("addr_id") ?>)\nUNION\nSELECT vend_id, 3, <? value("vendor") ?>, vend_number,\n       vend_name, crmacct_number, '',\n       '', '', '', ''\nFROM vendinfo LEFT OUTER JOIN crmacct ON (vend_id=crmacct_vend_id)\nWHERE (vend_addr_id=<? value("addr_id") ?>)\nUNION\nSELECT vendaddr_id, 4, <? value("vendaddr") ?>, vendaddr_code,\n       vendaddr_name, crmacct_number, '',\n       '', '', '', ''\nFROM vendaddrinfo LEFT OUTER JOIN crmacct ON (vendaddr_vend_id=crmacct_vend_id)\nWHERE (vendaddr_addr_id=<? value("addr_id") ?>)\nUNION\nSELECT warehous_id, 5, <? value("whs") ?>, warehous_code,\n       warehous_descrip, '', '',\n       '', '', '', ''\nFROM whsinfo\nWHERE (warehous_addr_id=<? value("addr_id") ?>)\nORDER BY 3, 5, 4;\n	admin	2015-10-01	0
230	addresses	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: addresses\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT ON (addr_country, addr_state, addr_city, addr_line1, addr_number) \n  addr_id, addr_line1, addr_line2, addr_line3, \n  addr_city, addr_state, addr_country, addr_postalcode \n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\nFROM addr \n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='ADDR') \n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=addr_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='ADDR') \n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=addr_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='ADDR') \n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=addr_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE true\n<? if not exists("showInactive") ?> \n AND addr_active \n<? endif ?>\n<? literal("charClause") ?>\nORDER BY addr_country, addr_state, addr_city, addr_line1, addr_number;\n	admin	2015-10-01	0
35	allocations	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: allocations\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT source_id, type, order_number, item_number, totalqty, relievedqty, balanceqty, duedate,\n       balanceqty AS runningbal,\n       'qty' AS totalqty_xtnumericrole,\n       'qty' AS relievedqty_xtnumericrole,\n       'qty' AS balanceqty_xtnumericrole,\n       0 AS runningbal_xtrunningrole,\n       'qty' AS runningbal_xtnumericrole,\n       CASE WHEN (duedate < CURRENT_DATE) THEN 'error'\n       END AS duedate_qtforegroundrole\nFROM\n(\nSELECT womatl_id AS source_id, TEXT('W/O') AS type,\n       formatWoNumber(wo_id) AS order_number,\n       paritem.item_number,\n       itemuomtouom(component.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)  AS totalqty,\n       itemuomtouom(component.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyiss) AS relievedqty,\n       itemuomtouom(component.itemsite_item_id, womatl_uom_id, NULL, noNeg(womatl_qtyreq - womatl_qtyiss)) AS balanceqty,\n       womatl_duedate AS duedate\n\nFROM womatl, wo, itemsite AS parent, itemsite AS component, item AS paritem, item AS compitem\nWHERE ((womatl_wo_id=wo_id)\n  AND (wo_status<>'C')\n  AND (wo_itemsite_id=parent.itemsite_id)\n  AND (womatl_itemsite_id=component.itemsite_id)\n  AND (parent.itemsite_item_id=paritem.item_id)\n  AND (component.itemsite_item_id=compitem.item_id)\n  AND (compitem.item_type != 'T')\n  AND (component.itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND (component.itemsite_item_id=<? value("item_id") ?>)\n<? if exists("leadTime") ?>\n  AND (womatl_duedate <= (CURRENT_DATE + component.itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND (womatl_duedate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND (womatl_duedate <= <? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND (womatl_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n)\n\nUNION \n\n-- Special handling for tools\nSELECT womatl_id AS source_id, TEXT('W/O') AS type,\n       formatWoNumber(wo_id) AS order_number,\n       paritem.item_number,\n       itemuomtouom(component.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)  AS totalqty,\n       COALESCE(sum(invhist_invqty),0) AS relievedqty,\n       noNeg(itemuomtouom(component.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq) - COALESCE(sum(invhist_invqty),0)) AS balanceqty,\n       womatl_duedate AS duedate\n\nFROM itemsite AS parent, itemsite AS component, item paritem, item AS compitem, wo, womatl\n  LEFT OUTER JOIN womatlpost ON (womatl_id=womatlpost_womatl_id)\n  LEFT OUTER JOIN invhist ON ((womatlpost_invhist_id=invhist_id)\n                          AND (invhist_invqty > 0))\nWHERE ((womatl_wo_id=wo_id)\n  AND (wo_status<>'C')\n  AND (wo_itemsite_id=parent.itemsite_id)\n  AND (womatl_itemsite_id=component.itemsite_id)\n  AND (parent.itemsite_item_id=paritem.item_id)\n  AND (component.itemsite_item_id=compitem.item_id)\n  AND (compitem.item_type='T')\n  AND (component.itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND (component.itemsite_item_id=<? value("item_id") ?>)\n<? if exists("leadTime") ?>\n  AND (womatl_duedate <= (CURRENT_DATE + component.itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND (womatl_duedate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND (womatl_duedate <= <? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND (womatl_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n)\nGROUP BY womatl_id, wo_id, paritem.item_number, womatl_uom_id, womatl_qtyreq, womatl_duedate, component.itemsite_item_id\n\nUNION \nSELECT coitem_id AS source_id, TEXT('S/O') AS type,\n       formatSoNumber(coitem_id) AS order_number,\n       item_number,\n       itemuomtouom(itemsite_item_id, coitem_qty_uom_id, NULL, coitem_qtyord) AS totalqty,\n       itemuomtouom(itemsite_item_id, coitem_qty_uom_id, NULL, (coitem_qtyshipped + qtyAtShipping(coitem_id)) - coitem_qtyreturned) as relievedqty,\n       itemuomtouom(itemsite_item_id, coitem_qty_uom_id, NULL, noNeg(coitem_qtyord - (coitem_qtyshipped + qtyAtShipping(coitem_id)) + coitem_qtyreturned)) AS balanceqty,\n       coitem_scheddate as duedate\nFROM cohead, coitem, itemsite, item \nWHERE ( (coitem_cohead_id=cohead_id)\n  AND  (coitem_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (item_sold)\n  AND  (coitem_status NOT IN ('C','X'))\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n<? if exists("leadTime") ?>\n  AND  (coitem_scheddate <= (CURRENT_DATE + itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND  (coitem_scheddate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND  (coitem_scheddate <= <? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND  (coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n)\n\n<? if exists("MultiWhs") ?>\nUNION \nSELECT toitem_id AS source_id, TEXT('T/O') AS type,\n       TEXT(tohead_number) AS order_number,\n       item_number,\n       toitem_qty_ordered AS totalqty,\n       (toitem_qty_shipped + qtyAtShipping(toitem_id)) as relievedqty,\n       noNeg(toitem_qty_ordered - (toitem_qty_shipped + qtyAtShipping(toitem_id))) AS balanceqty,\n       toitem_schedshipdate as duedate\nFROM tohead, toitem, itemsite, item \nWHERE ((toitem_tohead_id=tohead_id)\n  AND  (toitem_item_id=itemsite_item_id)\n  AND  (tohead_src_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=item_id)\n  AND  (toitem_status NOT IN ('C','X'))\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n<? if exists("leadTime") ?>\n  AND  (toitem_schedshipdate <= (CURRENT_DATE + itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND  (toitem_schedshipdate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND  (toitem_schedshipdate <= <? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND  (toitem_schedshipdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n)\n<? endif ?>\n) AS dummy\n\nORDER BY duedate;\n	admin	2015-10-01	0
36	apAging	detail	 used by dspTimePhasedOpenAPItems\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: apAging\n-- Name: detail\n-- Notes: used by dspTimePhasedOpenAPItems\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT apaging_vend_id, apaging_vend_number, apaging_vend_name,\n       SUM(apaging_total_val) AS apaging_total_val_sum,\n       SUM(apaging_cur_val) AS apaging_cur_val_sum,\n       SUM(apaging_thirty_val) AS apaging_thirty_val_sum,\n       SUM(apaging_sixty_val) AS apaging_sixty_val_sum,\n       SUM(apaging_ninety_val) AS apaging_ninety_val_sum,\n       SUM(apaging_plus_val) AS apaging_plus_val_sum,\n       'curr' AS apaging_total_val_sum_xtnumericrole,\n       'curr' AS apaging_cur_val_sum_xtnumericrole,\n       'curr' AS apaging_thirty_val_sum_xtnumericrole,\n       'curr' AS apaging_sixty_val_sum_xtnumericrole,\n       'curr' AS apaging_ninety_val_sum_xtnumericrole,\n       'curr' AS apaging_plus_val_sum_xtnumericrole,\n       0 AS apaging_total_val_sum_xttotalrole,\n       0 AS apaging_cur_val_sum_xttotalrole,\n       0 AS apaging_thirty_val_sum_xttotalrole,\n       0 AS apaging_sixty_val_sum_xttotalrole,\n       0 AS apaging_ninety_val_sum_xttotalrole,\n       0 AS apaging_plus_val_sum_xttotalrole\n\nFROM apaging(<? value("relDate") ?>, <? value("useDocDate") ?>)\n<? if exists("vend_id") ?>\nWHERE (apaging_vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\nWHERE (apaging_vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\nWHERE (apaging_vendtype_code ~ <? value("vendtype_pattern") ?>)\n<? endif ?>\nGROUP BY apaging_vend_number,apaging_vend_id,apaging_vend_name\nORDER BY apaging_vend_number;\n	admin	2015-10-01	0
94	apApplications	detail	 used by dspAPApplications\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: apApplications\n-- Name: detail\n-- Notes: used by dspAPApplications\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT apapply.*,\n       vend_number, vend_name,\n       CASE \n         WHEN apapply_source_doctype = 'K' THEN\n            apapply_checkhead_id\n         ELSE\n            apapply_source_apopen_id \n       END AS apapply_source_docnumber_xtidrole,\n       CASE WHEN (apapply_source_doctype='C') THEN <? value("creditMemo") ?>\n            WHEN (apapply_source_doctype='K') THEN <? value("check") ?>\n            ELSE apapply_source_doctype\n       END AS apapply_source_doctype_qtdisplayrole,\n       CASE WHEN (apapply_target_doctype='D') THEN apapply_target_apopen_id\n            WHEN (apapply_target_doctype='V') THEN (SELECT vohead_id\n                                                    FROM vohead\n                                                    WHERE (vohead_number=apapply_target_docnumber))\n       END AS apapply_target_docnumber_xtidrole,\n       CASE WHEN (apapply_target_doctype='C') THEN <? value("creditMemo") ?>\n            WHEN (apapply_target_doctype='D') THEN <? value("debitMemo") ?>\n            WHEN (apapply_target_doctype='V') THEN <? value("voucher") ?>\n            WHEN (apapply_target_doctype='K') THEN <? value("check") ?>\n            ELSE apapply_target_doctype\n       END AS apapply_target_doctype_qtdisplayrole,\n       formatDate(apapply_postdate) AS f_postdate,-- for openrpt\n       formatMoney(apapply_amount) AS f_amount,   -- for openrpt\n       currConcat(apapply_curr_id) AS currAbbr,\n       currtobase(apapply_curr_id,apapply_amount,apapply_postdate) AS base_applied,\n       'curr' AS apapply_amount_xtnumericrole,\n       'curr' AS base_applied_xtnumericrole,\n       0 AS base_applied_xttotalrole\nFROM apapply, vendinfo\nWHERE ( (apapply_vend_id=vend_id)\n  AND   (apapply_postdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("doctypeList") ?>\n  AND   (apapply_source_doctype IN (<? literal("doctypeList") ?>))\n<? endif ?>\n<? if exists("vend_id") ?>\n  AND   (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n  AND   (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n  AND   (vend_vendtype_id IN (SELECT vendtype_id FROM vendtype\n                              WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n      )\nORDER BY apapply_postdate, apapply_source_docnumber;\n	admin	2015-10-01	0
129	apOpenItems	detail	\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: apOpenItems\n-- Name:  detail\n-- Notes:\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT apopen_id, apopen_ponumber, apopen_docnumber,\n                    CASE WHEN (apopen_doctype='C') THEN <? value("creditMemo") ?>\n                         WHEN (apopen_doctype='D') THEN <? value("debitMemo") ?>\n                         WHEN (apopen_doctype='V') THEN <? value("voucher") ?>\n                         ELSE <? value("other") ?>\n                    END AS f_doctype,\n                    CASE WHEN (apopen_doctype='C') THEN 'emphasis' END AS f_doctype_qtforegroundrole,\n                    vend_number, vend_name,\n                    apopen_invcnumber AS invoicenumber,\n                    apopen_docdate, apopen_duedate, apopen_amount, apopen_status,\n<? if exists("isReport") ?>\n                    formatDate(apopen_docdate) AS f_docdate,\n                    formatDate(apopen_duedate) AS f_duedate,\n                    formatMoney(apopen_amount) AS f_amount,\n                    formatMoney(apopen_paid - COALESCE(SUM(apapply_target_paid),0)) AS f_paid,\n                    formatMoney((apopen_amount - apopen_paid + COALESCE(SUM(apapply_target_paid),0)) *\n                    CASE WHEN apopen_doctype IN ('D', 'V') THEN 1 ELSE -1\n                    END) AS f_balance,\n                    formatMoney((apopen_amount - apopen_paid + COALESCE(SUM(apapply_target_paid),0))\n                    / apopen_curr_rate * (CASE WHEN apopen_doctype IN ('D', 'V') THEN 1 ELSE -1\n                         END)) AS f_base_balance,\n<? endif ?>\n                    apopen_paid - COALESCE(SUM(apapply_target_paid),0) AS paid,\n                    (apopen_amount - apopen_paid + COALESCE(SUM(apapply_target_paid),0)) *\n                    CASE WHEN apopen_doctype IN ('D', 'V') THEN 1 ELSE -1\n                    END AS balance,\n                    currConcat(apopen_curr_id) AS currAbbr,\n                    (apopen_amount - apopen_paid + COALESCE(SUM(apapply_target_paid),0))\n                    / apopen_curr_rate * (CASE WHEN apopen_doctype IN ('D', 'V') THEN 1 ELSE -1\n                         END) AS base_balance,\n                    'curr' AS apopen_amount_xtnumericrole,\n                    'curr' AS paid_xtnumericrole,\n                    'curr' AS balance_xtnumericrole,\n                    'curr' AS base_balance_xtnumericrole,\n                    0 AS base_balance_xttotalrole\n             FROM apopen\n               JOIN vendinfo ON (vend_id=apopen_vend_id)\n               JOIN vendtype ON (vendtype_id=vend_vendtype_id)\n               LEFT OUTER JOIN apapply ON (((apopen_id=apapply_target_apopen_id)\n                                       OR (apopen_id=apapply_source_apopen_id))\n                                       AND (apapply_postdate > <? value("asofDate") ?>))\n              WHERE ( (COALESCE(apopen_closedate,date <? value("asofDate") ?> + integer '1')><? value("asofDate") ?>)\n                AND   (CASE WHEN (<? value("useDocDate") ?>) THEN apopen_docdate ELSE apopen_distdate END<=<? value("asofDate") ?>)\n<? if exists("vend_id") ?>\n                AND   (apopen_vend_id=<? value("vend_id") ?>)\n<? endif ?>\n<? if exists("vendtype_id") ?>\n                AND   (vendtype_id=<? value("vendtype_id") ?>)\n<? endif ?>\n<? if exists("vendtype_pattern") ?>\n                AND   (vendtype_code~<? value("vendtype_pattern") ?>)\n<? endif ?>\n                AND   (apopen_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) )\n              GROUP BY apopen_id, apopen_ponumber, apopen_docnumber,apopen_doctype, apopen_invcnumber, apopen_docdate,\n                apopen_duedate, apopen_docdate, apopen_amount, apopen_paid, apopen_curr_id, apopen_curr_rate,\n                apopen.apopen_status, vend_number, vend_name\n              ORDER BY apopen_docdate;	admin	2015-10-01	0
308	apOpenItems	selectedpayments	 \n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: apOpenItems\n-- Name:  selectedpayments\n-- Notes: \n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       CASE WHEN (apopen_doctype='V') THEN <? value("voucher") ?>\n            WHEN (apopen_doctype='D') THEN <? value("debitmemo") ?>\n            WHEN (apopen_doctype='C') THEN <? value("creditmemo") ?>\n       END AS doctype,\n       CASE WHEN (apopen_doctype='C') THEN 'emphasis' END AS doctype_qtforegroundrole,\n       'curr' AS apselect_amount_xtnumericrole,\n       'curr' AS apselect_amount_base_xtnumericrole,\n       'curr' AS apselect_running_base_xtnumericrole,\n       0 AS apselect_running_base_xtrunninginit,\n       1 AS apselect_running_base_xtrunningrole\nFROM (\n-- Vouchers and Debits\nSELECT apopen_id, apselect_id,\n       (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,\n       (vend_number || '-' || vend_name) AS f_vendor,\n       apopen_docnumber, apopen_ponumber, apselect_amount,\n       apopen_invcnumber, apopen_doctype,\n       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_amount_base,\n       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_running_base,\n       currConcat(apselect_curr_id) AS currAbbr\nFROM apopen, apselect, vendinfo, bankaccnt\nWHERE ( (apopen_vend_id=vend_id)\n  AND   (apselect_apopen_id=apopen_id)\n  AND   (apselect_bankaccnt_id=bankaccnt_id)\n  AND   (apopen_doctype IN ('V', 'D'))\n  AND   (apopen_open)\n<? if exists("bankaccntid") ?>\n  AND   (bankaccnt_id=<? value("bankaccntid") ?>)\n<? endif ?>\n<? if exists("vend_id") ?>\n  AND (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n  AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n  AND (vend_vendtype_id IN (SELECT vendtype_id\n                            FROM vendtype\n                            WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n )\nUNION\n-- Credits\nSELECT apopen_id, apselect_id,\n       (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,\n       (vend_number || '-' || vend_name) AS f_vendor,\n       apopen_docnumber, apopen_ponumber, -apselect_amount,\n       apopen_invcnumber, apopen_doctype,\n       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) * -1.0 AS apselect_amount_base,\n       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) * -1.0 AS apselect_running_base,\n       currConcat(apselect_curr_id) AS currAbbr\nFROM apopen, apselect, vendinfo, bankaccnt\nWHERE ( (apopen_vend_id=vend_id)\n  AND   (apselect_apopen_id=apopen_id)\n  AND   (apselect_bankaccnt_id=bankaccnt_id)\n  AND   (apopen_doctype='C')\n  AND   (apopen_open)\n<? if exists("bankaccntid") ?>\n  AND   (bankaccnt_id=<? value("bankaccntid") ?>)\n<? endif ?>\n<? if exists("vend_id") ?>\n  AND (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n  AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n  AND (vend_vendtype_id IN (SELECT vendtype_id\n                            FROM vendtype\n                            WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n )\nORDER BY f_bank, f_vendor, apopen_docnumber\n) AS data;\n	admin	2015-10-01	0
309	apOpenItems	selectpayments	 \n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: apOpenItems\n-- Name:  selectpayments\n-- Notes: \n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       CASE WHEN (apopen_doctype='V') THEN <? value("voucher") ?>\n            WHEN (apopen_doctype='D') THEN <? value("debitMemo") ?>\n            WHEN (apopen_doctype='C') THEN <? value("creditMemo") ?>\n       END AS doctype,\n       CASE WHEN (apopen_doctype='C') THEN 'emphasis' END AS doctype_qtforegroundrole,\n       CASE WHEN (apopen_duedate < CURRENT_DATE) THEN 'error'\n            WHEN(apopen_duedate > CURRENT_DATE) THEN 'emphasis'\n            WHEN(CURRENT_DATE <= determineDiscountDate(apopen_terms_id, apopen_docdate)) THEN 'altemphasis'\n       END AS apopen_duedate_qtforegroundrole,\n       CASE WHEN (apopen_status = 'H') THEN 'error' END AS qtforegroundrole,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS selected_xtnumericrole,\n       'curr' AS running_selected_xtnumericrole,\n       'curr' AS running_amount_xtnumericrole,\n       'curr' AS discount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       'curr' AS base_selected_xtnumericrole,\n       'curr' AS base_discount_xtnumericrole,\n       0      AS base_amount_xttotalrole,\n       0      AS base_selected_xttotalrole,\n       0      AS base_discount_xttotalrole,\n       0      AS running_selected_xtrunninginit,\n       0      AS running_amount_xtrunninginit,\n       1      AS running_selected_xtrunningrole,\n       1      AS running_amount_xtrunningrole\n FROM (\n-- Vouchers and Debits\nSELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,\n       (vend_number || '-' || vend_name) AS vendor,\n       apopen_doctype, apopen_docnumber, apopen_ponumber, apopen_invcnumber,\n       apopen_duedate, apopen_terms_id, apopen_docdate, apopen_status,\n       (apopen_amount - apopen_paid - apCheckPending(apopen_id)) AS amount,\n       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS base_amount,\n       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS running_amount,\n       COALESCE(apselect_amount, 0.0) AS selected,\n       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS base_selected,\n       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS running_selected,\n       COALESCE(apselect_discount,0.0) AS discount,\n       (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,\n       currConcat(apopen_curr_id) AS curr_concat\nFROM vendinfo JOIN apopen ON (apopen_vend_id=vend_id)\n              LEFT OUTER JOIN apselect ON (apselect_apopen_id=apopen_id)\nWHERE ( (apopen_open)\n AND (apopen_doctype IN ('V', 'D'))\n<? if exists("vend_id") ?>\n AND (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n AND (vend_vendtype_id IN (SELECT vendtype_id\n                           FROM vendtype\n                           WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n<? if exists("olderDate") ?>\n AND (apopen_duedate <= <? value("olderDate") ?>)\n<? elseif exists("startDate") ?>\n AND (apopen_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("curr_id") ?>\n AND (apopen_curr_id=<? value("curr_id") ?>)\n<? endif ?>\n)\nUNION\n-- Credits\nSELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,\n       (vend_number || '-' || vend_name) AS vendor,\n       apopen_doctype, apopen_docnumber, apopen_ponumber, apopen_invcnumber,\n       apopen_duedate, apopen_terms_id, apopen_docdate, apopen_status,\n       (apopen_amount - apopen_paid - apCheckPending(apopen_id))  * -1.0 AS amount,\n       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) * -1.0 AS base_amount,\n       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) * -1.0 AS running_amount,\n       COALESCE(apselect_amount, 0.0) * -1.0 AS selected,\n       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) * -1.0 AS base_selected,\n       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) * -1.0 AS running_selected,\n       COALESCE(apselect_discount,0.0) AS discount,\n       (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,\n       currConcat(apopen_curr_id) AS curr_concat\nFROM vendinfo JOIN apopen ON (apopen_vend_id=vend_id)\n              LEFT OUTER JOIN apselect ON (apselect_apopen_id=apopen_id)\nWHERE ( (apopen_open)\n AND (apopen_doctype = 'C')\n<? if exists("vend_id") ?>\n AND (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n AND (vend_vendtype_id IN (SELECT vendtype_id\n                           FROM vendtype\n                           WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n<? if exists("olderDate") ?>\n AND (apopen_duedate <= <? value("olderDate") ?>)\n<? elseif exists("startDate") ?>\n AND (apopen_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("curr_id") ?>\n AND (apopen_curr_id=<? value("curr_id") ?>)\n<? endif ?>\n)\nORDER BY apopen_duedate, amount DESC) AS data\nWHERE (amount != 0);	admin	2015-10-01	0
37	arAging	detail	 used by dspTimePhasedOpenARItems\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: arAging\n-- Name: detail\n-- Notes: used by dspTimePhasedOpenARItems\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT araging_cust_id, araging_cust_number, araging_cust_name,\n       SUM(araging_total_val) AS araging_total_val_sum,\n       SUM(araging_cur_val) AS araging_cur_val_sum,\n       SUM(araging_thirty_val) AS araging_thirty_val_sum,\n       SUM(araging_sixty_val) AS araging_sixty_val_sum,\n       SUM(araging_ninety_val) AS araging_ninety_val_sum,\n       SUM(araging_plus_val) AS araging_plus_val_sum,\n       'curr' AS araging_total_val_sum_xtnumericrole,\n       'curr' AS araging_cur_val_sum_xtnumericrole,\n       'curr' AS araging_thirty_val_sum_xtnumericrole,\n       'curr' AS araging_sixty_val_sum_xtnumericrole,\n       'curr' AS araging_ninety_val_sum_xtnumericrole,\n       'curr' AS araging_plus_val_sum_xtnumericrole,\n       0 AS araging_total_val_sum_xttotalrole,\n       0 AS araging_cur_val_sum_xttotalrole,\n       0 AS araging_thirty_val_sum_xttotalrole,\n       0 AS araging_sixty_val_sum_xttotalrole,\n       0 AS araging_ninety_val_sum_xttotalrole,\n       0 AS araging_plus_val_sum_xttotalrole\n\nFROM araging(<? value("relDate") ?>, <? value("useDocDate") ?>) \n<? if exists("cust_id") ?>\nWHERE (araging_cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\nWHERE (araging_cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custgrp_id") ?>\nLEFT OUTER JOIN custgrpitem ON (araging_cust_id = custgrpitem_cust_id)\nWHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? elseif exists("custtype_pattern") ?>\nWHERE (araging_custtype_code ~ <? value("custtype_pattern") ?>)\n<? endif ?>\nGROUP BY araging_cust_number,araging_cust_id,araging_cust_name\nORDER BY araging_cust_number;\n	admin	2015-10-01	0
38	arApplications	detail	 used by dspARApplications\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: arApplications\n-- Name: detail\n-- Notes: used by dspARApplications\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT arapply.*,\n       cust_number, cust_name,\n       CASE WHEN (arapply_source_doctype='C') THEN <? value("creditMemo") ?>\n            WHEN (arapply_source_doctype='R') THEN <? value("cashdeposit") ?>\n            WHEN (arapply_fundstype='C') THEN <? value("check") ?>\n            WHEN (arapply_fundstype='T') THEN <? value("certifiedCheck") ?>\n            WHEN (arapply_fundstype='M') THEN <? value("masterCard") ?>\n            WHEN (arapply_fundstype='V') THEN <? value("visa") ?>\n            WHEN (arapply_fundstype='A') THEN <? value("americanExpress") ?>\n            WHEN (arapply_fundstype='D') THEN <? value("discoverCard") ?>\n            WHEN (arapply_fundstype='R') THEN <? value("otherCreditCard") ?>\n            WHEN (arapply_fundstype='K') THEN <? value("cash") ?>\n            WHEN (arapply_fundstype='W') THEN <? value("wireTransfer") ?>\n            WHEN (arapply_fundstype='O') THEN <? value("other") ?>\n       END AS doctype,\n       CASE WHEN (arapply_source_doctype='C') THEN <? value("creditMemo") ?>\n            WHEN (arapply_source_doctype='R') THEN <? value("cashdeposit") ?>\n            WHEN (arapply_source_doctype='K') THEN <? value("apcheck") ?>\n            ELSE <? value("other") ?>\n       END AS sourcedoctype,\n       CASE WHEN (arapply_target_doctype='D') THEN <? value("debitMemo") ?>\n            WHEN (arapply_target_doctype='I') THEN <? value("invoice") ?>\n            WHEN (arapply_target_doctype='K') THEN <? value("apcheck") ?>\n            ELSE <? value("other") ?>\n       END AS targetdoctype,\n       CASE WHEN (arapply_source_doctype IN ('C','R')) THEN TEXT(arapply_source_docnumber)\n            ELSE arapply_refnumber\n       END AS source,\n       TEXT(arapply_target_docnumber) AS target,\n       currConcat(arapply_curr_id) AS currAbbr,\n       currtobase(arapply_curr_id,arapply_applied,arapply_postdate) AS base_applied,\n       'curr' AS arapply_applied_xtnumericrole,\n       'curr' AS base_applied_xtnumericrole,\n       0 AS base_applied_xttotalrole\nFROM arapply, custinfo\nWHERE ( (arapply_cust_id=cust_id)\n  AND   (arapply_postdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n  AND   (arapply_source_doctype IN (\n<? if exists("includeCreditMemos") ?>\n  <? if exists("includeCashReceipts") ?>\n            'K', 'C', 'R'\n  <? else ?>\n            'C', 'R'\n  <? endif ?>\n<? else ?>\n            'K'\n<? endif ?> ))\n<? if exists("cust_id") ?>\n  AND   (cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\n  AND   (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND   (cust_custtype_id IN (SELECT custtype_id FROM custtype\n                              WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n      )\nORDER BY arapply_postdate, source;\n	admin	2015-10-01	0
487	arCreditMemos	unapplied	 used by unappliedARCreditMemos\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: arCreditMemos\n-- Name: unapplied\n-- Notes: used by unappliedARCreditMemos\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT aropen_id, aropen_docnumber,\n       cust_number, cust_name,\n       aropen_amount,\n       (aropen_paid + COALESCE(prepared,0.0) + COALESCE(cashapplied,0.0)) AS applied,\n       (aropen_amount - aropen_paid - COALESCE(prepared,0.0) - COALESCE(cashapplied,0.0)) AS balance,\n       currConcat(aropen_curr_id) AS currAbbr,\n<? if exists("isReport") ?>\n       formatMoney(aropen_amount) AS f_amount,\n       formatMoney(aropen_paid + COALESCE(prepared,0.0) + COALESCE(cashapplied,0.0)) AS f_applied,\n       formatMoney(aropen_amount - aropen_paid - COALESCE(prepared,0.0) - COALESCE(cashapplied,0.0)) AS f_balance,\n<? endif ?>\n       'curr' AS aropen_amount_xtnumericrole,\n       'curr' AS applied_xtnumericrole,\n       'curr' AS balance_xtnumericrole\nFROM aropen\n       LEFT OUTER JOIN (SELECT aropen_id AS prepared_aropen_id,\n                               SUM(checkitem_amount + checkitem_discount) AS prepared\n                          FROM checkhead JOIN checkitem ON (checkitem_checkhead_id=checkhead_id)\n                                         JOIN aropen ON (checkitem_aropen_id=aropen_id)\n                         WHERE ((NOT checkhead_posted)\n                           AND  (NOT checkhead_void))\n                         GROUP BY aropen_id ) AS sub1\n         ON (prepared_aropen_id=aropen_id)\n       LEFT OUTER JOIN (SELECT aropen_id AS cash_aropen_id,\n                               SUM(cashrcptitem_amount + cashrcptitem_discount) * -1.0 AS cashapplied\n                          FROM cashrcpt JOIN cashrcptitem ON (cashrcptitem_cashrcpt_id=cashrcpt_id)\n                                        JOIN aropen ON (cashrcptitem_aropen_id=aropen_id)\n                         WHERE (NOT cashrcpt_posted)\n                         GROUP BY aropen_id ) AS sub2\n         ON (cash_aropen_id=aropen_id)\n       JOIN custinfo ON (aropen_cust_id=cust_id)\nWHERE (aropen_doctype IN ('C', 'R'))\n  AND (aropen_open)\n  AND ((aropen_amount - aropen_paid - COALESCE(prepared,0.0) - COALESCE(cashapplied,0.0)) > 0.0)\nORDER BY aropen_docnumber;\n	admin	2015-10-01	0
458	packingList	getreport	 get the reportname should be used for a packing list or pick list\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: packingList\n-- Name:  getreport\n-- Notes: get the reportname should be used for a packing list or pick list\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists('sohead_id') ?>\nSELECT findCustomerForm(cohead_cust_id,\n                       <? value('form') ?>) AS reportname\n  FROM cohead \n WHERE (cohead_id=<? value('sohead_id' ?>);\n<? elseif exists('tohead_id') ?>\nSELECT findTOForm(<? value('tohead_id') ?>,\n                  <? value('form') ?>) AS reportname;\n<? endif ?>\n	admin	2015-10-01	0
39	arHistory	detail	 used by dspCustomerARHistory, dspCustomerInformation\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: arHistory\n-- Name: detail\n-- Notes: used by dspCustomerARHistory, dspCustomerInformation\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT aropen_id, applyid,\n       sortdate, sortnumber, type,\n       docnumber, open, documenttype,\n       docdate, duedate, amount, balance, base_balance, currAbbr,\n       formatBoolYN(open) AS f_open,\n       formatDate(docdate) AS f_docdate, formatDate(duedate) AS f_duedate,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       type AS xtindentrole\n  FROM (\n    SELECT 0 AS type, aropen_id, -1 AS applyid,\n           aropen_docdate AS sortdate, (aropen_docnumber || aropen_doctype) AS sortnumber,\n           aropen_docnumber AS docnumber,\n           aropen_open AS open,\n           CASE WHEN (aropen_doctype='I') THEN <? value("invoice") ?>\n                WHEN (aropen_doctype='C') THEN <? value("creditMemo") ?>\n                WHEN (aropen_doctype='D') THEN <? value("debitMemo") ?>\n                WHEN (aropen_doctype='R') then <? value("cashdeposit") ?>\n                ELSE <? value("other") ?>\n           END AS documenttype,\n           aropen_docdate AS docdate,\n           aropen_duedate AS duedate,\n           aropen_amount AS amount,\n           (aropen_amount - aropen_paid) AS balance,\n           CASE WHEN (aropen_doctype IN ('C', 'R')) THEN\n                        (currtobase(aropen_curr_id,(aropen_amount - aropen_paid),aropen_docdate) * -1.0)\n                ELSE currtobase(aropen_curr_id,(aropen_amount - aropen_paid),aropen_docdate)\n           END AS base_balance,\n           currConcat(aropen_curr_id) AS currAbbr\n     FROM aropen\n    WHERE ( (aropen_cust_id=<? value("cust_id") ?>) \n    <? if exists("startDate") ?>\n      AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? endif ?> )\n\n    UNION\n    SELECT 1 AS type, -1 AS aropen_id, arapply_source_aropen_id AS applyid,\n           aropen_docdate AS sortdate, (aropen_docnumber || aropen_doctype) AS sortnumber,\n           CASE WHEN (arapply_source_doctype IN ('C','R')) THEN arapply_source_docnumber\n                WHEN (arapply_source_doctype='K') THEN arapply_refnumber\n                ELSE <? value("error") ?>\n           END AS docnumber,\n           NULL AS open,\n           CASE WHEN (arapply_source_doctype='C') THEN <? value("creditMemo") ?>\n                WHEN (arapply_source_doctype='R') THEN <? value("cashdeposit") ?>\n                WHEN (arapply_fundstype='C') THEN <? value("check") ?>\n                WHEN (arapply_fundstype='T') THEN <? value("certifiedCheck") ?>\n                WHEN (arapply_fundstype='M') THEN <? value("masterCard") ?>\n                WHEN (arapply_fundstype='V') THEN <? value("visa") ?>\n                WHEN (arapply_fundstype='A') THEN <? value("americanExpres") ?>\n                WHEN (arapply_fundstype='D') THEN <? value("discoverCard") ?>\n                WHEN (arapply_fundstype='R') THEN <? value("otherCreditCard") ?>\n                WHEN (arapply_fundstype='K') THEN <? value("cash") ?>\n                WHEN (arapply_fundstype='W') THEN <? value("wireTransfer") ?>\n                WHEN (arapply_fundstype='O') THEN <? value("other") ?>\n           END AS documenttype,\n           COALESCE(cashrcpt_docdate, arapply_postdate) AS docdate,\n           arapply_distdate AS duedate,\n           arapply_applied AS amount,\n           0 AS balance,\n           0 AS base_balance,\n           currConcat(arapply_curr_id) AS currAbbr\n     FROM arapply JOIN aropen ON (arapply_target_aropen_id=aropen_id)\n                  LEFT OUTER JOIN cashrcptitem ON ( (arapply_reftype='CR') AND\n                                                    (arapply_ref_id=cashrcptitem_id) )\n                  LEFT OUTER JOIN cashrcpt ON (cashrcpt_id=cashrcptitem_cashrcpt_id)\n    WHERE ( (arapply_target_doctype IN ('I', 'D'))\n      AND   (arapply_cust_id=<? value("cust_id") ?>)\n      AND   (aropen_cust_id=<? value("cust_id") ?>)\n    <? if exists("startDate") ?>\n      AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? endif ?> )\n\n    UNION\n    SELECT 2 AS type, -1 AS aropen_id, arapply_target_aropen_id AS applyid,\n           aropen_docdate AS sortdate, (aropen_docnumber || aropen_doctype) AS sortnumber,\n           arapply_target_docnumber AS docnumber,\n           NULL AS open,\n           CASE WHEN (arapply_target_doctype='I') THEN <? value("invoice") ?>\n                WHEN (arapply_target_doctype='D') THEN <? value("debitMemo") ?>\n                ELSE <? value("other") ?>\n           END AS documenttype,\n           arapply_postdate AS docdate,\n           arapply_distdate AS duedate,\n           arapply_applied AS amount,\n           0 AS balance,\n           0 AS base_balance,\n           currConcat(arapply_curr_id) AS currAbbr\n     FROM arapply, aropen\n    WHERE ( (arapply_source_doctype IN ('K', 'C', 'R'))\n      AND  (arapply_source_aropen_id=aropen_id)\n      AND  (arapply_cust_id=<? value("cust_id") ?>)\n      AND  (aropen_cust_id=<? value("cust_id") ?>)\n    <? if exists("startDate") ?>\n      AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? endif ?> )\n\n    UNION\n    SELECT 0 AS type, -1 AS aropen_id, -1 AS applyid,\n           invchead_invcdate AS sortdate, (invchead_invcnumber || 'I') AS sortnumber,\n           invchead_invcnumber AS docnumber,\n           false AS open,\n           <? value("zeroinvoice") ?> AS documenttype,\n           invchead_invcdate AS docdate,\n           invchead_invcdate AS duedate,\n           0 AS amount,\n           0 AS balance,\n           0 AS base_balance,\n           currConcat(invchead_curr_id) AS currAbbr\n     FROM invchead\n    WHERE ( (invchead_cust_id=<? value("cust_id") ?>) \n    <? if exists("startDate") ?>\n      AND   (invchead_invcdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? endif ?>\n      AND   (invchead_posted)\n      AND   ((SELECT SUM(invcitem_price)\n              FROM invcitem\n             WHERE (invcitem_invchead_id=invchead_id))=0) )\n  ) AS data\n  ORDER BY sortdate, sortnumber, type;\n	admin	2015-10-01	0
40	arOpenApplications	detail	 used by applyARCreditMemo, cashReceipt\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: arOpenApplications\n-- Name: detail\n-- Notes: used by applyARCreditMemo, cashReceipt\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS applied_xtnumericrole,\n       'curr' AS pending_xtnumericrole,\n       currConcat(balance_curr) AS balance_curr_qtdisplayrole,\n       CASE WHEN (doctype='D') THEN <? value("debitMemo") ?>\n            WHEN (doctype='I') THEN <? value("invoice") ?>\n            WHEN (doctype='C') THEN <? value("creditMemo") ?>\n            WHEN (doctype='R') THEN <? value("cashdeposit") ?>\n       END AS doctype_qtdisplayrole,\n       CASE WHEN (doctype='C') THEN 'emphasis'\n            WHEN (doctype='R') THEN 'altemphasis'\n       END AS doctype_qtforegroundrole,\n<? if exists("cashrcpt_id") ?>\n    CASE WHEN (pending - currtobase(cashrcpt_curr_id, applied, cashrcpt_distdate) - discount > balance) \n    AND doctype IN ('I','D')\n    AND NOT cashrcpt_posted\n<? else ?>\n    CASE WHEN (pending - applied - discount > balance)\n<? endif ?>  \n       THEN 'error' END AS qtforegroundrole\nFROM (SELECT\n      aropen_id,\n<? if exists("cashrcpt_id") ?>\n       COALESCE(s.cashrcptitem_id, -1) AS alt_id,\n       COALESCE(cashrcpt_posted,FALSE) AS cashrcpt_posted,\n       cashrcpt_curr_id,\n       cashrcpt_distdate,\n<? endif ?>\n       aropen_doctype AS doctype,\n       aropen_docnumber, aropen_ordernumber,\n       aropen_docdate, aropen_duedate,\n       (aropen_amount - aropen_paid - calcpendingarapplications(aropen_id)) *\n       (CASE WHEN aropen_doctype IN ('C','R') THEN -1 ELSE 1 END ) AS balance,\n       aropen_curr_id AS balance_curr,\n<? if exists("cashrcpt_id") ?>\n       COALESCE(s.cashrcptitem_amount, 0.0) AS applied,\n       COALESCE(s.cashrcptitem_discount, 0.0) AS discount,\n--       (SELECT COALESCE(SUM(p.cashrcptitem_amount), 0)\n--                      FROM cashrcptitem p\n--                     WHERE (p.cashrcptitem_aropen_id=aropen_id)\n--                     AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))\n--                   AS applied,\n--       (SELECT COALESCE(SUM(p.cashrcptitem_discount), 0)\n--                      FROM cashrcptitem p\n--                     WHERE (p.cashrcptitem_aropen_id=aropen_id)\n--                     AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))\n--                   AS discount,\n       currConcat(cashrcpt_curr_id) AS applied_curr,\n<? elseif exists("source_aropen_id") ?>\n       COALESCE(arcreditapply_amount, 0) AS applied,\n       0 AS discount,\n       currConcat(arcreditapply_curr_id) AS applied_curr,\n<? endif ?>\n       calcpendingarapplications(aropen_id) AS pending,\n       currConcat(aropen_curr_id) AS pending_curr\n FROM aropen LEFT OUTER JOIN\n <? if exists("cashrcpt_id") ?>\n      cashrcptitem s ON (s.cashrcptitem_aropen_id=aropen_id\n                     AND cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>)\n        LEFT OUTER JOIN\n      cashrcpt ON (cashrcptitem_cashrcpt_id = cashrcpt_id\n               AND cashrcpt_id=<? value("cashrcpt_id") ?>)\n<? elseif exists("source_aropen_id") ?>\n      arcreditapply ON ((arcreditapply_source_aropen_id=<? value("source_aropen_id") ?>)\n                    AND (arcreditapply_target_aropen_id=aropen_id) )\n<? endif ?>\n WHERE (\n<? if exists("posted") ?> \n   (s.cashrcptitem_aropen_id=aropen_id)\n<? else ?>\n   (aropen_open)\n<? endif ?>\n<? if exists("noCredits") ?>\n   AND (aropen_doctype IN ('D', 'I'))\n<? elseif exists("cashrcpt_id") ?>\n<? else ?>\n   AND (aropen_doctype IN ('D', 'I'))\n<? endif ?>\n   AND (aropen_cust_id=<? value("cust_id") ?>) )\n ) AS dummy\n ORDER BY aropen_duedate, balance;\n	admin	2015-10-01	0
42	arOpenItems	detail	 used by arWorkBench, dspAROpenItems\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: arOpenItems\n-- Name: detail\n-- Notes: used by arWorkBench, dspAROpenItems\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("totalOnly") ?>\nSELECT SUM(CASE WHEN (aropen_doctype IN ('C', 'R')) THEN\n                    (aropen_amount - aropen_paid) / aropen_curr_rate * -1\n                ELSE (aropen_amount - aropen_paid) / aropen_curr_rate\n           END) AS total_balance\nFROM aropen JOIN custinfo ON (aropen_cust_id=cust_id)\n            LEFT OUTER JOIN custtype ON (cust_custtype_id=custtype_id)\n            LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ( (aropen_open)\n<? if exists("cust_id") ?>\n  AND   (aropen_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n      )\n;\n<? else ?>\n\n-- Get unposted invoices\n<? if exists("showUnposted") ?>\n<? if not exists("creditsOnly") ?>\nSELECT -1 AS id,\n       0 AS altId,\n       invchead_invcnumber AS docnumber,\n       invchead_id AS docnumber_xtidrole,\n       invchead_posted AS posted,\n       invchead_invcdate AS docdate,\n       NULL::date AS aropen_duedate,\n       invchead_ordernumber AS ordernumber,\n       cohead_id AS ordernumber_xtidrole,\n       <? value("invoice") ?>  AS doctype,\n       NULL AS doctype_qtforegroundrole,\n       invoicetotal(invchead_id) AS amount,\n       currtobase(invchead_curr_id, invoicetotal(invchead_id), invchead_invcdate) AS base_amount,\n       0 AS paid,\n       0 AS base_paid,\n       0 AS balance,\n       currConcat(invchead_curr_id) AS currAbbr,\n       0 AS base_balance,\n<? if exists("includeFormatted") ?>\n       formatDate(invchead_invcdate) AS f_docdate,\n       NULL::text AS f_duedate,\n       formatMoney(0) AS f_amount,\n       formatMoney(0) AS f_paid,\n       formatMoney(0) AS f_balance,\n<? endif ?>\n       cust_id, cust_number, cust_name,\n       (invchead_recurring_invchead_id IS NOT NULL) AS recurring,\n       false AS open,\n       NULL AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       NULL::text AS aropen_docnumber_qtdisplayrole,\n       NULL::text AS aropen_docdate_qtdisplayrole,\n       0 AS xtindentrole,\n       '' AS aropen_duedate_qtforegroundrole,\n       NULL::integer AS ccard_number_xtidrole,\n       firstLine(invchead_notes) AS notes\nFROM invchead\n           LEFT OUTER JOIN cohead ON (invchead_ordernumber=cohead_number)\n           JOIN custinfo ON (invchead_cust_id=cust_id)\n           JOIN custtype ON (cust_custtype_id=custtype_id)\n\t   LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ((NOT invchead_posted)\n<? if exists("cust_id") ?>\n  AND   (invchead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (invchead_invcdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\n  GROUP BY id,                      altId,                  invchead_id,\n           invchead_invcdate,       invchead_posted,        invchead_curr_id,\n           invchead_recurring,      invchead_invcnumber,    invchead_posted,\n           invchead_ordernumber,    cohead_id,\n           cust_id,                 cust_number,            cust_name,\n           invchead_recurring_invchead_id, invchead_notes\n\nUNION\n<? endif ?>\n<? endif ?>\n\n-- Get unposted credit memos\n<? if exists("showUnposted") ?>\n<? if not exists("debitsOnly") ?>\nSELECT -1 AS id,\n       1 AS altId,\n       cmhead_number AS docnumber,\n       cmhead_id AS docnumber_xtidrole,\n       cmhead_posted AS posted,\n       cmhead_docdate AS docdate,\n       NULL::date AS aropen_duedate,\n       NULL::text AS ordernumber,\n       -1 AS ordernumber_xtidrole,\n       <? value("return") ?>  AS doctype,\n       CASE WHEN (NOT cmhead_posted) THEN 'emphasis'\n       END AS doctype_qtforegroundrole,\n       creditmemototal(cmhead_id) AS amount,\n       currtobase(cmhead_curr_id, creditmemototal(cmhead_id), cmhead_docdate) AS base_amount,\n       0 AS paid,\n       0 AS base_paid,\n       0 AS balance,\n       currConcat(cmhead_curr_id) AS currAbbr,\n       0  AS base_balance,\n<? if exists("includeFormatted") ?>\n       formatDate(cmhead_docdate) AS f_docdate,\n       NULL::text AS f_duedate,\n       formatMoney(creditmemototal(cmhead_id)) AS f_amount,\n       formatMoney(0) AS f_paid,\n       formatMoney(0) AS f_balance,\n<? endif ?>\n       cust_id, cust_number, cust_name,\n       false AS recurring,\n       false AS open,\n       NULL AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       NULL::text AS aropen_docnumber_qtdisplayrole,\n       NULL::text AS aropen_docdate_qtdisplayrole,\n       0 AS xtindentrole,\n       '' AS aropen_duedate_qtforegroundrole,\n       NULL::integer AS ccard_number_xtidrole,\n       firstLine(cmhead_comments) AS notes\nFROM cmhead\n            JOIN custinfo ON (cmhead_cust_id=cust_id)\n            JOIN custtype ON (cust_custtype_id=custtype_id)\n\t    LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ((NOT cmhead_posted)\n<? if exists("cust_id") ?>\n  AND   (cmhead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (cmhead_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\n  GROUP BY id,                      altId,                  cmhead_id,\n           cmhead_docdate,          cmhead_posted,          cmhead_curr_id,\n           cmhead_number,           cmhead_posted,          cmhead_comments,\n           cust_id,                 cust_number,            cust_name\n\nUNION\n<? endif ?>\n<? endif ?>\n\n-- Get Posted AR Open\nSELECT aropen_id AS id,\n       CASE WHEN (aropen_doctype='I') THEN 0\n            WHEN (aropen_doctype='C') THEN 1\n            WHEN (aropen_doctype='D') THEN 2\n            WHEN (aropen_doctype='R') THEN 3\n            ELSE -1\n       END AS altId,\n       aropen_docnumber AS docnumber,\n       COALESCE(invchead_id,cmhead_id,-1) AS docnumber_xtidrole,\n       true AS posted,\n       aropen_docdate AS docdate,\n       aropen_duedate,\n       aropen_ordernumber AS ordernumber,\n       COALESCE(cohead_id,-1) AS ordernumber_xtidrole,\n       CASE WHEN (aropen_doctype='I') THEN <? value("invoice") ?>\n            WHEN (aropen_doctype='C') THEN <? value("creditMemo") ?>\n            WHEN (aropen_doctype='D') THEN <? value("debitMemo") ?>\n            WHEN (aropen_doctype='R') THEN <? value("cashdeposit") ?>\n            ELSE <? value("other") ?>\n       END AS doctype,\n       CASE WHEN (aropen_doctype='C') THEN 'emphasis' \n         ELSE CASE WHEN(aropen_doctype='R')THEN 'altemphasis'\n         END\n       END AS doctype_qtforegroundrole,\n       aropen_amount AS amount,\n       aropen_amount/aropen_curr_rate AS base_amount,\n       (aropen_paid - (COALESCE(SUM(arapply_target_paid),0))) AS paid,\n       (aropen_paid - (COALESCE(SUM(arapply_target_paid),0))/aropen_curr_rate) AS base_paid,\n        (((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0))) *\n        CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END) AS balance,\n       currConcat(aropen_curr_id) AS currAbbr,\n        (((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0)))/aropen_curr_rate *\n        CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END)  AS base_balance,\n<? if exists("includeFormatted") ?>\n       formatDate(aropen_docdate) AS f_docdate,\n       formatDate(aropen_duedate) AS f_duedate,\n       formatMoney(aropen_amount) AS f_amount,\n       formatMoney(aropen_paid - (COALESCE(SUM(arapply_target_paid),0))) AS f_paid,\n       formatMoney((((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0))) *\n        CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END)) AS f_balance,\n<? endif ?>\n       cust_id, cust_number, cust_name,\n       COALESCE(invchead_recurring_invchead_id IS NOT NULL, false) AS recurring,\n       aropen_open AS open,\n       formatccnumber(decrypt(setbytea(ccard_number),\n                              setbytea(<? value("key") ?>), 'bf')) AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr'AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       NULL AS aropen_docnumber_qtdisplayrole,\n       NULL AS aropen_docdate_qtdisplayrole,\n       0 AS xtindentrole,\n       CASE WHEN ((COALESCE(aropen_duedate,current_date) < current_date) AND COALESCE(aropen_open,FALSE)) THEN 'error' \n       END AS aropen_duedate_qtforegroundrole,\n       ccpay_id AS ccard_number_xtidrole,\n       firstLine(aropen_notes) AS notes\nFROM aropen \n<? if exists("incidentsOnly") ?>\n            JOIN incdt ON (incdt_aropen_id=aropen_id)\n<? endif ?>\n            JOIN custinfo ON (aropen_cust_id=cust_id)\n            JOIN custtype ON (cust_custtype_id=custtype_id)\n\t    LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\n            LEFT OUTER JOIN invchead ON ((aropen_docnumber=invchead_invcnumber)\n                                   AND (aropen_doctype='I'))\n            LEFT OUTER JOIN cohead ON (invchead_ordernumber=cohead_number)\n            LEFT OUTER JOIN cmhead ON ((aropen_docnumber=cmhead_number)\n                                   AND (aropen_doctype='C'))\n            LEFT OUTER JOIN arapply ON (((aropen_id=arapply_source_aropen_id)\n                             OR (aropen_id=arapply_target_aropen_id))\n                             AND (arapply_distdate>COALESCE(<? value("asofDate") ?>,current_date)))\n            LEFT OUTER JOIN payaropen ON (payaropen_aropen_id=aropen_id)\n            LEFT OUTER JOIN ccpay     ON (payaropen_ccpay_id=ccpay_id)\n            LEFT OUTER JOIN ccard     ON (ccpay_ccard_id=ccard_id)\nWHERE ((true)\n<? if not exists("showClosed") ?>\n  AND (aropen_docdate <= COALESCE(<? value("asofDate") ?>, current_date))\n  AND (COALESCE(aropen_closedate, DATE(<? value("asofDate") ?>) + 1, current_date + 1) > COALESCE(<? value("asofDate") ?>, current_date)) \n<? endif ?>\n<? if exists("debitsOnly") ?>\n  AND   (aropen_doctype IN ('D','I'))\n<? elseif exists("creditsOnly") ?>\n  AND   (aropen_doctype IN ('C', 'R'))\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND   (aropen_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("startDueDate") ?>\n  AND   (aropen_duedate >= <? value("startDueDate") ?>)\n<? endif ?>\n<? if exists("endDueDate") ?>\n  AND   (aropen_duedate <= <? value("endDueDate") ?>)\n<? endif ?>\n      )\n  GROUP BY id,                      altId,\t            invchead_id,\n           aropen_docdate,          aropen_duedate,         aropen_doctype,         \n           aropen_docnumber,        aropen_amount,          \n           aropen_notes,            aropen_posted,          aropen_ordernumber,\n           aropen_paid,             aropen_open,            aropen_curr_id,\n           aropen_closedate,        aropen_curr_rate,       cmhead_id,\n           cust_id, \t\t    cust_number,            cust_name,\n           cohead_id,               ccpay_id,               ccard_number,\n           invchead_recurring_invchead_id\nUNION\nSELECT -1,\n       4 AS altId,\n       aropen_docnumber AS docnumber,\n       -1 AS docnumber_xtidrole,\n       NULL AS posted, \n       aropen_docdate AS docdate,\n       NULL AS aropen_duedate,\n       CAST(incdt_number AS text) AS ordernumber,\n       incdt_id AS ordernumber_xtidrole,\n       NULL AS doctype,\n       NULL AS doctype_qtforegroundrole,\n       NULL AS amount,\n       NULL AS base_amount,\n       NULL AS paid,\n       NULL AS base_paid,\n       NULL AS balance,\n       NULL AS currAbbr,\n       NULL AS base_balance,\n<? if exists("includeFormatted") ?>\n       NULL AS f_docdate,\n       NULL AS f_duedate,\n       NULL AS f_amount,\n       NULL AS f_paid,\n       NULL AS f_balance,\n<? endif ?>\n       NULL,incdt_assigned_username, incdt_summary,\n       NULL AS recurring, NULL AS open,\n       NULL AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       '' AS aropen_docnumber_qtdisplayrole,\n       '' AS aropen_docdate_qtdisplayrole,\n       1 AS xtindentrole,\n       CASE WHEN ((COALESCE(aropen_duedate,current_date) < current_date) AND COALESCE(aropen_open,FALSE)) THEN 'error' \n       END AS aropen_duedate_qtforegroundrole,\n       NULL::integer AS ccard_xtidrole,\n       firstLine(incdt_descrip) AS notes\nFROM incdt JOIN aropen ON (aropen_id=incdt_aropen_id)\n           JOIN custinfo ON (aropen_cust_id=cust_id)\n           JOIN custtype ON (cust_custtype_id=custtype_id)\n\t   LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ((true)\n<? if not exists("showClosed") ?>\n  AND (aropen_docdate <= COALESCE(<? value("asofDate") ?>, current_date))\n  AND (COALESCE(aropen_closedate, DATE(<? value("asofDate") ?>) + 1, current_date + 1) > COALESCE(<? value("asofDate") ?>, current_date)) \n<? endif ?>\n<? if exists("debitsOnly") ?>\n  AND   (NOT aropen_doctype IN ('C', 'R'))\n<? endif ?>\n<? if exists("creditsOnly") ?>\n  AND   (aropen_doctype IN ('C', 'R'))\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND   (aropen_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("startDueDate") ?>\n  AND   (aropen_duedate >= <? value("startDueDate") ?>)\n<? endif ?>\n<? if exists("endDueDate") ?>\n  AND   (aropen_duedate <= <? value("endDueDate") ?>)\n<? endif ?>\n      )\n\nORDER BY\n  docdate DESC, docnumber DESC, xtindentrole\n;\n<? endif ?>\n	admin	2015-10-01	0
231	arOpenItems	f_detail	 This version for printed reports that need a way to include formatted values\n        since there is no good way to differentiate different printed parameters in \n        display class.  Used to be printed version got an extra parameter. Formatted\n        values slow things down considerably on screen version otherwise. This\n        should go away if/when we get OpenRPT to do its own formatting.\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: arOpenItems\n-- Name:  f_detail\n-- Notes: This version for printed reports that need a way to include formatted values\n--        since there is no good way to differentiate different printed parameters in \n--        display class.  Used to be printed version got an extra parameter. Formatted\n--        values slow things down considerably on screen version otherwise. This\n--        should go away if/when we get OpenRPT to do its own formatting.\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("totalOnly") ?>\nSELECT SUM(CASE WHEN (aropen_doctype IN ('C', 'R')) THEN\n                    (aropen_amount - aropen_paid) / aropen_curr_rate * -1\n                ELSE (aropen_amount - aropen_paid) / aropen_curr_rate\n           END) AS total_balance\nFROM aropen JOIN custinfo ON (aropen_cust_id=cust_id)\n            LEFT OUTER JOIN custtype ON (cust_custtype_id=custtype_id)\n            LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ( (aropen_open)\n<? if exists("cust_id") ?>\n  AND   (aropen_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n      )\n;\n<? else ?>\n\n-- Get unposted invoices\n<? if exists("showUnposted") ?>\n<? if not exists("creditsOnly") ?>\nSELECT -1 AS id,\n       0 AS altId,\n       invchead_invcnumber AS docnumber,\n       invchead_id AS docnumber_xtidrole,\n       invchead_posted AS posted,\n       invchead_invcdate AS docdate,\n       NULL::date AS aropen_duedate,\n       invchead_ordernumber AS ordernumber,\n       cohead_id AS ordernumber_xtidrole,\n       <? value("invoice") ?>  AS doctype,\n       NULL AS doctype_qtforegroundrole,\n       invoicetotal(invchead_id) AS amount,\n       currtobase(invchead_curr_id, invoicetotal(invchead_id), invchead_invcdate) AS base_amount,\n       0 AS paid,\n       0 AS base_paid,\n       0 AS balance,\n       currConcat(invchead_curr_id) AS currAbbr,\n       0 AS base_balance,\n       formatDate(invchead_invcdate) AS f_docdate,\n       NULL::text AS f_duedate,\n       formatMoney(invoicetotal(invchead_id)) AS f_amount,\n       formatMoney(0) AS f_paid,\n       formatMoney(0) AS f_balance,\n       cust_id, cust_number, cust_name,\n       (invchead_recurring_invchead_id IS NOT NULL) AS recurring,\n       false AS open,\n       NULL AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       NULL::text AS aropen_docnumber_qtdisplayrole,\n       NULL::text AS aropen_docdate_qtdisplayrole,\n       0 AS xtindentrole,\n       '' AS aropen_duedate_qtforegroundrole,\n       NULL::integer AS ccard_number_xtidrole,\n       firstLine(invchead_notes) AS notes\nFROM invchead\n           LEFT OUTER JOIN cohead ON (invchead_ordernumber=cohead_number)\n           JOIN custinfo ON (invchead_cust_id=cust_id)\n           JOIN custtype ON (cust_custtype_id=custtype_id)\n\t   LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ((NOT invchead_posted)\n<? if exists("cust_id") ?>\n  AND   (invchead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (invchead_invcdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\n  GROUP BY id,                      altId,                  invchead_id,\n           invchead_invcdate,       invchead_posted,        invchead_curr_id,\n           invchead_recurring,      invchead_invcnumber,    invchead_posted,\n           invchead_ordernumber,    cohead_id,\n           cust_id,                 cust_number,            cust_name,\n           invchead_recurring_invchead_id, invchead_notes\n\nUNION\n<? endif ?>\n<? endif ?>\n\n-- Get unposted credit memos\n<? if exists("showUnposted") ?>\n<? if not exists("debitsOnly") ?>\nSELECT -1 AS id,\n       1 AS altId,\n       cmhead_number AS docnumber,\n       cmhead_id AS docnumber_xtidrole,\n       cmhead_posted AS posted,\n       cmhead_docdate AS docdate,\n       NULL::date AS aropen_duedate,\n       NULL::text AS ordernumber,\n       -1 AS ordernumber_xtidrole,\n       <? value("return") ?>  AS doctype,\n       CASE WHEN (NOT cmhead_posted) THEN 'emphasis'\n       END AS doctype_qtforegroundrole,\n       creditmemototal(cmhead_id) AS amount,\n       currtobase(cmhead_curr_id, creditmemototal(cmhead_id), cmhead_docdate) AS base_amount,\n       0 AS paid,\n       0 AS base_paid,\n       0 AS balance,\n       currConcat(cmhead_curr_id) AS currAbbr,\n       0  AS base_balance,\n       formatDate(cmhead_docdate) AS f_docdate,\n       NULL::text AS f_duedate,\n       formatMoney(creditmemototal(cmhead_id)) AS f_amount,\n       formatMoney(0) AS f_paid,\n       formatMoney(0) AS f_balance,\n       cust_id, cust_number, cust_name,\n       false AS recurring,\n       false AS open,\n       NULL AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       NULL::text AS aropen_docnumber_qtdisplayrole,\n       NULL::text AS aropen_docdate_qtdisplayrole,\n       0 AS xtindentrole,\n       '' AS aropen_duedate_qtforegroundrole,\n       NULL::integer AS ccard_number_xtidrole,\n       firstLine(cmhead_comments) AS notes\nFROM cmhead\n            JOIN custinfo ON (cmhead_cust_id=cust_id)\n            JOIN custtype ON (cust_custtype_id=custtype_id)\n\t    LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ((NOT cmhead_posted)\n<? if exists("cust_id") ?>\n  AND   (cmhead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (cmhead_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\n  GROUP BY id,                      altId,                  cmhead_id,\n           cmhead_docdate,          cmhead_posted,          cmhead_curr_id,\n           cmhead_number,           cmhead_posted,          cmhead_comments,\n           cust_id,                 cust_number,            cust_name\n\nUNION\n<? endif ?>\n<? endif ?>\n\n-- Get Posted AR Open\nSELECT aropen_id AS id,\n       CASE WHEN (aropen_doctype='I') THEN 0\n            WHEN (aropen_doctype='C') THEN 1\n            WHEN (aropen_doctype='D') THEN 2\n            WHEN (aropen_doctype='R') THEN 3\n            ELSE -1\n       END AS altId,\n       aropen_docnumber AS docnumber,\n       COALESCE(invchead_id,cmhead_id,-1) AS docnumber_xtidrole,\n       true AS posted,\n       aropen_docdate AS docdate,\n       aropen_duedate,\n       aropen_ordernumber AS ordernumber,\n       COALESCE(cohead_id,-1) AS ordernumber_xtidrole,\n       CASE WHEN (aropen_doctype='I') THEN <? value("invoice") ?>\n            WHEN (aropen_doctype='C') THEN <? value("creditMemo") ?>\n            WHEN (aropen_doctype='D') THEN <? value("debitMemo") ?>\n            WHEN (aropen_doctype='R') THEN <? value("cashdeposit") ?>\n            ELSE <? value("other") ?>\n       END AS doctype,\n       CASE WHEN (aropen_doctype='C') THEN 'emphasis' \n         ELSE CASE WHEN(aropen_doctype='R')THEN 'altemphasis'\n         END\n       END AS doctype_qtforegroundrole,\n       aropen_amount AS amount,\n       aropen_amount/aropen_curr_rate AS base_amount,\n       (aropen_paid - (COALESCE(SUM(arapply_target_paid),0))) AS paid,\n       (aropen_paid - (COALESCE(SUM(arapply_target_paid),0))/aropen_curr_rate) AS base_paid,\n        (((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0))) *\n        CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END) AS balance,\n       currConcat(aropen_curr_id) AS currAbbr,\n        (((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0)))/aropen_curr_rate *\n        CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END)  AS base_balance,\n       formatDate(aropen_docdate) AS f_docdate,\n       formatDate(aropen_duedate) AS f_duedate,\n       formatMoney(aropen_amount) AS f_amount,\n       formatMoney(aropen_paid - (COALESCE(SUM(arapply_target_paid),0))) AS f_paid,\n       formatMoney((((aropen_amount-aropen_paid+COALESCE(SUM(arapply_target_paid),0))) *\n        CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1 ELSE 1 END)) AS f_balance,\n       cust_id, cust_number, cust_name,\n       COALESCE(invchead_recurring_invchead_id IS NOT NULL, false) AS recurring,\n       aropen_open AS open,\n       formatccnumber(decrypt(setbytea(ccard_number),\n                              setbytea(<? value("key") ?>), 'bf')) AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr'AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       NULL AS aropen_docnumber_qtdisplayrole,\n       NULL AS aropen_docdate_qtdisplayrole,\n       0 AS xtindentrole,\n       CASE WHEN ((COALESCE(aropen_duedate,current_date) < current_date) AND COALESCE(aropen_open,FALSE)) THEN 'error' \n       END AS aropen_duedate_qtforegroundrole,\n       ccpay_id AS ccard_number_xtidrole,\n       firstLine(aropen_notes) AS notes\nFROM aropen \n<? if exists("incidentsOnly") ?>\n            JOIN incdt ON (incdt_aropen_id=aropen_id)\n<? endif ?>\n            JOIN custinfo ON (aropen_cust_id=cust_id)\n            JOIN custtype ON (cust_custtype_id=custtype_id)\n\t    LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\n            LEFT OUTER JOIN invchead ON ((aropen_docnumber=invchead_invcnumber)\n                                   AND (aropen_doctype='I'))\n            LEFT OUTER JOIN cohead ON (invchead_ordernumber=cohead_number)\n            LEFT OUTER JOIN cmhead ON ((aropen_docnumber=cmhead_number)\n                                   AND (aropen_doctype='C'))\n            LEFT OUTER JOIN arapply ON (((aropen_id=arapply_source_aropen_id)\n                             OR (aropen_id=arapply_target_aropen_id))\n                             AND (arapply_distdate>COALESCE(<? value("asofDate") ?>,current_date)))\n            LEFT OUTER JOIN payaropen ON (payaropen_aropen_id=aropen_id)\n            LEFT OUTER JOIN ccpay     ON (payaropen_ccpay_id=ccpay_id)\n            LEFT OUTER JOIN ccard     ON (ccpay_ccard_id=ccard_id)\nWHERE ((true)\n<? if not exists("showClosed") ?>\n  AND (aropen_docdate <= COALESCE(<? value("asofDate") ?>, current_date))\n  AND (COALESCE(aropen_closedate, DATE(<? value("asofDate") ?>) + 1, current_date + 1) > COALESCE(<? value("asofDate") ?>, current_date)) \n<? endif ?>\n<? if exists("debitsOnly") ?>\n  AND   (aropen_doctype IN ('D','I'))\n<? elseif exists("creditsOnly") ?>\n  AND   (aropen_doctype IN ('C', 'R'))\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND   (aropen_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("startDueDate") ?>\n  AND   (aropen_duedate >= <? value("startDueDate") ?>)\n<? endif ?>\n<? if exists("endDueDate") ?>\n  AND   (aropen_duedate <= <? value("endDueDate") ?>)\n<? endif ?>\n      )\n  GROUP BY id,                      altId,\t            invchead_id,\n           aropen_docdate,          aropen_duedate,         aropen_doctype,         \n           aropen_docnumber,        aropen_amount,          \n           aropen_notes,            aropen_posted,          aropen_ordernumber,\n           aropen_paid,             aropen_open,            aropen_curr_id,\n           aropen_closedate,        aropen_curr_rate,       cmhead_id,\n           cust_id, \t\t    cust_number,            cust_name,\n           cohead_id,               ccpay_id,               ccard_number,\n           invchead_recurring_invchead_id\nUNION\nSELECT -1,\n       4 AS altId,\n       aropen_docnumber AS docnumber,\n       -1 AS docnumber_xtidrole,\n       NULL AS posted, \n       aropen_docdate AS docdate,\n       NULL AS aropen_duedate,\n       CAST(incdt_number AS text) AS ordernumber,\n       incdt_id AS ordernumber_xtidrole,\n       NULL AS doctype,\n       NULL AS doctype_qtforegroundrole,\n       NULL AS amount,\n       NULL AS base_amount,\n       NULL AS paid,\n       NULL AS base_paid,\n       NULL AS balance,\n       NULL AS currAbbr,\n       NULL AS base_balance,\n       NULL AS f_docdate,\n       NULL AS f_duedate,\n       NULL AS f_amount,\n       NULL AS f_paid,\n       NULL AS f_balance,\n       NULL,incdt_assigned_username, incdt_summary,\n       NULL AS recurring, NULL AS open,\n       NULL AS ccard_number,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       0 AS base_amount_xttotalrole,\n       'curr' AS paid_xtnumericrole,\n       'curr' AS base_paid_xtnumericrole,\n       0 AS base_paid_xttotalrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS base_balance_xttotalrole,\n       '' AS aropen_docnumber_qtdisplayrole,\n       '' AS aropen_docdate_qtdisplayrole,\n       1 AS xtindentrole,\n       CASE WHEN ((COALESCE(aropen_duedate,current_date) < current_date) AND COALESCE(aropen_open,FALSE)) THEN 'error' \n       END AS aropen_duedate_qtforegroundrole,\n       NULL::integer AS ccard_xtidrole,\n       firstLine(incdt_descrip) AS notes\nFROM incdt JOIN aropen ON (aropen_id=incdt_aropen_id)\n           JOIN custinfo ON (aropen_cust_id=cust_id)\n           JOIN custtype ON (cust_custtype_id=custtype_id)\n\t   LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ((true)\n<? if not exists("showClosed") ?>\n  AND (aropen_docdate <= COALESCE(<? value("asofDate") ?>, current_date))\n  AND (COALESCE(aropen_closedate, DATE(<? value("asofDate") ?>) + 1, current_date + 1) > COALESCE(<? value("asofDate") ?>, current_date)) \n<? endif ?>\n<? if exists("debitsOnly") ?>\n  AND   (NOT aropen_doctype IN ('C', 'R'))\n<? endif ?>\n<? if exists("creditsOnly") ?>\n  AND   (aropen_doctype IN ('C', 'R'))\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND   (aropen_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("startDueDate") ?>\n  AND   (aropen_duedate >= <? value("startDueDate") ?>)\n<? endif ?>\n<? if exists("endDueDate") ?>\n  AND   (aropen_duedate <= <? value("endDueDate") ?>)\n<? endif ?>\n      )\n\nORDER BY\n  docdate DESC, docnumber DESC, xtindentrole\n;\n<? endif ?>\n	admin	2015-10-01	0
435	backlog	detail	 \n        Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: backlog\n-- Name: detail\n-- Notes: \n--        Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT\n       cohead_id, coitem_id, *, currconcat(cohead_curr_id) AS currAbbr,\n       CASE WHEN xtindentrole = 0 THEN cohead_number\n       END AS coitem_linenumber_qtdisplayrole,\n       CASE WHEN xtindentrole = 0 THEN cust_name\n       END AS item_number_qtdisplayrole,\n       CASE WHEN (coitem_scheddate <= current_date AND qtybalance > 0) THEN 'error' \n            WHEN (qtybalance > 0) THEN 'emphasis' \n       END AS coitem_scheddate_qtforegroundrole,\n       'qty' AS coitem_qtyord_xtnumericrole,\n       'qty' AS coitem_qtyshipped_xtnumericrole,\n       'qty' AS coitem_qtyreturned_xtnumericrole,\n       'qty' AS qtyatshipping_xtnumericrole,\n       'qty' AS qtybalance_xtnumericrole,\n       'qty' AS qtyavailable_xtnumericrole,\n       'salesprice' AS coitem_price_xtnumericrole,\n       'salesprice' AS baseunitprice_xtnumericrole,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS baseextprice_xtnumericrole,\n       'curr' AS extpricebalance_xtnumericrole,\n       'curr' AS baseextpricebalance_xtnumericrole,\n       0 AS coitem_qtyord_xttotalrole,\n       0 AS coitem_qtyshipped_xttotalrole,\n       0 AS coitem_qtyreturned_xttotalrole,\n       0 AS qtybalance_xttotalrole,\n       0 AS baseextprice_xttotalrole,\n       0 AS baseextpricebalance_xttotalrole\nFROM (\n  SELECT\n         0 AS xtindentrole,\n         -- dummy coitem record\n         -1            AS coitem_id,        NULL::INTEGER AS coitem_cohead_id,\n         -1            AS coitem_linenumber,NULL::INTEGER AS coitem_itemsite_id,\n         NULL::TEXT    AS coitem_status,    NULL::DATE    AS coitem_scheddate,\n         getSoSchedDate(cohead_id) AS sort_scheddate,\n         NULL::DATE    AS coitem_promdate,  NULL::NUMERIC AS coitem_qtyord,\n         NULL::NUMERIC AS coitem_unitcost,  NULL::NUMERIC AS coitem_price,\n         NULL::NUMERIC AS coitem_custprice, NULL::NUMERIC AS coitem_qtyshipped,\n         NULL::INTEGER AS coitem_order_id,  NULL::TEXT    AS coitem_memo,\n         NULL::BOOLEAN AS coitem_imported,  NULL::NUMERIC AS coitem_qtyreturned,\n         NULL::TIMESTAMP AS coitem_closedate, NULL::BOOLEAN AS coitem_firm,\n         NULL::TEXT    AS coitem_custpn,    NULL::TEXT    AS coitem_order_type,\n         NULL::TEXT    AS coitem_close_username,\n         NULL::TIMESTAMP AS coitem_lastupdated,\n         NULL::INTEGER AS coitem_substitute_item_id,\n         NULL::TIMESTAMP AS coitem_created, NULL::TEXT    AS coitem_creator,\n         NULL::NUMERIC AS coitem_prcost,\n         NULL::INTEGER AS coitem_qty_uom_id,\n         NULL::NUMERIC AS coitem_qty_invuomratio,\n         NULL::INTEGER AS coitem_price_uom_id,\n         NULL::NUMERIC AS coitem_price_invuomratio,\n         NULL::BOOLEAN AS coitem_warranty,\n         NULL::INTEGER AS coitem_cos_accnt_id,\n         NULL::NUMERIC AS coitem_qtyreserved,\n         NULL::INTEGER AS coitem_subnumber,\n         cohead.*,\n         cust_number, cust_name, saletype_descr,\n         NULL::TEXT AS item_number, NULL::TEXT AS item_descrip1,\n         NULL::TEXT AS itemdescription,\n         NULL::TEXT AS uom_name,\n         NULL::TEXT AS warehous_code,\n<? foreach("char_id_text_list") ?>\n       charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n       charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n       charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,\n<? endforeach ?>\n         NULL::NUMERIC AS qtybalance,\n         NULL::NUMERIC AS baseunitprice,\n         NULL::NUMERIC AS extprice,\n         NULL::NUMERIC AS baseextprice,\n         NULL::NUMERIC AS extpricebalance,\n         NULL::NUMERIC AS baseextpricebalance\n\n  FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)\n              JOIN custinfo ON (cust_id=cohead_cust_id)\n              LEFT OUTER JOIN saletype ON (saletype_id=cohead_saletype_id)\n              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n              JOIN site() ON (warehous_id=itemsite_warehous_id)\n              JOIN item ON (item_id=itemsite_item_id)\n              JOIN uom ON (uom_id=coitem_qty_uom_id)\n<? foreach("char_id_text_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> \n          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> \n          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> \n          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> \n          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> \n          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> \n          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\n  WHERE ( (coitem_status='O')\n  <? if exists("cohead_id") ?>\n    AND  (coitem_cohead_id=<? value("cohead_id") ?>)\n  <? endif ?>\n  <? if exists("startDate") ?>\n    AND  (cohead_orderdate >= <? value("startDate") ?>)\n  <? endif ?>\n  <? if exists("endDate") ?>\n    AND  (cohead_orderdate <= <? value("endDate") ?>)\n  <? endif ?>\n  <? if exists("saletype_id") ?>\n    AND  (cohead_saletype_id = <? value("saletype_id") ?>)\n  <? endif ?>\n  <? if exists("startDateSched") ?>\n    AND  (coitem_scheddate >= <? value("startDateSched") ?>)\n  <? endif ?>\n  <? if exists("endDateSched") ?>\n    AND  (coitem_scheddate <= <? value("endDateSched") ?>)\n  <? endif ?>\n  <? if exists("salesrep_id") ?>\n    AND  (cohead_salesrep_id=<? value("salesrep_id") ?>)\n  <? endif ?>\n  <? if exists("shipto_id") ?>\n    AND  (cohead_shipto_id=<? value("shipto_id") ?>)\n  <? endif ?>\n  <? if exists("cust_id") ?>\n    AND  (cohead_cust_id=<? value("cust_id") ?>)\n  <? endif ?>\n  <? if exists("custtype_id") ?>\n    AND  (cust_custtype_id=<? value("custtype_id") ?>)\n  <? endif ?>\n  <? if exists("custtype_pattern") ?>\n    AND  (cust_custtype_id IN (SELECT DISTINCT custtype_id\n                               FROM custtype\n                               WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n  <? endif ?>\n  <? if exists("custgrp") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem))\n  <? endif ?>\n  <? if exists("custgrp_id") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem\n                     WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n  <? endif ?>\n  <? if exists("custgrp_pattern") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrp, custgrpitem\n                     WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                       AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n  <? endif ?>\n\n  <? if exists("item_id") ?>\n    AND  (itemsite_item_id=<? value("item_id") ?>)\n  <? endif ?>\n  <? if exists("prodcat_id") ?>\n    AND (item_prodcat_id=<? value("prodcat_id") ?>)\n  <? endif ?>\n  <? if exists("prodcat_pattern") ?>\n    AND (item_prodcat_id IN (SELECT DISTINCT prodcat_id\n                             FROM prodcat\n                             WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n  <? endif ?>\n\n  <? if exists("warehous_id") ?>\n    AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n  <? literal("charClause") ?>\n        )\n\n  UNION\n\n  SELECT \n         1 AS xtindentrole,\n         coitem_id,        coitem_cohead_id,\n         coitem_linenumber,coitem_itemsite_id,\n         coitem_status,    coitem_scheddate,\n         getSoSchedDate(cohead_id) AS sort_scheddate,\n         coitem_promdate,  coitem_qtyord,\n         coitem_unitcost,  coitem_price,\n         coitem_custprice, coitem_qtyshipped,\n         coitem_order_id,  coitem_memo,\n         coitem_imported,  coitem_qtyreturned,\n         coitem_closedate, coitem_firm,\n         coitem_custpn,    coitem_order_type,\n         coitem_close_username,\n         coitem_lastupdated,\n         coitem_substitute_item_id,\n         coitem_created,   coitem_creator,\n         coitem_prcost,\n         coitem_qty_uom_id,\n         coitem_qty_invuomratio,\n         coitem_price_uom_id,\n         coitem_price_invuomratio,\n         coitem_warranty,\n         coitem_cos_accnt_id,\n         coitem_qtyreserved,\n         coitem_subnumber,\n         cohead.*,\n         cust_number, cust_name, '' AS saletype_descr,\n         item_number, item_descrip1, (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n         uom_name,\n         warehous_code,\n<? foreach("char_id_text_list") ?>\n       charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n       charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n       charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,\n<? endforeach ?>\n         noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS qtybalance,\n         currtobase(cohead_curr_id, coitem_price, cohead_orderdate) AS baseunitprice,\n         round((coitem_qtyord * coitem_qty_invuomratio) *\n                     (coitem_price / coitem_price_invuomratio), 2) AS extprice,\n         round((coitem_qtyord * coitem_qty_invuomratio) *\n                     (currtobase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio), 2) AS baseextprice,\n         round((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n                     (coitem_price / coitem_price_invuomratio), 2) AS extpricebalance,\n         round((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n                     (currtobase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio), 2) AS baseextpricebalance\n\n  FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)\n              JOIN custinfo ON (cust_id=cohead_cust_id)\n              LEFT OUTER JOIN saletype ON (saletype_id=cohead_saletype_id)\n              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n              JOIN site() ON (warehous_id=itemsite_warehous_id)\n              JOIN item ON (item_id=itemsite_item_id)\n              JOIN uom ON (uom_id=coitem_qty_uom_id)\n<? foreach("char_id_text_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> \n          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> \n          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> \n          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> \n          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> \n          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> \n          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\n  WHERE ( (coitem_status='O')\n  <? if exists("cohead_id") ?>\n    AND  (coitem_cohead_id=<? value("cohead_id") ?>)\n  <? endif ?>\n  <? if exists("startDate") ?>\n    AND  (cohead_orderdate >= <? value("startDate") ?>)\n  <? endif ?>\n  <? if exists("endDate") ?>\n    AND  (cohead_orderdate <= <? value("endDate") ?>)\n  <? endif ?>\n  <? if exists("saletype_id") ?>\n    AND  (cohead_saletype_id = <? value("saletype_id") ?>)\n  <? endif ?>\n  <? if exists("startDateSched") ?>\n    AND  (coitem_scheddate >= <? value("startDateSched") ?>)\n  <? endif ?>\n  <? if exists("endDateSched") ?>\n    AND  (coitem_scheddate <= <? value("endDateSched") ?>)\n  <? endif ?>\n  <? if exists("salesrep_id") ?>\n    AND  (cohead_salesrep_id=<? value("salesrep_id") ?>)\n  <? endif ?>\n  <? if exists("shipto_id") ?>\n    AND  (cohead_shipto_id=<? value("shipto_id") ?>)\n  <? endif ?>\n  <? if exists("cust_id") ?>\n    AND  (cohead_cust_id=<? value("cust_id") ?>)\n  <? endif ?>\n  <? if exists("custtype_id") ?>\n    AND  (cust_custtype_id=<? value("custtype_id") ?>)\n  <? endif ?>\n  <? if exists("custtype_pattern") ?>\n    AND  (cust_custtype_id IN (SELECT DISTINCT custtype_id\n                               FROM custtype\n                               WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n  <? endif ?>\n  <? if exists("custgrp") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem))\n  <? endif ?>\n  <? if exists("custgrp_id") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem\n                     WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n  <? endif ?>\n  <? if exists("custgrp_pattern") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrp, custgrpitem\n                     WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                       AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n  <? endif ?>\n\n  <? if exists("item_id") ?>\n    AND  (itemsite_item_id=<? value("item_id") ?>)\n  <? endif ?>\n  <? if exists("prodcat_id") ?>\n    AND (item_prodcat_id=<? value("prodcat_id") ?>)\n  <? endif ?>\n  <? if exists("prodcat_pattern") ?>\n    AND (item_prodcat_id IN (SELECT DISTINCT prodcat_id\n                             FROM prodcat\n                             WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n  <? endif ?>\n\n  <? if exists("warehous_id") ?>\n    AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n  <? literal("charClause") ?>\n        )\n\n) AS dummy\nORDER BY cohead_number, xtindentrole, coitem_linenumber;\n	admin	2015-10-01	0
444	bankrec	checks	 used by reconcileBankaccount\n        Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bankrec\n-- Name: checks\n-- Notes: used by reconcileBankaccount\n--        Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("summary") ?>\nSELECT COALESCE(SUM(amount),0.0) AS cleared_amount\n  FROM ( SELECT COALESCE( bankrecitem_amount,\n                          currToLocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) ) AS amount\n           FROM (bankaccnt CROSS JOIN gltrans)\n                       JOIN bankrecitem ON ((bankrecitem_source='GL')\n                                        AND (bankrecitem_source_id=gltrans_id)\n                                        AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                                        AND (bankrecitem_cleared))\n          WHERE ((gltrans_accnt_id=bankaccnt_accnt_id)\n            AND (NOT gltrans_deleted)\n            AND (NOT gltrans_rec)\n            AND (gltrans_amount > 0)\n            AND (gltrans_doctype != 'JP')\n            AND (bankaccnt_id=<? value("bankaccntid") ?>) )\n          UNION ALL\n         SELECT COALESCE( bankrecitem_amount,\n                          currToLocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) ) AS amount\n           FROM (bankaccnt CROSS JOIN sltrans)\n                       JOIN bankrecitem ON ((bankrecitem_source='SL')\n                                        AND (bankrecitem_source_id=sltrans_id)\n                                        AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                                        AND (bankrecitem_cleared))\n          WHERE ((sltrans_accnt_id=bankaccnt_accnt_id)\n            AND (NOT sltrans_rec)\n            AND (sltrans_amount > 0)\n            AND (bankaccnt_id=<? value("bankaccntid") ?>) )\n          UNION ALL\n         SELECT CASE WHEN(bankadjtype_iscredit=false) THEN (bankadj_amount * -1) ELSE bankadj_amount END AS amount\n           FROM bankadj, bankadjtype, bankrecitem\n          WHERE ( (bankrecitem_source='AD')\n            AND (bankrecitem_source_id=bankadj_id)\n            AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n            AND (bankrecitem_cleared)\n            AND (bankadj_bankadjtype_id=bankadjtype_id)\n            AND (NOT bankadj_posted)\n            AND (((bankadjtype_iscredit=true) AND (bankadj_amount > 0)) OR ((bankadjtype_iscredit=false) AND (bankadj_amount < 0)))\n            AND (bankadj_bankaccnt_id=<? value("bankaccntid") ?>) ) ) AS data;\n<? else ?>\nSELECT gltrans_id AS id, 1 AS altid,\n       COALESCE(bankrecitem_cleared, FALSE) AS cleared,\n       COALESCE(bankrecitem_effdate, gltrans_date) AS transdate,\n       gltrans_doctype AS doc_type,\n       gltrans_docnumber AS doc_number,\n       gltrans_notes AS notes,\n       (SELECT currConcat(COALESCE(checkhead_curr_id, baseCurrId()))) AS doc_curr,\n       CASE WHEN (fetchMetricValue('CurrencyExchangeSense') = 1) THEN\n         ROUND(1.0 / COALESCE(bankrecitem_curr_rate, checkhead_curr_rate, currRate(bankaccnt_curr_id, gltrans_date)),6)\n            ELSE\n         ROUND(COALESCE(bankrecitem_curr_rate, checkhead_curr_rate, currRate(bankaccnt_curr_id, gltrans_date)),6)\n       END AS doc_exchrate,\n       gltrans_amount AS base_amount,\n       CASE WHEN (bankaccnt_curr_id=checkhead_curr_id) THEN\n         COALESCE( bankrecitem_amount,\n                   checkhead_amount,\n                   currToLocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) )\n            ELSE\n         COALESCE( bankrecitem_amount,\n                   currToLocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) )\n       END AS amount,\n       gltrans_date AS sortdate,\n       '6' AS doc_exchrate_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       'curr' AS amount_xtnumericrole\n  FROM (bankaccnt CROSS JOIN gltrans)\n              LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='GL')\n                                          AND (bankrecitem_source_id=gltrans_id)\n                                          AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                                          AND (bankrecitem_cleared))\n              LEFT OUTER JOIN checkhead ON ((gltrans_doctype='CK')\n                                        AND (gltrans_misc_id=checkhead_id))\n WHERE ((gltrans_accnt_id=bankaccnt_accnt_id)\n   AND (NOT gltrans_deleted)\n   AND (NOT gltrans_rec)\n   AND (NOT COALESCE(checkhead_void, false))\n   AND (gltrans_amount > 0)\n   AND (gltrans_doctype != 'JP')\n   AND (bankaccnt_id=<? value("bankaccntid") ?>)\n<? if exists("source") ?>\n   AND ('GL' = <? value("source") ?>)\n<? endif ?>\n<? if exists("sourceid") ?>\n   AND (gltrans_id = <? value("sourceid") ?>)\n<? endif ?>\n )\n UNION ALL\nSELECT sltrans_id AS id, 2 AS altid,\n       COALESCE(bankrecitem_cleared, FALSE) AS cleared,\n       COALESCE(bankrecitem_effdate, sltrans_date) AS transdate,\n       sltrans_doctype AS doc_type,\n       sltrans_docnumber AS doc_number,\n       sltrans_notes AS notes,\n       (SELECT currConcat(COALESCE(checkhead_curr_id, baseCurrId()))) AS doc_curr,\n       CASE WHEN (fetchMetricValue('CurrencyExchangeSense') = 1) THEN\n         ROUND(1.0 / COALESCE(bankrecitem_curr_rate, checkhead_curr_rate, currRate(bankaccnt_curr_id, sltrans_date)),6)\n            ELSE\n         ROUND(COALESCE(bankrecitem_curr_rate, checkhead_curr_rate, currRate(bankaccnt_curr_id, sltrans_date)),6)\n       END AS doc_exchrate,\n       sltrans_amount AS base_amount,\n       CASE WHEN (bankaccnt_curr_id=checkhead_curr_id) THEN\n         COALESCE( bankrecitem_amount,\n                   checkhead_amount,\n                   currToLocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) )\n            ELSE\n         COALESCE( bankrecitem_amount,\n                   currToLocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) )\n       END AS amount,\n       sltrans_date AS sortdate,\n       '6' AS doc_exchrate_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       'curr' AS amount_xtnumericrole\n  FROM (bankaccnt CROSS JOIN sltrans)\n              LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='SL')\n                                          AND (bankrecitem_source_id=sltrans_id)\n                                          AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                                          AND (bankrecitem_cleared))\n              LEFT OUTER JOIN checkhead ON ((sltrans_doctype='CK')\n                                        AND (sltrans_misc_id=checkhead_id))\n WHERE ((sltrans_accnt_id=bankaccnt_accnt_id)\n   AND (NOT sltrans_rec)\n   AND (NOT COALESCE(checkhead_void, false))\n   AND (sltrans_amount > 0)\n   AND (bankaccnt_id=<? value("bankaccntid") ?>)\n<? if exists("source") ?>\n   AND ('SL' = <? value("source") ?>)\n<? endif ?>\n<? if exists("sourceid") ?>\n   AND (sltrans_id = <? value("sourceid") ?>)\n<? endif ?>\n )\n UNION ALL\nSELECT bankadj_id AS id, 3 AS altid,\n       COALESCE(bankrecitem_cleared, FALSE) AS cleared,\n       COALESCE(bankrecitem_effdate, bankadj_date) AS transdate,\n       'ADJ' AS doc_type,\n       bankadj_docnumber AS doc_number,\n       bankadjtype_name AS notes,\n       (SELECT currConcat(bankadj_curr_id)) AS doc_curr,\n       1.0 AS doc_exchrate,\n       CASE WHEN(bankadjtype_iscredit=false) THEN (bankadj_amount * -1.0) ELSE bankadj_amount END AS base_amount,\n       CASE WHEN(bankadjtype_iscredit=false) THEN (bankadj_amount * -1.0) ELSE bankadj_amount END AS amount,\n       bankadj_date AS sortdate,\n       '6' AS doc_exchrate_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       'curr' AS amount_xtnumericrole\n  FROM (bankadjtype CROSS JOIN bankadj)\n               LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='AD')\n                                           AND (bankrecitem_source_id=bankadj_id)\n                                           AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n                                           AND (bankrecitem_cleared))\n WHERE ( (((bankadjtype_iscredit=true) AND (bankadj_amount > 0)) OR ((bankadjtype_iscredit=false) AND (bankadj_amount < 0)))\n   AND (bankadj_bankadjtype_id=bankadjtype_id)\n   AND (NOT bankadj_posted)\n   AND (bankadj_bankaccnt_id=<? value("bankaccntid") ?>)\n<? if exists("source") ?>\n   AND ('AD' = <? value("source") ?>)\n<? endif ?>\n<? if exists("sourceid") ?>\n   AND (bankadj_id = <? value("sourceid") ?>)\n<? endif ?>\n )\nORDER BY sortdate;\n<? endif ?>\n	admin	2015-10-01	0
445	bankrec	clearedbalance	 used by reconcileBankaccount\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bankrec\n-- Name: clearedbalance\n-- Notes: used by reconcileBankaccount\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT (COALESCE(SUM(amount),0.0) + <? value("begBal") ?>) AS cleared_amount,\n       <? value("endBal") ?> AS end_amount,\n       (<? value("endBal") ?> - (<? value("begBal") ?> + (COALESCE(SUM(amount),0.0)))) AS diff_amount,\n       round(<? value("endBal") ?> - (<? value("begBal") ?> + COALESCE(SUM(amount),0.0)), 2) AS diff_value\n  FROM ( SELECT CASE WHEN (gltrans_amount > 0) THEN bankrecitem_amount * -1.0\n                     ELSE bankrecitem_amount END AS amount\n           FROM bankaccnt, gltrans, bankrecitem\n          WHERE ((gltrans_accnt_id=bankaccnt_accnt_id)\n            AND (bankrecitem_source='GL')\n            AND (bankrecitem_source_id=gltrans_id)\n            AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n            AND (bankrecitem_cleared)\n            AND (NOT gltrans_deleted)\n            AND (NOT gltrans_rec)\n            AND (bankaccnt_id=<? value("bankaccntid") ?>) ) \n          UNION ALL\n         SELECT CASE WHEN (sltrans_amount > 0) THEN bankrecitem_amount * -1.0\n                     ELSE bankrecitem_amount END AS amount\n           FROM bankaccnt, sltrans, bankrecitem\n          WHERE ((sltrans_accnt_id=bankaccnt_accnt_id)\n            AND (bankrecitem_source='SL')\n            AND (bankrecitem_source_id=sltrans_id)\n            AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n            AND (bankrecitem_cleared)\n            AND (NOT sltrans_rec)\n            AND (bankaccnt_id=<? value("bankaccntid") ?>) )\n          UNION ALL\n         SELECT CASE WHEN(bankadjtype_iscredit=true) THEN (bankadj_amount * -1) ELSE bankadj_amount END AS amount\n           FROM bankadj, bankadjtype, bankrecitem\n          WHERE ( (bankrecitem_source='AD')\n            AND (bankrecitem_source_id=bankadj_id)\n            AND (bankrecitem_bankrec_id=<? value("bankrecid") ?>)\n            AND (bankrecitem_cleared)\n            AND (bankadj_bankadjtype_id=bankadjtype_id)\n            AND (NOT bankadj_posted)\n            AND (bankadj_bankaccnt_id=<? value("bankaccntid") ?>) ) ) AS data;\n	admin	2015-10-01	0
105	bankrecHistory	reconciled	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bankrecHistory\n-- Name: reconciled\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("treeView") ?>\nSELECT -1 AS gltrans_id, bankrec_opendate AS gltrans_date, formatDate(bankrec_opendate) AS f_date,\n       <? value("openingBalance") ?> AS gltrans_docnumber, <? value("openingBalance") ?> AS type, 0 AS sort, NULL AS gltrans_notes, \n       bankrec_openbal AS amount, formatMoney(bankrec_openbal) AS f_amount,\n       'curr' AS amount_xtnumericrole,\n       0 AS xtindentrole\n  FROM bankrec\n  WHERE (bankrec_id=<? value("bankrec_id") ?>)\n  \nUNION\n<? endif ?>\n\nSELECT gltrans_id, gltrans_date, formatDate(gltrans_date) AS f_date,\n       gltrans_docnumber,\n       CASE WHEN gltrans_doctype = 'CK' THEN <? value("Checks") ?>\n            WHEN gltrans_doctype = 'CR' THEN <? value("Deposits") ?>\n            ELSE <? value("Adjustments") ?> END AS type,\n       CASE WHEN gltrans_doctype = 'CK' THEN 1\n            WHEN gltrans_doctype = 'CR' THEN 2\n            ELSE '3' END AS sort,\n       gltrans_notes AS notes,\n       COALESCE( bankrecitem_amount,\n                 (currtolocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) * -1.0) ) AS amount,\n       formatMoney(COALESCE( bankrecitem_amount,\n                             (currtolocal(bankaccnt_curr_id, gltrans_amount, gltrans_date) * -1.0) ) ) AS f_amount,\n       'curr' AS amount_xtnumericrole,\n       1 AS xtindentrole\n  FROM gltrans, bankrecitem \n    JOIN bankrec ON (bankrecitem_bankrec_id=bankrec_id)\n    JOIN bankaccnt ON (bankaccnt_id=bankrec_bankaccnt_id)\n WHERE ((bankrecitem_bankrec_id=<? value("bankrec_id") ?>)\n   AND (bankrecitem_source='GL')\n   AND (bankrecitem_source_id=gltrans_id)\n   AND (NOT gltrans_deleted) ) \n\nUNION\n\nSELECT sltrans_id, sltrans_date, formatDate(sltrans_date) AS f_date,\n       sltrans_docnumber,\n       CASE WHEN sltrans_doctype = 'CK' THEN <? value("Checks") ?>\n            WHEN sltrans_doctype = 'CR' THEN <? value("Deposits") ?>\n            ELSE <? value("Adjustments") ?> END AS type,\n       CASE WHEN sltrans_doctype = 'CK' THEN 1\n            WHEN sltrans_doctype = 'CR' THEN 2\n            ELSE '3' END AS sort,\n       sltrans_notes AS notes,\n       COALESCE( bankrecitem_amount,\n                 (currtolocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) * -1.0) ) AS amount,\n       formatMoney(COALESCE( bankrecitem_amount,\n                             (currtolocal(bankaccnt_curr_id, sltrans_amount, sltrans_date) * -1.0) ) ) AS f_amount,\n       'curr' AS amount_xtnumericrole,\n       1 AS xtindentrole\n  FROM sltrans, bankrecitem \n    JOIN bankrec ON (bankrecitem_bankrec_id=bankrec_id)\n    JOIN bankaccnt ON (bankaccnt_id=bankrec_bankaccnt_id)\n WHERE ((bankrecitem_bankrec_id=<? value("bankrec_id") ?>)\n   AND (bankrecitem_source='SL')\n   AND (bankrecitem_source_id=sltrans_id) ) \n\n<? if exists("treeView") ?>\nUNION\n\nSELECT -1 AS gltrans_id, bankrec_enddate, formatDate(bankrec_enddate) AS f_date,\n       <? value("closingBalance") ?>, <? value("closingBalance") ?> AS type, 7 AS sort, NULL, \n       bankrec_endbal AS amount, formatMoney(bankrec_endbal) AS f_amount,\n       'curr' AS amount_xtnumericrole,\n       0 AS xtindentrole\n  FROM bankrec\n  WHERE (bankrec_id=<? value("bankrec_id") ?>)\n\nUNION\nSELECT -1, NULL, NULL, <? value("Checks") ?>, NULL, 1, NULL, NULL, NULL, 'curr', 0 \nUNION\nSELECT -1, NULL, NULL, <? value("Deposits") ?>, NULL, 2, NULL, NULL, NULL, 'curr', 0 \nUNION\nSELECT -1, NULL, NULL, <? value("Adjustments") ?>, NULL, 3, NULL, NULL, NULL, 'curr', 0 \n<? endif ?>\n\nORDER BY  sort, xtindentrole, type, f_date, gltrans_id\n	admin	2015-10-01	0
106	bankrecHistory	unreconciled	 \n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bankrecHistory\n-- Name: unreconciled\n-- Notes: \n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT gltrans_id, gltrans_date, formatDate(gltrans_date) AS f_date,\n      gltrans_docnumber,\n       CASE WHEN gltrans_doctype = 'CK' THEN <? value("Checks") ?>\n            WHEN gltrans_doctype = 'CR' THEN <? value("Deposits") ?>\n            ELSE <? value("Adjustments") ?> END AS type,\n       CASE WHEN gltrans_doctype = 'CK' THEN 1\n            WHEN gltrans_doctype = 'CR' THEN 2\n            ELSE '3' END AS sort,\n      gltrans_notes AS notes,\n      currtolocal(bankaccnt_curr_id,gltrans_amount,gltrans_date) * -1 AS amount,\n      formatMoney(currtolocal(bankaccnt_curr_id,gltrans_amount,gltrans_date) * -1) AS f_amount,\n      CASE WHEN gltrans_doctype = 'CK' THEN \n        currtolocal(bankaccnt_curr_id,gltrans_amount,gltrans_date) * -1\n      ELSE 0 END AS rtcheck,\n      CASE WHEN gltrans_doctype = 'CR' THEN \n        currtolocal(bankaccnt_curr_id,gltrans_amount,gltrans_date) * -1\n      ELSE 0 END AS rtdep,\n      CASE WHEN gltrans_doctype NOT IN ('CK','CR') THEN \n        currtolocal(bankaccnt_curr_id,gltrans_amount,gltrans_date) * -1\n      ELSE 0 END AS rtadj,\n      'curr' AS amount_xtnumericrole,\n      1 AS xtindentrole\n FROM gltrans\n   JOIN bankaccnt ON (bankaccnt_accnt_id = gltrans_accnt_id)\n   JOIN bankrec selrec ON ((selrec.bankrec_bankaccnt_id = bankaccnt_id)\n                       AND (selrec.bankrec_id=<? value("bankrec_id") ?>))\n   LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='GL')\n\n                              AND (bankrecitem_source_id=gltrans_id))\n   LEFT OUTER JOIN bankrec actrec ON (actrec.bankrec_id = bankrecitem_bankrec_id)\n   LEFT OUTER JOIN checkhead ON ((gltrans_doctype='CK')\n                             AND (gltrans_misc_id=checkhead_id))\n<? if exists("showUnreconciled") ?>\n WHERE ((COALESCE(actrec.bankrec_postdate,endoftime()) > COALESCE(selrec.bankrec_postdate,now()))\n  AND (NOT gltrans_deleted)\n  AND (NOT COALESCE(checkhead_void, false)))\n  AND (gltrans_doctype != 'JP')\n<? else ?>\n WHERE (false)\n<? endif ?>\n\nUNION\n\nSELECT sltrans_id, sltrans_date, formatDate(sltrans_date) AS f_date,\n      sltrans_docnumber,\n       CASE WHEN sltrans_doctype = 'CK' THEN <? value("Checks") ?>\n            WHEN sltrans_doctype = 'CR' THEN <? value("Deposits") ?>\n            ELSE <? value("Adjustments") ?> END AS type,\n       CASE WHEN sltrans_doctype = 'CK' THEN 1\n            WHEN sltrans_doctype = 'CR' THEN 2\n            ELSE '3' END AS sort,\n      sltrans_notes AS notes,\n      currtolocal(bankaccnt_curr_id,sltrans_amount,sltrans_date) * -1 AS amount,\n      formatMoney(currtolocal(bankaccnt_curr_id,sltrans_amount,sltrans_date) * -1) AS f_amount,\n      CASE WHEN sltrans_doctype = 'CK' THEN \n        currtolocal(bankaccnt_curr_id,sltrans_amount,sltrans_date) * -1\n      ELSE 0 END AS rtcheck,\n      CASE WHEN sltrans_doctype = 'CR' THEN \n        currtolocal(bankaccnt_curr_id,sltrans_amount,sltrans_date) * -1\n      ELSE 0 END AS rtdep,\n      CASE WHEN sltrans_doctype NOT IN ('CK','CR') THEN \n        currtolocal(bankaccnt_curr_id,sltrans_amount,sltrans_date) * -1\n      ELSE 0 END AS rtadj,\n      'curr' AS amount_xtnumericrole,\n      1 AS xtindentrole\n FROM sltrans\n   JOIN bankaccnt ON (bankaccnt_accnt_id = sltrans_accnt_id)\n   JOIN bankrec selrec ON ((selrec.bankrec_bankaccnt_id = bankaccnt_id)\n                       AND (selrec.bankrec_id=<? value("bankrec_id") ?>))\n   LEFT OUTER JOIN bankrecitem ON ((bankrecitem_source='SL')\n\n                              AND (bankrecitem_source_id=sltrans_id))\n   LEFT OUTER JOIN bankrec actrec ON (actrec.bankrec_id = bankrecitem_bankrec_id)\n   LEFT OUTER JOIN checkhead ON ((sltrans_doctype='CK')\n                             AND (sltrans_misc_id=checkhead_id))\n<? if exists("showUnreconciled") ?>\n WHERE ((COALESCE(actrec.bankrec_postdate,endoftime()) > COALESCE(selrec.bankrec_postdate,now()))\n  AND (NOT COALESCE(checkhead_void, false)))\n<? if exists("treeView") ?>\nUNION\nSELECT -1, NULL, NULL, <? value("Checks") ?>, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL,'curr', 0 \nUNION\nSELECT -1, NULL, NULL, <? value("Deposits") ?>, NULL, 2, NULL, NULL, NULL, NULL, NULL, NULL, 'curr', 0 \nUNION\nSELECT -1, NULL, NULL, <? value("Adjustments") ?>, NULL, 3, NULL, NULL, NULL, NULL, NULL, NULL, 'curr', 0\n<? endif ?>\n\nORDER BY  sort, xtindentrole, type, f_date, gltrans_id\n<? else ?>\n WHERE (false)\n<? endif ?>\n	admin	2015-10-01	0
232	billingSelections	detail	 used by dspBillingSelections\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: billingSelections\n-- Name: detail\n-- Notes: used by dspBillingSelections\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cobmisc_id, cohead_id,\n       cohead_number, cust_number, cust_name,\n       sum(round(coitem_price*cobill_qty,2)) AS subtotal,\n       cobmisc_misc, cobmisc_freight, calcCobmiscTax(cobmisc_id) AS cobmisc_tax, cobmisc_payment,\n       (sum(round(coitem_price * cobill_qty, 2)) +\n                  cobmisc_misc + cobmisc_freight +\n                  calcCobmiscTax(cobmisc_id)) AS total,\n       'curr' AS subtotal_xtnumericrole,\n       'curr' AS total_xtnumericrole,\n       'curr' AS cobmisc_misc_xtnumericrole,\n       'curr' AS cobmisc_freight_xtnumericrole,\n       'curr' AS cobmisc_tax_xtnumericrole,\n       'curr' AS cobmisc_payment_xtnumericrole\nFROM cobmisc, cohead, custinfo, coitem, cobill\nWHERE ((cobmisc_cohead_id=cohead_id)\n   AND (cohead_cust_id=cust_id)\n   AND (coitem_cohead_id=cohead_id)\n   AND (cobill_coitem_id=coitem_id) AND (COALESCE(cobill_invcnum,0) = 0)\n   AND (NOT cobmisc_posted))\nGROUP BY cobmisc_id, cohead_id, cohead_number, cust_number,\n         cust_name, cobmisc_misc, cobmisc_freight, cobmisc_tax, cobmisc_payment\nORDER BY cohead_number;\n	admin	2015-10-01	0
233	bom	detail	 used by dspIndentedBOM, dspSingleLevelBOM, dspSummarizedBOM\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bom\n-- Name: detail\n-- Notes: used by dspIndentedBOM, dspSingleLevelBOM, dspSummarizedBOM\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT <? if exists("bySingleLvl") ?>\n         bomitem_item_id AS itemid, bomitem.*, item_number,\n         invuom.uom_name AS invuomname, issueuom.uom_name AS issueuomname,\n         (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n         (itemuomtouomratio(bomitem_item_id, bomitem_uom_id, NULL) * bomitem_qtyfxd) AS invqtyfxd,\n         (itemuomtouomratio(bomitem_item_id, bomitem_uom_id, NULL) * bomitem_qtyper) AS invqtyper,\n         'qty' AS bomitem_qtyfxd_xtnumericrole,\n         'qty' AS invqtyfxd_xtnumericrole,\n         'qtyper' AS bomitem_qtyper_xtnumericrole,\n         'qtyper' AS invqtyper_xtnumericrole,\n         'percent' AS bomitem_scrap_xtnumericrole,\n         CASE WHEN COALESCE(bomitem_effective, startOfTime()) = startOfTime() \n           THEN <? value("always") ?>\n         END AS bomitem_effective_qtdisplayrole,\n         CASE WHEN COALESCE(bomitem_expires, endOfTime()) = endOfTime() \n           THEN <? value("never") ?>\n         END AS bomitem_expires_qtdisplayrole,\n         CASE WHEN (bomitem_expires < CURRENT_DATE) THEN 'expired'\n              WHEN (bomitem_effective >= CURRENT_DATE) THEN 'future'\n              WHEN (item_type='M') THEN 'altemphasis'\n         END AS qtforegroundrole\n       <? else ?>\n         <? if exists("bySummarized") ?>\n           item_id AS itemid,\n         <? else ?>\n           bomdata_item_id AS itemid,\n         <? endif ?>\n         *,'percent' AS bomdata_scrap_xtnumericrole,\n         'qtyper' AS bomdata_qtyreq_xtnumericrole,\n         CASE WHEN COALESCE(bomdata_effective, startOfTime()) <=\n                   startOfTime() THEN <? value("always") ?>\n         END AS bomdata_effective_qtdisplayrole,\n         CASE WHEN COALESCE(bomdata_expires, endOfTime()) >=\n                   endOfTime() THEN <? value("never") ?>\n         END AS bomdata_expires_qtdisplayrole,\n         CASE WHEN (bomdata_expired) THEN 'expired'\n              WHEN (bomdata_future) THEN 'future'\n         END AS qtforegroundrole\n         <? if not exists("bySummarized") ?>\n           , bomdata_bomwork_level - 1 AS xtindentrole\n         <? endif ?>\n       <? endif ?>\nFROM <? if exists("bySingleLvl") ?>\n       bomitem(<? value("item_id") ?>,<? value("revision_id") ?>),\n       item, uom AS issueuom, uom AS invuom\n     <? elseif exists("byIndented") ?>\n       indentedBOM(<? value("item_id") ?>,\n                   <? value("revision_id") ?>,\n                   <? value("expiredDays") ?>,\n                   <? value("futureDays") ?>)\n     <? elseif exists("bySummarized") ?>\n       summarizedBOM(<? value("item_id") ?>,\n                     <? value("revision_id") ?>,\n                     <? value("expiredDays") ?>,\n                     <? value("futureDays") ?>)\n       JOIN item ON (bomdata_item_number=item_number)\n     <? endif ?>\nWHERE ((TRUE)\n<? if exists("byIndented") ?>\n   AND (bomdata_item_id > 0)\n<? elseif exists("bySingleLvl") ?>\n   AND (bomitem_item_id=item_id)\n   AND (item_inv_uom_id=invuom.uom_id)\n   AND (bomitem_uom_id=issueuom.uom_id)\n  <? if exists("expiredDays") ?>\n   AND (bomitem_expires > (CURRENT_DATE - <? value("expiredDays") ?>))\n  <? else ?>\n   AND (bomitem_expires > CURRENT_DATE)\n  <? endif ?>\n  <? if exists("effectiveDays") ?>\n   AND (bomitem_effective <= (CURRENT_DATE + <? value("effectiveDays") ?>))\n  <? else ?>\n   AND (bomitem_effective <= CURRENT_DATE)\n  <? endif ?>\n<? endif ?>\n      )\n<? if exists("bySingleLvl") ?>\n ORDER BY bomitem_seqnumber, bomitem_effective\n<? endif ?>\n;\n	admin	2015-10-01	0
117	bomItems	detail	 used by bom, booItem\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: bomItems\n-- Name: detail\n-- Notes: used by bom, booItem\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT bomitem_id, item_id, *,\n       (item_descrip1 || ' ' || item_descrip2) AS item_description,\n       CASE WHEN (item_type='P') THEN text(<? value("purchased") ?>)\n            WHEN (item_type='M') THEN text(<? value("manufactured") ?>)\n            WHEN (item_type='J') THEN text(<? value("job") ?>)\n            WHEN (item_type='F') THEN text(<? value("phantom") ?>)\n            WHEN (item_type='B') THEN text(<? value("breeder") ?>)\n            WHEN (item_type='C') THEN text(<? value("coProduct") ?>)\n            WHEN (item_type='Y') THEN text(<? value("byProduct") ?>)\n            WHEN (item_type='R') THEN text(<? value("reference") ?>)\n            WHEN (item_type='S') THEN text(<? value("costing") ?>)\n            WHEN (item_type='T') THEN text(<? value("tooling") ?>)\n            WHEN (item_type='A') THEN text(<? value("assortment") ?>)\n            WHEN (item_type='O') THEN text(<? value("outside") ?>)\n            WHEN (item_type='L') THEN text(<? value("planning") ?>)\n            WHEN (item_type='K') THEN text(<? value("kit") ?>)\n            ELSE text(<? value("error") ?>)\n       END AS itemtype,\n       uom_name AS issueuom,\n       CASE WHEN (bomitem_issuemethod = 'S') THEN <? value("push") ?>\n            WHEN (bomitem_issuemethod = 'L') THEN <? value("pull") ?>\n            WHEN (bomitem_issuemethod = 'M') THEN <? value("mixed") ?>\n            ELSE <? value("error") ?>\n       END AS issuemethod,\n       'qty' AS bomitem_qtyfxd_xtnumericrole,\n       'qtyper' AS bomitem_qtyper_xtnumericrole,\n       'percent' AS bomitem_scrap_xtnumericrole,\n       CASE WHEN (bomitem_effective = startOfTime()) THEN NULL\n            ELSE bomitem_effective END AS effective,\n       CASE WHEN (bomitem_expires = endOfTime()) THEN NULL\n            ELSE bomitem_expires END AS expires,\n       <? value("always") ?> AS effective_xtnullrole,\n       <? value("never") ?>  AS expires_xtnullrole,\n       CASE WHEN (bomitem_expires <= CURRENT_DATE) THEN 'expired'\n            WHEN (bomitem_effective > CURRENT_DATE) THEN 'future'\n            WHEN (item_type='M') THEN 'altemphasis'\n       END AS qtforegroundrole\n<? if exists("booitem_id") ?>\nFROM bomitem(<? value("item_id") ?>, <? value("revision_id") ?>), item, uom, xtmfg.booitem\n<? else ?>\nFROM bomitem(<? value("item_id") ?>, <? value("revision_id") ?>), item, uom\n<? endif ?>\nWHERE ((bomitem_item_id=item_id)\n  AND (bomitem_uom_id=uom_id)\n<? if not exists("showExpired") ?>\n  AND (bomitem_expires > CURRENT_DATE)\n<? endif ?>\n<? if not exists("showFuture") ?>\n  AND (bomitem_effective <= CURRENT_DATE)\n<? endif ?>\n<? if exists("booitem_id") ?>\n  AND (booitem_id = <? value("booitem_id") ?>)\n  AND (bomitem_booitem_seq_id = booitem_seq_id)\n<? endif ?>\n  )\nORDER BY bomitem_seqnumber, bomitem_effective;\n	admin	2015-10-01	0
234	briefEarnedCommission	detail	 used by dspBriefEarnedCommissions\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: briefEarnedCommission\n-- Name: detail\n-- Notes: used by dspBriefEarnedCommissions\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cohist_salesrep_id, salesrep_number, salesrep_name, cust_number, cust_name,\n       cohist_ordernumber, cohist_orderdate, cohist_invcnumber, cohist_invcdate, currAbbr,\n       SUM(extprice) AS sumextprice,\n       SUM(cohist_commission) AS sumcommission,\n       SUM(baseextprice) AS sumbaseextprice,\n       SUM(basecommission) AS sumbasecommission,\n<? if exists("isReport") ?>\n       formatDate(cohist_orderdate) AS f_orderdate,\n       formatDate(cohist_invcdate) AS f_invcdate,\n       formatMoney(SUM(extprice)) AS f_sumextprice,\n       formatMoney(SUM(baseextprice)) AS f_sumbaseextprice,\n       formatMoney(SUM(cohist_commission)) AS f_sumcommission,\n       formatMoney(SUM(basecommission)) AS f_sumbasecommission,\n<? endif ?>\n       <? value("return") ?> AS cohist_invcdate_xtnullrole,\n       'curr' AS sumextprice_xtnumericrole,\n       'curr' AS sumcommission_xtnumericrole,\n       'curr' AS sumbaseextprice_xtnumericrole,\n       'curr' AS sumbasecommission_xtnumericrole,\n       0 AS sumbaseextprice_xttotalrole,\n       0 AS sumbasecommission_xttotalrole\n<? if exists("includeMisc") ?>\nFROM saleshistorymisc\n<? else ?>\nFROM saleshistory\n<? endif ?>\nWHERE ((cohist_commission <> 0)\n    AND(cohist_invcdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? if exists("salesrep_id") ?>\n    AND (cohist_salesrep_id=<? value("salesrep_id") ?>)\n    <? endif ?>\n      )\nGROUP BY cohist_salesrep_id, salesrep_number, salesrep_name, cust_number, cust_name,\n         cohist_ordernumber, cohist_orderdate, cohist_invcnumber, cohist_invcdate, currAbbr\nORDER BY salesrep_number, cust_number, cohist_invcdate;\n	admin	2015-10-01	0
235	briefSalesHistory	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: briefSalesHistory\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cohead_id, cust_id, cohist_ponumber,\n       custtype_id, custtype_code,\n       cohist_cust_id, cohist_ordernumber,\n       cust_number, cust_name, currAbbr,\n       cohist_orderdate, cohist_invcdate,\n       CASE WHEN (COALESCE(cohist_invcnumber, '-1') IN ('', '-1')) THEN  <? value("credit") ?>\n            ELSE cohist_invcnumber\n       END AS invoicenumber,\n       SUM(extprice) AS extprice,\n       SUM(baseextprice) AS baseextprice,\n       SUM(extcost) AS extcost,\n       SUM(margin) AS margin,\n       CASE WHEN (SUM(baseextprice) > 0.0) THEN\n            ROUND(SUM(margin) / SUM(baseextprice), 4)\n            ELSE 0.0\n       END AS marginpercent,\n<? if exists("isReport") ?>\n       formatDate(cohist_orderdate) AS f_orderdate,\n       formatDate(cohist_invcdate) AS f_invcdate,\n       formatMoney(SUM(extprice)) AS f_extprice,\n       formatMoney(SUM(baseextprice)) AS f_baseextprice,\n       formatMoney(SUM(extcost)) AS f_extcost,\n       formatMoney(SUM(margin)) AS f_margin,\n       formatPrcnt(CASE WHEN (SUM(baseextprice) > 0.0) THEN\n                        ROUND(SUM(margin) / SUM(baseextprice), 4)\n                        ELSE 0.0\n                   END) AS f_marginpercent,\n<? endif ?>\n       <? value("return") ?> AS cohist_invcdate_xtnullrole,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS baseextprice_xtnumericrole,\n       'curr' AS extcost_xtnumericrole,\n       'curr' AS margin_xtnumericrole,\n       'percent' AS marginpercent_xtnumericrole,\n       0 AS baseextprice_xttotalrole,\n       0 AS extcost_xttotalrole,\n       0 AS margin_xttotalrole\n<? if exists("includeMisc") ?>\n  FROM saleshistorymisc\n<? else ?>\n  FROM saleshistory\n<? endif ?>\nWHERE ( (true)\n<? if exists("startDate") ?>\n  AND  (cohist_invcdate >= <? value("startDate") ?>)\n<? endif ?>\n<? if exists("endDate") ?>\n  AND  (cohist_invcdate <= <? value("endDate") ?>)\n<? endif ?>\n<? if exists("shipStartDate") ?>\n  AND  (cohist_shipdate >= <? value("shipStartDate") ?>)\n<? endif ?>\n<? if exists("shipEndDate") ?>\n  AND  (cohist_shipdate <= <? value("shipEndDate") ?>)\n<? endif ?>\n<? if exists("cust_id") ?>\n   AND (cohist_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("shipto_id") ?>\n   AND (cohist_shipto_id=<? value("shipto_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n   AND (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n   AND (custtype_code ~ <? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                   FROM custgrpitem\n                   WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n<? endif ?>\n<? if exists("custgrp_pattern") ?>\n  AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                   FROM custgrp, custgrpitem\n                   WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                     AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n<? endif ?>\n<? if exists("warehous_id") ?>\n   AND (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n  AND  (item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("prodcat_id") ?>\n   AND (prodcat_id=<? value("prodcat_id") ?>)\n<? endif ?>\n<? if exists("prodcat_pattern") ?>\n   AND (prodcat_id IN (SELECT prodcat_id\n                       FROM prodcat\n                       WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n<? endif ?>\n<? if exists("salesrep_id") ?>\n   AND (cohist_salesrep_id=<? value("salesrep_id") ?>)\n<? endif ?>\n<? if exists("shipzone_id") ?>\n  AND (cohist_shipzone_id=<? value("shipzone_id") ?>)\n<? endif ?>\n<? if exists("saletype_id") ?>\n  AND (cohist_saletype_id=<? value("saletype_id") ?>)\n<? endif ?>\n      )\nGROUP BY cohead_id, cust_id, cust_number, custtype_id,\n         cohist_cust_id, custtype_code, currAbbr,\n         cust_name, cohist_ordernumber, cohist_ponumber,\n         cohist_invcnumber, cohist_orderdate, cohist_invcdate\nORDER BY cohist_invcdate, cohist_orderdate;\n	admin	2015-10-01	0
44	capacityUOMs	detail	 used by dspCapacityUOMsByClassCode, dspCapacityUOMsByProductCategory\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: capacityUOMs\n-- Name: detail\n-- Notes: used by dspCapacityUOMsByClassCode, dspCapacityUOMsByProductCategory\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT item_id, item_number,\n<? if exists("getclasscode") ?>\n       classcode_code,\n<? endif ?>\n       (item_descrip1 || ' ' || item_descrip2) AS descrip,\n       uom_name,\n       itemcapuom(item_id)       AS capuom,\n       itemcapinvrat(item_id)    AS capinvrat,\n       itemaltcapuom(item_id)    AS altcapuom,\n       itemaltcapinvrat(item_id) AS altcapinvrat,\n       'uomratio' AS capinvrat_xtnumericrole,\n       'uomratio' AS altcapinvrat_xtnumericrole\nFROM item\n     JOIN uom ON (item_inv_uom_id=uom_id)\n<? if exists("getclasscode") ?>\n     LEFT OUTER JOIN classcode ON (item_classcode_id=classcode_id)\n<? endif ?>\nWHERE (\n<? if exists("getclasscode") ?> true <? else ?> item_sold <? endif ?>\n<? if exists("prodcat_id") ?>\n   AND (item_prodcat_id=<? value("prodcat_id") ?>)\n<? elseif exists("prodcat_pattern") ?>\n   AND (item_prodcat_id IN (SELECT prodcat_id\n                            FROM prodcat\n                            WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n<? elseif exists("classcode_id") ?>\n   AND (classcode_id=<? value("classcode_id") ?>)\n<? elseif exists("classcode_pattern") ?>\n   AND (classcode_code ~ <? value("classcode_pattern") ?>)\n<? endif ?>\n)\nORDER BY <? if exists("getclasscode") ?> classcode_code, <? endif ?>\n         item_number;\n	admin	2015-10-01	0
45	cashReceipts	detail	 used by dspCashReceipts\n There are 2 display modes for this query:\n 1) Legacy mode which uses A/R Application information\n 2) Version 3.3.0 upgrade mode which uses Cash Receipt information\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: cashReceipts\n-- Name: detail\n-- Notes: used by dspCashReceipts\n-- There are 2 display modes for this query:\n-- 1) Legacy mode which uses A/R Application information\n-- 2) Version 3.3.0 upgrade mode which uses Cash Receipt information\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("LegacyDisplayMode") ?>\n\n-- Posted cash receipts\nSELECT arapply_id, 1 AS type, '' AS cashrcpt_number, cust_number, cust_name,\n       false AS voided, true AS posted, arapply_postdate AS postdate,\n       ( CASE WHEN (arapply_source_doctype='C') THEN <? value("creditMemo") ?>\n              WHEN (arapply_source_doctype='R') THEN <? value("cashdeposit") ?>\n              WHEN (arapply_fundstype='C') THEN <? value("check") ?>\n              WHEN (arapply_fundstype='T') THEN <? value("certifiedCheck") ?>\n              WHEN (arapply_fundstype='M') THEN <? value("masterCard") ?>\n              WHEN (arapply_fundstype='V') THEN <? value("visa") ?>\n              WHEN (arapply_fundstype='A') THEN <? value("americanExpress") ?>\n              WHEN (arapply_fundstype='D') THEN <? value("discoverCard") ?>\n              WHEN (arapply_fundstype='R') THEN <? value("otherCreditCard") ?>\n              WHEN (arapply_fundstype='K') THEN <? value("cash") ?>\n              WHEN (arapply_fundstype='W') THEN <? value("wireTransfer") ?>\n              WHEN (arapply_fundstype='O') THEN <? value("other") ?>\n         END || ' ' ||\n         CASE WHEN (arapply_source_doctype IN ('C','R')) THEN TEXT(arapply_source_docnumber)\n              ELSE arapply_refnumber\n         END ) AS source,\n       COALESCE(cashrcptitem_cashrcpt_id,cashrcptmisc_cashrcpt_id,-1) AS source_xtidrole,\n       ( CASE WHEN (arapply_target_doctype='D') THEN <? value("debitMemo") ?>\n              WHEN (arapply_target_doctype='I') THEN <? value("invoice") ?>\n              ELSE <? value("other") ?>\n         END || ' ' || TEXT(arapply_target_docnumber) ) AS target,\n       COALESCE(arapply_target_aropen_id,-1) AS target_xtidrole,\n       arapply_applied AS applied,\n       'curr' AS applied_xtnumericrole,\n       currtobase(arapply_curr_id,arapply_applied,arapply_postdate) AS base_applied,\n<? if exists("includeFormatted") ?>\n       formatDate(arapply_postdate) AS f_postdate,\n       formatMoney(arapply_applied) AS f_applied,\n       formatMoney(currtobase(arapply_curr_id,arapply_applied,arapply_postdate)) AS f_base_applied,\n<? endif ?>\n       'curr' AS base_applied_xtnumericrole,\n       0 AS base_applied_xttotalrole,\n       currConcat(arapply_curr_id) AS currAbbr,\n       arapply_postdate AS sortdate\nFROM custinfo LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id), arapply\n  LEFT OUTER JOIN cashrcptitem ON ((arapply_reftype='CRA')\n                               AND (arapply_ref_id=cashrcptitem_id))\n  LEFT OUTER JOIN cashrcptmisc ON ((arapply_reftype='CRD')\n                               AND (arapply_ref_id=cashrcptmisc_id))\nWHERE ( (arapply_cust_id=cust_id)\n  AND   (arapply_postdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n  AND   (arapply_source_doctype ='K')\n<? if exists("cust_id") ?>\n  AND   (cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\n  AND   (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND   (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n      )\n\n-- Unposted cash receipts\nUNION\nSELECT cashrcpt_id, 2 AS type, '' AS cashrcpt_number, cust_number, cust_name,\n       false AS voided, false AS posted, cashrcpt_distdate AS postdate,\n       ( CASE WHEN (cashrcpt_fundstype='C') THEN <? value("check") ?>\n              WHEN (cashrcpt_fundstype='T') THEN <? value("certifiedCheck") ?>\n              WHEN (cashrcpt_fundstype='M') THEN <? value("masterCard") ?>\n              WHEN (cashrcpt_fundstype='V') THEN <? value("visa") ?>\n              WHEN (cashrcpt_fundstype='A') THEN <? value("americanExpress") ?>\n              WHEN (cashrcpt_fundstype='D') THEN <? value("discoverCard") ?>\n              WHEN (cashrcpt_fundstype='R') THEN <? value("otherCreditCard") ?>\n              WHEN (cashrcpt_fundstype='K') THEN <? value("cash") ?>\n              WHEN (cashrcpt_fundstype='W') THEN <? value("wireTransfer") ?>\n              WHEN (cashrcpt_fundstype='O') THEN <? value("other") ?>\n         END || ' ' || cashrcpt_docnumber ) AS source,\n      cashrcpt_id AS source_xtidrole,\n       <? value("unposted") ?> AS target,\n       -1 AS target_xtidrole,\n       cashrcpt_amount AS applied,\n       'curr' AS applied_xtnumericrole,\n       (cashrcpt_amount / cashrcpt_curr_rate) AS base_applied,\n<? if exists("includeFormatted") ?>\n       formatDate(cashrcpt_distdate) AS f_postdate,\n       formatMoney(cashrcpt_amount) AS f_applied,\n       formatMoney(cashrcpt_amount / cashrcpt_curr_rate) AS f_base_applied,\n<? endif ?>\n       'curr' AS base_applied_xtnumericrole,\n       0 AS base_applied_xttotalrole,\n       currConcat(cashrcpt_curr_id) AS currAbbr,\n       cashrcpt_distdate AS sortdate\nFROM cashrcpt, custinfo LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ( (NOT cashrcpt_posted)\n  AND   (cashrcpt_cust_id=cust_id)\n  AND   (cashrcpt_distdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("cust_id") ?>\n  AND   (cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\n  AND   (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND   (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n      )\n\n-- Cash Advance\nUNION\nSELECT aropen_id, 3 AS type, '' AS cashrcpt_number, cust_number, cust_name,\n       false AS voided, true AS posted, aropen_docdate AS postdate,\n       ( CASE WHEN (substr(aropen_notes, 16, 1)='C') THEN <? value("check") ?>\n              WHEN (substr(aropen_notes, 16, 1)='T') THEN <? value("certifiedCheck") ?>\n              WHEN (substr(aropen_notes, 16, 1)='M') THEN <? value("masterCard") ?>\n              WHEN (substr(aropen_notes, 16, 1)='V') THEN <? value("visa") ?>\n              WHEN (substr(aropen_notes, 16, 1)='A') THEN <? value("americanExpress") ?>\n              WHEN (substr(aropen_notes, 16, 1)='D') THEN <? value("discoverCard") ?>\n              WHEN (substr(aropen_notes, 16, 1)='R') THEN <? value("otherCreditCard") ?>\n              WHEN (substr(aropen_notes, 16, 1)='K') THEN <? value("cash") ?>\n              WHEN (substr(aropen_notes, 16, 1)='W') THEN <? value("wireTransfer") ?>\n              WHEN (substr(aropen_notes, 16, 1)='O') THEN <? value("other") ?>\n         END || ' ' ||\n         substr(aropen_notes, 18) ) AS source,\n       cashrcptitem_cashrcpt_id AS source_xtidrole,\n       CASE WHEN aropen_doctype = 'R' THEN\n         <? value("cashdeposit") ?> \n       ELSE <? value("creditMemo") ?> \n       END AS target,\n       aropen_id AS target_xtidrole,\n       aropen_amount AS applied,\n       'curr' AS applied_xtnumericrole,\n       aropen_amount / aropen_curr_rate AS base_applied,\n<? if exists("includeFormatted") ?>\n       formatDate(aropen_docdate) AS f_postdate,\n       formatMoney(aropen_amount) AS f_applied,\n       formatMoney(aropen_amount / aropen_curr_rate) AS f_base_applied,\n<? endif ?>\n       'curr' AS base_applied_xtnumericrole,\n       0 AS base_applied_xttotalrole,\n       currConcat(aropen_curr_id) AS currAbbr,\n       aropen_duedate AS sortdate\nFROM custinfo LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id), aropen\n  JOIN cashrcptitem ON (aropen_id=cashrcptitem_aropen_id)\nWHERE ( (aropen_cust_id=cust_id)\n  AND   (aropen_doctype IN ('R','C'))\n  AND   (aropen_docdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("cust_id") ?>\n  AND   (cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\n  AND   (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND   (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n      )\nORDER BY sortdate, source;\n\n<? else ?>\n\n--  New Display Mode\n\nSELECT id, type, cashrcpt_number, cust_number, cust_name,\n       postdate, posted, voided,\n       source, source_xtidrole,\n       posted,\n       target, target_xtidrole,\n       applied,\n       base_applied,\n<? if exists("includeFormatted") ?>\n       formatDate(postdate) AS f_postdate,\n       formatMoney(applied) AS f_applied,\n       formatMoney(base_applied) AS f_base_applied,\n<? endif ?>\n       currAbbr,\n       sortdate,\n       'curr' AS applied_xtnumericrole,\n       'curr' AS base_applied_xtnumericrole,\n       base_applied_xttotalrole,\n       type AS xtindentrole\nFROM (\n\n--  Cash Receipt headers\nSELECT cashrcpt_id AS id, 0 AS type, cashrcpt_number, cust_number, cust_name,\n       cashrcpt_distdate AS postdate, cashrcpt_posted AS posted, cashrcpt_void AS voided,\n       ( CASE WHEN (cashrcpt_fundstype='C') THEN <? value("check") ?>\n              WHEN (cashrcpt_fundstype='T') THEN <? value("certifiedCheck") ?>\n              WHEN (cashrcpt_fundstype='M') THEN <? value("masterCard") ?>\n              WHEN (cashrcpt_fundstype='V') THEN <? value("visa") ?>\n              WHEN (cashrcpt_fundstype='A') THEN <? value("americanExpress") ?>\n              WHEN (cashrcpt_fundstype='D') THEN <? value("discoverCard") ?>\n              WHEN (cashrcpt_fundstype='R') THEN <? value("otherCreditCard") ?>\n              WHEN (cashrcpt_fundstype='K') THEN <? value("cash") ?>\n              WHEN (cashrcpt_fundstype='W') THEN <? value("wireTransfer") ?>\n              WHEN (cashrcpt_fundstype='O') THEN <? value("other") ?>\n         END || ' ' || cashrcpt_docnumber ) AS source,\n       cashrcpt_id AS source_xtidrole,\n       CASE WHEN (cashrcpt_void) THEN <? value("voided") ?>\n            WHEN (NOT cashrcpt_posted) THEN <? value("unposted") ?>\n            ELSE                           ''\n       END AS target,\n       -1 AS target_xtidrole,\n       cashrcpt_amount AS applied,\n       (cashrcpt_amount / cashrcpt_curr_rate) AS base_applied,\n       currConcat(cashrcpt_curr_id) AS currAbbr,\n       cashrcpt_distdate AS sortdate,\n       0 AS base_applied_xttotalrole,\n       -1 AS arapply_id\nFROM cashrcpt JOIN custinfo ON (cust_id=cashrcpt_cust_id) LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\nWHERE ( (cashrcpt_distdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("cust_id") ?>\n  AND   (cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\n  AND   (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND   (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n<? if exists("fundstype") ?>\n  AND   (cashrcpt_fundstype=<? value("fundstype") ?>)\n<? endif ?>\n      )\n\n--  Cash Receipt items\nUNION\nSELECT cashrcpt_id AS id, 1 AS type, '', '', '',\n       cashrcpt_distdate AS postdate, cashrcpt_posted AS posted, cashrcpt_void AS voided,\n       '' AS source,\n       cashrcpt_id AS source_xtidrole,\n       ( CASE WHEN (aropen_doctype='D') THEN <? value("debitMemo") ?>\n              WHEN (aropen_doctype='I') THEN <? value("invoice") ?>\n              WHEN (aropen_doctype='C') THEN <? value("creditMemo") ?>\n              WHEN (aropen_doctype='R') THEN <? value("cashdeposit") ?>\n              ELSE <? value("other") ?>\n         END || ' ' || TEXT(aropen_docnumber) ) AS target,\n       aropen_id AS target_xtidrole,\n       COALESCE(arapply_applied, cashrcptitem_amount) AS applied,\n       (COALESCE(arapply_applied,cashrcptitem_amount) / cashrcpt_curr_rate) AS base_applied,\n       currConcat(cashrcpt_curr_id) AS currAbbr,\n       cashrcpt_distdate AS sortdate,\n       -1 AS base_applied_xttotalrole,\n       arapply_id\nFROM cashrcpt JOIN custinfo ON (cust_id=cashrcpt_cust_id)\n              LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\n              JOIN cashrcptitem ON (cashrcptitem_cashrcpt_id=cashrcpt_id)\n              JOIN aropen ON (aropen_id=cashrcptitem_aropen_id)\n              LEFT OUTER JOIN arapply ON ((arapply_target_aropen_id=aropen_id OR\n                                          arapply_source_aropen_id=aropen_id) AND\n                                          arapply_reftype='CRA' AND\n                                          arapply_ref_id=cashrcptitem_id)\nWHERE ( (cashrcpt_distdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("cust_id") ?>\n  AND   (cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\n  AND   (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND   (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n<? if exists("fundstype") ?>\n  AND   (cashrcpt_fundstype=<? value("fundstype") ?>)\n<? endif ?>\n      )\n\n--  Cash Receipt misc\nUNION\nSELECT cashrcpt_id AS id, 1 AS type, '', '', '',\n       cashrcpt_distdate AS postdate, cashrcpt_posted AS posted, cashrcpt_void AS voided,\n       '' AS source,\n       cashrcpt_id AS source_xtidrole,\n       formatGLAccount(cashrcptmisc_accnt_id) AS target,\n       -1 AS target_xtidrole,\n       COALESCE(arapply_applied, cashrcptmisc_amount) AS applied,\n       (COALESCE(arapply_applied, cashrcptmisc_amount) / cashrcpt_curr_rate) AS base_applied,\n       currConcat(cashrcpt_curr_id) AS currAbbr,\n       cashrcpt_distdate AS sortdate,\n       -1 AS base_applied_xttotalrole,\n       arapply_id\nFROM cashrcpt JOIN custinfo ON (cust_id=cashrcpt_cust_id)\n              LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\n              JOIN cashrcptmisc ON (cashrcptmisc_cashrcpt_id=cashrcpt_id)\n              LEFT OUTER JOIN arapply ON (arapply_reftype='CRD' AND\n                                          arapply_ref_id=cashrcptmisc_id)\nWHERE ( (cashrcpt_distdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("cust_id") ?>\n  AND   (cust_id=<? value("cust_id") ?>)\n<? elseif exists("custtype_id") ?>\n  AND   (cust_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND   (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n<? if exists("fundstype") ?>\n  AND   (cashrcpt_fundstype=<? value("fundstype") ?>)\n<? endif ?>\n      )\n  ) AS data\nORDER BY sortdate, id, type, target;\n\n<? endif ?>\n\n	admin	2015-10-01	0
96	ccpayments	list	 list credit card payments, optionally by customer\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: ccpayments\n-- Name:  list\n-- Notes: list credit card payments, optionally by customer\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT ccpay_id AS id, \n       CASE WHEN ((ccpay_status = 'A') AND \n                 (date_part('day', CURRENT_TIMESTAMP - ccpay_transaction_datetime) < COALESCE(<? value("ccValidDays") ?>,0))) THEN\n         1\n       ELSE 0\n       END AS altid, cohead_id,\n       ccpay.*,\n       cust_number, cust_name,       \n       ccpay_type AS type,       \n       CASE WHEN (ccpay_type='A') THEN <? value("preauth") ?>\n            WHEN (ccpay_type='C') THEN <? value("charge") ?>\n            WHEN (ccpay_type='R') THEN <? value("refund") ?>\n            ELSE ccpay_type\n       END AS type_qtdisplayrole,\n       ccpay_status AS status,\n       CASE WHEN (ccpay_status='A') THEN <? value("authorized") ?>\n            WHEN (ccpay_status='C') THEN <? value("approved") ?>\n            WHEN (ccpay_status='D') THEN <? value("declined") ?>\n            WHEN (ccpay_status='V') THEN <? value("voided") ?>\n            WHEN (ccpay_status='X') THEN <? value("noapproval") ?>\n            ELSE ccpay_status\n       END AS status_qtdisplayrole,\n       currConcat(ccpay_curr_id) AS currAbbr,\n       COALESCE(cohead_number, ccpay_order_number) AS docnumber,\n       ABS(COALESCE(payco_amount, ccpay_amount)) AS allocated,\n       currConcat(COALESCE(payco_curr_id, ccpay_curr_id)) AS payco_currAbbr,\n       cust_number, cust_name,\n       'curr' AS ccpay_amount_xtnumericrole,\n       'curr' AS allocated_xtnumericrole,\n        CASE WHEN ((ccpay_status = 'A')\n              AND (date_part('day', CURRENT_TIMESTAMP - ccpay_transaction_datetime) >= COALESCE(<? value("ccValidDays") ?>,0))) THEN\n          'error'\n        END AS qtforegroundrole\n  FROM ccpay LEFT OUTER JOIN \n       (payco JOIN cohead ON (payco_cohead_id=cohead_id))\n         ON (payco_ccpay_id=ccpay_id)\n      JOIN custinfo ON (ccpay_cust_id=cust_id)\n      JOIN custtype ON (cust_custtype_id=custtype_id)\n      LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)\n  WHERE ((true)\n<? if exists("processed") ?>\n  AND (ccpay_status != 'A')\n<? elseif exists("authorizations") ?>\n  AND (ccpay_status = 'A')\n<? endif ?>\n<? if exists("validOnly") ?>\n  AND ((ccpay_status != 'A')\n  OR (date_part('day', CURRENT_TIMESTAMP - ccpay_transaction_datetime) < <? value("ccValidDays") ?>))\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND   (ccpay_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND   (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND   (custtype_code~<? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)\n<? endif ?>)\n ORDER BY ccpay_transaction_datetime;\n	admin	2015-10-01	0
456	charass	populate	 Populate characteristic assignments combobox\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: charass\n-- Name:  populate\n-- Notes: Populate characteristic assignments combobox\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("name") ?>\nSELECT -1 AS charass_char_id, '' AS char_name\nUNION\nSELECT DISTINCT charass_char_id, char_name\n<? else ?>\nSELECT -1 AS charass_id, '' AS charass_value\nUNION\nSELECT DISTINCT charass_id, charass_value\n<? endif ?>\nFROM charass, char\nWHERE ((charass_char_id=char_id)\n  AND (charass_target_type=<? value("type") ?>)\n  AND (charass_target_id= <? value("id") ?>))\n<? if exists("char") ?>\n  AND (charass_char_id= <? value("char") ?>)\n  AND (COALESCE(charass_value,'')!='')\n<? endif ?>\n<? if exists("name") ?>\nORDER BY char_name;\n<? else ?>\nORDER BY charass_value;\n<? endif ?>\n	admin	2015-10-01	0
46	checkRegister	detail	 used by dspCheckRegister and viewCheckRun;\n        shows all the checks for a given date range, bank account, \n        check number(optional), and recipient(optional), optionally restricted\n        to 'new' (un-posted/replaced/deleted) checks for viewing check runs.\n        fills in the check item detail if showDetail is passed.\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: checkRegister\n-- Name: detail\n-- Notes: used by dspCheckRegister and viewCheckRun;\n--        shows all the checks for a given date range, bank account, \n--        check number(optional), and recipient(optional), optionally restricted\n--        to 'new' (un-posted/replaced/deleted) checks for viewing check runs.\n--        fills in the check item detail if showDetail is passed.\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT checkhead_id AS checkid,\n       CASE WHEN(checkhead_void) THEN -1\n            WHEN(checkhead_posted) THEN 1\n            ELSE 0\n       END AS extra,\n       -1 AS checkitem_id,\n       checkhead_void, checkhead_misc,\n       checkhead_printed, checkhead_posted,\n       CASE when checkhead_number = -1 THEN\n         'Unspecified'\n       ELSE TEXT(checkhead_number) END AS number,\n       COALESCE((SELECT checkrecip_number || '-' || checkrecip_name\n                 FROM checkrecip\n                 WHERE ((checkhead_recip_id=checkrecip_id)\n\t\t   AND  (checkhead_recip_type=checkrecip_type)))\n                ,\n\t\tcheckhead_recip_type || '-' || checkhead_recip_id ) AS description,\n       checkhead_checkdate AS checkdate,\n       checkhead_amount AS amount, \n       checkhead_amount / checkhead_curr_rate AS base_amount, \n       currConcat(checkhead_curr_id) AS currAbbr,\n       checkhead_number,\n       checkhead_ach_batch,\n       1 AS orderby,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       NULL AS checkhead_void_qtdisplayrole,    NULL AS checkhead_misc_qtdisplayrole,\n       NULL AS checkhead_printed_qtdisplayrole, NULL AS checkhead_posted_qtdisplayrole,\n       0 AS xtindentrole\n  FROM checkhead\n WHERE ((checkhead_bankaccnt_id=<? value("bankaccnt_id") ?>)\n   <? if exists("startDate") ?>\n     AND (checkhead_checkdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n   <? elseif exists("newOnly") ?>\n     AND (NOT checkhead_posted)\n     AND (NOT checkhead_replaced)\n     AND (NOT checkhead_deleted)\n   <? endif ?>\n   <? if exists("check_number") ?>\n      AND   (CAST(checkhead_number AS text) ~ <? value("check_number") ?>)\n   <? endif ?>\n   <? if exists("recip") ?>\n      <? if exists("recip_type_v") ?>\n         AND   (checkhead_recip_type = 'V' )\n      <? endif ?>\n      <? if exists("recip_type_c") ?>\n         AND   (checkhead_recip_type = 'C' )\n      <? endif ?>\n      <? if exists("recip_type_t") ?>\n         AND   (checkhead_recip_type = 'T' )\n      <? endif ?>\n      <? if exists("recip_id") ?>\n         AND   (checkhead_recip_id = <? value("recip_id") ?> )\n      <? endif ?>\n   <? endif ?>\n   <? if exists("vend_id") ?>\n     AND (checkhead_recip_type = 'V')\n     AND (checkhead_recip_id = <? value("vend_id") ?>)\n   <? elseif exists("vendtype_id") ?>\n     AND (checkhead_recip_type = 'V')\n     AND (checkhead_recip_id IN (SELECT vend_id\n                                 FROM vendinfo\n                                 WHERE (vend_vendtype_id=<? value("vendtype_id") ?>)))\n   <? elseif exists("vendtype_pattern") ?>\n     AND (checkhead_recip_type = 'V')\n     AND (checkhead_recip_id IN (SELECT vend_id\n                                 FROM vendinfo, vendtype\n                                 WHERE  (vend_vendtype_id=vendtype_id)\n                                   AND  (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n   <? endif ?>\n)\n<? if exists("showDetail") ?>\nUNION\nSELECT checkitem_checkhead_id AS checkid, 0 AS extra, checkitem_id,\n       checkhead_void, checkhead_misc,\n       checkhead_printed, checkhead_posted,\n       (CASE apopen_doctype WHEN 'V' THEN <? value("voucher") ?>\n                            WHEN 'D' THEN <? value("debitMemo") ?>\n                            WHEN 'C' THEN <? value("creditMemo") ?>\n                            ELSE ''\n        END || '-' || CAST(COALESCE(checkitem_ranumber, checkitem_vouchernumber) AS TEXT)) AS number,\n       CAST(COALESCE(checkitem_invcnumber, checkitem_cmnumber) AS TEXT) AS description,\n       CAST(NULL AS DATE) AS checkdate,\n       checkitem_amount AS amount,\n       currtobase(checkhead_curr_id,checkitem_amount,checkhead_checkdate) AS base_amount, \n       currConcat(checkitem_curr_id) AS currAbbr, \n       checkhead_number, \n       NULL AS checkhead_ach_batch,\n       2 AS orderby,\n       'curr' AS amount_xtnumericrole,\n       'curr' AS base_amount_xtnumericrole,\n       '' AS checkhead_void_qtdisplayrole,    '' AS checkhead_misc_qtdisplayrole,\n       '' AS checkhead_printed_qtdisplayrole, '' AS checkhead_posted_qtdisplayrole,\n       1 AS xtindentrole\n  FROM checkhead JOIN checkitem ON (checkitem_checkhead_id=checkhead_id)\n                 LEFT OUTER JOIN apopen ON (apopen_id=checkitem_apopen_id)\n WHERE ((checkhead_bankaccnt_id=<? value("bankaccnt_id") ?>)\n   <? if exists("startDate") ?>\n     AND   (checkhead_checkdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n   <? elseif exists("newOnly") ?>\n     AND (NOT checkhead_posted)\n     AND (NOT checkhead_replaced)\n     AND (NOT checkhead_deleted)\n   <? endif ?>\n   <? if exists("check_number") ?>\n      AND   (CAST(checkhead_number AS text) ~ <? value("check_number") ?>)\n   <? endif ?>\n   <? if exists("recip") ?>\n      <? if exists("recip_type_v") ?>\n         AND   (checkhead_recip_type = 'V' )\n      <? endif ?>\n      <? if exists("recip_type_c") ?>\n         AND   (checkhead_recip_type = 'C' )\n      <? endif ?>\n      <? if exists("recip_type_t") ?>\n         AND   (checkhead_recip_type = 'T' )\n      <? endif ?>\n      <? if exists("recip_id") ?>\n         AND   (checkhead_recip_id = <? value("recip_id") ?> )\n      <? endif ?>\n   <? endif ?>\n   <? if exists("vend_id") ?>\n     AND (checkhead_recip_type = 'V')\n     AND (checkhead_recip_id = <? value("vend_id") ?>)\n   <? elseif exists("vendtype_id") ?>\n     AND (checkhead_recip_type = 'V')\n     AND (checkhead_recip_id IN (SELECT vend_id\n                                 FROM vendinfo\n                                 WHERE (vend_vendtype_id=<? value("vendtype_id") ?>)))\n   <? elseif exists("vendtype_pattern") ?>\n     AND (checkhead_recip_type = 'V')\n     AND (checkhead_recip_id IN (SELECT vend_id\n                                 FROM vendinfo, vendtype\n                                 WHERE  (vend_vendtype_id=vendtype_id)\n                                   AND  (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n   <? endif ?>\n   )\n<? endif ?>\n ORDER BY checkhead_number, checkid, orderby;\n	admin	2015-10-01	0
97	checks	detail	 used by printChecks\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: checks\n-- Name: detail\n-- Notes: used by printChecks\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT checkhead.*, form_report_name AS report_name\nFROM checkhead\nLEFT OUTER JOIN vendinfo ON((checkhead_recip_id = vend_id)\n                        AND (checkhead_recip_type = 'V'))\nLEFT OUTER JOIN custinfo ON((checkhead_recip_id = cust_id)\n                        AND (checkhead_recip_type = 'C'))\nLEFT OUTER JOIN taxauth ON((checkhead_recip_id = taxauth_id)\n                       AND (checkhead_recip_type = 'T')),\n     bankaccnt, form\nWHERE ( (checkhead_bankaccnt_id=bankaccnt_id)\n  AND   (bankaccnt_check_form_id=form_id)\n<? if exists("toPrintOnly") ?>\n  AND   (NOT checkhead_printed)\n  AND   (NOT checkhead_void)\n<? endif ?>\n<? if exists("bankaccnt_id") ?>\n  AND   (bankaccnt_id=<? value("bankaccnt_id" ?>)\n<? endif ?>\n      )\n<? if exists("orderByName") ?>\nORDER BY checkhead_recip_type DESC, COALESCE(vend_name, cust_name, taxauth_name)\n<? else ?>\nORDER BY checkhead_recip_type DESC, COALESCE(vend_number, cust_number, taxauth_code)\n<? endif ?>\n<? if exists("numtoprint") ?>\nLIMIT <? value("numtoprint") ?>\n<? endif ?>\n;\n	admin	2015-10-01	0
450	contact	muststayactive	 This query determines whether a given contact should be kept\n        active because other active records depend on it.\n        Todo - should this be moved to the cntctAfterTrigger?\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contact\n-- Name:  muststayactive\n-- Notes: This query determines whether a given contact should be kept\n--        active because other active records depend on it.\n--        Todo - should this be moved to the cntctAfterTrigger?\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT EXISTS(\n SELECT 1\n   FROM crmacct\n  WHERE(crmacct_active\n    AND (<? value("id") ?> IN (crmacct_cntct_id_1, crmacct_cntct_id_2)))\n UNION SELECT 3\n   FROM custinfo\n  WHERE (cust_active\n    AND (<? value("id") ?> IN (cust_cntct_id, cust_corrcntct_id)))\n UNION SELECT 5\n   FROM vendinfo\n  WHERE (vend_active\n    AND (<? value("id") ?> IN (vend_cntct1_id, vend_cntct2_id)))\n UNION SELECT 7\n   FROM prospect\n  WHERE (prospect_active AND (prospect_cntct_id=<? value("id") ?>))\n UNION SELECT 8\n   FROM shiptoinfo\n  WHERE (shipto_active AND (shipto_cntct_id=<? value("id") ?>))\n UNION SELECT 9\n   FROM vendaddrinfo\n   JOIN vendinfo ON (vendaddr_vend_id=vend_id)\n  WHERE (vend_active AND (vendaddr_cntct_id=<? value("id") ?>))\n UNION SELECT 10\n   FROM whsinfo\n  WHERE (warehous_active AND (warehous_cntct_id=<? value("id") ?>))\n UNION SELECT 11\n   FROM emp\n  WHERE (emp_active AND (emp_cntct_id=<? value("id") ?>))\n UNION SELECT 21\n   FROM todoitem\n  WHERE (todoitem_completed_date IS NOT NULL\n    AND (todoitem_cntct_id=<? value("id") ?>))\n) AS inuse;\n	admin	2015-10-01	0
438	contact	uses	 Find and report uses of the contact\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contact\n-- Name:  uses\n-- Notes: Find and report uses of the contact\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if not exists('core') ?>\nSELECT <? value("id") ?>::text || '.' || type_id::text || '.' || type_code::text,\n       <? value("id") ?> AS contact,\n       *\nFROM (\n<? endif ?>\n  SELECT crmacct_id AS type_id, 1 AS type_code, <? value("crmacct") ?> AS type,\n         crmacct_number AS number,\n         crmacct_name AS name, <? value("primary") ?> AS role,\n         (crmacct_active) AS active,\n         crmacct_owner_username AS owner\n    FROM crmacct WHERE (crmacct_cntct_id_1=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT crmacct_id AS type_id, 2 AS type_code, <? value("crmacct") ?> AS type,\n         crmacct_number AS number,\n         crmacct_name AS name, <? value("secondary") ?> AS role,\n         (crmacct_active) AS active,\n         crmacct_owner_username AS owner\n    FROM crmacct WHERE (crmacct_cntct_id_2=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT cust_id AS type_id, 3 AS type_code, <? value("cust") ?> AS type,\n         cust_number AS number,\n         cust_name AS name, <? value("billing") ?> AS role,\n         (cust_active) AS active,\n         '' AS owner\n    FROM custinfo WHERE (cust_cntct_id=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT cust_id AS type_id, 4 AS type_code, <? value("cust") ?> AS type,\n         cust_number AS number,\n         cust_name AS name, <? value("correspond") ?> AS role,\n         (cust_active) AS active,\n         '' AS owner\n    FROM custinfo WHERE (cust_corrcntct_id=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT vend_id AS type_id, 5 AS type_code, <? value("vend") ?> AS type,\n         vend_number AS number,\n         vend_name AS name, <? value("primary") ?> AS role,\n         (vend_active) AS active,\n         '' AS owner\n    FROM vendinfo WHERE (vend_cntct1_id=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT vend_id AS type_id, 6 AS type_code, <? value("vend") ?> AS type,\n         vend_number AS number,\n         vend_name AS name, <? value("secondary") ?> AS role,\n         (vend_active) AS active,\n         '' AS owner\n    FROM vendinfo WHERE (vend_cntct2_id=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT prospect_id AS type_id, 7 AS type_code, <? value("prospect") ?> AS type,\n         prospect_number AS number,\n         prospect_name AS name, '' AS role,\n         (prospect_active) AS active,\n         '' AS owner\n    FROM prospect WHERE (prospect_cntct_id=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT shipto_id AS type_id, 8 AS type_code, <? value("shipto") ?> AS type,\n         shipto_num AS number,\n         shipto_name AS name, <? value("shipto") ?> AS role,\n         (shipto_active) AS active,\n         '' AS owner\n    FROM shiptoinfo WHERE (shipto_cntct_id=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT vendaddr_id AS type_id, 9 AS type_code, <? value("vendaddr") ?> AS type,\n         vendaddr_code AS number,\n         vendaddr_name AS name, '' AS role,\n         (true) AS active,\n         '' AS owner\n    FROM vendaddrinfo WHERE (vendaddr_cntct_id=<? value("id") ?>)\n   \n  UNION ALL\n  SELECT warehous_id AS type_id, 10 AS type_code, <? value("whs") ?> AS type,\n         warehous_code AS number,\n         warehous_descrip AS name, '' AS role,\n         (warehous_active) AS active,\n         '' AS owner\n    FROM whsinfo WHERE (warehous_cntct_id=<? value("id") ?>)\n  \n  UNION ALL\n  SELECT emp_id AS type_id, 11 AS type_code, <? value("emp") ?> AS type,\n         emp_code AS number,\n         emp_number AS name, '' AS role,\n         (emp_active) AS active,\n         '' AS owner\n    FROM emp WHERE (emp_cntct_id=<? value("id") ?>)\n\n<? if exists("showOrders") ?>\n  UNION ALL\n  SELECT cohead_id AS id, 12 AS altId, <? value("cohead") ?> AS type,\n         cohead_number AS number,\n         cust_number AS name, <? value("billing") ?> AS role,\n         (cohead_status = 'O') AS active,\n         '' AS owner\n    FROM cohead JOIN custinfo ON (cohead_cust_id=cust_id)\n   WHERE (<? value("id") ?>=cohead_billto_cntct_id)\n\n  UNION ALL\n  SELECT cohead_id AS id, 13 AS altId, <? value("cohead") ?> AS type,\n         cohead_number AS number,\n         cust_number AS name,  <? value("shipto") ?> AS role,\n         (cohead_status = 'O') AS active,\n         '' AS owner\n    FROM cohead JOIN custinfo ON (cohead_cust_id=cust_id)\n   WHERE (<? value("id") ?>=cohead_shipto_cntct_id)\n<? endif ?>\n\n  UNION ALL\n  SELECT incdt_id AS id, 14 AS altId, <? value("incdt") ?> AS type,\n         incdt_number::TEXT AS number,\n         incdt_summary AS name, '' AS role,\n         (incdt_status NOT IN ('R', 'L')) AS active,\n         incdt_owner_username AS owner\n    FROM incdt\n   WHERE (incdt_cntct_id=<? value("id") ?>)\n\n<? if exists("lsreg") ?>\n  UNION ALL\n  SELECT lsreg_id AS id, 15 AS altId, <? value("lsreg") ?> AS type,\n         ls_number AS number,\n         item_number AS name, '' AS role,\n         (lsreg_expiredate > current_date) AS active,\n         '' AS owner\n    FROM lsreg JOIN ls ON (lsreg_ls_id=ls_id) JOIN item ON (ls_item_id=item_id)\n   WHERE (lsreg_cntct_id=<? value("id") ?>)\n<? endif ?>\n\n  UNION ALL\n  SELECT ophead_id AS id, 16 AS altId, <? value("ophead") ?> AS type,\n         ophead_number AS number,\n         ophead_name AS name, '' AS role,\n         ophead_active AS active,\n         ophead_owner_username AS owner\n    FROM ophead\n   WHERE (ophead_cntct_id=<? value("id") ?>)\n\n<? if exists("showOrders") ?>\n  UNION ALL\n  SELECT pohead_id AS id, 17 AS altId, <? value("pohead") ?> AS type,\n         pohead_number AS number,\n         vend_number AS name, <? value("vendcntct") ?> AS role,\n         (pohead_status != 'C') AS active,\n         '' AS owner\n    FROM pohead JOIN vendinfo ON (pohead_vend_id=vend_id)\n   WHERE (<? value("id") ?>=pohead_vend_cntct_id)\n\n  UNION ALL\n  SELECT pohead_id AS id, 18 AS altId, <? value("pohead") ?> AS type,\n         pohead_number AS number,\n         vend_number AS name, <? value("shipto") ?> AS role,\n         (pohead_status != 'C') AS active,\n         '' AS owner\n    FROM pohead JOIN vendinfo ON (pohead_vend_id=vend_id)\n   WHERE (<? value("id") ?>=pohead_shipto_cntct_id)\n\n  UNION ALL\n  SELECT quhead_id AS id, 19 AS altId, <? value("quhead") ?> AS type,\n         quhead_number AS number,\n         COALESCE(cust_number, prospect_number) AS name,\n         <? value("billing") ?> AS role,\n         (quhead_status = 'O') AS active,\n         '' AS owner\n    FROM quhead LEFT OUTER JOIN custinfo ON (quhead_cust_id=cust_id)\n                LEFT OUTER JOIN prospect ON (quhead_cust_id=prospect_id)\n   WHERE (<? value("id") ?>=quhead_billto_cntct_id)\n\n  UNION ALL\n  SELECT quhead_id AS id, 20 AS altId, <? value("quhead") ?> AS type,\n         quhead_number AS number,\n         COALESCE(cust_number, prospect_number) AS name,\n         <? value("shipto") ?> AS role,\n         (quhead_status = 'O') AS active,\n         '' AS owner\n    FROM quhead LEFT OUTER JOIN custinfo ON (quhead_cust_id=cust_id)\n                LEFT OUTER JOIN prospect ON (quhead_cust_id=prospect_id)\n   WHERE (<? value("id") ?>=quhead_shipto_cntct_id)\n<? endif ?>\n\n  UNION ALL\n  SELECT todoitem_id, 21 AS altId, <? value("todo") ?> AS type,\n         todoitem_seq::TEXT AS number,\n         todoitem_name AS name, '' AS role,\n         (todoitem_completed_date IS NULL) AS active,\n         todoitem_owner_username AS owner\n    FROM todoitem\n   WHERE todoitem_cntct_id=<? value("id") ?>\n\n<? if exists("showOrders") ?>\n  <? if exists("tohead") ?>\n  UNION ALL\n  SELECT tohead_id, 22 AS altId, <? value("tohead") ?> AS type,\n         tohead_number AS number,\n         tohead_srcname || ' -> ' || tohead_destname AS name,\n         <? value("from") ?>  AS role,\n         (tohead_status = 'O') AS active,\n         '' AS owner\n    FROM tohead\n   WHERE (<? value("id") ?>=tohead_srccntct_id)\n  UNION ALL\n  SELECT tohead_id, 23 AS altId, <? value("tohead") ?> AS type,\n         tohead_number AS number,\n         tohead_srcname || ' -> ' || tohead_destname AS name,\n         <? value("dest") ?> AS role,\n         (tohead_status = 'O') AS active,\n         '' AS owner\n    FROM tohead\n   WHERE (<? value("id") ?>=tohead_destcntct_id)\n  <? endif ?>\n<? endif ?>\n\n<? if not exists('core') ?>\n) AS innerq\n<? endif ?>\n  ORDER BY type, number;\n	admin	2015-10-01	0
418	contactmerge	contactused	 Checks to see if this contact is used anywhere\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: contactused\n-- Notes: Checks to see if this contact is used anywhere\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntctused(<? value("cntct_id") ?>) AS used;\n	admin	2015-10-01	0
422	contactmerge	merge	 Merge contact selections\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: merge\n-- Notes: Merge contact selections\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntctmerge(\n  src.cntctsel_cntct_id, \n  trgt.cntctsel_cntct_id,\n  <? value("purge") ?>::boolean) AS result\nFROM cntctsel src, cntctsel trgt\nWHERE ((trgt.cntctsel_target)\nAND (NOT src.cntctsel_target));\n	admin	2015-10-01	0
421	contactmerge	merged	  Lists all merged contacts\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: merged\n-- Notes:  Lists all merged contacts\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntct_id,\n  CASE\n    WHEN (cntctUsed(cntctmrgd_cntct_id)=false) THEN\n      3 -- Already merged contact\n    ELSE\n      4 -- Already merged contact, but still has relationships\n  END AS status,\n  cntct.*,crmacct_number,crmacct_name,addr.*, \n 0 AS xtindentrole,\n  CASE\n    WHEN (cntctUsed(cntctmrgd_cntct_id)=false) THEN\n      'warning' -- Already merged contact\n    ELSE\n      'error'  -- Already merged contact, but still has relationships\n  END AS qtforegroundrole\nFROM cntct\n  JOIN cntctmrgd ON (cntct_id=cntctmrgd_cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n  LEFT OUTER JOIN crmacct ON (cntct_crmacct_id=crmacct_id);\n	admin	2015-10-01	0
423	contactmerge	populate	 Queries selected contact info\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: populate\n-- Notes: Queries selected contact info\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntct.*,\n  crmacct_number,\n  crmacct_name,\n  addr.*,\n  CASE WHEN cntctsel_mrg_first_name THEN 'emphasis' END AS cntct_first_name_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_last_name THEN 'emphasis' END AS cntct_last_name_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_honorific THEN 'emphasis' END AS cntct_honorific_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_initials THEN 'emphasis' END AS cntct_initials_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_phone THEN 'emphasis' END AS cntct_phone_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_phone2 THEN 'emphasis' END AS cntct_phone2_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_fax THEN 'emphasis' END AS cntct_fax_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_email THEN 'emphasis' END AS cntct_email_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_webaddr THEN 'emphasis' END AS cntct_webaddr_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_notes THEN 'emphasis' END AS cntct_notes_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_title THEN 'emphasis' END AS cntct_title_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_middle THEN 'emphasis' END AS cntct_middle_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_suffix THEN 'emphasis' END AS cntct_suffix_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_owner_username THEN 'emphasis' END AS cntct_owner_username_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_crmacct_id THEN 'emphasis' END AS crmacct_number_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_crmacct_id THEN 'emphasis' END AS crmacct_name_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_line1_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_line2_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_line3_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_city_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_state_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_postalcode_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_country_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_notes_qtforegroundrole,\n  CASE WHEN cntctsel_mrg_addr_id THEN 'emphasis' END AS addr_number_qtforegroundrole\nFROM cntctsel\n  JOIN cntct ON (cntctsel_cntct_id=cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n  LEFT OUTER JOIN crmacct ON (cntct_crmacct_id=crmacct_id)\nWHERE (cntctsel_target=<? value("target") ?>);\n	admin	2015-10-01	0
424	contactmerge	purge	 Purge contact(s) that was/were previously merged\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contactmerge\n-- Name: purge\n-- Notes: Purge contact(s) that was/were previously merged\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nDELETE FROM cntct WHERE cntct_id IN\n(SELECT cntctmrgd_cntct_id\n  FROM cntctmrgd\n  WHERE (NOT cntctmrgd_error)\n<? if exists("cntct_id") ?>\nAND (cntctmrgd_cntct_id=<? value("cntct_id") ?>)\n<? endif ?>)\nAND (NOT cntctUsed(cntct_id));\n	admin	2015-10-01	0
99	contacts	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contacts\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT ON (length(cntct_last_name)=0, length(cntct_first_name)=0, cntct_last_name, cntct_first_name, cntct_number) \n  cntct_id AS id\n<? if not exists("idOnly") ?> \n, addr_id AS altId, addr.*,\n  crmacct_id, crmacct_number, crmacct_name,\n  cntct.* \n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\n<? endif ?>\n<? if exists("hasContext") ?>\nFROM cntct\n<? else ?>\nFROM cntct()\n<? endif ?>\n  LEFT OUTER JOIN crmacct ON (cntct_crmacct_id=crmacct_id) \n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id) \n  LEFT OUTER JOIN cntcteml ON (cntcteml_cntct_id=cntct_id)\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='CNTCT') \n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cntct_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='CNTCT') \n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cntct_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='CNTCT') \n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cntct_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE true\n<? if exists("owner_username") ?> \n  AND (cntct_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (cntct_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\n<? if exists("activeOnly") ?> \n  AND cntct_active\n<? endif ?>\n<? if exists("search_pattern") ?>\n  AND (\n (crmacct_number ~* <? value("search_pattern") ?>)\n  OR (crmacct_name ~* <? value("search_pattern") ?>)\n  OR (COALESCE(cntct_first_name,'') || ' ' || COALESCE(cntct_last_name,'') ~* <? value("search_pattern") ?>)\n  OR (COALESCE(cntct_phone,'') || ' ' || COALESCE(cntct_phone2,'') || ' ' || COALESCE(cntct_fax,'') ~* <? value("search_pattern") ?>)\n  OR (COALESCE(cntcteml_email,'') ~* <? value("search_pattern") ?>)\n  OR (COALESCE(addr_line1,'') || ' ' || COALESCE(addr_line2,'') || ' ' || COALESCE(addr_line3,'') ~* <? value("search_pattern") ?>)\n  OR (COALESCE(addr_city,'') ~* <? value("search_pattern") ?>)\n  OR (COALESCE(addr_state,'') ~* <? value("search_pattern") ?>)\n  OR (COALESCE(addr_postalcode,'') ~* <? value("search_pattern") ?>)\n  OR (COALESCE(addr_country,'') ~* <? value("search_pattern") ?>)\n)\n<? endif ?>\n<? if exists("cntct_id") ?>\n  AND (cntct_id=<? value("cntct_id")?>)\n<? endif ?>\n<? if exists("crmacct_id") ?>\n  AND (crmacct_id=<? value("crmacct_id")?>)\n<? endif ?>\n<? if exists("cntct_name_pattern") ?>\n  AND (COALESCE(cntct_first_name,'') || ' ' || COALESCE(cntct_last_name,'') ~* <? value("cntct_name_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_phone_pattern") ?>\n  AND (COALESCE(cntct_phone,'') || ' ' || COALESCE(cntct_phone2,'') || ' ' || COALESCE(cntct_fax,'') ~* <? value("cntct_phone_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_email_pattern") ?>\n  AND (COALESCE(cntcteml_email,'') ~* <? value("cntct_email_pattern") ?>)\n<? endif ?>\n<? if exists("addr_street_pattern") ?>\n  AND (COALESCE(addr_line1,'') || ' ' || COALESCE(addr_line2,'') || ' ' || COALESCE(addr_line3,'') ~* <? value("addr_street_pattern") ?>)\n<? endif ?>\n<? if exists("addr_city_pattern") ?>\n  AND (COALESCE(addr_city,'') ~* <? value("addr_city_pattern") ?>)\n<? endif ?>\n<? if exists("addr_state_pattern") ?>\n  AND (COALESCE(addr_state,'') ~* <? value("addr_state_pattern") ?>)\n<? endif ?>\n<? if exists("addr_postalcode_pattern") ?>\n  AND (COALESCE(addr_postalcode,'') ~* <? value("addr_postalcode_pattern") ?>)\n<? endif ?>\n<? if exists("addr_country_pattern") ?>\n  AND (COALESCE(addr_country,'') ~* <? value("addr_country_pattern") ?>)\n<? endif ?>\n<? if exists("id") ?>\n  AND (cntct_id=<? literal("id") ?>)\n<? endif ?>\n<? if exists("addr_id") ?>\n  AND (addr_id=<? value("addr_id") ?>)\n<? endif ?>\n<? literal("charClause") ?>\nORDER BY length(cntct_last_name)=0, length(cntct_first_name)=0, cntct_last_name, cntct_first_name, cntct_number, cntcteml_primary desc;\n	admin	2015-10-01	0
474	contracts	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: contracts\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT contrct_id, \n       vend_number, vend_name, \n       contrct.*,\n       CASE WHEN COALESCE(contrct_effective, startOfTime()) <=\n                 startOfTime() THEN <? value("always") ?>\n       END AS contrct_effective_qtdisplayrole,\n       CASE WHEN COALESCE(contrct_expires, endOfTime()) >=\n                 endOfTime() THEN <? value("never") ?>\n       END AS contrct_expires_qtdisplayrole,\n       CASE WHEN (COALESCE(contrct_expires, endOfTime()) < CURRENT_DATE) THEN 'expired'\n            WHEN (COALESCE(contrct_effective, startOfTime()) > CURRENT_DATE) THEN 'future'\n       END AS qtforegroundrole,\n       (SELECT count(*) FROM itemsrc WHERE (itemsrc_contrct_id=contrct_id)) AS item_count \nFROM contrct JOIN vendinfo ON (vend_id=contrct_vend_id)\nWHERE ((true)\n<? if exists("vend_id") ?>\n  AND (contrct_vend_id=<? value("vend_id") ?>)\n<? endif ?>\n<? if exists("effectiveStartDate") ?>\n  AND (contrct_effective >= <? value("effectiveStartDate") ?>)\n<? endif ?>\n<? if exists("effectiveEndDate") ?>\n  AND (contrct_effective <= <? value("effectiveEndDate") ?>)\n<? endif ?>\n<? if exists("expireStartDate") ?>\n  AND (contrct_expires >= <? value("expireStartDate") ?>)\n<? endif ?>\n<? if exists("expireEndDate") ?>\n  AND (contrct_expires <= <? value("expireEndDate") ?>)\n<? endif ?>\n<? if exists("search_pattern") ?>\n  AND ( (contrct_number ~* <? value("search_pattern") ?>)\n    OR  (COALESCE(contrct_descrip,'') ~* <? value("search_pattern") ?>) )\n<? endif ?>\n)\nORDER By vend_number, contrct_number\n;\n	admin	2015-10-01	0
236	costedBOM	detail	 used by dspCostedIndentedBOM, dspCostedSingleLevelBOM, dspCostedSummarizedBOM\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: costedBOM\n-- Name: detail\n-- Notes: used by dspCostedIndentedBOM, dspCostedSingleLevelBOM, dspCostedSummarizedBOM\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT\n<? if exists("indentedBOM") ?>\n       bomdata_bomwork_id AS id,\n<? elseif exists("singleLevelBOM") ?>\n       bomdata_bomitem_id AS id,\n<? elseif exists("summarizedBOM") ?>\n       -1,\n<? endif ?>\n       \n<? if exists("indentedBOM") ?>\n       CASE WHEN bomdata_bomwork_parent_id = -1 AND bomdata_bomwork_id = -1 THEN -1\n         ELSE bomdata_item_id\n       END AS altid,\n<? elseif exists("singleLevelBOM") ?>\n       CASE WHEN (bomdata_bomitem_id = -1) THEN -1\n         ELSE bomdata_item_id\n       END AS altid,\n<? endif ?>\n       *,\n\n<? if exists("useStandardCosts") ?>\n       bomdata_stdunitcost AS unitcost,\n       bomdata_stdextendedcost AS extendedcost,\n<? elseif exists("useActualCosts") ?>\n       bomdata_actunitcost AS unitcost,\n       bomdata_actextendedcost AS extendedcost,\n<? endif ?>\n\n       'qty' AS bomdata_batchsize_xtnumericrole,\n       'qty' AS bomdata_qtyfxd_xtnumericrole,\n       'qtyper' AS bomdata_qtyper_xtnumericrole,\n       'percent' AS bomdata_scrap_xtnumericrole,\n       'qtyper' AS bomdata_qtyreq_xtnumericrole,\n       'cost' AS unitcost_xtnumericrole,\n       'cost' AS extendedcost_xtnumericrole,\n       CASE WHEN COALESCE(bomdata_effective, startOfTime()) <= startOfTime() THEN <? value("always") ?>\n         END AS bomdata_effective_qtdisplayrole,\n       CASE WHEN COALESCE(bomdata_expires, endOfTime()) <= endOfTime() THEN <? value("never") ?>\n         END AS bomdata_expires_qtdisplayrole,\n       CASE WHEN bomdata_expired THEN 'expired'\n            WHEN bomdata_future  THEN 'future'\n       END AS qtforegroundrole\n<? if exists("indentedBOM") ?>\n       , bomdata_bomwork_level - 1 AS xtindentrole\n<? elseif exists("singleLevelBOM") ?>\n       , 0 AS extendedcost_xttotalrole\n<? endif ?>\nFROM\n<? if exists("indentedBOM") ?>\n     indentedbom(<? value("item_id") ?>, <? value("revision_id") ?>, 0, 0);\n<? elseif exists("singleLevelBOM") ?>\n     singlelevelbom(<? value("item_id") ?>, <? value("revision_id") ?>, 0, 0);\n<? elseif exists("summarizedBOM") ?>\n     summarizedBOM(<? value("item_id") ?>, <? value("revision_id") ?>, <? value("expiredDays") ?>, <? value("futureDays") ?>);\n<? endif ?>\n	admin	2015-10-01	0
112	costelem	unusedbyitem	 list the cost elements that can be applied to an item that have\n        not already been applied to that item. takes an item_id and type.\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: costelem\n-- Name:  unusedbyitem\n-- Notes: list the cost elements that can be applied to an item that have\n--        not already been applied to that item. takes an item_id and type.\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("item_id") ?>\n\nSELECT costelem_id, costelem_type\nFROM costelem\nWHERE ((costelem_active)\n   AND (NOT costelem_sys\n        OR (CASE WHEN fetchMetricBool('Routings') AND\n                     (<? value("itemtype") ?> IN ('M', 'F', 'B', 'C', 'T')) THEN\n               costelem_type IN ('Direct Labor', 'Overhead', 'Machine Overhead')\n                 WHEN (<? value("itemtype") ?> IN ('O', 'P')) THEN\n                                                   costelem_type IN ('Material')\n            END))\n   AND (costelem_id NOT IN (SELECT itemcost_costelem_id\n                            FROM itemcost\n                            WHERE ((NOT itemcost_lowlevel)\n                               AND (itemcost_item_id=<? value("item_id") ?>))))\n      )\nORDER BY costelem_type;\n\n<? elseif exists("bomitem_id") ?>\n\nSELECT costelem_id, costelem_type\nFROM costelem\nWHERE ((costelem_active)\n   AND (NOT costelem_sys\n        OR (CASE WHEN fetchMetricBool('Routings') AND\n                     (<? value("itemtype") ?> IN ('M', 'F', 'B', 'C', 'T')) THEN\n               costelem_type IN ('Direct Labor', 'Overhead', 'Machine Overhead')\n                 WHEN (<? value("itemtype") ?> IN ('O', 'P')) THEN\n                                                   costelem_type IN ('Material')\n            END))\n   AND (costelem_id NOT IN (SELECT bomitemcost_costelem_id\n                            FROM bomitemcost\n                            WHERE ((NOT bomitemcost_lowlevel)\n                               AND (bomitemcost_bomitem_id=<? value("bomitem_id") ?>))))\n      )\nORDER BY costelem_type;\n\n\n<? endif ?>\n	admin	2015-10-01	0
237	countSlip	detail	 used by dspCountSlipEditList, dspCountSlipsByWarehouse\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: countSlip\n-- Name: detail\n-- Notes: used by dspCountSlipEditList, dspCountSlipsByWarehouse\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cntslip_id,\n       CASE WHEN (cntslip_posted) THEN 1\n         ELSE 0\n       END,\n       cntslip_username AS user,\n<? if exists("numericSlips") ?>\n       toNumeric(cntslip_number, 0) AS cntslip_number,\n       cntslip_number AS cntslip_number_qtdisplayrole,\n<? else ?>\n       cntslip_number,\n<? endif ?>\n       CASE WHEN (cntslip_location_id=-1) THEN ''\n         ELSE formatLocationName(cntslip_location_id)\n       END AS locname,\n       invcnt_tagnumber,\n<? if exists("byWarehouse") ?>\n       warehous_code,\n       item_number, (item_descrip1 || ' ' || item_descrip2) AS descrip,\n<? endif ?>\n       cntslip_lotserial, cntslip_posted,\n       cntslip_entered, cntslip_qty,\n       'qty' AS cntslip_qty_xtnumericrole,\n       cntslip_posted AS posted\nFROM cntslip, invcnt\n<? if exists("byWarehouse") ?>\n     JOIN itemsite ON (invcnt_itemsite_id=itemsite_id)\n     JOIN item ON (itemsite_item_id=item_id)\n     JOIN whsinfo ON (itemsite_warehous_id=warehous_id)\n<? endif ?>\nWHERE ((cntslip_cnttag_id=invcnt_id)\n<? if exists("byWarehouse") ?>\n   AND (cntslip_entered BETWEEN <? value("startDate") ?> AND  (<? value("endDate") ?>::DATE + 1))\n  <? if not exists("showUnposted") ?>\n    AND (cntslip_posted)\n  <? endif ?>\n  <? if exists("warehous_id") ?>\n    AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n<? else ?>\n    AND (NOT invcnt_posted)\n    AND (invcnt_id=<? value("cnttag_id") ?>)\n<? endif ?>\n      )\nORDER BY cntslip_number;\n	admin	2015-10-01	0
238	countTag	detail	 used by dspCountTagEditList\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: countTag\n-- Name: detail\n-- Notes: used by dspCountTagEditList\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       CASE WHEN (xtindentrole = 1) THEN NULL\n     <? if exists("varianceValue") ?>\n            WHEN (ABS(variancecost) >  <? value("varianceValue") ?>) THEN 'error'\n     <? elseif exists("variancePercent") ?>\n            WHEN (ABS(varianceprcnt * 100.0) >  <? value("variancePercent") ?>) THEN 'error'\n     <? else ?>\n            ELSE NULL\n     <? endif ?>\n       END AS qtforegroundrole,\n       CASE WHEN (xtindentrole = 1) THEN NULL\n            WHEN (qohafter IS NOT NULL) THEN 'emphasis'\n       END AS qohafter_qtforegroundrole,\n       CASE WHEN (xtindentrole = 0) THEN NULL ELSE '' END AS invcnt_priority_qtdisplayrole,\n       'qty' AS qoh_xtnumericrole,\n       'qty' AS qohafter_xtnumericrole,\n       'qty' AS variance_xtnumericrole,\n       'percent' AS varianceprcnt_xtnumericrole,\n       'curr' AS variancecost_xtnumericrole\nFROM (\n      SELECT invcnt_id, -1 AS cntslip_id, invcnt_priority,\n             COALESCE(invcnt_tagnumber, 'Misc.') AS tagnumber,\n             invcnt_tagdate AS tagdate,\n             item_number, (item_descrip1 || item_descrip2) AS item_descrip, warehous_code,\n\t     CASE WHEN (location_id IS NOT NULL) THEN\n               formatLocationName(location_id)\n               ELSE <? value("all") ?> END AS loc_specific,\n             qtyAtLocation(invcnt_itemsite_id, invcnt_location_id) AS qoh,\n      <? if exists("showSlips") ?>\n             calcTotalSlipQty(invcnt_id) AS qohafter,\n             (calcTotalSlipQty(invcnt_id) - qtyAtLocation(invcnt_itemsite_id, invcnt_location_id)) AS variance,\n             CASE WHEN (calcTotalSlipQty(invcnt_id) IS NULL) THEN NULL\n                  WHEN ((qtyAtLocation(invcnt_itemsite_id, invcnt_location_id) = 0) AND (calcTotalSlipQty(invcnt_id) > 0)) THEN 1\n                  WHEN ((qtyAtLocation(invcnt_itemsite_id, invcnt_location_id) = 0) AND (calcTotalSlipQty(invcnt_id) < 0)) THEN -1\n                  WHEN ((qtyAtLocation(invcnt_itemsite_id, invcnt_location_id) = 0) AND (calcTotalSlipQty(invcnt_id) = 0)) THEN 0\n               ELSE ((1 - (calcTotalSlipQty(invcnt_id) / qtyAtLocation(invcnt_itemsite_id, invcnt_location_id))) * -1)\n             END AS varianceprcnt,\n             (itemCost(itemsite_id) * (calcTotalSlipQty(invcnt_id) - qtyAtLocation(invcnt_itemsite_id, invcnt_location_id))) AS variancecost,\n      <? else ?>\n             COALESCE(invcnt_qoh_after, 0.0) AS qohafter,\n             (invcnt_qoh_after - qtyAtLocation(invcnt_itemsite_id, invcnt_location_id)) AS variance,\n             CASE WHEN (invcnt_qoh_after IS NULL) THEN NULL\n                  WHEN ((qtyAtLocation(invcnt_itemsite_id, invcnt_location_id) = 0) AND (invcnt_qoh_after > 0)) THEN 1\n                  WHEN ((qtyAtLocation(invcnt_itemsite_id, invcnt_location_id) = 0) AND (invcnt_qoh_after < 0)) THEN -1\n                  WHEN ((qtyAtLocation(invcnt_itemsite_id, invcnt_location_id) = 0) AND (invcnt_qoh_after = 0)) THEN 0\n               ELSE ((1 - (invcnt_qoh_after / qtyAtLocation(invcnt_itemsite_id, invcnt_location_id))) * -1)\n             END AS varianceprcnt,\n             (itemCost(itemsite_id) * (invcnt_qoh_after - qtyAtLocation(invcnt_itemsite_id, invcnt_location_id))) AS variancecost,\n      <? endif ?>\n             item_number AS orderby,\n             0 AS xtindentrole\n      FROM invcnt LEFT OUTER JOIN location ON (invcnt_location_id=location_id),\n     item, whsinfo, itemsite\n      WHERE ((invcnt_itemsite_id=itemsite_id)\n         AND (itemsite_item_id=item_id)\n         AND (itemsite_warehous_id=warehous_id)\n         AND (NOT invcnt_posted)\n      <? if exists("warehous_id") ?>\n         AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n      <? endif ?>\n      <? if exists("classcode_id") ?>\n         AND (item_classcode_id=<? value("classcode_id") ?>)\n      <? elseif exists("classcode_pattern") ?>\n         AND (item_classcode_id IN (SELECT classcode_id FROM classcode WHERE (classcode_code ~ <? value("classcode_pattern") ?>)))\n      <? elseif exists("plancode_id") ?>\n         AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n      <? elseif exists("plancode_pattern") ?>\n         AND (itemsite_plancode_id IN (SELECT plancode_id FROM plancode WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n      <? endif ?>\n      <? if exists("showSlips") ?>\n            )\n      UNION\n      SELECT invcnt_id, cntslip_id, invcnt_priority,\n             cntslip_number AS tagnumber,\n             cntslip_entered AS tagdate,\n             CASE WHEN (cntslip_posted) THEN <? value("posted") ?>\n               ELSE <? value("unposted") ?>\n             END AS item_number,\n             '' AS item_descrip,\n             '' AS warehous_code,\n             '' AS loc_specific,\n             NULL AS qoh,\n             cntslip_qty AS qohafter,\n             NULL AS variance, NULL AS varianceprcnt, 0 AS variancecost,\n             item_number AS orderby,\n             1 AS xtindentrole\n      FROM cntslip, invcnt, itemsite, item\n      WHERE ((cntslip_cnttag_id=invcnt_id)\n         AND (invcnt_itemsite_id=itemsite_id)\n         AND (itemsite_item_id=item_id)\n         AND (NOT invcnt_posted)\n       <? if exists("warehous_id") ?>\n         AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n       <? endif ?>\n       <? if exists("classcode_id") ?>\n         AND (item_classcode_id=<? value("classcode_id") ?>)\n       <? elseif exists("classcode_pattern") ?>\n         AND (item_classcode_id IN (SELECT classcode_id FROM classcode WHERE (classcode_code ~ <? value("classcode_pattern") ?>)))\n       <? elseif exists("plancode_id") ?>\n         AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n       <? elseif exists("plancode_pattern") ?>\n         AND (itemsite_plancode_id IN (SELECT plancode_id FROM plancode WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n       <? endif ?>\n       <? endif ?>\n            )\n) AS dummy\nORDER BY invcnt_priority DESC, orderby, invcnt_id, cntslip_id;\n	admin	2015-10-01	0
436	countTags	create	 used by createCountTagsByParameterList\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: countTags\n-- Name: create\n-- Notes: used by createCountTagsByParameterList\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT createCountTag(itemsite_id, <? value("comments") ?>, <? value("priority") ?>, <? value("freeze") ?>, <? value("location_id") ?>)\nFROM ( SELECT itemsite_id\n       FROM itemsite JOIN item ON (item_id=itemsite_item_id)\n<? if exists("location_id") ?>\n                     JOIN itemloc ON ( (itemloc_location_id=<? value("location_id") ?>)\n                                   AND (itemloc_itemsite_id = itemsite_id)\n                                   AND (validLocation(<? value("location_id") ?>, itemsite_id)) )\n<? endif ?>\n       WHERE (itemsite_active)\n         AND (item_active)\n<? if exists("warehous_id") ?>\n         AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("classcode_id") ?>\n         AND (item_classcode_id=<? value("classcode_id") ?>)\n<? elseif exists("classcode_pattern") ?>\n         AND (item_classcode_id IN (SELECT classcode_id\n                                    FROM classcode\n                                    WHERE (classcode_code ~ <? value("classcode_pattern") ?>)))\n<? endif ?>\n<? if exists("plancode_id") ?>\n  AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n<? elseif exists("plancode_pattern") ?>\n  AND (itemsite_plancode_id IN (SELECT plancode_id\n                                FROM plancode\n                                WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n<? endif ?>\n<? if exists("ignoreZeroBalance") ?>\n         AND (itemsite_qtyonhand <> 0.0)\n<? endif ?>\n       ORDER BY item_number ) AS data;\n	admin	2015-10-01	0
47	countTags	detail	 used by dspCountTagsByClassCode, dspCountTagsByItem, dspCountTagsByWarehouse\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: countTags\n-- Name: detail\n-- Notes: used by dspCountTagsByClassCode, dspCountTagsByItem, dspCountTagsByWarehouse\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT invcnt_id, invcnt_tagnumber, warehous_code,\n       item_number, (item_descrip1 || item_descrip2) AS item_descrip,\n       invcnt_tagdate,\n       CASE WHEN invcnt_tagdate IS NOT NULL THEN invcnt_tag_username\n       END AS creator,\n       invcnt_cntdate,\n       CASE WHEN invcnt_cntdate IS NOT NULL THEN invcnt_cnt_username\n       END AS counter,\n       invcnt_postdate,\n       CASE WHEN invcnt_postdate IS NOT NULL THEN invcnt_post_username\n       END AS poster,\n       CASE WHEN (NOT invcnt_posted) THEN NULL\n            ELSE invcnt_qoh_before\n       END AS qohbefore,\n       invcnt_qoh_after,\n       CASE WHEN (NOT invcnt_posted) THEN NULL\n            ELSE (invcnt_qoh_after - invcnt_qoh_before)\n       END AS variance,\n       CASE WHEN (NOT invcnt_posted) THEN NULL\n            WHEN ((invcnt_qoh_before = 0) AND (invcnt_qoh_after = 0)) THEN 0\n            WHEN (invcnt_qoh_before = 0) THEN 1\n            ELSE ((1 - (invcnt_qoh_after / invcnt_qoh_before)) * -1)\n       END AS percent,\n      'qty' AS qohbefore_xtnumericrole,\n      'qty' AS invcnt_qoh_after_xtnumericrole,\n      'qty' AS variance_xtnumericrole,\n      'percent' AS percent_xtnumericrole \nFROM invcnt, itemsite, item, whsinfo\nWHERE ((invcnt_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (itemsite_warehous_id=warehous_id)\n  AND  (DATE(invcnt_tagdate) BETWEEN <? value("startDate") ?>\n                                 AND <? value("endDate") ?>)\n<? if not exists("showUnposted") ?>\n  AND  invcnt_posted\n<? endif ?>\n<? if exists("warehous_id") ?>\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("classcode_id") ?>\n  AND  (item_classcode_id=<? value("classcode_id") ?>)\n<? elseif exists("classcode_pattern") ?>\n  AND  (item_classcode_id IN (SELECT classcode_id\n                             FROM classcode\n                             WHERE (classcode_code ~ <? value("classcode_pattern") ?>)))\n<? endif ?>\n<? if exists("item_id") ?>\n  AND  (item_id=<? value("item_id") ?>)\n<? endif ?>\n)\nORDER BY invcnt_tagdate;\n	admin	2015-10-01	0
48	creditCards	detail	 used by cashReceipt, customer, salesOrder\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: creditCards\n-- Name: detail\n-- Notes: used by cashReceipt, customer, salesOrder\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT ccard_id, ccard_seq,\n       CASE WHEN (ccard_type='M') THEN <? value("masterCard") ?>\n            WHEN (ccard_type='V') THEN <? value("visa") ?>\n            WHEN (ccard_type='A') THEN <? value("americanExpress") ?>\n            WHEN (ccard_type='D') THEN <? value("discover") ?>\n            ELSE <? value("other") ?>\n       END AS type,\n       formatccnumber(decrypt(setbytea(ccard_number),\n                              setbytea(<? value("key") ?>), 'bf')) AS f_number,\n       ccard_active,\n       formatbytea(decrypt(setbytea(ccard_name),\n                           setbytea(<? value("key") ?>), 'bf')) AS ccard_name,\n       formatbytea(decrypt(setbytea(ccard_month_expired),\n                           setbytea(<? value("key") ?>), 'bf')) ||\n                   '-' ||\n                   formatbytea(decrypt(setbytea(ccard_year_expired),\n                                       setbytea(<? value("key") ?>),\n                                       'bf')) AS expiration \nFROM ccard \nWHERE ((ccard_cust_id=<? value("cust_id") ?>) \n<? if exists("ccard_type") ?>\n AND   (ccard_type=<? value("ccard_type") ?>)\n<? endif ?>\n<? if exists("activeonly") ?>\n AND   (ccard_active)\n<? endif ?>\n)\nORDER BY ccard_seq;\n	admin	2015-10-01	0
243	depositesRegister	detail	 used by dspDepositsRegister\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: depositesRegister\n-- Name: detail\n-- Notes: used by dspDepositsRegister\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT trans_id, trans_date, trans_source,\n       CASE WHEN (trans_doctype='IN') THEN <? value("invoice") ?>\n            WHEN (trans_doctype='CM') THEN <? value("creditmemo") ?>\n         ELSE trans_doctype\n       END AS doctype,\n       trans_docnumber, firstLine(trans_notes) AS f_notes,\n       (formatGLAccount(accnt_id) || ' - ' || accnt_descrip) AS f_accnt,\n       CASE WHEN (trans_amount < 0) THEN formatMoney(ABS(trans_amount))\n         ELSE ''\n       END AS f_debit,\n       CASE WHEN (trans_amount < 0) THEN ABS(trans_amount)\n         ELSE 0\n       END AS debit,\n       CASE WHEN (trans_amount > 0) THEN trans_amount\n         ELSE 0\n       END AS credit,\n       (aropen_amount - aropen_paid) AS balance,\n       currtobase(aropen_curr_id,(aropen_amount - aropen_paid),aropen_docdate) AS base_balance,\n       currconcat(aropen_curr_id) AS currAbbr,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       'curr' AS balance_xtnumericrole,\n       'curr' AS base_balance_xtnumericrole,\n       0 AS debit_xttotalrole,\n       0 AS credit_xttotalrole,\n       0 AS base_balance_xttotalrole\nFROM (\nSELECT gltrans_id AS trans_id, gltrans_date AS trans_date, gltrans_created AS trans_created,\n       gltrans_source AS trans_source, gltrans_doctype AS trans_doctype, gltrans_sequence AS trans_sequence,\n       gltrans_docnumber AS trans_docnumber, gltrans_notes AS trans_notes, gltrans_amount AS trans_amount,\n       accnt_id, accnt_descrip,\n       aropen_amount, aropen_paid, aropen_curr_id, aropen_docdate\nFROM gltrans LEFT OUTER JOIN aropen ON ((text(gltrans_docnumber) = 'I-' || text(aropen_docnumber))\n                                    AND (aropen_doctype='I')), accnt\nWHERE ((gltrans_accnt_id=accnt_id)\n   AND (gltrans_doctype = 'CR')\n   AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) )\nUNION\nSELECT sltrans_id AS trans_id, sltrans_date AS trans_date, sltrans_created AS trans_created,\n       sltrans_source AS trans_source, sltrans_doctype AS trans_doctype, sltrans_sequence AS trans_sequence,\n       sltrans_docnumber AS trans_docnumber, sltrans_notes AS trans_notes, sltrans_amount AS trans_amount,\n       accnt_id, accnt_descrip,\n       aropen_amount, aropen_paid, aropen_curr_id, aropen_docdate\nFROM sltrans LEFT OUTER JOIN aropen ON ((text(sltrans_docnumber) = 'I-' || text(aropen_docnumber))\n                                    AND (aropen_doctype='I')), accnt\nWHERE ((sltrans_accnt_id=accnt_id)\n   AND (sltrans_doctype = 'CR')\n   AND (sltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) )\n     ) AS data\nORDER BY trans_created DESC, trans_sequence, trans_amount;\n	admin	2015-10-01	0
310	creditMemo	editlist	 used by creditMemoEditList\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: creditMemo\n-- Name: editlist\n-- Notes: used by creditMemoEditList\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       ('C/M-' || formatCreditMemoNumber(cmhead_id)) AS docnumber,\n       currConcat(curr_id) AS currabbr,\n       CASE WHEN seq != 0 THEN ''\n       END AS docnumber_qtdisplayrole,\n       'qty' AS qtytobill_xtnumericrole,\n       'price' AS price_xtnumericrole,\n       'curr' AS extprice_xtnumericrole,\n       CASE WHEN namedescrip = <? value("notassigned") ?> THEN 'error' END AS qtforegroundrole\nFROM (\n\nSELECT cmhead_id, -1 AS altid,\n       cmhead_number AS ordernumber,\n       cust_number AS custitemnumber,\n       cmhead_billtoname AS namedescrip,\n       CAST(NULL AS TEXT) AS uom_name,\n       CAST(NULL AS NUMERIC) AS qtytobill,\n       CAST(NULL AS NUMERIC) AS price,\n       CAST(NULL AS NUMERIC) AS extprice,\n       cmhead_curr_id AS curr_id,\n       0 AS cmitem_linenumber, 0 AS xtindentrole, 0 AS seq\nFROM cmhead JOIN custinfo ON (cmhead_cust_id=cust_id)\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold))\n\nUNION\nSELECT cmhead_id, cmitem_id,\n       NULL, item_number,\n       item_descrip1,\n       uom_name, cmitem_qtycredit * cmitem_qty_invuomratio,\n       cmitem_unitprice / cmitem_price_invuomratio,\n       cmitem_qtycredit * cmitem_qty_invuomratio * cmitem_unitprice / cmitem_price_invuomratio,\n       cmhead_curr_id AS curr_id,\n       cmitem_linenumber, 1 AS xtindentrole, 1 AS seq\nFROM cmhead, cmitem, itemsite, item, uom\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold)\n  AND  (cmhead_id=cmitem_cmhead_id)\n  AND  (cmitem_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (item_inv_uom_id=uom_id))\n\nUNION\nSELECT cmhead_id, -1,\n       NULL, <? value("debit") ?>,\n       COALESCE((SELECT formatGLAccountLong(accnt_id)\n                 FROM accnt, salesaccnt\n                 WHERE ((salesaccnt_sales_accnt_id=accnt_id)\n                    AND (salesaccnt_id=findSalesAccnt(itemsite_id, 'IS', cmhead_cust_id,\n                                                      cmhead_saletype_id, cmhead_shipzone_id)))), <? value("notassigned") ?>),\n       NULL, NULL, NULL,\n       cmitem_qtycredit * cmitem_qty_invuomratio * cmitem_unitprice / cmitem_price_invuomratio,\n       cmhead_curr_id AS curr_id,\n       cmitem_linenumber, 2 AS xtindentrole, 2 AS seq\nFROM cmhead, cmitem, itemsite, item, uom\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold)\n  AND  (cmhead_id=cmitem_cmhead_id)\n  AND  (cmitem_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (item_inv_uom_id=uom_id))\n\nUNION\nSELECT cmhead_id, -1,\n       NULL, <? value("debit") ?>,\n       CASE WHEN (accnt_id IS NULL) THEN <? value("notassigned") ?>\n            ELSE formatGLAccountLong(accnt_id)\n       END,\n       NULL, NULL, cmhead_freight,\n       cmhead_freight,\n       cmhead_curr_id AS curr_id,\n       99999, 1 AS xtindentrole, 3 AS seq\nFROM cmhead LEFT OUTER JOIN accnt ON (accnt_id=findFreightAccount(cmhead_cust_id))\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold)\n  AND  (cmhead_freight <> 0))\n\nUNION\nSELECT cmhead_id, -1,\n       NULL, <? value("debit") ?>,\n       formatGLAccountLong(cmhead_misc_accnt_id),\n       NULL, NULL, cmhead_misc,\n       cmhead_misc,\n       cmhead_curr_id AS curr_id,\n       99999, 1 AS xtindentrole, 4 AS seq\nFROM cmhead LEFT OUTER JOIN accnt ON (accnt_id=findFreightAccount(cmhead_cust_id))\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold)\n  AND  (cmhead_misc <> 0))\n\nUNION\nSELECT cmhead_id, -1,\n       NULL, <? value("debit") ?>,\n       CASE WHEN (tax_sales_accnt_id IS NULL) THEN <? value("taxes") ?>\n            ELSE formatGLAccountLong(tax_sales_accnt_id)\n       END,\n       NULL, NULL, SUM(taxhist_tax * -1.0),\n       SUM(taxhist_tax * -1.0),\n       cmhead_curr_id AS curr_id,\n       99999, 1 AS xtindentrole, 5 AS seq\nFROM cmhead JOIN cmheadtax ON ((taxhist_parent_id=cmhead_id) AND (taxhist_tax <> 0.0))\n            JOIN tax ON (tax_id=taxhist_tax_id)\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold))\nGROUP BY cmhead_id, tax_sales_accnt_id, cmhead_curr_id\n\nUNION\nSELECT cmhead_id, -1,\n       NULL, <? value("debit") ?>,\n       CASE WHEN (tax_sales_accnt_id IS NULL) THEN <? value("taxes") ?>\n            ELSE formatGLAccountLong(tax_sales_accnt_id)\n       END,\n       NULL, NULL, SUM(taxhist_tax * -1.0),\n       SUM(taxhist_tax * -1.0),\n       cmhead_curr_id AS curr_id,\n       99999, 1 AS xtindentrole, 5 AS seq\nFROM cmhead JOIN cmitem ON (cmitem_cmhead_id=cmhead_id)\n            JOIN cmitemtax ON ((taxhist_parent_id=cmitem_id) AND (taxhist_tax <> 0.0))\n            JOIN tax ON (tax_id=taxhist_tax_id)\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold))\nGROUP BY cmhead_id, tax_sales_accnt_id, cmhead_curr_id\n\nUNION\nSELECT cmhead_id, -1,\n       NULL, <? value("credit") ?>,\n       CASE WHEN (accnt_id IS NULL) THEN <? value("notassigned") ?>\n            ELSE formatGLAccountLong(accnt_id)\n       END,\n       NULL, NULL, NULL,\n       SUM((cmitem_qtycredit * cmitem_qty_invuomratio) *\n           (cmitem_unitprice / cmitem_price_invuomratio)) +\n           cmhead_freight + cmhead_misc +\n           (SELECT COALESCE(SUM(taxhist_tax * -1.0), 0.0) FROM cmheadtax WHERE (taxhist_parent_id=cmhead_id)) +\n           (SELECT COALESCE(SUM(taxhist_tax * -1.0), 0.0) FROM cmitem JOIN cmitemtax ON (taxhist_parent_id=cmitem_id)\n                                    WHERE (cmitem_cmhead_id=cmhead_id))\n            AS extprice,\n       cmhead_curr_id AS curr_id,\n       99999, 1 AS xtindentrole, 6 AS seq\nFROM cmhead LEFT OUTER JOIN cmitem ON (cmhead_id=cmitem_cmhead_id)\n            LEFT OUTER JOIN accnt ON (accnt_id=findARAccount(cmhead_cust_id))\nWHERE ((NOT cmhead_posted)\n  AND  (NOT cmhead_hold))\nGROUP BY cmhead_id, cmhead_cust_id, cmhead_freight, cmhead_misc, accnt_id, cmhead_curr_id\n\n) AS dummy\nORDER BY docnumber, cmitem_linenumber, seq;\n	admin	2015-10-01	0
49	creditMemoCreditCards	detail	 used by arWorkBench, returnAuthorization, returnAuthorizationWorkbench\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: creditMemoCreditCards\n-- Name: detail\n-- Notes: used by arWorkBench, returnAuthorization, returnAuthorizationWorkbench\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cmhead_number, cmhead_freight, cmhead_curr_id,\n       SUM(ROUND((cmitem_qtycredit * cmitem_qty_invuomratio) * \n                 (cmitem_unitprice / cmitem_price_invuomratio), 2)) +\n       cmhead_freight + cmhead_misc +\n       COALESCE( (SELECT SUM(tax) * -1 AS tax FROM\n                 (SELECT ROUND(SUM(taxdetail_tax), 2) AS tax\n                  FROM tax\n                   JOIN calculateTaxDetailSummary('CM', <? value("cmhead_id") ?>, 'T') ON (taxdetail_tax_id=tax_id)\n                  GROUP BY tax_id) AS data), 0) AS total,\n       COALESCE( (SELECT SUM(tax) * -1 AS tax FROM\n                 (SELECT ROUND(SUM(taxdetail_tax), 2) AS tax\n                  FROM tax\n                   JOIN calculateTaxDetailSummary('CM', <? value("cmhead_id") ?>, 'T') ON (taxdetail_tax_id=tax_id)\n                  GROUP BY tax_id) AS data), 0) AS tax_in_cmcurr,\n       ccard_id, ccard_seq, ccpay_id,\n       cohead_number\nFROM ccard, cmitem, cmhead LEFT OUTER JOIN\n     rahead ON (cmhead_rahead_id=rahead_id) LEFT OUTER JOIN\n     cohead ON (rahead_orig_cohead_id=cohead_id) LEFT OUTER JOIN\n     ccpay  ON (ccpay_order_number=cohead_number AND ccpay_type='C')\nWHERE ((cmitem_cmhead_id=cmhead_id)\n  AND  (cmhead_cust_id=ccard_cust_id)\n  AND  (ccard_active)\n  AND  (ccpay_ccard_id=ccard_id OR ccpay_ccard_id IS NULL)\n  AND  (cmhead_id=<? value("cmhead_id") ?>))\nGROUP BY cmhead_number, cmhead_curr_id, cmhead_freight,\n         cmhead_misc, ccard_id, ccard_seq, ccpay_id,\n\t cohead_number\nORDER BY ccpay_id DESC, ccard_seq \nLIMIT 1;\n	admin	2015-10-01	0
114	crm	strictcountrycheck	 select details about countries used throughout the database\n        that do not match country.country_name\n\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: crm\n-- Name:  strictcountrycheck\n-- Notes: select details about countries used throughout the database\n--        that do not match country.country_name\n--\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("count") ?>\nSELECT SUM(counter) AS counter FROM (\n<? endif ?>\n  SELECT <? if exists("count") ?> COUNT(*) AS counter\n         <? else ?> addr_id, 'Address' AS type, addr_number AS number, addr_country AS country, '' AS detail\n         <? endif ?>\n    FROM addr\n   WHERE addr_country != ''\n     AND addr_country NOT IN (SELECT country_name\n                                FROM country\n                               WHERE country_name IS NOT NULL)\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> cmhead_id, 'Credit Memo', cmhead_number, cmhead_billtocountry, 'Bill-To'\n         <? endif ?>\n    FROM cmhead\n   WHERE cmhead_billtocountry != ''\n     AND cmhead_billtocountry NOT IN (SELECT country_name\n                                        FROM country\n                                       WHERE country_name IS NOT NULL)\n     <? if not exists("showAll") ?> AND (NOT cmhead_posted) <? endif ?>\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> cmhead_id, 'Credit Memo', cmhead_number, cmhead_billtocountry, 'Ship-To'\n         <? endif ?>\n    FROM cmhead\n    WHERE cmhead_shipto_country != ''\n      AND cmhead_shipto_country NOT IN (SELECT country_name\n                                          FROM country\n                                         WHERE country_name IS NOT NULL)\n      <? if not exists("showAll") ?> AND (NOT cmhead_posted) <? endif ?>\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> invchead_id, 'Invoice', invchead_invcnumber, invchead_billto_country, 'Bill-To'\n         <? endif ?>\n    FROM invchead\n   WHERE invchead_billto_country != ''\n     AND invchead_billto_country NOT IN (SELECT country_name\n                                           FROM country\n                                          WHERE country_name IS NOT NULL)\n     <? if not exists("showAll") ?> AND (NOT invchead_posted) <? endif ?>\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> invchead_id, 'Invoice', invchead_invcnumber, invchead_shipto_country, 'Ship-To'\n         <? endif ?>\n    FROM invchead\n   WHERE invchead_shipto_country != ''\n     AND invchead_shipto_country NOT IN (SELECT country_name\n                                           FROM country\n                                          WHERE country_name IS NOT NULL)\n     <? if not exists("showAll") ?> AND (NOT invchead_posted) <? endif ?>\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> quhead_id, 'Quote', quhead_number, quhead_billtocountry, 'Bill-To'\n         <? endif ?>\n    FROM quhead\n   WHERE quhead_billtocountry != ''\n     AND quhead_billtocountry NOT IN (SELECT country_name\n                                        FROM country\n                                       WHERE country_name IS NOT NULL)\n     <? if not exists("showAll") ?> AND (quhead_expire>=CURRENT_DATE) <? endif ?>\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> quhead_id, 'Quote', quhead_number, quhead_shiptocountry, 'Ship-To'\n         <? endif ?>\n    FROM quhead\n   WHERE quhead_shiptocountry != ''\n     AND quhead_shiptocountry NOT IN (SELECT country_name\n                                        FROM country\n                                       WHERE country_name IS NOT NULL)\n     <? if not exists("showAll") ?> AND (quhead_expire>=CURRENT_DATE) <? endif ?>\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> cohead_id, 'Sales Order', cohead_number, cohead_billtocountry, 'Bill-To'\n         <? endif ?>\n    FROM cohead\n   WHERE cohead_billtocountry != ''\n     AND cohead_billtocountry NOT IN (SELECT country_name\n                                        FROM country\n                                       WHERE country_name IS NOT NULL)\n    <? if not exists("showAll") ?>\n     AND cohead_id IN (SELECT coitem_cohead_id\n                         FROM coitem\n                        WHERE COALESCE(coitem_status, 'O')='O')\n    <? endif ?>\n  UNION ALL\n  SELECT <? if exists("count") ?> COUNT(*)\n         <? else ?> cohead_id, 'Sales Order', cohead_number, cohead_shiptocountry, 'Ship-To'\n         <? endif ?>\n    FROM cohead\n   WHERE cohead_shiptocountry != ''\n     AND cohead_shiptocountry NOT IN (SELECT country_name\n                                       FROM country\n                                      WHERE country_name IS NOT NULL)\n    <? if not exists("showAll") ?>\n     AND cohead_id IN (SELECT coitem_cohead_id\n                         FROM coitem\n                        WHERE COALESCE(coitem_status, 'O')='O')\n    <? endif ?>\n\n<? if exists("count") ?>\n) AS dummy;\n<? endif ?>\n	admin	2015-10-01	0
447	crmaccountmerge	pickdatasources	 Show the records the user has selected to merge crm accounts. Emphasize\n        the particular fields in each record that s/he has selected.\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: crmaccountmerge\n-- Name:  pickdatasources\n-- Notes: Show the records the user has selected to merge crm accounts. Emphasize\n--        the particular fields in each record that s/he has selected.\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT c.crmacct_id,\n       crmacctsel_dest_crmacct_id,\n       c.crmacct_active,\n       formatCntctName(c.crmacct_cntct_id_1) AS primary,\n       formatCntctName(c.crmacct_cntct_id_2) AS secondary,\n       c.crmacct_competitor_id IS NOT NULL   AS competitor,\n       c.crmacct_cust_id       IS NOT NULL   AS cust,\n       c.crmacct_emp_id        IS NOT NULL   AS emp,\n       c.crmacct_name,\n       c.crmacct_number,\n       c.crmacct_owner_username              AS owner,\n       p.crmacct_number                      AS parent,\n       c.crmacct_partner_id    IS NOT NULL   AS partner,\n       c.crmacct_prospect_id   IS NOT NULL   AS prospect,\n       c.crmacct_salesrep_id   IS NOT NULL   AS salesrep,\n       c.crmacct_taxauth_id    IS NOT NULL   AS taxauth,\n       c.crmacct_type,\n       c.crmacct_usr_username  IS NOT NULL   AS usr,\n       c.crmacct_vend_id       IS NOT NULL   AS vend,\n       trim(firstline(c.crmacct_notes))      AS notes,\n\n       CASE crmacctsel_src_crmacct_id=crmacctsel_dest_crmacct_id\n            WHEN true THEN '#ccc'\n       END AS qtbackgroundrole,\n\n       CASE WHEN c.crmacct_active IS NULL THEN <? value('na') ?> END AS crmacct_active_qtdisplayrole,\n       CASE WHEN COALESCE(formatCntctName(c.crmacct_cntct_id_1), '') = '' THEN <? value('na') ?> END AS primary_qtdisplayrole,\n       CASE WHEN COALESCE(formatCntctName(c.crmacct_cntct_id_2), '') = '' THEN <? value('na') ?> END AS secondary_qtdisplayrole,\n       CASE WHEN COALESCE(c.crmacct_name,           '') = '' THEN <? value('na') ?>  END AS crmacct_name_qtdisplayrole,\n       CASE WHEN COALESCE(c.crmacct_number,         '') = '' THEN <? value('na') ?>  END AS crmacct_number_qtdisplayrole,\n       CASE WHEN COALESCE(c.crmacct_owner_username, '') = '' THEN <? value('na') ?>  END AS owner_qtdisplayrole,\n       CASE WHEN COALESCE(p.crmacct_number,         '') = '' THEN <? value('na') ?>  END AS parent_qtdisplayrole,\n       CASE c.crmacct_type WHEN 'I' THEN <? value('individual') ?>\n                           WHEN 'O' THEN <? value('organization') ?>\n                           ELSE <? value('na') ?> END AS crmacct_type_qtdisplayrole,\n       CASE WHEN COALESCE(TRIM(firstline(c.crmacct_notes)), '') = '' THEN <? value('na') ?> END AS notes_qtdisplayrole,\n\n       CASE WHEN crmacctsel_mrg_crmacct_number         THEN 'emphasis' END AS crmacct_number_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_active         THEN 'emphasis' END AS crmacct_active_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_cntct_id_1     THEN 'emphasis' END AS primary_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_cntct_id_2     THEN 'emphasis' END AS secondary_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_competitor_id  THEN 'emphasis' END AS competitor_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_cust_id        THEN 'emphasis' END AS cust_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_emp_id         THEN 'emphasis' END AS emp_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_name           THEN 'emphasis' END AS crmacct_name_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_owner_username THEN 'emphasis' END AS owner_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_parent_id      THEN 'emphasis' END AS parent_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_partner_id     THEN 'emphasis' END AS partner_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_prospect_id    THEN 'emphasis' END AS prospect_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_salesrep_id    THEN 'emphasis' END AS salesrep_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_taxauth_id     THEN 'emphasis' END AS taxauth_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_type           THEN 'emphasis' END AS crmacct_type_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_usr_username   THEN 'emphasis' END AS usr_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_vend_id        THEN 'emphasis' END AS vend_qtforegroundrole,\n       CASE WHEN crmacctsel_mrg_crmacct_notes          THEN 'emphasis' END AS notes_qtforegroundrole,\n\n       c.crmacct_cntct_id_1   AS primary_xtidrole,\n       c.crmacct_cntct_id_2   AS secondary_xtidrole,\n       c.crmacct_cust_id      AS cust_xtidrole,\n       c.crmacct_emp_id       AS emp_xtidrole,\n       c.crmacct_parent_id    AS parent_xtidrole,\n       c.crmacct_prospect_id  AS prospect_xtidrole,\n       c.crmacct_salesrep_id  AS salesrep_xtidrole,\n       c.crmacct_taxauth_id   AS taxauth_xtidrole,\n       c.crmacct_usr_username AS usr_xtidrole,\n       c.crmacct_vend_id      AS vend_xtidrole,\n\n       c.crmacct_notes AS notes_qttooltiprole\n\n  FROM crmacct c\n  JOIN crmacctsel ON (c.crmacct_id=crmacctsel_src_crmacct_id)\n  LEFT OUTER JOIN crmacct p ON (c.crmacct_parent_id=p.crmacct_id)\n WHERE crmacctsel_dest_crmacct_id=<? value('destid') ?>\n ORDER BY qtbackgroundrole DESC, c.crmacct_number;\n	admin	2015-10-01	0
448	crmaccountmerge	wip	 show an indented list of crm account merges that have\n        data to purge. this includes those that have been started\n        but not completed as well as those that have been completed\n        but neither purged nor undone.\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: crmaccountmerge\n-- Name:  wip\n-- Notes: show an indented list of crm account merges that have\n--        data to purge. this includes those that have been started\n--        but not completed as well as those that have been completed\n--        but neither purged nor undone.\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT\n       d.crmacct_id,     d.crmacct_id,\n       d.crmacct_number, d.crmacct_name,\n       d.crmacct_number AS destnumber,\n       <? value('mergedKey') ?>    AS status,\n       <? value('mergedParent') ?> AS status_qtdisplayrole,\n       0 AS xtindentrole\n  FROM crmacct d\n  JOIN mrgundo ON (d.crmacct_id=mrgundo_base_id\n               AND mrgundo_base_schema='public'\n               AND mrgundo_base_table='crmacct')\n<? if exists('destid') ?>\n WHERE d.crmacct_id = <? value("destid") ?>\n<? endif ?>\nUNION ALL\nSELECT s.crmacct_id,     d.crmacct_id,\n       s.crmacct_number, s.crmacct_name,\n       d.crmacct_number AS destnumber,\n       <? value('mergedKey') ?> AS status,\n       <? value('merged') ?>    AS status_qtdisplayrole,\n<? if exists('sourceAccountOnly') ?>\n       0\n<? else ?>\n       1\n<? endif ?>\n  FROM crmacct s\n  JOIN mrgundo ON (mrgundo_schema='public'\n               AND mrgundo_table='crmacct'\n               AND mrgundo_pkey_col='crmacct_id'\n               AND mrgundo_pkey_id=s.crmacct_id\n               AND mrgundo_col IS NULL)\n  JOIN crmacct d ON (mrgundo_base_id=d.crmacct_id\n                 AND mrgundo_base_schema='public')\n<? if exists('destid') ?>\n WHERE d.crmacct_id = <? value("destid") ?>\n<? endif ?>\nUNION\nSELECT s.crmacct_id,     d.crmacct_id,\n       s.crmacct_number, s.crmacct_name,\n       d.crmacct_number AS destnumber, \n       <? value('selectedKey') ?> AS status,\n       <? value('selected') ?>    AS status_qtdisplayrole,\n       CASE WHEN s.crmacct_id=d.crmacct_id THEN 0\n            ELSE 1\n       END\n  FROM crmacct d\n  JOIN crmacctsel ON (d.crmacct_id=crmacctsel_dest_crmacct_id)\n  JOIN crmacct s  ON (crmacctsel_src_crmacct_id=s.crmacct_id)\n<? if exists('destid') ?>\n WHERE d.crmacct_id = <? value("destid") ?>\n<? endif ?>\n\nORDER BY destnumber, xtindentrole, crmacct_number;\n	admin	2015-10-01	0
239	crmaccounts	detail	 \n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: crmaccounts\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT ON (crmacct_number)\n  crmacct_id AS id, crmacct_number, crmacct_name, crmacct_owner_username, crmacct_active,\n  cntct.*, addr.*,\n  (crmacct_cust_id       IS NOT NULL) AS cust,\n  (crmacct_prospect_id   IS NOT NULL) AS prospect,\n  (crmacct_vend_id       IS NOT NULL) AS vend,\n  (crmacct_competitor_id IS NOT NULL) AS competitor,\n  (crmacct_partner_id    IS NOT NULL) AS partner,\n  (crmacct_taxauth_id    IS NOT NULL) AS taxauth,\n  (crmacct_usr_username  IS NOT NULL) AS usr,\n  (crmacct_emp_id        IS NOT NULL) AS emp,\n  (crmacct_salesrep_id   IS NOT NULL) AS salesrep\n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\nFROM crmacct() LEFT OUTER JOIN\n  cntct ON (crmacct_cntct_id_1=cntct_id) LEFT OUTER JOIN\n  addr ON (cntct_addr_id=addr_id) \n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='CRMACCT') \n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=crmacct_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='CRMACCT') \n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=crmacct_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='CRMACCT') \n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=crmacct_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE true\n<? if exists("owner_username") ?> \n  AND (crmacct_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (crmacct_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\n<? if not exists("showInactive") ?> \n  AND crmacct_active \n<? endif ?>\n<? if exists("search_pattern") ?>\n  AND ((crmacct_number ~* <? value("search_pattern") ?>)\n       OR (crmacct_name ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_first_name,'') || ' ' || COALESCE(cntct_last_name,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_phone,'') || ' ' || COALESCE(cntct_phone2,'') || ' ' || COALESCE(cntct_fax,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_email,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_line1,'') || ' ' || COALESCE(addr_line2,'') || ' ' || COALESCE(addr_line3,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_city,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_state,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_postalcode,'') ~* <? value("search_pattern") ?>)\n       OR (addr_country ~* <? value("search_pattern") ?>))\n<? endif ?>\n<? if exists("crmacct_number_pattern") ?>\n  AND (crmacct_number ~* <? value("crmacct_number_pattern") ?>)\n<? endif ?>\n<? if exists("crmacct_name_pattern") ?>\n  AND (crmacct_name ~* <? value("crmacct_name_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_name_pattern") ?>\n  AND (COALESCE(cntct_first_name,'') || ' ' || COALESCE(cntct_last_name,'') ~* <? value("cntct_name_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_phone_pattern") ?>\n  AND (COALESCE(cntct_phone,'') || ' ' || COALESCE(cntct_phone2,'') || ' ' || COALESCE(cntct_fax,'') ~* <? value("cntct_phone_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_email_pattern") ?>\n  AND (COALESCE(cntct_email,'') ~* <? value("cntct_email_pattern") ?>)\n<? endif ?>\n<? if exists("addr_street_pattern") ?>\n  AND (COALESCE(addr_line1,'') || ' ' || COALESCE(addr_line2,'') || ' ' || COALESCE(addr_line3,'') ~* <? value("addr_street_pattern") ?>)\n<? endif ?>\n<? if exists("addr_city_pattern") ?>\n  AND (COALESCE(addr_city,'') ~* <? value("addr_city_pattern") ?>)\n<? endif ?>\n<? if exists("addr_state_pattern") ?>\n  AND (COALESCE(addr_state,'') ~* <? value("addr_state_pattern") ?>)\n<? endif ?>\n<? if exists("addr_postalcode_pattern") ?>\n  AND (COALESCE(addr_postalcode,'') ~* <? value("addr_postalcode_pattern") ?>)\n<? endif ?>\n<? if exists("addr_country_pattern") ?>\n  AND (COALESCE(addr_country,'') ~* <? value("addr_country_pattern") ?>)\n<? endif ?>\n<? if exists("id") ?>\n  AND (crmacct_id=<? value("id") ?>)\n<? endif ?>\n<? literal("charClause") ?>\n\n<? if exists("excludeMergeWIP") ?>\n  AND (crmacct_id NOT IN (SELECT mrgundo_base_id\n                            FROM mrgundo\n                           WHERE (mrgundo_base_schema='public')\n                             AND (mrgundo_base_table='crmacct')\n                          UNION\n                          SELECT crmacctsel_src_crmacct_id\n                            FROM crmacctsel\n                          UNION\n                          SELECT crmacctsel_dest_crmacct_id\n                            FROM crmacctsel))\n<? endif ?>\n<? if exists("crmacct_acct_type") ?>\n  AND CASE WHEN <? value("crmacct_acct_type") ?> = 1 THEN crmacct_cust_id IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 2 THEN crmacct_prospect_id IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 3 THEN crmacct_vend_id IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 4 THEN crmacct_competitor_id IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 5 THEN crmacct_partner_id IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 6 THEN crmacct_taxauth_id IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 7 THEN crmacct_usr_username IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 8 THEN crmacct_emp_id IS NOT NULL\n           WHEN <? value("crmacct_acct_type") ?> = 9 THEN crmacct_salesrep_id IS NOT NULL\n      END\n<? endif ?>\nORDER BY crmacct_number; 	admin	2015-10-01	0
95	currencyConversions	detail	 used by currencyConversions\n        the N in round(curr_rate, N) has to be SCALE - 1 of curr_rates\n        NUMERIC(p, SCALE) type definition\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: currencyConversions\n-- Name: detail\n-- Notes: used by currencyConversions\n--        the N in round(curr_rate, N) has to be SCALE - 1 of curr_rates\n--        NUMERIC(p, SCALE) type definition\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT curr_rate_id, currConcat(curr_id) AS f_curr,\n<? if exists("invert") ?>\n       round((1.0 / curr_rate),5) AS rate,\n<? else ?>\n       round(curr_rate,5) AS rate,\n<? endif ?>\n       'uomratio' AS rate_xtnumericrole,\n       curr_effective, curr_expires\nFROM curr_symbol NATURAL JOIN curr_rate\nWHERE ( (curr_base = FALSE)\n  AND   (curr_expires >= <? value("startDate") ?>)\n  AND   (curr_effective <= <? value("endDate") ?>)\n<? if exists("curr_id") ?>\n  AND   (curr_id = <? value("curr_id") ?>)\n<? endif ?>\n<? if exists("currConcat_pattern") ?>\n  AND   (currConcat(curr_id) ~ <? value("currConcat_pattern") ?>)\n<? endif ?>\n      )\nORDER BY f_curr, curr_effective, curr_expires;\n	admin	2015-10-01	0
242	customers	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: customers\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT ON ( cust_number ) \n  cust_id, cust_custtype_id, \n  cust_active, cust_number, cust_name,\n  custtype_code,\n  bill_cntct.cntct_first_name AS bill_first_name,\n  bill_cntct.cntct_last_name AS bill_last_name,\n  bill_cntct.cntct_title AS bill_title,\n  bill_cntct.cntct_phone AS bill_phone,\n  bill_cntct.cntct_fax AS bill_fax,\n  bill_cntct.cntct_email AS bill_email,\n  bill_addr.addr_line1 AS bill_line1,\n  bill_addr.addr_line2 AS bill_line2,\n  bill_addr.addr_line3 AS bill_line3,\n  bill_addr.addr_city AS bill_city,\n  bill_addr.addr_state AS bill_state,\n  bill_addr.addr_postalcode AS bill_postalcode,\n  bill_addr.addr_country AS bill_country,\n  corr_cntct.cntct_first_name AS corr_first_name,\n  corr_cntct.cntct_last_name AS corr_last_name,\n  corr_cntct.cntct_phone AS corr_phone,\n  corr_cntct.cntct_fax AS corr_fax,\n  corr_cntct.cntct_email AS corr_email,\n  corr_addr.addr_line1 AS corr_line1,\n  corr_addr.addr_line2 AS corr_line2,\n  corr_addr.addr_line3 AS corr_line3,\n  corr_addr.addr_city AS corr_city,\n  corr_addr.addr_state AS corr_state,\n  corr_addr.addr_postalcode AS corr_postalcode,\n  corr_addr.addr_country AS corr_country\n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\nFROM custinfo\n  JOIN custtype ON (cust_custtype_id=custtype_id)\n  LEFT OUTER JOIN cntct bill_cntct ON (cust_cntct_id=bill_cntct.cntct_id) \n  LEFT OUTER JOIN addr bill_addr ON (bill_cntct.cntct_addr_id=bill_addr.addr_id)\n  LEFT OUTER JOIN cntct corr_cntct ON (cust_corrcntct_id=corr_cntct.cntct_id) \n  LEFT OUTER JOIN addr corr_addr ON (corr_cntct.cntct_addr_id=corr_addr.addr_id)\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='C') \n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cust_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='C') \n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cust_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='C') \n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cust_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE true\n<? if not exists("showInactive") ?> \n  AND cust_active \n<? endif ?>\n<? if exists("search_pattern") ?>\n  AND ((cust_number ~* <? value("search_pattern") ?>)\n       OR (cust_name ~* <? value("search_pattern") ?>)\n       OR (custtype_code ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_cntct.cntct_first_name,'') || ' ' || COALESCE(bill_cntct.cntct_last_name,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_cntct.cntct_phone,'') || ' ' || COALESCE(bill_cntct.cntct_phone2,'') || ' ' || COALESCE(bill_cntct.cntct_fax, '') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_cntct.cntct_email, '') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_addr.addr_line1,'') || ' ' || COALESCE(bill_addr.addr_line2,'') || ' ' || COALESCE(bill_addr.addr_line3,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_addr.addr_city,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_addr.addr_state,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_addr.addr_postalcode,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(bill_addr.addr_country,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_cntct.cntct_first_name,'') || ' ' || COALESCE(corr_cntct.cntct_last_name,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_cntct.cntct_phone,'') || ' ' || COALESCE(corr_cntct.cntct_phone2,'') || ' ' || COALESCE(corr_cntct.cntct_fax, '') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_cntct.cntct_email, '') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_addr.addr_line1,'') || ' ' || COALESCE(corr_addr.addr_line2,'') || ' ' || COALESCE(corr_addr.addr_line3,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_addr.addr_city,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_addr.addr_state,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_addr.addr_postalcode,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(corr_addr.addr_country,'') ~* <? value("search_pattern") ?>))\n<? endif ?>\n<? if exists("cust_number_pattern") ?>\n  AND (cust_number ~* <? value("cust_number_pattern") ?>)\n<? endif ?>\n<? if exists("cust_name_pattern") ?>\n  AND (cust_name ~* <? value("cust_name_pattern") ?>)\n<? endif ?>\n<? if exists("custtype_code_pattern") ?>\n  AND (custtype_code ~* <? value("custtype_code_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_name_pattern") ?>\n  AND (COALESCE(bill_cntct.cntct_first_name,'') || ' ' || COALESCE(bill_cntct.cntct_last_name, '') ~* <? value("cntct_name_pattern") ?> \n   OR  COALESCE(corr_cntct.cntct_first_name,'') || ' ' || COALESCE(corr_cntct.cntct_last_name, '') ~* <? value("cntct_name_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_phone_pattern") ?>\n  AND (COALESCE(bill_cntct.cntct_phone,'') || ' ' || COALESCE(bill_cntct.cntct_phone2,'') || ' ' || COALESCE(bill_cntct.cntct_fax,'') ~* <? value("cntct_phone_pattern") ?>\n   OR  COALESCE(corr_cntct.cntct_phone,'') || ' ' || COALESCE(corr_cntct.cntct_phone2,'') || ' ' || COALESCE(corr_cntct.cntct_fax,'') ~* <? value("cntct_phone_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_email_pattern") ?>\n  AND (COALESCE(bill_cntct.cntct_email,'') ~* <? value("cntct_email_pattern") ?>\n   OR  COALESCE(corr_cntct.cntct_email,'') ~* <? value("cntct_email_pattern") ?>)\n<? endif ?>\n<? if exists("addr_street_pattern") ?>\n  AND (COALESCE(bill_addr.addr_line1,'') || ' ' || COALESCE(bill_addr.addr_line2,'') || ' ' || COALESCE(bill_addr.addr_line3,'') ~* <? value("addr_street_pattern") ?>\n   OR  COALESCE(corr_addr.addr_line1,'') || ' ' || COALESCE(corr_addr.addr_line2,'') || ' ' || COALESCE(corr_addr.addr_line3,'') ~* <? value("addr_street_pattern") ?>)\n<? endif ?>\n<? if exists("addr_city_pattern") ?>\n  AND (COALESCE(bill_addr.addr_city,'') ~* <? value("addr_city_pattern") ?>\n   OR  COALESCE(corr_addr.addr_city,'') ~* <? value("addr_city_pattern") ?>)\n<? endif ?>\n<? if exists("addr_state_pattern") ?>\n  AND (COALESCE(bill_addr.addr_state,'') ~* <? value("addr_state_pattern") ?>\n   OR  COALESCE(corr_addr.addr_state,'') ~* <? value("addr_state_pattern") ?>)\n<? endif ?>\n<? if exists("addr_postalcode_pattern") ?>\n  AND (COALESCE(bill_addr.addr_postalcode,'') ~* <? value("addr_postalcode_pattern") ?>\n   OR  COALESCE(corr_addr.addr_postalcode,'') ~* <? value("addr_postalcode_pattern") ?>)\n<? endif ?>\n<? if exists("addr_country_pattern") ?>\n  AND (COALESCE(bill_addr.addr_country,'') ~* <? value("addr_country_pattern") ?>\n   OR  COALESCE(corr_addr.addr_country,'') ~* <? value("addr_country_pattern") ?>)\n<? endif ?>\n<? if exists("salesrep_id") ?>\n  AND (cust_salesrep_id = <? value("salesrep_id") ?>)\n<? endif ?>\n<? literal("charClause") ?>\nORDER BY cust_number; \n	admin	2015-10-01	0
439	customers	statement	 used by printStatementsByCustomerType\nSELECT cust_id, (cust_number || '-' || cust_name) AS customer,\n       findCustomerForm(cust_id, 'S') AS reportname\nFROM\n<? if exists("asofDate") ?>\n  (SELECT araging_cust_id FROM araging(<? value ("asofDate") ?>, true))AS data,\n<? endif ?>\n  custinfo, custtype, aropen\nWHERE (cust_custtype_id=custtype_id)\n AND (aropen_cust_id=cust_id)\n AND (aropen_open)\n<? if exists("graceDays") ?>\n AND (aropen_duedate < (CURRENT_DATE - <? value ("graceDays") ?>))\n<? endif ?>\n<? if exists("custtype_id") ?>\n AND (custtype_id=<? value ("custtype_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n AND (custtype_code ~ <? value ("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("asofDate") ?>\n AND (cust_id = araging_cust_id)\n<? endif ?>\nGROUP BY cust_id, cust_number, cust_name\nHAVING (SUM((aropen_amount - aropen_paid) *\n             CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1\n                  ELSE 1 END) > 0)\nORDER BY cust_number;\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: customers\n-- Name:  statement\n-- Notes: used by printStatementsByCustomerType\n--SELECT cust_id, (cust_number || '-' || cust_name) AS customer,\n--       findCustomerForm(cust_id, 'S') AS reportname\n--FROM\n--<? if exists("asofDate") ?>\n--  (SELECT araging_cust_id FROM araging(<? value ("asofDate") ?>, true))AS data,\n--<? endif ?>\n--  custinfo, custtype, aropen\n--WHERE (cust_custtype_id=custtype_id)\n-- AND (aropen_cust_id=cust_id)\n-- AND (aropen_open)\n--<? if exists("graceDays") ?>\n-- AND (aropen_duedate < (CURRENT_DATE - <? value ("graceDays") ?>))\n--<? endif ?>\n--<? if exists("custtype_id") ?>\n-- AND (custtype_id=<? value ("custtype_id") ?>)\n--<? elseif exists("custtype_pattern") ?>\n-- AND (custtype_code ~ <? value ("custtype_pattern") ?>)\n--<? endif ?>\n--<? if exists("asofDate") ?>\n-- AND (cust_id = araging_cust_id)\n--<? endif ?>\n--GROUP BY cust_id, cust_number, cust_name\n--HAVING (SUM((aropen_amount - aropen_paid) *\n--             CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1\n--                  ELSE 1 END) > 0)\n--ORDER BY cust_number;\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT araging_cust_id AS cust_id,\n       (araging_cust_number || '-' || araging_cust_name) AS customer,\n       findCustomerForm(araging_cust_id, 'S') AS reportname\nFROM araging(<? value ("asofDate") ?>, true)\nWHERE (true)\n<? if exists("graceDays") ?>\n AND (COALESCE(araging_duedate, startOfTime()) < (CURRENT_DATE - <? value ("graceDays") ?>))\n<? endif ?>\n<? if exists("custtype_id") ?>\n AND (araging_cust_custtype_id=<? value ("custtype_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n AND (araging_custtype_code ~ <? value ("custtype_pattern") ?>)\n<? endif ?>\nGROUP BY araging_cust_id, araging_cust_number, araging_cust_name\nORDER BY araging_cust_number;\n	admin	2015-10-01	0
244	detailedInventoryHistory	detail	 used by dspDetailedInventoryHistoryByLocation, dspDetailedInventoryHistoryByLotSerial\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: detailedInventoryHistory\n-- Name: detail\n-- Notes: used by dspDetailedInventoryHistoryByLocation, dspDetailedInventoryHistoryByLotSerial\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT\n<? if exists("byLocation") ?>\n       invhist_id, invhist_transdate, invhist_transtype,\n       (invhist_ordtype || '-' || invhist_ordnumber) AS ordernumber,\n       invhist_invuom,\n       item_number, formatlotserialnumber(invdetail_ls_id) AS lotserial,\n       CASE WHEN invhist_posted THEN invdetail_qty\n       END AS transqty,\n       CASE WHEN invhist_posted THEN invdetail_qty_before\n       END AS qohbefore,\n       CASE WHEN invhist_posted THEN invdetail_qty_after\n       END AS qohafter,\n       invhist_posted,\n       'qty' AS transqty_xtnumericrole,\n       'qty' AS qohbefore_xtnumericrole,\n       'qty' AS qohafter_xtnumericrole,\n       CASE WHEN NOT invhist_posted THEN 'warning'\n       END AS qtforegroundrole\n<? else ?>\n       *\n<? endif ?>\nFROM <? if exists("byLocation") ?>\n       invdetail, invhist, itemsite, item\n     <? else ?>\n       lshist (<? value("itemid") ?>,<? value("warehouseid") ?>,<? value("lotSerial") ?>,\n               <? value("pattern") ?>,<? value("transType") ?>,<? value("startDate") ?>,\n               <? value("endDate") ?>,<? value("trace") ?>,1)\n     <? endif ?>\nWHERE (\n<? if exists("byLocation") ?>\n        (invdetail_invhist_id=invhist_id)\n    AND (invhist_itemsite_id=itemsite_id)\n    AND (itemsite_item_id=item_id)\n    AND (invdetail_location_id=<? value("location_id") ?>)\n    AND (DATE(invhist_transdate) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    AND (transType(invhist_transtype, <? value("transType") ?>))\n<? else ?>\n        (TRUE)\n<? endif ?>\n      )\n<? if exists("byLocation") ?>\nORDER BY invhist_transdate DESC, invhist_transtype\n<? endif ?>\n;\n	admin	2015-10-01	0
118	distributeInventory	locations	 \n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: distributeInventory\n-- Name: locations\n-- Notes: \n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT id, type, locationname, defaultlocation,\n           location_netable, location_usable, lotserial, f_expiration, expired,\n           qty, qtytagged, (qty + qtytagged) AS balance,\n           'qty' AS qty_xtnumericrole,\n           'qty' AS qtytagged_xtnumericrole,\n           'qty' AS balance_xtnumericrole,\n           CASE WHEN expired THEN 'error' END AS qtforegroundrole, \n           CASE WHEN defaultlocation AND expired = false THEN 'altemphasis' \n                WHEN expired THEN 'error' \n                ELSE null END AS defaultlocation_qtforegroundrole, \n           CASE WHEN expired THEN 'error' \n                WHEN qty > 0 AND expired = false THEN 'altemphasis' \n                ELSE null END AS qty_qtforegroundrole \nFROM ( \n  <? if exists("cNoIncludeLotSerial") ?>\n    SELECT location_id AS id, <? value("locationType") ?> AS type,\n           formatLocationName(location_id) AS locationname, location_whsezone_id,\n           CASE WHEN (<? value("transtype") ?> = 'R' AND location_id=itemsite_recvlocation_id) THEN TRUE\n                WHEN (<? value("transtype") ?> = 'I' AND location_id=itemsite_issuelocation_id) THEN TRUE\n                WHEN (<? value("transtype") ?> = 'O' AND location_id=itemsite_location_id) THEN TRUE\n                ELSE FALSE\n           END AS defaultlocation,\n           COALESCE(location_netable, true) AS location_netable,\n           COALESCE(location_usable, true) AS location_usable,\n           TEXT('') AS lotserial,\n           TEXT(<? value("na") ?>) AS f_expiration, FALSE AS expired,\n           qtyLocation(location_id, NULL, NULL, NULL,\n                       itemsite_id, itemlocdist_order_type, itemlocdist_order_id, itemlocdist_id) AS qty,\n           itemlocdistQty(location_id, itemlocdist_id) AS qtytagged \n    FROM itemlocdist, location, itemsite \n    WHERE ( (itemlocdist_itemsite_id=itemsite_id)\n      AND (itemsite_loccntrl)\n      AND (itemsite_warehous_id=location_warehous_id)\n      AND (validLocation(location_id, itemsite_id))\n      AND (itemlocdist_id=<? value("itemlocdist_id") ?>) ) \n  <? elseif exists("cIncludeLotSerial") ?>\n    SELECT itemloc_id AS id, <? value("itemlocType") ?> AS type,\n           COALESCE(formatLocationName(location_id), \n           <? value("undefined") ?>) AS locationname, location_whsezone_id,\n           (location_id IS NOT NULL AND\n             CASE WHEN (<? value("transtype") ?> = 'R' AND location_id=itemsite_recvlocation_id) THEN TRUE\n                  WHEN (<? value("transtype") ?> = 'I' AND location_id=itemsite_issuelocation_id) THEN TRUE\n                  WHEN (<? value("transtype") ?> = 'O' AND location_id=itemsite_location_id) THEN TRUE\n                  ELSE FALSE\n             END) AS defaultlocation,\n           COALESCE(location_netable, true) AS location_netable,\n           COALESCE(location_usable, true) AS location_usable,\n           ls_number AS lotserial,\n           CASE WHEN (itemsite_perishable) THEN formatDate(itemloc_expiration)\n                ELSE <? value("na") ?>\n           END AS f_expiration,\n           CASE WHEN (itemsite_perishable) THEN (itemloc_expiration < CURRENT_DATE)\n                ELSE FALSE \n           END AS expired,\n           qtyLocation(itemloc_location_id, itemloc_ls_id, itemloc_expiration,\n                       itemloc_warrpurc, itemsite_id, itemlocdist_order_type,\n                       itemlocdist_order_id, itemlocdist_id) AS qty,\n           ( SELECT COALESCE(SUM(target.itemlocdist_qty), 0)\n             FROM itemlocdist AS target\n             WHERE ( (target.itemlocdist_source_type='I')\n               AND (target.itemlocdist_source_id=itemloc_id)\n               AND (target.itemlocdist_itemlocdist_id=source.itemlocdist_id)) ) AS qtytagged \n    FROM itemlocdist AS source, itemsite, itemloc \n         LEFT OUTER JOIN location ON (itemloc_location_id=location_id) \n         LEFT OUTER JOIN ls ON (itemloc_ls_id=ls_id) \n   WHERE ( (source.itemlocdist_itemsite_id=itemsite_id)\n     AND (itemloc_itemsite_id=itemsite_id)\n     AND (source.itemlocdist_id=<? value("itemlocdist_id") ?>) ) \n    UNION \n    SELECT location_id AS id, <? value("locationType") ?> AS type,\n           formatLocationName(location_id) AS locationname,  location_whsezone_id,\n           CASE WHEN (<? value("transtype") ?> = 'R' AND location_id=itemsite_recvlocation_id) THEN TRUE\n                WHEN (<? value("transtype") ?> = 'I' AND location_id=itemsite_issuelocation_id) THEN TRUE\n                WHEN (<? value("transtype") ?> = 'O' AND location_id=itemsite_location_id) THEN TRUE\n                ELSE FALSE\n           END AS defaultlocation,\n           COALESCE(location_netable, true) AS location_netable,\n           COALESCE(location_usable, true) AS location_usable,\n           TEXT('') AS lotserial,\n           TEXT(<? value("na") ?>) AS f_expiration, FALSE AS expired,\n           qtyLocation(location_id, NULL, NULL, NULL,\n                       itemsite_id, itemlocdist_order_type, itemlocdist_order_id, itemlocdist_id) AS qty,\n           itemlocdistQty(location_id, itemlocdist_id) AS qtytagged \n    FROM itemlocdist, location, itemsite \n    WHERE ( (itemlocdist_itemsite_id=itemsite_id)\n      AND (itemsite_loccntrl)\n      AND (itemsite_warehous_id=location_warehous_id)\n      AND (validLocation(location_id, itemsite_id))\n      AND (itemsite_id=<? value("itemsite_id") ?> ) \n      AND (location_id NOT IN (SELECT DISTINCT itemloc_location_id\n                               FROM itemloc\n                               WHERE (itemloc_itemsite_id=itemsite_id)))\n      AND (itemlocdist_id=<? value("itemlocdist_id") ?>) ) \n  <? endif ?>\n  ) AS data \nWHERE ((TRUE) \n   AND ( (<? value("transtype") ?> != 'I') OR (<? value("transtype") ?> = 'I' AND location_usable) )\n<? if exists("showOnlyTagged") ?>\n  AND (qtytagged != 0) \n<? endif ?>\n<? if exists("showQtyOnly") ?>\n  AND (qty > 0) \n<? endif ?>\n<? if exists("zone") ?>\n  AND (location_whsezone_id = <? value("zone") ?>)\n<? endif ?>\n) ORDER BY locationname;\n	admin	2015-10-01	0
465	employees	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: employees\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT emp_id, warehous_code, emp_active, emp_code, emp_number,\n  cntct_first_name, cntct_last_name\n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\nFROM emp\n  LEFT OUTER JOIN cntct ON (emp_cntct_id=cntct_id)\n  LEFT OUTER JOIN whsinfo ON (emp_warehous_id=warehous_id)\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='EMP') \n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=emp_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='EMP') \n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=emp_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='EMP') \n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=emp_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE (true)\n<? if exists("warehous_id") ?>\n  AND (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("activeOnly") ?> \n  AND emp_active \n<? endif ?>\n<? if exists("search_pattern") ?>\n  AND ((emp_code ~* <? value("search_pattern") ?>)\n       OR (emp_number ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_first_name,'') || ' ' || COALESCE(cntct_last_name,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_phone,'') || ' ' || COALESCE(cntct_phone2,'') || ' ' || COALESCE(cntct_fax,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_email,'') ~* <? value("search_pattern") ?>))\n<? endif ?>\n<? literal("charClause") ?>\nORDER BY emp_code;\n	admin	2015-10-01	0
50	events	detail	 used by eventManager\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: events\n-- Name: detail\n-- Notes: used by eventManager\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT evntlog_id, evntlog_ord_id, evntlog_newdate,\n       evntlog_newvalue, warehous_code,\n       evntlog_evnttime,\n       evntlog_dispatched,\n       evnttype_name, evntlog_number \n  FROM evnttype, evntlog LEFT OUTER JOIN whsinfo ON (evntlog_warehous_id=warehous_id)\nWHERE ( (evntlog_evnttype_id=evnttype_id)\n AND (evntlog_username=<? value("username") ?>)\n<? if exists("warehous_id") ?>\n AND (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if not exists("showAcknowledged") ?>\n AND (evntlog_dispatched IS NULL)\n<? endif ?>\n) \nORDER BY evntlog_evnttime;\n	admin	2015-10-01	0
245	expiredInventory	detail	 used by dspExpiredInventoryByClassCode\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: expiredInventory\n-- Name: detail\n-- Notes: used by dspExpiredInventoryByClassCode\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id, itemloc_id, warehous_code, item_number, uom_name,\n       ls_number, itemloc_expiration,\n       itemloc_qty, costmethod, cost,\n       noNeg(cost * itemloc_qty) AS value,\n       'qty' AS itemloc_qty_xtnumericrole,\n       'cost' AS cost_xtnumericrole,\n       'curr' AS value_xtnumericrole,\n       'red' AS qtforegroundrole \nFROM ( SELECT itemsite_id, itemloc_id, warehous_code, item_number,\n              uom_name, ls_number,\n              CASE WHEN <? value("expiretype") ?>='Perishability' THEN \n                   itemloc_expiration\n                ELSE itemloc_warrpurc\n              END AS itemloc_expiration,\n              itemloc_qty,\n              CASE WHEN(itemsite_costmethod='A') THEN 'Average'\n                   WHEN(itemsite_costmethod='S') THEN 'Standard'\n                   WHEN(itemsite_costmethod='J') THEN 'Job'\n                   WHEN(itemsite_costmethod='N') THEN 'None'\n                ELSE 'UNKNOWN'\n              END AS costmethod,\n            <? if exists("useStandardCosts") ?>\n              stdcost(itemsite_item_id) AS cost\n            <? elseif exists("useActualCosts") ?>\n              actcost(itemsite_item_id) AS cost\n            <? else ?>\n              (itemsite_value / CASE WHEN(itemsite_qtyonhand=0) THEN 1 ELSE itemsite_qtyonhand END) AS cost\n            <? endif ?>\n       FROM itemloc, itemsite, item, whsinfo, uom, ls\n       WHERE ((itemloc_itemsite_id=itemsite_id)\n          AND (itemsite_item_id=item_id)\n          AND (item_inv_uom_id=uom_id)\n          AND (itemsite_warehous_id=warehous_id)\n          AND (itemloc_ls_id=ls_id)\n        <? if exists("perishability") ?>\n          AND (itemsite_perishable)\n          AND (itemloc_expiration < (CURRENT_DATE + <? value("thresholdDays") ?>))\n        <? else ?>\n          AND (itemsite_warrpurc)\n          AND (itemloc_warrpurc < (CURRENT_DATE + <? value("thresholdDays") ?>))\n        <? endif ?>\n        <? if exists("warehous_id") ?>\n          AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n        <? endif ?>\n        <? if exists("classcode_id") ?>\n          AND (item_classcode_id=<? value("classcode_id") ?>)\n        <? elseif exists("classcode_pattern") ?>\n          AND (item_classcode_id IN (SELECT classcode_id\n                                     FROM classcode\n                                     WHERE classcode_code ~ <? value("classcode_pattern") ?>))\n        <? endif ?>\n             )\n     ) AS data\nORDER BY warehous_code, item_number;\n	admin	2015-10-01	0
246	freightPrices	detail	 used by dspFreightPricesByCustomer, dspFreightPricesByCustomerType\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: freightPrices\n-- Name: detail\n-- Notes: used by dspFreightPricesByCustomer, dspFreightPricesByCustomerType\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemid, sourcetype, ipshead_name, source, ipsfreight_qtybreak, ipsfreight_price,\n       CASE WHEN (ipsfreight_type = 'F') THEN <? value("flatrate") ?>\n         ELSE <? value("peruom") ?>\n       END AS method,\n       currConcat(ipshead_curr_id) AS currConcat,\n       warehous_code, shipzone_name, freightclass_code, ipsfreight_shipvia,\n       'qty' AS ipsfreight_qtybreak_xtnumericrole,\n       <? value("na") ?> AS ipsfreight_qtybreak_xtnullrole,\n       'salesprice' AS ipsfreight_price_xtnumericrole,\n       <? value("any") ?> AS warehous_code_xtnullrole,\n       <? value("any") ?> AS shipzone_name_xtnullrole,\n       <? value("any") ?> AS freightclass_code_xtnullrole,\n       <? value("any") ?> AS ipsfreight_shipvia_xtnullrole\nFROM (SELECT ipsfreight_id AS itemid, 1 AS sourcetype,\n             ipshead_name,\n<? if exists("byCust") ?>\n             <? value("customer") ?> AS source,\n<? elseif exists("byCustType") ?>\n             <? value("custType") ?> AS source,\n<? endif ?>\n             ipsfreight_qtybreak, ipsfreight_price,\n             ipsfreight_type, ipshead_curr_id,\n             warehous_code, shipzone_name, freightclass_code, ipsfreight_shipvia\n      FROM ipsass JOIN ipshead ON (ipshead_id=ipsass_ipshead_id)\n           JOIN ipsfreight ON (ipsfreight_ipshead_id=ipshead_id)\n           LEFT OUTER JOIN whsinfo ON (warehous_id=ipsfreight_warehous_id)\n           LEFT OUTER JOIN shipzone ON (shipzone_id=ipsfreight_shipzone_id)\n           LEFT OUTER JOIN freightclass ON (freightclass_id=ipsfreight_freightclass_id)\n      WHERE ((true)\n<? if exists("byCust") ?>\n         AND (ipsass_cust_id=<? value("cust_id") ?>)\n         AND (COALESCE(LENGTH(ipsass_shipto_pattern), 0) = 0)\n<? elseif exists("byCustType") ?>\n         AND (ipsass_custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n<? endif ?>\n<? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n<? endif ?>\n            )\n\n      UNION\n\n      SELECT ipsfreight_id AS itemid, 2 AS sourcetype,\n             ipshead_name,\n<? if exists("byCust") ?>\n             <? value("custType") ?> AS source,\n<? elseif exists("byCustType") ?>\n             <? value("custTypePattern") ?> AS source,\n<? endif ?>\n             ipsfreight_qtybreak, ipsfreight_price,\n             ipsfreight_type, ipshead_curr_id,\n             warehous_code, shipzone_name, freightclass_code, ipsfreight_shipvia\n      FROM ipsass\n<? if exists("byCustType") ?>\n           JOIN custtype ON ((coalesce(length(ipsass_custtype_pattern), 0) > 0) AND\n                                         (custtype_code ~ ipsass_custtype_pattern))\n<? endif ?>\n           JOIN ipshead ON (ipshead_id=ipsass_ipshead_id)\n           JOIN ipsfreight ON (ipsfreight_ipshead_id=ipshead_id)\n<? if exists("byCust") ?>\n           JOIN custinfo ON (cust_custtype_id=ipsass_custtype_id)\n<? endif ?>\n           LEFT OUTER JOIN whsinfo ON (warehous_id=ipsfreight_warehous_id)\n           LEFT OUTER JOIN shipzone ON (shipzone_id=ipsfreight_shipzone_id)\n           LEFT OUTER JOIN freightclass ON (freightclass_id=ipsfreight_freightclass_id)\n      WHERE ((true)\n<? if exists("byCust") ?>\n         AND (cust_id=<? value("cust_id") ?>)\n<? elseif exists("byCustType") ?>\n         AND (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n<? endif ?>\n<? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n<? endif ?>\n            )\n\n      UNION\n\n      SELECT ipsfreight_id AS itemid, 3 AS sourcetype,\n             ipshead_name,\n<? if exists("byCust") ?>\n             <? value("custTypePattern") ?> AS source,\n<? elseif exists("byCustType") ?>\n             (<? value("sale") ?> || '-' || sale_name) AS source,\n<? endif ?>\n             ipsfreight_qtybreak, ipsfreight_price,\n             ipsfreight_type, ipshead_curr_id,\n             warehous_code, shipzone_name, freightclass_code, ipsfreight_shipvia\n      FROM\n<? if exists("byCust") ?>\n           custinfo JOIN custtype ON (custtype_id=cust_custtype_id)\n                JOIN ipsass ON ((coalesce(length(ipsass_custtype_pattern), 0) > 0) AND\n                                (custtype_code ~ ipsass_custtype_pattern))\n                JOIN ipshead ON (ipshead_id=ipsass_ipshead_id)\n<? elseif exists("byCustType") ?>\n           sale JOIN ipshead ON (ipshead_id=sale_ipshead_id)\n<? endif ?>\n                JOIN ipsfreight ON (ipsfreight_ipshead_id=ipshead_id)\n                LEFT OUTER JOIN whsinfo ON (warehous_id=ipsfreight_warehous_id)\n                LEFT OUTER JOIN shipzone ON (shipzone_id=ipsfreight_shipzone_id)\n                LEFT OUTER JOIN freightclass ON (freightclass_id=ipsfreight_freightclass_id)\n      WHERE ((true)\n<? if exists("byCust") ?>\n         AND (cust_id=<? value("cust_id") ?>)\n<? elseif exists("byCustType") ?>\n         AND (true)\n<? endif ?>\n<? if not exists("showExpired") ?>\n  <? if exists("byCust") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n  <? elseif exists("byCustType") ?>\n         AND (sale_enddate > CURRENT_DATE)\n  <? endif ?>\n<? endif ?>\n<? if not exists("showFuture") ?>\n  <? if exists("byCust") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n  <? elseif exists("byCustType") ?>\n         AND (sale_startdate <= CURRENT_DATE)\n  <? endif ?>\n<? endif ?>\n            )\n\n<? if exists("byCust") ?>\n      UNION\n\n      SELECT ipsfreight_id AS itemid, 4 AS sourcetype,\n             ipshead_name, (<? value("sale") ?> || '-' || sale_name) AS source,\n             ipsfreight_qtybreak, ipsfreight_price,\n             ipsfreight_type, ipshead_curr_id,\n             warehous_code, shipzone_name, freightclass_code, ipsfreight_shipvia\n      FROM sale JOIN ipshead ON (ipshead_id=sale_ipshead_id)\n                JOIN ipsfreight ON (ipsfreight_ipshead_id=ipshead_id)\n                LEFT OUTER JOIN whsinfo ON (warehous_id=ipsfreight_warehous_id)\n                LEFT OUTER JOIN shipzone ON (shipzone_id=ipsfreight_shipzone_id)\n                LEFT OUTER JOIN freightclass ON (freightclass_id=ipsfreight_freightclass_id)\n      WHERE ((true)\n  <? if not exists("showExpired") ?>\n         AND (sale_enddate > CURRENT_DATE)\n  <? endif ?>\n  <? if not exists("showFuture") ?>\n         AND (sale_startdate <= CURRENT_DATE)\n  <? endif ?>\n            )\n<? endif ?>\n     ) AS data\nORDER BY ipsfreight_qtybreak, ipsfreight_price;\n	admin	2015-10-01	0
247	frozenItemSites	detail	 used by dspFrozenItemSites\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: frozenItemSites\n-- Name: detail\n-- Notes: used by dspFrozenItemSites\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id, warehous_code, item_number,\n        (item_descrip1 || ' ' || item_descrip2) AS descrip,\n        COALESCE((SELECT invcnt_tagnumber\n                  FROM invcnt\n                  WHERE ((NOT invcnt_posted)\n                          AND (invcnt_itemsite_id=itemsite_id)) LIMIT 1), '') AS cnttag\nFROM itemsite, item, whsinfo\nWHERE ( (itemsite_item_id=item_id)\n    AND (itemsite_warehous_id=warehous_id)\n    AND (itemsite_freeze)\n<? if exists("warehous_id") ?>\n    AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n      )\nORDER BY warehous_code, item_number;\n	admin	2015-10-01	0
249	glseries	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: glseries\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *, \n                          CASE WHEN <? literal("table") ?>_id = -1 THEN 0\n                          ELSE 1 END AS xtindentrole,\n                          CASE WHEN <? literal("table") ?>_id = -1 THEN <? literal("table") ?>_date\n                          END AS transdate,   \n                          'curr' AS debit_xtnumericrole,\n                          'curr' AS credit_xtnumericrole \n                   FROM (SELECT DISTINCT \n                          <? literal("table") ?>_sequence AS sequence, \n                          -1 AS <? literal("table") ?>_id, \n                          <? literal("table") ?>_date, \n                          <? literal("table") ?>_source AS source, \n                          <? literal("table") ?>_journalnumber AS journalnumber,\n                          <? literal("table") ?>_doctype AS doctype, '' AS docnumber,\n                          -1 AS accnt_id, firstLine(<? literal("table") ?>_notes) AS accnt_id_qtdisplayrole,\n                          0.0 AS amount,\n                          CAST(NULL AS NUMERIC) AS debit,\n                          CAST(NULL AS NUMERIC) AS credit,\n                          <? literal("table") ?>_posted AS posted \n                   FROM <? literal("table") ?> \n                   WHERE ( (true) \n                   <? if exists("gltrans") ?>\n                    AND (NOT gltrans_deleted) \n                   <? endif ?>\n                    AND (<? literal("table") ?>_date BETWEEN <? value("startDate") ?>\n                                            AND <? value("endDate") ?>)\n                   <? if exists("source") ?>\n                      AND (<? literal("table") ?>_source=<? value("source") ?>)\n                   <? endif ?>\n                   <? if exists("startJrnlnum") ?>\n                      AND (<? literal("table") ?>_journalnumber BETWEEN <? value("startJrnlnum") ?>\n                                                     AND <? value("endJrnlnum") ?>)\n                   <? endif ?>\n                   ) \n                   UNION ALL \n                   SELECT <? literal("table") ?>_sequence AS sequence, \n                          <? literal("table") ?>_id, \n                          <? literal("table") ?>_date, \n                          NULL, NULL,\n                          NULL, <? literal("table") ?>_docnumber AS docnumber,\n                          accnt_id, (formatGLAccount(accnt_id) || ' - ' || accnt_descrip) AS accnt_id_qtdisplayrole,\n                          <? literal("table") ?>_amount,\n                          CASE WHEN (<? literal("table") ?>_amount < 0) THEN (<? literal("table") ?>_amount * -1)\n                          END AS debit,\n                          CASE WHEN (<? literal("table") ?>_amount > 0) THEN <? literal("table") ?>_amount \n                          END AS credit,\n                          NULL AS posted \n                   FROM <? literal("table") ?> JOIN accnt ON (<? literal("table") ?>_accnt_id=accnt_id) \n                   WHERE ( (true) \n                   <? if exists("gltrans") ?>\n                    AND (NOT gltrans_deleted) \n                   <? endif ?>\n                     AND (<? literal("table") ?>_date BETWEEN <? value("startDate") ?>\n                                            AND <? value("endDate") ?>)\n                   <? if exists("source") ?>\n                      AND (<? literal("table") ?>_source=<? value("source") ?>)\n                   <? endif ?>\n                   <? if exists("startJrnlnum") ?>\n                      AND (<? literal("table") ?>_journalnumber BETWEEN <? value("startJrnlnum") ?>\n                                                     AND <? value("endJrnlnum") ?>)\n                   <? endif ?>\n                    ) \n                   ) AS dummy \n                   ORDER BY sequence,\n                            xtindentrole, amount;\n	admin	2015-10-01	0
133	gltransactions	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: gltransactions\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT gltrans_id, gltrans_accnt_id,gltrans_date,gltrans_created,gltrans_source,\n       gltrans_doctype,gltrans_journalnumber,gltrans_posted,gltrans_username,\n       CASE WHEN(gltrans_docnumber='Misc.' AND\n              invhist_docnumber IS NOT NULL) THEN\n              (gltrans_docnumber || ' - ' || invhist_docnumber)\n            ELSE gltrans_docnumber\n       END AS docnumber,\n       firstLine(gltrans_notes) AS notes,\n       (formatGLAccount(accnt_id) || ' - ' || accnt_descrip) AS account,\n       CASE WHEN (gltrans_amount < 0) THEN ABS(gltrans_amount)\n            ELSE NULL\n       END AS debit,\n       CASE WHEN (gltrans_amount > 0) THEN gltrans_amount\n            ELSE NULL\n       END AS credit,\n       CASE WHEN accnt_type IN ('A','E') THEN \n         gltrans_amount * -1 \n       ELSE gltrans_amount END AS running,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       'curr' AS running_xtnumericrole,\n       0 AS running_xtrunningrole,\n       gltrans_deleted AS xtdeletedrole,\n<? value("beginningBalance") ?> AS running_xtrunninginit \nFROM gltrans JOIN accnt ON (gltrans_accnt_id=accnt_id) \n     LEFT OUTER JOIN invhist ON (gltrans_misc_id=invhist_id\n                            AND gltrans_docnumber='Misc.') \n<? if exists("company_id") ?>\n     JOIN company ON (accnt_company=company_number) \n<? endif ?>\n<? if exists("prfcntr_id") ?>\n     JOIN prftcntr ON (accnt_profit=prftcntr_number) \n<? endif ?>\n<? if exists("subaccnt_id") ?>\n     JOIN subaccnt ON (accnt_sub=subaccnt_number) \n<? endif ?>\n<? if exists("subType") ?>\n     JOIN subaccnttype ON (subaccnttype_code=accnt_subaccnttype_code) \n<? endif ?>\nWHERE (\n<? if exists("startDate") ?>\n  <? if exists("endDate") ?>\n       (gltrans_date BETWEEN <? value("startDate") ?>\n                         AND <? value("endDate") ?>)\n  <? else ?>\n       (gltrans_date BETWEEN <? value("startDate") ?>\n                         AND endoftime())\n  <? endif ?>\n<? else ?>\n  <? if exists("endDate") ?>\n       (gltrans_date BETWEEN startoftime()\n                         AND <? value("endDate") ?>)\n  <? else ?>\n       (gltrans_date BETWEEN startoftime()\n                         AND endoftime())\n  <? endif ?>\n<? endif ?>\n<? if not exists("showDeleted") ?>\n   AND (NOT gltrans_deleted)\n<? endif ?>\n<? if exists("company_id") ?>\n   AND (company_id=<? value("company_id") ?>)\n<? endif ?>\n<? if exists("prfcntr_id") ?>\n   AND (prftcntr_id=<? value("prfcntr_id") ?>)\n<? endif ?>\n<? if exists("accnt_number") ?>\n   AND (accnt_number=<? value("accnt_number") ?>)\n<? endif ?>\n<? if exists("subaccnt_id") ?>\n   AND (subaccnt_id=<? value("subaccnt_id") ?>)\n<? endif ?>\n<? if exists("subType") ?>\n   AND (subaccnttype_id=<? value("subType") ?>)\n<? endif ?>\n<? if exists("accntType") ?>\n   AND (accnt_type= <? value("accntType") ?>)\n<? endif ?>\n<? if exists("accnt_id") ?>\n   AND (gltrans_accnt_id=<? value("accnt_id") ?>)\n<? endif ?>\n<? if exists("docnum") ?>\n   AND (gltrans_docnumber = case when <? value("docnum") ?> = '' then \n gltrans_docnumber else \n<? value("docnum") ?> end ) \n<? endif ?>\n<? if exists("source") ?>\n   AND (gltrans_source=<? value("source") ?>)\n<? endif ?>\n) \nORDER BY\n<? if exists("beginningBalance") ?>\n   gltrans_date,\n<? else ?>\n   gltrans_created DESC,\n<? endif ?>\n   gltrans_sequence, gltrans_amount;\n	admin	2015-10-01	0
100	incidents	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: incidents \n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT ON (incdt_number) incdt_id AS id,\nincdt_number, DATE(incdt_timestamp) AS incdt_timestamp,\ncrmacct_name,\nincdtcat_name, incdtseverity_name,  \nincdtpriority_name, crmacct_name, \nCASE WHEN(incdt_status='N') THEN <? value("new") ?>\nWHEN(incdt_status='F') THEN <? value("feedback") ?>\nWHEN(incdt_status='C') THEN <? value("confirmed") ?>\nWHEN(incdt_status='A') THEN <? value("assigned") ?>\nWHEN(incdt_status='R') THEN <? value("resolved") ?>\nWHEN(incdt_status='L') THEN <? value("closed") ?>\nELSE incdt_status\nEND,\nincdt_assigned_username, incdt_owner_username,\nincdt_summary, cntct_name, incdt_updated::date AS incdt_updated,\nprj_number, incdt_public,\nitem_number,\n<? if exists("LotSerialControl") ?>\nls_number,\n<? endif ?>\nstatus_color AS qtbackgroundrole \n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\nFROM crmacct, status, incdt()\n  JOIN cntct ON (incdt_cntct_id=cntct_id)\n  LEFT OUTER JOIN incdtcat ON (incdtcat_id=incdt_incdtcat_id) \n  LEFT OUTER JOIN incdtseverity ON (incdtseverity_id=incdt_incdtseverity_id) \n  LEFT OUTER JOIN incdtpriority ON (incdtpriority_id=incdt_incdtpriority_id) \n  LEFT OUTER JOIN prj ON (incdt_prj_id=prj_id)\n  LEFT OUTER JOIN item ON (item_id=incdt_item_id)\n<? if exists("LotSerialControl") ?>\n  LEFT OUTER JOIN ls ON (ls_id=incdt_ls_id)\n<? endif ?>\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='INCDT') \n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=incdt_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='INCDT') \n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=incdt_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='INCDT') \n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=incdt_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE ((incdt_crmacct_id=crmacct_id)\nAND (status_type='INCDT')\nAND (incdt_status=status_code)\n<? if exists("statuslist") ?>\nAND (status_seq IN (-1\n  <? foreach("statuslist") ?> , <? value("statuslist") ?> <? endforeach ?>\n  ))\n<? endif ?>\n<? if exists("status_equal") ?> \nAND (status_seq = <? value("status_equal") ?>) \n<? endif ?>\n<? if exists("status_above") ?> \nAND (status_seq < <? value("status_above") ?>) \n<? endif ?>\n<? if exists("cntct_id") ?> \nAND (incdt_cntct_id = <? value("cntct_id") ?>) \n<? endif ?>\n<? if exists("username") ?>\nAND (<? value("username") ?> IN (incdt_assigned_username, incdt_owner_username))\n<? endif ?>\n<? if exists("owner_username") ?> \nAND (incdt_owner_username=<? value("owner_username") ?>) \n<? endif ?>\n<? if exists("owner_usr_pattern" ?>\nAND (incdt_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\n<? if exists("assigned_username") ?> \nAND (incdt_assigned_username=<? value("assigned_username") ?>) \n<? endif ?>\n<? if exists("assigned_usr_pattern" ?>\nAND (incdt_assigned_username ~ <? value("assigned_usr_pattern") ?>) \n<? endif ?>\n<? if exists("incdtpriority_id_list") ?>\nAND (incdt_incdtpriority_id IN (-1\n  <? foreach("incdtpriority_id_list") ?> , <? value("incdtpriority_id_list") ?> <? endforeach ?>\n  ))\n<? endif ?>\n<? if exists("categorylist") ?>\nAND (incdt_incdtcat_id IN (-1\n  <? foreach("categorylist") ?> , <? value("categorylist") ?> <? endforeach ?>\n  ))\n<? endif ?>\n<? if exists("category_id") ?> \nAND (incdt_incdtcat_id=<? value("category_id") ?>) \n<? endif ?> \n<? if exists("severity_id") ?> \nAND (incdt_incdtseverity_id=<? value("severity_id") ?>) \n<? endif ?>\n<? if exists("crmAccountId") ?> \nAND (incdt_crmacct_id=<? value("crmAccountId") ?>) \n<? endif ?> \n<? if exists("prj_id") ?> \nAND (incdt_prj_id=<? value("prj_id") ?>) \n<? endif ?> \n<? if exists("public") ?> \nAND (incdt_public=<? value("public") ?>) \n<? endif ?> \n)\n \n<? if exists("search_pattern") ?> \nAND ((incdt_number::text ~* <? value("search_pattern") ?>)\nOR (incdt_summary ~* <? value("search_pattern") ?>)\nOR (incdt_descrip ~* <? value("search_pattern") ?>)\nOR (incdt_id IN (SELECT comment_source_id\nFROM comment\nWHERE((comment_source='INCDT')\nAND (comment_text ~* <? value("search_pattern") ?>)))))\n<? endif ?>\n<? if exists("item_id") ?>\nAND (incdt_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("lspattern") ?>\nAND (ls_number ~* <? value("lspattern") ?>)\n<? endif ?>\n<? if exists("id") ?>\nAND (incdt_id=<? value("id") ?>)\n<? endif ?>\nAND (incdt_timestamp BETWEEN COALESCE(<? value("startDate") ?>, startOfTime()) AND COALESCE(<? value("endDate") ?>, endOfTime())+1) \n<? literal("charClause") ?>\nORDER BY incdt_number;\n	admin	2015-10-01	0
252	invalidBillsofMaterials	detail	 used by dspInvalidBillsOfMaterials\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: invalidBillsofMaterials\n-- Name: detail\n-- Notes: used by dspInvalidBillsOfMaterials\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id, parent.item_id AS pitem_id,\n       component.item_id AS citem_id,\n       warehous_id, warehous_code,\n       parent.item_number AS parentitem,\n       component.item_number AS componentitem,\n       (component.item_descrip1 || ' ' || component.item_descrip2) AS descrip\nFROM bomitem, itemsite, item AS parent, item AS component, whsinfo\nWHERE ((bomitem_parent_item_id=parent.item_id)\n   AND (bomitem_item_id=component.item_id)\n   AND (CURRENT_DATE BETWEEN bomitem_effective AND (bomitem_expires - 1))\n   AND (itemsite_item_id=parent.item_id)\n   AND (itemsite_warehous_id=warehous_id)\n   AND (parent.item_type='M')\n   AND (itemsite_wosupply)\n   AND (itemsite_active)\n   AND (component.item_id NOT IN ( SELECT itemsite_item_id\n                                   FROM itemsite\n                                   WHERE ((itemsite_warehous_id=warehous_id)\n                                      AND (itemsite_active)) ) ) \n<? if exists("warehous_id") ?>\n   AND (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n      )\nORDER BY warehous_code, parentitem, componentitem;\n	admin	2015-10-01	0
52	inventoryAvailability	general	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: inventoryAvailability\n-- Name:  general\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id, altId,\n       item_number, (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n       uom_name,\n       warehous_id, warehous_code, itemsite_leadtime,\n       qoh, allocated, noNeg(qoh - allocated) AS unallocated, \n       ordered, requests, reorderlevel, outlevel,\n       (qoh - allocated + ordered) AS available,\n       vend_number,\n       'qty' AS qoh_xtnumericrole,\n       'qty' AS allocated_xtnumericrole,\n       'qty' AS unallocated_xtnumericrole,       \n       'qty' AS ordered_xtnumericrole,\n       'qty' AS requests_xtnumericrole,\n       'qty' AS reorderlevel_xtnumericrole,\n       'qty' AS outlevel_xtnumericrole,\n       'qty' AS available_xtnumericrole,\n       <? if exists("byDates") ?>\n         'grey' AS qoh_qtforegroundrole,\n       <? endif ?>\n       CASE WHEN ((qoh - allocated + ordered) < 0) THEN 'error'\n            WHEN ((qoh - allocated + ordered) <= reorderlevel) THEN 'warning'\n       END AS available_qtforegroundrole\nFROM (SELECT \n           <? if reExists("[vV]end") ?>\n             DISTINCT\n           <? endif ?>\n             itemsite_id,\n             CASE WHEN (item_type IN ('P', 'O')) THEN 1\n                  WHEN (item_type IN ('M')) THEN 2\n                  ELSE 0\n             END AS altId,\n             item_number, item_descrip1, item_descrip2, item_inv_uom_id,\n             warehous_id, warehous_code, itemsite_leadtime,\n             qtyAvailable(itemsite_id) AS qoh,\n             CASE WHEN itemsite_useparams THEN itemsite_reorderlevel\n                  ELSE 0.0\n             END AS reorderlevel,\n             CASE WHEN itemsite_useparams THEN itemsite_ordertoqty\n                  ELSE 0.0\n             END AS outlevel,\n             <? if exists("byVend") ?>\n               vend_number,\n             <? else ?>\n               NULL AS vend_number,\n             <? endif ?>\n             <? if exists("byLeadTime") ?>\n               qtyAllocated(itemsite_id, itemsite_leadtime) AS allocated,\n               qtyOrdered(itemsite_id,   itemsite_leadtime) AS ordered, \n               qtypr(itemsite_id,   itemsite_leadtime) AS requests\n             <? elseif exists("byDays") ?>\n               qtyAllocated(itemsite_id, CAST(<? value("byDays") ?> AS INTEGER)) AS allocated,\n               qtyOrdered(itemsite_id,   CAST(<? value("byDays") ?> AS INTEGER)) AS ordered,\n               qtypr(itemsite_id,   CAST(<? value("byDays") ?> AS INTEGER)) AS requests  \n             <? elseif exists("byDate") ?>\n               qtyAllocated(itemsite_id, (<? value("byDate") ?> - CURRENT_DATE)) AS allocated,\n               qtyOrdered(itemsite_id,   (<? value("byDate") ?> - CURRENT_DATE)) AS ordered,\n               qtypr(itemsite_id,   (<? value("byDate") ?> - CURRENT_DATE)) AS requests \n             <? elseif exists("byDates") ?>\n               qtyAllocated(itemsite_id, <? value("startDate") ?>, <? value("endDate") ?>) AS allocated,\n               qtyOrdered(itemsite_id,   <? value("startDate") ?>, <? value("endDate") ?>) AS ordered,\n               qtypr(itemsite_id,   <? value("startDate") ?>, <? value("endDate") ?>) AS requests\n             <? endif ?>\n      FROM item, itemsite, whsinfo\n           <? if reExists("[vV]end") ?>\n             , vendinfo JOIN itemsrc ON (itemsrc_vend_id=vend_id)\n           <? endif ?>\n      WHERE ( (itemsite_active)\n          AND (itemsite_item_id=item_id)\n          AND (itemsite_warehous_id=warehous_id)\n          <? if exists("warehous_id") ?>\n            AND (warehous_id=<? value("warehous_id") ?>)\n          <? endif ?>\n          <? if exists("item_id") ?>\n            AND (item_id=<? value("item_id") ?>)\n          <? elseif exists("classcode_id") ?>\n            AND (item_classcode_id=<? value("classcode_id") ?>)\n          <? elseif exists("classcode_pattern") ?>\n            AND (item_classcode_id IN (SELECT classcode_id\n                                       FROM classcode\n                                       WHERE (classcode_code ~ <? value("classcode_pattern") ?>)))\n          <? elseif exists("plancode_id") ?>\n            AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n          <? elseif exists("plancode_pattern") ?>\n            AND (itemsite_plancode_id IN (SELECT plancode_id\n                                          FROM plancode\n                                          WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n          <? elseif exists("itemgrp_id") ?>\n            AND (item_id IN (SELECT itemgrpitem_item_id\n                             FROM itemgrpitem\n                             WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))\n          <? elseif exists("itemgrp_pattern") ?>\n            AND (item_id IN (SELECT itemgrpitem_item_id\n                             FROM itemgrpitem, itemgrp\n                             WHERE ( (itemgrpitem_itemgrp_id=itemgrp_id)\n                                    AND (itemgrp_name ~ <? value("itemgrp_pattern") ?>) ) ))\n          <? elseif exists("itemgrp") ?>\n            AND (item_id IN (SELECT DISTINCT itemgrpitem_item_id FROM itemgrpitem))\n          <? endif ?>\n          <? if reExists("[vV]end") ?>\n            AND (itemsrc_item_id=item_id)\n          <? endif ?>\n          <? if exists("vend_id") ?>\n            AND (vend_id=<? value("vend_id") ?>)\n          <? elseif exists("vendtype_id") ?>\n            AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n          <? elseif exists("vendtype_pattern") ?>\n            AND (vend_vendtype_id IN (SELECT vendtype_id\n                                      FROM vendtype\n                                      WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n          <? endif ?>\n      ) ) AS data, uom\nWHERE ((item_inv_uom_id=uom_id)\n<? if exists("showReorder") ?>\n  AND ((qoh - allocated + ordered) <= reorderlevel) \n  <? if exists("ignoreReorderAtZero") ?>\n    AND NOT ( ((qoh - allocated + ordered) = 0) AND (reorderlevel = 0))\n  <? endif ?>\n<? elseif exists("showShortages") ?>\n  AND ((qoh - allocated + ordered) < 0) \n<? endif ?>\n)\n\nORDER BY\n<? if exists("ListNumericItemNumbersFirst") ?>\n  toNumeric(item_number, 999999999999999),\n<? elseif exists("byVend") ?>\n  vend_number,\n<? endif ?>\n  item_number, warehous_code DESC;\n	admin	2015-10-01	0
