Exemple #1
0
        /// <summary>
        /// 删除库存产品
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteIvtProduct(long id, long userId)
        {
            var pdtInfo = GetIvtProductEdit(id);

            if (pdtInfo == null)
            {
                return(false);
            }
            if (int.Parse(pdtInfo.picked) > 0 || int.Parse(pdtInfo.on_order) > 0)
            {
                return(false);
            }

            ivt_warehouse_product product = dal.FindById(id);

            string sql = $"update ivt_warehouse_product_sn set delete_user_id={userId},delete_time={Tools.Date.DateHelper.ToUniversalTimeStamp()} where warehouse_product_id={id} and delete_time=0";

            dal.ExecuteSQL(sql);

            product.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            product.delete_user_id = userId;
            dal.Update(product);

            OperLogBLL.OperLogDelete <ivt_warehouse_product>(product, id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "删除库存产品");

            if (int.Parse(pdtInfo.reserved_picked) - int.Parse(pdtInfo.picked) > 0)     // 有预留库存产品,删除之
            {
                sql = $"update ivt_reserve set delete_user_id={userId},delete_time={Tools.Date.DateHelper.ToUniversalTimeStamp()} where warehouse_id={product.warehouse_id} and delete_time=0 and quote_item_id in(select id from crm_quote_item where object_id={product.id} and delete_time=0)";
                dal.ExecuteSQL(sql);
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 删除队列
        /// </summary>
        public bool DeleteQueue(long queId, long userId, ref string faileReason)
        {
            sys_department thisQue = _dal.FindNoDeleteById(queId);

            if (thisQue == null)
            {
                return(true);
            }
            if (thisQue.is_system == 1)
            {
                faileReason = "系统队列,不能删除";
                return(false);
            }
            List <sys_resource_department> resDepList = GetResDepList(queId);

            if (resDepList != null && resDepList.Count > 0)
            {
                faileReason = "队列下有多个联系人,不能删除";
                return(false);
            }

            List <sdk_task> ticketList = _dal.FindListBySql <sdk_task>("SELECT * from sdk_task where delete_time =0 and type_id = 1809 and department_id = " + queId.ToString());

            if (ticketList != null && ticketList.Count > 0)
            {
                faileReason = "队列被多个工单引用,不能删除";
                return(false);
            }
            _dal.SoftDelete(thisQue, userId);
            OperLogBLL.OperLogDelete <sys_department>(thisQue, thisQue.id, userId, OPER_LOG_OBJ_CATE.DEPARTMENT, "");
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 删除预付
        /// </summary>
        /// <param name="blockId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeletePurchase(long blockId, long userId)
        {
            ctt_contract_cost_dal costDal = new ctt_contract_cost_dal();
            var list = costDal.FindByBlockId(blockId);

            foreach (var cost in list)
            {
                cost.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                cost.delete_user_id = userId;
                costDal.Update(cost);
                OperLogBLL.OperLogDelete <ctt_contract_cost>(cost, cost.id, userId, OPER_LOG_OBJ_CATE.CONTRACT_COST, "删除合同预付");
            }

            var block = dal.FindById(blockId);

            if (block == null)
            {
                return(false);
            }
            block.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            block.delete_user_id = userId;
            dal.Update(block);
            OperLogBLL.OperLogDelete <ctt_contract_block>(block, block.id, userId, OPER_LOG_OBJ_CATE.CONTRACT_BLOCK, "删除合同预付");
            return(true);
        }
Exemple #4
0
        /// <summary>
        /// 删除知识库
        /// </summary>
        public bool DeleteKnow(long artId, long userId)
        {
            var timeNow       = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            var skatDal       = new sdk_kb_article_ticket_dal();
            var skacDal       = new sdk_kb_article_comment_dal();
            var thisArt       = _dal.FindNoDeleteById(artId);
            var thisArtTicket = skatDal.GetArtTicket(artId);
            var thisArtComm   = skacDal.GetCommByArt(artId);

            if (thisArtComm != null && thisArtComm.Count > 0)
            {
                thisArtComm.ForEach(_ => {
                    skacDal.SoftDelete(_, userId);
                    OperLogBLL.OperLogDelete <sdk_kb_article_comment>(_, _.id, userId, OPER_LOG_OBJ_CATE.SDK_KONWLEDGE_COMMENT, "删除知识库评论");
                });
            }
            if (thisArtTicket != null && thisArtTicket.Count > 0)
            {
                thisArtTicket.ForEach(_ => {
                    skatDal.SoftDelete(_, userId);
                    OperLogBLL.OperLogDelete <sdk_kb_article_ticket>(_, _.id, userId, OPER_LOG_OBJ_CATE.SDK_KONWLEDGE_TICKET, "删除知识库关联工单");
                });
            }
            if (thisArt != null)
            {
                _dal.SoftDelete(thisArt, userId);
                OperLogBLL.OperLogDelete <sdk_kb_article>(thisArt, thisArt.id, userId, OPER_LOG_OBJ_CATE.SDK_KONWLEDGE, "删除知识库");
            }

            return(true);
        }
Exemple #5
0
        public bool DeleteLocation(long location_id, long user_id)
        {
            var location = _dal.GetLocationById(location_id);
            var result   = _dal.SoftDelete(location, user_id);

            OperLogBLL.OperLogDelete <crm_location>(location, location.id, user_id, OPER_LOG_OBJ_CATE.CUSTOMER, "删除客户");
            return(result);
        }
Exemple #6
0
        /// <summary>
        /// 删除合同费率
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userId"></param>
        public void DeleteRate(long id, long userId)
        {
            var rate = dal.FindById(id);

            rate.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            rate.delete_user_id = userId;
            dal.Update(rate);
            OperLogBLL.OperLogDelete <ctt_contract_rate>(rate, rate.id, userId, DTO.DicEnum.OPER_LOG_OBJ_CATE.CONTRACT_RATE, "删除合同费率");
        }
Exemple #7
0
        /// <summary>
        /// 删除工作流规则
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteWorkflow(long id, long userId)
        {
            sys_workflow wf = dal.FindById(id);

            wf.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            wf.delete_user_id = userId;
            dal.Update(wf);
            OperLogBLL.OperLogDelete <sys_workflow>(wf, wf.id, userId, DicEnum.OPER_LOG_OBJ_CATE.WORKFLOW_RULE, "删除工作流规则");
            return(true);
        }
Exemple #8
0
        /// <summary>
        /// 删除工时
        /// </summary>
        /// <param name="batchId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteWorkEntry(long batchId, long userId)
        {
            var weList = dal.FindListBySql($"select * from sdk_work_entry where batch_id={batchId} and delete_time=0");

            if (weList.Count == 0)
            {
                return(false);
            }

            int  type;
            long id;

            if (!GetWorkEntryType(batchId, out type, out id))
            {
                return(false);
            }

            bool rtn     = true;
            var  bll     = new TimeOffPolicyBLL();
            var  taskbll = new TaskBLL();
            tst_timeoff_balance_dal balDal = new tst_timeoff_balance_dal();
            string reason;

            foreach (var we in weList)
            {
                if (type == 1)  // 常规工时
                {
                    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}");
                    }
                }
                else if (type == 2) // 休假请求
                {
                    bll.CancleTimeoffRequest(we.timeoff_request_id.Value, userId);
                }
                else    // 任务工时和工单工时
                {
                    if (!taskbll.DeleteEntry(we.id, userId, out reason))
                    {
                        rtn = false;
                    }
                }
            }

            return(rtn);
        }
Exemple #9
0
        /// <summary>
        /// 撤销费用审批
        /// </summary>
        public ERROR_CODE REVOKE_EXPENSE(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           seDal       = new sdk_expense_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.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 se = seDal.FindNoDeleteById((long)thisCad.object_id);
                                if (se != null)
                                {
                                    var oldSe = seDal.FindNoDeleteById((long)thisCad.object_id);
                                    se.approve_and_post_date    = null;
                                    se.approve_and_post_user_id = null;
                                    se.amount_deduction         = null;
                                    se.update_time    = timeNow;
                                    se.update_user_id = user_id;
                                    seDal.Update(se);
                                    OperLogBLL.OperLogUpdate <sdk_expense>(se, oldSe, se.id, user_id, OPER_LOG_OBJ_CATE.SDK_EXPENSE, "修改费用");
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            return(ERROR_CODE.SUCCESS);
        }
Exemple #10
0
 /// <summary>
 /// 删除服务包相关,不能删除时,返回所有不能删除相关对象数量
 /// </summary>
 public bool DeleteServiceBundle(long serviceId, long userId, ref string faileReason)
 {
     try
     {
         var isbDal        = new ivt_service_bundle_dal();
         var thisSerBundle = isbDal.FindNoDeleteById(serviceId);
         if (thisSerBundle == null)
         {
             return(true);
         }
         var conSerList = new ctt_contract_service_dal().getContractByServiceId(thisSerBundle.id);
         if (conSerList != null && conSerList.Count > 0)
         {
             faileReason += $"{conSerList.Count} 合同\n";
         }
         var quoteItemList = new crm_quote_item_dal().GetItemByObjId(thisSerBundle.id);
         if (quoteItemList != null && quoteItemList.Count > 0)
         {
             faileReason += $"{quoteItemList.Count} 报价项\n";
         }
         var labourList = new sdk_work_entry_dal().GetListByService(thisSerBundle.id);
         if (labourList != null && labourList.Count > 0)
         {
             faileReason += $"{labourList.Count} 工时\n";
         }
         var insProList = new crm_installed_product_dal().GetInsListBySerBunId(thisSerBundle.id);
         if (insProList != null && insProList.Count > 0)
         {
             faileReason += $"{insProList.Count} 配置项\n";
         }
         if (!string.IsNullOrEmpty(faileReason))
         {
             return(false);
         }
         else
         {
             var isbsDal = new ivt_service_bundle_service_dal();
             var serList = GetServiceListByServiceBundleId(thisSerBundle.id);
             if (serList != null && serList.Count > 0)
             {
                 serList.ForEach(_ => {
                     isbsDal.Delete(_);
                 });
             }
             isbDal.SoftDelete(thisSerBundle, userId);
             OperLogBLL.OperLogDelete <ivt_service_bundle>(thisSerBundle, thisSerBundle.id, userId, DTO.DicEnum.OPER_LOG_OBJ_CATE.IVT_SERVICE_BUNDLE, "删除服务包");
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Exemple #11
0
        public bool DeleteCode(long codeId, long userId)
        {
            if (!DeleteCodeCheck(codeId))
            {
                return(false);
            }
            d_cost_code thisCode = GetCodeById(codeId);

            _dal.SoftDelete(thisCode, userId);
            OperLogBLL.OperLogDelete <d_cost_code>(thisCode, thisCode.id, userId, OPER_LOG_OBJ_CATE.D_COST_CODE, "");
            return(true);
        }
Exemple #12
0
        /// <summary>
        /// 删除约会
        /// </summary>
        public bool DeleteAppointment(long dId, long userId)
        {
            var oldDis = saDal.FindNoDeleteById(dId);

            if (oldDis == null)
            {
                return(false);
            }
            saDal.SoftDelete(oldDis, userId);
            OperLogBLL.OperLogDelete <sdk_appointment>(oldDis, oldDis.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SERVICE_APPOINTMENT, "删除约会");
            return(true);
        }
Exemple #13
0
        /// <summary>
        /// 删除知识库评论
        /// </summary>
        public bool DeleteComment(long artComId, long userId)
        {
            var skacDal = new sdk_kb_article_comment_dal();
            var thisCom = skacDal.FindNoDeleteById(artComId);

            if (thisCom != null)
            {
                skacDal.SoftDelete(thisCom, userId);
                OperLogBLL.OperLogDelete <sdk_kb_article_comment>(thisCom, thisCom.id, userId, OPER_LOG_OBJ_CATE.SDK_KONWLEDGE_COMMENT, "删除知识库评论");
            }

            return(true);
        }
Exemple #14
0
        /// <summary>
        /// 删除工作组员工
        /// </summary>
        public bool DeleteGroupResource(long groupId, long userId)
        {
            sys_workgroup_resouce_dal swrDal = new sys_workgroup_resouce_dal();
            var oldGroup = swrDal.FindById(groupId);

            if (oldGroup == null)
            {
                return(true);
            }
            swrDal.Delete(oldGroup);
            OperLogBLL.OperLogDelete <sys_workgroup_resouce>(oldGroup, oldGroup.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SYS_WORKGROUP_RESOURCE, "");
            return(true);
        }
Exemple #15
0
        /// <summary>
        /// 删除约会
        /// </summary>
        public bool DeleteDispatchView(long dId, long userId)
        {
            var sdDal  = new sdk_dispatcher_view_dal();
            var oldDis = sdDal.FindNoDeleteById(dId);

            if (oldDis == null)
            {
                return(false);
            }
            sdDal.SoftDelete(oldDis, userId);
            OperLogBLL.OperLogDelete <sdk_dispatcher_view>(oldDis, oldDis.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SERVICE_DISPATCHER_VIEW, "删除调度工作室视图");
            return(true);
        }
Exemple #16
0
        public bool DeleteResource(long id, long userId)
        {
            sys_resource_department_dal srdDal = new sys_resource_department_dal();
            var oldResDep = srdDal.FindById(id);

            if (oldResDep == null)
            {
                return(true);
            }
            srdDal.Delete(oldResDep);
            OperLogBLL.OperLogDelete <sys_resource_department>(oldResDep, oldResDep.id, userId, OPER_LOG_OBJ_CATE.SYS_RESOURCE_DEPARTMENT, "");
            return(true);
        }
Exemple #17
0
        /// <summary>
        /// 删除附件
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userId"></param>
        public void DeleteAttachment(long id, long userId)
        {
            var att = dal.FindById(id);

            if (att == null)
            {
                return;
            }
            att.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            att.delete_user_id = userId;
            dal.Update(att);
            OperLogBLL.OperLogDelete <com_attachment>(att, att.id, userId, DicEnum.OPER_LOG_OBJ_CATE.ATTACHMENT, "删除附件");
        }
Exemple #18
0
        /// <summary>
        /// 删除工时表
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="resourceId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteWorkEntryReport(DateTime startDate, long resourceId, long userId)
        {
            sdk_work_entry_report_dal rptDal = new sdk_work_entry_report_dal();
            var find = rptDal.FindSignleBySql <sdk_work_entry_report>($"select * from sdk_work_entry_report where resource_id={resourceId} and start_date='{startDate}' and delete_time=0");

            if (find != null && find.status_id != (int)DicEnum.WORK_ENTRY_REPORT_STATUS.HAVE_IN_HAND)
            {
                return(false);
            }

            var weList = GetWorkEntryListByStartDate(startDate, resourceId);

            if (weList.Count == 0)
            {
                return(false);
            }

            var bll = new TimeOffPolicyBLL();
            tst_timeoff_balance_dal balDal = new tst_timeoff_balance_dal();

            //var weList = GetWorkEntryByBatchId(batchId);
            //if (weList.Count == 0)
            //    return true;
            //if (weList[0].approve_and_post_user_id != null) // 已审批提交不能删除
            //    return false;

            foreach (var we in weList)
            {
                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}");
                }
            }

            if (find != null)
            {
                find.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                find.delete_user_id = userId;
                rptDal.Update(find);
                OperLogBLL.OperLogDelete <sdk_work_entry_report>(find, find.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SDK_WORK_RECORD, "删除工时表");
            }
            return(true);
        }
Exemple #19
0
        /// <summary>
        /// 清除员工的审批设置
        /// </summary>
        public bool DeleteUserApproval(long resId, int type, long userId)
        {
            List <sys_resource_approver> appList = GetApprover(resId, type);

            if (appList != null && appList.Count > 0)
            {
                sys_resource_approver_dal sraDal = new sys_resource_approver_dal();
                appList.ForEach(_ => {
                    sraDal.Delete(_);
                    OperLogBLL.OperLogDelete <sys_resource_approver>(_, _.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "");
                });
            }
            return(true);
        }
Exemple #20
0
        /// <summary>
        /// 删除费用报表
        /// </summary>
        public bool DeleteReport(long rId, long userId, out string reason)
        {
            reason = "";
            try
            {
                var thisReport = _dal.FindNoDeleteById(rId);
                if (thisReport != null)
                {
                    if (thisReport.status_id == (int)DTO.DicEnum.EXPENSE_REPORT_STATUS.PAYMENT_BEEN_APPROVED || thisReport.status_id == (int)DTO.DicEnum.EXPENSE_REPORT_STATUS.ALREADY_PAID)
                    {
                        reason = "费用报表已审批通过,不能删除。请审批人员先拒绝";
                        return(false);
                    }
                    else
                    {
                        var teprDal = new tst_expense_report_log_dal();
                        var logList = teprDal.GetListByReportId(thisReport.id);



                        _dal.SoftDelete(thisReport, userId);
                        OperLogBLL.OperLogDelete <sdk_expense_report>(thisReport, thisReport.id, userId, OPER_LOG_OBJ_CATE.SDK_EXPENSE_REPORT, "删除费用报表");

                        if (logList != null && logList.Count > 0)
                        {
                            logList.ForEach(_ => {
                                teprDal.SoftDelete(_, userId);
                            });
                        }
                    }
                }
                else
                {
                    reason = "费用已经删除";
                    return(false);
                }

                // GetListByReportId
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemple #21
0
        /// <summary>
        /// 删除邮件模板
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteTmpl(long id, long userId)
        {
            var tmpl = dal.FindNoDeleteById(id);

            if (tmpl == null)
            {
                return(false);
            }

            var old = dal.FindById(tmpl.id);

            tmpl.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            tmpl.delete_user_id = userId;
            dal.Update(tmpl);
            OperLogBLL.OperLogDelete <sys_quote_email_tmpl>(tmpl, tmpl.id, userId, OPER_LOG_OBJ_CATE.QUOTE_TEMP, "删除邮件模板");

            return(true);
        }
Exemple #22
0
        /// <summary>
        /// 删除工作组
        /// </summary>
        public bool DeleteGroup(long groupId, long userId)
        {
            sys_workgroup_dal swDal = new sys_workgroup_dal();
            var oldGroup            = swDal.FindNoDeleteById(groupId);

            if (oldGroup == null)
            {
                return(true);
            }
            swDal.SoftDelete(oldGroup, userId);
            OperLogBLL.OperLogDelete <sys_workgroup>(oldGroup, oldGroup.id, userId, DicEnum.OPER_LOG_OBJ_CATE.SYS_WORKGROUP, "");
            var resList = GetGroupResList(oldGroup.id);

            if (resList != null && resList.Count > 0)
            {
                resList.ForEach(_ => {
                    DeleteGroupResource(_.id, userId);
                });
            }
            return(true);
        }
Exemple #23
0
        /// <summary>
        /// 删除联系人
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteContact(long id, long user_id)
        {
            crm_contact contact = GetContact(id);

            if (contact == null)
            {
                return(false);
            }
            if (_dal.SoftDelete(contact, user_id))
            {
                OperLogBLL.OperLogDelete <crm_contact>(contact, contact.id, user_id, OPER_LOG_OBJ_CATE.CONTACTS, "");
            }
            return(true);

            //   该联系人是公司的外包联系人(工单中的外包人员)
            //   该联系人有关联的工单或任务
            //   该联系人在自助服务台创建过工单备注或者附件
            //   该联系人是客户的账单联系人
            //   该联系人是客户的唯一的一个发票邮件接收人
            //    todo  删除校验本期暂时不做     07-13=====08-15
        }
Exemple #24
0
        /// <summary>
        /// 知识库附件管理
        /// </summary>
        public void KnowAttManage(long artId, string attIds, List <AddFileDto> filtList, long userId)
        {
            var caDal = new com_attachment_dal();

            #region 修改原附件
            var oldAttList = new com_attachment_dal().GetAttListByOid(artId);
            if (oldAttList != null && oldAttList.Count > 0)
            {
                var attIdList = attIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var oldAtt in oldAttList)
                {
                    if (!attIdList.Any(_ => _ == oldAtt.id.ToString()))
                    {
                        caDal.SoftDelete(oldAtt, userId);
                        OperLogBLL.OperLogDelete <com_attachment>(oldAtt, oldAtt.id, userId, OPER_LOG_OBJ_CATE.ATTACHMENT, "删除备注附件");
                    }
                }
            }
            #endregion


            #region 新增附件
            if (filtList != null && filtList.Count > 0)
            {
                var attBll = new AttachmentBLL();
                foreach (var thisFile in filtList)
                {
                    if (thisFile.type_id == ((int)DicEnum.ATTACHMENT_TYPE.ATTACHMENT).ToString())
                    {
                        attBll.AddAttachment((int)ATTACHMENT_OBJECT_TYPE.KNOWLEDGE, artId, (int)DicEnum.ATTACHMENT_TYPE.ATTACHMENT, thisFile.new_filename, "", thisFile.old_filename, thisFile.fileSaveName, thisFile.conType, thisFile.Size, userId);
                    }
                    else
                    {
                        attBll.AddAttachment((int)ATTACHMENT_OBJECT_TYPE.KNOWLEDGE, artId, int.Parse(thisFile.type_id), thisFile.new_filename, thisFile.old_filename, null, null, null, 0, userId);
                    }
                }
            }
            #endregion
        }
Exemple #25
0
        /// <summary>
        /// 删除库存仓库
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteLocation(long id, long userId)
        {
            string sql = $"select count(id) from ivt_warehouse_product where warehouse_id={id} and delete_time=0";
            var    cnt = dal.FindSignleBySql <int>(sql);

            if (cnt > 0)
            {
                return(false);
            }

            sql = $"select count(id) from ivt_order_product where order_id in" +
                  $"(select id from ivt_order where status_id<>{(int)DicEnum.PURCHASE_ORDER_STATUS.RECEIVED_FULL} and delete_time=0)" +
                  $" and warehouse_id={id} and delete_time=0";
            cnt = dal.FindSignleBySql <int>(sql);
            if (cnt > 0)
            {
                return(false);
            }

            var lct = dal.FindById(id);

            if (lct == null)
            {
                return(false);
            }
            if (lct.is_default == 1)    // 默认仓库不能删除
            {
                return(false);
            }

            lct.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            lct.delete_user_id = userId;

            dal.Update(lct);
            OperLogBLL.OperLogDelete <ivt_warehouse>(lct, lct.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_LOCATION, "删除库存仓库");
            return(true);
        }
Exemple #26
0
        /// <summary>
        /// 审批设置
        /// </summary>
        public bool ApprovalSet(long resId, string toResIds, long userId, int typeId)
        {
            sys_resource_approver_dal    sraDal  = new sys_resource_approver_dal();
            List <sys_resource_approver> appList = GetApprover(resId, typeId);

            if (appList != null && appList.Count > 0)
            {
                if (!string.IsNullOrEmpty(toResIds))
                {
                    var toResArr = toResIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var toResId in toResArr)
                    {
                        long thisToResId = 0;
                        int  tier        = 1;
                        if (typeId == (int)DicEnum.APPROVE_TYPE.EXPENSE_APPROVE)
                        {
                            long.TryParse(toResId, out thisToResId);
                        }
                        else if (typeId == (int)DicEnum.APPROVE_TYPE.TIMESHEET_APPROVE)
                        {
                            var toResIdArr = toResId.Split('-');
                            if (toResIdArr != null && toResIdArr.Count() == 2)
                            {
                                long.TryParse(toResIdArr[0], out thisToResId);
                                int.TryParse(toResIdArr[1], out tier);
                            }
                        }
                        if (thisToResId == 0)
                        {
                            continue;
                        }
                        sys_resource_approver thisApproval = appList.FirstOrDefault(_ => _.approver_resource_id == resId && _.resource_id == thisToResId);
                        if (thisApproval != null)
                        {
                            if (thisApproval.tier != tier)
                            {
                                thisApproval.tier = tier;
                                EditApproval(thisApproval, userId);
                            }
                            appList.Remove(thisApproval);
                            continue;
                        }
                        thisApproval = new sys_resource_approver()
                        {
                            id = sraDal.GetNextIdCom(),
                            approver_resource_id = resId,
                            resource_id          = thisToResId,
                            approve_type_id      = typeId,
                            tier = tier,
                        };
                        sraDal.Insert(thisApproval);
                        OperLogBLL.OperLogAdd <sys_resource_approver>(thisApproval, thisApproval.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "");
                    }
                }
                if (appList.Count > 0)
                {
                    appList.ForEach(_ => {
                        sraDal.Delete(_);
                        OperLogBLL.OperLogDelete <sys_resource_approver>(_, _.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "");
                    });
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(toResIds))
                {
                    var toResArr = toResIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var toResId in toResArr)
                    {
                        long thisToResId = 0;
                        int  tier        = 1;
                        if (typeId == (int)DicEnum.APPROVE_TYPE.EXPENSE_APPROVE)
                        {
                            long.TryParse(toResId, out thisToResId);
                        }
                        else if (typeId == (int)DicEnum.APPROVE_TYPE.TIMESHEET_APPROVE)
                        {
                            var toResIdArr = toResId.Split('-');
                            if (toResIdArr != null && toResIdArr.Count() == 2)
                            {
                                long.TryParse(toResIdArr[0], out thisToResId);
                                int.TryParse(toResIdArr[1], out tier);
                            }
                        }
                        if (thisToResId == 0)
                        {
                            continue;
                        }
                        sys_resource_approver thisApproval = sraDal.GetApproverByRes(resId, thisToResId, typeId);
                        if (thisApproval != null)
                        {
                            continue;
                        }
                        thisApproval = new sys_resource_approver()
                        {
                            id = sraDal.GetNextIdCom(),
                            approver_resource_id = resId,
                            resource_id          = thisToResId,
                            approve_type_id      = typeId,
                            tier = tier,
                        };
                        sraDal.Insert(thisApproval);
                        OperLogBLL.OperLogAdd <sys_resource_approver>(thisApproval, thisApproval.id, userId, OPER_LOG_OBJ_CATE.RESOURCE, "");
                    }
                }
            }

            return(true);
        }
Exemple #27
0
        /// <summary>
        /// 编辑报价项
        /// </summary>
        /// <param name="quote_item"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Update(crm_quote_item quote_item, Dictionary <long, int> wareDic, long user_id, bool isSaleOrder = false, long?saleOrderId = null)
        {
            if (quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT)
            {
                if (quote_item.unit_price == null || quote_item.unit_cost == null || quote_item.quantity == null || quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (quote_item.discount_percent == null && quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var old_quote_item = _dal.GetQuoteItem(quote_item.id);
            int?oldPeriod      = old_quote_item.period_type_id;

            quote_item.oid            = old_quote_item.oid;
            quote_item.update_user_id = user_id;
            quote_item.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote_item.tax_cate_id    = quote_item.tax_cate_id == 0 ? null : quote_item.tax_cate_id;
            _dal.Update(quote_item);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = (int)user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE_ITEM,
                oper_object_id      = quote_item.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                oper_description    = _dal.CompareValue(old_quote_item, quote_item),
                remark              = "编辑报价项信息"
            });

            var oDal = new crm_opportunity_dal();
            var oppo = oDal.GetOpByItemID(quote_item.id);

            if (oppo != null && oppo.use_quote == 1)
            {
                if (quote_item.optional != 1 && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES)
                {
                    decimal?changeRevenue = quote_item.quantity * quote_item.unit_price;
                    decimal?changeCost    = quote_item.quantity * quote_item.unit_cost;

                    decimal?oldChangeRevenue = old_quote_item.quantity * ((old_quote_item.unit_price ?? 0) - (old_quote_item.unit_discount ?? 0));
                    decimal?oldChangeCost    = old_quote_item.quantity * old_quote_item.unit_cost;
                    switch (oldPeriod)
                    {
                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.MONTH:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.QUARTER:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.HALFYEAR:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.YEAR:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    default:
                        break;
                    }

                    switch (quote_item.period_type_id)
                    {
                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME:
                        oppo.one_time_revenue += (changeRevenue ?? 0);
                        oppo.one_time_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.MONTH:
                        oppo.monthly_revenue += (changeRevenue ?? 0);
                        oppo.monthly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.QUARTER:
                        oppo.quarterly_revenue += (changeRevenue ?? 0);
                        oppo.quarterly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.HALFYEAR:
                        oppo.semi_annual_revenue += (changeRevenue ?? 0);
                        oppo.semi_annual_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.YEAR:
                        oppo.yearly_revenue += (changeRevenue ?? 0);
                        oppo.yearly_cost    += (changeCost ?? 0);
                        break;

                    default:
                        break;
                    }

                    // var udfDto = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.OPPORTUNITY);
                    // var udfValue =
                    OpportunityAddOrUpdateDto param = new OpportunityAddOrUpdateDto()
                    {
                        general = oppo,
                        udf     = null,
                        notify  = null
                    };
                    new OpportunityBLL().Update(param, user.id);
                }
            }


            if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
            {
                var irDal        = new ivt_reserve_dal();
                var iwDal        = new ivt_warehouse_dal();
                var oldReserList = irDal.GetListByItemId(quote_item.id);
                if (wareDic != null && wareDic.Count > 0)
                {
                    if (oldReserList != null && oldReserList.Count > 0)
                    {
                        foreach (var thisPageWare in wareDic)
                        {
                            var thisWareHouse = iwDal.FindNoDeleteById(thisPageWare.Key);

                            var thisOldReser = oldReserList.FirstOrDefault(_ => _.warehouse_id == thisPageWare.Key);
                            if (thisOldReser != null)
                            {
                                oldReserList.Remove(thisOldReser);
                                if (thisWareHouse != null)
                                {
                                    if (thisPageWare.Value == 0)
                                    {
                                        irDal.SoftDelete(thisOldReser, user_id);
                                        OperLogBLL.OperLogDelete <ivt_reserve>(thisOldReser, thisOldReser.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除库存预留");
                                        continue;
                                    }
                                    if (thisOldReser.quantity != thisPageWare.Value || thisOldReser.resource_id != thisWareHouse.resource_id)
                                    {
                                        thisOldReser.quantity    = thisPageWare.Value;
                                        thisOldReser.resource_id = thisWareHouse.resource_id;
                                        var thisOld = irDal.FindNoDeleteById(thisOldReser.id);
                                        irDal.Update(thisOldReser);
                                        OperLogBLL.OperLogUpdate <ivt_reserve>(thisOldReser, thisOld, thisOldReser.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "修改库存预留");
                                    }
                                }
                            }
                            else
                            {
                                if (thisWareHouse != null && thisPageWare.Value != 0)
                                {
                                    var thisReserve = new ivt_reserve()
                                    {
                                        id             = irDal.GetNextIdCom(),
                                        create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                        update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                        create_user_id = user_id,
                                        update_user_id = user_id,
                                        quote_item_id  = quote_item.id,
                                        warehouse_id   = thisPageWare.Key,
                                        quantity       = thisPageWare.Value,
                                        resource_id    = thisWareHouse.resource_id,
                                    };
                                    irDal.Insert(thisReserve);
                                    OperLogBLL.OperLogAdd <ivt_reserve>(thisReserve, thisReserve.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "新增库存预留");
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (var thisPageWare in wareDic)
                        {
                            var thisWareHouse = iwDal.FindNoDeleteById(thisPageWare.Key);
                            if (thisWareHouse != null)
                            {
                                var thisReserve = new ivt_reserve()
                                {
                                    id             = irDal.GetNextIdCom(),
                                    create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                    update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                    create_user_id = user_id,
                                    update_user_id = user_id,
                                    quote_item_id  = quote_item.id,
                                    warehouse_id   = thisPageWare.Key,
                                    quantity       = thisPageWare.Value,
                                    resource_id    = thisWareHouse.resource_id,
                                };
                                irDal.Insert(thisReserve);
                                OperLogBLL.OperLogAdd <ivt_reserve>(thisReserve, thisReserve.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "新增库存预留");
                            }
                        }
                    }
                }

                if (oldReserList != null && oldReserList.Count > 0)
                {
                    oldReserList.ForEach(_ =>
                    {
                        irDal.SoftDelete(_, user_id);
                        OperLogBLL.OperLogDelete <ivt_reserve>(_, _.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除库存预留");
                    });
                }
            }


            if (isSaleOrder && saleOrderId != null && (quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.PRODUCT || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DEGRESSION || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES))
            {
                var cccDal   = new ctt_contract_cost_dal();
                var thisCost = cccDal.GetSinBuQuoteItem(quote_item.id);
                if (thisCost != null)
                {
                    long?product_id   = thisCost.product_id;
                    int  status_id    = thisCost.status_id;
                    long cost_code_id = thisCost.cost_code_id;
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        product_id = quote_item.object_id;
                        status_id  = thisCost.status_id;
                        var thisProduct = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        if (thisProduct != null)
                        {
                            cost_code_id = thisProduct.cost_code_id;
                        }
                        else
                        {
                            return(ERROR_CODE.ERROR);
                        }
                        if (status_id != (int)COST_STATUS.UNDETERMINED && status_id != (int)COST_STATUS.PENDING_APPROVAL && status_id != (int)COST_STATUS.CANCELED)
                        {
                            if (thisCost.quantity != quote_item.quantity)
                            {
                                status_id = (int)COST_STATUS.PENDING_PURCHASE;
                                var appSet = new SysSettingBLL().GetSetById(DTO.SysSettingEnum.CTT_COST_APPROVAL_VALUE);
                                if (appSet != null && !string.IsNullOrEmpty(appSet.setting_value) && thisProduct.does_not_require_procurement == 0)
                                {
                                    if (((decimal)quote_item.quantity * (decimal)quote_item.unit_price) > decimal.Parse(appSet.setting_value)) // 金额超出(待审批)
                                    {
                                        status_id = (int)COST_STATUS.PENDING_APPROVAL;
                                    }
                                }
                            }
                        }
                    }
                    thisCost.product_id   = product_id;
                    thisCost.cost_code_id = cost_code_id;
                    thisCost.name         = quote_item.name;
                    thisCost.description  = quote_item.description;
                    thisCost.unit_price   = (quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0);
                    thisCost.unit_cost    = quote_item.unit_cost;
                    thisCost.quantity     = quote_item.quantity;
                    thisCost.status_id    = status_id;

                    var olderCost = cccDal.FindNoDeleteById(thisCost.id);
                    cccDal.Update(thisCost);
                    OperLogBLL.OperLogUpdate <ctt_contract_cost>(thisCost, olderCost, thisCost.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_COST, "修改成本");
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        var ccBll          = new ContractCostBLL();
                        var irDal          = new ivt_reserve_dal();
                        var thisPro        = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        var thisProResList = irDal.GetListByItemId(quote_item.id);
                        if (thisProResList != null && thisProResList.Count > 0 && thisPro != null)
                        {
                            foreach (var thisProRes in thisProResList)
                            {
                                ccBll.AddCostProduct(thisCost.id, thisPro.id, thisProRes.warehouse_id, thisProRes.quantity, "", "", user.id);

                                irDal.SoftDelete(thisProRes, user.id);
                                OperLogBLL.OperLogDelete <ivt_reserve>(thisProRes, thisProRes.id, user.id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除产品预留");
                            }
                            ccBll.ChangCostStatus(thisCost.id, user_id);
                        }
                    }
                }
            }

            return(ERROR_CODE.SUCCESS);
        }
Exemple #28
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);
        }
Exemple #29
0
        /// <summary>
        /// /撤销成本审批
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public ERROR_CODE Revoke_CHARGES(long user_id, string ids, out string re)
        {
            re = string.Empty;
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {   // 查询不到用户,用户丢失
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var cadDal = new crm_account_deduction_dal();
            var sweDal = new sdk_work_entry_dal();
            crm_account_deduction  cad         = new crm_account_deduction();
            ctt_contract_block     ccb         = new ctt_contract_block();
            ctt_contract_cost      ccc         = new ctt_contract_cost();
            ctt_contract_cost_dal  ccc_dal     = new ctt_contract_cost_dal();
            ctt_contract_block_dal ccb_dal     = new ctt_contract_block_dal();
            StringBuilder          returnvalue = new StringBuilder();

            //该条目已经生成发票(发票ID:发票ID),请先作废该发票
            if (!string.IsNullOrEmpty(ids))
            {
                var timeNow = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                var idList  = ids.Split(',');
                foreach (var id in idList)
                {
                    var oldcad = cad = GetAccountDed(long.Parse(id));

                    if (cad != null)
                    {
                        if (cad.object_id != null)
                        {
                            var cadList = cadDal.GetListByObjectId((long)cad.object_id);
                            if (cadList != null && cadList.Count > 0)
                            {
                                foreach (var thisCad in cadList)
                                {
                                    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(id + "条目已经生成发票(发票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 oldccc = ccc = ccc_dal.FindNoDeleteById((long)cad.object_id);
                                    if (ccc != null)
                                    {
                                        // var oldSwe = sweDal.FindNoDeleteById((long)cad.object_id);
                                        ccc.update_time    = timeNow;
                                        ccc.update_user_id = user.id;
                                        ccc.bill_status    = 0;
                                        ccc.extended_price = ccc.unit_price * ccc.quantity;
                                        ccc_dal.Update(ccc);
                                        OperLogBLL.OperLogUpdate <ctt_contract_cost>(ccc, oldccc, ccc.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_COST, "修改合同成本");
                                    }
                                }
                            }
                            else
                            {
                                re = returnvalue.ToString();
                            }
                        }
                    }


                    #region 原有的撤销成本审批相关逻辑
                    //if (cad.invoice_id != null)
                    //{
                    //    var ci = new ctt_invoice_dal().FindNoDeleteById((long)cad.invoice_id);
                    //    if (ci.is_voided != 1)
                    //    {
                    //        returnvalue.Append(id + "条目已经生成发票(发票ID:" + cad.invoice_id + "),请先作废该发票\n");
                    //    }
                    //}
                    //else
                    //{
                    //    cad.delete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //    cad.delete_user_id = user.id;
                    //    var add1_log = new sys_oper_log()
                    //    {
                    //        user_cate = "用户",
                    //        user_id = (int)user.id,
                    //        name = user.name,
                    //        phone = user.mobile == null ? "" : user.mobile,
                    //        oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    //        oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION,
                    //        oper_object_id = cad.id,// 操作对象id
                    //        oper_type_id = (int)OPER_LOG_TYPE.DELETE,
                    //        oper_description = cad_dal.CompareValue(oldcad, cad),
                    //        remark = "删除审批并提交"
                    //    };          // 创建日志
                    //    new sys_oper_log_dal().Insert(add1_log);       // 插入日志
                    //    if (!cad_dal.Update(cad))
                    //    {
                    //        return ERROR_CODE.ERROR;
                    //    }
                    //    //合同成本
                    //    var oldccc = ccc = ccc_dal.FindSignleBySql<ctt_contract_cost>($"select * from ctt_contract_cost where id={cad.object_id} and delete_time=0");
                    //    if (ccc != null)
                    //    {
                    //        ccc.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //        ccc.update_user_id = user.id;
                    //        ccc.bill_status = 0;
                    //        ccc.extended_price = ccc.unit_price * ccc.quantity;
                    //        var add_log = new sys_oper_log()
                    //        {
                    //            user_cate = "用户",
                    //            user_id = (int)user.id,
                    //            name = user.name,
                    //            phone = user.mobile == null ? "" : user.mobile,
                    //            oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    //            oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.CONTRACT_COST,
                    //            oper_object_id = ccc.id,// 操作对象id
                    //            oper_type_id = (int)OPER_LOG_TYPE.UPDATE,
                    //            oper_description = cad_dal.CompareValue(oldccc, ccc),
                    //            remark = "修改合同成本"
                    //        };          // 创建日志
                    //        new sys_oper_log_dal().Insert(add_log);       // 插入日志
                    //        if (!ccc_dal.Update(ccc))
                    //        {
                    //            return ERROR_CODE.ERROR;
                    //        }
                    //        if (cad.contract_block_id != null)
                    //        {
                    //            //合同预付
                    //            var oldccb = ccb = ccb_dal.FindSignleBySql<ctt_contract_block>($" select * from ctt_contract_block where id={cad.contract_block_id} and delete_time=0");
                    //            if (ccb != null)
                    //            {
                    //                ccb.is_billed = 0;
                    //                ccb.status_id = 1;
                    //                ccb.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //                ccb.update_user_id = user.id;
                    //                var add3_log = new sys_oper_log()
                    //                {
                    //                    user_cate = "用户",
                    //                    user_id = (int)user.id,
                    //                    name = user.name,
                    //                    phone = user.mobile == null ? "" : user.mobile,
                    //                    oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    //                    oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.CONTRACT_BLOCK,
                    //                    oper_object_id = ccc.id,// 操作对象id
                    //                    oper_type_id = (int)OPER_LOG_TYPE.UPDATE,
                    //                    oper_description = cad_dal.CompareValue(oldccb, ccb),
                    //                    remark = "修改合同预付"
                    //                };          // 创建日志
                    //                new sys_oper_log_dal().Insert(add3_log);       // 插入日志
                    //                if (!ccb_dal.Update(ccb))
                    //                {
                    //                    return ERROR_CODE.ERROR;
                    //                }
                    //            }
                    //        }
                    //    }

                    //}
                    #endregion
                }
            }
            if (!string.IsNullOrEmpty(returnvalue.ToString()))
            {
                re = returnvalue.ToString();
                return(ERROR_CODE.EXIST);
            }
            return(ERROR_CODE.SUCCESS);
        }
Exemple #30
0
        /// <summary>
        /// 新增报价项
        /// </summary>
        /// <param name="quote_item"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Insert(crm_quote_item quote_item, Dictionary <long, int> wareDic, long user_id, bool isSaleOrder = false, long?saleOrderId = null)
        {
            if (quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT)
            {
                if (quote_item.unit_price == null || quote_item.unit_cost == null || quote_item.quantity == null || quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (quote_item.discount_percent == null && quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }

            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {
                return(ERROR_CODE.USER_NOT_FIND);
            }
            quote_item.id             = _dal.GetNextIdCom();
            quote_item.tax_cate_id    = quote_item.tax_cate_id == 0 ? null : quote_item.tax_cate_id;
            quote_item.period_type_id = quote_item.period_type_id == 0 ? null : quote_item.period_type_id;
            quote_item.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote_item.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote_item.create_user_id = user_id;
            quote_item.update_user_id = user_id;

            _dal.Insert(quote_item);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = (int)user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE_ITEM,
                oper_object_id      = quote_item.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                oper_description    = _dal.AddValue(quote_item),
                remark              = "保存报价项信息"
            });

            var oDal = new crm_opportunity_dal();
            var oppo = oDal.GetOpByItemID(quote_item.id);

            if (oppo != null && oppo.use_quote == 1)
            {
                if (quote_item.optional != 1 && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES)
                {
                    decimal?changeRevenue = quote_item.quantity * ((quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0));
                    decimal?changeCost    = quote_item.quantity * quote_item.unit_cost;

                    switch (quote_item.period_type_id)
                    {
                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME:
                        oppo.one_time_revenue += (changeRevenue ?? 0);
                        oppo.one_time_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.MONTH:
                        oppo.monthly_revenue += (changeRevenue ?? 0);
                        oppo.monthly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.QUARTER:
                        oppo.quarterly_revenue += (changeRevenue ?? 0);
                        oppo.quarterly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.HALFYEAR:
                        oppo.semi_annual_revenue += (changeRevenue ?? 0);
                        oppo.semi_annual_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.YEAR:
                        oppo.yearly_revenue += (changeRevenue ?? 0);
                        oppo.yearly_cost    += (changeCost ?? 0);
                        break;

                    default:
                        break;
                    }

                    // var udfDto = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.OPPORTUNITY);
                    // var udfValue =
                    OpportunityAddOrUpdateDto param = new OpportunityAddOrUpdateDto()
                    {
                        general = oppo,
                        udf     = null,
                        notify  = null
                    };
                    new OpportunityBLL().Update(param, user.id);
                }
            }
            if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
            {
                if (wareDic != null && wareDic.Count > 0)
                {
                    var irDal = new ivt_reserve_dal();
                    var iwDal = new ivt_warehouse_dal();
                    foreach (var thisPageWare in wareDic)
                    {
                        var thisWareHouse = iwDal.FindNoDeleteById(thisPageWare.Key);
                        if (thisWareHouse != null && thisPageWare.Value != 0)
                        {
                            var thisReserve = new ivt_reserve()
                            {
                                id             = irDal.GetNextIdCom(),
                                create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                create_user_id = user_id,
                                update_user_id = user_id,
                                quote_item_id  = quote_item.id,
                                warehouse_id   = thisPageWare.Key,
                                quantity       = thisPageWare.Value,
                                resource_id    = thisWareHouse.resource_id,
                            };
                            irDal.Insert(thisReserve);
                            OperLogBLL.OperLogAdd <ivt_reserve>(thisReserve, thisReserve.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "新增库存预留");
                        }
                    }
                }
            }

            if (isSaleOrder && saleOrderId != null && (quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.PRODUCT || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DEGRESSION || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES))
            {
                var cccDal   = new ctt_contract_cost_dal();
                var costList = cccDal.GetListBySaleOrderId((long)saleOrderId);
                if (costList != null && costList.Count > 0)
                {
                    int  status_id    = 0;
                    long cost_code_id = (long)quote_item.object_id;
                    long?product_id   = null;
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        product_id = quote_item.object_id;
                        status_id  = (int)COST_STATUS.PENDING_PURCHASE;
                        var thisProduct = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        if (thisProduct != null)
                        {
                            cost_code_id = thisProduct.cost_code_id;
                        }
                        else
                        {
                            return(ERROR_CODE.ERROR);
                        }
                        var appSet = new SysSettingBLL().GetSetById(DTO.SysSettingEnum.CTT_COST_APPROVAL_VALUE);
                        if (appSet != null && !string.IsNullOrEmpty(appSet.setting_value) && thisProduct.does_not_require_procurement == 0) // 该产品走采购流程,并且价格大于设置,则带审批
                        {
                            if (((decimal)quote_item.quantity * (decimal)quote_item.unit_price) > decimal.Parse(appSet.setting_value))      // 金额超出(待审批)
                            {
                                status_id = (int)COST_STATUS.PENDING_APPROVAL;
                            }
                        }
                    }
                    else
                    {
                        status_id = (int)COST_STATUS.PENDING_DELIVERY;
                    }
                    ctt_contract_cost cost = new ctt_contract_cost()
                    {
                        id             = _dal.GetNextIdCom(),
                        opportunity_id = costList[0].opportunity_id,
                        quote_item_id  = quote_item.id,
                        cost_code_id   = cost_code_id,
                        product_id     = product_id,
                        name           = quote_item.name,
                        description    = quote_item.description,
                        date_purchased = DateTime.Now,
                        is_billable    = 1,
                        bill_status    = 0,
                        cost_type_id   = (int)COST_TYPE.OPERATIONA,
                        status_id      = status_id,
                        quantity       = quote_item.quantity ?? 0,
                        unit_price     = (quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0),
                        unit_cost      = quote_item.unit_cost,
                        extended_price = ((quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0)) * quote_item.quantity,
                        create_user_id = user.id,
                        update_user_id = user.id,
                        create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                        update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                        project_id     = costList[0].project_id,
                        contract_id    = costList[0].contract_id,
                        task_id        = costList[0].task_id,
                        sub_cate_id    = costList[0].sub_cate_id,
                    };
                    cccDal.Insert(cost);
                    OperLogBLL.OperLogAdd <ctt_contract_cost>(cost, cost.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_COST, "新增成本");
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        var ccBll          = new ContractCostBLL();
                        var irDal          = new ivt_reserve_dal();
                        var thisPro        = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        var thisProResList = irDal.GetListByItemId(quote_item.id);
                        if (thisProResList != null && thisProResList.Count > 0 && thisPro != null)
                        {
                            foreach (var thisProRes in thisProResList)
                            {
                                ccBll.AddCostProduct(cost.id, thisPro.id, thisProRes.warehouse_id, thisProRes.quantity, "", "", user.id);

                                irDal.SoftDelete(thisProRes, user.id);
                                OperLogBLL.OperLogDelete <ivt_reserve>(thisProRes, thisProRes.id, user.id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除产品预留");
                            }
                            ccBll.ChangCostStatus(cost.id, user_id);
                        }
                    }
                }
            }

            return(ERROR_CODE.SUCCESS);
        }