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