use of com.axelor.apps.base.db.Country in project axelor-open-suite by axelor.
the class ConvertLeadWizardService method createPrimaryAddress.
@SuppressWarnings("unchecked")
public Address createPrimaryAddress(Map<String, Object> context) {
Map<String, Object> leadContext = (Map<String, Object>) context.get("_lead");
Lead lead = Beans.get(LeadRepository.class).find(((Integer) leadContext.get("id")).longValue());
String addressL4 = lead.getPrimaryAddress();
if (addressL4 == null) {
return null;
}
String addressL5 = lead.getPrimaryState() != null ? lead.getPrimaryState().getName() : null;
String addressL6 = lead.getPrimaryPostalCode() + " " + (lead.getPrimaryCity() != null ? lead.getPrimaryCity().getName() : "");
Country addressL7Country = lead.getPrimaryCountry();
Address address = addressService.getAddress(null, null, addressL4, addressL5, addressL6, addressL7Country);
if (address == null) {
address = addressService.createAddress(null, null, addressL4, addressL5, addressL6, addressL7Country);
}
return address;
}
use of com.axelor.apps.base.db.Country in project axelor-open-suite by axelor.
the class SyncContactService method createCountry.
protected Country createCountry(String googleCountry, String googleCountryCode) {
Country country = new Country();
country.setAlpha2Code(googleCountryCode);
country.setName(googleCountry);
country.setImportOrigin(importOrigin);
return countryRepo.save(country);
}
use of com.axelor.apps.base.db.Country in project axelor-open-suite by axelor.
the class SyncContactService method createAddress.
protected Address createAddress(com.google.api.services.people.v1.model.Address googleAddr) {
Address partnerAddr = new Address();
Country partnerCountry = countryRepo.findByName(googleAddr.getCountry());
if (partnerCountry == null) {
partnerCountry = createCountry(googleAddr.getCountry(), googleAddr.getCountryCode());
}
partnerAddr.setAddressL7Country(partnerCountry);
if (!Strings.isNullOrEmpty(googleAddr.getCity())) {
City partnerCity = cityRepo.findByName(googleAddr.getCity());
if (partnerCity == null) {
partnerCity = createCity(googleAddr.getCity(), partnerCountry);
}
partnerAddr.setCity(partnerCity);
}
StringBuilder addrL4 = new StringBuilder();
if (!Strings.isNullOrEmpty(googleAddr.getPoBox())) {
addrL4.append(googleAddr.getPoBox()).append(" - ");
}
partnerAddr.setZip(googleAddr.getPostalCode());
addrL4.append(googleAddr.getStreetAddress());
partnerAddr.setAddressL4(addrL4.toString());
partnerAddr.setAddressL5(googleAddr.getCity());
partnerAddr.setAddressL2(googleAddr.getExtendedAddress());
partnerAddr.setAddressL6(googleAddr.getPostalCode() + " " + googleAddr.getCity());
partnerAddr.setFullName(Beans.get(AddressService.class).computeFullName(partnerAddr));
partnerAddr.setImportOrigin(importOrigin);
return partnerAddr;
}
use of com.axelor.apps.base.db.Country in project axelor-open-suite by axelor.
the class ImportBank method setCountry.
@Transactional(rollbackOn = Exception.class)
public Object setCountry(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof Bank;
Bank bank = (Bank) bean;
String code = (String) values.get("code");
String codeCountry = code.substring(4, 6);
Country country = countryRepository.all().filter("self.alpha2Code = :codeCountry").bind("codeCountry", codeCountry).fetchOne();
if (country != null) {
bank.setCountry(country);
}
bankRepository.save(bank);
return bank;
}
use of com.axelor.apps.base.db.Country in project axelor-open-suite by axelor.
the class MapRestSale method getGeoMapData.
@Path("/geomap/turnover")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getGeoMapData() {
Map<String, BigDecimal> data = new HashMap<String, BigDecimal>();
List<? extends SaleOrder> orders = saleOrderRepo.all().filter("self.statusSelect=?", 3).fetch();
JsonNodeFactory factory = JsonNodeFactory.instance;
ObjectNode mainNode = factory.objectNode();
ArrayNode arrayNode = factory.arrayNode();
ArrayNode labelNode = factory.arrayNode();
labelNode.add("Country");
labelNode.add("Turnover");
arrayNode.add(labelNode);
for (SaleOrder so : orders) {
Country country = so.getMainInvoicingAddress().getAddressL7Country();
BigDecimal value = so.getExTaxTotal();
if (country != null) {
String key = country.getName();
if (data.containsKey(key)) {
BigDecimal oldValue = data.get(key);
oldValue = oldValue.add(value);
data.put(key, oldValue);
} else {
data.put(key, value);
}
}
}
Iterator<String> keys = data.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
ArrayNode dataNode = factory.arrayNode();
dataNode.add(key);
dataNode.add(data.get(key));
arrayNode.add(dataNode);
}
mainNode.put("status", 0);
mainNode.set("data", arrayNode);
return mainNode;
}
Aggregations