public CommandResult Handle(InsertarActualizarDocumentoRecepcionDetalleCommand command)
        {
            if (command == null)
            {
                throw new ArgumentException("Tiene que ingresar una cliente");
            }


            DocumentoRecepcionDetalle dominio = null;

            if (command.iddocumentorecepciondetalle.HasValue)
            {
                dominio = _DocumentoRecepcionDetalleRepository.Get(x => x.iddocumentorecepciondetalle == command.iddocumentorecepciondetalle).LastOrDefault();
            }
            else
            {
                dominio = new DocumentoRecepcionDetalle();
            }

            dominio.caja     = command.caja;
            dominio.cantidad = command.cantidad;
            dominio.fechahorapersonalizacion = command.fechahorapersonalizacion;
            dominio.fila = command.fila;
            dominio.iddocumentorecepcion     = command.iddocumentorecepcion;
            dominio.idmodelo                 = command.idmodelo;
            dominio.idproducto               = command.idproducto;
            dominio.idtipoproducto           = command.idtipoproducto;
            dominio.idusuariopersonalizacion = command.idusuariopersonalizacion;
            dominio.imei         = command.imei;
            dominio.mac          = command.mac;
            dominio.numeropallet = command.numeropallet;
            dominio.repuesto     = command.repuesto;
            dominio.serie        = command.serie;



            try
            {
                if (!command.iddocumentorecepciondetalle.HasValue)
                {
                    _DocumentoRecepcionDetalleRepository.Add(dominio);
                }
                _DocumentoRecepcionDetalleRepository.Commit();



                return(new InsertarActualizarDocumentoRecepcionDetalleOutput()
                {
                    iddocumentorecepciondetalle = dominio.iddocumentorecepciondetalle
                });
            }
            catch (Exception ex)
            {
                //  _ValortablaRepository.Delete(dominio);
                //_ValortablaRepository.Commit();
                throw;
            }
        }
示例#2
0
        private List <DocumentoRecepcion> ObtenerDocumentosErpParaGrabar()
        {
            var listaDetalle = _vista.OrdenesDeCompraDetalle;

            listaDetalle = listaDetalle.OrderBy(d => d.CLIENT_CODE).ToList().OrderBy(d => d.ERP_DOC).ToList();
            var    listaDecoumentos  = new List <DocumentoRecepcion>();
            string idDocumentoActual = "";
            var    idClient          = "";
            var    catidadDetalles   = 0;
            var    cantidad          = 0;
            var    documento         = new DocumentoRecepcion
            {
                DocumentoRecepcionErpDetalles = new List <DocumentoRecepcionDetalle>()
            };


            foreach (var detalle in listaDetalle)
            {
                if (idDocumentoActual != detalle.ERP_DOC || idClient != detalle.CLIENT_CODE)
                {
                    if (documento.DocumentoRecepcionErpDetalles.Count != 0)
                    {
                        documento.IS_COMPLETE = Convert.ToInt32(cantidad == catidadDetalles); //Convert.ToInt32(documento.DocumentoRecepcionErpDetalles.Count == catidadDetalles);
                        listaDecoumentos.Add(documento);
                        documento = new DocumentoRecepcion
                        {
                            DocumentoRecepcionErpDetalles = new List <DocumentoRecepcionDetalle>()
                        };
                    }

                    idDocumentoActual = detalle.ERP_DOC;
                    idClient          = detalle.CLIENT_CODE;
                    if (detalle.DETAIL_COUNT != null)
                    {
                        catidadDetalles = (int)detalle.DETAIL_COUNT;
                    }
                    documento.DOC_NUM              = detalle.ERP_DOC;
                    documento.DOC_ID               = detalle.SAP_RECEPTION_ID;
                    documento.TYPE                 = detalle.TYPE_RECEPCTION;
                    documento.CODE_SUPPLIER        = detalle.PROVIDER_ID;
                    documento.LAST_UPDATE_BY       = InteraccionConUsuarioServicio.ObtenerUsuario();
                    documento.TASK_ID              = 0;
                    documento.EXTERNAL_SOURCE_ID   = Convert.ToInt32(detalle.EXTERNAL_SOURCE_ID);
                    documento.TRADE_AGREEMENT      = detalle.TRADE_AGREEMENT_ID.ToString();
                    documento.INSURANCE_POLICY     = detalle.INSURANCE_DOC_ID;
                    documento.TYPE_RECEPTION       = detalle.TYPE_RECEPCTION;
                    documento.TASK_ASSIGNEDTO      = detalle.LOGIN_ID;
                    documento.REGIMEN              = "GENERAL";
                    documento.CODE_CLIENT          = detalle.CLIENT_CODE;
                    documento.CLIENT_NAME          = "";
                    documento.PRIORITY             = detalle.PRIORITY.ToString();
                    documento.LOCATION_SPOT_TARGET = detalle.LOCATION_SPOT;
                    documento.NAME_SUPPLIER        = detalle.PROVIDER_NAME;
                    documento.OWNER                = detalle.OWNER;
                    documento.SOURCE               = detalle.SOURCE;
                    documento.ERP_WAREHOUSE_CODE   = detalle.ERP_WAREHOUSE_CODE;
                    documento.DOC_ENTRY            = detalle.DOC_ENTRY;
                    documento.ADDRESS              = detalle.ADDRESS;
                    documento.DOC_CURRENCY         = detalle.DOC_CURRENCY;
                    documento.DOC_RATE             = detalle.DOC_RATE;
                    documento.SUBSIDIARY           = detalle.SUBSIDIARY;
                    documento.COST_CENTER          = detalle.COST_CENTER;

                    cantidad = 1;
                    if (detalle.IS_ASSIGNED == 1)
                    {
                        continue;
                    }
                    var detalleAgregar = new DocumentoRecepcionDetalle
                    {
                        MATERIAL_ID = detalle.SKU,
                        QTY         = detalle.QTY
                        ,
                        LINE_NUM = detalle.LINE_NUM
                        ,
                        ERP_OBJECT_TYPE = Convert.ToInt32(detalle.OBJECT_TYPE)
                        ,
                        DET_CURRENCY = detalle.DET_CURRENCY
                        ,
                        DET_RATE = detalle.DET_RATE
                        ,
                        DET_TAX_CODE = detalle.DET_TAX_CODE
                        ,
                        DET_VAT_PERCENT = detalle.DET_VAT_PERCENT
                        ,
                        PRICE = detalle.PRICE
                        ,
                        DISCOUNT_PERCENT = detalle.DISCOUNT_PERCENT
                        ,
                        WAREHOUSE_CODE = detalle.ERP_WAREHOUSE_CODE
                        ,
                        COST_CENTER = detalle.COST_CENTER
                        ,
                        UNIT = detalle.UNIT
                        ,
                        UNIT_DESCRIPTION = detalle.UNIT_DESCRIPTION
                    };

                    documento.DocumentoRecepcionErpDetalles.Add(detalleAgregar);
                }
                else
                {
                    cantidad += 1;
                    if (detalle.IS_ASSIGNED == 1)
                    {
                        continue;
                    }
                    var detalleAgregar = new DocumentoRecepcionDetalle
                    {
                        MATERIAL_ID = detalle.SKU,
                        QTY         = detalle.QTY
                        ,
                        LINE_NUM = detalle.LINE_NUM
                        ,
                        ERP_OBJECT_TYPE = Convert.ToInt32(detalle.OBJECT_TYPE)
                        ,
                        DET_CURRENCY = detalle.DET_CURRENCY
                        ,
                        DET_RATE = detalle.DET_RATE
                        ,
                        DET_TAX_CODE = detalle.DET_TAX_CODE
                        ,
                        DET_VAT_PERCENT = detalle.DET_VAT_PERCENT
                        ,
                        PRICE = detalle.PRICE
                        ,
                        DISCOUNT_PERCENT = detalle.DISCOUNT_PERCENT
                        ,
                        WAREHOUSE_CODE = detalle.ERP_WAREHOUSE_CODE
                        ,
                        COST_CENTER = detalle.COST_CENTER
                        ,
                        UNIT = detalle.UNIT
                        ,
                        UNIT_DESCRIPTION = detalle.UNIT_DESCRIPTION
                    };

                    documento.DocumentoRecepcionErpDetalles.Add(detalleAgregar);
                }
            }
            documento.IS_COMPLETE = Convert.ToInt32(cantidad == catidadDetalles);
            listaDecoumentos.Add(documento);

            return(listaDecoumentos);
        }