Turns on invoice importation

This commit is contained in:
2023-04-27 08:53:49 -07:00
parent 19d83f655f
commit 066d82e0e4

View File

@@ -65,28 +65,34 @@
(defmethod extract-invoice-details :general-produce (defmethod extract-invoice-details :general-produce
[k input-stream clients] [k input-stream clients]
(log/info ::parsing-general-produce :key k) (log/info ::parsing-general-produce :key k)
(->> (read-csv input-stream) (try
(drop 1) (->> (read-csv input-stream)
(filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]] (drop 1)
(= "Y" break-flag))) (filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]]
(map (fn [[vendor location-hint invoice-number ship-date invoice-total ]] (= "Y" break-flag)))
(let [matching-client (and location-hint (map (fn [[vendor location-hint invoice-number ship-date invoice-total ]]
(parse/exact-match clients location-hint))] (let [matching-client (and location-hint
(when-not matching-client (parse/exact-match clients location-hint))]
(log/warn ::missing-client (when-not matching-client
:client-hint location-hint)) (log/warn ::missing-client
{:invoice/vendor vendor :client-hint location-hint))
:invoice/location (parse/best-location-match matching-client location-hint location-hint ) {:invoice/vendor vendor
:invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date)) :invoice/location (parse/best-location-match matching-client location-hint location-hint )
:invoice/invoice-number invoice-number :invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date))
:invoice/total (Double/parseDouble invoice-total) :invoice/invoice-number invoice-number
:invoice/outstanding-balance (Double/parseDouble invoice-total) :invoice/total (Double/parseDouble invoice-total)
:invoice/client matching-client :invoice/outstanding-balance (Double/parseDouble invoice-total)
:invoice/import-status :import-status/imported :invoice/client matching-client
:invoice/status :invoice-status/unpaid :invoice/import-status :import-status/imported
:invoice/client-identifier location-hint :invoice/status :invoice-status/unpaid
}))) :invoice/client-identifier location-hint
(filter :invoice/client))) })))
(filter :invoice/client)
(into []))
(catch Exception e
(log/error ::cant-import-general-produce
:error e)
[])))
(defmethod extract-invoice-details :unknown (defmethod extract-invoice-details :unknown
[k input-stream clients] [k input-stream clients]
@@ -230,17 +236,15 @@
(with-open [is (-> (s3/get-object {:bucket-name bucket-name (with-open [is (-> (s3/get-object {:bucket-name bucket-name
:key k}) :key k})
:input-stream)] :input-stream)]
(doto (->> (extract-invoice-details k
(->> (extract-invoice-details k is
is clients)
clients) (map (fn [i]
(map (fn [i] (log/info ::importing-invoice
(log/info ::importing-invoice :invoice i)
:invoice i) i))
i)) (mapv (fn [i]
(mapv (fn [i] [:propose-invoice (assoc i :invoice/source-url invoice-url)])))))
[:propose-invoice (assoc i :invoice/source-url invoice-url)])))
println)))
(catch Exception e (catch Exception e
(log/error ::cant-load-file (log/error ::cant-load-file
:key k :key k