public bool AddMovementDetail(BoardPrintRecipes data, string movementId)
        {
            try
            {
                foreach (var item in data.ListProducts)
                {
                    var objProduct = (from pro in Ctx.Product
                                      where pro.v_ProductId == item.ProductId
                                      select pro).FirstOrDefault();
                    var oMovementeDetailBE = new MovementDetailBE
                    {
                        v_MovementId     = movementId,
                        v_WarehouseId    = data.WarehouseId,
                        v_ProductId      = item.ProductId,
                        r_Quantity       = item.Quantity.Value,
                        i_MovementTypeId = data.MovementTypeId,
                        r_Price          = objProduct.r_ReferentialCostPrice,
                        r_SubTotal       = objProduct.r_ReferentialCostPrice * item.Quantity.Value,
                    };
                    Ctx.MovementDetail.Add(oMovementeDetailBE);
                }


                Ctx.SaveChanges();


                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public string  AddMovement(BoardPrintRecipes data)
        {
            try
            {
                string     NewId      = "(No generado)";
                var        supplierId = data.SupplierId == null ? null : data.SupplierId;
                var        motiveType = data.MotiveTypeId == null ? 4 : data.MotiveTypeId;
                DateTime   _date      = data.Date.Value == null ? DateTime.Now : data.Date.Value;
                MovementBE oMovement  = new MovementBE();

                //New
                NewId = new Common.Utils().GetPrimaryKey(data.NodeId.Value, 370, "MM");
                oMovement.v_MovementId         = NewId;
                oMovement.i_MovementTypeId     = data.MovementTypeId.Value;
                oMovement.v_WarehouseId        = data.WarehouseId;
                oMovement.i_IsLocallyProcessed = (int)Enumeratores.SiNo.No;
                oMovement.r_TotalQuantity      = 0;
                oMovement.v_ReferenceDocument  = data.ReferenceDocument;
                oMovement.i_MotiveTypeId       = motiveType;
                oMovement.v_SupplierId         = supplierId;
                oMovement.i_InsertUserId       = data.InsertUserId.Value;
                oMovement.d_Date = _date;
                Ctx.Movement.Add(oMovement);

                Ctx.SaveChanges();
                return(NewId);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 3
0
        public JsonResult PrintRecipes(BoardPrintRecipes data)
        {
            data.MovementTypeId = (int)Enumeratores.MovementType.Egreso;
            Api API = new Api();
            Dictionary <string, string> arg = new Dictionary <string, string>()
            {
                { "String1", JsonConvert.SerializeObject(data) },
                { "Int1", ViewBag.USER.NodeId.ToString() },
                { "Int2", ViewBag.USER.SystemUserId.ToString() },
            };

            var result = API.Post <string>("Eso/GeneratePrintRecipes", arg);

            return(new JsonResult {
                Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Esempio n. 4
0
        public MessageCustom SaveUpdateRecipe(BoardPrintRecipes data, int userId, int nodeId)
        {
            MessageCustom _MessageCustom = new MessageCustom();

            try
            {
                using (var ts = new TransactionScope())
                {
                    var result = new WarehouseDal().SaveUpdateRecipe(data, userId, nodeId);
                    if (!result)
                    {
                        throw new Exception("Sucedió un error al grabar la receta, por favor vuelva intentar.");
                    }
                    else
                    {
                        _MessageCustom.Error   = false;
                        _MessageCustom.Status  = (int)StatusHttp.Ok;
                        _MessageCustom.Message = "La receta se guardó correctamente.";
                        var filename = new EsoBl().BuildRecipe(data);
                        if (filename == null)
                        {
                            throw new Exception("Sucedió un error al generar el pdf de la receta, por favor vuelva intentar.");
                        }
                        else
                        {
                            _MessageCustom.Id = filename;
                        }
                    }
                    ts.Complete();
                }

                return(_MessageCustom);
            }
            catch (Exception ex)
            {
                _MessageCustom.Error   = true;
                _MessageCustom.Status  = (int)StatusHttp.BadRequest;
                _MessageCustom.Message = ex.Message;
                return(_MessageCustom);
            }
        }
        public string GenerateMovementInput(BoardPrintRecipes data)
        {
            string message = "";

            try
            {
                string movementId = _InputOutput.AddMovement(data);

                _InputOutput.AddMovementDetail(data, movementId);

                if (movementId != null)
                {
                    message = _InputOutput.ProcessMovementInput(movementId, data.InsertUserId.Value);
                }

                return(movementId);
            }
            catch (Exception ex)
            {
                message = ex.InnerException.Message;
                return(message);
            }
        }
        public bool SaveUpdateRecipe(BoardPrintRecipes data, int userId, int nodeId)
        {
            try
            {
                DatabaseContext ctx = new DatabaseContext();

                foreach (var item in data.ListProducts)
                {
                    DiagnosticCustom diag = new DiagnosticCustom();
                    diag.ComponentId = item.ComponentId;
                    diag.ServiceId   = data.ServiceId;
                    diag.DiseaseId   = item.DiseaseId;
                    if (item.RecetaId == null)
                    {
                        string diagnosticRespositoryId = new DiagnosticDal().AddDiagnosticRepository(diag, userId, nodeId);
                        if (diagnosticRespositoryId == null)
                        {
                            return(false);
                        }
                        else
                        {
                            item.DiagnosticRespository = diagnosticRespositoryId;
                        }
                    }
                    else
                    {
                        var objReceta = ctx.Receta.Where(x => x.i_IdReceta == item.RecetaId).FirstOrDefault();
                        item.DiagnosticRespository = objReceta.v_DiagnosticRepositoryId;
                    }



                    var  getPlan   = new PlanDal().GetPlan(data.ServiceId, item.IdLinea);
                    bool tienePlan = false;
                    if (getPlan.Count > 0)
                    {
                        tienePlan = true;
                    }

                    if (tienePlan)
                    {
                        if (getPlan[0].i_EsCoaseguro == (int)SiNo.Si)
                        {
                            var planCoaseguro = new PlanDal().GetPlanForImporte(data.ServiceId, item.DiagnosticRespository);
                            if (planCoaseguro.Count > 0)
                            {
                                item.SaldoPaciente    = (planCoaseguro[0].d_ImporteCo / 100) * (item.Price * decimal.Parse(item.Quantity.ToString()));
                                item.SaldoAseguradora = (item.Price * decimal.Parse(item.Quantity.ToString())) - item.SaldoPaciente;
                            }
                        }
                    }
                    else
                    {
                        item.SaldoPaciente = item.Price;
                    }


                    if (item.RecetaId == null)//Creo
                    {
                        RecetaBE _RecetaDto = new RecetaBE();
                        _RecetaDto.v_DiagnosticRepositoryId = item.DiagnosticRespository;
                        _RecetaDto.d_Cantidad           = decimal.Parse(item.Quantity.ToString());
                        _RecetaDto.v_Duracion           = item.Duration;
                        _RecetaDto.v_Posologia          = item.Posologia;
                        _RecetaDto.t_FechaFin           = item.FechaFin;
                        _RecetaDto.v_IdProductoDetalle  = item.ProductoDetalleId;
                        _RecetaDto.v_IdUnidadProductiva = item.IdLinea;
                        _RecetaDto.v_ServiceId          = data.ServiceId;
                        _RecetaDto.d_SaldoPaciente      = item.SaldoPaciente;
                        _RecetaDto.d_SaldoAseguradora   = item.SaldoAseguradora;

                        ctx.Receta.Add(_RecetaDto);
                    }
                    else//Actualizo
                    {
                        var objReceta = ctx.Receta.Where(x => x.i_IdReceta == item.RecetaId).FirstOrDefault();
                        objReceta.v_DiagnosticRepositoryId = item.DiagnosticRespository;
                        objReceta.d_Cantidad           = decimal.Parse(item.Quantity.ToString());
                        objReceta.v_Duracion           = item.Duration;
                        objReceta.v_Posologia          = item.Posologia;
                        objReceta.t_FechaFin           = item.FechaFin;
                        objReceta.v_IdProductoDetalle  = item.ProductoDetalleId;
                        objReceta.v_IdUnidadProductiva = item.IdLinea;
                        objReceta.v_ServiceId          = data.ServiceId;
                        objReceta.d_SaldoPaciente      = item.SaldoPaciente;
                        objReceta.d_SaldoAseguradora   = item.SaldoAseguradora;
                    }
                }


                ctx.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }