Created
July 15, 2012 10:59
-
-
Save metametaclass/3116262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns FBRest.registers.zhurnal_order | |
(:use FBRest.registers.account_sql) | |
(:use FBRest.registers.nalogreg) | |
(:use [clojure.tools.logging]) | |
) | |
;;-------------------------------------------------- | |
;;журнал-ордер | |
(defn is-90? | |
[acc] | |
(re-find #"^90/" acc) | |
) | |
(defn oborot-to-acc | |
[item] | |
(let [d (:daccnum item) | |
k (:kaccnum item) | |
] | |
(cond (is-90? d) (assoc item :Acc d :CorrAcc k :Debet true :AccName (:daccname item) :AccCode (:dc1 item) :AccCodeName (:dcname1 item) :Total (:totald item)) | |
(is-90? k) (assoc item :Acc k :CorrAcc d :Kredit true :AccName (:kaccname item) :AccCode (:kc1 item) :AccCodeName (:kcname1 item) :Total (:totalk item)) | |
:else item | |
) | |
) | |
) | |
(def valid-subaccounts | |
{"90/0100" 10001 "90/0200" 10002 "90/0300" 10003 "90/0400" 10004 "90/0401" 10005 "90/0500" 10006 "90/0600" 10007 } | |
) | |
(defn is-valid-subacc? | |
[{account :Acc}] | |
;(debugs "is-valid-subacc?" account) | |
;(debug-dump "result: " (contains? valid-subaccounts account)) | |
(valid-subaccounts account) | |
) | |
(defn is-valid-hozoper? | |
[{ho :AccCode}] | |
(not= ho 900000) | |
) | |
(defn is-valid-corresp? | |
[{corr-account :CorrAcc}] | |
(not= corr-account "99") | |
) | |
(def total-ho-code 999999) | |
(defn item-to-number | |
[{ho :AccCode}] | |
(if (= ho total-ho-code) | |
"-" | |
ho | |
) | |
) | |
(defn oborot-to-col | |
[item] | |
{:ID (:AccCode item) :Name (:AccCodeName item) :Number (item-to-number item) :Sort (:AccCode item) } | |
) | |
(defn oborot-to-row | |
[item] | |
(let [id (valid-subaccounts (:Acc item))] | |
{:ID id :Name (:AccName item) :Number (:Acc item) :Sort id } | |
) | |
) | |
(defn oborot-to-cell | |
;[[key value]] | |
[[[ColID RowID] value]] | |
{:ColID ColID :RowID RowID :Value value :StrValue "" :Details [] } | |
) | |
(defn fold-step-oborots-to-register | |
[mapping acc item] | |
(let [RowID (:RowID item) | |
ColID (:AccCode item) | |
Total (:Total item)] | |
(merge-with + acc {[ColID RowID] (or Total 0)}) | |
) | |
) | |
(defn fold-oborots-to-register | |
[mapping seq] | |
(map oborot-to-cell (reduce (partial fold-step-oborots-to-register mapping) {} seq)) | |
) | |
(defn add-total-col | |
[cell] | |
[cell (merge cell {:AccCode total-ho-code :AccCodeName "Итого"})] | |
) | |
(def old-order11-cells | |
{:SQL (fn [params] (debug (str "order11-cells:" params)) | |
[account-oborots-sql (joda-to-sql-date (params "Date")) | |
(joda-to-sql-date (params "EndDate")) | |
"90" 2 90 0 | |
"" 1 0 0 | |
(params "Dept") | |
]) | |
:Process (fn [seq] | |
(let [acc-seq (filter #(and (is-valid-subacc? %) (is-valid-hozoper? %) (is-valid-corresp? %)) (map oborot-to-acc seq)) | |
;indexed-accs (map oborot-to-row (unique-by-sorted :Acc acc-seq)) | |
cells-with-idx (map #(merge %1 {:RowID (valid-subaccounts (:Acc %1))}) acc-seq) | |
cells-with-totals (mapcat add-total-col cells-with-idx) | |
] | |
;(debug (str "acc-to-idx" acc-to-idx)) | |
{:Cells (fold-oborots-to-register {} cells-with-totals) | |
:Cols (map oborot-to-col (unique-by-sorted :AccCode cells-with-totals)) | |
;:Rows (concat indexed-accs [{:ID 99900 :Name "Финансовый результат" :Number "" :Sort 99900} | |
; {:ID 99999 :Name "Рентабельность" :Number "" :Sort 99999} | |
; ]) | |
}) | |
) | |
} | |
) | |
(def order11-cells (old-cells-to-new-cells old-order11-cells)) | |
(def zhurnal-metadata | |
{:Recalc [{:Expr "Cell[AllCol,99900]:=Cell[AllCol,10001]-Cell[AllCol,10002]-Cell[AllCol,10003]-Cell[AllCol,10004]-Cell[AllCol,10005]-Cell[AllCol,10006]-Cell[AllCol,10007]" :Cycle "Cols" :Range "All"} | |
{:Expr "Cell[AllCol,99999]:=Rentabil(Cell[AllCol,99900],Cell[AllCol,10004]+Cell[AllCol,10005])" :Cycle "Cols" :Range "All"} | |
] | |
:ReadOnly { | |
:Cols [total-ho-code] | |
:Rows [99900 99999] | |
:Cells [] | |
} | |
:Detailed { | |
:Cols [] | |
:Rows [] | |
:Cells [] | |
} | |
:DieHard { | |
:Cols [] | |
:Rows [] | |
:Cells [] | |
} | |
:Print {:Format "%14m" | |
:Form "T3_ZhurnalOrder11" | |
:SplitCount 5 | |
} | |
:Style { | |
:Rows {:Cells [{:SubCells [{:Data "Number"}]} | |
;{:SubCells [{:Data "ID"}]} | |
{:SubCells [{:Data "Name" :WordBreak 2}]} | |
] | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment