#include "FiveWin.ch"
#include "XBrowse.ch"
#include "Splitter.ch"
#include "Dtpicker.ch"
#include "InKey.ch"
MEMVAR oDatos
FUNCTION mfacventas()
LOCAL oDlg, nFor := 0, oError, oQBtn[2] ,;
cQryCli, oQryCli, cQryVen, oQryVen, cQryTrn, oQryTrn ,;
oBrw, oCol, aItems := {} ,;
aBtn[10], aVar[30], aGet[30] ,;
aCondi := { "CONTADO", "CREDITO" } ,;
aStatus := { "ACTIVA ", "PAGADA ", "ANULADA" }
// APERTURA DE TABLAS RELACIONADAS...
cQryCli := "SELECT * FROM clientes ORDER BY cli_codigo ASC"
TRY
oQryCli := TDolphinQry():New( cQryCli, oDatos:oConex )
CATCH oError
MSGSTOP( oError:description() + CRLF + CRLF + ;
"Error Ejecución de Sentencia en Tabla(clientes): " + ;
CRLF + CRLF + cQryCli, oDatos:cTitMsg )
RETURN( NIL )
END
cQryVen := "SELECT * FROM vendedores ORDER BY ven_codigo ASC"
TRY
oQryVen := TDolphinQry():New( cQryVen, oDatos:oConex )
CATCH oError
MSGSTOP( oError:description() + CRLF + CRLF + ;
"Error Ejecución de Sentencia en Tabla(vendedores): " + ;
CRLF + CRLF + cQryVen, oDatos:cTitMsg )
RETURN( NIL )
END
cQryTrn := "SELECT * FROM transporte ORDER BY trn_codigo ASC"
TRY
oQryTrn := TDolphinQry():New( cQryTrn, oDatos:oConex )
CATCH oError
MSGSTOP( oError:description() + CRLF + CRLF + ;
"Error Ejecución de Sentencia en Tabla(transporte): " + ;
CRLF + CRLF + cQryTrn, oDatos:cTitMsg )
RETURN( NIL )
END
// FIN APERTURA DE TABLAS RELACIONADAS...
// DEFINICION VARIABLES
aVar[1] := SPACE(10) // COD.CLIENTE
aVar[2] := SPACE(50) // NOMB.CLIENTE
aVar[3] := SPACE(10) // COD.VENDEDOR
aVar[4] := SPACE(50) // NOMB.VENDEDOR
aVar[5] := SPACE(10) // COD.TRANS.
aVar[6] := SPACE(50) // NOMB.TRANS.
aVar[7] := SPACE(10) // COMENTARIOS(memo)
aVar[8] := 1 // CONDICIONES(combo.box)
aVar[9] := 0 // DIAS PLAZO CREDITO
aVar[10] := 1 // ESTADO FACT.(combo.box)
aVar[11] := DATE() // FCH.FACT.
aVar[12] := DATE() // FCH.VENCE.
aVar[13] := 0 // NUM.CONTROL
aVar[14] := 0 // NUM.FACTURA
FOR nFor := 15 TO 24 // INICIALIZO var EN CERO
aVar[nFor] := 0.00
if nFor == 23
aVar[nFor] := -700
endif
NEXT
aVar[17] := oDatos:oQryCnf:por_iva // VALOR DE TABLA config
DEFINE DIALOG oDlg RESOURCE "FAC_COM-VTA" ;
TITLE oDatos:cTitDlg + " - VENTAS - Facturas de Ventas" ;
GRADIENT { { 1, nRGB( 125, 155, 175 ), nRGB( 125, 155, 175 ) } }
// EMPIEZA xBROWSE FACTURA...
REDEFINE xBrowse oBrw ID 100 of oDlg ;
HEADERS "CODIGO", "DESCRIPCION", "UNIDAD", "CANTIDAD", "PRECIO", "DESC", "SUB-TOTAL" ;
COLUMNS 1, 2, 3, 4, 5, 6, 7 ;
COLSIZES 100, 200, 70, 70, 70, 70, 70 ;
JUSTIFY AL_LEFT, AL_LEFT, AL_LEFT, AL_RIGHT, AL_RIGHT, AL_RIGHT, AL_RIGHT ;
PICTURES , , , "@E 9,999,999", "@E 9,999,999.99", "@E 999.99%", "@E 9,999,999.99" ;
ARRAY aItems FASTEDIT LINES
// CONFIGURACION DEL xBROWSE
WITH OBJECT oBrw
* :nMarqueeStyle := MARQSTYLE_HIGHLROW // NO PERMITE EDICION CELDA AUTO.
:nMarqueeStyle := MARQSTYLE_HIGHLCELL
:nColDividerStyle := LINESTYLE_BLACK
:nStretchCol := STRETCHCOL_LAST
:bRClicked := { || msginfo( "pulsastes boton derecho..." ) } // LLAMA MENU-POPUP CON BOTON DERECHO
:lColDividerComplete := .t.
:nHeaderHeight := 30 // ANCHO CABEZERA
:l2007 := .t.
:lFooter := .t.
* :lRecordSelector := .t. // SI/NO 1RA.COL.IZQ.QUE TIENE LA FLECHITA NEGRA
:lAllowColHiding := .f. // SI/NO BOTON DERECHO SOBRE CABEZERA, MUESTRE ARRAY COL.
:lAllowColSwapping := .f. // SI/NO INTERCAMBIAR COL.
:bClrStd := {|| IF( oBrw:nArrayAt % 2 == 0, {CLR_BLACK, CLR_WHITE}, {0, RGB(203, 226, 254)} ) }
:bKeyDown := {| nKey | teclado( nKey, oBrw, aVar, aGet ) } // CONTROLA VIRTUAL KEY
***:bPastEof := { || addrow( oBrw ) } // HACE EDICION DE CELDA AUTOMATICAMENTE CON FLECHA ABAJO...
END WITH
// COLOR GRADIANTE EN XBROWSE...
oBrw:bClrGrad := { | lInvert | IF( ! lInvert, ;
{ { 0.710,8388608,16777215 }, ;
{ 0.710,16777215,8388608 } }, ;
{ { 0.710,8388608,16777215 }, ;
{ 0.710,16777215,8388608 } } ) }
// COL.1 - CODIGO PRODUCTO
WITH OBJECT oBrw:aCols[1]
:bStrData := {|| IIF( LEN( aItems ) = 0, SPACE(10) ,;
aItems[oBrw:nArrayAt, 1] ) }
:cEditPicture := "@X"
:nEditType := EDIT_GET_BUTTON // EDIT_GET // EDIT_GET_LISTBOX
:bEditBlock := { || alert("Llamar maestro de Inventario") } // VALID BUTTON EN GET
:bEditValid := { | oGet, oCol | IF( !novacio( oGet:value ) , .f. ,;
buscacodigo( oGet, oCol, oBrw ) ) } // VALIDA ANTES DE PERDER FOCUS
:bOnPostEdit := { | oCol, xVal, nKey | IF( nKey <> VK_ESCAPE ,; // DESPUES DE LA EDICION
( oCol:value := xVal ,;
aItems[oBrw:nArrayAt, 2] := "DESCRIPCION DEL PRODUCTO" ,;
oBrw:SelectCol( 4 ) ), ) } // MUEVO PUNTERO A COL(n)
:bEditWhen := {|| LEN( oBrw:aArrayData ) > 0 } // REVISAR ESTO....DA ERROR DE RANGO ARRAY....
:bLClickHeader := { || alert("pulsaste boton izq.sobre cabecera col.") }
:cToolTip := "usando ToolTips..."
END WITH
// COL.2 - NOMBRE/DESCRIPCION
WITH OBJECT oBrw:aCols[2]
:bStrData := {|| IIF( LEN( aItems ) = 0, SPACE(10) ,;
aItems[oBrw:nArrayAt, 2] ) }
:nEditType := EDIT_BUTTON // EDIT_GET // EDIT_GET_LISTBOX
END WITH
// COL.3 - UNIDAD
WITH OBJECT oBrw:aCols[3]
:bStrData := {|| IIF( LEN( aItems ) = 0, SPACE(10) ,;
aItems[oBrw:nArrayAt, 3] ) }
:cFooter := "ITEMS =>"
:nFootStrAlign := AL_RIGHT // ALINEA DATA FOOTER
:nEditType := EDIT_LISTBOX
:aEditListTxt := { "UNIDAD", "AGRU1", "AGRU2" }
:bEditWhen := {|| IF( EMPTY( aItems[oBrw:nArrayAt, 1] ), .f., .t. ) }
:bOnPostEdit := { | oCol, xVal, nKey | If( nKey <> VK_ESCAPE ,;
( oCol:value:= xVal, alert(xVal) ), ) }
END WITH
// COL.4 - CANTIDAD
WITH OBJECT oBrw:aCols[4]
:bStrData := {|| IIF( LEN( aItems ) = 0, SPACE(10) ,;
aItems[oBrw:nArrayAt, 4] ) }
:cEditPicture := "@E 9,999,999"
:nFootStrAlign := AL_RIGHT // ALINEA DATA FOOTER
:lTotal := .t. // PARA TOTALIZAR COL.
:nTotal := 0 // PARA TOTALIZAR COL.
:nFooterType := AGGR_SUM // PARA TOTALIZAR COL.
:nEditType := EDIT_GET
:bEditValid := { | oGet, oCol | mayorqcero( oGet:value() ) }
:bOnPostEdit := { | oCol, xVal, nKey | If( nKey <> VK_ESCAPE ,;
( oCol:value := xVal ) , ) }
:bEditWhen := {|| !EMPTY( aItems[oBrw:nArrayAt, 1] ) }
END WITH
// COL.5 - PVP
WITH OBJECT oBrw:aCols[5]
:bStrData := {|| IIF( LEN( aItems ) = 0, SPACE(10) ,;
aItems[oBrw:nArrayAt, 5] ) }
:cEditPicture := "@E 9,999,999.99"
:nFootStrAlign := AL_RIGHT
:nEditType := EDIT_GET_BUTTON
:bEditBlock := { || alert("Seleccionar Varios Precios...") }
:bEditValid := { | oGet, oCol | mayorqcero( oGet:value() ) }
:bOnPostEdit := { | oCol, xVal, nKey | If( nKey <> VK_ESCAPE ,;
( oCol:value := xVal ,;
totalinea( oBrw, aVar, aGet ) ), ) }
:bEditWhen := {|| !EMPTY( aItems[oBrw:nArrayAt, 1] ) }
END WITH
// COL.6 - % DESCUENTO
WITH OBJECT oBrw:aCols[6]
:bStrData := {|| IIF( LEN( aItems ) = 0, SPACE(10) ,;
aItems[oBrw:nArrayAt, 6] ) }
:cFooter := "SUB-TOTAL=>"
:cEditPicture := "@E 999.99 %"
:nEditType := EDIT_GET
:bEditValid := { | oGet, oCol | IF( menorqcero( oGet:value() ) ,;
menorqcien( oGet:value() ), .f. ) }
:bOnPostEdit := { | oCol, xVal, nKey | If( nKey <> VK_ESCAPE ,;
( oCol:value := xVal ,;
totalinea( oBrw, aVar, aGet ) ,;
addrow( oBrw ) ) , ) }
:bEditWhen := {|| !EMPTY( aItems[oBrw:nArrayAt, 1] ) .and. ;
aItems[oBrw:nArrayAt, 5] > 0 }
END WITH
// COL.7 - TOTAL LINEA
WITH OBJECT oBrw:aCols[7]
:bStrData := {|| IIF( LEN( aItems ) = 0, SPACE(10) ,;
aItems[oBrw:nArrayAt, 7] ) }
:cEditPicture := "@E9,999,999.99"
:nFootStrAlign := AL_RIGHT // ALINEA DATA FOOTER
:lTotal := .t. // PARA TOTALIZAR COL.
:nTotal := 0 // PARA TOTALIZAR COL.
:nFooterType := AGGR_SUM // PARA TOTALIZAR COL.
:cToolTip := "Columna 7"
END WITH
oBrw:MakeTotals()
oBrw:Refresh()
// DATOS CLIENTE
REDEFINE GET aGet[1] VAR aVar[1] ID 101 OF oDlg PICTURE "@!" UPDATE ; // COD.CLIENTE
ACTION ( oQBtn := llamabrow( oQryCli, aVar[1], {"cli_codigo", "cli_nombre"} ,;
{"Código", "Nombre"} ) ,;
IIF( !oQBtn[1] ,;
( alert("DEBE SELECCIONAR CLIENTE o ZERO PARA CLIENTE VARIOS...") ,;
aVar[2] := nil, aGet[2]:REFRESH(), .f. ) ,;
( aVar[1] := oQBtn[2]:cli_codigo, aGet[1]:REFRESH() ,;
aVar[2] := oQBtn[2]:cli_nombre, aGet[2]:REFRESH() ,;
aGet[3]:SetFocus(), .t. ) ) ) ;
VALID ( IIF( oQryCli:Seek( aVar[1], "cli_codigo" ) == 0 ,;
( oQBtn := llamabrow( oQryCli, aVar[1], {"cli_codigo", "cli_nombre"} ,;
{"Código", "Nombre"} ) ,;
( IIF( !oQBtn[1] ,;
( alert("DEBE SELECCIONAR CLIENTE o ZERO PARA CLIENTE VARIOS...") ,;
aVar[2] := nil, aGet[2]:REFRESH(), .f. ) ,;
( aVar[1] := oQBtn[2]:cli_codigo, aGet[1]:REFRESH() ,;
aVar[2] := oQBtn[2]:cli_nombre, aGet[2]:REFRESH(), .t. ) ) ) ) ,;
( alert("ENTRO VALOR QUE EXISTE") ,;
aVar[1] := oQryCli:cli_codigo, aGet[1]:REFRESH() ,;
aVar[2] := oQryCli:cli_nombre, aGet[2]:REFRESH(), .t. ) ) )
REDEFINE GET aGet[2] VAR aVar[2] ID 102 OF oDlg UPDATE READONLY // NOMB.CLIENTE
REDEFINE GET aGet[3] VAR aVar[3] ID 103 OF oDlg PICTURE "@!" UPDATE ; // COD.VENDEDOR
ACTION ( oQBtn := llamabrow( oQryVen, aVar[3], {"ven_codigo", "ven_nombres"} ,;
{"Código", "Nombre"} ) ,;
IIF( !oQBtn[1] ,;
( alert("DEBE SELECCIONAR VENDEDOR...") ,;
aVar[4] := nil, aGet[4]:REFRESH(), .f. ) ,;
( aVar[3] := oQBtn[2]:ven_codigo, aGet[3]:REFRESH() ,;
aVar[4] := ALLTRIM( oQBtn[2]:ven_nombres ) + " " + ;
ALLTRIM( oQBtn[2]:ven_apellidos ) ,;
aGet[4]:REFRESH() ,;
aGet[5]:SetFocus(), .t. ) ) ) ;
VALID ( IIF( oQryVen:Seek( aVar[3], "ven_codigo" ) == 0 ,;
( oQBtn := llamabrow( oQryVen, aVar[3], {"ven_codigo", "ven_nombres"} ,;
{"Código", "Nombre"} ) ,;
( IIF( !oQBtn[1] ,;
( alert("DEBE SELECCIONAR VENDEDOR...") ,;
aVar[4] := nil, aGet[4]:REFRESH(), .f. ) ,;
( aVar[3] := oQBtn[2]:ven_codigo, aGet[3]:REFRESH() ,;
aVar[4] := ALLTRIM( oQBtn[2]:ven_nombres ) + " " + ;
ALLTRIM( oQBtn[2]:ven_apellidos ) ,;
aGet[4]:REFRESH(), .t. ) ) ) ) ,;
( alert("ENTRO VALOR QUE EXISTE") ,;
aVar[3] := oQryVen:ven_codigo, aGet[3]:REFRESH() ,;
aVar[4] := oQryVen:ven_nombres, aGet[4]:REFRESH(), .t. ) ) )
REDEFINE GET aGet[4] VAR aVar[4] ID 104 OF oDlg UPDATE READONLY // NOMB.VENDEDOR
REDEFINE GET aGet[5] VAR aVar[5] ID 105 OF oDlg PICTURE "@!" UPDATE ; // COD.TRANS.
ACTION ( oQBtn := llamabrow( oQryTrn, aVar[5], {"trn_codigo", "trn_nombre"} ,;
{"Código", "Nombre"} ) ,;
IIF( !oQBtn[1] ,;
( alert("DEBE SELECCIONAR TRANSPORTE...") ,;
aVar[6] := nil, aGet[6]:REFRESH(), .f. ) ,;
( aVar[5] := oQBtn[2]:trn_codigo, aGet[5]:REFRESH() ,;
aVar[6] := oQBtn[2]:trn_nombre, aGet[6]:REFRESH() ,;
aGet[7]:SetFocus(), .t. ) ) ) ;
VALID ( IIF( oQryTrn:Seek( aVar[5], "trn_codigo" ) == 0 ,;
( oQBtn := llamabrow( oQryTrn, aVar[5], {"trn_codigo", "trn_nombre"} ,;
{"Código", "Nombre"} ) ,;
( IIF( !oQBtn[1] ,;
( alert("DEBE SELECCIONAR TRANSPORTE...") ,;
aVar[6] := nil, aGet[6]:REFRESH(), .f. ) ,;
( aVar[5] := oQBtn[2]:trn_codigo, aGet[5]:REFRESH() ,;
aVar[6] := oQBtn[2]:trn_nombre, aGet[6]:REFRESH(), .t. ) ) ) ) ,;
( alert("ENTRO VALOR QUE EXISTE") ,;
aVar[5] := oQryTrn:trn_codigo, aGet[5]:REFRESH() ,;
aVar[6] := oQryTrn:trn_nombre, aGet[6]:REFRESH(), .t. ) ) )
REDEFINE GET aGet[6] VAR aVar[6] ID 106 OF oDlg UPDATE READONLY // NOMB.TRANS.
REDEFINE GET aGet[7] VAR aVar[7] MEMO ID 107 OF oDlg MULTILINE // COMENTARIOS
REDEFINE COMBOBOX aGet[8] VAR aVar[8] ITEMS aCondi ID 108 OF oDlg UPDATE // CONDICIONES
REDEFINE GET aGet[9] VAR aVar[9] ID 109 OF oDlg PICTURE "@E 9,999" UPDATE ; // DIAS PLAZO
VALID( menorqcero( aVar[9] ) ) ;
WHEN ( aVar[8] == 2 )
REDEFINE COMBOBOX aGet[10] VAR aVar[10] ITEMS aStatus ID 110 OF oDlg UPDATE // STATUS
REDEFINE DTPICKER aGet[11] VAR aVar[11] ID 111 OF oDlg UPDATE ; // FCH.FACT.
VALID( IIF( !validfecha( aVar[11] ), .f. ,;
( aVar[12] := aVar[11] + aVar[9], aGet[12]:REFRESH(), .t. ) ) )
REDEFINE GET aGet[12] VAR aVar[12] ID 112 OF oDlg UPDATE READONLY // FCH.VENCE
REDEFINE GET aGet[13] VAR aVar[13] ID 113 OF oDlg PICTURE "9999999999" UPDATE ; // NUM.CONTROL
VALID( IIF( !mayorqcero( aVar[13] ), .f., ( aVar[13] := STRZERO( aVar[13], 10 ) ,;
aGet[13]:REFRESH() ,;
addrow( oBrw ), .t. ) ) )
REDEFINE GET aGet[14] VAR aVar[14] ID 114 OF oDlg PICTURE "9999999999" UPDATE ; // NUM.FACTURA
READONLY
// DESC. IVA Y TOTALES FACTURA
// DESCUENTOS
REDEFINE GET aGet[15] VAR aVar[15] ID 115 OF oDlg PICTURE "@E 999.99" UPDATE ; // % DESC.SOBRE MTO.BRUTO
VALID( IIF( aVar[15] >= 0, netopagar( aVar[18], aVar, aGet ), .t. ) )
REDEFINE GET aGet[16] VAR aVar[16] ID 116 OF oDlg PICTURE "@E 9,999,999.99" UPDATE ; // MTO.DESC.SOBRE MTO.BRUTO
VALID( IIF( aVar[16] >= 0, netopagar( aVar[18], aVar, aGet ), .t. ) )
// IVA
REDEFINE GET aGet[17] VAR aVar[17] ID 117 OF oDlg PICTURE "@E 999.99" // % IVA
// TOTALES
REDEFINE GET aGet[18] VAR aVar[18] ID 118 OF oDlg PICTURE "@E 9,999,999.99" UPDATE // MTO.SIN IVA
REDEFINE GET aGet[19] VAR aVar[19] ID 119 OF oDlg PICTURE "@E 9,999,999.99" UPDATE // MTO.DESC.
REDEFINE GET aGet[20] VAR aVar[20] ID 120 OF oDlg PICTURE "@E 9,999,999.99" UPDATE // MTO.IVA
REDEFINE GET aGet[21] VAR aVar[21] ID 121 OF oDlg PICTURE "@E 9,999,999.99" UPDATE // MTO.NETO PAGAR
REDEFINE GET aGet[22] VAR aVar[22] ID 122 OF oDlg PICTURE "@E 9,999,999.99" UPDATE // MTO.SIN IVA - MTO.DESC.
REDEFINE GET aGet[23] VAR aVar[23] ID 123 OF oDlg PICTURE "@E 9,999,999.99" UPDATE // MTO.EXENTO(no paga imp.)
// BOTONES CUERPO FACTURA
REDEFINE BUTTONBMP aBtn[1] ID 201 OF oDlg UPDATE ; // INC.REG.
ACTION ( addrow( oBrw ) ) ;
BITMAP "incluir32" PROMPT "Incluir" + CRLF + "[F2]"
REDEFINE BUTTONBMP aBtn[2] ID 202 OF oDlg ; // MOD.REG.
ACTION ( alert("en construccion...") ) ;//ACTION ( modrow( oBrw ) ) ;
BITMAP "modificar32" PROMPT "Modificar" + CRLF + "[F3]" ;
WHEN ( LEN( oBrw:aArrayData ) > 0 ) UPDATE
REDEFINE BUTTONBMP aBtn[3] ID 203 OF oDlg ; // ELI.REG.
ACTION ( delrow( oBrw, aVar, aGet ) ) ;
BITMAP "eliminar32" PROMPT "E&liminar" + CRLF + "[F4]" ;
WHEN ( LEN( oBrw:aArrayData ) > 0 ) UPDATE
REDEFINE BUTTONBMP aBtn[4] ID 204 OF oDlg ; // BUSCAR REG.
ACTION ( alert("buscar reg.") ) ;
BITMAP "buscar32" PROMPT "B&uscar" + CRLF + "[F5]" ;
WHEN ( LEN( oBrw:aArrayData ) > 0 ) UPDATE
REDEFINE BUTTONBMP aBtn[5] ID 205 OF oDlg UPDATE ; // CANCELAR FACT.
ACTION ( oDlg:END() ) ;
BITMAP "Cancelar32" PROMPT "Cancelar" + CRLF + "[F6]"
REDEFINE BUTTONBMP aBtn[6] ID 206 OF oDlg UPDATE ; // FINALIZAR FACT.
ACTION ( alert("Fin Factura"), grabafactu( .t., .t., aVar, oBrw ), oDlg:END() ) ;
BITMAP "finalizar32" PROMPT "&Finalizar" + CRLF + "[F7]" ;//WHEN ( aVar[21] > 0 )
REDEFINE BUTTONBMP aBtn[7] ID 207 OF oDlg ; // IMP.RENGLONES
ACTION ( alert("Importar renglon desde...") ) ;
BITMAP "importar32" PROMPT "&Importar" + CRLF + "[F12]" ;
WHEN ( LEN( oBrw:aArrayData ) > 0 ) UPDATE
aBtn[5]:lCancel := .t.
// FIN BOTONES CUERPO FACTURA
ACTIVATE DIALOG oDlg CENTER
oQryCli:END(); oQryVen:END(); oQryTrn:END()
RETURN ( .t. )
STATIC FUNCTION buscacodigo( oGet, oCol, oBrw ) // BUSCO CODIGO
* ? "busco codigo..."
RETURN ( .t. )
STATIC FUNCTION addrow( oBrw ) // ADICIONO REGISTRO
IF LEN( oBrw:aArrayData ) > 0
oBrw:GoBottom()
IF oBrw:aArrayData[ oBrw:nArrayAt, 7] > 0
AADD( oBrw:aArrayData ,;
{ , , "UNIDAD", 0, 0, 0, 0 } )
ENDIF
ELSE
AADD( oBrw:aArrayData ,;
{ , , "UNIDAD", 0, 0, 0, 0 } )
ENDIF
oBrw:SetPos( , 1, ) // MUEVE PUNTO A COL.1
oBrw:GoBottom()
oBrw:Refresh()
oBrw:SetFocus()
RETURN nil
STATIC FUNCTION modirow( oBrw ) // MODIFICAR REGISTRO
oBrw:SetPos( , 1, ) // MUEVE PUNTO A COL.1
oBrw:Refresh()
oBrw:SetFocus()
RETURN nil
STATIC FUNCTION totalinea( oBrw, aVar, aGet ) // TOTAL POR RENGLON CON Y SIN DESC.
// TOTAL = CANTIDAD * PRECIO
oBrw:aArrayData[oBrw:nArrayAt, 7] := ;
( oBrw:aArrayData[oBrw:nArrayAt, 4] * oBrw:aArrayData[oBrw:nArrayAt, 5] )
// TOTAL = TOTAL - MTO.DESCUENTO
oBrw:aArrayData[oBrw:nArrayAt, 7] := ;
oBrw:aArrayData[oBrw:nArrayAt, 7] - ;
( oBrw:aArrayData[oBrw:nArrayAt, 7] * oBrw:aArrayData[oBrw:nArrayAt, 6] / 100 )
oBrw:MakeTotals(); oBrw:Refresh()
netopagar( oBrw:aCols[7]:nTotal, aVar, aGet ) // CALCULA NETO PAGAR
RETURN nil
STATIC FUNCTION netopagar( nSTotal, aVar, aGet ) // CALCULA NETO PAGAR
LOCAL nFor := 0
aVar[18] := nSTotal // MTO.SIN IVA NI DESCUENTO
aVar[19] := aVar[16] + ( aVar[18] * aVar[15] ) / 100 // MTO.DESCUENTO GENERAL
aVar[22] := aVar[18] - aVar[19]
aVar[20] := ( ( ( aVar[18]-aVar[19] ) * aVar[17] ) / 100 ) // MTO.IVA SEGUN TASA ACTIVA
aVar[21] := ( aVar[18] - aVar[19] ) + aVar[20]
FOR nFor := 18 TO 22
aGet[nFor]:REFRESH()
NEXT
RETURN ( .t. )
STATIC FUNCTION delrow( oBrw, aVar, aGet ) // ELIMINO REGISTRO
IF LEN( oBrw:aArrayData ) == 0
MSGINFO( "No hay Registro(s) para Eliminar...", oDatos:cTitMsg )
RETURN nil
ENDIF
IF MSGNOYES( "Seguro Desea ELIMINAR el Registro: " + ;
ALLTRIM( cValToChar( oBrw:aArrayData[oBrw:nArrayAt, 1] ) ) + " ?", oDatos:cTitMsg )
IF oBrw:nLen > 0
ADEL( oBrw:aArrayData, oBrw:nArrayAt )
ASIZE( oBrw:aArrayData, oBrw:nLen - 1 )
ENDIF
ENDIF
oBrw:GOTOP()
oBrw:SetFocus()
oBrw:MakeTotals()
oBrw:Refresh()
netopagar( oBrw:aCols[7]:nTotal, aVar, aGet ) // CALCULA NETO PAGAR
RETURN nil
FUNCTION grabafactu( lNew, lTipoVta, aVar, oBrwMFV ) // GRABO FACTURA Y CUERPO FACTURA
// lNew -> FACTURA NUEVA/MODIFICADA
// lTipoVta -> CONTROLA TIPO VTA. FACT.VTA.CON PRODUCTOS(.t.) / DOCUMENTO(.f.)
// aVar -> DATOS CABEZERA Y TOTALES DE FV.
// oBrwMFV -> MAESTRO DE FV.
LOCAL cQryFV, cQryMFV, cQryCNF, oError ,;
nFor := 0, nFactura := 0
IF aVar[21] == 0 // SI POR ALGUN MOTIVO LLEGA SIN MONTO
alert("factura sin mto.neto...")
RETURN .t.
ENDIF
oDatos:oQryCnf:REFRESH() // REFRESCO TABLA config, QUERY PUBLICO
nFactura := oDatos:oQryCnf:num_factura
nFactura := nFactura + 1 // DEBO HACER nFac = AL No.MAS ALTO EN config + 1
IF oDatos:oQryCnf:LastRec() = 0 // VERIFICO SI TABLA ESTA VACIA
cQryCNF := "INSERT INTO config SET num_factura = ' " + ClipValue2SQL( nFactura ) + "'"
ELSE
cQryCNF := "UPDATE config SET num_factura = ' " + ClipValue2SQL( nFactura ) + "'"
ENDIF
TRY
oDatos:oConex:Execute( cQryCNF )
CATCH oError
MSGSTOP( oError:Description + CRLF + "Error Grabando en Tabla (config), Sentencia" + ;
CRLF + CRLF + cQryCNF, oDatos:cTitMsg )
END
oDatos:oQryCnf:REFRESH()
aVar[14] := nFactura // ACTUALIZO NUM.FACT.PARA GRABAR EN facturas
// GRABO FACTURA
IF lNew
cQryFV := "INSERT INTO facturas SET "
cQryFV += "fac_numfac=" + ClipValue2SQL( aVar[14] ) + ","
ELSE
cQryFV := "UPDATE facturas SET "
ENDIF
cQryFV += "fac_codicli=" + ClipValue2SQL( aVar[1] ) + ","
cQryFV += "fac_nombcli=" + ClipValue2SQL( aVar[2] ) + ","
cQryFV += "fac_codiven=" + ClipValue2SQL( aVar[3] ) + ","
cQryFV += "fac_nombven=" + ClipValue2SQL( aVar[4] ) + ","
cQryFV += "fac_coditrans=" + ClipValue2SQL( aVar[5] ) + ","
cQryFV += "fac_nombtrans=" + ClipValue2SQL( aVar[6] ) + ","
cQryFV += "fac_comentarios=" + ClipValue2SQL( Val2Escape( aVar[7] ) ) + ","
cQryFV += "fac_condiciones=" + ClipValue2SQL( aVar[8] ) + ","
cQryFV += "fac_diasplazo=" + ClipValue2SQL( aVar[9] ) + ","
cQryFV += "fac_status=" + ClipValue2SQL( aVar[10] ) + ","
cQryFV += "fac_fchfac=" + ClipValue2SQL( aVar[11] ) + ","
cQryFV += "fac_fchvence=" + ClipValue2SQL( aVar[12] ) + ","
cQryFV += "fac_numctrl=" + ClipValue2SQL( aVar[13] ) + ","
//
cQryFV += "fac_pordesc=" + ClipValue2SQL( aVar[15] ) + ","
cQryFV += "fac_mtodesc=" + ClipValue2SQL( aVar[16] ) + ","
cQryFV += "fac_poriva=" + ClipValue2SQL( aVar[17] ) + ","
cQryFV += "fac_mtototal=" + ClipValue2SQL( aVar[18] ) + ","
cQryFV += "fac_totdesc=" + ClipValue2SQL( aVar[19] ) + ","
cQryFV += "fac_mtosobre=" + ClipValue2SQL( aVar[22] ) + ","
cQryFV += "fac_mtoiva=" + ClipValue2SQL( aVar[20] ) + ","
cQryFV += "fac_mtoexento=" + ClipValue2SQL( aVar[23] ) + ","
cQryFV += "fac_neto=" + ClipValue2SQL( aVar[21] ) + ","
cQryFV += "usuario=" + ClipValue2SQL( Val2Escape( "JL" ) ) + ","
cQryFV += "fchcrea=" + ClipValue2SQL( DATE() )
TRY // GRABO EN LA TABLA...
oDatos:oConex:Execute( cQryFV )
CATCH oError
MSGSTOP( oError:Description + CRLF + "Error Grabando en Tabla (factura), Sentencia" + ;
CRLF + CRLF + cQryFV, oDatos:cTitMsg )
END
// FIN GRABO DATOS FACTURA / DOCUMENTO
return .t.
IF !lTipoVta // VTA.DOCUMENTO
RETURN .t.
ENDIF
// GRABO CUERPO FACTURA
IF lNew // SIEMPE ES NUEVA, SI SE USA MODIFICAR FV SE CAMBIARA
FOR nFor := 1 TO LEN( oBrwMFV:aArrayData )
cQryMFV := "INSERT INTO movi_facturas SET "
cQryMFV += "cod_producto=" + ClipValue2SQL( oBrwMFV:aArrayData[nFor,1] ) + ","
cQryMFV += "nom_producto=" + ClipValue2SQL( oBrwMFV:aArrayData[nFor,2] ) + ","
cQryMFV += "cantidad=" + ClipValue2SQL( oBrwMFV:aArrayData[nFor,3] ) + ","
cQryMFV += "pvp=" + ClipValue2SQL( oBrwMFV:aArrayData[nFor,4] ) + ","
cQryMFV += "stotal=" + ClipValue2SQL( oBrwMFV:aArrayData[nFor,5] ) + ","
cQryMFV += "poriva=" + ClipValue2SQL( oDatos:oQryCnf:por_iva ) + ","
//
cQryMFV += "cedula=" + ClipValue2SQL( Val2Escape( aVar[1] ) ) + ","
cQryMFV += "num_inscripcion=" + ClipValue2SQL( aVar[2] ) + ","
cQryMFV += "num_factura=" + ClipValue2SQL( aVar[4] ) + ","
cQryMFV += "fch_movimiento=" + ClipValue2SQL( aVar[3] ) + ","
cQryMFV += "cod_asesor=" + ClipValue2SQL( Val2Escape( aVar[11] ) ) + ","
cQryMFV += "nom_asesor=" + ClipValue2SQL( Val2Escape( aVar[12] ) ) + ","
cQryMFV += "grupo=" + ClipValue2SQL( Val2Escape( aVar[14] ) ) + ","
//
cQryMFV += "usuario=" + ClipValue2SQL( 00 ) + ","
cQryMFV += "fchcrea=" + ClipValue2SQL( DATE() ) //+ ","
TRY // GRABO EN LA TABLA...
oDatos:oConex:Execute( cQryMFV )
CATCH oError
MSGSTOP( oError:Description + CRLF + "Error Grabando en Tabla (movi_facturas), Sentencia" + ;
CRLF + CRLF + cQryMFV, oDatos:cTitMsg )
END
NEXT
ENDIF
// FIN GRABO CUERPO FACTURA
RETURN .t. //( aVar )
STATIC FUNCTION teclado( nKey, oBrw, aVar, aGet ) // CONTROLA TECLA PRESIONADA CUANDO xBRW TIENE FOCUS
DO CASE
CASE nKey == VK_DELETE .or. nKey == VK_F4 // ELIMINAR REGISTRO(Supr/F4)
delrow( oBrw, aVar, aGet )
CASE nKey == VK_F2 // ADICIONA REGISTRO CON TECLA DE FUNCION...
addrow( oBrw )
CASE nKey == VK_F3 // MODIFICAR REGISTRO CON TECLA DE FUNCION...
modirow( oBrw )
CASE nKey == VK_F7
alert("F7...")
grabafactu( .t., .t., aVar, oBrw )
CASE nKey == VK_F12
alert("pulso F12")
CASE nKey == VK_F11
alert("pulso F11")
CASE nKey == VK_F10 // NO FUNCIONA
alert("pulso F10")
CASE nKey == VK_F9
alert("pulso F9")
CASE nKey == VK_F8
alert("pulso F8")
CASE nKey == VK_F6
alert("pulso F6")
CASE nKey == VK_F5
alert("pulso F5")
CASE nKey == VK_INSERT
alert("insertar Reg.")
CASE nKey == VK_DOWN
alert("pa´bajo")
CASE nKey == VK_UP
alert("pa´rriba")
END CASE
RETURN nil