//--------------------------------------------------------------------------- #include #include #pragma hdrstop #define DEBUG #ifdef EXIST_CFG #include "TpvCFG.h" #endif #include "TpvVentas.h" #include "TDlgBuscar.h" // #include "TpvVntCtbl.h" #include "TpvVntFctPrint.h" #include "TpvVntAlbPrint.h" //--------------------------------------------------------------------------- #pragma link "Grids" #pragma link "DigitNum" #pragma link "LetreroDigital" #pragma link "ElastFrm" #pragma resource "*.dfm" TVentas *Ventas; #define NUM_TERMINAL_ACTUAL 10 #define clQREADY clLime //--------------------------------------------------------------------------- __fastcall TVentas::TVentas(TComponent* Owner) : TForm(Owner) { EsAlbaran = true; TerminalActual = NUM_TERMINAL_ACTUAL; ActualizandoTOTALES = false; FocoRapido = true; LetreroDigital1 -> FuenteRAW = ExtractFilePath(Application->ExeName) + "systm\\8x8.fnt"; try { BtmOK = new Graphics::TBitmap(); BtmOK -> LoadFromFile( "Systm\\ok.bmp" ); } catch (...) { ShowMessage( "Error: La imagen OK! está corrupta" ); } // Mostramos el dialogo, buscar [Productos] DlgBuscarProd = new TDlgBuscar(this); DlgBuscarProd -> TbBusquedas -> TableName = "Tb_Ref"; DlgBuscarProd -> TbBusquedas -> Active = true; TbProdCircular -> IndexFieldNames = "CodProdC"; TbProdCircular -> MasterFields = "ForcedIndex"; TbProdCircular -> MasterSource = DlgBuscarProd -> DsBusquedas; TbProdCircular -> Active = true; TbCartera -> Active = true; //--------- // Imprimir (SI/NO) ImprimirTicket = !ImprimirTicket; PideTicketClick( 0 ); TbVentasC -> TableName = "Ventas (cabecera).db"; TbVentasD -> TableName = "Ventas (cuerpo).db"; TbVentasI -> TableName = "Ventas (caja).db"; TbVentasAbiertas -> TableName = TbVentasC -> TableName; TbInfoClt -> Active = true; // Información de los clientes TbInfoEmpl -> Active = true; // Información de los empleados TbVentasI -> Active = true; // Información sobre la caja del día TbVentasC -> Active = true; // Cabecera de la factura TbVentasD -> Active = true; // Datos de la factura TbVentasF -> Active = true; // Números de factura // Sus cálculos se basan en la existencia de las tablas "InfoClt'&'InfoEmpl" TbVentasAbiertas -> Active = true; // Facturas pendiente de cierre // Preparamos e inicializamos una factura NUEVA... NuevaFacturaCliente(); //--------- } //--------------------------------------------------------------------------- void __fastcall TVentas::SpeedButton5Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TVentas::NuevaFacturaCliente(void) { bool OneOpen = false; // Localizamos las fichas del Empleado por defecto... if ( ! ( TbInfoEmpl -> Locate( "CodCliente1", 1, TLocateOptions() << loCaseInsensitive ) ) ) { ShowMessage( "ERROR: Vendedor Anómimo no encontrado\n-->CIERRE LA APLICACIÖN <<-" ); Close(); } // Localizamos las fichas del Cliente por defecto... if ( ! ( TbInfoClt -> Locate( "CodCliente1", 1, TLocateOptions() << loCaseInsensitive ) ) ) { ShowMessage( "ERROR: Cliente Anómimo no encontrado\n-->CIERRE LA APLICACIÖN <<-" ); Close(); } TbVentasAbiertas -> Refresh(); TbVentasAbiertas -> DisableControls(); TbVentasAbiertas -> First(); while ( ! TbVentasAbiertas -> Eof ) { if ( TbVentasAbiertas->FieldByName("TotalSin")->AsInteger == 0 && TbVentasAbiertas->FieldByName("CodFactura")->AsInteger == 0 ) { OneOpen = true; TbVentasC->GotoCurrent( TbVentasAbiertas ); TbVentasC->Edit(); TbVentasC->FieldByName("FechaFactura")->AsDateTime = TDateTime::CurrentDate(); TbVentasC->FieldByName("HoraFactura")->AsDateTime = TDateTime::CurrentTime(); TbVentasC->Post(); break; } try { TbVentasAbiertas -> Next(); } catch(...) { break; } } TbVentasAbiertas -> EnableControls(); if ( ! OneOpen ) { // Insertamos (y hacemos que sea el actual), un nuevo registro // Cód. Factura TbVentasC->Insert(); TbVentasC->FieldByName("CodCliente")->AsInteger = TbInfoClt->FieldByName( "CodCliente1" )->AsInteger; TbVentasC->FieldByName("CodEmpleado")->AsInteger = TbInfoEmpl->FieldByName( "CodCliente1" )->AsInteger; TbVentasC->FieldByName("FechaFactura")->AsDateTime = TDateTime::CurrentDate(); TbVentasC->FieldByName("HoraFactura")->AsDateTime = TDateTime::CurrentTime(); TbVentasC->FieldByName("TotalSin")->AsInteger = 0; TbVentasC->FieldByName("TotalIva")->AsInteger = 0; TbVentasC->FieldByName("FacturaAbierta")->AsInteger = TerminalActual; TbVentasC->FieldByName("UltimoPago")->AsDateTime = TDateTime::CurrentDate(); TbVentasC->FieldByName("TotalFrac")->AsInteger = 0; TbVentasC->FieldByName("FormaPago")->AsInteger = 0; TbVentasC->FieldByName("NumeroPagos")->AsInteger = 0; TbVentasC->FieldByName("ImprimirNotas")->AsBoolean = false; TbVentasC->FieldByName("Contabilizada")->AsBoolean = 0; TbVentasCCodFactura -> AsInteger = 0; TbVentasC->Post(); } // Reseteamos los totales de compra... DigitNum1 -> Value = 0; DigitNum2 -> Value = 0; StatusBar1->Panels->Items[2]->Text = ""; TbVentasAbiertas -> Refresh(); } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasCNewRecord(TDataSet *DataSet) { // Fecha / Hora Factura TbVentasCFormaPago->AsInteger = 0; TbVentasCUltimoPago -> AsDateTime = TDateTime::CurrentDate(); TbVentasCFechaAlbaran -> AsDateTime = TDateTime::CurrentDate(); TbVentasCFechaFactura -> AsDateTime = TDateTime::CurrentDate(); TbVentasCHoraFactura -> AsDateTime = TDateTime::CurrentTime(); // Terminal que abrió la cuenta... TbVentasCFacturaAbierta -> AsInteger = TerminalActual; } //--------------------------------------------------------------------------- void __fastcall TVentas::BusqClienteClick(TObject *Sender) { // Mostramos la zona de busqueda de clientes... // Mostramos el dialogo, buscar Vendedores TDlgBuscar *DlgBuscar; DlgBuscar = new TDlgBuscar(this); DlgBuscar -> DefaultField = "Nombre"; DlgBuscar -> TbBusquedas -> TableName = TbInfoClt -> TableName; DlgBuscar -> TbBusquedas -> Active = true; DlgBuscar -> ShowModal(); if ( DlgBuscar -> ModalResult == mrOk ) { TbVentasC -> Edit(); TbVentasCCodCliente -> AsInteger = DlgBuscar -> TbBusquedas -> FieldByName( "CodCliente1" ) -> AsInteger; TbVentasC->FieldByName("Banco_Entidad" )->Value = DlgBuscar->TbBusquedas->FieldByName("Banco_Entidad" )->Value; TbVentasC->FieldByName("Banco_Sucursal" )->Value = DlgBuscar->TbBusquedas->FieldByName("Banco_Sucursal" )->Value; TbVentasC->FieldByName("Banco_DC" )->Value = DlgBuscar->TbBusquedas->FieldByName("Banco_DC" )->Value; TbVentasC->FieldByName("Banco_NumCuenta" )->Value = DlgBuscar->TbBusquedas->FieldByName("Banco_NumCuenta" )->Value; TbVentasC -> Post(); } delete DlgBuscar; // Levamos el foco a donde debe... if ( FocoRapido ) QCodigo->SetFocus(); else DBGrid1->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TVentas::BusqVendedorClick(TObject *Sender) { // Mostramos el dialogo, buscar Vendedores TDlgBuscar *DlgBuscar; DlgBuscar = new TDlgBuscar(this); DlgBuscar -> Filter = "[Empleado] >= 1"; DlgBuscar -> DefaultField = "Nombre"; DlgBuscar -> TbBusquedas -> TableName = TbInfoEmpl -> TableName; DlgBuscar -> TbBusquedas -> Active = true; DlgBuscar -> ShowModal(); if ( DlgBuscar -> ModalResult == mrOk ) { TbVentasC -> Edit(); TbVentasCCodEmpleado -> AsInteger = DlgBuscar -> TbBusquedas -> FieldByName( "CodCliente1" ) -> AsInteger; TbVentasC -> Post(); // Y sincronizamos las bases de datos // TbInfoEmpl -> GotoCurrent( DlgBuscar -> TbBusquedas ); } delete DlgBuscar; // Levamos el foco a donde debe... if ( FocoRapido ) QCodigo->SetFocus(); else DBGrid1->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDCalcFields(TDataSet *DataSet) { Currency Cdto; Cdto = TbVentasDPrecioC -> AsCurrency * TbVentasDCantidad -> AsFloat; Cdto = Cdto * ( 1 - ( TbVentasD->FieldByName("Dto")->AsCurrency / 100 ) ); TbVentasDSubTotal -> AsCurrency = Cdto; } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasAbiertasCalcFields(TDataSet *DataSet) { Set flags; flags << loCaseInsensitive; // 1º Obtenemos el Nombre del Cliente if ( TbInfoClt -> Locate( "CodCliente1", TbVentasAbiertasCodCliente->AsInteger, flags ) ) TbVentasAbiertasNombreCliente -> AsString = TbInfoClt -> FieldByName( "Nombre" ) -> AsString + ", " + TbInfoClt -> FieldByName( "Apellidos" ) -> AsString; else TbVentasAbiertasNombreCliente -> AsString = "No Encontrado: " + TbVentasCCodCliente -> AsString; // 2º Obtenemos el Nombre del Vendedor if ( TbInfoEmpl -> Locate( "CodCliente1", TbVentasAbiertasCodEmpleado -> Value, flags ) ) TbVentasAbiertasNombreVendedor -> AsString = TbInfoEmpl -> FieldByName( "Nombre" ) -> AsString + ", " + TbInfoEmpl -> FieldByName( "Apellidos" ) -> AsString; else TbVentasAbiertasNombreVendedor -> AsString = "No Encontrado: " + TbVentasCCodEmpleado -> AsString; } //--------------------------------------------------------------------------- void __fastcall TVentas::bFicharTicketClick(TObject *Sender) { if ( TbVentasD -> RecordCount > 0 ) { FicharTicket(); TbVentasI -> Edit(); TbVentasI -> FieldByName( "Tickets" ) -> AsInteger ++; TbVentasI -> Post(); } else { TbVentasI -> Edit(); TbVentasI -> FieldByName( "Cambios" ) -> AsInteger ++; TbVentasI -> Post(); EfectuarCambio(); } #ifdef EXIST_CFG if ( CFG->CajonMonedas->Checked ) CFG->AbrirCajon(); #endif // Levamos el foco a donde debe... if ( FocoRapido ) QCodigo->SetFocus(); else DBGrid1->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TVentas::EfectuarCambio(void) { // Nothing... } //--------------------------------------------------------------------------- void __fastcall TVentas::AsignarNumFactura(void) { int NumFactura = 0; #ifdef EXIST_CFG try { NumFactura = CFG->SigFactura->Text.ToInt(); } catch(...) { // continuamos NumFactura = 0; } #endif if ( NumFactura <= 0 ) { TbVentasF->Last(); NumFactura = TbVentasF->FieldByName( "idF" )->AsInteger + 1; } #ifdef EXIST_CFG else CFG->SigFactura->Text = "0"; #endif TbVentasF->InsertRecord( ARRAYOFCONST( ( NumFactura, TbVentasC->FieldByName( "EnlaceFactura" )->AsInteger, true ) ) ); TbVentasC -> Edit(); TbVentasC -> FieldByName( "CodFactura" ) -> AsInteger = NumFactura; TbVentasC -> FieldByName("Contabilizada")->AsBoolean = true; TbVentasCFechaFactura -> AsDateTime = TDateTime::CurrentDate(); TbVentasC -> Post(); } //--------------------------------------------------------------------------- void __fastcall TVentas::FicharTicket(void) { TbVentasC -> Edit(); TbVentasC -> FieldByName( "FacturaAbierta" ) -> AsInteger = 0; TbVentasC -> Post(); EsAlbaran = false; #ifdef EXIST_CFG switch ( CFG->alFacturar->ItemIndex ) { // 0 ...siempre case 0: AsignarNumFactura(); break; // 1 ...solo a clientes case 1: if ( TbVentasC->FieldByName( "CodCliente" )->AsInteger > 1 ) AsignarNumFactura(); else EsAlbaran = true; break; // 2 ...a clientes y preguntar otros case 2: if ( TbVentasC->FieldByName( "CodCliente" )->AsInteger > 1 ) { AsignarNumFactura(); } else { if ( MessageDlg( "¿Facturar, ahora?", mtConfirmation, TMsgDlgButtons() << mbNo << mbYes, 0 ) == mrYes ) { AsignarNumFactura(); } else { EsAlbaran = true; } } break; // 3 ...preguntar siempre case 3: if ( MessageDlg( "¿Facturar, ahora?", mtConfirmation, TMsgDlgButtons() << mbNo << mbYes, 0 ) == mrYes ) { AsignarNumFactura(); } else { EsAlbaran = true; } break; // 4 ...nunca case 4: EsAlbaran = true; break; } #else if ( TbVentasC->FieldByName( "CodCliente" )->AsInteger > 1 ) AsignarNumFactura(); #endif TbVentasC->FlushBuffers(); TbVentasD->FlushBuffers(); // Muestra cuadro Entregado/Cambio //**** ***************(##########); // Imprime Factura / Ticket //**** ***************(##########); if ( ImprimirTicket ) SpeedButton11Click( 0 ); NuevaFacturaCliente(); TbVentasAbiertas -> Refresh(); DBGrid1 -> SelectedField = DBGrid1 -> Fields[0]; } //--------------------------------------------------------------------------- void __fastcall TVentas::TabSheet4Enter(TObject *Sender) { // Refrescamos el listado de cuentas abiertas... TbVentasAbiertas -> Refresh(); } //--------------------------------------------------------------------------- void __fastcall TVentas::FormClose(TObject *Sender, TCloseAction &Action) { // Destruimos la imagen de OK! delete BtmOK; try { // Si no hay productos en la factura... La eliminamos... if ( TbVentasD -> RecordCount == 0 && ( TbVentasC -> State == dsInsert || TbVentasC -> State == dsEdit ) ) TbVentasC -> Delete(); if ( TbVentasD->State == dsEdit || TbVentasD->State == dsInsert ) TbVentasD->Post(); if ( TbVentasC->State == dsEdit || TbVentasC->State == dsInsert ) TbVentasC->Post(); if ( TbVentasI->State == dsEdit || TbVentasI->State == dsInsert ) TbVentasI->Post(); } catch(...) { ShowMessage( "Error Eliminando factura vacia.\nVentas Cierre" ); } try { TbVentasI -> Edit(); TbVentasI -> FieldByName( "Fin" ) -> AsDateTime = TDateTime::CurrentTime(); #ifdef _COMPLETO TbVentasI -> FieldByName( "ExitoSalir" ) -> AsInteger++; #else TbVentasI -> FieldByName( "IntentosSalir" ) -> AsInteger++; #endif TbVentasI -> Post(); } catch(...) { ShowMessage( "Error altamente grave.\nVentas Cierre" ); } // Eliminamos el dialogo, buscar [Productos] delete DlgBuscarProd; } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDCodProductoSetText(TField *Sender, const AnsiString Text) { // ## Cambiado 09/08/01 // AnsiString oldCodProducto; int oldCodProducto; Currency TParcial; bool Localizado = true; // ## Cambiado 09/08/01 // oldCodProducto = Sender -> AsString; oldCodProducto = TbVentasD->FieldByName( "CodProductoAux" )->AsInteger; TParcial = TbVentasDPrecioC -> AsCurrency * Currency( ( TbVentasDCantidad -> AsFloat ) ); TParcial = TParcial * (1 - ( TbVentasD -> FieldByName( "Dto" ) -> AsCurrency / 100 ) ); SUMAcompraC -= TParcial; if ( ! TbVentasD -> FieldByName( "IVA" ) -> IsNull ) IVAcompraC -= ( TParcial / 100 ) * Currency( (int)( TbVentasD -> FieldByName( "IVA" ) -> AsInteger ) ); Sender -> AsString = Text; // Localizacion del producto DlgBuscarProd -> TbBusquedas -> Filtered = false; if ( DlgBuscarProd -> TbBusquedas -> Locate( "ID Producto", Text, TLocateOptions() << loCaseInsensitive ) ) { /***********************\ */ TbVentasD->FieldByName( "CodProductoAux" )->AsInteger = DlgBuscarProd -> TbBusquedas -> FieldByName( "ForcedIndex" ) -> AsInteger; TbVentasD->FieldByName( "NombreProducto" )->AsString = DlgBuscarProd -> TbBusquedas -> FieldByName( "Nombre del Producto" ) -> AsString; TbVentasD->FieldByName( "IVA" )->AsCurrency = DlgBuscarProd->TbBusquedas->FieldByName( "I.V.A" )->AsCurrency; /***********************\ */ TbVentasDPrecioC -> AsCurrency = GetPrecioVenta( DlgBuscarProd -> TbBusquedas ); if ( oldCodProducto != TbVentasD->FieldByName( "CodProductoAux" )->AsInteger ) { ActualizaStock( oldCodProducto, +1 * TbVentasD -> FieldByName( "Cantidad" ) -> AsFloat ); ActualizaStock( TbVentasD->FieldByName( "CodProductoAux" )->AsInteger, -1 * TbVentasD -> FieldByName( "Cantidad" ) -> AsFloat ); } } else { Localizado = false; TbVentasD -> FieldByName( "CodProductoAux" ) -> AsInteger = 0; TbVentasD -> FieldByName( "NombreProducto" ) -> AsString = "[##SU PRODUCTO##]"; } if ( TbVentasDCantidad -> AsFloat <= 0 ) TbVentasDCantidad -> AsFloat = 1; ActualizaTotales(); #ifdef EXIST_CFG if ( !CFG->Codigo_y_Unidad->Checked ) { #endif if ( Localizado ) { DBGrid1 -> SelectedField = DBGrid1 -> Fields[0]; TbVentasD -> Next(); if ( TbVentasD -> Eof ) { TbVentasD -> Append(); } } #ifdef EXIST_CFG } #endif } //--------------------------------------------------------------------------- Currency __fastcall TVentas::GetPrecioVenta( TTable *Sender ) { Currency dev; dev = Sender -> FieldByName( "Precio Venta 1" ) -> AsCurrency; return dev; } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDCantidadSetText(TField *Sender, const AnsiString Text) { Currency TParcial; // ## Cambiado 09/08/01 // ActualizaStock( TbVentasDCodProducto -> AsString, ActualizaStock( TbVentasDCodProductoAux -> AsInteger, +1 * TbVentasDCantidad -> AsFloat ); TParcial = TbVentasDPrecioC -> AsCurrency * Currency( (int)( Sender -> AsInteger ) ); TParcial = TParcial * (1 - ( TbVentasD -> FieldByName( "Dto" ) -> AsCurrency / 100 ) ); SUMAcompraC -= TParcial; if ( ! TbVentasD -> FieldByName( "IVA" ) -> IsNull ) IVAcompraC -= ( TParcial / 100 ) * Currency( (int)( TbVentasD -> FieldByName( "IVA" ) -> AsInteger ) ); try { Sender -> AsFloat = Text.ToDouble(); } catch(...) { Sender->AsFloat = 1; } ActualizaTotales(); // ## Cambiado 09/08/01 // ActualizaStock( TbVentasDCodProducto -> AsString, ActualizaStock( TbVentasDCodProductoAux -> AsInteger, -1 * TbVentasDCantidad -> AsFloat ); } //--------------------------------------------------------------------------- void __fastcall TVentas::DBGrid1ColExit(TObject *Sender) { if ( TbVentasD -> State == dsEdit ) try { TbVentasD -> Post(); }catch(...){ // Do nothing } } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDBeforeDelete(TDataSet *DataSet) { // No nos olvidemos de anular todo esto (Y del STOCK) // ## Cambiado 09/08/01 // ActualizaStock( TbVentasD -> FieldByName( "CodProducto" ) -> AsString, ActualizaStock( TbVentasD -> FieldByName( "CodProductoAux" ) -> AsInteger, +1 * TbVentasD -> FieldByName( "Cantidad" ) -> AsFloat ); Currency TParcial; TParcial = TbVentasDPrecioC -> AsCurrency * Currency( ( TbVentasDCantidad -> AsFloat ) ); TParcial = TParcial * (1 - ( TbVentasDDto->AsFloat / 100 ) ); SUMAcompraC -= TParcial; if ( ! TbVentasDIVA->IsNull ) IVAcompraC -= TParcial * ( TbVentasDIVA->AsCurrency / 100 ); ActualizandoTOTALES = true; TbVentasC -> Edit(); TbVentasC -> FieldByName( "TotalSin") -> AsCurrency = SUMAcompraC; TbVentasC -> FieldByName( "TotalIva") -> AsCurrency = IVAcompraC; TbVentasC -> Post(); ActualizandoTOTALES = false; int Number = (int)( ( SUMAcompraC + IVAcompraC ) * 100); DigitNum1 -> Value = Number / 100; DigitNum2 -> Value = Number % 100; StatusBar1->Panels->Items[2]->Text = FormatCurr("###,###,###.#0 €", Number/16638.6 ); } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDNombreProductoSetText(TField *Sender, const AnsiString Text) { if ( ( TbVentasDCodProducto -> AsString ) . IsEmpty() ) { Sender -> AsString = Text; TbVentasD -> FieldByName( "CodProductoAux" ) -> AsInteger = 0; } } //--------------------------------------------------------------------------- // ## Cambiado 09/08/2001 // void __fastcall TVentas::ActualizaStock( AnsiString CodProducto, float Cantidad ) void __fastcall TVentas::ActualizaStock( int CodProducto, float Cantidad ) { TStringList *ListaCombinados; ListaCombinados = new TStringList; DlgBuscarProd -> TbBusquedas -> Filtered = false; // ## Cambiado 09/08/2001 // if ( DlgBuscarProd -> TbBusquedas -> Locate( "ID Producto", CodProducto, TLocateOptions()< 0 ) // ## Cambiado 09/08/2001 // ActualizaStockMultiple( DlgBuscarProd -> TbBusquedas -> FieldByName( "ForcedIndex" ) -> AsInteger, Cantidad, ListaCombinados ); ActualizaStockMultiple( CodProducto, Cantidad, ListaCombinados ); delete ListaCombinados; } //--------------------------------------------------------------------------- void __fastcall TVentas::ActualizaStockMultiple( int CodProducto, float Cantidad, TStringList *ListaCombinados ) { // Localizamos el CodProducto y actualizamos short i; typedef struct AList { int CodProd; float Cantidad; } TAList; typedef TAList* PAList; if ( DlgBuscarProd -> TbBusquedas -> Locate( "ForcedIndex", CodProducto, TLocateOptions()< TbBusquedas -> FieldByName( "COMBINADO" ) -> AsBoolean == false ) { // No es un combinado (Actualizamos directamente) DlgBuscarProd -> TbBusquedas -> Edit(); DlgBuscarProd -> TbBusquedas -> FieldByName( "Stock Actual" ) -> AsInteger += Cantidad; DlgBuscarProd -> TbBusquedas -> Post(); } else { // No hemos pasado por él aun ( Evitar códigos ciclicos ) if ( ListaCombinados -> IndexOf( CodProducto ) == -1 ) { ListaCombinados -> Add( CodProducto ); PAList AStruct; TList *ListaProdC = new TList; // Productos a seguir while ( ! TbProdCircular -> Eof ) { AStruct = new TAList; AStruct->CodProd = TbProdCircular -> FieldByName( "CodProdE" ) -> AsInteger; AStruct->Cantidad = TbProdCircular -> FieldByName( "Cantidad" ) -> AsFloat; ListaProdC->Add(AStruct); TbProdCircular -> Next(); } // Recorremos todos los productos (Circulares) que forman este combinado for ( i = 0; i < ListaProdC -> Count; i++ ) { AStruct = (PAList) ListaProdC->Items[i]; ActualizaStockMultiple( AStruct->CodProd, Cantidad*(AStruct->Cantidad), ListaCombinados ); } delete ListaProdC; } } } } //--------------------------------------------------------------------------- void __fastcall TVentas::BitBtn2Click(TObject *Sender) { #ifdef DEM001 ShowMessage( "Esta función ha sido deshabilitada para esta versión.\nPongase en contacto con el autor, si desea\nel módulo correspondiente: jd@infdj.com" ); #else // Si la factura actual, no tiene asignado ningún producto, ¿PARA QUE CAMBIAR? if ( TbVentasD -> RecordCount == 0 ) { ShowMessage( "Imposible abrir otra sesión,\n existiendo una LIBRE." ); } else { // Creamos una nueva factura NuevaFacturaCliente(); } #endif // Levamos el foco a donde debe... if ( FocoRapido ) QCodigo->SetFocus(); else DBGrid1->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TVentas::bCancelarTicketClick(TObject *Sender) { bool RecorrerAbiertas = true; // Ok! Eliminamos la factura en curso TbVentasC -> Delete(); ////////////////////////////////////////////////////////////////////// if ( RecorrerAbiertas ) { TbVentasAbiertas -> Refresh(); if ( TbVentasAbiertas -> RecordCount > 0 ) { TbVentasAbiertas -> First(); TbVentasC -> GotoCurrent( TbVentasAbiertas ); } else NuevaFacturaCliente(); } else NuevaFacturaCliente(); ////////////////////////////////////////////////////////////////////// // Levamos el foco a donde debe... if ( FocoRapido ) QCodigo->SetFocus(); else DBGrid1->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasCBeforeDelete(TDataSet *DataSet) { // Mostramos la advertencia... (Solo si hay algún registro...) if ( TbVentasD -> RecordCount > 0 ) switch( MessageDlg( "Atención, está apunto de eliminar\el albaran/factura en curso...\n¿Realmente desea continuar?", mtWarning, TMsgDlgButtons() << mbNo << mbYes, 0 ) ) { case mrNo: Abort(); break; default: // Borramos cada uno de los producto que contiene la facura... while ( TbVentasD -> RecordCount > 0 ) { try { TbVentasD -> Delete(); }catch(...){ break; } } TbVentasI -> Edit(); TbVentasI -> FieldByName( "Cancelados" ) -> AsInteger ++; TbVentasI -> Post(); break; }; } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDPrecioCSetText(TField *Sender, const AnsiString Text) { Currency TParcial; if ( TbVentasD->FieldByName("CodProductoAux")->AsInteger != 0 ) { if ( !CFG->CambioPrecioProdExistente->Checked ) return; } TParcial = Sender -> AsCurrency * Currency( ( TbVentasDCantidad -> AsFloat ) ); TParcial = TParcial * (1 - ( TbVentasD -> FieldByName( "Dto" ) -> AsCurrency / 100 ) ); SUMAcompraC -= TParcial; if ( ! TbVentasD -> FieldByName( "IVA" ) -> IsNull ) IVAcompraC -= ( TParcial / 100 ) * Currency( (int)( TbVentasD -> FieldByName( "IVA" ) -> AsInteger ) ); try { Sender->AsString = Text; } catch(...) { Sender->AsCurrency =0; } ActualizaTotales(); } //--------------------------------------------------------------------------- void __fastcall TVentas::DBGrid1KeyPress(TObject *Sender, char &Key) { short int Salto; switch( Key ) { case VK_RETURN: if ( DBGrid1 -> EditorMode ) { Key = 0; if ( DBGrid1 -> SelectedIndex >= 5 )//Fields[DBGrid1 -> SelectedIndex + 2] == NULL ) { DBGrid1 -> SelectedField = DBGrid1 -> Fields[0]; TbVentasD -> Next(); if ( TbVentasD -> Eof ) { TbVentasD -> Append(); } } else { Salto = 1; switch ( DBGrid1 -> SelectedIndex ) { case 0: if ( ! TbVentasDCodProducto -> AsString . IsEmpty() ) Salto = 5; break; case 1: Salto = 2; break; } DBGrid1 -> SelectedIndex += Salto; } } break; case '.': Key = ','; break; case '+': // Fichamos el ticket actual --> si el REGISTRO ACTUAL esta vacio if ( DBGrid1->SelectedField == DBGrid1 -> Fields[0] && DBGrid1->Fields[0]-> AsString . IsEmpty() ) { Key = 0; bFicharTicketClick(0); } break; } } //--------------------------------------------------------------------------- void __fastcall TVentas::DBGrid4DblClick(TObject *Sender) { // Sincronizamos la base de datos principal... TbVentasC -> GotoCurrent( TbVentasAbiertas ); // Mostramos la solapa inicial PageControl1 -> ActivePage = TabSheet1; } //--------------------------------------------------------------------------- void __fastcall TVentas::DsVentasCDataChange(TObject *Sender, TField *Field) { // Actualizamos los totales... /* Currency TParcial; SUMAcompraC = 0; IVAcompraC = 0; TbVentasD -> DisableControls(); TbVentasD -> First(); do { TParcial = TbVentasDPrecioC -> AsCurrency * TbVentasDCantidad -> AsFloat; TParcial = TParcial * (1 - ( TbVentasD -> FieldByName( "Dto" ) -> AsCurrency / 100 ) ); SUMAcompraC += TParcial; if ( ! TbVentasD -> FieldByName( "IVA" ) -> IsNull ) IVAcompraC += TParcial * ( 1 + (TbVentasD -> FieldByName( "IVA" ) -> AsCurrency / 100) ); try { TbVentasD -> Next(); } catch(...) { // nothing break; } }while( ! TbVentasD -> Eof ); TbVentasD -> EnableControls(); if ( TbVentasC -> FieldByName( "TotalSin") -> AsCurrency != SUMAcompraC || TbVentasC -> FieldByName( "TotalIva") -> AsCurrency != IVAcompraC ) ShowMessage( "ERROR LOS TOTALES SON DISCORDANTES\n\t" + TbVentasC -> FieldByName( "TotalSin") -> AsString + "\n\t" + TbVentasC -> FieldByName( "TotalIva") -> AsString ); */ if ( !ActualizandoTOTALES ) { cbFormaPago->ItemIndex = TbVentasC->FieldByName( "FormaPago" )->AsInteger; SUMAcompraC = TbVentasC -> FieldByName( "TotalSin") -> AsCurrency; IVAcompraC = TbVentasC -> FieldByName( "TotalIva") -> AsCurrency; } int Number = (int)( ( SUMAcompraC + IVAcompraC ) * 100); DigitNum1 -> Value = Number / 100; DigitNum2 -> Value = Number % 100; StatusBar1->Panels->Items[2]->Text = FormatCurr("###,###,###.#0 €", Number/16638.6 ); } //--------------------------------------------------------------------------- void __fastcall TVentas::DBGrid1DrawColumnCell(TObject *Sender, const TRect &Rect, int DataCol, TColumn *Column, TGridDrawState State) { if ( ! State.Contains(gdSelected) ) { if ( TbVentasDCantidad -> AsFloat < 0 ) { DBGrid1->Canvas->Font->Color = clGreen; DBGrid1->DefaultDrawColumnCell( Rect, DataCol, Column, State ); } } } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDNewRecord(TDataSet *DataSet) { // Por defecto una unidad... // TbVentasDCantidad -> AsInteger = 1; } //--------------------------------------------------------------------------- void __fastcall TVentas::DBGrid4CellClick(TColumn *Column) { // Sincronizamos la base de datos principal... TbVentasC -> GotoCurrent( TbVentasAbiertas ); } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasIBeforeOpen(TDataSet *DataSet) { #ifdef TB_DISCONTINUAS AnsiString FileEmp; FileEmp = TbVentasI -> TableName; if ( access( FileEmp.c_str(), 0 ) != 0 ) { // Establecemos la ruta TbVentasI -> DatabaseName = "TpvWin"; // Facilitamos el nombre de la nueva tabla y su tipo TbVentasI -> TableType = ttParadox; // Usamos la propiedad FielDefs para definir // las columnas que contendrá la tabla TbVentasI -> FieldDefs -> Clear(); TbVentasI -> FieldDefs -> Add("FechaCaja", ftDate, 0, false ); TbVentasI -> FieldDefs -> Add("Inicio", ftTime, 0, false ); TbVentasI -> FieldDefs -> Add("Fin", ftTime, 0, false ); TbVentasI -> FieldDefs -> Add("IntentosSalir", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("ExitoSalir", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Tickets", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Cancelados", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Cambios", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x1", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x1", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x5", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x5", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x10", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x10", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x25", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x25", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x50", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x50", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x100", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x100", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x200", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x200", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x500", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x500", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x1000", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x1000", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x2000", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x2000", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x5000", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x5000", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad x10000", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total x10000", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Cantidad xvarios", ftSmallint, 0, false ); TbVentasI -> FieldDefs -> Add("Total xvarios", ftInteger, 0, false ); TbVentasI -> FieldDefs -> Add("Notas", ftMemo, 0, false ); TbVentasI -> IndexDefs-> Clear(); TbVentasI->IndexDefs->Add("Primary", "FechaCaja", TIndexOptions() << ixPrimary << ixUnique ); // Creamos la base... TbVentasI -> CreateTable(); } #endif } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasCAfterOpen(TDataSet *DataSet) { // Localizamos el dia actual. StatusBar1->Panels->Items[1]->Text = "Localizando registro de caja..."; if ( ! ( TbVentasI -> Locate( "FechaCaja", TDateTime::CurrentDate(), TLocateOptions()<Panels->Items[1]->Text = "Inicilizando dia actual..."; // Inicializamos el dia TbVentasI -> InsertRecord( OPENARRAY( TVarRec, ( // FechaCaja (Variant)TDateTime::CurrentDate(), // Inicio (Variant)TDateTime::CurrentTime() ) ) ); } StatusBar1->Panels->Items[1]->Text = ""; } //--------------------------------------------------------------------------- void __fastcall TVentas::PideTicketClick(TObject *Sender) { #ifdef DEM001 static bool visto = true; if ( !visto ) ShowMessage( "Esta función ha sido deshabilitada para esta versión.\nPongase en contacto con el autor, si desea\nel módulo correspondiente: Jose-David.Guillen@cs.us.es" ); visto = false; #else // Imprimir (SI/NO) try { ImprimirTicket = !ImprimirTicket; if ( ImprimirTicket ) PideTicket -> Picture -> LoadFromFile( "systm\\On.bmp" ); else PideTicket -> Picture -> LoadFromFile( "systm\\Off.bmp" ); } catch(...) { PideTicket -> Picture -> LoadFromFile( "systm\\imerro.bmp" ); } #endif } //--------------------------------------------------------------------------- void __fastcall TVentas::LoadMoldeClick(TObject *Sender) { #ifdef DEM001 ShowMessage( "Esta función ha sido deshabilitada para esta versión.\nPongase en contacto con el autor, si desea\nel módulo correspondiente: Jose-David.Guillen@cs.us.es" ); #else /*nothing*/ #endif } //--------------------------------------------------------------------------- void __fastcall TVentas::SalvarMolde1Click(TObject *Sender) { #ifdef DEM001 ShowMessage( "Esta función ha sido deshabilitada para esta versión.\nPongase en contacto con el autor, si desea\nel módulo correspondiente: Jose-David.Guillen@cs.us.es" ); #else /*nothing*/ #endif } //--------------------------------------------------------------------------- void __fastcall TVentas::EliminarX1Click(TObject *Sender) { #ifdef DEM001 ShowMessage( "Esta función ha sido deshabilitada para esta versión.\nPongase en contacto con el autor, si desea\nel módulo correspondiente: Jose-David.Guillen@cs.us.es" ); #else /*nothing*/ #endif } //--------------------------------------------------------------------------- void __fastcall TVentas::dbgFraccionDrawColumnCell(TObject *Sender, const TRect &Rect, int DataCol, TColumn *Column, TGridDrawState State) { if ( Column -> ID == 0 ) { if ( TbCartera->FieldByName("Pagado")->AsBoolean ) { dbgFraccion->Canvas->StretchDraw( Rect, BtmOK ); } else { dbgFraccion->Canvas->Brush->Color = clWindow; dbgFraccion->Canvas->FillRect( Rect ); } } } //--------------------------------------------------------------------------- void __fastcall TVentas::ComboBoxChange(TObject *Sender) { /* // Debemos cambiar todo lo fraccionado if ( cbFormaPago->Items->Strings[cbFormaPago->ItemIndex] == "Contado" ) { if ( Application->MessageBox("¿Eliminar todo el fraccionamiento de pagos?", "Alerta contable", MB_OKCANCEL ) != IDCANCEL ) { while( !TbCartera->Eof ) // Eliminamos los pagos actuales TbCartera->Delete(); dbgFraccion->Enabled = false; Edit1->Enabled=false; Edit2->Enabled=false; TbVentasC->Edit(); TbVentasC->FieldByName("UltimoPago")->AsDateTime = TDateTime::CurrentDate(); TbVentasC->Post(); } else { cbFormaPago->ItemIndex = TbCartera->FieldByName("FormaPago")->AsInteger; } } else { dbgFraccion->Enabled = true; Edit1->Enabled=true; Edit2->Enabled=true; TbCartera->First(); while( !TbCartera->Eof ) { TbCartera->Edit(); TbCartera->FieldByName("FormaPago")->AsInteger = cbFormaPago->ItemIndex; TbCartera->Post(); TbCartera->Next(); } } */ ActualizandoTOTALES = true; TbVentasC->Edit(); TbVentasC->FieldByName("FormaPago")->AsInteger = cbFormaPago->ItemIndex; TbVentasC->Post(); ActualizandoTOTALES = false; } //--------------------------------------------------------------------------- void __fastcall TVentas::Edit2Change(TObject *Sender) { bool pag; short int i; int npagos; Currency Total = SUMAcompraC + IVAcompraC; if ( Edit2->Text . IsEmpty() ) return; try { npagos = Edit2->Text.ToInt(); } catch(...) { ShowMessage( "El número de veces a fraccionar el pago, no es correcto" ); return; } if ( npagos < 2 ) { ShowMessage( "El número de veces a fraccionar el pago, no es correcto" ); return; } pag = false; // Eliminamos todos los pagos acumulados (SOLO SI NO HAY NINGUN PAGO REALIZADO) TbCartera->First(); while( !TbCartera->Eof ) if ( TbCartera->FieldByName("Pagado")->AsBoolean == true ) { pag = true; break; } if ( pag ) { while( !TbCartera->Eof ) // Eliminamos los pagos actuales TbCartera->Delete(); unsigned short year; Total /= npagos; TDateTime::CurrentDate().DecodeDate( &year, NULL, NULL); // desde 1 para que inc. los meses for ( i = 1; i <= npagos; i++ ) TbCartera->InsertRecord( ARRAYOFCONST( ( TbVentasC->FieldByName("EnlaceFactura")->AsInteger, Variant( EncodeDate( year, i, 1 ) ), Total, 0, cbFormaPago->ItemIndex, false ) ) ); } } //--------------------------------------------------------------------------- void __fastcall TVentas::Edit1Change(TObject *Sender) { bool pag; short int i; int npagos; int tpagos; Currency Total = SUMAcompraC + IVAcompraC; if ( Edit1->Text . IsEmpty() ) return; try { tpagos = Edit1->Text.ToInt(); } catch(...) { ShowMessage( "La cantidad para fraccionar el pago, no es correcta" ); return; } if ( tpagos < 2000 ) { ShowMessage( "La cantidad para fraccionar el pago, no es correcta" ); return; } pag = false; // Eliminamos todos los pagos acumulados (SOLO SI NO HAY NINGUN PAGO REALIZADO) TbCartera->First(); while( !TbCartera->Eof ) if ( TbCartera->FieldByName("Pagado")->AsBoolean == true ) { pag = true; break; } else { TbCartera->Next(); } if ( pag ) { while( !TbCartera->Eof ) // Eliminamos los pagos actuales TbCartera->Delete(); unsigned short year; npagos = Total / tpagos; Total = tpagos; TDateTime::CurrentDate().DecodeDate(&year, NULL, NULL); // desde 1 para que inc. los meses for ( i = 1; i <= npagos; i++ ) TbCartera->InsertRecord( ARRAYOFCONST( ( TbVentasC->FieldByName("EnlaceFactura")->AsInteger, Variant( EncodeDate( year, i, 1 ) ), Total, 0, cbFormaPago->ItemIndex, false ) ) ); } } //--------------------------------------------------------------------------- void __fastcall TVentas::DsCarteraDataChange(TObject *Sender, TField *Field) { Edit2->Text = ""; Edit1->Text = ""; } //--------------------------------------------------------------------------- void __fastcall TVentas::TbCarteraFechaChange(TField *Sender) { if ( (int)Sender->AsDateTime > (int)TbVentasC->FieldByName("UltimoPago")->AsDateTime ) { TbVentasC->Edit(); TbVentasC->FieldByName("UltimoPago")->AsDateTime = Sender->AsDateTime; TbVentasC->Post(); } } //--------------------------------------------------------------------------- void __fastcall TVentas::TbCarteraImporteSetText(TField *Sender, const AnsiString Text) { TbVentasC->Edit(); TbVentasC->FieldByName("TotalFrac")->AsCurrency -= Sender->AsCurrency * ( 0.01 * TbCartera->FieldByName("Incremento")->AsCurrency ); TbVentasC->FieldByName("TotalFrac")->AsCurrency += Currency( Text ) * ( 0.01 * TbCartera->FieldByName("Incremento")->AsCurrency ); TbVentasC->Post(); Sender->AsString = Text; } //--------------------------------------------------------------------------- void __fastcall TVentas::TbCarteraBeforeDelete(TDataSet *DataSet) { if ( TbCartera->FieldByName("Pagado")->AsBoolean == true ) { ShowMessage( "No se pueden eliminar, fraccionamientos que ya han sido efectuados." ); Abort(); } TbVentasC->Edit(); TbVentasC->FieldByName("TotalFrac")->AsCurrency -= TbCartera->FieldByName("Importe")->AsCurrency * ( 0.01 * TbCartera->FieldByName("Incremento")->AsCurrency ); TbVentasC->Post(); } //--------------------------------------------------------------------------- void __fastcall TVentas::TbCarteraBeforeInsert(TDataSet *DataSet) { if ( !( TbVentasC -> RecNo > 0 && TbVentasC -> RecordCount > 0 ) && !( TbVentasD -> RecNo > 0 && TbVentasD -> RecordCount > 0 ) ) { MessageDlg("¿ No cree que debería crear,\no seleccionar una factura CON DATOS,\nantes de intentar fracionar su pago?.", mtWarning, TMsgDlgButtons() << mbOK, 0); Abort(); } } //--------------------------------------------------------------------------- void __fastcall TVentas::TbCarteraCalcFields(TDataSet *DataSet) { TbCartera->FieldByName("Total")->AsCurrency = TbCartera->FieldByName("Importe")->AsCurrency * ( 0.01 * TbCartera->FieldByName("Incremento")->AsCurrency ); } //--------------------------------------------------------------------------- void __fastcall TVentas::TbCarteraNewRecord(TDataSet *DataSet) { TbCartera->FieldByName("Fecha")->AsDateTime = TDateTime::CurrentDate(); TbCartera->FieldByName("FormaPago")->AsInteger = cbFormaPago->ItemIndex; } //--------------------------------------------------------------------------- void __fastcall TVentas::TbCarteraIncrementoSetText(TField *Sender, const AnsiString Text) { TbVentasC->Edit(); TbVentasC->FieldByName("TotalFrac")->AsCurrency -= TbCartera->FieldByName("Importe")->AsCurrency * ( 0.01 * Sender->AsCurrency ); TbVentasC->FieldByName("TotalFrac")->AsCurrency += TbCartera->FieldByName("Importe")->AsCurrency * ( 0.01 * Currency( Text ) ); TbVentasC->Post(); Sender->AsString = Text; } //--------------------------------------------------------------------------- void __fastcall TVentas::SpeedButton3Click(TObject *Sender) { #ifdef DEM001 ShowMessage( "Esta función ha sido deshabilitada para esta versión.\nPongase en contacto con el autor, si desea\nel módulo correspondiente: Jose-David.Guillen@cs.us.es" ); #else // Mostramos el dialogo, buscar [Productos] TDlgBuscar *DlgBuscarFactAlb; DlgBuscarFactAlb = new TDlgBuscar(this); DlgBuscarFactAlb -> TbBusquedas -> TableName = "Ventas (cabecera)"; DlgBuscarFactAlb -> Filter = "[FacturaAbierta] = '0' AND [FechaFactura] = '" + TDateTime::CurrentDate() +"'"; DlgBuscarFactAlb -> TbBusquedas -> Active = true; DlgBuscarFactAlb -> ShowModal(); if ( DlgBuscarFactAlb -> ModalResult == mrOk ) { if ( MessageDlg( "Albarán nº: " + DlgBuscarFactAlb->TbBusquedas->FieldByName("EnlaceFactura")->AsString + "\nFactura asociada: " + DlgBuscarFactAlb->TbBusquedas->FieldByName("CodFactura")->AsString + "\n ¿ Eliminar ?", mtConfirmation, TMsgDlgButtons() << mbNo << mbYes, 0 ) == mrYes ) { if ( DlgBuscarFactAlb->TbBusquedas->FieldByName("CodFactura")->AsInteger <= 0 ) { TBookmark SavePlace; SavePlace = TbVentasC->GetBookmark(); TbVentasC->GotoCurrent( DlgBuscar->TbBusquedas ); TbVentasC->Delete(); TbVentasC->GotoBookmark(SavePlace); TbVentasC->FreeBookmark(SavePlace); } else { // Realizamos otra factura con importe negativo // ################ PENDIENTE ShowMessage( " Función no disponible\n1º Realizar copia factura (abono)\\n2º Ingresar los articulos en stock"); } } } #endif } //--------------------------------------------------------------------------- void __fastcall TVentas::SpeedButton11Click(TObject *Sender) { #ifdef DEM001 ShowMessage( "Esta función ha sido deshabilitada para esta versión.\nPongase en contacto con el autor, si desea\nel módulo correspondiente: Jose-David.Guillen@cs.us.es" ); #else bool iEsAlbaran = EsAlbaran; TDlgBuscar *DlgBuscarFactAlb; TTable *TbDATOS; if ( Sender != 0 ) { DlgBuscarFactAlb = new TDlgBuscar(this); DlgBuscarFactAlb -> TbBusquedas -> TableName = TbVentasC -> TableName; DlgBuscarFactAlb -> Filter = "[FechaFactura] = '" + TDateTime::CurrentDate() +"'"; DlgBuscarFactAlb -> TbBusquedas -> Active = true; DlgBuscarFactAlb->ShowModal(); if ( DlgBuscarFactAlb -> ModalResult == mrOk ) { if ( MessageDlg( "Albarán nº: " + DlgBuscarFactAlb->TbBusquedas->FieldByName("EnlaceFactura")->AsString + "\nFactura asociada: " + DlgBuscarFactAlb->TbBusquedas->FieldByName("CodFactura")->AsString + "\n ¿ Volver a Imprimir ?", mtConfirmation, TMsgDlgButtons() << mbNo << mbYes, 0 ) == mrYes ) { iEsAlbaran = DlgBuscarFactAlb->TbBusquedas->FieldByName("CodFactura")->AsInteger <= 0; TbDATOS = DlgBuscarFactAlb->TbBusquedas; } else return; } else { delete DlgBuscarFactAlb; return; } } else TbDATOS = TbVentasC; if ( iEsAlbaran ) { // Imprime Ticket TQRMDFacturaVnt1 *QRMDFacturaVnt; // Creamos una ficha del tipo TProductos // Guardando la referencia en la variable TProductos QRMDFacturaVnt = new TQRMDFacturaVnt1(this); // Mostrarla como modal y según el valor devuelto QRMDFacturaVnt -> TbVntCabecera -> GotoCurrent( TbDATOS ); QRMDFacturaVnt -> Print(); /* #ifdef DEBUG QRMDFacturaVnt -> Preview(); #else QRMDFacturaVnt -> Print(); #endif */ // Destruimos la ficha delete QRMDFacturaVnt; } else { // Imprime factura TQRMDFacturaVnt *QRMDFacturaVnt; // Creamos una ficha del tipo TProductos // Guardando la referencia en la variable TProductos QRMDFacturaVnt = new TQRMDFacturaVnt(this); // Mostrarla como modal y según el valor devuelto QRMDFacturaVnt -> TbVntCabecera -> GotoCurrent( TbDATOS ); QRMDFacturaVnt -> Print(); /* #ifdef DEBUG QRMDFacturaVnt -> Preview(); #else QRMDFacturaVnt -> Print(); #endif */ // Destruimos la ficha delete QRMDFacturaVnt; } if ( Sender != 0 ) delete DlgBuscarFactAlb; #endif } //--------------------------------------------------------------------------- void __fastcall TVentas::TbVentasDDtoSetText(TField *Sender, const AnsiString Text) { Currency TParcial; if ( Text.ToInt() > 15 ) { ShowMessage( "Uff!, el descuento es demasiado grande.\nNosotros trabajamos con porcentajes demasiado pequeños\nIMPOSIBLE aplicar ese descuento..." ); } else { TParcial = ( TbVentasDPrecioC -> AsCurrency * Currency( ( TbVentasDCantidad -> AsFloat ) ) ); TParcial = TParcial * (1 - ( Sender->AsCurrency / 100 ) ); SUMAcompraC -= TParcial; if ( ! TbVentasD -> FieldByName( "IVA" ) -> IsNull ) IVAcompraC -= ( TParcial / 100 ) * Currency( (int)( TbVentasD -> FieldByName( "IVA" ) -> AsInteger ) ); Sender -> AsString = Text; ActualizaTotales(); } } //--------------------------------------------------------------------------- void __fastcall TVentas::ActualizaTotales(void) { Currency TParcial; int Number; try { TParcial = TbVentasDPrecioC -> AsCurrency * Currency( ( TbVentasDCantidad -> AsFloat ) ); TParcial = TParcial * (1 - ( TbVentasDDto->AsFloat / 100 ) ); SUMAcompraC += TParcial; if ( ! TbVentasDIVA->IsNull ) IVAcompraC += TParcial * ( TbVentasDIVA->AsCurrency / 100 ); // Number = (int)( ( SUMAcompraC + IVAcompraC ) * 100 ); ActualizandoTOTALES = true; TbVentasC -> Edit(); TbVentasC -> FieldByName( "TotalSin") -> AsCurrency = SUMAcompraC; TbVentasC -> FieldByName( "TotalIva") -> AsCurrency = IVAcompraC; TbVentasC -> Post(); ActualizandoTOTALES = false; } catch(...) { // nothing ActualizandoTOTALES = false; } // DigitNum1 -> Value = Number / 100; // DigitNum2 -> Value = Number % 100; } //--------------------------------------------------------------------------- void __fastcall TVentas::QPrecioChange(TObject *Sender) { try { if ( !QUnds->Text.IsEmpty() && !QPrecio->Text.IsEmpty() && !QDto->Text.IsEmpty() ) QSubtotal->Text = QUnds->Text.ToDouble() * QPrecio->Text.ToDouble() * (1 - ( QDto->Text.ToInt() / 100 ) ); } catch(...) { QSubtotal->Text = ""; QPrecio->Text = ""; } } //--------------------------------------------------------------------------- void __fastcall TVentas::QUndsChange(TObject *Sender) { try { if ( !QUnds->Text.IsEmpty() && !QPrecio->Text.IsEmpty() && !QDto->Text.IsEmpty() ) QSubtotal->Text = QUnds->Text.ToDouble() * QPrecio->Text.ToDouble() * (1 - ( QDto->Text.ToInt() / 100 ) ); } catch(...) { QUnds->Text = "1"; QSubtotal->Text = QPrecio->Text.ToDouble() * (1 - ( QDto->Text.ToInt() / 100 ) ); } } //--------------------------------------------------------------------------- void __fastcall TVentas::QDtoChange(TObject *Sender) { if ( !QUnds->Text.IsEmpty() && !QPrecio->Text.IsEmpty() && !QDto->Text.IsEmpty() ) QSubtotal->Text = QUnds->Text.ToDouble() * QPrecio->Text.ToDouble() * (1 - ( QDto->Text.ToInt() / 100 ) ); } //--------------------------------------------------------------------------- void __fastcall TVentas::QNProductoChange(TObject *Sender) { DlgBuscarProd -> TbBusquedas -> Filtered = false; DlgBuscarProd -> TbBusquedas -> IndexName = "NombreProd"; if ( DlgBuscarProd -> TbBusquedas -> Locate( "Nombre Del Producto", QNProducto->Text, TLocateOptions() << loPartialKey << loCaseInsensitive ) ) { QRellenaDatos(QNProducto->Text.Length()); } else { StatusBar1->Panels->Items[3]->Text = ""; StatusBar1->Panels->Items[1]->Text = ""; QCodAux = 0; QPrecio->Text="0"; QDto->Text="0"; QUnds->Text="1"; QSubtotal->Text="0"; QCodigo->Text=""; } } //--------------------------------------------------------------------------- void __fastcall TVentas::QRellenaDatos(int start) { QNProducto->Text = DlgBuscarProd->TbBusquedas->FieldByName("Nombre Del Producto")->AsString; if ( start == -1 ) { QNProducto->SelStart = QNProducto->Text.Length(); QNProducto->SelLength = 0; }else{ QNProducto->SelStart = start; QNProducto->SelLength = QNProducto->Text.Length() - QNProducto->SelStart; } QCodAux = DlgBuscarProd -> TbBusquedas -> FieldByName( "ForcedIndex" ) -> AsInteger; QCodigo->Text = DlgBuscarProd-> TbBusquedas->FieldByName( "ID Producto" )->AsString; QIva->Text = DlgBuscarProd-> TbBusquedas->FieldByName( "I.V.A" )->AsString; try { if ( QUnds->Text.IsEmpty() || QUnds->Text.ToDouble() <= 0 ) QUnds->Text="1"; }catch(...){QUnds->Text="1";} QDto->Text = "0"; QPrecio->Text = AnsiString( GetPrecioVenta( DlgBuscarProd -> TbBusquedas ) ); int Stock = DlgBuscarProd->TbBusquedas->FieldByName( "Stock Actual")->AsInteger; StatusBar1->Panels->Items[3]->Text = (Stock <= 0) ? AnsiString("-No disponibles-") : AnsiString(Stock); StatusBar1->Panels->Items[1]->Text = DlgBuscarProd->TbBusquedas->FieldByName( "Localizacion")->AsString; } //--------------------------------------------------------------------------- void __fastcall TVentas::QNProductoKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if ( Key == VK_DOWN ) { if ( !DlgBuscarProd->TbBusquedas->Eof ) { DlgBuscarProd->TbBusquedas->Next(); QRellenaDatos(-1); } } if ( Key == VK_UP ) { if ( !DlgBuscarProd->TbBusquedas->Bof ) { DlgBuscarProd->TbBusquedas->Prior(); QRellenaDatos(-1); } } } //--------------------------------------------------------------------------- void __fastcall TVentas::QNProductoKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { if ( Key == VK_BACK ) { QNProducto->SelStart --; QNProducto->SelLength = QNProducto->Text.Length() - QNProducto->SelStart; Key = 0; } if ( Key == VK_RETURN ) { if ( QPrecio->Text.IsEmpty() || ( QPrecio->Text.ToDouble() ) <= 0 ) QPrecio->SetFocus(); else QUnds->SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TVentas::ClearQuickControl(void) { // Volver a pedir datos... QCodAux = 0; QNProducto->Text = ""; QPrecio->Text="0"; QDto->Text="0"; QUnds->Text="1"; QSubtotal->Text="0"; QCodigo->Text=""; StatusBar1->Panels->Items[3]->Text = ""; StatusBar1->Panels->Items[1]->Text = ""; } //--------------------------------------------------------------------------- void __fastcall TVentas::QUndsEnter(TObject *Sender) { QUnds->Color = clMenu; } //--------------------------------------------------------------------------- void __fastcall TVentas::QUndsExit(TObject *Sender) { QUnds->Color = clWindow; } //--------------------------------------------------------------------------- void __fastcall TVentas::DBGrid1Enter(TObject *Sender) { // Limpiamos el QuickControl ClearQuickControl(); FocoRapido = false; } //--------------------------------------------------------------------------- void __fastcall TVentas::QCodigoEnter(TObject *Sender) { FocoRapido = true; QCodigo->Color = clQREADY; QCodigo->SelStart = 0; QCodigo->SelLength = QCodigo->Text.Length(); } //--------------------------------------------------------------------------- /* ShowMessage( TbVentasD->FieldByName("CodProducto")->AsString + " -#- " + TbVentasD->FieldByName("NombreProducto")->AsString + " -#- " + TbVentasD->FieldByName("Cantidad")->AsString + " -#- " + " BeforeEdit" ); */ void __fastcall TVentas::QCodigoExit(TObject *Sender) { QCodigo->Color = clWindow; } //--------------------------------------------------------------------------- void __fastcall TVentas::QCodigoKeyPress(TObject *Sender, char &Key) { if ( Key == VK_RETURN ) { if ( DlgBuscarProd -> TbBusquedas -> Locate( "ID Producto", QCodigo->Text, TLocateOptions() << loCaseInsensitive ) ) { QRellenaDatos(-1); QUnds->SetFocus(); } else { StatusBar1->Panels->Items[3]->Text = ""; StatusBar1->Panels->Items[1]->Text = ""; } QCodigo->Color = clWindow; } if ( QCodigo->Text.IsEmpty() && Key=='+' ) { Key = 0; bFicharTicketClick(0); QCodigo->Color = clQREADY; } } //--------------------------------------------------------------------------- void __fastcall TVentas::QPrecioKeyPress(TObject *Sender, char &Key) { if ( Key == VK_RETURN ) QUnds->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TVentas::QUndsKeyPress(TObject *Sender, char &Key) { if ( Key == VK_RETURN && DlgBuscarProd -> TbBusquedas -> Locate( "ID Producto", QCodigo->Text, TLocateOptions() << loCaseInsensitive ) ) { // Añadir el producto a la lista... try { if ( QPrecio->Text.IsEmpty() || QPrecio->Text.ToDouble() < 0 ) return; if ( QUnds->Text.IsEmpty() || QUnds->Text.ToDouble() < 1 ) QUnds->Text = "1"; if ( QDto->Text.IsEmpty() || QDto->Text.ToDouble() < 0 ) QDto->Text = "0"; if ( QIva->Text.IsEmpty() || QIva->Text.ToDouble() < 0 ) QIva->Text = "0"; } catch(...) { return; } TbVentasD->Insert(); TbVentasD->FieldByName( "CodProductoAux" )->AsInteger = QCodAux; TbVentasD->FieldByName( "CodProducto" )->AsString = QCodigo->Text; TbVentasD->FieldByName( "NombreProducto" )->AsString = QNProducto->Text; TbVentasD->FieldByName( "Cantidad" )->AsFloat = QUnds->Text.ToDouble(); TbVentasD->FieldByName( "Dto" )->AsCurrency = QDto->Text.ToDouble(); TbVentasD->FieldByName( "IVA" )->AsInteger = QIva->Text.ToInt(); TbVentasD->FieldByName( "PrecioC" )->AsCurrency = QPrecio->Text.ToDouble(); TbVentasD->Post(); ActualizaTotales(); // ## Cambiado 09/08/01 // ActualizaStock( TbVentasD -> FieldByName( "CodProducto" ) -> AsString, ActualizaStock( QCodAux, -1 * QUnds->Text.ToDouble() ); ClearQuickControl(); QCodigo->SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TVentas::QCodigoClick(TObject *Sender) { QCodigo->Text=""; } //--------------------------------------------------------------------------- void __fastcall TVentas::QIvaKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if ( Key == VK_RETURN ) QPrecio->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TVentas::ElasticForm1AfterResize(TObject *Sender) { DBGrid1->Font->Size = DBText6->Font->Size; DBGrid1->TitleFont->Size = DBText6->Font->Size; } //--------------------------------------------------------------------------- void __fastcall TVentas::QUndsClick(TObject *Sender) { QUnds->Text=""; } //--------------------------------------------------------------------------- void __fastcall TVentas::QPrecioEnter(TObject *Sender) { if ( QCodAux != 0 ) QPrecio->Enabled = CFG->CambioPrecioProdExistente->Checked; } //--------------------------------------------------------------------------- void __fastcall TVentas::QPrecioExit(TObject *Sender) { QPrecio->Enabled = true; } //---------------------------------------------------------------------------