Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never
package br.com.senior.erpxcomven.pedido.converter.impl;

import static br.com.senior.erpxcomven.utils.ConvertUtils.convertNull;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import br.com.senior.erpxcomven.foundation.E075derEntity;
import br.com.senior.erpxcomven.foundation.repository.E075derRepository;
import br.com.senior.erpxcomven.pedido.E120ipdEntity;
import br.com.senior.erpxcomven.pedido.Item;

@Component
public class ConvertItem  {
	
    @Inject
    private E075derRepository productRepository;
    @Inject
    private ConvertTax convertTax;
    
	public Item convert(E120ipdEntity item) {
		if (Objects.isNull(item)) {
			return null;
		}
		var dto = new Item();
		if (Objects.nonNull(item.getE075der())) {
		    Optional<E075derEntity> product = productRepository.findById(item.getE075der());
		    dto.id = product.map(E075derEntity::getId).map(UUID::toString).orElse(null);
			dto.code = product.map(E075derEntity::getCodDer).orElse(null);
		}
		dto.quantity = convertNull(item.getQtdPed());
		dto.price = convertNull(item.getPreUni());
		dto.discount = convertNull(item.getVlrDsc());
		dto.total = convertNull(item.getVlrLiq());
		dto.expectedDeliveryDate = item.getDatEnt();
		dto.observation = item.getObsIpd();
		dto.taxes = item.getE120imi().stream().map(convertTax::convert).collect(Collectors.toList());
		return dto;
	}
	
}