3 * Table Definition for ipshead
5 require_once 'DB/DataObject.php';
7 class Pman_Xtuple_DataObjects_Ipshead extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'ipshead'; // table name
13 public $ipshead_id; // int4(4) not_null default_nextval%28%28%22ipshead_ipshead_id_seq%22%29%3A%3Aregclass%29 primary_key
14 public $ipshead_name; // text(-1) unique_key
15 public $ipshead_descrip; // text(-1)
16 public $ipshead_effective; // date(4)
17 public $ipshead_expires; // date(4)
18 public $ipshead_curr_id; // int4(4) not_null default_basecurrid%28%29
19 public $ipshead_updated; // date(4)
23 * Getter / Setter for $ipshead_curr_id
25 * @param mixed (optional) value to assign
28 public function curr() {
29 return func_num_args() ? $this->link('ipshead_curr_id', func_get_arg(0)) : $this->link('ipshead_curr_id');
33 /* the code above is auto generated do not remove the tag below */
36 function applyFilters($q, $au, $roo)
38 if(!empty($q['_with_item'])){
39 $item_id = (int) $q['_with_item'];
43 COALESCE(ipsitem_price,0.0)
47 ipsitem_ipshead_id = ipshead_id
49 ipsitem_item_id = {$item_id}
50 ) AS ipshead_ipsitem_price,
53 COALESCE(ipsitem_id,0)
57 ipsitem_ipshead_id = ipshead_id
59 ipsitem_item_id = {$item_id}
60 ) AS ipshead_ipsitem_id
66 function beforeUpdate()
68 $this->ipshead_updated = $this->sqlValue('NOW()');
70 function beforeInsert()
72 $this->ipshead_updated = $this->sqlValue('NOW()');
75 function beforeDelete($dependants_array, $roo)
79 $ass = DB_DataObject::factory('ipsass');
80 $ass->ipsass_ipshead_id = $this->ipshead_id;
82 $roo->jerr("This price list is assigned to a customer - please change that customer to another price list first");
84 $ass = DB_DataObject::factory('ipsiteminfo');
85 $ass->query("DELETE FROM ipsiteminfo WHERE ipsiteminfo_ipshead_id = {$this->id}");
90 function itemPrice($item) {
91 $ipsitem = DB_DataObject::Factory('ipsiteminfo');
92 $ipsitem->ipsitem_item_id = $item->pid();
93 $ipsitem->ipsitem_ipshead_id = $this->pid();
94 if (!$ipsitem->find(true)) {
97 return $ipsitem->ipsitem_price;
102 function updatePrices($kv, $imap)
105 public $__table = 'ipsitem'; // table name
106 public $ipsitem_id; // int4(4)
107 public $ipsitem_ipshead_id; // int4(4)
108 public $ipsitem_item_id; // int4(4)
109 public $ipsitem_qtybreak; // numeric(-1)
110 public $ipsitem_price; // numeric(-1)
111 public $ipsitem_qty_uom_id; // int4(4)
112 public $ipsitem_price_uom_id; // int4(4)
113 public $ipsitem_discntprcnt; // numeric(-1)
114 public $ipsitem_fixedamtdiscount; // numeric(-1)
117 ipsitem_ipshead_id | 65
118 ipsitem_item_id | 2768
119 ipsitem_qtybreak | 0.000000
120 ipsitem_price | 14.5000
121 ipsitem_qty_uom_id | 4
122 ipsitem_price_uom_id | 4
123 ipsitem_discntprcnt | 0.000000
124 ipsitem_fixedamtdiscount | 0.0000
129 // grab a list of current prices with ids'
130 $d = DB_DataObject::Factory('ipsiteminfo');
138 $d->_join = ' LEFT JOIN item ON ipsiteminfo.ipsitem_item_id = item.item_id ';
140 $d->ipsitem_ipshead_id = $this->pid();
143 while ($d->fetch()) {
144 $old[$d->item_number] = clone($d);
151 foreach($kv as $item=>$price) {
152 $o = isset($old[$item]) ? $old[$item] : false;
153 // no record, and not updated.
154 if (!strlen($price) && $o === false) {
157 // updated or not changed.
158 if (strlen($price) && $o !== false) {
160 if ($o->ipsitem_price == $price) {
164 $o->ipsitem_price = $price;
170 if (strlen($price) && $o === false) {
171 $d = DB_DataObject::Factory('ipsiteminfo');
174 'ipsitem_ipshead_id' => $this->pid(),
175 'ipsitem_item_id' => $imap[$item],
176 'ipsitem_qtybreak' => 0.0,
177 'ipsitem_price' => $price,
179 'ipsitem_discntprcnt' => 0.0,
180 'ipsitem_fixedamtdiscount' => 0.0
184 $d->ipsitem_qty_uom_id = $d->sqlValue("getuomid('EA')");
185 $d->ipsitem_price_uom_id = $d->sqlValue("getuomid('EA')");
193 // o is true, and price is empty..
194 // theory goes we should delete this item..
197 // do not delete prices...
200 $x = $this->factory($this->tableName());
201 $x->get($this->pid());
203 $x->ipshead_updated = $this->sqlValue('NOW()');
208 'deleted' => $deleted,
209 'updated' => $updated,
210 'inserted' => $inserted