/* * 获取对象列表 */ public Object[] getElements(Context context, STableStatus tablestatus) { GetGoodsSplitBillListKey key = new GetGoodsSplitBillListKey(tablestatus.getBeginIndex(), tablestatus.getPageSize(), false); if (CheckIsNull.isNotEmpty(tablestatus.getSortColumn())) { key.setSortField(getSortField(tablestatus.getSortColumn())); key.setSortType(getSortType(tablestatus.getSortDirection())); } key.setStatus(new GoodsSplitStatus[] {GoodsSplitStatus.Approvaling}); key.setSearchText(searchText.getText()); key.setBeginTime(context.find(QueryTerm.class, queryTermList.getText()).getStartTime()); key.setEndTime(context.find(QueryTerm.class, queryTermList.getText()).getEndTime()); ListEntity<GoodsSplitItem> entity = context.find(ListEntity.class, key); List<GoodsSplitItem> itemList = entity.getItemList(); // if (CheckIsNull.isEmpty(itemList)) { // countLabel.setText("0"); // return null; // } GoodsSplitItem[] items = new GoodsSplitItem[itemList.size()]; for (int i = 0; i < itemList.size(); i++) { items[i] = itemList.get(i); itemMap.put(items[i].getRECID().toString(), items[i]); } int size = items.length; if (tablestatus.getPageNo() != STableStatus.FIRSTPAGE) { String preSize = countLabel.getText(); if (StringHelper.isNotEmpty(preSize)) { size += Integer.parseInt(preSize); } } countLabel.setText(String.valueOf(size)); // countLabel.setText("" + items.length); countLabel.getParent().getParent().layout(); return items; }
/** 对一个入库单实体添加基础数据 */ private void fillEntity(Context context, Instorage entity, String type) { Login login = context.find(Login.class); Employee emp = context.find(Employee.class, login.getEmployeeId()); entity.setRECID(context.newRECID()); entity.setSheetType(type); entity.setCreateDate(new Date().getTime()); if (CheckIsNull.isNotEmpty(entity.getPartnerId())) { Partner partner = context.find(Partner.class, entity.getPartnerId()); if (null != partner) { entity.setPartnerName(partner.getName()); entity.setPartnerShortName(partner.getShortName()); entity.setPartnerCode(partner.getCode()); } } Store store = context.find(Store.class, entity.getStoreId()); if (null != store) { entity.setStoreName(store.getName()); entity.setStoreNamePY(PinyinHelper.getLetter(store.getName())); } if (CheckingInType.Irregular.getCode().equals(type) || CheckingInType.Kit.getCode().equals(type)) { entity.setCreatorId(login.getEmployeeId()); entity.setCreator(emp.getName()); } }
@Override protected SaleCancel getOrderInfo(GUID orderId) { if (CheckIsNull.isNotEmpty(this.orderInfo) && orderInfo instanceof SaleCancel) { return (SaleCancel) orderInfo; } return context.find(SaleCancel.class, orderId); }
@Override protected void occur(Context context, CheckInEvent event) throws Throwable { if (CheckIsNull.isEmpty(event.getRelaOrderId()) || CheckIsNull.isEmpty(event.getType())) { throw new Throwable("相关单据编号和入库类型不能为空"); } OrderInfo info = null; BillsEnum billsEnum = null; switch (event.getType()) { // Purchase("01", "采购入库"), // // Irregular("02", "零星采购"), // // Return("03", "销售退货"), // // RetailReturn("04","零售退货"), // Other("05", "其他入库"); case Purchase: info = context.find(PurchaseOrderInfo.class, event.getRelaOrderId()); billsEnum = BillsEnum.PURCHASE; break; case Return: info = context.find(SaleCancel.class, event.getRelaOrderId()); billsEnum = BillsEnum.SALE_CANCEL; break; // case DirectSupply: // info = context.find(PurchaseOrderInfo.class, event.getRelaOrderId()); // billsEnum = BillsEnum.PURCHASE; // break; default: return; } if (CheckIsNull.isEmpty(info)) { throw new Throwable("相关单据编号在订单中不存在"); } StatusEnum newstatus = InventoryDataUtil.getOrderStatusByIn(context, event.getRelaOrderId()); if (!newstatus.isThis(info.getStatus())) { OrderUtil.modifystatus( billsEnum, context, info.getRECID(), newstatus, StatusEnum.getstatus(info.getStatus())); // 全部出库完成出库 if (newstatus == StatusEnum.Store_All) { if (BillsEnum.PURCHASE == billsEnum) { context.dispatch( new PurchaseOrderChangedEvent(info.getRECID(), ChangedType.StoreFinish)); } else { context.dispatch(new SalesReturnChangedEvent(info.getRECID(), ChangedType.StoreFinish)); } } } }
@Override protected void occur(Context context, CheckOutEvent event) throws Throwable { if (CheckIsNull.isEmpty(event.getRelaOrderId()) || CheckIsNull.isEmpty(event.getType())) { throw new Throwable("相关单据编号和出库类型不能为空"); } OrderInfo info = null; BillsEnum billsEnum = null; switch (event.getType()) { // Sales("01", "销售出库"), // // Return("02", "采购退货"), // // Retail("03", "零售出库"), // // Kit("04", "其他出库"); case Sales: info = context.find(SaleOrderInfo.class, event.getRelaOrderId()); billsEnum = BillsEnum.SALE; break; case Return: info = context.find(PurchaseCancel.class, event.getRelaOrderId()); billsEnum = BillsEnum.PURCHASE_CANCEL; break; default: return; } if (CheckIsNull.isEmpty(info)) { throw new Throwable("相关单据编号在订单中不存在"); } StatusEnum newstatus = InventoryDataUtil.getOrderStatusByOut(context, event.getRelaOrderId()); if (!newstatus.isThis(info.getStatus())) { OrderUtil.modifystatus( billsEnum, context, info.getRECID(), newstatus, StatusEnum.getstatus(info.getStatus())); // 全部出库完成出库 if (newstatus == StatusEnum.Store_All) { if (BillsEnum.SALE == billsEnum) { context.dispatch(new SalesOrderChangedEvent(info.getRECID(), ChangedType.StoreFinish)); } else { context.dispatch( new PurchaseReturnChangedEvent(info.getRECID(), ChangedType.StoreFinish)); } } } }
@Override protected void provide(Context context, ReportCommonKey key, List<ReportResult> list) throws Throwable { SubjectEnum subject = key.getSubject(); if (null == subject) { return; } if (CheckIsNull.isEmpty(key.getTargets())) { return; } switch (subject) { case GoodsItem: GoodsSubjectProvider.provide(context, key, list); break; case DateTime: DateTimeProvider.provide(context, key, list); break; /** 客户 */ case Customer: CustomerSubjectProvider.provide(context, key, list); break; /** 客户并销售人员 */ case Customer_Employee: Customer_EmployeeSubjectProvider.provide(context, key, list); break; /** 供应商 */ case Supplier: SupplierSubjectProvider.provide(context, key, list); break; /** 员工 */ case Employee: EmployeeSubjectProvider.provide(context, key, list); break; /** 部门 */ case Department: DepartmentSubjectProvider.provide(context, key, list); break; /** 地区 */ case Area: AreaSubjectProvider.provide(context, key, list); break; /** 库存台账 */ case InventoryBook: InventorySubjectProvider.provide(context, key, list); break; /** 公司 */ case Company: TenantSubjectProvider.provide(context, key, list); break; } }
@SuppressWarnings("unchecked") @Override protected ReportChartDatas provide(Context context, ReportCommonKey key) throws Throwable { List<ReportResult> list = context.getList(ReportResult.class, key); if (CheckIsNull.isEmpty(key.getOrderTarget())) { return null; } Enum target = null; SubjectEnum subject = null; if (key.isDateColumn()) { subject = SubjectEnum.DateTime; target = ReportTargetUtil.getTarget(subject, key.getOrderTarget()); } else { subject = key.getSubject(); target = ReportTargetUtil.getTarget(subject, "Id"); } ReportChartDatas datas = new ReportChartDatas(list, target); return datas; }
/** * @param context * @param key * @param list */ @SuppressWarnings("unchecked") private static void purchaseProvider( Context context, ReportCommonKey key, List<ReportResult> list) { Tenant tenant = context.find(Tenant.class); QuerySqlBuilder qb = new QuerySqlBuilder(context); qb.addTable("SA_REPORT_GOODS_BUY_DATE", "t2"); qb.addArgs("comNo", qb.guid, tenant.getId()); qb.addEquals("t2.tenantId", "@comNo"); List<Enum> targets = key.getTargets(); qb.addColumn("t2.goodsItemId", "goodsItemId"); if (targets.indexOf(GoodsItemEnum.PurchaseAmount) >= 0) { qb.addColumn("sum(t2.ordAmount)", "ordAmounts"); } if (targets.indexOf(GoodsItemEnum.PurchaseCount) >= 0) { qb.addColumn("sum(t2.ordCount)", "ordCount2"); } if (targets.indexOf(GoodsItemEnum.PurchaseReturnAmount) >= 0) { qb.addColumn("sum(t2.rtnAmount)", "rtnAmounts"); } if (targets.indexOf(GoodsItemEnum.InStoreCount) >= 0) { qb.addColumn("sum(t2.outstoAmount)", "outstoAmount2"); } if (targets.indexOf(GoodsItemEnum.PayAmount) >= 0) { qb.addColumn("sum(t2.receiptAmount)", "receiptAmount2"); } Map<GUID, ReportResult> ymap = null; if (targets.indexOf(GoodsItemEnum.PurchaseAmount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.PurchaseCount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.PurchaseReturnAmount_OfYear) >= 0) { ymap = getYearDoubleMapPurchase(context, key, tenant); } for (Condition con : key.getConditions()) { if ("month".toUpperCase().equals(con.getConditionColumn().toUpperCase())) { qb.addArgs("month", qb.INT, con.getValue()); qb.addEquals("t2.monthNo", "@month"); } else if ("season".toUpperCase().equals(con.getConditionColumn().toUpperCase())) { qb.addArgs("season", qb.INT, con.getValue()); qb.addEquals("t2.quarter", "@season"); } else { } } qb.addGroupBy("t2.goodsItemId"); if (CheckIsNull.isNotEmpty(key.getOrderTarget()) && GoodsItemEnum.getTarget(key.getOrderTarget()) == GoodsItemEnum.PurchaseAmount) { String column = "ordAmounts"; if (key.isOrderDesc()) { column = column + " desc"; } qb.addOrderBy(column); } else if (CheckIsNull.isNotEmpty(key.getOrderTarget()) && GoodsItemEnum.getTarget(key.getOrderTarget()) == GoodsItemEnum.PurchaseReturnAmount) { String column = "rtnAmounts"; if (key.isOrderDesc()) { column = column + " desc"; } qb.addOrderBy(column); } RecordSet rs = null; if (key.getMaxCount() == 0) { rs = qb.getRecord(); } else { rs = qb.getRecordLimit(0, key.getMaxCount()); } while (rs.next()) { ReportResult rr = new ReportResult(); int index = 0; GUID goodsItemId = rs.getFields().get(index++).getGUID(); rr.setTargetValue(GoodsItemEnum.Id, goodsItemId); GoodsItem item = context.find(GoodsItem.class, goodsItemId); rr.setTargetValue(GoodsItemEnum.GoodsName, item.getGoodsName()); rr.setTargetValue(GoodsItemEnum.GoodsAttr, item.getPropertiesWithoutUnit()); rr.setTargetValue(GoodsItemEnum.GoodsUnit, item.getGoodsUnit()); if (targets.indexOf(GoodsItemEnum.PurchaseAmount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.PurchaseAmount, value); } if (targets.indexOf(GoodsItemEnum.PurchaseCount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.PurchaseCount, value); } if (targets.indexOf(GoodsItemEnum.PurchaseReturnAmount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.PurchaseReturnAmount, value); } if (targets.indexOf(GoodsItemEnum.InStoreCount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.InStoreCount, value); } if (targets.indexOf(GoodsItemEnum.PayAmount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.PayAmount, value); } if (targets.indexOf(GoodsItemEnum.PurchaseAmount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.PurchaseCount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.PurchaseReturnAmount_OfYear) >= 0) { ReportResult tt = ymap.get(goodsItemId); if (tt != null) { rr.setTargetValue( GoodsItemEnum.PurchaseAmount_OfYear, tt.getTargetValue(GoodsItemEnum.PurchaseAmount_OfYear)); rr.setTargetValue( GoodsItemEnum.PurchaseCount_OfYear, tt.getTargetValue(GoodsItemEnum.PurchaseCount_OfYear)); rr.setTargetValue( GoodsItemEnum.PurchaseReturnAmount_OfYear, tt.getTargetValue(GoodsItemEnum.PurchaseReturnAmount_OfYear)); } } list.add(rr); } }
/** * @param context * @param key * @param list */ @SuppressWarnings("unchecked") private static void salesProvider(Context context, ReportCommonKey key, List<ReportResult> list) { Login login = context.find(Login.class); QuerySqlBuilder qb = new QuerySqlBuilder(context); qb.addTable("SA_REPORT_GOODS_SALE_DATE", "t1"); qb.addArgs("comNo", qb.guid, login.getTenantId()); qb.addEquals("t1.tenantId", "@comNo"); List<Enum> targets = key.getTargets(); qb.addColumn("t1.goodsItemId", "goodsItemId"); if (targets.indexOf(GoodsItemEnum.SalesAmount) >= 0) { qb.addColumn("sum(t1.ordAmount)", "ordAmounts"); } if (targets.indexOf(GoodsItemEnum.SalesCount) >= 0) { qb.addColumn("sum(t1.ordCount)", "ordCount1"); } if (targets.indexOf(GoodsItemEnum.SalesReturnAmount) >= 0) { if (targets.indexOf(GoodsItemEnum.SalesAmount) < 0) { qb.addArgs("zero", qb.INT, 0); qb.addGreaterThan("t1.rtnAmount", "@zero"); } qb.addColumn("sum(t1.rtnAmount)", "rtnAmounts"); } if (targets.indexOf(GoodsItemEnum.OutStoreCount) >= 0) { qb.addColumn("sum(t1.outstoAmount)", "outstoAmount1"); } if (targets.indexOf(GoodsItemEnum.ReceiptAmount) >= 0) { qb.addColumn("sum(t1.receiptAmount)", "receiptAmount1"); } Map<GUID, ReportResult> ymap = null; if (targets.indexOf(GoodsItemEnum.SalesAmount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.SalesCount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.SalesReturnAmount_HuanBi) >= 0) { ymap = getYearDoubleMap_Sales(context, key, login); } for (Condition con : key.getConditions()) { if ("month".toUpperCase().equals(con.getConditionColumn().toUpperCase())) { qb.addArgs("month", qb.INT, con.getValue()); qb.addEquals("t1.monthNo", "@month"); } else if ("thismonth".toUpperCase().equals(con.getConditionColumn().toUpperCase())) { qb.addArgs("month", qb.INT, ReportDateUtils.getMonthNo(new Date())); qb.addEquals("t1.monthNo", "@month"); } else if ("season".toUpperCase().equals(con.getConditionColumn().toUpperCase())) { qb.addArgs("season", qb.INT, con.getValue()); qb.addEquals("t1.quarter", "@season"); } else { } } qb.addGroupBy("t1.goodsItemId"); if (CheckIsNull.isNotEmpty(key.getOrderTarget()) && GoodsItemEnum.getTarget(key.getOrderTarget()) == GoodsItemEnum.SalesAmount) { String column = "ordAmounts"; if (key.isOrderDesc()) { column = column + " desc"; } qb.addOrderBy(column); } else if (CheckIsNull.isNotEmpty(key.getOrderTarget()) && GoodsItemEnum.getTarget(key.getOrderTarget()) == GoodsItemEnum.SalesReturnAmount) { String column = "rtnAmounts"; if (key.isOrderDesc()) { column = column + " desc"; } qb.addOrderBy(column); } Condition depCon = ReportUtils.findCondition("DepartmentId", key.getConditions()); if (AuthUtils.isBoss(context, login.getEmployeeId()) && null == depCon) { } else if (AuthUtils.isManager(context, login.getEmployeeId()) || null != depCon) { GUID deptId = null; if (null == depCon) { Employee emp = context.find(Employee.class, login.getEmployeeId()); deptId = emp.getDepartmentId(); } else { deptId = (GUID) depCon.getValue(); } Department dep = context.find(Department.class, deptId); List<String> argslist = new ArrayList<String>(); int i = 0; for (Department d : dep.getDescendants(context)) { argslist.add("@" + "deptId" + i); qb.addArgs("deptId" + i, qb.guid, d.getId()); i++; } qb.addIn("t1.deptGuid", argslist); } else if (AuthUtils.isSales(context, login.getEmployeeId())) { qb.addArgs("userId", qb.guid, login.getEmployeeId()); qb.addEquals("t1.orderPerson", "@userId"); } RecordSet rs = null; if (key.getMaxCount() == 0) { rs = qb.getRecord(); } else { rs = qb.getRecordLimit(0, key.getMaxCount()); } while (rs.next()) { ReportResult rr = new ReportResult(); int index = 0; GUID goodsItemId = rs.getFields().get(index++).getGUID(); rr.setTargetValue(GoodsItemEnum.Id, goodsItemId); GoodsItem item = context.find(GoodsItem.class, goodsItemId); rr.setTargetValue(GoodsItemEnum.GoodsName, item.getGoodsName()); rr.setTargetValue(GoodsItemEnum.GoodsAttr, item.getPropertiesWithoutUnit()); rr.setTargetValue(GoodsItemEnum.GoodsUnit, item.getGoodsUnit()); if (targets.indexOf(GoodsItemEnum.SalesAmount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.SalesAmount, value); } if (targets.indexOf(GoodsItemEnum.SalesCount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.SalesCount, value); } if (targets.indexOf(GoodsItemEnum.SalesReturnAmount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.SalesReturnAmount, value); } if (targets.indexOf(GoodsItemEnum.OutStoreCount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.OutStoreCount, value); } if (targets.indexOf(GoodsItemEnum.ReceiptAmount) >= 0) { Object value = rs.getFields().get(index++).getObject(); rr.setTargetValue(GoodsItemEnum.ReceiptAmount, value); } if (targets.indexOf(GoodsItemEnum.SalesAmount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.SalesCount_OfYear) >= 0 || targets.indexOf(GoodsItemEnum.SalesReturnAmount_OfYear) >= 0) { ReportResult tt = ymap.get(goodsItemId); if (tt != null) { rr.setTargetValue( GoodsItemEnum.SalesAmount_OfYear, tt.getTargetValue(GoodsItemEnum.SalesAmount_OfYear)); rr.setTargetValue( GoodsItemEnum.SalesCount_OfYear, tt.getTargetValue(GoodsItemEnum.SalesCount_OfYear)); rr.setTargetValue( GoodsItemEnum.SalesReturnAmount_OfYear, tt.getTargetValue(GoodsItemEnum.SalesReturnAmount_OfYear)); } } list.add(rr); } }