CREATE VIEW combined_orders_views AS
SELECT
    'cutoms' :: text AS jenis_transaksi,
    tpc.anggota_id,
    a.nama_lengkap,
    a.foto,
    rls.roles_name,
    tpc.jenis_barang_id,
    tpc.toko_id,
    t.nama_toko,
    tpc.tgl_pesan as tanggal,
    tpc.berat,
    tpc.harga_produk as harga
FROM
    "public"."transaksi_pesanan_customs" as tpc
    LEFT JOIN anggota as a ON tpc.anggota_id = a.id
    LEFT JOIN roles as rls ON rls.id=a.roles_id
    LEFT JOIN tokos as t ON tpc.toko_id = t.id
WHERE
    tpc.deleted_at IS NULL
    AND tpc.deleted_by IS NULL

UNION
SELECT
    'orders' :: text AS jenis_transaksi,
    o.anggota_id,
    a.nama_lengkap,
    a.foto,
    rls.roles_name,
    ib.jenis_barang_id,
    o.toko_id,
    t.nama_toko,
    o.tanggal_jual as tanggal,
    ib.berat,
    ib.harga_jual as harga
FROM
    "public"."order_details" as od
    LEFT JOIN "public"."orders" as o ON o.id = od.order_id
    LEFT JOIN anggota as a ON o.anggota_id = a.id
    LEFT JOIN roles as rls ON rls.id=a.roles_id
    LEFT JOIN tokos as t ON o.toko_id = t.id
    LEFT JOIN "public"."inventory_barangs" as ib ON ib.id = od.inventory_barang_id
WHERE
    o.deleted_at IS NULL
    AND o.deleted_by IS NULL