diff --git a/migrator/migrations/1534475443-DOWN-update-companies.sql b/migrator/migrations/1534475443-DOWN-update-companies.sql new file mode 100644 index 00000000..5a30112a --- /dev/null +++ b/migrator/migrations/1534475443-DOWN-update-companies.sql @@ -0,0 +1 @@ +-- 1534475443 DOWN update-companies \ No newline at end of file diff --git a/migrator/migrations/1534475443-UP-update-companies.sql b/migrator/migrations/1534475443-UP-update-companies.sql new file mode 100644 index 00000000..eada3941 --- /dev/null +++ b/migrator/migrations/1534475443-UP-update-companies.sql @@ -0,0 +1,25 @@ +-- 1534475443 UP update-companies +DELETE FROM companies where code in +('BES', 'BSA', 'HM', 'FCF', 'INT', 'JS', 'MV', 'ORA', 'SK', 'SLO', 'WE', 'MPI'); + +INSERT INTO companies (code, name, data) +VALUES +('BES', 'Brian & Erin Skarbek', '{:locations ["CB"] }'), +('BSA', 'Be Steak A', '{:locations ["CB"] }'), +('HM', 'Hiro Mura', '{:locations ["SV"] }'), +('FCF', 'Frost Cupcake Factory', '{:locations ["CB"] }'), +('INT', 'Integreat', '{:locations ["CB"] }'), +('JS', 'Jason Skarbek', '{:locations ["CB"] }'), +('MV', 'Mio Vicino - Santa Clara', '{:locations ["SC"] }'), +('MPI', 'Moscini Pizza', '{:locations ["CB"] }'), +('ORA', 'Orale''s', '{:locations ["CB"] }'), +('SK', 'Savory Kitchen', '{:locations ["AL"] }'), +('SLO', 'Skarbek Law Offices', '{:locations ["CB"] }'), +('WE', 'Warm Elements', '{:locations ["CB"] }'); + +DELETE FROM invoices_expense_accounts where invoice_id in (select id from invoices where company_id in (select id from companies where name in ('Knock Out Grill & Bar', 'Nasch Bistro', 'Naschmarkt', 'The Socialight'))); +DELETE FROM invoices_checks where invoice_id in (select id from invoices where company_id in (select id from companies where name in ('Knock Out Grill & Bar', 'Nasch Bistro', 'Naschmarkt', 'The Socialight'))); + +DELETE FROM invoices where company_id in (select id from companies where name in ('Knock Out Grill & Bar', 'Nasch Bistro', 'Naschmarkt', 'The Socialight')); +DELETE FROM checks where company_id in (select id from companies where name in ('Knock Out Grill & Bar', 'Nasch Bistro', 'Naschmarkt', 'The Socialight')); +DELETE FROM companies where name in ('Knock Out Grill & Bar', 'Nasch Bistro', 'Naschmarkt', 'The Socialight'); diff --git a/resources/new-bank-accounts.csv b/resources/new-bank-accounts.csv new file mode 100644 index 00000000..e6f14084 --- /dev/null +++ b/resources/new-bank-accounts.csv @@ -0,0 +1,31 @@ +Bella Saratoga BSG - Capitol One Card - 5729 16551129 Capital One CC NA 5729 NA NA +Bella Saratoga BSG - Capitol One Card 5814 16551286 Capital One CC NA 5814 NA NA +Brian & Erin Skarbek SBE Chase Checking 16421865 Chase Bank, NA 322271627 4440034059 90-7162/3222 10000 +Be Steak A CSH - Chase Bus Platinum Checking 16417200 Chase Bank, NA 322271627 876352191 90-7162/3222 10000 +Hiro Mura HIM WF Checking  9522 16421944 Wells Fargo 121042882 5700859522 11-4288/1210 10000 +Hiro Mura HIM WF Payroll 7599 16421943 Wells Fargo 121042882 7599 11-4288/1210 10000 +Hiro Mura HIM WF CC Derik 2418 16421945 Wells Fargo NA 2418 NA NA +Hiro Mura HIM WF CC Todd 6993 16421946 Wells Fargo NA 6993 NA NA +Hiro Mura HIM Citi Visa Costco 9392 16428403 Citi Visa CC NA 9392 NA NA +Integreat BSK Chase BSK Main 16421862 Chase Bank, NA 322271627 793785572 90-7162/3222 10000 +Integreat BSK Chase BSK Ink 16421963 Chase CC NA 8362 NA NA +Jason Skarbek JMS - BofA Checking 16428443 Bank of America 121000358 3275 11-35/1210 10000 +Mio Vicino - Santa Clara MVSC - BofA Main - 2799 16422493 Bank of America 121000358 42902799 11-35/1210 10000 +Mio Vicino - Santa Clara MVSC - BofA Payroll - 2283 16422492 Bank of America 121000358 2283 11-35/1210 10000 +Mio Vicino - Santa Clara MVSC - BofA Inv - 5537 16422491 Bank of America NA 5537 NA NA +Mio Vicino - Santa Clara MVSC - BofA Corp Card Main - 5918 16422494 BofA CC NA 5918 NA NA +Mio Vicino - Santa Clara MVSC - BofA Corp Card John - 6485 16422495 BofA CC NA 6485 NA NA +Moscini Pizza MPI - Cap One - CB 0065 16550810 Capital One CC 65 NA NA +Moscini Pizza MPI - Cap One - SC 8392 16550811 Capital One CC 8392 NA NA +Moscini Pizza MPI - Cap One - BM 8396 16551102 Capital One CC 8396 NA NA +Orale's OMG - WF Business Checking 16422285 Wells Fargo 121042882 7319440462 11-4288/1210 10000 +Orale's OMG - BofA CC 4914 16422296 BofA CC NA 4914 NA NA +Savory Kitchen SK - Citi Card 16428420 Citi CC NA 3039 NA NA +Skarbek Law Offices SLO Chase SLO Main 16421863 Chase Bank, NA 322271627 571585533 90-7162/3222 10000 +Skarbek Law Offices SLO Chase Payroll 16421869 Chase Bank, NA 322271627 3110388457 90-7162/3222 10000 +Skarbek Law Offices SLO Chase UD Exp 16421860 Chase Bank, NA 322271627 891155269 90-7162/3222 10000 +Skarbek Law Offices SLO IOLTA 16421861 Chase Bank, NA 322271627 987982816 90-7162/3222 10000 +Skarbek Law Offices SLO Chase CC 16421962 Chase CC NA 6088 NA NA +Skarbek Law Offices LTE Chase Main 16421864 Chase Bank, NA 322271627 259687089 90-7162/3222 10000 +Warm Elements HOB - AmEx Card 16428453 Amex CC NA 51009 NA NA +Warm Elements HOB - AmEx Card 16428453 Amex CC 51009 NA NA \ No newline at end of file diff --git a/scratch-sessions/add-bank-accounts.clj b/scratch-sessions/add-bank-accounts.clj new file mode 100644 index 00000000..1d8be756 --- /dev/null +++ b/scratch-sessions/add-bank-accounts.clj @@ -0,0 +1,64 @@ +;; This buffer is for Clojure experiments and evaluation. +;; Press C-j to evaluate the last expression. + +(require #_'[clojure.data.csv :as csv] + '[clojure.java.io :as io] + '[auto-ap.db.companies :as c] + '[clojure.string :as str] + '[auto-ap.utils :refer [by]]) + +(def companies (by :name (c/get-all))) +#_ (defonce rows (with-open [reader (io/reader "resources/new-bank-accounts.csv")] + (doall + (csv/read-csv reader :separator \tab)))) +(defonce all-rows (list ["Bella Saratoga" "BSG - Capitol One Card - 5729" "16551129" "Capital One CC" "NA" "5729" "NA" "NA"] + ["Bella Saratoga" "BSG - Capitol One Card 5814" "16551286" "Capital One CC" "NA" "5814" "NA" "NA"] + ["Brian & Erin Skarbek" "SBE Chase Checking" "16421865" "Chase Bank, NA" "322271627" "4440034059" "90-7162/3222" "10000"] + ["Be Steak A" "CSH - Chase Bus Platinum Checking" "16417200" "Chase Bank, NA" "322271627" "876352191" "90-7162/3222" "10000"] + ["Hiro Mura" "HIM WF Checking  9522" "16421944" "Wells Fargo" "121042882" "5700859522" "11-4288/1210" "10000"] + ["Hiro Mura" "HIM WF Payroll 7599" "16421943" "Wells Fargo" "121042882" "7599" "11-4288/1210" "10000"] + ["Hiro Mura" "HIM WF CC Derik 2418" "16421945" "Wells Fargo" "NA" "2418" "NA" "NA"] + ["Hiro Mura" "HIM WF CC Todd 6993" "16421946" "Wells Fargo" "NA" "6993" "NA" "NA"] + ["Hiro Mura" "HIM Citi Visa Costco 9392" "16428403" "Citi Visa CC" "NA" "9392" "NA" "NA"] + ["Integreat" "BSK Chase BSK Main" "16421862" "Chase Bank, NA" "322271627" "793785572" "90-7162/3222" "10000"] + ["Integreat" "BSK Chase BSK Ink" "16421963" "Chase CC" "NA" "8362" "NA" "NA"] + ["Jason Skarbek" "JMS - BofA Checking" "16428443" "Bank of America" "121000358" "3275" "11-35/1210" "10000"] + ["Mio Vicino - Santa Clara" "MVSC - BofA Main - 2799" "16422493" "Bank of America" "121000358" "42902799" "11-35/1210" "10000"] + ["Mio Vicino - Santa Clara" "MVSC - BofA Payroll - 2283" "16422492" "Bank of America" "121000358" "2283" "11-35/1210" "10000"] + ["Mio Vicino - Santa Clara" "MVSC - BofA Inv - 5537" "16422491" "Bank of America" "NA" "5537" "NA" "NA"] + ["Mio Vicino - Santa Clara" "MVSC - BofA Corp Card Main - 5918" "16422494" "BofA CC" "NA" "5918" "NA" "NA"] + ["Mio Vicino - Santa Clara" "MVSC - BofA Corp Card John - 6485" "16422495" "BofA CC" "NA" "6485" "NA" "NA"] + ["Moscini Pizza" "MPI - Cap One - CB 0065" "16550810" "Capital One CC" "" "65" "NA" "NA"] + ["Moscini Pizza" "MPI - Cap One - SC 8392" "16550811" "Capital One CC" "" "8392" "NA" "NA"] + ["Moscini Pizza" "MPI - Cap One - BM 8396" "16551102" "Capital One CC" "" "8396" "NA" "NA"] + ["Orale's" "OMG - WF Business Checking" "16422285" "Wells Fargo" "121042882" "7319440462" "11-4288/1210" "10000"] + ["Orale's" "OMG - BofA CC 4914" "16422296" "BofA CC" "NA" "4914" "NA" "NA"] + ["Savory Kitchen" "SK - Citi Card" "16428420" "Citi CC" "NA" "3039" "NA" "NA"] + ["Skarbek Law Offices" "SLO Chase SLO Main" "16421863" "Chase Bank, NA" "322271627" "571585533" "90-7162/3222" "10000"] + ["Skarbek Law Offices" "SLO Chase Payroll" "16421869" "Chase Bank, NA" "322271627" "3110388457" "90-7162/3222" "10000"] + ["Skarbek Law Offices" "SLO Chase UD Exp" "16421860" "Chase Bank, NA" "322271627" "891155269" "90-7162/3222" "10000"] + ["Skarbek Law Offices" "SLO IOLTA" "16421861" "Chase Bank, NA" "322271627" "987982816" "90-7162/3222" "10000"] + ["Skarbek Law Offices" "SLO Chase CC" "16421962" "Chase CC" "NA" "6088" "NA" "NA"] + ["Skarbek Law Offices" "LTE Chase Main" "16421864" "Chase Bank, NA" "322271627" "259687089" "90-7162/3222" "10000"] + ["Warm Elements" "HOB - AmEx Card" "16428453" "Amex CC" "NA" "51009" "NA" "NA"] ["Warm Elements" "HOB - AmEx Card" "16428453" "Amex CC" "" "51009" "NA" "NA"])) + +(doseq [[company-name nickname yodlee-account-id bank routing account bank-code starting-at] all-rows] + (let [company-name (str/trim company-name)] + + (println (str "adding '" company-name "' : " (companies company-name))) + (c/add-bank-account (:id (companies company-name)) + {:number account + :name nickname + :yodlee-account-id (Integer/parseInt yodlee-account-id) + :bank-name bank + :routing (if (#{"NA" ""} routing) + nil + routing) + :bank-code (if (#{"NA" ""} bank-code) + nil + bank-code) + :check-number (if (#{"NA" ""} starting-at) + nil + (Integer/parseInt starting-at))}))) + + diff --git a/src/cljs/auto_ap/views/components/typeahead.cljs b/src/cljs/auto_ap/views/components/typeahead.cljs index 095bec52..2f4d4b0e 100644 --- a/src/cljs/auto_ap/views/components/typeahead.cljs +++ b/src/cljs/auto_ap/views/components/typeahead.cljs @@ -18,9 +18,10 @@ ] (r/create-class {:reagent-render (fn [{:keys [matches on-change field text-field value class not-found-description]}] + (let [text @text valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range)) - :when (str/includes? (.toLowerCase t) (.toLowerCase text))] + :when (str/includes? (or (some-> t .toLowerCase) "") (or (some-> text .toLowerCase) ""))] match)) valid-matches (if (and not-found-description text) (concat valid-matches [[:not-found (not-found-description text) (not-found-value text)]]) @@ -68,6 +69,7 @@ false) true)) :on-change (fn [e] + (println valid-matches) (reset! highlighted (ffirst valid-matches)) (select [nil (.. e -target -value)]))} ]) diff --git a/src/cljs/auto_ap/views/pages/admin/excel_import.cljs b/src/cljs/auto_ap/views/pages/admin/excel_import.cljs index 04dfaba4..eca73fae 100644 --- a/src/cljs/auto_ap/views/pages/admin/excel_import.cljs +++ b/src/cljs/auto_ap/views/pages/admin/excel_import.cljs @@ -3,8 +3,11 @@ (:require [re-frame.core :as re-frame] [reagent.core :as reagent] [auto-ap.subs :as subs] + [auto-ap.events :as all-events] [auto-ap.events.admin.companies :as events] [auto-ap.entities.companies :as entity] + + [auto-ap.views.components.typeahead :refer [typeahead]] [auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]] [cljs.reader :as edn] [auto-ap.routes :as routes] @@ -16,6 +19,11 @@ (fn [db] (::excel-import db))) +(re-frame/reg-sub + ::expense-accounts + (fn [db] + (::expense-accounts db))) + (re-frame/reg-event-db ::change (fn [db [_ field v]] @@ -71,13 +79,15 @@ ::create-vendors (fn [{:keys [db]}] (let [excel-import (::excel-import db)] + (println (::expense-accounts db)) {:https {:requests (map (fn [v] {:token (:user db) :method :post - :body (pr-str {:name v}) + :body (pr-str {:name v :default-expense-account (-> db ::expense-accounts (get v) :default-expense-account) }) :headers {"Content-Type" "application/edn"} :uri (str "/api/vendors/")}) - (get-in db [::excel-import :create-vendors])) + (doto (get-in db [::excel-import :create-vendors]) + println)) :on-success [::create-vendor-complete] :on-error [::create-vendor-error]} :db (-> db @@ -98,7 +108,11 @@ (let [{{:keys [vendors-not-found already-imported imported]} :rows :keys [create-vendors] :or {create-vendors #{}} - :as excel-import-data} @(re-frame/subscribe [::excel-import])] + :as excel-import-data} @(re-frame/subscribe [::excel-import]) + data @(re-frame/subscribe [::expense-accounts]) + + chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) + change-event [::all-events/change-form [::expense-accounts]]] [:div [:h1.title "Import Invoices from Integreat Excel"] (when (seq vendors-not-found) @@ -113,17 +127,26 @@ ^{:key i} [:div.column (for [v vendor-group] - ^{:key v} [:div.control - [:label.checkbox - [:input {:value v - :checked (if (create-vendors v) - "checked" - "") + ^{:key v} [:div.field.is-grouped + [:p.control + [:label.checkbox + [:input {:value v + :checked (if (create-vendors v) + "checked" + "") - :type "checkbox" - :on-change (fn [] - (re-frame/dispatch [::toggle-vendor v]))}] - (str " " v)]])])] + :type "checkbox" + :on-change (fn [] + (re-frame/dispatch [::toggle-vendor v]))}] + (str " " v)]] + + [:p.control + [bind-field + [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) chooseable-expense-accounts) + :type "typeahead" + :field [v :default-expense-account] + :event change-event + :subscription data}]]]])])] [:div [:button.button.is-pulled-right {:on-click (dispatch-event [::create-vendors]) diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 811a9cff..de41b5b9 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -554,7 +554,7 @@ (for [{:keys [id number name]} (:bank-accounts current-company)] ^{:key id} [:option {:value id} name])]]]] - [:table.table + [:table.table.is-fullwidth [:thead [:tr [:th "Vendor"]