|
|
@@ -5,7 +5,9 @@ namespace App\Service;
|
|
|
use App\Model\AuxiliaryAccountDetails;
|
|
|
use App\Model\DailyDwOrderDetails;
|
|
|
use App\Model\DailyPwOrderDetails;
|
|
|
+use App\Model\Depart;
|
|
|
use App\Model\Device;
|
|
|
+use App\Model\DeviceDepartDetails;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\EmployeeDepartPermission;
|
|
|
use App\Model\ExpenseClaimsDetails;
|
|
|
@@ -230,11 +232,31 @@ class StatisticService extends StatisticCommonService
|
|
|
$item = Item::TopClear($user, $data);
|
|
|
$item_title_key_list = $item->wherein('id', $items)->pluck("title", "id")->toArray();
|
|
|
$item_code_key_list = $item->wherein('id', $items)->pluck("code", "id")->toArray();
|
|
|
-
|
|
|
$device_ids = collect($item_month_list)->pluck('device_id')->unique()->values()->all();
|
|
|
|
|
|
$device = Device::TopClear($user, $data);
|
|
|
- $device_key_list = $device->wherein('id', $device_ids)->pluck("title", "id")->toArray();
|
|
|
+ $devices = $device->whereIn('id', $device_ids)
|
|
|
+ ->get(['id', 'title', 'total_depreciation', 'in_time', 'device_type']);
|
|
|
+ $timestamps = $devices->pluck('in_time')->unique()->toArray();
|
|
|
+ $yearsMap = $this->getBatchDiffYears($timestamps);
|
|
|
+ $depart_map = $this->getDepart($devices->pluck('id')->unique()->toArray());
|
|
|
+
|
|
|
+ $device_key_list = [];
|
|
|
+ foreach ($devices as $d) {
|
|
|
+ $useYear = $d->in_time ? $yearsMap[$d->in_time] : 0;
|
|
|
+ $depart_title = $depart_map[$d->id] ?? "";
|
|
|
+
|
|
|
+ $device_key_list[$d->id] = [
|
|
|
+ 'id' => $d->id,
|
|
|
+ 'title' => $d->title,
|
|
|
+ 'now_depreciation' => $d->total_depreciation,
|
|
|
+ 'in_time' => $d->in_time,
|
|
|
+ 'device_type_title' => Device::$device_type[$d->device_type] ?? "",
|
|
|
+ 'use_year' => $useYear,
|
|
|
+ 'depart_title' => $depart_title,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+// $device_key_list = $device->wherein('id', $device_ids)->pluck("title", "id")->toArray();
|
|
|
$device_original_value_key_list = $device->wherein('id', $device_ids)->pluck("original_value", "id")->toArray();
|
|
|
|
|
|
$collect = collect($item_month_list);
|
|
|
@@ -273,7 +295,12 @@ class StatisticService extends StatisticCommonService
|
|
|
$item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, $device_key_list, $device_original_value_key_list, &$device_total_depreciation, &$device_counts,&$rate_list,$word_keys) {
|
|
|
$item['item_title'] = $item_title_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
|
|
|
$item['item_code'] = $item_code_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
|
|
|
- $item['device_title'] = $device_key_list[$item['device_id']] ?? "未知人员({$item['device_id']})";
|
|
|
+ $tmp = $device_key_list[$item['device_id']] ?? [];
|
|
|
+ $item['device_title'] = $tmp['title'] ?? "";
|
|
|
+ $item['device_type_title'] = $tmp['device_type_title'] ?? "";
|
|
|
+ $item['use_year'] = $tmp['use_year'] ?? 0;
|
|
|
+ $item['depart_title'] = $tmp['depart_title'] ?? "";
|
|
|
+ $item['now_depreciation'] = $tmp['now_depreciation'] ?? 0;
|
|
|
$item['allocated_depreciatio'] = $item['allocated_depreciation'];
|
|
|
$item['total_depreciatio'] = round($item['total_depreciation']/100,2);
|
|
|
$item['device_original'] = $device_original_value_key_list[$item['device_id']] ?? "未知人员({$item['device_id']})";
|
|
|
@@ -287,6 +314,34 @@ class StatisticService extends StatisticCommonService
|
|
|
return [true, $item_month_list];
|
|
|
}
|
|
|
|
|
|
+ public function getDepart($id){
|
|
|
+ $details = DeviceDepartDetails::where('del_time', 0)
|
|
|
+ ->whereIn('main_id', $id)
|
|
|
+ ->select(['main_id as device_id', 'depart_id'])
|
|
|
+ ->get();
|
|
|
+ $departIds = $details->pluck('depart_id')->unique()->toArray();
|
|
|
+ $departMap = Depart::whereIn('id', $departIds)
|
|
|
+ ->pluck('title', 'id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+
|
|
|
+ foreach ($details as $value) {
|
|
|
+ $deviceId = $value['device_id'];
|
|
|
+ $departId = $value['depart_id'];
|
|
|
+
|
|
|
+ $t = $departMap[$departId] ?? '';
|
|
|
+ if(empty($t)) continue;
|
|
|
+
|
|
|
+ if(isset($result[$deviceId])){
|
|
|
+ $result[$deviceId] .= ',' . $t;
|
|
|
+ }else{
|
|
|
+ $result[$deviceId] = $t;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
|
|
|
public function employeeAttendanceMonthStatistic($data, $user)
|
|
|
{
|
|
|
@@ -1112,4 +1167,55 @@ class StatisticService extends StatisticCommonService
|
|
|
|
|
|
return $list;
|
|
|
}
|
|
|
+
|
|
|
+ public function employeeMonthSalaryStatisticCountCommon($data,$user){
|
|
|
+ $model = MonthlyPsOrder::Clear($user,$data);
|
|
|
+ $model->leftJoin('monthly_ps_order_details as b', 'b.main_id', 'monthly_ps_order.id')
|
|
|
+ ->where('monthly_ps_order.del_time',0)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->select('monthly_ps_order.month', 'b.employee_id', 'b.base_salary','b.performance_salary','b.bonus','b.other')
|
|
|
+ ->orderby('monthly_ps_order.month','desc');
|
|
|
+
|
|
|
+ if(! empty($data['time'][0]) && ! empty($data['time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['time']);
|
|
|
+ $model->where('monthly_ps_order.month','>=',$return[0]);
|
|
|
+ $model->where('monthly_ps_order.month','<=',$return[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($data['employee_title'])){
|
|
|
+ $model_2 = Employee::TopClear($user,$data);
|
|
|
+ $id = $model_2->where('del_time',0)
|
|
|
+ ->where('title', 'LIKE', '%'.$data['employee_title'].'%')
|
|
|
+ ->pluck('id')
|
|
|
+ ->toArray();
|
|
|
+ $model->whereIn('b.employee_id', $id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function employeeMonthSalaryStatisticCount($data, $user){
|
|
|
+ $model = $this->employeeMonthSalaryStatisticCountCommon($data, $user);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillEmployeeMonthSalaryStatisticCount($list, $data, $user);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillEmployeeMonthSalaryStatisticCount($data, $ergs, $user){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'employee_id')));
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['month'] = $value['month'] ? date('Y-m',$value['month']) : '';
|
|
|
+ $data['data'][$key]['employee_title'] = $emp[$value['employee_id']] ?? '';
|
|
|
+ $totalSalary = (float)($value['base_salary'] ?? 0)
|
|
|
+ + (float)($value['performance_salary'] ?? 0)
|
|
|
+ + (float)($value['bonus'] ?? 0)
|
|
|
+ + (float)($value['other'] ?? 0);
|
|
|
+ $data['data'][$key]['total_salary'] = number_format($totalSalary, 2, '.', '');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
}
|