Your SlideShare is downloading. ×
SISTEMA DE FACTURACION (Ejemplo desarrollado)
Próxima SlideShare
Cargando en...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

SISTEMA DE FACTURACION (Ejemplo desarrollado)

91,496
views

Published on

Visual Studio 2008 ...

Visual Studio 2008
SQL Server 2008
Crystal Reports

Published in: Educación

21 comentarios
26 Me gusta
Estadísticas
Notas
Sin descargas
reproducciones
reproducciones totales
91,496
En SlideShare
0
De insertados
0
Número de insertados
1
Acciones
Compartido
0
Descargas
5,723
Comentarios
21
Me gusta
26
Insertados 0
No embeds

Denunciar contenido
Marcada como inapropiada Marcar como inapropiada
Marcar como inapropiada

Seleccione la razón para marcar esta presentación como inapropiada.

Cancelar
No notes for slide

Transcript

  • 1. http://sistemasddm.blogspot.comFACTURA – BOLETABD. SQL SERVERCREATE DATABASE SISTEMAGOUSE SISTEMAGOCREATE TABLE CLIENTES(IDCLI VARCHAR(5)NOT NULL ,NOMBRE VARCHAR(20)NOT NULL,APELLIDOS VARCHAR(50)NOT NULL,SEXO VARCHAR(1)NULL,Primary Key (IDCLI))GOINSERT INTO CLIENTES VALUES(C0001,LUIS,GOMEZ,M)INSERT INTO CLIENTES VALUES(C0002,CARLOS,SANCHEZ,M)INSERT INTO CLIENTES VALUES(C0003,ELIANA,CASTRO,M)GOCREATE TABLE EMPLEADOS(IDEMP VARCHAR(5)NOT NULL,NOMBRE VARCHAR(20)NOT NULL,APELLIDOS VARCHAR(50)NOT NULL,SEXO VARCHAR(1)NULL,Primary Key (IDEMP))GOINSERT INTO EMPLEADOS VALUES(E0001,LUIS,GOMEZ,M)INSERT INTO EMPLEADOS VALUES(E0002,FERNANDA,PEREZ,M)INSERT INTO EMPLEADOS VALUES(E0003,LUISA,VERASTEGUI,M)GO--DOCUMENTO--CREATE TABLE CAB_DOCUMENTO(NDOC VARCHAR (5) NOT NULL,TIP_DOC VARCHAR (30) NOT NULL,IDCLI VARCHAR(5) NOT NULL,IDEMP VARCHAR (5)NOT NULL,FECHA DATETIME NOT NULL,SUBTOTAL REAL NULL,IGV REAL NULL,TOTAL REAL NULL,ESTADO VARCHAR(20) NOT NULL,PRIMARY KEY(NDOC,TIP_DOC))GOCREATE TABLE DETALLE_DOCUMENTO(NDOC VARCHAR (5)NOT NULL,TIP_DOC VARCHAR (30) NOT NULL,ITEM INT NOT NULL,PRODUCTO VARCHAR(20) NOT NULL,PRECIO REAL NULL,CANTIDAD INT NULL,PRIMARY KEY(ITEM,NDOC,TIP_DOC))GOALTER TABLE CAB_DOCUMENTOADD FOREIGN KEY(IDCLI) REFERENCES CLIENTES
  • 2. http://sistemasddm.blogspot.comALTER TABLE CAB_DOCUMENTOADD FOREIGN KEY(IDEMP) REFERENCES EMPLEADOSALTER TABLE DETALLE_DOCUMENTOADD FOREIGN KEY (NDOC,TIP_DOC) REFERENCES CAB_DOCUMENTOGO--CREACION DE LA TABLA GENERADORGOCREATE TABLE GENERADOR(PARAMETRO Varchar(40) Not Null,ULTIMO Int Null)GO-- INSERCCION DE DATOS EN LA TABLA GENERADORINSERT INTO GENERADOR values(DOCUMENTO,0)GOCREATE PROCEDURE SP_MANTEDOCUMENTO@NDO VARCHAR (5),@TIP VARCHAR (30),@IDC VARCHAR(5),@IDE VARCHAR (5),@FEC DATETIME ,@SUBTOT REAL,@IGV REAL,@TOT REAL,@EST VARCHAR(20)ASBEGININSERT INTO CAB_DOCUMENTO VALUES (@NDO, @TIP, @IDC,@IDE,@FEC,@SUBTOT,@IGV,@TOT,@EST)ENDGOSELECT * FROM CLIENTESSELECT * FROM EMPLEADOSSELECT * FROM CAB_DOCUMENTOSELECT * FROM DETALLE_DOCUMENTOSELECT * FROM GENERADORAPLICACIÓN. VISUAL STUDIO.NET
  • 3. http://sistemasddm.blogspot.com
  • 4. http://sistemasddm.blogspot.comCODIGO Facturacion (Form1.vb)Imports System.Data.SqlClientPublic Class FacturacionDim fila As Integer = -1Dim TIPO As String = ""Dim D As Integer = 0Dim pre As DoublePrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.LoadMe.txtFecha.Text = NowEnd SubPrivate Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnAgregar.ClickMe.DatosGrid.Rows.Add("")End SubPrivate Sub btnQuitar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnQuitar.ClickIf fila <> -1 ThenMe.DatosGrid.Rows.RemoveAt(fila)fila = -1ElseMsgBox("Debe eliminar una fila")End IfEnd SubPrivate Sub btnGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnGrabar.ClickTryCONDICIONES EN BOLETAIf radBoleta.Checked = True ThenTIPO = "BOLETA"End IfIf radFactura.Checked = True ThenTIPO = "FACTURA"End IfCABECERAcn.Open()Dim cmd As New SqlCommand("SP_MANTEDOCUMENTO", cn)Dim prm As New SqlParameterWith cmd.CommandType = CommandType.StoredProcedureprm = .Parameters.Add("@NDO", SqlDbType.VarChar, 5)prm.Value = Me.txtNum.Textprm = .Parameters.Add("@TIP", SqlDbType.VarChar, 30)prm.Value = TIPO
  • 5. http://sistemasddm.blogspot.comprm = .Parameters.Add("@IDC", SqlDbType.VarChar, 5)prm.Value = Me.txtCodCli.Textprm = .Parameters.Add("@IDE", SqlDbType.VarChar, 5)prm.Value = Me.txtCodEmpl.Textprm = .Parameters.Add("@FEC", SqlDbType.DateTime)prm.Value = Me.txtFecha.Textprm = .Parameters.Add("@SUBTOT", SqlDbType.Real)prm.Value = Me.txtSubTotal.Textprm = .Parameters.Add("@IGV", SqlDbType.Real)prm.Value = Me.txtIgv.Textprm = .Parameters.Add("@TOT", SqlDbType.Real)prm.Value = Me.txtTotal.Textprm = .Parameters.Add("@EST", SqlDbType.VarChar, 20)prm.Value = Me.cbEstado.SelectedItem.ExecuteNonQuery()End Withcn.Close()cmd.Dispose()DETALLEDim I As IntegerDim prod, precio, cant, imp, sql2 As StringFor I = 0 To DatosGrid.Rows.Count - 1prod = DatosGrid.Rows(I).Cells(0).Valueprecio = DatosGrid.Rows(I).Cells(1).Valuecant = DatosGrid.Rows(I).Cells(2).Valueimp = DatosGrid.Rows(I).Cells(3).Valuesql2 = "INSERT INTO DETALLE_DOCUMENTO VALUES(" + Me.txtNum.Text + "," + TIPO + "," +(I + 1).ToString + ", " + prod + " , " + precio + " , " + cant + ")"Dim cmd2 As New SqlCommand(sql2, cn)cn.Open()cmd2.ExecuteNonQuery()cn.Close()cmd2.Dispose()NextMsgBox("Documento Almacenado")ACTUALIZARDim cmd3 As New SqlCommand("UPDATE GENERADOR SET ULTIMO = ULTIMO + 1WHERE PARAMETRO = DOCUMENTO", cn)cn.Open()cmd3.ExecuteNonQuery()cn.Close()cmd3.Dispose()pre = 0Catch ex As ExceptionMsgBox(ex.Message)cn.Close()End TryEnd Sub
  • 6. http://sistemasddm.blogspot.comPrivate Sub btnBusCliente_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnBusCliente.ClickTryDim NR As Integer = -1Dim Codigo As String = ""Codigo = InputBox("Ingrese Cliente:")Dim Da1 As New SqlDataAdapter("select * from CLIENTES where IdCLI = " + Codigo + "", cn)Da1.Fill(dsEntorno, "Busq1")NR = dsEntorno.Tables("Busq1").Rows.CountIf NR > 0 ThenMe.txtCodCli.Text = dsEntorno.Tables("Busq1").Rows(0)(0)Me.txtNomCli.Text = dsEntorno.Tables("Busq1").Rows(0)(1)ElseMsgBox("Cliente no Existe")End IfdsEntorno.Tables("Busq1").Rows.Clear()Catch ex As ExceptionMsgBox(ex.Message)End TryEnd SubPrivate Sub btnBusEmpleado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnBusEmpleado.ClickTryDim NR As Integer = -1Dim Codigo As String = ""Codigo = InputBox("Ingrese Empleado:")Dim Da1 As New SqlDataAdapter("select * from EMPLEADOS where IDEMP = " + Codigo + "", cn)Da1.Fill(dsEntorno, "Busq2")NR = dsEntorno.Tables("Busq2").Rows.CountIf NR > 0 ThenMe.txtCodEmpl.Text = dsEntorno.Tables("Busq2").Rows(0)(0)Me.txtNomEmp.Text = dsEntorno.Tables("Busq2").Rows(0)(1)ElseMsgBox("Empleado no Existe")End IfdsEntorno.Tables("Busq2").Rows.Clear()Catch ex As ExceptionMsgBox(ex.Message)MsgBox(ex.ToString)End TryEnd SubPrivate Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnNuevo.ClickCall limpiar()Me.txtNum.Text = Generadores("DOCUMENTO")End SubSub limpiar()Me.txtNum.Text = ""Me.txtCodCli.Text = ""Me.txtNomCli.Text = ""Me.txtCodEmpl.Text = ""Me.txtNomEmp.Text = ""
  • 7. http://sistemasddm.blogspot.comMe.txtSubTotal.Text = ""Me.txtIgv.Text = ""Me.txtTotal.Text = ""Me.cbEstado.Text = ""Me.DatosGrid.Rows.Clear()Me.DatosGrid.DataSource = NothingD = 0End SubPrivate Sub DatosGrid_CellClick(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.DataGridViewCellEventArgs) Handles DatosGrid.CellClickfila = e.RowIndexEnd SubPrivate Sub DatosGrid_CellEnter(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.DataGridViewCellEventArgs) Handles DatosGrid.CellEnterTryIf (DatosGrid.Rows(D).Cells(2).Value > 0) ThenMe.DatosGrid.Rows(D).Cells(3).Value = Me.DatosGrid.Rows(D).Cells(2).Value *Me.DatosGrid.Rows(D).Cells(1).ValueEnd IfIf (radBoleta.Checked = True) ThenIf (DatosGrid.Rows(D).Cells(3).Value > 0) Thenpre = pre + DatosGrid.Rows(D).Cells(3).ValueMe.txtSubTotal.Text = preMe.txtIgv.Text = 0Me.txtTotal.Text = Me.txtSubTotal.TextD = D + 1End IfElseIf (radFactura.Checked = True) ThenIf (DatosGrid.Rows(D).Cells(3).Value > 0) Thenpre = pre + DatosGrid.Rows(D).Cells(3).ValueMe.txtSubTotal.Text = preMe.txtIgv.Text = (Val(Me.txtSubTotal.Text) * 0.19)Me.txtTotal.Text = (Val(Me.txtSubTotal.Text) + Val(Me.txtIgv.Text))D = D + 1End IfEnd IfCatch ex As ExceptionMsgBox(ex.Message)End TryEnd SubPrivate Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnImprimir.ClicktipoDocu = cbTipoDocu.SelectedItemcodDocu = txtCodigoDocu.TextfrmImprimir.Show()End SubEnd Class
  • 8. http://sistemasddm.blogspot.comMODULO DE CONEXION Y AUTOGENERADOR DE CODIGO (Generar.vb)Imports System.Data.SqlClientModule GenerarPublic cn As New SqlConnection("server=localhost;database=SISTEMA; integrated security = true")Public dsEntorno As New DataSetPublic tipoDocu As StringPublic codDocu As StringPublic Function Generadores(ByVal TABLA As String) As StringDim RESULT As String = ""Dim DR1 As SqlDataReaderDim ULT As Integer = 0Dim CMD As New SqlCommand("SELECT ULTIMO FROM GENERADOR WHERE PARAMETRO = " +TABLA + "", cn)cn.Open()DR1 = CMD.ExecuteReaderWhile DR1.ReadULT = Val(DR1("ULTIMO") + 1)End Whilecn.Close()Dim CEROS As IntegerCEROS = 5 - Len(Str(ULT))Select Case CEROSCase 3 : RESULT = Left(TABLA, 1) + "000" + Trim(Str(ULT))Case 2 : RESULT = Left(TABLA, 1) + "00" + Trim(Str(ULT))Case 1 : RESULT = Left(TABLA, 1) + "0" + Trim(Str(ULT))Case 0 : RESULT = Left(TABLA, 1) + "" + Trim(Str(ULT))End SelectGeneradores = RESULTEnd FunctionEnd Module
  • 9. http://sistemasddm.blogspot.comMODELO CRISTAL REPORT (Reporte.rpt)
  • 10. http://sistemasddm.blogspot.comFORMULARIO PARA VISUALIZAR EL REPORTE (FrmImprimir.vb)CODIGO DE FrmImprimirImports System.Data.SqlClientPublic Class frmImprimirDim Cn As New SqlConnection("Server=LocalHost;Uid=sa;Password=123;Database=SISTEMA")Dim INFORME1 As ReporteDim MITABLA As CrystalDecisions.CrystalReports.Engine.TableDim MILOGIN As CrystalDecisions.Shared.TableLogOnInfoPrivate Sub frmImprimir_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.LoadTryINFORME1 = New ReporteFor Each Me.MITABLA In INFORME1.Database.TablesMILOGIN = MITABLA.LogOnInfoMILOGIN.ConnectionInfo.Password = "123"MILOGIN.ConnectionInfo.UserID = "sa"MITABLA.ApplyLogOnInfo(MILOGIN)NextMe.CrystalReportViewer1.ReportSource = INFORME1INFORME1.RecordSelectionFormula = "{CAB_DOCUMENTO.TIP_DOC}=" + tipoDocu + " And{DETALLE_DOCUMENTO.NDOC}=" + codDocu + ""Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd SubEnd Class