Facturacion

Solo disponible en BuenasTareas
  • Páginas : 6 (1457 palabras )
  • Descarga(s) : 0
  • Publicado : 25 de agosto de 2012
Leer documento completo
Vista previa del texto
FACTURA – BOLETA
BD. SQL SERVER

CREATE DATABASE SISTEMA
GO
USE SISTEMA
GO

CREATE TABLE CLIENTES
(IDCLI VARCHAR(5)NOT NULL ,
NOMBRE VARCHAR(20)NOT NULL,
APELLIDOS VARCHAR(50)NOT NULL,
SEXO VARCHAR(1)NULL,
Primary Key (IDCLI))
GO

INSERT INTO CLIENTES VALUES('C0001','LUIS','GOMEZ','M')
INSERT INTO CLIENTES VALUES('C0002','CARLOS','SANCHEZ','M')
INSERT INTO CLIENTESVALUES('C0003','ELIANA','CASTRO','M')
GO

CREATE TABLE EMPLEADOS
(IDEMP VARCHAR(5)NOT NULL,
NOMBRE VARCHAR(20)NOT NULL,
APELLIDOS VARCHAR(50)NOT NULL,
SEXO VARCHAR(1)NULL,
Primary Key (IDEMP))
GO

INSERT 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))
GO

CREATE TABLE DETALLE_DOCUMENTO(
NDOC VARCHAR (5)NOT NULL,
TIP_DOC VARCHAR (30) NOT NULL,
ITEMINT NOT NULL,
PRODUCTO VARCHAR(20) NOT NULL,
PRECIO REAL NULL,
CANTIDAD INT NULL,
PRIMARY KEY(ITEM,NDOC,TIP_DOC))
GO

ALTER TABLE CAB_DOCUMENTO
ADD FOREIGN KEY(IDCLI) REFERENCES CLIENTES
ALTER TABLE CAB_DOCUMENTO
ADD FOREIGN KEY(IDEMP) REFERENCES EMPLEADOS
ALTER TABLE DETALLE_DOCUMENTO
ADD FOREIGN KEY (NDOC,TIP_DOC) REFERENCES CAB_DOCUMENTO
GO

--CREACION DE LA TABLA GENERADOR
GOCREATE TABLE GENERADOR(
PARAMETRO Varchar(40) Not Null,
ULTIMO Int Null
)GO

-- INSERCCION DE DATOS EN LA TABLA GENERADOR
INSERT INTO GENERADOR values('DOCUMENTO',0)
GO

CREATE 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)
AS
BEGIN
INSERT INTOCAB_DOCUMENTO VALUES (@NDO, @TIP, @IDC,@IDE, @FEC,@SUBTOT,@IGV,@TOT,@EST)
END
GO

SELECT * FROM CLIENTES
SELECT * FROM EMPLEADOS
SELECT * FROM CAB_DOCUMENTO
SELECT * FROM DETALLE_DOCUMENTO
SELECT * FROM GENERADOR

APLICACIÓN. VISUAL STUDIO.NET
[pic]


[pic]

CODIGO Facturacion (Form1.vb)

Imports System.Data.SqlClient
Public Class Facturacion
Dim fila As Integer = -1
Dim TIPOAs String = ""
Dim D As Integer = 0
Dim pre As Double

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.txtFecha.Text = Now
End Sub

Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
Me.DatosGrid.Rows.Add("")
End SubPrivate Sub btnQuitar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuitar.Click
If fila -1 Then
Me.DatosGrid.Rows.RemoveAt(fila)
fila = -1
Else
MsgBox("Debe eliminar una fila")
End If
End Sub

Private Sub btnGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnGrabar.Click
Try
'CONDICIONES EN BOLETA
If radBoleta.Checked = True Then
TIPO = "BOLETA"
End If

If radFactura.Checked = True Then
TIPO = "FACTURA"
End If

'CABECERA
cn.Open()
Dim cmd As New SqlCommand("SP_MANTEDOCUMENTO", cn)
Dim prm AsNew SqlParameter

With cmd
.CommandType = CommandType.StoredProcedure

prm = .Parameters.Add("@NDO", SqlDbType.VarChar, 5)
prm.Value = Me.txtNum.Text

prm = .Parameters.Add("@TIP", SqlDbType.VarChar, 30)
prm.Value = TIPO

prm = .Parameters.Add("@IDC", SqlDbType.VarChar, 5)...
tracking img