Search in sources :

Example 1 with TaxClass

use of com.salesmanager.core.model.tax.taxclass.TaxClass in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxClasses.

@Override
public ReadableEntityList<ReadableTaxClass> taxClasses(MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        List<TaxClass> models = taxClassService.listByStore(store);
        List<ReadableTaxClass> taxClasses = models.stream().map(t -> convertToReadableTaxClass(t, store, language)).collect(Collectors.toList());
        ReadableEntityList<ReadableTaxClass> list = new ReadableEntityList<ReadableTaxClass>();
        list.setItems(taxClasses);
        list.setNumber(taxClasses.size());
        list.setTotalPages(1);
        list.setRecordsTotal(taxClasses.size());
        return list;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClasses for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClasses for store [" + store.getCode() + "]", e);
    }
}
Also used : PersistableTaxClassMapper(com.salesmanager.shop.mapper.tax.PersistableTaxClassMapper) Entity(com.salesmanager.shop.model.entity.Entity) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) TaxRateService(com.salesmanager.core.business.services.tax.TaxRateService) PersistableTaxRateMapper(com.salesmanager.shop.mapper.tax.PersistableTaxRateMapper) TaxClassService(com.salesmanager.core.business.services.tax.TaxClassService) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Logger(org.slf4j.Logger) TaxFacade(com.salesmanager.shop.store.controller.tax.facade.TaxFacade) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClassMapper(com.salesmanager.shop.mapper.tax.ReadableTaxClassMapper) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) List(java.util.List) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) Validate(org.apache.commons.lang3.Validate) ReadableTaxRateMapper(com.salesmanager.shop.mapper.tax.ReadableTaxRateMapper) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with TaxClass

use of com.salesmanager.core.model.tax.taxclass.TaxClass in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method createTaxClass.

@Override
public Entity createTaxClass(PersistableTaxClass taxClass, MerchantStore store, Language language) {
    Validate.notNull(taxClass, "TaxClass cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        if (this.existsTaxClass(taxClass.getCode(), store, language)) {
            throw new OperationNotAllowedException("Tax class [" + taxClass.getCode() + "] already exist for store [" + store.getCode() + "]");
        }
        taxClass.setStore(store.getCode());
        TaxClass model = persistableTaxClassMapper.convert(taxClass, store, language);
        model = taxClassService.saveOrUpdate(model);
        ;
        Entity id = new Entity();
        id.setId(model.getId());
        return id;
    } catch (ServiceException e) {
        LOGGER.error("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : Entity(com.salesmanager.shop.model.entity.Entity) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with TaxClass

use of com.salesmanager.core.model.tax.taxclass.TaxClass in project shopizer by shopizer-ecommerce.

the class InitializationDatabaseImpl method createMerchant.

private void createMerchant() throws ServiceException {
    LOGGER.info(String.format("%s : Creating merchant ", name));
    Date date = new Date(System.currentTimeMillis());
    Language en = languageService.getByCode("en");
    Country ca = countryService.getByCode("CA");
    Currency currency = currencyService.getByCode("CAD");
    Zone qc = zoneService.getByCode("QC");
    List<Language> supportedLanguages = new ArrayList<Language>();
    supportedLanguages.add(en);
    // create a merchant
    MerchantStore store = new MerchantStore();
    store.setCountry(ca);
    store.setCurrency(currency);
    store.setDefaultLanguage(en);
    store.setInBusinessSince(date);
    store.setZone(qc);
    store.setStorename("Default store");
    store.setStorephone("888-888-8888");
    store.setCode(MerchantStore.DEFAULT_STORE);
    store.setStorecity("My city");
    store.setStoreaddress("1234 Street address");
    store.setStorepostalcode("H2H-2H2");
    store.setStoreEmailAddress("john@test.com");
    store.setDomainName("localhost:8080");
    store.setStoreTemplate("december");
    store.setRetailer(true);
    store.setLanguages(supportedLanguages);
    merchantService.create(store);
    TaxClass taxclass = new TaxClass(TaxClass.DEFAULT_TAX_CLASS);
    taxclass.setMerchantStore(store);
    taxClassService.create(taxclass);
    // create default manufacturer
    Manufacturer defaultManufacturer = new Manufacturer();
    defaultManufacturer.setCode("DEFAULT");
    defaultManufacturer.setMerchantStore(store);
    ManufacturerDescription manufacturerDescription = new ManufacturerDescription();
    manufacturerDescription.setLanguage(en);
    manufacturerDescription.setName("DEFAULT");
    manufacturerDescription.setManufacturer(defaultManufacturer);
    manufacturerDescription.setDescription("DEFAULT");
    defaultManufacturer.getDescriptions().add(manufacturerDescription);
    manufacturerService.create(defaultManufacturer);
    Optin newsletter = new Optin();
    newsletter.setCode(OptinType.NEWSLETTER.name());
    newsletter.setMerchant(store);
    newsletter.setOptinType(OptinType.NEWSLETTER);
    optinService.create(newsletter);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Optin(com.salesmanager.core.model.system.optin.Optin) Zone(com.salesmanager.core.model.reference.zone.Zone) Currency(com.salesmanager.core.model.reference.currency.Currency) ArrayList(java.util.ArrayList) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Date(java.sql.Date)

Example 4 with TaxClass

use of com.salesmanager.core.model.tax.taxclass.TaxClass in project shopizer by shopizer-ecommerce.

the class TaxClassServiceImpl method delete.

@Override
public void delete(TaxClass taxClass) throws ServiceException {
    TaxClass t = getById(taxClass.getId());
    super.delete(t);
}
Also used : TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass)

Example 5 with TaxClass

use of com.salesmanager.core.model.tax.taxclass.TaxClass in project shopizer by shopizer-ecommerce.

the class PersistableTaxClassMapper method convert.

@Override
public TaxClass convert(PersistableTaxClass source, MerchantStore store, Language language) {
    Validate.notNull(source, "PersistableTaxClass cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    TaxClass taxClass = new TaxClass();
    taxClass.setMerchantStore(store);
    taxClass.setTitle(source.getName());
    taxClass.setId(source.getId());
    return this.merge(source, taxClass, store, language);
}
Also used : TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass)

Aggregations

TaxClass (com.salesmanager.core.model.tax.taxclass.TaxClass)9 PersistableTaxClass (com.salesmanager.shop.model.tax.PersistableTaxClass)6 ServiceException (com.salesmanager.core.business.exception.ServiceException)5 ReadableTaxClass (com.salesmanager.shop.model.tax.ReadableTaxClass)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)5 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)4 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 Country (com.salesmanager.core.model.reference.country.Country)2 Language (com.salesmanager.core.model.reference.language.Language)2 Zone (com.salesmanager.core.model.reference.zone.Zone)2 TaxRate (com.salesmanager.core.model.tax.taxrate.TaxRate)2 Entity (com.salesmanager.shop.model.entity.Entity)2 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)2 ArrayList (java.util.ArrayList)2 TaxClassService (com.salesmanager.core.business.services.tax.TaxClassService)1 TaxRateService (com.salesmanager.core.business.services.tax.TaxRateService)1 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)1 ManufacturerDescription (com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription)1 Billing (com.salesmanager.core.model.common.Billing)1