|
|
@@ -7,9 +7,11 @@ use App\Model\DailyDwOrderDetails;
|
|
|
use App\Model\DailyPwOrderDetails;
|
|
|
use App\Model\Device;
|
|
|
use App\Model\Employee;
|
|
|
+use App\Model\EmployeeDepartPermission;
|
|
|
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;
|
|
|
@@ -915,4 +917,133 @@ class StatisticService extends StatisticCommonService
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public function enterpriseRdStatistic($data, $user){
|
|
|
+ $model = Item::TopClear($user,$data);
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
+ ->select(Item::$report_field_1)
|
|
|
+ ->orderby('id', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
|
|
|
+ if(! empty($data['state'])) $model->where('state', $data['state']);
|
|
|
+
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ $list = $this->fillEnterpriseRdStatistic($list, $data, $user);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function fillEnterpriseRdStatistic($list, $data, $user){
|
|
|
+ //项目实际支出 项目费用单
|
|
|
+ $expense = ExpenseClaimsDetails::Clear($user, $data);
|
|
|
+ $expense_map = $expense->where('del_time', 0)
|
|
|
+ ->whereIn('item_id', array_unique(array_column($list,'id')))
|
|
|
+ ->selectRaw('item_id, SUM(amount) as total_amount')
|
|
|
+ ->groupBy('item_id')
|
|
|
+ ->pluck('total_amount', 'item_id') // 这一步直接生成 item_id => total_amount 结构
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ foreach ($list as $key => $value){
|
|
|
+ $list[$key]['actual_expenditure'] = $expense_map[$value['id']] ?? 0;
|
|
|
+ $start_time = $value['start_time'] ? date('Y-m-d', $value['start_time']) : '';
|
|
|
+ $end_time = $value['end_time'] ? date('Y-m-d', $value['end_time']) : '';
|
|
|
+ $list[$key]['time_range'] = $start_time . ' ' . $end_time;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function enterpriseRdManStatistic($data, $user){
|
|
|
+ $model = Employee::TopClear($user,$data);
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
+ ->where('is_admin', '<=', Employee::IS_ADMIN_ONE)
|
|
|
+ ->select(Employee::$report_field)
|
|
|
+ ->orderBy('id','desc');
|
|
|
+
|
|
|
+ if(! empty($data['id_card'])) $model->where('id_card', 'LIKE', '%'.$data['id_card'].'%');
|
|
|
+ if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ if(! empty($data['employee_type'])) $model->where('employee_type', $data['employee_type']);
|
|
|
+ if(isset($data['education'])) $model->where('education', $data['education']);
|
|
|
+
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ $list = $this->fillEnterpriseRdManStatistic($list, $data, $user);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function fillEnterpriseRdManStatistic($list, $data, $user){
|
|
|
+ $man = EmployeeDepartPermission::from('employee_depart_permission as a')
|
|
|
+ ->join('depart as b', 'b.id', '=', 'a.depart_id')
|
|
|
+ ->whereIn('a.employee_id', array_unique(array_column($list,'id')))
|
|
|
+ ->select('a.employee_id', 'b.title')
|
|
|
+ ->get()->toArray();
|
|
|
+ $man_map = [];
|
|
|
+ foreach ($man as $value){
|
|
|
+ if(isset($man_map[$value['employee_id']])){
|
|
|
+ $man_map[$value['employee_id']] .= ',' . $value['title'];
|
|
|
+ }else{
|
|
|
+ $man_map[$value['employee_id']] = $value['title'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($list as $key => $value){
|
|
|
+ $depart_title = $man_map[$value['id']] ?? "";
|
|
|
+ $list[$key]['position_new'] = $depart_title . '/' . $value['position'];
|
|
|
+ $list[$key]['employee_type_title'] = Employee::E_State_Type[$value['employee_type']] ?? '';
|
|
|
+ $list[$key]['education'] = Employee::Education[$value['education']] ?? '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function enterpriseRdItemStatistic($data, $user){
|
|
|
+ // 1. 先声明表名和别名
|
|
|
+ $model = ItemDetails::from('item_details as i');
|
|
|
+ // 2. 再调用 TopClear
|
|
|
+ $model = $model->TopClear($user, $data);
|
|
|
+ $model = $model->from('item_details as i')
|
|
|
+ ->where('i.del_time', 0)
|
|
|
+ ->where('i.type', ItemDetails::type_one);
|
|
|
+ $model = $model->leftJoin('employee as e', 'i.data_id', '=', 'e.id');
|
|
|
+
|
|
|
+ $fields = ['e.id', 'e.title', 'e.education', 'e.major','e.p_title','i.item_id'];
|
|
|
+
|
|
|
+ $list = $model->select($fields)
|
|
|
+ ->orderBy('i.id', 'desc')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $list = $this->fillEnterpriseRdItemStatistic($list, $data, $user);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function fillEnterpriseRdItemStatistic($list, $data, $user){
|
|
|
+ $man = EmployeeDepartPermission::from('employee_depart_permission as a')
|
|
|
+ ->join('depart as b', 'b.id', '=', 'a.depart_id')
|
|
|
+ ->whereIn('a.employee_id', array_unique(array_column($list,'id')))
|
|
|
+ ->select('a.employee_id', 'b.title')
|
|
|
+ ->get()->toArray();
|
|
|
+ $man_map = [];
|
|
|
+ foreach ($man as $value){
|
|
|
+ if(isset($man_map[$value['employee_id']])){
|
|
|
+ $man_map[$value['employee_id']] .= ',' . $value['title'];
|
|
|
+ }else{
|
|
|
+ $man_map[$value['employee_id']] = $value['title'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $item_map = Item::whereIn('id',array_unique(array_column($list,'item_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ foreach ($list as $key => $value){
|
|
|
+ $depart_title = $man_map[$value['id']] ?? "";
|
|
|
+ $list[$key]['depart_title'] = $depart_title;
|
|
|
+ $item_title = $item_map[$value['item_id']] ?? "";
|
|
|
+ $list[$key]['item_title'] = $item_title;
|
|
|
+ $list[$key]['education'] = Employee::Education[$value['education']] ?? '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
}
|