(ns auto-ap.views.pages.pos.table (:require [auto-ap.subs :as subs] [auto-ap.routes :as routes] [auto-ap.events :as events] [auto-ap.views.components.buttons :as buttons] [auto-ap.views.components.grid :as grid] [auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.pos.form :as form] [bidi.bidi :as bidi] [cemerick.url :as url] [auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]] [auto-ap.views.utils :refer [date->str nf dispatch-event-with-propagation]] [clojure.string :as str] [re-frame.core :as re-frame])) (defn row [{sales-order :sales-order selected-client :selected-client}] (let [{:keys [client date total tax tip charges source line-items id]} sales-order expected-deposits (->> charges (filter :expected-deposit) (map :expected-deposit))] [grid/row {:class (:class sales-order) :id id} (when-not selected-client [grid/cell {} (:name client)]) [grid/cell {} (date->str date)] [grid/cell {} source] [grid/cell {:class "has-text-right"} (nf total)] [grid/cell {:class "has-text-right"} (nf tax)] [grid/cell {:class "has-text-right"} (nf tip)] [grid/cell {} [:div.level-left (for [charge charges] (with-meta (condp = (:type-name charge) "CASH" [:span.icon.level-item {:style {:font-size "24px"}} [:span {:class "icon-accounting-bill" :style {:font-weight "400"}}]] "CARD" [:span.icon.level-item {:style {:font-size "24px"}} [:span {:class "icon-credit-card-1" :style {:font-weight "400"}}]] "SQUARE_GIFT_CARD" [:span.icon.level-item {:style {:font-size "24px"}} [:span {:class "icon-gift-box" :style {:font-weight "400"}}]] [:span.level-item [:span (:type-name charge) (when-let [note (:note charge)] [:span [:i.has-text-grey " (" note ")"]])] ]) {:key (:id charge)}))]] [grid/cell {} [:div.level [:div.level-left (for [charge charges] (with-meta (condp = (:processor charge) :grubhub [:img.level-item {:src "/img/grubhub.png" :style {:width "24px" :height "24px"}}] :doordash [:img.level-item {:src "/img/doordash.png" :style {:width "24px" :height "24px"}}] :uber-eats [:img.level-item {:src "/img/ubereats.png" :style {:width "24px" :height "24px"}}] :square [:img.level-item {:src "/img/square.png" :style {:width "24px" :height "24px"}}] :koala [:img.level-item {:src "/img/koala.png" :style {:width "24px" :height "24px"}}] :ezcater [:img.level-item {:src "/img/ezcater.png" :style {:width "24px" :height "24px"}}] nil) {:key (:id charge)}))]]] [grid/cell {} (str/join ", " (map :item-name line-items))] [grid/button-cell {} [:div.buttons (when (seq expected-deposits) [:<> [drop-down {:id [::links id] :is-right? true :header [buttons/fa-icon {:class "badge" :on-click (dispatch-event-with-propagation [::events/toggle-menu [::links id]]) :data-badge (str (clojure.core/count expected-deposits)) :icon "fa-paperclip"}]} [drop-down-contents [:div.dropdown-item [:table.table.grid.compact [:tbody (for [ed expected-deposits] ^{:key (:id ed)} [:tr [:td "Expected Deposit " (:id ed) ] [:td [buttons/fa-icon {:icon "fa-external-link" :href (str (bidi/path-for routes/routes :expected-deposits ) "?" (url/map->query {:exact-match-id (:id ed)}))}]]])]]]]] [:span {:style {:margin-left "1em"}}]]) [buttons/fa-icon {:event [::form/editing sales-order] :icon "fa-pencil"}]]]])) (defn table [{:keys [data-page]}] (let [selected-client @(re-frame/subscribe [::subs/client]) {:keys [data]} @(re-frame/subscribe [::data-page/page data-page])] [grid/grid {:data-page data-page :column-count (if selected-client 7 8)} [grid/controls data [:div.level-item [:div.tag "Total: " (nf (:sales-order-total data))] ] [:div.level-item [:div.tag " Tax: " (nf (:sales-order-tax data))]]] [grid/table {:fullwidth true} [grid/header {} [grid/row {} (when-not selected-client [grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"]) [grid/sortable-header-cell {:sort-key "date" :sort-name "Date" :style {:width "8em"}} "Date"] [grid/sortable-header-cell {:sort-key "source" :sort-name "Source"} "Source"] [grid/sortable-header-cell {:sort-key "total" :sort-name "Total" :class "has-text-right" :style {:width "8em"}} "Total"] [grid/sortable-header-cell {:sort-key "tax" :sort-name "Tax" :class "has-text-right" :style {:width "7em"}} "Tax"] [grid/sortable-header-cell {:sort-key "tip" :sort-name "Tip" :class "has-text-right" :style {:width "7em"}} "Tip"] [grid/header-cell {} "Payment Methods"] [grid/header-cell {} "Processor"] [grid/header-cell {} "Line Items"] [grid/header-cell {:style {:width "8em"}}]]] [grid/body (for [sales-order (:data data)] ^{:key (:id sales-order)} [row {:sales-order sales-order :selected-client selected-client}])]]]))