setupCustomFields('EcmStockStates'); foreach ($this->field_defs as $field) { $this->field_name_map[$field['name']] = $field; } } function get_summary_text() { return $this->name; } function create_list_query($order_by, $where, $show_deleted = 0) { $custom_join = $this->custom_fields->getJOIN(); $query = "SELECT "; $query .= "ecmstockstates.*,users.user_name as assigned_user_name"; if ($custom_join) $query .= $custom_join['select']; $query .= " FROM ecmstockstates "; $query .= "LEFT JOIN users ON ecmstockstates.assigned_user_id=users.id"; $query .= " "; if ($custom_join) $query .= $custom_join['join']; $where_auto = '1=1'; if ($show_deleted == 0) $where_auto = " $this->table_name.deleted=0 "; elseif ($show_deleted == 1) $where_auto = " $this->table_name.deleted=1 "; if ($where != "") $query .= "where $where AND " . $where_auto; else $query .= "where " . $where_auto; if (substr_count($order_by, '.') > 0) $query .= " ORDER BY $order_by"; elseif ($order_by != "") $query .= " ORDER BY $order_by"; else $query .= " ORDER BY ecmstockstates.name"; return $query; } function create_export_query($order_by, $where) { $custom_join = $this->custom_fields->getJOIN(); $query = "SELECT "; $query .= "ecmstockstates.*,users.user_name as assigned_user_name"; if ($custom_join) $query .= $custom_join['select']; $query .= " FROM ecmstockstates "; $query .= "LEFT JOIN users ON ecmstockstates.assigned_user_id=users.id"; $query .= " "; if ($custom_join) $query .= $custom_join['join']; $where_auto = '1=1'; if ($show_deleted == 0) $where_auto = " $this->table_name.deleted=0 "; elseif ($show_deleted == 1) $where_auto = " $this->table_name.deleted=1 "; if ($where != "") $query .= "where $where AND " . $where_auto; else $query .= "where " . $where_auto; if (substr_count($order_by, '.') > 0) $query .= " ORDER BY $order_by"; elseif ($order_by != "") $query .= " ORDER BY $order_by"; else $query .= " ORDER BY ecmstockstates.name"; return $query; } function fill_in_additional_list_fields() { } function fill_in_additional_detail_fields() { parent::fill_in_additional_detail_fields(); } function UpdateStockState($stock_id, $product_id) { $q = 0; $p = 0; $i = 0; $pp = 0; $qq = 0; $w = $GLOBALS['db']->query("select quantity as qty, id, price, parent_id, parent_type, parent_name from ecmstockoperations where deleted='0' and type='0' and used=0 and in_id IS NULL and stock_id='" . $stock_id . "' and product_id='" . $product_id . "'"); while ($rrr = $GLOBALS['db']->fetchByAssoc($w)) { $rrp = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(quantity) as s from ecmstockoperations where in_id='" . $rrr['id'] . "' and type='1' and in_id IS NOT NULL and stock_id='" . $stock_id . "' and product_id='" . $product_id . "' and deleted='0'")); $rqty = $rrp['s']; $qty = $rrr['qty'] - $rqty; if ($qty > 0) { $arr[] = array("qty" => $qty, "id" => $rrr['id'], "price" => $rrr['price'], "parent_id"=>$rrr['parent_id'], "parent_type"=>$rrr['parent_type'], "parent_name"=>$rrr['parent_name']); } else if ($qty == 0) { //set used = 1 $GLOBALS['db']->query("UPDATE ecmstockoperations SET used='1' WHERE id='" . $rrr['id'] . "'"); } } if (count($arr) > 0) { foreach ($arr as $v) { $q1 += $v['qty']; $pp1 += $v['qty'] * $v['price']; } } if ($_REQUEST['type'] != "test") { $GLOBALS['db']->query("delete from ecmstockstates where stock_id='" . $stock_id . "' and product_id='" . $product_id . "' and deleted='0'"); require_once("modules/EcmStockOperations/EcmStockOperation.php"); $o = new EcmStockState(); $o->unformat_all_fields(); require_once("modules/EcmProducts/EcmProduct.php"); $o->product_id = $product_id; $p = new EcmProduct(); $p->retrieve($product_id); $o->product_name = $p->name; $o->product_code = $p->code; $o->product_id = $p->id; require_once("modules/EcmStocks/EcmStock.php"); $o->stock_id = $stock_id; $s = new EcmStock(); $s->retrieve($stock_id); $o->stock_name = $s->name; $o->quantity = $q1; if ($q1 > 0) $o->price = $pp1 / $q1; if ($p->id) $oid = $o->save(); //if($q1>0)if($p->code=="RE00867")echo ($pp1/$q1)."
"; if ($q1 > 0) $GLOBALS['db']->query("update ecmstockstates set price='" . ($pp1 / $q1) . "' where id='" . $oid . "'"); } //add mz //update ems_price $GLOBALS['db']->query( "UPDATE ecmproducts as p INNER JOIN ( SELECT round(sum(quantity*price)/sum(quantity),2) as avg_price, product_id, SUM(quantity) as stock_state FROM ecmstockstates GROUP BY product_id ) s ON p.id=s.product_id SET p.ems_price = s.avg_price, p.ems_qty_in_stock = s.stock_state WHERE p.id='$product_id'" ); } function save($check_notify = FALSE) { return parent::save($check_notify); } function get_list_view_data() { global $current_language, $current_user; $the_array = parent::get_list_view_data(); $app_list_strings = return_app_list_strings_language($current_language); $mod_strings = return_module_language($current_language, 'EcmStockStates'); $the_array['NAME'] = (($this->name == "") ? "blank" : $this->name); $the_array['NEW_FIELD'] = '1'; /* $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select ecmproducts.name from ecmstockstates inner join ecmproducts on ecmproducts.id=ecmstockstates.product_id")); $the_array['PRODUCT_NAME']=$r['name']; $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select ecmstocks.name from ecmstockstates inner join ecmstocks on ecmstocks.id=ecmstockstates.stock_id")); $the_array['STOCK_NAME']=$r['name']; $this->retrieve($this->id); $dd=substr($this->parent_type,0,strlen($this->parent_type)-1); require_once("modules/".$this->parent_type."/".$dd.".php"); $d=new $dd(); $d->retrieve($this->parent_id); $the_array['PARENT_NAME']=$d->number; */ $the_array['ENCODED_NAME'] = $this->name; return $the_array; } function build_generic_where_clause($the_query_string) { $where_clauses = array(); $the_query_string = PearDatabase::quote(from_html($the_query_string)); array_push($where_clauses, "ecmstockstates.name like '$the_query_string%'"); $the_where = ""; foreach ($where_clauses as $clause) { if ($the_where != "") $the_where .= " or "; $the_where .= $clause; } return $the_where; } function set_notification_body($xtpl, $ecmstockstate) { global $mod_strings, $app_list_strings; $xtpl->assign("ECMSTOCKSTATE_SUBJECT", $ecmstockstate->name); return $xtpl; } function bean_implements($interface) { switch ($interface) { case 'ACL': return true; } return false; } } ?>