Created
August 7, 2013 04:34
-
-
Save anonymous/6171193 to your computer and use it in GitHub Desktop.
Módulo genérico de documentos de programa de Gestión desde 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit UXPAF; | |
interface | |
//Total de lineas en el antiguo módulo 3031 | |
uses | |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | |
Dialogs, ComCtrls, StdCtrls, GroupboxJL, Spin, Buttons, SPBBC, ExtCtrls, | |
NewPanelDB, DB, Grids, DBGrids, DBneweditjl, MyDbIbMemo, Mask, DBCtrls, | |
TDbIbchkbox, EditDefault, JvExMask, JvSpin, JvDBSpinEdit, DbEditDefault, | |
NewDBSpinEdit, NewDBSpinEditDouble, Mneweditjl, NewSpinEdit, IBCustomDataSet, | |
IBQuery, Menus; | |
//[ 1]----------------[ Para poder tener tabs del page control en color]-------- | |
Type | |
TTabSheet = class(ComCtrls.TTabSheet) | |
private | |
FColor: TColor; | |
procedure SetColor(Value: TColor); | |
procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); | |
message WM_ERASEBKGND; | |
public | |
constructor Create(aOwner: TComponent); override; | |
property Color: TColor read FColor write SetColor; | |
end; | |
//[ 1]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
type | |
TFXPAF = class(TForm) | |
PanelBotonera: TNewPanelDB; | |
SBPrimero: TSpeedButtonBC; | |
SBMenosx: TSpeedButtonBC; | |
SBMenos1: TSpeedButtonBC; | |
SBMas1: TSpeedButtonBC; | |
SBMasX: TSpeedButtonBC; | |
SBUltimo: TSpeedButtonBC; | |
SbNuevo: TSpeedButtonBC; | |
SbModificar: TSpeedButtonBC; | |
Label1: TLabel; | |
SB_Salir: TSpeedButtonBC; | |
SBBuscar: TSpeedButtonBC; | |
SBImprimir: TSpeedButtonBC; | |
SEMobeByX: TSpinEdit; | |
GBBuscar: TGroupBoxJL; | |
Ebusqueda: TEdit; | |
BLimpiar: TButton; | |
BBuscar: TButton; | |
BCerrar: TButton; | |
SbBorrar: TSpeedButtonBC; | |
PC: TPageControl; | |
Visor: TTabSheet; | |
Datos: TTabSheet; | |
DSPrincipal: TDataSource; | |
NPDBVisorDocumentos: TNewPanelDB; | |
Panel1: TPanel; | |
NPDBVisorDetalles: TNewPanelDB; | |
NewPanelDB2: TNewPanelDB; | |
NPDBContenedor: TNewPanelDB; | |
DsDetalle: TDataSource; | |
DSLoteDocumento: TDataSource; | |
DBGrid1: TDBGrid; | |
Panel2: TPanel; | |
Panel3: TPanel; | |
NPDBDatosDocumentos: TNewPanelDB; | |
NPlDBDetalle: TNewPanelDB; | |
NewPanelDB6: TNewPanelDB; | |
NPDBTotales: TNewPanelDB; | |
Panel4: TPanel; | |
DBGrid2: TDBGrid; | |
Panel5: TPanel; | |
DBGrid3: TDBGrid; | |
Panel6: TPanel; | |
PC2: TPageControl; | |
Valores: TTabSheet; | |
Datos1: TTabSheet; | |
Cobros: TTabSheet; | |
Nota: TTabSheet; | |
Protecciondatos: TTabSheet; | |
Label2: TLabel; | |
Label3: TLabel; | |
Label4: TLabel; | |
Label5: TLabel; | |
Label6: TLabel; | |
Label7: TLabel; | |
Label8: TLabel; | |
GroupBox1: TGroupBox; | |
Label9: TLabel; | |
GroupBox2: TGroupBox; | |
Label10: TLabel; | |
Label11: TLabel; | |
GroupBox3: TGroupBox; | |
GroupBox4: TGroupBox; | |
Label12: TLabel; | |
GroupBox5: TGroupBox; | |
Label14: TLabel; | |
Label15: TLabel; | |
Label16: TLabel; | |
Label17: TLabel; | |
DBIBMemo1: TDBIBMemo; | |
Label18: TLabel; | |
Label19: TLabel; | |
Label20: TLabel; | |
GroupBox7: TGroupBox; | |
Label21: TLabel; | |
Label22: TLabel; | |
GroupBox8: TGroupBox; | |
Label23: TLabel; | |
Label24: TLabel; | |
Label25: TLabel; | |
DBNewEditJL1: TDBNewEditJL; | |
DBNewEditJL2: TDBNewEditJL; | |
DBNewEditJL3: TDBNewEditJL; | |
DBNewEditJL4: TDBNewEditJL; | |
DBNewEditJL5: TDBNewEditJL; | |
DBNewEditJL10: TDBNewEditJL; | |
DBNewEditJL6: TDBNewEditJL; | |
DBNVisorTotalRetenciones: TDBNewEditJL; | |
DBNVisorPorcentajeRetenciones: TDBNewEditJL; | |
DBNewEditJL9: TDBNewEditJL; | |
DBNVisorTotalFinanciado: TDBNewEditJL; | |
DBNewEditJL13: TDBNewEditJL; | |
DBNewEditJL14: TDBNewEditJL; | |
Label26: TLabel; | |
DBNewEditJL15: TDBNewEditJL; | |
DBText1: TDBText; | |
DBNewEditJL16: TDBNewEditJL; | |
DBNewEditJL17: TDBNewEditJL; | |
DBNewEditJL18: TDBNewEditJL; | |
DBNewEditJL19: TDBNewEditJL; | |
DBNewEditJL20: TDBNewEditJL; | |
DBNewEditJL21: TDBNewEditJL; | |
DBIBCheckbox1: TDBIBCheckbox; | |
DBNewEditJL22: TDBNewEditJL; | |
DBNewEditJL24: TDBNewEditJL; | |
DBNewEditJL23: TDBNewEditJL; | |
Label13: TLabel; | |
DBIBMemo2: TDBIBMemo; | |
DBNewEditJL25: TDBNewEditJL; | |
SpeedButtonBC1: TSpeedButtonBC; | |
SpeedButtonBC2: TSpeedButtonBC; | |
SpeedButtonBC3: TSpeedButtonBC; | |
SpeedButtonBC4: TSpeedButtonBC; | |
SpeedButtonBC5: TSpeedButtonBC; | |
DBNavigator1: TDBNavigator; | |
DBNavigator2: TDBNavigator; | |
DSDM_IBQNOTAS: TDataSource; | |
DSDM_IBDCONFI: TDataSource; | |
Label40: TLabel; | |
Label41: TLabel; | |
Label42: TLabel; | |
Label43: TLabel; | |
Label44: TLabel; | |
GroupBox10: TGroupBox; | |
Label45: TLabel; | |
Label46: TLabel; | |
Label47: TLabel; | |
Label48: TLabel; | |
SBNuevoCliente: TSpeedButton; | |
SBBuscarCliente: TSpeedButton; | |
GroupBox11: TGroupBox; | |
Label49: TLabel; | |
SBNuevoAgente: TSpeedButton; | |
Label50: TLabel; | |
Label51: TLabel; | |
Label52: TLabel; | |
SBBuscarAgente: TSpeedButton; | |
DBIImagenComercial: TDBImage; | |
NewPanelDB1: TNewPanelDB; | |
SBDetallePrimero: TSpeedButton; | |
SBDetalleAnterior: TSpeedButton; | |
SBDetalleSiguiente: TSpeedButton; | |
SBDetalleUltimo: TSpeedButton; | |
SBDetalleNuevo: TSpeedButton; | |
SBDetalleModificar: TSpeedButton; | |
SBDetalleBorrar: TSpeedButton; | |
SBInsertarComentario: TSpeedButton; | |
SBInsertarMuestra: TSpeedButton; | |
SBInstertarComentarioFecha: TSpeedButton; | |
NPDBConfirmarDetalle: TNewPanelDB; | |
SBDetalleCancelar: TSpeedButton; | |
SBDetalleConfirmar: TSpeedButton; | |
Panel7: TPanel; | |
SBEscribirNota: TSpeedButton; | |
Label27: TLabel; | |
Label28: TLabel; | |
Label29: TLabel; | |
Panel8: TPanel; | |
Label30: TLabel; | |
DBTNombreImpuestos: TDBText; | |
DBTNombreImpuesto1: TDBText; | |
DBTNombreImpuesto2: TDBText; | |
DBTNombreImpuesto3: TDBText; | |
DBTValorImpuesto1: TDBText; | |
DBTValorImpuesto2: TDBText; | |
DBTValorImpuesto3: TDBText; | |
DBText9: TDBText; | |
Label31: TLabel; | |
Label32: TLabel; | |
Label33: TLabel; | |
Label34: TLabel; | |
Label35: TLabel; | |
Label36: TLabel; | |
Label37: TLabel; | |
Label38: TLabel; | |
Label39: TLabel; | |
Label53: TLabel; | |
DBEdit2: TDBEdit; | |
StringGrid1: TStringGrid; | |
DBEdit3: TDBEdit; | |
DBETotalComisiones19: TDBEdit; | |
DBEdit5: TDBEdit; | |
DBEditDefault1: TDBEditDefault; | |
EditDefault1: TEditDefault; | |
EditDefault2: TEditDefault; | |
DBEditDefault4: TDBEditDefault; | |
Edit1: TEdit; | |
Label67: TLabel; | |
Label68: TLabel; | |
Label69: TLabel; | |
Label70: TLabel; | |
Label71: TLabel; | |
Label72: TLabel; | |
Label73: TLabel; | |
Label74: TLabel; | |
Label76: TLabel; | |
Label77: TLabel; | |
Label78: TLabel; | |
SpeedButton19: TSpeedButton; | |
Panel9: TPanel; | |
GroupBox6: TGroupBox; | |
SBProductos: TSpeedButton; | |
SBComerciales: TSpeedButton; | |
SBClientes: TSpeedButton; | |
PC3: TPageControl; | |
Clientes: TTabSheet; | |
Label55: TLabel; | |
Label57: TLabel; | |
Label58: TLabel; | |
Label59: TLabel; | |
Label60: TLabel; | |
Label84: TLabel; | |
DBEdit6: TDBEdit; | |
DBEdit8: TDBEdit; | |
DBEdit9: TDBEdit; | |
DBIBMemo3: TDBIBMemo; | |
DBIBMemo4: TDBIBMemo; | |
DBEdit19: TDBEdit; | |
Comercial: TTabSheet; | |
Label61: TLabel; | |
Label63: TLabel; | |
Label64: TLabel; | |
Label65: TLabel; | |
DBEdit21: TDBEdit; | |
DBEdit22: TDBEdit; | |
DBEdit23: TDBEdit; | |
DBIBMemo5: TDBIBMemo; | |
Productos: TTabSheet; | |
Label66: TLabel; | |
Label79: TLabel; | |
Label80: TLabel; | |
Label81: TLabel; | |
Label82: TLabel; | |
Label83: TLabel; | |
Label85: TLabel; | |
DBEdit24: TDBEdit; | |
DBImage1: TDBImage; | |
DBImage3: TDBImage; | |
DBEdit25: TDBEdit; | |
DBEdit37: TDBEdit; | |
DBEdit38: TDBEdit; | |
DBIBMemo6: TDBIBMemo; | |
Panel10: TPanel; | |
Panel11: TPanel; | |
Panel12: TPanel; | |
DBGrid4: TDBGrid; | |
DBNSerie: TDBNewEditJL; | |
DBNNumeroDocumento: TDBNewEditJL; | |
DBNFecha: TDBNewEditJL; | |
DBNCodigoCliente: TDBNewEditJL; | |
DBNCIF: TDBNewEditJL; | |
DBNNombreCliente: TDBNewEditJL; | |
DBNFormaPago: TDBNewEditJL; | |
SBNuevaFormaPago: TSpeedButton; | |
SBBuscarFormaPago: TSpeedButton; | |
DBNCodigoComercial: TDBNewEditJL; | |
DBNNIF: TDBNewEditJL; | |
DBNNombreComercial: TDBNewEditJL; | |
NDBSEDPorcentajeFinanciado: TNewDBSpinEditDouble; | |
NDBSENumeroProteccionDatos: TNewDBSpinEdit; | |
BBNDetalleCodigoArticulo: TDBNewEditJL; | |
DBNDetallePeso: TDBNewEditJL; | |
DBIBCheckBoxDetalleServicio: TDBIBCheckbox; | |
PanelConfirmar: TNewPanelDB; | |
SBConfirmar: TSpeedButton; | |
SBCancelar: TSpeedButton; | |
DBNDetalleComision: TDBNewEditJL; | |
DBNDetallePrecioUnidad: TDBNewEditJL; | |
DBNDetalleImpuestos: TDBNewEditJL; | |
DBNDetalleDescripcion: TDBNewEditJL; | |
DBNDetalleCantidad: TDBNewEditJL; | |
DBNewEditJL26: TDBNewEditJL; | |
DBNewEditJL27: TDBNewEditJL; | |
NEDResumenLotes: TMyNewEditJL; | |
NEDResumenVencimientos: TMyNewEditJL; | |
NSESerie: TNewSpinEdit; | |
IBQBuscarNumeroDocumento: TIBQuery; | |
IBQClientes: TIBQuery; | |
DSIBQCLientes: TDataSource; | |
IBQAgentes: TIBQuery; | |
DSIBQAgentes: TDataSource; | |
IBQAgenteIMAGEN: TIBQuery; | |
DSIBQAgenteImagen: TDataSource; | |
Memo1: TMemo; | |
DBNewEditJL28: TDBNewEditJL; | |
Memo2: TMemo; | |
PopupMenuDirecciones: TPopupMenu; | |
IBQDirecciones: TIBQuery; | |
SBDirecciones: TSpeedButton; | |
DSSTOCK: TDataSource; | |
IBQDEsgloce: TIBQuery; | |
DBTNombreImpuesto4: TDBText; | |
DBTValorImpuesto4: TDBText; | |
NEVisorTotal: TMyNewEditJL; | |
DSRetenciones: TDataSource; | |
DBEditDefault2: TDBEditDefault; | |
Label54: TLabel; | |
DSComisioness: TDataSource; | |
DSFinanciado: TDataSource; | |
IBQDESbus: TIBQuery; | |
DsDesBu: TDataSource; | |
procedure SBPrimeroClick(Sender: TObject); | |
procedure SBUltimoClick(Sender: TObject); | |
procedure SB_SalirClick(Sender: TObject); | |
procedure BBuscarClick(Sender: TObject); | |
procedure BCerrarClick(Sender: TObject); | |
procedure BLimpiarClick(Sender: TObject); | |
procedure FormActivate(Sender: TObject); | |
procedure FormKeyPress(Sender: TObject; var Key: Char); | |
procedure SbBorrarClick(Sender: TObject); | |
procedure SBBuscarClick(Sender: TObject); | |
procedure SBImprimirClick(Sender: TObject); | |
procedure SBMas1Click(Sender: TObject); | |
procedure SBMasXClick(Sender: TObject); | |
procedure SBMenos1Click(Sender: TObject); | |
procedure SBMenosxClick(Sender: TObject); | |
procedure SbModificarClick(Sender: TObject); | |
procedure SbNuevoClick(Sender: TObject); | |
procedure DSPrincipalDataChange(Sender: TObject; Field: TField); | |
procedure DsDetalleDataChange(Sender: TObject; Field: TField); | |
procedure actualizardatos; | |
procedure FormCreate(Sender: TObject); | |
procedure PCDrawTab(Control: TCustomTabControl; TabIndex: Integer; | |
const Rect: TRect; Active: Boolean); | |
procedure PC2DrawTab(Control: TCustomTabControl; TabIndex: Integer; | |
const Rect: TRect; Active: Boolean); | |
procedure SpeedButtonBC1Click(Sender: TObject); | |
procedure SpeedButtonBC2Click(Sender: TObject); | |
procedure SpeedButtonBC3Click(Sender: TObject); | |
procedure SpeedButtonBC4Click(Sender: TObject); | |
procedure SpeedButtonBC5Click(Sender: TObject); | |
procedure SBInsertarComentarioClick(Sender: TObject); | |
procedure SBInstertarComentarioFechaClick(Sender: TObject); | |
procedure SBEscribirNotaClick(Sender: TObject); | |
procedure SpeedButton19Click(Sender: TObject); | |
procedure SBNuevoClienteClick(Sender: TObject); | |
procedure SBBuscarClienteClick(Sender: TObject); | |
procedure SBNuevoAgenteClick(Sender: TObject); | |
procedure SBBuscarAgenteClick(Sender: TObject); | |
procedure SBClientesClick(Sender: TObject); | |
procedure SBComercialesClick(Sender: TObject); | |
procedure SBProductosClick(Sender: TObject); | |
procedure SBInsertarMuestraClick(Sender: TObject); | |
procedure SBConfirmarClick(Sender: TObject); | |
procedure SBCancelarClick(Sender: TObject); | |
procedure SBDetallePrimeroClick(Sender: TObject); | |
procedure SBDetalleAnteriorClick(Sender: TObject); | |
procedure SBDetalleSiguienteClick(Sender: TObject); | |
procedure SBDetalleUltimoClick(Sender: TObject); | |
procedure SBDetalleNuevoClick(Sender: TObject); | |
procedure SBDetalleModificarClick(Sender: TObject); | |
procedure SBDetalleBorrarClick(Sender: TObject); | |
procedure SBDetalleConfirmarClick(Sender: TObject); | |
procedure SBDetalleCancelarClick(Sender: TObject); | |
procedure DBNCodigoClienteChange(Sender: TObject); | |
procedure DBNCodigoClienteEnter(Sender: TObject); | |
procedure DBNCodigoClienteExit(Sender: TObject); | |
procedure BBNDetalleCodigoArticuloChange(Sender: TObject); | |
procedure BBNDetalleCodigoArticuloEnter(Sender: TObject); | |
procedure DBNCodigoComercialChange(Sender: TObject); | |
procedure DBNCodigoComercialEnter(Sender: TObject); | |
procedure DBNCodigoComercialExit(Sender: TObject); | |
procedure DBEditDefault1Change(Sender: TObject); | |
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; | |
Rect: TRect; State: TGridDrawState); | |
procedure DBEditDefault4Click(Sender: TObject); | |
function CambiarEstado:Integer; //Total de lineas en el antiguo módulo 3031 | |
procedure CalcularRetenciones; | |
procedure CalcularFinanCiado; | |
procedure autograb(Sender: TObject); | |
procedure Entrada(Tipo: Integer); | |
procedure CalculoDatos; | |
procedure CalculoVisor; | |
procedure desgloceBlanco; | |
procedure VerDesgloce; | |
function CalcularSubtotal:Real; | |
procedure DBEditDefault3Change(Sender: TObject); | |
procedure FormClose(Sender: TObject; var Action: TCloseAction); | |
procedure DBNNumeroDocumentoExit(Sender: TObject); | |
function VerNumeroDocumento(Tipo, Serie:string;Numero:Integer=0):string; | |
procedure NSESerieChange(Sender: TObject); | |
procedure DBNNumeroDocumentoChange(Sender: TObject); | |
procedure NDBSENumeroProteccionDatosChange(Sender: TObject); | |
procedure SBDireccionesClick(Sender: TObject); //Sólo usada en este módulo | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
FXPAF: TFXPAF; | |
VarSTipoDocumento:string; | |
VPPAFSumaImportesImpuestos1, VPPAFSumaImportesImpuestos2, VPPAFSumaImportesImpuestos3, VPPAFSumaImportesImpuestos4: Real; | |
VPPAFSumaSubTotales, VPPAFSumaSubTotalesIMPUESTOS, VPPAFSumaSubTotalesCOMISIONES : Real; | |
VarRSubtotal1: Real; | |
VPPAFSumaSubTotalesPeso, VPPAFSumaSubTotalesDTOS: Real; VPPAFCantAnterior, VPPAFCantDif: Integer; | |
VPPAFSCadenaLote,VarSPPAFCadenaBuscada: string; | |
VARBPPAFModi:Boolean; | |
VarautoGRab:Integer; //Para la grabación del detalle | |
VarBModificadoStock,VarBModificadoLotesDocumento, VarBModificacion:Boolean; | |
VarSCadenaLotes:String; | |
implementation | |
{$R *.dfm} | |
uses Fun, FUN_DBGRID, UDM, UNotas, Udirecciones, UArticulos, UEmpleados, UMENU, UExtPPAF, UbusquedaFP, UMuestrasEntrega, | |
UCLIENTES, UFInanciado, UIMPPPAF; | |
procedure TFXPAF.VerDesgloce; | |
//------------------------------------------------------------------------------ | |
//***********************************************************[ Verdesgloce ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then | |
begin | |
if not(DsPrincipal.DataSet.State in [DsInsert]) then | |
begin | |
ActQuery(IBQDesgloce, 'SELECT * FROM DETALLE ' + | |
'INNER JOIN DOCUMENTOS ON (DETALLE.NUMERODOCUMENTO=DOCUMENTOS.NUMERODOCUMENTO) ' + 'AND (DETALLE.SERIE=DOCUMENTOS.SERIE) ' + | |
'WHERE (DOCUMENTOS.SERIE = ' + QuotedStr(DM.IBDDocumentosSERIE.Value) | |
+ ') AND (DOCUMENTOS.NUMERODOCUMENTO = ' + QuotedStr(DM.IBDDocumentosNUMERODOCUMENTO.Value) | |
+ ') AND (DOCUMENTOS.TIPODOCUMENTO='+ QuotedStr(DM.IBDDocumentosTIPODOCUMENTO.Value)+')'); | |
CalculoDatos; | |
CalculoVisor; | |
end; | |
end; | |
end; | |
function TFXPAF.VerNumeroDocumento(Tipo, Serie:string;Numero:Integer=0):string; | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ VerNumeroDocumento]**** | |
// Funcion para este módulo | |
//------------------------------------------------------------------------------ | |
var VarILargoSerie, VarINumero:Integer; | |
begin | |
VarILargoSerie:=Length(Serie); | |
if Numero=0 then | |
begin | |
if Tipo='FACTURA' then if DM.IBDCONFINUMEROFACTURA.Text='0' then VarINumero:=1 else VarINumero:=dm.IBDCONFINUMEROFACTURA.AsInteger+1; | |
if Tipo='ALBARAN' then if DM.IBDCONFINUMEROALBARAN.Text='0' then VarINumero:=1 else VarINumero:=dm.IBDCONFINUMEROALBARAN.AsInteger+1; | |
if Tipo='PEDIDO' then if DM.IBDCONFINUMEROPEDIDO.Text='0' then VarINumero:=1 else VarINumero:=dm.IBDCONFINUMEROPEDIDO.AsInteger+1; | |
if Tipo='PRESUPUESTO' then if DM.IBDCONFINUMEROPRESUPUESTO.Text='0' then VarINumero:=1 else VarINumero:=dm.IBDCONFINUMEROPRESUPUESTO.AsInteger+1; | |
Result:=ceros(IntToStr(VarINumero),dm.IBDCONFILAGONUMEROS.Value-VarILargoSerie) | |
end else Result:=ceros(IntToStr(Numero),dm.IBDCONFILAGONUMEROS.Value-VarILargoSerie) | |
end; | |
procedure TFXPAF.CalcularFinanCiado; | |
//------------------------------------------------------------------------------ | |
//****************************************************[ CalcularFinanCiado ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then | |
begin | |
if Not DsDetalle.DataSet.IsEmpty then | |
begin | |
DBNVisorTotalFinanciado.Text:=FormatFloat('###,###,##0.00',DSPrincipal.DataSet.FieldByName('TOTALFINANCIADO').value); | |
EditDefault2.Text:=FormatFloat('###,###,##0.00',DSPrincipal.DataSet.FieldByName('TOTALFINANCIADO').value); | |
end; | |
end; | |
end; | |
procedure TFXPAF.CalcularRetenciones; | |
//------------------------------------------------------------------------------ | |
//***************************************************[ CalcularRetenciones ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then | |
begin | |
if Not DsDetalle.DataSet.IsEmpty then | |
begin | |
DBNVisorTotalRetenciones.Text:=FormatFloat('###,###,##0.00',((DBNVisorPorcentajeRetenciones.Field.Value*(DSPrincipal.DataSet.FieldByName('SUBTOTAL').value)) / 100)); | |
EditDefault1.Text:=FormatFloat('###,###,##0.00',((DBNVisorPorcentajeRetenciones.Field.Value*(DSPrincipal.DataSet.FieldByName('SUBTOTAL').value)) / 100)); | |
end; | |
end; | |
end; | |
function TFXPAF.CalcularSubtotal: Real; | |
//------------------------------------------------------------------------------ | |
//**************************************************[ Calcular el subtotal ]**** | |
//------------------------------------------------------------------------------ | |
begin //Primero calculamos el Precio si tiene descuento | |
VarRSubtotal1:=0; | |
if not IBQDesgloce.FieldByName('DESCUENTO').IsNull then VarRSubtotal1:=Porcentaje(IBQDesgloce.FieldByName('PRECIOUNIDAD').Value,IBQDesgloce.FieldByName('DESCUENTO').value) | |
else VarRSubtotal1:=IBQDesgloce.FieldByName('PRECIOUNIDAD').Value; | |
Result:=(IBQDesgloce.FieldByName('CANTIDAD').Value*IBQDesgloce.FieldByName('PRECIOUNIDAD').Value)-VarRSubtotal1; //Calculamos el subtotal | |
end; | |
procedure TFXPAF.desgloceBlanco; | |
//------------------------------------------------------------------------------ | |
//********************************************************[ DesgloceBlanco ]**** | |
// Deja el registro con valores a vacio, negatiovo o 0 para evitar errores | |
// Tabla detalles | |
//------------------------------------------------------------------------------ | |
begin | |
DsDetalle.DataSet.FieldByName('CANTIDAD').value:=0; | |
DsDetalle.DataSet.FieldByName('PRECIOUNIDAD').value:=0; | |
DsDetalle.DataSet.FieldByName('IMPUESTO').value:=0; | |
DsDetalle.DataSet.FieldByName('DESCUENTO').value:=0; | |
DsDetalle.DataSet.FieldByName('COMISION').value:=0; | |
DsDetalle.DataSet.FieldByName('PESOUNIDAD').value:=0; | |
DsDetalle.DataSet.FieldByName('MODIFICADO').value:=0; | |
DsDetalle.DataSet.FieldByName('SERVICIO').value:='N'; | |
end; | |
procedure TFXPAF.CalculoVisor; | |
// ------------------------------------------------------------------------------ | |
// *****************************[ Calcula y muetra los datos en el visor ]******* | |
// ------------------------------------------------------------------------------ | |
var I: Integer; | |
begin | |
if FXPAF.active then | |
begin | |
CalcularRetenciones; | |
CalcularFinanCiado; | |
NEVisorTotal.Text := FormatFloat('###,###,##0.00',(VPPAFSumaSubTotales)+ VPPAFSumaSubTotalesIMPUESTOS); | |
if (VarSTipoDocumento='ALBARAN') or (VarSTipoDocumento='FACTURA') then | |
begin //Si tiene retenciones | |
if DBNVisorTotalRetenciones.Field.Value<>0 then NEVisorTotal.Text :=FormatFloat('###,###,##0.00',((VPPAFSumaSubTotales)+ VPPAFSumaSubTotalesIMPUESTOS)-DBNVisorTotalRetenciones.Field.Value); | |
end; | |
end; | |
end; | |
procedure TFXPAF.CalculoDatos; | |
// ------------------------------------------------------------------------------ | |
// ****************************[ Calcula y muetra los datos en los datos ]******* | |
// ------------------------------------------------------------------------------ | |
var VarINumeroRecors, I: Integer; | |
VarRTotalSinDto:Real; | |
begin | |
if FXPAF.active then | |
begin // --Borramos el estado actual de las variables genericas | |
VPPAFSumaImportesImpuestos1 := 0; | |
VPPAFSumaImportesImpuestos2 := 0; | |
VPPAFSumaImportesImpuestos3 := 0; | |
VPPAFSumaImportesImpuestos4 := 0; | |
VPPAFSumaSubTotales := 0; | |
VPPAFSumaSubTotalesIMPUESTOS := 0; | |
VPPAFSumaSubTotalesCOMISIONES := 0; | |
VPPAFSumaSubTotalesPeso := 0; | |
VPPAFSumaSubTotalesDTOS := 0; | |
VarRTotalSinDto:=0; | |
Edit1.Text :='0,00'; | |
for I := 1 to StringGrid1.RowCount - 1 do | |
StringGrid1.Rows[I].Clear; | |
IBQDesgloce.Last; // Dsdesgloce.DataSet.Last; | |
VarINumeroRecors := IBQDesgloce.RecNo; // Dsdesgloce.DataSet.RecNo; | |
IBQDesgloce.First; // Dsdesgloce.DataSet.First; | |
while not IBQDesgloce.Eof do // Dsdesgloce.DataSet.Eof do | |
begin | |
if IBQDesgloce.FieldByName('IMPUESTO').Value = DBTValorImpuesto1.Field.Value then // Impuesto 1 | |
BEGIN | |
VPPAFSumaImportesImpuestos1 := VPPAFSumaImportesImpuestos1 + Porcentaje(CalcularSubtotal, DBTValorImpuesto1.Field.Value); | |
END; | |
if IBQDesgloce.FieldByName('IMPUESTO').Value = DBTValorImpuesto2.Field.Value then // Impuesto 2 | |
begin | |
VPPAFSumaImportesImpuestos2 := VPPAFSumaImportesImpuestos2 + Porcentaje(CalcularSubtotal, DBTValorImpuesto2.Field.Value); | |
end; | |
if IBQDesgloce.FieldByName('IMPUESTO').Value = DBTValorImpuesto3.Field.Value then // Impuesto 3 | |
Begin | |
VPPAFSumaImportesImpuestos3 := VPPAFSumaImportesImpuestos3 + Porcentaje(CalcularSubtotal, DBTValorImpuesto3.Field.Value); | |
End; | |
if IBQDesgloce.FieldByName('IMPUESTO').Value = DBTValorImpuesto4.Field.Value then // Impuesto 4 | |
Begin | |
VPPAFSumaImportesImpuestos4 := VPPAFSumaImportesImpuestos4 + Porcentaje(CalcularSubtotal, DBTValorImpuesto4.Field.Value); | |
End; | |
VPPAFSumaSubTotalesIMPUESTOS:=VPPAFSumaImportesImpuestos1+VPPAFSumaImportesImpuestos2+VPPAFSumaImportesImpuestos3+VPPAFSumaImportesImpuestos4; | |
VPPAFSumaSubTotales := VPPAFSumaSubTotales + CalcularSubtotal; | |
VarRTotalSinDto:=CalcularSubtotal; | |
VPPAFSumaSubTotalesCOMISIONES := VPPAFSumaSubTotalesCOMISIONES + Porcentaje(VarRTotalSinDto, IBQDesgloce.FieldByName('COMISION').Value); | |
VPPAFSumaSubTotalesPeso := VPPAFSumaSubTotalesPeso + (IBQDesgloce.FieldByName('CANTIDAD').Value*IBQDesgloce.FieldByName('PESOUNIDAD').Value); | |
VPPAFSumaSubTotalesDTOS := VPPAFSumaSubTotalesDTOS + Porcentaje ((IBQDesgloce.FieldByName('PRECIOUNIDAD').Value*IBQDesgloce.FieldByName('CANTIDAD').Value), IBQDesgloce.FieldByName('DESCUENTO').Value); | |
IBQDesgloce.Next; // Dsdesgloce.DataSet.Next; | |
end; // Fin del calulo----------------------------------------------------------- | |
for I := 1 to StringGrid1.RowCount - 1 do | |
StringGrid1.Rows[I].Clear; | |
StringGrid1.Cells[0, 0] := FormatFloat('###,###,##0.00', VPPAFSumaImportesImpuestos1); | |
StringGrid1.Cells[0, 1] := FormatFloat('###,###,##0.00', VPPAFSumaImportesImpuestos2); | |
StringGrid1.Cells[0, 2] := FormatFloat('###,###,##0.00', VPPAFSumaImportesImpuestos3); | |
StringGrid1.Cells[0, 3] := FormatFloat('###,###,##0.00', VPPAFSumaImportesImpuestos4); | |
CalcularRetenciones; | |
CalcularFinanCiado; | |
Edit1.Text := FormatFloat('###,###,##0.00',(VPPAFSumaSubTotales )+ VPPAFSumaSubTotalesIMPUESTOS); | |
if (VarSTipoDocumento='ALBARAN') or (VarSTipoDocumento='FACTURA') then | |
begin | |
if EditDefault1.MyReal<>0 then //Si tiene retenciones | |
begin | |
Edit1.Text := FormatFloat('###,###,##0.00',((VPPAFSumaSubTotales )+ VPPAFSumaSubTotalesIMPUESTOS)-EditDefault1.MyReal); | |
end else EditDefault1.Text:='0,00' | |
end; | |
end; | |
end; | |
procedure TFXPAF.Entrada(Tipo: Integer); | |
var VarDdataM, VarDdataD: TDataSource; | |
// ------------------------------------------------------------------------------ | |
// ************************************************************[ Entrada ]******* | |
// para regular lo visible y datos y datasource según para lo que se use el form | |
// ------------------------------------------------------------------------------ | |
begin | |
CalculoVisor; | |
CalculoDatos; | |
end; | |
procedure TFXPAF.autograb(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************************[ Autograb ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
FExtPPAF.Close; | |
Case MensajeGr(2,Clmoneygreen) of | |
6:begin | |
VarautoGRab:=1; | |
SBDetalleConfirmarClick(Sender); | |
end; | |
7:begin | |
VarautoGRab:=2; | |
SBDetalleConfirmarClick(Sender); | |
end; | |
end; | |
end; | |
//[ 2]----------------[ Para poder tener tabs del page control en color]-------- | |
constructor TTabSheet.Create(aOwner: TComponent); | |
//------------------------------------------------------------------------------ | |
//*************************************[ Crear nueva propiedad tabsheet ]******* | |
//------------------------------------------------------------------------------ | |
begin | |
inherited; | |
FColor := clBtnFace; | |
end; | |
//[ 2]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
//[ 3]----------------[ Para poder tener tabs del page control en color]-------- | |
procedure TTabSheet.SetColor(Value: TColor); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ Seleción de color ]******* | |
//------------------------------------------------------------------------------ | |
begin | |
if FColor <> Value then | |
begin | |
FColor := Value; | |
Invalidate; | |
end; | |
end; | |
//[ 3]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
//[ 4]----------------[ Para poder tener tabs del page control en color]-------- | |
procedure TTabSheet.WMEraseBkGnd(var Msg: TWMEraseBkGnd); | |
//------------------------------------------------------------------------------ | |
//******************************************[ Dibujar en el pagecontrol ]******* | |
//------------------------------------------------------------------------------ | |
begin | |
if FColor = clBtnFace then | |
inherited | |
else | |
begin | |
Brush.Color := FColor; | |
Windows.FillRect(Msg.dc, ClientRect, Brush.Handle); | |
Msg.Result := 1; | |
end; | |
end; | |
//[ 4]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
procedure TFXPAF.actualizardatos; | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Actualizar datos ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then | |
begin | |
if not (DsDetalle.DataSet.State in [dsEdit, dsInsert]) then | |
begin | |
Panel5.Caption:='Lotes del artículo: '+DsDetalle.DataSet.FieldByName('DESCRIPCIONARTICULO').AsString; | |
end; | |
if not (DSPrincipal.DataSet.State in [dsEdit, dsInsert]) then | |
begin | |
Panel4.Caption:=VarSTipoDocumento+' [ '+ DSPrincipal.DataSet.FieldByName('NUMERODOCUMENTO').AsString+' ]'; | |
end; | |
end; | |
Caption:='Gestión de '+VarSTipoDocumento; | |
end; | |
procedure TFXPAF.BBuscarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************************[ Buscar ]****** | |
//------------------------------------------------------------------------------ | |
var Campo:string; | |
begin | |
Campo:='NUMERODOCUMENTO'; {Dato a rellenar por el progrmador con el nombre del campo en la busqueda} | |
DSPrincipal.DataSet.Locate(Campo,Ebusqueda.Text,[loCaseInsensitive,loPartialKey]); | |
end; | |
procedure TFXPAF.BCerrarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Cerrar Busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
BLimpiarClick(Sender); | |
GBBuscar.Visible:=False; | |
end; | |
procedure TFXPAF.BLimpiarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ Limpia la busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
Ebusqueda.Text:=''; | |
BBuscarClick(Sender); | |
Ebusqueda.SetFocus; | |
end; | |
procedure TFXPAF.DBEditDefault1Change(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ RETENCIONES DATOS ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then CalcularRetenciones; | |
end; | |
procedure TFXPAF.DBEditDefault3Change(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ FINANCIADO DATOS ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then CalcularFinanCiado; | |
end; | |
procedure TFXPAF.DBEditDefault4Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ RETENCIONES DATOS ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then CalcularRetenciones; | |
end; | |
procedure TFXPAF.DBNCodigoClienteChange(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ********************************************************[ Change Cod Cli ]**** | |
// Para posicionar en el cliente | |
// ------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then | |
begin | |
if DBNCodigoCliente.Text <> '' then | |
begin | |
ActQuery(IBQClientes, 'Select * from Clientes where Upper(CODIGO)=Upper(' + QuotedStr (DBNCodigoCliente.Text) + ')'); | |
if not IBQDirecciones.isempty then ActQuery(IBQDirecciones,'SELECT * FROM DIRECCIONES WHERE (DIRECCIONES.MODULO = '+ | |
QuotedStr ('CLIENTES')+') AND (DIRECCIONES.CODIGO = '+QuotedStr (DBNCodigoCliente.Text)+')'); | |
end; | |
end; | |
end; | |
procedure TFXPAF.DBNCodigoClienteEnter(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ****************************************************[ entrar en clientes ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
SBClientesClick(Sender); | |
end; | |
procedure TFXPAF.DBNCodigoClienteExit(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// *************************************************[ Salir de cód. cliente ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
if DBNCodigoCliente.Text = '' then | |
begin | |
ShowMessage('Este campo no puede quedar vacio, por favor rellene el campo [Código de cliente]'); | |
DBNCodigoCliente.SetFocus; | |
end else | |
begin | |
if UpperCase(DBNCodigoCliente.Text)='B' then SBBuscarClienteClick(Sender) else | |
begin | |
if IBQClientes.IsEmpty then | |
begin | |
Case Application.MessageBox(pchar( 'El cliente búscado no se encuntra, ¿desea crearlo?'), | |
pchar('No se encuentra el cliente'),4+32+0) of | |
6:SBNuevoClienteClick(Sender); //Si | |
7:DBNCodigoCliente.SetFocus; //No | |
end; | |
end else | |
begin | |
if DBNNombreCliente.Text='' then DBNNombreCliente.Field.Value:=IBQClientes.FieldByName('NOMBRE').Value else //Descripción del cliente | |
begin | |
if DBNNombreCliente.Text<>IBQClientes.FieldByName('NOMBRE').AsString then | |
begin | |
Case Application.MessageBox( pchar( 'El nombre de este cliente y el que tiene puesto no coinciden, ¿desea cambiarlo por el nombre que tiene asignado este código?'), | |
pchar('Datos diferentes'),4+64+0) of | |
6:DBNNombreCliente.Field.Value:=IBQClientes.FieldByName('NOMBRE').Value; //Si | |
end; | |
end; | |
end; | |
if DBNFormaPago.Text='' then DBNFormaPago.Field.Value:=IBQClientes.FieldByName('FORMAPAGO').Value else //Forma de pago | |
begin | |
if DBNFormaPago.Text<>IBQClientes.FieldByName('FORMAPAGO').AsString then | |
begin | |
Case Application.MessageBox( pchar( 'La forma de pago de este cliente y el que tiene puesta no coinciden, ¿desea cambiarlo por la que tiene asignado este código?'), | |
pchar('Datos diferentes'),4+64+0) of | |
6:DBNFormaPago.Field.Value:=IBQClientes.FieldByName('FORMAPAGO').Value; //Si | |
end; | |
end; | |
end; | |
end; | |
end; | |
end; | |
end; | |
procedure TFXPAF.DBNCodigoComercialChange(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **************************************************[ Change Cod Comercial ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then | |
begin | |
if DBNCodigoComercial.Text <> '' then | |
begin | |
ActQuery(IBQAgentes, 'Select * from EMPLEADOS where (EMPLEADOS.AGENTE = '+QuotedStr('S')+') AND (Upper(EMPLEADOS.CODIGO)=Upper('+ | |
QuotedStr(DBNCodigoComercial.Text) + '))'); | |
if Not IBQAgentes.IsEmpty then ActQuery(IBQAgenteIMAGEN, 'Select * from PC where (PC.MODULO = '+QuotedStr('EMPLEADOS')+') AND (Upper(PC.CODIGO)=Upper('+ | |
QuotedStr(DBNCodigoComercial.Text) + '))'); | |
end; | |
end; | |
end; | |
procedure TFXPAF.DBNCodigoComercialEnter(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// *************************************************[ entrar en comerciales ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
SBComercialesClick(Sender); | |
end; | |
procedure TFXPAF.DBNCodigoComercialExit(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ***********************************************[ Salir de cód. Comercial ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
if DBNCodigoComercial.Text = '' then | |
begin | |
ShowMessage('Este campo no puede quedar vacio, por favor rellene el campo [Código de ccomercial]'); | |
DBNCodigoComercial.SetFocus; | |
end else | |
begin | |
if UpperCase(DBNCodigoComercial.Text)='B' then SBBuscarAgenteClick(Sender) else | |
begin | |
if IBQAgentes.IsEmpty then | |
begin | |
Case Application.MessageBox(pchar( 'El comercial búscado no se encuntra, ¿desea crearlo?'), | |
pchar('No se encuentra el comercial'),4+32+0) of | |
6:SBNuevoAgenteClick(Sender); //Si | |
7:DBNCodigoComercial.SetFocus; //No | |
end; | |
end else | |
begin //Descripción del comercial | |
if DBNNombreComercial.Text='' then DBNNombreComercial.Field.Value:=IBQAgentes.FieldByName('NOMBRE').Value else | |
begin | |
if DBNNombreComercial.Text<>IBQAgentes.FieldByName('NOMBRE').AsString then | |
begin | |
Case Application.MessageBox( pchar( 'El nombre de este comercial y el que tiene puesto no coinciden, ¿desea cambiarlo por el nombre que tiene asignado este código?'), | |
pchar('Datos diferentes'),4+64+0) of | |
6:DBNNombreComercial.Field.Value:=IBQAgentes.FieldByName('NOMBRE').Value; //Si | |
end; | |
end; | |
end; | |
end; | |
end; | |
end; | |
end; | |
procedure TFXPAF.DBNNumeroDocumentoChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************[ Cambia el nº de documento ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
LAbel44.Caption:='[ '+Trim(DBNSerie.Text)+DBNNumeroDocumento.Text+' ]'; | |
end; | |
procedure TFXPAF.DBNNumeroDocumentoExit(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ***************************************************[ Salir del Núm. Doc. ]**** | |
// Muestra el número de documento | |
// ------------------------------------------------------------------------------ | |
begin | |
if not (DsPrincipal.DataSet.State in [dsEdit]) then | |
begin | |
if DBNNumeroDocumento.Text='' then DBNNumeroDocumento.Field.value:=VerNumeroDocumento(VarSTipoDocumento,DBNSerie.Text); | |
DBNNumeroDocumento.Field.value:=VerNumeroDocumento(VarSTipoDocumento,DBNSerie.Text,StrToInt(DBNNumeroDocumento.Text)); | |
ActQuery(IBQBuscarNumeroDocumento,'Select * From DOCUMENTOS WHERE (DOCUMENTOS.TIPODOCUMENTO = '+QuotedStr(VarSTipoDocumento)+ | |
') AND (DOCUMENTOS.NUMERODOCUMENTO = '+QuotedStr(DBNNumeroDocumento.Text) + | |
') AND (DOCUMENTOS.SERIE = '+QuotedStr(DBNSerie.Text)+')'); | |
if not IBQBuscarNumeroDocumento.IsEmpty then | |
begin | |
ShowMessage('Este número de documento ya existe'); | |
DBNNumeroDocumento.SetFocus; | |
end; | |
end; | |
end; | |
procedure TFXPAF.BBNDetalleCodigoArticuloChange(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **************************************[ Cambia el código del producto ]******* | |
// ------------------------------------------------------------------------------ | |
begin | |
DM.dsarticulos.DataSet.Locate('CODIGO', BBNDetalleCodigoArticulo.Text, [LoCaseInsensitive, LoPartialKey]); | |
PC3.ActivePageIndex := 2; | |
end; | |
procedure TFXPAF.BBNDetalleCodigoArticuloEnter(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ***************************************************[ entrar en Productos ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
PC3.ActivePage := Productos; | |
end; | |
procedure TFXPAF.DsDetalleDataChange(Sender: TObject; Field: TField); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ DSdetalle DataChange ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then if not (DsDetalle.DataSet.State in [dsEdit, dsInsert]) then actualizardatos; | |
end; | |
procedure TFXPAF.DSPrincipalDataChange(Sender: TObject; Field: TField); | |
//------------------------------------------------------------------------------ | |
//************************************************[ DSPrincipal DataChange ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
VerDesgloce; | |
if FXPAF.Active then if not (DSPrincipal.DataSet.State in [dsEdit, dsInsert]) then actualizardatos; | |
end; | |
procedure TFXPAF.FormActivate(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************[ Cuando se activa El form ]****** | |
// Lo que queremos que haga nuestro Form Cuando se Actiba | |
//------------------------------------------------------------------------------ | |
begin //Carganmos las imagenes de los botones | |
SBPrimero.Glyph.Handle:=Loadbitmap(HInstance,'FIRST'); | |
SBMenosx.Glyph.Handle:=Loadbitmap(HInstance,'RETROCEDER'); | |
SBMenos1.Glyph.Handle:=Loadbitmap(HInstance,'PRIOR'); | |
SBMas1.Glyph.Handle:=Loadbitmap(HInstance,'NEXT'); | |
SBMasX.Glyph.Handle:=Loadbitmap(HInstance,'AVANZAR'); | |
SBUltimo.Glyph.Handle:=Loadbitmap(HInstance,'LAST'); | |
SbNuevo.Glyph.Handle:=Loadbitmap(HInstance,'NUEVO'); | |
SbModificar.Glyph.Handle:=Loadbitmap(HInstance,'EDIT'); | |
SbBorrar.Glyph.Handle:=Loadbitmap(HInstance,'BORRAR'); | |
SB_Salir.Glyph.Handle:=Loadbitmap(HInstance,'SALIR'); | |
SBBuscar.Glyph.Handle:=Loadbitmap(HInstance,'BUSCAR'); | |
SBImprimir.Glyph.Handle:=Loadbitmap(HInstance,'IMPRIMIR'); | |
PanelBotonera.ColorNotActive:=COLORPANELACT; //Ponemos el Juego de colores de mis NewPanelDB | |
PanelBotonera.ActiveColor:=COLORPANELNOACT; | |
actualizardatos; | |
NDBSENumeroProteccionDatosChange(Sender); | |
VerDesgloce; | |
QuerryOC(IBQClientes, True); | |
QuerryOC(IBQAgentes, True); | |
QuerryOC(IBQDesgloce, True); | |
QuerryOC(IBQAgenteIMAGEN, True); | |
QuerryOC(IBQDirecciones, True); | |
QuerryOC(IBQBuscarNumeroDocumento, True); | |
QuerryOC(IBQDESbus, True); | |
VerDesgloce; | |
end; | |
procedure TFXPAF.FormClose(Sender: TObject; var Action: TCloseAction); | |
// ------------------------------------------------------------------------------ | |
// *************************************************[ Al Cerrarse El Form ]****** | |
// Cerramos todos los procesos para que no consuman memoria y posibles errores | |
// ------------------------------------------------------------------------------ | |
begin | |
QuerryOC(IBQClientes); | |
QuerryOC(IBQAgentes); | |
QuerryOC(IBQDesgloce); | |
QuerryOC(IBQAgenteIMAGEN); | |
QuerryOC(IBQDirecciones); | |
QuerryOC(IBQBuscarNumeroDocumento); | |
QuerryOC(IBQDESbus); | |
end; | |
procedure TFXPAF.FormCreate(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************[ Al Crearse el Fom ]****** | |
// Cosas que queremos que haga según se inicie el Form | |
//------------------------------------------------------------------------------ | |
begin | |
//[ 5]----------------------------[ Tabs de page control en color ]------------- | |
Visor.Color:=clMoneyGreen; //verde pastel | |
Datos.Color:=clSkyBlue; //Azul Pastel | |
Valores.Color:=clMoneyGreen; //verde pastel | |
Datos1.Color:=clSkyBlue; //Azul Pastel | |
Cobros.Color:=clInfoBk; //Amarillo pastel | |
Nota.Color:=$0099CCFF; //Color naranja | |
Protecciondatos.Color:=$0000CCCC; //Verde limón | |
//[ 5]----------------------------[ Tabs de page control en color ]------------- | |
{Cosas que queremos que haga según se inicie el Form} | |
PC.ActivePageIndex:=0; | |
Pc2.ActivePageIndex:=0; | |
PC3.ActivePageIndex:=0; | |
VarBModificacion:=False; | |
end; | |
procedure TFXPAF.FormKeyPress(Sender: TObject; var Key: Char); | |
//------------------------------------------------------------------------------ | |
//************************************************[ Al pulsar una tecla ]****** | |
// Al pulsar la tecla salta al foco del siguiente componente, si esta admitido | |
//------------------------------------------------------------------------------ | |
begin | |
if (Key = #13) then {Si se ha pulsado enter } | |
if (ActiveControl is TEdit) | |
or (ActiveControl is TDBEdit) | |
or (ActiveControl is TDBNewEditJL) | |
or (ActiveControl is TNewDBSpinEdit) | |
or (ActiveControl is TNewDBSpinEditDouble) | |
or (ActiveControl is TDBComboBox) then | |
begin | |
Key := #0; { anula la puulsación } | |
Perform(WM_NEXTDLGCTL, 0, 0); { mueve al próximo control } | |
end | |
end; | |
procedure TFXPAF.NDBSENumeroProteccionDatosChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Cambia la LOPD ]**** | |
// Cambiamos la ley de protección de datos. | |
//------------------------------------------------------------------------------ | |
begin | |
if FXPAF.Active then | |
begin | |
if NDBSENumeroProteccionDatos.Text='' then NDBSENumeroProteccionDatos.Value:=1; | |
if not ((NDBSENumeroProteccionDatos.Value<1) or (NDBSENumeroProteccionDatos.Value>3)) then | |
begin | |
Memo1.Lines.Clear; | |
case NDBSENumeroProteccionDatos.Value of | |
1:Memo1.Lines.Text:=DM.IBDCONFILDPD1.AsString; | |
2:Memo1.Lines.Text:=DM.IBDCONFILDPD2.AsString; | |
3:Memo1.Lines.Text:=DM.IBDCONFILDPD3.AsString; | |
end; | |
end else | |
begin | |
if (DSPrincipal.DataSet.State in [dsEdit,dsInsert]) then | |
begin | |
ShowMessage('El rango sólo esta permitido entre 1 y 3'); | |
NDBSENumeroProteccionDatos.SetFocus; | |
end; | |
end; | |
end; | |
end; | |
procedure TFXPAF.NSESerieChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************[ Cambiar la serie ]******* | |
//------------------------------------------------------------------------------ | |
begin | |
case NSESerie.Value of | |
1:DBNSerie.Field.Value:=DM.IBDCONFISERIE.Value; | |
2:DBNSerie.Field.Value:=DM.IBDCONFISERIE2.Value; | |
3:DBNSerie.Field.Value:=DM.IBDCONFISERIE3.Value; | |
end; | |
end; | |
procedure TFXPAF.PC2DrawTab(Control: TCustomTabControl; TabIndex: Integer; | |
const Rect: TRect; Active: Boolean); | |
//------------------------------------------------------------------------------ | |
//************************************************[ COLORES PAGECONTROL ]******* | |
//------------------------------------------------------------------------------ | |
var //[ 6]----------------[ Para poder tener tabs del page control en color]-------- | |
AText: string; | |
APoint: TPoint; //[ 6]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
begin //[ 7]----------------[ Para poder tener tabs del page control en color]-------- | |
with (Control as TPageControl).Canvas do | |
begin | |
case TabIndex of | |
0: brush.Color:=clMoneyGreen; | |
1: brush.Color:=clSkyBlue; | |
2: brush.Color:=clInfoBk; | |
3: Brush.Color:=$0099CCFF; | |
4: Brush.Color:=$0000CCCC; | |
end; | |
PC2.Canvas.Rectangle(Rect); | |
PC2.Canvas.Brush.Color:=Control.Canvas.Brush.Color; | |
PC2.Pages[TabIndex].brush.Color := Control.Canvas.brush.Color; | |
PC2.Pages[TabIndex].Repaint; | |
FillRect(Rect); | |
AText := TPageControl(Control).Pages[TabIndex].Caption; | |
with Control.Canvas do | |
begin | |
APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2; | |
APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2; | |
TextRect(Rect, Rect.Left + APoint.x, Rect.Top + APoint.y, AText); | |
end; | |
end; | |
end; //[ 7]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
procedure TFXPAF.PCDrawTab(Control: TCustomTabControl; TabIndex: Integer; | |
const Rect: TRect; Active: Boolean); | |
//------------------------------------------------------------------------------ | |
//************************************************[ COLORES PAGECONTROL ]******* | |
//------------------------------------------------------------------------------ | |
var //[ 6]----------------[ Para poder tener tabs del page control en color]-------- | |
AText: string; | |
APoint: TPoint; //[ 6]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
begin //[ 7]----------------[ Para poder tener tabs del page control en color]-------- | |
with (Control as TPageControl).Canvas do | |
begin | |
case TabIndex of | |
0: brush.Color:=clMoneyGreen; | |
1: brush.Color:=clSkyBlue; | |
end; | |
PC.Canvas.Rectangle(Rect); | |
PC.Canvas.Brush.Color:=Control.Canvas.Brush.Color; | |
PC.Pages[TabIndex].brush.Color := Control.Canvas.brush.Color; | |
PC.Pages[TabIndex].Repaint; | |
FillRect(Rect); | |
AText := TPageControl(Control).Pages[TabIndex].Caption; | |
with Control.Canvas do | |
begin | |
APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2; | |
APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2; | |
TextRect(Rect, Rect.Left + APoint.x, Rect.Top + APoint.y, AText); | |
end; | |
end; | |
end; //[ 7]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]-------- | |
procedure TFXPAF.SbBorrarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Borrar el Actual Registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
if not DSPrincipal.DataSet.IsEmpty then //Cambiar por el mensaje elegido | |
begin | |
Case Application.MessageBox(pchar('[ Si ] Marca como nulo el actual registro'+#13#10+'[ No ] Elimina físicamente el actual registro' | |
+#13#10+'[ Cancelar ] No realiza ninguna acción'+#13#10+#13#10+'(Eliminar físicamente el registro puede provocar fallos por llamadas desde otros procedimientos, así como un descuadre en la numeración y contabilidad, al desprenderse del actual documento).'), | |
pchar('¿Que es lo que desea hacer?'),3+64+0) of | |
6:begin //Si | |
DSPrincipal.DataSet.Edit; | |
DSPrincipal.DataSet.FieldByName('ESTADO').Value:='NULO'; | |
DSPrincipal.DataSet.Post; | |
ShowMessage('El registro ha sido marcado como nulo'); | |
IBT.CommitRetaining; | |
end; | |
7:begin //No | |
DSPrincipal.DataSet.Delete; | |
ShowMessage('El registro ha sido eliminado'); | |
IBT.CommitRetaining; | |
end; | |
end; | |
end else ShowMessage('No hay datos para anular'); | |
end; | |
procedure TFXPAF.SBBuscarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Abrir Busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
GBBuscar.Visible:=True; | |
Ebusqueda.SetFocus; | |
end; | |
procedure TFXPAF.SBCancelarClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// *****************************************************[ Cancelar Proceso]****** | |
// ------------------------------------------------------------------------------ | |
var continuar:Boolean; | |
begin | |
if DsDetalle.DataSet.State in [DsInsert, DsEdit] then DsDetalle.DataSet.Cancel; | |
if DSPrincipal.DataSet.State in [DsInsert, DsEdit] then DSPrincipal.DataSet.Cancel; | |
DM.IBTransaction1.RollbackRetaining; | |
end; | |
procedure TFXPAF.SBConfirmarClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ********************************************************[ Grabar datos ]****** | |
// ------------------------------------------------------------------------------ | |
var Numdoc,VarNRet: Integer; VarBGrabar:Boolean; | |
VarRSumComi, VarRTotalSinDto:Real; | |
begin | |
VarRTotalSinDto:=0; | |
CalculoDatos; | |
try | |
if NPDBConfirmarDetalle.Visible=false then | |
begin | |
if DSPrincipal.DataSet.State in [dsEdit] then //Sólo si estamos editando | |
begin | |
DSDM_IBDCONFI.DataSet.Edit; | |
if VarSTipoDocumento='FACTURA' then if SoloInteger(DSDM_IBDCONFI.DataSet.FieldByName('NUMEROFACTURA').value)<SoloInteger(DBNNumeroDocumento.Text) then DSDM_IBDCONFI.DataSet.FieldByName('NUMEROFACTURA').value:=DBNNumeroDocumento.Text; | |
if VarSTipoDocumento='ALBARAN' then if SoloInteger(DSDM_IBDCONFI.DataSet.FieldByName('NUMEROALBARAN').value)<SoloInteger(DBNNumeroDocumento.Text) then DSDM_IBDCONFI.DataSet.FieldByName('NUMEROALBARAN').value:=DBNNumeroDocumento.Text; | |
if VarSTipoDocumento='PEDIDO' then if SoloInteger(DSDM_IBDCONFI.DataSet.FieldByName('NUMEROPEDIDO').value)<SoloInteger(DBNNumeroDocumento.Text) then DSDM_IBDCONFI.DataSet.FieldByName('NUMEROPEDIDO').value:=DBNNumeroDocumento.Text; | |
if VarSTipoDocumento='PRESUPUESTO' then if SoloInteger(DSDM_IBDCONFI.DataSet.FieldByName('NUMEROPRESUPUESTO').value)<SoloInteger(DBNNumeroDocumento.Text) then DSDM_IBDCONFI.DataSet.FieldByName('NUMEROPRESUPUESTO').value:=DBNNumeroDocumento.Text; | |
CamposObligatorios(DSDM_IBDCONFI,'ID'); | |
DSDM_IBDCONFI.DataSet.Post; | |
end; | |
if VarSTipoDocumento='FACTURA' then | |
begin | |
if EditDefault1.MyReal>0 then //Retenciones | |
begin | |
if Dsretenciones.DataSet.Locate('NUMERODOCUMENTO;SERIE', VarArrayOf([DBNNumeroDocumento.Field.Value, DBNSerie.Field.Value]), [LoCaseInsensitive, LoPartialKey]) then | |
begin | |
VarNRet:=Dsretenciones.DataSet.FieldByName('NUMERO_COM_RETENCION').Value; //Mal | |
Dsretenciones.DataSet.Edit; | |
end else | |
begin | |
if DM.IBDCONFINUMERORETENCION.IsNull then VarNRet:=1 | |
else VarNRet:= StrToInt(DM.IBDCONFINUMERORETENCION.value)+1; | |
Dsretenciones.DataSet.Insert; | |
end; | |
Dsretenciones.DataSet.FieldByName('SERIE').Value:=DBNSerie.Field.Value; | |
Dsretenciones.DataSet.FieldByName('NUMERODOCUMENTO').Value:=DBNNumeroDocumento.Field.Value; | |
Dsretenciones.DataSet.FieldByName('FECHA').Value:=DBNFecha.Field.Value; | |
Dsretenciones.DataSet.FieldByName('CODIGOCLIENTE ').Value:=DBNCodigoCliente.Field.Value; | |
Dsretenciones.DataSet.FieldByName('SUBTOTAL').Value:=CalcularSubtotal; | |
Dsretenciones.DataSet.FieldByName('IMPUESTOS').Value:=VPPAFSumaSubTotalesIMPUESTOS; | |
Dsretenciones.DataSet.FieldByName('NUMERORETENCION').Value:=VarNRet; | |
Dsretenciones.DataSet.FieldByName('PORCENTAJERETENCION').Value:=DBEditDefault1.Field.Value; | |
Dsretenciones.DataSet.FieldByName('TOTALRETENIDO').Value:=EditDefault1.MyReal; | |
CamposObligatorios(DSRetenciones,'ID'); | |
Dsretenciones.DataSet.Post; | |
end; | |
end; | |
if VarSTipoDocumento>='FACTURA' then DsPrincipal.DataSet.FieldByName('TOTALRETENCIONES').Value:=EditDefault1.MyReal; | |
if DsPrincipal.DataSet.State in [dsEdit] then | |
begin | |
DsPrincipal.DataSet.FieldByName('TOTALIMPUESTO1').Value:=VPPAFSumaImportesImpuestos1; | |
DsPrincipal.DataSet.FieldByName('TOTALIMPUESTO2').Value:=VPPAFSumaImportesImpuestos2; | |
DsPrincipal.DataSet.FieldByName('TOTALIMPUESTO3').Value:=VPPAFSumaImportesImpuestos3; | |
DsPrincipal.DataSet.FieldByName('TOTALIMPUESTO4').Value:=VPPAFSumaImportesImpuestos4; | |
DsPrincipal.DataSet.FieldByName('TOTALIMPUESTOS').Value:=(VPPAFSumaImportesImpuestos1+VPPAFSumaImportesImpuestos2+ | |
VPPAFSumaImportesImpuestos3+VPPAFSumaImportesImpuestos4); | |
end; | |
VARBPPAFModi:=False; | |
CamposObligatorios(DSPrincipal,'ID'); | |
if DSPrincipal.DataSet.State in [dsEdit,dsInsert] then DSPrincipal.DataSet.Post; | |
DM.IBTransaction1.CommitRetaining; | |
IBQDesgloce.Active:=False; | |
IBQDesgloce.Active:=True; | |
if VarSTipoDocumento='FACTURA' then | |
begin | |
if DBEditDefault2.Field.Value>0 then //Finanaciado | |
begin | |
if not (DSFinanciado.DataSet.Locate('NUMERODOCUMENTO;SERIE', VarArrayOf([DBNNumeroDocumento.Field.Value, DBNSerie.Field.Value]), [LoCaseInsensitive, LoPartialKey])) then | |
begin | |
Case Application.MessageBox(pchar('Puede acceder al apartado de Finacidos ahora, o lo hara despues desde su apartado oportuno.'+#13#10 | |
+#13#10+'Desea acceder a la gestion de Finaciados ahora, '),pchar('Esta factura tiene una parte financiada'), | |
MB_YESNO+MB_ICONWARNING+MB_SYSTEMMODAL) of | |
IDYES:begin //Si | |
FFInanciado.Show; | |
FFInanciado.SbNuevoClick(Sender); | |
FFInanciado.DBNEFecha1.Field.value:=DBNFecha.Field.Value; | |
if DM.IBDCONFINUMEROFINANCIADO.IsNull then FFInanciado.DBNENumeroFinanciado2.Field.value:='1' | |
else FFInanciado.DBNENumeroFinanciado2.Field.value:=IntToStr(SoloInteger(DM.IBDCONFINUMEROFINANCIADO.AsString)+1); | |
FFInanciado.DsPrincipal.DataSet.FieldByName('NUMERODOCUMENTO').value:=VarSTipoDocumento; | |
FFInanciado.DsPrincipal.DataSet.FieldByName('TIPODOCUMENTO').value:=DBNNumeroDocumento.Field.Value; | |
FFInanciado.DsPrincipal.DataSet.FieldByName('SERIE').value:=DBNSerie.Field.Value; | |
FFInanciado.DsPrincipal.DataSet.FieldByName('FECHA').value:=DBNFecha.Field.Value; | |
FFInanciado.DBNEImporte3.Field.value:=EditDefault2.MyReal; | |
FFInanciado.DBNECodigoCliente4.Field.value:=DBNCodigoCliente.Field.Value; | |
FFInanciado.SetFocus | |
end; | |
end; | |
end; | |
end; | |
if DBETotalComisiones19.Field.value>0 then //Comisiones | |
begin | |
if DSComisioness.DataSet.Locate('NUMERODOCUMENTO;SERIE', VarArrayOf([DBNNumeroDocumento.Field.Value, DBNSerie.Field.Value]), [LoCaseInsensitive, LoPartialKey]) then | |
DSComisioness.DataSet.Edit else DSComisioness.DataSet.Insert; | |
if DSComisioness.DataSet.State in [dsInsert] then DSComisioness.DataSet.FieldByName('PAGADAS').Value:='N'; //Si es nueva | |
DSComisioness.DataSet.FieldByName('CODIGOEMPLEADO').Value:=DBNCodigoComercial.Field.Value; //Not null | |
DSComisioness.DataSet.FieldByName('NUMERODOCUMENTO').Value:=DBNNumeroDocumento.Field.Value; //Not null | |
DSComisioness.DataSet.FieldByName('TIPODOCUMENTO').Value:=VarSTipoDocumento; | |
DSComisioness.DataSet.FieldByName('SERIE').Value:=DBNSerie.Field.Value; | |
DSComisioness.DataSet.FieldByName('IMPORTEDOCUMENTO').Value:=StrToFloat(Edit1.Text); | |
DSComisioness.DataSet.FieldByName('COMISION').Value:=IBQAgentes.FieldByName('MEDIACOMISION').Value; | |
DSComisioness.DataSet.FieldByName('IMPORTECOMISION').Value:=DBETotalComisiones19.Field.Value; | |
DSComisioness.DataSet.FieldByName('FECHA').Value:=DBNFecha.Field.Value; | |
CamposObligatorios(DSComisioness,'ID'); | |
DSComisioness.DataSet.Post; | |
end; | |
end; | |
DM.IBTransaction1.CommitRetaining; | |
end else ShowMessage('Confirme/cancele el producto que esta editando'); | |
except | |
on E: Exception do | |
begin | |
MessageBeep(1000); | |
ShowMessage( | |
'Se ha producido un error y el proceso no se ha podido terminar Unidad:[ uFormPPAF ] Modulo:[ Grabar ]' | |
+ Chr(13) + Chr(13) + 'Clase de error: ' + E.ClassName + Chr(13) + Chr(13) | |
+ 'Mensaje del error:' + E.Message + Chr(13) + Chr(13) + ' ' + Chr(13) + Chr(13) | |
+ 'El proceso ha quedado interrumpido'); | |
DSPrincipal.DataSet.Cancel; | |
DM.IBTransaction1.RollbackRetaining; | |
end; | |
end; | |
end; | |
procedure TFXPAF.SBImprimirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Abrir Imprimir ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
FIMPPPAF.ShowModal; | |
end; | |
procedure TFXPAF.SBMas1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Avanzar un registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Next; | |
end; | |
procedure TFXPAF.SBMasXClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Avanzar x Registros ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.MoveBy(SEMobeByX.Value); | |
end; | |
procedure TFXPAF.SBMenos1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Retroceder 1 registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Prior; | |
end; | |
procedure TFXPAF.SBMenosxClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**********************************************[ Retroceder x Registros ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.MoveBy(-SEMobeByX.Value); | |
end; | |
procedure TFXPAF.SbModificarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Editar el actual registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
if DsPrincipal.DataSet.IsEmpty<>true then | |
begin | |
DSPrincipal.DataSet.Edit; | |
DSPrincipal.DataSet.FieldByName('MODIFICACIONES').Value:=DSPrincipal.DataSet.FieldByName('MODIFICACIONES').Value+1; | |
DBNFecha.SetFocus | |
end else ShowMessage('No hay registros disponibles para editar') | |
end; | |
procedure TFXPAF.SbNuevoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Creamos un nuevo registro ]****** | |
//------------------------------------------------------------------------------ | |
var I:integer; | |
begin | |
PC.ActivePageIndex:=1; | |
for I := 0 to StringGrid1.RowCount - 1 do | |
StringGrid1.Rows[I].Clear; | |
EditDefault1.MyReal:=0; | |
EditDefault2.MyReal:=0; | |
Edit1.Text:='0,00'; | |
DSPrincipal.DataSet.Insert; | |
NSESerie.Value:=1; | |
DBNFecha.Field.Value:=Now; | |
QuerryOC(IBQClientes); //PAra no mostrar datos antes de tiempo | |
QuerryOC(IBQAgentes); | |
QuerryOC(IBQAgenteIMAGEN); | |
if DM.IBDCONFIUSARSERIEYEAR.Value='S' then | |
begin | |
NSESerie.Enabled:=False; | |
DBNSerie.Field.Value:=Copy(IntToStr(Ano(now)),3,4); | |
end else | |
begin | |
NSESerie.Enabled:=True; | |
DBNSerie.Field.Value:=DM.IBDCONFISERIE.AsString; | |
end; | |
NDBSENumeroProteccionDatos.Field.Value:=1; | |
DBNNumeroDocumento.Field.value:=VerNumeroDocumento(VarSTipoDocumento,DBNSerie.Text); | |
DSPrincipal.DataSet.FieldByName('PORCENTAJEFINANCIADO').Value:=0; //Campos que no pueden quedar nulos | |
DSPrincipal.DataSet.FieldByName('TIPODOCUMENTO').Value:=VarSTipoDocumento; | |
DSPrincipal.DataSet.FieldByName('COBRADO').Value:='N'; | |
DSPrincipal.DataSet.FieldByName('TOTALCOMISIONES').Value:=0; | |
DSPrincipal.DataSet.FieldByName('MODIFICACIONES').Value:=0; | |
DSPrincipal.DataSet.FieldByName('SUBTOTAL').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALIMPUESTOS').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALIMPUESTO1').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALIMPUESTO2').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALIMPUESTO3').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALIMPUESTO4').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALPESO').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALDESCUENTOS').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALFINANCIADO').Value:=0; | |
DSPrincipal.DataSet.FieldByName('TOTALRETENCIONES').Value:=0; | |
DSPrincipal.DataSet.FieldByName('PORCENTAJERETENCIONES').Value:=0; | |
Memo2.Lines.Clear; | |
DBNSerie.SetFocus; | |
end; | |
procedure TFXPAF.SBPrimeroClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Ir al Primer Registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.First; | |
end; | |
procedure TFXPAF.SBUltimoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Ir al último registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Last; | |
end; | |
procedure TFXPAF.SB_SalirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Salir Del Form ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
FXPAF.Close; | |
end; | |
procedure TFXPAF.SBDetalleModificarClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// *******************************************[ Editar el actual registro ]****** | |
// ------------------------------------------------------------------------------ | |
begin | |
if DsDetalle.DataSet.IsEmpty<>true then | |
begin | |
DsDetalle.DataSet.Edit; | |
VarBModificadoStock:=False; | |
VarBModificadoLotesDocumento:=False; | |
VarBModificacion:=True; | |
VarSCadenaLotes:=NEDResumenLotes.Text; | |
FExtPPAF.Show; | |
FExtPPAF.DBNExtCodigoArticulo.SetFocus; | |
end else ShowMessage('No existen datos para poder editar'); | |
end; | |
procedure TFXPAF.SBDetalleBorrarClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **********************************[ Borrar el Actual Registro Desgloce ]****** | |
// ------------------------------------------------------------------------------ | |
begin // Cambiar por el mensaje elegido | |
if not DsDetalle.DataSet.IsEmpty then | |
begin | |
if (MessageBox(0, '¿Esta seguro de eliminar el registro detalle?', // Aqui no se porque me manda la última comilla simple y la coma a la linea de abajo, por favor subir al final de la linea anterior | |
'Eliminar Registro', MB_ICONSTOP or MB_YESNO or MB_DEFBUTTON2) = ID_No) then Abort | |
else | |
begin | |
DsDetalle.DataSet.Delete; | |
ShowMessage('El registro ha sido eliminado'); | |
end; | |
end else ShowMessage('No existen datos para eliminar'); | |
end; | |
procedure TFXPAF.SBInsertarComentarioClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ************************************************[ Insertar Comentario ]******* | |
// ------------------------------------------------------------------------------ | |
var VarScadena: string; | |
begin | |
VarScadena := InputBox('Comentario a insertar', 'Su comentario', ''); | |
if VarScadena <> '' then | |
begin | |
if CambiarEstado=0 then | |
begin | |
DsDetalle.DataSet.Insert; | |
DsDetalle.DataSet.FieldByName('CODIGOARTICULO').value:='COM.'; | |
DsDetalle.DataSet.FieldByName('DESCRIPCIONARTICULO').value:=VarScadena; | |
desgloceBlanco; | |
end; | |
end; | |
end; | |
procedure TFXPAF.SBInsertarMuestraClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **************************************************[ Insertar Muestra ]******* | |
// ------------------------------------------------------------------------------ | |
begin | |
if CambiarEstado=0 then FEntrMuestra.Show; | |
end; | |
procedure TFXPAF.SBDetalleCancelarClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ************************************************[ Cancela el producto ]******* | |
// ------------------------------------------------------------------------------ | |
begin | |
DsDetalle.DataSet.Cancel; | |
end; | |
procedure TFXPAF.SBDetalleConfirmarClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **********************************[ Grabar temporralmente el producto ]******* | |
// ------------------------------------------------------------------------------ | |
var VarBModifLotes: Boolean; VarSLote: string; VarICant: array of Integer; | |
VarSLot: array of string; VariCantidadLotes, I: Integer; VarSTextResto: string; | |
VarIGRabCantidad,VarIGrabResto:Integer; | |
//Para la grabacion en lotes Salida | |
VarSPPAFLote:string; | |
VarIPPAFCant:Integer; | |
PosError, Errores:string; | |
//Variables para grabación forzada | |
VarForID, VarForCANTIDAD, VarForMODI :INTEGER; | |
VarForSERIE, VarForNUM_DOC, VarForCOD_ART, VarForDESCRIPCION, VarForMINI_NOTA, VarForLOTE, VarForVENCIMIENTO, VarForCAMPO_LIBRE, | |
VarForALBARAN, VarForSERVICIO, VarForADR, Campo :string; | |
VarForPRECIO_UD, VarForIMPUESTO, VarForDTO, VarForCOMISION, VarForPESO_UD, VarForSUBTOT_IMP, VarForSUBTOT_COM, VarForSUBTOT_PESO, | |
VarForSUBTOT_IMPORTE:Real; | |
VarForFECHA_ALBARAN:TDate; | |
begin //Confirmar datos detalles y lotesDocumentos entre ellos el identificador Coger los Datos de NEDvencimiento y NEDLotes | |
Errores:=''; | |
try | |
PosError:='Principio'; | |
VarBModifLotes := False; | |
CalculoDatos; | |
CamposObligatorios(DsDetalle,'ID'); | |
if DsDetalle.DataSet.FieldByName('DESCUENTO').IsNull then DsDetalle.DataSet.FieldByName('DESCUENTO').Value:=0; | |
if CamposObligatorios(DsDetalle,'ID') then | |
begin | |
if DsDetalle.DataSet.State in [dsInsert, DsEdit] then DsDetalle.DataSet.Post; | |
CalculoDatos; | |
DM.IBDDocumentosTOTALIMPUESTOS.Value:=VPPAFSumaSubTotalesIMPUESTOS; | |
if VarBModificacion=true then //Borramos los datos modificados para grabarlos nuevamente | |
begin | |
if (VarSCadenaLotes<>NEDResumenLotes.Text) and (VarSCadenaLotes<>'') then | |
begin | |
VariCantidadLotes := ContarCaracter(VarSCadenaLotes); | |
SetLength(VarICant, VariCantidadLotes + 2); | |
SetLength(VarSLot, VariCantidadLotes + 2); | |
VarSTextResto := VarSCadenaLotes; | |
for I := 1 to VariCantidadLotes do | |
begin | |
VarICant[I] := StrToInt(SacarCandena(VarSTextResto)); | |
VarSLot[I] := SacarCandena(VarSTextResto, '(', ')'); | |
VarSTextResto := CortarCadena('[', ']', VarSTextResto, 1); | |
VarSTextResto := CortarCadena('(', ')', VarSTextResto, 1); | |
end; | |
VarICant[VariCantidadLotes + 1] := 0; // PAra evitar un error de puntero añadimos 1 | |
VarSLot[VariCantidadLotes + 1] := ' '; | |
if VPPAFSCadenaLote <> VarSCadenaLotes then | |
VarBModifLotes := True; // Comprobar si hay diferencia entre el lote actual y la variable VPPAFSCadenaLote | |
for I := 1 to VariCantidadLotes do | |
begin | |
VarSPPAFLote:=VarSLot[I]; | |
VarIPPAFCant:=VarICant[I]; | |
if VarBModificadoStock=false then | |
begin | |
if DSSTOCK.DataSet.Locate('CODIGOPRODUCTO;LOTE', VarArrayOf([BBNDetalleCodigoArticulo.Field.Value, VarSLot[I]]), [LoCaseInsensitive, LoPartialKey]) then | |
begin // Aqui ajustamo lotes de productos Descontamos | |
if (BBNDetalleCodigoArticulo.Field.Value <> 'COM./FE.') and (BBNDetalleCodigoArticulo.Field.Value <> '-') and (BBNDetalleCodigoArticulo.Field.Value <> 'COM.') | |
and (BBNDetalleCodigoArticulo.Field.Value <> 'C-NE') and (BBNDetalleCodigoArticulo.Field.Value <> 'C-AL') then | |
begin | |
DSSTOCK.DataSet.Edit; | |
DSSTOCK.DataSet.FieldByName('EXISTENCIAS').Value :=DSSTOCK.DataSet.FieldByName('EXISTENCIAS').Value + VarICant[I]; | |
DSSTOCK.DataSet.Post; | |
VarBModificadoStock:=True; | |
end; | |
end; | |
end; | |
PosError:='Según el tipo'; | |
if (VarSTipoDocumento='ALBARAN') or (VarSTipoDocumento='FACTURA') then//SI ES ALBARAN O FACTURA GRABAR EN DOCUMENTOS LOTES | |
begin | |
if DM.IBDLotesDocuemntos.locate('IDENTIFICADOR;LOTE', VarArrayOf([DsDetalle.DataSet.FieldByName('ID').AsString, VarSLot[I]]), [LoCaseInsensitive, LoPartialKey]) then DM.IBDLotesDocuemntos.Delete; | |
end; | |
end; | |
end; | |
VarBModificacion:=False; | |
end; //cierra el borrado de datos modificados para grabarlos nuevamente | |
if NEDResumenLotes.Text<>'' then //Cambiamos el Stock | |
begin | |
VariCantidadLotes := ContarCaracter(NEDResumenLotes.Text); | |
SetLength(VarICant, VariCantidadLotes + 2); | |
SetLength(VarSLot, VariCantidadLotes + 2); | |
VarSTextResto := NEDResumenLotes.Text; | |
for I := 1 to VariCantidadLotes do | |
begin | |
VarICant[I] := StrToInt(SacarCandena(VarSTextResto)); | |
VarSLot[I] := SacarCandena(VarSTextResto, '(', ')'); | |
VarSTextResto := CortarCadena('[', ']', VarSTextResto, 1); | |
VarSTextResto := CortarCadena('(', ')', VarSTextResto, 1); | |
end; | |
VarICant[VariCantidadLotes + 1] := 0; // PAra evitar un error de puntero añadimos 1 | |
VarSLot[VariCantidadLotes + 1] := ' '; | |
if VPPAFSCadenaLote <> NEDResumenLotes.Text then | |
VarBModifLotes := True; // Comprobar si hay diferencia entre el lote actual y la variable VPPAFSCadenaLote | |
for I := 1 to VariCantidadLotes do | |
begin | |
VarSPPAFLote:=VarSLot[I]; | |
VarIPPAFCant:=VarICant[I]; | |
if VarBModificadoStock=false then | |
begin | |
if DSSTOCK.DataSet.Locate('CODIGOPRODUCTO;LOTE', VarArrayOf([BBNDetalleCodigoArticulo.Field.Value, VarSLot[I]]), [LoCaseInsensitive, LoPartialKey]) then | |
begin // Aqui ajustamo lotes de productos Descontamos | |
if (BBNDetalleCodigoArticulo.Field.Value <> 'COM./FE.') and (BBNDetalleCodigoArticulo.Field.Value <> '-') and (BBNDetalleCodigoArticulo.Field.Value <> 'COM.') | |
and (BBNDetalleCodigoArticulo.Field.Value <> 'C-NE') and (BBNDetalleCodigoArticulo.Field.Value <> 'C-AL') then | |
begin | |
DSSTOCK.DataSet.Edit; | |
DSSTOCK.DataSet.FieldByName('EXISTENCIAS').Value :=DSSTOCK.DataSet.FieldByName('EXISTENCIAS').Value - VarICant[I]; | |
DSSTOCK.DataSet.Post; | |
VarBModificadoStock:=True; | |
end; | |
end else | |
begin // Si no existe, aunque es mejor crearlo en formularios | |
if (BBNDetalleCodigoArticulo.Field.Value <> 'COM./FE.') and (BBNDetalleCodigoArticulo.Field.Value <> '-') and (BBNDetalleCodigoArticulo.Field.Value <> 'COM.') | |
and (BBNDetalleCodigoArticulo.Field.Value <> 'C-NE') and (BBNDetalleCodigoArticulo.Field.Value <> 'C-AL') then | |
begin | |
DSSTOCK.DataSet.Insert; | |
DSSTOCK.DataSet.FieldByName('EXISTENCIAS').Value := VarICant[I]; | |
DSSTOCK.DataSet.FieldByName('CODIGOPRODUCTO').Value := BBNDetalleCodigoArticulo.Field.Value; | |
DSSTOCK.DataSet.FieldByName('CANTIDADDEENTRADA').Value := VarICant[I]; | |
DSSTOCK.DataSet.FieldByName('LOTE').Value := VarSLot[I]; | |
DSSTOCK.DataSet.FieldByName('ACTIVO').Value := 'S'; | |
DSSTOCK.DataSet.FieldByName('FECHAENTRADA').Value := Now; | |
DSSTOCK.DataSet.FieldByName('CADUCIDAD').Value := (Now+365); | |
DSSTOCK.DataSet.Post; | |
VarBModificadoStock:=True; | |
end; | |
end; | |
end; | |
PosError:='Según el tipo'; | |
if VarBModificadoLotesDocumento=false then //Grabnos loslotes documento | |
begin | |
if (VarSTipoDocumento='ALBARAN') or (VarSTipoDocumento='FACTURA') then//SI ES ALBARAN O FACTURA GRABAR EN DOCUMENTOS LOTES | |
begin | |
if not (DM.IBDLotesDocuemntos.State in [dsInsert, dsEdit]) then DM.IBDLotesDocuemntos.Insert; //Insertamos un nuevo registro | |
if DM.DSaRTICULOS.DataSet.Locate('CODIGO',BBNDetalleCodigoArticulo.Text,[loCaseInsensitive,loPartialKey]) then | |
begin | |
if DM.DSaRTICULOS.DataSet.FieldByName('ADR').IsNull then DM.IBDLotesDocuemntosADR.Value:='Exento' | |
else DM.IBDLotesDocuemntosADR.Value:=DM.DSaRTICULOS.DataSet.FieldByName('ADR').Value; | |
if not DM.DSaRTICULOS.DataSet.FieldByName('ADREXEPCION').IsNull then DM.IBDLotesDocuemntosEXCEPCION.Value:=DM.DSaRTICULOS.DataSet.FieldByName('ADREXEPCION').Value; | |
if not DM.DSaRTICULOS.DataSet.FieldByName('ADRLIMITE').IsNull then DM.IBDLotesDocuemntosLIMITE.Value:=DM.DSaRTICULOS.DataSet.FieldByName('ADRLIMITE').Value; | |
end; | |
DM.IBDLotesDocuemntosLOTE.Value:=VarSPPAFLote; | |
DM.IBDLotesDocuemntosTIPODOCUMENTO.Value:=VarSTipoDocumento; | |
DM.IBDLotesDocuemntosNUMERODOCUMETO.Value:=DBNNumeroDocumento.Field.Value; | |
DM.IBDLotesDocuemntosCODIGOARTICULO.Value:=BBNDetalleCodigoArticulo.Field.Value; | |
DM.IBDLotesDocuemntosCANTIDAD.Value:=VarIPPAFCant; | |
DM.IBDLotesDocuemntosSERIE.Value:=DBNSerie.Field.Value; | |
if not DSSTOCK.DataSet.FieldByName('CADUCIDAD').IsNull then DM.IBDLotesDocuemntosCADUCIDAD.Value:=DSSTOCK.DataSet.FieldByName('CADUCIDAD').Value; | |
DM.IBDLotesDocuemntosIDENTIFICADOR.Value:=DsDetalle.DataSet.FieldByName('ID').Value; | |
DM.IBDLotesDocuemntos.Post; | |
VarBModificadoLotesDocumento:=True; | |
end; | |
end; | |
end; | |
end; | |
CalculoDatos; // ------Aqui hacer los calculos y adaptarlos | |
DM.IBDDocumentosTOTALIMPUESTOS.Value:=VPPAFSumaSubTotalesIMPUESTOS; | |
DM.IBDDocumentosTOTALDESCUENTOS.Value:=VPPAFSumaSubTotalesDTOS; | |
DM.IBDDocumentosTOTALFINANCIADO.Value:=EditDefault2.MyReal; | |
DM.IBDDocumentosTOTALRETENCIONES.Value:=EditDefault1.MyReal; | |
DM.IBDDocumentosTOTALPESO.Value:=VPPAFSumaSubTotalesPeso; | |
DM.IBDDocumentosSUBTOTAL.Value:=VPPAFSumaSubTotales; | |
DM.IBDDocumentosTOTALCOMISIONES.Value:=VPPAFSumaSubTotalesCOMISIONES; | |
PosError:='Al final'; | |
DsPrincipal.DataSet.Post; | |
DsPrincipal.DataSet.Edit; | |
VarBModificadoStock:=False; | |
VarBModificadoLotesDocumento:=False; | |
if VarautoGRab=0 then | |
begin | |
Case MessageBox(0, Pchar('¿Desea Insertar un nuevo producto?'), Pchar ('Desea insertar un nuevo articulo'), 4 + 32 + 0 + 4096) of | |
6: SBDetalleNuevoClick(Sender); //Si elegimos si | |
end; | |
end else | |
begin | |
if VarautoGRab=1 then SBDetalleNuevoClick(Sender); | |
VarautoGRab:=0 | |
end; | |
end; | |
except //Si se produce un error, editamos nuevammente según lo que lijamos | |
on E: Exception do | |
begin | |
MessageBeep(1000); | |
ShowMessage( | |
'Se ha producido un error y el proceso no se ha podido terminar Unidad:[ uFormPPAF ] Modulo:[ Grabar detalle ]' | |
+ Chr(13) + Chr(13) + 'Clase de error: ' + E.ClassName + Chr(13) + Chr(13) + 'Mensaje del error:' + E.Message + Chr(13) | |
+ Chr(13) + ' ' + Chr(13) + Chr(13) + 'El proceso ha quedado interrumpido, posición:'+PosError); | |
Case Application.MessageBox(pchar( 'Se ha detectado un error al grabar, ¿que desea hacer?' +#13#10 | |
+#13#10+'[ SI ] Intentar la grabación forzada (se comprobará, los datos y se ' | |
+#13#10+' intentará la grabación directa)' | |
+#13#10+'[ No ] Volver a editar el registro'+#13#10+'[Cancelar ]Cancelar la edición del actual registro'), | |
pchar('Ha habido un error'),MB_YESNOCANCEL+MB_ICONERROR+MB_DEFBUTTON2+MB_SYSTEMMODAL) of | |
IDCANCEL:begin | |
DsDetalle.DataSet.cancel; // si elegimos Cancelar | |
VarBModificadoStock:=False; | |
VarBModificacion:=False; | |
VarBModificacion:=False; | |
end; | |
IDYES:begin //Si Intentar grabación forzada | |
try //Primero comprobamos los Datos principales | |
if not (DsDetalle.DataSet.State in [dsEdit, dsInsert]) then DsDetalle.DataSet.Edit; | |
if DsDetalle.DataSet.FieldByName('NUMERODOCUMENTO').Value<>DsPrincipal.DataSet.FieldByName('NUMERODOCUMENTO').Value then | |
begin | |
Errores:='-No cuadraba el Nº de Documento'; | |
DsDetalle.DataSet.FieldByName('NUMERODOCUMENTO').Value:=DsPrincipal.DataSet.FieldByName('NUMERODOCUMENTO').Value; | |
end; | |
if DsDetalle.DataSet.FieldByName('SERIE').Value<>DsPrincipal.DataSet.FieldByName('SERIE').Value then | |
begin | |
Errores:=Errores+'-No cuadraba la Serie'; | |
DsDetalle.DataSet.FieldByName('SERIE').Value:=DsPrincipal.DataSet.FieldByName('SERIE').Value; | |
end; | |
//Compromabos los nulos | |
if DsDetalle.DataSet.FieldByName('CODIGOARTICULO').IsNull then | |
begin | |
Errores:=Errores+'-No se encotraba el código del articulo'; | |
DsDetalle.DataSet.FieldByName('CODIGOARTICULO').Value:='0'; | |
end; | |
if DsDetalle.DataSet.FieldByName('SERVICIO').IsNull then | |
begin | |
Errores:=Errores+'-No se encotraba el servicio'; | |
DsDetalle.DataSet.FieldByName('SERVICIO').Value:='N'; | |
end; | |
DsDetalle.DataSet.Post; | |
CalculoDatos; | |
DM.IBDDocumentosTOTALIMPUESTOS.Value:=VPPAFSumaSubTotalesIMPUESTOS; | |
DM.IBDDocumentosTOTALDESCUENTOS.Value:=VPPAFSumaSubTotalesDTOS; | |
DM.IBDDocumentosTOTALFINANCIADO.Value:=EditDefault2.MyReal; | |
DM.IBDDocumentosTOTALRETENCIONES.Value:=EditDefault1.MyReal; | |
DM.IBDDocumentosTOTALPESO.Value:=VPPAFSumaSubTotalesPeso; | |
DM.IBDDocumentosSUBTOTAL.Value:=VPPAFSumaSubTotales; | |
DM.IBDDocumentosTOTALCOMISIONES.Value:=VPPAFSumaSubTotalesCOMISIONES; | |
DsPrincipal.DataSet.Post; | |
DsPrincipal.DataSet.Edit; | |
except //Si persite el error 1º) cargamos las variables | |
if Not DsDetalle.DataSet.FieldByName('CANTIDAD').IsNull then VarForCANTIDAD:=DsDetalle.DataSet.FieldByName('CANTIDAD').Value | |
else VarForCANTIDAD:=0; | |
if Not DsDetalle.DataSet.FieldByName('MODIFICADO').IsNull then VarForMODI:=DsDetalle.DataSet.FieldByName('MODIFICADO').Value | |
else VarForMODI:=0; | |
VarForCAMPO_LIBRE:=''; | |
VarForMINI_NOTA:=''; | |
if Not DsDetalle.DataSet.FieldByName('DESCRIPCIONARTICULO').IsNull then VarForDESCRIPCION:=DsDetalle.DataSet.FieldByName('DESCRIPCIONARTICULO').Value | |
else VarForDESCRIPCION:='?'; | |
if Not DsDetalle.DataSet.FieldByName('CODIGOARTICULO').IsNull then VarForCOD_ART:=DsDetalle.DataSet.FieldByName('CODIGOARTICULO').Value | |
else VarForCOD_ART:='?'; | |
if Not DsDetalle.DataSet.FieldByName('NUMERODOCUMENTO').IsNull then VarForNUM_DOC:=DsDetalle.DataSet.FieldByName('NUMERODOCUMENTO').Value | |
else VarForNUM_DOC:='?'; | |
if Not DsDetalle.DataSet.FieldByName('SERIE').IsNull then VarForSERIE:=DsDetalle.DataSet.FieldByName('SERIE').Value | |
else VarForSERIE:='?'; | |
if Not DsDetalle.DataSet.FieldByName('SERVICIO').IsNull then VarForSERVICIO:=DsDetalle.DataSet.FieldByName('SERVICIO').Value | |
else VarForSERVICIO:='N'; | |
if Not DsDetalle.DataSet.FieldByName('PRECIOUNIDAD').IsNull then VarForPRECIO_UD:=DsDetalle.DataSet.FieldByName('PRECIOUNIDAD').Value | |
else VarForPRECIO_UD:=0; | |
if Not DsDetalle.DataSet.FieldByName('IMPUESTO').IsNull then VarForIMPUESTO:=DsDetalle.DataSet.FieldByName('IMPUESTO').Value | |
else VarForIMPUESTO:=0; | |
if Not DsDetalle.DataSet.FieldByName('DESCUENTO').IsNull then VarForDTO:=DsDetalle.DataSet.FieldByName('DESCUENTO').Value | |
else VarForDTO:=0; | |
if Not DsDetalle.DataSet.FieldByName('COMISION').IsNull then VarForCOMISION:=DsDetalle.DataSet.FieldByName('COMISION').Value | |
else VarForCOMISION:=0; | |
if Not DsDetalle.DataSet.FieldByName('PESOUNIDAD').IsNull then VarForPESO_UD:=DsDetalle.DataSet.FieldByName('PESOUNIDAD').Value | |
else VarForPESO_UD:=0; | |
DsDetalle.DataSet.Cancel; | |
DsPrincipal.DataSet.Post; | |
DsDetalle.DataSet.Insert; | |
DsDetalle.DataSet.FieldByName('CANTIDAD').Value:=VarForCANTIDAD; | |
DsDetalle.DataSet.FieldByName('MODIFICADO').Value:=VarForMODI; | |
DsDetalle.DataSet.FieldByName('DESCRIPCIONARTICULO').Value:=VarForDESCRIPCION; | |
DsDetalle.DataSet.FieldByName('CODIGOARTICULO').Value:=VarForCOD_ART; | |
DsDetalle.DataSet.FieldByName('NUMERODOCUMENTO').Value:=VarForNUM_DOC; | |
DsDetalle.DataSet.FieldByName('SERIE').Value:=VarForSERIE; | |
DsDetalle.DataSet.FieldByName('SERVICIO').Value:=VarForSERVICIO; | |
DsDetalle.DataSet.FieldByName('PRECIOUNIDAD').Value:=VarForPRECIO_UD; | |
DsDetalle.DataSet.FieldByName('IMPUESTO').Value:=VarForIMPUESTO; | |
DsDetalle.DataSet.FieldByName('DESCUENTO').Value:=VarForDTO; | |
DsDetalle.DataSet.FieldByName('COMISION').Value:=VarForCOMISION; | |
DsDetalle.DataSet.FieldByName('PESOUNIDAD').Value:=VarForPESO_UD; | |
DsDetalle.DataSet.Post; | |
DsPrincipal.DataSet.Edit; | |
end; | |
VarBModificadoStock:=False; | |
VarBModificadoLotesDocumento:=False; | |
VarBModificacion:=False; | |
end; | |
IDNO:DsDetalle.DataSet.Edit; | |
end; | |
end; | |
end; | |
end; | |
procedure TFXPAF.SBInstertarComentarioFechaClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **************************************[ Insertar Comentario con fecha ]******* | |
// ------------------------------------------------------------------------------ | |
var VarScadena: string; | |
begin | |
VarScadena := Inputdate('Comentario con fecha', 'Su comentario'); | |
if VarScadena <> '' then | |
begin | |
if CambiarEstado=0 then | |
begin | |
DsDetalle.DataSet.Insert; | |
DsDetalle.DataSet.FieldByName('CODIGOARTICULO').value:='COM./FE.'; | |
DsDetalle.DataSet.FieldByName('DESCRIPCIONARTICULO').value:=VarScadena; | |
desgloceBlanco; | |
end; | |
end; | |
end; | |
procedure TFXPAF.SBEscribirNotaClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************************[ Nota ]**** | |
//------------------------------------------------------------------------------ | |
var VarSText:string; | |
begin | |
VarSText:=Memo2.Lines.Text; | |
Memo2.Lines.Text:=InputMemo('Nota','Escriba su nota',VarSText); | |
end; | |
procedure TFXPAF.SBProductosClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **********************************************************[ Productos PC ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
PC3.ActivePage := Productos; | |
end; | |
procedure TFXPAF.SpeedButton19Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Abrir selector ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
FExtPPAF.Show; | |
end; | |
procedure TFXPAF.SBDetallePrimeroClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ****************************************************[ Primer registro ]******* | |
// Desgloce | |
// ------------------------------------------------------------------------------ | |
begin | |
DsDetalle.DataSet.First; | |
end; | |
procedure TFXPAF.SBComercialesClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// *********************************************************[ Ccomercial PC ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
PC3.ActivePage := Comercial; | |
end; | |
procedure TFXPAF.SBClientesClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ***********************************************************[ Clientes PC ]**** | |
// ------------------------------------------------------------------------------ | |
begin | |
PC3.ActivePage := Clientes; | |
end; | |
procedure TFXPAF.SBDetalleAnteriorClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// **************************************************[ registro anterior ]******* | |
// Desgloce | |
// ------------------------------------------------------------------------------ | |
begin | |
DsDetalle.DataSet.Prior; | |
end; | |
procedure TFXPAF.SBDetalleSiguienteClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// *************************************************[ Siguiente registro ]******* | |
// Desgloce | |
// ------------------------------------------------------------------------------ | |
begin | |
DsDetalle.DataSet.Next; | |
end; | |
procedure TFXPAF.SBDetalleUltimoClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// ****************************************************[ Último registro ]******* | |
// Desgloce | |
// ------------------------------------------------------------------------------ | |
begin | |
DsDetalle.DataSet.Last; | |
end; | |
procedure TFXPAF.SBDireccionesClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Buscar direcciones ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if DBNCodigoCliente.Text<>'' then | |
begin | |
VarSTabla:='DIRECCIONES'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='XPAFD'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end else ShowMessage('Debe seleccionar primero el código del cliente'); | |
end; | |
procedure TFXPAF.SBNuevoClienteClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************************[ Clientes ]**** | |
// Llama a la gestión de clientes | |
//------------------------------------------------------------------------------ | |
begin | |
FMenu.A_ClientesExecute(Sender); | |
end; | |
procedure TFXPAF.SBBuscarClienteClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Buscar cliente ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FMenu.Acceso(7,FCLIENTES) then | |
begin | |
VarSTabla:='CLIENTES'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='XPAFC'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end; | |
end; | |
procedure TFXPAF.SBNuevoAgenteClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************************[ Agentes ]**** | |
// Llama a la gestión de agentes | |
//------------------------------------------------------------------------------ | |
begin | |
FMenu.Act_Gen_EmpleadosExecute(Sender); | |
end; | |
procedure TFXPAF.SBBuscarAgenteClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*********************************************************[ Buscar Agente ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FMenu.Acceso(7,FEmpleados) then | |
begin | |
VarSTabla:='EMPLEADOS'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='XPAFA'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end; | |
end; | |
function TFXPAF.CambiarEstado: Integer; | |
//------------------------------------------------------------------------------ | |
//*********************************************************[ CambiarEstado ]**** | |
// Nos permite comprobar si los datos necesarios estan rellenos | |
//------------------------------------------------------------------------------ | |
var varIPaso:Integer; | |
begin | |
varIPaso:=0; //Si sigue a 0 grabará y pasará al siguiente | |
if DsPrincipal.DataSet.State in [DsInsert] then | |
begin { Si esta en insercion, lo salvamos y editamos, para que acepte los cambios posteriores } | |
if DM.IBDDocumentosIDDIRECCIONES.IsNull then | |
begin | |
if IBQDirecciones.IsEmpty then DM.IBDDocumentosIDDIRECCIONES.Value:=0 | |
else DM.IBDDocumentosIDDIRECCIONES.Value:=IBQDirecciones.FieldByName('ID').Value; | |
end; | |
DSPrincipal.DataSet.FieldByName('NUMERODOCUMENTO').Value:=DBNNumeroDocumento.Text; | |
DSPrincipal.DataSet.FieldByName('SERIE').Value:=DBNSerie.Text; | |
if DSPrincipal.DataSet.FieldByName('CODIGOCLIENTE').IsNull then varIPaso:=1; | |
if DSPrincipal.DataSet.FieldByName('CODIGOAGENTE').IsNull then varIPaso:=2; | |
if DSPrincipal.DataSet.FieldByName('FECHA').IsNull then varIPaso:=3; | |
if DSPrincipal.DataSet.FieldByName('FORMADEPAGO').IsNull then varIPaso:=4; | |
if DSPrincipal.DataSet.FieldByName('NUMEROPROTECCIONDATOS').IsNull then varIPaso:=5; | |
if varIPaso=0 then | |
begin | |
DsPrincipal.DataSet.Post; | |
DsPrincipal.DataSet.Edit; | |
end else | |
begin | |
case varIPaso of | |
1:begin | |
ShowMessage('Falta por rellenar el código de cliente'); | |
DBNCodigoCliente.SetFocus; | |
end; | |
2:begin | |
ShowMessage('Falta por rellenar el código de agente/comercial'); | |
DBNCodigoComercial.SetFocus; | |
end; | |
3:begin | |
ShowMessage('Falta por rellenar la fecha'); | |
DBNFecha.SetFocus; | |
end; | |
4:begin | |
ShowMessage('Falta por rellenar la forma de pago'); | |
DBNFormaPago.SetFocus; | |
end; | |
5:begin | |
ShowMessage('Falta por rellenar el número de protección de datos'); | |
NDBSENumeroProteccionDatos.SetFocus; | |
end; | |
end; | |
end; | |
end; | |
if varIPaso=0 then Result:=0 else Result:=1; //0 = OK, 1 = problema | |
end; | |
procedure TFXPAF.SBDetalleNuevoClick(Sender: TObject); | |
// ------------------------------------------------------------------------------ | |
// *********************************************************[ Nuevo Detalle ]**** | |
// ------------------------------------------------------------------------------ | |
var I:Integer; | |
begin | |
VarautoGRab:=0; | |
if CambiarEstado=0 then | |
begin | |
DsDetalle.DataSet.Insert; | |
DsDetalle.DataSet.FieldByName('TIPODOCUMENTO').Value:=DSPrincipal.DataSet.FieldByName('TIPODOCUMENTO').Value; | |
DsDetalle.DataSet.FieldByName('NUMERODOCUMENTO').Value:=DSPrincipal.DataSet.FieldByName('NUMERODOCUMENTO').Value; | |
DsDetalle.DataSet.FieldByName('SERIE').Value:=DSPrincipal.DataSet.FieldByName('SERIE').Value; | |
DsDetalle.DataSet.FieldByName('IDENTIFICADOR').Value:=DSPrincipal.DataSet.FieldByName('ID').Value; | |
DsDetalle.DataSet.FieldByName('MODIFICADO').Value:=0; | |
FExtPPAF.ListView1.Items.Clear; | |
for I := 1 to FExtPPAF.StringGrid1.RowCount - 1 do FExtPPAF.StringGrid1.Rows[i].Clear; | |
VarBModificadoStock:=False; | |
VarBModificadoLotesDocumento:=False; | |
FExtPPAF.Show; | |
FExtPPAF.DBNExtCodigoArticulo.SetFocus; | |
end; | |
end; | |
procedure TFXPAF.SpeedButtonBC1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************************[ Valores ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
PC2.ActivePageIndex:=0; | |
end; | |
procedure TFXPAF.SpeedButtonBC2Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************************[ Datos ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
PC2.ActivePageIndex:=1; | |
end; | |
procedure TFXPAF.SpeedButtonBC3Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************************[ Cobros ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
PC2.ActivePageIndex:=2; | |
end; | |
procedure TFXPAF.SpeedButtonBC4Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************************[ Notas ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
PC2.ActivePageIndex:=3; | |
end; | |
procedure TFXPAF.SpeedButtonBC5Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************[ Protección de datos ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
PC2.ActivePageIndex:=4; | |
end; | |
procedure TFXPAF.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; | |
Rect: TRect; State: TGridDrawState); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Drawcell de datos ]**** | |
//------------------------------------------------------------------------------ | |
procedure WriteText(StringGrid: TStringGrid; ACanvas: TCanvas; const ARect: TRect; | |
const Text: string; Format: Word); | |
const DX = 2; | |
DY = 2; | |
var S: array[0..255] of Char; | |
B, R: TRect; | |
begin | |
with Stringgrid, ACanvas, ARect do | |
begin | |
ACanvas.Font.Color:=clNavy; | |
ACanvas.Font.Style:=[fsBold]; | |
case Format of | |
DT_LEFT: ExtTextOut(Handle, Left + DX, Top + DY, | |
ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text), Length(Text), nil); | |
DT_RIGHT: ExtTextOut(Handle, Right - TextWidth(Text) - 3, Top + DY, | |
ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text), | |
Length(Text), nil); | |
DT_CENTER: ExtTextOut(Handle, Left + (Right - Left - TextWidth(Text)) div 2, | |
Top + DY, ETO_OPAQUE or ETO_CLIPPED, @ARect, | |
StrPCopy(S, Text), Length(Text), nil); | |
end; | |
end; | |
end; | |
procedure Display(StringGrid: TStringGrid; const S: string; Alignment: TAlignment); | |
const Formats: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER); | |
begin | |
WriteText(StringGrid, StringGrid.Canvas, Rect, S, Formats[Alignment]); | |
end; | |
begin | |
Display(StringGrid1, StringGrid1.Cells[ACol, ARow], taRightJustify); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment