Notes
![]() ![]() Notes - notes.io |
import java.sql.Date;
import java.util.HashMap;
import java.util.Map;
import com.highradius.common.util.HRCLogFactory;
import com.highradius.common.util.HRCLog;
import com.github.openjson.JSONObject;
import com.google.gson.Gson;
import com.highradius.training.manager.InvoiceDetailsManager;
import com.receivablesradius.deductions.action.BaseAction;
import com.receivablesradius.deductions.constants.JSONRowResult;
import com.receivablesradius.deductions.manager.impl.AdvanceSearchQueryHelperManagerImpl;
import bbsr.highradius.training.model.invoice.Customer;
import bbsr.highradius.training.model.invoice.InvoiceDetails;
import bbsr.highradius.training.model.invoice.InvoiceType;
import bbsr.highradius.training.model.invoice.PostingKey;
import bbsr.highradius.training.model.invoice.account;
public class InvoiceDetailsAction extends BaseAction {
private static final HRCLog LOGGER = HRCLogFactory.getLog(InvoiceDetailsAction.class);
private String jsonData;
public String getJsonData() {
return jsonData;
}
public void setJsonData(String jsonData) {
this.jsonData = jsonData;
}
InvoiceDetailsManager invoiceDetailsManager;
public InvoiceDetailsManager getInvoiceDetailsManager() {
return invoiceDetailsManager;
}
public void setInvoiceDetailsManager(InvoiceDetailsManager invoiceDetailsManager) {
this.invoiceDetailsManager = invoiceDetailsManager;
}
private String query;
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
/*
* public Customer getFkCustomerId() { return fkCustomerId; } public void
* setFkCustomerId(Customer fkCustomerId) { this.fkCustomerId = fkCustomerId; }
*/
public String getOpenInvoiceDetails() {
LOGGER.debug("Inside getEmployeeDetails() called from EmployeeDetailsManager");
//LOGGER.debug("Searched Name :"+firstName+" Employee ID : "+employeeId);
AdvanceSearchQueryHelperManagerImpl advanceSearchQueryHelperManagerImpl = new AdvanceSearchQueryHelperManagerImpl();
String advanceSearchWhereQuery = advanceSearchQueryHelperManagerImpl.massageQuery(null,query);
Map<String, Object> invoiceDetailsMap = new HashMap<>();
JSONRowResult result = new JSONRowResult();
try {
//invoiceDetailsMap = invoiceDetailsManager.getInvoiceDetails(advanceSearchWhereQuery, getStartIndex(), getRowsToFetch());
//getInvoiceDetails into getOpenInvoiceDetails
invoiceDetailsMap = invoiceDetailsManager.getOpenInvoiceDetails(advanceSearchWhereQuery, getStartIndex(), getRowsToFetch());
//null check to avoid null pointer exception
if(invoiceDetailsMap != null) {
result.results = invoiceDetailsMap.get("count");
result.rows = invoiceDetailsMap.get("rows");
}
}
catch (Exception e) {
LOGGER.error("Error inside getEmployeeDetails :",e);
return ERROR;
}
Gson gson = new Gson();
String jsonResult = gson.toJson(result);
setOutput(jsonResult);
return SUCCESS;
}
//new from here
public String getCloseInvoiceDetails() {
LOGGER.debug("Inside getEmployeeDetails() called from EmployeeDetailsManager");
//LOGGER.debug("Searched Name :"+firstName+" Employee ID : "+employeeId);
AdvanceSearchQueryHelperManagerImpl advanceSearchQueryHelperManagerImpl = new AdvanceSearchQueryHelperManagerImpl();
String advanceSearchWhereQuery = advanceSearchQueryHelperManagerImpl.massageQuery(null,query);
Map<String, Object> invoiceDetailsMap = new HashMap<>();
JSONRowResult result = new JSONRowResult();
try {
//invoiceDetailsMap = invoiceDetailsManager.getInvoiceDetails(advanceSearchWhereQuery, getStartIndex(), getRowsToFetch());
//getInvoiceDetails into getOpenInvoiceDetails
invoiceDetailsMap = invoiceDetailsManager.getCloseInvoiceDetails(advanceSearchWhereQuery, getStartIndex(), getRowsToFetch());
//null check to avoid null pointer exception
if(invoiceDetailsMap != null) {
result.results = invoiceDetailsMap.get("count");
result.rows = invoiceDetailsMap.get("rows");
}
}
catch (Exception e) {
LOGGER.error("Error inside getEmployeeDetails :",e);
return ERROR;
}
Gson gson = new Gson();
String jsonResult = gson.toJson(result);
setOutput(jsonResult);
return SUCCESS;
}
// public String updateInvoiceDetails() {
//
// LOGGER.debug("Inside getEmployeeDetails() called from InvoiceDetailsManager");
// JSONRowResult result = new JSONRowResult();
// Gson gson = new Gson();
// InvoiceDetailsAction jsonResult=gson.fromJson(jsonData, InvoiceDetailsAction.class);
// try {
// //InvoiceReaderAction ac=new InvoiceReaderAction();
//
// System.out.println(jsonData );
//
// result.success= true;
// } catch (Exception e) {
// LOGGER.error("Exception inside addNewEmployeeDetails() : ",e);
// return ERROR;
// }
//
//
// return SUCCESS;
//
// }
public String updateInvoiceDetails() {
LOGGER.debug("Inside UpdateInvoiceDetails() called from InvoiceDetailsManager");
//LOGGER.debug("Inserting Name : "+firstName+" Employee ID : "+employeeId);
JSONRowResult result = new JSONRowResult();
JSONObject jsonResult=new JSONObject(jsonData);
System.out.println(jsonData);
int checkForPk=0;
System.out.println(jsonResult);
try {
if(invoiceDetailsManager.checkExist(String.valueOf(jsonResult.get("companyCode")))==1 || invoiceDetailsManager.checkExist(String.valueOf(jsonResult.get("invoiceNumber")))==1) {
return ERROR;
}
else if(invoiceDetailsManager.invoiceAmountCheck((String) jsonResult.get("invoiceTotalAmount"))==1) {
return ERROR;
}
else if(invoiceDetailsManager.validCustomer(Integer.parseInt((String) jsonResult.get("fkCustomerId.customerNumber")),Integer.parseInt((String) jsonResult.get("fkAccountId.accountId")))==1) {
return ERROR;
}
else {
if(jsonResult.get("pkInvoiceId").equals(""));{
checkForPk=1;
}
InvoiceDetails ID=setDetails(jsonResult,checkForPk);
if(ID==null) {
return ERROR;
}
else {
System.out.println(jsonResult.get("pkInvoiceId")+" "+jsonResult.get("fkAccountId.accountId"));
System.out.println(ID.toString());
boolean status = invoiceDetailsManager.updateInvoiceDetails(ID);
result.success=status;
}
}
}
catch (Exception e) {
LOGGER.error("Exception inside addNewInvoiceDetails() : ",e);
return ERROR;
}
return SUCCESS;
}
public InvoiceDetails setDetails(JSONObject jsonResult,int check) {
InvoiceDetails invoiceDetail=new InvoiceDetails();
if(check==0) {
invoiceDetail.setPkInvoiceId(Integer.parseInt((String) jsonResult.get("pkInvoiceId")));
}
account ac=new account();
ac.setAccountId(Integer.parseInt((String) jsonResult.get("fkAccountId.accountId")));
invoiceDetail.setFkAccountId(ac);
String str=(String)jsonResult.get("invoiceNumber");
if(str.length()>15)
str=str.substring(0,15);
invoiceDetail.setInvoiceNumber(str);
str=(String) jsonResult.get("companyCode");
if(str.length()>4)
str=str.substring(0,4);
invoiceDetail.setCompanyCode(str);
str=(String) jsonResult.get("fiscalYear");
if(str.length()>4)
str=str.substring(0, 4);
invoiceDetail.setFiscalYear(str);
str=(String) jsonResult.get("itemNumber");
if(str.length()>3)
str=str.substring(0, 3);
invoiceDetail.setItemNumber(str);
InvoiceType it=new InvoiceType();
it.setPkInvoiceTypeId(Integer.parseInt((String) jsonResult.get("fkInvoiceType.invoiceType")));
it.setFkAccountId(ac);
invoiceDetail.setFkInvoiceType(it);
PostingKey pk=new PostingKey();
pk.setKeyType((String) jsonResult.get("fkPostingKey.keyType"));
pk.setFkAccountId(ac);
PostingKey pt=invoiceDetailsManager.fetch_data_posting(pk);
if(pt==null)
return null;
invoiceDetail.setFkPostingKey(pt);
Customer cd=new Customer();
cd.setCustomerNumber((String) jsonResult.get("fkCustomerId.customerNumber"));
cd.setFkAccountId(ac);
Customer cD=invoiceDetailsManager.getPkCustomerId(cd);
if(cD==null)
return null;
invoiceDetail.setFkCustomerId(cD);
invoiceDetail.setInvoiceTotalAmount(Double.parseDouble((String) jsonResult.get("invoiceTotalAmount")));
//invoiceDetail.setInvoiceDueAmount(Double.parseDouble((String) jsonResult.get("invoiceDueAmount")));
invoiceDetail.setInvoiceCreatedDate(invoiceDetailsManager.convertDate((String) jsonResult.get("invoiceCreatedDate")));
invoiceDetail.setDueDate(invoiceDetailsManager.convertDate((String) jsonResult.get("dueDate")));
Date dueDate=(Date) invoiceDetail.getDueDate();
Integer discount=invoiceDetailsManager.discountPer(dueDate);
Double dueAmount=invoiceDetailsManager.dueAmt(invoiceDetail.getInvoiceTotalAmount(), discount);
invoiceDetail.setInvoiceDueAmount(dueAmount);
if(discount==3)
invoiceDetail.setDiscount1Percentage(discount);
else if(discount==2)
invoiceDetail.setDiscount2Percentage(discount);
else if(discount==1)
invoiceDetail.setDiscount3Percentage(discount);
// if(!(jsonResult.get("debitCreditIndicator").equals("")))
// invoiceDetail.setDebitCreditIndicator((String) jsonResult.get("debitCreditIndicator"));
return invoiceDetail;
}
// public String updateInvoiceDetails() {
// LOGGER.debug("Inside updateInvoiceDetails() called from InvoiceDetailsManager");
// InvoiceDetails ob = new InvoiceDetails();
// account ac = new account();
// ac.setAccountId(Integer.parseInt(fkAccountId));
// ob.setFkAccountId(ac);
// JSONRowResult result = new JSONRowResult();
//
// if (invoiceNumber.length() > 11) {
// ob.setInvoiceNumber(invoiceNumber.substring(0, 9));
// } else {
// ob.setInvoiceNumber(invoiceNumber);
// }
// if (companyCode.length() > 4) {
// ob.setCompanyCode(companyCode.substring(0, 4));
// } else {
// ob.setCompanyCode(companyCode);
// }
// if (fiscalYear.length() > 4) {
// ob.setFiscalYear(fiscalYear.substring(0, 4));
// } else {
// ob.setFiscalYear(fiscalYear);
// }
// if (itemNumber.length() > 3) {
// ob.setItemNumber(itemNumber.substring(0, 1));
// } else {
// ob.setItemNumber(itemNumber);
// }
//// InvoiceType it = new InvoiceType();
//// it.setFkAccountId(ac);
//// it.setPkInvoiceTypeId(Integer.parseInt(fkInvoiceType));
////
//// PostingKey pk = new PostingKey();
//// pk.setFkAccountId(ac);
//// pk.setKeyType(fkPostingKey);
//// PostingKey getPk = invoiceDetailsManager.fetch_data_posting(pk);
//// ob.setFkPostingKey(getPk);
////
//// Customer cm = new Customer();
//// cm.setCustomerNumber(fkCustomerId);
//// cm.setFkAccountId(ac);
//// Customer getPkCustomerNo = invoiceDetailsManager.getPkCustomerId(cm);
//// ob.setFkCustomerId(getPkCustomerNo);
////
// System.out.println(ob);
//
// // boolean status = invoiceDetailsManager.addNewInvoiceDetails(ob);
// // result.success= status;
//
// // Gson gson = new Gson();
// // String jsonResult = gson.toJson(result);
// // setOutput(jsonResult);
// return SUCCESS;
//
// }
//
}
![]() |
Notes is a web-based application for online 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 14 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