Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37792 amit 1
package com.spice.profitmandi.dao.model;
2
 
3
/**
4
 * How a cart's carry bags are charged: one bag per smartphone above Rs. 12,000 at the flat price,
5
 * every bag beyond that - and every bag of a partner who does not get the flat price - at the carry bag's listing price.
6
 */
7
public class CarryBagQuote {
8
 
9
	private final int allowance;
10
	private final int quantity;
11
	private final boolean flatPriced;
12
	private final float flatPrice;
13
	private final float listingPrice;
14
 
15
	public CarryBagQuote(int allowance, int quantity, boolean flatPriced, float flatPrice, float listingPrice) {
16
		this.allowance = allowance;
17
		this.quantity = quantity;
18
		this.flatPriced = flatPriced;
19
		this.flatPrice = flatPrice;
20
		this.listingPrice = listingPrice;
21
	}
22
 
23
	/** The same cart charged for a different number of bags. */
24
	public CarryBagQuote withQuantity(int quantity) {
25
		return new CarryBagQuote(allowance, quantity, flatPriced, flatPrice, listingPrice);
26
	}
27
 
28
	/** Bags the partner may have at the flat price: one per smartphone above Rs. 12,000. */
29
	public int getAllowance() { return allowance; }
30
 
31
	public int getQuantity() { return quantity; }
32
 
33
	/** False for a partner who pays listing price for every bag (Bronze). */
34
	public boolean isFlatPriced() { return flatPriced; }
35
 
36
	public int getFlatQty() { return flatPriced ? Math.min(quantity, allowance) : 0; }
37
 
38
	public int getListingQty() { return quantity - getFlatQty(); }
39
 
40
	public float getFlatPrice() { return flatPrice; }
41
 
42
	public float getListingPrice() { return listingPrice; }
43
 
44
	public double getTotal() { return (double) getFlatQty() * flatPrice + (double) getListingQty() * listingPrice; }
45
 
46
	/** Blended price the single cart line carries, so a client summing price x qty lands on the total. */
47
	public float getUnitPrice() { return quantity == 0 ? flatPrice : (float) (getTotal() / quantity); }
48
}