/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.taxiservicios.beans.stocktaking.service.order;

import com.arrebol.taxiservicios.beans.TaxiGenericBean;
import com.arrebol.taxiservicios.controller.admin.GenericValidationController;
import com.arrebol.taxiservicios.controller.catalog.BankCardController;
import com.arrebol.taxiservicios.controller.catalog.ClaveProductoServicioController;
import com.arrebol.taxiservicios.controller.catalog.ClaveUnidadController;
import com.arrebol.taxiservicios.controller.catalog.ProductBrandController;
import com.arrebol.taxiservicios.controller.catalog.ProductController;
import com.arrebol.taxiservicios.controller.stocktaking.HistoryUpdateKmController;
import com.arrebol.taxiservicios.controller.stocktaking.ServiceOrderController;
import com.arrebol.taxiservicios.controller.stocktaking.ServiceOrderSingletonController;
import com.arrebol.taxiservicios.controller.util.DateWrapper;
import com.arrebol.taxiservicios.model.admin.GeneralPublic;
import com.arrebol.taxiservicios.model.admin.Taxi;
import com.arrebol.taxiservicios.model.catalog.BankCard;
import com.arrebol.taxiservicios.model.catalog.Brand;
import com.arrebol.taxiservicios.model.catalog.ClaveProductoServicio;
import com.arrebol.taxiservicios.model.catalog.ClaveUnidad;
import com.arrebol.taxiservicios.model.catalog.Product;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.BasicType;
import com.arrebol.taxiservicios.model.enums.ExpenseStatusType;
import com.arrebol.taxiservicios.model.enums.PaymentMethodType;
import com.arrebol.taxiservicios.model.enums.ServiceOrderActionType;
import com.arrebol.taxiservicios.model.enums.ServiceOrderType;
import com.arrebol.taxiservicios.model.stocktaking.ServiceOrder;
import com.arrebol.taxiservicios.model.stocktaking.ServiceOrderHasProduct;
import com.arrebol.taxiservicios.model.stocktaking.ServiceOrderHasProductId;
import com.arrebol.taxiservicios.model.stocktaking.ServiceOrderNotification;
import com.arrebol.taxiservicios.model.stocktaking.view.HistoryUpdateKm;
import com.arrebol.taxiservicios.services.catalog.ProductService;
import com.arrebol.taxiservicios.utils.FolioUtility;
import com.arrebol.taxiservicios.wrapper.PersonWrapper;
import com.arrebol.taxiservicios.wrapper.ProductWrapper;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.primefaces.event.RowEditEvent;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author oscarvargas
 */
@Named
@ViewScoped
public class GarageAddBean extends TaxiGenericBean implements Serializable {
    
    /**
     *
     */
    public void createNewProduct() {
        try {
            if(getGenericController().existCheckStocktakingPending(getLoggedUser().getLocation().getId()))
        {
            showMessage(FacesMessage.SEVERITY_WARN,
                        "Inventario cerrado",
                        "No puedes hacer ningun movimiento al inventario hasta que se termine de cotejar");
            return;
        }
            getNewProduct().setAmount(0d);
            getNewProduct().setAmount2(0d);
            getNewProduct().setQuantity(0);
            getNewProduct().setQuantity2(0);
            getNewProduct().setUtility(0d);
            getNewProduct().setUtility2(0d);
            getNewProduct().setService(BasicType.DISABLED);
            getNewProduct().setHerramienta(BasicType.DISABLED);
            getNewProduct().setActiveStatus(BasicType.ENEBLED);
            getNewProduct().setClaveUnidad(getClaveUnidad());
            getNewProduct().setClaveProductoServicio(getClaveProductoServicio());

            if (productCtrl.saveProduct(getNewProduct(), getLoggedUser().getId(), getBrandId())) {
                logger.info("createNewProduct");
                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("garage.title"),
                        getBundlePropertyFile().getString("invoice.add.new.product.success.desc"));

                setComboProducts(getController().getAllProducts());
            } else {
                logger.info("Error createNewProduct");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("garage.title"),
                        getBundlePropertyFile().getString("invoice.add.new.product.fail.desc"));
            }
        } catch (Exception e) {
            logger.error("createNewProduct: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("invoice.add.new.product.exception.desc"));
        }

        setNewProduct(null);
        setClaveUnidad(null);
        setClaveProductoServicio(null);
        setIdClaveUnidad(null);
        setIdClaveProductoServicio(null);
        setBrandId("N/A");
    }

    /**
     *
     */
    public void createServiceOrder() {
        logger.info("saveServiceOrder");
        try {
            if(getGenericController().existCheckStocktakingPending(getLoggedUser().getLocation().getId()))
        {
            showMessage(FacesMessage.SEVERITY_WARN,
                        "Inventario cerrado",
                        "No puedes hacer ningun movimiento al inventario hasta que se termine de cotejar");
            return;
        }
            try {
                if (null == getServiceOrder().getKm() || getServiceOrder().getKm() <= 0d) {
                    throw new NumberFormatException();
                }
                Float km = getServiceOrder().getKm();
                if (null == getServiceOrder().getKmMaintenance() || getServiceOrder().getKmMaintenance() <= 0d) {
                    throw new NumberFormatException();
                }
                Float kmMaintenance = getServiceOrder().getKmMaintenance();
                
                if(kmMaintenance < km)
                {
                    showMessage(FacesMessage.SEVERITY_WARN,
                        "ADVERTENCIA",
                        "El kilometraje de proximo servicio no puede ser menor al kilometraje actual del vehículo");
                    return;
                }
            } catch (Exception e) {
                logger.error("Error KM value a new Service Order: ", e);
                throw new NumberFormatException("Error KM value a new Service Order");
            }
            
            if(isPaseTaller())
            {
                getServiceOrder().setServiceOrderType(ServiceOrderType.PASE_TALLER);
                getServiceOrder().setPaseTallerDate(DateWrapper.getTodayMXTime());
                getServiceOrder().setPaseTallerUser(getLoggedUser());
            }
            else
            {
                if(!isHasProduct())
                {
                    showMessage(FacesMessage.SEVERITY_WARN,
                        "ADVERTENCIA",
                        "Tienes que agregar productos a tu orden de servicio");
                    return;
                }
                else
                {
                    getServiceOrder().setServiceOrderType(ServiceOrderType.PENDING);
                    getServiceOrder().setPendingDate(DateWrapper.getTodayMXTime());
                    getServiceOrder().setPendienteUser(getLoggedUser());
                }
                    
            }
            
            if(isTallerExterno())
            {
                getServiceOrder().setTallerExterno(BasicType.ENEBLED);
            }
            else
            {
                getServiceOrder().setTallerExterno(BasicType.DISABLED);
            }

            User user = new User(getLoggedUser().getId(), "");
            getServiceOrderHasProducts().clear();

            getDtTblProducts().stream().map((wrapper) -> {
                ServiceOrderHasProduct sohp = new ServiceOrderHasProduct(
                        new ServiceOrderHasProductId(
                                getServiceOrder().getId(),
                                wrapper.getProductId()
                        )
                );

                if (null == wrapper.getQuantity() || wrapper.getQuantity() <= 0) {
                    throw new NumberFormatException("Quantity is wrong value " + wrapper.getQuantity());
                }
                if (null == wrapper.getName()) {
                    throw new NullPointerException("Description of the project es null");
                }

                sohp.setCreatedBy(user);
                sohp.setCreatedOn(DateWrapper.getTodayMXTime());
                sohp.setQuantity(wrapper.getQuantity());
                sohp.setPrice(wrapper.getPrice().floatValue());
                sohp.setTotal(wrapper.getTotal().floatValue());//Total within IVA
                sohp.setMayoreo(Float.valueOf(wrapper.getUtility()+""));
                sohp.setCobrado(BasicType.DISABLED);
                sohp.setFinanciado(BasicType.DISABLED);
                sohp.setCommercialInvoiceStatus(BasicType.DISABLED);

                return sohp;
            }).forEachOrdered((sohp) -> {
                getServiceOrderHasProducts().add(sohp);
            });

            Double ivaSO = 0d;
            Double subtotalSO = 0d;
            Double totalSO = 0d;

            for (ServiceOrderHasProduct sohp : getServiceOrderHasProducts()) {
                subtotalSO = sohp.getTotal() + subtotalSO;
                ivaSO = (sohp.getTotal() * iva) + ivaSO;
            }

            totalSO = subtotalSO + ivaSO;

            
            getServiceOrder().setPaymentMethodType(PaymentMethodType.EMPTY);
            getServiceOrder().setTaxi(new Taxi(getTaxi().getId()));
            getServiceOrder().setActive(true);
            getServiceOrder().setCreatedBy(user);
            if(generalPublic != null)
            {
              getServiceOrder().setGeneralPublic(generalPublic);
            }
            getServiceOrder().setCreatedOn(DateWrapper.getTodayMXTime());
            getServiceOrder().setSubtotal(subtotalSO.floatValue());
            getServiceOrder().setIva(ivaSO.floatValue());
            getServiceOrder().setTotal(totalSO.floatValue());
            getServiceOrder().setNameNumber(getController().getNextFolio());
            getServiceOrder().setName(
                    FolioUtility.buildFolio(
                            getServiceOrder().getNameNumber().toString(),
                            "SO-", "-" + getCurrentYear(), 6, "0"
                    )
            );
            
            if(isDeposit()){
                getServiceOrder().setDepositStatus(ExpenseStatusType.PENDING);
                getServiceOrder().setBankCard(new BankCard(getBankCardId()));
            }else{
                getServiceOrder().setDepositStatus(ExpenseStatusType.AUTHORIZED);
            }

            if (getController().createServiceOrder(getServiceOrder(), getServiceOrderHasProducts())) {
                setCreatedOrder(true);
                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("garage.title"),
                        getBundlePropertyFile().getString("garage.add.new.order.desc"));

                logger.info("saveServiceOrder ");
                
                HistoryUpdateKm history = new HistoryUpdateKm();
                history.setId(UUID.randomUUID().toString());
                history.setActiveStatus(BasicType.ENEBLED);
                history.setComments("Orden de servicio con folio: " + getServiceOrder().getName());
                history.setModule("Orden de servicio");
                history.setCreatedBy(user);
                history.setCreatedOn(new Date());
                history.setNewKm(getServiceOrder().getKm());
                history.setLastKm(taxi.getKm());
                history.setTaxi(taxi);
                
                getHistoryController().save(history);
                
                ServiceOrderNotification notification = new ServiceOrderNotification(
                        UUID.randomUUID().toString(),
                        "Orden de servicio creada",
                        "Número de folio " + getServiceOrder().getName(),
                        new Date(),
                        ServiceOrderActionType.CREATED);

                List<String> permissionLst = new ArrayList<>();

                permissionLst.add("stocktaking.service.order.management.update");
                permissionLst.add("stocktaking.service.order.management.delete");

                ServiceOrderNotificationThread notificationThread
                        = new ServiceOrderNotificationThread(notification, permissionLst, getLoggedUser().getId()
                        );

                notificationThread.start();
            } else {
                logger.error("saveServiceOrder");

                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("garage.title"),
                        getBundlePropertyFile().getString("garage.add.new.order.exception.desc"));
            }
        } catch (NumberFormatException e) {
            logger.error("saveServiceOrder NumberFormatException: " + e);

            String msg = getBundlePropertyFile().getString("garage.km.exception");

            if (null != e.getMessage() && e.getMessage().contains("Quantity is wrong value")) {
                msg = getBundlePropertyFile().getString("garage.search.number.format.exception");
            }

            showMessage(FacesMessage.SEVERITY_ERROR,
                    getBundlePropertyFile().getString("garage.title"), msg);
        } catch (NullPointerException e) {
            logger.error("saveServiceOrder NullPointerException : " + e);

            String msg = getBundlePropertyFile().getString("garage.generic.exception");

            if (null != e.getMessage() && e.getMessage().contains("Description of the project es null")) {
                msg = getBundlePropertyFile().getString("garage.search.null.pointer.exception");
            }
            showMessage(FacesMessage.SEVERITY_ERROR,
                    getBundlePropertyFile().getString("garage.title"), msg);
        } catch (Exception e) {
            logger.error("saveServiceOrder: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("fatal.access.details"));
        }
    }
    
    public void onItemSelectClaveUnidad(SelectEvent event) {
        
        try {
            setClaveUnidad(claveUnidadController.getById(getIdClaveUnidad()));
        } catch (Exception e) {
            
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.generic.exception"));
        }
    }
    
    public void onItemSelectClaveProductoServicio(SelectEvent event) {
        
        try {
            setClaveProductoServicio(claveProductoServicioController.getById(getIdClaveProductoServicio()));
        } catch (Exception e) {
            
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.generic.exception"));
        }
    }
    
    public List<ClaveProductoServicio> searchClaveProductoServicios(String query) {
        
        List<ClaveProductoServicio> list = null;
        try {
            list = getClaveProductoServicioController().getClaveProductoServicioLike(query);
        } catch (Exception e) {
            
            showMessage(FacesMessage.SEVERITY_FATAL,
                    "No se pudo buscar la clave producto servicio",
                    "Error");
        }
        return list;
    }
    
    public List<ClaveUnidad> searchClaveUnidad(String query) {
        
        List<ClaveUnidad> list = null;
        try {
            list = getClaveUnidadController().getClaveUnidadLike(query);
        } catch (Exception e) {
            
            showMessage(FacesMessage.SEVERITY_FATAL,
                    "No se pudo buscar la clave producto servicio",
                    "Error");
        }
        return list;
    }
    
    public void handleClose() {
        setClaveUnidad(null);
        setClaveProductoServicio(null);
        setIdClaveUnidad(null);
        setIdClaveProductoServicio(null);
        
    }

    /**
     *
     * @param query
     * @return
     */
    public List<String> searchEconomicNumebers(String query) {
        logger.info("searchEconomicNumebers");

        List<String> list = new ArrayList<String>();
        try {
            list = getController().getEconomicNumbersLike(query);
        } catch (Exception e) {
            logger.error("searchEconomicNumebers: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.generic.exception"));
        }
        return list;
    }
    
    public List<String> searchPlacaGeneralPublic(String query) {
        logger.info("searchPlacaGeneralPublic");

        List<String> list = new ArrayList<String>();
        try {
            list = getController().getPlacaLike(query);
        } catch (Exception e) {
            logger.error("searchPlacaGeneralPublic: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.generic.exception"));
        }
        return list;
    }

    /**
     *
     * @param event
     */
    public void onItemSelect(SelectEvent event) {
        logger.info("onItemSelect");
        try {
            setTaxi(getController().getTaxiByEconomicNumber(getEconomicNumber()));
            setComboProducts(getController().getAllProducts());
            setClient(wraperPerson(getTaxi().getCustomer()));
            if(getTaxi().getDriver() != null)
            {
                setDriver(wraperPerson(getTaxi().getDriver()));
            }
            setAddOrder(true);
        } catch (Exception e) {
            setAddOrder(false);
            logger.error("onItemSelect: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.generic.exception"));
        }
    }
    
    public void onItemSelectGeneralPublic(SelectEvent event) {
        logger.info("onItemSelectGeneralPublic");
        try {
            setGeneralPublic(getController().getGeneralPublicByPlaca(getPlaca()));

            setAddOrder(true);
        } catch (Exception e) {
            setAddOrder(true);
            logger.error("onItemSelectGeneralPublic: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    "No se pudo cargar el cliente público general");
        }
    }

    /**
     *
     */
    public void onAddNew() {
        getDtTblProducts().add(new ProductWrapper(UUID.randomUUID().toString()));

        logger.info(getDtTblProducts());
    }

    /**
     *
     * @param event
     */
    public void onRowEdit(RowEditEvent event) {
        logger.info("onRowEdit");
        try {
            ProductWrapper product = (ProductWrapper) event.getObject();

            if (null == product.getQuantity() || product.getQuantity() <= 0) {
                throw new NumberFormatException("Quantity is wrong value " + product.getQuantity());
            }
            if (null == product.getProductId()) {
                throw new NullPointerException("Description of the project es null");
            }

            getComboProducts().forEach((Product comboPrdct) -> {
                if (product.getProductId().equals(comboPrdct.getId())) {
                    if(getLoggedUser().getLocation().getId().equalsIgnoreCase("4d0859be-e31a-4acb-a690-2a5c2cb027a7"))
                    {
                       product.wrapper(comboPrdct, comboPrdct.getCode(), comboPrdct.getBrand().getName());
                       setHasProduct(true);
                    }
                    else
                    {
                        product.wrapper(comboPrdct, comboPrdct.getCode(), comboPrdct.getBrand().getName(), true);
                        setHasProduct(true);
                    }
                    
                }
            });
        } catch (NumberFormatException e) {
            logger.error("onRowEdit ", e);
            showMessage(FacesMessage.SEVERITY_ERROR,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.search.number.format.exception"));
        } catch (NullPointerException e) {
            logger.error("onRowEdit ", e);
            showMessage(FacesMessage.SEVERITY_ERROR,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.search.null.pointer.exception"));
        } catch (Exception e) {
            logger.error("onRowEdit", e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("garage.search.exception.desc"));
        }
    }

    public void onRowCancel(RowEditEvent event) {

    }

    public void deleteSelectedProduct() {
        logger.info("deleteSelectedProduct");
        try {
            getDtTblProducts().remove(getSelectedProduct());

            if (getDtTblProducts().isEmpty()) {
                setHasProduct(false);
            }
        } catch (Exception e) {
            logger.error("deleteSelectedProduct", e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("garage.title"),
                    getBundlePropertyFile().getString("fatal.access.details"));
        }
    }

    private static final long serialVersionUID = 7262352676899406479L;

    final Logger logger = LogManager.getLogger(GarageAddBean.class);

    private final String SERVICE_ORDER_ID = UUID.randomUUID().toString();

    private ServiceOrderController controller;
    private ServiceOrderSingletonController singletonController;
    private HistoryUpdateKmController historyController;
    private GenericValidationController genericController;
    private ServiceOrder serviceOrder;
    private Taxi taxi;
    private String economicNumber;
    private String placa;
    private List<String> economicNumbers;
    private PersonWrapper client;
    private PersonWrapper driver;
    private GeneralPublic generalPublic;
    private boolean addOrder;
    private List<ServiceOrderHasProduct> serviceOrderHasProducts;
    private List<Product> comboProducts;
    private List<ProductWrapper> dtTblProducts;
    private boolean saveSOHPBtnOnclick;
    private ProductWrapper selectedProduct;
    private boolean createdOrder;
    private boolean hasProduct;
    private Product newProduct;
    private String brandId;
    private boolean paseTaller;
    private boolean tallerExterno;
    
    private String idClaveUnidad;
    private ClaveUnidad claveUnidad;
    private String idClaveProductoServicio;
    private ClaveProductoServicio claveProductoServicio;
    private ClaveUnidadController claveUnidadController;
    private ClaveProductoServicioController claveProductoServicioController;
    private boolean deposit;
    private String bankCardId;
    private BankCardController bankCardController;
    private List<BankCard> bankCards;
    private ProductController productCtrl;
    private ProductBrandController brandCtrl;

    @PostConstruct
    public void init() {
        logger.info("init");
        try {
            loadBundlePropertyFile();
            productCtrl = new ProductController();
            brandCtrl = new ProductBrandController();
            setController(new ServiceOrderController());
            setHistoryController(new HistoryUpdateKmController());
            setGenericController(new GenericValidationController());
            setSingletonController(ServiceOrderSingletonController.getInstance());
            setBankCardController(new BankCardController());
            setBankCards(getBankCardController().findAllBankCardsByLocation(getLoggedUser().getLocation().getId()));
            setDeposit(false);
            
        setClaveUnidadController(new ClaveUnidadController());
        setClaveProductoServicioController(new ClaveProductoServicioController());
            paseTaller = false;
            tallerExterno = false;

            logger.info("Garage loaded");
        } catch (Exception e) {
            logger.error("init", e);
        }
    }

    public ProductController getProductCtrl() {
        return productCtrl;
    }

    public void setProductCtrl(ProductController productCtrl) {
        this.productCtrl = productCtrl;
    }

    public ProductBrandController getBrandCtrl() {
        return brandCtrl;
    }

    public void setBrandCtrl(ProductBrandController brandCtrl) {
        this.brandCtrl = brandCtrl;
    }

    public GenericValidationController getGenericController() {
        return genericController;
    }

    public void setGenericController(GenericValidationController genericController) {
        this.genericController = genericController;
    }

    public GeneralPublic getGeneralPublic() {
        return generalPublic;
    }

    public void setGeneralPublic(GeneralPublic generalPublic) {
        this.generalPublic = generalPublic;
    }

    public String getPlaca() {
        return placa;
    }

    public void setPlaca(String placa) {
        this.placa = placa;
    }

    public boolean isTallerExterno() {
        return tallerExterno;
    }

    public void setTallerExterno(boolean tallerExterno) {
        this.tallerExterno = tallerExterno;
    }

    public boolean isPaseTaller() {
        return paseTaller;
    }

    public void setPaseTaller(boolean paseTaller) {
        this.paseTaller = paseTaller;
    }

    public HistoryUpdateKmController getHistoryController() {
        return historyController;
    }

    public void setHistoryController(HistoryUpdateKmController historyController) {
        this.historyController = historyController;
    }

    public ServiceOrderController getController() {
        return controller;
    }

    public void setController(ServiceOrderController controller) {
        this.controller = controller;
    }

    public ServiceOrderSingletonController getSingletonController() {
        return singletonController;
    }

    public void setSingletonController(ServiceOrderSingletonController singletonController) {
        this.singletonController = singletonController;
    }

    public ServiceOrder getServiceOrder() {
        if (null == serviceOrder) {
            serviceOrder = new ServiceOrder(UUID.randomUUID().toString());
        }
        return serviceOrder;
    }

    public void setServiceOrder(ServiceOrder serviceOrder) {
        this.serviceOrder = serviceOrder;
    }

    public Taxi getTaxi() {
        return taxi;
    }

    public void setTaxi(Taxi taxi) {
        this.taxi = taxi;
    }

    public String getEconomicNumber() {
        return economicNumber;
    }

    public void setEconomicNumber(String economicNumber) {
        this.economicNumber = economicNumber;
    }

    public List<String> getEconomicNumbers() {
        return economicNumbers;
    }

    public void setEconomicNumbers(List<String> economicNumbers) {
        this.economicNumbers = economicNumbers;
    }

    public PersonWrapper getClient() {
        if (null == client) {
            client = new PersonWrapper();
        }
        return client;
    }

    public void setClient(PersonWrapper client) {
        this.client = client;
    }

    public PersonWrapper getDriver() {
        if (null == driver) {
            driver = new PersonWrapper();
        }
        return driver;
    }

    public void setDriver(PersonWrapper driver) {
        this.driver = driver;
    }

    public boolean isAddOrder() {
        return addOrder;
    }

    public void setAddOrder(boolean addOrder) {
        this.addOrder = addOrder;
    }

    public List<ServiceOrderHasProduct> getServiceOrderHasProducts() {
        if (null == serviceOrderHasProducts) {
            serviceOrderHasProducts = new ArrayList<ServiceOrderHasProduct>();
        }
        return serviceOrderHasProducts;
    }

    public void setServiceOrderHasProducts(List<ServiceOrderHasProduct> serviceOrderHasProducts) {
        this.serviceOrderHasProducts = serviceOrderHasProducts;
    }

    public List<Product> getComboProducts() {
        if (null == comboProducts) {
            comboProducts = new ArrayList<Product>();
        }
        return comboProducts;
    }

    public void setComboProducts(List<Product> comboProducts) {
        this.comboProducts = comboProducts;
    }

    public List<ProductWrapper> getDtTblProducts() {
        if (null == dtTblProducts) {
            dtTblProducts = new ArrayList<ProductWrapper>();
        }
        return dtTblProducts;
    }

    public void setDtTblProducts(List<ProductWrapper> dtTblProducts) {
        this.dtTblProducts = dtTblProducts;
    }

    public void setSaveSOHPBtnOnclick(boolean saveSOHPBtnOnclick) {
        this.saveSOHPBtnOnclick = saveSOHPBtnOnclick;
    }

    public boolean isSaveSOHPBtnOnclick() {
        return saveSOHPBtnOnclick;
    }

    public ProductWrapper getSelectedProduct() {
        return selectedProduct;
    }

    public void setSelectedProduct(ProductWrapper selectedProduct) {
        this.selectedProduct = selectedProduct;
    }

    public boolean isCreatedOrder() {
        return createdOrder;
    }

    public void setCreatedOrder(boolean createdOrder) {
        this.createdOrder = createdOrder;
    }

    public boolean isHasProduct() {
        return hasProduct;
    }

    public void setHasProduct(boolean hasProduct) {
        this.hasProduct = hasProduct;
    }

    public Product getNewProduct() {
        if (null == newProduct) {
            newProduct = new Product();
        }

        return newProduct;
    }

    public void setNewProduct(Product newProduct) {
        this.newProduct = newProduct;
    }

    public List<Brand> getBrandes() {
        return brandCtrl.fillProductBrandComboBox();
    }

    public String getBrandId() {
        return brandId;
    }

    public void setBrandId(String brandId) {
        this.brandId = brandId;
    }

    public String getIdClaveUnidad() {
        return idClaveUnidad;
    }

    public void setIdClaveUnidad(String idClaveUnidad) {
        this.idClaveUnidad = idClaveUnidad;
    }

    public ClaveUnidad getClaveUnidad() {
        return claveUnidad;
    }

    public void setClaveUnidad(ClaveUnidad claveUnidad) {
        this.claveUnidad = claveUnidad;
    }

    public String getIdClaveProductoServicio() {
        return idClaveProductoServicio;
    }

    public void setIdClaveProductoServicio(String idClaveProductoServicio) {
        this.idClaveProductoServicio = idClaveProductoServicio;
    }

    public ClaveProductoServicio getClaveProductoServicio() {
        return claveProductoServicio;
    }

    public void setClaveProductoServicio(ClaveProductoServicio claveProductoServicio) {
        this.claveProductoServicio = claveProductoServicio;
    }

    public ClaveUnidadController getClaveUnidadController() {
        return claveUnidadController;
    }

    public void setClaveUnidadController(ClaveUnidadController claveUnidadController) {
        this.claveUnidadController = claveUnidadController;
    }

    public ClaveProductoServicioController getClaveProductoServicioController() {
        return claveProductoServicioController;
    }

    public void setClaveProductoServicioController(ClaveProductoServicioController claveProductoServicioController) {
        this.claveProductoServicioController = claveProductoServicioController;
    }

    public boolean isDeposit() {
        return deposit;
    }

    public void setDeposit(boolean deposit) {
        this.deposit = deposit;
    }

    public String getBankCardId() {
        return bankCardId;
    }

    public void setBankCardId(String bankCardId) {
        this.bankCardId = bankCardId;
    }

    public BankCardController getBankCardController() {
        return bankCardController;
    }

    public void setBankCardController(BankCardController bankCardController) {
        this.bankCardController = bankCardController;
    }

    public List<BankCard> getBankCards() {
        return bankCards;
    }

    public void setBankCards(List<BankCard> bankCards) {
        this.bankCards = bankCards;
    }

    
}
