     # on_conflict update query
     # i.e. alittle special check due to timestamp not updated on cash, credit or chq changes
     upsert_query =
-      from(
-        i in Invoice,
-        where:
-          fragment(
-            "i0.lmt < EXCLUDED.lmt OR i0.cash <> EXCLUDED.cash OR i0.cheque <> EXCLUDED.cheque OR i0.credit <> EXCLUDED.credit"
-          ),
-        update: [
-          set: [
-            customer_id: fragment("EXCLUDED.customer_id"),
-            date: fragment("EXCLUDED.date"),
-            detail1: fragment("EXCLUDED.detail1"),
-            detail2: fragment("EXCLUDED.detail2"),
-            detail3: fragment("EXCLUDED.detail3"),
-            from_stock: fragment("EXCLUDED.from_stock"),
-            cash: fragment("EXCLUDED.cash"),
-            credit: fragment("EXCLUDED.credit"),
-            cheque: fragment("EXCLUDED.cheque"),
-            price_level: fragment("EXCLUDED.price_level"),
-            lmu: fragment("EXCLUDED.lmu"),
-            lmt: fragment("EXCLUDED.lmt")
-          ]
-        ]
-      )
+      Invoice
+      |> where(
+        fragment(
+          "i0.lmt < EXCLUDED.lmt OR i0.cash <> EXCLUDED.cash OR i0.cheque <> EXCLUDED.cheque OR i0.credit <> EXCLUDED.credit"
+        )
+      )
+      |> custom_on_conflict_update_replace_all()
 
     rows = upsert_records(Invoice, records, upsert_query, :id)
     {:ok, %{ctx | upserted: Map.put(ctx.upserted, :invoices, rows)}}

      )

    upsert_query =
      from(
        p in Price,
        where: fragment("p0.lmt < EXCLUDED.lmt"),
        update: [
          set: [
            cash: fragment("EXCLUDED.cash"),
            credit: fragment("EXCLUDED.credit"),
            trek: fragment("EXCLUDED.trek"),
            lmu: fragment("EXCLUDED.lmu"),
            lmt: fragment("EXCLUDED.lmt")
          ]
        ]
      )

    rows =
      upsert_records(

      )

    upsert_query =
      Posting
      |> where([u], u.lmt < fragment("EXCLUDED.lmt"))
      |> custom_on_conflict_update_replace_all()

    rows = upsert_records(Posting, records, upsert_query, :id)

