Exemplo n.º 1
0
        /// <summary>
        /// 撤销工时审批
        /// </summary>
        public ERROR_CODE REVOKE_LABOUR(long user_id, string ids, out string re)
        {
            re = "";
            if (!string.IsNullOrEmpty(ids))
            {
                var           idArr       = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var           cadDal      = new crm_account_deduction_dal();
                var           sweDal      = new sdk_work_entry_dal();
                var           ccbDal      = new ctt_contract_block_dal();
                StringBuilder returnvalue = new StringBuilder();
                var           timeNow     = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                foreach (var accId in idArr)
                {
                    var thisCad = cadDal.FindNoDeleteById(long.Parse(accId));
                    if (thisCad != null)
                    {
                        if (thisCad.object_id != null)
                        {
                            var cadList = cadDal.GetListByObjectId((long)thisCad.object_id);

                            if (cadList != null && cadList.Count > 0)
                            {
                                foreach (var cad in cadList)
                                {
                                    if (cad.invoice_id != null)
                                    {
                                        var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                                        if (ci != null && ci.is_voided != 1)
                                        {
                                            returnvalue.Append(accId + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                                        }
                                    }
                                }
                            }


                            if (string.IsNullOrEmpty(returnvalue.ToString()))
                            {
                                if (cadList != null && cadList.Count > 0)
                                {
                                    cadList.ForEach(_ => {
                                        RecoveryBlock(_.id, user_id);
                                        cadDal.SoftDelete(_, user_id);
                                        OperLogBLL.OperLogDelete <crm_account_deduction>(_, _.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                                    });
                                    var swe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                                    if (swe != null)
                                    {
                                        var oldSwe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                                        swe.approve_and_post_date    = null;
                                        swe.approve_and_post_user_id = null;
                                        swe.hours_billed_deduction   = null;
                                        swe.hours_rate_deduction     = null;
                                        swe.update_time    = timeNow;
                                        swe.update_user_id = user_id;
                                        sweDal.Update(swe);
                                        OperLogBLL.OperLogUpdate <sdk_work_entry>(swe, oldSwe, swe.id, user_id, OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "修改工时");
                                    }
                                }
                            }
                            else
                            {
                                re = returnvalue.ToString();
                            }
                        }
                        #region  原来的撤销审批的相关逻辑(原来只针对单个条目进行删除,现在批量操作)
                        //if (thisCad.invoice_id!=null)
                        //{
                        //    var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                        //    if (ci!=null&&ci.is_voided != 1)
                        //    {
                        //        returnvalue.Append(accId + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                        //    }
                        //}
                        //else
                        //{
                        //    #region 删除条目信息
                        //    // var oldCad = cadDal.FindNoDeleteById(long.Parse(accId));
                        //    cadDal.SoftDelete(thisCad,user_id);
                        //    OperLogBLL.OperLogDelete<crm_account_deduction>(thisCad, thisCad.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                        //    #endregion

                        //    #region 修改工时表
                        //    if (thisCad.object_id != null)
                        //    {
                        //        var swe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                        //        if (swe != null)
                        //        {
                        //            var oldSwe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                        //            swe.approve_and_post_date = null;
                        //            swe.approve_and_post_user_id = null;
                        //            swe.hours_billed_deduction = null;
                        //            swe.hours_rate_deduction = null;
                        //            swe.update_time = timeNow;
                        //            swe.update_user_id = user_id;
                        //            sweDal.Update(swe);
                        //            OperLogBLL.OperLogUpdate<sdk_work_entry>(swe, oldSwe, swe.id, user_id, OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "修改工时");
                        //        }
                        //    }
                        //    #endregion

                        //    #region 修改预付费信息
                        //    if (thisCad.contract_block_id != null)
                        //    {
                        //        var thisCcb = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                        //        if (thisCcb != null)
                        //        {
                        //            var oldCcb = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                        //            thisCcb.is_billed = 0;
                        //            thisCcb.status_id = 1;
                        //            thisCcb.update_time = timeNow;
                        //            thisCcb.update_user_id = user_id;
                        //            ccbDal.Update(thisCcb);
                        //            OperLogBLL.OperLogUpdate<ctt_contract_block>(thisCcb, oldCcb, thisCcb.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_BLOCK, "修改合同预付");
                        //        }

                        //    }
                        //    #endregion
                        //}
                        #endregion
                    }
                    else
                    {
                    }
                }
            }
            return(ERROR_CODE.SUCCESS);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 编辑工时
        /// </summary>
        /// <param name="weList">编辑后的工时列表</param>
        /// <param name="batchId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool EditWorkEntry(List <sdk_work_entry> weList, long batchId, long userId)
        {
            var bll = new TimeOffPolicyBLL();
            tst_timeoff_balance_dal balDal = new tst_timeoff_balance_dal();
            var weListOld = GetWorkEntryByBatchId(batchId);

            if (weListOld[0].approve_and_post_user_id != null) // 已审批提交不能编辑
            {
                return(false);
            }

            foreach (var we in weListOld)
            {
                if (weList.Exists(_ => _.start_time == we.start_time))  // 原工时被编辑
                {
                    var weOld  = dal.FindById(we.id);
                    var weEdit = weList.Find(_ => _.start_time == we.start_time);
                    we.internal_notes = weEdit.internal_notes;
                    we.summary_notes  = weEdit.summary_notes;
                    we.hours_worked   = weEdit.hours_worked;
                    we.hours_billed   = weEdit.hours_billed;
                    we.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                    we.update_user_id = userId;
                    var desc = OperLogBLL.CompareValue <sdk_work_entry>(weOld, we);
                    if (!string.IsNullOrEmpty(desc))
                    {
                        dal.Update(we);
                        OperLogBLL.OperLogUpdate(desc, we.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "编辑工时");

                        if (we.task_id == (long)CostCode.Sick && we.hours_worked != weOld.hours_worked)  // 病假需要在假期余额表修改记录
                        {
                            bll.UpdateTimeoffBalance(we.resource_id.Value, Tools.Date.DateHelper.TimeStampToUniversalDateTime(we.start_time.Value), (CostCode)we.task_id);
                            //var balance = bll.UpdateTimeoffBalance((long)we.resource_id, Tools.Date.DateHelper.TimeStampToDateTime((long)we.start_time), (decimal)weOld.hours_billed - (decimal)we.hours_billed);
                            //var bal = balDal.FindSignleBySql<tst_timeoff_balance>($"select * from tst_timeoff_balance where object_id={we.id}");
                            //bal.balance = bal.balance + ((decimal)we.hours_billed - (decimal)weOld.hours_billed);
                            //balDal.Update(bal);
                        }
                    }
                    weList.Remove(weEdit);
                }
                else    // 原工时被删除
                {
                    we.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                    we.delete_user_id = userId;
                    dal.Update(we);
                    OperLogBLL.OperLogDelete <sdk_work_entry>(we, we.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "编辑工时删除");

                    if (we.task_id == (long)CostCode.Sick)  // 病假需要在假期余额表删除记录
                    {
                        bll.UpdateTimeoffBalance(we.resource_id.Value, Tools.Date.DateHelper.TimeStampToUniversalDateTime(we.start_time.Value), (CostCode)we.task_id);
                        //var balance = bll.UpdateTimeoffBalance((long)we.resource_id, Tools.Date.DateHelper.TimeStampToDateTime((long)we.start_time), (decimal)we.hours_billed);
                        //balDal.ExecuteSQL($"delete from tst_timeoff_balance where object_id={we.id}");
                    }
                }
            }
            foreach (var we in weList)  // 剩余需要新增
            {
                we.id             = dal.GetNextIdCom();
                we.batch_id       = batchId;
                we.resource_id    = weListOld[0].resource_id;
                we.cost_code_id   = weListOld[0].cost_code_id;
                we.task_id        = weListOld[0].task_id;
                we.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                we.update_time    = we.create_time;
                we.create_user_id = userId;
                we.update_user_id = userId;

                dal.Insert(we);
                OperLogBLL.OperLogAdd <sdk_work_entry>(we, we.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "编辑工时新增");

                if (we.task_id == (long)CostCode.Sick)  // 病假需要在假期余额表添加记录
                {
                    bll.UpdateTimeoffBalance(we.resource_id.Value, Tools.Date.DateHelper.TimeStampToUniversalDateTime(we.start_time.Value), (CostCode)we.task_id);
                    //var balance = bll.UpdateTimeoffBalance((long)we.resource_id, Tools.Date.DateHelper.TimeStampToDateTime((long)we.start_time), 0 - (decimal)we.hours_billed);
                    //tst_timeoff_balance bal = new tst_timeoff_balance();
                    //bal.object_id = we.id;
                    //bal.object_type_id = 2214;
                    //bal.task_id = we.task_id;
                    //bal.balance = balance + (decimal)we.hours_billed;
                    //balDal.Insert(bal);
                }
            }

            return(true);
        }