示例#1
0
 public ResponseDocDelete DocDelete([FromBody] RequestDocDelete request)
 {
     try
     {
         DocBLL bll = new DocBLL();
         return(bll.DocDelete(request));
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(
                   Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
示例#2
0
        public ResponseDocDelete DocDelete(RequestDocDelete request)
        {
            ResponseDocDelete response = new ResponseDocDelete();

            using (cnn = GetConnection())
            {
                var ts = cnn.BeginTransaction();
                try
                {
                    BalanceBLL     balanceBLL = new BalanceBLL(cnn);
                    var            user       = this.UserInfoGet(request.Token, ts);
                    FixedAssetsBLL fixBLL     = new FixedAssetsBLL(cnn);
                    var            flag       = fixBLL.IsDocHasChangeRecord(request.Data.Id, ts);
                    if (flag)
                    {
                        //取消此判断 update by Hero.Zhang 20180404
                        //throw new NormalException("该凭证通过固定资产生成,无法删除");
                    }


                    string sql     = @"select * from tks_fas_doc where id=@Id";
                    var    DocDate = cnn.Query(sql, new { Id = request.Data.Id }, ts);
                    if (DocDate.Count() <= 0)
                    {
                        throw new NormalException("该凭证已经删除");
                    }
                    var       data   = cnn.QueryFirst <TKS_FAS_Doc>(sql, new { Id = request.Data.Id }, ts);
                    PeriodBLL period = new PeriodBLL(cnn);
                    flag = period.IsPeriodPaid(data.PeriodId, ts);
                    if (flag)
                    {
                        throw new NormalException("该凭证已经期末结转,无法删除");
                    }
                    #region 先回滚余额表 Hero.Zhang
                    List <TKS_FAS_DocDetail> Detail = cnn.Query <TKS_FAS_DocDetail>("select *  from TKS_FAS_DocDetail where parentId=@ParentId", new { ParentId = request.Data.Id }, ts).ToList();
                    var doc = cnn.QueryFirst <TKS_FAS_Doc>("select * from TKS_FAS_Doc where id=@Id",
                                                           new { Id = request.Data.Id }, ts);
                    RequestDocAdd oldDoc = new RequestDocAdd();
                    oldDoc.Head   = doc;
                    oldDoc.Detail = Detail;
                    foreach (var det in oldDoc.Detail)
                    {
                        det.Money_Debit  = -1 * det.Money_Debit;
                        det.Money_Credit = -1 * det.Money_Credit;
                        det.Quantity     = -1 * det.Quantity;
                    }
                    balanceBLL.UpdateBalance(oldDoc, ts, user);
                    #endregion

                    sql = @" delete from TKS_FAS_Doc where id=@Id";

                    cnn.Execute(sql, request.Data, ts);

                    sql = "delete from TKS_FAS_DocDetail where parentId=@ParentId";
                    cnn.Execute(sql, new { ParentId = request.Data.Id }, ts);

                    //发票状态置为 递交财务
                    sql = "update tks_fas_invoice set status=1 where pzId=@PZId and AccountId=@AccountId";
                    cnn.Execute(sql, new { PZId = data.Id, AccountId = data.AccountId }, ts);

                    sql = "delete from TKS_FAS_TPL2PZ where pzId=@PZID and AccountId=@AccountId ";
                    cnn.Execute(sql, new { PZID = data.Id, AccountId = data.AccountId }, ts);
                    // add by Hero.Zhang 20180404

                    /*判断次凭证号是否在变更记录及生成凭证表TKS_FAS_FixedAssetsChange中,如果存在,则
                     * 将这笔数据还原成新增并且没有生成凭证的状态;同时将固定资产表TKS_FAS_FixedAssets中这笔固定资产变更为‘未生成凭证状态’,同时将折旧相关数据回冲一个月*/
                    var check     = "select * from TKS_FAS_FixedAssetsChange where docid=@docid and AccountId=@AccountId";
                    var datacheck = cnn.Query(check, new { docid = data.Id, AccountId = data.AccountId }, ts);
                    if (datacheck.Count() > 0)
                    {
                        var dataUpdate = cnn.QueryFirst <TKS_FAS_FixedAssetsChange>(check, new { docid = data.Id, AccountId = data.AccountId }, ts);
                        if (dataUpdate != null)
                        {
                            sql = "update TKS_FAS_FixedAssetsChange set ChangeType=1,DocId='',DocPZZ='' where id=@id  and AccountId=@AccountId";
                            //cnn.Execute(sql, new { id = request.TKS_FAS_FixedAssetsChange_Id, AccountId = data.AccountId }, ts);
                            cnn.Execute(sql, new { id = dataUpdate.Id, AccountId = data.AccountId }, ts);
                            sql = "update TKS_FAS_FixedAssets set IsGenPZ=0 where id=@id  and AccountId=@AccountId";
                            //cnn.Execute(sql, new { id = request.TKS_FAS_FixedAssets_Id, AccountId = data.AccountId }, ts);
                            cnn.Execute(sql, new { id = dataUpdate.ParentId, AccountId = data.AccountId }, ts);
                        }
                    }
                    //add by Hero.Zhang 20180903 删除计提折旧凭证,回滚固定资产计提折旧数据
                    if (data.Source == PZType.GD.ToString())
                    {
                        //add by Hero.Zhang 删除折旧凭证判断,如果改凭证的日期之后有折旧凭证,则不允许删除
                        var checkPZ = @"select * from tks_fas_doc where source='GD' and PZDate>@PZDate AND AccountId=@AccountId";
                        var PZcheck = cnn.Query(checkPZ, new { PZDate = data.PZDate, AccountId = data.AccountId }, ts);
                        if (PZcheck.Count() > 0)
                        {
                            throw new NormalException("该计提折旧凭证无法删除,请先删除下一个期间的计提折旧凭证");
                        }

                        //回滚固定资产
                        fixBLL.RollbackFixedAssets(user.AccountId, data.PeriodId, ts);
                    }
                    ts.Commit();
                    response.IsSuccess = true;
                    response.Message   = "删除成功";
                    return(response);
                }
                catch (Exception ex)
                {
                    ts.Rollback();
                    return(this.DealException(response, ex) as ResponseDocDelete);
                }
            }
        }