/** * 按品名,型号为分组查询库存 * * @param unknown_type $condition * @return unknown */ public function queryCurrentStocksByGoods($condition = '') { try { $sql = "select goodsName,spec,sum(qty) as qty,voltage1,current1," . "direct,constant,grade,madeIn,madeDate,memo" . " from " . (DB_PREFIX ? DB_PREFIX . "_" : "") . "currentstocks "; if ($condition != '') { $sql .= " where " . $condition; } $sql .= "group by goodsName,spec,voltage1,current1"; $fields = "goodsName,spec,qty,voltage1,current1,direct,constant,grade,madeIn,madeDate,memo"; $stocks = new StocksManagerAction(); $result = $stocks->queryCurrentStocksWithSQL($sql); $struct = $stocks->getStruct(); if ($fields != '*') { $field = explode(',', $fields); $visible = array("_type_" => "INCLUDE", "data" => $field); $struct["visible"] = $visible; $struct["item"] = $field; } $rtn["struct"] = $struct; $rtn["data"] = $result; return $rtn; } catch (Exception $e) { system_out("StocksManager.queryCurrentStocksByGoods:" . $e); return false; } }
/** * 查询超期库存 * * @param String $condition * @param number $expireday */ public function queryCurrentStocksExpire($condition = '', $expireday = 0) { try { $stoday = date('y-m-d'); switch (DB_TYPE) { case 'mysql': $sql = "select `code`,`goodsName`,`spec`,`qty`,`voltage1`,`current1`," . "`direct`,`constant`,`grade`,`madeIn`,`madeDate`,datediff('" . $stoday . "',indateDate) as overdate,`memo`,place`,`station`" . " from " . (DB_PREFIX ? DB_PREFIX . "_" : "") . "currentstocks "; break; case 'SQLite': $sql = "select `code`,`goodsName`,`spec`,`qty`,`voltage1`,`current1`," . "`direct`,`constant`,`grade`,`madeIn`,`madeDate`,(julianday('now') - julianday(indateDate)) as overdate,`memo`,place`,`station`" . " from " . (DB_PREFIX ? DB_PREFIX . "_" : "") . "currentstocks "; break; } if ($condition != '') { switch (DB_TYPE) { case 'mysql': $sql .= " where " . $condition . " and datediff('" . $stoday . "',indateDate)>=" . $expireday; break; case 'SQLite': $sql .= " where " . $condition . " and julianday('now') - julianday(indateDate)>=" . $expireday; break; } } else { switch (DB_TYPE) { case 'mysql': $sql .= "where " . "datediff('" . $stoday . "',indateDate)>=" . $expireday; break; case 'SQLite': $sql .= "where " . "datediff('" . $stoday . "',indateDate)>=" . $expireday; $sql .= " where " . "julianday('now') - julianday(indateDate)>=" . $expireday; break; } } $field = "code,goodsName,spec,qty,overdate,voltage1,current1," . "direct,constant,grade,madeIn,madeDate,memo,place,station"; $action = new StocksManagerAction(); $result = $action->queryCurrentStocksWithSQL($sql); if ($result) { for ($i = 0; $i < sizeof($result); $i++) { $result[$i]["overdate"] = (int) $result[$i]["overdate"]; } //计算合计 $sumrecord['goodsName'] = '合计:'; $sumrecord["qty"] = ExFunction::ex_array_sum($result, 'qty'); array_push($result, $sumrecord); } $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"] = $result; return $rtn; } catch (ExecBackEnd $e) { system_out("Report.queryCurrentStocksExpire error:" . $e); throw new ExcelDateUtil($e); } }