goodsAction.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?php
  2. class goodsClassAction extends Action
  3. {
  4. public function initAction()
  5. {
  6. $this->goodsobj = m('goods');
  7. }
  8. private function gettypename($tid)
  9. {
  10. return $this->goodsobj->gettypename($tid);
  11. }
  12. public function aftershow($table, $rows)
  13. {
  14. $typearr = $depotarr = array();
  15. $mid = (int)$this->post('mid','0');//根据主表出入库操作
  16. if($rows){
  17. $aid = '0';
  18. foreach($rows as $k=>$rs){
  19. $rows[$k]['typeid'] = $this->gettypename($rs['typeid']);
  20. $aid.=','.$rs['id'].'';
  21. if($rs['stock']=='0')$rows[$k]['stock'] = '';
  22. if($rs['stock']<0)$rows[$k]['ishui']=1;
  23. }
  24. $rows = $this->pandian($aid, $rows);
  25. }else{
  26. if($mid>0){
  27. m('goodm')->update('state=1', $mid);
  28. }
  29. }
  30. if($this->loadci==1){
  31. $type = (int)$this->post('type');
  32. $typearr= $this->option->getdata('kutype'.$type.'');
  33. $where = m('admin')->getcompanywhere(1);
  34. $depotarr = m('godepot')->getall('1=1'.$where.'','id,depotname as name,depotnum','`sort`');
  35. foreach($depotarr as $k=>$rs){
  36. $depotarr[$k]['namea']= $rs['name'];
  37. $depotarr[$k]['name'] = ''.$rs['depotnum'].'.'.$rs['name'].'';
  38. }
  39. }
  40. return array(
  41. 'rows' => $rows,
  42. 'typearr' => $typearr,
  43. 'depotarr' => $depotarr,
  44. );
  45. }
  46. public function beforeshow($table)
  47. {
  48. $key = $this->post('key');
  49. $typeid = (int)$this->post('typeid');
  50. $mid = (int)$this->post('mid','0');//根据主表出入库操作
  51. $where = '';
  52. if($typeid != 0){
  53. $alltpeid = $this->option->getalldownid($typeid);
  54. $where .= ' and `typeid` in('.$alltpeid.')';
  55. }
  56. if($key!=''){
  57. $where .= " and (`name` like '%$key%' or `num` like '%$key%' or `guige` like '%$key%' or `xinghao` like '%$key%') ";
  58. }
  59. $where.=m('admin')->getcompanywhere(1);
  60. if($mid>0){
  61. /*
  62. $carro = m('goodn')->getall('mid='.$mid.' and `couns`<`count`');
  63. $typeids = '0';
  64. foreach($carro as $k=>$rs)$typeids.=','.$rs['aid'].'';
  65. $where .= ' and `id` in('.$typeids.')';
  66. */
  67. return array(
  68. 'where' => 'and b.`mid`='.$mid.' and b.`couns`<b.`count`',
  69. 'fields' => 'a.*,(b.`count`-b.`couns`)maxcount',
  70. 'table' => '`[Q]goods` a left join `[Q]goodn` b on a.`id`=b.`aid`'
  71. );
  72. }
  73. return $where;
  74. }
  75. //盘点对应仓库库存计算
  76. private function pandian($aid,$rows)
  77. {
  78. if($this->post('atype')!='pan')return $rows;
  79. $ckarr = m('goods')->getstock($aid, $this->post('dt'));
  80. foreach($rows as $k=>&$rs){
  81. $rs['stock'] = '';
  82. if(isset($ckarr[$rs['id']])){
  83. $kdsra= $ckarr[$rs['id']];
  84. $rs['stock'] = $kdsra[0]=='0'?'':$kdsra[0]; //总库存
  85. foreach($kdsra as $k1=>$v1){
  86. if($k1>0)$rs['stockdepotid'.$k1.''] = $v1=='0'?'':$v1; //对应仓库库存
  87. }
  88. }
  89. }
  90. return $rows;
  91. }
  92. public function xiangbeforeshow($table)
  93. {
  94. $key = $this->post('key');
  95. $dt = $this->post('dt');
  96. $types = $this->post('types');
  97. $typeid = (int)$this->post('typeid', 0);
  98. $depotid = (int)$this->post('depotid', 0);
  99. $where = '';
  100. if($typeid>0){
  101. $alltpeid = $this->option->getalldownid($typeid);
  102. $where.=" and b.typeid in($alltpeid)";
  103. }
  104. if($key!=''){
  105. $where .= " and (b.`name` like '%$key%' or a.optname like '%$key%' or c.depotname like '%$key%' )";
  106. }
  107. if($dt!=''){
  108. $where .= " and a.`applydt` like '$dt%' ";
  109. }
  110. if($depotid>0){
  111. $where .= " and a.`depotid`='$depotid'";
  112. }
  113. if($types){
  114. $typea = explode('_', $types);
  115. $where.= ' and a.type='.substr($typea[0],1).' and a.kind='.$typea[1].'';
  116. }
  117. $where .= m('admin')->getcompanywhere(1,'a.');
  118. $table = '`[Q]goodss` a left join `[Q]goods` b on a.aid=b.id left join `[Q]godepot` c on a.depotid=c.id';
  119. $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';
  120. return array(
  121. 'where' => $where,
  122. 'table' => $table,
  123. 'fields' => $fields,
  124. );
  125. }
  126. public function xiangaftershow($table, $rows)
  127. {
  128. $tyeparr = array();
  129. if($rows){
  130. $typearr0= $this->option->getdata('kutype0');
  131. $typearr1= $this->option->getdata('kutype1');
  132. $tyeparr['a0_3'] = '调拨入库';
  133. $tyeparr['a1_3'] = '调拨出库';
  134. foreach($typearr0 as $k=>$rs)$tyeparr['a0_'.$rs['value'].''] = $rs['name'];
  135. foreach($typearr1 as $k=>$rs)$tyeparr['a1_'.$rs['value'].''] = $rs['name'];
  136. $statusar= array('<font color=blue>待审核</font>','<font color=green>已审核</font>','<font color=red>审核未通过</font>');
  137. $typearr = array();
  138. foreach($rows as $k=>$rs){
  139. $tid = $rs['typeid'];
  140. if(isset($typearr[$tid])){
  141. $rows[$k]['typeid'] = $typearr[$tid];
  142. }else{
  143. $rows[$k]['typeid'] = $this->db->getpval('[Q]option','pid','name', $tid,'/','id',2);
  144. $typearr[$tid] = $rows[$k]['typeid'];
  145. }
  146. $skey = 'a'.$rs['type'].'_'.$rs['kind'].'';
  147. $kind = '';
  148. if(isset($tyeparr[$skey]))$kind = $tyeparr[$skey];
  149. $rows[$k]['kind'] = $kind;
  150. $rows[$k]['status'] = $statusar[$rs['status']];
  151. if($rs['mid']>0)$rows[$k]['checkdisabled'] = true;//有主表ID,不能删除
  152. }
  153. }
  154. $barr = array('rows' => $rows,'tyeparr'=>$tyeparr);
  155. return $barr;
  156. }
  157. /**
  158. * 删除出入库详情
  159. */
  160. public function delxiangAjax()
  161. {
  162. $ids = c('check')->onlynumber($this->post('id','0'));
  163. m('goodss')->delete("id in($ids) and `mid`=0");
  164. backmsg();
  165. }
  166. public function chukuoptAjax()
  167. {
  168. $dt = $this->post('dt');
  169. $type = (int)$this->post('type');
  170. $depotid= (int)$this->post('depotid');
  171. $kind = (int)$this->post('kind');
  172. $mid = (int)$this->post('mid','0');
  173. $sm = $this->post('sm');
  174. $cont = $this->post('cont');
  175. $sharr = c('array')->strtoarray($cont);
  176. $arr['applydt'] = $dt;
  177. $arr['type'] = $type;
  178. $arr['kind'] = $kind;
  179. $arr['depotid'] = $depotid;
  180. $arr['explain'] = $sm;
  181. $arr['uid'] = $this->adminid;
  182. $arr['optid'] = $this->adminid;
  183. $arr['optdt'] = $this->now;
  184. $arr['comid'] = m('admin')->getcompanyid();
  185. $arr['optname'] = $this->adminname;
  186. $arr['status'] = 1;
  187. $aid = '0';
  188. $ndbs = m('goodn');
  189. $mtype = -1;
  190. //根据主表出入库操作
  191. if($mid>0){
  192. $mrs = m('goodm')->getone("`id`='$mid' and `status`=1");
  193. if(!$mrs)return '该单据还未审核完成,不能出入库操作';
  194. //读取已入库数量
  195. $arwos = $ndbs->getall('`mid`='.$mid.' and `couns`<`count`');
  196. $ruks = array();
  197. foreach($arwos as $k1=>$rs1){
  198. $ruks[$rs1['aid']] = array(
  199. 'kes' => floatval($rs1['count']) - floatval($rs1['couns']),//还可入库数
  200. 'id' => $rs1['id'],
  201. 'couns' => floatval($rs1['couns'])
  202. );
  203. }
  204. $mtype = (int)$mrs['type']; //3就是调拨
  205. $arr['comid'] = $mrs['comid'];
  206. }
  207. //调拨必须先出库原来的
  208. if($mtype==3 && $depotid==$mrs['custid'])return '调拨出入库仓库不能相同';
  209. foreach($sharr as $k=>$rs){
  210. $arr['aid'] = $rs[0];
  211. $count = (int)$rs[1];
  212. $arr['depotid'] = $depotid;
  213. $arr['type'] = $type;
  214. $arr['explain'] = $sm;
  215. if($count<0)$count = 0-$count;
  216. if($mid>0){
  217. if(!isset($ruks[$arr['aid']]))continue;
  218. $shua = $ruks[$arr['aid']];
  219. if($count>$shua['kes'])$count=$shua['kes'];//超过
  220. $arr['mid'] = $mid;
  221. }
  222. if($count==0)continue;
  223. $arr['count'] = $count;
  224. if($type==1)$arr['count'] = 0- $arr['count'];//出库为负数
  225. $ussid = $this->db->record('[Q]goodss', $arr);
  226. $aid.=','.$rs[0].'';
  227. //更新已出入库的数量
  228. if($mid>0 && $ussid){
  229. $ndbs->update('`couns`=`couns`+'.$count.'', $shua['id']);
  230. }
  231. if($mtype==3){
  232. $arr['depotid'] = $mrs['custid']; //仓库
  233. $arr['type'] = 1; //出库
  234. $arr['count'] = 0 - $count;
  235. //$arr['explain'] = '调拨出库';
  236. $this->db->record('[Q]goodss', $arr);
  237. }
  238. }
  239. if($aid!='0')m('goods')->setstock($aid);
  240. if($mid>0){
  241. m('goods')->upstatem($mid);
  242. }
  243. return 'success';
  244. }
  245. //刷新库存
  246. public function reloadkcAjax()
  247. {
  248. m('goods')->setstock();
  249. }
  250. //出入库操作
  251. public function croptbeforeshow($table)
  252. {
  253. $key = $this->post('key');
  254. $where= '';
  255. if($key!=''){
  256. $where.=" and (b.`uname` like '%$key%' or b.`sericnum` like '$key%')";
  257. }
  258. $where .= m('admin')->getcompanywhere(1,'a.');
  259. return array(
  260. 'where' => 'and a.`status`=1 and a.`state`<>1 '.$where.'',
  261. 'table' => '`[Q]'.$table.'` a left join `[Q]flow_bill` b on a.id=b.mid and b.`table`=\''.$table.'\'',
  262. 'fields' => 'a.id,a.applydt,a.optdt,a.`explain`,a.`state`,a.`type`,b.uname,b.sericnum,b.udeptname'
  263. );
  264. }
  265. public function croptaftershow($table, $rows)
  266. {
  267. $dgs = m('goods');
  268. $typeb = array('0' ,'1' ,'2' ,'3', '4','5');
  269. $typea = array('领用单' ,'采购单' ,'销售单' ,'调拨单', '归还单','退货单');
  270. $chux = array('0','2');
  271. if($rows)foreach($rows as $k=>&$rs){
  272. $rs['typev'] = $rs['type'];
  273. $rs['type'] = arrvalue($typea, $rs['type']);
  274. $lx = 0; //入
  275. if(in_array($rs['typev'],$chux))$lx=1;
  276. $rs['state'] = $dgs->crkstate($rs['state'], $lx);
  277. }
  278. return array(
  279. 'rows' => $rows
  280. );
  281. }
  282. //根据仓库统计
  283. public function pdck_beforeshow($table)
  284. {
  285. $depotid = (int)$this->post('depotid');
  286. $where = 'and a.`depotid`='.$depotid.'';
  287. $key = $this->post('key');
  288. $dt = $this->post('dt');
  289. if($key!=''){
  290. $where .= " and (b.`name` like '%$key%' or b.`num` like '%$key%' or b.`guige` like '%$key%' or b.`xinghao` like '%$key%') ";
  291. }
  292. if($dt!=''){
  293. $where .= " and a.`applydt` <= '$dt'";
  294. }
  295. return array(
  296. 'table' => '`[Q]goodss` a left join `[Q]goods` b on a.`aid`=b.`id`',
  297. 'where' => $where,
  298. 'fields'=> 'b.*,sum(a.`count`) as `stock`',
  299. 'group' => 'a.`aid`'
  300. );
  301. }
  302. public function pdck_aftershow($table, $rows)
  303. {
  304. foreach($rows as $k=>$rs){
  305. $rows[$k]['typeid'] = $this->gettypename($rs['typeid']);
  306. if($rs['stock']<='0')$rows[$k]['ishui']=1;
  307. }
  308. return array(
  309. 'rows' => $rows
  310. );
  311. }
  312. //打印二维码
  313. public function printewmAction()
  314. {
  315. $sid = c('check')->onlynumber($this->get('sid'));
  316. $rows= m('goods')->getall('id in('.$sid.')');
  317. foreach($rows as $k=>$rs){
  318. $rows[$k]['url'] = $this->jm->base64encode('task.php?a=x&num=goods&mid='.$rs['id'].'');
  319. }
  320. $this->assign('rows', $rows);
  321. $this->displayfile = ''.P.'/main/assetm/tpl_assetm_printewm.html';
  322. $this->title = '物品二维码打印';
  323. }
  324. }