private void updateCustomerStatusOf( final Optional<Draft> customerDraftOptional, final Optional<Draft> agreementDraftOptional, final Draft serviceDraft, final Handle handle) { final Map<String, Object> customerUpdate = Maps.newHashMap(); final long customerId; final Service service = new Service(serviceDraft); if (customerDraftOptional.isPresent() && agreementDraftOptional.isPresent()) { customerId = customerDraftOptional.get().entityId(); final Draft agreementDraft = agreementDraftOptional.get(); final Agreement agreement = new Agreement(agreementDraft); if ("PL".equals(agreementDraft.entitySpate())) { final Object symbol = "PL-" + (agreementDraft.entityId() - 200000); customerUpdate.put("symbol", symbol); } final Object variable = agreement.number(); customerUpdate.put("lastly_billed", service.periodStart().dayOfMonth().withMaximumValue()); customerUpdate.put("status", 20); customerUpdate.put("variable", variable); } else { customerId = service.customerId(); } customerUpdate.put("customer_status", "ACTIVE"); customerUpdate.put("is_active", true); updateRecord(CUSTOMERS_TABLE, customerId, customerUpdate, handle); }
public Customer(Draft draft) { checkArgument( Draft.Entity.CUSTOMERS.equals(draft.entity()), "expected CUSTOMERS draft, but got %s", draft.entity()); this.id = new CustomerId(draft.entityId()); this.props = propsFromDraft(draft); this.record = recordFromProps(); }
private void insertCustomerOf(final Draft draft, final Handle handle) { log.debug("adding new customer '{}' from draft '{}'", draft.entityId(), draft.id().value()); final Customer customer = new Customer(draft); final Map<String, Object> record = Maps.newHashMap(customer.record()); final DateTime now = DateTime.now(); record.put("inserted_on", now); record.put("updated", now); final long historyId = insertCustomerAuditOf(draft, handle); record.put("history_id", historyId); insertRecordWithoutKey(CUSTOMERS_TABLE, record, handle); }
private Map<String, Object> propsFromDraft(final Draft draft) { final Map<String, Object> props = Maps.newLinkedHashMap(); props.put("id", draft.entityId()); final ValueMap data = valueMapOf(draft.data()); final boolean isBusiness = "2".equals(data.get("customer_type").asString()); if (isBusiness) { props.put("name", data.getRaw("supplementary_name")); props.put("nameExtra", data.getRaw("representative")); } else { props.put( "name", Joiner.on(" ") .skipNulls() .join(data.get("surname").asStringOr(null), data.get("name").asStringOr(null))); props.put("nameExtra", ""); } props.put( "addressStreet", streetAddress( data.getRaw("street"), data.getRaw("descriptive_number"), data.getRaw("orientation_number"))); props.put("addressTown", data.getRaw("town")); props.put("addressPostalCode", data.getRaw("postal_code")); props.put("addressCountryId", data.get("country").asLong()); props.put("contactName", data.getRaw("contact_name")); props.put("contactEmail", data.getRaw("email")); props.put("contactPhone", data.getRaw("phone")); props.put("publicId", data.getRaw("public_id")); if (isBusiness) { props.put( "taxId", data.get("dic") .asStringValueOr( data.get("public_id").asStringValueOr("" + System.currentTimeMillis()))); } else { props.put("taxId", ""); } props.put("otherInfo", data.getRaw("info")); return Collections.unmodifiableMap(props); }
private void insertAgreementOf(final Draft draft, final Handle handle) { log.debug("adding new agreement '{}' from draft '{}'", draft.entityId(), draft.id().value()); final Agreement agreement = new Agreement(draft); insertRecordWithoutKey(AGREEMENTS_TABLE, agreement.record(), handle); }
private void insertServiceOf(final Draft draft, final Handle handle) { log.debug("adding new service '{}' from draft '{}'", draft.entityId(), draft.id().value()); final Service service = new Service(draft); insertRecordWithoutKey(SERVICES_TABLE, service.record(), handle); }