This commit is contained in:
2023-05-01 17:10:34 -07:00
8 changed files with 234 additions and 82 deletions

View File

@@ -200,6 +200,62 @@
:returns 0.0
:vendor :vendor/ccp-ezcater}))
(defn get-by-id [integration id]
(query
integration
{:venia/queries [[:order {:id id}
[:uuid
:orderNumber
:orderSourceType
[:caterer
[:name
:uuid
[:address [:street]]]]
[:event
[:timestamp
:catererHandoffFoodTime
:orderType]]
[:catererCart [[:orderItems
[:name
:quantity
:posItemId
[:totalInSubunits
[:currency
:subunits]]]]
[:totals
[:catererTotalDue]]
[:feesAndDiscounts
{:type 'DELIVERY_FEE}
[[:cost
[:currency
:subunits]]]]]]
[:totals [[:customerTotalDue
[
:currency
:subunits
]]
[:pointOfSaleIntegrationFee
[
:currency
:subunits
]]
[:tip
[:currency
:subunits]]
[:salesTax
[
:currency
:subunits
]]
[:salesTaxRemittance
[:currency
:subunits
]]
[:subTotal
[:currency
:subunits]]]]]]]}))
(defn lookup-order [json]
(let [caterer (get-caterer (get json "parent_id"))
integration (:ezcater-integration/_caterers caterer)
@@ -207,58 +263,7 @@
location (-> caterer :ezcater-location/_caterer first :ezcater-location/location)]
(if (and client location)
(doto
(-> (query
integration
{:venia/queries [[:order {:id (get json "entity_id")}
[:uuid
:orderSourceType
[:caterer
[:name
:uuid
[:address [:street]]]]
[:event
[:timestamp
:catererHandoffFoodTime
:orderType]]
[:catererCart [[:orderItems
[:name
:quantity
:posItemId
[:totalInSubunits
[:currency
:subunits]]]]
[:totals
[:catererTotalDue]]
[:feesAndDiscounts
{:type 'DELIVERY_FEE}
[[:cost
[:currency
:subunits]]]]]]
[:totals [[:customerTotalDue
[
:currency
:subunits
]]
[:pointOfSaleIntegrationFee
[
:currency
:subunits
]]
[:tip
[:currency
:subunits]]
[:salesTax
[
:currency
:subunits
]]
[:salesTaxRemittance
[:currency
:subunits
]]
[:subTotal
[:currency
:subunits]]]]]]]})
(-> (get-by-id integration (get json "entity_id"))
(:order)
(assoc :client-code client
:client-location location))

View File

@@ -75,9 +75,9 @@
amount (str "--" (.format df amount) "--")]
[:table {:num-cols 12 :border false :leading 11 :widths (distribute [2 3 3 3 3 3 3 3 3 2 2 2])}
[(let [{:keys [:client/name] {:keys [:address/street1 :address/city :address/state :address/zip]} :client/address} client]
[:cell {:colspan 4 } [:paragraph {:leading 14} name "\n" street1 "\n" (str city ", " state " " zip)] ])
[:cell {:colspan 5 } [:paragraph {:leading 14} name "\n" street1 "\n" (str city ", " state " " zip)] ])
(let [{:keys [:bank-account/bank-name :bank-account/bank-code] } bank-account]
[:cell {:colspan 6 :align :center} [:paragraph {:style :bold} bank-name] [:paragraph {:size 8 :leading 8} bank-code]])
[:cell {:colspan 5 :align :center} [:paragraph {:style :bold} bank-name] [:paragraph {:size 8 :leading 8} bank-code]])
[:cell {:colspan 2 :size 13}
check]]

View File

@@ -428,7 +428,8 @@
(let [payment-tx (i-transactions/add-new-payment (dc/pull db [:transaction/amount :transaction/date :db/id] transaction_id)
(map (fn [id]
(let [entity (dc/pull db [:invoice/vendor :db/id :invoice/total] id)]
[(-> entity :invoice/vendor :db/id)
[(or (-> entity :invoice/vendor :db/id)
(-> entity :invoice/vendor))
(-> entity :db/id)
(-> entity :invoice/total)]))
autopay_invoice_ids)
@@ -466,7 +467,8 @@
(let [payment-tx (i-transactions/add-new-payment (dc/pull db [:transaction/amount :transaction/date :db/id] transaction_id)
(map (fn [id]
(let [entity (dc/pull db [:invoice/vendor :db/id :invoice/total] id)]
[(-> entity :invoice/vendor :db/id)
[(or (-> entity :invoice/vendor :db/id)
(-> entity :invoice/vendor))
(-> entity :db/id)
(-> entity :invoice/total)]))
unpaid_invoice_ids)

View File

@@ -70,13 +70,15 @@
(drop 1)
(filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]]
(= "Y" break-flag)))
(map (fn [[vendor location-hint invoice-number ship-date invoice-total ]]
(map (fn [[_ location-hint invoice-number ship-date invoice-total ]]
(let [matching-client (and location-hint
(parse/exact-match clients location-hint))]
(parse/exact-match clients location-hint))
location (parse/best-location-match matching-client location-hint location-hint )
vendor (d/pull (d/db conn) '[:vendor/default-account] :vendor/general-produce)]
(when-not matching-client
(log/warn ::missing-client
:client-hint location-hint))
{:invoice/location (parse/best-location-match matching-client location-hint location-hint )
{:invoice/location location
:invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date))
:invoice/invoice-number invoice-number
:invoice/total (Double/parseDouble invoice-total)
@@ -86,7 +88,11 @@
:invoice/import-status :import-status/imported
:invoice/status :invoice-status/unpaid
:invoice/client-identifier location-hint
})))
:invoice/expense-accounts [{:invoice-expense-account/account
(-> vendor :vendor/default-account :db/id)
:invoice-expense-account/location location
:invoice-expense-account/amount (Math/abs (Double/parseDouble invoice-total))
}]})))
(filter :invoice/client)
(into []))
(catch Exception e
@@ -228,11 +234,8 @@
:client/locations])
:where [?c :client/code]]
(d/db conn)))]
(log/info ::found-invoice-keys
:keys keys )
(let [transaction (->> keys
(mapcat (fn [k]
(try
@@ -249,12 +252,15 @@
:invoice i)
i))
(mapv (fn [i]
[:propose-invoice (assoc i :invoice/source-url invoice-url)]))))) (catch Exception e
(log/error ::cant-load-file
:key k
:exception e)
(mark-error k)
[]))))
(if (= :vendor/cintas (:invoice/vendor i))
[:propose-invoice (assoc i :invoice/source-url invoice-url)]
[:propose-invoice i]))))))
(catch Exception e
(log/error ::cant-load-file
:key k
:exception e)
(mark-error k)
[]))))
(into []))]
(audit-transact transaction {:user/name "sysco importer" :user/role "admin"})
(log/info ::success

View File

@@ -194,9 +194,14 @@
(defn form-data->map [form-data]
(reduce-kv
(fn [acc k v]
(assoc-in acc (->> (str/split k #"_")
(mapv #(apply keyword (str/split % #"/"))))
v))
(cond (and (string? v)
(empty? v))
acc
:else
(assoc-in acc (->> (str/split k #"_")
(mapv #(apply keyword (str/split % #"/"))))
v)))
{}
form-data))
@@ -213,8 +218,8 @@
@(dc/transact conn [(remove-nils
(-> (form-data->map form-params)
(assoc :db/id (Long/parseLong (:vendor-id route-params)))
(update :vendor/legal-entity-1099-type #(some->> % (keyword "legal-entity-1099-type")))
(update :vendor/legal-entity-tin-type #(some->> % (keyword "legal-entity-tin-type")))))]))
(update :vendor/legal-entity-1099-type #(some->> % not-empty (keyword "legal-entity-1099-type")))
(update :vendor/legal-entity-tin-type #(some->> % not-empty (keyword "legal-entity-tin-type")))))]))
(html-response
(table request :flash-id (Long/parseLong (:vendor-id route-params)))))