public $__table = 'core_company'; // table name
public $code; // string(32) not_null
public $name; // string(128)
- public $remarks; // blob(65535) blob
+ public $remarks; // blob(65535) blobeforeDeleteb
public $owner_id; // int(11) not_null
public $address; // blob(65535) blob
public $tel; // string(32)
public $country; // string(4) not_null
public $is_system; // int(2)
+
+ public $comptype_id;
+ public $address1;
+ public $address2;
+ public $address3;
+
+
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function applyFilters($q, $au)
+ function applyFilters($q, $au, $roo)
{
$tn = $this->tableName();
}
if (!empty($q['query']['comptype'])) {
- $this->whereAddIn('comptype', explode(',', $q['query']['comptype']), 'string');
+ $this->whereAddIn($tn.'.comptype', explode(',', $q['query']['comptype']), 'string');
}
- /*if (!empty($q['query']['deleted_by'])) {
- $deleted_by = $this->escape($q['query']['deleted_by']);
- $this->whereAdd("deleted_by = '$deleted_by'");
- }*/
+
// depricated - should be moved to module specific (texon afair)
if (!empty($q['query']['province'])) {
) as comptype_display_name
");
- if(!empty($q['query']['name'])){
- $s = $this->escape($q['query']['name']);
+ if(!empty($q['query']['name']) || !empty($q['search']['name'])){
+
+ $s = (!empty($q['query']['name'])) ? $this->escape($q['query']['name']) : $this->escape($q['search']['name']);
+
$this->whereAdd("
{$tn}.name LIKE '%$s%'
");
}
- if(!empty($q['search']['name_starts'])){
- $s = $this->escape($q['search']['name_starts']);
+
+ if(!empty($q['query']['name_starts']) || !empty($q['search']['name_starts'])){
+
+ $s = (!empty($q['query']['name_starts'])) ? $this->escape($q['query']['name_starts']) : $this->escape($q['search']['name_starts']);
+
$this->whereAdd("
{$tn}.name LIKE '$s%'
");
{
$db = $this->getDatabaseConnection();
$sesPrefix = $db->dsn['database'];
- @session_start();
+ if (empty($_SERVER['PHP_AUTH_USER'])) {
+ @session_start();
+ }
if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
// in session...
$a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
function beforeInsert($q, $roo)
{
+ // we still use comptype in some old systems...
+
+ if(!empty($q['comptype']) && empty($q['comptype_id'])) {
+ $en = DB_DataObject::Factory('core_enum');
+ $en->setFrom(array(
+ 'etype' => 'COMPTYPE',
+ 'name' => $q['comptype'],
+ 'active' => 1
+ ));
+ if($en->find(true)) {
+ $this->comptype_id = $en->id;
+ }
+ }
+
+ if (!empty($q['comptype_id'])) {
+ $en = DB_DataObject::Factory('core_enum');
+ $en->get($q['comptype_id']);
+ $this->comptype = $en->name;
+ }
+
if(!empty($q['_check_name'])){
if($this->checkName()){
$roo->jok('OK');
}
- $roo->jerr('EXIST');
+ $roo->jerror('NOTICE-EXIST-CHECK','EXIST');
}
}
function beforeUpdate($old, $q,$roo)
{
-
- if(!empty($q['_flag_delete']) && $q['_flag_delete'] * 1 == 1){
- //$delete_dt = date('Y-m-d H:i:s');
- $this->deleted_dt = date('Y-m-d H:i:s');
- $this->deleted_by = $roo->getAuthUser()->name;
- $this->id = $q['_ids'];
-
- $this->update();
- //$roo->query("UPDATE {$old->tableName()} SET deleted_by = {$roo->getAuthUser()} , deleted_dt = {$delete_dt} WHERE id = {$req['_update_id']}");
- //$this->addEvent("UPDATE", false, "update core_company record");
+ // we still use comptype in some old systems...
+
+ if(!empty($q['comptype']) && empty($q['comptype_id'])) {
+ $en = DB_DataObject::Factory('core_enum');
+ $en->setFrom(array(
+ 'etype' => 'COMPTYPE',
+ 'name' => $q['comptype'],
+ 'active' => 1
+ ));
+ if($en->find(true)) {
+ $this->comptype_id = $en->id;
+ }
+ }
+
+ if (!empty($q['comptype_id'])) {
+ $en = DB_DataObject::Factory('core_enum');
+ $en->get($q['comptype_id']);
+ $this->comptype = $en->name;
+ }
+
+ if(!empty($q['_flag_delete'])){
+ $this->deleted_dt = $this->sqlValue("NOW()");
+ $this->deleted_by = $roo->getAuthUser()->id;
+ }
+
+ if(!empty($q['_flag_undelete'])){
+ $this->deleted_dt = "";
+ $this->deleted_by = 0;
}
if(!empty($q['_check_name'])){
if($this->checkName()){
$roo->jok('OK');
}
- $roo->jerr('EXIST');
+ $roo->jerror('NOTICE-EXIST-CHECK','EXIST');
}
if(!empty($q['_merge_id'])){
$img->onid = $this->id;
$img->find();
while ($img->fetch()) {
- $img->beforeDelete();
+ $img->beforeDelete(array(), $roo);
$img->delete();
}
return true;
$companies->insert();
$companies->onInsert(array(), $roo);
}
+
+ function owner()
+ {
+ if (empty($this->owner_id)) {
+ return false;
+ }
+ static $cache = false;
+ if ($cache !== false && isset($cache[$this->owner_id])) {
+ return $cache[$this->owner_id];
+ }
+ $o = DB_DataObject::factory('core_company');
+ if (!$o->get($this->owner_id)) {
+ return false;
+ }
+ $cache[$this->owner_id] = $o;
+ return $o;
+
+ }
+
+ /// look up the company which is the system owner...
static function lookupOwner()
{
+ static $cache = false;
+ if ($cache !== false) {
+ return clone($cache); // no updating this object..
+ }
+
$enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', 'OWNER' );
$companies = DB_DataObject::factory('core_company');
$companies->comptype_id = $enum;
if ($companies->find(true)) {
+ $cache = clone($companies);
return $companies;
}
return false;