supports location matches, adds invoice types
This commit is contained in:
@@ -8,6 +8,11 @@
|
|||||||
:where [?e :client/name]]
|
:where [?e :client/name]]
|
||||||
(d/db (d/connect uri)))
|
(d/db (d/connect uri)))
|
||||||
(map first)
|
(map first)
|
||||||
|
(map (fn [c]
|
||||||
|
(update c :client/location-matches
|
||||||
|
(fn [lms]
|
||||||
|
|
||||||
|
(map #(assoc % :location-match/match (first (:location-match/matches %))) lms)))))
|
||||||
(map (fn [c]
|
(map (fn [c]
|
||||||
(update c :client/bank-accounts
|
(update c :client/bank-accounts
|
||||||
(fn [bas]
|
(fn [bas]
|
||||||
|
|||||||
@@ -38,12 +38,17 @@
|
|||||||
:serialize (schema/as-conformer #(or (:ident %) (:db/ident %) %))}}
|
:serialize (schema/as-conformer #(or (:ident %) (:db/ident %) %))}}
|
||||||
:objects
|
:objects
|
||||||
{
|
{
|
||||||
|
:location_match
|
||||||
|
{:fields {:location {:type 'String}
|
||||||
|
:match {:type 'String}}}
|
||||||
|
|
||||||
:client
|
:client
|
||||||
{:fields {:id {:type :id}
|
{:fields {:id {:type :id}
|
||||||
:name {:type 'String}
|
:name {:type 'String}
|
||||||
:code {:type 'String}
|
:code {:type 'String}
|
||||||
:email {:type 'String}
|
:email {:type 'String}
|
||||||
:address {:type :address}
|
:address {:type :address}
|
||||||
|
:location_matches {:type '(list :location_match)}
|
||||||
:locations {:type '(list String)}
|
:locations {:type '(list String)}
|
||||||
:bank_accounts {:type '(list :bank_account)}}}
|
:bank_accounts {:type '(list :bank_account)}}}
|
||||||
:contact
|
:contact
|
||||||
@@ -284,6 +289,8 @@
|
|||||||
{
|
{
|
||||||
:invoice_payment_amount {:fields {:invoice_id {:type :id}
|
:invoice_payment_amount {:fields {:invoice_id {:type :id}
|
||||||
:amount {:type 'Float}}}
|
:amount {:type 'Float}}}
|
||||||
|
:edit_location_match {:fields {:location {:type 'String}
|
||||||
|
:match {:type 'String}}}
|
||||||
|
|
||||||
:edit_client {:fields {:id {:type :id}
|
:edit_client {:fields {:id {:type :id}
|
||||||
:name {:type 'String}
|
:name {:type 'String}
|
||||||
@@ -291,6 +298,7 @@
|
|||||||
:email {:type 'String}
|
:email {:type 'String}
|
||||||
:address {:type :add_address}
|
:address {:type :add_address}
|
||||||
:locations {:type '(list String)}
|
:locations {:type '(list String)}
|
||||||
|
:location_matches {:type '(list :edit_location_match)}
|
||||||
:bank_accounts {:type '(list :edit_bank_account)}}}
|
:bank_accounts {:type '(list :edit_bank_account)}}}
|
||||||
:edit_bank_account
|
:edit_bank_account
|
||||||
{:fields {:id {:type :id }
|
{:fields {:id {:type :id }
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
:client/name (:name edit_client)
|
:client/name (:name edit_client)
|
||||||
:client/email (:email edit_client)
|
:client/email (:email edit_client)
|
||||||
:client/locations (filter identity (:locations edit_client))
|
:client/locations (filter identity (:locations edit_client))
|
||||||
|
:client/location-matches (->> (:location_matches edit_client)
|
||||||
|
(filter (fn [lm] (and (:location lm) (:match lm))))
|
||||||
|
(map (fn [lm] {:location-match/location (:location lm)
|
||||||
|
:location-match/matches [(:match lm)]})))
|
||||||
:client/address (remove-nils {
|
:client/address (remove-nils {
|
||||||
:address/street1 (:street1 (:address edit_client))
|
:address/street1 (:street1 (:address edit_client))
|
||||||
:address/street2 (:street2 (:address edit_client))
|
:address/street2 (:street2 (:address edit_client))
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
[_ _ value]
|
[_ _ value]
|
||||||
value)
|
value)
|
||||||
|
|
||||||
|
(def last-text (atom nil))
|
||||||
|
|
||||||
|
|
||||||
(defn template-applies? [text {:keys [keywords]}]
|
(defn template-applies? [text {:keys [keywords]}]
|
||||||
(every? #(re-find % text) keywords))
|
(every? #(re-find % text) keywords))
|
||||||
@@ -49,7 +51,7 @@
|
|||||||
:text text}))])))
|
:text text}))])))
|
||||||
|
|
||||||
(defn parse [text]
|
(defn parse [text]
|
||||||
(println text)
|
(reset! last-text text)
|
||||||
(->> t/pdf-templates
|
(->> t/pdf-templates
|
||||||
(filter (partial template-applies? text))
|
(filter (partial template-applies? text))
|
||||||
first
|
first
|
||||||
|
|||||||
@@ -34,6 +34,20 @@
|
|||||||
:customer-identifier #"Bill To[^\n]+\n[^\n]*\n([\w ]+)\s{2,}"
|
:customer-identifier #"Bill To[^\n]+\n[^\n]*\n([\w ]+)\s{2,}"
|
||||||
:date #"Invoice #\s*\n\s*[\w\.]+\s+([\w\./]+)"
|
:date #"Invoice #\s*\n\s*[\w\.]+\s+([\w\./]+)"
|
||||||
:total #"Total\s+\$([0-9.]+)"}
|
:total #"Total\s+\$([0-9.]+)"}
|
||||||
|
:parser {:date [:clj-time "MM/dd/yy"]}}
|
||||||
|
{:vendor "DVW Commercial"
|
||||||
|
:keywords [#"DVW Commercial"]
|
||||||
|
:extract {:date #"\s*([0-9]+/[0-9]+/[0-9]+)"
|
||||||
|
:customer-identifier #"Bill To:[^\n]+\n[^\n]*\n\s*([\w ]+) \("
|
||||||
|
:invoice-number #"Invoice\s*\n\s*([\w\./]+)*"
|
||||||
|
:total #"Total:\s+\$ ([0-9.]+)"}
|
||||||
|
:parser {:date [:clj-time "MM/dd/yy"]}}
|
||||||
|
{:vendor "Daylight Foods"
|
||||||
|
:keywords [#"DAYLIGHT FOODS"]
|
||||||
|
:extract {:date #"\n\s*Date[^\n]+\n\s*([0-9]+/[0-9]+/[0-9]+)"
|
||||||
|
:customer-identifier #"Bill To:[^\n]+\n\s*([\w ]+)"
|
||||||
|
:invoice-number #"Invoice\s([\w\./]+)*"
|
||||||
|
:total #"Total Invoice\s+([0-9.]+)"}
|
||||||
:parser {:date [:clj-time "MM/dd/yy"]}}])
|
:parser {:date [:clj-time "MM/dd/yy"]}}])
|
||||||
|
|
||||||
(def excel-templates
|
(def excel-templates
|
||||||
|
|||||||
@@ -163,13 +163,15 @@
|
|||||||
_ (println imports)
|
_ (println imports)
|
||||||
|
|
||||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text] :as info}]
|
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text] :as info}]
|
||||||
|
(println "searching for" vendor-code)
|
||||||
(let [[matching-vendor default-expense-account] (->> (d/query
|
(let [[matching-vendor default-expense-account] (->> (d/query
|
||||||
(cond-> {:query {:find ['?vendor '?default-expense-account]
|
{:query {:find ['?vendor '?default-expense-account]
|
||||||
:in ['$ '?vendor-name]
|
:in ['$ '?vendor-name]
|
||||||
:where ['[?vendor :vendor/name ?vendor-name]
|
:where ['[?vendor :vendor/name ?vendor-name]
|
||||||
'[?vendor :vendor/default-expense-account ?default-expense-account]]}
|
'[?vendor :vendor/default-expense-account ?default-expense-account]]}
|
||||||
:args [(d/db (d/connect uri)) vendor-code]}))
|
:args [(d/db (d/connect uri)) vendor-code]})
|
||||||
first)
|
first)
|
||||||
|
_ (println matching-vendor)
|
||||||
matching-client (parse/best-match clients customer-identifier)
|
matching-client (parse/best-match clients customer-identifier)
|
||||||
_ (println "New invoice matches client" matching-client)
|
_ (println "New invoice matches client" matching-client)
|
||||||
matching-location (parse/best-location-match matching-client text )
|
matching-location (parse/best-location-match matching-client text )
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
:graphql {:token token
|
:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
|
|
||||||
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]
|
[:id :name :code :email :locations [:location-matches [:location :match]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]
|
||||||
[:address [:street1 :street2 :city :state :zip]]]]
|
[:address [:street1 :street2 :city :state :zip]]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
(fn [{:keys [db]} [_ token user]]
|
(fn [{:keys [db]} [_ token user]]
|
||||||
{:graphql {:token token
|
{:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]]]
|
[:id :name :code [:location-matches [:location :match]] [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
:code (:code new-client-data) ;; TODO add validation can't change
|
:code (:code new-client-data) ;; TODO add validation can't change
|
||||||
:email (:email new-client-data)
|
:email (:email new-client-data)
|
||||||
:locations (:locations new-client-data)
|
:locations (:locations new-client-data)
|
||||||
|
:location-matches (:location-matches new-client-data)
|
||||||
:address {:street1 (:street1 (:address new-client-data))
|
:address {:street1 (:street1 (:address new-client-data))
|
||||||
:street2 (:street2 (:address new-client-data)),
|
:street2 (:street2 (:address new-client-data)),
|
||||||
:city (:city (:address new-client-data))
|
:city (:city (:address new-client-data))
|
||||||
@@ -85,7 +86,7 @@
|
|||||||
:operation/name "EditClient"}
|
:operation/name "EditClient"}
|
||||||
:venia/queries [{:query/data [:edit-client
|
:venia/queries [{:query/data [:edit-client
|
||||||
{:edit-client new-client-req}
|
{:edit-client new-client-req}
|
||||||
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order]]]]}]}
|
[:id :name :code :email :locations [:location-matches [:location :match]] [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order]]]]}]}
|
||||||
:on-success [::save-complete]
|
:on-success [::save-complete]
|
||||||
:on-error [::forms/save-error ::new-client]}}
|
:on-error [::forms/save-error ::new-client]}}
|
||||||
{:db new-client-form}))))
|
{:db new-client-form}))))
|
||||||
@@ -111,6 +112,14 @@
|
|||||||
(update :locations conj (:location client))
|
(update :locations conj (:location client))
|
||||||
(dissoc :location))))
|
(dissoc :location))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::add-new-location-match
|
||||||
|
[(forms/in-form ::new-client) (re-frame/path [:data])]
|
||||||
|
(fn [client _]
|
||||||
|
(-> client
|
||||||
|
(update :location-matches conj (:location-match client))
|
||||||
|
(dissoc :location-match))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::add-new-bank-account
|
::add-new-bank-account
|
||||||
[(forms/in-form ::new-client) (re-frame/path [:data])]
|
[(forms/in-form ::new-client) (re-frame/path [:data])]
|
||||||
@@ -372,6 +381,31 @@
|
|||||||
(for [location (:locations new-client)]
|
(for [location (:locations new-client)]
|
||||||
^{:key location} [:li location ])]]]
|
^{:key location} [:li location ])]]]
|
||||||
|
|
||||||
|
[:div.field
|
||||||
|
[:p.help "Location matches"]
|
||||||
|
[:div.control
|
||||||
|
[:div.field.has-addons
|
||||||
|
|
||||||
|
[:p.control
|
||||||
|
|
||||||
|
[bind-field
|
||||||
|
[:input.input {:type "text"
|
||||||
|
:placeholder "San Jose"
|
||||||
|
:field [:location-match :match]
|
||||||
|
:event change-event
|
||||||
|
:subscription new-client}]]]
|
||||||
|
[:p.control
|
||||||
|
[bind-field
|
||||||
|
[:input.input {:type "text"
|
||||||
|
:placeholder "DT"
|
||||||
|
:field [:location-match :location]
|
||||||
|
:event change-event
|
||||||
|
:subscription new-client}]]]
|
||||||
|
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-new-location-match])} "Add"]]]
|
||||||
|
[:ul
|
||||||
|
(for [{:keys [location match]} (:location-matches new-client)]
|
||||||
|
^{:key location} [:li match "->" location ])]]]
|
||||||
|
|
||||||
[:div {:style {:padding-bottom "0.75em" :padding-top "0.75em"}}
|
[:div {:style {:padding-bottom "0.75em" :padding-top "0.75em"}}
|
||||||
[:h2.subtitle "Address"]
|
[:h2.subtitle "Address"]
|
||||||
[address-field {:field [:address]
|
[address-field {:field [:address]
|
||||||
|
|||||||
Reference in New Issue
Block a user