Skip to content

Commit

Permalink
OK-719 first stab at setting tuition payment obligation together with…
Browse files Browse the repository at this point in the history
… application payment obligation
  • Loading branch information
vaeinoe committed Dec 18, 2024
1 parent d68ab11 commit a177311
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/clj/ataru/applications/application_store.clj
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,11 @@
(when (or (and (= "not-obligated" (:state review-to-store))
(= "unreviewed" (:state existing-requirement-review "unreviewed")))
(and (= "unreviewed" (:state review-to-store))
(= "not-obligated" (:state existing-requirement-review))
automatically-changed?)
(and (= "obligated" (:state review-to-store))
(= "unreviewed" (:state existing-requirement-review "unreviewed")))
(and (= "obligated" (:state review-to-store))
(= "not-obligated" (:state existing-requirement-review))
automatically-changed?))
(queries/yesql-upsert-application-hakukohde-review! review-to-store connection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
(time/plus (time/today-at 12 0 0)
(time/days kk-application-payment-due-days))))

; This could be done automatically on every DB select, but needed so rarely that let's just convert on demand.
(defn parse-due-date
"Convert due date retrieved from db to local date, interpreting it in correct time zone"
"Convert due date timestamp retrieved from db to local date"
[due-date]
(time/local-date (time/year due-date) (time/month due-date) (time/day due-date)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[clj-time.core :as time]
[clj-time.format :as f]
[clojure.java.jdbc :as jdbc]
[clojure.string :as str]
[taoensso.timbre :as log]
[ataru.config.core :refer [config]]
[ataru.kk-application-payment.kk-application-payment-email-job :as email-job]
Expand Down Expand Up @@ -119,6 +120,36 @@
(payment/get-valid-payment-info-for-application-id tarjonta-service application-id)
(payment/get-valid-payment-info-for-application-key tarjonta-service application-key))))

(defn- oid-if-needs-tuition-fee
[hakukohde]
(let [codes (->> (:opetuskieli-koodi-urit hakukohde)
(map #(first (str/split % #"#")))
set)]
(when (and (seq codes)
(not (contains? codes "oppilaitoksenopetuskieli_1")) ; fi
(not (contains? codes "oppilaitoksenopetuskieli_2")) ; sv
(not (contains? codes "oppilaitoksenopetuskieli_3"))) ; fi/sv
(:oid hakukohde))))

(defn- mark-tuition-fee-obligated
"Marks tuition fee (lukuvuosimaksu) obligation for application key for every hakukohde that does not organize
studies in Finnish and/or Swedish."
[{:keys [tarjonta-service]} application-key]
(let [application (application-store/get-latest-application-by-key application-key)
hakukohde-oids (:hakukohde application)
hakukohteet (tarjonta/get-hakukohteet
tarjonta-service
(remove nil? hakukohde-oids))
tuition-hakukohde-oids (remove nil? (map oid-if-needs-tuition-fee hakukohteet))]
(doseq [hakukohde-oid tuition-hakukohde-oids]
(log/info "Marking tuition payment obligation due to kk application fee eligibility for application key"
application-key "and hakukohde oid" hakukohde-oid)
(application-store/save-payment-obligation-automatically-changed
application-key
hakukohde-oid
"payment-obligation"
"obligated"))))

(defn- invalidate-maksut-payments-if-needed
"Whenever a payment for a term is made, other payment invoices for the person and term
should be invalidated to avoid accidental double payments."
Expand All @@ -132,8 +163,9 @@

(defn update-kk-payment-status-for-person-handler
"Updates payment requirement status for a single (person oid, term, year) either directly or
via an application id/key. Creates payments and sends e-mails when necessary. Marking status as paid/overdue
is done separately via kk-application-payment-maksut-poller-job, never here."
via an application id/key. Creates payments and sends e-mails when necessary. Also marks tuition fee obligation
if necessary. Marking status as paid/overdue is done separately via kk-application-payment-maksut-poller-job,
never here."
[{:keys [person_oid term year application_id application_key]}
{:keys [ohjausparametrit-service person-service tarjonta-service
koodisto-cache get-haut-cache maksut-service] :as job-runner}]
Expand All @@ -151,7 +183,13 @@
(let [new-state (:state payment)]
(cond
(= (:awaiting payment/all-states) new-state)
(create-payment-and-send-email job-runner maksut-service payment))))
(do
(create-payment-and-send-email job-runner maksut-service payment)
; If application payment is required, tuition fee will be always required as well.
(mark-tuition-fee-obligated job-runner (:application-key payment)))

(= (:ok-by-proxy payment/all-states) new-state)
(mark-tuition-fee-obligated job-runner (:application-key payment)))))

(doseq [application-payment existing-payments]
(let [{:keys [application payment]} application-payment]
Expand Down

0 comments on commit a177311

Please sign in to comment.