diff --git a/src/clj/user.clj b/src/clj/user.clj index 52a0e94a..288bef70 100644 --- a/src/clj/user.clj +++ b/src/clj/user.clj @@ -485,11 +485,16 @@ (let [data (with-open [reader (io/reader (char-array tsv))] (doall (csv/read-csv reader :separator \tab))) db (d/db auto-ap.datomic/conn) + i->invoice-id (fn [i] + (try (Long/parseLong i) + (catch Exception e + (:db/id (d/pull db '[:db/id] + [:invoice/original-id (Long/parseLong (first (str/split i #"-")))]))))) invoice-totals (->> data (drop 1) (group-by first) (map (fn [[k values]] - [(Long/parseLong k) + [(i->invoice-id k) (reduce + 0.0 (->> values (map (fn [[_ _ _ _ amount]] @@ -497,9 +502,9 @@ ])) (into {}))] (->> - (for [[invoice-id invoice-expense-account-id target-account target-date amount _ location] (drop 1 data) + (for [[i invoice-expense-account-id target-account target-date amount _ location] (drop 1 data) :let [ - invoice-id (Long/parseLong invoice-id) + invoice-id (i->invoice-id i) invoice (d/entity db invoice-id) current-total (:invoice/total invoice) @@ -511,7 +516,8 @@ (:db/id (first (:invoice/expense-accounts invoice))) (d/tempid :db.part/user)) invoice-expense-account (when-not new-account? - (d/entity db invoice-expense-account-id)) + (or (d/entity db invoice-expense-account-id) + (d/entity db [:invoice-expense-account/original-id invoice-expense-account-id]))) current-account-id (:db/id (:invoice-expense-account/account invoice-expense-account)) target-account-id (Long/parseLong (str/trim target-account)) @@ -519,7 +525,7 @@ current-date (:invoice/date invoice) - current-expense-account-amount (:invoice-expense-account/amount invoice-expense-account) + current-expense-account-amount (:invoice-expense-account/amount invoice-expense-account 0.0) target-expense-account-amount (- (Double/parseDouble amount)) diff --git a/src/cljc/auto_ap/ledger/reports.cljc b/src/cljc/auto_ap/ledger/reports.cljc index 7d8deba0..6fa14ba2 100644 --- a/src/cljc/auto_ap/ledger/reports.cljc +++ b/src/cljc/auto_ap/ledger/reports.cljc @@ -566,15 +566,11 @@ (into rows ;; TODO colspan ? (concat (when (seq (:journal-entries category)) - [[{:value (str "Total" ) - :bold true} - {:value (str (client-codes (:client-id category)) " - " (:location category) " - " (:name (:account category))) - :bold true} + [[{:value (str "" )} + {:value (str (client-codes (:client-id category)) " - " (:location category) " - " (:name (:account category)))} {:value ""} {:value ""} - {:value (:total category) - :format :dollar - :bold true}]]) + {:value ""}]]) (map (fn [je] [{:value (user-friendly-date (:date je))} @@ -588,18 +584,18 @@ (:journal-entries category)) [[{:value (str "Total" ) :bold true - :border [:bottom]} + :border [:top]} {:value (str (client-codes (:client-id category)) " - " (:location category) " - " (:name (:account category))) :bold true - :border [:bottom]} + :border [:top]} {:value "" - :border [:bottom]} + :border [:top]} {:value "" - :border [:bottom]} + :border [:top]} {:value (:total category) :format :dollar :bold true - :border [:bottom]}]])) + :border [:top]}]])) ) []