(ns auto-ap.ssr.invoice.common)

(def default-read '[:db/id
                    :invoice/invoice-number
                    :invoice/total
                    { :invoice/uploader [:user/name]}
                    :invoice/outstanding-balance
                    :invoice/source-url
                    :invoice/location
                    [:invoice/date :xform clj-time.coerce/from-date]
                    [:invoice/due :xform clj-time.coerce/from-date]
                    [:invoice/scheduled-payment :xform clj-time.coerce/from-date]
                    {:invoice/client [:client/code :db/id :client/name]
                     :invoice/expense-accounts [* {:invoice-expense-account/account [:account/name :db/id
                                                                                     :account/location
                                                                                     {:account/client-overrides [:account-client-override/name
                                                                                                                 {:account-client-override/client [:db/id]}]}]}]
                     [:transaction/_invoices :as :invoice/transaction] [:db/id]
                     [:journal-entry/_original-entity :as :invoice/journal-entry] [:db/id]
                     [:invoice-payment/_invoice :as :invoice/payments] [{:invoice-payment/payment [:db/id :payment/date :payment/amount

                                                                                                   {[:transaction/_payment :as :payment/transaction] [:db/id]
                                                                                                    [:payment/status :xform iol-ion.query/ident] [:db/ident]}]}]
                     #_[:payment/_invoices :as :invoice/payments]
                     [:invoice/status :xform iol-ion.query/ident] [:db/ident]
                     [:invoice/import-status :xform iol-ion.query/ident] [:db/ident]
                     :invoice/vendor [:vendor/name :db/id]}])