creating new customer settings if required

This commit is contained in:
2025-10-07 11:43:11 +02:00
parent 6976b20ebe
commit 3f1c17e7c0
3 changed files with 7 additions and 3 deletions

View File

@@ -488,6 +488,7 @@ public class DocumentApi extends BaseHandler implements DocumentService {
String currency = company.currency();
String sep = company.decimalSeparator();
var settings = db.getCustomerSettings(companyId.longValue(),type,customer.id());
if (settings == null) settings = CustomerSettings.empty();
var companySettings = db.getCompanySettings(companyId.longValue(),type);
var nextNumber = companySettings.nextDocId();
String lastHead = settings.header();

View File

@@ -285,13 +285,12 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
CustomerSettings settings = null;
if (rs.next()) settings = CustomerSettings.of(rs);
rs.close();
if (settings != null) return settings;
return settings;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load customer settings (company: {0}, document type: {1}",companyId, docType.name(),e);
}
throw new UmbrellaException(500,"Failed to load customer settings (company: {0}, document type: {1}",companyId, docType.name());
}
}
@Override
public Type getType(int typeId) throws UmbrellaException {

View File

@@ -18,6 +18,10 @@ public record CustomerSettings(String header, String footer, String mailText) im
return new CustomerSettings(header,footer,mailText);
}
public static CustomerSettings empty() {
return new CustomerSettings("","","");
}
@Override
public Map<String, Object> toMap() {
return Map.of(FIELD_FOOTER,footer,FIELD_HEAD,header,CONTENT,mailText);