Nearly able to create invoices manually

This commit is contained in:
2024-03-24 22:07:17 -07:00
parent ede4d756af
commit 1ac90804b8
6 changed files with 82 additions and 106 deletions

View File

@@ -14,7 +14,6 @@ document.addEventListener('alpine:init', () => {
effect(() => {
dependent_properties(props => {
console.log("CHANGED PROPS", expression, props)
el.dispatchEvent(
new CustomEvent(value, {
props,

File diff suppressed because one or more lines are too long

View File

@@ -43,8 +43,12 @@
[manifold.deferred :as de])
(:import [java.util UUID]))
;; TODO make more reusable malli schemas, use unions if it would be helpful
;; TODO copy save logic from graphql version
;; TODO cash drawer shift
;; TODO a few bug fixes from slack
;; TOOD check pinecone
(defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
@@ -1346,14 +1350,16 @@
:validation-route ::route/navigate))
mm/Initializable
(init-step-params
[_ request]
[_ multi-form-state request]
(let [bank-account-type (get-in request [:query-params :bank-account-type])]
(cond->
{:db/id (str (java.util.UUID/randomUUID))
:new? true}
(if (= {} (:step-params multi-form-state))
(cond->
{:db/id (str (java.util.UUID/randomUUID))
:new? true}
bank-account-type (assoc :bank-account/type (keyword "bank-account-type" bank-account-type)
:bank-account/visible true))))
bank-account-type (assoc :bank-account/type (keyword "bank-account-type" bank-account-type)
:bank-account/visible true))
(:step-params multi-form-state))))
mm/Discardable
(can-discard? [_ step-params]

View File

@@ -1,28 +1,19 @@
(ns auto-ap.ssr.components.multi-modal
(:require [auto-ap.ssr.components :as com]
[auto-ap.ssr.form-cursor :as fc]
[auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]]
[auto-ap.ssr.utils
:refer [html-response
assert-schema
main-transformer
modal-response
wrap-form-4xx-2
wrap-schema-enforce]]
(:require [auto-ap.cursor :as cursor]
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.components :as com]
[auto-ap.ssr.components.timeline :as timeline]
[auto-ap.ssr.form-cursor :as fc]
[auto-ap.ssr.hx :as hx]
[auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]]
[auto-ap.ssr.svg :as svg]
[auto-ap.ssr.utils
:refer [assert-schema html-response main-transformer
modal-response wrap-form-4xx-2 wrap-schema-enforce]]
[bidi.bidi :as bidi]
[hiccup.util :as hu]
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.svg :as svg]
[auto-ap.ssr.hx :as hx]
[malli.core :as mc]
[hiccup2.core :as hiccup2]
[hiccup2.core :as hiccup]
[auto-ap.cursor :as cursor]
[malli.core :as m]
[auto-ap.logging :as alog])
(:import [auto_ap.cursor VecCursor]))
[malli.core :as m]))
(def default-form-props {:hx-ext "response-targets"
@@ -40,18 +31,12 @@
(step-name [this]))
(defprotocol Initializable
(init-step-params [this request]))
(init-step-params [this multi-form-state request]))
(defprotocol Discardable
(can-discard? [this step-params])
(discard-changes [this request]))
(defn- init-step-params- [step request]
(if (satisfies? Initializable step)
(init-step-params step request)
{}))
(defprotocol LinearModalWizard
(hydrate-from-request [this request])
(get-current-step [this])
@@ -175,7 +160,7 @@
(com/modal-card-advanced
{"@keydown.enter.prevent.stop" "$refs.next.click()"
:class (str
"w-[750px] h-[600px]
"w-full h-full md:w-[750px] md:h-[600px]
group-[.forward]/transition:htmx-swapping:opacity-0
group-[.forward]/transition:htmx-swapping:-translate-x-1/4
group-[.forward]/transition:htmx-swapping:scale-75
@@ -207,7 +192,7 @@
head)
#_(com/modal-header-attachment {})
[:div.flex.shrink.overflow-auto.grow
[:div.grow-0.pr-6.pt-2.bg-gray-100.self-stretch #_{:style "margin-left:-20px"} (render-timeline linear-wizard step validation-route)]
[:div.grow-0.pr-6.pt-2.bg-gray-100.self-stretch.hidden.md:block #_{:style "margin-left:-20px"} (render-timeline linear-wizard step validation-route)]
(com/modal-body {}
body)]
@@ -253,9 +238,11 @@
(-> request
(assoc :multi-form-state (-> (:multi-form-state request)
(merge-multi-form-state)
(select-state
(edit-path new-step request)
(init-step-params- new-step request))))))
(select-state (edit-path new-step request) {})
(#(cond-> %
(satisfies? Initializable new-step)
(assoc :step-params
(init-step-params new-step % request))))))))
:headers {"HX-reswap" (when transition-type "outerHTML swap:0.16s")
"x-transition-type" (or transition-type "none")})))
(wrap-ensure-step)

View File

@@ -40,7 +40,8 @@
children ]))
(defn vertical-timeline [params & children]
[:ol {:class "flex flex-col items-start space-y-2 text-xs text-center text-gray-500 bg-gray-100 dark:text-gray-400 sm:text-base dark:bg-gray-800 sm:space-y-4 px-2"}
[:ol {:class (hh/add-class "flex flex-col items-start space-y-2 text-xs text-center text-gray-500 bg-gray-100 dark:text-gray-400 sm:text-base dark:bg-gray-800 sm:space-y-4 px-2"
(:class params))}
children
#_[:li {:class "flex items-center"}
[:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border border-gray-500 rounded-full shrink-0 dark:border-gray-400"}]]])

View File

@@ -38,6 +38,49 @@
[:invoice-expense-account/location :string]
[:invoice-expense-account/amount money]]]]])
(defn clientize-vendor [{:vendor/keys [terms-overrides automatically-paid-when-due default-account account-overrides] :as vendor} client-id]
(let [terms-override (->> terms-overrides
(filter (fn [to]
(= (->db-id (:vendor-terms-override/client to))
client-id)))
(map :vendor-terms-override/terms)
first)
account (or (->> account-overrides
(filter (fn [to]
(= (->db-id (:vendor-account-override/client to))
client-id)))
(map :vendor-account-override/account)
first)
default-account)
account (d-accounts/clientize account client-id)
automatically-paid-when-due (->> automatically-paid-when-due
(filter (fn [to]
(= (->db-id to)
client-id)))
seq
boolean)
vendor (cond-> vendor
terms-override (assoc :vendor/terms terms-override)
true (assoc :vendor/automatically-paid-when-due automatically-paid-when-due
:vendor/default-account account)
true (dissoc :vendor/account-overrides :vendor/terms-overrides))]
vendor))
(defn get-vendor [vendor-id]
(dc/pull
(dc/db conn)
[:vendor/terms
:vendor/automatically-paid-when-due
{:vendor/default-account d-accounts/default-read
:vendor/account-overrides
[:vendor-account-override/client
{:vendor-account-override/account d-accounts/default-read}]}
{:vendor/terms-overrides
[:vendor-terms-override/client :vendor-terms-override/terms]}]
vendor-id))
(defrecord BasicDetailsStep [linear-wizard]
mm/ModalWizardStep
(step-name [_]
@@ -95,7 +138,7 @@
:content-fn (fn [c] (pull-attr (dc/db conn) :vendor/name c))
:x-model "vendorId"})]))
[:div.flex.space-x-8
[:div.flex.gap-x-8.md:flex-row.flex-col
(fc/with-field :invoice/date
(com/validated-field
{:label "Date"
@@ -126,7 +169,6 @@
:name (fc/field-name)
:x-model "due"
:x-effect "console.log('hello due', [due])"
:error? (fc/field-errors)
:placeholder "1/1/2024"})]))
(fc/with-field :invoice/scheduled-payment
@@ -138,7 +180,6 @@
:hx-put (bidi.bidi/path-for ssr-routes/only-routes ::route/scheduled-payment-date)
:x-dispatch:changed "[clientId, vendorId, due]"
:x-effect "console.log('hello', [clientId, vendorId, due])"
:hx-trigger "changed"
:hx-target "this"
:hx-swap "innerHTML"}
@@ -254,7 +295,7 @@
(defrecord AccountsStep [linear-wizard]
mm/ModalWizardStep
(step-name [_]
"Details")
"Expense Accounts")
(step-key [_]
:accounts)
@@ -293,13 +334,11 @@
:validation-route ::route/new-wizard-navigate))
mm/Initializable
(init-step-params
[_ request]
(alog/peek ::INIT {:invoice/expense-accounts [{:db/id "123"
:invoice-expense-account/amount 100}]})
[_ current request]
{:invoice/expense-accounts [{:db/id "123"
:invoice-expense-account/location "Shared"
:invoice-expense-account/account (ffirst (dc/q '[:find ?a :where [?a :account/name]]
(dc/db conn)))
:invoice-expense-account/account (:db/id (:vendor/default-account (clientize-vendor (get-vendor (->db-id (:invoice/vendor (:snapshot current))))
(->db-id (:invoice/client (:snapshot current))))))
:invoice-expense-account/amount 100}]}))
@@ -353,63 +392,7 @@
(pull-attr (dc/db conn) :account/location))
:client-locations (some->> client-id
(pull-attr (dc/db conn) :client/locations))})))
(defn clientize-vendor [{:vendor/keys [terms-overrides automatically-paid-when-due default-account account-overrides] :as vendor} client-id]
(let [terms-override (->> terms-overrides
(filter (fn [to]
(= (->db-id (:vendor-terms-override/client to))
client-id)))
(map :vendor-terms-override/terms)
first)
account (or (->> account-overrides
(filter (fn [to]
(= (->db-id (:vendor-account-override/client to))
client-id)))
(map :vendor-account-override/account)
first)
default-account)
account (d-accounts/clientize account client-id)
automatically-paid-when-due (->> automatically-paid-when-due
(filter (fn [to]
(= (->db-id to)
client-id)))
seq
boolean)
vendor (cond-> vendor
terms-override (assoc :vendor/terms terms-override)
true (assoc :vendor/automatically-paid-when-due automatically-paid-when-due
:vendor/default-account account)
true (dissoc :vendor/account-overrides :vendor/terms-overrides))]
vendor))
(comment
(clojure.pprint/pprint
(clientize-vendor (dc/pull
(dc/db conn)
[:vendor/terms
:vendor/automatically-paid-when-due
{:vendor/default-account d-accounts/default-read
:vendor/account-overrides
[:vendor-account-override/client
{:vendor-account-override/account d-accounts/default-read}]}
{:vendor/terms-overrides
[:vendor-terms-override/client :vendor-terms-override/terms]}]
(ffirst (dc/q '[:find ?v :in $ :where [?v :vendor/name "Sysco"]] (dc/db conn))))
(pull-attr (dc/db conn) :db/id [:client/code "DEMO"]))))
(defn get-vendor [vendor-id]
(dc/pull
(dc/db conn)
[:vendor/terms
:vendor/automatically-paid-when-due
{:vendor/default-account d-accounts/default-read
:vendor/account-overrides
[:vendor-account-override/client
{:vendor-account-override/account d-accounts/default-read}]}
{:vendor/terms-overrides
[:vendor-terms-override/client :vendor-terms-override/terms]}]
vendor-id))
(defn due-date [{:keys [multi-form-state]}]
(alog/peek ::date multi-form-state)