示例#1
0
 public function calcBomPrice($recordkey, $currency = 'CNY')
 {
     $low = $high = $average = 0.0;
     $fa = new Product_Model_Fa();
     $son = new Product_Model_Son();
     $price_list = new Erp_Model_Warehouse_Pricelist();
     $data = $this->getJoinList('recordkey = ' . $recordkey);
     // 检查当前BOM是否已有价格
     if (count($data) == 0) {
         // 计算价格
         $sonData = $son->getJoinList("recordkey = " . $recordkey, array(), array('code', 'qty'));
         foreach ($sonData as $sonRow) {
             // 检查是否有BOM数据,如果没有,当作物料处理
             $sonFaData = $fa->getJoinList("code = '" . $sonRow['code'] . "'", array(), array('recordkey'), array('ver desc'));
             if (count($sonFaData) == 0) {
                 if (isset($_SESSION['mprice'][$sonRow['code']])) {
                     // session 中存在
                     $price = $_SESSION['mprice'][$sonRow['code']];
                 } else {
                     $price = $price_list->getMultiPrice($sonRow['code'], $currency);
                     $_SESSION['mprice'][$sonRow['code']] = $price;
                 }
             } else {
                 $price = $this->calcBomPrice($sonFaData[0]['recordkey'], $currency);
             }
             $low += $price['low'] * $sonRow['qty'];
             $high += $price['high'] * $sonRow['qty'];
             $average += $price['average'] * $sonRow['qty'];
         }
     } else {
         $bomPrice = $data[0];
         $low = $bomPrice['low_' . strtolower($currency)];
         $high = $bomPrice['high_' . strtolower($currency)];
         $average = $bomPrice['average_' . strtolower($currency)];
     }
     return array('low' => round($low, 4), 'high' => round($high, 4), 'average' => round($average, 4));
 }
示例#2
0
 /**
  * bom dosage
  * @param $id
  * @param $name
  * @return string
  */
 public function getmaterieldosageAction()
 {
     $code = $this->getRequest()->getParam('code');
     $data = array();
     if ($code) {
         $fa = new Product_Model_Fa();
         $son = new Product_Model_Son();
         $materiel = new Product_Model_Materiel();
         $catalog = new Product_Model_Catalog();
         // first step: find recordkey from bom_son
         $recordkeyData = $son->getJoinList("code = '{$code}'", array(), array('recordkey', 'code', 'qty', 'partposition', 'replace'));
         $recordkeys = $codes = $qtys = $partpositions = $replaces = array();
         foreach ($recordkeyData as $r) {
             if (!in_array($r['recordkey'], $recordkeys)) {
                 $recordkey = $r['recordkey'];
                 $recordkeys[] = $recordkey;
                 $codes[$recordkey] = $r['code'];
                 $qtys[$recordkey] = $r['qty'];
                 $partpositions[$recordkey] = $r['partposition'];
                 $replaces[$recordkey] = $r['replace'];
             }
         }
         // second step: query bom code from bom_son with recordkey
         if (count($recordkeys) > 0) {
             $join = array(array('type' => INNERJOIN, 'table' => $materiel->getName(), 'condition' => $materiel->getName() . '.code = ' . $fa->getName() . '.code', 'cols' => array('name', 'description')), array('type' => LEFTJONIN, 'table' => $catalog->getName(), 'condition' => $catalog->getName() . '.id = ' . $fa->getName() . '.project_no', 'cols' => array('project_no_name' => 'model_internal')));
             $where = $fa->getName() . ".recordkey in (" . implode(',', $recordkeys) . ") and " . $fa->getName() . ".state != 'Obsolete'";
             $data = $fa->getJoinList($where, $join, array('sid', 'recordkey', 'code', 'state', 'ver', 'bom_upd_time'));
             for ($i = 0; $i < count($data); $i++) {
                 $recordkey = $data[$i]['recordkey'];
                 $data[$i]['archive_time'] = strtotime($data[$i]['bom_upd_time']);
                 $data[$i]['qty'] = $qtys[$recordkey];
                 $data[$i]['partposition'] = $partpositions[$recordkey];
                 $data[$i]['replace'] = $replaces[$recordkey];
             }
         }
     }
     echo Zend_Json::encode($data);
     exit;
 }