zoho currency and taxes

This commit is contained in:
Ralph Soika 2025-06-16 12:46:05 +02:00
parent 177d75c13a
commit 9de6a9fe23
8 changed files with 2360 additions and 166 deletions

View file

@ -10,7 +10,6 @@ import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -140,67 +139,6 @@ public class ZohoAPIService {
} }
/**
* This finder method returns the tax ID to a given percentage.
* The method returns null if no tax with this percentage exists
*
* @param tax_percentage
* @param accessToken
* @return taxID
* @throws PluginException
*/
public String findTaxIDByPercentage(float tax_percentage, String accessToken)
throws PluginException {
if (tax_percentage == 0.0) {
return null;
}
// Print JSON to console for verification
logger.info("├── Zoho lookup tax '" + tax_percentage + "'...");
try {
// https://www.zohoapis.com/books/v3/settings/taxes?organization_id=10234695&company_name=xxx'
String uri = zohoOAuthManager.getBaseURI() + "settings/taxes?organization_id="
+ zohoOAuthManager.getOrganization();
logger.fine("│ ├── uri= " + uri);
logger.fine("│ ├── accessToken=" + accessToken);
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(uri))
.header("Authorization", "Zoho-oauthtoken " + accessToken)
.header("Content-Type", "application/json").GET().build();
HttpResponse<String> response;
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Print response details to console
logger.fine("├── Zoho Response:");
logger.fine("│ ├── Status Code: " + response.statusCode());
logger.fine("│ ├── Response Body: " + response.body());
if (response.statusCode() >= 300) {
throw new PluginException(this.getClass().getName(), "Zoho API error",
"Failed to find Contacts - Status code: " + response.statusCode() + ", Response: "
+ response.body());
}
ZohoTaxListResponse taxListResponse = jsonb.fromJson(response.body(), ZohoTaxListResponse.class);
if (taxListResponse != null && taxListResponse.getTaxes() != null) {
// Durchsuche die Ergebnisse nach exakter Übereinstimmung
for (ZohoTax tax : taxListResponse.getTaxes()) {
if (tax_percentage == tax.getRate()) {
logger.info("│ ├── taxID= " + tax.getTaxId());
return tax.getTaxId();
}
}
}
logger.warning("│ ├── No tax with " + tax_percentage + "% found in Zoho taxes!");
} catch (IOException | InterruptedException e) {
throw new PluginException(this.getClass().getName(), "Zoho API error",
"Failed to find tax: " + e.getMessage());
}
return null;
}
/** /**
* Exports an invocie document * Exports an invocie document
* *
@ -213,8 +151,10 @@ public class ZohoAPIService {
throws PluginException { throws PluginException {
logger.info("├── Zoho Export Invoice " + invoice.getItemValueString("invoice.number") + "..."); logger.info("├── Zoho Export Invoice " + invoice.getItemValueString("invoice.number") + "...");
String currencyID = lookupCurrency(invoice.getItemValueString("invoice.currency"), accessToken);
// Konvertiere ItemCollection zu ZohoInvoiceDTO // Konvertiere ItemCollection zu ZohoInvoiceDTO
ZohoInvoice zohoInvoice = convertToZohoInvoice(invoice, contactID); ZohoInvoice zohoInvoice = convertToZohoInvoice(invoice, contactID, currencyID);
try { try {
String requestBody = jsonb.toJson(zohoInvoice); String requestBody = jsonb.toJson(zohoInvoice);
@ -284,8 +224,10 @@ public class ZohoAPIService {
String accessToken) throws PluginException { String accessToken) throws PluginException {
logger.info("├── Zoho Export creditnote " + invoice.getItemValueString("invoice.number") + "..."); logger.info("├── Zoho Export creditnote " + invoice.getItemValueString("invoice.number") + "...");
String currencyID = lookupCurrency(invoice.getItemValueString("invoice.currency"), accessToken);
// Konvertiere ItemCollection zu ZohoInvoiceDTO // Konvertiere ItemCollection zu ZohoInvoiceDTO
ZohoCreditnote zohoCreditnote = convertToZohoCreditnote(invoice, contactID); ZohoCreditnote zohoCreditnote = convertToZohoCreditnote(invoice, contactID, currencyID);
try { try {
String requestBody = jsonb.toJson(zohoCreditnote); String requestBody = jsonb.toJson(zohoCreditnote);
@ -354,8 +296,10 @@ public class ZohoAPIService {
String accessToken) throws PluginException { String accessToken) throws PluginException {
logger.info("├── Zoho Export Bill " + invoice.getItemValueString("invoice.number") + "..."); logger.info("├── Zoho Export Bill " + invoice.getItemValueString("invoice.number") + "...");
String currencyID = lookupCurrency(invoice.getItemValueString("invoice.currency"), accessToken);
// Konvertiere ItemCollection zu ZohoInvoiceDTO // Konvertiere ItemCollection zu ZohoInvoiceDTO
ZohoBill zohoBill = convertToZohoBill(invoice, contactID, accountID); ZohoBill zohoBill = convertToZohoBill(invoice, contactID, accountID, currencyID);
try { try {
String requestBody = jsonb.toJson(zohoBill); String requestBody = jsonb.toJson(zohoBill);
@ -422,8 +366,10 @@ public class ZohoAPIService {
String accessToken) throws PluginException { String accessToken) throws PluginException {
logger.info("├── Zoho Export VendorCredit " + invoice.getItemValueString("invoice.number") + "..."); logger.info("├── Zoho Export VendorCredit " + invoice.getItemValueString("invoice.number") + "...");
String currencyID = lookupCurrency(invoice.getItemValueString("invoice.currency"), accessToken);
// Konvertiere ItemCollection zu ZohoInvoiceDTO // Konvertiere ItemCollection zu ZohoInvoiceDTO
ZohoVendorCredit zohoVendorCredit = convertToZohoVendorCredit(invoice, contactID, accountID); ZohoVendorCredit zohoVendorCredit = convertToZohoVendorCredit(invoice, contactID, accountID, currencyID);
try { try {
String requestBody = jsonb.toJson(zohoVendorCredit); String requestBody = jsonb.toJson(zohoVendorCredit);
@ -480,18 +426,6 @@ public class ZohoAPIService {
} }
public String lookupContact(String companyName, String contactType, String accessToken) throws PluginException {
// first lookup contact!
String contactID = "";
contactID = findContactIDByCompanyName(companyName, contactType, accessToken);
if (contactID == null) {
logger.info("│ ├── contact '" + companyName + "' not found");
ZohoContact contact = createContact(companyName, contactType, accessToken);
contactID = contact.getContactId();
}
return contactID;
}
/** /**
* Erstellt einen neuen Contact in Zoho Books * Erstellt einen neuen Contact in Zoho Books
* *
@ -500,7 +434,7 @@ public class ZohoAPIService {
* @return Der erstellte ZohoContact mit contact_id * @return Der erstellte ZohoContact mit contact_id
* @throws PluginException Wenn der API-Aufruf fehlschlägt * @throws PluginException Wenn der API-Aufruf fehlschlägt
*/ */
public ZohoContact createContact(String companyName, String contactType, String accessToken) public ZohoContact createContact(String companyName, String contactType, String currencyID, String accessToken)
throws PluginException { throws PluginException {
logger.info("├── Zoho create contact '" + companyName + "'..."); logger.info("├── Zoho create contact '" + companyName + "'...");
try { try {
@ -510,6 +444,11 @@ public class ZohoAPIService {
newContact.setCompanyName(companyName); newContact.setCompanyName(companyName);
newContact.setContactType(contactType); newContact.setContactType(contactType);
// set currency?
if (currencyID != null && !currencyID.isEmpty()) {
newContact.setCurrencyId(currencyID);
}
// JSON serialisieren // JSON serialisieren
String requestBody = jsonb.toJson(newContact); String requestBody = jsonb.toJson(newContact);
logger.fine("│ ├── " + requestBody); logger.fine("│ ├── " + requestBody);
@ -548,7 +487,16 @@ public class ZohoAPIService {
} }
private ZohoInvoice convertToZohoInvoice(ItemCollection invoice, String contactID) /**
* Ausgangsrechnung
*
* @param invoice
* @param contactID
* @param currencyID
* @return
* @throws PluginException
*/
private ZohoInvoice convertToZohoInvoice(ItemCollection invoice, String contactID, String currencyID)
throws PluginException { throws PluginException {
ZohoInvoice zohoInvoice = new ZohoInvoice(); ZohoInvoice zohoInvoice = new ZohoInvoice();
@ -562,39 +510,45 @@ public class ZohoAPIService {
zohoInvoice.setCustomerId(contactID); zohoInvoice.setCustomerId(contactID);
// convert total by rate // set currency?
zohoInvoice.setTotal(convertInvoiceTotalToAED(invoice, invoice.getItemValueDouble("invoice.total"))); if (currencyID != null && !currencyID.isEmpty()) {
zohoInvoice.setCurrencyId(currencyID);
}
/* // convert total by rate
* Change: 10.06.2025 zohoInvoice.setTotal(invoice.getItemValueDouble("invoice.total"));
* Das Cargosoft unlogische Positionen sendet, ZOHO diese aber erzwingt, // set exchange Rate
* erzeugen wir nur noch eine einzige Zeile mit dem tatsächlichen Betrag! double exchangeRate = invoice.getItemValueDouble("invoice.rate");
* if (exchangeRate != 0.0) {
*/ zohoInvoice.setExchangeRate(exchangeRate);
// List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice); }
// List<ZohoInvoiceItem> lineItems = positionen.stream().map(item -> {
// ItemCollection itemCol = (ItemCollection) item; // add line items...
// ZohoInvoiceItem lineItem = new ZohoInvoiceItem(); List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice);
// lineItem.setName(itemCol.getItemValueString("datev.text")); List<ZohoInvoiceItem> lineItems = positionen.stream().map(item -> {
// lineItem.setDescription(itemCol.getItemValueString("billingtext")); ItemCollection itemCol = (ItemCollection) item;
// lineItem.setRate(convertInvoiceTotalToAED(invoice, ZohoInvoiceItem lineItem = new ZohoInvoiceItem();
// itemCol.getItemValueDouble("datev.umsatz"))); lineItem.setName(itemCol.getItemValueString("datev.text"));
// lineItem.setQuantity(1); lineItem.setDescription(itemCol.getItemValueString("billingtext"));
// return lineItem; lineItem.setRate(itemCol.getItemValueDouble("datev.umsatz"));
// }).collect(Collectors.toList()); lineItem.setQuantity(1);
List<ZohoInvoiceItem> lineItems = new ArrayList<>(); return lineItem;
ZohoInvoiceItem lineItem = new ZohoInvoiceItem(); }).collect(Collectors.toList());
lineItem.setName(invoice.getItemValueString("invoice.text"));
lineItem.setDescription("");
lineItem.setRate(convertInvoiceTotalToAED(invoice, invoice.getItemValueDouble("invoice.total")));
lineItem.setQuantity(1);
lineItems.add(lineItem);
zohoInvoice.setLineItems(lineItems); zohoInvoice.setLineItems(lineItems);
return zohoInvoice; return zohoInvoice;
} }
private ZohoCreditnote convertToZohoCreditnote(ItemCollection invoice, String contactID) /**
* Gutschrift Ausgang
*
* @param invoice
* @param contactID
* @param currencyID
* @return
* @throws PluginException
*/
private ZohoCreditnote convertToZohoCreditnote(ItemCollection invoice, String contactID, String currencyID)
throws PluginException { throws PluginException {
ZohoCreditnote zohoCreditnote = new ZohoCreditnote(); ZohoCreditnote zohoCreditnote = new ZohoCreditnote();
@ -608,35 +562,29 @@ public class ZohoAPIService {
zohoCreditnote.setCustomerId(contactID); zohoCreditnote.setCustomerId(contactID);
// convert total by rate - negativer betrag! // set currency?
zohoCreditnote if (currencyID != null && !currencyID.isEmpty()) {
.setTotal(convertInvoiceTotalToAED(invoice, Math.abs(invoice.getItemValueDouble("invoice.total")))); zohoCreditnote.setCurrencyId(currencyID);
}
/* // convert total by rate - negativer betrag!
* Change: 10.06.2025 zohoCreditnote.setTotal(Math.abs(invoice.getItemValueDouble("invoice.total")));
* Das Cargosoft unlogische Positionen sendet, ZOHO diese aber erzwingt, // set exchange Rate
* erzeugen wir nur noch eine einzige Zeile mit dem tatsächlichen Betrag! double exchangeRate = invoice.getItemValueDouble("invoice.rate");
* if (exchangeRate != 0.0) {
*/ zohoCreditnote.setExchangeRate(exchangeRate);
// List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice); }
// List<ZohoInvoiceItem> lineItems = positionen.stream().map(item -> {
// ItemCollection itemCol = (ItemCollection) item; List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice);
// ZohoInvoiceItem lineItem = new ZohoInvoiceItem(); List<ZohoInvoiceItem> lineItems = positionen.stream().map(item -> {
// lineItem.setName(itemCol.getItemValueString("datev.text")); ItemCollection itemCol = (ItemCollection) item;
// lineItem.setDescription(itemCol.getItemValueString("billingtext")); ZohoInvoiceItem lineItem = new ZohoInvoiceItem();
// lineItem.setRate(convertInvoiceTotalToAED(invoice, lineItem.setName(itemCol.getItemValueString("datev.text"));
// itemCol.getItemValueDouble("datev.umsatz"))); lineItem.setDescription(itemCol.getItemValueString("billingtext"));
// lineItem.setQuantity(1); lineItem.setRate(itemCol.getItemValueDouble("datev.umsatz"));
// return lineItem; lineItem.setQuantity(1);
// }).collect(Collectors.toList()); return lineItem;
List<ZohoInvoiceItem> lineItems = new ArrayList<>(); }).collect(Collectors.toList());
ZohoInvoiceItem lineItem = new ZohoInvoiceItem();
lineItem.setName(invoice.getItemValueString("invoice.text"));
lineItem.setDescription("");
// negativer Betrag!
lineItem.setRate(convertInvoiceTotalToAED(invoice, Math.abs(invoice.getItemValueDouble("invoice.total"))));
lineItem.setQuantity(1);
lineItems.add(lineItem);
zohoCreditnote.setLineItems(lineItems); zohoCreditnote.setLineItems(lineItems);
return zohoCreditnote; return zohoCreditnote;
@ -645,8 +593,8 @@ public class ZohoAPIService {
/** /**
* Diese Hilfsmethode rechnet den Rechnungsbetrag in Fremdwährung auf AED um * Diese Hilfsmethode rechnet den Rechnungsbetrag in Fremdwährung auf AED um
* *
* es ist eine Fremdwährung *
* Herr Heolzl 15.05.2025 * Herr Hoelzl 15.05.2025
* However the backend reports the P&L & Balance sheet will reflect in AED as * However the backend reports the P&L & Balance sheet will reflect in AED as
* AGL Dubai books are maintained in AED therefore we need to have an * AGL Dubai books are maintained in AED therefore we need to have an
* exchange rate which can be fixed @3.6725 AED for 1 USD. * exchange rate which can be fixed @3.6725 AED for 1 USD.
@ -655,7 +603,8 @@ public class ZohoAPIService {
* *
* @return * @return
*/ */
public double convertInvoiceTotalToAED(ItemCollection invoice, double total) { @Deprecated
public double xxxxconvertInvoiceTotalToAED(ItemCollection invoice, double total) {
// convert total by fixed rate? // convert total by fixed rate?
String currency = invoice.getItemValueString("invoice.currency"); String currency = invoice.getItemValueString("invoice.currency");
if (!currency.isEmpty() && !currency.equalsIgnoreCase("AED")) { if (!currency.isEmpty() && !currency.equalsIgnoreCase("AED")) {
@ -687,20 +636,30 @@ public class ZohoAPIService {
} }
} }
private ZohoBill convertToZohoBill(ItemCollection invoice, String contactID, String accountID) private ZohoBill convertToZohoBill(ItemCollection invoice, String contactID, String accountID, String currencyID)
throws PluginException { throws PluginException {
ZohoBill zohoBill = new ZohoBill(); ZohoBill zohoBill = new ZohoBill();
// Basisinformationen
// Kunden-ID (muss angepasst werden je nachdem wie du sie speicherst)
zohoBill.setVendorId(contactID);
// set currency?
if (currencyID != null && !currencyID.isEmpty()) {
zohoBill.setCurrencyId(currencyID);
}
// Basisinformationen
zohoBill.setInvoiceNumber(invoice.getItemValueString("invoice.number")); zohoBill.setInvoiceNumber(invoice.getItemValueString("invoice.number"));
zohoBill.setDate( zohoBill.setDate(
LocalDate.ofInstant(invoice.getItemValueDate("invoice.date").toInstant(), ZoneId.systemDefault())); LocalDate.ofInstant(invoice.getItemValueDate("invoice.date").toInstant(), ZoneId.systemDefault()));
// convert total by rate // convert total by rate
zohoBill.setAmount(convertInvoiceTotalToAED(invoice, invoice.getItemValueDouble("invoice.total"))); // zohoBill.setAmount(invoice.getItemValueDouble("invoice.total"));
// Kunden-ID (muss angepasst werden je nachdem wie du sie speicherst) // set exchange Rate
zohoBill.setVendorId(contactID); double exchangeRate = invoice.getItemValueDouble("invoice.exchangerate");
if (exchangeRate != 0.0) {
zohoBill.setExchangeRate(exchangeRate);
}
// zohoBill.setPaid_through_account_id("1700"); // zohoBill.setPaid_through_account_id("1700");
List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice); List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice);
@ -712,12 +671,12 @@ public class ZohoAPIService {
lineItem.setName(itemCol.getItemValueString("name")); lineItem.setName(itemCol.getItemValueString("name"));
lineItem.setAccountId(accountID); lineItem.setAccountId(accountID);
lineItem.setQuantity(1); lineItem.setQuantity(1);
lineItem.setRate(convertInvoiceTotalToAED(invoice, itemCol.getItemValueDouble("amount"))); lineItem.setRate(itemCol.getItemValueDouble("amount"));
// tax - tax_id, tax_percentage // tax - tax_id, tax_percentage
try { try {
float tax = itemCol.getItemValueFloat("tax"); float tax = itemCol.getItemValueFloat("tax");
String taxID = findTaxIDByPercentage(tax, accountID); String taxID = lookupTaxID(tax, accountID);
if (taxID != null && !taxID.isEmpty()) { if (taxID != null && !taxID.isEmpty()) {
lineItem.setTaxId(taxID); lineItem.setTaxId(taxID);
} }
@ -732,7 +691,8 @@ public class ZohoAPIService {
return zohoBill; return zohoBill;
} }
private ZohoVendorCredit convertToZohoVendorCredit(ItemCollection invoice, String contactID, String accountID) private ZohoVendorCredit convertToZohoVendorCredit(ItemCollection invoice, String contactID,
String accountID, String currencyID)
throws PluginException { throws PluginException {
ZohoVendorCredit zohoVendorCredit = new ZohoVendorCredit(); ZohoVendorCredit zohoVendorCredit = new ZohoVendorCredit();
@ -748,6 +708,17 @@ public class ZohoAPIService {
// Kunden-ID (muss angepasst werden je nachdem wie du sie speicherst) // Kunden-ID (muss angepasst werden je nachdem wie du sie speicherst)
zohoVendorCredit.setVendorId(contactID); zohoVendorCredit.setVendorId(contactID);
// set currency?
if (currencyID != null && !currencyID.isEmpty()) {
zohoVendorCredit.setCurrencyId(currencyID);
}
// set exchange Rate
double exchangeRate = invoice.getItemValueDouble("invoice.exchangerate");
if (exchangeRate != 0.0) {
zohoVendorCredit.setExchangeRate(exchangeRate);
}
// zohoBill.setPaid_through_account_id("1700"); // zohoBill.setPaid_through_account_id("1700");
List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice); List<ItemCollection> positionen = InvoiceUtil.explodeChildList(invoice);
// {amount=[11825.00], total=[11825.00], numpos=[1], name=[AB-DEFGHI-1234-567], // {amount=[11825.00], total=[11825.00], numpos=[1], name=[AB-DEFGHI-1234-567],
@ -758,12 +729,12 @@ public class ZohoAPIService {
lineItem.setName(itemCol.getItemValueString("name")); lineItem.setName(itemCol.getItemValueString("name"));
lineItem.setAccountId(accountID); lineItem.setAccountId(accountID);
lineItem.setQuantity(1); lineItem.setQuantity(1);
lineItem.setRate(convertInvoiceTotalToAED(invoice, itemCol.getItemValueDouble("amount"))); lineItem.setRate(itemCol.getItemValueDouble("amount"));
// tax - tax_id, tax_percentage // tax - tax_id, tax_percentage
try { try {
float tax = itemCol.getItemValueFloat("tax"); float tax = itemCol.getItemValueFloat("tax");
String taxID = findTaxIDByPercentage(tax, accountID); String taxID = lookupTaxID(tax, accountID);
if (taxID != null && !taxID.isEmpty()) { if (taxID != null && !taxID.isEmpty()) {
lineItem.setTaxId(taxID); lineItem.setTaxId(taxID);
} }
@ -890,8 +861,8 @@ public class ZohoAPIService {
} }
/** /**
* Sucht eine currency ID Wegen eifnachheit parsen wir hier direkt die JSON * Sucht eine currency ID. Die Methode läd die Liste aller Currencies und parsed
* struktur * the currency ID mit einer Regex
* *
* @param currency * @param currency
* @param accessToken * @param accessToken
@ -903,7 +874,7 @@ public class ZohoAPIService {
// Print JSON to console for verification // Print JSON to console for verification
logger.info("├── Zoho lookup currency '" + currency + "'..."); logger.info("├── Zoho lookup currency '" + currency + "'...");
try { try {
// https://www.zohoapis.com/books/v3/contacts?organization_id=10234695&company_name=xxx' // https://www.zohoapis.com/books/v3/currencies?organization_id=10234695'
String uri = zohoOAuthManager.getBaseURI() + "settings/currencies?organization_id=" String uri = zohoOAuthManager.getBaseURI() + "settings/currencies?organization_id="
+ zohoOAuthManager.getOrganization(); + zohoOAuthManager.getOrganization();
logger.fine("│ ├── uri= " + uri); logger.fine("│ ├── uri= " + uri);
@ -936,9 +907,94 @@ public class ZohoAPIService {
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
throw new PluginException(this.getClass().getName(), "Zoho API error", throw new PluginException(this.getClass().getName(), "Zoho API error",
"Failed to find Contacts: " + e.getMessage()); "Failed to find currency: " + e.getMessage());
} }
} }
/**
* This method lookups a Contact by name.
* If no contact with the given name exists, the method creats a new one. In
* this case the defaultCurrencyID is mandatory!
*
* @param companyName
* @param contactType
* @param defaultCurrencyID
* @param accessToken
* @return
* @throws PluginException
*/
public String lookupContact(String companyName, String contactType, String defaultCurrencyID, String accessToken)
throws PluginException {
// first lookup contact!
String contactID = "";
contactID = findContactIDByCompanyName(companyName, contactType, accessToken);
if (contactID == null) {
logger.info("│ ├── contact '" + companyName + "' not found");
ZohoContact contact = createContact(companyName, contactType, defaultCurrencyID, accessToken);
contactID = contact.getContactId();
}
return contactID;
}
/**
* This finder method returns the tax ID to a given percentage.
* The method returns null if no tax with this percentage exists
*
* @param tax_percentage
* @param accessToken
* @return taxID
* @throws PluginException
*/
public String lookupTaxID(float tax_percentage, String accessToken)
throws PluginException {
if (tax_percentage == 0.0) {
return null;
}
// Print JSON to console for verification
logger.info("├── Zoho lookup tax '" + tax_percentage + "'...");
try {
// https://www.zohoapis.com/books/v3/settings/taxes?organization_id=10234695'
String uri = zohoOAuthManager.getBaseURI() + "settings/taxes?organization_id="
+ zohoOAuthManager.getOrganization();
logger.fine("│ ├── uri= " + uri);
logger.fine("│ ├── accessToken=" + accessToken);
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(uri))
.header("Authorization", "Zoho-oauthtoken " + accessToken)
.header("Content-Type", "application/json").GET().build();
HttpResponse<String> response;
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Print response details to console
logger.fine("├── Zoho Response:");
logger.fine("│ ├── Status Code: " + response.statusCode());
logger.fine("│ ├── Response Body: " + response.body());
if (response.statusCode() >= 300) {
throw new PluginException(this.getClass().getName(), "Zoho API error",
"Failed to find Contacts - Status code: " + response.statusCode() + ", Response: "
+ response.body());
}
ZohoTaxListResponse taxListResponse = jsonb.fromJson(response.body(), ZohoTaxListResponse.class);
if (taxListResponse != null && taxListResponse.getTaxes() != null) {
// Durchsuche die Ergebnisse nach exakter Übereinstimmung
for (ZohoTax tax : taxListResponse.getTaxes()) {
if (tax_percentage == tax.getRate()) {
logger.info("│ ├── taxID= " + tax.getTaxId());
return tax.getTaxId();
}
}
}
logger.warning("│ ├── No tax with " + tax_percentage + "% found in Zoho taxes!");
} catch (IOException | InterruptedException e) {
throw new PluginException(this.getClass().getName(), "Zoho API error",
"Failed to find tax: " + e.getMessage());
}
return null;
}
} }

View file

@ -85,12 +85,14 @@ public class ZohoExportAdapter implements SignalAdapter {
* @throws PluginException * @throws PluginException
*/ */
private void exportRechnungsausgang(ItemCollection document, String accessToken) throws PluginException { private void exportRechnungsausgang(ItemCollection document, String accessToken) throws PluginException {
// find currencyID
String currencyID = zohoAPIService.lookupCurrency(document.getItemValueString("invoice.currency"), accessToken);
// find companyID // find companyID
String contactID = zohoAPIService.lookupContact(document.getItemValueString("dbtr.name"), "customer", String contactID = zohoAPIService.lookupContact(document.getItemValueString("dbtr.name"), "customer",
currencyID,
accessToken); accessToken);
// String currencyID =
// zohoAPIService.lookupCurrency(document.getItemValueString("invoice.currency"),
// accessToken);
// Gutschrift?? // Gutschrift??
if (document.getItemValueDouble("invoice.total") < 0) { if (document.getItemValueDouble("invoice.total") < 0) {
@ -142,13 +144,13 @@ public class ZohoExportAdapter implements SignalAdapter {
* @throws PluginException * @throws PluginException
*/ */
private void exportRechnungseingang(ItemCollection document, String accessToken) throws PluginException { private void exportRechnungseingang(ItemCollection document, String accessToken) throws PluginException {
String currencyID = zohoAPIService.lookupCurrency(document.getItemValueString("invoice.currency"), accessToken);
// find companyID // find companyID
String contactID = zohoAPIService.lookupContact(document.getItemValueString("cdtr.name"), "vendor", String contactID = zohoAPIService.lookupContact(document.getItemValueString("cdtr.name"), "vendor", currencyID,
accessToken); accessToken);
// String currencyID =
// zohoAPIService.lookupCurrency(document.getItemValueString("invoice.currency"),
// accessToken);
String accountID = zohoOAuthManager.getAccountId(); String accountID = zohoOAuthManager.getAccountId();
// Gutschrift?? // Gutschrift??

View file

@ -30,7 +30,10 @@ public class ZohoBill {
@JsonbProperty("line_items") @JsonbProperty("line_items")
private List<ZohoBillItem> lineItems; private List<ZohoBillItem> lineItems;
private double amount; @JsonbProperty("exchange_rate")
private double exchangeRate;
// private double amount;
// Getter und Setter // Getter und Setter
@ -82,13 +85,13 @@ public class ZohoBill {
this.lineItems = lineItems; this.lineItems = lineItems;
} }
public double getAmount() { // public double getAmount() {
return amount; // return amount;
} // }
public void setAmount(double amount) { // public void setAmount(double amount) {
this.amount = amount; // this.amount = amount;
} // }
public String getCurrencyId() { public String getCurrencyId() {
return currencyId; return currencyId;
@ -98,4 +101,12 @@ public class ZohoBill {
this.currencyId = currencyId; this.currencyId = currencyId;
} }
public double getExchangeRate() {
return exchangeRate;
}
public void setExchangeRate(double exchangeRate) {
this.exchangeRate = exchangeRate;
}
} }

View file

@ -16,6 +16,9 @@ public class ZohoContact {
@JsonbProperty("contact_type") @JsonbProperty("contact_type")
private String contactType; private String contactType;
@JsonbProperty("currency_id")
private String currencyId;
// Weitere Felder nach Bedarf // Weitere Felder nach Bedarf
// Getter und Setter // Getter und Setter
@ -51,4 +54,12 @@ public class ZohoContact {
this.contactType = contactType; this.contactType = contactType;
} }
public String getCurrencyId() {
return currencyId;
}
public void setCurrencyId(String currencyId) {
this.currencyId = currencyId;
}
} }

View file

@ -29,6 +29,9 @@ public class ZohoCreditnote {
@JsonbProperty("line_items") @JsonbProperty("line_items")
private List<ZohoInvoiceItem> lineItems; private List<ZohoInvoiceItem> lineItems;
@JsonbProperty("exchange_rate")
private double exchangeRate;
private double total; private double total;
// Getter und Setter // Getter und Setter
@ -96,4 +99,12 @@ public class ZohoCreditnote {
public void setCurrencyId(String currencyId) { public void setCurrencyId(String currencyId) {
this.currencyId = currencyId; this.currencyId = currencyId;
} }
public double getExchangeRate() {
return exchangeRate;
}
public void setExchangeRate(double exchangeRate) {
this.exchangeRate = exchangeRate;
}
} }

View file

@ -30,6 +30,9 @@ public class ZohoInvoice {
@JsonbProperty("line_items") @JsonbProperty("line_items")
private List<ZohoInvoiceItem> lineItems; private List<ZohoInvoiceItem> lineItems;
@JsonbProperty("exchange_rate")
private double exchangeRate;
private double total; private double total;
// Getter und Setter // Getter und Setter
@ -97,4 +100,12 @@ public class ZohoInvoice {
public void setCurrencyId(String currencyId) { public void setCurrencyId(String currencyId) {
this.currencyId = currencyId; this.currencyId = currencyId;
} }
public double getExchangeRate() {
return exchangeRate;
}
public void setExchangeRate(double exchangeRate) {
this.exchangeRate = exchangeRate;
}
} }

View file

@ -23,6 +23,9 @@ public class ZohoVendorCredit {
@JsonbProperty("vendor_credit_number") @JsonbProperty("vendor_credit_number")
private String invoiceNumber; private String invoiceNumber;
@JsonbProperty("exchange_rate")
private double exchangeRate;
@JsonbProperty("line_items") @JsonbProperty("line_items")
private List<ZohoBillItem> lineItems; private List<ZohoBillItem> lineItems;
@ -76,4 +79,12 @@ public class ZohoVendorCredit {
this.currencyId = currencyId; this.currencyId = currencyId;
} }
public double getExchangeRate() {
return exchangeRate;
}
public void setExchangeRate(double exchangeRate) {
this.exchangeRate = exchangeRate;
}
} }

File diff suppressed because it is too large Load diff