Warehousefactory.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Warehousefactory extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_warehousefactory','warehousefactory');
  7. $this->load->_model('Model_warehousefactoryout','warehousefactoryout');
  8. $this->load->_model('Model_excel','excel');
  9. $this->load->_model('Model_typeclass','typeclass');
  10. }
  11. //定义方法的调用规则 获取URI第二段值
  12. public function _remap($arg,$arg_array)
  13. {
  14. if($arg == 'add')//添加
  15. {
  16. $this->_add();
  17. }
  18. else if($arg == 'edit')//修改
  19. {
  20. $this->_edit($arg_array);
  21. }
  22. else if($arg == 'editnum')//修改
  23. {
  24. $this->_editnum($arg_array);
  25. }
  26. else if($arg == 'ck')//修改
  27. {
  28. $this->_ck($arg_array);
  29. }
  30. else if($arg == 'del')//修改
  31. {
  32. $this->_del();
  33. }
  34. else if($arg == 'enter')
  35. {
  36. $this->_enter($arg_array);
  37. }
  38. else if($arg == 'out')
  39. {
  40. $this->_out($arg_array);
  41. }
  42. else if($arg == 'outxq')
  43. {
  44. $this->_outxq($arg_array);
  45. }
  46. else if($arg == 'presetedit')//修改
  47. {
  48. $this->_presetedit($arg_array);
  49. }
  50. else if($arg == 'dcexcel')
  51. {
  52. $this->_dcexcel();
  53. }
  54. else if($arg == 'drmb')
  55. {
  56. $this->_drmb();
  57. }
  58. else if($arg == 'pd')
  59. {
  60. $this->_pd();
  61. }
  62. else if($arg == 'outexcel')
  63. {
  64. $this->_outexcel($arg_array);
  65. }
  66. else if($arg == 'ckmb')
  67. {
  68. $this->_ckmb();
  69. }
  70. else
  71. {
  72. $this->_index();
  73. }
  74. }
  75. //管理
  76. public function _index()
  77. {
  78. $t = array();
  79. $typeclass = $this->typeclass->find_all();
  80. foreach ($typeclass as $v)
  81. {
  82. $t[$v['id']] = $v['title'];
  83. }
  84. $post = $this->input->post(NULL, TRUE);
  85. if(isset($post['page']))
  86. {
  87. $page = $this->input->post('page',true);
  88. $perpage = $this->input->post('perpage',true);
  89. $warehouse = $this->input->post('warehouse',true);
  90. $sku = $this->input->post('sku',true);
  91. $title = $this->input->post('title',true);
  92. $lowe = $this->input->post('lowe',true);
  93. $color = $this->input->post('color',true);
  94. $size = $this->input->post('size',true);
  95. $specs = $this->input->post('specs',true);
  96. $tax = $this->input->post('tax',true);
  97. $contract = $this->input->post('contract',true);
  98. $ktime = $this->input->post('ktime',true);
  99. $jtime = $this->input->post('jtime',true);
  100. $ktime = strtotime($ktime);
  101. $jtime = strtotime($jtime);
  102. $where = "1=1 ";
  103. //数据排序
  104. $order_str = "id desc";
  105. if(empty($page))
  106. {
  107. $start = 0;
  108. $perpage = 1;
  109. }
  110. else
  111. {
  112. $start = ($page - 1)*$perpage;
  113. }
  114. if($sku)
  115. {
  116. $where .= " and sku like '%$sku%'";
  117. }
  118. if($title)
  119. {
  120. $where .= " and title like '%$title%'";
  121. }
  122. if($lowe)
  123. {
  124. $where .= " and lowe like '%$lowe%'";
  125. }
  126. if($color)
  127. {
  128. $where .= " and color like '%$color%'";
  129. }
  130. if($size)
  131. {
  132. $where .= " and size like '%$size%'";
  133. }
  134. if($specs)
  135. {
  136. $where .= " and specs like '%$specs%'";
  137. }
  138. if($tax)
  139. {
  140. $where .= " and tax = '$tax'";
  141. }
  142. if($contract)
  143. {
  144. $where .= " and contract = '$contract'";
  145. }
  146. //取得信息列表
  147. $info_list = $this->warehousefactory->find_pc($where,'warehouse,sku,lowe,color,size,specs','id,warehouse,sku,title,lowe,color,size,specs,synum,price',$order_str,$start,$perpage);
  148. //格式化数据
  149. foreach ($info_list as $key=>$value)
  150. {
  151. if($value['warehouse'] == '1')
  152. {
  153. $info_list[$key]['warehouse'] = '原材料仓';
  154. }
  155. else if($value['warehouse'] == '2')
  156. {
  157. $info_list[$key]['warehouse'] = '半成品仓';
  158. }
  159. else if($value['warehouse'] == '3')
  160. {
  161. $info_list[$key]['warehouse'] = '成品仓';
  162. }
  163. else if($value['warehouse'] == '4')
  164. {
  165. $info_list[$key]['warehouse'] = '辅料仓';
  166. }
  167. else if($value['warehouse'] == '5')
  168. {
  169. $info_list[$key]['warehouse'] = '普通仓';
  170. }
  171. $info_list[$key]['lowe'] = $t[$value['lowe']];
  172. $info_list[$key]['color'] = $t[$value['color']];
  173. $info_list[$key]['size'] = $t[$value['size']];
  174. $m = 0;
  175. $r = $this->warehousefactory->find_all($where." and sku = '".$value['sku']."' and warehouse = '".$value['warehouse']."' and lowe = '".$value['lowe']."' and color = '".$value['color']."' and size = '".$value['size']."' and specs = '".$value['specs']."' and review = '2'");
  176. foreach ($r as $v)
  177. {
  178. $m += $v['synum']*$v['price'];
  179. }
  180. $c = $this->warehousefactoryout->find_all($where." and sku = '".$value['sku']."' and warehouse = '".$value['warehouse']."' and lowe = '".$value['lowe']."' and color = '".$value['color']."' and size = '".$value['size']."' and specs = '".$value['specs']."' and review = '2'");
  181. $info_list[$key]['synum'] = array_sum(array_column($r,'num'));
  182. $info_list[$key]['price'] = array_sum(array_column($c,'num'));
  183. $info_list[$key]['jy'] = sprintf("%01.2f",$info_list[$key]['synum'] - $info_list[$key]['price']);
  184. $synum = array_sum(array_column($r,'synum'));
  185. if($synum > 0)
  186. {
  187. $info_list[$key]['jj'] = sprintf("%01.2f",$m/$synum);
  188. }
  189. else
  190. {
  191. $info_list[$key]['jj'] = 0;
  192. }
  193. $info_list[$key]['syzj'] = sprintf("%01.2f",$m);
  194. }
  195. $total = $this->warehousefactory->find_count($where,'warehouse,sku,lowe,color,size,specs','id,warehouse,sku,title,lowe,color,size,specs');
  196. $pagenum = ceil($total/$perpage);
  197. $over = $total-($start+$perpage);
  198. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  199. echo json_encode($rows);exit;
  200. }
  201. $this->_Template('warehousefactory',$this->data);
  202. }
  203. public function _enter($arg_array)
  204. {
  205. $t = array();
  206. $typeclass = $this->typeclass->find_all();
  207. foreach ($typeclass as $v)
  208. {
  209. $t[$v['id']] = $v['title'];
  210. }
  211. $post = $this->input->post(NULL, TRUE);
  212. if(isset($post['page']))
  213. {
  214. $page = $this->input->post('page',true);
  215. $perpage = $this->input->post('perpage',true);
  216. $warehouse = $this->input->post('warehouse',true);
  217. $entertype = $this->input->post('entertype',true);
  218. $sku = $this->input->post('sku',true);
  219. $title = $this->input->post('title',true);
  220. $agent = $this->input->post('agent',true);
  221. $supply = $this->input->post('supply',true);
  222. $enterorder = $this->input->post('enterorder',true);
  223. $tax = $this->input->post('tax',true);
  224. $contract = $this->input->post('contract',true);
  225. $ktime = $this->input->post('ktime',true);
  226. $jtime = $this->input->post('jtime',true);
  227. $ktime = strtotime($ktime);
  228. $jtime = strtotime($jtime);
  229. $where = "1=1";
  230. //数据排序
  231. $order_str = "id desc";
  232. if(empty($page))
  233. {
  234. $start = 0;
  235. $perpage = 1;
  236. }
  237. else
  238. {
  239. $start = ($page - 1)*$perpage;
  240. }
  241. if($sku)
  242. {
  243. $where .= " and sku like '%$sku%'";
  244. }
  245. if($title)
  246. {
  247. $where .= " and title like '%$title%'";
  248. }
  249. if($agent)
  250. {
  251. $where .= " and agent like '%$agent%'";
  252. }
  253. if($supply)
  254. {
  255. $where .= " and supply like '%$supply%'";
  256. }
  257. if($enterorder)
  258. {
  259. $where .= " and enterorder like '%$enterorder%'";
  260. }
  261. if($warehouse)
  262. {
  263. $where .= " and warehouse = '$warehouse'";
  264. }
  265. if($entertype)
  266. {
  267. $where .= " and entertype = '$entertype'";
  268. }
  269. if($tax)
  270. {
  271. $where .= " and tax = '$tax'";
  272. }
  273. if($contract)
  274. {
  275. $where .= " and contract = '$contract'";
  276. }
  277. if($ktime && $jtime)
  278. {
  279. $where .= " and rtime > '$ktime' and rtime < '$jtime'";
  280. }
  281. //取得信息列表
  282. $info_list = $this->warehousefactory->find_all($where,'id,warehouse,entertype,enterorder,contract,sku,title,lowe,color,size,specs,num,money,rtime',$order_str,$start,$perpage);
  283. $sl = 0;$jg = 0;
  284. //格式化数据
  285. foreach ($info_list as $key=>$value)
  286. {
  287. if($value['warehouse'] == '1')
  288. {
  289. $info_list[$key]['warehouse'] = '原材料仓';
  290. }
  291. else if($value['warehouse'] == '2')
  292. {
  293. $info_list[$key]['warehouse'] = '半成品仓';
  294. }
  295. else if($value['warehouse'] == '3')
  296. {
  297. $info_list[$key]['warehouse'] = '成品仓';
  298. }
  299. else if($value['warehouse'] == '4')
  300. {
  301. $info_list[$key]['warehouse'] = '辅料仓';
  302. }
  303. else if($value['warehouse'] == '5')
  304. {
  305. $info_list[$key]['warehouse'] = '普通仓';
  306. }
  307. if($value['entertype'] == '1')
  308. {
  309. $info_list[$key]['entertype'] = '采购入库单';
  310. }
  311. else if($value['entertype'] == '2')
  312. {
  313. $info_list[$key]['entertype'] = '生产入库单';
  314. }
  315. else if($value['entertype'] == '3')
  316. {
  317. $info_list[$key]['entertype'] = '其他入库单';
  318. }
  319. $info_list[$key]['lowe'] = $t[$value['lowe']];
  320. $info_list[$key]['color'] = $t[$value['color']];
  321. $info_list[$key]['size'] = $t[$value['size']];
  322. $info_list[$key]['rtime'] = date('Y-m-d H:i',$value['rtime']);
  323. $sl += $value['num'];
  324. $jg += $value['money'];
  325. }
  326. $total = $this->warehousefactory->find_count($where);
  327. $pagenum = ceil($total/$perpage);
  328. $over = $total-($start+$perpage);
  329. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'wf'=>(array(sprintf("%01.2f",$sl),sprintf("%01.2f",$jg))));
  330. echo json_encode($rows);exit;
  331. }
  332. $this->_Template('warehousefactory_enter',$this->data);
  333. }
  334. public function _out($arg_array)
  335. {
  336. $t = array();
  337. $typeclass = $this->typeclass->find_all();
  338. foreach ($typeclass as $v)
  339. {
  340. $t[$v['id']] = $v['title'];
  341. }
  342. $post = $this->input->post(NULL, TRUE);
  343. if(isset($post['page']))
  344. {
  345. $page = $this->input->post('page',true);
  346. $perpage = $this->input->post('perpage',true);
  347. $warehouse = $this->input->post('warehouse',true);
  348. $outtype = $this->input->post('outtype',true);
  349. $sku = $this->input->post('sku',true);
  350. $title = $this->input->post('title',true);
  351. $cagent = $this->input->post('cagent',true);
  352. $department = $this->input->post('department',true);
  353. $customer = $this->input->post('customer',true);
  354. $outorder = $this->input->post('outorder',true);
  355. $tax = $this->input->post('tax',true);
  356. $contract = $this->input->post('contract',true);
  357. $ktime = $this->input->post('ktime',true);
  358. $jtime = $this->input->post('jtime',true);
  359. $ktime = strtotime($ktime);
  360. $jtime = strtotime($jtime);
  361. $where = "1=1";
  362. //数据排序
  363. $order_str = "id desc";
  364. if(empty($page))
  365. {
  366. $start = 0;
  367. $perpage = 1;
  368. }
  369. else
  370. {
  371. $start = ($page - 1)*$perpage;
  372. }
  373. if($sku)
  374. {
  375. $where .= " and sku like '%$sku%'";
  376. }
  377. if($title)
  378. {
  379. $where .= " and title like '%$title%'";
  380. }
  381. if($cagent)
  382. {
  383. $where .= " and cagent like '%$cagent%'";
  384. }
  385. if($department)
  386. {
  387. $where .= " and department like '%$department%'";
  388. }
  389. if($customer)
  390. {
  391. $where .= " and customer like '%$customer%'";
  392. }
  393. if($outorder)
  394. {
  395. $where .= " and outorder like '%$outorder%'";
  396. }
  397. if($warehouse)
  398. {
  399. $where .= " and warehouse = '$warehouse'";
  400. }
  401. if($outtype)
  402. {
  403. $where .= " and outtype = '$outtype'";
  404. }
  405. if($tax)
  406. {
  407. $where .= " and tax = '$tax'";
  408. }
  409. if($contract)
  410. {
  411. $where .= " and contract = '$contract'";
  412. }
  413. if($ktime && $jtime)
  414. {
  415. $where .= " and ctime > '$ktime' and ctime < '$jtime'";
  416. }
  417. //取得信息列表
  418. $info_list = $this->warehousefactoryout->find_all($where,'id,warehouse,outtype,outorder,sku,title,lowe,color,size,specs,num,jj,ctime',$order_str,$start,$perpage);
  419. //格式化数据
  420. foreach ($info_list as $key=>$value)
  421. {
  422. if($value['warehouse'] == '1')
  423. {
  424. $info_list[$key]['warehouse'] = '原材料仓';
  425. }
  426. else if($value['warehouse'] == '2')
  427. {
  428. $info_list[$key]['warehouse'] = '半成品仓';
  429. }
  430. else if($value['warehouse'] == '3')
  431. {
  432. $info_list[$key]['warehouse'] = '成品仓';
  433. }
  434. else if($value['warehouse'] == '4')
  435. {
  436. $info_list[$key]['warehouse'] = '辅料仓';
  437. }
  438. else if($value['warehouse'] == '5')
  439. {
  440. $info_list[$key]['warehouse'] = '普通仓';
  441. }
  442. if($value['outtype'] == '1')
  443. {
  444. $info_list[$key]['outtype'] = '材料出库单';
  445. }
  446. else if($value['outtype'] == '2')
  447. {
  448. $info_list[$key]['outtype'] = '销售出库单';
  449. }
  450. else if($value['outtype'] == '3')
  451. {
  452. $info_list[$key]['outtype'] = '其他出库单';
  453. }
  454. $info_list[$key]['lowe'] = $t[$value['lowe']];
  455. $info_list[$key]['color'] = $t[$value['color']];
  456. $info_list[$key]['size'] = $t[$value['size']];
  457. $info_list[$key]['ctime'] = date('Y-m-d H:i',$value['ctime']);
  458. }
  459. $total = $this->warehousefactoryout->find_count($where);
  460. $pagenum = ceil($total/$perpage);
  461. $over = $total-($start+$perpage);
  462. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  463. echo json_encode($rows);exit;
  464. }
  465. $this->_Template('warehousefactory_out',$this->data);
  466. }
  467. public function _outxq($arg_array)
  468. {
  469. $arg_array = $arg_array[0];$m=0;
  470. $warehousefactory = $this->warehousefactoryout->read($arg_array);
  471. $r = $this->warehousefactory->find_all("sku = '".$warehousefactory['sku']."' and warehouse = '".$warehousefactory['warehouse']."' and lowe = '".$warehousefactory['lowe']."' and color = '".$warehousefactory['color']."' and size = '".$warehousefactory['size']."' and specs = '".$warehousefactory['specs']."' and review = '2'");
  472. foreach ($r as $v)
  473. {
  474. if($v['synum'] > 0)
  475. {
  476. $m += $v['synum']*$v['price'];
  477. }
  478. }
  479. $c = $this->warehousefactoryout->find_all("sku = '".$warehousefactory['sku']."' and warehouse = '".$warehousefactory['warehouse']."' and lowe = '".$warehousefactory['lowe']."' and color = '".$warehousefactory['color']."' and size = '".$warehousefactory['size']."' and specs = '".$warehousefactory['specs']."' and review = '2'");
  480. $warehousefactory['r'] = array_sum(array_column($r,'num'));
  481. $warehousefactory['c'] = array_sum(array_column($c,'num'));
  482. $warehousefactory['j'] = array_sum(array_column($r,'synum'));
  483. $this->data['warehousefactory'] = $warehousefactory;
  484. $this->_Template('warehousefactory_outxq',$this->data);
  485. }
  486. //添加
  487. public function _add()
  488. {
  489. $post = $this->input->post(NULL, TRUE);
  490. if(isset($post['sku']))
  491. {
  492. $time = time();
  493. $num = $this->input->post('num',true);
  494. if($num < 1)
  495. {
  496. echo json_encode(array('msg'=>'添加数量不正确!','success'=>false));exit;
  497. }
  498. $post['time'] = $time;
  499. $post['rtime'] = $time;
  500. $post['grtime'] = date('Y-m-d',$time);
  501. $post['review'] = 2;//需要审核改为1
  502. $post['synum'] = $post['num'];
  503. if (!$this->warehousefactory->insert($post))
  504. {
  505. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  506. }
  507. else
  508. {
  509. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  510. }
  511. }
  512. $this->data['order'] = time().rand(10,99);
  513. $this->_Template('warehousefactory_add',$this->data);
  514. }
  515. public function _edit($arg_array)
  516. {
  517. $post = $this->input->post(NULL, TRUE);
  518. if(isset($post['id']))
  519. {
  520. $time = time();
  521. $id = $this->input->post('id',true);
  522. $d = $this->warehousefactory->read($id);
  523. if($post['num'] < 1 || $d['synum']-($d['num']-$post['num']) < 0)
  524. {
  525. echo json_encode(array('msg'=>'可用数量小于1或剩余数量不足扣减','success'=>false));exit;
  526. }
  527. if($d['synum'] != $d['num'])
  528. {
  529. echo json_encode(array('msg'=>'已有出库记录,无法修改!','success'=>false));exit;
  530. }
  531. if($post['num'] > $d['num'])
  532. {
  533. $post['synum'] = $post['num']-$d['num']+$d['synum'];
  534. }
  535. else
  536. {
  537. $post['synum'] = $d['synum']-($d['num']-$post['num']);
  538. }
  539. if (!$this->warehousefactory->save($post,$id))
  540. {
  541. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  542. }
  543. else
  544. {
  545. echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
  546. }
  547. }
  548. $arg_array = $arg_array[0];
  549. $warehousefactory = $this->warehousefactory->read($arg_array);
  550. $this->data['warehousefactory'] = $warehousefactory;
  551. $this->_Template('warehousefactory_edit',$this->data);
  552. }
  553. public function _ck($arg_array)
  554. {
  555. $post = $this->input->post(NULL, TRUE);
  556. if(isset($post['id']))
  557. {
  558. $id = $this->input->post('id',true);
  559. $wyl = $this->warehousefactory->read($id);
  560. $warehousefactory = $this->warehousefactory->find_all("sku = '".$wyl['sku']."' and warehouse = '".$wyl['warehouse']."' and lowe = '".$wyl['lowe']."' and color = '".$wyl['color']."' and size = '".$wyl['size']."' and specs = '".$wyl['specs']."' and review = '2' and state = '0'");
  561. $time = time();
  562. $num = $this->input->post('num',true);
  563. $k = 0;$sl = 0;$money = 0;$x = 0;
  564. foreach ($warehousefactory as $v)
  565. {
  566. $k++;
  567. if($v['synum'] != 0)
  568. {
  569. $sl += $v['synum'];
  570. $money += $v['synum']*$v['price'];
  571. }
  572. if($x == '0' && $sl >= $num)
  573. {
  574. $x = $k;
  575. }
  576. }
  577. if($sl < abs($num))
  578. {
  579. echo json_encode(array('msg'=>'扣减数量大于库存剩余数量!','success'=>false));exit;
  580. }
  581. $post = $warehousefactory[0];
  582. $post['jj'] = sprintf("%01.2f",$money/$sl);
  583. $post['num'] = $this->input->post('num',true);
  584. $post['outtype'] = $this->input->post('outtype',true);
  585. $post['department'] = $this->input->post('department',true);
  586. $post['customer'] = $this->input->post('customer',true);
  587. $post['cagent'] = $this->input->post('cagent',true);
  588. $post['ctext'] = $this->input->post('ctext',true);
  589. $post['outorder'] = time().rand(10,99);
  590. $post['ctime'] = $time;
  591. $post['time'] = $time;
  592. $post['gctime'] = date('Ymd',$time);
  593. unset($post['id']);
  594. $this->db->trans_begin();
  595. $kcjl = '';
  596. for($i=0;$i<$x;$i++)
  597. {
  598. if($warehousefactory[$i]['synum'] <= $post['num'])
  599. {
  600. $this->warehousefactory->save(array('synum'=>0),$warehousefactory[$i]['id']);
  601. $post['num'] = $post['num'] - $warehousefactory[$i]['synum'];
  602. $kcjl .= $warehousefactory[$i]['id'].'-'.$warehousefactory[$i]['synum'].'|';
  603. }
  604. else
  605. {
  606. $this->warehousefactory->save(array('synum'=>$warehousefactory[$i]['synum']-$post['num']),$warehousefactory[$i]['id']);
  607. $kcjl .= $warehousefactory[$i]['id'].'-'.$post['num'].'|';
  608. }
  609. }
  610. $post['kcjl'] = $kcjl;
  611. $this->warehousefactoryout->insert($post);
  612. if ($this->db->trans_status() === TRUE)
  613. {
  614. $this->db->trans_commit();
  615. echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
  616. }
  617. else
  618. {
  619. $this->db->trans_rollback();
  620. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  621. }
  622. }
  623. $m = 0;
  624. $arg_array = $arg_array[0];
  625. $warehousefactory = $this->warehousefactory->read($arg_array);
  626. $r = $this->warehousefactory->find_all("sku = '".$warehousefactory['sku']."' and warehouse = '".$warehousefactory['warehouse']."' and lowe = '".$warehousefactory['lowe']."' and color = '".$warehousefactory['color']."' and size = '".$warehousefactory['size']."' and specs = '".$warehousefactory['specs']."' and review = '2'");
  627. foreach ($r as $v)
  628. {
  629. if($v['synum'] > 0)
  630. {
  631. $m += $v['synum']*$v['price'];
  632. }
  633. }
  634. $c = $this->warehousefactoryout->find_all("sku = '".$warehousefactory['sku']."' and warehouse = '".$warehousefactory['warehouse']."' and lowe = '".$warehousefactory['lowe']."' and color = '".$warehousefactory['color']."' and size = '".$warehousefactory['size']."' and specs = '".$warehousefactory['specs']."' and review = '2'");
  635. $warehousefactory['r'] = array_sum(array_column($r,'num'));
  636. $warehousefactory['c'] = array_sum(array_column($c,'num'));
  637. $warehousefactory['j'] = array_sum(array_column($r,'synum'));
  638. $warehousefactory['jj'] = sprintf("%01.2f",$m/$warehousefactory['j']);
  639. $this->data['warehousefactory'] = $warehousefactory;
  640. $this->_Template('warehousefactory_ck',$this->data);
  641. }
  642. //删除
  643. public function _del()
  644. {
  645. $post = $this->input->post(NULL, TRUE);
  646. if(isset($post['s']))
  647. {
  648. $id_arr = $this->input->post('s');
  649. $id_arr = explode(',',$id_arr);
  650. if(!$id_arr)
  651. {
  652. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  653. }
  654. //循环删除记录
  655. foreach ($id_arr as $v)
  656. {
  657. $d = $this->warehousefactory->read($v);
  658. if($d['num'] == $d['synum'])//只能删除未使用的库存
  659. {
  660. $this->warehousefactory->remove($v);
  661. }
  662. }
  663. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  664. }
  665. }
  666. public function _outdel()
  667. {
  668. $post = $this->input->post(NULL, TRUE);
  669. if(isset($post['s']))
  670. {
  671. $id_arr = $this->input->post('s');
  672. $id_arr = explode(',',$id_arr);
  673. if(!$id_arr)
  674. {
  675. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  676. }
  677. $this->db->trans_begin();
  678. foreach ($id_arr as $v)
  679. {
  680. $d = $this->warehousefactoryout->read($v);
  681. $data = explode('|',rtrim($d['kcjl'],'|'));
  682. if(count($data) > 0)
  683. {
  684. foreach ($data as $vv)
  685. {
  686. $u = explode('-',$vv);
  687. $y = $this->warehousefactory->read($u[0]);
  688. if($y)
  689. {
  690. $this->warehousefactory->save(array('synum'=>$y['synum']+$u[1]),$u[0]);
  691. }
  692. }
  693. }
  694. $this->warehousefactory->remove($v);
  695. }
  696. if ($this->db->trans_status() === TRUE)
  697. {
  698. $this->db->trans_commit();
  699. echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
  700. }
  701. else
  702. {
  703. $this->db->trans_rollback();
  704. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  705. }
  706. }
  707. }
  708. public function _presetedit($arg_array)
  709. {
  710. $t = array();$bs = array();
  711. $typeclass = $this->typeclass->find_all();
  712. foreach ($typeclass as $v)
  713. {
  714. $t[$v['title']] = $v['id'];
  715. $bs[$v['bqsku']] = $v['id'];
  716. }
  717. $dir = '/data/excel/'.date('Ymd',time()).'/';
  718. $config['upload_path'] = '.'.$dir ;
  719. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  720. $config['allowed_types'] = 'xls|xlsx|csv';
  721. $config['max_size'] = 10240;
  722. $this->load->library('upload', $config);
  723. $this->upload->initialize($config);
  724. if ($this->upload->do_upload('userfile'))
  725. {
  726. $full_path = $dir.$this->upload->data('file_name');
  727. $fileName = '.' . $full_path;
  728. if (!file_exists($fileName))
  729. {
  730. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  731. }
  732. else
  733. {
  734. libxml_use_internal_errors(true);
  735. require_once "./data/excel/PHPExcel/IOFactory.php";
  736. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  737. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  738. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  739. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  740. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  741. ++$column;//如果列数大于26行
  742. $list = array();
  743. for ($i = 2; $i <= $row; $i++) // 行数循环
  744. {
  745. $data = array();
  746. for ($c = 'A'; $c != $column; $c++) // 列数循环
  747. {
  748. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  749. }
  750. $list[] = $data;
  751. }
  752. }
  753. $i = 0;$j = 0;$ed = array();$x=0;$cs = '';
  754. foreach ($list as $key=>$value)
  755. {
  756. $h = $key+2;
  757. $x++;
  758. $time = time();
  759. if($value['1'] == "" || $value['1'] == null)
  760. {
  761. continue;
  762. }
  763. $value8='';
  764. if(preg_match('/\d/',$value['8']))
  765. {
  766. if(stripos($value['8'],'以上') !== false)
  767. {
  768. for($i=0;$i<strlen($value['8']);$i++)
  769. {
  770. if(is_numeric($value['8'][$i]))
  771. {
  772. $value8.=$value['8'][$i];
  773. }
  774. }
  775. $value8 = $value8.'inch以上';
  776. }
  777. else
  778. {
  779. for($i=0;$i<strlen($value['8']);$i++)
  780. {
  781. if(is_numeric($value['8'][$i]))
  782. {
  783. $value8.=$value['8'][$i];
  784. }
  785. }
  786. $value8 = $value8.'inch';
  787. }
  788. }
  789. else
  790. {
  791. $value8 = preg_replace('/( | | |\s)/',' ',$value['8']);
  792. }
  793. $warehouse = $value['0'];
  794. $entertype = $value['1'];
  795. $sku = $value['2'];
  796. $title = $value['3'];
  797. $agent = $value['4'];
  798. $supply = $value['5'];
  799. if(!isset($t[$value['6']]))
  800. {
  801. $ed[] = array('第'.$h.'行,曲度填写不规范或没有此曲度');
  802. $j++;
  803. continue;
  804. }
  805. else
  806. {
  807. $lowe = $t[$value['6']];
  808. }
  809. if(!isset($t[$value['7']]))
  810. {
  811. $ed[] = array('第'.$h.'行,颜色填写不规范或没有此颜色');
  812. $j++;
  813. continue;
  814. }
  815. else
  816. {
  817. $color = $t[$value['7']];
  818. }
  819. if(!isset($bs[$value['8']]))
  820. {
  821. $ed[] = array('第'.$h.'行,尺寸填写不规范或没有此尺寸');
  822. $j++;
  823. continue;
  824. }
  825. else
  826. {
  827. $size = $bs[$value['8']];
  828. }
  829. $specs = ($value['9'])?$value['9']:'';
  830. $company = $value['10'];
  831. $num = $value['11'];
  832. $yprice = $value['12'];
  833. $ymoney = $value['13'];
  834. $price = $yprice*$value['18'];
  835. $money = $ymoney*$value['18'];
  836. $tax = $value['14'];
  837. $contract = ($value['15'])?$value['15']:'';
  838. $nbgl = $value['16'];
  839. $bgd = $value['17'];
  840. $hl = $value['18'];
  841. if(!isset($t[$value['19']]))
  842. {
  843. $ed[] = array('第'.$h.'行,币种填写不规范或没有此币种');
  844. $j++;
  845. continue;
  846. }
  847. else
  848. {
  849. $bz = $t[$value['19']];
  850. }
  851. $text = ($value['20'])?$value['20']:'';
  852. $enterorder = time()*100+$x;
  853. $d = $this->warehousefactory->get_sku($sku);
  854. if($nbgl == '' || $bgd == '' || $hl == '' || $bz == '')
  855. {
  856. $ed[] = array('第'.$h.'行添加失败,请查看是否缺:内部关联号、少报关单号、汇率、币种');
  857. $j++;
  858. continue;
  859. }
  860. if($num > 0)
  861. {
  862. $post['state'] = 0;
  863. $post['warehouse'] = $warehouse;
  864. $post['entertype'] = $entertype;
  865. $post['sku'] = $sku;
  866. $post['title'] = $title;
  867. $post['agent'] = $agent;
  868. $post['supply'] = $supply;
  869. $post['lowe']= $lowe;
  870. $post['color'] = $color;
  871. $post['size']= $size;
  872. $post['specs'] = $specs;
  873. $post['company'] = $company;
  874. $post['num']= $num;
  875. $post['synum']= $num;
  876. $post['yprice'] = $yprice;
  877. $post['ymoney'] = $ymoney;
  878. $post['price'] = $price;
  879. $post['money'] = $money;
  880. $post['tax'] = $tax;
  881. $post['contract'] = $contract;
  882. $post['nbgl'] = $nbgl;
  883. $post['bgd'] = $bgd;
  884. $post['hl'] = $hl;
  885. $post['bz'] = $bz;
  886. $post['text'] = $text;
  887. $post['enterorder'] = $enterorder;
  888. $post['rtime'] =$time+$x;
  889. $post['grtime'] = date('Ymd',$time+$x);
  890. $post['time'] = $time+$x;
  891. $post['review'] = 2;//需要审核改为1
  892. $this->warehousefactory->insert($post);
  893. }
  894. //防止入库时间一样,需要延迟1秒
  895. }
  896. if($j > 0)
  897. {
  898. $tt = date('Ymd',time());
  899. $title = '导入错误信息-'.$tt;
  900. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  901. $tail = "\n";
  902. $filename = $title.".xls";
  903. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  904. $dir = '/data/excel/'.$time.'/';
  905. $file_name = 'error_'.$time.rand(1000,9999);
  906. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  907. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  908. fwrite($myfile,$ecl);
  909. fclose($myfile);
  910. $error = $dir.$file_name.'.xls';
  911. echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
  912. }
  913. else
  914. {
  915. echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
  916. }
  917. }
  918. }
  919. public function _outexcel($arg_array)
  920. {
  921. $dir = '/data/excel/'.date('Ymd',time()).'/';
  922. $config['upload_path'] = '.'.$dir ;
  923. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  924. $config['allowed_types'] = 'xls|xlsx|csv';
  925. $config['max_size'] = 10240;
  926. $this->load->library('upload', $config);
  927. $this->upload->initialize($config);
  928. if ($this->upload->do_upload('userfile'))
  929. {
  930. $full_path = $dir.$this->upload->data('file_name');
  931. $fileName = '.' . $full_path;
  932. if (!file_exists($fileName))
  933. {
  934. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  935. }
  936. else
  937. {
  938. libxml_use_internal_errors(true);
  939. require_once "./data/excel/PHPExcel/IOFactory.php";
  940. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  941. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  942. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  943. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  944. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  945. ++$column;//如果列数大于26行
  946. $list = array();
  947. for ($i = 2; $i <= $row; $i++) // 行数循环
  948. {
  949. $data = array();
  950. for ($c = 'A'; $c != $column; $c++) // 列数循环
  951. {
  952. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  953. }
  954. $list[] = $data;
  955. }
  956. }
  957. $i = 0;$j = 0;$ed = array();$x=0;
  958. foreach ($list as $key=>$value)
  959. {
  960. $x++;
  961. $time = time();
  962. if($value['0'] == "")
  963. {
  964. continue;
  965. }
  966. $outdata['warehouse'] = $value['0'];
  967. $outdata['sku'] = $value['1'];
  968. $outdata['outtype'] = $value['2'];
  969. $outdata['department'] = $value['3'];
  970. $outdata['customer'] = $value['4'];
  971. $outdata['cagent'] = $value['5'];
  972. $outdata['num'] = $value['6'];
  973. $outdata['ctext'] = $value['7'];
  974. $outdata['outorder'] = time().rand(10,999);
  975. $outdata['ctime'] = $time;
  976. $outdata['time'] = $time;
  977. $outdata['gctime'] = date('Ymd',$time);
  978. $outdata['state'] = 1;
  979. if($outdata['warehouse'] == '' || $outdata['sku'] == '' || $outdata['outtype'] == '' || $outdata['department'] == '' || $outdata['customer'] == '' || $outdata['cagent'] == '' || $outdata['num'] == '' || $outdata['ctext'] == '')
  980. {
  981. $ed[] = array($outdata['sku'].'信息不完整');
  982. $j++;
  983. continue;
  984. }
  985. $data = $this->warehousefactory->find_all('sku = "'.$outdata['sku'].'" and warehouse = "'.$outdata['warehouse'].'" and state = "0" and synum != "0" and review = "2"','*','id asc');
  986. if(!$data)//如果没有这个SKU
  987. {
  988. $ed[] = array($outdata['sku'].'-库存中不存在此编码');
  989. $j++;
  990. continue;
  991. }
  992. $sl = 0;$money = 0;$k=0;$x=0;
  993. foreach ($data as $v)
  994. {
  995. $k++;
  996. if($v['synum'] != 0)
  997. {
  998. $sl += $v['synum'];
  999. $money += $v['synum']*$v['price'];
  1000. }
  1001. if($x == '0' && $sl >= $outdata['num'])
  1002. {
  1003. $x = $k;
  1004. }
  1005. }
  1006. if($sl < abs($outdata['num']))
  1007. {
  1008. $ed[] = array($outdata['sku'].'-扣减数量大于库存剩余数量!');
  1009. $j++;
  1010. continue;
  1011. }
  1012. $outdata = $data[0];
  1013. $outdata['jj'] = sprintf("%01.2f",$money/$sl);
  1014. $outdata['outtype'] = $value['2'];
  1015. $outdata['department'] = $value['3'];
  1016. $outdata['customer'] = $value['4'];
  1017. $outdata['cagent'] = $value['5'];
  1018. $outdata['num'] = $value['6'];
  1019. $outdata['ctext'] = $value['7'];
  1020. $outdata['outorder'] = time().rand(10,999);
  1021. $outdata['ctime'] = $time;
  1022. $outdata['time'] = $time;
  1023. $outdata['gctime'] = date('Ymd',$time);
  1024. $outdata['state'] = 1;
  1025. unset($outdata['id']);
  1026. $this->db->trans_begin();
  1027. $kcjl = '';
  1028. $this->warehousefactoryout->insert($outdata);
  1029. for($i=0;$i<$x;$i++)
  1030. {
  1031. if($data[$i]['synum'] <= $outdata['num'])
  1032. {
  1033. $this->warehousefactory->save(array('synum'=>0),$data[$i]['id']);
  1034. $outdata['num'] = $outdata['num'] - $data[$i]['synum'];
  1035. $kcjl .= $data[$i]['id'].'-'.$data[$i]['synum'].'|';
  1036. }
  1037. else
  1038. {
  1039. $this->warehousefactory->save(array('synum'=>$data[$i]['synum']-$outdata['num']),$data[$i]['id']);
  1040. $kcjl .= $data[$i]['id'].'-'.$outdata['num'].'|';
  1041. }
  1042. }
  1043. $outdata['kcjl'] = $kcjl;
  1044. $this->warehousefactoryout->insert($outdata);
  1045. if ($this->db->trans_status() === TRUE)
  1046. {
  1047. $this->db->trans_commit();
  1048. }
  1049. else
  1050. {
  1051. $this->db->trans_rollback();
  1052. $ed[] = array($outdata['sku'].'-操作失败,需要重试!');
  1053. $j++;
  1054. }
  1055. sleep(1);//防止入库时间一样,需要延迟1秒
  1056. }
  1057. if($j > 0)
  1058. {
  1059. $tt = date('Ymd',time());
  1060. $title = '导入错误信息-'.$tt;
  1061. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  1062. $tail = "\n";
  1063. $filename = $title.".xls";
  1064. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  1065. $dir = '/data/excel/'.$time.'/';
  1066. $file_name = 'error_'.$time.rand(1000,9999);
  1067. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  1068. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  1069. fwrite($myfile,$ecl);
  1070. fclose($myfile);
  1071. $error = $dir.$file_name.'.xls';
  1072. echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
  1073. }
  1074. else
  1075. {
  1076. echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
  1077. }
  1078. }
  1079. }
  1080. public function _dcexcel()
  1081. {
  1082. if(isset($_GET['excel']))
  1083. {
  1084. $ktime = $this->input->get('ktime',true);
  1085. $jtime = $this->input->get('jtime',true);
  1086. $tax = $this->input->get('tax',true);
  1087. $contract = $this->input->get('contract',true);
  1088. $ktime = strtotime($ktime);
  1089. $jtime = strtotime($jtime);
  1090. $where = "1=1";
  1091. if($ktime && $jtime)
  1092. {
  1093. $where .= " and time > '$ktime' and time < '$jtime'";
  1094. }
  1095. if($tax)
  1096. {
  1097. $where .= " and tax = '$tax'";
  1098. }
  1099. if($contract)
  1100. {
  1101. $where .= " and contract = '$contract'";
  1102. }
  1103. //数据排序
  1104. $order_str = "time desc";
  1105. $info_list = $this->warehousefactory->find_all($where,'sku,title,specs,size,text',$order_str);
  1106. $rows = array();$list = array();
  1107. foreach ($info_list as $key=>$value)
  1108. {
  1109. $rows[strtolower($value['sku'])] = $value;//所有数据sku
  1110. }
  1111. $rowsdq = $rows;
  1112. //格式化数据
  1113. foreach ($rowsdq as $key=>$value)
  1114. {
  1115. $r = $this->warehousefactory->find_count($where.' and sku = "'.$value['sku'].'" and state = "0"');
  1116. $c = $this->warehousefactory->find_count($where.' and sku = "'.$value['sku'].'" and state = "1"');
  1117. $rowsdq[$key]['r'] = $r+$c;
  1118. $rowsdq[$key]['c'] = $c;
  1119. $rowsdq[$key]['j'] = $r;
  1120. }
  1121. $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).'详情';
  1122. $titlename = "<table border=1>
  1123. <tr align='center'>
  1124. <td>编码</td>
  1125. <td>产品名称</td>
  1126. <td>规格</td>
  1127. <td>尺寸</td>
  1128. <td>描述</td>
  1129. <td>入库</td>
  1130. <td>出库</td>
  1131. <td>结余</td>
  1132. </tr>
  1133. </table>";
  1134. $filename = $title.".xls";
  1135. $tail = "";
  1136. $this->excel->get_fz2($rowsdq,$titlename,$filename,$tail);
  1137. }
  1138. }
  1139. public function _drmb()
  1140. {
  1141. $title = '导入模板';
  1142. $titlename = "<table border=1>
  1143. <tr align='center'>
  1144. <td>仓库1原材料仓,2半成品仓,3成品仓,4辅料仓,5普通仓</td>
  1145. <td>入库类别1采购入库单,2生产入库单,3其他入库单</td>
  1146. <td>存货编码</td>
  1147. <td>存货名称</td>
  1148. <td>经办人</td>
  1149. <td>供应单位</td>
  1150. <td>曲度</td>
  1151. <td>颜色</td>
  1152. <td>尺寸</td>
  1153. <td>其它规格</td>
  1154. <td>单位(KG)</td>
  1155. <td>数量</td>
  1156. <td>单价</td>
  1157. <td>金额</td>
  1158. <td>1保税/2非保税:</td>
  1159. <td>合同号</td>
  1160. <td>内部关联号</td>
  1161. <td>报关单号</td>
  1162. <td>汇率(数字,如:6.41)</td>
  1163. <td>币种(USD,CNY,EUR,GBP)</td>
  1164. <td>备注</td>
  1165. </tr>
  1166. <tr align='center'>
  1167. <td>2</td>
  1168. <td>2</td>
  1169. <td>1001</td>
  1170. <td>缅甸发</td>
  1171. <td>小明</td>
  1172. <td>龙盈实业</td>
  1173. <td>Straight</td>
  1174. <td>Natural Black</td>
  1175. <td>20</td>
  1176. <td>8A</td>
  1177. <td>KG</td>
  1178. <td>10</td>
  1179. <td>35</td>
  1180. <td>350</td>
  1181. <td>2</td>
  1182. <td>HT123456</td>
  1183. <td>2022032801</td>
  1184. <td>123456</td>
  1185. <td>6.41</td>
  1186. <td>USD</td>
  1187. <td>质量上乘</td>
  1188. </tr>
  1189. </table>";
  1190. $filename = $title.".xls";
  1191. $tail = "\n";
  1192. $this->excel->get_fz2(array(),$titlename,$filename,$tail);
  1193. }
  1194. public function _ckmb()
  1195. {
  1196. $title = '批量出库模板';
  1197. $titlename = "<table border=1>
  1198. <tr align='center'>
  1199. <td>仓库1原材料仓,2半成品仓,3成品仓,4辅料仓,5普通仓</td>
  1200. <td>存货编码</td>
  1201. <td>出库类别1材料出库单,2销售出库单,3其他出库单</td>
  1202. <td>领用部门</td>
  1203. <td>客户</td>
  1204. <td>经办人</td>
  1205. <td>出库数量</td>
  1206. <td>备注</td>
  1207. </tr>
  1208. </table>";
  1209. $filename = $title.".xls";
  1210. $tail = "\n";
  1211. $this->excel->get_fz2(array(),$titlename,$filename,$tail);
  1212. }
  1213. public function _pd()
  1214. {
  1215. $t = array();
  1216. $typeclass = $this->typeclass->find_all();
  1217. foreach ($typeclass as $v)
  1218. {
  1219. $t[$v['id']] = $v['title'];
  1220. }
  1221. $post = $this->input->get(NULL, TRUE);
  1222. if(isset($post['page']))
  1223. {
  1224. $warehouse = $this->input->get('warehouse',true);
  1225. $sku = $this->input->get('sku',true);
  1226. $title = $this->input->get('title',true);
  1227. $lowe = $this->input->get('lowe',true);
  1228. $color = $this->input->get('color',true);
  1229. $size = $this->input->get('size',true);
  1230. $specs = $this->input->get('specs',true);
  1231. $tax = $this->input->get('tax',true);
  1232. $contract = $this->input->get('contract',true);
  1233. $ktime = $this->input->get('ktime',true);
  1234. $jtime = $this->input->get('jtime',true);
  1235. $ktime = strtotime($ktime);
  1236. $jtime = strtotime($jtime);
  1237. $where = "1=1 ";
  1238. //数据排序
  1239. $order_str = "id desc";
  1240. if(empty($page))
  1241. {
  1242. $start = 0;
  1243. $perpage = 1;
  1244. }
  1245. else
  1246. {
  1247. $start = ($page - 1)*$perpage;
  1248. }
  1249. if($sku)
  1250. {
  1251. $where .= " and sku like '%$sku%'";
  1252. }
  1253. if($title)
  1254. {
  1255. $where .= " and title like '%$title%'";
  1256. }
  1257. if($lowe)
  1258. {
  1259. $where .= " and lowe like '%$lowe%'";
  1260. }
  1261. if($color)
  1262. {
  1263. $where .= " and color like '%$color%'";
  1264. }
  1265. if($size)
  1266. {
  1267. $where .= " and size like '%$size%'";
  1268. }
  1269. if($specs)
  1270. {
  1271. $where .= " and specs like '%$specs%'";
  1272. }
  1273. if($tax)
  1274. {
  1275. $where .= " and tax = '$tax'";
  1276. }
  1277. if($contract)
  1278. {
  1279. $where .= " and contract = '$contract'";
  1280. }
  1281. $zrk = 0;$zck = 0;$zjy = 0;$zjg = 0;
  1282. //取得信息列表
  1283. $info_list = $this->warehousefactory->find_pc($where,'warehouse,sku,lowe,color,size,specs','warehouse,sku,nbgl,bgd,contract,title,lowe,color,size,specs,synum,price,');
  1284. //格式化数据
  1285. foreach ($info_list as $key=>$value)
  1286. {
  1287. if($value['warehouse'] == '1')
  1288. {
  1289. $info_list[$key]['warehouse'] = '原材料仓';
  1290. }
  1291. else if($value['warehouse'] == '2')
  1292. {
  1293. $info_list[$key]['warehouse'] = '半成品仓';
  1294. }
  1295. else if($value['warehouse'] == '3')
  1296. {
  1297. $info_list[$key]['warehouse'] = '成品仓';
  1298. }
  1299. else if($value['warehouse'] == '4')
  1300. {
  1301. $info_list[$key]['warehouse'] = '辅料仓';
  1302. }
  1303. else if($value['warehouse'] == '5')
  1304. {
  1305. $info_list[$key]['warehouse'] = '普通仓';
  1306. }
  1307. $info_list[$key]['lowe'] = $t[$value['lowe']];
  1308. $info_list[$key]['color'] = $t[$value['color']];
  1309. $info_list[$key]['size'] = $t[$value['size']];
  1310. $m = 0;$ym = 0;
  1311. $r = $this->warehousefactory->find_all($where." and sku = '".$value['sku']."' and warehouse = '".$value['warehouse']."' and lowe = '".$value['lowe']."' and color = '".$value['color']."' and size = '".$value['size']."' and specs = '".$value['specs']."' and review = '2'");
  1312. foreach ($r as $v)
  1313. {
  1314. $m += $v['synum']*$v['price'];
  1315. $ym += $v['synum']*$v['yprice'];
  1316. }
  1317. $c = $this->warehousefactoryout->find_all($where." and sku = '".$value['sku']."' and warehouse = '".$value['warehouse']."' and lowe = '".$value['lowe']."' and color = '".$value['color']."' and size = '".$value['size']."' and specs = '".$value['specs']."' and review = '2'");
  1318. $info_list[$key]['synum'] = array_sum(array_column($r,'num'));
  1319. $info_list[$key]['price'] = array_sum(array_column($c,'num'));
  1320. $info_list[$key]['jy'] = sprintf("%01.2f",$info_list[$key]['synum'] - $info_list[$key]['price']);
  1321. $synum = array_sum(array_column($r,'synum'));
  1322. if($synum > 0)
  1323. {
  1324. $info_list[$key]['yjj'] = sprintf("%01.2f",$ym/$synum);
  1325. $info_list[$key]['jj'] = sprintf("%01.2f",$m/$synum);
  1326. }
  1327. else
  1328. {
  1329. $info_list[$key]['yjj'] = 0;
  1330. $info_list[$key]['jj'] = 0;
  1331. }
  1332. $info_list[$key]['ysyzj'] = $ym;
  1333. $info_list[$key]['syzj'] = $m;
  1334. $info_list[$key]['spsl'] = '';
  1335. $info_list[$key]['bz'] = '';
  1336. $zrk += $info_list[$key]['synum'];
  1337. $zck += $info_list[$key]['price'];
  1338. $zjy += $info_list[$key]['jy'];
  1339. $yzjg += $ym;
  1340. $zjg += $m;
  1341. }
  1342. }
  1343. $title = '盘点';
  1344. $titlename = "<table border=1>
  1345. <tr align='center'>
  1346. <td>所属仓库</td>
  1347. <td>编码</td>
  1348. <td>内部关联号</td>
  1349. <td>报关单号</td>
  1350. <td>合同号</td>
  1351. <td>产品名称</td>
  1352. <td>曲度</td>
  1353. <td>颜色</td>
  1354. <td>尺寸</td>
  1355. <td>规格</td>
  1356. <td>入库</td>
  1357. <td>出库</td>
  1358. <td>结余</td>
  1359. <td>均价(原)</td>
  1360. <td>均价(CNY)</td>
  1361. <td>总价(原)</td>
  1362. <td>总价(CNY)</td>
  1363. <td>实盘数量</td>
  1364. <td>备注</td>
  1365. </tr>
  1366. </table>";
  1367. $filename = $title.".xls";
  1368. $tail = "<table border=1><tr align='center'><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td><b>汇总入库:".$zrk."</b></td><td><b>汇总出库:".$zck."</b></td><td><b>汇总结余:".sprintf("%01.2f",$zjy)."</b></td><td></td><td></td><td><b>汇总价(原)".$yzjg."</b></td><td><b>汇总价(CNY)".$zjg."</b></td><td></td><td></td></tr></table>";
  1369. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1370. }
  1371. }