--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/fis/base/model/Payment.scala Thu May 24 11:19:26 2012 +0200
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package fis.base.model
+
+import fis.cl.model.{CodeList, CodeListItem, CodeListItemField}
+import java.math.MathContext
+import net.liftweb.record.{MetaRecord, Record}
+import net.liftweb.record.field._
+import net.tz.lift.model._
+import net.tz.lift.model.{FieldLabel => FL}
+import org.squeryl.annotations.Column
+
+trait Payment[T <: Record[T]] { self: T =>
+
+ val direction = new EnumField(this.asInstanceOf[T], PaymentDirection) with FL
+ {
+ override def defaultValue = PaymentDirection.Cost
+ override def get = PaymentDirection(super.get.id)
+ }
+
+ @Column("period")
+ val periodFld = new CodeListItemField(this.asInstanceOf[T], 'payment_period)
+ with FL
+ def period: PaymentPeriod = periodFld.item.dmap(PaymentPeriod.empty)(PaymentPeriod(_))
+
+ val amount = new DecimalField(this.asInstanceOf[T], MathContext.DECIMAL64, 2)
+ with FL
+ val currency = new CodeListItemField(this.asInstanceOf[T], 'currency) with FL
+}
+
+object PaymentDirection extends Enumeration {
+ type PaymentDirection = Value
+
+ val Cost = new L10nVal(1, "payment.direction.cost")
+ val Revenue = new L10nVal(2, "payment.direction.revenue")
+
+ class L10nVal(id: Int, n: String) extends Val(id, n) {
+ override def toString = l10n(n)
+ }
+}
+
+case class PaymentPeriod(perYear: Int, initial: Boolean, i: CodeListItem,
+ rank: Int)
+
+object PaymentPeriod {
+ def apply(i: CodeListItem): PaymentPeriod =
+ PaymentPeriod(i.i1.get, i.i1.get == 0, i, i.rank.get)
+
+ lazy val empty = apply(CodeListItem.createRecord)
+
+ private lazy val cl = CodeList('payment_period)
+
+ def periods = cl.items map(apply(_))
+}
+
+// vim: set ts=2 sw=2 et: