/// <summary> /// 撤销核销处理 /// </summary> public void RHXCancel(InvoiceOperation entity, int p_DtsID, IDBTransAccess sqlTrans) { try { string sql = string.Empty; //First 处理发票主表数据 InvoiceOperation entityinvoice = new InvoiceOperation(sqlTrans);//处理收付款主表数据 entityinvoice.ID = entity.ID; entityinvoice.SelectByID(); //Second 删除发票核销明细数据 InvoiceOperationDtsRule dtsRule = new InvoiceOperationDtsRule(); InvoiceOperationDts entityDts = new InvoiceOperationDts(sqlTrans); entityDts.ID = p_DtsID; entityDts.SelectByID(); if (entityDts.PayAmount != 0) { throw new Exception("不能操作,数据有收付款数据了,不能进行撤销"); } dtsRule.RDelete(entityDts, sqlTrans);//删除明细实体 //First 处理发票主表数据 entityinvoice.PreHXFlag = (int)YesOrNo.No; entityinvoice.PreHXQty -= entityDts.DInvoiceQty; entityinvoice.PreHXAmount -= entityDts.DInvoiceAmount; this.RUpdate(entityinvoice, sqlTrans); IOFormDtsRule ioformdtsRule = new IOFormDtsRule(); //处理出入库单据明细数据 IOFormDts entityIOF = new IOFormDts(sqlTrans); //出入库单据明细 entityIOF.ID = entityDts.DLOADDtsID; entityIOF.SelectByID(); //处理发票明细数据;出入库明细数据 if (entityIOF.PayAmount != 0) { throw new Exception("不能操作,数据已有收付款数据 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); } sql = "UPDATE WH_IOFormDts SET InvoiceQty=ISNULL(InvoiceQty,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceQty) + ")"; sql += ",InvoiceAmount=ISNULL(InvoiceAmount,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceAmount) + ")"; sql += ",DtsInvoiceDelOPID=" + SysString.ToDBString(entity.SaleOPID); sql += ",DtsInvoiceDelTime=null"; sql += ",DtsInvoiceNo=''"; sql += ",DtsInvoiceDelFlag=0";//开票完成标志 sql += " WHERE ID=" + SysString.ToDBString(entityDts.DLOADDtsID); sqlTrans.ExecuteNonQuery(sql); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 修改 /// </summary> /// <param name="p_BE">要修改的实体</param> /// <param name="sqlTrans">事务类</param> public void RUpdate(BaseEntity p_BE, BaseEntity[] p_BE2, BaseEntity[] p_BE3, IDBTransAccess sqlTrans) { try { this.RUpdate(p_BE, sqlTrans); InvoiceOperationDtsRule ruledts = new InvoiceOperationDtsRule(); ruledts.RSave2((InvoiceOperation)p_BE, p_BE2, p_BE3, sqlTrans);//保存从表 } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 核销处理 /// </summary> public void RHX(InvoiceOperation entity, InvoiceOperationDts entityDts, IDBTransAccess sqlTrans) { try { string sql = string.Empty; //First 处理发票主表数据 InvoiceOperation entityinvoice = new InvoiceOperation(sqlTrans);//处理收付款主表数据 entityinvoice.ID = entity.ID; entityinvoice.SelectByID(); if (entityinvoice.PreHXAmount + entityDts.DInvoiceAmount > entityinvoice.TotalAmount) { throw new Exception("不能操作,核销金额超过了开票未核金额"); } if (entityinvoice.PreHXQty + entityDts.DInvoiceQty > entityinvoice.TotalQty) { throw new Exception("不能操作,核销数量超过了开票未核数量"); } if (entityinvoice.PreHXAmount + entityDts.DInvoiceAmount == entityinvoice.TotalAmount) { entityinvoice.PreHXFlag = (int)YesOrNo.Yes; } entityinvoice.PreHXQty += entityDts.DInvoiceQty; entityinvoice.PreHXAmount += entityDts.DInvoiceAmount; this.RUpdate(entityinvoice, sqlTrans); //Second IOFormDtsRule ioformdtsRule = new IOFormDtsRule(); //处理出入库单据明细数据 IOFormDts entityIOF = new IOFormDts(sqlTrans); //出入库单据明细 entityIOF.ID = entityDts.DLOADDtsID; entityIOF.SelectByID(); if (entityIOF.DtsInvoiceDelFlag == (int)YesOrNo.Yes) { throw new Exception("不能操作,数据已开票结束 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); } if (entityDts.DInvoiceQty + entityIOF.InvoiceQty > entityIOF.DZQty || entityDts.DInvoiceAmount + entityIOF.InvoiceAmount > entityIOF.DZAmount)//开票溢出 { throw new Exception("不能操作,开票数超过对账数 或 开票金额超过对账金额 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); } sql = "UPDATE WH_IOFormDts SET InvoiceQty=ISNULL(InvoiceQty,0)+" + "(" + SysString.ToDBString(entityDts.DInvoiceQty) + ")"; sql += ",InvoiceAmount=ISNULL(InvoiceAmount,0)+" + "(" + SysString.ToDBString(entityDts.DInvoiceAmount) + ")"; sql += ",DtsInvoiceDelOPID=" + SysString.ToDBString(entity.SaleOPID); sql += ",DtsInvoiceDelTime=" + SysString.ToDBString(entity.FormDate.ToString("yyyy-MM-dd")); sql += ",DtsInvoiceNo=" + SysString.ToDBString(entity.InvoiceNO); if (entityDts.DInvoiceAmount + entityIOF.InvoiceAmount >= entityIOF.DZAmount)//开票完成 { sql += ",DtsInvoiceDelFlag=1"; } else { sql += ",DtsInvoiceDelFlag=0"; } sql += " WHERE ID=" + SysString.ToDBString(entityDts.DLOADDtsID); sqlTrans.ExecuteNonQuery(sql); InvoiceOperationDtsRule dtsRule = new InvoiceOperationDtsRule(); entityDts.MainID = entity.ID; entityDts.Seq = SysConvert.ToInt32(sqlTrans.Fill("SELECT ISNULL(MAX(Seq),0)+1 FROM Finance_InvoiceOperationDts WHERE MainID=" + entity.ID).Rows[0][0]);//取最大的MAXSEQ值 dtsRule.RAdd(entityDts, sqlTrans); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }