| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393 | 
							- <?php defined('BASEPATH') OR exit('No direct script access allowed');
 
- class Warehousefactory extends Start_Controller {
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		$this->load->library('session');
 
- 		$this->load->_model('Model_warehousefactory','warehousefactory');
 
- 		$this->load->_model('Model_warehousefactoryout','warehousefactoryout');
 
- 		$this->load->_model('Model_excel','excel');
 
- 		$this->load->_model('Model_typeclass','typeclass');
 
- 	}
 
- 	//定义方法的调用规则 获取URI第二段值
 
-     public function _remap($arg,$arg_array)
 
-     {
 
- 		if($arg == 'add')//添加
 
-         {
 
-              $this->_add();
 
-         }
 
- 		else if($arg == 'edit')//修改
 
-         {
 
-              $this->_edit($arg_array);
 
-         }
 
- 		else if($arg == 'editnum')//修改
 
-         {
 
-              $this->_editnum($arg_array);
 
-         }
 
- 		else if($arg == 'ck')//修改
 
-         {
 
-              $this->_ck($arg_array);
 
-         }
 
- 		else if($arg == 'del')//修改
 
-         {
 
-              $this->_del();
 
-         }
 
- 		else if($arg == 'enter')
 
-         {
 
-              $this->_enter($arg_array);
 
-         }
 
- 		else if($arg == 'out')
 
-         {
 
-              $this->_out($arg_array);
 
-         }
 
- 		else if($arg == 'outxq')
 
-         {
 
-              $this->_outxq($arg_array);
 
-         }
 
- 		else if($arg == 'presetedit')//修改
 
-         {
 
-              $this->_presetedit($arg_array);
 
-         }
 
- 		else if($arg == 'dcexcel')
 
-         {
 
-              $this->_dcexcel();
 
-         }
 
- 		else if($arg == 'drmb')
 
-         {
 
-              $this->_drmb();
 
-         }
 
- 		else if($arg == 'pd')
 
-         {
 
-              $this->_pd();
 
-         }
 
- 		else if($arg == 'outexcel')
 
-         {
 
-              $this->_outexcel($arg_array);
 
-         }
 
- 		else if($arg == 'ckmb')
 
-         {
 
-              $this->_ckmb();
 
-         }
 
- 		else
 
- 		{
 
- 			 $this->_index();
 
- 		}
 
-     }
 
- 	//管理
 
- 	public function _index()
 
- 	{
 
- 		$t = array();
 
- 		$typeclass = $this->typeclass->find_all();
 
- 		foreach ($typeclass as $v)
 
- 		{
 
- 			$t[$v['id']] = $v['title'];
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['page']))  
 
- 		{
 
- 		    $page = $this->input->post('page',true);
 
- 		    $perpage = $this->input->post('perpage',true);
 
- 			$warehouse = $this->input->post('warehouse',true);
 
- 			$sku = $this->input->post('sku',true);
 
- 			$title = $this->input->post('title',true);
 
- 			$lowe = $this->input->post('lowe',true);
 
- 			$color = $this->input->post('color',true);
 
- 			$size = $this->input->post('size',true);
 
- 			$specs = $this->input->post('specs',true);
 
- 			$tax = $this->input->post('tax',true);
 
- 			$contract = $this->input->post('contract',true);
 
- 			$ktime = $this->input->post('ktime',true);
 
- 			$jtime = $this->input->post('jtime',true);
 
- 			$ktime = strtotime($ktime);
 
- 			$jtime = strtotime($jtime);
 
- 			$where = "1=1 ";
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
- 			if($sku)
 
-             {
 
-                 $where  .= " and sku like '%$sku%'";
 
-             }
 
- 			if($title)
 
-             {
 
-                 $where  .= " and title like '%$title%'";
 
-             }
 
- 			if($lowe)
 
-             {
 
-                 $where  .= " and lowe like '%$lowe%'";
 
-             }
 
- 			if($color)
 
-             {
 
-                 $where  .= " and color like '%$color%'";
 
-             }
 
- 			if($size)
 
-             {
 
-                 $where  .= " and size like '%$size%'";
 
-             }
 
- 			if($specs)
 
-             {
 
-                 $where  .= " and specs like '%$specs%'";
 
-             }
 
- 			if($tax)
 
-             {
 
-                 $where  .= " and tax = '$tax'";
 
-             }
 
- 			if($contract)
 
-             {
 
-                 $where  .= " and contract = '$contract'";
 
-             }
 
-             //取得信息列表
 
-             $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);
 
- 			 //格式化数据
 
-             foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				if($value['warehouse'] == '1')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '原材料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '2')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '半成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '3')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '4')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '辅料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '5')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '普通仓';
 
- 				}
 
- 				$info_list[$key]['lowe'] = $t[$value['lowe']];
 
- 				$info_list[$key]['color'] = $t[$value['color']];
 
- 				$info_list[$key]['size'] = $t[$value['size']];
 
- 				$m = 0;
 
- 				$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'");
 
- 				foreach ($r as $v) 
 
- 		        {
 
- 					$m += $v['synum']*$v['price'];
 
- 				}
 
- 				$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'");
 
- 				$info_list[$key]['synum'] = array_sum(array_column($r,'num'));
 
- 				$info_list[$key]['price'] = array_sum(array_column($c,'num'));
 
- 				$info_list[$key]['jy'] = sprintf("%01.2f",$info_list[$key]['synum'] - $info_list[$key]['price']);
 
- 				$synum = array_sum(array_column($r,'synum'));
 
- 				if($synum > 0)
 
- 				{
 
- 				    $info_list[$key]['jj'] = sprintf("%01.2f",$m/$synum);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['jj'] = 0;
 
- 				}
 
- 				$info_list[$key]['syzj'] = sprintf("%01.2f",$m);
 
-             }
 
- 		    $total = $this->warehousefactory->find_count($where,'warehouse,sku,lowe,color,size,specs','id,warehouse,sku,title,lowe,color,size,specs');
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
 
- 		    echo json_encode($rows);exit;
 
- 		}
 
- 		$this->_Template('warehousefactory',$this->data);
 
- 	}
 
- 	
 
- 	public function _enter($arg_array)
 
- 	{
 
- 		$t = array();
 
- 		$typeclass = $this->typeclass->find_all();
 
- 		foreach ($typeclass as $v)
 
- 		{
 
- 			$t[$v['id']] = $v['title'];
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['page']))  
 
- 		{
 
- 		    $page = $this->input->post('page',true);
 
- 		    $perpage = $this->input->post('perpage',true);
 
- 			$warehouse = $this->input->post('warehouse',true);
 
- 			$entertype = $this->input->post('entertype',true);
 
- 			$sku = $this->input->post('sku',true);
 
- 			$title = $this->input->post('title',true);
 
- 			$agent = $this->input->post('agent',true);
 
- 			$supply = $this->input->post('supply',true);
 
- 			$enterorder = $this->input->post('enterorder',true);
 
- 			$tax = $this->input->post('tax',true);
 
- 			$contract = $this->input->post('contract',true);
 
- 			$ktime = $this->input->post('ktime',true);
 
- 			$jtime = $this->input->post('jtime',true);
 
- 			$ktime = strtotime($ktime);
 
- 			$jtime = strtotime($jtime);
 
- 			$where = "1=1";
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
- 			if($sku)
 
-             {
 
-                 $where  .= " and sku like '%$sku%'";
 
-             }
 
- 			if($title)
 
-             {
 
-                 $where  .= " and title like '%$title%'";
 
-             }
 
- 			if($agent)
 
-             {
 
-                 $where  .= " and agent like '%$agent%'";
 
-             }
 
- 			if($supply)
 
-             {
 
-                 $where  .= " and supply like '%$supply%'";
 
-             }
 
- 			if($enterorder)
 
-             {
 
-                 $where  .= " and enterorder like '%$enterorder%'";
 
-             }
 
- 			if($warehouse)
 
-             {
 
-                 $where  .= " and warehouse = '$warehouse'";
 
-             }
 
- 			if($entertype)
 
-             {
 
-                 $where  .= " and entertype = '$entertype'";
 
-             }
 
- 			if($tax)
 
-             {
 
-                 $where  .= " and tax = '$tax'";
 
-             }
 
- 			if($contract)
 
-             {
 
-                 $where  .= " and contract = '$contract'";
 
-             }
 
- 			if($ktime && $jtime)
 
-             {
 
- 				$where  .= " and rtime > '$ktime' and rtime < '$jtime'";
 
-             }
 
-             //取得信息列表
 
-             $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);
 
- 			$sl = 0;$jg = 0;
 
- 			 //格式化数据
 
-             foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				if($value['warehouse'] == '1')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '原材料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '2')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '半成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '3')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '4')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '辅料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '5')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '普通仓';
 
- 				}
 
- 				if($value['entertype'] == '1')
 
- 				{
 
- 					$info_list[$key]['entertype'] = '采购入库单';
 
- 				}
 
- 				else if($value['entertype'] == '2')
 
- 				{
 
- 					$info_list[$key]['entertype'] = '生产入库单';
 
- 				}
 
- 				else if($value['entertype'] == '3')
 
- 				{
 
- 					$info_list[$key]['entertype'] = '其他入库单';
 
- 				}
 
- 				$info_list[$key]['lowe'] = $t[$value['lowe']];
 
- 				$info_list[$key]['color'] = $t[$value['color']];
 
- 				$info_list[$key]['size'] = $t[$value['size']];
 
- 				$info_list[$key]['rtime'] = date('Y-m-d H:i',$value['rtime']);
 
- 				$sl += $value['num'];
 
- 				$jg += $value['money'];
 
-             }
 
- 		    $total = $this->warehousefactory->find_count($where);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'wf'=>(array(sprintf("%01.2f",$sl),sprintf("%01.2f",$jg))));
 
- 		    echo json_encode($rows);exit;
 
- 		}
 
- 		$this->_Template('warehousefactory_enter',$this->data);
 
- 	}
 
- 	
 
- 	public function _out($arg_array)
 
- 	{
 
- 		$t = array();
 
- 		$typeclass = $this->typeclass->find_all();
 
- 		foreach ($typeclass as $v)
 
- 		{
 
- 			$t[$v['id']] = $v['title'];
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['page']))  
 
- 		{
 
- 		    $page = $this->input->post('page',true);
 
- 		    $perpage = $this->input->post('perpage',true);
 
- 			$warehouse = $this->input->post('warehouse',true);
 
- 			$outtype = $this->input->post('outtype',true);
 
- 			$sku = $this->input->post('sku',true);
 
- 			$title = $this->input->post('title',true);
 
- 			$cagent = $this->input->post('cagent',true);
 
- 			$department = $this->input->post('department',true);
 
- 			$customer = $this->input->post('customer',true);
 
- 			$outorder = $this->input->post('outorder',true);
 
- 			$tax = $this->input->post('tax',true);
 
- 			$contract = $this->input->post('contract',true);
 
- 			$ktime = $this->input->post('ktime',true);
 
- 			$jtime = $this->input->post('jtime',true);
 
- 			$ktime = strtotime($ktime);
 
- 			$jtime = strtotime($jtime);
 
- 			$where = "1=1";
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
- 			if($sku)
 
-             {
 
-                 $where  .= " and sku like '%$sku%'";
 
-             }
 
- 			if($title)
 
-             {
 
-                 $where  .= " and title like '%$title%'";
 
-             }
 
- 			if($cagent)
 
-             {
 
-                 $where  .= " and cagent like '%$cagent%'";
 
-             }
 
- 			if($department)
 
-             {
 
-                 $where  .= " and department like '%$department%'";
 
-             }
 
- 			if($customer)
 
-             {
 
-                 $where  .= " and customer like '%$customer%'";
 
-             }
 
- 			if($outorder)
 
-             {
 
-                 $where  .= " and outorder like '%$outorder%'";
 
-             }
 
- 			if($warehouse)
 
-             {
 
-                 $where  .= " and warehouse = '$warehouse'";
 
-             }
 
- 			if($outtype)
 
-             {
 
-                 $where  .= " and outtype = '$outtype'";
 
-             }
 
- 			if($tax)
 
-             {
 
-                 $where  .= " and tax = '$tax'";
 
-             }
 
- 			if($contract)
 
-             {
 
-                 $where  .= " and contract = '$contract'";
 
-             }
 
- 			if($ktime && $jtime)
 
-             {
 
- 				$where  .= " and ctime > '$ktime' and ctime < '$jtime'";
 
-             }
 
-             //取得信息列表
 
- 			$info_list = $this->warehousefactoryout->find_all($where,'id,warehouse,outtype,outorder,sku,title,lowe,color,size,specs,num,jj,ctime',$order_str,$start,$perpage);
 
- 			 //格式化数据
 
-             foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				if($value['warehouse'] == '1')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '原材料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '2')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '半成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '3')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '4')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '辅料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '5')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '普通仓';
 
- 				}
 
- 				if($value['outtype'] == '1')
 
- 				{
 
- 					$info_list[$key]['outtype'] = '材料出库单';
 
- 				}
 
- 				else if($value['outtype'] == '2')
 
- 				{
 
- 					$info_list[$key]['outtype'] = '销售出库单';
 
- 				}
 
- 				else if($value['outtype'] == '3')
 
- 				{
 
- 					$info_list[$key]['outtype'] = '其他出库单';
 
- 				}
 
- 				$info_list[$key]['lowe'] = $t[$value['lowe']];
 
- 				$info_list[$key]['color'] = $t[$value['color']];
 
- 				$info_list[$key]['size'] = $t[$value['size']];
 
- 				$info_list[$key]['ctime'] = date('Y-m-d H:i',$value['ctime']);
 
-             }
 
- 		    $total = $this->warehousefactoryout->find_count($where);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
 
- 		    echo json_encode($rows);exit;
 
- 		}
 
- 		$this->_Template('warehousefactory_out',$this->data);
 
- 	}
 
- 	
 
- 	public function _outxq($arg_array)
 
- 	{
 
- 		$arg_array = $arg_array[0];$m=0;
 
- 		$warehousefactory = $this->warehousefactoryout->read($arg_array);
 
- 		$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'");
 
- 		foreach ($r as $v) 
 
- 		{
 
- 			if($v['synum'] > 0)
 
- 			{
 
- 			    $m += $v['synum']*$v['price'];
 
- 			}
 
- 		}
 
- 		$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'");
 
- 		$warehousefactory['r'] = array_sum(array_column($r,'num'));
 
- 		$warehousefactory['c'] = array_sum(array_column($c,'num'));
 
- 		$warehousefactory['j'] = array_sum(array_column($r,'synum'));
 
- 		$this->data['warehousefactory'] = $warehousefactory;
 
- 		$this->_Template('warehousefactory_outxq',$this->data);
 
- 	}
 
- 	
 
- 	//添加
 
- 	public function _add()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['sku']))
 
- 		{
 
- 			$time = time();
 
- 			$num = $this->input->post('num',true);
 
- 			if($num < 1)
 
- 			{
 
- 				echo json_encode(array('msg'=>'添加数量不正确!','success'=>false));exit;
 
- 			}
 
- 			$post['time'] = $time;
 
- 			$post['rtime'] = $time;
 
- 			$post['grtime'] = date('Y-m-d',$time);
 
- 			$post['review'] = 2;//需要审核改为1
 
- 			$post['synum'] = $post['num'];
 
- 			if (!$this->warehousefactory->insert($post))
 
- 			{
 
- 				echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
 
- 			}
 
- 		}
 
- 		$this->data['order'] = time().rand(10,99);
 
- 		$this->_Template('warehousefactory_add',$this->data);
 
- 	}
 
- 	
 
- 	public function _edit($arg_array)
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['id']))
 
- 		{
 
- 			$time = time();
 
- 			$id = $this->input->post('id',true);
 
- 			$d = $this->warehousefactory->read($id);
 
- 			if($post['num'] < 1 || $d['synum']-($d['num']-$post['num']) < 0)
 
- 			{
 
- 				echo json_encode(array('msg'=>'可用数量小于1或剩余数量不足扣减','success'=>false));exit;
 
- 			}
 
- 			if($d['synum'] != $d['num'])
 
- 			{
 
- 				echo json_encode(array('msg'=>'已有出库记录,无法修改!','success'=>false));exit;
 
- 			}
 
- 			if($post['num'] > $d['num'])
 
- 			{
 
- 				$post['synum'] = $post['num']-$d['num']+$d['synum'];
 
- 			}
 
- 			else
 
- 			{
 
- 				$post['synum'] = $d['synum']-($d['num']-$post['num']);
 
- 			}
 
- 			if (!$this->warehousefactory->save($post,$id))
 
- 			{
 
- 				echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
 
- 			}
 
- 		}
 
- 		$arg_array = $arg_array[0];
 
- 		$warehousefactory = $this->warehousefactory->read($arg_array);
 
- 		$this->data['warehousefactory'] = $warehousefactory;
 
- 		$this->_Template('warehousefactory_edit',$this->data);
 
- 	}
 
- 	
 
- 	public function _ck($arg_array)
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['id']))
 
- 		{
 
- 			$id = $this->input->post('id',true);
 
- 			$wyl = $this->warehousefactory->read($id);
 
- 			$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'");
 
- 			$time = time();
 
- 			$num = $this->input->post('num',true);
 
- 			$k = 0;$sl = 0;$money = 0;$x = 0;
 
- 			foreach ($warehousefactory as $v)
 
- 		    {
 
- 				$k++;
 
- 				if($v['synum'] != 0)
 
- 				{
 
- 					$sl += $v['synum'];
 
- 					$money += $v['synum']*$v['price'];
 
- 				}
 
- 				if($x == '0' && $sl >= $num)
 
- 				{
 
- 					$x = $k;
 
- 				}
 
- 			}
 
- 			if($sl < abs($num))
 
- 			{
 
- 				echo json_encode(array('msg'=>'扣减数量大于库存剩余数量!','success'=>false));exit;
 
- 			}
 
- 			$post = $warehousefactory[0];
 
- 			$post['jj'] = sprintf("%01.2f",$money/$sl);
 
- 			$post['num'] = $this->input->post('num',true);
 
- 			$post['outtype'] = $this->input->post('outtype',true);
 
- 			$post['department'] = $this->input->post('department',true);
 
- 			$post['customer'] = $this->input->post('customer',true);
 
- 			$post['cagent'] = $this->input->post('cagent',true);
 
- 			$post['ctext'] = $this->input->post('ctext',true);
 
- 			$post['outorder'] = time().rand(10,99);
 
- 			$post['ctime'] = $time;
 
- 			$post['time'] = $time;
 
- 			$post['gctime'] = date('Ymd',$time);
 
- 			unset($post['id']);
 
- 			$this->db->trans_begin();
 
- 			$kcjl = '';
 
- 			for($i=0;$i<$x;$i++)
 
- 		    {
 
- 				if($warehousefactory[$i]['synum'] <= $post['num'])
 
- 				{
 
- 					$this->warehousefactory->save(array('synum'=>0),$warehousefactory[$i]['id']);
 
- 					$post['num'] = $post['num'] - $warehousefactory[$i]['synum'];
 
- 					$kcjl .= $warehousefactory[$i]['id'].'-'.$warehousefactory[$i]['synum'].'|';
 
- 				}
 
- 				else
 
- 				{
 
- 					$this->warehousefactory->save(array('synum'=>$warehousefactory[$i]['synum']-$post['num']),$warehousefactory[$i]['id']);
 
- 					$kcjl .= $warehousefactory[$i]['id'].'-'.$post['num'].'|';
 
- 				}
 
- 			}
 
- 			$post['kcjl'] = $kcjl;
 
- 			$this->warehousefactoryout->insert($post);
 
- 			if ($this->db->trans_status() === TRUE)
 
-         	{
 
- 				$this->db->trans_commit();
 
- 				echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				$this->db->trans_rollback();
 
- 				echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
 
- 			}
 
- 		}
 
- 		$m = 0;
 
- 		$arg_array = $arg_array[0];
 
- 		$warehousefactory = $this->warehousefactory->read($arg_array);
 
- 		$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'");
 
- 		foreach ($r as $v) 
 
- 		{
 
- 			if($v['synum'] > 0)
 
- 			{
 
- 			    $m += $v['synum']*$v['price'];
 
- 			}
 
- 		}
 
- 		$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'");
 
- 		$warehousefactory['r'] = array_sum(array_column($r,'num'));
 
- 		$warehousefactory['c'] = array_sum(array_column($c,'num'));
 
- 		$warehousefactory['j'] = array_sum(array_column($r,'synum'));
 
- 		$warehousefactory['jj'] = sprintf("%01.2f",$m/$warehousefactory['j']);
 
- 		$this->data['warehousefactory'] = $warehousefactory;
 
- 		$this->_Template('warehousefactory_ck',$this->data);
 
- 	}
 
- 	//删除
 
- 	public function _del()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['s']))  
 
- 		{
 
-             $id_arr = $this->input->post('s');
 
-             $id_arr =  explode(',',$id_arr);
 
-             if(!$id_arr)
 
-             {
 
-                 echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
 
-             }
 
-             //循环删除记录
 
-             foreach ($id_arr as $v) 
 
- 		    {
 
- 				$d = $this->warehousefactory->read($v);
 
- 				if($d['num'] == $d['synum'])//只能删除未使用的库存
 
- 				{
 
-                     $this->warehousefactory->remove($v);
 
- 				}
 
-             }
 
-             echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
 
- 		}
 
-     }
 
- 	
 
- 	public function _outdel()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['s']))  
 
- 		{
 
-             $id_arr = $this->input->post('s');
 
-             $id_arr =  explode(',',$id_arr);
 
-             if(!$id_arr)
 
-             {
 
-                 echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
 
-             }
 
-             $this->db->trans_begin();
 
-             foreach ($id_arr as $v) 
 
- 		    {
 
- 				$d = $this->warehousefactoryout->read($v);
 
- 				$data = explode('|',rtrim($d['kcjl'],'|'));
 
- 				if(count($data) > 0)
 
- 				{
 
- 					foreach ($data as $vv) 
 
- 		            {
 
- 						$u = explode('-',$vv);
 
- 						$y = $this->warehousefactory->read($u[0]);
 
- 						if($y)
 
- 						{
 
- 							$this->warehousefactory->save(array('synum'=>$y['synum']+$u[1]),$u[0]);
 
- 						}
 
- 					}
 
- 				}
 
- 				$this->warehousefactory->remove($v);
 
-             }
 
-             if ($this->db->trans_status() === TRUE)
 
-         	{
 
- 				$this->db->trans_commit();
 
- 				echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				$this->db->trans_rollback();
 
- 				echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
 
- 			}
 
- 		}
 
-     }
 
- 	
 
- 	public function _presetedit($arg_array)
 
- 	{
 
- 		$t = array();$bs = array();
 
- 		$typeclass = $this->typeclass->find_all();
 
- 		foreach ($typeclass as $v)
 
- 		{
 
- 			$t[$v['title']] = $v['id'];
 
- 			$bs[$v['bqsku']] = $v['id'];
 
- 		}
 
- 		$dir = '/data/excel/'.date('Ymd',time()).'/';
 
- 		$config['upload_path'] = '.'.$dir ;
 
- 		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
 
-         $config['allowed_types'] = 'xls|xlsx|csv';
 
-         $config['max_size'] = 10240;
 
- 		$this->load->library('upload', $config);
 
- 		$this->upload->initialize($config);
 
-         if ($this->upload->do_upload('userfile'))
 
-         {
 
- 			$full_path = $dir.$this->upload->data('file_name');
 
- 			$fileName = '.' . $full_path;
 
-             if (!file_exists($fileName)) 
 
- 			{
 
- 				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
 
-             }
 
- 			else
 
- 			{
 
- 				libxml_use_internal_errors(true);
 
- 				require_once "./data/excel/PHPExcel/IOFactory.php";
 
- 				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
 
- 				$phpExcel->setActiveSheetIndex(0);// 设置为默认表
 
- 				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
 
- 				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
 
- 				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
 
- 				++$column;//如果列数大于26行
 
- 				$list = array();
 
- 				for ($i = 2; $i <= $row; $i++) // 行数循环
 
- 				{
 
- 					$data = array();
 
-                     for ($c = 'A'; $c != $column; $c++)  // 列数循环
 
- 	                {
 
- 						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
 
-                     }
 
- 					$list[] = $data;
 
-                 }
 
- 			}
 
- 			$i = 0;$j = 0;$ed = array();$x=0;$cs = '';
 
- 		    foreach ($list as $key=>$value)
 
- 		    {
 
- 				$h = $key+2;
 
- 				$x++;
 
- 				$time = time();
 
- 				if($value['1'] == "" || $value['1'] == null)
 
- 				{
 
- 					continue;
 
- 				}
 
- 				$value8='';
 
- 				if(preg_match('/\d/',$value['8']))
 
- 				{
 
- 					if(stripos($value['8'],'以上') !== false)
 
- 					{
 
- 						for($i=0;$i<strlen($value['8']);$i++)
 
- 						{
 
- 							if(is_numeric($value['8'][$i]))
 
- 							{
 
- 								$value8.=$value['8'][$i];
 
- 				    		}
 
-                 		}
 
- 						$value8 = $value8.'inch以上';
 
- 					}
 
- 					else
 
- 					{
 
- 						for($i=0;$i<strlen($value['8']);$i++)
 
- 						{
 
- 							if(is_numeric($value['8'][$i]))
 
- 							{
 
- 								$value8.=$value['8'][$i];
 
- 				    		}
 
-                 		}
 
- 						$value8 = $value8.'inch';
 
- 					}
 
- 				}
 
- 				else
 
- 				{
 
- 					$value8 = preg_replace('/( | | |\s)/',' ',$value['8']);
 
- 				}
 
- 				$warehouse = $value['0'];
 
- 				$entertype =  $value['1'];
 
- 				$sku =  $value['2'];
 
- 				$title =  $value['3'];
 
- 				$agent =  $value['4'];
 
- 				$supply =  $value['5'];
 
- 				if(!isset($t[$value['6']]))
 
- 				{
 
- 					$ed[] = array('第'.$h.'行,曲度填写不规范或没有此曲度');
 
- 					$j++;
 
- 					continue;
 
- 				}
 
- 				else
 
- 				{
 
- 					$lowe = $t[$value['6']];
 
- 				}
 
- 				if(!isset($t[$value['7']]))
 
- 				{
 
- 					$ed[] = array('第'.$h.'行,颜色填写不规范或没有此颜色');
 
- 					$j++;
 
- 					continue;
 
- 				}
 
- 				else
 
- 				{
 
- 					$color = $t[$value['7']];
 
- 				}
 
- 				if(!isset($bs[$value['8']]))
 
- 				{
 
- 					$ed[] = array('第'.$h.'行,尺寸填写不规范或没有此尺寸');
 
- 					$j++;
 
- 					continue;
 
- 				}
 
- 				else
 
- 				{
 
- 					$size = $bs[$value['8']];
 
- 				}
 
- 				$specs =  ($value['9'])?$value['9']:'';
 
- 				$company =  $value['10'];
 
- 				$num =  $value['11'];
 
- 				$yprice =  $value['12'];
 
- 				$ymoney =  $value['13'];
 
- 				$price =  $yprice*$value['18'];
 
- 				$money =  $ymoney*$value['18'];
 
- 				$tax =  $value['14'];
 
- 				$contract =  ($value['15'])?$value['15']:'';
 
- 				$nbgl =  $value['16'];
 
- 				$bgd =  $value['17'];
 
- 				$hl =  $value['18'];
 
- 				if(!isset($t[$value['19']]))
 
- 				{
 
- 					$ed[] = array('第'.$h.'行,币种填写不规范或没有此币种');
 
- 					$j++;
 
- 					continue;
 
- 				}
 
- 				else
 
- 				{
 
- 					$bz = $t[$value['19']];
 
- 				}
 
- 				$text =  ($value['20'])?$value['20']:'';
 
- 				$enterorder =  time()*100+$x;
 
- 				$d = $this->warehousefactory->get_sku($sku);
 
- 				if($nbgl == '' || $bgd == '' || $hl == '' || $bz == '')
 
- 				{
 
- 					$ed[] = array('第'.$h.'行添加失败,请查看是否缺:内部关联号、少报关单号、汇率、币种');
 
- 					$j++;
 
- 					continue;
 
- 				}
 
- 				if($num > 0)
 
- 				{
 
- 					$post['state'] = 0;
 
- 					$post['warehouse'] = $warehouse;
 
- 					$post['entertype'] =  $entertype;
 
- 					$post['sku'] =  $sku;
 
- 					$post['title'] =  $title;
 
- 					$post['agent'] =  $agent;
 
- 					$post['supply'] =  $supply;
 
- 					$post['lowe']=  $lowe;
 
- 					$post['color'] =  $color;
 
- 					$post['size']=  $size;
 
- 					$post['specs'] =  $specs;
 
- 					$post['company'] =  $company;
 
- 					$post['num']=  $num;
 
- 					$post['synum']=  $num;
 
- 					$post['yprice'] =  $yprice;
 
- 					$post['ymoney'] =  $ymoney;
 
- 					$post['price'] =  $price;
 
- 					$post['money'] =  $money;
 
- 					$post['tax'] =  $tax;
 
- 					$post['contract'] =  $contract;
 
- 					$post['nbgl'] =  $nbgl;
 
- 					$post['bgd'] =  $bgd;
 
- 					$post['hl'] =  $hl;
 
- 					$post['bz'] =  $bz;
 
- 					$post['text'] =  $text;
 
- 					$post['enterorder'] = $enterorder;
 
- 					$post['rtime'] =$time+$x;
 
- 					$post['grtime'] =  date('Ymd',$time+$x);
 
- 					$post['time'] = $time+$x;
 
- 					$post['review'] = 2;//需要审核改为1
 
- 					$this->warehousefactory->insert($post);
 
- 				}
 
- 				//防止入库时间一样,需要延迟1秒
 
- 			}
 
- 			if($j > 0)
 
- 			{
 
- 				$tt = date('Ymd',time());
 
- 				$title = '导入错误信息-'.$tt;
 
-         		$titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
 
- 				$tail = "\n";
 
-         		$filename = $title.".xls";
 
-         		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
 
- 				$dir = '/data/excel/'.$time.'/';
 
- 				$file_name = 'error_'.$time.rand(1000,9999);
 
- 				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
 
- 				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
 
- 				fwrite($myfile,$ecl);
 
- 				fclose($myfile);
 
- 				$error = $dir.$file_name.'.xls';
 
- 				echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	public function _outexcel($arg_array)
 
- 	{
 
- 		$dir = '/data/excel/'.date('Ymd',time()).'/';
 
- 		$config['upload_path'] = '.'.$dir ;
 
- 		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
 
-         $config['allowed_types'] = 'xls|xlsx|csv';
 
-         $config['max_size'] = 10240;
 
- 		$this->load->library('upload', $config);
 
- 		$this->upload->initialize($config);
 
-         if ($this->upload->do_upload('userfile'))
 
-         {
 
- 			$full_path = $dir.$this->upload->data('file_name');
 
- 			$fileName = '.' . $full_path;
 
-             if (!file_exists($fileName)) 
 
- 			{
 
- 				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
 
-             }
 
- 			else
 
- 			{
 
- 				libxml_use_internal_errors(true);
 
- 				require_once "./data/excel/PHPExcel/IOFactory.php";
 
- 				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
 
- 				$phpExcel->setActiveSheetIndex(0);// 设置为默认表
 
- 				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
 
- 				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
 
- 				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
 
- 				++$column;//如果列数大于26行
 
- 				$list = array();
 
- 				for ($i = 2; $i <= $row; $i++) // 行数循环
 
- 				{
 
- 					$data = array();
 
-                     for ($c = 'A'; $c != $column; $c++)  // 列数循环
 
- 	                {
 
- 						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
 
-                     }
 
- 					$list[] = $data;
 
-                 }
 
- 			}
 
- 			$i = 0;$j = 0;$ed = array();$x=0;
 
- 		    foreach ($list as $key=>$value)
 
- 		    {
 
- 				$x++;
 
- 				$time = time();
 
- 				if($value['0'] == "")
 
- 				{
 
- 					continue;
 
- 				}
 
- 				
 
- 				$outdata['warehouse'] = $value['0'];
 
- 				$outdata['sku'] =  $value['1'];
 
- 				$outdata['outtype'] = $value['2'];
 
- 				$outdata['department'] =  $value['3'];
 
- 				$outdata['customer'] =  $value['4'];
 
- 				$outdata['cagent'] =  $value['5'];
 
- 				$outdata['num'] =  $value['6'];
 
- 				$outdata['ctext'] =  $value['7'];
 
- 				$outdata['outorder'] = time().rand(10,999);
 
- 				$outdata['ctime'] = $time;
 
- 				$outdata['time'] = $time;
 
- 				$outdata['gctime'] = date('Ymd',$time);
 
- 				$outdata['state'] = 1;
 
- 				
 
- 				if($outdata['warehouse'] == '' || $outdata['sku'] == '' || $outdata['outtype'] == '' || $outdata['department'] == '' || $outdata['customer'] == '' || $outdata['cagent'] == '' || $outdata['num'] == '' || $outdata['ctext'] == '')
 
- 				{
 
- 					$ed[] = array($outdata['sku'].'信息不完整');
 
- 						$j++;
 
- 						continue;
 
- 				}
 
- 					$data = $this->warehousefactory->find_all('sku = "'.$outdata['sku'].'" and warehouse = "'.$outdata['warehouse'].'" and state = "0" and synum != "0" and review = "2"','*','id asc');
 
- 					
 
- 					if(!$data)//如果没有这个SKU
 
- 					{
 
- 						$ed[] = array($outdata['sku'].'-库存中不存在此编码');
 
- 						$j++;
 
- 						continue;
 
- 					}
 
- 					
 
- 					$sl = 0;$money = 0;$k=0;$x=0;
 
- 					foreach ($data as $v)
 
- 		            {
 
- 						$k++;
 
- 						if($v['synum'] != 0)
 
- 						{
 
- 						    $sl += $v['synum'];
 
- 						    $money += $v['synum']*$v['price'];
 
- 						}
 
- 						if($x == '0' && $sl >= $outdata['num'])
 
- 						{
 
- 							$x = $k;
 
- 						}
 
- 					}
 
- 					if($sl < abs($outdata['num']))
 
- 					{
 
- 						$ed[] = array($outdata['sku'].'-扣减数量大于库存剩余数量!');
 
- 						$j++;
 
- 						continue;
 
- 					}
 
- 					$outdata = $data[0];
 
- 					$outdata['jj'] = sprintf("%01.2f",$money/$sl);
 
- 					$outdata['outtype'] = $value['2'];
 
- 					$outdata['department'] =  $value['3'];
 
- 					$outdata['customer'] =  $value['4'];
 
- 					$outdata['cagent'] =  $value['5'];
 
- 					$outdata['num'] =  $value['6'];
 
- 					$outdata['ctext'] =  $value['7'];
 
- 					$outdata['outorder'] = time().rand(10,999);
 
- 					$outdata['ctime'] = $time;
 
- 					$outdata['time'] = $time;
 
- 					$outdata['gctime'] = date('Ymd',$time);
 
- 					$outdata['state'] = 1;
 
- 					unset($outdata['id']);
 
- 					$this->db->trans_begin();
 
- 					$kcjl = '';
 
- 					$this->warehousefactoryout->insert($outdata);
 
- 					for($i=0;$i<$x;$i++)
 
- 		            {
 
- 						if($data[$i]['synum'] <= $outdata['num'])
 
- 						{
 
- 							$this->warehousefactory->save(array('synum'=>0),$data[$i]['id']);
 
- 							$outdata['num'] = $outdata['num'] - $data[$i]['synum'];
 
- 							$kcjl .= $data[$i]['id'].'-'.$data[$i]['synum'].'|';
 
- 						}
 
- 						else
 
- 						{
 
- 							$this->warehousefactory->save(array('synum'=>$data[$i]['synum']-$outdata['num']),$data[$i]['id']);
 
- 							$kcjl .= $data[$i]['id'].'-'.$outdata['num'].'|';
 
- 						}
 
- 					}
 
- 					$outdata['kcjl'] = $kcjl;
 
- 					$this->warehousefactoryout->insert($outdata);
 
- 					if ($this->db->trans_status() === TRUE)
 
-         			{
 
- 						$this->db->trans_commit();
 
- 					}
 
- 					else
 
- 					{
 
- 						$this->db->trans_rollback();
 
- 						$ed[] = array($outdata['sku'].'-操作失败,需要重试!');
 
- 						$j++;
 
- 					}
 
- 					
 
- 				sleep(1);//防止入库时间一样,需要延迟1秒
 
- 			}
 
- 			if($j > 0)
 
- 			{
 
- 				$tt = date('Ymd',time());
 
- 				$title = '导入错误信息-'.$tt;
 
-         		$titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
 
- 				$tail = "\n";
 
-         		$filename = $title.".xls";
 
-         		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
 
- 				$dir = '/data/excel/'.$time.'/';
 
- 				$file_name = 'error_'.$time.rand(1000,9999);
 
- 				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
 
- 				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
 
- 				fwrite($myfile,$ecl);
 
- 				fclose($myfile);
 
- 				$error = $dir.$file_name.'.xls';
 
- 				echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	public function _dcexcel()
 
- 	{
 
- 		if(isset($_GET['excel']))  
 
- 		{
 
- 			$ktime = $this->input->get('ktime',true);
 
- 			$jtime = $this->input->get('jtime',true);
 
- 			$tax = $this->input->get('tax',true);
 
- 			$contract = $this->input->get('contract',true);
 
- 			$ktime = strtotime($ktime);
 
- 			$jtime = strtotime($jtime);
 
- 			$where = "1=1";
 
- 			if($ktime && $jtime)
 
-             {
 
-                 $where  .= " and time > '$ktime' and time < '$jtime'";
 
-             }
 
- 			if($tax)
 
-             {
 
-                 $where  .= " and tax = '$tax'";
 
-             }
 
- 			if($contract)
 
-             {
 
-                 $where  .= " and contract = '$contract'";
 
-             }
 
-             //数据排序
 
-             $order_str = "time desc";
 
- 			 $info_list = $this->warehousefactory->find_all($where,'sku,title,specs,size,text',$order_str);
 
- 			$rows = array();$list = array();
 
- 			foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				$rows[strtolower($value['sku'])] = $value;//所有数据sku
 
- 		    }
 
- 			$rowsdq = $rows;
 
- 			 //格式化数据
 
-             foreach ($rowsdq as $key=>$value) 
 
- 		    {
 
- 				$r = $this->warehousefactory->find_count($where.' and sku = "'.$value['sku'].'" and state = "0"');
 
- 				$c = $this->warehousefactory->find_count($where.' and sku = "'.$value['sku'].'" and state = "1"');
 
- 				$rowsdq[$key]['r'] = $r+$c;
 
- 				$rowsdq[$key]['c'] = $c;
 
- 				$rowsdq[$key]['j'] = $r;
 
-             }
 
- 				
 
- 				$title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).'详情';
 
-                 $titlename = "<table border=1>
 
-                 <tr align='center'>
 
- 				<td>编码</td>
 
-                 <td>产品名称</td>
 
-                 <td>规格</td>
 
- 			    <td>尺寸</td>
 
- 				<td>描述</td>
 
- 				<td>入库</td>
 
- 				<td>出库</td>
 
- 				<td>结余</td>
 
-                 </tr>
 
-                 </table>"; 
 
-                 $filename = $title.".xls";
 
- 			    $tail = "";
 
-                 $this->excel->get_fz2($rowsdq,$titlename,$filename,$tail);
 
- 	    }
 
- 	}
 
- 	
 
- 	public function _drmb()
 
- 	{
 
- 				$title = '导入模板'; 
 
-                 $titlename = "<table border=1>
 
-                 <tr align='center'>
 
- 				<td>仓库1原材料仓,2半成品仓,3成品仓,4辅料仓,5普通仓</td>
 
- 				<td>入库类别1采购入库单,2生产入库单,3其他入库单</td>
 
- 				<td>存货编码</td>
 
- 				<td>存货名称</td>
 
- 				<td>经办人</td>
 
- 				<td>供应单位</td>
 
- 				<td>曲度</td>
 
- 				<td>颜色</td>
 
- 				<td>尺寸</td>
 
- 				<td>其它规格</td>
 
-                 <td>单位(KG)</td>
 
-                 <td>数量</td>
 
- 			    <td>单价</td>
 
- 				<td>金额</td>
 
- 				<td>1保税/2非保税:</td>
 
- 				<td>合同号</td>
 
- 				<td>内部关联号</td>
 
- 				<td>报关单号</td>
 
- 				<td>汇率(数字,如:6.41)</td>
 
- 				<td>币种(USD,CNY,EUR,GBP)</td>
 
- 				<td>备注</td>
 
-                 </tr>
 
- 				<tr align='center'>
 
- 				<td>2</td>
 
- 				<td>2</td>
 
- 				<td>1001</td>
 
-                 <td>缅甸发</td>
 
- 				<td>小明</td>
 
- 				<td>龙盈实业</td>
 
- 				<td>Straight</td>
 
- 			    <td>Natural Black</td>
 
- 				<td>20</td>
 
- 				<td>8A</td>
 
- 				<td>KG</td>
 
- 				<td>10</td>
 
- 				<td>35</td>
 
- 				<td>350</td>
 
- 				<td>2</td>
 
- 				<td>HT123456</td>
 
- 				<td>2022032801</td>
 
- 				<td>123456</td>
 
- 				<td>6.41</td>
 
- 				<td>USD</td>
 
- 				<td>质量上乘</td>
 
-                 </tr>
 
-                 </table>"; 
 
-                 $filename = $title.".xls";
 
- 			    $tail = "\n";
 
-                 $this->excel->get_fz2(array(),$titlename,$filename,$tail);
 
- 	    
 
- 	}
 
- 	
 
- 	public function _ckmb()
 
- 	{
 
- 				$title = '批量出库模板'; 
 
-                 $titlename = "<table border=1>
 
-                 <tr align='center'>
 
- 				<td>仓库1原材料仓,2半成品仓,3成品仓,4辅料仓,5普通仓</td>
 
- 				<td>存货编码</td>
 
- 				<td>出库类别1材料出库单,2销售出库单,3其他出库单</td>
 
- 				<td>领用部门</td>
 
- 				<td>客户</td>
 
- 				<td>经办人</td>
 
- 				<td>出库数量</td>
 
- 				<td>备注</td>
 
-                 </tr>
 
-                 </table>"; 
 
-                 $filename = $title.".xls";
 
- 			    $tail = "\n";
 
-                 $this->excel->get_fz2(array(),$titlename,$filename,$tail);
 
- 	    
 
- 	}
 
- 	
 
- 	public function _pd()
 
- 	{
 
- 		$t = array();
 
- 		$typeclass = $this->typeclass->find_all();
 
- 		foreach ($typeclass as $v)
 
- 		{
 
- 			$t[$v['id']] = $v['title'];
 
- 		}
 
- 		$post = $this->input->get(NULL, TRUE);
 
- 		if(isset($post['page']))  
 
- 		{
 
- 			$warehouse = $this->input->get('warehouse',true);
 
- 			$sku = $this->input->get('sku',true);
 
- 			$title = $this->input->get('title',true);
 
- 			$lowe = $this->input->get('lowe',true);
 
- 			$color = $this->input->get('color',true);
 
- 			$size = $this->input->get('size',true);
 
- 			$specs = $this->input->get('specs',true);
 
- 			$tax = $this->input->get('tax',true);
 
- 			$contract = $this->input->get('contract',true);
 
- 			$ktime = $this->input->get('ktime',true);
 
- 			$jtime = $this->input->get('jtime',true);
 
- 			$ktime = strtotime($ktime);
 
- 			$jtime = strtotime($jtime);
 
- 			$where = "1=1 ";
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
- 			if($sku)
 
-             {
 
-                 $where  .= " and sku like '%$sku%'";
 
-             }
 
- 			if($title)
 
-             {
 
-                 $where  .= " and title like '%$title%'";
 
-             }
 
- 			if($lowe)
 
-             {
 
-                 $where  .= " and lowe like '%$lowe%'";
 
-             }
 
- 			if($color)
 
-             {
 
-                 $where  .= " and color like '%$color%'";
 
-             }
 
- 			if($size)
 
-             {
 
-                 $where  .= " and size like '%$size%'";
 
-             }
 
- 			if($specs)
 
-             {
 
-                 $where  .= " and specs like '%$specs%'";
 
-             }
 
- 			if($tax)
 
-             {
 
-                 $where  .= " and tax = '$tax'";
 
-             }
 
- 			if($contract)
 
-             {
 
-                 $where  .= " and contract = '$contract'";
 
-             }
 
- 			$zrk = 0;$zck = 0;$zjy = 0;$zjg = 0;
 
-             //取得信息列表
 
-             $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,');
 
- 			 //格式化数据
 
-             foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				if($value['warehouse'] == '1')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '原材料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '2')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '半成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '3')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '成品仓';
 
- 				}
 
- 				else if($value['warehouse'] == '4')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '辅料仓';
 
- 				}
 
- 				else if($value['warehouse'] == '5')
 
- 				{
 
- 					$info_list[$key]['warehouse'] = '普通仓';
 
- 				}
 
- 				$info_list[$key]['lowe'] = $t[$value['lowe']];
 
- 				$info_list[$key]['color'] = $t[$value['color']];
 
- 				$info_list[$key]['size'] = $t[$value['size']];
 
- 				$m = 0;$ym = 0;
 
- 				$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'");
 
- 				foreach ($r as $v) 
 
- 		        {
 
- 					$m += $v['synum']*$v['price'];
 
- 					$ym += $v['synum']*$v['yprice'];
 
- 				}
 
- 				$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'");
 
- 				$info_list[$key]['synum'] = array_sum(array_column($r,'num'));
 
- 				$info_list[$key]['price'] = array_sum(array_column($c,'num'));
 
- 				$info_list[$key]['jy'] = sprintf("%01.2f",$info_list[$key]['synum'] - $info_list[$key]['price']);
 
- 				$synum = array_sum(array_column($r,'synum'));
 
- 				if($synum > 0)
 
- 				{
 
- 					$info_list[$key]['yjj'] = sprintf("%01.2f",$ym/$synum);
 
- 				    $info_list[$key]['jj'] = sprintf("%01.2f",$m/$synum);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['yjj'] = 0;
 
- 					$info_list[$key]['jj'] = 0;
 
- 				}
 
- 				$info_list[$key]['ysyzj'] = $ym;
 
- 				$info_list[$key]['syzj'] = $m;
 
- 				$info_list[$key]['spsl'] = '';
 
- 				$info_list[$key]['bz'] = '';
 
- 				$zrk += $info_list[$key]['synum'];
 
- 				$zck += $info_list[$key]['price'];
 
- 				$zjy += $info_list[$key]['jy'];
 
- 				$yzjg += $ym;
 
- 				$zjg += $m;
 
-             }
 
- 		}
 
- 		$title = '盘点';
 
-                 $titlename = "<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>入库</td>
 
- 				<td>出库</td>
 
- 				<td>结余</td>
 
- 				<td>均价(原)</td>
 
- 				<td>均价(CNY)</td>
 
- 				<td>总价(原)</td>
 
- 				<td>总价(CNY)</td>
 
- 				<td>实盘数量</td>
 
- 				<td>备注</td>
 
-                 </tr>
 
-                 </table>"; 
 
-                 $filename = $title.".xls";
 
- 			    $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>";
 
-                 $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
 
- 	}
 
- }
 
 
  |