-- View: public.vw_utility_invoices

-- DROP VIEW public.vw_utility_invoices;

CREATE OR REPLACE VIEW public.vw_utility_invoices AS
 SELECT ai.id AS "intInvoiceId",
    ai.company AS "intCompanyId",
    cparty.name AS "strCompanyName",
    ai.number AS "strInvoiceNumber",
    ai.invoice_date AS "dtmInvoiceDate",
    p.name AS "strPartyName",
    ai.type AS "strInvoiceType",
    aipt.name AS "strPaymentTerm",
    ai.accounting_date AS "dtmAccountingDate",
    ai.currency AS "intCurrencyId",
    cc.name AS "strCurrencyCode",
    ai.state AS "strInvoiceState",
    ai.move AS "intMoveId",
    ai.account AS "intAccountId",
    aa.name AS "strAccountName"
   FROM account_invoice ai
     JOIN currency_currency cc ON ai.currency = cc.id
     JOIN party_party p ON ai.party = p.id
     JOIN company_company comp ON ai.company = comp.id
     JOIN party_party cparty ON comp.party = cparty.id
     JOIN account_invoice_payment_term aipt ON ai.payment_term = aipt.id
     LEFT JOIN account_account aa ON ai.account = aa.id
  WHERE 1 = 1;

ALTER TABLE public.vw_utility_invoices
    OWNER TO postgres;
