Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.model;

/**
 * How a cart's carry bags are charged: one bag per smartphone above Rs. 12,000 at the flat price,
 * every bag beyond that - and every bag of a partner who does not get the flat price - at the carry bag's listing price.
 */
public class CarryBagQuote {

        private final int allowance;
        private final int quantity;
        private final boolean flatPriced;
        private final float flatPrice;
        private final float listingPrice;

        public CarryBagQuote(int allowance, int quantity, boolean flatPriced, float flatPrice, float listingPrice) {
                this.allowance = allowance;
                this.quantity = quantity;
                this.flatPriced = flatPriced;
                this.flatPrice = flatPrice;
                this.listingPrice = listingPrice;
        }

        /** The same cart charged for a different number of bags. */
        public CarryBagQuote withQuantity(int quantity) {
                return new CarryBagQuote(allowance, quantity, flatPriced, flatPrice, listingPrice);
        }

        /** Bags the partner may have at the flat price: one per smartphone above Rs. 12,000. */
        public int getAllowance() { return allowance; }

        public int getQuantity() { return quantity; }

        /** False for a partner who pays listing price for every bag (Bronze). */
        public boolean isFlatPriced() { return flatPriced; }

        public int getFlatQty() { return flatPriced ? Math.min(quantity, allowance) : 0; }

        public int getListingQty() { return quantity - getFlatQty(); }

        public float getFlatPrice() { return flatPrice; }

        public float getListingPrice() { return listingPrice; }

        public double getTotal() { return (double) getFlatQty() * flatPrice + (double) getListingQty() * listingPrice; }

        /** Blended price the single cart line carries, so a client summing price x qty lands on the total. */
        public float getUnitPrice() { return quantity == 0 ? flatPrice : (float) (getTotal() / quantity); }
}