Ejemplo n.º 1
0
        private void txtMedicamento_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            TicketBL oTicketBL = new TicketBL();
            var      f         = new frmSearchMedicamento();
            var      result    = f.ShowDialog();

            if (result == DialogResult.OK)
            {
                var medicamento = f.MedicamentoSeleccionado;
                if (medicamento == null)
                {
                    return;
                }
                txtMedicamento.Text      = medicamento.NombreCompleto;
                txtMedicamento.Tag       = medicamento.IdProductoDetalle;
                idUnidadProductiva       = medicamento.IdLinea;
                txtUnidadProductiva.Text = medicamento.IdLinea;
                txtPrecio.Text           = medicamento.PrecioVenta.ToString();
                var tienePlan  = false;
                var resultplan = oTicketBL.TienePlan(_protocolId, txtUnidadProductiva.Text);
                if (resultplan.Count > 0)
                {
                    tienePlan = true;
                }
                else
                {
                    tienePlan = false;
                }

                if (tienePlan)
                {
                    if (resultplan[0].i_EsCoaseguro == 1)
                    {
                        #region Conexion SAM
                        ConexionSigesoft conectasam = new ConexionSigesoft();
                        conectasam.opensigesoft();
                        #endregion
                        var           cadena1 = "select PR.r_MedicineDiscount, OO.v_Name, PR.v_CustomerOrganizationId from Organization OO inner join protocol PR On PR.v_AseguradoraOrganizationId = OO.v_OrganizationId where PR.v_ProtocolId ='" + _protocolId + "'";
                        SqlCommand    comando = new SqlCommand(cadena1, connection: conectasam.conectarsigesoft);
                        SqlDataReader lector  = comando.ExecuteReader();
                        string        eps     = "";
                        while (lector.Read())
                        {
                            eps = lector.GetValue(0).ToString();
                        }
                        lector.Close();
                        conectasam.closesigesoft();
                        //calculo nuevo precio
                        txtPPS.Text     = medicamento.d_PrecioMayorista.ToString();
                        txtDctoEPS.Text = eps;
                        decimal nuevoPrecio = decimal.Parse(txtPPS.Text) - ((decimal.Parse(eps) * decimal.Parse(txtPPS.Text)) / 100);
                        txtNuevoPrecio.Text = nuevoPrecio.ToString();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            TicketBL oTicketBL = new TicketBL();

            if (_TempTicketDetalleList == null)
            {
                _TempTicketDetalleList = new List <TicketDetalleList>();
            }
            OperationResult objOperationResult = new OperationResult();

            string[] componentIdFromProtocol = _TempTicketDetalleList.FindAll(p => p.i_RecordStatus != (int)RecordStatus.EliminadoLogico)
                                               .Select(p => p.v_IdProductoDetalle).ToArray();

            bool IsExists = _ticketlBL.IsExistsproductoInTicket(ref objOperationResult, componentIdFromProtocol, _ProductoId);

            if (IsExists)
            {
                var msj = string.Format("El examen producto puede agregar, ya existe", labelmensaje.Text);
                MessageBox.Show(msj, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (_mode == "New")
            {
                // || cbExamen.Text == ""
                if (txtMedicamento.Tag == null)
                {
                    string mensage = "";
                    if (txtMedicamento.Tag == null)
                    {
                        mensage = @"Por favor seleccione un medicamento";
                    }
                    //else if (cbExamen.Text == ""){mensage = @"Por favor seleccione un examen";}
                    MessageBox.Show(mensage, @"Error de validación", MessageBoxButtons.OK);
                    txtMedicamento.Focus();
                    return;
                }

                var findResult = _TempTicketDetalleList.Find(p => p.v_IdProductoDetalle == _ProductoId);
                _objTicketDetalleList = new TicketDetalleList();

                if (findResult == null)
                {
                    _objTicketDetalleList.v_TicketDetalleId = Guid.NewGuid().ToString();

                    _objTicketDetalleList.v_IdProductoDetalle  = txtMedicamento.Tag.ToString();
                    _objTicketDetalleList.v_NombreProducto     = txtMedicamento.Text;
                    _objTicketDetalleList.v_CodInterno         = txtCodigo.Text;
                    _objTicketDetalleList.v_IdUnidadProductiva = txtUnidadProductiva.Text;
                    var precioTarifa = oTicketBL.ObtenerPrecioTarifario(_serviceId, _objTicketDetalleList.v_IdProductoDetalle);


                    decimal d;
                    _objTicketDetalleList.d_Cantidad = decimal.TryParse(txtCantidad.Text, out d) ? d : 0;

                    //nuevo
                    //int planId = 0;
                    //var servicioDet = oTicketBL.GetService(ref objOperationResult,_serviceId);
                    //if (servicioDet.i_PlanId != null)
                    //{
                    //    planId = (int)servicioDet.i_PlanId;
                    //}
                    //////


                    var tienePlan = false;
                    //var resultplan = oTicketBL.TienePlan_(_protocolId, planId);
                    var resultplan = oTicketBL.TienePlan(_protocolId, lineId);

                    if (resultplan.Count > 0)
                    {
                        tienePlan = true;
                    }
                    else
                    {
                        tienePlan = false;
                    }

                    if (tienePlan)
                    {
                        if (resultplan[0].i_EsCoaseguro == 1)
                        {
                            #region Conexion SIGESOFT verificar la unidad productiva del componente
                            ConexionSigesoft conectasam = new ConexionSigesoft();
                            conectasam.opensigesoft();
                            var cadena1 = "select PL.d_ImporteCo, PL.i_PlanId " +
                                          "from [dbo].[plan] PL " +
                                          "inner join protocol PR on PL.v_ProtocoloId=PR.v_ProtocolId " +
                                          "where PR.v_ProtocolId='" + _protocolId + "' and PL.v_IdUnidadProductiva='" + lineId + "'";
                            SqlCommand    comando = new SqlCommand(cadena1, connection: conectasam.conectarsigesoft);
                            SqlDataReader lector = comando.ExecuteReader();
                            string        ImporteCo = ""; string PlanId = "";
                            bool          lectorleido = false;
                            while (lector.Read())
                            {
                                ImporteCo   = lector.GetValue(0).ToString();
                                PlanId      = lector.GetValue(1).ToString();
                                lectorleido = true;
                            }

                            if (lectorleido == false)
                            {
                                MessageBox.Show(@"Elija un Examen que tenga Plan de Seguros", @"Error de validación", MessageBoxButtons.OK);
                                return;
                            }
                            lector.Close();

                            #endregion
                            _objTicketDetalleList.d_SaldoPaciente    = decimal.Round((decimal.Parse(txtPrecioVenta.Text)), 2) * decimal.Round((decimal.Parse(txtCantidad.Text)), 2) * decimal.Round((decimal.Parse(ImporteCo)), 2) / 100;
                            _objTicketDetalleList.d_SaldoAseguradora = decimal.Round((decimal.Parse(txtPrecioVenta.Text)), 2) * decimal.Round((decimal.Parse(txtCantidad.Text)), 2) - _objTicketDetalleList.d_SaldoPaciente;
                            _objTicketDetalleList.d_PrecioVenta      = decimal.Round((decimal.Parse(txtPrecioVenta.Text)), 2);

                            #region Update a service agrega el PlanId
                            var cadena2 = "update service set " +
                                          "i_PlanId = '" + PlanId + "' " +
                                          "where v_ServiceId = '" + _serviceId + "' ";
                            SqlCommand    comando_ = new SqlCommand(cadena2, connection: conectasam.conectarsigesoft);
                            SqlDataReader lector_  = comando_.ExecuteReader();
                            lector_.Close();

                            conectasam.closesigesoft();
                            #endregion
                        }
                        else if (resultplan[0].i_EsDeducible == 1)
                        {
                        }
                    }
                    else
                    {
                        _objTicketDetalleList.d_PrecioVenta = decimal.Round((decimal.Parse(txtPrecio.Text)), 2);   // decimal.Parse(txtPrecioVenta.Text);
                    }

                    _objTicketDetalleList.i_RecordStatus = (int)RecordStatus.Agregado;
                    _objTicketDetalleList.i_RecordType   = (int)RecordType.Temporal;


                    _TempTicketDetalleList.Add(_objTicketDetalleList);
                }
                else
                {
                    if (findResult.i_RecordStatus == (int)RecordStatus.EliminadoLogico)
                    {
                        if (findResult.i_RecordType == (int)RecordType.NoTemporal)
                        {
                            _objTicketDetalleList.v_IdProductoDetalle  = txtMedicamento.Tag.ToString();
                            _objTicketDetalleList.v_NombreProducto     = txtMedicamento.Text;
                            _objTicketDetalleList.v_CodInterno         = txtCodigo.Text;
                            _objTicketDetalleList.v_IdUnidadProductiva = txtUnidadProductiva.Text;
                            var precioTarifa = oTicketBL.ObtenerPrecioTarifario(_serviceId, _objTicketDetalleList.v_IdProductoDetalle);
                            _objTicketDetalleList.d_PrecioVenta = precioTarifa;    // decimal.Parse(txtPrecioVenta.Text);
                            decimal d;
                            _objTicketDetalleList.d_Cantidad = decimal.TryParse(txtCantidad.Text, out d) ? d : 0;

                            var tienePlan  = false;
                            var resultplan = oTicketBL.TienePlan(_protocolId, txtUnidadProductiva.Text);
                            if (resultplan.Count > 0)
                            {
                                tienePlan = true;
                            }
                            else
                            {
                                tienePlan = false;
                            }

                            if (tienePlan)
                            {
                                if (resultplan[0].i_EsCoaseguro == 1)
                                {
                                    _objTicketDetalleList.d_SaldoPaciente    = resultplan[0].d_Importe;
                                    _objTicketDetalleList.d_SaldoAseguradora = (decimal.Parse(_objTicketDetalleList.d_PrecioVenta.ToString()) * _objTicketDetalleList.d_Cantidad) - resultplan[0].d_Importe;
                                }
                                if (resultplan[0].i_EsDeducible == 1)
                                {
                                    _objTicketDetalleList.d_SaldoPaciente    = resultplan[0].d_Importe * decimal.Parse(_objTicketDetalleList.d_PrecioVenta.ToString()) * _objTicketDetalleList.d_Cantidad / 100;
                                    _objTicketDetalleList.d_SaldoAseguradora = (decimal.Parse(_objTicketDetalleList.d_PrecioVenta.ToString()) * _objTicketDetalleList.d_Cantidad) - _objTicketDetalleList.d_SaldoPaciente;
                                }
                            }

                            findResult.i_RecordStatus = (int)RecordStatus.Grabado;
                        }
                        else if (findResult.i_RecordType == (int)RecordType.Temporal)       // El registro tiene un ID temporal [GUID]
                        {
                            _objTicketDetalleList.v_IdProductoDetalle  = txtMedicamento.Tag.ToString();
                            _objTicketDetalleList.v_NombreProducto     = txtMedicamento.Text;
                            _objTicketDetalleList.v_CodInterno         = txtCodigo.Text;
                            _objTicketDetalleList.d_PrecioVenta        = decimal.Parse(txtPrecioVenta.Text);
                            _objTicketDetalleList.v_IdUnidadProductiva = txtUnidadProductiva.Text;
                            decimal d;
                            _objTicketDetalleList.d_Cantidad = decimal.TryParse(txtCantidad.Text, out d) ? d : 0;

                            var tienePlan  = false;
                            var resultplan = oTicketBL.TienePlan(_protocolId, txtUnidadProductiva.Text);
                            if (resultplan.Count > 0)
                            {
                                tienePlan = true;
                            }
                            else
                            {
                                tienePlan = false;
                            }

                            if (tienePlan)
                            {
                                if (resultplan[0].i_EsCoaseguro == 1)
                                {
                                    _objTicketDetalleList.d_SaldoPaciente    = resultplan[0].d_Importe;
                                    _objTicketDetalleList.d_SaldoAseguradora = (decimal.Parse(_objTicketDetalleList.d_PrecioVenta.ToString()) * _objTicketDetalleList.d_Cantidad) - resultplan[0].d_Importe;
                                }
                                if (resultplan[0].i_EsDeducible == 1)
                                {
                                    _objTicketDetalleList.d_SaldoPaciente    = resultplan[0].d_Importe * decimal.Parse(_objTicketDetalleList.d_PrecioVenta.ToString()) * _objTicketDetalleList.d_Cantidad / 100;
                                    _objTicketDetalleList.d_SaldoAseguradora = (decimal.Parse(_objTicketDetalleList.d_PrecioVenta.ToString()) * _objTicketDetalleList.d_Cantidad) - _objTicketDetalleList.d_SaldoPaciente;
                                }
                            }

                            _objTicketDetalleList.i_RecordType = (int)RecordType.Temporal;

                            findResult.i_RecordStatus = (int)RecordStatus.Agregado;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Por favor seleccione otro medicamento. ya existe", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
            }
            else if (_mode == "Edit")
            {
                var     result = _TempTicketDetalleList.Find(p => p.v_TicketDetalleId == _id);
                decimal d;
                result.d_Cantidad = decimal.Round((decimal.TryParse(txtCantidad.Text, out d) ? d : 0), 2);
                if ((result.d_SaldoAseguradora != null || result.d_SaldoAseguradora >= 0) || result.d_SaldoPaciente != null || result.d_SaldoPaciente >= 0)
                {
                    result.d_SaldoAseguradora =
                        decimal.Round((decimal.TryParse(txtCantidad.Text, out d) ? d : 0), 2) * decimal.Round((decimal)result.d_PrecioVenta, 2);
                    result.d_SaldoPaciente = 0;
                }
                result.v_CodInterno   = txtCodigo.Text;
                result.i_RecordStatus = (int)RecordStatus.Modificado;
            }
            MessageBox.Show("Se grabo correctamente.", "INFORMACION!", MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.Close();
        }
Ejemplo n.º 3
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            TicketBL oTicketBL = new TicketBL();

            try
            {
                _pobjOperationResult = new OperationResult();
                if (!uvDatos.Validate(true, false).IsValid)
                {
                    return;
                }

                if (txtMedicamento.Tag == null)
                {
                    MessageBox.Show(@"Por favor seleccione un medicamento", @"Error de validación", MessageBoxButtons.OK);
                    txtMedicamento.Focus();
                    return;
                }

                decimal d;
                _recetaDto.d_Cantidad           = decimal.TryParse(txtCantidad.Text, out d) ? d : 0;
                _recetaDto.v_Duracion           = txtDuracion.Text.Trim();
                _recetaDto.v_Posologia          = txtPosologia.Text.Trim();
                _recetaDto.t_FechaFin           = dtpFechaFin.Value;
                _recetaDto.v_IdProductoDetalle  = txtMedicamento.Tag.ToString();
                _recetaDto.v_IdUnidadProductiva = idUnidadProductiva;
                _recetaDto.v_ServiceId          = _serviceId;

                var tienePlan  = false;
                var resultplan = oTicketBL.TienePlan(_protocolId, txtUnidadProductiva.Text);
                if (resultplan.Count > 0)
                {
                    tienePlan = true;
                }
                else
                {
                    tienePlan = false;
                }

                if (tienePlan)
                {
                    if (resultplan[0].i_EsCoaseguro == 1)
                    {
                        #region Conexion SIGESOFT verificar la unidad productiva del componente
                        ConexionSigesoft conectasam = new ConexionSigesoft();
                        conectasam.opensigesoft();
                        var cadena1 = "select PL.d_ImporteCo " +
                                      "from [dbo].[plan] PL " +
                                      "inner join protocol PR on PL.v_ProtocoloId=PR.v_ProtocolId " +
                                      "inner join servicecomponent SC on PL.v_IdUnidadProductiva=SC.v_IdUnidadProductiva " +
                                      "inner join diagnosticrepository DR on DR.v_ComponentId=SC.v_ComponentId " +
                                      "where PR.v_ProtocolId='" + _protocolId + "' and DR.v_DiagnosticRepositoryId='" + _idDiagnosticRepository + "' ";
                        SqlCommand    comando     = new SqlCommand(cadena1, connection: conectasam.conectarsigesoft);
                        SqlDataReader lector      = comando.ExecuteReader();
                        string        ImporteCo   = "";
                        bool          lectorleido = false;
                        while (lector.Read())
                        {
                            ImporteCo   = lector.GetValue(0).ToString();
                            lectorleido = true;
                        }
                        if (lectorleido == false)
                        {
                            MessageBox.Show(@"El consultorio no tiene Plan de Seguros", @"Error de validación", MessageBoxButtons.OK);
                            return;
                        }
                        lector.Close();
                        conectasam.closesigesoft();
                        #endregion
                        _recetaDto.d_SaldoPaciente    = (decimal.Parse(ImporteCo) / 100) * (decimal.Parse(txtNuevoPrecio.Text) * _recetaDto.d_Cantidad);
                        _recetaDto.d_SaldoAseguradora = (decimal.Parse(txtNuevoPrecio.Text) * _recetaDto.d_Cantidad) - _recetaDto.d_SaldoPaciente;
                    }
                }
                else
                {
                    _recetaDto.d_SaldoPaciente = decimal.Parse(txtPrecio.Text) * _recetaDto.d_Cantidad;
                }

                _objRecetaBl.AddUpdateRecipe(ref _pobjOperationResult, _recetaDto);

                if (_pobjOperationResult.Success == 0)
                {
                    MessageBox.Show(_pobjOperationResult.ErrorMessage, @"Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, @"btnGuardar_Click()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }