1
0

goodsAction.php 10 KB

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