NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.nomin.portal.web.controller.vendor;

import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.commons.io.FilenameUtils;
import org.primefaces.PrimeFaces;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.event.data.FilterEvent;
import org.primefaces.model.UploadedFile;

import com.google.common.primitives.Longs;
import com.nomin.core.utils.Messages;
import com.nomin.portal.web.controller.LoginController;
import com.nomin.portal.web.controller.ReportController;

import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import nomin.core.utils.BigDecimals;
import nomin.core.utils.Dates;
import nomin.core.utils.Lists;
import nomin.core.utils.Tools;
import nomin.core.web.controller.SuperController;
import nomin.portal.businessentity.cash.CalculationPayment;
import nomin.portal.businessentity.vendor.CalculationActDtl;
import nomin.portal.businesslogic.interfaces.IPortalUserLogicLocal;
import nomin.portal.businesslogic.interfaces.IRefundLogicLocal;
import nomin.portal.businesslogic.interfaces.IVendorLogicLocal;
import nomin.portal.entity.portaluser.CustomerInfo;
import nomin.portal.entity.portaluser.PortalUser;
import nomin.portal.entity.vendor.BillCustomer;
import nomin.portal.entity.vendor.BillCustomerDivision;
import nomin.portal.entity.vendor.BillCustomerDtl;
import nomin.portal.entity.vendor.BillCustomerFile;
import nomin.portal.entity.vendor.BillCustomerState;
import nomin.portal.model.login.LoginInfo;

@Named(value = "billController")
@SessionScoped
public class BillController extends SuperController implements Serializable {

private static final long serialVersionUID = 1L;

@Inject
private IVendorLogicLocal vendorLogic;

@Inject
private LoginController loginController;

@Inject
private ReportController reportController;

@Inject
VendorController vendorController;

@Inject
IPortalUserLogicLocal portalUserLogic;

@Inject
IRefundLogicLocal refundLogic;

@Inject
DataPool pool;

private List<BillCustomerDtl> listBillCustomerDtl;
private List<BillCustomerDtl> filteredListBillCustomerDtl;
private BillCustomer billCustomer;
private List<BillCustomerFile> fileList;
private List<CalculationPayment> listPayment;

private String currencyId;
private String accountName;

public HashMap<String, Object> params() {
return pool.getParams();
}

public void showDataAkt() {
BigDecimal sumCloseAmountAkt = (BigDecimal) params().get("sumCloseAmountAkt");
if (BigDecimals.convertNullToZero(sumCloseAmountAkt).equals(BigDecimal.ZERO)) {
Messages.showWarningMessage("Мэдээлэл байхгүй байна.");
return;
}
try {

billCustomer = vendorLogic.getBillCustomer(loginController.getLoginInfo().getCustomerKey());

params().put("scheduleDateParameter", "");
params().put("itemBillInRef", null);
params().put("beginDateAct", null);
params().put("endDateAct", null);
params().put("invRefAkt", null);
params().put("userNameAkt", null);
params().put("billReceiveName", null);
params().put("billBonusCardNumber", null);
params().put("billCurrencyId", null);
params().put("noteAkt", null);
params().put("invDescriptionAkt", null);
params().put("payedRcvAmountAkt", BigDecimal.ZERO);
params().put("payedAmountAkt", BigDecimal.ZERO);
params().put("bonusAmountAkt", BigDecimal.ZERO);

params().put("itemBarCodeCountParameter", BigDecimal.ZERO);
params().put("sumSaleAmountParameter", BigDecimal.ZERO);
params().put("vendorRefundCount", BigDecimal.ZERO);
params().put("vendorNotificationCount", BigDecimal.ZERO);
params().put("billCustomerStatusValue", null);

if (params().get("sumCloseAmountAkt") == null)
params().put("sumCloseAmountAkt", BigDecimal.ZERO);

if (billCustomer == null)
return;
fileList = vendorLogic.getCalculationAktAttachments(billCustomer.getpKey());

vendorController.setBeginDatePayable(billCustomer.getBeginDate());
vendorController.setEndDatePayable(billCustomer.getEndDate());

pool.changedValuesRendered("showBillCustomer");
listBillCustomerDtl = vendorLogic.showDataAkt(loginController.getLoginInfo().getCustomerKey(), pool.getIsRenter());
if (listBillCustomerDtl != null && listBillCustomerDtl.size() > 0 && listBillCustomerDtl.get(0) != null) {
BigDecimal sumCloseAmount = listBillCustomerDtl.stream().filter(f -> f.getCloseAmount() != null)
.map(a -> a.getCloseAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
BillCustomerDtl billCustomerDtl = listBillCustomerDtl.get(0);

params().put("scheduleDateParameter", billCustomerDtl.getScheduleDate());
params().put("beginDateAct", billCustomerDtl.getBeginDate());
params().put("endDateAct", billCustomerDtl.getEndDate());
params().put("invRefAkt", billCustomerDtl.getInvRef());
params().put("userNameAkt", billCustomerDtl.getUserName());
params().put("payedRcvAmountAkt", billCustomerDtl.getPayedRcvAmount());
params().put("payedAmountAkt", billCustomerDtl.getPayedAmount());
params().put("invDescriptionAkt", billCustomerDtl.getInvDescription());
params().put("noteAkt", billCustomerDtl.getNote());
params().put("sumCloseAmountAkt", sumCloseAmount);
params().put("bonusAmountAkt", billCustomerDtl.getBonusAmount());

params().put("itemBarCodeCountParameter", listBillCustomerDtl.size());
params().put("sumSaleAmountParameter",
listBillCustomerDtl.stream().filter(b -> b.getSaleAmount() != null).map(s -> s.getSaleAmount())
.reduce(BigDecimal.ZERO, BigDecimal::add));
params().put("hdrKey", billCustomerDtl.getHdrKey());
params().put("billCustomerCreatedName", billCustomerDtl.getUserName());
Long billCustomerStatus = vendorLogic.getBillCustomerState(billCustomerDtl.getHdrKey(), 1);
if (billCustomerStatus != null) {
params().put("billCustomerStatus", billCustomerStatus);
} else {
billCustomerStatus = vendorLogic.getBillCustomerState(billCustomerDtl.getHdrKey(), 0);
if (billCustomerStatus != null) {
params().put("billCustomerStatus", billCustomerStatus);
params().put("billCustomerStatusValue", "Y");
}
}

calculateBillCustomerFooter(listBillCustomerDtl);
}
listPayment = vendorLogic.getCustomerPayment(billCustomer.getpKey());
if(!Lists.isNullOrEmpty(listPayment)) {
params().put("sumCloseAmountAkt", listPayment.stream().filter(f -> f.getCloseAmount() != null)
.map(a -> a.getCloseAmount()).reduce(BigDecimal.ZERO, BigDecimal::add));
params().put("payedRcvAmountAkt", listPayment.stream().filter(f -> f.getReceivableAmount() != null)
.map(a -> a.getReceivableAmount()).reduce(BigDecimal.ZERO, BigDecimal::add));
params().put("payedAmountAkt", listPayment.stream().filter(f -> f.getPaidAmount() != null)
.map(a -> a.getPaidAmount()).reduce(BigDecimal.ZERO, BigDecimal::add));
params().put("bonusAmountAkt", listPayment.stream().filter(f -> f.getBonusAmount() != null)
.map(a -> a.getBonusAmount()).reduce(BigDecimal.ZERO, BigDecimal::add));
}
calculateEndBalance();
CustomerInfo info = vendorLogic.showBankAndAccount(loginController.getLoginInfo().getCustomerKey());
params().put("billBankName", billCustomer.getBankName());
params().put("billAccountId", billCustomer.getBankAccountId());
params().put("billReceiveName", info.getReceiveName());
params().put("billBonusCardNumber", billCustomer.getBonusCardNumber());
// params().put("billCurrencyId", info.getCurrencyId());
params().put("isCitizen", info.getIsCitizen());
} catch (Exception ex) {
ex.printStackTrace();
}
}

public void downloadReceipt() {
try {
List<BillCustomerDivision> listCompany = vendorLogic.getCompanyAmounts(billCustomer.getpKey());
Map<String, Object> params = new HashMap<String, Object>();
for (BillCustomerDivision tmp : listCompany) {
params.put(String.format("%sAmount", tmp.getDbName().toLowerCase()), tmp.getPaidAmount() == null ? BigDecimal.ZERO : tmp.getPaidAmount());
params.put(String.format("%sName", tmp.getDbName().toLowerCase()), tmp.getCompanyName());
params.put(String.format("%sTug", tmp.getDbName().toLowerCase()), tmp.getPaidAmount() == null ? "" : Tools.currencyToLetter(tmp.getPaidAmount()));
}
params.put("customerName", billCustomer.getCustomerName());
params.put("bankName", billCustomer.getBankName());
params.put("accountId", billCustomer.getBankAccountId());
params.put("registerNo", billCustomer.getCustomerReg());
params.put("bonusPercent", billCustomer.getBonusPercent());
params.put("receiptDate", Dates.convertDateToFormatString(new Date()));
String templatePath = "D:\nominPortal\nomin-portal\Web\WebContent\reports\customerReceipt.jrxml";
reportController.saveNewReportTemplate(templatePath, "customerReceipt");
reportController.printReport("customerReceipt", params);

BillCustomerState state = new BillCustomerState();
state.setpKey(Tools.createNewPKey());
state.setHdrKey(listBillCustomerDtl.get(0).getHdrKey());
state.setStatus(8);
state.setCreatedKey(loginController.getLoginInfo().getUserKey());
state.setCreatedDate(new Date());
state.setModifiedKey(loginController.getLoginInfo().getUserKey());
state.setModifiedDate(new Date());
vendorLogic.insert(state);
} catch (Exception e) {
addErrorMessage(e);
}
}

/** BELTGEN NIILEGCH TOOTSOO NIILUULEH AKT BATALGAAJUULAH DARAH */
public void saveCalculationAct() {

if (params().get("billCustomerStatus") == null) {
Messages.showWarningMessage("Үлдэгдлээ батална уу.");
return;
}

if (params().get("billCustomerStatusValue") == null) {
Messages.showWarningMessage("Дансны мэдээллээ батална уу.");
return;
}

try {
String invRef = params().get("itemBillInRef") == null ? null : params().get("itemBillInRef").toString();
if (invRef != null && vendorLogic.checkBillCustomer(invRef)) {
Messages.showWarningMessage(invRef + " нэхэмжлэхийн дугаар давхардсан байна!");
return;
}
if (fileList.size() == 0) {
Messages.showWarningMessage("Хавсаргах файлаа сонгоно уу.");
return;
}
vendorLogic.saveCalculationAct(listBillCustomerDtl, invRef);
Messages.showSuccessMessageById("Message", "Амжилттай хадгаллаа.");
PrimeFaces.current().executeScript("document.getElementById('buttonPrintCalculationAct').click();");
showDataAkt();
try {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect("/");
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception ex) {
if(ex.getMessage().contains("RequiredReceipt"))
addWarningMessage("Нэхэмжлэхийн загвар заавал татаж байж файл хавсаргана уу");
else
addErrorMessage(ex);
}
}

public void restoreLastBalance() {
try {
vendorLogic.restoreLastBalance(loginController.getLoginInfo().getCustomerKey());
calculateEndBalance();
} catch (Exception e) {
e.printStackTrace();
}
}

/** FILE UPLOAD */
public void handleFileUpload(FileUploadEvent event) {

if (event == null || event.getFile() == null) {
Messages.showWarningMessage("Файл сонгогдоогүй байна!");
return;
}

try {
if (billCustomer == null)
return;
UploadedFile file = event.getFile();
if (getFileList().stream().map(i -> i.getFileName()).collect(Collectors.toList())
.contains(file.getFileName())) {
addWarningMessage(String.format("%s нэр файл оруулсан байна", file.getFileName()));
return;
}
byte[] fileByteValue = Tools.resize(file.getContents());

if(fileByteValue.length == 0) {
Messages.showWarningMessage("Файл дахин илгээнэ үү.");
}

BillCustomerFile bFile = new BillCustomerFile();
bFile.setpKey(Tools.createNewPKey());
bFile.setHdrKey(billCustomer.getpKey());
bFile.setCustomerKey(loginController.getLoginInfo().getCustomerKey());
bFile.setBlob(fileByteValue);
bFile.setFileName(file.getFileName());
bFile.setFileExtension(FilenameUtils.getExtension(file.getFileName()));
bFile.setCreatedDate(new Date());

vendorLogic.saveCalculationActAttachment(bFile);
fileList = vendorLogic.getCalculationAktAttachments(billCustomer.getpKey());
PrimeFaces.current().ajax().update("form:fileList");

Messages.showSuccessMessage(event.getFile().getFileName() + " амжилттай хуулагдлаа.");

} catch (Exception e) {
addErrorMessage(e);
}
}

public void downloadCalculationAct() {
try {

String invRef = "";
BillCustomerDtl billCustomerDtl = listBillCustomerDtl.get(0);
List<CalculationActDtl> list = vendorLogic.downloadDataAkt(billCustomerDtl.getHdrKey());

CustomerInfo customer = vendorLogic.showCurrentCustomer(loginController.getLoginInfo().getCustomerKey());
Map<String, Object> params = new HashMap<>();

BigDecimal totalAmount = list.stream().map(CalculationActDtl::getAmount).reduce(BigDecimal::add).get();

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String now = df.format(new Date());

params.put("invoiceNumber", invRef);
params.put("date", now);

params.put("sVatPayerNo", "54699929");
params.put("sName", "НОМИН ТАВ ТРЕЙД");
params.put("sAddress", "Монгол, Улаанбаатар, Чингэлтэй, 3-р хороо, УИД, 7 Давхар");
params.put("sPhone", "89881129, 95091129, 99097386");

params.put("bVatPayerNo", customer.getVatPayerNo());
params.put("bName", customer.getName());
params.put("bAddress", customer.getAddress());
params.put("bPhone", customer.getPhoneNumber());

params.put("vatAmount", new BigDecimal(0));
params.put("totalAmount", totalAmount);
params.put("amount", totalAmount);
params.put("user", loginController.getLoginInfo().getFullName());

params.put("itemList", list);

reportController.downloadReportPDF("invoice", params);

} catch (Exception e) {
e.printStackTrace();
}
}

public void billCustomerFilterListener(FilterEvent filterEvent) {
calculateBillCustomerFooter(filteredListBillCustomerDtl);
}

public void calculateBillCustomerFooter(List<BillCustomerDtl> list) {
if (list == null || list.size() == 0)
return;
params().put("sumBillQty", list.stream().filter(b -> b.getBillQty() != null).map(s -> s.getBillQty())
.reduce(BigDecimal.ZERO, BigDecimal::add));
params().put("sumCloseQty", list.stream().filter(b -> b.getCloseQty() != null).map(s -> s.getCloseQty())
.reduce(BigDecimal.ZERO, BigDecimal::add));
params().put("sumBillEndQty", list.stream().filter(b -> b.getBillEndQty() != null).map(s -> s.getBillEndQty())
.reduce(BigDecimal.ZERO, BigDecimal::add));
params().put("sumCloseAmount", list.stream().filter(b -> b.getCloseAmount() != null)
.map(s -> s.getCloseAmount()).reduce(BigDecimal.ZERO, BigDecimal::add));
PrimeFaces.current().ajax().update("form:tblCalculationAct");
}

/** ETSSIIN ULDEGDEL TOOTSOOLOH */
public void calculateEndBalance() {
try {
Date endDate = (Date) params().get("endDateAct");
if (endDate != null) {
BigDecimal endBalance = vendorLogic.calculateEndBalance(loginController.getLoginInfo().getCustomerKey(),
endDate);
params().put("endBalanceAmount", endBalance);
}
} catch (Exception e) {
e.printStackTrace();
}
}

/** ETSSIIN ULDEGDEL BATLAH */
public void confirmBillCustomerStatus() {
try {
Long hdrKey = (Long) params().get("hdrKey");
BigDecimal endBalanceAmount = (BigDecimal) params().get("endBalanceAmount");
if (hdrKey != null) {
Long billCustomerStateKey = vendorLogic.getBillCustomerState(hdrKey, 1);
if (billCustomerStateKey == null) {
vendorLogic.saveBillCustomerStatus(hdrKey, endBalanceAmount,
loginController.getLoginInfo().getUserKey());
billCustomerStateKey = vendorLogic.getBillCustomerState(hdrKey, 1);
if (billCustomerStateKey != null) {
params().put("billCustomerStatus", billCustomerStateKey);
Messages.showSuccessMessage("Амжилттай батлагдлаа");
} else {
Messages.showErrorMessage("Батлахад алдаа гарлаа");
}
}
}
} catch (Exception e) {
e.printStackTrace();
Messages.showErrorMessage("Батлахад алдаа гарлаа");
}
}


/** TOOTSOONII BANK DANS BATLAH */
public void confirmBillCustomerAccount() {
try {
Long hdrKey = (Long) params().get("hdrKey");
if (hdrKey != null) {
Long billCustomerStateKey = vendorLogic.getBillCustomerState(hdrKey, 1);
if (billCustomerStateKey != null) {
vendorLogic.confirmBillCustomerAccount(billCustomerStateKey,
loginController.getLoginInfo().getUserKey());
billCustomerStateKey = vendorLogic.getBillCustomerState(hdrKey, 0);
if (billCustomerStateKey != null) {
params().put("billCustomerStatus", billCustomerStateKey);
Messages.showSuccessMessage("Амжилттай батлагдлаа");
} else {
Messages.showErrorMessage("Батлахад алдаа гарлаа");
}
}
}
} catch (Exception e) {
e.printStackTrace();
Messages.showErrorMessage("Батлахад алдаа гарлаа");
}
}

/** ETSSIIN ULDEGDLIIN BATALGAAJILT TSUTSLAH */
public void deleteBillCustomerStatus() {
try {
Long billCustomerStatus = (Long) params().get("billCustomerStatus");
if (billCustomerStatus != null) {
vendorLogic.deleteBillCustomerStatus(billCustomerStatus, loginController.getLoginInfo().getUserKey());
params().remove("billCustomerStatus");
Messages.showWarningMessage("Баталгаажилт цуцлагдлаа");
}
} catch (Exception e) {
e.printStackTrace();
Messages.showErrorMessage("Батлахад алдаа гарлаа");
}
}

/** ETSSIIN ULDEGDLIIN AKT HEVLEH */
public void printEndBalanceAkt() {
try {
BigDecimal endBalanceAmount = (BigDecimal) params().get("endBalanceAmount");
if (endBalanceAmount != null) {
Map<String, Object> params = new HashMap<>();

CustomerInfo customer = vendorLogic
.showCurrentCustomer(loginController.getLoginInfo().getCustomerKey());

LoginInfo login = loginController.getLoginInfo();
PortalUser user = portalUserLogic.getPortalUser(login.getUserKey());
String createdUser = (String) params().get("billCustomerCreatedName");

Date beginDate = (Date) params().get("beginDateAct");
Date endDate = (Date) params().get("endDateAct");

params.put("companyName", customer.getName());
params.put("userPosition", user.getPositionName());
params.put("userName", login.getFirstName());
params.put("beginDate", beginDate);
params.put("endDate", endDate);
params.put("cashierName", createdUser);
params.put("amount", endBalanceAmount);
params.put("amountLetter", Tools.currencyToLetter(endBalanceAmount));
reportController.printReport("lastBalanceAkt", params);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void goToReceiveDetail() {
try {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect("/pages/vendor/receiveDetail.html");
} catch (IOException e) {
e.printStackTrace();
}
}

public void showPayableDetailWithDate() {
vendorController.setBeginDatePayable((Date) params().get("beginDateAct"));
vendorController.setEndDatePayable((Date) params().get("endDateAct"));
goToReceiveDetail();
}

public void removeFile(BillCustomerFile file) {
try {
fileList.remove(file);
vendorLogic.delete(file);
} catch (Exception e) {
addErrorMessage(e);
}
}

/*** GETTER SETTER ***/
public BillCustomer getBillCustomer() {
return billCustomer;
}

public void setBillCustomer(BillCustomer billCustomer) {
this.billCustomer = billCustomer;
}

public List<BillCustomerFile> getFileList() {
if (fileList == null)
fileList = new ArrayList<>();
return fileList;
}

public void setFileList(List<BillCustomerFile> fileList) {
this.fileList = fileList;
}

public List<BillCustomerDtl> getListBillCustomerDtl() {
return listBillCustomerDtl;
}

public void setListBillCustomerDtl(List<BillCustomerDtl> listBillCustomerDtl) {
this.listBillCustomerDtl = listBillCustomerDtl;
}

public List<BillCustomerDtl> getFilteredListBillCustomerDtl() {
return filteredListBillCustomerDtl;
}

public void setFilteredListBillCustomerDtl(List<BillCustomerDtl> filteredListBillCustomerDtl) {
this.filteredListBillCustomerDtl = filteredListBillCustomerDtl;
}

public String getCurrencyId() {
return currencyId;
}

public void setCurrencyId(String currencyId) {
this.currencyId = currencyId;
}

public String getAccountName() {
return accountName;
}

public void setAccountName(String accountName) {
this.accountName = accountName;
}

public List<CalculationPayment> getListPayment() {
if(listPayment == null)
listPayment = new ArrayList<CalculationPayment>();
return listPayment;
}

public void setListPayment(List<CalculationPayment> listPayment) {
this.listPayment = listPayment;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.