Example #1
0
 /**
  * 通过条码从本系统中获取产品信息
  *
  * @param string $code
  * @return array
  */
 public function getInfoByCodeFormMySystem($code)
 {
     try {
         $tablename = StocksIndexAction::getTableNameByCode($code);
         if (!$tablename) {
             return false;
         }
         $dao = new StocksDao();
         $result = '';
         foreach ($tablename as $table) {
             $sql = "select * from {$table} where id=\n\t\t\t\t\t\t\t\t( select max(id) from {$table} where code = '{$code}') ";
             $result = $dao->query($sql)->toArray();
             if (!$result) {
                 continue;
             } else {
                 break;
             }
         }
         if (!$result) {
             return false;
         } else {
             return $result[0];
         }
     } catch (Exception $e) {
         throw new Exception($e);
     }
 }
 /**
  * 获取数据存放表名
  *
  * @param Date $date 日期
  * @return String 表名
  */
 public static function getSaveTableName($date)
 {
     try {
         $result = StocksIndexAction::getTableNameByDate($date);
         if ($result) {
             return $result;
         } else {
             //create new table
             $tablename = StocksIndexAction::createNewTable();
             //create table index
             if ($tablename) {
                 StocksIndexAction::createTableIndex($date, $tablename);
             }
             return $tablename;
         }
     } catch (Exception $e) {
         throw new Exception($e);
     }
 }
 /**
  * 确认表所放的位置
  *
  * @param $billno	单据号
  * @param $data  	数据 array("station"=>,"code"=>)
  * @return boolean
  */
 public function confirmInstation($billdata, $data)
 {
     $sysno = $billdata['sysno'];
     $billdate = $billdata['billDate'];
     //明细表
     $stocks = new StocksDao();
     $stocks->startTrans();
     //当前库存表
     $current = new CurrentStocksDao();
     $current->startTrans();
     //未确认表位
     $unconfirm = new UnconfirmstationDao();
     $unconfirm->startTrans();
     try {
         $newinsert = false;
         $station = $data["station"];
         $code = $data["code"];
         $result = $current->findAll("`code`='{$code}'")->toResultSet();
         if (sizeof($result) == 0 && NOBILL_SCAN == false) {
             $stocks->rollback();
             $current->rollback();
             $unconfirm->rollback();
             $this->setError("库存里找不到该条码[{$code}]对应的表计!");
             return false;
         } else {
             if (sizeof($result) == 0) {
                 $newinsert = true;
                 $codeinfo = new CodeInfo();
                 $codedetail = $codeinfo->getInfoByCode($code);
                 $vo = $stocks->createVo('add', '', 'id', 0, $codedetail);
                 $vo->id = 0;
                 $vo->inoutType = 'IN';
                 $vo->code = $code;
                 $vo->sysno = $billdata['sysno'];
                 $vo->placeno = $billdata['placeno'];
                 $vo->place = $billdata['place'];
                 $vo->billType = $billdata['billType'];
                 $vo->billDate = $billdata['billDate'];
                 $vo->billNo = $billdata['billNo'];
                 $vo->sendMan = $billdata['sendMan'];
                 $vo->saveMan = $billdata['saveMan'];
                 $vo->orderNo = $billdata['orderNo'];
                 $vo->client = $billdata['client'];
                 $vo->inqty = 1;
                 $vo->outqty = 0;
                 $vo->station = $station;
                 //inert new records
                 $stocksmanageraction = new StocksManagerAction();
                 $savedata["modify"] = array($vo->toArray());
                 $result = $stocksmanageraction->save($savedata);
                 if (!$result) {
                     system_out("create new recod error:" . $stocksmanageraction->getError());
                     $this->setError($stocksmanageraction->getError());
                     return false;
                 }
             }
         }
         $sql = "UPDATE " . (DB_PREFIX ? DB_PREFIX . "_" : "") . "currentstocks\n\t\t\t           SET `station`='{$station}'\n\t\t\t\t\t WHERE `code` ='{$code}'";
         system_out("update sql:" . $sql);
         $current->execute($sql);
         if (!$newinsert) {
             //返写stocks
             $result = StocksIndexAction::getTableNameByDate($billdate);
             if ($result == '') {
                 $stocks->rollback();
                 $current->rollback();
                 $unconfirm->rollback();
                 system_out("get tablename error,billdate:" . $billdate);
                 $this->setError("获取存储表出错!");
                 return false;
             }
             $tablename = $result;
             $sql = "UPDATE\t`{$tablename}`\n\t\t\t\t\t\t   SET `station` = '{$station}'\n\t\t\t\t\t\t WHERE `code` = '{$code}' and\n\t\t\t\t\t\t \t\t`sysno` = '{$sysno}' ";
             $stocks->execute($sql);
         }
         //标记已经确认的开灯记录
         $sql = "UPDATE " . (DB_PREFIX ? DB_PREFIX . "_" : "") . "unconfirmstation\n\t\t\t           SET  `confirm` = 1\n\t\t\t\t\t WHERE  `station` = '{$station}' and `state`='U'";
         $unconfirm->execute($sql);
     } catch (Exception $e) {
         $stocks->rollback();
         $current->rollback();
         $unconfirm->rollback();
         system_out("UnconfirmstationAction.confirmInstation error:{$e},\n\t\t\t\t\t\tsysno:{$sysno},data:" . print_r($data, true));
         throw new Exception($e);
     }
     //commit
     $stocks->commit();
     $current->commit();
     $unconfirm->commit();
     return true;
 }
 /**
  * 保存
  *
  * @param Array $data  Example:$data["modify"] = array()
  *                             $data["delete"} = array()
  * @return boolean true if succeed
  */
 public function save($data)
 {
     //明细表
     $stocks = new StocksDao();
     $stocks->startTrans();
     //当前库存表
     $current = new CurrentStocksDao();
     $current->startTrans();
     $modify = $data["modify"];
     $delete = $data["delete"];
     //删除的数据
     for ($i = 0; $i < sizeof($delete); $i++) {
         try {
             $tablename = StocksIndexAction::getSaveTableName($delete[$i]["billDate"]);
             if ($delete[$i]["id"] != '') {
                 $vo = $stocks->find("id=" . $delete[$i]["id"], $tablename);
                 //if($vo==true && $vo->station != '' && $vo->station != null)
                 //{
                 //	$stocks->rollback();
                 //	$current->rollback() ;
                 //	$this->setError("[" . $delete[$i]["code"] . "]已经确认位置,不能删除");
                 //	return false ;
                 //}
                 $rtn = $stocks->deleteById($delete[$i]["id"], $tablename);
                 //减库存
                 if ($vo != null && !$vo->isEmpty()) {
                     $rtn = $this->createCurrentStocks($current, '', $vo->toArray());
                     if (!$rtn) {
                         $stocks->rollback();
                         $current->rollback();
                         $this->setError($this->getError());
                         return false;
                     }
                 }
             }
             //end if
         } catch (Exception $e) {
             $current->rollback();
             $stocks->rollback();
             throw new Exception($e);
         }
         //end try
     }
     //end for
     //保存人员近参数表
     $otherparm = new OtherParmSetupAction();
     $otherparm->addParm('other', 'member', $modify[0]['sendMan']);
     $mis = new MIS();
     //添加/修改的数据
     for ($i = 0; $i < sizeof($modify); $i++) {
         //保存进库存明细表
         try {
             $tablename = StocksIndexAction::getSaveTableName($modify[$i]["billDate"]);
             if ($modify[$i]["id"] == '' || $modify[$i]["id"] == null || $modify[$i]["id"] == 0) {
                 $vo = $stocks->createVo('add', '', 'id', 0, $modify[$i]);
                 $result = $stocks->add($vo, $tablename);
                 if (!$result) {
                     $stocks->rollback();
                     $current->rollback();
                     system_out("StocksManagerActin.save error:新增数据保存出错,errcode:{$result}");
                     $this->setError("数据保存出错!");
                     return false;
                 }
                 //生成当前库存表
                 $rtn = $this->createCurrentStocks($current, $vo->toArray(), '');
                 if (!$rtn) {
                     $current->rollback();
                     $stocks->rollback();
                     $this->setError($this->getError());
                     return false;
                 }
                 //增加条码索引
                 if ($vo->code != '' && $vo->code != null) {
                     CodeIndexAction::addCodeIndex($vo->billDate, $vo->code);
                 }
                 //输出出库列表
                 $result = $mis->outPut($modify[$i]);
             } else {
                 $vo = $stocks->find("id=" . $modify[$i]["id"], $tablename);
                 if (!$vo) {
                     $stocks->rollback();
                     $current->rollback();
                     $this->setError("数据保存出错,数据在保存前已被删除!");
                     return false;
                 }
                 $oldvo = clone $vo;
                 //给Vo对象赋值
                 $this->refreshStocksInfo(&$vo, $modify[$i]);
                 $result = $stocks->save($vo, $tablename);
                 if (!$result) {
                     $stocks->rollback();
                     $current->rollback();
                     system_out("StocksManagerActin.save error:修改数据保存出错,errcode:{$result}");
                     $this->setError("数据保存出错,数据在保存前已被删除!");
                     return false;
                 }
                 //生成当前库存表
                 $rtn = $this->createCurrentStocks($current, $vo->toArray(), $oldvo->toArray());
                 if (!$rtn) {
                     $current->rollback();
                     $stocks->rollback();
                     $this->setError($this->getError());
                     return false;
                 }
             }
             //end if
         } catch (Exception $e) {
             $current->rollback();
             $stocks->rollback();
             throw new Exception($e);
         }
         //end try
     }
     //end for
     $stocks->commit();
     $current->commit();
     return true;
 }
Example #5
0
 public function queryLocationDetail($code = '')
 {
     $table = StocksIndexAction::getTableNameByCode($code);
     $volist = new VoList();
     $dao = new StocksDao();
     //开始查询
     for ($i = 0; $i < sizeof($table); $i++) {
         $tablename = $table[$i];
         $result = $dao->findAll("code='{$code}'", $tablename, '*', 'id');
         $volist->addAll($result);
     }
     $field = "billType,billNo,billDate,goodsName,madeIn,code,factoryNo,spec,client,inqty,outqty,voltage1,current1," . "direct,constant,grade,madeDate,memo,place,station";
     $action = new StocksManagerAction();
     $struct = $action->getStruct();
     //如果字段不是全部的,则把必须的字段替换
     if ($field != '*') {
         $field = explode(',', $field);
         $visible = array("_type_" => "INCLUDE", "data" => $field);
         $struct["visible"] = $visible;
         $struct["item"] = $field;
     }
     //返回值
     $rtn["struct"] = $struct;
     $rtn["data"] = $volist->toResultSet();
     return $rtn;
 }