eas bos单据预算查询

 其中有两种情况,一种是dep单据获取方法:

        IDynamicObject instance = DynamicObjectFactory.getLocalInstance(ctx); //用于动态获取单据对象
        info = instance.getValue(uuid.getType(), new ObjectUuidPK(uuid),sic2); //记账单对象

另外一种是标准单据或者自己做的单据:

        通过单据id或者为对象赋值来查询预算

 //报销预算查询
    @Override
    protected String _budgetQuery(Context ctx, String jsonData)
    		throws BOSException, EASBizException {

    	AjaxJson j = new AjaxJson();
    	try {
    		if (!validator.validate(jsonData)) {
    			throw new EASBizException(new NumericExceptionSubItem("100","Json数据格式有误!"));
    		}

    System.out.println("预算查询入参:" + jsonData);
    JSONObject jo = JSONObject.parseObject(jsonData);
    if (jo == null) {
		throw new EASBizException(new NumericExceptionSubItem("100","jsonData数据格式有误!"));
	}
    //单据ID
    String id = jo.getString("id");
    verifyFieldNotNull("单据ID", id);
   
    //获取UUID
    BOSUuid uuid = BOSUuid.read(id);
    BOSObjectType  objectType = uuid.getType();
    boolean flag = false;
    if (objectType.toString().equals("AE13E073")) {//薪酬报账单
    	 j.getData().put("noBudget", flag);//返回结果 noBudget此字段是本人返回给前端是否有预算的一个提示,如果你不需要用到此提示可以忽略。
    	 return j.getJsonStr();
	}else if (objectType.toString().equals("D001019A")) { //付款申请单
		 j.getData().put("noBudget", flag);//返回结果
    	 return j.getJsonStr();
	}else if (objectType.toString().equals("8110AAB2")) { //借款单
		 j.getData().put("noBudget", flag);//返回结果
    	 return j.getJsonStr();
	}else if (objectType.toString().equals("8FD159FE")) { //收入报账单
		 j.getData().put("noBudget", flag);//返回结果
    	 return j.getJsonStr();
	}
    IBudgetCtrlFacade balance = BudgetCtrlUtil.getBudgetCtrlFacadeImpl(ctx);
    BgCtrlResultCollection  ctrlResultCol = null;
    IObjectValue info = null;
    if (objectType.toString().equals("F1C85B33")) {//通用报账单
    	 SelectorItemCollection sic = new SelectorItemCollection();
    	    sic.add(new SelectorItemInfo("*"));
    	    sic.add(new SelectorItemInfo("company.*"));
    	    sic.add(new SelectorItemInfo("entrys.*"));
    	    sic.add(new SelectorItemInfo("entrys.currency.*"));
    	    sic.add(new SelectorItemInfo("entrys.expensetype.*"));
    	 //公司 
    	String companyStr = jo.getString("company");
    	verifyFieldNotNull("公司", companyStr);
    	CompanyOrgUnitInfo company =(CompanyOrgUnitInfo) BillProertiesConvertor.getValueObject(companyStr, CompanyOrgUnitInfo.class, null, ctx);
    	verifyFieldNotNull("company", company);
    	ctx.put(OrgType.Company, company);
    	IDynamicObject instance = DynamicObjectFactory.getLocalInstance(ctx); //用于动态获取单据对象
    	info = instance.getValue(uuid.getType(), new ObjectUuidPK(uuid),sic); //报账单对象
    	ctrlResultCol = balance.getBudget(info);
	}
    
    if (objectType.toString().equals("78D5CA77")) {//记账单对象
    	SelectorItemCollection sic2 = new SelectorItemCollection();
        sic2.add(new SelectorItemInfo("*"));
        sic2.add(new SelectorItemInfo("company.*"));
        sic2.add(new SelectorItemInfo("currency.*"));
        sic2.add(new SelectorItemInfo("entrys.*"));
        sic2.add(new SelectorItemInfo("entrys.account.*"));
    	 //公司 
    	String companyStr = jo.getString("company");
    	verifyFieldNotNull("公司", companyStr);
    	CompanyOrgUnitInfo company =(CompanyOrgUnitInfo) BillProertiesConvertor.getValueObject(companyStr, CompanyOrgUnitInfo.class, null, ctx);
    	verifyFieldNotNull("company", company);
    	ctx.put(OrgType.Company, company);
    	IDynamicObject instance = DynamicObjectFactory.getLocalInstance(ctx); //用于动态获取单据对象
    	info = instance.getValue(uuid.getType(), new ObjectUuidPK(uuid),sic2); //记账单对象
    	ctrlResultCol = balance.getBudget(info);
	}
    
    if (objectType.toString().equals("C57003BC")) {//差旅费报销单对象
    	SelectorItemCollection sic = new SelectorItemCollection();
	    sic.add(new SelectorItemInfo("*"));
	    sic.add(new SelectorItemInfo("company.*"));
	    sic.add(new SelectorItemInfo("currencyType.*"));
	    sic.add(new SelectorItemInfo("entries.*"));
	    sic.add(new SelectorItemInfo("entries.expenseType.*"));
   	 	//公司 
    	String companyStr = jo.getString("company");
    	verifyFieldNotNull("公司", companyStr);
    	CompanyOrgUnitInfo company =(CompanyOrgUnitInfo) BillProertiesConvertor.getValueObject(companyStr, CompanyOrgUnitInfo.class, null, ctx);
    	verifyFieldNotNull("company", company);
    	ctx.put(OrgType.Company, company);
    	IDynamicObject instance = DynamicObjectFactory.getLocalInstance(ctx); //用于动态获取单据对象
    	info = instance.getValue(uuid.getType(), new ObjectUuidPK(uuid),sic); //差旅费报销单对象
    	ctrlResultCol = balance.getBudget(info);
	}
    if (objectType.toString().equals("4A44F49F")) {//费用报销单对象
    	BizAccountBillInfo bizAccountInfo = BizAccountBillFactory.getLocalInstance(ctx).getBizAccountBillInfo(new ObjectUuidPK(uuid));
    	StringBuffer sqlBuff = new StringBuffer();
    	sqlBuff.append("/*dialect*/SELECT FCURRENCYID,FCOMPANYID,FPAYMENT,FCOSTEDDEPTID FROM T_BC_BIZACCOUNTBILL where FID ='"+uuid+"'");
    	String companyID = "";//公司
    	String payMent = "";//付款方式
    	String currencyID = "";//币别
    	String costeddepID = "";//成本中心
    	IRowSet rows = DbUtil.executeQuery(ctx, sqlBuff.toString());
    	if (rows != null && rows.size() > 0) {
			while (rows.next()) {
				companyID = rows.getString("FCOMPANYID");
				payMent = rows.getString("FPAYMENT");
				currencyID = rows.getString("FCURRENCYID");
				costeddepID = rows.getString("FCOSTEDDEPTID");
			}
		}
    	    BizAccountBillInfo bizInfo = new BizAccountBillInfo();
    		bizInfo.setNumber("预算查询");
    		bizInfo.setName("预算查询");
    		//业务日期
    	    Date bizDate = bizAccountInfo.getBizDate();
    	    verifyFieldNotNull("业务日期", bizDate);
    	    bizInfo.setBizDate(bizDate);
    	    bizInfo.setBizReqDate(bizDate);
    	    bizInfo.setBillDate(bizDate);

    	    bizInfo.setBiller(ContextUtil.getCurrentUserInfo(ctx));
    	    //成本中心
    	    CostCenterOrgUnitInfo costCenter = CostCenterOrgUnitFactory.getLocalInstance(ctx).getCostCenterOrgUnitInfo(new ObjectUuidPK(costeddepID));
//    	    verifyFieldNotNull("costedDept", costCenter);
    	    bizInfo.setCostedDept(costCenter);
    	    //公司
    	    CompanyOrgUnitInfo company = CompanyOrgUnitFactory.getLocalInstance(ctx).getCompanyOrgUnitInfo(new ObjectUuidPK(companyID));
    	    verifyFieldNotNull("公司", company);
    	    bizInfo.setCompany(company);
    	    //申请公司
    	    bizInfo.setApplierCompany(company);
    	    //管理单元
    	    bizInfo.setCU(CtrlUnitFactory.getLocalInstance(ctx).getCtrlUnitInfo(
    		    new ObjectUuidPK(company.getCU().getId())));
    		//紧急程度
    	    bizInfo.setPrior(PriorEnum.LOW);
    	    //支付方式
    		SettlementTypeInfo settlementTypeInfo = SettlementTypeFactory.getLocalInstance(ctx).getSettlementTypeInfo(new ObjectUuidPK(payMent));
//    		verifyFieldNotNull("支付方式", settlementTypeInfo);
    		bizInfo.setPayMode(settlementTypeInfo);
    		
    		//单据类型
    		bizInfo.setBillTypeCode(BizCollBillTypeEnum.BIZ_ACCOUNT);
    	    //币别
    	    CurrencyInfo bb01 = CurrencyFactory.getLocalInstance(ctx).getCurrencyInfo(new ObjectUuidPK(currencyID));
    	    bizInfo.setCurrencyType(bb01);

    	    //付现金额
    		BigDecimal biaoAmount =bizAccountInfo.getAmountEncashed();
    		//分录
    	    for (int i = 0; i < bizAccountInfo.getEntries().size(); i++) {
    	    	StringBuffer sqlBuff2 = new StringBuffer();
    	    	sqlBuff2.append("/*dialect*/SELECT FEXPENSETYPEID,FOPERATIONTYPEID FROM T_BC_BIZACCOUNTBILLENTRY where FBILLID ='"+uuid+"'");
    	    	String expenseTypeID = "";//费用项目类型
    	    	String operationtypeID = "";//业务类别
    	    	IRowSet rows2 = DbUtil.executeQuery(ctx, sqlBuff2.toString());
    	    	if (rows2 != null && rows2.size() > 0) {
    				while (rows2.next()) {
    					expenseTypeID = rows2.getString("FEXPENSETYPEID");
    					operationtypeID = rows2.getString("FOPERATIONTYPEID");
    				}
    			}
    		BizAccountBillEntryInfo eInfo = bizAccountInfo.getEntries().get(i);
    		int seq = eInfo.getSeq();
    		eInfo.setSeq(seq);
    		//费用类型
    		ExpenseTypeInfo expenInfo = ExpenseTypeFactory.getLocalInstance(ctx).getExpenseTypeInfo(new ObjectUuidPK(expenseTypeID));
//			verifyFieldNotNull("费用类型", expenInfo);
    		eInfo.setExpenseType(expenInfo);
    		//业务类别
    		OperationTypeInfo operationType = OperationTypeFactory.getLocalInstance(ctx).getOperationTypeInfo(new ObjectUuidPK(operationtypeID));
//    		verifyFieldNotNull("业务类别", operationType);
    		eInfo.setOperationType(operationType);
    		
    		//申请原因
    		eInfo.setPurpose("");
    		//币别
    		CurrencyInfo  currencyType2 = eInfo.getCurrencyType();
    		eInfo.setCurrencyType(currencyType2);
    		//汇率
    		eInfo.setExchangeRate(eInfo.getExchangeRate());
    		//汇率精度
    		eInfo.setExchangeRatePrecision(eInfo.getExchangeRatePrecision());
    		//原币申请金额
    		eInfo.setAmountOri(biaoAmount);
    		
    		//本位币申请金额
    		eInfo.setAmount(biaoAmount);
    		//原币核定金额
    		eInfo.setAmountApprovedOri(biaoAmount);
    		//本位币核定金额
    		eInfo.setAmountApproved(biaoAmount);
    		//表头金额
    		biaoAmount = biaoAmount.add(biaoAmount);	
    		//费用支付部门
    		eInfo.setCompany(company);
    		//费用支付公司
    		eInfo.setCostCenter(costCenter);
    		bizInfo.getEntries().add(eInfo);
    	    }
    	    
    	    for (int k = 0; k < bizAccountInfo.getCollectionEntries().size(); k++) {
    	    	BizAccountBillAccountEntryInfo accountInfo = bizAccountInfo.getCollectionEntries().get(k);
    	    	SettlementTypeInfo settlementInfo = accountInfo.getPayMode();
    	    	accountInfo.setPayMode(settlementInfo);
    	    	//币别
    	    	CurrencyInfo accCurrency = accountInfo.getCurrencyType();
    	    	accountInfo.setCurrencyType(accCurrency);
    	    	//支付方式
    	    	SettlementTypeInfo settletype = accountInfo.getPayMode();
    	    	accountInfo.setPayMode(settletype);
    	    	//汇率精度
    	    	accountInfo.setExchangeRatePrecision(accountInfo.getExchangeRatePrecision());
    	    	//汇率
    	    	accountInfo.setExchangeRate(accountInfo.getExchangeRate());
    	    	//本位币金额
    	    	accountInfo.setAmount(biaoAmount);
    	    	//原币金额
    	    	accountInfo.setAmountOri(biaoAmount);
    	    	bizInfo.getCollectionEntries().add(accountInfo);
			}
    	    //申请金额
    	    bizInfo.setAmount(biaoAmount);
    		//核定总额
    	    bizInfo.setAmountApproved(biaoAmount);
    	    //付现
    	    bizInfo.setAmountEncashed(biaoAmount);
    	    ctx.put(OrgType.Company, company);
    	    ctrlResultCol = balance.getBudget(bizInfo);
	}
    
    
    if (objectType.toString().equals("48DA3A71")) {//应付单
    	OtherBillInfo OtherBillInfo = OtherBillFactory.getLocalInstance(ctx).getOtherBillInfo(new ObjectUuidPK(uuid));
    	StringBuffer sqlBuff = new StringBuffer();
    	sqlBuff.append("/*dialect*/SELECT FASSTACTTYPEID,FPURORGID,FPAYMENTTYPEID,FCOMPANYID,FCURRENCYID FROM T_AP_OTHERBILL where FID ='"+uuid+"'");
    	String companyID = "";//公司
    	String asstActTypeID = "";//单据类型
    	String paymentTypeID = "";//付款方式
    	String purOrgID = "";//采购
    	String currencyID = "";//币别
    	IRowSet rows = DbUtil.executeQuery(ctx, sqlBuff.toString());
    	if (rows != null && rows.size() > 0) {
			while (rows.next()) {
				companyID = rows.getString("FCOMPANYID");
				asstActTypeID = rows.getString("FASSTACTTYPEID");
				paymentTypeID = rows.getString("FPAYMENTTYPEID");
				purOrgID = rows.getString("FPURORGID");
				currencyID = rows.getString("FCURRENCYID");
			}
		}
    		OtherBillInfo OtherInfo = new OtherBillInfo();

    	    OtherInfo.setNumber(OtherBillInfo.getNumber());
    	    //业务日期
            Date date = OtherBillInfo.getBizDate();
    	    OtherInfo.setBizDate(date);
    	    OtherInfo.setBillDate(date);
    	    //公司
    	    CompanyOrgUnitInfo companyInfo = CompanyOrgUnitFactory.getLocalInstance(ctx).getCompanyOrgUnitInfo(new ObjectUuidPK(companyID));
    	    verifyFieldNotNull("公司", companyInfo);
    	    OtherInfo.setCompany(companyInfo);
    	    //采购组织
    	    PurchaseOrgUnitInfo purOrg = PurchaseOrgUnitFactory.getLocalInstance(ctx).getPurchaseOrgUnitInfo(new ObjectUuidPK(purOrgID));
    	    OtherInfo.setPurOrg(purOrg);
    	    //管理单元
    	    OtherInfo.setCU(CtrlUnitFactory.getLocalInstance(ctx).getCtrlUnitInfo(
    		    new ObjectUuidPK(companyInfo.getCU().getId())));
    	    //单据类型
    	    OtherInfo.setBillType(OtherBillInfo.getBillType());
    	     // 往来类型 T_BD_AsstActType (辅助核算项目 47385590)
   		    AsstActTypeInfo asstActTypeInfo = AsstActTypeFactory.getLocalInstance(ctx).getAsstActTypeInfo(new ObjectUuidPK(asstActTypeID)) ;
   		    verifyFieldNotNull("往来类型", asstActTypeInfo);
   		    OtherInfo.setAsstActType(asstActTypeInfo);
   		    setAsstActor(ctx, OtherInfo,OtherBillInfo,asstActTypeInfo);
   		    //付款方式
   		     PaymentTypeInfo paymentType = PaymentTypeFactory.getLocalInstance(ctx).getPaymentTypeInfo(new ObjectUuidPK(paymentTypeID));
   		     verifyFieldNotNull("付款方式", paymentType);
   		     OtherInfo.setPaymentType(paymentType);
    	    //币别
    	    CurrencyInfo bb01 = CurrencyFactory.getLocalInstance(ctx).getCurrencyInfo(new ObjectUuidPK(currencyID));
    	    verifyFieldNotNull("币别", paymentType);
    	    OtherInfo.setCurrency(bb01);
    	    //汇率
    	    OtherInfo.setExchangeRate(OtherBillInfo.getExchangeRate());
    	    //应付金额
    	    BigDecimal amountOri = OtherBillInfo.getAmount();
    	    //预计总费用
    	    OtherInfo.setAmount(amountOri);
    	    OtherInfo.setAmountLocal(amountOri);
    	    for (int i = 0; i < OtherBillInfo.getEntry().size(); i++) {
    	    	StringBuffer sqlBuff2 = new StringBuffer();
    	    	sqlBuff2.append("/*dialect*/SELECT FEXPENSEITEMID FROM T_AP_OTHERBILLENTRY where FPARENTID ='"+uuid+"'");
    	    	String expenseItemID = "";//费用项目类型
    	    	IRowSet rows2 = DbUtil.executeQuery(ctx, sqlBuff2.toString());
    	    	if (rows2 != null && rows2.size() > 0) {
    				while (rows2.next()) {
    					expenseItemID = rows2.getString("FEXPENSEITEMID");
    				}
    			}
    		OtherBillentryInfo entryInfo = OtherBillInfo.getEntry().get(i);;
    		int seq = entryInfo.getSeq();
    		entryInfo.setSeq(seq);
    		OtherBillType billType = OtherBillInfo.getBillType();
    		boolean isInvoice = billType.equals(OtherBillType.InvoiceBill);
    		if (isInvoice) {
    			MaterialInfo mInfo = entryInfo.getMaterial();
    			verifyFieldNotNull("material", mInfo);
    			entryInfo.setMaterial(mInfo);
    			entryInfo.setMeasureUnit(mInfo.getBaseUnit());
    		} else {
    			//费用项目编码
    			ExpenseItemInfo eInfo = ExpenseItemFactory.getLocalInstance(ctx).getExpenseItemInfo(new ObjectUuidPK(expenseItemID));
    			verifyFieldNotNull("expenseItem", eInfo);
    			entryInfo.setExpenseItem(eInfo);
    		}
    		 // 计量单位 T_BD_MeasureUnit (计量单位 5B825C57)
//    		MeasureUnitInfo measureUnit = entryInfo.getMeasureUnit();
//    		verifyFieldNotNull("measureUnit", measureUnit);
//    		entryInfo.setMeasureUnit(measureUnit);
    		// 应收(付)金额
    		entryInfo.setRecievePayAmount(entryInfo.getRecievePayAmount());
    		// 应收(付)本币金额
    		entryInfo.setRecievePayAmountLocal(entryInfo.getRecievePayAmountLocal());
    		//未结算本币金额
    		entryInfo.setUnVerifyAmount(entryInfo.getUnVerifyAmount());
    		// 未锁定金额
    		entryInfo.setLockUnVerifyAmt(entryInfo.getLockUnVerifyAmt());
    		// 未锁定本币金额
    		entryInfo.setLockUnVerifyAmtLocal(entryInfo.getLockUnVerifyAmt());
    		//单价
    		entryInfo.setPrice(entryInfo.getPrice());
    		//实际单价
    		entryInfo.setActualPrice(entryInfo.getActualPrice());
    		// 税额
    		entryInfo.setTaxAmount(entryInfo.getTaxAmount());
    		// 税额本币
    		entryInfo.setTaxAmountLocal(entryInfo.getTaxAmountLocal());
    		// 金额
    		entryInfo.setAmount(entryInfo.getAmount());
    		// 本币金额
    		entryInfo.setAmountLocal(entryInfo.getAmountLocal());
    		OtherInfo.getEntry().add(entryInfo);
    	    }
    	   
    	    for (int i = 0; i < OtherBillInfo.getPayPlan().size(); i++) {
    	    	OtherBillPlanInfo planInfo = OtherBillInfo.getPayPlan().get(i);
    	    	//应付日期
                Date bizDate2 = planInfo.getRecievePayDate();
    	    	planInfo.setRecievePayDate(bizDate2);
    	    	// 应收(付)金额
    	    	planInfo.setRecievePayAmount(planInfo.getRecievePayAmount());
    	    	// 应收(付)本币金额
    	    	planInfo.setRecievePayAmountLocal(planInfo.getRecievePayAmountLocal());
    	    	planInfo.setLockAmount(planInfo.getLockAmount());
    	    	planInfo.setVerifyAmountLocal(planInfo.getVerifyAmountLocal());
			}
    	    ctx.put(OrgType.Company, companyInfo);
    	    ctrlResultCol = balance.getBudget(OtherInfo);
	}
     System.out.println();
    if (ctrlResultCol != null && ctrlResultCol.size() > 0) {
    	List<HashMap<String, Object>> maps=new ArrayList<HashMap<String,Object>>();
	for (int i = 0; i < ctrlResultCol.size(); i++) {
		HashMap<String, Object> obj = new HashMap<String, Object>();
	    BgCtrlResultInfo param = ctrlResultCol.get(i);
	    if (param.getOrgUnitName() == null)
	    	continue;
	    int precision = 2;
	    //预算申请项目
	    String billItemName = param.getBillItemName();
	    obj.put("billItemName", billItemName);
	    // 组织
	    String orgName = param.getOrgUnitName();
	    obj.put("seq", i + 1);
	    obj.put("orgName", orgName);
	    // 预算方案
	    String scheme = param.getBgSchemeId();
	    BgSchemeInfo schemeInfo = BgSchemeFactory.getLocalInstance(ctx).getBgSchemeInfo(new ObjectUuidPK(scheme));
	    obj.put("scheme", schemeInfo.getName());
	    // 预算期间
	    String bgPeriod = param.getPeriodName();
	    obj.put("bgPeriod", bgPeriod);
	    // 预算要素
	    String bgElement = param.getElementName();
	    obj.put("bgElement", bgElement);
	    // 预算数
	    BigDecimal budgetValue = param.getBgValue();
	    if (budgetValue == null) {
	    	budgetValue = param.getBgValue() == null ? BigDecimal.ZERO: param.getBgValue();
	    }
	    obj.put("budget", budgetValue.setScale(precision,BigDecimal.ROUND_HALF_UP));
	    // 实际数
	    BigDecimal actualValue = param.getBizActual();
	    if (actualValue == null) {
	    	actualValue = param.getBizActual() == null ? BigDecimal.ZERO
	    			: param.getBizActual();
	    }
	    obj.put("actual", actualValue.setScale(precision,BigDecimal.ROUND_HALF_UP));
	    BigDecimal balanceValue = BigDecimal.ZERO;
	    // 预算余额
	    if (param.getBalance() != null)
		balanceValue = param.getBalance();
	    else
		balanceValue = param.getBalance() == null ? BigDecimal.ZERO: param.getBalance();
	    obj.put("balance", balanceValue.setScale(precision,BigDecimal.ROUND_HALF_UP));
	    maps.add(obj);
		   }
	   j.getData().put("noBudget", true);//返回结果
	   j.getData().put("result", maps);
    	 }
    	} catch (EASBizException e) {
    		j.setSuccess(false);
    		j.setMessage(e.getMessage());
    		System.out.println("预算查询回执:" + j.getJsonStr());
    		return j.getJsonStr();
    	} catch (BOSException e) {
    		j.setSuccess(false);
    		j.setMessage(e.getMessage());
    		System.out.println("预算查询回执:" + j.getJsonStr());
    		return j.getJsonStr();
    	} catch (Exception e) {
    		j.setSuccess(false);
    		j.setMessage("error occur");
    		System.out.println("预算查询回执:" + j.getJsonStr());
    		return j.getJsonStr();
    	}
    		System.out.println("预算查询回执:" + j.getJsonStr());
    		return j.getJsonStr();
    }

!!!!注意的地方:

        dep查询预算需要过滤的条件是根据单据的预算配置属性去过滤的,每个单据的过滤条件不一定相同,需要自己去根据实际情况来过滤。

发布了78 篇原创文章 · 获赞 32 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/a754315344/article/details/102784117
EAS