<?php

App::uses('Model', 'Model');

/**
 * Application model for Cake.
 *
 * Add your application-wide methods in the class below, your models
 * will inherit them.
 *
 * @package       app.Model
 */

class Brand extends AppModel {


	public $belongsTo = array(
						'BrandGroup' => array('className' => 'BrandGroup', 'counterCache' => true, 'foreignKey' => 'brand_group_id',  'fields'=>array('id', 'name','brand_count'),'type'=>'left'),
			);
	
    public function getUnitPrice($call_type, $brand_id, $unit){
        $unit_price = 0;
        $brand = $this->find('first', array('conditions'=>array('Brand.id'=>$brand_id))); 
        if($call_type == 'sale'){
            switch($unit){
                case 'Case':
                    $unit_price = $brand['Brand']['case_price'];
                    break;
                    
                case 'Roll':
                    $unit_price = $brand['Brand']['roll_price'];
                    break;
                    
                case 'Pack':
                    $unit_price = $brand['Brand']['pack_price'];
                    break;
                    
                    default:
                    break;
            }
        }
        return $unit_price;
        
    }

}