CREATE OR REPLACE VIEW public.vw_utility_lot_not_invoiced_on_sale AS
 SELECT s.id AS "intSaleId",
    sl.id AS "intSaleLineId",
    l.id AS "intLotId",
    so.id AS "intShipmentOutId",
    s.party AS "intCustomerId",
    l.lot_qt AS "dblLotQuantity",
    qth.quantity AS "dblNetWeight",
    qth.gross_quantity AS "dblGrossWeight",
    sl.quantity AS "dblLineQuantity",
    sl.unit_price AS "dblLineUnitPrice",
    sl.price_type AS "strLinePriceType",
    s.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_out so ON ((so.id = l.lot_shipment_out)))
     JOIN sale_line sl ON ((sl.id = l.sale_line)))
     JOIN sale_sale s ON ((s.id = sl.sale)))
     JOIN party_party pp ON ((pp.id = s.party)))
     JOIN currency_currency cur ON ((cur.id = s.currency)))
  WHERE ((1 = 1) AND ((so.state)::text = 'done'::text) AND (l.sale_invoice_line IS NULL));;
