소스 검색

津补贴试算

sugangqiang 1 년 전
부모
커밋
dc061a5f85

+ 1 - 1
app/admin/controller/TalentAllowance.php

@@ -637,7 +637,7 @@ class TalentAllowance extends AdminController {
             $enterpriseMap = \app\common\model\Enterprise::where("type", $this->user["type"])->column("name", "id");
             foreach ($detailList as &$detail) {
                 $detail["enterpriseName"] = $enterpriseMap[$detail["enterpriseId"]];
-                if (\StrUtil::isNotEmpAndNull($detal["talentType"])) {
+                if (\StrUtil::isNotEmpAndNull($detail["talentType"])) {
                     $detail["talentTypeName"] = $talentTypeMap[$detail["talentType"]];
                 }
             }

+ 313 - 0
app/common/api/TalentAllowanceApi.php

@@ -6,6 +6,9 @@ use app\common\model\TalentAllowance as TaModel;
 use app\common\state\MainState;
 use think\facade\Db;
 use app\common\state\CommonConst;
+use app\common\state\AllowanceProjectEnum;
+use app\common\model\TalentAllowanceArrange;
+use app\common\model\AmountStandard as AsModel;
 
 /**
  * Description of TalentAllowanceApi
@@ -93,4 +96,314 @@ class TalentAllowanceApi {
         return $passYears;
     }
 
+    public static function validateAllowanceType($id) {
+        $info = ["id" => $id];
+        $old = self::getInfoById($id);
+        $enterpriseMap = \app\common\model\Enterprise::where("type", $old["type"])->column("name", "id");
+        /*         * 查询工作单位记录 */
+        $initDetailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $info["id"])->select()->toArray();
+        $detaiPdList = [];                //用于判定类型
+        $detailMonthList = [];            //用于计算月份
+
+        foreach ($initDetailList as $detail) {
+            $projectList = \app\common\model\TalentAllowanceProject::where("baseId", $detail["id"])->select()->toArray();
+            $projectMap = [];
+            foreach ($projectList as $project) {
+                $projectMap[$project["project"]] = $project;
+            }
+            $detail["list"] = $projectList;
+            $detail["projectMap"] = $projectMap;
+            $detail["enterpriseName"] = $enterpriseMap[$detail["enterpriseId"]];
+            /*             * 筛选符合条件的人才标签 */
+            $detaiPdList[] = $detail;
+            $detailMonthList[] = $detail;
+        }
+        $monthMap = self::mergeMonth($detailMonthList);
+        $monthAndDayMap = self::mergeMonthNeedDay($detailMonthList);
+        $info["recommendAllowanceType"] = 1;
+        $info["recommendAllowanceMsg"] = [];
+        $projectList = \app\common\model\TalentAllowanceProject::where("mainId", $id)->select()->toArray();
+        $set = self::valideAllowanceType($info, $projectList, $monthMap, $monthAndDayMap);
+        $info["recommendAllowanceMsg"][] = "综合以上所有判断得到最终补贴类型为:";
+        if ($info["recommendAllowanceType"] == 1) {
+            $info["recommendAllowanceMsg"][] = "工作津贴;可享受月份为:" . implode(",", $set);
+        }
+        if ($info["recommendAllowanceType"] == 2)
+            $info["recommendAllowanceMsg"][] = "一次性交通补贴;";
+        if ($info["recommendAllowanceType"] == 3)
+            $info["recommendAllowanceMsg"][] = "不予兑现;";
+        usort($set, function($a, $b) {
+            return (int) $a - (int) $b;
+        });
+        $info["recommendMonths"] = implode(",", $set);
+        self::calculateAllowance($info, $set, $detailMonthList);
+        return $info;
+    }
+
+    /**
+     * 集成电路津补贴总校验
+     * */
+    private static function valideAllowanceType(&$info, $projectList, $monthMap, $monthAndDayMap) {
+        $set = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
+        /*         * 2.判定工作月份、五险和个税是否满足重叠6个月要求* */
+        $workdaySet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_ATTENDANCE], $info, "上年度工作月份", "①");
+        $pensionSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_SB_PENSION], $info, "养老保险", "②");
+        $unemploymentSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT], $info, "失业保险", "③");
+        $medicaSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_SB_MEDICA], $info, "医疗保险", "④");
+        $taxSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_TAX], $info, "个税", "⑤");
+        $set = array_intersect($set, $workdaySet);
+        $set = array_intersect($set, $pensionSet);
+        $set = array_intersect($set, $unemploymentSet);
+        $set = array_intersect($set, $medicaSet);
+        $set = array_intersect($set, $taxSet);
+        usort($set, function($a, $b) {
+            return (int) $a - (int) $b;
+        });
+        if ($info["recommendAllowanceType"] == 1) {
+            if (count($set) < 6) {
+                //如果全部满足6个月,但是重叠时间不满足6个月,开始检测是否符合交通补贴要求
+                $info["recommendAllowanceType"] = 2;
+                $info["recommendAllowanceMsg"][] = "社会保险、个税、上年度工作月份交集月份不满足6个月(" . implode(",", $set) . "),无法享受工作津贴(×)";
+            } else {
+                //检查连续缴纳月份是否满足6个月
+                $count = 1;
+                foreach ($set as $s) {
+                    $currentVal = intval($s);
+                    $nextVal = $currentVal + 1;
+                    $nextKey = str_pad($nextVal, 2, "0", STR_PAD_LEFT);
+                    if (in_array($nextKey, $set)) {
+                        $count++;
+                        if ($count >= 6) {
+                            break;
+                        }
+                    } else {
+                        $count = 1;
+                    }
+                }
+                if ($count < 6) {
+                    $info["recommendAllowanceType"] = 2;
+                    $info["recommendAllowanceMsg"][] = "社会保险、个税、上年度工作月份交集月份不满足连续缴纳6个月(" . implode(",", $set) . "),无法享受工作津贴(×)";
+                }
+            }
+        }
+        if ($info["recommendAllowanceType"] == 2) {
+            //判断境内工作时间是否大于30天
+            if ($info["allowanceType"] == 2) {
+                $totalDays = 0;
+                $workmonths = $monthAndDayMap[AllowanceProjectEnum::PROJECT_ATTENDANCE];
+                foreach ($workmonths as $days) {
+                    $totalDays += $days;
+                }
+                if ($totalDays < 30) {
+                    $info["recommendAllowanceType"] = 3;
+                    $info["recommendAllowanceMsg"][] = "全年在我市工作仅{$totalDays}天,未达到30天,无法享受一次性交通津贴(×)";
+                }
+            } else {
+                if (count($workdaySet) == 0) {
+                    $info["recommendAllowanceType"] = 3;
+                    $info["recommendAllowanceMsg"][] = "全年在我市工作未达到30天,无法享受一次性交通津贴(×)";
+                } else {
+                    $info["recommendAllowanceType"] = 2;
+                    $info["recommendAllowanceMsg"][] = "*首选为工作津贴,未录入实际工作天数,需要进一步核实提交的相关附件是否满足全年在我市工作30天";
+                }
+            }
+        }
+        return $set;
+    }
+
+    /**
+     * 计算津补贴
+     */
+    private static function calculateAllowance(&$info, $retainMonths, $detailMonthList) {
+        /*         * 查询人才层次变更记录 */
+        $arrangeList = TalentAllowanceArrange::where("mainId", $info["id"])->order("talentArrange")->select()->toArray();
+        foreach ($arrangeList as &$arrange) {
+            $where = [];
+            $where[] = ["type", "=", $info["type"]];
+            $where[] = ["allowanceType", "in", [1, 2]];
+            $where[] = ["talentArrange", "=", $arrange["talentArrange"]];
+            $list = AsModel::where($where)->field("money,allowanceType")->select()->toArray();
+            foreach ($list as $amount) {
+                if ($amount["allowanceType"] == 1) {
+                    $arrange["jobMoney"] = $amount["money"];
+                }
+                if ($amount["allowanceType"] == 2) {
+                    $arrange["jtMoney"] = $amount["money"];
+                }
+            }
+        }unset($arrange);
+
+        /*         * * 容器 */
+        $jobMoney = 0.00;               //计算所得工作津贴
+        $jtMoney = 0.00;               //计算所得一次性交通补贴
+        $recommendMonths = []; //推荐月份
+        $talentArrange = null;
+        /*         * *********计算************* */
+        $msgBulider = [];
+        switch ($info["recommendAllowanceType"]) {
+            case 1:
+                foreach ($arrangeList as &$arrange) {
+                    if (\StrUtil::isNotEmpAndNull($arrange["prepareMonths"])) {
+                        $levelList = array_filter(explode(",", $arrange["prepareMonths"]));
+                        $levelList = array_intersect($levelList, $retainMonths);
+                        $total = round($arrange["jobMoney"] * count($levelList), 2);
+                        $jobMoney += $total;
+                        $msgBulider[] = sprintf("%d(%s)x%s(第%d层次)", count($levelList), $levelList ? implode(",", $levelList) : "", $arrange["jobMoney"], $arrange["talentArrange"]);
+                        $recommendMonths = array_merge($recommendMonths, $levelList);
+                        usort($recommendMonths, function($a, $b) {
+                            return (int) $a - (int) $b;
+                        });
+                        $arrange["months"] = implode(",", $levelList);
+                        $arrange["count"] = count($levelList);
+                        $arrange["total"] = $total;
+                    } else {
+                        $msgBulider[] = sprintf("0()x%s(第%d层次)", $arrange["jobMoney"], $arrange["talentArrange"]);
+                        $arrange["count"] = 0;
+                        $arrange["total"] = 0.00;
+                    }
+                }unset($arrange);
+                $info["recommendMonths"] = implode(",", $recommendMonths);
+                $info["recommendAllowanceMsg"][] = "通过与人才证书有效期取交集得到最终可享受月份:" . implode(",", $recommendMonths) . ",经过计算:人才津贴为" . $jobMoney . ";";
+                $info["recommendMoney"] = $jobMoney;
+                $info["recommendMoneyDesc"] = implode("+", $msgBulider);
+
+                break;
+            case 2:
+                foreach ($arrangeList as $arrange) {
+                    $jtMoney = $arrange["jtMoney"];
+                    $talentArrange = $arrange["talentArrange"];
+                }
+                $info["recommendMoney"] = $jtMoney;
+                $info["recommendMonths"] = "";
+                $info["recommendMoneyDesc"] = "一次性交通补贴";
+                $info["workAllowanceMoney"] = 0.00;
+                $info["developAllowanceMoney"] = 0.00;
+                $info["recommendTalentArrange"] = $talentArrange;
+                break;
+            case 3:
+                $info["recommendMoney"] = 0.00;
+                $info["recommendMonths"] = "";
+                $info["recommendMoneyDesc"] = "不予兑现";
+                $info["workAllowanceMoney"] = 0.00;
+                $info["developAllowanceMoney"] = 0.00;
+                break;
+        }
+        return $arrangeList;
+    }
+
+    /**
+     * 判定是否交足6个月(集成电路)
+     * @param set
+     * @param info
+     * @param name
+     */
+    private static function chkMonths($set, &$info, $name, $sort) {
+        if ($name == "上年度工作月份") {
+            if ($info["allowanceType"] == 2) {
+                $tmp = [];
+                foreach ($set as $s) {
+                    $_s = explode("=", $s);
+                    $month = $_s[0];
+                    $days = $_s[1];
+                    if ($days > 0) {
+                        $tmp[] = $month;
+                    }
+                }
+                $set = $tmp;
+            }
+        }
+        if ($info["recommendAllowanceType"] == 1 && (!$set || count($set) < 6)) {
+            $info["recommendAllowanceType"] = 2;
+            $info["recommendAllowanceMsg"][] = $sort . $name . "不足6个月,无法享受工作津贴(×)";
+        }
+        return $set;
+    }
+
+    //合并所有项目的月份
+    private static function mergeMonth($detailList) {
+        $taxList = [];
+        $wagesList = [];
+        $pensionList = [];
+        $unemploymentList = [];
+        $medicaList = [];
+        $attendanceList = [];
+        $workdayList = [];
+        foreach ($detailList as $detail) {
+            $projectMap = $detail["projectMap"];
+            if ($projectMap[AllowanceProjectEnum::PROJECT_TAX] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_TAX]["months"])) {
+                $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_TAX]["months"]));
+                $taxList = array_merge($taxList, $tmp);
+            }
+            if ($projectMap[AllowanceProjectEnum::PROJECT_WAGES] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_WAGES]["months"])) {
+                $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_WAGES]["months"]));
+                $wagesList = array_merge($wagesList, $tmp);
+            }
+            if ($projectMap[AllowanceProjectEnum::PROJECT_SB_PENSION] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_SB_PENSION]["months"])) {
+                $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_SB_PENSION]["months"]));
+                $pensionList = array_merge($pensionList, $tmp);
+            }
+            if ($projectMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT]["months"])) {
+                $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT]["months"]));
+                $unemploymentList = array_merge($unemploymentList, $tmp);
+            }
+            if ($projectMap[AllowanceProjectEnum::PROJECT_SB_MEDICA] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_SB_MEDICA]["months"])) {
+                $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_SB_MEDICA]["months"]));
+                $medicaList = array_merge($medicaList, $tmp);
+            }
+            if ($projectMap[AllowanceProjectEnum::PROJECT_ATTENDANCE] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_ATTENDANCE]["months"])) {
+                $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_ATTENDANCE]["months"]));
+                $attendanceList = array_merge($attendanceList, $tmp);
+            }
+            if ($projectMap[AllowanceProjectEnum::PROJECT_WORKDAY] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_WORKDAY]["months"])) {
+                $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_WORKDAY]["months"]));
+                $workdayList = array_merge($workdayList, $tmp);
+            }
+        }
+        $map = [
+            AllowanceProjectEnum::PROJECT_TAX => $taxList,
+            AllowanceProjectEnum::PROJECT_WAGES => $wagesList,
+            AllowanceProjectEnum::PROJECT_SB_PENSION => $pensionList,
+            AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT => $unemploymentList,
+            AllowanceProjectEnum::PROJECT_SB_MEDICA => $medicaList,
+            AllowanceProjectEnum::PROJECT_ATTENDANCE => $attendanceList,
+            AllowanceProjectEnum::PROJECT_WORKDAY => $workdayList,
+        ];
+        return $map;
+    }
+
+    /**
+     * 合并多个单位带有天数的项目的月份如考勤1月30天,
+     * */
+    private static function mergeMonthNeedDay($detailList) {
+        $attendMap = [];
+        $workDayMap = [];
+        foreach ($detailList as $detail) {
+            $attendMap = self::getMergeMonthNeedDayMap($detail["projectMap"][AllowanceProjectEnum::PROJECT_ATTENDANCE], $attendMap);
+            $workDayMap = self::getMergeMonthNeedDayMap($detail["projectMap"][AllowanceProjectEnum::PROJECT_WORKDAY], $workDayMap);
+        }
+        $res = [
+            AllowanceProjectEnum::PROJECT_ATTENDANCE => $attendMap,
+            AllowanceProjectEnum::PROJECT_WORKDAY => $workDayMap
+        ];
+        return $res;
+    }
+
+    private static function getMergeMonthNeedDayMap($project, $map) {
+        if (\StrUtil::isNotEmpAndNull($project["months"])) {
+            $monthAndDayList = array_filter(explode(",", $project["months"]));
+            for ($i = 0; $i < count($monthAndDayList); $i++) {
+                $obj = explode("=", $monthAndDayList[$i]);
+                $month = $obj[0];
+                $day = $obj[1];
+                $count = $map[$month];
+                if ($count == 0) {
+                    $map[$month] = $day;
+                } else {
+                    $map[$month] = $day + $count;
+                }
+            }
+        }
+        return $map;
+    }
+
 }

+ 5 - 0
app/enterprise/controller/TalentAllowance.php

@@ -48,6 +48,11 @@ class TalentAllowance extends EnterpriseController {
         return json($res);
     }
 
+    public function calculator($id) {
+        $cal = TalentAllowanceApi::validateAllowanceType($id);
+        return json($cal);
+    }
+
     /**
      * 申请
      */

+ 17 - 0
public/static/modular/gate/talentAllowance/common/talentAllowanceInfo_select.js

@@ -405,6 +405,23 @@ TalentAllowanceInfoDlg.showAllLog = function () {
         Feng.getCheckLog("logTable", {"type": CONFIG.project_jbt, "mainId": id, "typeFileId": "", "active": 1})
     }
 }
+TalentAllowanceInfoDlg.calculator = function () {
+    var id = $("#id").val();
+    if (!id) {
+        Feng.error("请先保存再进行计算");
+        return;
+    }
+    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/calculator/id/" + id, function (data) {
+        var message = data.recommendAllowanceMsg.join("<br>");
+        if (data.recommendAllowanceType != 3) {
+            message += "<br>试算补贴金额:" + data.recommendMoney;
+        }
+        Feng.confirm(message);
+    }, function (data) {
+        Feng.error("查询失败!" + data.responseJSON.message + "!");
+    });
+    ajax.start();
+}
 
 $(function () {
     Feng.initValidatorTip("talentAllowanceForm", TalentAllowanceInfoDlg.validateFields);

+ 18 - 0
public/static/modular/gate/talentAllowance/common/talentAllowance_info.js

@@ -84,6 +84,24 @@ TalentAllowanceInfoDlg.onAllowanceTypeChange = function (allowanceType) {
     }
 }
 
+TalentAllowanceInfoDlg.calculator = function () {
+    var id = $("#id").val();
+    if (!id) {
+        Feng.error("请先保存再进行计算");
+        return;
+    }
+    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/calculator/id/" + id, function (data) {
+        var message = data.recommendAllowanceMsg.join("<br>");
+        if (data.recommendAllowanceType != 3) {
+            message += "\n" + "试算补贴金额:" + data.recommendMoney;
+        }
+        Feng.confirm(message);
+    }, function (data) {
+        Feng.error("查询失败!" + data.responseJSON.message + "!");
+    });
+    ajax.start();
+}
+
 /**
  * 选择申报对象初始化
  */

+ 17 - 5
public/static/modular/gate/talentAllowance/ic/talentAllowanceInfoIC.js

@@ -126,7 +126,7 @@ TalentAllowanceInfo.openAddTalentAllowanceInfo = function () {
                 fix: false, //不固定
                 maxmin: true,
                 content: '/enterprise/talentAllowance/apply?year=' + data.batch,
-                btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-check layui-bg-green"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
+                btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-check layui-bg-green"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-calculator"></i>&nbsp;&nbsp;试算', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
                 btnAlign: 'c',
                 btn1: function (index, layero) {
                     var obj = layero.find("iframe")[0].contentWindow;
@@ -135,8 +135,11 @@ TalentAllowanceInfo.openAddTalentAllowanceInfo = function () {
                     var obj = layero.find("iframe")[0].contentWindow;
                     obj.TalentAllowanceInfoDlg.submitToCheck();
                     return false;
-                },
-                success: function (layero, index) {
+                }, btn3: function (index, layero) {
+                    var obj = layero.find("iframe")[0].contentWindow;
+                    obj.TalentAllowanceInfoDlg.calculator();
+                    return false;
+                }, success: function (layero, index) {
                     layer.tips('添加基本信息并上传附件后点击', '.layui-layer-btn1', {tips: [1, "#78BA32"], time: 0, closeBtn: 2});
                 },
                 end: function () {
@@ -169,7 +172,7 @@ TalentAllowanceInfo.openTalentAllowanceInfoDetail = function () {
                     fix: false, //不固定
                     maxmin: true,
                     content: Feng.ctxPath + '/enterprise/talentAllowance/apply/id/' + TalentAllowanceInfo.seItem.id,
-                    btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-check"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
+                    btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-check"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-calculator"></i>&nbsp;&nbsp;试算', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
                     btnAlign: 'c',
                     btn1: function (index, layero) {
                         var obj = layero.find("iframe")[0].contentWindow;
@@ -179,6 +182,10 @@ TalentAllowanceInfo.openTalentAllowanceInfoDetail = function () {
                         var obj = layero.find("iframe")[0].contentWindow;
                         obj.TalentAllowanceInfoDlg.submitToCheck();
                         return false;
+                    }, btn3: function (index, layero) {
+                        var obj = layero.find("iframe")[0].contentWindow;
+                        obj.TalentAllowanceInfoDlg.calculator();
+                        return false;
                     },
                     success: function (layero, index) {
                         layer.tips('添加基本信息并上传附件后点击', '.layui-layer-btn0', {tips: [1, "#78BA32"], time: 0, closeBtn: 2});
@@ -210,8 +217,13 @@ TalentAllowanceInfo.openTalentAllowanceInfoSelect = function () {
             fix: false, //不固定
             maxmin: true,
             content: Feng.ctxPath + '/enterprise/talentAllowance/detail/id/' + TalentAllowanceInfo.seItem.id,
-            btn: ['<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
+            btn: ['<i class="fa fa-calculator"></i>&nbsp;&nbsp;试算', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
             btnAlign: 'c',
+            btn1: function (index, layero) {
+                var obj = layero.find("iframe")[0].contentWindow;
+                obj.TalentAllowanceInfoDlg.calculator();
+                return false;
+            }
         });
         layer.full(index);
         TalentAllowanceInfo.layerIndex = index;