<?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 Payment extends AppModel {
	public $belongsTo = array(
		'User' => array('className' => 'User', 'foreignKey' => 'user_id', 'fields' => array('first_name', 'last_name'), 'type'=>'inner'),
		'Bank' => array('className' => 'Bank', 'foreignKey' => 'bank_id', 'fields' => array('id','name')),
		'Distributor' => array('className' => 'Distributor', 'foreignKey' => 'distributor_id', 'fields' => array('id','title'))
	);
	
	function _userCondition(&$conditions, $user){
		switch($user['Role']['grade']){
			
			case 3:
				$conditions[] = 'Payment.depot_id IN (SELECT id FROM depots WHERE region_id = '.$user['region_id'].')';
			break;
			case 4:
				$conditions['Payment.depot_id'] = $user['depot_id'];
			break;
			case 5:
				$conditions['Payment.user_id'] = $user['id'];
			break;
			case 6:
				$conditions['Payment.user_id'] = $user['id'];
			break;
			
		}
	}
}