Index: ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/dwr/table/ExpensiveGoodsBillTableManager.java =================================================================== diff -u --- ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/dwr/table/ExpensiveGoodsBillTableManager.java (revision 0) +++ ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/dwr/table/ExpensiveGoodsBillTableManager.java (revision 21030) @@ -0,0 +1,85 @@ +package com.forgon.disinfectsystem.expensiveGoods.dwr.table; + +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import net.sf.json.JSONObject; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Service; + +import com.forgon.component.grid.GridManager; +import com.forgon.databaseadapter.service.DateQueryAdapter; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.disinfectsystem.basedatamanager.warehouse.service.WareHouseManager; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBill; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsStock; +import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchaseItem; +import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchasePlan; +import com.forgon.disinfectsystem.entity.basedatamanager.materialdefinition.MaterialDefinition; +import com.forgon.disinfectsystem.entity.basedatamanager.warehouse.WareHouse; +import com.forgon.disinfectsystem.entity.goodsstock.GoodsStock; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsManager; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsPurchasePlanManager; +import com.forgon.search.service.TBarFilterManager; +import com.forgon.tools.hibernate.ObjectDao; + +/** + *高值耗材发票管理 + * + */ +@Service +public class ExpensiveGoodsBillTableManager { + + private GridManager gridManager; + private DateQueryAdapter dateQueryAdapter; + private ExpensiveGoodsManager expensiveGoodsManager; + private ExpensiveGoodsPurchasePlanManager expensiveGoodsPurchasePlanManager; + private WareHouseManager wareHouseManager; + private ObjectDao objectDao; + + @Resource(name = "expensiveGoodsBillTableFilterManagerImpl") + private TBarFilterManager expensiveGoodsBillTableFilterManagerImpl; + + public void setGridManager(GridManager gridManager) { + this.gridManager = gridManager; + } + + public void setDateQueryAdapter(DateQueryAdapter dateQueryAdapter) { + this.dateQueryAdapter = dateQueryAdapter; + } + + + public void setExpensiveGoodsManager(ExpensiveGoodsManager expensiveGoodsManager) { + this.expensiveGoodsManager = expensiveGoodsManager; + } + + + public void setExpensiveGoodsPurchasePlanManager( + ExpensiveGoodsPurchasePlanManager expensiveGoodsPurchasePlanManager) { + this.expensiveGoodsPurchasePlanManager = expensiveGoodsPurchasePlanManager; + } + + public void setWareHouseManager(WareHouseManager wareHouseManager) { + this.wareHouseManager = wareHouseManager; + } + + public void setObjectDao(ObjectDao objectDao) { + this.objectDao = objectDao; + } + // 查看高值耗材发票列表 + public String findExpensiveGoodBillTableList(Map> parameterMap) { + Map sqlWhereParamMap = gridManager.getParamFromView(parameterMap); + StringBuilder sql = new StringBuilder(" where 1=1 "); + //根据关键字和时间来过滤 + expensiveGoodsBillTableFilterManagerImpl.filterPara(sqlWhereParamMap,sql); + String json = gridManager.renderGrid(parameterMap, ExpensiveGoodsBill.class.getSimpleName(), sql.toString(), new String[] { "itemsList","orgUnit" }); + return json; + } + + +} Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsBill.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsBill.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsBill.java (revision 21030) @@ -0,0 +1,212 @@ +package com.forgon.disinfectsystem.entity.assestmanagement; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Transient; + +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.forgon.disinfectsystem.entity.basedatamanager.imagefilemanager.ImageFile; +import com.forgon.disinfectsystem.entity.basedatamanager.supplier.RegistrationCertification; +import com.forgon.tools.hibernate.ObjectDao; + +/** + *高值耗材发票 + * + */ +@Entity +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class ExpensiveGoodsBill{ + + private Long id; + /** + * 发票单号 + */ + private String serialNumber; + /** + * 录入人 + */ + private String operator; + + /** + * 操作时间 + */ + private Date time; + + /** + * 开票时间时间 + */ + private Date settledTime; + + /** + * 备注 + */ + private String remark; + + /** + * 发票总价 + */ + private Double totalPrice; + + /** + * 供应商 + */ + private String supplierName; + + /** + * 供应商id + */ + private String supplierId; + + /** + * 发票明细 + */ + @JsonIgnore + private List items = new ArrayList(); + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public Date getSettledTime() { + return settledTime; + } + + public void setSettledTime(Date settledTime) { + this.settledTime = settledTime; + } + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + @OneToMany(fetch = FetchType.LAZY) + @Cascade(value = { CascadeType.ALL }) + @JoinColumn(name = "expensivegoodsbill_id") + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Double getTotalPrice() { + return totalPrice; + } + + public void setTotalPrice(Double totalPrice) { + this.totalPrice = totalPrice; + } + + public String getSupplierName() { + return supplierName; + } + + public void setSupplierName(String supplierName) { + this.supplierName = supplierName; + } + + public String getSupplierId() { + return supplierId; + } + + public void setSupplierId(String supplierId) { + this.supplierId = supplierId; + } + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } + + public void calculateTotalPrice() { + totalPrice = 0.0; + List items = getItems(); + for (ExpensiveGoodsBillItem expensiveGoodsBill : items) { + //如果成功为空,则跳过 + if(expensiveGoodsBill.getPrice() == null){ + continue; + } + totalPrice += (expensiveGoodsBill.getPrice() * expensiveGoodsBill + .getAmount()); + } + setTotalPrice(new BigDecimal(totalPrice).setScale(4, + BigDecimal.ROUND_HALF_UP).doubleValue()); + } + + /** + * 查询发票的图片的数量 + * @param objectDao + * @return + */ + @Transient + public int getImagesCount(ObjectDao objectDao) { + String sql = " where po.imageType='" + ImageFile.IMAGE_TYPE_ExpensiveGoodsBill + + "' and po.objectId in (select id from "+ ExpensiveGoodsBill.class.getSimpleName() +" where id=" + id + ")"; + int count = objectDao.countObjectBySql(ImageFile.class.getSimpleName(), sql); + return count; + } + + /** + * 查询发票所有上传的图片 + * @param objectDao + * @param index + * @return + */ + public ImageFile getImageAt(ObjectDao objectDao, int index) { + Session session = objectDao.getHibernateSession(); + Query query = session.createQuery("from ImageFile where objectId in (select id from "+ ExpensiveGoodsBill.class.getSimpleName() +" where id=" + id + ") and imageType= ‘"+ ImageFile.IMAGE_TYPE_ExpensiveGoodsBill+"’ order by serialNum asc"); + query.setLong("id", id); + query.setMaxResults(1); //最大一条数据 + query.setFirstResult(index); //根据页数找第几张图片 + ImageFile image = (ImageFile)query.uniqueResult(); + return image; + } + +} Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsInstance.java =================================================================== diff -u -r20980 -r21030 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsInstance.java (.../ExpensiveGoodsInstance.java) (revision 20980) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsInstance.java (.../ExpensiveGoodsInstance.java) (revision 21030) @@ -114,7 +114,15 @@ */ private String thirdBodyCode; - private Date expDate;// 失效期; + /** + * 失效期 + */ + private Date expDate; + + /** + * 发票id + */ + private Long expensiveGoodsBillId; /** * 入库类型(区分是自购入库还是预入库) @@ -123,6 +131,15 @@ public static final String ENTRY_TYPE_PURCHASE = "自购入库"; public static final String ENTRY_TYPE_PREPARE = "预入库"; + + public Long getExpensiveGoodsBillId() { + return expensiveGoodsBillId; + } + + public void setExpensiveGoodsBillId(Long expensiveGoodsBillId) { + this.expensiveGoodsBillId = expensiveGoodsBillId; + } + public ExpensiveGoodsInstance() { super(); setType(BarcodeDevice.BARCODE_TYPE_EXPENSIVEGOODS); Index: ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillManager.java =================================================================== diff -u --- ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillManager.java (revision 0) +++ ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillManager.java (revision 21030) @@ -0,0 +1,78 @@ +package com.forgon.disinfectsystem.expensiveGoods.service; + +import java.io.OutputStream; +import java.util.Map; + +import net.sf.json.JSONObject; + +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBill; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBillItem; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsGodownEntry; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsGodownEntryItem; +import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchaseItem; +import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchasePlan; +import com.forgon.tools.hibernate.BasePoManager; + +public interface ExpensiveGoodsBillManager extends BasePoManager { + + public void loadGoodPurchasePlanPrintData( + String[] invoiceIds,JSONObject jsonObject); + + /** + * 导出采购计划单,可能有多张单,合并导出明细 + * @param ops + * @param ids 要导出的采购计划单的id + */ +// public void exportGoodPurchasePlan(OutputStream ops,String ids); + + + /** + * 获取高值耗材明细 + * @param itemId + * @return + */ + public ExpensiveGoodsBillItem getExpensiveGoodsBillItemById(String itemId); + /** + * 获得高值耗材单 + * @param id + * @return + */ + public ExpensiveGoodsBill getExpensiveGoodsBillById(String id); + + /** + * 删除高值耗材发票单 + * @param id + * @return + */ + public Map deleteExpensiveGoodsBill(String id); + + /** + * 保存高值耗材发票 + * @param ExpensiveGoodsBill 高值耗材发票 + * @param result + */ + public void saveExpensiveGoodsBill(ExpensiveGoodsBill goodPurchasePlan,Map result); + + /** + * 更新高值耗材发票单 + * @param original + * @param bill + * @param returnMsg + */ + public void updateExpensiveGoodsBill(ExpensiveGoodsBill original, + ExpensiveGoodsBill entry, Map returnMsg); + + /** + * 根据前台传入数据创建发票单 + * @param bill + * @param godownEntryInfo + */ + public void updateBillInfo(ExpensiveGoodsBill bill,JSONObject godownEntryInfo); + + /** + * 根据前台传入数据创建发票单明细 + * @param entry + * @param itemObject + */ + public void addItemToBill(ExpensiveGoodsBill entry, JSONObject itemObject); +} Index: ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillTableFilterManagerImpl.java =================================================================== diff -u --- ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillTableFilterManagerImpl.java (revision 0) +++ ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillTableFilterManagerImpl.java (revision 21030) @@ -0,0 +1,31 @@ +package com.forgon.disinfectsystem.expensiveGoods.service; + +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; +import com.forgon.search.service.TBarFilterManager; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * 高值耗材发票dwr工具栏sql条件过滤处理类 + */ +@Service("expensiveGoodsBillTableFilterManagerImpl") +public class ExpensiveGoodsBillTableFilterManagerImpl extends TBarFilterManager { + + @Override + public void filterPara(Map sqlWhereParamMap, StringBuilder sql) { + this.createTimeFilterSql(sqlWhereParamMap, sql, "po.time"); + this.createKeyWordFilterSql(sqlWhereParamMap, sql); + } + + @Override + public void createKeyWordFilterSql(Map sqlWhereParamMap, StringBuilder sql) { + String keyWord = sqlWhereParamMap.get("keyWord"); + if (StringUtils.isNotBlank(keyWord)) { + sql.append(" and po.id in (select egbi.expensiveGoodsbBill.id from ExpensiveGoodsBillItem egbi where "); + sql.append(String.format(" egbi.expensiveGoodsId = %s)", keyWord)); + } + } +} Index: ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/imagefilemanager/service/ImageFileManagerImpl.java =================================================================== diff -u -r20820 -r21030 --- ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/imagefilemanager/service/ImageFileManagerImpl.java (.../ImageFileManagerImpl.java) (revision 20820) +++ ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/imagefilemanager/service/ImageFileManagerImpl.java (.../ImageFileManagerImpl.java) (revision 21030) @@ -33,13 +33,15 @@ import com.forgon.disinfectsystem.basedatamanager.supplier.service.RegistrationCertificationManager; import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; import com.forgon.disinfectsystem.common.geom.SizeAndPosition; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBill; import com.forgon.disinfectsystem.entity.basedatamanager.imagefilemanager.ImageFile; import com.forgon.disinfectsystem.entity.basedatamanager.materialdefinition.MaterialDefinition; import com.forgon.disinfectsystem.entity.basedatamanager.supplier.RegistrationCertification; import com.forgon.disinfectsystem.entity.basedatamanager.supplier.Supplier; import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; import com.forgon.disinfectsystem.entity.qualitymonitoringmanager.qualitymonitoring.QualityMonitoringInstance; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsBillManager; import com.forgon.disinfectsystem.tousse.materialdefinition.service.MaterialDefinitionManager; import com.forgon.disinfectsystem.tousse.toussedefinition.service.TousseDefinitionManager; import com.forgon.tools.db.DatabaseUtil; @@ -70,6 +72,14 @@ private RegistrationCertificationManager registrationCertificationManager; + private ExpensiveGoodsBillManager expensiveGoodsBillManager; + + + public void setExpensiveGoodsBillManager( + ExpensiveGoodsBillManager expensiveGoodsBillManager) { + this.expensiveGoodsBillManager = expensiveGoodsBillManager; + } + public void setSupplyRoomConfigManager( SupplyRoomConfigManager supplyRoomConfigManager) { this.supplyRoomConfigManager = supplyRoomConfigManager; @@ -762,7 +772,16 @@ registrationCertification.setIsUploadImage("是"); objectDao.saveOrUpdate(registrationCertification); - } else { + }else if(ImageFile.IMAGE_TYPE_ExpensiveGoodsBill + .equals(objectType)){ + ExpensiveGoodsBill expensiveGoodsBill = expensiveGoodsBillManager.getExpensiveGoodsBillById(objectID); + for (ImageFile imageFile : uploadImageList) { + setImageFileOrder(imageFile); + imageFile.setObjectId(expensiveGoodsBill.getId().toString()); + saveImage(imageFile); + } + objectDao.saveOrUpdate(expensiveGoodsBill); + } else { ret = false; } return ret; Index: ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillManagerImpl.java =================================================================== diff -u --- ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillManagerImpl.java (revision 0) +++ ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/service/ExpensiveGoodsBillManagerImpl.java (revision 21030) @@ -0,0 +1,615 @@ +package com.forgon.disinfectsystem.expensiveGoods.service; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sf.json.JSONObject; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFFont; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.RichTextString; +import org.springframework.stereotype.Service; + +import com.forgon.Constants; +import com.forgon.directory.model.BarcodeDevice; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBill; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBillItem; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsGodownEntry; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsGodownEntryItem; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsInstance; +import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntry; +import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchaseItem; +import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchasePlan; +import com.forgon.disinfectsystem.vo.GodownEntryItemPrintVO; +import com.forgon.serialnumber.model.SerialNum; +import com.forgon.serialnumber.service.SerialNumManager; +import com.forgon.tools.Path; +import com.forgon.tools.date.DateTools; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.excel.ExcelCellStyle; +import com.forgon.tools.excel.ExcelHelper; +import com.forgon.tools.hibernate.BasePoManagerImpl; +import com.forgon.tools.hibernate.ObjectDao; +import com.forgon.tools.json.JSONUtil; +import com.forgon.tools.util.ForgonDateUtils; + +@Service("expensiveGoodsBillManagerTarget") +public class ExpensiveGoodsBillManagerImpl extends BasePoManagerImplimplements ExpensiveGoodsBillManager { + + private ObjectDao objectDao; + + private SerialNumManager serialNumManager; + + private ExpensiveGoodsManager expensiveGoodsManager; + + public void setExpensiveGoodsManager(ExpensiveGoodsManager expensiveGoodsManager) { + this.expensiveGoodsManager = expensiveGoodsManager; + } + + public void setObjectDao(ObjectDao objectDao) { + this.objectDao = objectDao; + } + + public void setSerialNumManager(SerialNumManager serialNumManager) { + this.serialNumManager = serialNumManager; + } + + public void saveOrUpdate(ExpensiveGoodsBill expensiveGoodsBill) { + objectDao.saveOrUpdate(expensiveGoodsBill); + } + + + @Override + public ExpensiveGoodsBill getExpensiveGoodsBillById(String id) { + return (ExpensiveGoodsBill) objectDao.getByProperty( + ExpensiveGoodsBill.class.getSimpleName(), "id", Long.valueOf(id)); + } + + @Override + public ExpensiveGoodsBillItem getExpensiveGoodsBillItemById(String itemId) { + return (ExpensiveGoodsBillItem) objectDao.getByProperty( + ExpensiveGoodsBillItem.class.getSimpleName(), "id", Long.valueOf(itemId)); + } + + private ExpensiveGoodsBill getExpensiveGoodsBillById_ForUpdate(String id){ + return (ExpensiveGoodsBill) objectDao.getByProperty_ForUpdate( + ExpensiveGoodsBill.class.getSimpleName(), "id", Long.valueOf(id)); + } + private void deleteExpensiveGoodsBillItem(ExpensiveGoodsBillItem expensiveGoodsBillItem) { + // 删除goodPurchaseItem + expensiveGoodsBillItem.getExpensiveGoodsbBill().getItems().remove(expensiveGoodsBillItem); + objectDao.delete(expensiveGoodsBillItem); + } + + @Override + public Map deleteExpensiveGoodsBill(String id) { + Map result = new HashMap(); + result.put("success", false); + try { + // 锁定并获取采购计划单 + ExpensiveGoodsBill expensiveGoodsBill = getExpensiveGoodsBillById_ForUpdate(id); + if (expensiveGoodsBill == null) { + // 采购计划单已被删除 + throw new RuntimeException("采购计划单已被删除!"); + } + + List itemList = new ArrayList(expensiveGoodsBill.getItems()); + for (ExpensiveGoodsBillItem expensiveGoodsBillItem : itemList) { + deleteExpensiveGoodsBillItem(expensiveGoodsBillItem); + } + //删除 + objectDao.delete(expensiveGoodsBill); + result.put("success", true); + } catch (Exception e) { + e.printStackTrace(); + result.put("errMsg", e.getMessage()); + throw e; + } + + return result; + } + + private static ExpensiveGoodsBillItem getExpensiveGoodsBillItemByItemId( + List items, Long id) { + if (id == null) { + return null; + } + for (ExpensiveGoodsBillItem item : items) { + Long itemID = item.getId(); + if (itemID != null && itemID.equals(id)) { + return item; + } + } + return null; + } + + @Override + public void updateExpensiveGoodsBill(ExpensiveGoodsBill original, + ExpensiveGoodsBill bill, Map returnMsg) { + + // 锁定并获取发票单 + ExpensiveGoodsBill curExpensiveGoodsBill = getExpensiveGoodsBillById_ForUpdate(original.getId().toString()); + if(curExpensiveGoodsBill == null){ + // 发票单已被删除 + throw new RuntimeException("发票单已被删除!"); + } + + List originalItemList = original.getItems(); + List billItemList = bill.getItems();//修改的发票单明细 + List curItemList = curExpensiveGoodsBill.getItems();//未修改的发票明细 + + // 处理修改 + for (int i = 0; i < billItemList.size(); ++i) { + ExpensiveGoodsBillItem expensiveGoodsBillItem = billItemList.get(i); + Long itemID = expensiveGoodsBillItem.getId(); + if(itemID == null){ + continue; + } + ExpensiveGoodsBillItem originalExpensiveGoodsBillItem = getExpensiveGoodsBillItemByItemId(originalItemList, itemID); + if(originalExpensiveGoodsBillItem == null){ + // 在页面上被删除了。 + //continue; + throw new RuntimeException("参数错误!"); + } + ExpensiveGoodsBillItem curExpensiveGoodsBillItem = getExpensiveGoodsBillItemByItemId(curItemList, itemID); + if(curExpensiveGoodsBillItem == null){ + // 被并发删除了,也不需要处理 + continue; + } + + // 数量 + Long originalAmount = originalExpensiveGoodsBillItem.getAmount(); + Long amount = expensiveGoodsBillItem.getAmount(); + Long curAmount = curExpensiveGoodsBillItem.getAmount(); + if(originalAmount == null || !originalAmount.equals(amount)){ + if(curAmount != null && !curAmount.equals(originalAmount)){// 有可能被并发修改了库存 + throw new RuntimeException("数量已被修改!"); + } + Long amountChange = amount - originalAmount; + + curExpensiveGoodsBillItem.setAmount(amount); + } + // 修改价格 + Double originalPrice = originalExpensiveGoodsBillItem.getPrice(); + Double price = expensiveGoodsBillItem.getPrice(); + Double curPrice = curExpensiveGoodsBillItem.getPrice(); + if(originalPrice == null || !originalPrice.equals(price)){ + if(price != null && !price.equals(curPrice)){// 这个判断是有必要的,有可能价格已经被并发修改过了。所以就不需要再修改。 + curExpensiveGoodsBillItem.setPrice(price); + } + } + } + // 处理新增 + for (int i = 0; i < billItemList.size(); ++i) { + ExpensiveGoodsBillItem expensiveGoodsBillItem = billItemList.get(i); + Long itemID = expensiveGoodsBillItem.getId(); + if(itemID != null){// 有id就不是新增项 + continue; + } + //核对发票明细 + checkExpensiveGoodsBillItem(expensiveGoodsBillItem); + //若核对成功修改高值耗材实例 + changeExpensiveGoodsInstance(expensiveGoodsBillItem,curExpensiveGoodsBill.getId()); + // 保存expensiveGoodsBillItem + expensiveGoodsBillItem.setExpensiveGoodsbBill(curExpensiveGoodsBill); + curItemList.add(expensiveGoodsBillItem); + objectDao.save(expensiveGoodsBillItem); + } + // 处理删除项 + for (int i = 0; i < originalItemList.size(); ++i) { + ExpensiveGoodsBillItem originalGodownEntryItem = originalItemList.get(i); + Long itemID = originalGodownEntryItem.getId(); + if(itemID == null){ + continue; + } + ExpensiveGoodsBillItem expensiveGoodsBillItem = getExpensiveGoodsBillItemByItemId(billItemList, itemID); + if(expensiveGoodsBillItem != null){// 现在还存在,就不是删除项 + // 在页面上被删除了。 + continue; + } + ExpensiveGoodsBillItem curExpensiveGoodsBillItem = getExpensiveGoodsBillItemByItemId(curItemList, itemID); + if(curExpensiveGoodsBillItem == null){ + // 被并发删除了。也不需要处理 + continue; + } + // 删除godownEntryItem + curItemList.remove(curExpensiveGoodsBillItem); + //需要改高值耗材实例状态吗? + objectDao.delete(curExpensiveGoodsBillItem); + } + + // 更新发票单属性 + updateExpensiveGoodsBillProperties(original, bill, curExpensiveGoodsBill); + // 更新发票单对象 + saveOrUpdate(curExpensiveGoodsBill); + } + + private void updateExpensiveGoodsBillProperties(ExpensiveGoodsBill original, + ExpensiveGoodsBill bill, ExpensiveGoodsBill curExpensiveGoodsBill) { + // 备注 + String originalRemark = original.getRemark(); + String remark = bill.getRemark(); + if(!StringUtils.equals(originalRemark, remark)){ + curExpensiveGoodsBill.setRemark(remark); + } + // 录入时间 + Date originalTime = original.getTime(); + Date time = bill.getTime(); + if(originalTime != null && !originalTime.equals(time)){ + curExpensiveGoodsBill.setTime(time); + } + // 发开票时间 + Date originalSettledTime = original.getSettledTime(); + Date settledTime = bill.getSettledTime(); + if(originalSettledTime != null && !originalSettledTime.equals(settledTime)){ + curExpensiveGoodsBill.setTime(settledTime); + } + // 供应商 + String originalSupplierId = original.getSupplierId(); + String SupplierId = bill.getSupplierId(); + if(originalSupplierId != null && !originalSupplierId.equals(SupplierId)){ + //是否可以修改供应商? + } + } + @Override + public void saveExpensiveGoodsBill(ExpensiveGoodsBill expensiveGoodsBill, + Map result) { + //核对发票单 + List expensiveGoodsBillItemList = expensiveGoodsBill.getItems(); + List expensiveGoodsInstanceList = new ArrayList(); + for (ExpensiveGoodsBillItem expensiveGoodsBillItem : expensiveGoodsBillItemList) { + + String goodName = expensiveGoodsBillItem.getGoodsName();//拼接后的名字 + Long expensiveGoodsId = expensiveGoodsBillItem.getExpensiveGoodsId();//高值耗材物品定义id + Long amount = expensiveGoodsBillItem.getAmount();//数量 + + //根据高值耗材id获得状态为'已使用'且入库类型为‘预入库’的高值耗材实例 + String sql = String.format(" where po.expensiveGoods.id = %s and po.status = '%s' and po.entryType = '%s'", + expensiveGoodsId,ExpensiveGoodsInstance.STATUS_USED,ExpensiveGoodsInstance.ENTRY_TYPE_PREPARE); + expensiveGoodsInstanceList = objectDao.findBySql( + ExpensiveGoodsInstance.class.getSimpleName(),sql); + Long usedAmount = (long) expensiveGoodsInstanceList.size(); + //判断数量是否和已使用的预入库高值耗材实例数量匹配 + if( usedAmount!= amount){ + throw new IllegalArgumentException("物品:"+goodName+"预入库已使用数量为:"+usedAmount+" 和结算数量:"+amount+"不一致!"); + } + } + //保存发票单 + objectDao.saveOrUpdate(expensiveGoodsBill); + //通过修改高值耗材实例 + for (ExpensiveGoodsInstance expensiveGoodsInstance : expensiveGoodsInstanceList) { + expensiveGoodsInstance.setStatus(ExpensiveGoodsInstance.STATUS_SETTLED);//状态改为以结算 + expensiveGoodsInstance.setExpensiveGoodsBillId(expensiveGoodsBill.getId());//高值耗材实例的发票单id赋值 + } + } + + //核对发票单 + private void checkExpensiveGoodsBill(ExpensiveGoodsBill expensiveGoodsBill){ + List expensiveGoodsBillItemList = expensiveGoodsBill.getItems(); + for (ExpensiveGoodsBillItem expensiveGoodsBillItem : expensiveGoodsBillItemList) { + checkExpensiveGoodsBillItem(expensiveGoodsBillItem); + } + } + //核对发票明细 + private void checkExpensiveGoodsBillItem(ExpensiveGoodsBillItem expensiveGoodsBillItem){ + String goodName = expensiveGoodsBillItem.getGoodsName(); + Long expensiveGoodsId = expensiveGoodsBillItem.getExpensiveGoodsId(); + Long amount = expensiveGoodsBillItem.getAmount(); + //根据高值耗材id获得状态为'已使用'且入库类型为‘预入库’的高值耗材实例 + String sql = String.format(" where po.expensiveGoods.id = %s and po.status = '%s' and po.entryType = '%s'", + expensiveGoodsId,ExpensiveGoodsInstance.STATUS_USED,ExpensiveGoodsInstance.ENTRY_TYPE_PREPARE); + List expensiveGoodsInstanceList = objectDao.findBySql( + ExpensiveGoodsInstance.class.getSimpleName(),sql); + Long usedAmount = (long) expensiveGoodsInstanceList.size(); + //判断数量是否和以使用的高值耗材实例匹配 + if( usedAmount!= amount){ + throw new IllegalArgumentException("物品:"+goodName+"预入库已使用数量为:"+usedAmount+" 和结算数量:"+amount+"不一致!"); + } + } + //通过发票明细修改高值耗材实例 + private void changeExpensiveGoodsInstance( + ExpensiveGoodsBillItem expensiveGoodsBillItem, + Long expensiveGoodsBillId){ + Long expensiveGoodsId = expensiveGoodsBillItem.getExpensiveGoodsId(); + //根据高值耗材物品id获得状态为'已使用'且入库类型为‘预入库’的高值耗材实例 + String sql = String.format(" where po.expensiveGoods.id = %s and po.status = '%s' and po.entryType = '%s'", + expensiveGoodsId,ExpensiveGoodsInstance.STATUS_USED,ExpensiveGoodsInstance.ENTRY_TYPE_PREPARE); + List expensiveGoodsInstanceList = objectDao.findBySql( + ExpensiveGoodsInstance.class.getSimpleName(),sql); + + for (ExpensiveGoodsInstance expensiveGoodsInstance : expensiveGoodsInstanceList) { + expensiveGoodsInstance.setStatus(ExpensiveGoodsInstance.STATUS_SETTLED);//状态改为以结算 + expensiveGoodsInstance.setExpensiveGoodsBillId(expensiveGoodsBillId);//高值耗材实例的发票单id赋值 + } + } + + @Override + public void updateBillInfo(ExpensiveGoodsBill bill,JSONObject billInfo) { + if(bill == null || billInfo == null){ + return; + } + //获得表单的数据 + Long id = billInfo.optLong("id"); + String remark = billInfo.optString("remark"); + String timeStr = billInfo.optString("time"); + String settledTimeStr = billInfo.optString("settledTime"); + String operator = billInfo.optString("operator"); + String serialNumber = billInfo.optString("serialNumber"); + String supplierId = billInfo.optString("supplierId"); + String supplierName = billInfo.optString("supplier1"); + + if(DatabaseUtil.isPoIdValid(id)){ + bill.setId(id); + } + bill.setRemark(remark); + bill.setOperator(operator); + bill.setSerialNumber(serialNumber); + bill.setSupplierId(supplierId); + bill.setSupplierName(supplierName); + Date time; + Date settledTime; + try { + time = new SimpleDateFormat(DateTools.COMMON_DATE_ONLY).parse(timeStr); + settledTime = new SimpleDateFormat(DateTools.COMMON_DATE_ONLY).parse(settledTimeStr); + } catch (ParseException e) { + e.printStackTrace(); + throw new RuntimeException("日期格式错误!"); + } + bill.setTime(time); + bill.setSettledTime(settledTime); + } + + @Override + public void addItemToBill(ExpensiveGoodsBill bill, JSONObject itemObject) { + if(bill == null || itemObject == null){ + throw new IllegalArgumentException("entry和itemObject都不能为空"); + } + //新建发票明细 + ExpensiveGoodsBillItem expensiveGoodsBillItem = parseExpensiveGoodsBillItem(itemObject); + expensiveGoodsBillItem.setExpensiveGoodsbBill(bill); + bill.getItems().add(expensiveGoodsBillItem); + } + + //新建发票明细 + private ExpensiveGoodsBillItem parseExpensiveGoodsBillItem(JSONObject itemObject) { + if(itemObject == null){ + return null; + } + Long itemId = JSONUtil.optLong(itemObject,"id",null); + Long expensiveGoodsId = JSONUtil.optLong(itemObject,"expensiveGoodsId",null);//高值耗材定义id + Long amount = JSONUtil.optLong(itemObject,"amount",null);//数量 + double price = Double.valueOf(itemObject.optString("price"));// 价格 + ExpensiveGoods expensiveGoods = expensiveGoodsManager.get(expensiveGoodsId); + //拼接物品名字[规格] + String goodsName = expensiveGoods.getName(); + if(expensiveGoods.getSpecification() !=null){ + goodsName+="["+expensiveGoods.getSpecification()+"]"; + } + ExpensiveGoodsBillItem expensiveGoodsBillItem = new ExpensiveGoodsBillItem(); + expensiveGoodsBillItem.setName(expensiveGoods.getName()); + expensiveGoodsBillItem.setSpecification(expensiveGoods.getSpecification()); + expensiveGoodsBillItem.setGoodsName(goodsName); + expensiveGoodsBillItem.setId(itemId); + expensiveGoodsBillItem.setExpensiveGoodsId(expensiveGoodsId); + expensiveGoodsBillItem.setAmount(amount); + expensiveGoodsBillItem.setPrice(price); + return expensiveGoodsBillItem; + } + +///////////////// + // 获取入库单打印信息 + @Override + public void loadGoodPurchasePlanPrintData( + String[] invoiceIds,JSONObject jsonObject) { + Collection tousseList = CollectionUtils.emptyCollection(); + jsonObject.put("goods", tousseList); + if (ArrayUtils.isEmpty(invoiceIds)){ + return ; + } + + String idsStr = StringUtils.join(invoiceIds, ","); + String sql = String.format(" where po.id in (%s)", idsStr); + List list = objectDao.findBySql( + GoodPurchasePlan.class.getSimpleName(), sql); + if (list == null || list.size() == 0){ + return ; + } + String serialNumber = ""; + String applicant = ""; + String time = ""; + String supplierName = "";//供应商 + if(list.size() == 1){ + GoodPurchasePlan plan = list.get(0); + serialNumber = plan.getSerialNumber(); + time = ForgonDateUtils.safelyFormatDate(plan.getTime(), Constants.DATEFORMAT_YYYYMMDD, ""); + List items = plan.getItemsList(); + if(items != null && items.size() > 0){ + supplierName = items.get(0).getSupplierName(); + } + } + jsonObject.put("serialNumber", serialNumber); + jsonObject.put("applicant", applicant); + jsonObject.put("godownEntryTime", time); + jsonObject.put("supplierName", supplierName); + + tousseList = loadToussePrintData(list); + jsonObject.put("goods", tousseList); + } + + // 找出已经存在项 + private Collection loadToussePrintData( + Collection plans) { + if (CollectionUtils.isEmpty(plans)) { + return CollectionUtils.emptyCollection(); + } + + List voList = new ArrayList(); +// for (GoodPurchasePlan plan : plans) { +// List items = plan.getItemsList(); +// for (GoodPurchaseItem item : items) { +// JSONObject obj = CssdUtils.getGoodsNameAndSp(item.getName()); +// DisposableGoods diposableGoods = diposableGoodsManager.get( +// obj.optString("materialName"), +// obj.optString("specification")); +// GodownEntryItemPrintVO tempVo = new GodownEntryItemPrintVO(); +// if(diposableGoods == null && DatabaseUtil.isPoIdValid(item.getMaterialDefinitionId())){ +// MaterialDefinition md = +// (MaterialDefinition)objectDao.getBySql(MaterialDefinition.class.getSimpleName(), "where id=" + item.getMaterialDefinitionId()); +// if(md == null){ +// continue; +// } +// tempVo.setCode(md.getExternalCode()); +// tempVo.setName(md.getName()); +// tempVo.setSpecification(md.getSpecification()); +// tempVo.setInventorySerialNumber(md.getInventorySerialNumber()); +// tempVo.setUnit(md.getUnit()); +// }else{ +// tempVo.setCode(diposableGoods.getExternalCode()); +// tempVo.setName(diposableGoods.getName()); +// tempVo.setSpecification(diposableGoods.getSpecification()); +// tempVo.setInventorySerialNumber(diposableGoods.getInventorySerialNumber()); +// tempVo.setUnit(diposableGoods.getUnit()); +// tempVo.setCertification(diposableGoods.getCertification()); +// } +// tempVo.setAmount(Long.valueOf(item.getScheduleAmout())); +// tempVo.setPrice(item.getPurchase()); +// tempVo.setRowPrice(item.getTotalPrice()); +// tempVo.setTotalPrice(tempVo.getRowPrice()); +// tempVo.setBatchNumber(""); +// tempVo.setSupplierName(item.getSupplierName()); +// voList.add(tempVo); +// } +// } + return voList; + } + + +// @Override +// public void exportGoodPurchasePlan(OutputStream ops, String ids) { +// String sql = String.format(" where po.id in (%s)", ids); +// +// @SuppressWarnings("unchecked") +// List list = objectDao.findBySql( +// GoodPurchasePlan.class.getSimpleName(), sql); +// Collection itemVos = loadToussePrintData(list); +// createExportFile(itemVos, ops); +// +// } + private void createExportFile(Collection itemVos, + OutputStream ops) { + String inputFile = Path.getWebAppRoot() + + "/disinfectsystem/reportforms/receiveDetail.xls"; + FileInputStream fos = null; + POIFSFileSystem fs = null; + HSSFWorkbook wb = null; + try { + fos = new FileInputStream(inputFile); + fs = new POIFSFileSystem(fos); + wb = new HSSFWorkbook(fs); + ExcelHelper.setWorkbook(wb); + ExcelCellStyle.iniAllStyles(); + HSSFSheet sheet = wb.getSheetAt(0); + + HSSFCellStyle cellStyle = wb.createCellStyle(); // 数据单元格格式 + cellStyle.setWrapText(true); + cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); + cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); + HSSFFont font = wb.createFont(); + font.setFontHeightInPoints((short) 10); // 设置字体大小为10 + font.setFontName("宋体"); + cellStyle.setFont(font); + + HSSFRow operatingRow1 = sheet.createRow(0); + createCell(operatingRow1, cellStyle, 0, "编码"); + createCell(operatingRow1, cellStyle, 1, "名称"); + createCell(operatingRow1, cellStyle, 2, "规格"); + createCell(operatingRow1, cellStyle, 3, "单位"); + createCell(operatingRow1, cellStyle, 4, "数量"); + createCell(operatingRow1, cellStyle, 5, "进价"); + createCell(operatingRow1, cellStyle, 6, "进价金额"); + createCell(operatingRow1, cellStyle, 7, "产地"); + createCell(operatingRow1, cellStyle, 8, "供应商"); + createCell(operatingRow1, cellStyle, 9, "注册证号"); + + int row = 1; + for (GodownEntryItemPrintVO item : itemVos) { + HSSFRow operatingRow = sheet.createRow(row); + createCell(operatingRow, cellStyle, 0, item.getCode()); + createCell(operatingRow, cellStyle, 1,item.getName()); + createCell(operatingRow, cellStyle, 2, item.getSpecification()); + createCell(operatingRow, cellStyle, 3, item.getUnit()); + Long storage = item.getAmount(); + if (storage != null) { + createCell(operatingRow, cellStyle, 4, + Integer.parseInt("" + storage)); + } else { + createCell(operatingRow, cellStyle, 4, 0); + } + + createCell(operatingRow, cellStyle, 5, item.getPrice()); + createCell(operatingRow, cellStyle, 6,item.getTotalPrice()); + createCell(operatingRow, cellStyle, 7,item.getProducingArea()); + createCell(operatingRow, cellStyle, 8,item.getSupplierName()); + createCell(operatingRow, cellStyle, 9,item.getCertification()); + row++; + } + wb.write(ops); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + ops.close(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + private void createCell(HSSFRow row, HSSFCellStyle cellStyle, + int cellIndex,Object value){ + HSSFCell cell = row.createCell(cellIndex); + cell.setCellStyle(cellStyle); + if(value != null){ + if(value instanceof Double){ + cell.setCellValue((Double) value); + }else if(value instanceof Integer){ + cell.setCellValue((Integer)value); + }else if(value instanceof Boolean){ + cell.setCellValue((Boolean)value); + }else if(value instanceof Date){ + cell.setCellValue((Date)value); + }else if(value instanceof Calendar){ + cell.setCellValue((Calendar)value); + }else if(value instanceof RichTextString){ + cell.setCellValue((RichTextString)value); + }else{ + cell.setCellValue(value.toString()); + } + } + } + +/////////////////////////// + +} Index: ssts-web/src/main/webapp/homepage/menuconfigure.js =================================================================== diff -u -r20981 -r21030 --- ssts-web/src/main/webapp/homepage/menuconfigure.js (.../menuconfigure.js) (revision 20981) +++ ssts-web/src/main/webapp/homepage/menuconfigure.js (.../menuconfigure.js) (revision 21030) @@ -331,7 +331,8 @@ //{hidden :SSTS_ExpensiveGoods_Menu,text:"高值耗材调拨单管理",href:WWWROOT+'/disinfectsystem/assestManagement/godownEntry/appropriationView.jsp',hrefTarget:linkTarget,leaf:true}, //{hidden :SSTS_DisposableGoodsProfitAndLoss_Manager,text:"高值耗材盘盈盘亏管理",href:WWWROOT+'/disinfectsystem/assestManagement/godownEntry/godownStockTakeView.jsp',hrefTarget:linkTarget,leaf:true}, //{hidden :!sstsConfig.enableExpensiveGoods,text:"高值耗材盘点管理",href:WWWROOT+'/disinfectsystem/stocktakerecordmanager/inventoryrecordView.jsp'+'?type=expensiveGoods',hrefTarget:linkTarget,leaf:true}, - {hidden :SSTS_ExpensiveGoods_Menu,text:"高值耗材结算管理",href:WWWROOT+'/disinfectsystem/reportforms/stocktakeView.jsp',hrefTarget:linkTarget,leaf:true} + {hidden :SSTS_ExpensiveGoods_Menu,text:"高值耗材结算管理",href:WWWROOT+'/disinfectsystem/reportforms/stocktakeView.jsp',hrefTarget:linkTarget,leaf:true}, + {hidden :SSTS_ExpensiveGoods_Menu,text:"高值耗材发票管理",href:WWWROOT+'/disinfectsystem/assestManagement/expensiveGoods/expensiveGoodsBillView.jsp',hrefTarget:linkTarget,leaf:true} ] },{ text:"采购计划", Index: ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/action/ExpensiveGoodsBillAction.java =================================================================== diff -u --- ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/action/ExpensiveGoodsBillAction.java (revision 0) +++ ssts-expensivegoods/src/main/java/com/forgon/disinfectsystem/expensiveGoods/action/ExpensiveGoodsBillAction.java (revision 21030) @@ -0,0 +1,312 @@ +package com.forgon.disinfectsystem.expensiveGoods.action; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +import org.apache.commons.lang.StringUtils; +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.Namespace; +import org.apache.struts2.convention.annotation.ParentPackage; + +import com.forgon.Constants; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.directory.service.OrgUnitManager; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBill; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBillItem; +import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchasePlan; +import com.forgon.disinfectsystem.entity.basedatamanager.imagefilemanager.ImageFile; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsBillManager; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsManager; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsPurchasePlanManager; +import com.forgon.tools.ImageUtils; +import com.forgon.tools.StrutsParamUtils; +import com.forgon.tools.util.PageUtil; +import com.opensymphony.xwork2.ModelDriven; + +@ParentPackage(value = "default") +@Namespace(value = "/disinfectSystem") +@Action(value = "expensiveGoodsBillAction") +public class ExpensiveGoodsBillAction implements ModelDriven { + + private OrgUnitManager orgUnitManager; + + private String spell; + + private ExpensiveGoodsManager expensiveGoodsManager; + + private ExpensiveGoodsBillManager expensiveGoodsBillManager; + + private ExpensiveGoodsBill expensiveGoodsBill = new ExpensiveGoodsBill(); + + + public void setExpensiveGoodsBill(ExpensiveGoodsBill expensiveGoodsBill){ + this.expensiveGoodsBill = expensiveGoodsBill; + } + + public void setExpensiveGoodsBillManager(ExpensiveGoodsBillManager expensiveGoodsBillManager) { + this.expensiveGoodsBillManager = expensiveGoodsBillManager; + } + + + public void setOrgUnitManager(OrgUnitManager orgUnitManager) { + this.orgUnitManager = orgUnitManager; + } + + public String getSpell() { + return spell; + } + + public void setSpell(String spell) { + this.spell = spell; + } + + public void setExpensiveGoodsManager(ExpensiveGoodsManager expensiveGoodsManager) { + this.expensiveGoodsManager = expensiveGoodsManager; + } + + @Override + public ExpensiveGoodsBill getModel() { + return expensiveGoodsBill; + } + + /** + * @param out + * :输出流 + * @param result + * :显示的文本信息 + */ + private void printMsgToClient(boolean success, PrintWriter out, + String result, String printResult) { + String printValue = null; + if (printResult != null && printResult.length() > 0) { + String str = printResult.toString(); + printValue = str.substring(0, str.length() - 1); + } + out.print("{success:" + success + ",message:'" + result + "',barcode:'" + + printValue + "'}"); + out.close(); + } + + /** + * 根据拼音简拼,获取高值耗材物品 + * + * @return + * @throws Exception + */ + public String getExpensiveGoodsData() { + spell = spell == null ? "" : spell; + try { + spell = java.net.URLDecoder.decode(spell, "UTF-8"); + //是否搜索全部高值耗材 + String allItems = StrutsParamUtils.getPraramValue("allItems",null); + String handleDepartCode = AcegiHelper.getCurrentOrgUnitCode(); + List> mapList = expensiveGoodsManager.searchExpensiveGoodsAndMaterialList(spell, allItems, handleDepartCode, true); + PageUtil.outPutResult(PageUtil.getPagePara(), mapList); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 保存高值耗材发票 + */ + public String saveExpensiveGoodsBill() { + HttpServletResponse response = StrutsParamUtils.getResponse(); + PrintWriter out = null; + String result = "保存成功"; + response.setCharacterEncoding("UTF-8"); + Map returnMsg = new HashMap(); + returnMsg.put("success", false); + returnMsg.put("errMsg", "保存失败"); + try { + out = response.getWriter(); + } catch (IOException e) { + e.printStackTrace(); + } + boolean saveResult = false; + try { + String id = StrutsParamUtils.getPraramValue("id", ""); + ExpensiveGoodsBill NewBill = expensiveGoodsBill; + if (StringUtils.isNotBlank(id)) { + ExpensiveGoodsBill original = new ExpensiveGoodsBill(); + buildExpensiveGoodsBillParamsForUpdate(original, NewBill); + System.out.println(1); + expensiveGoodsBillManager.updateExpensiveGoodsBill(original, NewBill, returnMsg); + } else { + NewBill = expensiveGoodsBill; + buildExpensiveGoodsBillParamsForSave(NewBill); + expensiveGoodsBillManager.saveExpensiveGoodsBill(NewBill, returnMsg); + } + saveResult = true; + } catch (Exception e) { + e.printStackTrace(); + saveResult = false; + result = e.getMessage(); + } + String itemsDetails = (String)returnMsg.get("itemsDetails"); + + printMsgToClient(saveResult, out, result.toString(), itemsDetails); + return null; + } + + //新建发票对象 + private void buildExpensiveGoodsBillParamsForSave(ExpensiveGoodsBill bill) { + String items = StrutsParamUtils.getPraramValue("items", ""); + String formParams = StrutsParamUtils.getPraramValue("formParams", ""); + + setBillPropertiesFromParams(bill,formParams,items); + } + + //更新发票对象 + private void buildExpensiveGoodsBillParamsForUpdate(ExpensiveGoodsBill original, + ExpensiveGoodsBill bill) { + String originalFormParams = StrutsParamUtils.getPraramValue("originalFormParams", ""); + String originalItems = StrutsParamUtils.getPraramValue("originalItems", ""); + String items = StrutsParamUtils.getPraramValue("items", ""); + + setBillPropertiesFromParams(original,originalFormParams,originalItems); + setBillPropertiesFromParams(bill,null,items); + } + + // 根据前台传入参数构造发票单及发票明细对象 + private void setBillPropertiesFromParams(ExpensiveGoodsBill bill,String formParams,String items){ + // 表单参数 + if(StringUtils.isNotBlank(formParams)){ + JSONObject formParamsObj = JSONObject.fromObject(formParams); + expensiveGoodsBillManager.updateBillInfo(bill, formParamsObj); + } + // items列表 + JSONArray itemsArray = JSONArray.fromObject(items); + int size = itemsArray.size(); + for (int i = 0; i < size; ++i) { + JSONObject obj = itemsArray.optJSONObject(i); + if (obj != null) { + expensiveGoodsBillManager.addItemToBill(bill, obj); + } + } + } + + /** + * 读取高值耗材发票单 + */ + public String loadExopensiveGoodsBill() { + String id = StrutsParamUtils.getPraramValue("id", ""); + if (StringUtils.isNotBlank(id) && StringUtils.isNumeric(id)) { + expensiveGoodsBill = expensiveGoodsBillManager.getExpensiveGoodsBillById(id); + } + StrutsParamUtils.getResponse().setCharacterEncoding("UTF-8"); + + JSONArray jsonArray = new JSONArray(); + for(ExpensiveGoodsBillItem item : expensiveGoodsBill.getItems()){ + JSONObject obj = new JSONObject(); + obj.put("id", item.getId()); + obj.put("expensiveGoodsId", item.getExpensiveGoodsId()); + obj.put("name", item.getGoodsName()); + obj.put("amount", item.getAmount()); + obj.put("price", item.getPrice()); + obj.put("totalPrice", item.getAmount()*item.getPrice()); + obj.put("supplierName", expensiveGoodsBill.getSupplierName()); + + jsonArray.add(obj); + } + + JSONObject dataObj = new JSONObject(); + dataObj.put("id", expensiveGoodsBill.getId()); + dataObj.put("operator", expensiveGoodsBill.getOperator()); + dataObj.put("remark", expensiveGoodsBill.getRemark()); + dataObj.put("serialNumber",expensiveGoodsBill.getSerialNumber()); + dataObj.put("supplierId",expensiveGoodsBill.getSupplierId()); + dataObj.put("supplierName",expensiveGoodsBill.getSupplierName()); + dataObj.put("time", expensiveGoodsBill.getTime()); + dataObj.put("settledTime", expensiveGoodsBill.getSettledTime()); + dataObj.put("itemsList", jsonArray); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("success", true); + jsonObject.put("data", dataObj); + + + String jsonStr = jsonObject.toString(); + try { + StrutsParamUtils.getResponse().getWriter().println(jsonStr); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 删除高值耗材发票单 + */ + public void deleteGoodPurchasePlan() { + String idStr = StrutsParamUtils.getPraramValue("ids", ""); + String message = ""; + try { + if (StringUtils.isNotBlank(idStr)) { + Map result = new HashMap(); + int deletedCount = 0; + int totalCount = 0; + result.put("deletedCount", deletedCount); + result.put("totalCount", totalCount); + result.put("failureCount", totalCount - deletedCount); + try { + String[] idsArray = idStr.split(Constants.IDS_SEPARATOR); + totalCount = idsArray.length; + for (String id : idsArray) { + // 每一个入库单作为一个单独的事务 + try { + expensiveGoodsBillManager.deleteExpensiveGoodsBill(id); + deletedCount++; + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + int failureCount = totalCount-deletedCount; + message = "成功删除"+deletedCount+"条采购计划单信息,失败"+failureCount+"条"; + } + } catch (Exception e) { + message = "删除失败!"; + e.printStackTrace(); + } + HttpServletResponse httpServletResponse = StrutsParamUtils + .getResponse(); + httpServletResponse.setCharacterEncoding("UTF-8"); + try { + httpServletResponse.getWriter().print( + "{success:true,message:'" + message + "'}"); + } catch (IOException e) { + e.printStackTrace(); + } + } + +// // 合并打印 +// public void mergeLoadToussePrintData() { +// try { +// String idsStr = StrutsParamUtils.getPraramValue("ids", ""); +// String[] idStrs = StringUtils.split(idsStr, ','); +// +// JSONObject jsonObject = new JSONObject(); +// expensiveGoodsPurchasePlanManager.loadGoodPurchasePlanPrintData(idStrs, jsonObject); +// jsonObject.put("success", true); +// HttpServletResponse response = StrutsParamUtils.getResponse(); +// response.setCharacterEncoding("UTF-8"); +// response.getWriter() +// .println(jsonObject.toString()); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +} Index: ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/showExpensiveGoodsBillUploadIamge.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/showExpensiveGoodsBillUploadIamge.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/showExpensiveGoodsBillUploadIamge.js (revision 21030) @@ -0,0 +1,148 @@ +//图片上传分页定义 +var currentImageType; +var page = 1; +var totalPage = 0; +var toolbarPage = new Ext.Toolbar.TextItem({ + text : '第 1 页' +}); +var toolbarTotalPage = new Ext.Toolbar.TextItem({ + text : '共 0 页' +}); + +var pageNameStr = new Ext.Toolbar.TextItem({ + text : ' ' +}); + + +//展示高值耗材预览图 +function showUploadImageWin(objectId) { + currentImageType = imageType_expensiveGoodsBill; + var imagePanel = new top.Ext.Panel({ + id : 'imagePanel', + layout : 'fit', + bbar : [{ + xtype : 'button', + text : '删除此图片', + tooltip:'删除当前图片', + listeners:{ + click : function(thiz, e){ + Ext.Ajax.request({ + url : WWWROOT + '/disinfectSystem/baseData/showImageAction!deleteExpensiveGoodsBillUploadImage.do?page='+page, + params : {id : objectId,pageNum:page}, + success : function(response,options){ + showResult("删除成功!"); + loadImage(objectId,currentImageType); + }, + failure : function(response, options) { + showResult('删除失败!'); + } + }); + } + } + },'->',{ + xtype : 'button', + text : '<<', + tooltip:'上一页', + handler : function(){ + if (page - 1 <= 0) { + showResult('已是第一页'); + return; + } + page = page - 1; + + var url = WWWROOT + '/disinfectSystem/baseData/showImageAction!getExpensiveBillImage.do?objectId='+objectId + '&page=' + page+'&imageType='+currentImageType+'&time='+new Date(); + var imageBrowse = top.Ext.get('imageBrowse'); + var image = imageBrowse.dom; + image.src = url;// 覆盖原来的图片 + var element = Ext.get(toolbarPage.el); + element.update('第 ' + page + ' 页'); + } + }, + toolbarPage, + toolbarTotalPage,{ + xtype : 'button', + text : '>>', + tooltip:'下一页', + handler : function() { + if (page + 1 > totalPage) { + showResult('已是最后一页'); + return; + } + page = page + 1; + var url = WWWROOT + '/disinfectSystem/baseData/showImageAction!getExpensiveBillImage.do?objectId='+objectId + '&page=' + page+'&imageType='+currentImageType+'&time='+new Date(); + var imageBrowse = top.Ext.get('imageBrowse'); + var image = imageBrowse.dom; + image.src = url;// 覆盖原来的图片 + var element = Ext.get(toolbarPage.el); + element.update('第 ' + page + ' 页'); + } + }], + items : [{ + xtype : 'box', + id : 'browseImage', + fieldLabel : "预览图片", + autoEl : { + id : 'imageBrowse', + tag : 'img', + autoHeight:true, + src : Ext.BLANK_IMAGE_URL, + style : 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);', + complete : 'off' + } + }] + }); + + /////////////////////////////////////////图片预览 + + var window = new top.Ext.Window({ + id : 'packageImg', + title : '图片预览', + width : 650, + height :450, + border : false, + autoScroll: true, + autoShow:true, + layout : 'fit', + items : [imagePanel] + }); + window.show(); + //图片 + if(objectId == undefined && objectId == "objectId" && objectId == null||objectId==""){ + objectId=""; + } + loadImage(objectId,currentImageType); +} + + +function loadImage(objectId,imageType){ + page = 1; + totalPage = 0; + //加载当前包图片总页数 + Ext.Ajax.request({ + url : WWWROOT + '/disinfectSystem/baseData/showImageAction!getExpenGoodsBillUploadImageCount.do', + params : { + imageType:imageType, + objectId:objectId + }, + success : function(result){ + var pageStr = result.responseText; + if(pageStr==null||pageStr=='undefiend'){ + totalPage=0; + } + totalPage = parseInt(pageStr); + var element = Ext.get(toolbarTotalPage.el); + element.update(' 共 ' + totalPage + ' 页'); + //加载图片 + var url = WWWROOT + '/disinfectSystem/baseData/showImageAction!getExpensiveBillImage.do?objectId='+objectId + '&page=' + page+'&imageType='+currentImageType+'&time='+new Date(); + var imageBrowse = top.Ext.get('imageBrowse'); + var image = imageBrowse.dom; + image.src = url;// 覆盖原来的图片 + var element = top.Ext.get(toolbarPage.el); + element.update('第 ' + page + ' 页'); + + var element = Ext.get(pageNameStr.el); + }, + failure : function(){ + } + }); +} \ No newline at end of file Index: ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/expensiveGoodsBillView.jsp =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/expensiveGoodsBillView.jsp (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/expensiveGoodsBillView.jsp (revision 21030) @@ -0,0 +1,103 @@ +<%@page import="com.forgon.disinfectsystem.entity.basedatamanager.supplier.Supplier,com.forgon.disinfectsystem.entity.assestmanagement.GodownEntry "%> +<%@ page contentType="text/html; charset=UTF-8"%> +<%@ include file="/common/taglibs.jsp"%> +<%@ include file="/common/includeExtJsAndCss.jsp"%> +<%@ page import="com.forgon.tools.SpringBeanManger" %> +<% + String userName = AcegiHelper.getLoginUser().getUserFullName(); + request.setAttribute("userName",userName); + String departName = AcegiHelper.getLoginUser().getCurrentOrgUnitName(); + request.setAttribute("departName",departName); + String departCoding = AcegiHelper.getLoginUser().getOrgUnitCodingFromSupplyRoomConfig(); + request.setAttribute("departCoding",departCoding); + //System.out.println(departName + " : " + departCoding); +%> +<%@ include file="/common/includeExtJs4_2.jsp"%> + + + +高值耗材发票管理 + + + + + + + + + + + + + + + + +<%@page import="com.forgon.disinfectsystem.entity.basedatamanager.imagefilemanager.ImageFile"%> + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + +
+ + + + + <%----%> +
+ + + \ No newline at end of file Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/imagefilemanager/ImageFile.java =================================================================== diff -u -r20892 -r21030 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/imagefilemanager/ImageFile.java (.../ImageFile.java) (revision 20892) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/imagefilemanager/ImageFile.java (.../ImageFile.java) (revision 21030) @@ -42,6 +42,7 @@ public static final String IMAGE_TYPE_STERILIZATION = "灭菌监测图片"; public static final String IMAGE_TYPE_SPECIFICATION = "器械包说明书"; public static final String IMAGE_TYPE_CERTIFICATION = "注册证图片"; + public static final String IMAGE_TYPE_ExpensiveGoodsBill = "发票图片"; private Long id; Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsBillItem.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsBillItem.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/ExpensiveGoodsBillItem.java (revision 21030) @@ -0,0 +1,137 @@ +package com.forgon.disinfectsystem.entity.assestmanagement; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Cascade; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsBatchStock; +import com.forgon.disinfectsystem.entity.basedatamanager.materialdefinition.MaterialDefinition; + +/** + * 高值耗材发票明细 + * + */ +@Entity +@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class ExpensiveGoodsBillItem { + + private Long id; + + /** + * 高值耗材发票单 + */ + private ExpensiveGoodsBill expensiveGoodsbBill; + + /** + * 高值耗材定义id + */ + private Long expensiveGoodsId ; + + /** + * 一次性物品名称,带规格 + */ + private String goodsName; + + /** + * 物品名称 + */ + private String name; + + /** + * 规格 + */ + private String specification; + + /** + * 价格 + */ + private Double price; + + /** + * 数量 + */ + private Long amount ; + + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @ManyToOne + @JoinColumn(name = "expensivegoodsbill_id") + public ExpensiveGoodsBill getExpensiveGoodsbBill() { + return expensiveGoodsbBill; + } + + public void setExpensiveGoodsbBill(ExpensiveGoodsBill expensiveGoodsInvoice) { + this.expensiveGoodsbBill = expensiveGoodsInvoice; + } + + public Long getAmount() { + return amount; + } + + public void setAmount(Long amount) { + this.amount = amount; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public String getGoodsName() { + return goodsName; + } + + public void setGoodsName(String goodsName) { + this.goodsName = goodsName; + } + + public Long getExpensiveGoodsId() { + return expensiveGoodsId; + } + + public void setExpensiveGoodsId(Long expensiveGoodsId) { + this.expensiveGoodsId = expensiveGoodsId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSpecification() { + return specification; + } + + public void setSpecification(String specification) { + this.specification = specification; + } + +} Index: ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/expensiveGoodsBillView.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/expensiveGoodsBillView.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/assestManagement/expensiveGoods/expensiveGoodsBillView.js (revision 21030) @@ -0,0 +1,1055 @@ +var entityName = "采购计划管理"; +var grid; +var g_localID = 1;// 为了区分每一个item,增加的ID。 +var disableShowImageButton = true; +var recycleQM = false; +//高值耗材 +var expensiveGoodsStore = new Ext.data.Store({ + pageSize: 100, + proxy : new Ext.data.HttpProxy({ + url : WWWROOT + '/disinfectSystem/expensiveGoodsAction!getExpensiveGoodsData.do', + method : 'POST' + }), + reader : new Ext.data.JsonReader({ + totalProperty : 'totalCount', + root : 'data' + }, [ + {name : 'id',mapping : 'id'}, + {name : 'spelling',mapping : 'spelling'}, + {name : 'name',mapping : 'name'}, + {name : 'displayName',mapping : 'displayName'}, + {name : 'referencePrice',mapping : 'referencePrice'}, + {name : 'validityTime',mapping : 'validityTime'}, + {name : 'certification',mapping : 'certification'} + ]) +}); + +function dateCompare(date1,date2){ + date1 = date1.replace(/\-/gi,"/"); + date2 = date2.replace(/\-/gi,"/"); + var time1 = new Date(date1).getTime(); + var time2 = new Date(date2).getTime(); + if(time1 > time2){ + return 1; + }else if(time1 == time2){ + return 2; + }else{ + return 3; + }} + +//供应商 +var expensiveGoodsSupplierStore = new Ext.data.Store({ + proxy : new Ext.data.HttpProxy({ + url : WWWROOT + '/disinfectSystem/baseData/supplierAction!getSupplierData.do?supplierType='+encodeURI(expensiveGoodsSupplier), + method : 'POST' + }), + reader : new Ext.data.JsonReader({ + totalProperty : 'totalCount', + root : 'data' + }, [ + {name : 'id',mapping : 'id'}, + {name : 'name',mapping : 'name'} + ]) +}); + +//高值耗材采购单对象 +var expensiveGoodPurchasePlanItemRecord = Ext.data.Record.create([ + {name : 'localID'}, + {name : 'id'}, + {name : 'name'}, + {name : 'amount'}, + {name : 'price'}, + {name : 'totalPrice'}, + {name : 'supplierName'}, + {name : 'expensiveGoodsId'} +]); + +//打印,目前只支持单个打印 +function printGoodPurchasePlan(id, printType){ + if(id == null) + return; + top.Ext.MessageBox.show({ + title:'请等待', + msg:'打印中……', + width:350, + progress:true, + closable:false + }); + Ext.Ajax.timeout=300*000; + Ext.Ajax.request({ + timeout: 300*000, + url : WWWROOT + '/disinfectSystem/expensiveGoodsPurchaseAction!mergeLoadToussePrintData.do', + params : {ids : id}, + success : function(response){ + var result = Ext.decode(response.responseText); + result.printUser = curUserName; + result.printTime = Ext.util.Format.date(new Date(), 'Y-m-d H:i'); + result.formTypeOfPrinted = 'purchasePlan'; + result.unitName = ""; + setGoodsInfos(result); + hideMessageBox(true); + printPurchasePlanInfo(result, printType); + }, + failure: function(response){ + showResult("打印失败!"); + hideMessageBox(true); + } + }); +} +//判断是否填错 +function validateForm(){ + if(!top.Ext.getCmp('expensiveGoodPurchaseForm').form.isValid()){ + showResult('请正确填写表单各值'); + return false; + } + var name = top.Ext.getCmp('name1').getValue(); + if(name.length==0){ + showResult('请填写物品名称!'); + top.Ext.getCmp('name1').focus(false,100); + return false; + } + var count = top.Ext.getCmp('amount1').getValue(); + if(count.length==0){ + showResult('请填写物品数量!'); + top.Ext.getCmp('amount1').focus(false,100); + return false; + } + if(!/^\d+$/.test(count)){ + showResult('物品数量只能是整数'); + top.Ext.getCmp('amount1').focus(false,100); + return false; + } + var price = top.Ext.getCmp('price').getValue(); + if(price.length==0){ + showResult('请填写物品价格!'); + top.Ext.getCmp('price').focus(false,100); + return false; + } + if(!/^(([1-9]+[0-9]*.{1}[0-9]+)|([0].{1}[1-9]+[0-9]*)|([1-9][0-9]*)|([0][.][0-9]+[1-9]*))$/.test(price)){ + showResult('物品价格只能是正数'); + top.Ext.getCmp('price').focus(false,100); + return false; + } + var serialNumber = top.Ext.getCmp('serialNumber').getValue(); + if(!/^(([1-9]+[0-9]*.{1}[0-9]+)|([0].{1}[1-9]+[0-9]*)|([1-9][0-9]*)|([0][.][0-9]+[1-9]*))$/.test(serialNumber)){ + showResult('发票号只能是正数'); + top.Ext.getCmp('serialNumber').focus(false,100); + return false; + } + + if(top.Ext.getCmp('supplier1').getValue() == null || top.Ext.getCmp('supplier1').getValue() == ''){ + showResult("请填写供应商!"); + top.Ext.getCmp('supplier1').focus(false,100); + return false; + } + return true; +} +function clearForm(){ + top.Ext.getCmp('name1').setValue(''); + top.Ext.getCmp('amount1').setValue(''); + top.Ext.getCmp('expensiveGoodsId').setValue(''); + top.Ext.getCmp('price').setValue(''); +} + +//添加发票 +function addItems(name,amount,price,supplierName,expensiveGoodsId){ + for(var i = 0;i < top.Ext.getCmp('goodPurchaseItemGrid').getStore().getCount();i++){ + //console.log(top.Ext.getCmp('goodPurchaseItemGrid').getStore().getAt(i).data); + //console.log(name); + if(top.Ext.getCmp('goodPurchaseItemGrid').getStore().getAt(i).data.name == name){ + showResult("该物品已经存在,不能重复添加!"); + return false; + } + if(top.Ext.getCmp('goodPurchaseItemGrid').getStore().getAt(i).data.supplierName != supplierName){ + showResult("一张发票只能有一个供应商!"); + return false; + } + } + + var amount = Ext.num(parseInt(amount),0) + if(isNaN(amount)){ + amount = ''; + } + + var price = Ext.num(parseFloat(price),0) + if(isNaN(price)){ + price = ''; + } + + var totalPrice = Ext.num(parseInt(amount) * parseFloat(price),0) + if(isNaN(totalPrice)){ + totalPrice = ''; + } +// console.log(totalPrice); + //添加操作 + var expensivegoodPurchasePlanItem = new expensiveGoodPurchasePlanItemRecord({ + localID:g_localID++, + id : "", + name : name, + amount : amount, + price : price, + totalPrice:totalPrice, + supplierName : supplierName, + expensiveGoodsId : expensiveGoodsId + }); + top.Ext.getCmp('goodPurchaseItemGrid').getStore().insert(0 , expensivegoodPurchasePlanItem); + setTotalMoney(top.Ext.getCmp('goodPurchaseItemGrid')); + clearForm(); + return true; +} + +function renderDeleteButton(v,p,record){ + return ""; +} +/** +* 精确计算arg1和arg2的乘积 +* @param arg1 +* @param arg2 +* @return +*/ +function accMul(arg1,arg2) { + var s1=null ,m=0; + if(!arg1){ + s1 = '0.0'; + }else{ + s1=arg1.toString(); + } + if(!arg2){ + s2='0.0'; + }else{ + s2=arg2.toString(); + } + try{m+=s1.split(".")[1].length;}catch(e){s1='0.0';} + try{m+=s2.split(".")[1].length;}catch(e){s2='0.0';} + return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m); +} +/** +* 精确计算arg1和arg2的和 +* @param arg1 +* @param arg2 +* @return +*/ +function accAdd(arg1,arg2){ + var r1=null ,m=0; + if(!arg1){ + r1 = '0.0'; + }else{ + r1=arg1.toString(); + } + if(!arg2){ + r2='0.0'; + }else{ + r2=arg2.toString(); + } + try{r1=arg1.toString().split(".")[1].length;}catch(e){r1=0;} + try{r2=arg2.toString().split(".")[1].length;}catch(e){r2=0;} + m=Math.pow(10,Math.max(r1,r2)); + return round((arg1*m+arg2*m)/m,2); +} +function round(v,e){ + var t=1; + for(;e>0;t*=10,e--); + for(;e<0;t/=10,e++); + return Math.round(v*t)/t; +} +function setTotalMoney(grid) { + var totalMoney = 0.0; + grid.getStore().each(function(record){ + var amount = Ext.num(parseFloat(record.data.amount),0.0); + var price = Ext.num(parseFloat(record.data.price),0.0); + var mul = amount*price*1.00; + totalMoney += mul; + }); + top.Ext.getCmp("totalPrice").setValue(Ext.util.Format.usMoney(totalMoney)); +} +function renderTotalPrice(val,p,record){ + var amount = Ext.num(parseFloat(record.data.scheduleAmount),0.0); + var cost = Ext.num(parseFloat(record.data.price),0.0); + var total = Ext.util.Format.usMoney(cost*amount); + return total; +} + +function deleteItem(localID){ + var goodPurchaseItemGridStore = top.Ext.getCmp('goodPurchaseItemGrid').getStore(); + for(var i = 0;i 1) { + showResult("一次只能修改一个发票单!"); + return false; + } + id = records[0].data['id']; + editRecord(id); +}; + +function editRecord(id){ + addGoodPurchasePlan(id); + top.Ext.getCmp('expensiveGoodPurchaseForm').form.load({ + url : WWWROOT + '/disinfectSystem/expensiveGoodsBillAction!loadExopensiveGoodsBill.do', + method : 'GET', + waitMsg : '正在加载数据,请稍候', + params : {id : id}, + success : function(form, action) { + var data = action.result.data; + //console.log(data); + top.Ext.getCmp("time").setValue(Ext.util.Format.date(new Date(data.time.time), 'Y-m-d H:i')); + top.Ext.getCmp("settledTime").setValue(Ext.util.Format.date(new Date(data.settledTime.time), 'Y-m-d H:i')); +// top.Ext.getCmp("supplier1").setValue(data.supplierName); +// top.Ext.getCmp("supplierId").setValue(data.supplierId); +// top.Ext.getCmp('supplier1').disable(); + top.Ext.getCmp('operator').disable(); + top.Ext.getCmp('serialNumber').disable(); + top.Ext.getCmp('name1').enable(); + //top.Ext.getCmp('name1').setDisabled(true); + for(var i = 0 ;i < data.itemsList.length ;i++){ + var amount = data.itemsList[i].amount; + if(amount == null || amount == 'null'){ + amount = ''; + } + var price = parseFloat(data.itemsList[i].price); + var expensiveGoodsId = data.itemsList[i].expensiveGoodsId; + var expensivegoodPurchasePlanItem = new expensiveGoodPurchasePlanItemRecord({ + localID:g_localID++, + id : data.itemsList[i].id, + name : data.itemsList[i].name, + amount : amount, + price : price, + totalPrice:parseFloat(Ext.util.Format.usMoney(amount*price)), + supplierName : data.itemsList[i].supplierName, + expensiveGoodsId : expensiveGoodsId + }); + + top.Ext.getCmp('goodPurchaseItemGrid').getStore().add(expensivegoodPurchasePlanItem); + } + setTotalMoney(top.Ext.getCmp('goodPurchaseItemGrid')); + // 保存原始数据,只需要保存需要修改的属性 + setOriginalFormParams(form,['id','serialNumber','supplierId','supplier1','remark','time','settledTime']); + var originalItems = buildJSONStringFromStore(top.Ext.getCmp('goodPurchaseItemGrid').getStore()); + //alert(originalItems); + top.Ext.getCmp("originalItems").setValue(originalItems); + }, + failure : function(form, action) { + } + }); +} + +/////附件上传图片////// +function showResultQM(msg){ + if(recycleQM == true){ + showResultCurPage(msg); + }else{ + showResult(msg); + } +} +function uploadWindowA(imageType,id){ + var onUploadComplete = function(dialog){ + disableShowImageButton = false; + dialog.hide(); + }; + //文件上传成功后的回调函数 + var onUploadSuccess = function(dialog, filename, resp_data, record){ + disableShowImageButton = false; + dialog.hide(); + }; +// //文件上传失败后的回调函数 + var onUploadFailed = function(dialog, filename, resp_data, record){ + showResultQM(resp_data.message);//resp_data是json格式的数据 + disableShowImageButton = true; + }; + var dialog = new top.Ext.ux.UploadDialog.Dialog({ + title: "上传" + imageType, + url:WWWROOT + '/disinfectSystem/baseData/uploadImageFileAction!uploadImage.do?imageType='+imageType+'&objectId='+id , //这里我用struts2做后台处理 + post_var_name:'uploadFiles',//这里是自己定义的,默认的名字叫file + width : 450, + height : 300, + minWidth : 450, + minHeight : 300, + draggable : true , + resizable : true , + constraintoviewport: true , + permitted_extensions:['JPG','jpg','jpeg','JPEG','GIF','gif','png','PNG'], + modal: true , + reset_on_hide: false , + allow_close_on_upload: false , //关闭上传窗口是否仍然上传文件 + upload_autostart: false + }); + dialog.show(); + dialog.on('uploadsuccess',onUploadSuccess); //定义上传成功回调函数 + dialog.on('uploadfailed',onUploadFailed); //定义上传失败回调函数 +// dialog.on('uploadcomplete',onUploadComplete); //定义上传完成回调函数 +} +/** + * 修改记录 + * modifyRecord函数 触发modify函数调用,并传入当前列的值以及record.data对象 + * 页面中需要定义 modify(v,data) 函数 + */ +function modify(v,data){ + editRecord(data['id']); +} +/** + * onReady + */ +Ext.onReady(function() { + Ext.QuickTips.init(); + var columns = [ + {header : "发票号",width : 200,dataIndex : 'serialNumber', renderer : modifyRecord}, + {header : "录入人",width : 200,dataIndex : 'operator'}, + {header : "总金额",width : 200,dataIndex : 'totalPrice'}, + {header : "录入时间",width : 200,dataIndex : 'time' , renderer : myDateFormatByMinute}, + {header : "开票时间",width : 200,dataIndex : 'settledTime' , renderer : myDateFormatByMinute}, + {header : "供应商",width : 200,dataIndex : 'supplierName' }, + {id : 'operationRemark',header : "备注",width : 120,dataIndex : 'remark'} + ]; + + var readerDetail = [ + {name : 'id'}, + {name : 'serialNumber'}, + {name : 'operator'}, + {name : 'totalPrice'}, + {name : 'settledTime'}, + {name : 'time'}, + {name : 'supplierName'}, + {name : 'remark'} + ]; + + var filters = new Ext.grid.GridFilters({ + filters:[ + {type: 'string', dataIndex: 'serialNumber'}, + {type: 'string', dataIndex: 'operator'}, + {type: 'date', dataIndex: 'settledTime'}, + {type: 'date', dataIndex: 'time'}, + {type: 'String', dataIndex: 'supplierName'}, + {type: 'string', dataIndex: 'remark'} + ]} + ); + + var sign = true; + var tbar = [{ + text : '添加', + hidden : SSTS_WarehouseEntry_Create, + iconCls : 'btn_ext_application_add', + handler : function() { + addGoodPurchasePlan(""); + } + },/* '-',*/ { + text : '修改', + //hidden : SSTS_WarehouseEntry_Update, + hidden : true, + iconCls : 'btn_ext_application_edit', + id : 'editTbar', + handler : function() { + loadFormData(grid); + } + }, '-', { + text : '删除', + hidden : SSTS_WarehouseEntry_Delete, + iconCls : 'btn_ext_application_del', + handler : function() { + deleteGoodPurchasePlan(grid); + } + }, '-', { + text : '打印', + hidden : false, + iconCls : 'icon_print', + handler : function() { + var records = grid.getSelectionModel().getSelections(); + if (records.length == 0) { + showResult("请选择要打印的采购计划单!"); + return; + } + if (records.length != 1) { + showResult("一次只能打印1个采购计划单!"); + return; + } + var ids = null; + for ( var i = 0, len = records.length; i < len; i++) { + if (ids == null) { + ids = records[i].data['id']; + } else { + ids = ids + ',' + records[i].data['id']; + } + } + top.Ext.MessageBox.confirm("请确认", "要打印选择的采购计划单吗?", + function(btn) { + if (btn == 'yes') { + printGoodPurchasePlan(ids,0); + } + }); + } + },'-',{ + text : '导出', + hidden : true, + iconCls:'btn_ext_download', + handler : function() { + var records = grid.getSelectionModel().getSelections(); + if (records.length == 0) { + showResult("请选择要导出的采购计划单!"); + return; + } + if (records.length != 1) { + showResult("一次只能导出1个采购计划单!"); + return; + } + var ids = null; + for ( var i = 0, len = records.length; i < len; i++) { + if (ids == null) { + ids = records[i].data['id']; + } else { + ids = ids + ',' + records[i].data['id']; + } + } + location.href = WWWROOT + "/disinfectsystem/assestManagement/godownEntry/exportGoodPurchasePlan.jsp?ids=" + ids; + } + }]; + + grid = new Ext.ux.ForgonPageGrid( { + tbar : tbar, + pageSize : 20, + defaultSortField : 'id', + title : '高值耗材发票列表', + defaultSortDirection : 'DESC', + isCheckboxSelectionModel : true, + rememberSelected : false, + isShowSearchField : true, + columns : columns, + plugins: filters, + autoExpandColumn : 'operationRemark', + renderTo : 'gridDiv', + frame : false + }, readerDetail, + ExpensiveGoodsBillTableManager.findExpensiveGoodBillTableList, + // ExpensiveGoodsPurchaseTableManager.findExpensiveGoodPurchaseTableList, + null + ); + + function initQueryValueAndReload() { + var startDate = $Id('startDate').value; + var endDate = $Id('endDate').value; + var code = $Id('code').value; + if(startDate || endDate){ + if(!compareDate(startDate,endDate)){ + showResult("开始时间不能大于结束时间"); + return; + } + } + $Id('parm_s_startDate').value = startDate; + $Id('parm_s_endDate').value = endDate; + $Id('parm_s_code').value = code; + grid.dwrReload(); + } + var dt = new Date(); + var v = dt.getMonth()+1; + if(v < 10){ + v = "0" + (dt.getMonth()+1); + } + var startDayofMonth = dt.getFullYear() + "/" + v + "/01"; + + var queryForm = new TBarForm(expensiveGoodsStore, 100).initForm(); + + var viewport = new Ext.Viewport( { + layout : 'border', + items : [queryForm,{ + region : 'center', + margins : '0 0 0 0', + layout : 'fit', + items : grid + }] + }); +}); \ No newline at end of file Index: ssts-web/src/main/webapp/WEB-INF/dwr.xml =================================================================== diff -u -r20827 -r21030 --- ssts-web/src/main/webapp/WEB-INF/dwr.xml (.../dwr.xml) (revision 20827) +++ ssts-web/src/main/webapp/WEB-INF/dwr.xml (.../dwr.xml) (revision 21030) @@ -581,6 +581,11 @@ + + + + + Index: ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/imagefilemanager/action/ShowImageAction.java =================================================================== diff -u -r19824 -r21030 --- ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/imagefilemanager/action/ShowImageAction.java (.../ShowImageAction.java) (revision 19824) +++ ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/imagefilemanager/action/ShowImageAction.java (.../ShowImageAction.java) (revision 21030) @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.OutputStream; import java.net.URLDecoder; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; @@ -16,9 +17,12 @@ import org.apache.struts2.convention.annotation.ParentPackage; import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsBill; import com.forgon.disinfectsystem.entity.basedatamanager.imagefilemanager.ImageFile; import com.forgon.disinfectsystem.entity.basedatamanager.materialdefinition.MaterialDefinition; import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsBillManager; +import com.forgon.disinfectsystem.expensiveGoods.service.ExpensiveGoodsManager; import com.forgon.disinfectsystem.tousse.imagefilemanager.service.ImageFileManager; import com.forgon.disinfectsystem.tousse.materialdefinition.service.MaterialDefinitionManager; import com.forgon.disinfectsystem.tousse.toussedefinition.service.TousseDefinitionManager; @@ -27,6 +31,7 @@ import com.forgon.tools.StrutsParamUtils; import com.forgon.tools.StrutsResponseUtils; import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.hibernate.ObjectDao; import com.forgon.tools.json.JSONUtil; import com.forgon.tools.string.StringTools; import com.forgon.tools.util.FileUtils; @@ -44,7 +49,12 @@ private MaterialDefinitionManager materialDefinitionManager; private ImageFileManager imageFileManager; private SupplyRoomConfigManager supplyRoomConfigManager; + private ExpensiveGoodsBillManager expensiveGoodsBillManager; + private ObjectDao objectDao; + public void setObjectDao(ObjectDao objectDao) { + this.objectDao = objectDao; + } public void setTousseDefinitionManager( TousseDefinitionManager tousseDefinitionManager) { this.tousseDefinitionManager = tousseDefinitionManager; @@ -60,6 +70,9 @@ SupplyRoomConfigManager supplyRoomConfigManager) { this.supplyRoomConfigManager = supplyRoomConfigManager; } + public void setExpensiveGoodsBillManager(ExpensiveGoodsBillManager expensiveGoodsBillManager) { + this.expensiveGoodsBillManager = expensiveGoodsBillManager; + } /** * 获取器械包图片的数量 */ @@ -99,6 +112,104 @@ outputImage(img, imageId); } + /** + * 加载高值耗材发票图片 + */ + public void getExpensiveBillImage() { + String page = StrutsParamUtils.getPraramValue("page", "1"); + String imageType = StrutsParamUtils.getPraramValue("imageType", ""); + String objectId = StrutsParamUtils.getPraramValue("objectId", ""); + byte[] img = null; + if (StringUtils.isNotBlank(objectId)) { + if (ImageFile.IMAGE_TYPE_ExpensiveGoodsBill.equals(imageType)) { + ExpensiveGoodsBill expensiveGoodsBill = expensiveGoodsBillManager + .getExpensiveGoodsBillById(objectId); + if(expensiveGoodsBill!=null){ + img = imageFileManager.getImageByIdAndType(expensiveGoodsBill.getId(), + ImageFile.IMAGE_TYPE_ExpensiveGoodsBill, page); + } + } + } + img = ImageUtils.defaultIfEmpty(img); + OutputStream outputStream = null; + try { + HttpServletResponse response = StrutsParamUtils.getResponse(); + response.setContentType("image/jpeg"); + outputStream = response.getOutputStream(); + outputStream.write(img, 0, img.length); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * 加载高值耗材发票上传图片数量 + */ + public void getExpenGoodsBillUploadImageCount() { + String imageType = StrutsParamUtils.getPraramValue("imageType", ""); + String objectId = StrutsParamUtils.getPraramValue("objectId", ""); + int imageCount = 0; + if (StringUtils.isNotBlank(objectId)) { + if (ImageFile.IMAGE_TYPE_ExpensiveGoodsBill.equals(imageType)) { + ExpensiveGoodsBill expensiveGoodsBill = expensiveGoodsBillManager + .getExpensiveGoodsBillById(objectId); + if (expensiveGoodsBill != null) { + imageCount = expensiveGoodsBill.getImagesCount(objectDao); + } + } + } + HttpServletResponse httpServletResponse = StrutsParamUtils + .getResponse(); + httpServletResponse.setCharacterEncoding("UTF-8"); + try { + httpServletResponse.getWriter().print(imageCount); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 删除上传的高值耗材发票图片 + */ + public void deleteExpensiveGoodsBillUploadImage() { + String page = StrutsParamUtils.getPraramValue("page", "1"); + String objectId = StrutsParamUtils.getPraramValue("id", ""); + if (StringUtils.isNotBlank(objectId)) { + ExpensiveGoodsBill expensiveGoodsBill = expensiveGoodsBillManager + .getExpensiveGoodsBillById(objectId); + if (expensiveGoodsBill != null) { + String sql = " where po.objectId = '" + + expensiveGoodsBill.getId() + "' and po.imageType = '" + + ImageFile.IMAGE_TYPE_ExpensiveGoodsBill + + "' order by po.serialNum asc"; + List imagesList = imageFileManager + .getImageFileBySql(sql); + if (Integer.parseInt(page) <= imagesList.size()) { + ImageFile imageFile = imagesList + .get(Integer.parseInt(page) - 1); + imageFileManager.deleteImageFile(imageFile); + } + } + } + HttpServletResponse httpServletResponse = StrutsParamUtils + .getResponse(); + httpServletResponse.setCharacterEncoding("UTF-8"); + String result = "{success:true}"; + try { + httpServletResponse.getWriter().print(result); + } catch (IOException e) { + e.printStackTrace(); + } + } + private void outputImage(byte[] img, long imageId) { OutputStream outputStream = null; img = ImageUtils.defaultIfEmpty(img); @@ -232,4 +343,5 @@ JSONUtil.addProperty(json, "count", count); return json; } + }