public $__table = 'Companies'; // table name
public $code; // string(32) not_null
- public $name; // string(128) multiple_key
+ public $name; // string(128)
public $remarks; // blob(65535) blob
public $owner_id; // int(11) not_null
public $address; // blob(65535) blob
public $logo_id; // int(11) not_null
public $background_color; // string(8) not_null
public $comptype; // string(8) not_null
- public $ava_craft; // string(254)
public $url; // string(254) not_null
public $main_office_id; // int(11) not_null
public $created_by; // int(11) not_null
public $updated_by; // int(11) not_null
public $updated_dt; // datetime(19) not_null binary
public $passwd; // string(64) not_null
-
+ public $dispatch_port; // string(255) not_null
+ public $province; // string(255) not_null
+ public $country; // string(4) not_null
+ public $is_system; // int(2)
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
function applyFilters($q, $au)
{
-
+ $tn = $this->tableName();
//DB_DataObject::debugLevel(1);
$x = DB_DataObject::factory('Companies');
$x->comptype= 'OWNER';
$this->whereAdd("Companies.id IN (
SELECT distinct(company_id) FROM ProjectDirectory where project_id IN ($pids)
) $add" );
-
-
-
+
}
if (!empty($q['query']['comptype'])) {
$this->whereAddIn('comptype', explode(',', $q['query']['comptype']), 'string');
}
-
+
+ // depricated - should be moved to module specific (texon afair)
+
if (!empty($q['query']['province'])) {
$prov = $this->escape($q['query']['province']);
$this->whereAdd("province LIKE '$prov%'");
}
+ // ADD comptype_display name.. = for combos..
+ $this->selectAdd("
+ (SELECT display_name
+ FROM
+ core_enum
+ WHERE
+ etype='comptype'
+ AND
+ name={$tn}.comptype
+ LIMIT 1
+ ) as comptype_display_name
+ ");
+
+ if(!empty($q['query']['name'])){
+ $s = $this->escape($q['query']['name']);
+ $this->whereAdd("
+ {$tn}.name LIKE '%$s%'
+ ");
+ }
}
+
function toEventString() {
return $this->name;
}
}
- function beforeDelete()
+ function beforeUpdate($old, $q,$roo)
+ {
+ if(!empty($this->is_system) &&
+ ($old->code != $this->code || $old->name != $this->name)
+ ){
+ $roo->jerr('This company is not allow to editing Ref. or Company Name...');
+ }
+ }
+
+ function beforeDelete($req, $roo)
{
// should check for members....
-
+ if(!empty($this->is_system) &&
+ ($old->code != $this->code || $old->name != $this->name)
+ ){
+ $roo->jerr('This company is not allow to delete');
+ }
$img = DB_DataObject::factory('Images');
$img->ontable = 'Companies';
$img->onid = $this->id;
return $this->id == $au->company_id;
}
- return $au->hasPerm("Core.".$this->tableName(), $lvl);
- }
+ return $au->hasPerm("Core.Companies", $lvl);
+ }
+ function logoImageToHTML($size)
+ {
+ $i = DB_DataObject::factory('Images');
+ if (!$this->logo_id || !$i->get($this->logo_id)) {
+ return '';
+ }
+ return $i->toHTML($size);
+
+ }
+ function firstImage($filter='image/%')
+ {
+ $i = DB_DataObject::factory('Images');
+ //DB_DataObject::debugLevel(1);
+ $im = $i->gather($this, $filter);
+ if (empty($im)) {
+ return false;
+ }
+ return $im[0];
+ }
+
+ function firstImageTag($size =-1, $base="/Images/Thumb", $filter='image/%')
+ {
+ $fm = $this->firstImage($filter);
+ if (empty($fm)) {
+ return '';
+ }
+ return $fm->toHTML($size, $base);
+ }
+
+ function toRooSingleArray($authUser, $request)
+ {
+ $ret = $this->toArray();
+ // DB_DataObject::debugLevel(1);
+ // get the comptype display
+ $e = DB_DataObject::Factory('core_enum')->lookupObject('COMPTYPE', $this->comptype);
+
+ $ret['comptype_display'] = $ret['comptype'];
+ if ($e && !empty($e->name_display)) {
+ $ret['comptype_display'] = $e->name_display;
+ }
+
+
+ return $ret;
+ }
+
+ /**
+ * # 2028
+ * create the suppliers...
+ *
+ * @param object $roo
+ * @param array $data
+ *
+ */
+ function initCompaniesArray($roo, $data)
+ {
+ $tn = $this->tableName();
+
+ foreach($data as $d){
+ $com = DB_DataObject::factory($tn);
+ $com->setFrom($d);
+ if(!$com->find(true)){
+ $com->created_dt = Date('Y-m-d H:i:s');
+ $com->updated_dt = Date('Y-m-d H:i:s');
+ $com->is_system = 1;// new column.. block the user changing the code and name..
+ $com->insert();
+ }
+ }
+
+
+ }
+
+
+ function initCompanies($roo, $opts)
+ {
+ $companies = DB_DataObject::factory('companies');
+
+ $ctype = empty($opts['add-company-with-type']) ? 'OWNER' : $opts['add-company-with-type'];
+
+ $enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', $ctype );
+
+ if (empty($enum)) {
+ $roo->jerr("invalid company type '$ctype'");
+ }
+ if ($ctype =='OWNER') {
+ $companies = DB_DataObject::factory('companies');
+ $companies->comptype_id = $enum;
+ if ($companies->count()) {
+ $roo->jerr("Owner company already exists");
+ }
+ }
+ $companies = DB_DataObject::factory('companies');
+
+ // check that
+ $companies->setFrom(array(
+ 'name' => $opts['add-company'],
+ 'comptype' => $ctype,
+ 'comptype_id' => $enum,
+ ));
+ if ($companies->find(true)) {
+ $roo->jerr("company already exists");
+ }
+ $companies->setFrom(array(
+ 'background_color' => '',
+ 'created_dt' => $this->sqlValue('NOW()'),
+ 'updated_dt' => $this->sqlValue('NOW()')
+ ));
+
+
+ $companies->insert();
+ $companies->onInsert(array(), $roo);
+ }
+ function lookupOwner()
+ {
+ $enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', 'OWNER' );
+ $companies = DB_DataObject::factory('companies');
+ $companies->comptype_id = $enum;
+ if ($companies->find(true)) {
+ return $companies;
+ }
+ return false;
+ }
}