lvhao hai 1 mes
pai
achega
826f678592
Modificáronse 2 ficheiros con 149 adicións e 25 borrados
  1. 133 22
      core/CoreApp/controllers/Whlabel.php
  2. 16 3
      template/erp/whlabel_typejs.html

+ 133 - 22
core/CoreApp/controllers/Whlabel.php

@@ -198,6 +198,8 @@ class Whlabel extends Start_Controller
 			$this->_summaryjs($arg_array);
 		}else if($arg == 'uckjs'){
 			$this->_uckjs();
+		}else if ($arg == 'whlabelexcelzhjs') {
+			$this->_whlabelexcelzhjs();
 		}else if($arg == "w_t_cs"){
 			$this->_w_t_cs(); //首页
 		}else {
@@ -8690,33 +8692,142 @@ class Whlabel extends Start_Controller
 				["wch"=>"10"],["wch"=>"10"],["wch"=>"10"],["wch"=>"40"],["wch"=>"40"],["wch"=>"10"],["wch"=>"15"],["wch"=>"15"],["wch"=>"15"],
 			];
 			array_unshift($final_list, $first_row);
-			// echo "<pre>";
-			// print_r($merges);
-			// die;
 
 			exit(json_encode(array('code' => 1,'msg'=>"获取成功",'data'=>['merges'=>$merges, 'data' => $final_list,'title'=>$title,'cols' => $cols])));
+		}
+	}
 
+	public function _whlabelexcelzhjs(){
+		if(empty($_GET['excel'])){
+			exit(json_encode(array('code' => 0, 'msg' => '请求参数缺失')));
+		}
+		
+		$where = "sku != 'Preset' and sku != '' ";
+		//数据排序
+		$order_str = "id desc";
+		if (empty($page)) {
+			$start = 0;
+			$perpage = 1;
+		} else {
+			$start = ($page - 1) * $perpage;
+		}
+		$category = $this->input->get('category', true);
+		$warehouse = $this->input->get('warehouse', true);
+		$excelid = $this->input->get('sid', true);
+		if ($category) {
+			$where  .= " and features like '%-$category-%'";
+		}
+		if ($warehouse) {
+			$where  .= " and warehouse = '$warehouse'";
+		}
+		$xzid = '';
+		if ($excelid) {
+			$excelid = explode(',', trim($excelid, ','));
+			foreach ($excelid as $key => $value) {
+				$xzid .= " id = " . $value . " or";
+			}
+			$xzid = " and (" . rtrim($xzid, 'or') . ")";;
+		}
+		$merges = [
+			[
+				"s"=>["r"=>0,"c"=>0],
 
-			exit();
-			
-			$titlename = "<table border=1>
-            <tr align='center'>
-			<td>类别</td>
-			<td>颜色</td>
-			<td>曲度</td>
-			<td>名称</td>
-			<td>SKU</td>
-			<td>月初库存</td>
-			<td>剩余库存</td>
-			<td>在途数量</td>
-			<td>预达日期</td>" .
-				$rq
-				. "<td>本月出库</td></tr>
-            </table>";
-			$filename = $title . ".xls";
-			$tail = "";
-			$this->excel->get_fz2($data, $titlename, $filename, $tail);
+
+				"e"=>["r"=>0,"c"=>6]
+			]
+		];
+
+		$rows = $this->whlabel->find_pc($where, 'sku,features,warehouse', 'warehouse,sku,title,number,features');
+		
+		$excel_index = 2;
+		$final_list = [];
+		foreach ($rows as $key => $value) {
+			$c = $this->whlabel->find_count($where . ' and sku = "' . $value['sku'] . '" and warehouse = "' . $value['warehouse'] . '" and state = "0" and features = "' . $value['features'] . '"');
+			$zh = '';
+			$zt_list = $this->whlabeltransport->find_all('sku = "' . $value['sku'] . '" and time = "0" and warehouse = "' . $value['warehouse'] . '" and features = "' . $value['features'] . '"', 'num,stime');
+			// foreach ($zt_list as $v) {
+			// 	$zh .= $v['num'] . " / " . date('Y-m-d', $v['stime']) . "<br>";
+			// }
+			$zt = array_sum(array_column($zt_list, 'num'));
+			$number = $value['number'];
+			$ftime = time() - 15 * 24 * 3600;
+			$warehouse = $this->warehouse->read($value['warehouse']);
+			// $rows[$key]['warehouse'] = $warehouse['title'];
+			// $rows[$key]['number'] = $c;
+			// $rows[$key]['features'] = $zh;
+			//$rows[$key]['hb'] = $c + $zt;
+			$tmp = [];
+			$tmp[0] = $warehouse['title'];
+			$tmp[1] = $value['sku'];
+			$tmp[2] = $value['title'];
+			$tmp[3] = $c;
+			$tmp[4] = "";
+			$tmp[5] = $c + $zt;
+
+			if(empty($zt_list)){
+				$tmp[4] = "";
+				$final_list[] = $tmp;
+				$excel_index = $excel_index + 1;
+			}else{
+				if(count($zt_list) == 1){
+					$tmp[4] = "";
+					$tmp[4] = $zt_list[0]['num'] . " / " . date('Y-m-d', $zt_list[0]['stime']);
+					$final_list[] = $tmp;
+					$excel_index = $excel_index + 1;
+				}else{
+					$len = count($zt_list);
+					foreach ($zt_list as $v){
+						$tmp[4] = "";
+						$tmp[4] = $v['num'] . " / " . date('Y-m-d', $v['stime']);
+						$final_list[] = $tmp;
+					}
+					$merges[] = [
+						"s"=>["r"=>$excel_index,"c"=>0],
+						"e"=>["r"=>$excel_index+$len-1,"c"=>0]
+					];
+					$merges[] = [
+						"s"=>["r"=>$excel_index,"c"=>1],
+						"e"=>["r"=>$excel_index+$len-1,"c"=>1]
+					];
+					$merges[] = [
+						"s"=>["r"=>$excel_index,"c"=>2],
+						"e"=>["r"=>$excel_index+$len-1,"c"=>2]
+					];
+					$merges[] = [
+						"s"=>["r"=>$excel_index,"c"=>3],
+						"e"=>["r"=>$excel_index+$len-1,"c"=>3]
+					];
+					$merges[] = [
+						"s"=>["r"=>$excel_index,"c"=>5],
+						"e"=>["r"=>$excel_index+$len-1,"c"=>5]
+					];
+					$excel_index = $excel_index + $len;
+				}
+			}
 		}
+		$first_row = [
+			'仓库','SKU','产品','库存数量','在途数量及预达日期','在途+库存数量',
+		];
+		
+		$title = "导出库存数据及在途中数据" . date('Y-m-d', time());
+
+		if(empty($final_list)){
+			exit(json_encode(array('code' => 0, 'msg' => '无符合条件数据')));
+		}
+
+		$cols = [
+			["wch"=>"15"],["wch"=>"30"],["wch"=>"30"],["wch"=>"10"],["wch"=>"15"],["wch"=>"15"],
+		];
+		array_unshift($final_list, $first_row);
+		array_unshift($final_list, [
+			$title,"","","","",""
+		]);
+		$end_list = [];
+		foreach ($final_list as $key => $value) {
+			$end_list[] = array_values($value);
+		}
+
+		exit(json_encode(array('code' => 1,'msg'=>"获取成功",'data'=>['merges'=>$merges, 'data' => $end_list,'title'=>$title,'cols' => $cols])));
 	}
 
 }

+ 16 - 3
template/erp/whlabel_typejs.html

@@ -279,9 +279,7 @@ $(this).find('td:eq(15)').css("width","12%");
 });}
 
 
-$(".whlabelexcelzh").click(function() {
-window.location.href = "/whlabel/whlabelexcelzh?excel=1";
-});
+
 $(".plszbhtype").click(function() {
             $(".systemwindow").show();
 });
@@ -463,10 +461,25 @@ $(".whlabelxq").click(function() {
         }
     },'json')
 });
+$(".whlabelexcelzh").click(function() {
+    let url   = "/whlabel/whlabelexcelzhjs?excel=1";
+    layx.load('loadId','导出中,请稍后',{shadable:0.6});
+    $.get(url,{},function(res){
+        layx.destroy('loadId');
+        if(res.code == 1){
+            importDataNoCol(res.data)
+        }else{
+            layx.alert('错误',res.msg,function(id,button){
+            },{dialogIcon:'error'});
+        }
+    },'json')
+});
 //导出第一行不含合并单元格的
 function importDataNoCol(data){
     console.log(data.merges)
     console.log(data.cols)
+    console.log(data.data)
+    console.log(data.title)
     const fileName = data.title+'.xlsx' ;
     // 将数据转换为工作表