CREATE OR REPLACE VIEW public.vw_utility_lot_not_invoiced_on_purchase AS
 SELECT pur.id AS "intPurchaseId",
    pl.id AS "intPurchaseLineId",
    l.id AS "intLotId",
    si.id AS "intShipmentInId",
    pur.party AS "intVendorId",
    l.lot_qt AS "dblLotQuantity",
    qth.quantity AS "dblNetWeight",
    qth.gross_quantity AS "dblGrossWeight",
    pl.quantity AS "dblLineQuantity",
    pl.unit_price AS "dblLineUnitPrice",
    pl.price_type AS "strLinePriceType",
    pur.currency AS "intCurrencyId"
   FROM ((((((lot_lot l
     LEFT JOIN lot_qt_hist qth ON (((l.id = qth.lot) AND (l.lot_state = qth.quantity_type))))
     JOIN stock_shipment_in si ON ((si.id = l.lot_shipment_in)))
     JOIN purchase_line pl ON ((pl.id = l.line)))
     JOIN purchase_purchase pur ON ((pur.id = pl.purchase)))
     JOIN party_party pp ON ((pp.id = pur.party)))
     JOIN currency_currency cur ON ((cur.id = pur.currency)))
  WHERE ((1 = 1) AND ((l.lot_type)::text = 'physic'::text) AND ((si.state)::text = ANY (ARRAY[('received'::character varying)::text, ('done'::character varying)::text])) AND (l.invoice_line IS NULL));;
