Skip to content

Commit

Permalink
Make outsourcing possible in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco van 't Veer committed Jun 11, 2024
1 parent d95703b commit 760657e
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 47 deletions.
26 changes: 13 additions & 13 deletions src/dil_demo/erp/web.clj
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,19 @@
(POST "/publish-:id" {:keys [::store/store]
{:keys [id]} :params}
(when-let [consignment (get-consignment store id)]
(-> (str "published-" id)
(redirect :see-other)
(assoc :flash {:success "Transportopdracht aangemaakt"})
(assoc ::store/commands [[:put! :consignments
(assoc consignment :status "requested")]
[:publish! ;; to warehouse WMS
:transport-orders
(otm/consignment-warehouse-eori consignment)
(otm/consignment->transport-order consignment)]
[:publish! ;; to carrier TMS
:trips
(otm/consignment-carrier-eori consignment)
(otm/consignment->trip consignment)]]))))
(let [consignment (otm/consignment-status! consignment otm/status-requested)]
(-> (str "published-" id)
(redirect :see-other)
(assoc :flash {:success "Transportopdracht aangemaakt"})
(assoc ::store/commands [[:put! :consignments consignment]
[:publish! ;; to warehouse WMS
:transport-orders
(otm/consignment-warehouse-eori consignment)
(otm/consignment->transport-order consignment)]
[:publish! ;; to carrier TMS
:trips
(otm/consignment-carrier-eori consignment)
(otm/consignment->trip consignment)]])))))

(GET "/published-:id" {:keys [flash master-data ::store/store]
{:keys [id]} :params}
Expand Down
47 changes: 36 additions & 11 deletions src/dil_demo/otm.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,28 @@
java.time.LocalDateTime
java.time.format.DateTimeFormatter))

;; standard OTM
(def status-draft "draft")
(def status-requested "requested")
(def status-confirmed "confirmed")
(def status-in-transit "inTransit")
(def status-completed "completed")
(def status-cancelled "cancelled")

(def statuses {status-draft "Klad"
status-requested "Ingediend"
status-confirmed "Bevestigd"
;; custom for TMS
(def status-assigned "assigned")
(def status-outsourced "outsourced")

(def statuses {status-draft "Klad"
status-requested "Ingediend"
status-confirmed "Bevestigd"
status-in-transit "In Transit"
status-completed "Afgerond"
status-cancelled "Geannuleerd"})
status-completed "Afgerond"
status-cancelled "Geannuleerd"

;; custom
status-assigned "Toegewezen"
status-outsourced "Uitbesteed"})



Expand Down Expand Up @@ -86,6 +95,9 @@
(defn consignment-status [{:keys [status]}]
status)

(defn consignment-status! [consignment status]
(assoc consignment :status status))

(defn consignment-goods [{[{{:keys [description]} :entity}] :goods}]
description)

Expand Down Expand Up @@ -207,12 +219,13 @@
(time-stamp
{:id (str (UUID/randomUUID))
:external-attributes {:consignment-ref (consignment-ref consignment)}
:status (consignment-status consignment)

:actors
[{:association-type "inline"
:roles #{"carrier"}
:roles #{"carrier"}
:entity
{:contact-details [{:type "eori"
{:contact-details [{:type "eori"
:value (consignment-carrier-eori consignment)}]}}]

:actions
Expand All @@ -235,22 +248,23 @@
:geo-reference {}}}
:remarks (consignment-unload-remarks consignment)}}]}))

(defn map->trip [{:keys [id ref load-date load-location load-remarks unload-date unload-location unload-remarks carrier-eori driver-id-digits license-plate]}]
(defn map->trip [{:keys [id ref status load-date load-location load-remarks unload-date unload-location unload-remarks carrier-eori driver-id-digits license-plate]}]
{:id id
:external-attributes {:consignment-ref ref}
:status status

:vehicle
[{:association-type "inline"
:entity {:license-plate license-plate}}]

:actors
[{:association-type "inline"
:roles #{"carrier"}
:roles #{"carrier"}
:entity
{:contact-details [{:type "eori"
{:contact-details [{:type "eori"
:value carrier-eori}]}}
{:association-type "inline"
:roles #{"driver"}
:roles #{"driver"}
:entity
{:external-attributes {:id-digits driver-id-digits}}}]

Expand All @@ -277,6 +291,12 @@
(defn trip-ref [trip]
(get-in trip [:external-attributes :consignment-ref]))

(defn trip-status [trip]
(get trip :status))

(defn trip-status! [trip status]
(assoc trip :status status))

(defn trip-action [{:keys [actions]} action-type]
(->> actions
(map :entity)
Expand Down Expand Up @@ -326,6 +346,10 @@
(first)
:value))

(defn trip-carrier-eori! [trip _carrier-eori]
;; TODO
trip)

(defn trip-driver-id-digits [trip]
(-> trip
(trip-actor "driver")
Expand All @@ -349,6 +373,7 @@

(defn trip->map [trip]
{:id (:id trip)
:status (trip-status trip)
:ref (trip-ref trip)
:load-date (trip-load-date trip)
:load-location (trip-load-location trip)
Expand Down
108 changes: 88 additions & 20 deletions src/dil_demo/tms/web.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[:table
[:thead
[:tr
[:th.status "Status"]
[:th.date "Ophaaldatum"]
[:th.ref "Klantorder nr."]
[:th.location "Ophaaladres"]
Expand All @@ -31,9 +32,10 @@
[:td {:colspan 999}
"Nog geen transportopdrachten geregistreerd.."]])

(for [{:keys [id ref load-date load-location unload-location driver-id-digits license-plate]}
(for [{:keys [id ref status load-date load-location unload-location driver-id-digits license-plate]}
(map otm/trip->map trips)]
[:tr.trip
[:td.status (otm/statuses status)]
[:td.date load-date]
[:td.ref ref]
[:td.location (warehouses load-location)]
Expand All @@ -43,6 +45,8 @@
[:td.actions
[:ul
[:li [:a.button.button-secondary {:href (str "assign-" id)} "Openen"]]
(when-not (= otm/status-outsourced status)
[:li [:a.button.button-secondary {:href (str "outsource-" id)} "Outsource"]])
[:li (w/delete-button (str "trip-" id))]]]])]])

(defn qr-code-dil-demo [{:keys [carrier-eori driver-id-digits license-plate]}]
Expand Down Expand Up @@ -71,17 +75,11 @@
[:div.actions
[:a.button {:href "../chauffeur/"} "Terug naar overzicht"]]])

(defn assign-trip [trip {:keys [warehouses warehouse-addresses]}]
(let [{:keys [ref carrier-eori load-date load-location load-remarks unload-date unload-location unload-remarks driver-id-digits license-plate]
:as params}
(defn trip-details [trip {:keys [warehouses warehouse-addresses]}]
(let [{:keys [ref load-date load-location load-remarks unload-date unload-location unload-remarks]}
(otm/trip->map trip)]
[:form {:method "POST"}
(w/anti-forgery-input)

[:section
[:section.details
(when (and carrier-eori driver-id-digits license-plate)
(qr-code-dil-demo params))

[:dl
[:div
[:dt "Klantorder nr."]
Expand All @@ -107,10 +105,21 @@
(when-let [address (get d/locations unload-location)]
[:pre address])
(when-not (string/blank? unload-remarks)
[:blockquote.remarks unload-remarks])]]
[:blockquote.remarks unload-remarks])]]]))

(defn assign-trip [trip master-data]
(let [{:keys [carrier-eori driver-id-digits license-plate] :as params}
(otm/trip->map trip)]
[:form {:method "POST"}
(w/anti-forgery-input)

(when (and carrier-eori driver-id-digits license-plate)
(qr-code-dil-demo params))

(trip-details trip master-data)

(w/field {:name "driver-id-digits", :value driver-id-digits
:label "Rijbewijs", :placeholder "Laatste 4 cijfers"
:label "Rijbewijs", :placeholder "Laatste 4 cijfers"
:type "text", :pattern "\\d{4}", :required true})
(w/field {:name "license-plate", :value license-plate
:label "Kenteken",
Expand Down Expand Up @@ -142,6 +151,35 @@
[:pre.json (w/to-json trip)]]
(w/ishare-log-intercept-to-hiccup ishare-log)]]]))

(defn outsource-trip [trip {:keys [carriers] :as master-data}]
[:form {:method "POST"}
(w/anti-forgery-input)

(trip-details trip master-data)

[:section
(let [carriers (into {nil nil} carriers)]
(w/field {:label "Vervoerder"
:name "carrier-eori", :required true
:type "select", :list carriers}))]

[:div.actions
[:button.button-primary {:type "submit"} "Uitbesteden"]
[:a.button {:href "."} "Annuleren"]]])

(defn outsourced-trip [trip {:keys [ishare-log]}]
(let [{:keys [ref]} (otm/trip->map trip)]
[:div
[:section
[:p "Transportopdracht " [:q ref] " uitbesteed."]

[:div.actions
[:a.button {:href "."} "Terug naar overzicht"]]]
[:details.explanation
[:summary "Uitleg"]
[:ol
(w/ishare-log-intercept-to-hiccup ishare-log)]]]))

(defn deleted-trip [{:keys [ishare-log]}]
[:div
[:section
Expand Down Expand Up @@ -170,7 +208,7 @@

(def ^:dynamic *slug* nil)

(defn make-handler [{:keys [id site-name]}]
(defn make-handler [{:keys [id site-name], own-eori :eori}]
(let [slug (name id)
render (fn render [title main flash & {:keys [slug-postfix]}]
(w/render-body (str slug slug-postfix)
Expand Down Expand Up @@ -215,7 +253,7 @@
::store/keys [store]
{:keys [id]} :params}
(when-let [trip (get-trip store id)]
(render (str "Transportopdracht: " (otm/trip-ref trip))
(render (str "Toewijzen: " (otm/trip-ref trip))
(assign-trip trip master-data)
flash)))

Expand All @@ -224,12 +262,14 @@
driver-id-digits
license-plate]} :params}
(when-let [trip (get-trip store id)]
(-> (str "assigned-" id)
(redirect :see-other)
(assoc :flash {:success "Chauffeur en kenteken toegewezen"})
(assoc ::store/commands [[:put! :trips (-> trip
(otm/trip-driver-id-digits! driver-id-digits)
(otm/trip-license-plate! license-plate))]]))))
(let [trip (-> trip
(otm/trip-status! otm/status-assigned)
(otm/trip-driver-id-digits! driver-id-digits)
(otm/trip-license-plate! license-plate))]
(-> (str "assigned-" id)
(redirect :see-other)
(assoc :flash {:success "Chauffeur en kenteken toegewezen"})
(assoc ::store/commands [[:put! :trips trip]])))))

(GET "/assigned-:id" {:keys [flash]
::store/keys [store]
Expand All @@ -238,4 +278,32 @@
(when-let [trip (get-trip store id)]
(render (str "Transportopdracht toegewezen")
(assigned-trip trip {:ishare-log ishare-log})
flash)))

(GET "/outsource-:id" {:keys [flash master-data]
::store/keys [store]
{:keys [id]} :params}
(when-let [trip (get-trip store id)]
(render (str "Uitbesteden: " (otm/trip-ref trip))
(outsource-trip trip (-> master-data
;; can't outsource to ourselves
(update :carriers dissoc own-eori)))
flash)))

(POST "/outsource-:id" {::store/keys [store]
{:keys [id carrier-eori]} :params}
(when-let [trip (get-trip store id)]
(let [trip (otm/trip-carrier-eori! trip carrier-eori)]
(-> (str "outsourced-" id)
(redirect :see-other)
(assoc :flash {:success "Naar vervoerder gestuurd"})
(assoc ::store/commands [[:put! :trips (otm/trip-status! trip otm/status-outsourced)]
[:publish! :trips carrier-eori trip]])))))

(GET "/outsourced-:id" {:keys [flash master-data]
::store/keys [store]
{:keys [id]} :params}
(when-let [trip (get-trip store id)]
(render "Transportopdracht uitbesteed"
(outsourced-trip trip master-data)
flash))))))
30 changes: 27 additions & 3 deletions test/dil_demo/tms/web_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,36 @@
(is (re-find #"\b31415\b" body))))

(testing "POST /assign-31415"
(let [{:keys [status ::store/commands]} (do-request :post "/assign-31415"
{:driver-id-digits "1234"
:license-plate "AB-01-ABC"})]
(let [{:keys [status
headers
::store/commands]} (do-request :post "/assign-31415"
{:driver-id-digits "1234"
:license-plate "AB-01-ABC"})]
(is (= http-status/see-other status))
(is (= "assigned-31415" (get headers "Location")))
(is (= [:put! :trips] (->> commands first (take 2))))))

(testing "GET /outsource-31415"
(let [{:keys [status headers body]} (do-request :get "/outsource-31415")]
(is (= http-status/ok status))
(is (= "text/html; charset=utf-8" (get headers "Content-Type")))
(is (re-find #"\b31415\b" body))))

(testing "POST /outsource-31415"
(let [{:keys [status
headers
::store/commands]} (do-request :post "/outsource-31415"
{:carrier-eori "EU.EORI.OTHER"})]
(is (= http-status/see-other status))
(is (= "outsourced-31415" (get headers "Location")))
(is (= [:put! :trips] (->> commands first (take 2))))))

(testing "GET /outsourced-31415"
(let [{:keys [status headers body]} (do-request :get "/outsourced-31415")]
(is (= http-status/ok status))
(is (= "text/html; charset=utf-8" (get headers "Content-Type")))
(is (re-find #"\b31415\b" body))))

(testing "GET /chauffeur/"
(let [{:keys [status headers body]} (do-request :get "/chauffeur/")]
(is (= http-status/ok status))
Expand Down

0 comments on commit 760657e

Please sign in to comment.