cqp 2 mēneši atpakaļ
vecāks
revīzija
95d8500c70
2 mainītis faili ar 199 papildinājumiem un 58 dzēšanām
  1. 1 0
      app/Http/Middleware/CheckLogin.php
  2. 198 58
      app/Service/U8ServerService.php

+ 1 - 0
app/Http/Middleware/CheckLogin.php

@@ -32,6 +32,7 @@ class CheckLogin
         if(empty($user)) return response()->json(['code'=>1,'msg'=>'登录信息不存在或错误','data'=>null]);
         $user = $user->toArray();
         $loginUser['qx'] = $user['qx'];
+        $loginUser = $user;
 
         //数据库账套
         $config = config("u8_database.{$LoginType}");

+ 198 - 58
app/Service/U8ServerService.php

@@ -37,6 +37,7 @@ class U8ServerService extends Service
     {
         return $this->error;
     }
+
     public function purchaseOrder($data, $user){
         $qx = $user['qx'];
         $order_date = $data['order_date'] ?? [];
@@ -44,29 +45,45 @@ class U8ServerService extends Service
         $order_number = $data['order_number'] ?? "";
 
         $model = $this->databaseService->table('PO_Pomain as a')
-            ->leftJoin('Vendor as c', 'c.cVenCode', 'a.cVenCode')
+            ->leftJoin('Vendor as c', 'c.cVenCode', 'a.cVenCode')      // 供应商
+            ->leftJoin('Department as d', 'd.cDepCode', 'a.cDepCode')  // 部门
+            ->leftJoin('Person as e', 'e.cPersonCode', 'a.cPersonCode')// 业务员
+            ->leftJoin('PurchaseType as f', 'f.cPTCode', 'a.cPTCode')  // 采购类型
             ->when(empty($qx), function ($query) use($user){
-                return $query->where('a.cMaker',$user['username']);
+                return $query->where('a.cMaker', $user['username']);
             })
-            ->when(! empty($order_number), function ($query) use($order_number){
-                return $query->where('a.cPOID','LIKE', '%'.$order_number.'%');
+            ->when(!empty($order_number), function ($query) use($order_number){
+                return $query->where('a.cPOID', 'LIKE', '%'.$order_number.'%');
             })
-            ->when(! empty($order_date), function ($query) use($order_date){
-                $start = date('Y-m-d H:i:s.000', $order_date[0]);
-                $end = date('Y-m-d H:i:s.000', $order_date[1]);
+            ->when(!empty($order_date), function ($query) use($order_date){
+                $start = date('Y-m-d 00:00:00.000', $order_date[0]);
+                $end = date('Y-m-d 23:59:59.000', $order_date[1]);
                 return $query->whereBetween('a.dPODate', [$start, $end]);
             })
             ->where(function ($query) {
                 $query->where('a.iverifystateex', 0)
-                    ->OrwhereNull('a.iverifystateex');
+                    ->orWhereNull('a.iverifystateex');
             })
-            ->select('a.cMaker as crt_name', 'a.cBusType as business_type','a.cPOID as order_number',DB::raw("CONVERT(varchar(10), a.dPODate, 120) as order_date"),'c.cVenName as supplier_title')
-            ->orderBy('a.POID','desc');
+            ->select(
+                DB::raw("ISNULL(a.cBusType, '') as business_type"),      // 业务类型
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dPODate, 120), '') as order_date"), // 订单日期
+                DB::raw("ISNULL(a.cPOID, '') as order_number"),          // 订单编号
+                DB::raw("ISNULL(f.cPTName, '') as purchase_type"),       // 采购类型
+                DB::raw("ISNULL(c.cVenName, '') as supplier_title"),     // 供应商
+                DB::raw("ISNULL(d.cDepName, '') as department_name"),    // 部门
+                DB::raw("ISNULL(e.cPersonName, '') as person_name"),     // 业务员
+                DB::raw("CAST(ISNULL(a.iTaxRate, 0) AS varchar) as tax_rate"), // 税率(数值转字符,null转0或空)
+                DB::raw("ISNULL(a.cexch_name, '') as currency_name"),    // 币种
+                DB::raw("CAST(ISNULL(a.nflat, 0) AS varchar) as exchange_rate"), // 汇率
+                DB::raw("ISNULL(a.cMemo, '') as remark"),                // 备注
+                DB::raw("ISNULL(a.cMaker, '') as crt_name")              // 制单人
+            )
+            ->orderBy('a.POID', 'desc');
 
-        $list = $this->limit($model,'',$data);
+        $list = $this->limit($model, '', $data);
         $list = $this->fillAll($list, 1, $user['login_type']);
 
-        return [true , $list];
+        return [true, $list];
     }
 
     public function purchaseOrderDetail($data, $user){
@@ -74,25 +91,59 @@ class U8ServerService extends Service
 
         $order = $this->databaseService->table('PO_Pomain as a')
             ->leftJoin('Vendor as c', 'c.cVenCode', 'a.cVenCode')
-            ->where('cPOID', $data['order_number'])
-//            ->where('a.cMaker',$user['username'])
-//            ->where('a.iverifystateex',0)
-            ->select('a.cMaker as crt_name', 'a.cBusType as business_type','a.cPOID as order_number',DB::raw("CONVERT(varchar(10), a.dPODate, 120) as order_date"),'c.cVenName as supplier_title','a.POID as id')
+            ->leftJoin('Department as d', 'd.cDepCode', 'a.cDepCode')
+            ->leftJoin('Person as e', 'e.cPersonCode', 'a.cPersonCode')
+            ->leftJoin('PurchaseType as f', 'f.cPTCode', 'a.cPTCode')
+            ->where('a.cPOID', $data['order_number'])
+            ->select(
+                'a.POID',
+                DB::raw("ISNULL(a.cBusType, '') as business_type"),
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dPODate, 120), '') as order_date"),
+                DB::raw("ISNULL(a.cPOID, '') as order_number"),
+                DB::raw("ISNULL(f.cPTName, '') as purchase_type"),
+                DB::raw("ISNULL(c.cVenName, '') as supplier_title"),
+                DB::raw("ISNULL(d.cDepName, '') as department_name"),
+                DB::raw("ISNULL(e.cPersonName, '') as person_name"),
+                DB::raw("CAST(ISNULL(a.iTaxRate, 0) AS varchar) as tax_rate"),
+                DB::raw("ISNULL(a.cexch_name, '') as currency_name"),
+                DB::raw("CAST(ISNULL(a.nflat, 0) AS varchar) as exchange_rate"),
+                DB::raw("ISNULL(a.cMemo, '') as remark"),
+                DB::raw("ISNULL(a.cMaker, '') as crt_name")
+            )
             ->first();
+
         if(empty($order)) return [false, '采购单不存在'];
         $order = (array) $order;
 
+        // 获取明细
         $detail = $this->databaseService->table('PO_Podetails as a')
             ->leftJoin('Inventory as b', 'b.cInvCode', 'a.cInvCode')
             ->leftJoin('ComputationUnit as c', 'c.cComunitCode', 'b.cComUnitCode')
-            ->where('a.POID', $order['id'])
-            ->select('b.cInvName as product_title','b.cInvCode as product_code','c.cComUnitName as unit_title',DB::raw("LTRIM(STR(a.iQuantity, 20, 2)) as quantity"),DB::raw("LTRIM(STR(a.iSum, 20, 2)) as amount"))
+            ->where('a.POID', $order['POID'])
+            ->select(
+                DB::raw("ISNULL(b.cInvCode, '') as product_code"),
+                DB::raw("ISNULL(b.cInvName, '') as product_title"),
+                DB::raw("ISNULL(b.cInvStd, '') as product_std"),
+                DB::raw("ISNULL(c.cComUnitName, '') as unit_title"),
+                // 数字转字符串并去除空格,NULL 则返回 '0.00' 或 ''
+                DB::raw("ISNULL(LTRIM(STR(a.iQuantity, 20, 2)), '0.00') as quantity"),
+                DB::raw("ISNULL(LTRIM(STR(a.iTaxPrice, 20, 4)), '0.0000') as tax_unit_price"),
+                DB::raw("ISNULL(LTRIM(STR(a.iUnitPrice, 20, 4)), '0.0000') as unit_price"),
+                DB::raw("ISNULL(LTRIM(STR(a.iMoney, 20, 2)), '0.00') as amount"),
+                DB::raw("ISNULL(LTRIM(STR(a.iSum, 20, 2)), '0.00') as tax_amount"),
+                DB::raw("ISNULL(LTRIM(STR(a.iPerTaxRate, 20, 2)), '0.00') as tax_rate"),
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dArriveDate, 120), '') as arrive_date"),
+                DB::raw("ISNULL(b.cEnterprise, '') as factory_name")
+            )
             ->get();
-        // 转为数组的数组
-        $detail = array_map(function ($item) {
+
+        // 转为数组
+        $order['detail'] = $detail->map(function ($item) {
             return (array) $item;
-        }, $detail->toArray());
-        $order['detail'] = $detail;
+        })->toArray();
+
+        // 移除内部 ID 避免暴露
+        unset($order['POID']);
 
         return [true, $order];
     }
@@ -104,7 +155,9 @@ class U8ServerService extends Service
         $order_number = $data['order_number'] ?? "";
 
         $model = $this->databaseService->table('PU_AppVouch as a')
-            ->leftJoin('Person as c', 'c.cPersonCode', 'a.cPersonCode')
+            ->leftJoin('Person as c', 'c.cPersonCode', 'a.cPersonCode') // 请购人
+            ->leftJoin('Department as d', 'd.cDepCode', 'a.cDepCode')  // 请购部门
+            ->leftJoin('PurchaseType as f', 'f.cPTCode', 'a.cPTCode')  // 采购类型
             ->when(empty($qx), function ($query) use($user){
                 return $query->where('a.cMaker',$user['username']);
             })
@@ -112,21 +165,29 @@ class U8ServerService extends Service
                 return $query->where('a.cCode','LIKE', '%'.$order_number.'%');
             })
             ->when(! empty($order_date), function ($query) use($order_date){
-                $start = date('Y-m-d H:i:s.000', $order_date[0]);
-                $end = date('Y-m-d H:i:s.000', $order_date[1]);
+                $start = date('Y-m-d 00:00:00.000', $order_date[0]);
+                $end = date('Y-m-d 23:59:59.000', $order_date[1]);
                 return $query->whereBetween('a.dDate', [$start, $end]);
             })
             ->where(function ($query) {
                 $query->where('a.iverifystateex', 0)
-                    ->OrwhereNull('a.iverifystateex');
+                    ->orWhereNull('a.iverifystateex');
             })
-            ->select('a.cMaker as crt_name', DB::raw("COALESCE(c.cPersonName, '') as purchase_name"),'a.cBusType as business_type','a.cCode as order_number',DB::raw("CONVERT(varchar(10), a.dDate, 120) as order_date"))
+            ->select(
+                DB::raw("ISNULL(a.cBusType, '') as business_type"),      // 业务类型
+                DB::raw("ISNULL(a.cCode, '') as order_number"),          // 单据号
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dDate, 120), '') as order_date"), // 日期
+                DB::raw("ISNULL(d.cDepName, '') as department_name"),    // 请购部门
+                DB::raw("ISNULL(c.cPersonName, '') as purchase_name"),   // 请购人员
+                DB::raw("ISNULL(f.cPTName, '') as purchase_type"),       // 采购类型
+                DB::raw("ISNULL(a.cMaker, '') as crt_name")              // 制单人
+            )
             ->orderBy('a.ID','desc');
 
         $list = $this->limit($model,'',$data);
         $list = $this->fillAll($list, 2, $user['login_type']);
 
-       return [true , $list];
+        return [true , $list];
     }
 
     public function purchaseRequisitionDetail($data, $user){
@@ -134,25 +195,48 @@ class U8ServerService extends Service
 
         $order = $this->databaseService->table('PU_AppVouch as a')
             ->leftJoin('Person as c', 'c.cPersonCode', 'a.cPersonCode')
-//            ->where('a.cMaker',$user['username'])
-//            ->where('a.iverifystateex',0)
-            ->where('cCode', $data['order_number'])
-            ->select('a.cMaker as crt_name', DB::raw("COALESCE(c.cPersonName, '') as purchase_name"),'a.cBusType as business_type','a.cCode as order_number',DB::raw("CONVERT(varchar(10), a.dDate, 120) as order_date"),'a.ID as id')
+            ->leftJoin('Department as d', 'd.cDepCode', 'a.cDepCode')
+            ->leftJoin('PurchaseType as f', 'f.cPTCode', 'a.cPTCode')
+            ->where('a.cCode', $data['order_number'])
+            ->select(
+                'a.ID', // 用于关联子表
+                DB::raw("ISNULL(a.cBusType, '') as business_type"),
+                DB::raw("ISNULL(a.cCode, '') as order_number"),
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dDate, 120), '') as order_date"),
+                DB::raw("ISNULL(d.cDepName, '') as department_name"),
+                DB::raw("ISNULL(c.cPersonName, '') as purchase_name"),
+                DB::raw("ISNULL(f.cPTName, '') as purchase_type"),
+                DB::raw("ISNULL(a.cMaker, '') as crt_name")
+            )
             ->first();
+
         if(empty($order)) return [false, '采购请购单不存在'];
         $order = (array) $order;
 
         $detail = $this->databaseService->table('PU_AppVouchs as a')
             ->leftJoin('Inventory as b', 'b.cInvCode', 'a.cInvCode')
             ->leftJoin('ComputationUnit as c', 'c.cComunitCode', 'b.cComUnitCode')
-            ->where('a.ID', $order['id'])
-            ->select('b.cInvName as product_title','b.cInvCode as product_code','c.cComUnitName as unit_title',DB::raw("CONVERT(varchar(10), a.dRequirDate, 120) as need_arrived_date"),DB::raw("LTRIM(STR(a.fQuantity, 20, 2)) as quantity"))
+            ->where('a.ID', $order['ID'])
+            ->select(
+                DB::raw("ISNULL(b.cInvCode, '') as product_code"),    // 存货编码
+                DB::raw("ISNULL(b.cInvName, '') as product_title"),   // 存货名称
+                DB::raw("ISNULL(b.cInvStd, '') as product_std"),      // 规格型号
+                DB::raw("ISNULL(c.cComUnitName, '') as unit_title"),  // 主计量
+                DB::raw("ISNULL(LTRIM(STR(a.fQuantity, 20, 2)), '0.00') as quantity"), // 数量
+                DB::raw("ISNULL(LTRIM(STR(a.fUnitPrice, 20, 4)), '0.0000') as unit_price"), // 本币单价
+                DB::raw("ISNULL(LTRIM(STR(a.iOriSum, 20, 2)), '0.00') as tax_amount"), // 本币价税合计
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dRequirDate, 120), '') as need_arrived_date"), // 需求日期
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dArriveDate, 120), '') as suggest_order_date"), // 建议订货日期
+                DB::raw("ISNULL(b.cEnterprise, '') as factory_name") // 生产企业
+            )
             ->get();
-        // 转为数组的数组
-        $detail = array_map(function ($item) {
+
+        // 转为数组格式
+        $order['detail'] = $detail->map(function ($item) {
             return (array) $item;
-        }, $detail->toArray());
-        $order['detail'] = $detail;
+        })->toArray();
+
+        unset($order['ID']); // 隐藏内部ID
 
         return [true, $order];
     }
@@ -164,7 +248,12 @@ class U8ServerService extends Service
         $order_number = $data['order_number'] ?? "";
 
         $model = $this->databaseService->table('RdRecord01 as a')
-            ->leftJoin('Vendor as c', 'c.cVenCode', 'a.cVenCode')
+            ->leftJoin('Vendor as c', 'c.cVenCode', 'a.cVenCode')      // 供货单位
+            ->leftJoin('Warehouse as w', 'w.cWhCode', 'a.cWhCode')    // 仓库
+            ->leftJoin('Department as d', 'd.cDepCode', 'a.cDepCode')  // 部门
+            ->leftJoin('Person as p', 'p.cPersonCode', 'a.cPersonCode')// 业务员
+            ->leftJoin('PurchaseType as pt', 'pt.cPTCode', 'a.cPTCode')// 采购类型
+            ->leftJoin('Rd_Style as rs', 'rs.cRdCode', 'a.cRdCode')   // 入库类别
             ->when(empty($qx), function ($query) use($user){
                 return $query->where('a.cMaker',$user['username']);
             })
@@ -172,12 +261,28 @@ class U8ServerService extends Service
                 return $query->where('a.cCode','LIKE', '%'.$order_number.'%');
             })
             ->when(! empty($order_date), function ($query) use($order_date){
-                $start = date('Y-m-d H:i:s.000', $order_date[0]);
-                $end = date('Y-m-d H:i:s.000', $order_date[1]);
+                $start = date('Y-m-d 00:00:00.000', $order_date[0] / 1000);
+                $end = date('Y-m-d 23:59:59.000', $order_date[1] / 1000);
                 return $query->whereBetween('a.dDate', [$start, $end]);
             })
-            ->whereNull('a.cHandler')
-            ->select('a.cMaker as crt_name', 'c.cVenName as supplier_title','a.cCode as order_number',DB::raw("CONVERT(varchar(10), a.dDate, 120) as order_date"))
+            ->whereNull('a.cHandler') // 未审核
+            ->select(
+                DB::raw("ISNULL(a.cCode, '') as order_number"),           // 入库单号
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dDate, 120), '') as order_date"), // 入库日期
+                DB::raw("ISNULL(w.cWhName, '') as warehouse_name"),       // 仓库
+                DB::raw("ISNULL(a.cOrderCode, '') as po_number"),         // 订单号
+                DB::raw("ISNULL(a.cARVCode, '') as arrival_number"),      // 到货单号
+                DB::raw("ISNULL(p.cPersonName, '') as person_name"),      // 业务员
+                DB::raw("ISNULL(c.cVenName, '') as supplier_title"),      // 供货单位
+                DB::raw("ISNULL(d.cDepName, '') as department_name"),     // 部门
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dARVDate, 120), '') as arrival_date"), // 到货日期
+                DB::raw("ISNULL(a.cBusType, '') as business_type"),       // 业务类型
+                DB::raw("ISNULL(pt.cPTName, '') as purchase_type"),       // 采购类型
+                DB::raw("ISNULL(rs.cRdName, '') as rd_style_name"),       // 入库类别
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dVeriDate, 120), '') as audit_date"), // 审核日期
+                DB::raw("ISNULL(a.cMemo, '') as remark"),                 // 备注
+                DB::raw("ISNULL(a.cMaker, '') as crt_name")               // 制单人
+            )
             ->orderBy('a.ID','desc');
 
         $list = $this->limit($model,'',$data);
@@ -187,31 +292,66 @@ class U8ServerService extends Service
     }
 
     public function purchaseInOrderDetail($data, $user){
-        if(empty($data['order_number'])) return [false, '付款申请单号不能为空'];
+        if(empty($data['order_number'])) return [false, '入库单号不能为空'];
 
         $order = $this->databaseService->table('RdRecord01 as a')
             ->leftJoin('Vendor as c', 'c.cVenCode', 'a.cVenCode')
-//            ->where('a.cOperator',$user['username'])
-//            ->whereNull('a.cCheckMan')
-            ->where('cCode', $data['order_number'])
-            ->select('a.cMaker as crt_name', 'c.cVenName as supplier_title','a.cCode as order_number',DB::raw("CONVERT(varchar(10), a.dDate, 120) as order_date"))
+            ->leftJoin('Warehouse as w', 'w.cWhCode', 'a.cWhCode')
+            ->leftJoin('Department as d', 'd.cDepCode', 'a.cDepCode')
+            ->leftJoin('Person as p', 'p.cPersonCode', 'a.cPersonCode')
+            ->leftJoin('PurchaseType as pt', 'pt.cPTCode', 'a.cPTCode')
+            ->leftJoin('Rd_Style as rs', 'rs.cRdCode', 'a.cRdCode')
+            ->where('a.cCode', $data['order_number'])
+            ->select(
+                'a.ID',
+                DB::raw("ISNULL(a.cCode, '') as order_number"),
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dDate, 120), '') as order_date"),
+                DB::raw("ISNULL(w.cWhName, '') as warehouse_name"),
+                DB::raw("ISNULL(a.cOrderCode, '') as po_number"),
+                DB::raw("ISNULL(a.cARVCode, '') as arrival_number"),
+                DB::raw("ISNULL(p.cPersonName, '') as person_name"),
+                DB::raw("ISNULL(c.cVenName, '') as supplier_title"),
+                DB::raw("ISNULL(d.cDepName, '') as department_name"),
+                DB::raw("ISNULL(CONVERT(varchar(10), a.darvdate, 120), '') as arrival_date"),
+                DB::raw("ISNULL(a.cBusType, '') as business_type"),
+                DB::raw("ISNULL(pt.cPTName, '') as purchase_type"),
+                DB::raw("ISNULL(rs.cRdName, '') as rd_style_name"),
+                DB::raw("ISNULL(CONVERT(varchar(10), a.dVeriDate, 120), '') as audit_date"),
+                DB::raw("ISNULL(a.cMemo, '') as remark"),
+                DB::raw("ISNULL(a.cMaker, '') as crt_name")
+            )
             ->first();
+
         if(empty($order)) return [false, '采购入库单不存在'];
         $order = (array) $order;
 
-        $detail = $this->databaseService->table('RdRecords01 as a')
+        $detail = $this->databaseService->table('rdrecords01 as a')
             ->leftJoin('Inventory as b', 'b.cInvCode', 'a.cInvCode')
             ->leftJoin('ComputationUnit as c', 'c.cComunitCode', 'b.cComUnitCode')
-            ->where('a.ID', $order['id'])
-            ->select('b.cInvName as product_title','c.cComUnitName as unit_title')
+            ->where('a.ID', $order['ID'])
+            ->select(
+                DB::raw("ISNULL(b.cInvCode, '') as product_code"),    // 存货编码
+                DB::raw("ISNULL(b.cInvName, '') as product_title"),   // 存货名称
+                DB::raw("ISNULL(b.cInvStd, '') as product_std"),      // 规格型号
+                DB::raw("ISNULL(c.cComUnitName, '') as unit_title"),  // 主计量单位
+                DB::raw("ISNULL(LTRIM(STR(a.iQuantity, 20, 2)), '0.00') as quantity"), // 数量
+                DB::raw("ISNULL(LTRIM(STR(a.iUnitCost, 20, 4)), '0.0000') as unit_price"), // 本币单价
+                DB::raw("ISNULL(LTRIM(STR(a.iPrice, 20, 2)), '0.00') as amount"), // 本币金额
+                DB::raw("ISNULL(LTRIM(STR(a.iTax, 20, 2)), '0.00') as tax"), // 税额
+                DB::raw("ISNULL(LTRIM(STR(a.iTaxPrice, 20, 2)), '0.00') as nat_tax"), // 本币税额 (入库单本币税额通常等于原币税额)
+                DB::raw("ISNULL(LTRIM(STR(a.iSum, 20, 2)), '0.00') as tax_amount") // 本币价税合计
+            )
             ->get();
-        // 转为数组的数组
-        $detail = array_map(function ($item) {
+
+        $detailArr = $detail->map(function ($item) {
             return (array) $item;
-        }, $detail->toArray());
-        // 使用 array_column 提取所有 amount 并求和
-        $order['total_amount'] = number_format(array_sum(array_column($detail, 'amount')), 2, '.', '');
-        $order['detail'] = $detail;
+        })->toArray();
+
+        // 计算总金额(价税合计之和)
+        $order['total_amount'] = number_format(array_sum(array_column($detailArr, 'tax_amount')), 2, '.', '');
+        $order['detail'] = $detailArr;
+
+        unset($order['ID']);
 
         return [true, $order];
     }
@@ -246,7 +386,7 @@ class U8ServerService extends Service
             // 采购单
             [$success, $order] = $this->purchaseOrderDetail($data,$user);
         }elseif ($type == 2){
-            // 请购单
+            // 采购请购单
             [$success, $order] = $this->purchaseRequisitionDetail($data,$user);
         }elseif ($type == 3){
             // 采购入库