Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.40 KB | None | 0 0
  1. package eu.cosmedico.cloud.domain.manufacturer
  2.  
  3. import eu.cosmedico.cloud.domain.ItemCode
  4. import eu.cosmedico.cloud.domain.billing.{BasicInvoiceItem, InvoiceItem}
  5.  
  6. /**
  7.  * Created by g.duszynski@cos-medico.eu on 2015-04-16.
  8.  * All rights belong to CM International Ltd.
  9.  */
  10. trait ProfitShare {
  11.   def name:     String
  12.   def itemCode: ItemCode
  13.   def taxRate:  Option[BigDecimal]
  14.  
  15.   def shareOf(item: InvoiceItem): Option[InvoiceItem]
  16. }
  17.  
  18. case class NoShare(name: String, itemCode: ItemCode)
  19.   extends ProfitShare {
  20.  
  21.   def taxRate: Option[BigDecimal] = None
  22.  
  23.   def shareOf(item: InvoiceItem) = None
  24. }
  25.  
  26. case class FixedShare(name: String, itemCode: ItemCode, shareAmount: BigDecimal, taxRate: Option[BigDecimal] = None)
  27.   extends ProfitShare {
  28.  
  29.   def shareOf(item: InvoiceItem) = {
  30.     if(item.code == itemCode){
  31.       Some(BasicInvoiceItem(itemCode, name, None, item.unit, item.quantity, taxRate, shareAmount))
  32.     } else None
  33.   }
  34. }
  35.  
  36. case class RelativeShare(name: String, itemCode: ItemCode, shareRatio: BigDecimal, taxRate: Option[BigDecimal] = None)
  37.   extends ProfitShare {
  38.  
  39.   if(shareRatio>1 || shareRatio<=0) throw new IllegalArgumentException("Unit price ratio must be between (0,1>")
  40.  
  41.   def shareOf(item: InvoiceItem) = {
  42.     if(item.code == itemCode){
  43.       Some(BasicInvoiceItem(itemCode, name, None, item.unit, item.quantity, taxRate, item.unitPrice*shareRatio))
  44.     } else None
  45.   }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement