private void PreFacturar() { try { using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { //pFormFac.cod_cliente = Convert.ToDecimal(vLiq.CODCLIENTE); //pFormFac.cod_liquidacion = Convert.ToDecimal(vLiq.Cod__Liquidación); //pFormFac.cod_moneda = Convert.ToInt32(((DropDownList)PreFacturaFormView.FindControl("new_monedaDDL")).SelectedValue); //pFormFac.fecha = System.DateTime.Now; //pFormFac.ruc = vLiq.R_U_C_.Trim(); //pFormFac.direccion = vLiq.Dirección; //pFormFac.cod_empresa = Convert.ToInt32(vLiq.CodEmpresa); //pFormFac.telefono = vLiq.Teléfono; //pFormFac.cod_tipo_factura = Guid.Parse(((DropDownList)PreFacturaFormView.FindControl("new_tipo_facturaDDL")).SelectedValue.ToString()); //pFormFac.nro_despacho_interno = Convert.ToDecimal(vLiq.Nro__Despacho_Interno.Trim()); //pFormFac.nro_despacho = vLiq.Nro__Despacho; Models.ProFormaFactura num_factura = new Models.ProFormaFactura { num_factura = Convert.ToDecimal(((TextBox)PreFacturaFormView.FindControl("new_num_facturaTB")).Text) }; Models.ProFormaFactura cod_cliente = new Models.ProFormaFactura { cod_cliente = Convert.ToDecimal(((TextBox)PreFacturaFormView.FindControl("new_CodClienteTB")).Text) }; Models.ProFormaFactura cod_liquidacion = new Models.ProFormaFactura { cod_liquidacion = Convert.ToDecimal(((TextBox)PreFacturaFormView.FindControl("new_num_liquidacionTB")).Text) }; Models.ProFormaFactura cod_moneda = new Models.ProFormaFactura { cod_moneda = Convert.ToInt32(((DropDownList)PreFacturaFormView.FindControl("new_monedaDDL")).SelectedValue) }; Models.ProFormaFactura fecha = new Models.ProFormaFactura { fecha = System.DateTime.Now }; Models.ProFormaFactura ruc = new Models.ProFormaFactura { ruc = ((TextBox)PreFacturaFormView.FindControl("new_rucTB")).Text }; Models.ProFormaFactura direccion = new Models.ProFormaFactura { direccion = ((TextBox)PreFacturaFormView.FindControl("new_direccionTB")).Text }; Models.ProFormaFactura cod_empresa = new Models.ProFormaFactura { cod_empresa = Convert.ToInt32(((TextBox)PreFacturaFormView.FindControl("new_CodEmpresaTB")).Text) }; Models.ProFormaFactura telefono = new Models.ProFormaFactura { telefono = ((TextBox)PreFacturaFormView.FindControl("new_telefonoTB")).Text }; db.ProFormaFacturas.Add(num_factura); db.ProFormaFacturas.Add(cod_cliente); db.ProFormaFacturas.Add(cod_liquidacion); //db.SaveChanges(); } } catch (Exception ex) { } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { /*Codigo de Inicializacion Beta*/ object[] para = { 1 }; using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { Models.Moneda moneda = db.Monedas.Find(para); Session["user.moneda_formato"] = moneda.formato.ToString(); Session["user.fecha_formato"] = "{0:dd/MM/yyyy}"; } } }
public static string GetParameter(string modulo, string key) { object[] busquedaParametro = { key, modulo }; string valor = null; using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { Models.Parametro parametro = db.Parametros.Find(busquedaParametro); valor = parametro.valor.ToString(); } return(valor); }
private void Obtener_datos_liquidacion(int p_cod_liquidacion) { try { /*Codigo de Inicializacion Beta*/ object[] para = { p_cod_liquidacion }; Models.V_LIQUIDACIONES vLiq; if (p_cod_liquidacion > 0) { using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { //Obtengo la Liquidacion segun el cod_liquidacion recibdo por el formulario web vLiq = db.V_LIQUIDACIONES.Find(para); ((TextBox)PreFacturaFormView.FindControl("new_num_facturaTB")).Attributes.Add("onblur", "javascript:verifyNroFactura(this);"); // Asignamos los valores a los campos del form view ((TextBox)PreFacturaFormView.FindControl("new_fechaTB")).Text = DateTime.Now.ToShortDateString(); ((TextBox)PreFacturaFormView.FindControl("new_clienteTB")).Text = vLiq.Cliente.Trim(); ((TextBox)PreFacturaFormView.FindControl("new_CodClienteTB")).Text = vLiq.CODUSUARIO.ToString(); ((TextBox)PreFacturaFormView.FindControl("new_CodEmpresaTB")).Text = vLiq.CODEMPRESA.ToString(); ((TextBox)PreFacturaFormView.FindControl("new_num_liquidacionTB")).Text = vLiq.Nro__Liquidación.ToString(); ((DropDownList)PreFacturaFormView.FindControl("new_monedaDDL")).SelectedIndex = 1; ((TextBox)PreFacturaFormView.FindControl("new_telefonoTB")).Text = vLiq.Teléfono.Trim(); ((TextBox)PreFacturaFormView.FindControl("new_rucTB")).Text = vLiq.R_U_C_.Trim(); ((TextBox)PreFacturaFormView.FindControl("new_direccionTB")).Text = vLiq.Dirección.Trim(); ((TextBox)PreFacturaFormView.FindControl("new_despachanteTB")).Text = vLiq.Despachante.Trim(); ((TextBox)PreFacturaFormView.FindControl("new_ruc_despachanteTB")).Text = vLiq.R_U_C__Despachante.Trim(); ((DropDownList)PreFacturaFormView.FindControl("new_tipo_facturaDDL")).SelectedIndex = 1; ((TextBox)PreFacturaFormView.FindControl("new_despacho_internoTB")).Text = vLiq.Nro__Despacho_Interno.Trim(); ((TextBox)PreFacturaFormView.FindControl("new_despachoTB")).Text = vLiq.Nro__Despacho.Trim(); ((TextBox)PreFacturaFormView.FindControl("new_totalTB")).Text = Core.Util.GetFormatedNumber(vLiq.Total); ((TextBox)PreFacturaFormView.FindControl("new_iva_gastosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Gastos); ((TextBox)PreFacturaFormView.FindControl("new_iva_honorariosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Honorarios); ((TextBox)PreFacturaFormView.FindControl("new_retencion_ivaTB")).Text = Core.Util.GetFormatedNumber(calcularRetenciones(Convert.ToDecimal(vLiq.IVA_Gastos), Convert.ToDecimal(vLiq.IVA_Retención))); ((TextBox)PreFacturaFormView.FindControl("new_retencion_iva_gastosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Ret__Gastos); ((TextBox)PreFacturaFormView.FindControl("new_retencion_iva_honorariosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Ret__Honorarios); } } } catch (Exception ex) { Response.Write(ex.Message); } }
public static string verifyNroFactura(string nroFactura) { using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { Models.Factura factura; Models.ProFormaFactura proFormaFactura; object[] busquedaFactura = { int.Parse(nroFactura) }; factura = db.Facturas.Find(busquedaFactura); proFormaFactura = db.ProFormaFacturas.Find(busquedaFactura); if ((factura != null && factura.cod_factura > 0) || (proFormaFactura != null && proFormaFactura.cod_ProFormafactura > 0)) { return("El nro de factura: " + nroFactura + " ya ha sido utilizado anteriormente, favor indique otro número"); } else { return(string.Empty); } } }
protected void SeleccionarClienteButton_Click(object sender, EventArgs e) { Type cstype = this.GetType(); try { using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { try { object[] para = { "cliente" }; Models.ParametrosBusqueda parametro = db.ParametrosBusquedas.Find(para); db.ParametrosBusquedas.Remove(parametro); } catch (Exception ax) { } Models.ParametrosBusqueda param_cliente = new Models.ParametrosBusqueda { parametro = "cliente", valor = ClienteTB.Text }; db.ParametrosBusquedas.Add(param_cliente); db.SaveChanges(); ClientScript.RegisterStartupScript(cstype, "NewWinScript", "Seleccionar();", true); } } catch (Exception ex) { Core.Util.ShowAlert("Error al buscar cliente: " + ex.Message); } }
private void PreFacturar() { try { using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { Models.ProFormaFactura p = new Models.ProFormaFactura(); Models.ProFormaFactura num_factura = new Models.ProFormaFactura { num_factura = Convert.ToDecimal(((TextBox)PreFacturaFormView.FindControl("new_num_facturaTB")).Text) }; Models.ProFormaFactura cod_cliente = new Models.ProFormaFactura { cod_cliente = Convert.ToDecimal(((TextBox)PreFacturaFormView.FindControl("new_CodClienteTB")).Text) }; Models.ProFormaFactura cod_liquidacion = new Models.ProFormaFactura { cod_liquidacion = Convert.ToDecimal(((TextBox)PreFacturaFormView.FindControl("new_num_liquidacionTB")).Text) }; Models.ProFormaFactura cod_moneda = new Models.ProFormaFactura { cod_moneda = Convert.ToInt32(((DropDownList)PreFacturaFormView.FindControl("new_monedaDDL")).SelectedValue) }; Models.ProFormaFactura fecha = new Models.ProFormaFactura { fecha = System.DateTime.Now }; Models.ProFormaFactura ruc = new Models.ProFormaFactura { ruc = ((TextBox)PreFacturaFormView.FindControl("new_rucTB")).Text }; Models.ProFormaFactura direccion = new Models.ProFormaFactura { direccion = ((TextBox)PreFacturaFormView.FindControl("new_direccionTB")).Text }; Models.ProFormaFactura cod_empresa = new Models.ProFormaFactura { cod_empresa = Convert.ToInt32(((TextBox)PreFacturaFormView.FindControl("new_CodEmpresaTB")).Text) }; Models.ProFormaFactura telefono = new Models.ProFormaFactura { telefono = ((TextBox)PreFacturaFormView.FindControl("new_telefonoTB")).Text }; Models.ProFormaFactura cod_tipo_factura = new Models.ProFormaFactura { cod_tipo_factura = Guid.Parse(((DropDownList)PreFacturaFormView.FindControl("new_tipo_facturaDDL")).SelectedValue.ToString()) }; Models.ProFormaFactura nro_despacho_interno = new Models.ProFormaFactura { nro_despacho_interno = Convert.ToDecimal(((TextBox)PreFacturaFormView.FindControl("new_despacho_internoTB")).Text) }; Models.ProFormaFactura nro_despacho = new Models.ProFormaFactura { nro_despacho = ((TextBox)PreFacturaFormView.FindControl("new_despachoTB")).Text }; /* * db.ProFormaFacturas.Add(num_factura); * db.ProFormaFacturas.Add(cod_cliente); * db.ProFormaFacturas.Add(cod_liquidacion); * db.ProFormaFacturas.Add(cod_moneda); * db.ProFormaFacturas.Add(fecha); * db.ProFormaFacturas.Add(ruc); * db.ProFormaFacturas.Add(direccion); * db.ProFormaFacturas.Add(cod_empresa); * db.ProFormaFacturas.Add(telefono); * db.ProFormaFacturas.Add(cod_tipo_factura); * db.ProFormaFacturas.Add(nro_despacho_interno); * db.ProFormaFacturas.Add(nro_despacho); */ db.SaveChanges(); for (int i = 0; i <= PreFacturaDetalleGridView.Rows.Count - 1; i++) { GridViewRow row = (GridViewRow)PreFacturaDetalleGridView.Rows[i]; CheckBox chk = (CheckBox)row.FindControl("ConceptoCheck"); if (chk.Checked) { Models.ProFormaFacturaDetalle secuencia = new Models.ProFormaFacturaDetalle { secuencia_interna = Convert.ToDecimal(((Label)row.FindControl("lblSecuencia")).Text) }; Models.ProFormaFacturaDetalle comentario = new Models.ProFormaFacturaDetalle { comentario = ((Label)row.FindControl("lblComentario")).Text }; Models.ProFormaFacturaDetalle cod_con_liquidacion = new Models.ProFormaFacturaDetalle { cod_con_liquidacion = Convert.ToDecimal(cod_liquidacion) }; Models.ProFormaFacturaDetalle descripcion = new Models.ProFormaFacturaDetalle { descripcion = ((Label)row.FindControl("lblConcepto")).Text }; Models.ProFormaFacturaDetalle grupo_impresion = new Models.ProFormaFacturaDetalle { grupo_impresion = Byte.Parse(((Label)row.FindControl("lblGrupo")).Text) }; Models.ProFormaFacturaDetalle importe = new Models.ProFormaFacturaDetalle { importe = Convert.ToDecimal(((Label)row.FindControl("lblImporte")).Text) }; Models.ProFormaFacturaDetalle facturado = new Models.ProFormaFacturaDetalle { Facturado = true }; } } } } catch (Exception ex) { } }
//Procedimiento que factura los concpetos de manera individual protected void FacturarConceptosBtn_Click(object sender, EventArgs e) { int v_cod_factura; try { //Asigno el Numero de factura NroFactura = ((TextBox)FacturaFormView.FindControl("new_num_facturaTB")).Text; FechaFactura = ((TextBox)FacturaFormView.FindControl("new_fechaTB")).Text; //Agrego la cabecera de la Factura de conceptos /*Ejecuto el procedieminto de Facturacion de la Liquidacion*/ using (SqlConnection conexion = new SqlConnection(FacturaDataSource.ConnectionString)) { conexion.Open(); SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.StoredProcedure; comando.Connection = conexion; comando.CommandText = "sp_facturar_liquidacion_cabecera"; comando.Parameters.AddWithValue("@p_cod_liquidacion", CodigoLiquidacion); comando.Parameters.AddWithValue("@p_nro_factura", NroFactura); comando.Parameters.AddWithValue("@p_fecha_factura", FechaFactura); comando.Parameters.AddWithValue("@p_tipo_factura", ((DropDownList)FacturaFormView.FindControl("new_tipo_facturaDDL")).SelectedValue); comando.Parameters.AddWithValue("@p_cod_moneda", ((DropDownList)FacturaFormView.FindControl("new_monedaDDL")).SelectedValue); SqlParameter p_cod_factura = new SqlParameter("@p_cod_factura", SqlDbType.Int); p_cod_factura.Direction = ParameterDirection.Output; comando.Parameters.Add(p_cod_factura); comando.CommandTimeout = 0; //Facturo la liquidación comando.ExecuteNonQuery(); //Obtengo el Codigo de Factura generado v_cod_factura = Convert.ToInt32(comando.Parameters["@p_cod_factura"].Value); conexion.Close(); } //Seccion de insercion de Detalles GridViewRow dr; //Agrego los Conceptos de la tabla Temporal using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { for (int i = 0; i <= FacturaDetalleGeneradaGridView.Rows.Count - 1; i++) { dr = FacturaDetalleGeneradaGridView.Rows[i]; Models.FacturaDetalle detalle = new Models.FacturaDetalle { Cod__Concepto = Convert.ToInt32(dr.Cells[4].Text), cod_factura = v_cod_factura, Cod__Liquidación = Convert.ToInt32(CodigoLiquidacion), Concepto = dr.Cells[1].Text, Comentario = dr.Cells[3].Text, Importe = Convert.ToDecimal(dr.Cells[2].Text), Grupo = Convert.ToInt32(dr.Cells[0].Text) }; db.FacturaDetalles.Add(detalle); } //Guardo los cmabios en la DB db.SaveChanges(); } //Actualizo los impouestos CalcularImpuestosFactura(v_cod_factura); //Elimino los Conceptos por facturar correspondiente a la factura EliminarConceptosMarcados(Convert.ToInt32(CodigoLiquidacion)); //Actualizo las grillas RefrescarGrillas(); //Verifico las facturaciones Verificarfacturacion(); //Limpio el cuadro de Numero de factura ya que se facturo con exito esta ((TextBox)FacturaFormView.FindControl("new_num_facturaTB")).Text = ""; //me posiciono en la seccion de facturas generadas SetFocusControl("#facturas"); } catch (Exception ex) { Core.Util.ShowAlert("Error al facturar conceptos: " + ex.Message); } }
//Procedimiento que agrega los conceptos de forma independiente para su facturacion en facturas separadas protected void AgregarBtn_Click(object sender, EventArgs e) { Decimal vImporte; try { //Asigno el Numero de factura NroFactura = ((TextBox)FacturaFormView.FindControl("new_num_facturaTB")).Text; FechaFactura = ((TextBox)FacturaFormView.FindControl("new_fechaTB")).Text; if (NroFactura != null && NroFactura != "") { using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { for (int i = 0; i <= FacturaDetalleGridView.Rows.Count - 1; i++) { GridViewRow row = (GridViewRow)FacturaDetalleGridView.Rows[i]; CheckBox chk = (CheckBox)row.FindControl("ConceptoCheck"); if (chk.Checked) { try { vImporte = Convert.ToDecimal(row.Cells[5].Text); } catch (Exception ax) { vImporte = 0; } InsertarConceptoMarcado(Convert.ToInt32(row.Cells[1].Text), Convert.ToInt32(row.Cells[2].Text), Convert.ToInt32(row.Cells[4].Text), 0, row.Cells[3].Text, vImporte, ""); // Habilitamos el boton para que se pueda eliminar la operacion this.EliminarBtn.Enabled = true; this.FacturarConceptosBtn.Enabled = true; } } } this.FacturaDetalleGeneradaGridView.DataBind(); // Cargamos nuevamente la grilla this.FacturaDetalleGridView.DataBind(); //Muevo el foco a la tabla de Faturas generadas SetFocusControl("#Generada"); } else { Core.Util.ShowAlert("El campo nro. de factura debe tener información."); } } catch (Exception ex) { Core.Util.ShowAlert("Error al agregar concepto: " + ex.Message); } }
//Procediemiento que recupera los datos de la liquidacion //segun el codigo de liquidacion que recibe la pagina private void Obtener_datos_liquidacion(int p_cod_liquidacion) { try { /*Codigo de Inicializacion Beta*/ object[] para = { p_cod_liquidacion }; Models.V_LIQUIDACIONES vLiq; //Models.ProFormaFactura pFormFac = new Models.ProFormaFactura(); if (p_cod_liquidacion > 0) { TextBox txtNew_fact = (TextBox)FacturaFormView.FindControl("new_num_facturaTB"); TextBox txtNew_ruc = (TextBox)FacturaFormView.FindControl("new_ruc_despachanteTB"); using (Models.WerkERPContext db = new WerkUI.Models.WerkERPContext()) { //Obtengo la Liquidacion segun el cod_liquidacion recibdo por el formulario web vLiq = db.V_LIQUIDACIONES.Find(para); } ((TextBox)FacturaFormView.FindControl("new_num_facturaTB")).Attributes.Add("onblur", "javascript:verifyNroFactura(this,'" + vLiq.R_U_C__Despachante + "');"); // Asignamos los valores a los campos del form view ((TextBox)FacturaFormView.FindControl("new_fechaTB")).Text = ((DateTime)vLiq.Fecha).ToShortDateString(); // DateTime.Now.ToShortDateString(); ((TextBox)FacturaFormView.FindControl("new_clienteTB")).Text = vLiq.Cliente.Trim(); ((TextBox)FacturaFormView.FindControl("new_CodClienteTB")).Text = vLiq.CODUSUARIO.ToString(); ((TextBox)FacturaFormView.FindControl("new_num_liquidacionTB")).Text = vLiq.Nro__Liquidación.ToString(); ((DropDownList)FacturaFormView.FindControl("new_monedaDDL")).SelectedIndex = 0; ((TextBox)FacturaFormView.FindControl("new_telefonoTB")).Text = vLiq.Teléfono.Trim(); ((TextBox)FacturaFormView.FindControl("new_rucTB")).Text = vLiq.R_U_C_.Trim(); ((TextBox)FacturaFormView.FindControl("new_direccionTB")).Text = vLiq.Dirección.Trim(); ((TextBox)FacturaFormView.FindControl("new_despachanteTB")).Text = vLiq.Despachante.Trim(); ((TextBox)FacturaFormView.FindControl("new_ruc_despachanteTB")).Text = vLiq.R_U_C__Despachante.Trim(); ((DropDownList)FacturaFormView.FindControl("new_tipo_facturaDDL")).SelectedIndex = 1; ((TextBox)FacturaFormView.FindControl("new_despacho_internoTB")).Text = vLiq.Nro__Despacho_Interno.Trim(); ((TextBox)FacturaFormView.FindControl("new_tipo_movimientoTB")).Text = vLiq.Tipo_Movimiento.Trim(); ((TextBox)FacturaFormView.FindControl("new_despachoTB")).Text = vLiq.Nro__Despacho.Trim(); ((TextBox)FacturaFormView.FindControl("new_totalTB")).Text = Core.Util.GetFormatedNumber(vLiq.Total); ((TextBox)FacturaFormView.FindControl("new_iva_gastosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Gastos); ((TextBox)FacturaFormView.FindControl("new_iva_honorariosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Honorarios); ((TextBox)FacturaFormView.FindControl("new_retencion_ivaTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Retención); ((TextBox)FacturaFormView.FindControl("new_retencion_iva_gastosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Ret__Gastos); ((TextBox)FacturaFormView.FindControl("new_retencion_iva_honorariosTB")).Text = Core.Util.GetFormatedNumber(vLiq.IVA_Ret__Honorarios); } FacturaDetalleGeneradaGridView.DataBind(); } catch (Exception ex) { Core.Util.ShowAlert("Error al obtener datos liquidación: " + ex.Message); } }