         tsask.pages.template-pg)
   (:require [clojure.java.jdbc :as j]
             [clojure.java.io :as io]
+            [tsask.order.crud :as order]
             [com.reasonr.scriptjure :as sj]
             [clojure.java.jdbc.sql :as sql]))
 

        [:div
          [:h2 (:form_name order)]
          [:div.requf_tit.form_control.form_head (:order_content order)]]))))

(defn delete-selected [params]
  (if (empty? (:ids params)) (redirect "/orders")
    (let [ids_ary (clojure.string/split (:ids params) #",")]
      (do
        (doseq [id ids_ary]
          (do 
            (if (.exists (io/file (str "resources/public/files/Invoice-" id ".jpg")))
              (io/delete-file (str "resources/public/files/Invoice-" id ".jpg")))
              (if (.exists (io/file (str "resources/public/files/Invoice-" id ".pdf")))
                (io/delete-file (str "resources/public/files/Invoice-" id ".pdf")))
            (j/delete! SQLDB :sa_orders (sql/where {:id id}))
            (j/delete! SQLDB :CSV_report (sql/where {:o_id id}))))
        (redirect "/orders")))))

   :body ""})

(defn index [session]
  (let [orders (not-empty (:orders session))
        sum (reduce + (for [order orders] (read-string (:payment_amt order))))]
    (binding [*js-css-files* orders-files 
              *sub-nav* nil]
      (pages
        [:dl.txtcont
         [:dt [:div.ltit [:strong "Orders in Cart"]] [:div.clear]]
         [:form {:method "post" :action "/cart/pay"}
          [:dd
           [:div.fc_con
            [:table.fcc_tab {:width "100%" :cellspacing "0" :cellpadding "0" :border "0"}
             [:tr
              [:th.sf_admin_text.sf_admin_list_th
               "Form Name"]
              [:th.sf_admin_list_th "pirce"]
              [:th.sf_admin_list_th "Actions"]]
             (for [order orders]
              [:tr
               [:td.sf_admin_text.sf_admin_list_td_form_name (:form_name order)]
               [:td.sf_admin_text.sf_admin_list_td_form_name (:payment_amt order)]
               [:td [:ul.sf_admin_td_actions
                     [:li.sf_admin_action_delete [:a "Remove"]]]]])
             ]]] 
          [:span "total: "]
          [:input {:value sum :type "text"}] 
          [:input {:value "Pay" :type "submit"}]]]))))

(defn create [params] 
  (let [order_record (order/create {:order_content (:order_content params) 
                                    :form_name (:form_name params)})]))

(defn delete [id]
  (if (.exists (io/file (str "resources/public/files/Invoice-" id ".jpg")))
