cqp 2 meses atrás
pai
commit
c9994fb330

+ 1 - 1
app/Model/AuxiliaryAccount.php

@@ -4,7 +4,7 @@ namespace App\Model;
 
 class AuxiliaryAccount extends DataScopeBaseModel
 {
-    //设备日工时
+    //研发支出辅助帐
     protected $table = "auxiliary_account"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';

+ 36 - 27
app/Service/AuxiliaryAccountService.php

@@ -4,21 +4,14 @@ namespace App\Service;
 
 use App\Model\AuxiliaryAccount;
 use App\Model\AuxiliaryAccountDetails;
-use App\Model\CalendarDetails;
-use App\Model\Device;
 use App\Model\Employee;
 use App\Model\ExpenseClaims;
 use App\Model\ExpenseClaimsDetails;
 use App\Model\Fee;
-use App\Model\Item;
-use App\Model\ItemDetails;
 use App\Model\MonthlyDdOrder;
 use App\Model\MonthlyDdOrderDetails;
 use App\Model\MonthlyPsOrder;
 use App\Model\MonthlyPsOrderDetails;
-use App\Model\MonthlyPwOrderDetails;
-use App\Model\RuleSet;
-use App\Model\RuleSetDetails;
 use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 
@@ -31,20 +24,19 @@ class AuxiliaryAccountService extends Service
 
         return [true, $list];
     }
-    //
 
-    private function setCommon($data,$user, $field = []){
+    public function setCommon($data,$user, $field = []){
         if(empty($field)) $field = AuxiliaryAccount::$field;
-        $data['top_depart_id'] = $user['top_depart_id'];
         $model = AuxiliaryAccount::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select($field)
             ->orderby('month', 'desc');
         if(! empty($data['month'])) $model->where('month', $data['month']);
         if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
-        return $model;
 
+        return $model;
     }
+
     public function fillData($data){
         if(empty($data['data'])) return $data;
 
@@ -55,6 +47,7 @@ class AuxiliaryAccountService extends Service
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['month'] =  $value['month'] ? date('Y-m',$value['month']) : '';
         }
+
         return $data;
     }
 
@@ -122,6 +115,7 @@ class AuxiliaryAccountService extends Service
             "total_amount" => $total_amount,
         ]];
     }
+
     private  function feeMonthAmount($month,$user,$monthStart,$monthEnd){
         $data['top_depart_id'] = $user['top_depart_id'];
         $month_ps_order = ExpenseClaims::Clear($user,$data);
@@ -136,8 +130,8 @@ class AuxiliaryAccountService extends Service
         $list = $model->where('expense_claims_id',$month_ps_order_id)->select("fee_id","amount as total_amount","remark","entrust_type","item_id")->get()->toArray();
         ///分组
         $fee_type_list = Fee::Clear($user,$data)->where('del_time',0)->select("title","id","parent_id")->get()->toArray();
-        return [true,$this->groupListByRoot($list,$fee_type_list)];
 
+        return [true,$this->groupListByRoot($list,$fee_type_list)];
     }
 
     /**
@@ -197,7 +191,7 @@ class AuxiliaryAccountService extends Service
     public function auxiliaryAccountAdd($data,$user){
         list($status,$msg) = $this->auxiliaryAccountRule($data, $user);
         if(!$status) return [$status,$msg];
-        //费用报销结构
+
         try {
             DB::beginTransaction();
 
@@ -207,11 +201,10 @@ class AuxiliaryAccountService extends Service
                 'type' => ExpenseClaims::Order_type,
                 'period' => date("Ym", strtotime($data['month']))
             ]);
-            $model->month = strtotime($data['month']);
+            $model->month = $data['month'];
             $model->crt_id = $user['id'];
             $model->top_depart_id = $user['top_depart_id'];
             $model->save();
-            $data['top_depart_id'] = $user['top_depart_id'];
             $this->saveDetail($model->id, time(), $data,$user['id']);
 
             DB::commit();
@@ -222,6 +215,7 @@ class AuxiliaryAccountService extends Service
 
         return [true, ''];
     }
+
     private function saveDetail($id, $time, $data,$crt_id){
         if(! empty($data['details'])){
             $unit = [];
@@ -251,12 +245,12 @@ class AuxiliaryAccountService extends Service
         }
     }
 
-    private function auxiliaryAccountRule($data,$user){
-        if(!isset($data['month'])) return [false,"月份必传"];
-        $monthStr = $data['month']; // 假设是 "2026-03"
-        $monthStart = strtotime($monthStr); // 2026-03-01 00:00:00
-        // 获取该月最后一秒:下个月 1 号减去 1 秒
-        $monthEnd = strtotime("$monthStr +1 month") - 1;
+    private function auxiliaryAccountRule(&$data, $user, $is_add = true){
+        if (empty($data['month'])) return [false, '月份不能为空'];
+        $data['month'] = $this->changeDateToDate($data['month']);
+        $monthStart = $data['month'];
+        $monthEnd = strtotime('+1 month', $monthStart) - 1;
+        if(empty($data['details'])) return [false, '研发支出辅助账单明细不能为空'];
         foreach ($data['details'] as $index => $item) {
             if (!isset($item['voucher_date'])) {
                 return [false, "第" . ($index + 1) . "凭证日期缺失"];
@@ -267,12 +261,17 @@ class AuxiliaryAccountService extends Service
             if (!isset($item['voucher_amount'])) {
                 return [false, "第" . ($index + 1) . "凭证记载金额缺失"];
             }
+            $res = $this->checkNumber($item['voucher_amount'], 2, 'non-negative');
+            if (! $res['valid']) return [false,  "第" . ($index + 1) . "凭证记载金额" . $res['error']];
+
             if (!isset($item['voucher_type'])) {
                 return [false, "第" . ($index + 1) . "凭证类型缺失"];
             }
             if (!isset($item['aggregation_amount'])) {
                 return [false, "第" . ($index + 1) . "凭证归集金额缺失"];
             }
+            $res = $this->checkNumber($item['aggregation_amount'], 2, 'non-negative');
+            if (! $res['valid']) return [false,  "第" . ($index + 1) . "凭证归集金额" . $res['error']];
             if (!isset($item['voucher_remark'])) {
                 return [false, "第" . ($index + 1) . "凭证摘要缺失"];
             }
@@ -280,11 +279,21 @@ class AuxiliaryAccountService extends Service
             $claimTime = strtotime($item['voucher_date']);
             // 判断:voucher_date 必须早于 month
             // 如果 voucher_date 是 2026-02-28,而 month 是 2026-03-01,则校验通过
-            if ($claimTime < $monthStart || $claimTime > $monthEnd) {
-                return [false, "第" . ($index + 1) . "凭证日期必须早于当前结算月份(" . $data['month'] . ")"];
-            }
+            if ($claimTime < $monthStart || $claimTime > $monthEnd) return [false, "第" . ($index + 1) . "凭证日期必须早于当前结算月份(" . $data['month'] . ")"];
+        }
+
+        $query = AuxiliaryAccount::where('top_depart_id', $data['top_depart_id'])
+            ->where('month', $monthStart)
+            ->where('del_time', 0);
+
+        if (!$is_add) {
+            if (empty($data['id'])) return [false, 'ID不能为空'];
+            $query->where('id', '<>', $data['id']);
         }
-        return [true,""];
+
+        if ($query->exists())  return [false, date("Y-m", $monthStart) . '已存在研发支出辅助账单'];
+
+        return [true, ''];
     }
 
     public function auxiliaryAccountEdit($data,$user){
@@ -295,13 +304,13 @@ class AuxiliaryAccountService extends Service
             DB::beginTransaction();
 
             $model = AuxiliaryAccount::where('id',$data['id'])->first();
-            //不允许修改头部
 //            $model->save();
+
             $time = time();
             AuxiliaryAccountDetails::where('del_time',0)
                 ->where('auxiliary_account_id', $model->id)
                 ->update(['del_time' => $time]);
-            $data['top_depart_id'] = $user['top_depart_id'];
+
             $this->saveDetail($model->id, $time, $data,$user['id']);
 
             DB::commit();