From a1773114f56b1cfdd1552713f167175df488191a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A4in=C3=B6=20Ala-H=C3=A4rk=C3=B6nen?= Date: Wed, 18 Dec 2024 16:34:54 +0200 Subject: [PATCH] OK-719 first stab at setting tuition payment obligation together with application payment obligation --- .../ataru/applications/application_store.clj | 5 +++ .../kk_application_payment.clj | 3 +- ...application_payment_status_updater_job.clj | 44 +++++++++++++++++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/clj/ataru/applications/application_store.clj b/src/clj/ataru/applications/application_store.clj index 537357951c..315c0d6841 100644 --- a/src/clj/ataru/applications/application_store.clj +++ b/src/clj/ataru/applications/application_store.clj @@ -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) diff --git a/src/clj/ataru/kk_application_payment/kk_application_payment.clj b/src/clj/ataru/kk_application_payment/kk_application_payment.clj index 0953503b94..514f8a1bf1 100644 --- a/src/clj/ataru/kk_application_payment/kk_application_payment.clj +++ b/src/clj/ataru/kk_application_payment/kk_application_payment.clj @@ -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))) diff --git a/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj b/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj index 0f06064b92..ab84cfed7b 100644 --- a/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj +++ b/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj @@ -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] @@ -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." @@ -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}] @@ -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]