List of usage examples for java.util ArrayList trimToSize
public void trimToSize()
From source file:com.turborep.turbotracker.vendor.controller.VendorInvoiceBillController.java
@RequestMapping(value = "/addVendorInvoiceFromPO", method = RequestMethod.POST) public @ResponseBody Vebill addVendorInvoiceFromPO( @RequestParam(value = "recDateIdPO", required = false) String recDateIdPO, @RequestParam(value = "datePO", required = false) String datePO, @RequestParam(value = "duePO", required = false) String duePO, @RequestParam(value = "shipviaPO", required = false) Integer shipviaPO, @RequestParam(value = "vendorInvoicePO", required = false) String vendorInvoicePO, @RequestParam(value = "apacctPO", required = false) Integer apacctPO, @RequestParam(value = "postdatePO", required = false) String postdatePO, @RequestParam(value = "postDate1PO", required = false) String postDate1PO, @RequestParam(value = "shipDatePO", required = false) String shipDatePO, @RequestParam(value = "proPO", required = false) String proPO, @RequestParam(value = "subtotalGeneralId", required = false) BigDecimal subtotalGeneralId, @RequestParam(value = "freightGeneralId", required = false) BigDecimal freightGeneralId, @RequestParam(value = "taxGeneralId", required = false) BigDecimal taxGeneralId, @RequestParam(value = "totalGeneralId", required = false) BigDecimal totalGeneralId, @RequestParam(value = "balDuePO", required = false) BigDecimal balDuePO, @RequestParam(value = "vepoId", required = false) Integer vepoId, @RequestParam(value = "veBillIdPO", required = false) Integer veBillIdPO, @RequestParam(value = "prMasterIDPO", required = false) Integer prMasterIDPO, @RequestParam(value = "rxMasterIDPayablePO", required = false) Integer rxMasterIDPayablePO, @RequestParam(value = "buttonValue", required = false) String buttonValue, @RequestParam(value = "updatePO", required = false) String updatePO, @RequestParam(value = "reason", required = false) String reason, @RequestParam(value = "coFiscalPeriodId", required = false) Integer periodId, @RequestParam(value = "coFiscalYearId", required = false) Integer yearId, @RequestParam(value = "joreleasedetid", required = false) Integer joreleasedetid, @RequestParam(value = "operatorStatus", required = false) String operatorStatus, @RequestParam(value = "gridData", required = false) String gridData, @RequestParam(value = "delData[]", required = false) ArrayList<String> delData, ModelMap theModel, HttpSession theSession, HttpServletResponse theResponse, HttpServletRequest theRequest) throws IOException, JobException, ParseException, BankingException, CompanyException, MessagingException {/*w w w. j av a 2 s . co m*/ Vebill aVebill = new Vebill(); String result = null; Integer insertStatus = 0; logger.info("updatePO Status : " + updatePO + "REason" + reason); Vebilldetail vebilDetail = new Vebilldetail(); System.out.println("check vendor invoice bill contr"); UserBean aUserBean; aUserBean = (UserBean) theSession.getAttribute(SessionConstants.USER); try { if (recDateIdPO != null && recDateIdPO != "") { aVebill.setReceiveDate(DateUtils.parseDate(recDateIdPO.trim(), new String[] { "MM/dd/yyyy" })); } if (datePO != null && datePO != "") { aVebill.setBillDate(DateUtils.parseDate(datePO.trim(), new String[] { "MM/dd/yyyy" })); } if (duePO != null && duePO != "") { aVebill.setDueDate(DateUtils.parseDate(duePO.trim(), new String[] { "MM/dd/yyyy" })); } if (shipDatePO != null && shipDatePO != "") { aVebill.setShipDate(DateUtils.parseDate(shipDatePO.trim(), new String[] { "MM/dd/yyyy" })); } aVebill.setVeShipViaId(shipviaPO); aVebill.setApaccountId(apacctPO); aVebill.setInvoiceNumber(vendorInvoicePO); if (joreleasedetid != null) aVebill.setJoReleaseDetailId(joreleasedetid); if (rxMasterIDPayablePO != null) aVebill.setRxMasterId(rxMasterIDPayablePO); /*if(postdatePO != null && "on".equalsIgnoreCase(postdatePO)) { aVebill.setUsePostDate(true); if (postDate1PO != null && postDate1PO != "") { aVebill.setPostDate(DateUtils.parseDate(postDate1PO.trim(), new String[] { "MM/dd/yyyy" })); } } else { aVebill.setUsePostDate(false); if (postDate1PO != null && postDate1PO != "") { aVebill.setPostDate(DateUtils.parseDate(postDate1PO.trim(), new String[] { "MM/dd/yyyy" })); } }*/ aVebill.setTrackingNumber(proPO); aVebill.setReason(reason); aVebill.setBillAmount(subtotalGeneralId.add(freightGeneralId).add(taxGeneralId)); aVebill.setFreightAmount(freightGeneralId); aVebill.setTaxAmount(taxGeneralId); aVebill.setVePoid(vepoId); if ("Void".equalsIgnoreCase(buttonValue)) aVebill.setTransactionStatus(-1); else if ("Acct. HOLD".equalsIgnoreCase(buttonValue)) aVebill.setTransactionStatus(0); else if ("Open".equalsIgnoreCase(buttonValue)) aVebill.setTransactionStatus(1); else if ("Pmt. HOLD".equalsIgnoreCase(buttonValue)) aVebill.setTransactionStatus(-2); else aVebill.setTransactionStatus(2); aVebill.setAppliedAmount(new BigDecimal(0.00)); //aVebill.setFreightAmount(new BigDecimal(0.00)); //aVebill.setVePoid(1); aVebill.setApplied(false); aVebill.setVoid_(false); /*if(veBillIdPO != null && veBillIdPO != 0) aVebill.setVeBillId(veBillIdPO);*/ // Vebill theVebill = new Vebill(); // theVebill = vendorService.getVeBill(vepoId); aVebill.setCreatedById(aUserBean.getUserId()); aVebill.setCreatedOn(new Date()); /* * Added by Simon * Reason for Adding ID#573 for differentiating purchases. */ ArrayList<Prmaster> prMaster = new ArrayList<Prmaster>(); if (veBillIdPO == null || veBillIdPO == 0) { if (vepoId != null && vepoId != 0) { Vepo testvepo = itsJobService.getVepo(vepoId); if (testvepo != null && testvepo.getJoReleaseId() != null && testvepo.getJoReleaseId() != 0) { JoReleaseDetail thejoreleaseDetail = new JoReleaseDetail(); thejoreleaseDetail.setJoReleaseId(testvepo.getJoReleaseId()); thejoreleaseDetail.setShipDate(aVebill.getShipDate()); thejoreleaseDetail.setVendorInvoiceDate(aVebill.getBillDate()); thejoreleaseDetail.setVendorInvoiceAmount(aVebill.getBillAmount()); JoRelease thejorelease = itsJobService.getJoRelease(testvepo.getJoReleaseId()); if (thejorelease != null && thejorelease.getJoMasterId() != null && thejorelease.getJoMasterId() != 0) { thejoreleaseDetail.setJoMasterId(thejorelease.getJoMasterId()); } Integer joReleaseDetailID = itsJobService.addJoReleaseDetail(thejoreleaseDetail); aVebill.setJoReleaseDetailId(joReleaseDetailID); } } Integer veBillid = vendorService.insertVebill(aVebill); if (veBillid != null && veBillid != 0) aVebill.setVeBillId(veBillid); else aVebill.setVeBillId(veBillIdPO); if (delData != null) { for (String detailID : delData) { Vebilldetail aVebilldetail = new Vebilldetail(); System.out.println("delData[i]" + detailID); Integer vebillDetailID = JobUtil.ConvertintoInteger(detailID); aVebilldetail.setVeBillDetailId(vebillDetailID); aVebilldetail.setVeBillId(aVebill.getVeBillId()); vendorService.saveVebillDetail(aVebilldetail, "delete"); } } if (veBillIdPO == null || veBillIdPO == 0) { //insertStatus = vendorService.insertVebillDetail(veBillid,vepoId,aUserBean.getUserId()); JsonParser parser = new JsonParser(); if (gridData != null) { System.out.println("gridData" + gridData); JsonElement ele = parser.parse(gridData); JsonArray array = ele.getAsJsonArray(); System.out.println("array length==>" + array.size()); for (int ki = 0; ki < array.size() - 1; ki++) { JsonElement ele1 = array.get(ki); Prmaster master = new Prmaster(); JsonObject obj = ele1.getAsJsonObject(); String desc = obj.get("description").getAsString(); String note = obj.get("note").getAsString(); master.setItemCode(note); BigDecimal quantityOrder = obj.get("quantityOrdered").getAsBigDecimal(); Integer prMasterID = obj.get("prMasterId").getAsInt(); master.setPrMasterId(prMasterID); BigDecimal priceMultiplier = obj.get("priceMultiplier").getAsBigDecimal(); String unitCost_String = obj.get("unitCost").getAsString().replaceAll("\\$", ""); unitCost_String = unitCost_String.replaceAll(",", ""); BigDecimal unitCost = JobUtil.ConvertintoBigDecimal(unitCost_String); String quantityBilled_String = obj.get("quantityBilled").getAsString().replaceAll("\\$", ""); quantityBilled_String = quantityBilled_String.replaceAll(",", ""); BigDecimal quantityBilled = JobUtil.ConvertintoBigDecimal(quantityBilled_String); master.setLastCost(quantityBilled); Integer veBillDetailId = null; if (obj.get("veBillDetailId") != null && obj.get("veBillDetailId").getAsString() != "" && obj.get("veBillDetailId").getAsString().length() > 0) { veBillDetailId = obj.get("veBillDetailId").getAsInt(); } String Oper = "add"; if (veBillDetailId != null) { Oper = "edit"; } Integer vePODetailId = null; if (obj.get("vePodetailId") != null && obj.get("vePodetailId").getAsString() != "" && obj.get("vePodetailId").getAsString().length() > 0) { vePODetailId = obj.get("vePodetailId").getAsInt(); } Vebilldetail aVebilldetail = new Vebilldetail(); aVebilldetail.setVeBillDetailId(veBillDetailId); aVebilldetail.setDescription(desc); aVebilldetail.setNote(note); aVebilldetail.setQuantityBilled(quantityOrder); aVebilldetail.setPriceMultiplier(priceMultiplier); aVebilldetail.setUnitCost(unitCost); aVebilldetail.setVePodetailId(vePODetailId); aVebilldetail.setPrMasterId(prMasterID); aVebilldetail.setVeBillId(aVebill.getVeBillId()); if (obj.get("taxable").getAsString().equals("Yes")) aVebilldetail.setTaxable(true); else aVebilldetail.setTaxable(false); vendorService.saveVebillDetail(aVebilldetail, Oper); master.setInitialCost(freightGeneralId); prMaster.add(master); } } if ((prMaster.size() == 0) && (freightGeneralId.compareTo(BigDecimal.ZERO) != 0)) { Prmaster master = new Prmaster(); master.setInitialCost(freightGeneralId); prMaster.add(master); } prMaster.trimToSize(); vendorService.insertVebillHistory(aVebill.getVeBillId(), vepoId, aUserBean.getUserId()); vendorService.updateveBillHistory(aVebill.getVeBillId()); if (updatePO.equalsIgnoreCase("yes")) { vendorService.updateVepoStatus(vepoId, 2); } if (operatorStatus.equals("close")) { /* *Modified Signature by Simon *Reason for Modifying ID#573 for differentiating purchases */ itsGltransactionService.recieveVendorBill(prMaster, aVebill, insertStatus, yearId, periodId, aUserBean.getFullName()); } } } else { //update the edited vendor invoice if (!reason.equals("")) { // vendorService.rollbackupdatePrMaster(veBillIdPO); } aVebill.setVeBillId(veBillIdPO); System.out.println("delData" + delData); //functionality for delete the grid columns if (delData != null) { for (String detailID : delData) { Vebilldetail aVebilldetail = new Vebilldetail(); System.out.println("delData[i]" + detailID); Integer vebillDetailID = JobUtil.ConvertintoInteger(detailID); aVebilldetail.setVeBillDetailId(vebillDetailID); aVebilldetail.setVeBillId(aVebill.getVeBillId()); vendorService.saveVebillDetail(aVebilldetail, "delete"); } } JsonParser parser = new JsonParser(); if (gridData != null) { System.out.println("gridData" + gridData); JsonElement ele = parser.parse(gridData); JsonArray array = ele.getAsJsonArray(); System.out.println("array length==>" + array.size()); for (int ki = 0; ki < array.size() - 1; ki++) { JsonElement ele1 = array.get(ki); Prmaster master = new Prmaster(); JsonObject obj = ele1.getAsJsonObject(); String desc = obj.get("description").getAsString(); String note = obj.get("note").getAsString(); master.setItemCode(note); BigDecimal quantityOrder = obj.get("quantityOrdered").getAsBigDecimal(); Integer prMasterID = obj.get("prMasterId").getAsInt(); master.setPrMasterId(prMasterID); BigDecimal priceMultiplier = obj.get("priceMultiplier").getAsBigDecimal(); String unitCost_String = obj.get("unitCost").getAsString().replaceAll("\\$", ""); unitCost_String = unitCost_String.replaceAll(",", ""); BigDecimal unitCost = JobUtil.ConvertintoBigDecimal(unitCost_String); String quantityBilled_String = obj.get("quantityBilled").getAsString().replaceAll("\\$", ""); quantityBilled_String = quantityBilled_String.replaceAll(",", ""); BigDecimal quantityBilled = JobUtil.ConvertintoBigDecimal(quantityBilled_String); master.setLastCost(quantityBilled); Integer veBillDetailId = null; if (obj.get("veBillDetailId") != null && obj.get("veBillDetailId").getAsString() != "" && obj.get("veBillDetailId").getAsString().length() > 0) { veBillDetailId = obj.get("veBillDetailId").getAsInt(); } String Oper = "add"; if (veBillDetailId != null) { Oper = "edit"; } Integer vePODetailId = null; if (obj.get("vePodetailId") != null && obj.get("vePodetailId").getAsString() != "" && obj.get("vePodetailId").getAsString().length() > 0) { vePODetailId = obj.get("vePodetailId").getAsInt(); } Vebilldetail aVebilldetail = new Vebilldetail(); aVebilldetail.setVeBillDetailId(veBillDetailId); aVebilldetail.setDescription(desc); aVebilldetail.setNote(note); aVebilldetail.setQuantityBilled(quantityOrder); aVebilldetail.setPriceMultiplier(priceMultiplier); aVebilldetail.setUnitCost(unitCost); aVebilldetail.setVePodetailId(vePODetailId); aVebilldetail.setPrMasterId(prMasterID); aVebilldetail.setVeBillId(veBillIdPO); if (obj.get("taxable").getAsString().equals("Yes")) aVebilldetail.setTaxable(true); else aVebilldetail.setTaxable(false); vendorService.saveVebillDetail(aVebilldetail, Oper); master.setInitialCost(freightGeneralId); prMaster.add(master); } } if (prMaster.size() == 0) { Prmaster master = new Prmaster(); master.setInitialCost(freightGeneralId); prMaster.add(master); } prMaster.trimToSize(); if (!reason.equals("")) { Coledgersource aColedgersource = itsGltransactionService.getColedgersourceDetail("VB"); GlRollback glRollback = new GlRollback(); glRollback.setVeBillID(aVebill.getVeBillId()); glRollback.setCoLedgerSourceID(aColedgersource.getCoLedgerSourceId()); glRollback.setPeriodID(periodId); glRollback.setYearID(yearId); glRollback.setTransactionDate(aVebill.getBillDate()); itsGltransactionService.rollBackGlTransaction(glRollback); //vendorService.rollbackupdatePrMaster(veBillIdPO); } aVebill.setChangedById(aUserBean.getUserId()); aVebill.setChangedOn(new Date()); vendorService.insertVebill(aVebill); vendorService.updateveBillHistory(veBillIdPO); if (operatorStatus != null) if (veBillIdPO != null && veBillIdPO != 0 && operatorStatus.equals("close") && !buttonValue.equals("Void")) itsGltransactionService.recieveVendorBill(prMaster, aVebill, 0, yearId, periodId, aUserBean.getFullName()); } // throw new VendorException("Testing Exception"); } catch (VendorException e) { logger.error(e.getMessage()); theResponse.sendError(e.getItsErrorStatusCode(), e.getMessage()); theResponse.sendError(e.getItsErrorStatusCode(), e.getMessage()); Transactionmonitor transObj = new Transactionmonitor(); SendQuoteMail sendMail = new SendQuoteMail(); transObj.setHeadermsg("Transaction Log << " + e.getMessage() + " >>"); transObj.setTrackingId("<b>Invoice No:</b>" + aVebill.getInvoiceNumber() + "<br><b>RxMasterID:</b>" + aVebill.getRxMasterId()); transObj.setTimetotriggerd(new Date()); transObj.setJobStatus("Outside"); transObj.setUsername(aUserBean.getFullName() + "[" + aUserBean.getUserId() + "]"); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); transObj.setDescription("Message :: " + errors.toString()); sendMail.sendTransactionInfo(transObj, theRequest); } /* Commented by Jenith on 2014-09-11 11:52 * catch (FinancePostingException e){ logger.error(e.getMessage()); theResponse.sendError(e.getItsErrorStatusCode(), e.getMessage()); } catch (ProductException e) { logger.error(e.getMessage()); }*/ return aVebill; }