Browse Source

面料退还,面料汇总

qiuenguang 9 tháng trước cách đây
mục cha
commit
23294c2c49

+ 121 - 116
application/api/controller/WorkOrder.php

@@ -1730,55 +1730,6 @@ class WorkOrder extends Api
         $this->success('修改成功');
     }
 
-    /**
-     * 订单BOM出库、退还详情显示
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function FabricDetail()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param) || !isset($param['order'])){
-            $this->error('参数错误');
-        }
-        if (isset($param['searchh']) || !empty($param['search'])){
-            $list['入库记录'] = \db('设备_报工日志')
-                ->where('order_id|款号',$param['order'])
-                ->where('name','入库')
-                ->field('id,order_id as 订单编号,款号,sum(number) as 数量,rq as 入库时间,sys_id as 入库人员,recipient as 入仓人员,receipt_number as 单号')
-                ->group('receipt_number')
-                ->order('入库时间 desc')
-                ->whereNull('Mod_rq')
-                ->select();
-        }else{
-            //出库记录查询
-            $list['出库记录'] = \db('设备_报工日志')
-                ->where('order_id|款号',$param['order'])
-                ->where('name','出库')
-                ->field('id,order_id as 订单编号,款号,sum(number) as 数量,rq as 出库时间,sys_id as 出库人员,receipt_number as 出库单据编号,recipient as 出库人员,receipt_number as 单号')
-                ->group('receipt_number')
-                ->order('出库时间 desc')
-                ->whereNull('Mod_rq')
-                ->select();
-            //退还记录查询
-            $list['退还记录'] = \db('设备_报工日志')
-                ->where('order_id|款号',$param['order'])
-                ->where('name','退还')
-                ->field('id,order_id as 订单编号,款号,sum(number) as 数量,rq as 退还时间,sys_id as 退还机台,recipient as 退还人员,receipt_number as 单号')
-                ->group('receipt_number')
-                ->order('退还时间 desc')
-                ->whereNull('Mod_rq')
-                ->select();
-        }
-
-        $this->success('成功',$list);
-    }
-
     /**
      * 入库、出库、退还详情数据
      */
@@ -1788,66 +1739,71 @@ class WorkOrder extends Api
             $this->error('请求错误');
         }
         $param = $this->request->param();
-        if (empty($param) || !isset($param['order'])){
-            $this->error('参数错误');
+        $where = [];
+        if (isset($param['order']) && !empty($param['order'])){
+            $where['a.order_id'] = $param['order'];
         }
-        // 定义查询字段
-            $fields = '
-                a.id,
-                a.order_id as 订单编号,
-                a.客户编号,
-                a.款号 as 生产款号,
-                a.款式,
-                a.物料名称,
-                b.BOM_计划用量 as 计划用料,
-                b.BOM_标准用量 as 定额用料,
-                b.BOM_计划门幅 as 计划门幅,
-                b.BOM_定额门幅 as 定额门幅,
-                b.BOM_实际用量 as 裁床实际用料,
-                b.Bom_领用数量 as 裁床领用面料,
-                b.BOM_退还数量 as  裁床退还数量,
-                b.BOM_库存总量 as 库存总量,
-                b.BOM_面料结余 as 面料结余,
-                a.number as 入库数量,
-                a.number as 出库数量,
-                b.BOM_投料单位 as 投料单位,
-                a.rq as 入库时间,
-                a.rq as 出库时间,
-                a.sys_id as 入库人员,
-                a.sys_id as 出库人员,
-                a.recipient as 领用人员,
-                a.receipt_number as 单号,
-                b.BOM_desc as 备注
-            ';
-        if (isset($param['searchh']) || !empty($param['search'])){
-            $list['入库记录'] = \db('设备_报工日志')->alias('a')
-                ->join('工单_bom资料 b', 'b.BOM_工单编号 = a.order_id AND a.物料名称 = b.BOM_物料名称', 'left')  // 多条件关联
-                ->where('a.receipt_number', $param['order'])
-                ->where('a.name', '入库')
-                ->field($fields)
-                ->order('a.rq desc')
-                ->whereNull('a.Mod_rq')
-                ->select();
-        }else{
-            //出库记录查询
-            $list['出库记录'] = \db('设备_报工日志')->alias('a')
-                ->join('工单_bom资料 b', 'b.BOM_工单编号 = a.order_id AND a.物料名称 = b.BOM_物料名称', 'left')  // 多条件关联
-                ->where('a.receipt_number', $param['order'])
-                ->where('a.name', '出库')
-                ->field($fields)
-                ->order('a.rq desc')
-                ->whereNull('a.Mod_rq')
-                ->select();
-            //退还记录查询
-            $list['退还记录'] = \db('设备_报工日志')->alias('a')
-                ->join('工单_bom资料 b', 'b.BOM_工单编号 = a.order_id AND a.物料名称 = b.BOM_物料名称', 'left')  // 多条件关联
-                ->where('a.receipt_number', $param['order'])
-                ->where('a.name', '退还')
-                ->field($fields)
-                ->order('a.rq desc')
-                ->whereNull('a.Mod_rq')
-                ->select();
+        if (isset($param['lotNumber']) && !empty($param['lotNumber'])){
+            $where['a.批次号'] = $param['lotNumber'];
         }
+        // 定义查询字段
+        $fields = '
+            a.id,
+            a.批次号,
+            a.order_id as 订单编号,
+            a.客户编号,
+            a.款号 as 生产款号,
+            a.款式,
+            a.物料名称,
+            c.BOM_计划用量 as 计划用料,
+            c.BOM_标准用量 as 定额用料,
+            c.BOM_计划门幅 as 计划门幅,
+            c.BOM_定额门幅 as 定额门幅,
+            b.入仓总量 as 入库总量,
+            b.库存数量 as 面料结余,
+            a.number as 入库数量,
+            a.number as 出库数量,
+            a.库存数量 as 库存数量,
+            b.单位 as 投料单位,
+            a.rq as 入库时间,
+            a.rq as 出库时间,
+            a.sys_id as 入库人员,
+            a.sys_id as 出库人员,
+            a.recipient as 领用人员,
+            a.receipt_number as 单号,
+            c.BOM_desc as 备注
+        ';
+        $list['入库记录'] = \db('设备_报工日志')
+            ->alias('a')
+            ->join('物料_库存 b', 'a.批次号 = b.批次号 AND a.物料编码 = b.物料编号', 'left')  // 多条件关联
+            ->join('工单_面料资料 c','a.order_id = c.BOM_工单编号 AND a.物料编码 = c.BOM_物料编码','left')
+            ->where($where)
+            ->where('a.name', '入库')
+            ->field($fields)
+            ->order('a.rq desc')
+            ->whereNull('a.Mod_rq')
+            ->select();
+
+        //出库记录查询
+        $list['出库记录'] = \db('设备_报工日志')->alias('a')
+            ->join('物料_库存 b', 'a.批次号 = b.批次号 AND a.物料编码 = b.物料编号', 'left')  // 多条件关联
+            ->join('工单_面料资料 c','a.order_id = c.BOM_工单编号 AND a.物料编码 = c.BOM_物料编码','left')
+            ->where($where)
+            ->where('a.name', '出库')
+            ->field($fields)
+            ->order('a.rq desc')
+            ->whereNull('a.Mod_rq')
+            ->select();
+        //退还记录查询
+        $list['退还记录'] = \db('设备_报工日志')->alias('a')
+            ->join('物料_库存 b', 'a.批次号 = b.批次号 AND a.物料编码 = b.物料编号', 'left')  // 多条件关联
+            ->join('工单_面料资料 c','a.order_id = c.BOM_工单编号 AND a.物料编码 = c.BOM_物料编码','left')
+            ->where($where)
+            ->where('a.name', '退还')
+            ->field($fields)
+            ->order('a.rq desc')
+            ->whereNull('a.Mod_rq')
+            ->select();
         $this->success('成功',$list);
     }
 
@@ -1979,20 +1935,18 @@ class WorkOrder extends Api
     public function fabricListmonth()
     {
         // 使用DATE_FORMAT函数提取年月部分,格式为 "YYYY-MM"
-        $list = \db('工单_bom资料')
-            ->alias('a')
-            ->join('工单_基本资料 b', 'b.订单编号 = a.BOM_工单编号')
-            ->field('DATE_FORMAT(a.Sys_rq, "%Y-%m") as date')  // 提取年月,格式化为 "YYYY-MM"
+        $list = \db('物料_库存')
             ->group('date')
             ->order('date desc')
-            ->select();
-
+            ->column('DATE_FORMAT(sys_rq, "%Y-%m") as date');
         // 格式化返回的数据,生成期望的结构
         $result = [];
-        foreach ($list as $item) {
-            $result[] = ['date' => $item['date']];  // 返回格式为 {"date": "YYYY-MM"}
+        foreach ($list as $item){
+            $result[$item] = \db('物料_库存')
+                ->group('date')
+                ->order('date desc')
+                ->column('DATE_FORMAT(sys_rq, "%Y-%m-%d") as date');
         }
-
         if (!empty($result)) {
             $this->success('成功', $result);  // 返回查询到的结果
         } else {
@@ -2263,4 +2217,55 @@ class WorkOrder extends Api
         $this->success('成功', $data);
     }
 
+
+    /**
+     * 面料批次列表
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function FabricLotList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $field = '
+            a.批次号,
+            a.关联号,
+            a.物料编号,
+            a.物料名称,
+            a.入仓总量,
+            a.库存数量,
+            a.领用数量,
+            a.退还数量 as 裁切退还,
+            a.单位,
+            a.实际门幅,
+            a.状态,
+            a.sys_id as 入仓人员,
+            a.sys_rq as 入仓日期,
+            b.BOM_颜色 as 颜色,
+            b.BOM_计划用量 as 计划用料,
+            b.BOM_标准用量 as 定额用料,
+            b.BOM_计划门幅 as 计划门幅,
+            b.BOM_定额门幅 as 定额门幅,
+            GROUP_CONCAT(DISTINCT c.订单编号 SEPARATOR ",") AS 关联订单
+        ';
+        $list = \db('物料_库存')
+            ->alias('a')
+            ->join('工单_面料资料 b','a.物料编号 = b.BOM_物料编码')
+            ->join('工单关联表 c','a.关联号 = c.关联编号')
+            ->field($field)
+            ->where('a.sys_rq','like',$param['date'].'%')
+            ->select();
+        if (empty($list)){
+            $this->error('未找到面料数据');
+        }else{
+            $this->success('成功',$list);
+        }
+    }
 }

+ 73 - 0
application/api/controller/WorkOrderSpotCheck.php

@@ -2830,6 +2830,7 @@ class WorkOrderSpotCheck extends Api{
         unset($ReportData['关联编号']);
         $ReportData['批次号'] = $param['批次号'];
         $ReportData['rq'] = date('Y-m-d H:i:s',time());
+        $ReportData['库存数量'] = $InventoryData['库存数量'];
         //创建事务,存储库存表数据和入库报工表数据
         Db::startTrans();
         try {
@@ -2934,6 +2935,7 @@ class WorkOrderSpotCheck extends Api{
             unset($ReportData['实际门幅']);
             $ReportData['批次号'] = $BatchNumber[0];
             $ReportData['rq'] = date('Y-m-d H:i:s',time());
+            $ReportData['库存数量'] = $InventoryData['库存数量'];
             //创建事务,存储库存表数据和入库报工表数据
             db()->startTrans();
             try {
@@ -2968,6 +2970,7 @@ class WorkOrderSpotCheck extends Api{
             unset($ReportData['实际门幅']);
             $ReportData['批次号'] = $BatchNumber[0];
             $ReportData['rq'] = date('Y-m-d H:i:s',time());
+            $ReportData['库存数量'] = $InventoryData['库存数量'];
             //创建事务,存储库存表数据和入库报工表数据
             \db()->startTrans();
             try {
@@ -3054,4 +3057,74 @@ class WorkOrderSpotCheck extends Api{
         $list['关联订单'] = $orderList[0];
         $this->success('成功',$list);
     }
+
+    /**
+     * 裁剪面料退货包工
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function TuihuoReport()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        //搜索批次号库存表中中数据
+        $number = \db('物料_库存')
+            ->where('批次号',$param['批次号'])
+            ->where('关联号',$param['关联编号'])
+            ->where('物料编号',$param['物料编码'])
+            ->field('库存数量,退还数量')
+            ->find();
+        //构建库存表数据
+        $InventoryData = [
+            '退还数量' => $number['退还数量'] + (int)$param['number'],
+            '库存数量' => $number['库存数量'] + (int)$param['number'],
+        ];
+        $ReportData = $param;
+        unset($ReportData['关联编号']);
+        unset($ReportData['实际门幅']);
+        $ReportData['批次号'] = $param['批次号'];
+        $ReportData['rq'] = date('Y-m-d H:i:s',time());
+        $ReportData['库存数量'] = $InventoryData['库存数量'];
+        //创建事务,存储库存表数据和入库报工表数据
+        db()->startTrans();
+        try {
+            //存储库存表数据
+            $InventorySql = \db('物料_库存')
+                ->where('批次号',$param['批次号'])
+                ->where('关联号',$param['关联编号'])
+                ->where('物料编号',$param['物料编码'])
+                ->fetchSql(true)
+                ->update($InventoryData);
+            \db()->query($InventorySql);
+            //存储入库报工表数据
+            $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
+            \db()->query($ReportSql);
+
+            //提交事务
+            \db()->commit();
+        }catch (\Exception $e){
+            \db()->rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('成功');
+    }
+
+
+    //面料批次左侧菜单栏
+//    public function GetFabricTab()
+//    {
+//        if ($this->request->isGet() === false){
+//            $this->error('请求错误');
+//        }
+//        $mouth = \db('物料_库存')
+//            ->column('')
+//    }
 }