lunes, 26 de marzo de 2012

Cuentas contables del adempiere en orden


CREATE OR REPLACE VIEW vw_cuentas_catalogo_ctamayor AS
 SELECT cel.c_elementvalue_id, cel.value, cel.name, cel.description, cel.isactive, cel.accounttype, fn_usr_getnivelcuenta(cel.c_elementvalue_id, ce.ad_tree_id) AS nivelcuenta, atn.parent_id, atn.seqno, fn_usr_getparentid_upto(cel.c_elementvalue_id, 1::numeric) AS ctamayor_id, cel.accountsign AS nat
   FROM c_elementvalue cel
   JOIN c_element ce ON cel.c_element_id = ce.c_element_id
   JOIN ad_treenode atn ON atn.ad_tree_id = ce.ad_tree_id AND atn.node_id = cel.c_elementvalue_id
  WHERE cel.ad_client_id = 1000000::numeric AND cel.c_currency_id = 209::numeric AND cel.isactive = 'Y'::bpchar
  ORDER BY cel.value, cel.name, atn.parent_id, atn.seqno;


CREATE OR REPLACE VIEW vw_cuentas_contables AS
 SELECT cel.c_elementvalue_id, cel.value, cel.name, cel.description, cel.isactive, cel.accounttype, cel.nivelcuenta, cel.parent_id, cel.seqno, cel.ctamayor_id, COALESCE(( SELECT aux.description
           FROM c_elementvalue aux
          WHERE aux.c_elementvalue_id = cel.ctamayor_id), ''::character varying) AS ctmayor_name, COALESCE(( SELECT aux.value
           FROM c_elementvalue aux
          WHERE aux.c_elementvalue_id = cel.ctamayor_id), '0'::character varying)::numeric AS ctmayor_value, COALESCE(( SELECT aux.value
           FROM c_elementvalue aux
          WHERE aux.c_elementvalue_id = cel.parent_id), '0'::character varying)::numeric AS parent_value, COALESCE(( SELECT aux.description
           FROM c_elementvalue aux
          WHERE aux.c_elementvalue_id = cel.parent_id), ''::character varying) AS parent_name, cel.nat
   FROM vw_cuentas_catalogo_ctamayor cel;

SELECT * FROM vw_cuentas_contables vc;




No hay comentarios:

Publicar un comentario