private OBError CreateRegisters(VariablesSecureApp vars, String strTaxpaymentID,
String strDatefrom, String strDateto, String strProcessed, String strGeneratePayment,
String strProcessing) throws IOException, ServletException {
// Connection conn = getTransactionConnection();
OBError myMessage = null;
TaxPayment[] taxpayment = TaxPayment.select(this, strTaxpaymentID);
String strUser = vars.getUser();
log4j.info("strTaxpaymentID: " + strTaxpaymentID + "strDatefrom: " + strDatefrom
+ "strDateto: " + strDateto + "strProcessed: " + strProcessed + "strGeneratePayment: "
+ strGeneratePayment);
// If processing=n then i deleted all old record of tax register and
// register lines
if (strProcessed.equalsIgnoreCase("N")) {
// check for already used periods)
BigDecimal CrossPeriodCount = new BigDecimal(TaxPayment.selectCrossPeriodCount(this, vars
.getClient(), strDatefrom, strDateto));
if (CrossPeriodCount.intValue() > 0) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this,
"PeriodsDontMatch", vars.getLanguage()));
return myMessage;
}
try {
TaxPayment.deleteRegisterLinesChild(this, strTaxpaymentID);
TaxPayment.deleteRegisterChild(this, strTaxpaymentID);
} catch (ServletException ex) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
return myMessage;
}
// Select all active Register Type for create the Tax Registers
TaxRegisterType[] taxregistertypes = TaxRegisterType.select(this, vars.getClient(), Tree
.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), taxpayment[0].adOrgId));
log4j.info("2strTaxpaymentID: " + strTaxpaymentID + "strDatefrom: " + strDatefrom
+ "strDateto: " + strDateto + "strProcessed: " + strProcessed + "strGeneratePayment: "
+ strGeneratePayment);
// For all active Register Type i create a Tax Register
for (TaxRegisterType taxRegisterType : taxregistertypes) {
String strSequence = SequenceIdData.getUUID();
log4j.info("Sequence: " + strSequence);
try {
TaxRegister.insert(this, taxpayment[0].adClientId, taxpayment[0].adOrgId, strSequence,
strTaxpaymentID, taxRegisterType.cTaxregisterTypeId, "0",
taxRegisterType.registername, strUser, strUser);
} catch (ServletException ex) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
return myMessage;
}
}
// For every TaxRegister i select the invoices with a specific
// doctype
// in that specific period and inser them in the respective
// TaxRegisterLine
log4j.info("3strTaxpaymentID: " + strTaxpaymentID + "strDatefrom: " + strDatefrom
+ "strDateto: " + strDateto + "strProcessed: " + strProcessed + "strGeneratePayment: "
+ strGeneratePayment);
TaxRegister[] taxregisters = TaxRegister.selectChild(this, strTaxpaymentID);
for (TaxRegister taxRegister : taxregisters) {
CreateVatRegistersData[] invoices = CreateVatRegistersData.select(this, strTaxpaymentID,
taxRegister.cTaxregisterTypeId, strDatefrom, DateTimeData.nDaysAfter(this, strDateto,
"1"), Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()),
taxpayment[0].adOrgId));
for (CreateVatRegistersData myinvoice : invoices) {
String strTaxBaseAmt = "0";
String strTaxAmt = "0";
String strTaxUndeducAmt = "0";
String strExemptAmt = "0";
String strTotalAmt = "0";
String strNoVatAmt = "0";
log4j.info("cTaxregisterTypeId: " + taxRegister.cTaxregisterTypeId + "strTaxpaymentID: "
+ strTaxpaymentID + "strDatefrom: " + strDatefrom + "strDateto: " + strDateto
+ "strGeneratePayment: " + strGeneratePayment);
if ((myinvoice.istaxexempt.equals("N")) && (myinvoice.istaxundeductable.equals("N"))
&& (myinvoice.isnovat.equals("N"))) {
strTaxBaseAmt = myinvoice.taxbaseamt;
strTaxAmt = myinvoice.taxamt;
} else if ((myinvoice.istaxexempt.equals("Y"))
&& (myinvoice.istaxundeductable.equals("N")) && (myinvoice.isnovat.equals("N"))) {
strTaxAmt = myinvoice.taxamt;
strExemptAmt = myinvoice.taxbaseamt;
} else if ((myinvoice.istaxexempt.equals("N"))
&& (myinvoice.istaxundeductable.equals("Y")) && (myinvoice.isnovat.equals("N"))) {
strTaxBaseAmt = myinvoice.taxbaseamt;
strTaxUndeducAmt = myinvoice.taxamt;
} else if ((myinvoice.istaxexempt.equals("N"))
&& (myinvoice.istaxundeductable.equals("N")) && (myinvoice.isnovat.equals("Y"))) {
strNoVatAmt = myinvoice.taxbaseamt;
strTaxAmt = myinvoice.taxamt;
} else {
// if (!(((myinvoice.istaxexempt.equals("Y") )
// ^ (myinvoice.istaxundeductable.equals("Y"))
// ^ (myinvoice.isnovat.equals("Y"))))) {
// return
// "InvoiceTax Error: istaxexempt, istaxundeduc or isnovat could have wrong values, C_InvoiceTax_ID="+myinvoice.cInvoicetaxId;
myMessage = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(
this, "TaxCriteriaNotFound", vars.getLanguage()));
return myMessage;
}
if (myinvoice.docbasetype.equals(DocInvoice.DOCTYPE_APCredit)
|| myinvoice.docbasetype.equals(DocInvoice.DOCTYPE_ARCredit)) {
strTaxBaseAmt = (new BigDecimal(strTaxBaseAmt).negate()).toPlainString();
strTaxAmt = (new BigDecimal(strTaxAmt).negate()).toPlainString();
strTaxUndeducAmt = (new BigDecimal(strTaxUndeducAmt).negate()).toPlainString();
strExemptAmt = (new BigDecimal(strExemptAmt).negate()).toPlainString();
strNoVatAmt = (new BigDecimal(strNoVatAmt).negate()).toPlainString();
}
// Calculate totalamt
log4j.info("4strTaxpaymentID: " + strTaxpaymentID + "strDatefrom: " + strDatefrom
+ "strDateto: " + strDateto + "strProcessed: " + strProcessed
+ "strGeneratePayment: " + strGeneratePayment);
BigDecimal dbTotalAmt = new BigDecimal(strTaxBaseAmt).add(new BigDecimal(strTaxAmt)).add(
new BigDecimal(strTaxUndeducAmt)).add(new BigDecimal(strExemptAmt)).add(
new BigDecimal(strNoVatAmt));
strTotalAmt = dbTotalAmt.toPlainString();
String strSequence = SequenceIdData.getUUID();
log4j.info("Sequence: " + strSequence);
try {
TaxRegister.insertLines(this, taxRegister.adClientId, taxRegister.adOrgId, strSequence,
taxRegister.cTaxregisterId, myinvoice.cInvoicetaxId, myinvoice.documentno,
myinvoice.cTaxId, strTaxBaseAmt, strTaxAmt, strTaxUndeducAmt, strExemptAmt,
strNoVatAmt, strTotalAmt, myinvoice.taxdate, "RegisterLine", strUser, strUser);
} catch (ServletException ex) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
return myMessage;
}
}
try {
TaxRegister.updateTaxTotalAmt(this, taxRegister.cTaxregisterId);
TaxRegister.updateRegAccumAmt(this, taxRegister.cTaxregisterId,
taxRegister.cTaxregisterTypeId, strDatefrom);
} catch (ServletException ex) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
return myMessage;
}
}
// if GeneratePayment= Y then i set the field processing = N so next
// time i print only the tax registers
// if (strProcessing.equalsIgnoreCase("Y")) {
// TaxPayment
// .updateProcessed(this, "Y", strUser, strTaxpaymentID);
// }
log4j.info("5strTaxpaymentID: " + strTaxpaymentID + "strDatefrom: " + strDatefrom
+ "strDateto: " + strDateto + "strProcessed: " + strProcessed + "strGeneratePayment: "
+ strGeneratePayment);
try {
if (new BigDecimal(TaxPayment.calculateVatPayment(this, strTaxpaymentID))
.compareTo(BigDecimal.ZERO) > 0) {
TaxPayment.updateGeneratePayment(this, "Y", strUser, strTaxpaymentID);
} else
TaxPayment.updateGeneratePayment(this, "N", strUser, strTaxpaymentID);
} catch (NumberFormatException e) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this,
"NoDataSelected", vars.getLanguage()));
return myMessage;
}
if (myMessage == null) {
myMessage = new OBError();
myMessage.setType("Success");
myMessage.setTitle("");
myMessage.setMessage(Utility.messageBD(this, "Success", vars.getLanguage()));
}
return myMessage;
}