improve invoice plugin logic
This commit is contained in:
parent
fecb9e8813
commit
78739d3517
3 changed files with 50 additions and 36 deletions
|
|
@ -123,26 +123,34 @@ public class BusinessPartnerService {
|
||||||
* Diese Methode aktualisiert das business Partner object. Sie wird von den
|
* Diese Methode aktualisiert das business Partner object. Sie wird von den
|
||||||
* Invoice Plugins genutzt. Die Methode wirft eine PluginException falls das
|
* Invoice Plugins genutzt. Die Methode wirft eine PluginException falls das
|
||||||
* BusinessPartner Objekt gesperrt oder in verification ist!
|
* BusinessPartner Objekt gesperrt oder in verification ist!
|
||||||
*
|
* <p>
|
||||||
* Gleichzeitig wird bei Rechnungen in Abhängigkeit der Rechnungsart die
|
* Gleichzeitig wird bei Rechnungen in Abhängigkeit der Rechnungsart die
|
||||||
* dbtr./cdtr. items sowie mail und country aktualisiert.
|
* dbtr./cdtr. items sowie mail und country aktualisiert.
|
||||||
*
|
* <p>
|
||||||
|
* Die Methode wirft eine Plugin Exception falls der Business Partner im Status
|
||||||
|
* Verification ist und updateWhenVerification=false.
|
||||||
|
* <p>
|
||||||
|
* Die Methode wirft eine Plugin Exception falls der Business Partner im Status
|
||||||
|
* Locked ist und updateWhenLocked=false.
|
||||||
|
*
|
||||||
* @param partnerID
|
* @param partnerID
|
||||||
* @param workitem
|
* @param invoice
|
||||||
* @return BusinessPartner Object
|
* @return BusinessPartner Object
|
||||||
* @throws PluginException
|
* @throws PluginException
|
||||||
*/
|
*/
|
||||||
public ItemCollection updateBusinessPartnerData(ItemCollection workitem) throws PluginException {
|
public ItemCollection updateBusinessPartnerData(ItemCollection invoice, boolean updateWhenVerification,
|
||||||
String partnerID = workitem.getItemValueString("partner.id").trim();
|
boolean updateWhenLocked)
|
||||||
// Migration wenn keine partner.id existier!
|
throws PluginException {
|
||||||
|
String partnerID = invoice.getItemValueString("partner.id").trim();
|
||||||
|
// Migration wenn keine partner.id existiert!
|
||||||
if (partnerID.isEmpty()) {
|
if (partnerID.isEmpty()) {
|
||||||
if (InvoiceUtil.isCreditorInvoice(workitem)) {
|
if (InvoiceUtil.isCreditorInvoice(invoice)) {
|
||||||
partnerID = InvoiceUtil.buildBPID(workitem.getItemValueString("cdtr.number"));
|
partnerID = InvoiceUtil.buildBPID(invoice.getItemValueString("cdtr.number"));
|
||||||
}
|
}
|
||||||
if (InvoiceUtil.isDebitorInvoice(workitem)) {
|
if (InvoiceUtil.isDebitorInvoice(invoice)) {
|
||||||
partnerID = InvoiceUtil.buildBPID(workitem.getItemValueString("dbtr.number"));
|
partnerID = InvoiceUtil.buildBPID(invoice.getItemValueString("dbtr.number"));
|
||||||
}
|
}
|
||||||
workitem.setItemValue("partner.id", partnerID);
|
invoice.setItemValue("partner.id", partnerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partnerID == null || partnerID.isEmpty()) {
|
if (partnerID == null || partnerID.isEmpty()) {
|
||||||
|
|
@ -164,40 +172,40 @@ public class BusinessPartnerService {
|
||||||
Integer.parseInt(partnerID);
|
Integer.parseInt(partnerID);
|
||||||
// it is an int - get last 4 digits
|
// it is an int - get last 4 digits
|
||||||
partnerID = "BP" + partnerID.substring(Math.max(0, partnerID.length() - 4));
|
partnerID = "BP" + partnerID.substring(Math.max(0, partnerID.length() - 4));
|
||||||
workitem.setItemValue("partner.id", partnerID);
|
invoice.setItemValue("partner.id", partnerID);
|
||||||
businessPartner = getBusinessPartnerByID(partnerID);
|
businessPartner = getBusinessPartnerByID(partnerID);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
/* not an int */
|
/* not an int */
|
||||||
}
|
}
|
||||||
if (businessPartner == null) {
|
if (businessPartner == null) {
|
||||||
workitem.removeItem("partner.id");
|
invoice.removeItem("partner.id");
|
||||||
logger.warning("Business Partner for Partner ID " + partnerID + " not found!");
|
logger.warning("Business Partner for Partner ID " + partnerID + " not found!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// because the method can be called multiple times within one worklfow
|
// because the method can be called multiple times within one workflow
|
||||||
// processing cycle
|
// processing cycle we need to load the object within the current transaction
|
||||||
// we need to load the object within the current transaction context
|
// context
|
||||||
businessPartner = documentService.load(businessPartner.getUniqueID());
|
businessPartner = documentService.load(businessPartner.getUniqueID());
|
||||||
if (businessPartner != null) {
|
if (businessPartner != null) {
|
||||||
// update partner id data
|
// update partner id data
|
||||||
workitem.setItemValue("partner.id", partnerID);
|
invoice.setItemValue("partner.id", partnerID);
|
||||||
workitem.setItemValue("partner.name", businessPartner.getItemValueString("partner.name"));
|
invoice.setItemValue("partner.name", businessPartner.getItemValueString("partner.name"));
|
||||||
logger.info("check invoice type....");
|
logger.info("check invoice type....");
|
||||||
// Update Invoice Partner Meta Data
|
// Update Invoice Partner Meta Data
|
||||||
if (InvoiceUtil.isDebitorInvoice(workitem)) {
|
if (InvoiceUtil.isDebitorInvoice(invoice)) {
|
||||||
logger.info("...is debitor invoice");
|
logger.info("...is debitor invoice");
|
||||||
workitem.setItemValue("dbtr.number", businessPartner.getItemValueString("dbtr.number"));
|
invoice.setItemValue("dbtr.number", businessPartner.getItemValueString("dbtr.number"));
|
||||||
workitem.setItemValue("dbtr.name", businessPartner.getItemValueString("partner.name"));
|
invoice.setItemValue("dbtr.name", businessPartner.getItemValueString("partner.name"));
|
||||||
workitem.setItemValue("dbtr.mail", businessPartner.getItemValueString("dbtr.mail"));
|
invoice.setItemValue("dbtr.mail", businessPartner.getItemValueString("dbtr.mail"));
|
||||||
workitem.setItemValue("invoice.country", businessPartner.getItemValueString("_vendor_country"));
|
invoice.setItemValue("invoice.country", businessPartner.getItemValueString("_vendor_country"));
|
||||||
}
|
}
|
||||||
logger.info("...is creditor invoice");
|
logger.info("...is creditor invoice");
|
||||||
if (InvoiceUtil.isCreditorInvoice(workitem)) {
|
if (InvoiceUtil.isCreditorInvoice(invoice)) {
|
||||||
workitem.setItemValue("cdtr.name", businessPartner.getItemValueString("partner.name"));
|
invoice.setItemValue("cdtr.name", businessPartner.getItemValueString("partner.name"));
|
||||||
workitem.setItemValue("cdtr.mail", businessPartner.getItemValueString("cdtr.mail"));
|
invoice.setItemValue("cdtr.mail", businessPartner.getItemValueString("cdtr.mail"));
|
||||||
workitem.setItemValue("invoice.country", businessPartner.getItemValueString("_vendor_country"));
|
invoice.setItemValue("invoice.country", businessPartner.getItemValueString("_vendor_country"));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sonderfall - Frau Mahner 9.10.2025
|
* Sonderfall - Frau Mahner 9.10.2025
|
||||||
|
|
@ -205,25 +213,25 @@ public class BusinessPartnerService {
|
||||||
* ein alternatives Konto gewählt hat muss dieses gewinnen!
|
* ein alternatives Konto gewählt hat muss dieses gewinnen!
|
||||||
* Ansonsten nehmen wir die cdtr.number
|
* Ansonsten nehmen wir die cdtr.number
|
||||||
*/
|
*/
|
||||||
if ("credit".equals(workitem.getItemValueString("payment.type"))) {
|
if ("credit".equals(invoice.getItemValueString("payment.type"))) {
|
||||||
String bookingAccount = workitem.getItemValueString("payment.booking.account");
|
String bookingAccount = invoice.getItemValueString("payment.booking.account");
|
||||||
if (!bookingAccount.isBlank()) {
|
if (!bookingAccount.isBlank()) {
|
||||||
workitem.setItemValue("cdtr.number", bookingAccount);
|
invoice.setItemValue("cdtr.number", bookingAccount);
|
||||||
} else {
|
} else {
|
||||||
workitem.setItemValue("cdtr.number", businessPartner.getItemValueString("cdtr.number"));
|
invoice.setItemValue("cdtr.number", businessPartner.getItemValueString("cdtr.number"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// default - cdtr.number
|
// default - cdtr.number
|
||||||
workitem.setItemValue("cdtr.number", businessPartner.getItemValueString("cdtr.number"));
|
invoice.setItemValue("cdtr.number", businessPartner.getItemValueString("cdtr.number"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate Business Partner Status!
|
// Validate Business Partner Status!
|
||||||
if (businessPartner.getTaskID() == TASK_VERIFICATION) {
|
if (businessPartner.getTaskID() == TASK_VERIFICATION && !updateWhenVerification) {
|
||||||
throw new PluginException(InvoicePlugin.class.getName(), ERROR_BUSINESSPARTNER_VERIFICATION,
|
throw new PluginException(InvoicePlugin.class.getName(), ERROR_BUSINESSPARTNER_VERIFICATION,
|
||||||
"Businesspartner is in verification. Invoice can't be processed!");
|
"Businesspartner is in verification. Invoice can't be processed!");
|
||||||
}
|
}
|
||||||
if (businessPartner.getTaskID() == TASK_LOCKED) {
|
if (businessPartner.getTaskID() == TASK_LOCKED && updateWhenLocked) {
|
||||||
throw new PluginException(InvoicePlugin.class.getName(), ERROR_BUSINESSPARTNER_LOCKED,
|
throw new PluginException(InvoicePlugin.class.getName(), ERROR_BUSINESSPARTNER_LOCKED,
|
||||||
"Businesspartner is locked. Invoice can't be processed!");
|
"Businesspartner is locked. Invoice can't be processed!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import jakarta.inject.Inject;
|
||||||
* Das InvoiceOutgoingPlugin aktualisiert die Debitor E-Mail Adresse
|
* Das InvoiceOutgoingPlugin aktualisiert die Debitor E-Mail Adresse
|
||||||
*
|
*
|
||||||
* Auch das feld _img wird in Abhängigkeit vom item 'invoice.protest' gesetzt
|
* Auch das feld _img wird in Abhängigkeit vom item 'invoice.protest' gesetzt
|
||||||
|
*
|
||||||
|
* Das Plugin ignoriert den Status des Business Partners.
|
||||||
*
|
*
|
||||||
* @author rsoika
|
* @author rsoika
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
|
|
@ -29,7 +31,7 @@ public class InvoiceOutgoingPlugin extends AbstractPlugin {
|
||||||
public ItemCollection run(ItemCollection workitem, ItemCollection event) throws PluginException {
|
public ItemCollection run(ItemCollection workitem, ItemCollection event) throws PluginException {
|
||||||
|
|
||||||
// Update BUsiness Partner Data
|
// Update BUsiness Partner Data
|
||||||
businessPartnerService.updateBusinessPartnerData(workitem);
|
businessPartnerService.updateBusinessPartnerData(workitem, true, true);
|
||||||
|
|
||||||
// Update Invoice.positions
|
// Update Invoice.positions
|
||||||
InvoiceUtil.updateInvoicePositions(workitem);
|
InvoiceUtil.updateInvoicePositions(workitem);
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,10 @@ import jakarta.inject.Inject;
|
||||||
* 26.4.25 - Das Plugin setzt nun auch partner.name und partner.id zusätzlich
|
* 26.4.25 - Das Plugin setzt nun auch partner.name und partner.id zusätzlich
|
||||||
* processed es das BP Workitem
|
* processed es das BP Workitem
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* Das Plugin prüft den Status des Business Partners und wirft eine Exception
|
||||||
|
* wenn dieser in Verification oder Locked ist.
|
||||||
|
*
|
||||||
* @author rsoika
|
* @author rsoika
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*
|
*
|
||||||
|
|
@ -83,7 +87,7 @@ public class InvoicePlugin extends AbstractPlugin {
|
||||||
public ItemCollection run(ItemCollection workitem, ItemCollection event) throws PluginException {
|
public ItemCollection run(ItemCollection workitem, ItemCollection event) throws PluginException {
|
||||||
|
|
||||||
// Update BUsiness Partner Data
|
// Update BUsiness Partner Data
|
||||||
ItemCollection businessPartner = businessPartnerService.updateBusinessPartnerData(workitem);
|
ItemCollection businessPartner = businessPartnerService.updateBusinessPartnerData(workitem, false, false);
|
||||||
|
|
||||||
updateImg(workitem);
|
updateImg(workitem);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue