wugg 2 years ago
parent
commit
103138ebd2
1 changed files with 56 additions and 0 deletions
  1. 56 0
      app/command/NowReportHandle.php

+ 56 - 0
app/command/NowReportHandle.php

@@ -80,6 +80,10 @@ class NowReportHandle extends Command
                     case 'K':
                         $res = $this->K($info['start'], $info['end']);
                         break;
+                         //【库存报表】-库存品出库明细
+                    case 'L':
+                        $res = $this->NewOut($info['start'], $info['end']);
+                        break;
                     default:
                         throw new Exception('暂不支持这个报表');
                 }
@@ -763,5 +767,57 @@ class NowReportHandle extends Command
         return $data;
     }
 
+    private function NewOut(string $start,string $end)
+    {
+		$data = Db::name("order_out")
+		->alias("a")
+		->leftJoin("sale b","a.orderCode=b.orderCode")
+		->leftJoin("depart_user du"," b.apply_id=du.uid and du.is_del=0")
+		->field("b.supplierNo '业务公司',a.orderCode AS '销售单号',outCode '出库单号',
+	b.good_code '商品编号',b.cat_id ,'' as '一级分类','' as '二级分类','' as  '三级分类','' as '财务核算编号',
+	b.good_name '商品名称',a.send_num '出库数量','' as '出库金额',a.sendtime '本次出库时间',
+    ''as '税率', b.apply_id as '业务部门',a.apply_name as '业务人员',cgder as '采购员','' as '成本裸价',
+	'' as '供应商名称','' as '出库退货数量',b.order_type")
+	->where([["a.status",">=",2],["a.is_del","=",0],["b.order_type","=",1],['a.sendtime','between',[$start, $end]]])
+	->cursor();
+		$list=[];
+		foreach ($data as $value){
+			 $value['业务公司'] = Db::name("business")->where(["companyNo" => $value['业务公司']])->value('company', '');
+			$value['业务部门'] = Db::name("depart_user")->alias("a")->leftJoin("company_item ci", "a.itemid=ci.id")->where(["a.uid" => $value['业务部门'], "a.status" => 1, "a.is_del" => 0])->value('ci.name', '');
+			$cat = made($value['cat_id']);
+			 $value['财务核算编号'] = Db::name("cat")->where(["id"=>$value['cat_id']])->value("fund_code",'');
+			 unset($value['cat_id']);
+             $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
+             $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
+             $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
+			if($value["order_type"]==3){
+				$good =Db::name("good_zixun")->where(["spuCode"=>$value['商品编号']])->find();
+			}else{
+				$good =Db::name("good")->where(["spuCode"=>$value['商品编号']])->find();
+			}
+			$saleinfo =Db::name("sale_info")->where(["orderCode"=>$value['销售单号']])->field("num,origin_price,num*origin_price as total_price")->select()
+			->toArray();
+			if(empty($saleinfo)){
+				$value['成本裸价'] = Db::name("order_out")->alias("a")
+				->leftJoin("order_send b","a.outCode=b.outCode")
+				->leftJoin("purchease_order c","b.cgdNo=c.cgdNo")
+				->where(["a.outCode"=>$value['出库单号']])->value("c.good_price",'0');
+			}else{
+				$num=array_sum(array_column($saleinfo,"num"));
+				if($num==0){
+					$value['成本裸价']=0;
+				}else{
+					$value['成本裸价'] = round(array_sum(array_column($saleinfo,"total_price"))/ array_sum(array_column($saleinfo,"num"))
+						,2) ;
+				}
+			}
+			$value['出库金额'] = $value['出库数量']*$value['成本裸价'];
+			$value['税率'] = $good['tax']."%";
+			$value['供应商名称']=Db::name("supplier")->where(["code"=>$good['supplierNo']])->value("name","");
+			$value["出库退货数量"] = Db::name("order_back")->where(["outCode"=>$value['出库单号']])->sum("return_num");
+			unset($value['order_type']);
+			yield $list[] = $value;
+		}
+    }
 
 }