| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- <?php
- class goodsClassAction extends Action
- {
- public $goodsobj;
- public function initAction()
- {
- $this->goodsobj = m('goods');
- }
-
- private function gettypename($tid)
- {
- return $this->goodsobj->gettypename($tid);
- }
-
- public function aftershow($table, $rows)
- {
- $typearr = $depotarr = array();
- $mid = (int)$this->post('mid','0');//根据主表出入库操作
- if($rows){
- $aid = '0';
- foreach($rows as $k=>$rs){
- $rows[$k]['typeid'] = $this->gettypename($rs['typeid']);
- $aid.=','.$rs['id'].'';
- if($rs['stock']=='0')$rows[$k]['stock'] = '';
- if($rs['stock']<0)$rows[$k]['ishui']=1;
- }
- $rows = $this->pandian($aid, $rows);
- }else{
- if($mid>0){
- m('goodm')->update('state=1', $mid);
- }
- }
- if($this->loadci==1){
- $type = (int)$this->post('type');
- $typearr= $this->option->getdata('kutype'.$type.'');
- $where = m('admin')->getcompanywhere(1);
- $depotarr = m('godepot')->getall('1=1'.$where.'','id,depotname as name,depotnum','`sort`');
- foreach($depotarr as $k=>$rs){
- $depotarr[$k]['namea']= $rs['name'];
- $depotarr[$k]['name'] = ''.$rs['depotnum'].'.'.$rs['name'].'';
- }
- }
- return array(
- 'rows' => $rows,
- 'typearr' => $typearr,
- 'depotarr' => $depotarr,
- );
- }
-
- public function beforeshow($table)
- {
- $key = $this->post('key');
- $typeid = (int)$this->post('typeid');
- $mid = (int)$this->post('mid','0');//根据主表出入库操作
- $where = '';
- if($typeid != 0){
- $alltpeid = $this->option->getalldownid($typeid);
- $where .= ' and `typeid` in('.$alltpeid.')';
- }
- if($key!=''){
- $where .= " and (`name` like '%$key%' or `num` like '%$key%' or `guige` like '%$key%' or `xinghao` like '%$key%') ";
- }
-
- $where.=m('admin')->getcompanywhere(1);
-
- if($mid>0){
- /*
- $carro = m('goodn')->getall('mid='.$mid.' and `couns`<`count`');
- $typeids = '0';
- foreach($carro as $k=>$rs)$typeids.=','.$rs['aid'].'';
- $where .= ' and `id` in('.$typeids.')';
- */
- return array(
- 'where' => 'and b.`mid`='.$mid.' and b.`couns`<b.`count`',
- 'fields' => 'a.*,(b.`count`-b.`couns`)maxcount',
- 'table' => '`[Q]goods` a left join `[Q]goodn` b on a.`id`=b.`aid`'
- );
- }
-
- return $where;
- }
-
-
- //盘点对应仓库库存计算
- private function pandian($aid,$rows)
- {
- if($this->post('atype')!='pan')return $rows;
-
- $ckarr = m('goods')->getstock($aid, $this->post('dt'));
- foreach($rows as $k=>&$rs){
- $rs['stock'] = '';
- if(isset($ckarr[$rs['id']])){
- $kdsra= $ckarr[$rs['id']];
- $rs['stock'] = $kdsra[0]=='0'?'':$kdsra[0]; //总库存
-
- foreach($kdsra as $k1=>$v1){
- if($k1>0)$rs['stockdepotid'.$k1.''] = $v1=='0'?'':$v1; //对应仓库库存
- }
- }
- }
-
- return $rows;
- }
-
- public function xiangbeforeshow($table)
- {
- $key = $this->post('key');
- $dt = $this->post('dt');
- $types = $this->post('types');
- $typeid = (int)$this->post('typeid', 0);
- $depotid = (int)$this->post('depotid', 0);
-
- $where = '';
- if($typeid>0){
- $alltpeid = $this->option->getalldownid($typeid);
- $where.=" and b.typeid in($alltpeid)";
- }
- if($key!=''){
- $where .= " and (b.`name` like '%$key%' or a.optname like '%$key%' or c.depotname like '%$key%' )";
- }
- if($dt!=''){
- $where .= " and a.`applydt` like '$dt%' ";
- }
- if($depotid>0){
- $where .= " and a.`depotid`='$depotid'";
- }
- if($types){
- $typea = explode('_', $types);
- $where.= ' and a.type='.substr($typea[0],1).' and a.kind='.$typea[1].'';
- }
-
- $where .= m('admin')->getcompanywhere(1,'a.');
- $table = '`[Q]goodss` a left join `[Q]goods` b on a.aid=b.id left join `[Q]godepot` c on a.depotid=c.id';
- $fields = 'a.id,b.name,a.count,c.depotname,a.type,a.kind,a.status,a.optname,b.typeid,b.xinghao,b.guige,a.applydt,a.explain,a.mid';
- return array(
- 'where' => $where,
- 'table' => $table,
- 'fields' => $fields,
- );
- }
-
- public function xiangaftershow($table, $rows)
- {
- $tyeparr = array();
- if($rows){
- $typearr0= $this->option->getdata('kutype0');
- $typearr1= $this->option->getdata('kutype1');
- $tyeparr['a0_3'] = '调拨入库';
- $tyeparr['a1_3'] = '调拨出库';
- foreach($typearr0 as $k=>$rs)$tyeparr['a0_'.$rs['value'].''] = $rs['name'];
- foreach($typearr1 as $k=>$rs)$tyeparr['a1_'.$rs['value'].''] = $rs['name'];
- $statusar= array('<font color=blue>待审核</font>','<font color=green>已审核</font>','<font color=red>审核未通过</font>');
- $typearr = array();
-
- foreach($rows as $k=>$rs){
-
- $tid = $rs['typeid'];
- if(isset($typearr[$tid])){
- $rows[$k]['typeid'] = $typearr[$tid];
- }else{
- $rows[$k]['typeid'] = $this->db->getpval('[Q]option','pid','name', $tid,'/','id',2);
- $typearr[$tid] = $rows[$k]['typeid'];
- }
-
- $skey = 'a'.$rs['type'].'_'.$rs['kind'].'';
- $kind = '';
- if(isset($tyeparr[$skey]))$kind = $tyeparr[$skey];
- $rows[$k]['kind'] = $kind;
- $rows[$k]['status'] = $statusar[$rs['status']];
- if($rs['mid']>0)$rows[$k]['checkdisabled'] = true;//有主表ID,不能删除
- }
- }
- $barr = array('rows' => $rows,'tyeparr'=>$tyeparr);
- return $barr;
- }
-
- /**
- * 删除出入库详情
- */
- public function delxiangAjax()
- {
- $ids = c('check')->onlynumber($this->post('id','0'));
- m('goodss')->delete("id in($ids) and `mid`=0");
- backmsg();
- }
-
- public function chukuoptAjax()
- {
- $dt = $this->post('dt');
- $type = (int)$this->post('type');
- $depotid= (int)$this->post('depotid');
- $kind = (int)$this->post('kind');
- $mid = (int)$this->post('mid','0');
- $sm = $this->post('sm');
- $cont = $this->post('cont');
- $sharr = c('array')->strtoarray($cont);
- $arr['applydt'] = $dt;
- $arr['type'] = $type;
- $arr['kind'] = $kind;
- $arr['depotid'] = $depotid;
- $arr['explain'] = $sm;
- $arr['uid'] = $this->adminid;
- $arr['optid'] = $this->adminid;
- $arr['optdt'] = $this->now;
- $arr['comid'] = m('admin')->getcompanyid();
- $arr['optname'] = $this->adminname;
- $arr['status'] = 1;
- $aid = '0';
-
- $ndbs = m('goodn');
-
- $mtype = -1;
-
- //根据主表出入库操作
- if($mid>0){
- $mrs = m('goodm')->getone("`id`='$mid' and `status`=1");
- if(!$mrs)return '该单据还未审核完成,不能出入库操作';
- //读取已入库数量
- $arwos = $ndbs->getall('`mid`='.$mid.' and `couns`<`count`');
- $ruks = array();
- foreach($arwos as $k1=>$rs1){
- $ruks[$rs1['aid']] = array(
- 'kes' => floatval($rs1['count']) - floatval($rs1['couns']),//还可入库数
- 'id' => $rs1['id'],
- 'couns' => floatval($rs1['couns'])
- );
- }
- $mtype = (int)$mrs['type']; //3就是调拨
- $arr['comid'] = $mrs['comid'];
- }
-
- //调拨必须先出库原来的
- if($mtype==3 && $depotid==$mrs['custid'])return '调拨出入库仓库不能相同';
-
-
- foreach($sharr as $k=>$rs){
- $arr['aid'] = $rs[0];
- $count = (int)$rs[1];
- $arr['depotid'] = $depotid;
- $arr['type'] = $type;
- $arr['explain'] = $sm;
-
- if($count<0)$count = 0-$count;
-
- if($mid>0){
- if(!isset($ruks[$arr['aid']]))continue;
- $shua = $ruks[$arr['aid']];
- if($count>$shua['kes'])$count=$shua['kes'];//超过
- $arr['mid'] = $mid;
- }
-
-
- if($count==0)continue;
-
-
- $arr['count'] = $count;
- if($type==1)$arr['count'] = 0- $arr['count'];//出库为负数
-
- $ussid = $this->db->record('[Q]goodss', $arr);
- $aid.=','.$rs[0].'';
-
- //更新已出入库的数量
- if($mid>0 && $ussid){
- $ndbs->update('`couns`=`couns`+'.$count.'', $shua['id']);
- }
-
- if($mtype==3){
- $arr['depotid'] = $mrs['custid']; //仓库
- $arr['type'] = 1; //出库
- $arr['count'] = 0 - $count;
- //$arr['explain'] = '调拨出库';
- $this->db->record('[Q]goodss', $arr);
- }
- }
- if($aid!='0')m('goods')->setstock($aid);
- if($mid>0){
- m('goods')->upstatem($mid);
- }
- return 'success';
- }
-
-
-
-
-
-
-
-
-
-
- //刷新库存
- public function reloadkcAjax()
- {
- m('goods')->setstock();
- }
-
- //出入库操作
- public function croptbeforeshow($table)
- {
- $key = $this->post('key');
- $where= '';
- if($key!=''){
- $where.=" and (b.`uname` like '%$key%' or b.`sericnum` like '$key%')";
- }
- $where .= m('admin')->getcompanywhere(1,'a.');
- return array(
- 'where' => 'and a.`status`=1 and a.`state`<>1 '.$where.'',
- 'table' => '`[Q]'.$table.'` a left join `[Q]flow_bill` b on a.id=b.mid and b.`table`=\''.$table.'\'',
- 'fields' => 'a.id,a.applydt,a.optdt,a.`explain`,a.`state`,a.`type`,b.uname,b.sericnum,b.udeptname'
- );
- }
- public function croptaftershow($table, $rows)
- {
- $dgs = m('goods');
- $typeb = array('0' ,'1' ,'2' ,'3', '4','5');
- $typea = array('领用单' ,'采购单' ,'销售单' ,'调拨单', '归还单','退货单');
- $chux = array('0','2');
- if($rows)foreach($rows as $k=>&$rs){
- $rs['typev'] = $rs['type'];
- $rs['type'] = arrvalue($typea, $rs['type']);
- $lx = 0; //入
- if(in_array($rs['typev'],$chux))$lx=1;
- $rs['state'] = $dgs->crkstate($rs['state'], $lx);
- }
- return array(
- 'rows' => $rows
- );
- }
-
-
-
-
-
-
-
-
- //根据仓库统计
- public function pdck_beforeshow($table)
- {
- $depotid = (int)$this->post('depotid');
- $where = 'and a.`depotid`='.$depotid.'';
- $key = $this->post('key');
- $dt = $this->post('dt');
-
- if($key!=''){
- $where .= " and (b.`name` like '%$key%' or b.`num` like '%$key%' or b.`guige` like '%$key%' or b.`xinghao` like '%$key%') ";
- }
- if($dt!=''){
- $where .= " and a.`applydt` <= '$dt'";
- }
-
- return array(
- 'table' => '`[Q]goodss` a left join `[Q]goods` b on a.`aid`=b.`id`',
- 'where' => $where,
- 'fields'=> 'b.*,sum(a.`count`) as `stock`',
- 'group' => 'a.`aid`'
- );
- }
- public function pdck_aftershow($table, $rows)
- {
- foreach($rows as $k=>$rs){
- $rows[$k]['typeid'] = $this->gettypename($rs['typeid']);
- if($rs['stock']<='0')$rows[$k]['ishui']=1;
- }
- return array(
- 'rows' => $rows
- );
- }
-
- //打印二维码
- public function printewmAction()
- {
- $sid = c('check')->onlynumber($this->get('sid'));
- $rows= m('goods')->getall('id in('.$sid.')');
-
- foreach($rows as $k=>$rs){
- $rows[$k]['url'] = $this->jm->base64encode('task.php?a=x&num=goods&mid='.$rs['id'].'');
- }
- $this->assign('rows', $rows);
- $this->displayfile = ''.P.'/main/assetm/tpl_assetm_printewm.html';
- $this->title = '物品二维码打印';
- }
- }
|