Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.accounting.inventory; import com.accounting.dto.SalesDTO; import com.accounting.commonutils.HelperUtil; import com.accounting.ejb.exceptions.ClientException; import com.accounting.utils.TransactionDTO; import com.accounting.entities.account.AccMaster; import com.accounting.entities.account.BasicAccountSetup; import com.accounting.entities.account.PersonalInfo; import com.accounting.entities.account.TxnDetail; import com.accounting.entities.inventory.IInventoryReturnDetail; import com.accounting.entities.inventory.IInventoryReturnHeader; import com.accounting.entities.inventory.IItemIssueDetail; import com.accounting.entities.inventory.IItemIssueHeader; import com.accounting.entities.inventory.IItemMaster; import com.accounting.entities.inventory.IItemPurchasePropertyValue; import com.accounting.entities.inventory.IPurchaseDetail; import com.accounting.entities.inventory.ISalesDetail; import com.accounting.entities.inventory.SalesHeaderDetail; import com.accounting.entities.office.Office; import com.accounting.entities.parameters.AppData; import com.accounting.entities.parameters.MetaTable; import com.accounting.entities.user.FyTable; import com.accounting.entities.user.User; import com.accounting.jasperbean.JasperReportBean; import com.accounting.session.commonreport.CommonSessionReport; import com.accounting.sessions.account.AccMasterSession; import com.accounting.sessions.account.AccOwnershipSession; import com.accounting.sessions.account.BasicAccountSetupSessionBean; import com.accounting.sessions.account.GlSubHeadSession; import com.accounting.sessions.account.TransactionSessionBean; import com.accounting.sessions.account.TxnDetailSession; import com.accounting.sessions.inventory.AppDataSession; import com.accounting.sessions.inventory.IPurchaseDetailSession; import com.accounting.sessions.inventory.ISalesDetailSession; import com.accounting.sessions.inventory.ItemMasterSession; import com.accounting.sessions.inventory.SalesTransactionBean; import com.accounting.sessions.office.OfficeSession; import com.accounting.sessions.simtracker.FyTableSessionBean; import com.accounting.util.JsfUtil; import com.accounting.util.InventoryValueSetup; import com.accounting.utils.KeyConstants; import com.accounting.utils.NepaliDateConverter; import static com.accounting.utils.NepaliDateConverter.formatNepaliDate; import com.accounting.utils.PageNameEnum; import com.accounting.utils.Util; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.ejb.EJB; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.UserTransaction; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; 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.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.util.CellRangeAddress; import org.primefaces.event.SelectEvent; import org.primefaces.event.UnselectEvent; import org.primefaces.model.LazyDataModel; import org.primefaces.model.SortOrder; /** * * @author Zabir */ @ManagedBean @SessionScoped public class InventorySalesMBean { @EJB public ISalesDetailSession iSalesDetailSession; @EJB private AccOwnershipSession accOwnershipSession; @EJB public IPurchaseDetailSession iPurchaseDetailSession; @EJB public ItemMasterSession itemMasterSession; @EJB public AccMasterSession accMasterSession; @EJB private BasicAccountSetupSessionBean basicAccountSetupSessionBean; @EJB private OfficeSession officeSession; @EJB private TransactionSessionBean transactionSessionBean; @EJB private GlSubHeadSession glSubHeadSession; @EJB private AppDataSession appDataSession; @EJB private SalesTransactionBean salesTransactionBean; @Resource UserTransaction tx; @EJB private CommonSessionReport commonSessionReport; private Date beforeDate; private String currentDate, soldDate, paymentDate, filterString; public String fromDate, toDate, selectedSalesAccountType, selectedPaymentMode; public String salesDate; public Integer billNo; public int selectedOffice; private int stage; public long purchaseAccMstrCustomerId; public Double totalSalesPrice, totalSalesPriceFinal, discount, taxableAmount, vatAmount, advancePayment, vatPercentage; public Double totalReturnAmount; public String address, panNo; private double actualQtySum; private Double totalQuantityCount; private String pageNameForReturn; private double totalBillAmount; public PersonalInfo addressAndPan; private double totalVatAmount; private double totalDiscountAmount; private double totalAmountBeforevat; private double sumOfnetSalesAmount; public List<SalesDTO> salesDtoList; public List<IPurchaseDetail> purchaseDetailDropDown; private List<IItemMaster> itemMasterList; private List<ISalesDetail> isalesDetailsList, isalesDetailsListForDeleted; // private List<SalesHeaderDetail> salesHeaderListt; private List<SalesHeaderDetail> salesHeaderList; private List<Object[]> salesHeaderListt; private List<IItemIssueHeader> issueHeadersList; private List<AccMaster> purchaseAccMstrSuppList; private List<AccMaster> sellerAccMstrList; public List<Office> otherOfficeList = new ArrayList<Office>(); public SalesDTO salesDTO; public IPurchaseDetail ipurchaseDetail; private NepaliDateConverter ndc = new NepaliDateConverter(); private Date startDate; private Date endDate; private boolean accountTypeRender, paymentModeNonCash; private boolean salesBetnDateRendered, displayAll;; private SalesHeaderDetail selectedSalesHeader; private String salesModeOfReceipt; public String issueEntryRemarks, remarks; private FyTable fyTable = new FyTable(); private IItemIssueHeader issueHeader; private IItemIssueDetail issueDetail; private List<IItemIssueDetail> issueDetailList; private List<AppData> productReturnReasons; private String productReturnReasonsString; private IInventoryReturnHeader selectedInventoryReturnHeader; private List<IInventoryReturnDetail> returnDetailsList; private long salesHeaderIdForBillPrint; /** * Creates a new instance of InventorySalesMBean */ public InventorySalesMBean() { } @PostConstruct public void init() { paymentModeNonCash = false; selectedOffice = 0; purchaseAccMstrSuppList = new ArrayList<AccMaster>(); fyTable = (FyTable) Util.getSession().getAttribute("fytable"); selectedSalesAccountType = "customer"; selectedPaymentMode = "CASH"; issueEntryRemarks = "Issue Req No. "; purchaseAccMstrSuppList.addAll(accMasterSession.retrieveAccMasterByGlSubCodeAndOffice(KeyConstants.CASH, getLoggedInOffice().getId())); purchaseAccMstrSuppList.addAll(accMasterSession.retrieveAccMasterByGlSubCodeAndOffice(KeyConstants.BANK, getLoggedInOffice().getId())); } public void initialize() { editRender = false; totalSalesPrice = 0.0; salesDTO = new SalesDTO(); ipurchaseDetail = null; totalSalesPriceFinal = 0.0; discount = 0.0; taxableAmount = 0.0; vatAmount = 0.0; advancePayment = 0.0; billNo = iSalesDetailSession.retrieveMaxSalesBillNo(getLoggedInOffice().getId()) + 1; salesDtoList = new ArrayList<SalesDTO>(); purchaseAccMstrCustomerId = 0; selectedOffice = 0; } @ManagedProperty(value = "#{jasperReportBean}") JasperReportBean jasperReportBean; public void salesExporter(ActionEvent event, int j) { if (HelperUtil.getPageName() == PageNameEnum.SALESINVOICE) { if (salesHeaderIdForBillPrint > 0) { selectedSalesHeader = iSalesDetailSession.findSalesHeader(salesHeaderIdForBillPrint); isalesDetailsList = iSalesDetailSession.returnSalesDetailByHeader(selectedSalesHeader.getId()); if (isalesDetailsList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no item found"); return; } totalSalesPrice = 0.0; for (ISalesDetail i : isalesDetailsList) { totalSalesPrice += (i.getSalesQty() * i.getSellingPrice()); } totalSalesPriceFinal = selectedSalesHeader.getBillAmount(); discount = selectedSalesHeader.getDiscount(); vatPercentage = selectedSalesHeader.getVatPercentage(); ajaxTotalCalculation(); } else { JsfUtil.addErrorMessage("System Error!!!"); return; } } List<ISalesDetail> temp = new ArrayList<ISalesDetail>(isalesDetailsList); for (ISalesDetail i : temp) { if (i.getPurchaseDetailId().getParentId() == null) { i.setItemNameConverted(i.getPurchaseDetailId().getItemId().getItemName() + " " + i.getPurchaseDetailId().getPropertyValues()); } else { i.setItemNameConverted(i.getPurchaseDetailId().getItemId().getItemName() + " : " + i.getPurchaseDetailId().getItemId().getVariantName()); } i.setTotal(i.getSalesQty() * i.getSellingPrice()); } Map params = new HashMap(); params.put("officeName", HelperUtil.getLoggedInOffice().getName()); params.put("currentDate", ndc.convertToNepaliDate(new Date())); params.put("soldDate", selectedSalesHeader.getSalesDateNp()); params.put("billNo", selectedSalesHeader.getBillNo()); params.put("customer", selectedSalesHeader.getCustomerId().getAccName()); params.put("address", selectedSalesHeader.getCustomerId().getPersonalInfo().getAddress()); params.put("panNo", selectedSalesHeader.getCustomerId().getPersonalInfo().getPanNo()); params.put("subTotal", totalSalesPrice); params.put("discount", discount); params.put("txnAmt", taxableAmount); params.put("vat", (vatPercentage == null ? 0 : vatPercentage) + "% vat"); params.put("vatAmt", (vatAmount == null ? 0.0 : vatAmount)); params.put("total", totalSalesPriceFinal); try { JRBeanCollectionDataSource beancoldatasrc = new JRBeanCollectionDataSource(temp); if (j == 1) { jasperReportBean.exportReportToPDF(event, beancoldatasrc, params, "salesReportPdf"); } else { jasperReportBean.exportToExcel(event, beancoldatasrc, params, "salesReportExcel"); } } catch (Exception ex) { ex.printStackTrace(); } if (HelperUtil.getPageName() == PageNameEnum.SALESINVOICE) { initialize(); } } private long irHeaderIdForPrint; public void salesReturnExporter(ActionEvent event, int j) { if (HelperUtil.getPageName() == PageNameEnum.SALESRETURN) { if (irHeaderIdForPrint > 0) { selectedInventoryReturnHeader = iSalesDetailSession.findIInventoryReturnHeader(irHeaderIdForPrint); returnDetailsList = iPurchaseDetailSession.returnPurchaseReturnDetailByHeaderId( selectedInventoryReturnHeader.getId(), HelperUtil.getLoggedInOfficeID()); } else { JsfUtil.addErrorMessage("System Error!!!"); return; } } double totals = 0; List<IInventoryReturnDetail> temp = new ArrayList<IInventoryReturnDetail>(returnDetailsList); for (IInventoryReturnDetail i : temp) { i.setTotal(i.getReturnQtyTemp() * i.getSalesDetailId().getSellingPrice()); totals += i.getTotal(); } if (totals > 0) { IInventoryReturnDetail ir = new IInventoryReturnDetail(); ir.setTotal(totals); temp.add(ir); } Map params = new HashMap(); params.put("officeName", HelperUtil.getLoggedInOffice().getName()); params.put("currentDate", ndc.convertToNepaliDate(new Date())); params.put("soldDate", selectedInventoryReturnHeader.getSalesHeaderId().getSalesDateNp()); params.put("billNo", selectedInventoryReturnHeader.getSalesHeaderId().getBillNo()); params.put("companyAddress", HelperUtil.getLoggedInOffice().getAddress()); params.put("contactDetails", HelperUtil.getLoggedInOffice().getContact()); params.put("customer", selectedInventoryReturnHeader.getSalesHeaderId().getCustomerId().getAccName()); params.put("panNo", selectedInventoryReturnHeader.getSalesHeaderId().getCustomerId().getPersonalInfo().getPanNo()); params.put("reason", selectedInventoryReturnHeader.getReturnReason()); try { JRBeanCollectionDataSource beancoldatasrc = new JRBeanCollectionDataSource(temp); if (j == 1) { jasperReportBean.exportReportToPDF(event, beancoldatasrc, params, "salesReturnPdf"); } else { jasperReportBean.exportToExcel(event, beancoldatasrc, params, "salesReturnExcel"); } } catch (Exception ex) { ex.printStackTrace(); } } public void postProcessXLSSalesBetDate(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0); int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES INVOICE REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6)); for (Row row : sheet) { if (row.getRowNum() > 4) { for (int i = 4; i < 7; i++) { String cost1 = row.getCell(i).getStringCellValue(); if (!cost1.isEmpty()) { row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(i).setCellValue(Double.valueOf(cost1)); } } } } } public void postProcessXLS(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0); int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); if (!displayAll) { if (stage == 1) { HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); } } sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6)); HSSFRow lastRow; double totalSold = 0; for (Row row : sheet) { if (row.getRowNum() > 4) { String cost = row.getCell(3).getStringCellValue(); if (cost != null && !cost.isEmpty()) { row.getCell(3).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(3).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(3).setCellValue(Double.valueOf(cost)); totalSold += Double.parseDouble(cost.replace(",", "")); } } } for (Row row : sheet) { if (row.getRowNum() > 4) { for (int i = 4; i < 5; i++) { String cost1 = row.getCell(i).getStringCellValue(); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(i).setCellValue(Double.valueOf(cost1)); // totalSold += Double.valueOf(row.getCell(3).getStringCellValue()); } } } lastRow = sheet.createRow(sheet.getLastRowNum() + 1); HSSFCell totalSumTextCell = lastRow.createCell(2); totalSumTextCell.setCellValue("Total Sales Amount: "); HSSFCell totalUnitsCell = lastRow.createCell(3); totalUnitsCell.setCellValue(totalSold); } public void postProcessXLSSalesReturn(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0); int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES RETURN REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); if (stage == 1) { HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); } sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 4)); HSSFRow lastRow; double totalSold = 0; for (Row row : sheet) { if (row.getRowNum() > 4) { String cost = row.getCell(4).getStringCellValue(); row.getCell(4).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(4).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(4).setCellValue(Double.valueOf(cost)); totalSold += Double.valueOf(cost); } } lastRow = sheet.createRow(sheet.getLastRowNum() + 1); HSSFCell totalSumTextCell = lastRow.createCell(3); totalSumTextCell.setCellValue("Total : "); HSSFCell totalUnitsCell = lastRow.createCell(4); totalUnitsCell.setCellValue(totalSold); } public void cancelEditSalesEntry() { editRender = false; salesDTO = new SalesDTO(); ipurchaseDetail = null; } public void ajaxSellingPriceSetup() { if (ipurchaseDetail != null) { salesDTO.setSalesAmount(ipurchaseDetail.getMrp()); } } public List<IPurchaseDetail> buildFromSalesEntrySuggestions(String query) { return this.queryForSalesEntry(query); } public List<IPurchaseDetail> queryForSalesEntry(String name) { List<IPurchaseDetail> queried = new ArrayList<IPurchaseDetail>(); for (IPurchaseDetail ip : purchaseDetailDropDown) { if (ip.getItemId().getItemName().toLowerCase().trim().startsWith(name.toLowerCase())) { boolean add = true; if (salesDtoList != null && !salesDtoList.isEmpty()) { for (SalesDTO s : salesDtoList) { if (s.getPurchaseDetail().getId().equals(ip.getId())) { ip.setAvailableQtyTemp(ip.getAvailableQty() - s.getQuantity()); itemNameConvertMethod(ip); if (ip.getAvailableQtyTemp() == 0) { add = false; } break; } } } if (add) { queried.add(ip); } } } return queried; } public List<IPurchaseDetail> buildFromItemIssueSuggestions(String query) { return this.queryForItemIssueEntry(query); } public void submitSalesReturn() { try { salesDate = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); if (salesDate == null || salesDate.isEmpty()) { showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please Enter Return Date", ""); return; } Date endDate; try { endDate = ndc.convertToEnglishDate(salesDate); } catch (Exception e) { e.printStackTrace(); endDate = new Date(); } int returnItemCount = 0; double totalAmount = 0.0; for (ISalesDetail i : isalesDetailsList) { if (i.getReturnQtyTmp() > 0) { if (i.getReturnQtyTmp() > i.getSalesQty()) { IPurchaseDetail p = i.getPurchaseDetailId(); JsfUtil.addErrorMessage("Sorry, Item " + p.getItemId().getItemName() + " has sells qty " + i.getSalesQty() + " " + p.getItemId().getMeasurementUnitId().getName() + " ."); return; } returnItemCount++; totalAmount += (i.getReturnQtyTmp() * i.getSellingPrice()); } } if (returnItemCount == 0) { JsfUtil.addErrorMessage("No Return Item Found!!!"); return; } else if (returnHeader.getReturnReason() == null || returnHeader.getReturnReason().isEmpty()) { JsfUtil.addErrorMessage("Reason Required."); return; } returnHeader.setTotalAmount(totalAmount); returnHeader.setOfficeId(HelperUtil.getLoggedInOffice()); returnHeader.setCreatedBy(getLoggedInUser().getId()); returnHeader.setCreatedDate(new Date()); returnHeader.setReturnDate(endDate); returnHeader.setDelFlg(false); returnHeader.setReturnDateNepali(NepaliDateConverter.formatNepaliDate(salesDate)); returnHeader.setRefBillNo(selectedSalesHeader.getBillNo().toString()); salesTransactionBean.submitSalesReturn(returnHeader, isalesDetailsList, selectedSalesHeader); long id = returnHeader.getId(); soldListToReturn(selectedSalesHeader); irHeaderIdForPrint = id; JsfUtil.addSuccessMessage("Sales Return Save Successful."); } catch (ClientException ex) { HelperUtil.showErrorMessage(ex.getMessage()); } } private List<IInventoryReturnHeader> returnHeadersList; public String redirectToSalesReturnReport() { stage = 1; HelperUtil.setPageName(PageNameEnum.SALESRETURNREPORT); fromDate = JsfUtil.dateBeforThirtyDaysNDC(new Date(), -30); toDate = ndc.convertToNepaliDate(new Date()); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 59); Date fdate = JsfUtil.dateBeforThirtyDays(new Date(), -30); returnHeadersList = iSalesDetailSession.retrieveSalesReturnHeaderByBtwnDates(fdate, cal.getTime(), getLoggedInOffice().getId()); if (!returnHeadersList.isEmpty()) { totalBillAmount = 0.0; for (IInventoryReturnHeader sales : returnHeadersList) { if (sales.getTotalAmount() != null) { totalBillAmount += sales.getTotalAmount(); } } } return HelperUtil.getPageName().getPageLink(); } public String viewSalesReturnItems(IInventoryReturnHeader prh) { selectedInventoryReturnHeader = prh; selectedSalesHeader = prh.getSalesHeaderId(); purchaseAccMstrCustomerId = prh.getSalesHeaderId().getCustomerId().getId(); returnDetailsList = iPurchaseDetailSession.returnPurchaseReturnDetailByHeaderId(prh.getId(), getLoggedInOffice().getId()); inventoryValueSetup.serialPropertyFillUpOnInventoryReturnDetail(returnDetailsList); return "salesReturnDetail.xhtml"; } private InventoryValueSetup inventoryValueSetup = new InventoryValueSetup(); public void editSoldReturnItems(IInventoryReturnHeader prh) { selectedInventoryReturnHeader = prh; selectedSalesHeader = prh.getSalesHeaderId(); purchaseAccMstrCustomerId = prh.getSalesHeaderId().getCustomerId().getId(); returnDetailsList = iPurchaseDetailSession.returnPurchaseReturnDetailByHeaderId(prh.getId(), getLoggedInOffice().getId()); propertyValueFillUpPurchaseDetailFromSalesReturn(returnDetailsList); stage = 2; } public void removeSalesReturnReport(IInventoryReturnHeader prh) { try { returnDetailsList = iSalesDetailSession.returnSalesReturnDetailByHeaderId(prh.getId(), getLoggedInOffice().getId()); salesTransactionBean.removeSalesReturnReport(returnDetailsList, prh); returnHeadersList.remove(prh); JsfUtil.addSuccessMessage("Item Sales Return Remove Successful."); } catch (ClientException ex) { HelperUtil.showErrorMessage(ex.getMessage()); } } public void propertyValueFillUpPurchaseDetailFromSalesReturn(List<IInventoryReturnDetail> queried) { if (queried != null) { for (IInventoryReturnDetail ip : queried) { if (ip.getSalesDetailId().getPurchaseDetailId().getItemType().equals(KeyConstants.Serial)) { List<IItemPurchasePropertyValue> temp = itemMasterSession .returnIItemPurchasePropertyValueByPurchaseDetail( ip.getSalesDetailId().getPurchaseDetailId().getId()); if (temp != null && !temp.isEmpty()) { String s = ": "; for (IItemPurchasePropertyValue i : temp) { s += i.getItemMasterPropertyId().getPropertyName() + "-" + i.getPropertyValue() + ", "; } s = JsfUtil.trimComma(s); System.out.println("s " + s); ip.getSalesDetailId().getPurchaseDetailId().setPropertyValues(s); } } } } } public void returnToIndex() { stage = 1; } public void updateSalesReturn() { try { /* First check if updated return qty is above sold qty. If found then we cannot allow further process. Because if i sold one item with qty 2 and i return 3 qty, it is unacceptable. */ for (IInventoryReturnDetail rd : returnDetailsList) { if (!rd.getReturnQty().equals(rd.getReturnQtyTemp())) { if (rd.getReturnQtyTemp() > rd.getReturnQty()) { if (rd.getSalesDetailId().getSalesQty() < (rd.getReturnQtyTemp() - rd.getReturnQty())) { IPurchaseDetail pd = rd.getSalesDetailId().getPurchaseDetailId(); JsfUtil.addErrorMessage("Sorry, Item " + pd.getItemId().getItemName() + " has " + (pd.getAvailableQty() + rd.getReturnQty()) + " " + pd.getItemId().getMeasurementUnitId().getName() + " sold."); return; } } } } salesTransactionBean.updateSalesReturn(selectedInventoryReturnHeader, returnDetailsList); JsfUtil.addSuccessMessage("Item Purchase Return Update Successful."); } catch (ClientException ex) { HelperUtil.showErrorMessage(ex.getMessage()); } } public void inventoryManagement(IInventoryReturnDetail i, double qty) { IPurchaseDetail ip = iPurchaseDetailSession .findIPurchaseDetail(i.getSalesDetailId().getPurchaseDetailId().getId()); ip.setAvailableQty(ip.getAvailableQty() + qty); iPurchaseDetailSession.merge(ip); ip.getItemId().setAvailableQty(ip.getItemId().getAvailableQty() + qty); iPurchaseDetailSession.merge(ip.getItemId()); if (ip.getParentId() != null) { IPurchaseDetail pd = iPurchaseDetailSession.findIPurchaseDetail(ip.getParentId()); pd.setAvailableQty(pd.getAvailableQty() + qty); iPurchaseDetailSession.merge(i); pd.getItemId().setAvailableQty(pd.getItemId().getAvailableQty() + qty); iPurchaseDetailSession.merge(pd.getItemId()); } } public void salesReturnReportSearchClicked() { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); if ("".equals(startDateString) || startDateString == null) { showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please Enter From Date", ""); return; } if ("".equals(endDateString) || endDateString == null) { showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please Enter To Date", ""); return; } Date startDate = ndc.convertToEnglishDate(startDateString); Date endDate = ndc.convertToEnglishDate(endDateString); returnHeadersList = iSalesDetailSession.retrieveSalesReturnHeaderByBtwnDates(startDate, endDate, getLoggedInOffice().getId()); if (returnHeadersList == null || returnHeadersList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); } if (!returnHeadersList.isEmpty()) { totalBillAmount = 0.0; for (IInventoryReturnHeader sales : returnHeadersList) { if (sales.getTotalAmount() != null) { totalBillAmount += sales.getTotalAmount(); } } } } public void salesReturnReportViewAllClicked() { returnHeadersList = iSalesDetailSession .retrieveAllSalesReturnHeader(HelperUtil.getLoggedInOffice().getId()); if (returnHeadersList == null || returnHeadersList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); } if (!returnHeadersList.isEmpty()) { totalBillAmount = 0.0; for (IInventoryReturnHeader sales : returnHeadersList) { if (sales.getTotalAmount() != null) { totalBillAmount += sales.getTotalAmount(); } } } } public void inventoryStockManagement(ISalesDetail is) { selectedSalesHeader .setBillAmount(selectedSalesHeader.getBillAmount() - (is.getSellingPrice() * is.getSalesQty())); is.setSalesQty(is.getSalesQty() - is.getReturnQtyTmp()); iPurchaseDetailSession.merge(is); selectedSalesHeader .setBillAmount(selectedSalesHeader.getBillAmount() + (is.getSellingPrice() * is.getSalesQty())); iPurchaseDetailSession.merge(selectedSalesHeader); IPurchaseDetail ip = iPurchaseDetailSession.findIPurchaseDetail(is.getPurchaseDetailId().getId()); ip.setAvailableQty(ip.getAvailableQty() + is.getReturnQtyTmp()); iPurchaseDetailSession.merge(ip); ip.getItemId().setAvailableQty(ip.getItemId().getAvailableQty() + is.getReturnQtyTmp()); iPurchaseDetailSession.merge(ip.getItemId()); if (ip.getParentId() != null) { IPurchaseDetail i = iPurchaseDetailSession.findIPurchaseDetail(ip.getParentId()); i.setAvailableQty(i.getAvailableQty() + is.getReturnQtyTmp()); iPurchaseDetailSession.merge(i); i.getItemId().setAvailableQty(i.getItemId().getAvailableQty() + is.getReturnQtyTmp()); i.getItemId().getAccMasterId().setVersion(i.getItemId().getAccMasterId().getVersion() + 1); iPurchaseDetailSession.merge(i.getItemId()); } } public List<IPurchaseDetail> queryForItemIssueEntry(String name) { List<IPurchaseDetail> queried = new ArrayList<IPurchaseDetail>(); for (IPurchaseDetail ip : purchaseDetailDropDown) { if (ip.getItemId().getItemName().toLowerCase().startsWith(name.toLowerCase())) { boolean add = true; if (issueDetailList != null && !issueDetailList.isEmpty()) { for (IItemIssueDetail s : issueDetailList) { if (s.getPurchaseDetailId().getId().equals(ip.getId())) { ip.setAvailableQtyTemp(ip.getAvailableQty() - s.getQuantity()); itemNameConvertMethod(ip); if (ip.getAvailableQtyTemp() == 0) { add = false; } break; } } } if (add) { queried.add(ip); } } } return queried; } public void itemNameConvertMethod(List<IPurchaseDetail> queried) { if (queried != null) { for (IPurchaseDetail ip : queried) { if (ip.getParentId() != null) { ip.setItemNameConverted( ip.getItemId().getItemName() + " : " + ip.getItemId().getVariantName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { if (ip.getItemType().equals(KeyConstants.NonSerial)) { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { List<IItemPurchasePropertyValue> temp = itemMasterSession .returnIItemPurchasePropertyValueByPurchaseDetail(ip.getId()); if (temp != null && !temp.isEmpty()) { String s = ""; for (IItemPurchasePropertyValue i : temp) { s += i.getItemMasterPropertyId().getPropertyName() + "-" + i.getPropertyValue() + ", "; } s = JsfUtil.trimComma(s); ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " , (" + s + ")"); ip.setPropertyValues(s); } else { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } } } // System.out.println(ip.getItemNameConverted()); } } } public void itemNameConvertSalesReport(List<IPurchaseDetail> queried) { if (queried != null) { for (IPurchaseDetail ip : queried) { if (ip.getParentId() != null) { ip.setItemNameConverted(ip.getItemId().getItemName() + " : " + ip.getItemId().getVariantName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { if (ip.getItemType().equals(KeyConstants.NonSerial)) { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { List<IItemPurchasePropertyValue> temp = itemMasterSession .returnIItemPurchasePropertyValueByPurchaseDetail(ip.getId()); if (temp != null && !temp.isEmpty()) { String s = ""; for (IItemPurchasePropertyValue i : temp) { s += i.getItemMasterPropertyId().getPropertyName() + "-" + i.getPropertyValue() + ", "; } s = JsfUtil.trimComma(s); ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " , (" + s + ")"); ip.setPropertyValues(s); } else { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } } } } } } public void itemNameConvertSalesReport(IPurchaseDetail ip) { if (ip != null) { if (ip.getParentId() != null) { ip.setItemNameConverted(ip.getItemId().getItemName() + " : " + ip.getItemId().getVariantName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { if (ip.getItemType().equals(KeyConstants.NonSerial)) { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { List<IItemPurchasePropertyValue> temp = itemMasterSession .returnIItemPurchasePropertyValueByPurchaseDetail(ip.getId()); if (temp != null && !temp.isEmpty()) { String s = ""; for (IItemPurchasePropertyValue i : temp) { s += i.getItemMasterPropertyId().getPropertyName() + "-" + i.getPropertyValue() + ", "; } s = JsfUtil.trimComma(s); ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " , (" + s + ")"); ip.setPropertyValues(s); } else { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ip.getAvailableQty() + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } } } } } // public void propertyValueFillUpForSalesDetail(List<ISalesDetail> queried) { // if (queried != null) { // for (ISalesDetail is : queried) { // if (is.getPurchaseDetailId().getItemType().equals(KeyConstants.Serial)) { // List<IItemPurchasePropertyValue> temp = itemMasterSession.returnIItemPurchasePropertyValueByPurchaseDetail(is.getPurchaseDetailId().getId()); // if (temp != null && !temp.isEmpty()) { // String s = ""; // for (IItemPurchasePropertyValue i : temp) { // s += i.getItemMasterPropertyId().getPropertyName() + "-" + i.getPropertyValue() + ", "; // } // s = JsfUtil.trimComma(s); // is.getPurchaseDetailId().setPropertyValues(s); // } // } // } // } // } public void itemNameConvertMethod(IPurchaseDetail ip) { if (ip != null) { if (ip.getParentId() != null) { ip.setItemNameConverted(ip.getItemId().getItemName() + " : " + ip.getItemId().getVariantName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { if (ip.getItemType().equals(KeyConstants.NonSerial)) { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } else { List<IItemPurchasePropertyValue> temp = itemMasterSession .returnIItemPurchasePropertyValueByPurchaseDetail(ip.getId()); if (temp != null && !temp.isEmpty()) { String s = ""; for (IItemPurchasePropertyValue i : temp) { s += i.getItemMasterPropertyId().getPropertyName() + "-" + i.getPropertyValue() + ", "; } s = JsfUtil.trimComma(s); ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " , (" + s + ")"); ip.setPropertyValues(s); } else { ip.setItemNameConverted(ip.getItemId().getItemName() + " - " + ((ip.getAvailableQtyTemp() != null && ip.getAvailableQtyTemp() > 0) ? ip.getAvailableQtyTemp() : ip.getAvailableQty()) + " " + ip.getItemId().getMeasurementUnitId().getShortName() + " - " + ip.getPurchaseHeaderId().getPurchaseDateNepali()); } } } } } public List<IPurchaseDetail> buildFromSalesUpdateSuggestions(String query) { return this.queryForSalesUpdate(query); } public List<IPurchaseDetail> queryForSalesUpdate(String name) { List<IPurchaseDetail> queried = new ArrayList<IPurchaseDetail>(); for (IPurchaseDetail ip : purchaseDetailDropDown) { if (ip.getItemId().getItemName().toLowerCase().startsWith(name.toLowerCase())) { if (ip.getAvailableQtyTemp() != null) { ip.setAvailableQtyTemp(null); itemNameConvertSalesReport(ip); } if (ip.getAvailableQty() > 0) { queried.add(ip); } } } return queried; } public List<IPurchaseDetail> buildFromItemIssueUpdateSuggestions(String query) { return this.queryForItemIssueUpdate(query); } public List<IPurchaseDetail> queryForItemIssueUpdate(String name) { List<IPurchaseDetail> queried = new ArrayList<IPurchaseDetail>(); for (IPurchaseDetail ip : purchaseDetailDropDown) { if (ip.getItemId().getItemName().toLowerCase().startsWith(name.toLowerCase())) { if (ip.getAvailableQtyTemp() != null) { ip.setAvailableQtyTemp(null); itemNameConvertSalesReport(ip); } if (ip.getAvailableQty() > 0) { queried.add(ip); } } } return queried; } private PersonalInfo personalInfo; public void ajaxAccPersonalInfo() { if (purchaseAccMstrCustomerId > 0) { personalInfo = accMasterSession.returnPersonalInfo(purchaseAccMstrCustomerId); } if (personalInfo == null) { personalInfo = new PersonalInfo(); } } public String redirectToSalesEntry() { addressAndPan = new PersonalInfo(); HelperUtil.setPageName(PageNameEnum.SALESINVOICE); MetaTable m = appDataSession.returnMetaTableByMetaKey(KeyConstants.SALES_VAT, HelperUtil.getLoggedInOfficeID()); if (m != null && m.getMetaValue() != null) { try { String s = m.getMetaValue(); s = s.replaceAll("%", ""); vatPercentage = Double.parseDouble(s); } catch (Exception e) { e.printStackTrace(); vatPercentage = 0.0; } } selectedPaymentMode = "CASH"; initialize(); /* * Dont put salesHeaderIdForBillPrint to initialize() method because this method is called from various other methods * and salesHeaderIdForBillPrint variable may flush the value that may be required. */ salesHeaderIdForBillPrint = 0; remarks = "Sales Bill No. " + billNo; purchaseDetailDropDown = iPurchaseDetailSession.returnNativePurchaseDetail(getLoggedInOffice().getId()); itemNameConvertMethod(purchaseDetailDropDown); return HelperUtil.getPageName().getPageLink(); } public String redirectToSalesReturn() { HelperUtil.setPageName(PageNameEnum.SALESRETURN); billNo = null; stage = 1; salesHeaderList = new ArrayList<SalesHeaderDetail>(); productReturnReasons = appDataSession.returnAppDataByDataType(KeyConstants.PRODUCTRETURNREASON); irHeaderIdForPrint = 0; return "/salesReturn.xhtml?faces-redirect=true"; } public void searchSalesHeader() { HelperUtil.setPageName(pageName.SALESRETURN); if (!JsfUtil.validationNumber(billNo, "Bill No")) { return; } System.out.println("billNo " + billNo); salesHeaderList = iSalesDetailSession.returnSalesHeadersByBillNo(HelperUtil.getLoggedInOffice().getId(), billNo); if (salesHeaderList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); } } public void salesReportViewAllClicked() { HelperUtil.setPageName(pageName.SALESRETURN); salesHeaderList = iSalesDetailSession.returnAllSalesHeaders(HelperUtil.getLoggedInOffice().getId()); if (salesHeaderList == null || salesHeaderList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); } } public String redirectToItemIssuePage() { issueHeader = new IItemIssueHeader(); issueDetail = new IItemIssueDetail(); issueDetailList = new ArrayList<IItemIssueDetail>(); ipurchaseDetail = null; editRender = false; totalQuantityCount = 0.0; purchaseDetailDropDown = iPurchaseDetailSession .returnNativePurchaseDetailByRawProcessed(getLoggedInOffice().getId(), false); itemNameConvertMethod(purchaseDetailDropDown); return "itemIssueForm.xhtml?faces-redirect=true"; } private PageNameEnum pageName; private LazyDataModel salesListSummaryLazy; public String redirectToSalesBetweenDate() { HelperUtil.setPageName(PageNameEnum.SALESINVOICEREPORT); itemMasterList = itemMasterSession.retrieveIItemMasterByOffice(getLoggedInOffice().getId()); /* * SALES REPORT SHOWS TWO LIST i.e. SUMMARY VIEW AND DETAIL VIEW * 1. DETAIL VIEW SHOWS SALES HEADER LIST AND THE HEADER SHOWS FURTHER DETAILS * 2. SUMMARY VIEW SHOWS ALL SALES DETAILS LIST WHICH SHOWS BOTH SALES ITEMS DETAIL AND SALES HEADER DETAILS. * THIS FIRST PROCESS RETURN ALL THE HEADERS LIST i.e. DETAIL VIEW */ Date fdate = JsfUtil.dateBeforThirtyDays(new Date(), -30); Date tdate = HelperUtil.getDateToDate(new Date()); returnAllNonLazySalesDetail(fdate, tdate); /* * THIS SECOND PROCESS RETURN SALES DETAIL LIST i.e. SUMMARY VIEW THAT SHOWS BOTH SALES ITEMS DETAIL AND SALES HEADER DETAILS. */ returnAllLazySalesDetail(fdate, tdate); // searchDetailList(tdate, tdate); salesReportCleanup(); return "salesBetnDate.xhtml?faces-redirect=true"; } public void returnAllNonLazySalesDetail(Date date1, Date date2) { resetTotal(); salesHeaderList = iSalesDetailSession.returnSalesHeadersByBtwnDates(date1, date2, getLoggedInOffice().getId()); if (salesHeaderList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); return; } double returnAmount = 0.0; for (SalesHeaderDetail sales : salesHeaderList) { if (sales.getBillAmount() != null) { totalBillAmount += sales.getBillAmount(); totalVatAmount += sales.getVatAmount(); totalDiscountAmount += sales.getDiscount(); totalAmountBeforevat += sales.getSubTotalAmount(); } returnAmount = iSalesDetailSession.retriveSalesReturn(sales.getId(), getLoggedInOffice().getId(), date1, date2); // System.out.println("return Amount is " + returnAmount); sales.setTotalReturnAmount(returnAmount); totalSalesPriceFinal = totalBillAmount - returnAmount; totalReturnAmount += sales.getTotalReturnAmount(); } } public void returnAllLazySalesDetail(Date date1, Date date2) { HelperUtil.setPageName(pageName.SALESAGEINGREPORT); this.startDate = date1; this.endDate = date2; final int count = iSalesDetailSession.returnAllSalesDetailCount(HelperUtil.getLoggedInOfficeID(), startDate, endDate); salesListSummaryLazy = new LazyDataModel<ISalesDetail>() { @Override public List<ISalesDetail> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { List<ISalesDetail> salesList = iSalesDetailSession.returnAllISalesDetailLazyMode(first, pageSize, filters, HelperUtil.getLoggedInOfficeID(), startDate, endDate); if (salesList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); } else { inventoryValueSetup.serialPropertyFillUpOnSalesDetail(salesList); } this.setRowCount(count); return salesList; } }; } public void salesReportCleanup() { fromDate = JsfUtil.dateBeforThirtyDaysNDC(new Date(), -30); toDate = ndc.convertToNepaliDate(new Date()); stage = 1; displayAll = true; filterString = "detail"; } public String redirectToItemIssueReport() { fromDate = JsfUtil.dateBeforThirtyDaysNDC(new Date(), -30); toDate = ndc.convertToNepaliDate(new Date()); stage = 1; // itemMasterList = itemMasterSession.retrieveIItemMasterByOffice(getLoggedInOffice().getId()); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 59); Date fdate = JsfUtil.dateBeforThirtyDays(new Date(), -30); issueHeadersList = iSalesDetailSession.returnItemIssueHeadersByDates(fdate, cal.getTime(), getLoggedInOffice().getId()); purchaseDetailDropDown = iPurchaseDetailSession.returnNativePurchaseDetail(getLoggedInOffice().getId()); itemNameConvertMethod(purchaseDetailDropDown); return "itemIssueReport.xhtml?faces-redirect=true"; } public void redirectToIndex() { stage = 1; } public String returnFromSalesDetail() { System.out.println("geting back to " + HelperUtil.getPageName().getPageLink()); return HelperUtil.getPageName().getPageLink(); } public void displayAllSearchReportClicked() { HelperUtil.setPageName(pageName.SALESINVOICEREPORT); if (filterString.equals("detail")) { displayAll = true; returnAllNonLazySalesDetail(null, null); } else { returnAllLazySalesDetail(null, null); } } public void resetTotal() { totalAmountBeforevat = 0.0; totalBillAmount = 0.0; totalDiscountAmount = 0.0; totalVatAmount = 0.0; totalSalesPriceFinal = 0.0; totalReturnAmount = 0.0; } public void salesDetailSearchClicked() { HelperUtil.setPageName(pageName.SALESINVOICEREPORT); resetTotal(); String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); if (startDateString == null || "".equals(startDateString)) { showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please Enter From Date", ""); return; } if (endDateString == null || "".equals(endDateString)) { showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please Enter To Date", ""); return; } startDate = ndc.convertToEnglishDate(startDateString); endDate = ndc.convertToEnglishDate(endDateString); if (filterString.equals("detail")) { System.out.println(startDate + " " + endDate); searchDetailList(startDate, endDate); } else { returnAllLazySalesDetail(startDate, endDate); } } public void searchDetailList(Date date1, Date date2) { salesHeaderList = iSalesDetailSession.returnSalesHeadersByBtwnDates(date1, date2, getLoggedInOffice().getId()); if (salesHeaderList == null || salesHeaderList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); return; } if (!salesHeaderList.isEmpty()) { resetTotal(); double returnAmount = 0.0; for (SalesHeaderDetail sales : salesHeaderList) { if (sales.getBillAmount() != null) { totalBillAmount += sales.getBillAmount(); totalVatAmount += sales.getVatAmount(); totalDiscountAmount += sales.getDiscount(); totalAmountBeforevat += sales.getSubTotalAmount(); } returnAmount = iSalesDetailSession.retriveSalesReturn(sales.getId(), getLoggedInOffice().getId(), date1, date2); // System.out.println("return Amount is " + returnAmount); sales.setTotalReturnAmount(returnAmount); totalSalesPriceFinal = totalBillAmount - returnAmount; totalReturnAmount += sales.getTotalReturnAmount(); } } displayAll = false; } public void displayAllItemIssuedHeaders() { issueHeadersList = iSalesDetailSession.returnAllItemIssued(getLoggedInOffice().getId()); if (issueHeadersList == null || issueHeadersList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); if (!salesHeaderList.isEmpty()) { totalBillAmount = 0.0; for (SalesHeaderDetail sales : salesHeaderList) { if (sales.getBillAmount() != null) { totalBillAmount += sales.getBillAmount(); } } } } } public void itemIssuedHeaderSearched() { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); if (startDateString == null || "".equals(startDateString)) { showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please Enter From Date", ""); return; } if (endDateString == null || "".equals(endDateString)) { showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please Enter To Date", ""); return; } startDate = ndc.convertToEnglishDate(startDateString); endDate = ndc.convertToEnglishDate(endDateString); issueHeadersList = iSalesDetailSession.returnItemIssueHeadersByDates(startDate, endDate, getLoggedInOffice().getId()); if (issueHeadersList == null || issueHeadersList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no record found."); } } public void editSoldItems(SalesHeaderDetail sh) { billNo = sh.getBillNo(); soldDate = sh.getSalesDateNp(); paymentDate = ""; selectedSalesAccountType = KeyConstants.SALES_ACC_TYPE_CUSTOMER; selectedOffice = 0; selectedPaymentMode = sh.getPaymentMethod(); if (sh.getPaymentMethod().equals(KeyConstants.PAYMENT_MODE_CREDIT)) { paymentDate = sh.getExpectedPaymentDateNp(); } ajaxPaymentMode(); selectedSalesHeader = sh; ipurchaseDetail = null; salesDTO = new SalesDTO(); isalesDetailsList = iSalesDetailSession.retrieveSalesDetailByHeaderId(sh.getId()); inventoryValueSetup.serialPropertyFillUpOnSalesDetail(isalesDetailsList); isalesDetailsListForDeleted = new ArrayList<ISalesDetail>(); salesDate = sh.getSalesDateNp(); totalSalesPrice = 0.0; for (ISalesDetail s : isalesDetailsList) { totalSalesPrice += (s.getSellingPrice() * s.getSalesQty()); } totalSalesPriceFinal = selectedSalesHeader.getBillAmount(); discount = selectedSalesHeader.getDiscount(); vatPercentage = selectedSalesHeader.getVatPercentage(); ajaxTotalCalculation(); advancePayment = selectedSalesHeader.getAdvancePayment(); purchaseDetailDropDown = iPurchaseDetailSession.returnNativePurchaseDetail(getLoggedInOffice().getId()); itemNameConvertMethod(purchaseDetailDropDown); stage = 3; editRender = false; purchaseAccMstrCustomerId = sh.getCustomerId().getId(); System.out .println("editSoldItems > customer/supplier account Id after edit > " + purchaseAccMstrCustomerId); } private IItemIssueHeader selectedItemIssuedHeader; public String showSoldItems(SalesHeaderDetail sh) { HelperUtil.setPageName(pageName.SALESINVOICEREPORT); selectedSalesHeader = sh; isalesDetailsList = iSalesDetailSession.returnSalesDetailByHeader(sh.getId()); if (isalesDetailsList == null || isalesDetailsList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no item found"); return null; } totalSalesPrice = 0.0; for (ISalesDetail i : isalesDetailsList) { totalSalesPrice += (i.getSalesQty() * i.getSellingPrice()); } totalSalesPriceFinal = selectedSalesHeader.getBillAmount(); discount = selectedSalesHeader.getDiscount(); vatPercentage = selectedSalesHeader.getVatPercentage(); ajaxTotalCalculation(); inventoryValueSetup.serialPropertyFillUpOnSalesDetail(isalesDetailsList); return "salesDetail.xhtml?faces-redirect=true"; } public String showSoldItemsForReturn(SalesHeaderDetail sh) { HelperUtil.setPageName(pageName.SALESRETURN); selectedSalesHeader = sh; isalesDetailsList = iSalesDetailSession.returnSalesDetailByHeader(sh.getId()); if (isalesDetailsList == null || isalesDetailsList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no item found"); return null; } totalSalesPrice = 0.0; for (ISalesDetail i : isalesDetailsList) { totalSalesPrice += (i.getSalesQty() * i.getSellingPrice()); } totalSalesPriceFinal = selectedSalesHeader.getBillAmount(); discount = selectedSalesHeader.getDiscount(); vatPercentage = selectedSalesHeader.getVatPercentage(); ajaxTotalCalculation(); inventoryValueSetup.serialPropertyFillUpOnSalesDetail(isalesDetailsList); return "salesDetail.xhtml?faces-redirect=true"; } public void soldListToReturn(SalesHeaderDetail sh) { selectedSalesHeader = sh; returnHeader = new IInventoryReturnHeader(); returnHeader.setSalesHeaderId(sh); isalesDetailsList = iSalesDetailSession.returnSalesDetailByHeader(sh.getId()); if (isalesDetailsList == null || isalesDetailsList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no item found"); return; } stage = 2; irHeaderIdForPrint = 0; } private IInventoryReturnHeader returnHeader; public void showItemIssued(IItemIssueHeader ih) { issueDetailList = iSalesDetailSession.returnItemIssueDetailByHeader(ih.getId()); if (issueDetailList == null || issueDetailList.isEmpty()) { JsfUtil.addErrorMessage("Sorry, no item found"); return; } editRender = false; stage = 2; } public void itemIssuedBackBtnClicked() { stage = 1; editRender = false; } public void removeSalesBySalesHeader(SalesHeaderDetail sh) { try { salesTransactionBean.removeSalesBySalesHeader(sh); salesHeaderList.remove(sh); JsfUtil.addSuccessMessage("Sales remove successful."); } catch (ClientException ex) { HelperUtil.showErrorMessage(ex.getMessage()); } } public void removeItemFromSaleReport1(ISalesDetail is) { isalesDetailsList.remove(is); isalesDetailsListForDeleted.add(is); totalSalesPrice = 0.0; for (ISalesDetail s : isalesDetailsList) { totalSalesPrice += (s.getSalesQty() * s.getSellingPrice()); } ajaxTotalCalculation(); for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(is.getPurchaseDetailId().getId())) { p.setAvailableQty(p.getAvailableQty() + is.getSalesQty()); itemNameConvertSalesReport(p); break; } } } // public void removeItemFromSaleReport(ISalesDetail is) { // // try { // salesTransactionBean.removeItemFromSaleReport(is, selectedSalesHeader); // // /* // Now calulate the total amount and include/exclude dscount, vat, tax if any available and later merge. . // */ // totalSalesPrice = 0.0; // for (ISalesDetail s : isalesDetailsList) { // totalSalesPrice += (s.getSalesQty() * s.getSellingPrice()); // } // ajaxTotalCalculation(); // // selectedSalesHeader.setDiscount(discount); // selectedSalesHeader.setVatPercentage(vatPercentage); // selectedSalesHeader.setBillAmount(totalSalesPriceFinal); // selectedSalesHeader.setAdvancePayment(advancePayment); // // iPurchaseDetailSession.merge(selectedSalesHeader); // // /* // Now update the "purchaseDetailDropDown" list, since it is the dropdown list of item select so it must be updated whether // while removal or new addition or existing qty modified. // */ // for (IPurchaseDetail p : purchaseDetailDropDown) { // if (p.getId().equals(is.getPurchaseDetailId().getId())) { // p.setAvailableQty(p.getAvailableQty() + is.getSalesQty()); // itemNameConvertSalesReport(p); // break; // } // } // // isalesDetailsList.remove(is); // // JsfUtil.addSuccessMessage("Item Successfully Removed."); // } catch (ClientException ex) { // HelperUtil.showErrorMessage(ex.getMessage()); // } // } private boolean editRender; private ISalesDetail selectedISalesDetail; private IItemIssueDetail selectedIssueDetail; public void editItemFromSaleReport(ISalesDetail is) { selectedISalesDetail = is; ipurchaseDetail = is.getPurchaseDetailId(); for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(is.getPurchaseDetailId().getId())) { p.setAvailableQtyTemp(p.getAvailableQty() + is.getSalesQty()); ipurchaseDetail.setAvailableQtyTemp(p.getAvailableQty() + is.getSalesQty()); itemNameConvertMethod(p); } } itemNameConvertMethod(ipurchaseDetail); editRender = true; salesDTO = new SalesDTO(); salesDTO.setQuantity(is.getSalesQty()); salesDTO.setSalesAmount(is.getSellingPrice()); } public void editFromItemIssued(IItemIssueDetail is) { selectedIssueDetail = is; ipurchaseDetail = is.getPurchaseDetailId(); ipurchaseDetail.setAvailableQtyTemp(ipurchaseDetail.getAvailableQty() + is.getQuantity()); for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(is.getPurchaseDetailId().getId())) { p.setAvailableQtyTemp(p.getAvailableQty() + is.getQuantity()); itemNameConvertMethod(p); } } itemNameConvertMethod(ipurchaseDetail); editRender = true; salesDTO = new SalesDTO(); issueDetail = new IItemIssueDetail(); issueDetail.setQuantity(is.getQuantity()); } public void onRowSelect(SelectEvent event) { double qty = 0; if (ipurchaseDetail.getAvailableQtyTemp() != null) { qty = ipurchaseDetail.getAvailableQtyTemp(); } else { qty = ipurchaseDetail.getAvailableQty(); } salesDTO = new SalesDTO(); IPurchaseDetail ip = new IPurchaseDetail(); ip = (IPurchaseDetail) event.getObject(); salesDTO.setQuantity(qty); actualQtySum = qty; salesDTO.setSalesAmount(ipurchaseDetail.getUnitPrice()); salesDTO.setItemName(ip.getItemId().getItemName()); salesDTO.setPurchaseDetailId(ip.getId()); } public void onRowUnselect(UnselectEvent event) { actualQtySum = 0; salesDTO = new SalesDTO(); } public void updateItemsFromSalesReport1() { try { itemNameConvertMethod(ipurchaseDetail); IPurchaseDetail detail = iPurchaseDetailSession .findIPurchaseDetail(selectedISalesDetail.getPurchaseDetailId().getId()); System.out.println(salesDTO.getQuantity() + " " + selectedISalesDetail.getSalesQty() + " " + detail.getAvailableQty()); if (salesDTO.getQuantity() > (selectedISalesDetail.getSalesQty() + detail.getAvailableQty())) { JsfUtil.addErrorMessage("Sorry, quantity is above availabe stock."); return; } else if (salesDTO.getQuantity() == 0) { JsfUtil.addErrorMessage("Sales quantity must be greater than zero."); return; } selectedISalesDetail.setSalesQty(salesDTO.getQuantity()); selectedISalesDetail.setSellingPrice(salesDTO.getSalesAmount()); totalSalesPrice = 0.0; for (ISalesDetail s : isalesDetailsList) { totalSalesPrice += (s.getSalesQty() * s.getSellingPrice()); } ajaxTotalCalculation(); for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(selectedISalesDetail.getPurchaseDetailId().getId())) { ISalesDetail sd = iSalesDetailSession.findSalesDetail(selectedISalesDetail.getId()); p.setAvailableQty(sd.getPurchaseDetailId().getAvailableQty() + sd.getSalesQty() - selectedISalesDetail.getSalesQty()); itemNameConvertSalesReport(p); break; } } cleanSalesDetailsListPage(); } catch (Exception ex) { HelperUtil.showErrorMessage(ex.getMessage()); } } // public void updateItemsFromSalesReport() { // // try { // itemNameConvertMethod(ipurchaseDetail); // // IPurchaseDetail detail = iPurchaseDetailSession.findIPurchaseDetail(selectedISalesDetail.getPurchaseDetailId().getId()); // // /* // First check if the new updating sales qty is more or less than available qty by adding the available qty with // sold qty because while updating total available qty shows by adding sold qty. For eg: if i have 4 iphone // and i sold 1 unit. Now the available qty is 3 and sold qty is 1. If i need to update the sold qty i.e. 1, the // availble qty should show 4 qty i.e. by adding available qty with sold qty. // */ // if (salesDTO.getQuantity() > (selectedISalesDetail.getSalesQty() + detail.getAvailableQty())) { // JsfUtil.addErrorMessage("Sorry, quantity is above availabe stock."); // return; // } else if (salesDTO.getQuantity() == 0) { // JsfUtil.addErrorMessage("Sales quantity must be greater than zero."); // return; // } // // boolean addQty = false; // double qtyCount = 0; // // /* // Now assign value to the variable "addQty" i.e. true if updated value is greater and we need to add additional qty // and similarly false if updated value is less and we need to less some qty. // */ // if (salesDTO.getQuantity() > selectedISalesDetail.getSalesQty()) { // addQty = true; // } else if (salesDTO.getQuantity() < selectedISalesDetail.getSalesQty()) { // addQty = false; // } else { // if (salesDTO.getSalesAmount().equals(selectedISalesDetail.getSellingPrice())) { // JsfUtil.addErrorMessage("No Change Found."); // return; // } // } // // salesTransactionBean.updateItemsFromSalesReport(addQty, qtyCount, selectedSalesHeader, selectedISalesDetail, salesDTO, detail); // // totalSalesPrice = 0.0; // for (ISalesDetail s : isalesDetailsList) { // totalSalesPrice += (s.getSalesQty() * s.getSellingPrice()); // } // ajaxTotalCalculation(); // // selectedSalesHeader.setDiscount(discount); // selectedSalesHeader.setVatPercentage(vatPercentage); // selectedSalesHeader.setBillAmount(totalSalesPriceFinal); // selectedSalesHeader.setAdvancePayment(advancePayment); // // iPurchaseDetailSession.merge(selectedSalesHeader); // // for (IPurchaseDetail p : purchaseDetailDropDown) { // if (p.getId().equals(selectedISalesDetail.getPurchaseDetailId().getId())) { // p.setAvailableQty(selectedISalesDetail.getPurchaseDetailId().getAvailableQty()); // itemNameConvertSalesReport(p); // break; // } // } // // JsfUtil.addSuccessMessage("Sales entry update successful."); // cleanSalesDetailsListPage(); // } catch (ClientException ex) { // HelperUtil.showErrorMessage(ex.getMessage()); // } // } private double totalAccountingAmount; public void updateItemsToItemIssuedEditRender() { itemNameConvertMethod(ipurchaseDetail); if (issueDetail.getQuantity() > (selectedIssueDetail.getQuantity() + selectedIssueDetail.getPurchaseDetailId().getAvailableQty())) { JsfUtil.addErrorMessage("Sorry, quantity is above availabe stock."); return; } else if (issueDetail.getQuantity() == 0) { JsfUtil.addErrorMessage("Sales quantity must be greater than zero."); return; } boolean addQty = false; double qtyCount; if (issueDetail.getQuantity() > selectedIssueDetail.getQuantity()) { addQty = true; } else if (issueDetail.getQuantity() < selectedIssueDetail.getQuantity()) { addQty = false; } else { JsfUtil.addErrorMessage("Qty found unchanged."); return; } if (addQty) { qtyCount = issueDetail.getQuantity() - selectedIssueDetail.getQuantity(); } else { qtyCount = selectedIssueDetail.getQuantity() - issueDetail.getQuantity(); } singleItemIssueJournalEntry(selectedIssueDetail, true); selectedIssueDetail.setQuantity(issueDetail.getQuantity()); iPurchaseDetailSession.merge(selectedIssueDetail); singleItemIssueJournalEntry(selectedIssueDetail, false); if (addQty) { selectedIssueDetail.getPurchaseDetailId() .setAvailableQty(selectedIssueDetail.getPurchaseDetailId().getAvailableQty() - qtyCount); } else { selectedIssueDetail.getPurchaseDetailId() .setAvailableQty(selectedIssueDetail.getPurchaseDetailId().getAvailableQty() + qtyCount); } iPurchaseDetailSession.merge(selectedIssueDetail.getPurchaseDetailId()); if (addQty) { selectedIssueDetail.getPurchaseDetailId().getItemId().setAvailableQty( selectedIssueDetail.getPurchaseDetailId().getItemId().getAvailableQty() - qtyCount); } else { selectedIssueDetail.getPurchaseDetailId().getItemId().setAvailableQty( selectedIssueDetail.getPurchaseDetailId().getItemId().getAvailableQty() + qtyCount); } iPurchaseDetailSession.merge(selectedIssueDetail.getPurchaseDetailId().getItemId()); if (selectedIssueDetail.getPurchaseDetailId().getParentId() != null) { IPurchaseDetail i = iPurchaseDetailSession .findIPurchaseDetail(selectedIssueDetail.getPurchaseDetailId().getParentId()); if (addQty) { i.setAvailableQty(i.getAvailableQty() - qtyCount); } else { i.setAvailableQty(i.getAvailableQty() + qtyCount); } iPurchaseDetailSession.merge(i); if (addQty) { i.getItemId().setAvailableQty(i.getItemId().getAvailableQty() - qtyCount); } else { i.getItemId().setAvailableQty(i.getItemId().getAvailableQty() + qtyCount); } iPurchaseDetailSession.merge(i.getItemId()); } for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(selectedIssueDetail.getPurchaseDetailId().getId())) { p.setAvailableQty(selectedIssueDetail.getPurchaseDetailId().getAvailableQty()); break; } } JsfUtil.addSuccessMessage("Item Issue update successful."); editRender = false; ipurchaseDetail = null; issueDetail = new IItemIssueDetail(); } public void cleanSalesDetailsListPage() { ipurchaseDetail = null; salesDTO = new SalesDTO(); editRender = false; } public void updateItemsToSalesDto() { itemNameConvertMethod(ipurchaseDetail); if (validationItemAdd()) { return; } if (salesDtoList != null && !salesDtoList.isEmpty()) { for (SalesDTO s : salesDtoList) { if (s.getPurchaseDetail().getId().equals(ipurchaseDetail.getId())) { s.setQuantity(salesDTO.getQuantity()); s.setSalesAmount(salesDTO.getSalesAmount()); break; } } } ipurchaseDetail = null; salesDTO = new SalesDTO(); totalSalesPrice = 0.0; for (SalesDTO s : salesDtoList) { totalSalesPrice += (s.getSalesAmount() * s.getQuantity()); } ajaxTotalCalculation(); editRender = false; } public void updateItemsIssue() { itemNameConvertMethod(ipurchaseDetail); if (validationItemIssueAdd()) { return; } if (issueDetailList != null && !issueDetailList.isEmpty()) { for (IItemIssueDetail s : issueDetailList) { if (s.getPurchaseDetailId().getId().equals(ipurchaseDetail.getId())) { s.setQuantity(issueDetail.getQuantity()); break; } } } ipurchaseDetail = null; issueDetail = new IItemIssueDetail(); editRender = false; } public void addItemsToSalesDto() { itemNameConvertMethod(ipurchaseDetail); System.out.println( "ipurchaseDetail.getItemId().getAccMasterId() " + ipurchaseDetail.getItemId().getAccMasterId()); if (ipurchaseDetail.getItemId().getAccMasterId() == null) { JsfUtil.addErrorMessage( "Click on Master> Product manager> Item and category setup *And then edit credit a/c."); return; } if (validationItemAdd()) { return; } boolean found = false; /* First check if salesDtoList list already contains the item because system doesnt allow to enter same purchase item twice. So with the help of s.getPurchaseDetail().getId() we need to check the item first and if the item id found the item price is overwritten with the new one and the qty is added with the new one. */ if (salesDtoList != null && !salesDtoList.isEmpty()) { for (SalesDTO s : salesDtoList) { if (s.getPurchaseDetail().getId().equals(ipurchaseDetail.getId())) { s.setQuantity(s.getQuantity() + salesDTO.getQuantity()); s.setSalesAmount(salesDTO.getSalesAmount()); System.out.println("s.getSalesDetail().getSalesQty() " + s.getSalesDetail()); if (s.getSalesDetail() != null) { s.getSalesDetail().setSalesQty(s.getQuantity()); s.getSalesDetail().setSellingPrice(s.getSalesAmount()); } found = true; break; } } } if (!found) { if (ipurchaseDetail.getParentId() != null) { salesDTO.setItemName(ipurchaseDetail.getItemId().getItemName() + ":" + ipurchaseDetail.getItemId().getVariantName()); } else { if (ipurchaseDetail.getItemType().equals(KeyConstants.NonSerial)) { salesDTO.setItemName(ipurchaseDetail.getItemId().getItemName()); } else { if (ipurchaseDetail.getPropertyValues() != null && !ipurchaseDetail.getPropertyValues().isEmpty()) { salesDTO.setItemName(ipurchaseDetail.getItemId().getItemName() + " (" + ipurchaseDetail.getPropertyValues() + ")"); } else { salesDTO.setItemName(ipurchaseDetail.getItemId().getItemName()); } } } salesDTO.setPurchaseDetail(ipurchaseDetail); salesDtoList.add(salesDTO); } salesDTO = new SalesDTO(); ipurchaseDetail = null; totalSalesPrice = 0.0; for (SalesDTO s : salesDtoList) { totalSalesPrice += (s.getSalesAmount() * s.getQuantity()); } ajaxTotalCalculation(); System.out.println("totalSalesPrice " + totalSalesPrice); } public void addItemsToItemIssueTable() { itemNameConvertMethod(ipurchaseDetail); if (validationItemIssueAdd()) { return; } // if(issueDetail!=null){ totalQuantityCount = totalQuantityCount - issueDetail.getQuantity(); // } boolean found = false; if (issueDetailList != null && !issueDetailList.isEmpty()) { for (IItemIssueDetail s : issueDetailList) { if (s.getPurchaseDetailId().getId().equals(ipurchaseDetail.getId())) { s.setQuantity(s.getQuantity() + issueDetail.getQuantity()); found = true; break; } } } if (!found) { if (ipurchaseDetail.getParentId() != null) { issueDetail.setItemName(ipurchaseDetail.getItemId().getItemName() + ":" + ipurchaseDetail.getItemId().getVariantName()); } else { if (ipurchaseDetail.getItemType().equals(KeyConstants.NonSerial)) { issueDetail.setItemName(ipurchaseDetail.getItemId().getItemName()); } else { if (ipurchaseDetail.getPropertyValues() != null && !ipurchaseDetail.getPropertyValues().isEmpty()) { issueDetail.setItemName(ipurchaseDetail.getItemId().getItemName() + " (" + ipurchaseDetail.getPropertyValues() + ")"); } else { issueDetail.setItemName(ipurchaseDetail.getItemId().getItemName()); } } } issueDetail.setPurchaseDetailId(ipurchaseDetail); issueDetail.setDelFlg(false); // totalQuantityCount=totalQuantityCount-issueDetail.getQuantity(); issueDetailList.add(issueDetail); } ipurchaseDetail = null; issueDetail = new IItemIssueDetail(); totalQuantityCount = null; } public void addItemsToItemIssueEditRender() { itemNameConvertMethod(ipurchaseDetail); if (validationItemIssueAdd()) { return; } boolean found = false; if (issueDetailList != null && !issueDetailList.isEmpty()) { for (IItemIssueDetail is : issueDetailList) { if (is.getPurchaseDetailId().getId().equals(ipurchaseDetail.getId())) { is.setQuantity(is.getQuantity() + issueDetail.getQuantity()); iPurchaseDetailSession.merge(is); is.getPurchaseDetailId().setAvailableQty( is.getPurchaseDetailId().getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(is.getPurchaseDetailId()); is.getPurchaseDetailId().getItemId().setAvailableQty( is.getPurchaseDetailId().getItemId().getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(is.getPurchaseDetailId().getItemId()); if (is.getPurchaseDetailId().getParentId() != null) { IPurchaseDetail pd = iPurchaseDetailSession .findIPurchaseDetail(is.getPurchaseDetailId().getParentId()); pd.setAvailableQty(pd.getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(pd); pd.getItemId() .setAvailableQty(pd.getItemId().getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(pd.getItemId()); } found = true; break; } } } if (!found) { issueDetail.setPurchaseDetailId(ipurchaseDetail); issueDetail.setDelFlg(false); issueDetail.setIssueHeaderId(issueHeader.getId()); salesDate = issueHeader.getIssuedDateNp(); issueDetail.setIssueHeaderId(issueHeader.getId()); iPurchaseDetailSession.persist(issueDetail); issueDetailList.add(issueDetail); IPurchaseDetail ip = issueDetail.getPurchaseDetailId(); ip.setAvailableQty(ip.getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(ip); IItemMaster it = itemMasterSession.findItemMaster(ip.getItemId().getId()); it.setAvailableQty(it.getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(it); if (ip.getParentId() != null) { IPurchaseDetail i = iPurchaseDetailSession.findIPurchaseDetail(ip.getParentId()); i.setAvailableQty(i.getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(i); it = itemMasterSession.findItemMaster(i.getItemId().getId()); it.setAvailableQty(it.getAvailableQty() - issueDetail.getQuantity()); iPurchaseDetailSession.merge(it); } } singleItemIssueJournalEntry(issueDetail, false); for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(ipurchaseDetail.getId())) { p.setAvailableQty(p.getAvailableQty() - issueDetail.getQuantity()); itemNameConvertSalesReport(p); break; } } ipurchaseDetail = null; issueDetail = new IItemIssueDetail(); JsfUtil.addSuccessMessage("Sales entry save successful."); } public void postProcessXLSItemIssue(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0); int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("Item Issue REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); if (stage == 1) { HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); } sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 4)); } public void cancelUpdateItemIssue() { editRender = false; ipurchaseDetail = null; issueDetail = new IItemIssueDetail(); totalQuantityCount = null; } public void addItemsFromSalesReport1() { try { itemNameConvertSalesReport(ipurchaseDetail); if (ipurchaseDetail.getItemId().getAccMasterId() == null) { JsfUtil.addErrorMessage("Sorry, couldnt find account for this item."); return; } if (validationItemAddEditRender()) { return; } boolean found = false; if (isalesDetailsList != null && !isalesDetailsList.isEmpty()) { for (ISalesDetail is : isalesDetailsList) { if (is.getPurchaseDetailId().getId().equals(ipurchaseDetail.getId())) { is.setSalesQty(is.getSalesQty() + salesDTO.getQuantity()); is.setSellingPrice(salesDTO.getSalesAmount()); found = true; break; } } } if (!found) { ISalesDetail sales = new ISalesDetail(); sales.setPurchaseDetailId(ipurchaseDetail); sales.setSalesHeaderDetailId(selectedSalesHeader); sales.setItemId(ipurchaseDetail.getItemId()); sales.setDelFlg(false); sales.setSellingPrice(salesDTO.getSalesAmount()); sales.setSalesQty(salesDTO.getQuantity()); isalesDetailsList.add(sales); } totalSalesPrice = 0.0; for (ISalesDetail s : isalesDetailsList) { totalSalesPrice += (s.getSalesQty() * s.getSellingPrice()); } ajaxTotalCalculation(); for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(ipurchaseDetail.getId())) { p.setAvailableQty(p.getAvailableQty() - salesDTO.getQuantity()); itemNameConvertSalesReport(p); break; } } ipurchaseDetail = null; salesDTO = new SalesDTO(); } catch (Exception ex) { HelperUtil.showErrorMessage(ex.getMessage()); } } // public void addItemsFromSalesReport() { // // try { // itemNameConvertSalesReport(ipurchaseDetail); // // if (ipurchaseDetail.getItemId().getAccMasterId() == null) { // JsfUtil.addErrorMessage("Sorry, couldnt find account for this item."); // return; // } // // if (validationItemAddEditRender()) { // return; // } // salesTransactionBean.addItemsFromSalesReport(isalesDetailsList, selectedSalesHeader, ipurchaseDetail, salesDTO); // // totalSalesPrice = 0.0; // for (ISalesDetail s : isalesDetailsList) { // totalSalesPrice += (s.getSalesQty() * s.getSellingPrice()); // } // ajaxTotalCalculation(); // // selectedSalesHeader.setDiscount(discount); // selectedSalesHeader.setVatPercentage(vatPercentage); // selectedSalesHeader.setBillAmount(totalSalesPriceFinal); // selectedSalesHeader.setAdvancePayment(advancePayment); // // iPurchaseDetailSession.merge(selectedSalesHeader); // // for (IPurchaseDetail p : purchaseDetailDropDown) { // if (p.getId().equals(ipurchaseDetail.getId())) { // p.setAvailableQty(p.getAvailableQty() - salesDTO.getQuantity()); // itemNameConvertSalesReport(p); // break; // } // } // // ipurchaseDetail = null; // salesDTO = new SalesDTO(); // // JsfUtil.addSuccessMessage("Sales Entry Save Successful."); // } catch (ClientException ex) { // HelperUtil.showErrorMessage(ex.getMessage()); // } // } public boolean validationItemAdd() { if (ipurchaseDetail == null) { JsfUtil.addErrorMessage("Please Select Item."); return true; } else if (!JsfUtil.validationNumber(salesDTO.getQuantity(), "Qty")) { return true; } /* While editRender is false i.e. while inserting but not updating.. for example if i have iphone 10 unit and i added 1 unit already to the salesDtoList list. The unit stock doesnt decrease by 1 in this so the unit is still 10. So when i add iphone but this time with 10 units, it shows validation error because it check the stock by adding already added 1 unit with current adding unit 10.. so it makes 11. s */ if (!editRender) { if (salesDtoList != null && !salesDtoList.isEmpty()) { for (SalesDTO s : salesDtoList) { if (s.getPurchaseDetail().getId().equals(ipurchaseDetail.getId())) { if ((s.getQuantity() + salesDTO.getQuantity()) > ipurchaseDetail.getAvailableQty()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } break; } } } } if (ipurchaseDetail.getAvailableQtyTemp() != null) { if (salesDTO.getQuantity() > ipurchaseDetail.getAvailableQtyTemp()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } } else { if (salesDTO.getQuantity() > ipurchaseDetail.getAvailableQty()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } } if (salesDTO.getSalesAmount() == 0) { JsfUtil.addErrorMessage("Please enter sales price."); return true; } if (vatAmount != null && vatAmount > 0) { MetaTable mt = appDataSession.returnMetaTableByMetaKey(KeyConstants.SALES_VAT, HelperUtil.getLoggedInOfficeID()); if (mt.getAccMasterId() == null) { JsfUtil.addErrorMessage( "Ledger for VAT is not setup, please set proper ledger for VAT in Settings > Parameters"); return true; } } if (discount != null && discount > 0) { MetaTable mt = appDataSession.returnMetaTableByMetaKey(KeyConstants.SALES_DISCOUNT, HelperUtil.getLoggedInOfficeID()); if (mt.getAccMasterId() == null) { JsfUtil.addErrorMessage( "Ledger for Discount is not setup, please set proper ledger for Discount in Settings > Parameters"); return true; } } return false; } public boolean validationItemIssueAdd() { if (ipurchaseDetail == null) { JsfUtil.addErrorMessage("Please select item."); return true; } else if (issueDetail.getQuantity() == 0) { JsfUtil.addErrorMessage("Please enter quantity."); return true; } else if (issueDetail.getQuantity() < 0) { JsfUtil.addErrorMessage("Please enter valid quantity."); return true; } else if (issueDetail.getQuantity() >= totalQuantityCount) { JsfUtil.addErrorMessage("Please enter valid quantity."); return true; } if (!editRender) { if (issueDetailList != null && !issueDetailList.isEmpty()) { for (IItemIssueDetail s : issueDetailList) { if (s.getPurchaseDetailId().getId().equals(ipurchaseDetail.getId())) { if ((s.getQuantity() + issueDetail.getQuantity()) > ipurchaseDetail.getAvailableQty()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } break; } } } } if (ipurchaseDetail.getAvailableQtyTemp() != null) { if (issueDetail.getQuantity() > ipurchaseDetail.getAvailableQtyTemp()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } } else { if (issueDetail.getQuantity() > ipurchaseDetail.getAvailableQty()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } } return false; } public boolean validationItemAddEditRender() { if (ipurchaseDetail == null) { JsfUtil.addErrorMessage("Please select item."); return true; } else if (salesDTO.getQuantity() == 0) { JsfUtil.addErrorMessage("Please enter quantity."); return true; } // Now check if the already available item and the going to be added quantity sum is not above available stock quantity // for eg. if i have samsung phone 4 piece. and i have added 2 piece to my list already and now if i add 3 piece it must // avoid me adding the item because now the stock remainig quantity is 2 where i added 3. if (!editRender) { if (salesDtoList != null && !salesDtoList.isEmpty()) { for (SalesDTO s : salesDtoList) { if (s.getPurchaseDetail().getId().equals(ipurchaseDetail.getId())) { if ((s.getQuantity() + salesDTO.getQuantity()) > ipurchaseDetail.getAvailableQty()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } break; } } } } if (ipurchaseDetail.getAvailableQtyTemp() != null) { if (salesDTO.getQuantity() > ipurchaseDetail.getAvailableQtyTemp()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } } else { if (salesDTO.getQuantity() > ipurchaseDetail.getAvailableQty()) { JsfUtil.addErrorMessage("Sorry, the quantity is above our available stock."); return true; } } if (salesDTO.getSalesAmount() == 0) { JsfUtil.addErrorMessage("Please enter sales price."); return true; } return false; } public void ajaxTotalCalculation() { if (vatPercentage == null) { vatPercentage = 0.0; } taxableAmount = totalSalesPrice - (discount == null ? 0.0 : discount); try { vatAmount = ((vatPercentage == null ? 0.0 : vatPercentage) * taxableAmount) / 100; totalSalesPriceFinal = taxableAmount + vatAmount; } catch (Exception e) { e.printStackTrace(); //JsfUtil.addErrorMessage("Sorry, some error occured while parsing vat percentage value"); } } public void updateSalesBill() { try { if (!validationSalesEntrySubmit()) { return; } selectedSalesHeader.setSalesDate(ndc.convertToEnglishDate(salesDate)); selectedSalesHeader.setSalesDateNp(formatNepaliDate(salesDate)); selectedSalesHeader.setDiscount(discount); selectedSalesHeader.setVatPercentage(vatPercentage); selectedSalesHeader.setVatAmount(vatAmount); selectedSalesHeader.setBillAmount(totalSalesPriceFinal); selectedSalesHeader.setAdvancePayment(advancePayment); selectedSalesHeader.setPaymentMethod(selectedPaymentMode); selectedSalesHeader.setTaxableAmount(taxableAmount); selectedSalesHeader.setSubTotalAmount(totalSalesPrice); if (selectedSalesAccountType.equals("customer")) { if (purchaseAccMstrCustomerId > 0) { AccMaster acm = accMasterSession.retrieveAccMasterById(purchaseAccMstrCustomerId); selectedSalesHeader.setCustomerId(acm); } } else if (selectedSalesAccountType.equals("office")) { if (selectedOffice > 0) { selectedSalesHeader.setCustomerId(addAccountReceivable(selectedOffice)); } } String paymentDate = null; if (selectedPaymentMode.equals(KeyConstants.PAYMENT_MODE_CREDIT)) { paymentDate = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate7"); selectedSalesHeader.setExpectedPaymentDateNp(paymentDate); selectedSalesHeader .setExpectedPaymentDate(new NepaliDateConverter().convertToEnglishDate(paymentDate)); } salesTransactionBean.updateSalesBill(isalesDetailsList, selectedSalesHeader, isalesDetailsListForDeleted); JsfUtil.addSuccessMessage("Bill update successful."); cleanSalesDetailsListPage(); redirectToSalesBetweenDate(); } catch (ClientException c) { HelperUtil.showErrorMessage(c.getMessage()); } } public void ajaxSalesOptions() { addressAndPan = new PersonalInfo(); purchaseAccMstrCustomerId = 0; // if(selectedSalesAccountType) } public void ajaxPaymentMode() { addressAndPan = new PersonalInfo(); purchaseAccMstrCustomerId = 0; if (!selectedPaymentMode.equals("CASH")) { purchaseAccMstrSuppList = new ArrayList<AccMaster>(); purchaseAccMstrSuppList = accMasterSession.retrieveAccMasterByOwner(getLoggedInOffice().getId(), KeyConstants.OWNERCUSTOMER); } else { purchaseAccMstrSuppList = new ArrayList<AccMaster>(); purchaseAccMstrSuppList.addAll(accMasterSession.retrieveAccMasterByGlSubCodeAndOffice(KeyConstants.CASH, getLoggedInOffice().getId())); purchaseAccMstrSuppList.addAll(accMasterSession.retrieveAccMasterByGlSubCodeAndOffice(KeyConstants.BANK, getLoggedInOffice().getId())); } } public AccMaster addAccountReceivable(int associateId) { AccMaster a = accMasterSession.retrieveAccountMasterByofficeIdGlSubheadCodeAndAssociatedOfficeId( getLoggedInOffice().getId(), KeyConstants.ACCOUNTSRECEIVABLE, associateId); if (a == null) { Office o = officeSession.findOfficeById(associateId); AccMaster add = accMasterSession.addAccMaster(o.getName(), accOwnershipSession.retrieveAccOwnershipById(KeyConstants.OWNERCUSTOMER), getLoggedInOffice(), glSubHeadSession.retrieveGlSubIdByOffAndCode(KeyConstants.ACCOUNTSRECEIVABLE, getLoggedInOffice().getId()), o, getLoggedInUser(), false, false); a = add; PersonalInfo pi = new PersonalInfo(); pi.setName(a.getAccName()); pi.setAccId(a.getId()); pi.setAddress(o.getAddress()); pi.setPanNo(o.getPanNo()); pi.setMobile1(o.getContact()); accMasterSession.persistObject(pi); } return a; } BasicAccountSetup b = new BasicAccountSetup(); public void saveSalesEntry() { try { if (!validationSalesEntrySubmit()) { return; } SalesHeaderDetail detail = new SalesHeaderDetail(); detail.setBillNo(billNo); detail.setPaymentMethod(selectedPaymentMode); if (selectedSalesAccountType.equals("customer")) { if (purchaseAccMstrCustomerId > 0) { AccMaster acm = accMasterSession.retrieveAccMasterById(purchaseAccMstrCustomerId); detail.setCustomerId(acm); } } else if (selectedSalesAccountType.equals("office")) { if (selectedOffice > 0) { detail.setCustomerId(addAccountReceivable(selectedOffice)); } } detail.setDelFlg(false); detail.setEnteredBy(getLoggedInUser().getId()); detail.setEnteredDate(new Date()); detail.setOfficeId(getLoggedInOffice()); detail.setDiscount(discount); try { detail.setVatPercentage(vatPercentage); detail.setSalesDate(ndc.convertToEnglishDate(salesDate)); } catch (Exception e) { e.printStackTrace(); } detail.setBillAmount(totalSalesPriceFinal); detail.setAdvancePayment(advancePayment); detail.setSalesDateNp(formatNepaliDate(salesDate)); detail.setAccepted(false); detail.setVatAmount(vatAmount); detail.setTaxableAmount(taxableAmount); detail.setSubTotalAmount(totalSalesPrice); String paymentDate = null; if (selectedPaymentMode.equals(KeyConstants.PAYMENT_MODE_CREDIT)) { paymentDate = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); detail.setExpectedPaymentDateNp(paymentDate); detail.setExpectedPaymentDate(new NepaliDateConverter().convertToEnglishDate(paymentDate)); } salesTransactionBean.saveSalesEntry(detail, salesDtoList, remarks); JsfUtil.addSuccessMessage("Sales entry successfully saved."); redirectToSalesEntry(); salesHeaderIdForBillPrint = detail.getId(); } catch (ClientException c) { HelperUtil.showErrorMessage(c.getMessage()); } } public void saveItemIssueEntry() throws NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException { if (!validationItemIssueSubmit()) { return; } tx.begin(); issueHeader.setCreatedBy(getLoggedInUser().getId()); issueHeader.setCreatedDate(new Date()); issueHeader.setDelFlg(false); issueHeader.setOfficeId(getLoggedInOffice().getId()); try { issueHeader.setIssuedDate(ndc.convertToEnglishDate(salesDate)); } catch (Exception e) { e.printStackTrace(); } issueHeader.setIssuedDateNp(ndc.formatNepaliDate(salesDate)); iPurchaseDetailSession.persist(issueHeader); for (IItemIssueDetail se : issueDetailList) { // singleItemIssueJournalEntry(se, false); se.setIssueHeaderId(issueHeader.getId()); iPurchaseDetailSession.persist(se); IPurchaseDetail ip = se.getPurchaseDetailId(); ip.setAvailableQty(ip.getAvailableQty() - se.getQuantity()); iPurchaseDetailSession.merge(ip); IItemMaster it = itemMasterSession.findItemMaster(ip.getItemId().getId()); it.setAvailableQty(it.getAvailableQty() - se.getQuantity()); iPurchaseDetailSession.merge(it); if (ip.getParentId() != null) { IPurchaseDetail i = iPurchaseDetailSession.findIPurchaseDetail(ip.getParentId()); i.setAvailableQty(i.getAvailableQty() - se.getQuantity()); iPurchaseDetailSession.merge(i); it = itemMasterSession.findItemMaster(i.getItemId().getId()); it.setAvailableQty(it.getAvailableQty() - se.getQuantity()); iPurchaseDetailSession.merge(it); } } tx.commit(); JsfUtil.addSuccessMessage("Item issued successfully."); issueHeader = new IItemIssueHeader(); issueDetail = new IItemIssueDetail(); issueDetailList = new ArrayList<IItemIssueDetail>(); ipurchaseDetail = null; editRender = false; purchaseDetailDropDown = iPurchaseDetailSession.returnNativePurchaseDetail(getLoggedInOffice().getId()); itemNameConvertMethod(purchaseDetailDropDown); } public boolean validationSalesEntrySubmit() { System.out.println("greater then 0================ 0" + vatAmount); boolean pass = true; if (selectedSalesAccountType.equals("office")) { if (selectedOffice < 1) { JsfUtil.addErrorMessage("Please select office"); pass = false; } } else if (selectedSalesAccountType.equals("customer")) { if (purchaseAccMstrCustomerId < 1) { JsfUtil.addErrorMessage("Please select customer"); pass = false; } } if (vatAmount != null && vatAmount > 0) { MetaTable mt = appDataSession.returnMetaTableByMetaKey(KeyConstants.SALES_VAT, HelperUtil.getLoggedInOfficeID()); if (mt.getAccMasterId() == null) { JsfUtil.addErrorMessage( "Ledger for VAT is not setup, please set proper ledger for VAT in Settings > Parameters"); return true; } } if (discount != null && discount > 0) { MetaTable mt = appDataSession.returnMetaTableByMetaKey(KeyConstants.SALES_DISCOUNT, HelperUtil.getLoggedInOfficeID()); if (mt.getAccMasterId() == null) { JsfUtil.addErrorMessage( "Ledger for Discount is not setup, please set proper ledger for Discount in Settings > Parameters"); return true; } } if (billNo == null || billNo == 0) { JsfUtil.addErrorMessage("Please enter bill no."); pass = false; } PageNameEnum p = HelperUtil.getPageName(); System.out.println("validationSalesEntrySubmit> Helperutil pagename > " + p.getPageName()); int maxSalesBillNo = iSalesDetailSession.retrieveMaxSalesBillNo(getLoggedInOffice().getId()) + 1; if (p == PageNameEnum.SALESINVOICE) { if (billNo < maxSalesBillNo) { JsfUtil.addErrorMessage("Please enter bill no above " + iSalesDetailSession.retrieveMaxSalesBillNo(getLoggedInOffice().getId()) + "."); pass = false; } } else if (p == PageNameEnum.SALESINVOICEREPORT) { System.out.println(billNo + " " + selectedSalesHeader.getBillNo()); if (billNo < maxSalesBillNo && billNo.intValue() != selectedSalesHeader.getBillNo().intValue()) { JsfUtil.addErrorMessage("Please enter bill no above " + iSalesDetailSession.retrieveMaxSalesBillNo(getLoggedInOffice().getId()) + "."); pass = false; } } if (p == PageNameEnum.SALESINVOICE) { salesDate = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); } else if (p == PageNameEnum.SALESINVOICEREPORT) { salesDate = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate6"); } if (salesDate == null || salesDate.isEmpty()) { JsfUtil.addErrorMessage("Please Enter Transaction Date"); pass = false; } if (p == PageNameEnum.SALESINVOICE) { if (salesDtoList == null || salesDtoList.isEmpty()) { JsfUtil.addErrorMessage("No items found."); pass = false; } } return pass; } public boolean validationItemIssueSubmit() { boolean pass = true; if (issueHeader.getReqNo() == null || issueHeader.getReqNo().isEmpty()) { JsfUtil.addErrorMessage("Please enter ref no."); pass = false; } salesDate = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); if (salesDate == null || salesDate.isEmpty()) { JsfUtil.addErrorMessage("Please Enter Purchase Date"); pass = false; } else if (issueDetailList == null || issueDetailList.isEmpty()) { JsfUtil.addErrorMessage("No items found."); pass = false; } return pass; } public void displyAddressAndPan() { addressAndPan = new PersonalInfo(); // System.out.println("suppplier id is" + purchaseAccMstrCustomerId); addressAndPan = iPurchaseDetailSession.returnAddress(purchaseAccMstrCustomerId); } private void singleSalesJournalEntry(double amount, long accMaster, boolean reversed, String moduleType) { List<TransactionDTO> purTxnList = new ArrayList<TransactionDTO>(); boolean checkSuccess = false; System.out.println("amount " + amount); BasicAccountSetup b = basicAccountSetupSessionBean.findAccountBasicSetup("sales", getLoggedInOffice().getId()); System.out.println("-------------three---------------------"); TransactionDTO dt3 = new TransactionDTO(); dt3.setTxnAmount(amount); dt3.setDrCr((reversed ? "D" : "C")); dt3.setAccMasterId(b.getMainAccount()); dt3.setRemarks(remarks); purTxnList.add(dt3); System.out.println("------------four---------------------"); TransactionDTO dt4 = new TransactionDTO(); dt4.setTxnAmount(amount); dt4.setDrCr((reversed ? "C" : "D")); dt4.setAccMasterId(accMaster); dt4.setRemarks(remarks); purTxnList.add(dt4); try { long tranId = transactionSessionBean.addTransaction(purTxnList, moduleType, ndc.convertToEnglishDate(salesDate), null, HelperUtil.getLoggedInUser(), HelperUtil.getLoggedInOffice(), HelperUtil.getLoggedInFyId(), KeyConstants.TRANMODULE_SALESVOUCHER); if (tranId > 0) { checkSuccess = true; } } catch (ClientException e) { checkSuccess = false; } } private void salesDtoJournalEntry(SalesDTO sd, IPurchaseDetail ipurchaseDetail, boolean isReverse) { List<TransactionDTO> purTxnList = new ArrayList<TransactionDTO>(); boolean checkSuccess = false; System.out.println("-------------three---------------------"); TransactionDTO dt3 = new TransactionDTO(); dt3.setTxnAmount(sd.getQuantity() * sd.getSalesAmount()); dt3.setDrCr((isReverse ? "D" : "C")); dt3.setAccMasterId(ipurchaseDetail.getItemId().getAccMasterId().getId()); purTxnList.add(dt3); System.out.println("------------four---------------------"); TransactionDTO dt4 = new TransactionDTO(); dt4.setTxnAmount(sd.getQuantity() * sd.getSalesAmount()); dt4.setDrCr((isReverse ? "C" : "D")); dt4.setAccMasterId(selectedSalesHeader.getCustomerId().getId()); purTxnList.add(dt4); checkSuccess = addTransaction(purTxnList, ndc.convertToEnglishDate(salesDate), "", "", "sale"); } private void singleItemIssueJournalEntry(IItemIssueDetail sd, boolean isReverse) { List<TransactionDTO> purTxnList = new ArrayList<TransactionDTO>(); boolean checkSuccess = false; BasicAccountSetup b = basicAccountSetupSessionBean.findAccountBasicSetup("sales", getLoggedInOffice().getId()); if (sd.getPurchaseDetailId() != null) { System.out.println("-------------three---------------------"); TransactionDTO dt3 = new TransactionDTO(); dt3.setTxnAmount(sd.getQuantity() * sd.getPurchaseDetailId().getUnitPrice()); dt3.setDrCr((isReverse ? "D" : "C")); dt3.setAccMasterId(sd.getPurchaseDetailId().getItemId().getAccMasterId().getId()); dt3.setRemarks(issueEntryRemarks); purTxnList.add(dt3); System.out.println("------------four---------------------"); TransactionDTO dt4 = new TransactionDTO(); dt4.setTxnAmount(sd.getQuantity() * sd.getPurchaseDetailId().getUnitPrice()); dt4.setDrCr((isReverse ? "C" : "D")); dt4.setAccMasterId(b.getMainAccount()); dt4.setRemarks(issueEntryRemarks); purTxnList.add(dt4); } checkSuccess = addTransaction(purTxnList, ndc.convertToEnglishDate(salesDate), "", "", "sale"); } public boolean addTransaction(List<TransactionDTO> tranDTO, Date tranDate, String tranRemarks, String txnId, String moduleType) { /* * This method is called when transaction post button is clicked. * Max value of TransactionId is retrieved from txnDetail table. * Then one is added in this TransactionId which becomes the transctionId for this transction. * * We make two list : * 1)TxnDetail list:-here we add the txnDetail object if the DTO value if not null. * 2) AccMasterList:- here we add accMaster object which we retrieved by its id on TransactionDTO i.e. accMasterId. * * boolean checkfilled:- this is to check value is entered in data table or not. * When transactionDTO size is greeater than one, its value sets to true. * * boolean checkSum:- this is to check whether debitSum and creditSum are equal or not. * * boolean sumDebit:- Here the sum of debit amount is added till there is value in DTO list. * * boolean subCredit:- Here the sum of credit is added till the value is not null. * * int counter:- This is used to set the leg_no. * * * * */ boolean checkTxnSuccessful = false; System.out.println("printing size of combined dto list-----" + tranDTO.size()); Long tranId; List<TxnDetail> txnDetailList = new ArrayList<TxnDetail>(); List<AccMaster> accMasterList = new ArrayList<AccMaster>(); List<Double> accMasterBalace = new ArrayList<Double>(); TxnDetail txnDtl = null; this.drTotalGlobal = 0.0; this.crTotalGlobal = 0.0; boolean checkSum = false; boolean checkFilled = false; int counter = 1; tranId = txnDetailSession.retrieveMaxTranIds(getLoggedInOffice().getId(), fyTable.getId()); for (TransactionDTO dto : tranDTO) { txnDtl = new TxnDetail(); AccMaster acMaster = null; System.out.println( "for lopppp------acmstr and acmstrId" + dto.getAccMaster() + "---" + dto.getAccMasterId()); System.out.println("printing----first----" + tranDTO.get(0).getAccMaster() + "--" + tranDTO.get(0).getAccMasterId()); System.out.println("---------------chekcing drct and txnamt--------------" + dto.getDrCr() + "---" + dto.getTxnAmount()); if (dto.getDrCr() != null && dto.getTxnAmount() != 0.0) { if (dto.getAccMasterId() != null || dto.getAccMaster() != null) /* * This condition is satisfied if any dto value is not null. */ { checkFilled = true; if (dto.getAccMaster() == null) { System.out.println("accMaster--------accMaster==null"); acMaster = accMasterSession.retrieveAccMasterById(dto.getAccMasterId()); } if (dto.getAccMaster() != null) { // System.out.println("accMastrid<0----"); acMaster = dto.getAccMaster(); } // for (AccNatureEnum em : AccNatureEnum.values()) { // /* // * Here, accMaster's nature id is checked and if id matches with AccNatureEnum, then its status is retrieved. // * This status determines whether account is to be added or subtracted for dr or cr. // */ // // // System.out.println("------************----id and drcr-----*************-------"+acMaster.getGlSubheadId().getGlId().getNatureId().getId()+"-----"+dto.getDrCr()); // if (acMaster.getGlSubheadId().getGlId().getNatureId().getId() == em.getId() && em.getDrCr().toString().equals(dto.getDrCr())) { // String status = em.getStatus(); // // // System.out.println("||||||||---0000000000000000---printing stauts----000000000000000----|||||||||---"+em); // if ("add".equals(status)) { // accMasterBalace.add(dto.getTxnAmount()); // } else if ("sub".equals(status)) { // System.out.println("-------------C----------"); // double negBal = dto.getTxnAmount() * (-1); // accMasterBalace.add(negBal); // } // // break; // } // } if ("D".equals(dto.getDrCr())) { /* * If debit is selected in radio box,sumdebit is added. */ System.out.println("-----D-----------"); this.drTotalGlobal += dto.getTxnAmount(); accMasterBalace.add(dto.getTxnAmount()); } if ("C".equals(dto.getDrCr())) { /* * If credit is selected in radio box,sumcredit is added. */ System.out.println("-------------C----------"); this.crTotalGlobal += dto.getTxnAmount(); accMasterBalace.add(dto.getTxnAmount() * (-1)); } // System.out.println("-----dr----cr----" + this.drTotalGlobal + " , " + this.crTotalGlobal); if (this.drTotalGlobal == this.crTotalGlobal) { /* * This condition is satisfied when debitsum and creditsum are equal. */ checkSum = true; } else { checkSum = false; } NepaliDateConverter ndc = new NepaliDateConverter(); FyTable fyTable = fyTableSessionBean.currentFyTable(getLoggedInOffice().getId()); Date startDateFiscDate = ndc.convertToEnglishDate(fyTable.getStartDate()); Date endDateFiscDate = ndc.convertToEnglishDate(fyTable.getEndDate()); /* * Now setting values to txnDetail object. */ txnDtl.setTxnRemarks(tranRemarks); txnDtl.setTxnDate(tranDate); txnDtl.setDrCr(dto.getDrCr().charAt(0)); txnDtl.setTxnAmt(dto.getTxnAmount()); txnDtl.setTranId(tranId); txnDtl.setDeleted(false); txnDtl.setAccId(acMaster); txnDtl.setGlSubheadId(acMaster.getGlSubheadId()); txnDtl.setLegNo(counter); txnDtl.setTranId(tranId); txnDtl.setFyId(fyTable); txnDtl.setTransactionDateNepali(ndc.convertToNepaliDate(tranDate)); txnDtl.setModuleType(moduleType); txnDtl.setEnteredBy(getLoggedInUser()); txnDtl.setRefNo(String.valueOf(billNo)); txnDtl.setReversalFlag(false); txnDtl.setIsReversed(false); txnDtl.setOfficeId(getLoggedInOffice()); if (dto.getRemarks() != null) { if (!"".equals(dto.getRemarks())) { txnDtl.setTxnRemarks(dto.getRemarks()); } } /* * Now adding txnDetail object ot txnDetailList and accMaster object to accMasterList. */ txnDetailList.add(txnDtl); accMasterList.add(acMaster); } counter++; } } if (checkFilled == false) { /* * When all the rows of datatable are null. */ // System.out.println("please enter required fields----------------"); showFacesMsg(FacesMessage.SEVERITY_ERROR, "Please fill the transaction.", ""); checkTxnSuccessful = false; } else { /* * When the values are inserted in datatable. */ System.out.println( "------printing drsum and crsum----" + this.drTotalGlobal + "---" + this.crTotalGlobal); if (checkSum) { /* * This condition is executed when the debitsum and creditsum are equal. */ System.out.println("====txnDetailList------" + txnDetailList.size()); // try // { // /* // * Here, transaction is done. // * We use UserTransaction tx. // * // * First tx is started by tx.begin(). // * If there is no error in updateToDBAccMaster() and addToDBTxnDetail() methods. // * Transaction is commited. // * else // * whole transaction is rolled back. // */ // tx.begin(); System.out.println("tx.begin---txn" + tx); for (TxnDetail dtl : txnDetailList) { // System.out.println("-----addding tran---------------"); txnDetailSession.addTxnDetail(dtl); } // System.out.println("-----accmaster list updating"); // System.out.println("-----sizessssssssssssss------acmlist and acmBalList-----" + accMasterList.size() + " , " + accMasterBalace.size()); if (accMasterList.size() > 0 && accMasterBalace.size() > 0) { if (accMasterList.size() == accMasterBalace.size()) { for (int i = 0; i < accMasterList.size(); i++) { // System.out.println("printing accMaster id-----" + accMasterList.get(i).getId()); accMasterSession.editAndUpdateAccMaster(Long.valueOf(accMasterList.get(i).getId()), accMasterBalace.get(i)); } } } //updateToDBAccMaster(accMasterList, accMasterBalace); //addToDBTxnDetail(txnDetailList); System.out.println("before commiting--------"); // tx.commit(); checkTxnSuccessful = true; // } // catch(Exception e) // { // System.out.println("----catch----"); // try { // System.out.println("-----rollback----"); // tx.rollback(); // } catch (IllegalStateException ex) { // Logger.getLogger(TransactionMBean.class.getName()).log(Level.SEVERE, null, ex); // } catch (SecurityException ex) { // Logger.getLogger(TransactionMBean.class.getName()).log(Level.SEVERE, null, ex); // } catch (SystemException ex) { // Logger.getLogger(TransactionMBean.class.getName()).log(Level.SEVERE, null, ex); //// } // } // } // this.setTranDTOList(null); // this.journalEntryRemarks=""; // initialize(); // this.drTotal=0; // this.crTotal=0; } else { checkTxnSuccessful = false; showFacesMsg(FacesMessage.SEVERITY_ERROR, "Transaction Error.", "Please check transaction."); // txnDetailList=null; // accMasterList=null; // accMasterBalace=null; // txnDtl=null; } } return checkTxnSuccessful; } @EJB private TxnDetailSession txnDetailSession; @EJB private FyTableSessionBean fyTableSessionBean; private double drTotalGlobal, crTotalGlobal; public void editSalesDto2(SalesDTO sa) { ipurchaseDetail = sa.getPurchaseDetail(); itemNameConvertMethod(ipurchaseDetail); salesDTO.setSalesAmount(sa.getSalesAmount()); salesDTO.setQuantity(sa.getQuantity()); editRender = true; // salesDtoList.remove(sa); // totalSalesPrice = 0; // for (SalesDTO s : salesDtoList) { // totalSalesPrice += (s.getSalesAmount() * s.getQuantity()); // } // ajaxTotalCalculation(); } public void editItemIssue(IItemIssueDetail sa) { ipurchaseDetail = sa.getPurchaseDetailId(); issueDetail.setQuantity(sa.getQuantity()); editRender = true; } public void removeFromItemIssued(IItemIssueDetail is) { is.setDelFlg(true); iPurchaseDetailSession.merge(is); singleItemIssueJournalEntry(is, true); is.getPurchaseDetailId().setAvailableQty(is.getPurchaseDetailId().getAvailableQty() + is.getQuantity()); iPurchaseDetailSession.merge(is.getPurchaseDetailId()); is.getPurchaseDetailId().getItemId() .setAvailableQty(is.getPurchaseDetailId().getItemId().getAvailableQty() + is.getQuantity()); is.getPurchaseDetailId().getItemId().getAccMasterId() .setVersion(is.getPurchaseDetailId().getItemId().getAccMasterId().getVersion() + 1); iPurchaseDetailSession.merge(is.getPurchaseDetailId().getItemId()); if (is.getPurchaseDetailId().getParentId() != null) { IPurchaseDetail i = iPurchaseDetailSession.findIPurchaseDetail(is.getPurchaseDetailId().getParentId()); i.setAvailableQty(i.getAvailableQty() + is.getQuantity()); iPurchaseDetailSession.merge(i); i.getItemId().setAvailableQty(i.getItemId().getAvailableQty() + is.getQuantity()); i.getItemId().getAccMasterId().setVersion(i.getItemId().getAccMasterId().getVersion() + 1); iPurchaseDetailSession.merge(i.getItemId()); } issueDetailList.remove(is); for (IPurchaseDetail p : purchaseDetailDropDown) { if (p.getId().equals(is.getPurchaseDetailId().getId())) { p.setAvailableQty(p.getAvailableQty() + is.getQuantity()); itemNameConvertSalesReport(p); } } JsfUtil.addSuccessMessage("Item successfully removed."); } public void editItemIssued(IItemIssueHeader ih) { issueHeader = ih; issueDetail = new IItemIssueDetail(); issueDetailList = iSalesDetailSession.returnItemIssueDetailByHeader(ih.getId()); ipurchaseDetail = null; stage = 3; editRender = false; } // public void editSalesDto(SalesDTO s) { // salesDTO = s; // purchaseDetailTableListByItemId = s.getPurchaseDetailsList(); // selectedItemId = s.getPurchaseDetail().getItemId().getId(); // ipurchaseDetail = s.getPurchaseDetail(); // ipurchaseDetail.setAvailableQtyTemp(null); //// for (Iterator<IPurchaseDetail> iterator = purchaseListToCheckAvailableQty.iterator(); iterator.hasNext();) { //// IPurchaseDetail m = iterator.next(); //// if (m.getId().equals(ipurchaseDetail.getId())) { //// iterator.remove(); //// break; //// } //// } // salesDtoList.remove(s); // editRender = true; // mainEditRender = false; // } public void removeSalesDto(SalesDTO s) { s.setDelFlg(true); List<SalesDTO> temp = new ArrayList<SalesDTO>(salesDtoList); salesDtoList = new ArrayList<SalesDTO>(); for (SalesDTO sd : temp) { if (!sd.isDelFlg()) { salesDtoList.add(sd); } } for (IPurchaseDetail ip : purchaseDetailDropDown) { if (ip.getId().equals(s.getPurchaseDetail().getId())) { ip.setAvailableQtyTemp(null); itemNameConvertMethod(ip); break; } } initialize(); } public void removeItemIssue(IItemIssueDetail s) { s.setDelFlg(true); List<IItemIssueDetail> temp = new ArrayList<IItemIssueDetail>(issueDetailList); issueDetailList = new ArrayList<IItemIssueDetail>(); for (IItemIssueDetail sd : temp) { if (!sd.getDelFlg()) { issueDetailList.add(sd); } } for (IPurchaseDetail ip : purchaseDetailDropDown) { if (ip.getId().equals(s.getPurchaseDetailId().getId())) { ip.setAvailableQtyTemp(null); itemNameConvertMethod(ip); break; } } ipurchaseDetail = null; issueDetail = new IItemIssueDetail(); editRender = false; } public void insertPurchaseEntry() { try { SalesHeaderDetail sh = new SalesHeaderDetail(); sh.setBillNo(billNo); sh.setBillAmount(totalSalesPrice); sh.setDelFlg(false); sh.setOfficeId(getLoggedInOffice()); sh.setEnteredBy(getLoggedInUser().getId()); sh.setEnteredDate(new Date()); SalesHeaderDetail addSalesHeaderDetail = iSalesDetailSession.addSalesHeaderDetail(sh); for (SalesDTO s : salesDtoList) { ISalesDetail iSalesDetail = new ISalesDetail(); IPurchaseDetail ipd = new IPurchaseDetail(); ipd = iSalesDetailSession.retrievePurchaseDetailByid(s.getPurchaseDetailId()); } } catch (Exception e) { System.out.println("----catch----"); try { System.out.println("-----rollback----"); tx.rollback(); } catch (IllegalStateException ex) { Logger.getLogger(InventorySalesMBean.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(InventorySalesMBean.class.getName()).log(Level.SEVERE, null, ex); } catch (SystemException ex) { Logger.getLogger(InventorySalesMBean.class.getName()).log(Level.SEVERE, null, ex); // } } } } public SalesHeaderDetail addSalesHeaderDetail() { SalesHeaderDetail sh = new SalesHeaderDetail(); sh.setBillNo(billNo); sh.setBillAmount(totalSalesPrice); sh.setDelFlg(false); sh.setOfficeId(getLoggedInOffice()); sh.setEnteredBy(getLoggedInUser().getId()); sh.setEnteredDate(new Date()); SalesHeaderDetail addSalesHeaderDetail = iSalesDetailSession.addSalesHeaderDetail(sh); return addSalesHeaderDetail; } public void handleKeyEvent() { issueEntryRemarks = ""; issueEntryRemarks = "Issue Req No. " + issueHeader.getReqNo(); } public void simplePostProcessXLS(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0); int noOfColumns = sheet.getRow(0).getLastCellNum(); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 5); HSSFRow firstRow = sheet.createRow(0); firstRow.createCell(0).setCellValue("SALES ANALYSIS REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(1); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(2); String date = ndc.convertToNepaliDate(new Date()); thirdRow.createCell(0).setCellValue("Generated on:" + date + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow fourthRow = sheet.createRow(3); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow fifthRow = sheet.createRow(4); fifthRow.createCell(0).setCellValue("Customer name "); fifthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(4, 4, 0, 7)); } public void handleKeyEventSalesEntry() { remarks = "Sales Bill No. " + billNo; } /* Getters and Setters */ public Integer getBillNo() { return billNo; } public void setBillNo(Integer billNo) { this.billNo = billNo; } public List<SalesDTO> getSalesDtoList() { return salesDtoList; } public void setSalesDtoList(List<SalesDTO> salesDtoList) { this.salesDtoList = salesDtoList; } public User getLoggedInUser() { User u = (User) Util.getSession().getAttribute("user"); return u; } public Office getLoggedInOffice() { Office o = (Office) Util.getSession().getAttribute("office"); return o; } public List<IItemMaster> getItemMasterList() { return itemMasterList; } public void setItemMasterList(List<IItemMaster> itemMasterList) { this.itemMasterList = itemMasterList; } public SalesDTO getSalesDTO() { return salesDTO; } public void setSalesDTO(SalesDTO salesDTO) { this.salesDTO = salesDTO; } public IPurchaseDetail getIpurchaseDetail() { return ipurchaseDetail; } public void setIpurchaseDetail(IPurchaseDetail ipurchaseDetail) { this.ipurchaseDetail = ipurchaseDetail; } // public List<IPurchaseDetail> getPurchaseListToCheckAvailableQty() { // return purchaseListToCheckAvailableQty; // } // // public void setPurchaseListToCheckAvailableQty(List<IPurchaseDetail> purchaseListToCheckAvailableQty) { // this.purchaseListToCheckAvailableQty = purchaseListToCheckAvailableQty; // } public Double getTotalSalesPrice() { return totalSalesPrice; } public void setTotalSalesPrice(Double totalSalesPrice) { this.totalSalesPrice = totalSalesPrice; } public ISalesDetailSession getiSalesDetailSession() { return iSalesDetailSession; } public void setiSalesDetailSession(ISalesDetailSession iSalesDetailSession) { this.iSalesDetailSession = iSalesDetailSession; } public IPurchaseDetailSession getiPurchaseDetailSession() { return iPurchaseDetailSession; } public void setiPurchaseDetailSession(IPurchaseDetailSession iPurchaseDetailSession) { this.iPurchaseDetailSession = iPurchaseDetailSession; } public ItemMasterSession getItemMasterSession() { return itemMasterSession; } public void setItemMasterSession(ItemMasterSession itemMasterSession) { this.itemMasterSession = itemMasterSession; } public UserTransaction getTx() { return tx; } public void setTx(UserTransaction tx) { this.tx = tx; } public double getActualQtySum() { return actualQtySum; } public void setActualQtySum(double actualQtySum) { this.actualQtySum = actualQtySum; } public List<ISalesDetail> getIsalesDetailsList() { return isalesDetailsList; } public void setIsalesDetailsList(List<ISalesDetail> isalesDetailsList) { this.isalesDetailsList = isalesDetailsList; } public Date getBeforeDate() { return beforeDate; } public void setBeforeDate(Date beforeDate) { this.beforeDate = beforeDate; } public long getPurchaseAccMstrCustomerId() { return purchaseAccMstrCustomerId; } public void setPurchaseAccMstrCustomerId(long purchaseAccMstrCustomerId) { this.purchaseAccMstrCustomerId = purchaseAccMstrCustomerId; } public String getPreviousDate() { String previousDate = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); if (previousDate == null || previousDate.isEmpty()) { previousDate = ndc.convertToNepaliDate(new Date()); } return previousDate; } public String getCurrentDate() { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); if (startDateString != null && !startDateString.isEmpty()) { currentDate = startDateString; } return currentDate; } public String getSoldDate() { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate6"); if (startDateString != null && !startDateString.isEmpty()) { soldDate = startDateString; } return soldDate; } public void setSoldDate(String soldDate) { this.soldDate = soldDate; } public String getPaymentDate() { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate7"); if (startDateString != null && !startDateString.isEmpty()) { paymentDate = startDateString; } return paymentDate; } public void setPaymentDate(String paymentDate) { this.paymentDate = paymentDate; } public double getSumOfnetSalesAmount() { return sumOfnetSalesAmount; } public void setSumOfnetSalesAmount(double sumOfnetSalesAmount) { this.sumOfnetSalesAmount = sumOfnetSalesAmount; } public AccMasterSession getAccMasterSession() { return accMasterSession; } public void setAccMasterSession(AccMasterSession accMasterSession) { this.accMasterSession = accMasterSession; } public String getProductReturnReasonsString() { return productReturnReasonsString; } public void setProductReturnReasonsString(String productReturnReasonsString) { this.productReturnReasonsString = productReturnReasonsString; } public NepaliDateConverter getNdc() { return ndc; } public void setNdc(NepaliDateConverter ndc) { this.ndc = ndc; } public void showFacesMsg(FacesMessage.Severity severType, String first, String second) { FacesMessage msg = new FacesMessage(severType, first, second); FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, msg); } public String getSalesDate() { return salesDate; } public void setSalesDate(String salesDate) { this.salesDate = salesDate; } public Date getStartDate() { return startDate; } public void setStartDate(Date startDate) { this.startDate = startDate; } public Date getEndDate() { return endDate; } public void setEndDate(Date endDate) { this.endDate = endDate; } public boolean isSalesBetnDateRendered() { return salesBetnDateRendered; } public void setSalesBetnDateRendered(boolean salesBetnDateRendered) { this.salesBetnDateRendered = salesBetnDateRendered; } public List<Object[]> getSalesHeaderListt() { return salesHeaderListt; } public void setSalesHeaderListt(List<Object[]> salesHeaderListt) { this.salesHeaderListt = salesHeaderListt; } public String getFromDate() { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); if (startDateString != null && !startDateString.isEmpty()) { fromDate = startDateString; } return fromDate; } public void setFromDate(String fromDate) { this.fromDate = fromDate; } public String getToDate() { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); if (startDateString != null && !startDateString.isEmpty()) { toDate = startDateString; } return toDate; } public void setToDate(String toDate) { this.toDate = toDate; } public double getTotalAmountBeforevat() { return totalAmountBeforevat; } public void setTotalAmountBeforevat(double totalAmountBeforevat) { this.totalAmountBeforevat = totalAmountBeforevat; } public SalesHeaderDetail getSelectedSalesHeader() { return selectedSalesHeader; } public void setSelectedSalesHeader(SalesHeaderDetail selectedSalesHeader) { this.selectedSalesHeader = selectedSalesHeader; } public boolean isEditRender() { return editRender; } public void setEditRender(boolean editRender) { this.editRender = editRender; } public ISalesDetail getSelectedISalesDetail() { return selectedISalesDetail; } public void setSelectedISalesDetail(ISalesDetail selectedISalesDetail) { this.selectedISalesDetail = selectedISalesDetail; } public List<AccMaster> getPurchaseAccMstrSuppList() { return purchaseAccMstrSuppList; } public void setPurchaseAccMstrSuppList(List<AccMaster> purchaseAccMstrSuppList) { this.purchaseAccMstrSuppList = purchaseAccMstrSuppList; } public int getStage() { return stage; } public void setStage(int stage) { this.stage = stage; } public List<AccMaster> getSellerAccMstrList() { return accMasterSession.retrieveAccMasterByOwner(getLoggedInOffice().getId(), KeyConstants.OWNERCUSTOMER); } public void setSellerAccMstrList(List<AccMaster> sellerAccMstrList) { this.sellerAccMstrList = sellerAccMstrList; } public List<IPurchaseDetail> getPurchaseDetailDropDown() { return purchaseDetailDropDown; } public void setPurchaseDetailDropDown(List<IPurchaseDetail> purchaseDetailDropDown) { this.purchaseDetailDropDown = purchaseDetailDropDown; } public PersonalInfo getPersonalInfo() { return personalInfo; } public void setPersonalInfo(PersonalInfo personalInfo) { this.personalInfo = personalInfo; } public Double getDiscount() { return discount; } public void setDiscount(Double discount) { this.discount = discount; } public Double getVatPercentage() { return vatPercentage; } public void setVatPercentage(Double vatPercentage) { this.vatPercentage = vatPercentage; } public Double getVatAmount() { return vatAmount; } public void setVatAmount(Double vatAmount) { this.vatAmount = vatAmount; } public Double getTotalSalesPriceFinal() { return totalSalesPriceFinal; } public void setTotalSalesPriceFinal(Double totalSalesPriceFinal) { this.totalSalesPriceFinal = totalSalesPriceFinal; } public String getSalesModeOfReceipt() { return salesModeOfReceipt; } public void setSalesModeOfReceipt(String salesModeOfReceipt) { this.salesModeOfReceipt = salesModeOfReceipt; } public Double getAdvancePayment() { return advancePayment; } public void setAdvancePayment(Double advancePayment) { this.advancePayment = advancePayment; } public Double getTaxableAmount() { return taxableAmount; } public void setTaxableAmount(Double taxableAmount) { this.taxableAmount = taxableAmount; } public IItemIssueHeader getIssueHeader() { return issueHeader; } public void setIssueHeader(IItemIssueHeader issueHeader) { this.issueHeader = issueHeader; } public IItemIssueDetail getIssueDetail() { return issueDetail; } public void setIssueDetail(IItemIssueDetail issueDetail) { this.issueDetail = issueDetail; } public List<IItemIssueDetail> getIssueDetailList() { return issueDetailList; } public void setIssueDetailList(List<IItemIssueDetail> issueDetailList) { this.issueDetailList = issueDetailList; } public List<IItemIssueHeader> getIssueHeadersList() { return issueHeadersList; } public void setIssueHeadersList(List<IItemIssueHeader> issueHeadersList) { this.issueHeadersList = issueHeadersList; } public List<Office> getOtherOfficeList() { if (otherOfficeList.isEmpty()) { otherOfficeList = officeSession.allOtherOfficeList(getLoggedInOffice().getId()); } return otherOfficeList; } public void setOtherOfficeList(List<Office> otherOfficeList) { this.otherOfficeList = otherOfficeList; } public int getSelectedOffice() { return selectedOffice; } public void setSelectedOffice(int selectedOffice) { this.selectedOffice = selectedOffice; } public String getSelectedSalesAccountType() { return selectedSalesAccountType; } public void setSelectedSalesAccountType(String selectedSalesAccountType) { this.selectedSalesAccountType = selectedSalesAccountType; } public String getSelectedPaymentMode() { return selectedPaymentMode; } public void setSelectedPaymentMode(String selectedPaymentMode) { this.selectedPaymentMode = selectedPaymentMode; } public boolean isPaymentModeNonCash() { return paymentModeNonCash; } public void setPaymentModeNonCash(boolean paymentModeNonCash) { this.paymentModeNonCash = paymentModeNonCash; } public String getIssueEntryRemarks() { return issueEntryRemarks; } public void setIssueEntryRemarks(String issueEntryRemarks) { this.issueEntryRemarks = issueEntryRemarks; } public String getSalesEntryRemarks() { return remarks; } public void setSalesEntryRemarks(String salesEntryRemarks) { this.remarks = salesEntryRemarks; } public List<AppData> getProductReturnReasons() { return productReturnReasons; } public void setProductReturnReasons(List<AppData> productReturnReasons) { this.productReturnReasons = productReturnReasons; } public List<IInventoryReturnHeader> getReturnHeadersList() { return returnHeadersList; } public void setReturnHeadersList(List<IInventoryReturnHeader> returnHeadersList) { this.returnHeadersList = returnHeadersList; } public List<IInventoryReturnDetail> getReturnDetailsList() { return returnDetailsList; } public void setReturnDetailsList(List<IInventoryReturnDetail> returnDetailsList) { this.returnDetailsList = returnDetailsList; } public IInventoryReturnHeader getSelectedInventoryReturnHeader() { return selectedInventoryReturnHeader; } public void setSelectedInventoryReturnHeader(IInventoryReturnHeader selectedInventoryReturnHeader) { this.selectedInventoryReturnHeader = selectedInventoryReturnHeader; } public double getTotalBillAmount() { return totalBillAmount; } public void setTotalBillAmount(double totalBillAmount) { this.totalBillAmount = totalBillAmount; } public Double getTotalQuantityCount() { return totalQuantityCount; } public void setTotalQuantityCount(Double totalQuantityCount) { this.totalQuantityCount = totalQuantityCount; } public PageNameEnum getPageName() { return (PageNameEnum) Util.getSession().getAttribute("pageName"); } public JasperReportBean getJasperReportBean() { return jasperReportBean; } public void setJasperReportBean(JasperReportBean jasperReportBean) { this.jasperReportBean = jasperReportBean; } public long getSalesHeaderIdForBillPrint() { return salesHeaderIdForBillPrint; } public void setSalesHeaderIdForBillPrint(long salesHeaderIdForBillPrint) { this.salesHeaderIdForBillPrint = salesHeaderIdForBillPrint; } public List<SalesHeaderDetail> getSalesHeaderList() { return salesHeaderList; } public void setSalesHeaderList(List<SalesHeaderDetail> salesHeaderList) { this.salesHeaderList = salesHeaderList; } public double getTotalVatAmount() { return totalVatAmount; } public void setTotalVatAmount(double totalVatAmount) { this.totalVatAmount = totalVatAmount; } public double getTotalDiscountAmount() { return totalDiscountAmount; } public void setTotalDiscountAmount(double totalDiscountAmount) { this.totalDiscountAmount = totalDiscountAmount; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getPanNo() { return panNo; } public void setPanNo(String panNo) { this.panNo = panNo; } public long getIrHeaderIdForPrint() { return irHeaderIdForPrint; } public void setIrHeaderIdForPrint(long irHeaderIdForPrint) { this.irHeaderIdForPrint = irHeaderIdForPrint; } public String getFilterString() { return filterString; } public void setFilterString(String filterString) { this.filterString = filterString; } public LazyDataModel getSalesListSummaryLazy() { return salesListSummaryLazy; } public void setSalesListSummaryLazy(LazyDataModel salesListSummaryLazy) { this.salesListSummaryLazy = salesListSummaryLazy; } public IInventoryReturnHeader getReturnHeader() { return returnHeader; } public void setReturnHeader(IInventoryReturnHeader returnHeader) { this.returnHeader = returnHeader; } public Double getTotalReturnAmount() { return totalReturnAmount; } public void setTotalReturnAmount(Double totalReturnAmount) { this.totalReturnAmount = totalReturnAmount; } public PersonalInfo getAddressAndPan() { return addressAndPan; } public void setAddressAndPan(PersonalInfo addressAndPan) { this.addressAndPan = addressAndPan; } }