cmc-sales/php/app/models/principle.php

88 lines
2.4 KiB
PHP
Raw Permalink Normal View History

<?php
class Principle extends AppModel {
var $name = 'Principle';
var $recursive = 0;
2011-03-09 23:18:26 -08:00
2011-04-21 00:38:01 -07:00
var $order = 'Principle.name ASC';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'Country' => array('className' => 'Country',
'foreignKey' => 'country_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Currency' => array('className' => 'Currency',
'foreignKey' => 'currency_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'Enquiry' => array('className' => 'Enquiry',
'foreignKey' => 'principle_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Product' => array('className' => 'Product',
'foreignKey' => 'principle_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'PrincipleAddress' => array('className' => 'PrincipleAddress',
'foreignKey' => 'principle_id'
),
'PrincipleContact' => array('className' => 'Users',
'foreignKey' => 'principle_id'
),
);
function getCityCountryList() {
2019-07-02 01:44:50 -07:00
//$principles = $this->find('all', array('recursive'=>1));
$principles = $this->query("select p.name, p.city, c.name FROM principles p JOIN countries c ON p.country_id = c.id ORDER BY p.name ASC");
$search = array('{company}','{city}','{country}');
$phrase = "Ex Works Incoterms 2010 ({company}, {city}, {country})";
$list = array();
/*
Format returned from that query
Array ( [0] => Array ( [p] => Array ( [name] => A GRADE AIR CONDITIONING PTY LIMITED [city] => SEVEN HILLS ) [c] => Array ( [name] => Australia ) )
*/
foreach($principles as $principle) {
$replace = array($principle['p']['name'], $principle['p']['city'], $principle['c']['name']);
$newPhrase = str_replace($search, $replace, $phrase);
$list[$newPhrase] = $newPhrase;
}
return $list;
}
}
?>