Makes sales orders link to their deposits

This commit is contained in:
2022-07-04 07:19:14 -07:00
parent 496b0f487c
commit 2d5b8eded4
6 changed files with 146 additions and 70 deletions

View File

@@ -4,19 +4,23 @@
[auto-ap.utils :refer [dollars=]]
[clj-time.coerce :as c]
[datomic.api :as d]
[clojure.tools.logging :as log]))
[clojure.tools.logging :as log]
[clojure.set :as set]))
(defn <-datomic [result]
(-> result
(update :sales-order/date c/from-date)
(update :sales-order/charges (fn [cs]
(map (fn [c]
(update c :charge/processor :db/ident))
(-> c
(update :charge/processor :db/ident)
(set/rename-keys {:expected-deposit/_charges :expected-deposit})
(update :expected-deposit first)))
cs)))))
(def default-read '[*
{:sales-order/client [:client/name :db/id :client/code]
:sales-order/charges [* {:charge/processor [:db/ident]}]}])
:sales-order/charges [* {:charge/processor [:db/ident]} {:expected-deposit/_charges [:db/id]}]}])
(defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find []
@@ -118,10 +122,8 @@
:tax tax}))
(defn get-graphql [args]
(log/info "ARGS" args)
(let [db (d/db (d/connect uri))
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
[(->> (graphql-results ids-to-retrieve db args))
matching-count
(summarize-orders ids-to-retrieve)]))

View File

@@ -2,7 +2,6 @@
(:require
[auto-ap.datomic :refer [merge-query uri]]
[auto-ap.datomic.checks :as d-checks]
[auto-ap.datomic.sales-orders :as d-sales-orders]
[auto-ap.datomic.users :as d-users]
[auto-ap.graphql.accounts :as gq-accounts]
[auto-ap.graphql.checks :as gq-checks]
@@ -194,34 +193,9 @@
:order_line_item
{:fields {:id {:type :id}
:item_name {:type 'String}
:total {:type :money}
:tax {:type :money}
:category {:type 'String}
:discount {:type :money}}}
:charge
{:fields {:id {:type :id}
:processor {:type :processor}
:type_name {:type 'String}
:total {:type :money}
:tip {:type :money}}}
:sales_order
{:fields {:id {:type :id}
:location {:type 'String}
:external_id {:type 'String}
:total {:type :money}
:tip {:type :money}
:tax {:type :money}
:discount {:type :money}
:service_charge {:type :money}
:returns {:type :money}
:client {:type :client}
:date {:type 'String}
:charges {:type '(list :charge)}
:line_items {:type '(list :order_line_item)}}}
:yodlee_merchant {:fields {:id {:type :id}
:yodlee_id {:type 'String}
:name {:type 'String}}}
@@ -291,13 +265,7 @@
:sales_order_page {:fields {:sales_orders {:type '(list :sales_order)}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}
:sales_order_total {:type :money}
:sales_order_tax {:type :money}}}
:vendor_page {:fields {:vendors {:type '(list :vendor)}
:count {:type 'Int}
@@ -386,11 +354,7 @@
:all_sales_orders {:type '(list :sales_order)
:args {:client_id {:type :id}
:date_range {:type :date_range}
:client_code {:type 'String}}
:resolve :get-all-sales-orders}
:yodlee_merchants {:type '(list :yodlee_merchant)
:args {}
@@ -413,16 +377,7 @@
:sales_order_page {:type :sales_order_page
:args {:client_id {:type :id}
:date_range {:type :date_range}
:total_lte {:type :money}
:total_gte {:type :money}
:processor {:type :processor}
:start {:type 'Int}
:per_page {:type 'Int}
:sort {:type '(list :sort_item)}}
:resolve :get-sales-order-page}
:vendor {:type :vendor_page
:args {:name_like {:type 'String}
:start {:type 'Int}
@@ -636,11 +591,7 @@
(defn get-all-sales-orders [context args value]
(assert-admin (:id context))
(map
->graphql
(first (d-sales-orders/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
(defn get-user [context args value]
(assert-admin (:id context))
@@ -812,10 +763,8 @@
(-> integreat-schema
(attach-resolvers {
:get-yodlee-provider-account-page gq-yodlee2/get-yodlee-provider-account-page
:get-all-sales-orders get-all-sales-orders
:get-accounts gq-accounts/get-graphql
:get-all-accounts gq-accounts/get-all-graphql
:get-sales-order-page gq-sales-orders/get-sales-orders-page
:get-transaction-rule-page gq-transaction-rules/get-transaction-rule-page
:get-transaction-rule-matches gq-transaction-rules/get-transaction-rule-matches
:get-expense-account-stats get-expense-account-stats
@@ -847,6 +796,7 @@
gq-expected-deposit/attach
gq-invoices/attach
gq-clients/attach
gq-sales-orders/attach
schema/compile))

View File

@@ -22,7 +22,6 @@
(defn get-expected-deposit-page [context args value]
(let [args (assoc args :id (:id context))
[expected-deposits expected-deposit-count] (d-expected-deposit/get-graphql (<-graphql args))
_ (log/info expected-deposits)
expected-deposits (map status->graphql expected-deposits)]
(result->page expected-deposits expected-deposit-count :expected_deposits args)))

View File

@@ -1,10 +1,100 @@
(ns auto-ap.graphql.sales-orders
(:require [auto-ap.datomic.sales-orders :as d-sales-orders2]
[auto-ap.graphql.utils :refer [->graphql <-graphql result->page]]))
[auto-ap.graphql.utils :refer [->graphql <-graphql result->page assert-admin] ]
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]))
(defn get-sales-orders-page [context args value]
(defn get-sales-orders-page [context args _]
(let [args (assoc args :id (:id context))
[sales-orders sales-orders-count {:keys [total tax]}] (d-sales-orders2/get-graphql (<-graphql args))]
(assoc (result->page sales-orders sales-orders-count :sales_orders args)
:sales_order_total total
:sales_order_tax tax)))
(defn get-all-sales-orders [context args _]
(assert-admin (:id context))
(map
->graphql
(first (d-sales-orders2/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
(def objects
{:sales_order_page
{:fields {:sales_orders {:type '(list :sales_order)}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}
:sales_order_total {:type :money}
:sales_order_tax {:type :money}}}
:sales_order
{:fields {:id {:type :id}
:location {:type 'String}
:external_id {:type 'String}
:total {:type :money}
:tip {:type :money}
:tax {:type :money}
:discount {:type :money}
:service_charge {:type :money}
:returns {:type :money}
:client {:type :client}
:date {:type 'String}
:charges {:type '(list :charge)}
:line_items {:type '(list :order_line_item)}}}
:order_line_item
{:fields {:id {:type :id}
:item_name {:type 'String}
:total {:type :money}
:tax {:type :money}
:category {:type 'String}
:discount {:type :money}}}
:charge
{:fields {:id {:type :id}
:processor {:type :processor}
:type_name {:type 'String}
:total {:type :money}
:tip {:type :money}
:expected_deposit {:type :expected_deposit}}}})
(def queries
{:all_sales_orders {:type '(list :sales_order)
:args {:client_id {:type :id}
:date_range {:type :date_range}
:client_code {:type 'String}}
:resolve :get-all-sales-orders}
:sales_order_page {:type :sales_order_page
:args {:client_id {:type :id}
:date_range {:type :date_range}
:total_lte {:type :money}
:total_gte {:type :money}
:processor {:type :processor}
:start {:type 'Int}
:per_page {:type 'Int}
:sort {:type '(list :sort_item)}}
:resolve :get-sales-order-page}})
(def mutations
{})
(def input-objects
{})
(def enums
{})
(def resolvers
{:get-all-sales-orders get-all-sales-orders
:get-sales-order-page get-sales-orders-page
})
(defn attach [schema]
(->
(merge-with merge schema
{:objects objects
:queries queries
:mutations mutations
:input-objects input-objects
:enums enums})
(attach-resolvers resolvers)))