Пример #1
0
 public function getmaterielAction()
 {
     $request = $this->getRequest()->getParams();
     $whereSearch = "1=1";
     foreach ($request as $k => $v) {
         if ($v) {
             if ($k == "search_state") {
                 continue;
             }
             $col = str_replace('search_', '', $k);
             if ($col != $k) {
                 // 查询条件
                 $whereSearch .= " and ifnull(t1." . $col . ",'') like '%" . $v . "%'";
             }
         }
     }
     $model = "";
     if (isset($request["model"]) && $request["model"]) {
         $model = $request["model"];
     }
     $type = "";
     if (isset($request["type"]) && $request["type"]) {
         $type = $request["type"];
     }
     $materiel = new Product_Model_Materiel();
     $record = new Dcc_Model_Record();
     $db = $materiel->getAdapter();
     $existsIds = array();
     // 获取当前正在流程中的id
     if ($model == 'fa' && $type == 'new') {
         $table = "oa_product_bom_fa_dev";
         $bomIds = $db->query("select t1.id from {$table} t1 inner join oa_product_bom_new t2 on t1.nid=t2.id and t1.type = '{$type}' where t2.state = 'Reviewing' or t2.state = 'Return' or t2.state = 'Active'")->fetchAll();
         if ($bomIds && count($bomIds) > 0) {
             foreach ($bomIds as $ids) {
                 $existsIds[] = $ids['id'];
             }
         }
         //  已归档的
         $whereSearch .= " and t1.id not in (select t.id from oa_product_materiel t inner join oa_product_bom_fa tt where t.code=tt.code)";
         // 获取物料数据
         $data = $materiel->getBomList($whereSearch, 0, 100);
     } else {
         if ($model == 'fa' && ($type == 'DEV' || $type == 'ECO')) {
             $table = "oa_product_bom_fa_dev";
             $bomIds = $db->query("select t1.id from {$table} t1 inner join oa_product_bom_upd t2 on t1.nid=t2.id and t1.type = '{$type}' where t2.state = 'Reviewing' or t2.state = 'Return'")->fetchAll();
             if ($bomIds && count($bomIds) > 0) {
                 foreach ($bomIds as $ids) {
                     $existsIds[] = $ids['id'];
                 }
             }
             // 已存在的BOM
             $sql = "select distinct id from oa_product_bom_fa";
             /* if($type == 'ECO') {
               		$sql = "select distinct id from oa_product_bom_fa where state = 'MBOM'";
               	} */
             $results = $db->query($sql)->fetchAll();
             $bomIds = array();
             foreach ($results as $row) {
                 $bomIds[] = $row['id'];
             }
             $ids = array();
             if (count($bomIds) > 0) {
                 foreach ($bomIds as $id) {
                     if (!in_array($id, $ids)) {
                         $ids[] = $id;
                     }
                 }
             }
             if (count($ids) > 0) {
                 $whereSearch .= " and t1.id in (" . implode(',', $ids) . ")";
             }
             // 获取物料数据
             $data = $materiel->getBomList($whereSearch, 0, 100);
         } else {
             if ($model == 'son') {
                 /* if($type == 'ECO') {
                   		$whereSearch .= " and t1.state = 'APL'";
                   	} */
                 $data = $materiel->getArchiveList($whereSearch, 0, 100);
             }
         }
     }
     $tmps = array();
     for ($i = 0; $i < count($data); $i++) {
         if (in_array($data[$i]['id'], $existsIds)) {
             continue;
         }
         if (($typeId = $data[$i]['type']) != '') {
             $typeName = $this->getTypeByConnect($typeId, '');
             $data[$i]['type_name'] = $typeName;
         }
         $data[$i]['remark1'] = $data[$i]['remark'];
         $data[$i]['sid'] = $data[$i]['id'] . time();
         $data[$i]['remark'] = "";
         $data[$i]['qty'] = "1";
         if (isset($data[$i]['model_internal']) && !$data[$i]['project_no']) {
             $data[$i]['project_no'] = $data[$i]['model_internal'];
         }
         $tmps[] = $data[$i];
     }
     // 转为json格式并输出
     echo Zend_Json::encode($tmps);
     exit;
 }