link('shipto_addr_id', func_get_arg(0)) : $this->link('shipto_addr_id'); } /** * Getter / Setter for $shipto_cntct_id * * @param mixed (optional) value to assign * @access public */ public function cntct() { return func_num_args() ? $this->link('shipto_cntct_id', func_get_arg(0)) : $this->link('shipto_cntct_id'); } /** * Getter / Setter for $shipto_cust_id * * @param mixed (optional) value to assign * @access public */ public function cust() { return func_num_args() ? $this->link('shipto_cust_id', func_get_arg(0)) : $this->link('shipto_cust_id'); } /** * Getter / Setter for $shipto_salesrep_id * * @param mixed (optional) value to assign * @access public */ public function salesrep() { return func_num_args() ? $this->link('shipto_salesrep_id', func_get_arg(0)) : $this->link('shipto_salesrep_id'); } /** * Getter / Setter for $shipto_shipform_id * * @param mixed (optional) value to assign * @access public */ public function shipform() { return func_num_args() ? $this->link('shipto_shipform_id', func_get_arg(0)) : $this->link('shipto_shipform_id'); } /** * Getter / Setter for $shipto_shipzone_id * * @param mixed (optional) value to assign * @access public */ public function shipzone() { return func_num_args() ? $this->link('shipto_shipzone_id', func_get_arg(0)) : $this->link('shipto_shipzone_id'); } /** * Getter / Setter for $shipto_taxzone_id * * @param mixed (optional) value to assign * @access public */ public function taxzone() { return func_num_args() ? $this->link('shipto_taxzone_id', func_get_arg(0)) : $this->link('shipto_taxzone_id'); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE function address() { $ret = $this->addr()->addressArray(); array_unshift($ret, $this->shipto_name); return $ret; } function applyFilters($q, $au) { if (isset($q['query']['for_cohead_id'])) { $cid = (int)$q['query']['for_cohead_id']; $this->whereAdd(" shipto_id IN (SELECT coitem_shipto_id FROM coitem where coitem_cohead_id = $cid ) "); } //DB_DataObject::debugLevel(1); $this->selectAdd(" CASE WHEN LENGTH( join_shipto_addr_id_addr_id.addr_line1) < 1 THEN 'UNKNOWN' ELSE join_shipto_addr_id_addr_id.addr_line1 END as shipto_addr_id_addr_name "); } function createFromCustomerContact($cust, $cnt, $num = false ) { //DB_DataObject::debugLevel(1); if (!$cust) { $cust = $cnt->crmacct()->cust(); if (!$cust->pid()) { return false; } } if ($num !== false) { $sh = DB_DataObject::Factory('shiptoinfo'); if ($sh->get('shipto_num', $num)) { return $sh; } } if ( $num === false && !empty($cnt->cntct_number)) { $sh = DB_DataObject::Factory('shiptoinfo'); if ($sh->get('shipto_num', $cnt->cntct_number)) { return $sh; } } // verify we do not have one.. $sh = DB_DataObject::Factory('shiptoinfo'); $sh->cust($cust); $cust= $sh->cust(); $sh->cntct($cnt); $cnt = $sh->cntct(); if ($sh->count() == 1) { $sh->find(true); return $sh; } $this->cust($cust); $this->cntct($cnt); $this->salesrep($cust->salesrep()); $this->taxzone($cust->taxzone()); $this->shipform($cust->shipform()); $addr = $cnt->addr(); //$this->shipzone($cust->salesrep()); $sz = $this->shipzone(); if (!$sz->get('shipzone_name', 'DEFAULT')) { $sz->shipzone_descrip = 'Default'; $sz->insert(); } if (empty($this->shipto_cntct_id)) { print_r($cnt); throw("invalid shipto contact id ?"); } $name = empty($addr->line1 ) ? $cnt->cntct_name : $addr->line1 ; $this->setFrom(array( // 'shipto_cntct_id' => $cnt->cntct_id, -- not needed??? as we set it earlier.. 'shipto_shipchrg_id' => $cust->cust_shipchrg_id, 'shipto_shipzone_id' => $sz->shipzone_id, 'shipto_active' => true, 'shipto_name' => $cnt->cntct_name, //unique with customer.. 'shipto_shipvia' => $cust->cust_shipvia, 'shipto_commission' => 0, 'shipto_default' => false, /// should we have defaults here.. 'shipto_num' => $num !== false ? $num : $cnt->cntct_number, 'shipto_ediprofile_id' => $cust->cust_ediprofile_id, 'shipto_addr_id' => $addr->pid() )); //print_R($this);exit; $this->insert(); return $this; } function genNum() { $l = $this->cntct()->cntct_number. '-' . $this->addr()->addr_number; if (empty($l)) { $l = 'Shipto'; } $x = DB_DataObject::Factory('shiptoinfo'); $suf = 0; while ($x->get('shipto_num', $l . (!$suf ? '' : '-' . $suf))) { $x = DB_DataObject::Factory('shiptoinfo'); $suf++; //if ($suf > 10) {die("TO MANYU");} } // got a suf.. $this->shipto_num = $l . (!$suf ? '' : '-' . $suf); } function defaultShipZone() { $sz = $this->shipzone(); if (!$sz->get('shipzone_name', 'DEFAULT')) { $sz->shipzone_descrip = 'Default'; $sz->insert(); } return $sz->pid(); } }