First step in coding sales.
This commit is contained in:
@@ -115,6 +115,31 @@
|
||||
[]))]
|
||||
[existing-accounts]))
|
||||
|
||||
|
||||
(defn apply-idents-to-well-known [conn]
|
||||
(let [[ccp-square] (d/q '[:find [?v]
|
||||
:where [?v :vendor/name "CCP Square"]]
|
||||
(d/db conn))
|
||||
[receipts-split] (d/q '[:find [?a]
|
||||
:where [?a :account/numeric-code 12990]]
|
||||
(d/db conn))
|
||||
[ccp] (d/q '[:find [?a]
|
||||
:where [?a :account/numeric-code 12100]]
|
||||
(d/db conn))
|
||||
[accounts-payable] (d/q '[:find [?a]
|
||||
:where [?a :account/numeric-code 21000]]
|
||||
(d/db conn))]
|
||||
[[{:db/id ccp :db/ident :account/ccp}]
|
||||
[{:db/id ccp-square
|
||||
:db/ident :vendor/ccp-square
|
||||
:vendor/name "CCP Square"
|
||||
:vendor/default-account :account/ccp}
|
||||
{:db/id receipts-split
|
||||
:db/ident :account/receipts-split}
|
||||
|
||||
{:db/id accounts-payable
|
||||
:db/ident :account/accounts-payable}]]))
|
||||
|
||||
(defn migrate [conn]
|
||||
(let [
|
||||
norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
||||
@@ -443,7 +468,10 @@
|
||||
:db/doc "error message for a failed job"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}]]
|
||||
:requires [:auto-ap/add-transaction-import2]}}
|
||||
:requires [:auto-ap/add-transaction-import2]}
|
||||
:auto-ap/apply-idents-to-well-known {:txes-fn `apply-idents-to-well-known
|
||||
:requires [:auto-ap/add-general-ledger6
|
||||
:auto-ap/add-account-to-vendor]}}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -223,8 +223,15 @@
|
||||
(defn maybe-clear-expected-deposit [{:transaction/keys [amount client date] :as transaction}]
|
||||
(when (>= amount 0.0)
|
||||
(when-let [expected-deposit (find-expected-deposit client amount (coerce/to-date-time date))]
|
||||
(assoc transaction :transaction/expected-deposit {:db/id expected-deposit
|
||||
:expected-deposit/status :expected-deposit-status/cleared}))))
|
||||
(assoc transaction
|
||||
:transaction/expected-deposit {:db/id expected-deposit
|
||||
:expected-deposit/status :expected-deposit-status/cleared}
|
||||
:transaction/accounts [{:transaction-account/account :account/ccp
|
||||
:transaction-account/amount amount
|
||||
:transaction-account/location "A"}]
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/vendor :vendor/ccp-square
|
||||
))))
|
||||
|
||||
(defn maybe-code [{:transaction/keys [client amount] :as transaction} apply-rules valid-locations]
|
||||
(if-let [unpaid-invoices (seq (match-transaction-to-unpaid-invoices amount client))]
|
||||
@@ -249,9 +256,6 @@
|
||||
code-fn)]))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn get-existing [bank-account]
|
||||
(log/info "looking up bank account data for" bank-account)
|
||||
(into {}
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
(map :a)
|
||||
(map namespace)
|
||||
set)]
|
||||
(println namespaces changes)
|
||||
(cond (namespaces "invoice" ) [[:invoice e]]
|
||||
(namespaces "invoice-expense-account" ) [[:invoice (:db/id (:invoice/_expense-accounts entity))]]
|
||||
(namespaces "transaction-account" ) [[:transaction (:db/id (:transaction/_accounts entity))]]
|
||||
(namespaces "transaction" ) [[:transaction e]]
|
||||
(namespaces "expected-deposit" ) [[:expected-deposit e]]
|
||||
:else nil)))
|
||||
|
||||
|
||||
@@ -33,6 +35,7 @@
|
||||
(cond (namespaces "invoice" ) :invoice
|
||||
(namespaces "invoice-expense-account" ) :invoice-expense-account
|
||||
(namespaces "transaction-account" ) :transaction-account
|
||||
(namespaces "expected-deposit" ) :expected-deposit
|
||||
:else nil)))
|
||||
|
||||
(defmulti entity-change->ledger (fn [_ [type]]
|
||||
@@ -57,7 +60,7 @@
|
||||
:journal-entry/vendor (:db/id (:invoice/vendor entity))
|
||||
:journal-entry/amount (Math/abs (:invoice/total entity))
|
||||
|
||||
:journal-entry/line-items (into [(cond-> {:journal-entry-line/account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
|
||||
:journal-entry/line-items (into [(cond-> {:journal-entry-line/account :account/accounts-payable
|
||||
:journal-entry-line/location "A"
|
||||
}
|
||||
credit-invoice? (assoc :journal-entry-line/debit (Math/abs (:invoice/total entity)))
|
||||
@@ -120,6 +123,26 @@
|
||||
|
||||
:journal-entry/cleared true}))))
|
||||
|
||||
(defmethod entity-change->ledger :expected-deposit
|
||||
[db [type id]]
|
||||
(let [{:expected-deposit/keys [total client date]} (d/pull db '[:expected-deposit/total :expected-deposit/client :expected-deposit/date] id)]
|
||||
#:journal-entry
|
||||
{:source "expected-deposit"
|
||||
:original-entity id
|
||||
|
||||
:client client
|
||||
:date date
|
||||
:amount total
|
||||
:vendor :vendor/ccp-square
|
||||
:line-items [#:journal-entry-line
|
||||
{:credit total
|
||||
:location "A"
|
||||
:account :account/receipts-split}
|
||||
#:journal-entry-line
|
||||
{:debit total
|
||||
:location "A"
|
||||
:account :account/ccp}]}))
|
||||
|
||||
(defmethod entity-change->ledger :invoice-expense-account
|
||||
[db [entity changes]]
|
||||
nil
|
||||
|
||||
Reference in New Issue
Block a user