|
@@ -36,14 +36,14 @@ class NowReportHandle extends Command
|
|
|
|
|
|
//不同的方法处理不同的脚本
|
|
|
switch ($info['code']) {
|
|
|
- //【财务报表】退货台账-业务口径
|
|
|
- case 'A':
|
|
|
- $res = $this->A($info['start'], $info['end']);
|
|
|
- break;
|
|
|
- //【财务报表】库存日报及预警汇总表
|
|
|
- case 'B':
|
|
|
- $res = $this->B($info['start'], $info['end']);
|
|
|
- break;
|
|
|
+// //【财务报表】退货台账-业务口径
|
|
|
+// case 'A':
|
|
|
+// $res = $this->A($info['start'], $info['end']);
|
|
|
+// break;
|
|
|
+// //【财务报表】库存日报及预警汇总表
|
|
|
+// case 'B':
|
|
|
+// $res = $this->B($info['start'], $info['end']);
|
|
|
+// break;
|
|
|
//【财务报表】退货台账
|
|
|
case 'C':
|
|
|
$res = $this->C($info['start'], $info['end']);
|
|
@@ -57,9 +57,9 @@ class NowReportHandle extends Command
|
|
|
$res = $this->E($info['start'], $info['end']);
|
|
|
break;
|
|
|
//【财务报表】库存品出库明细
|
|
|
- case 'F':
|
|
|
- $res = $this->F($info['start'], $info['end']);
|
|
|
- break;
|
|
|
+// case 'F':
|
|
|
+// $res = $this->F($info['start'], $info['end']);
|
|
|
+// break;
|
|
|
//【销售】订单表导出
|
|
|
case 'G':
|
|
|
$res = $this->G($info['start'], $info['end']);
|
|
@@ -271,11 +271,8 @@ class NowReportHandle extends Command
|
|
|
->leftJoin('sale_return wsr', 'wtd.thCode = wsr.returnCode and wtd.th_type=1')
|
|
|
->leftJoin('order_return wor', 'wtd.thCode = wor.returnCode and wtd.th_type in (2,3)')
|
|
|
->leftJoin('sale ws', 'ws.orderCode=wtd.orderCode and ws.is_del=0')
|
|
|
-// ->leftJoin('business wb', ' ws.supplierNo=wb.companyNo')
|
|
|
->leftJoin('order_num won', 'won.orderCode=wtd.orderCode')
|
|
|
->leftJoin('purchease_order wpo', 'wpo.cgdNo=won.cgdNo and wpo.is_del=0')
|
|
|
-// ->leftJoin('supplier wps', 'wps.code=wpo.supplierNo')
|
|
|
-// ->leftJoin('customer_info wci', 'wci.companyNo =ws.customer_code')
|
|
|
->whereBetween('wtd.addtime', [$start_date, $end_date])
|
|
|
->field(" year(wtd.addtime) '年',
|
|
|
month(wtd.addtime) '月',
|
|
@@ -393,7 +390,6 @@ class NowReportHandle extends Command
|
|
|
->leftJoin("purchease_order wpo", "wpo.cgdNo=won.cgdNo and wpo.is_del=0")
|
|
|
->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
|
|
|
->leftJoin("good_zixun wgz", "wgz.spuCode=wpo.spuCode and wgz.is_del=0")
|
|
|
-// ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
|
|
|
->where('woo.status', ">=", 2)
|
|
|
->where('woo.is_del', "=", 0)
|
|
|
->where('wpo.order_type', "<>", 1)
|
|
@@ -404,6 +400,7 @@ class NowReportHandle extends Command
|
|
|
a.supplierName as '公司名称',
|
|
|
a.apply_id '业务部门名称' ,
|
|
|
a.apply_name as '业务人员',
|
|
|
+ if(a.pay_id>0,'是','否') 是否拆单,
|
|
|
a.order_type as '订单类型',
|
|
|
a.good_type as '商品类型',
|
|
|
woo.outCode '发货编号',
|
|
@@ -447,16 +444,10 @@ class NowReportHandle extends Command
|
|
|
$unit = Db::name('unit')->where('is_del', 0)->column('unit', 'id');
|
|
|
|
|
|
foreach ($list as $value) {
|
|
|
-
|
|
|
-// $tmp=User::getIns()->handle('getCodeAndName',['code'=>$value['公司名称']]);
|
|
|
-// $value['公司名称'] = $tmp['data'][$value['公司名称']]??'';//Db::name("business")->where(["companyNo"=>$value['公司名称']])->value('company','');
|
|
|
if (!isset($tmp[$value['业务部门名称']])) $tmp[$value['业务部门名称']] = get_company_name_by_uid($value['业务部门名称']);
|
|
|
$value['业务部门名称'] = $tmp[$value['业务部门名称']] ?? '';//get_company_name_by_uid($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','');
|
|
|
|
|
|
-
|
|
|
-// $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','');
|
|
|
- $value['订单类型'] = $order_tyepe[$value['订单类型'] - 1];
|
|
|
+ $value['订单类型'] = $order_tyepe[$value['订单类型'] - 1];
|
|
|
$value['商品类型'] = $good_type[$value['商品类型'] - 1];
|
|
|
$cat = made($value['三级分类']);
|
|
|
$value['财务核算编码'] = $fund_code[$value['三级分类']] ?? '';//Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
|
|
@@ -503,7 +494,7 @@ class NowReportHandle extends Command
|
|
|
->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
|
|
|
->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
|
|
|
// ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
|
|
|
- ->where('wpi.status', "in", [4, 6])
|
|
|
+ ->where('wpi.status', "=", 2)
|
|
|
->where('wpi.is_del', "=", 0)
|
|
|
->where('wpo.order_type', "=", 1)
|
|
|
->where('wpo.order_source', "=", 0)
|
|
@@ -519,8 +510,8 @@ class NowReportHandle extends Command
|
|
|
wgb.cat_id as '三级分类',
|
|
|
wgb.cat_id as '财务核算编号',
|
|
|
wpo.good_name as '商品名称',
|
|
|
- if(wpi.status=4,wpi.send_num,wpi.wsm_num) '入库数量',
|
|
|
- round( if(wpi.status=4,wpi.send_num,wpi.wsm_num) * good_price, 2 ) '入库金额',
|
|
|
+ wpi.send_num '入库数量',
|
|
|
+ wpi.send_num * good_price '入库金额',
|
|
|
wpi.updatetime '本次入库时间',
|
|
|
wgb.tax/100 '采购税率',
|
|
|
'' as '不含税入库金额',
|
|
@@ -562,7 +553,6 @@ class NowReportHandle extends Command
|
|
|
->leftJoin("order_back wor", "wor.outCode=woo.outCode and wor.status=4 and wor.is_del=0")
|
|
|
->leftJoin("purchease_order wpo", "wpo.cgdNo=won.cgdNo")
|
|
|
->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
|
|
|
-// ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
|
|
|
->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
|
|
|
->where([['woo.status', ">=", 2], ['woo.is_del', "=", 0], ['a.order_type', "=", 1], ['woo.sendtime', "between", [$start, $end]]])
|
|
|
->field("wpo.companyName '业务公司',
|
|
@@ -614,7 +604,7 @@ class NowReportHandle extends Command
|
|
|
//网络部出入库
|
|
|
public function GetWlb($start, $end)
|
|
|
{
|
|
|
- $db = Db::connect("mysql3");
|
|
|
+ $db = Db::connect("mysql_cxinv");
|
|
|
$list = $db->name("cgd_info")
|
|
|
->where(['cgdSource' => 10, "is_del" => 0])->whereBetweenTime('createdTime', $start, $end)->field(
|
|
|
"year(createdTime) AS `年`,
|
|
@@ -623,6 +613,7 @@ class NowReportHandle extends Command
|
|
|
companyName '公司名称',
|
|
|
department '业务部门',
|
|
|
ownerName '业务人员',
|
|
|
+ if(cxCode='','否','是') '是否拆单',
|
|
|
'网络部采购单' '订单类型',
|
|
|
'' as '商品类型',
|
|
|
'' as '发货编号',
|
|
@@ -649,7 +640,7 @@ class NowReportHandle extends Command
|
|
|
deliveryPrice AS `物流费`,
|
|
|
goodPrice AS `成本合计`,
|
|
|
totalPrice AS `采购货款`,
|
|
|
- tax AS `采购税点`,
|
|
|
+ tax/100 AS `采购税点`,
|
|
|
supplierName AS `供应商名称`,
|
|
|
'否'as '是否库存品',
|
|
|
'包邮' as '发货方式',
|
|
@@ -679,17 +670,17 @@ class NowReportHandle extends Command
|
|
|
|
|
|
$data = Db::name('sale')
|
|
|
->alias('s')
|
|
|
- ->field('s.addtime 确认单下单时间,s.orderCode 订单编号,s.order_type 订单类型,s.status 订单状态,s.apply_name 创建人,"" 部门,s.supplierName 销售方公司,"" 一级组织,"" 二级组织,s.customerName 购买方公司,p.platform_name 所属平台,s.platform_order 平台订单号,s.poNo 其他单号,s.paytime 承诺回款时间,ou.order_use 订单用途,"" 活动类型,s.good_name 产品名称,"" 一级分类,gb.tax 税率,s.sale_price 销售单价,s.good_num 下单数量,s.total_price 销售总额,po.cgder 采购人,gb.customized 工期时间,s.arrive_time 要求到货时间,s.remark 备注,s.is_stock 是否库存品,s.cat_id,s.is_activity,s.good_type,s.customer_code,s.apply_id')
|
|
|
-// ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
|
|
|
-// ->leftJoin('business b', 'b.companyNo=s.supplierNo')
|
|
|
+ ->field('s.addtime 确认单下单时间,s.orderCode 订单编号,s.order_type 订单类型,s.status 订单状态,s.apply_name 创建人,
|
|
|
+ "" 部门,s.supplierName 销售方公司,"" 一级组织,"" 二级组织,s.customerName 购买方公司,p.platform_name 所属平台,
|
|
|
+ s.platform_order 平台订单号,s.poNo 其他单号,s.paytime 承诺回款时间,ou.order_use 订单用途,"" 活动类型,s.good_name 产品名称,
|
|
|
+ "" 一级分类,gb.tax 税率,s.sale_price 销售单价,s.good_num 下单数量,s.total_price 销售总额,po.cgder 采购人,gb.customized 工期时间,
|
|
|
+ s.arrive_time 要求到货时间,s.remark 备注,s.is_stock 是否库存品,s.cat_id,s.is_activity,s.good_type,s.customer_code,s.apply_id')
|
|
|
->leftJoin('platform p', 'p.id=s.platform_id')
|
|
|
->leftJoin('good_basic gb', 'gb.spuCode=s.good_code')
|
|
|
->leftJoin('order_use ou', 'ou.id=s.use_order')
|
|
|
-// ->leftJoin('depart_user u', 'u.uid=s.apply_id')
|
|
|
-// ->leftJoin('company_item ci', 'ci.id=u.itemid')
|
|
|
->leftJoin('order_num on', 'on.orderCode=s.orderCode')
|
|
|
->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
|
|
|
- ->where(['s.is_del' => 0, 'ci.is_del' => 0])
|
|
|
+ ->where(['s.is_del' => 0])
|
|
|
->whereBetween('s.addtime', [$start_date, $end_date])
|
|
|
->order('s.addtime', 'desc')
|
|
|
->cursor();
|
|
@@ -704,17 +695,17 @@ class NowReportHandle extends Command
|
|
|
|
|
|
if (!isset($tmp_customer[$value['customer_code']])) {
|
|
|
$tmp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
|
|
|
- $tmp_customer[$value['customer_code']] = $tmp['data']['itemid'];
|
|
|
+ $tmp_customer[$value['customer_code']] = $tmp['data']['itemid']??0;
|
|
|
}
|
|
|
+ $value['itemid'] = $tmp_customer[$value['customer_code']]??"";
|
|
|
|
|
|
- $value['itemid'] = $tmp_customer[$value['customer_code']];
|
|
|
|
|
|
|
|
|
- $value['订单类型'] = isset($all_order_type[$value['订单类型']]) ? $all_order_type[$value['订单类型']] : '';
|
|
|
+ $value['订单类型'] = isset($all_order_type[$value['订单类型']]) ? $all_order_type[$value['订单类型']] : '';
|
|
|
$value['订单状态'] = isset($all_sale_status[$value['订单状态']]) ? $all_sale_status[$value['订单状态']] : '';
|
|
|
|
|
|
- if (!empty($value['itemid'])) {
|
|
|
- $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
|
|
|
+ if ($value['itemid']!='') {
|
|
|
+ $customer_org1 = array_column(get_top_customer_org($value['itemid'])??[], 'name', 'level');
|
|
|
$value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
|
|
|
$value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
|
|
|
}
|
|
@@ -764,7 +755,8 @@ class NowReportHandle extends Command
|
|
|
$cat = made($value['一级分类']);
|
|
|
$value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
|
|
|
|
|
|
- $value['最近入库时间'] = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in c", "a.cgdNo=c.cgdNo")->where(["spuCode" => $value['产品编号'], "order_type" => 1, "order_source" => 0, "c.status" => [4, 6]])->order("a.addtime desc")->value("c.addtime", "");
|
|
|
+ $value['最近入库时间'] = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in c", "a.cgdNo=c.cgdNo")
|
|
|
+ ->where(["spuCode" => $value['产品编号'], "order_type" => 1, "order_source" => 0, "c.status" =>2])->order("a.addtime desc")->value("c.addtime", "");
|
|
|
$value['备库单号'] = Db::name("purchease_order")->alias("a")->where(["spuCode" => $value['产品编号'], "order_type" => 1, "order_source" => 0])->order("a.addtime desc")->value("a.bkcode", "");
|
|
|
if (!empty($value['最近入库时间'])) {
|
|
|
$value['保质期时间'] = date('Y-m-d H:i:s', strtotime($value['最近入库时间']) + 31536000);//365天之后
|
|
@@ -841,11 +833,11 @@ class NowReportHandle extends Command
|
|
|
->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode")
|
|
|
->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
|
|
|
// ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
|
|
|
- ->where('wpi.status', "in", [4, 6])
|
|
|
+ ->where('wpi.status', "=", 2)
|
|
|
->where('wpo.order_type', "=", 1)
|
|
|
->where('wpo.order_source', "=", 0)
|
|
|
->whereBetween('wpi.addtime', [$start, $end])
|
|
|
- ->field("wpo.companyName '业务公司',bkcode '备库单号',wpi.wsm_in_code '入库单号',wpi.cgdNo '采购单号',wpo.spuCode '商品编号','' as '一级分类','' as '二级分类',wgb.cat_id as '三级分类',wgb.cat_id as '财务核算编号',wpo.good_name as '商品名称',if(wpi.status=4,wpi.send_num,wpi.wsm_num) '入库数量',wpo.updatetime '本次入库时间',wp.apply_id as '业务部门',wp.apply_name as '业务员',wpo.cgder as '采购员',wsm_type '仓库类型',wpo.supplier_name '供应商名称',wwi.name '仓库名称'")
|
|
|
+ ->field("wpo.companyName '业务公司',bkcode '备库单号',wpi.wsm_in_code '入库单号',wpi.cgdNo '采购单号',wpo.spuCode '商品编号','' as '一级分类','' as '二级分类',wgb.cat_id as '三级分类',wgb.cat_id as '财务核算编号',wpo.good_name as '商品名称',wpi.send_num '入库数量',wpo.updatetime '本次入库时间',wp.apply_id as '业务部门',wp.apply_name as '业务员',wpo.cgder as '采购员',wsm_type '仓库类型',wpo.supplier_name '供应商名称',wwi.name '仓库名称'")
|
|
|
->cursor();
|
|
|
$data = [];
|
|
|
$fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
|
|
@@ -911,22 +903,22 @@ class NowReportHandle extends Command
|
|
|
$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.supplierName '业务公司',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")
|
|
|
+ '' as '供应商名称','' as '出库退货数量',b.order_type,b.addtime")
|
|
|
->where([["a.status", ">=", 2], ["a.is_del", "=", 0], ["b.order_type", "=", 1], ['a.sendtime', 'between', [$start, $end]]])
|
|
|
->cursor();
|
|
|
$list = $tmp = [];
|
|
|
$fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
|
|
|
+ $date=strtotime("2023-04-15 00:00:00");
|
|
|
foreach ($data as $value) {
|
|
|
-// $value['业务公司'] = Db::name("business")->where(["companyNo" => $value['业务公司']])->value('company', '');
|
|
|
+
|
|
|
if (!isset($tmp[$value['业务部门']])) $tmp[$value['业务部门']] = get_company_name_by_uid($value['业务部门']);
|
|
|
- $value['业务部门'] = $tmp[$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', '');
|
|
|
+ $value['业务部门'] = $tmp[$value['业务部门']] ?? '';
|
|
|
$cat = made($value['cat_id']);
|
|
|
- $value['财务核算编号'] = $fund_code[$value['cat_id']] ?? '';//Db::name("cat")->where(["id"=>$value['cat_id']])->value("fund_code",'');
|
|
|
+ $value['财务核算编号'] = $fund_code[$value['cat_id']] ?? '';
|
|
|
unset($value['cat_id']);
|
|
|
$value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
|
|
|
$value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
|
|
@@ -936,95 +928,75 @@ class NowReportHandle extends Command
|
|
|
} 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);
|
|
|
- }
|
|
|
+ if(strtotime($value['addtime'])<=$date){
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $mp= Db::name("child_bn")->where(["outCode"=> $value['出库单号']])->field("sum(origin_price * total_bn_num)/sum(total_bn_num) as total")->findOrEmpty();
|
|
|
+ $value['成本裸价'] = $mp['total']??0;
|
|
|
}
|
|
|
$value['出库金额'] = $value['出库数量'] * $value['成本裸价'];
|
|
|
$value['税率'] = $good['tax'] . "%";
|
|
|
$value['供应商名称'] = $good['supplierName'];//Db::name("supplier")->where(["code"=>$good['supplierNo']])->value("name","");
|
|
|
$value["出库退货数量"] = Db::name("order_back")->where(["outCode" => $value['出库单号']])->sum("return_num");
|
|
|
unset($value['order_type']);
|
|
|
+ unset($value['addtime']);
|
|
|
yield $list[] = $value;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**每日库存记录
|
|
|
- * @param string $start
|
|
|
- * @param string $end
|
|
|
- * @return \Generator
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\DbException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- */
|
|
|
- private function EveryDayStock(string $start, string $end)
|
|
|
- {
|
|
|
- $list = Db::name("good_stock_info")
|
|
|
- ->alias("a")
|
|
|
- ->leftJoin("good_stock b", "a.stockid=b.id")
|
|
|
- ->leftJoin("purchease_in c", "c.bnCode=a.bnCode")
|
|
|
- ->leftJoin("purchease_order d", "c.cgdNo=d.cgdNo")
|
|
|
- ->leftJoin("purchease e", "d.bkcode=e.bk_code")
|
|
|
- ->leftJoin("good f", "b.spuCode=f.spuCode")
|
|
|
- ->leftJoin("warehouse_info j", "b.wsm_code=j.wsm_code")
|
|
|
- ->field(" e.companyName '业务公司',
|
|
|
- e.apply_id '申请部门',
|
|
|
- e.apply_name '申请人',
|
|
|
- e.addtime '备库创建时间',
|
|
|
- e.bk_code '备库单号',
|
|
|
- a.bnCode 'BN编号' ,
|
|
|
- a.addtime '入库时间',
|
|
|
- c.cgdNo '采购单编号' ,
|
|
|
+ /**每日库存记录
|
|
|
+ * @param string $start
|
|
|
+ * @param string $end
|
|
|
+ * @return \Generator
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ private function EveryDayStock(string $start,string $end){
|
|
|
+ $list = Db::name("good_stock")->alias("b")
|
|
|
+ ->leftJoin("good_basic f","b.spuCode=f.spuCode")
|
|
|
+ ->leftJoin("warehouse_info j","b.wsm_code=j.wsm_code")
|
|
|
+ ->field(" f.companyName '业务公司',
|
|
|
f.spuCode '产品编号' ,
|
|
|
- f.good_name '产品名称' ,
|
|
|
- e.good_num '备库数量' ,
|
|
|
f.cat_id '一级分类' ,
|
|
|
+ f.good_name '产品名称' ,
|
|
|
f.cat_id,
|
|
|
- '' as '财务核算编码',
|
|
|
- f.tax as '税率',
|
|
|
- a.origin_price '成本单价',
|
|
|
+ '' as '财务核算编号',
|
|
|
+ f.tax/100 as '税率',
|
|
|
+ '' as '成本单价',
|
|
|
b.wait_in_stock '待入库数量',
|
|
|
b.wait_out_stock '待出库数量',
|
|
|
- (b.wait_out_stock+b.usable_stock) '当前库存数量',
|
|
|
+ (b.wait_out_stock+b.usable_stock) '当前库存数量',
|
|
|
b.usable_stock '可用库存数量',
|
|
|
- a.total_num 'BN总数',
|
|
|
- a.balance_num 'BN库存数',
|
|
|
- a.used_num 'BN已使用数量',
|
|
|
- DATEDIFF(NOW(),a.addtime) '库存天数',
|
|
|
- f.supplierNo '采购员',
|
|
|
- d.supplier_name '供应商名称',
|
|
|
- j.`name` '仓库名称'")
|
|
|
- ->where(["f.is_stock" => 1])
|
|
|
- ->whereBetween("a.updatetime", [$start, $end])
|
|
|
- ->cursor();
|
|
|
- $fund_code = Db::name('cat')->where(['is_del' => 0, 'level' => 3])->column('fund_code', 'id');
|
|
|
- $tmp = [];
|
|
|
- foreach ($list as $value) {
|
|
|
- if (!isset($tmp[$value['申请部门']])) $tmp[$value['申请部门']] = get_company_name_by_uid($value['申请部门']);
|
|
|
- $value['申请部门'] = $tmp[$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', '');
|
|
|
-// $value['业务公司'] = Db::name("business")->where(["companyNo" => $value['业务公司']])->value('company', '');
|
|
|
- $cat = made($value['cat_id']);
|
|
|
- $value['财务核算编号'] = $fund_code[$value['cat_id']] ?? '';//Db::name("cat")->where(["id"=>$value['cat_id']])->value("fund_code",'');
|
|
|
- unset($value['cat_id']);
|
|
|
- $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
|
|
|
- $supplier = Db::connect('mysql_sys')->name("supplier")->where(["code" => $value['采购员']])->field("person,name")->find();
|
|
|
- if ($value['供应商名称'] == '') {
|
|
|
- $value['供应商名称'] = $supplier['name'] ?? "";
|
|
|
- }
|
|
|
- $value['采购员'] = $supplier['person'] ?? "";
|
|
|
- yield $value;
|
|
|
- }
|
|
|
+ f.creater '采购员',
|
|
|
+ f.supplierName as '供应商名称',
|
|
|
+ j.`name` '仓库名称',
|
|
|
+ ''as '最新备库时间'
|
|
|
+ ")
|
|
|
+ ->where(["f.is_stock"=>1])
|
|
|
+ ->cursor();
|
|
|
+ foreach ($list as $value){
|
|
|
+ $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['最新备库时间']= Db::name("purchease_order")->where(["spuCode"=>$value['产品编号'],"status"=>[2,3]])
|
|
|
+ ->order("id desc")->value("addtime",'');
|
|
|
+ yield $value;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**获取商品成本列表
|