first commit (2002-04-24)
This commit is contained in:
617
cap_gestion/capg_abonados.cpp
Normal file
617
cap_gestion/capg_abonados.cpp
Normal file
@ -0,0 +1,617 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <vcl.h>
|
||||
#pragma hdrstop
|
||||
#include <inifiles.hpp>
|
||||
|
||||
#include "capg_abonados.h"
|
||||
#include "crd_ctrl.h"
|
||||
#include "capg_qrLabonados.h"
|
||||
//---------------------------------------------------------------------------
|
||||
#pragma package(smart_init)
|
||||
#pragma resource "*.dfm"
|
||||
TForm1 *Form1;
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TForm1::TForm1(TComponent* Owner)
|
||||
: TForm(Owner)
|
||||
{
|
||||
isSettingData = false;
|
||||
PageControl1->ActivePage = TabSheet1;
|
||||
PageControl2->ActivePage = TabSheet3;
|
||||
|
||||
TbTAbonados->Active = true;
|
||||
TbAbonados->Active = true;
|
||||
|
||||
TbVehiculos->Active = true;
|
||||
TbCards->Active = true;
|
||||
TbFacturas->Active = true;
|
||||
SelIndex->ItemIndex = 0;
|
||||
|
||||
TIniFile *ini;
|
||||
ini = new TIniFile( ExtractFileDir( Application->ExeName ) + "\\CAP.INI" );
|
||||
// Cargamos los importes del periodo (Mes/biM/triM/Anual)
|
||||
ImportesPeriodo[0] = ini->ReadFloat( "CAP_g", "ImporteMensual", 0.0 );
|
||||
ImportesPeriodo[1] = ini->ReadFloat( "CAP_g", "ImporteBimestral", 0.0 );
|
||||
ImportesPeriodo[2] = ini->ReadFloat( "CAP_g", "ImporteTrimestral", 0.0 );
|
||||
ImportesPeriodo[3] = ini->ReadFloat( "CAP_g", "ImporteAnual", 0.0 );
|
||||
|
||||
cfgPWD = ini->ReadString( "CAP_g", "cfgPWD", "default" );
|
||||
delete ini;
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::TbAbonadosBeforeOpen(TDataSet *DataSet)
|
||||
{
|
||||
if ( !FileExists( TbAbonados -> TableName ) )
|
||||
{
|
||||
// Usamos la propiedad FielDefs para definir
|
||||
// las columnas que contendr<64> la tabla
|
||||
TbAbonados -> FieldDefs -> Clear();
|
||||
|
||||
/********************\
|
||||
|* Datos B<>sicos *|
|
||||
\********************/
|
||||
TbAbonados -> FieldDefs -> Add("ida", ftAutoInc, 0, false );
|
||||
TbAbonados -> FieldDefs -> Add("dni", ftString, 20, false );
|
||||
TbAbonados -> FieldDefs -> Add("nombre", ftString, 20, false );
|
||||
TbAbonados -> FieldDefs -> Add("apellidos", ftString, 40, false );
|
||||
|
||||
TbAbonados -> FieldDefs -> Add("direccion", ftString, 40, false );
|
||||
TbAbonados -> FieldDefs -> Add("localidad", ftString, 20, false );
|
||||
TbAbonados -> FieldDefs -> Add("provincia", ftString, 20, false );
|
||||
TbAbonados -> FieldDefs -> Add("cp", ftInteger, 0, false );
|
||||
|
||||
TbAbonados -> FieldDefs -> Add("telefono1", ftString, 20, false );
|
||||
TbAbonados -> FieldDefs -> Add("telefono2", ftString, 20, false );
|
||||
|
||||
TbAbonados -> FieldDefs -> Add("tipoa", ftInteger, 0, false );
|
||||
TbAbonados -> FieldDefs -> Add("estado", ftInteger, 0, false );
|
||||
|
||||
TbAbonados -> FieldDefs -> Add("vip", ftBoolean, 0, false );
|
||||
TbAbonados -> FieldDefs -> Add("dentro", ftBoolean, 0, false );
|
||||
|
||||
TbAbonados -> FieldDefs -> Add("falta", ftDate, 0, false );
|
||||
TbAbonados -> FieldDefs -> Add("fperiodo", ftInteger, 0, false );
|
||||
|
||||
TbAbonados -> IndexDefs-> Clear();
|
||||
|
||||
TbAbonados->IndexDefs->Add("Primary", "ida", TIndexOptions() << ixPrimary << ixUnique);
|
||||
|
||||
// Creamos la base...
|
||||
TbAbonados -> CreateTable();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::TbVehiculosBeforeOpen(TDataSet *DataSet)
|
||||
{
|
||||
if ( !FileExists( TbVehiculos -> TableName ) )
|
||||
{
|
||||
// Usamos la propiedad FielDefs para definir
|
||||
// las columnas que contendr<64> la tabla
|
||||
TbVehiculos -> FieldDefs -> Clear();
|
||||
|
||||
/********************\
|
||||
|* Datos B<>sicos *|
|
||||
\********************/
|
||||
TbVehiculos -> FieldDefs -> Add("idc", ftAutoInc, 0, false );
|
||||
TbVehiculos -> FieldDefs -> Add("ida", ftInteger, 0, false );
|
||||
/** CDA se compone como: (idCard)+(ida)*100
|
||||
donde idCard va desde 0 .. 99
|
||||
*/
|
||||
TbVehiculos -> FieldDefs -> Add("idCard", ftInteger, 0, false );
|
||||
|
||||
|
||||
TbVehiculos -> FieldDefs -> Add("matricula", ftString, 10, false );
|
||||
TbVehiculos -> FieldDefs -> Add("color", ftString, 15, false );
|
||||
TbVehiculos -> FieldDefs -> Add("modelo", ftString, 40, false );
|
||||
TbVehiculos -> FieldDefs -> Add("idplaza", ftString, 5, false );
|
||||
|
||||
TbVehiculos -> IndexDefs-> Clear();
|
||||
|
||||
TbVehiculos->IndexDefs->Add("Primary", "idc", TIndexOptions() << ixPrimary << ixUnique);
|
||||
TbVehiculos->IndexDefs->Add("iAbonados", "ida;idCard", TIndexOptions() << ixCaseInsensitive );
|
||||
TbVehiculos->IndexDefs->Add("iCards", "idCard", TIndexOptions() << ixCaseInsensitive );
|
||||
// Creamos la base...
|
||||
TbVehiculos -> CreateTable();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
void __fastcall TForm1::DBGrid1DblClick(TObject *Sender)
|
||||
{
|
||||
PageControl1->ActivePage = TabSheet2;
|
||||
PageControl2->ActivePage = TabSheet3;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::BuscadorKeyUp(TObject *Sender, WORD &Key,
|
||||
TShiftState Shift)
|
||||
{
|
||||
TbAbonados->Locate( SelIndex->Items->Strings[SelIndex->ItemIndex], Buscador->Text, TLocateOptions() << loCaseInsensitive << loPartialKey );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
|
||||
{
|
||||
//
|
||||
TbBusqMatriculas->Active = true;
|
||||
if ( TbBusqMatriculas->Locate( "matricula", Buscador->Text, TLocateOptions() << loCaseInsensitive << loPartialKey ) )
|
||||
{
|
||||
if ( TbAbonados->Locate( "ida", TbBusqMatriculas->FieldByName("ida")->AsInteger, TLocateOptions() << loCaseInsensitive << loPartialKey ) )
|
||||
{
|
||||
PageControl1->ActivePage = TabSheet2;
|
||||
}
|
||||
}
|
||||
TbBusqMatriculas->Active = false;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::TbAbonadosBeforeDelete(TDataSet *DataSet)
|
||||
{
|
||||
if ( Application->MessageBox("<EFBFBD>Eliminar al abonado actual?", "CAP: Eliminaci<63>n", MB_OKCANCEL) != IDOK)
|
||||
{
|
||||
Abort();
|
||||
return;
|
||||
}
|
||||
// Eliminamos todos los vehiculos de este ABONADO
|
||||
while (1)
|
||||
{
|
||||
try {
|
||||
// Finalmente ELIMINAMOS al vehiculo
|
||||
TbVehiculos->Delete();
|
||||
} catch(...) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::TbCardsBeforeOpen(TDataSet *DataSet)
|
||||
{
|
||||
if ( !FileExists( TbCards -> TableName ) )
|
||||
{
|
||||
// Usamos la propiedad FielDefs para definir
|
||||
// las columnas que contendr<64> la tabla
|
||||
TbCards -> FieldDefs -> Clear();
|
||||
|
||||
/********************\
|
||||
|* Datos B<>sicos *|
|
||||
\********************/
|
||||
TbCards -> FieldDefs -> Add("id", ftAutoInc, 0, false );
|
||||
TbCards -> FieldDefs -> Add("idowner", ftInteger, 0, false );
|
||||
TbCards -> FieldDefs -> Add("idh", ftInteger, 0, false );
|
||||
|
||||
// idCARD se forma de la siguiente manera:
|
||||
// (32 bits) bit 0 (1) Indica Abonado=0 <20> Ocasional=1
|
||||
// En los abonados:
|
||||
// bit 1..5 (5) N<>mero de version (vCard)
|
||||
// bit 6..32 (28) ID poseedor tarjeta (idowner)
|
||||
// No Abonados:
|
||||
// bit 1..32 (31) ID cliente ocacional
|
||||
TbCards -> FieldDefs -> Add("idCard", ftInteger, 0, false );
|
||||
TbCards -> FieldDefs -> Add("vCard", ftInteger, 0, false );
|
||||
TbCards -> FieldDefs -> Add("fechaM", ftDate, 0, false );
|
||||
TbCards -> FieldDefs -> Add("acceso", ftBoolean, 0, false );
|
||||
TbCards -> FieldDefs -> Add("vip", ftBoolean, 0, false );
|
||||
TbCards -> FieldDefs -> Add("msg", ftString, 32, false );
|
||||
|
||||
TbCards -> IndexDefs-> Clear();
|
||||
|
||||
TbCards->IndexDefs->Add("Primary", "id", TIndexOptions() << ixPrimary << ixUnique);
|
||||
TbCards->IndexDefs->Add("iOwner", "idowner", TIndexOptions() << ixCaseInsensitive );
|
||||
TbCards->IndexDefs->Add("iCards", "idCard", TIndexOptions() << ixCaseInsensitive << ixUnique );
|
||||
// Creamos la base...
|
||||
TbCards -> CreateTable();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::DBGrid2DrawColumnCell(TObject *Sender,
|
||||
const TRect &Rect, int DataCol, TColumn *Column,
|
||||
TGridDrawState State)
|
||||
{
|
||||
if ( Column->ID == 4 )
|
||||
{
|
||||
if ( TbVehiculos->FieldByName("idCard")->AsInteger > 0 )
|
||||
{
|
||||
DBGrid2 -> Canvas -> StretchDraw( Rect, CardOK->Picture->Graphic );
|
||||
}
|
||||
} else {
|
||||
DBGrid2 -> DefaultDrawColumnCell( Rect, DataCol, Column, State );
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::TbVehiculosBeforeDelete(TDataSet *DataSet)
|
||||
{
|
||||
// Eliminamos la TARJETA asociada a este VEHICULO
|
||||
if ( TbCards->Locate( "id", TbVehiculos->FieldByName("idCard")->AsInteger, TLocateOptions() << loCaseInsensitive << loPartialKey ) )
|
||||
{
|
||||
TbCards->Delete();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::DBGrid2DblClick(TObject *Sender)
|
||||
{
|
||||
if ( DBGrid2->SelectedIndex == 4 )
|
||||
{
|
||||
if ( TbVehiculos->State == dsEdit || TbVehiculos->State == dsInsert )
|
||||
TbVehiculos->Post();
|
||||
|
||||
int idCard, idCardA;
|
||||
// Abrimos el editor de TARJETA
|
||||
TCardCtrl *CCard;
|
||||
CCard = new TCardCtrl(this);
|
||||
if ( TbVehiculos->FieldByName("idCard")->IsNull )
|
||||
idCardA = -1;
|
||||
else
|
||||
idCardA = TbVehiculos->FieldByName("idCard")->AsInteger;
|
||||
idCard = CCard->LocateCard( idCardA,
|
||||
TbVehiculos->FieldByName("idc")->AsInteger );
|
||||
if ( idCard != idCardA )
|
||||
{
|
||||
TbVehiculos->Edit();
|
||||
TbVehiculos->FieldByName("idCard")->AsInteger = idCard;
|
||||
TbVehiculos->Post();
|
||||
}
|
||||
CCard->ShowModal();
|
||||
delete CCard;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
void __fastcall TForm1::DsAbonadosUpdateData(TObject *Sender)
|
||||
{
|
||||
int idc; bool acceso; AnsiString msg;
|
||||
// Propagamos los cambios de tarjeta a todos sus vehiculos
|
||||
acceso = false;
|
||||
switch( TbAbonados->FieldByName("estado")->AsInteger )
|
||||
{
|
||||
// ALTA
|
||||
case 0:
|
||||
//########################
|
||||
//########################
|
||||
if ( TbTAbonados->Locate( "idta", TbAbonados->FieldByName("tipoa")->AsInteger, TLocateOptions() << loCaseInsensitive << loPartialKey ) )
|
||||
acceso = TbTAbonados->FieldByName("acceso")->AsBoolean;
|
||||
else
|
||||
acceso = false;
|
||||
msg = TbTAbonados->FieldByName("msg")->AsString;
|
||||
break;
|
||||
// Sancionado
|
||||
case 1:
|
||||
msg = " SANCIONADO Pase por CAJA";
|
||||
break;
|
||||
// Baja temporal
|
||||
case 2:
|
||||
msg = " BAJA ImPagado Pase por CAJA";
|
||||
break;
|
||||
// Baja definitiva
|
||||
case 3:
|
||||
//123456789ABCDEF-123456789ABCDEF-
|
||||
msg = "BAJA DEFINITIVA Pase por CAJA";
|
||||
break;
|
||||
default:
|
||||
msg = "Por favor, Pase por CAJA";
|
||||
break;
|
||||
}
|
||||
|
||||
TbVehiculos->First();
|
||||
while ( !TbVehiculos->Eof )
|
||||
{
|
||||
idc = TbVehiculos->FieldByName("idCard")->AsInteger;
|
||||
if ( TbCards->Locate( "id", idc, TLocateOptions() << loCaseInsensitive << loPartialKey ) )
|
||||
{
|
||||
TbCards->Edit();
|
||||
TbCards->FieldByName("idh")->AsInteger = TbAbonados->FieldByName("tipoa")->AsInteger;
|
||||
TbCards->FieldByName("acceso")->AsBoolean = acceso;
|
||||
TbCards->FieldByName("vip")->AsBoolean = TbAbonados->FieldByName("vip")->AsBoolean;
|
||||
TbCards->FieldByName("msg")->AsString = msg;
|
||||
TbCards->Post();
|
||||
}
|
||||
TbVehiculos->Next();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
|
||||
{
|
||||
if ( TbAbonados->State == dsEdit || TbAbonados->State == dsInsert )
|
||||
TbAbonados->Post();
|
||||
if ( TbVehiculos->State == dsEdit || TbVehiculos->State == dsInsert )
|
||||
TbVehiculos->Post();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::PageControl2Change(TObject *Sender)
|
||||
{
|
||||
if ( TbAbonados->State == dsEdit || TbAbonados->State == dsInsert )
|
||||
TbAbonados->Post();
|
||||
if ( TbVehiculos->State == dsEdit || TbVehiculos->State == dsInsert )
|
||||
TbVehiculos->Post();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::PageControl1Change(TObject *Sender)
|
||||
{
|
||||
if ( TbAbonados->State == dsEdit || TbAbonados->State == dsInsert )
|
||||
TbAbonados->Post();
|
||||
if ( TbVehiculos->State == dsEdit || TbVehiculos->State == dsInsert )
|
||||
TbVehiculos->Post();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
|
||||
{
|
||||
TbAbonados->Edit();
|
||||
TbAbonados->FieldByName("estado")->AsInteger = ComboBox1->ItemIndex;
|
||||
TbAbonados->Post();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::DsAbonadosDataChange(TObject *Sender,
|
||||
TField *Field)
|
||||
{
|
||||
if ( isSettingData ) return;
|
||||
ComboBox1->ItemIndex = TbAbonados->FieldByName("estado")->AsInteger;
|
||||
ComboBox2->ItemIndex = TbAbonados->FieldByName("fperiodo")->AsInteger;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::AvanzaCampo(TObject *Sender, char &Key)
|
||||
{
|
||||
if ( Key != VK_RETURN ) return;
|
||||
|
||||
try {
|
||||
TbAbonados->Post();
|
||||
} catch(...) {
|
||||
// Nothing
|
||||
}
|
||||
if ( Sender == (TObject *)DBEdit1 ) DBEdit2->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit2 ) DBEdit6->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit6 ) DBEdit3->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit3 ) DBEdit4->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit4 ) DBEdit5->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit5 ) DBEdit7->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit7 ) DBEdit8->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit8 ) DBEdit9->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit9 ) DBLookupComboBox2->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)DBLookupComboBox2 ) ComboBox1->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)ComboBox1 ) ComboBox2->SetFocus();
|
||||
else
|
||||
if ( Sender == (TObject *)ComboBox2 ) DBEdit1->SetFocus();
|
||||
/*
|
||||
else
|
||||
if ( Sender == (TObject *)DBEdit11 ) DBEdit1->SetFocus();
|
||||
*/
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::TbAbonadosNewRecord(TDataSet *DataSet)
|
||||
{
|
||||
TbAbonados->FieldByName("fAlta")->AsDateTime = TDateTime::CurrentDate();
|
||||
TbAbonados->FieldByName("fInicio")->AsDateTime = TDateTime::CurrentDate();
|
||||
TbAbonados->FieldByName("estado")->AsInteger = 0;
|
||||
TbAbonados->FieldByName("fPeriodo")->AsInteger = 0;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::ComboBox2Change(TObject *Sender)
|
||||
{
|
||||
isSettingData = true;
|
||||
TbAbonados->Edit();
|
||||
TbAbonados->FieldByName("fperiodo")->AsInteger = ComboBox2->ItemIndex;
|
||||
TbAbonados->Post();
|
||||
isSettingData = false;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
TDateTime __fastcall TForm1::DiasEnPeriodoDesde( TDateTime fechaE )
|
||||
{
|
||||
TDateTime NuevaFechaS;
|
||||
unsigned short YY, MM, DD;
|
||||
fechaE.DecodeDate( &YY, &MM, &DD );
|
||||
// Le asignamos un nuevo periodo...
|
||||
switch( TbAbonados->FieldByName("fperiodo")->AsInteger )
|
||||
{
|
||||
case 0: // Mensual
|
||||
NuevaFechaS = EncodeDate( (MM==12)?(YY+1):YY, (MM==12)?1:(MM+1), 1 );
|
||||
break;
|
||||
case 1: // BiMestral
|
||||
NuevaFechaS = EncodeDate( (MM>=11)?(YY+1):YY, (MM==11)?1:( (MM==12)?2:(MM+2) ), 1 );
|
||||
break;
|
||||
case 2: // TriMestral
|
||||
NuevaFechaS = EncodeDate( (MM>=10)?(YY+1):YY, (MM==10)?1:( (MM==11)?2:( (MM==12)? 3: (MM+3) )), 1 );
|
||||
break;
|
||||
case 3: // Anual
|
||||
NuevaFechaS = EncodeDate( YY+1, MM+1, 1 );
|
||||
break;
|
||||
default:
|
||||
NuevaFechaS = fechaE + 15;
|
||||
break;
|
||||
}
|
||||
return NuevaFechaS;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
Currency __fastcall TForm1::ImporteDelPeriodo()
|
||||
{
|
||||
if ( TbAbonados->FieldByName("fperiodo")->AsInteger >= 0 &&
|
||||
TbAbonados->FieldByName("fperiodo")->AsInteger <= 3 )
|
||||
|
||||
return ImportesPeriodo[ TbAbonados->FieldByName("fperiodo" )->AsInteger ];
|
||||
|
||||
return 0;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::RenovarAbonoClick(TObject *Sender)
|
||||
{
|
||||
bool firstTime;
|
||||
TDateTime AntS = AntS.CurrentDate();
|
||||
|
||||
// No es la primera vez que renueva
|
||||
if ( TbFacturas->RecordCount > 0 )
|
||||
{
|
||||
TbFacturas->Last(); // Ordenado al reves, asi que esta es la <20>ltima factura
|
||||
// Si la <20>ltima factura no esta pagada
|
||||
if ( ! TbFacturas->FieldByName("pagado")->AsBoolean )
|
||||
{
|
||||
// Pero esta aun vigente
|
||||
if ( TbFacturas->FieldByName("fechaS")->AsDateTime < TDateTime::CurrentDate() )
|
||||
{
|
||||
TDateTime NuevaFechaS = DiasEnPeriodoDesde( TbFacturas->FieldByName("fechaE")->AsDateTime );
|
||||
|
||||
if ( NuevaFechaS >= TDateTime::CurrentDate() )
|
||||
{
|
||||
TbFacturas->Edit();
|
||||
TbFacturas->FieldByName("fechaS")->AsDateTime = NuevaFechaS;
|
||||
TbFacturas->FieldByName("importe")->AsInteger = ImporteDelPeriodo();
|
||||
TbFacturas->Post();
|
||||
}
|
||||
} else {
|
||||
// <20>ltima factura impagada / Fuera del periodo
|
||||
ShowMessage( "Imposible renovar periodo de Abono. Aun tiene facturas pendientes, (expiradas)." );
|
||||
}
|
||||
} else { // La <20>ltima factura esta abonada...
|
||||
// Preparamos un periodo nuevo, para el mes siguiente
|
||||
AntS = TbFacturas->FieldByName( "fechaS" )->AsDateTime;
|
||||
firstTime = true;
|
||||
|
||||
}
|
||||
} else {
|
||||
// Como es la primera vez que se emite un recibo
|
||||
firstTime = true; // Realizar nuevo abono para el periodo en curso
|
||||
}
|
||||
|
||||
// Primera vez que se emite un recibo, <20> el periodo del recibo
|
||||
// esta dentro del mes en curso...
|
||||
if ( firstTime )
|
||||
{
|
||||
TbFacturas->Insert();
|
||||
TbFacturas->FieldByName("pagado")->AsBoolean = false;
|
||||
// Si aun no ha expirado el periodo (ya pagado actual)
|
||||
if ( AntS > TDateTime::CurrentDate() )
|
||||
{
|
||||
// Preparamos el nuevo periodo a partir de "fechaS"
|
||||
TbFacturas->FieldByName("fechaE")->AsDateTime = AntS;
|
||||
} else {
|
||||
// Preparamos a partir del dia actual...
|
||||
TbFacturas->FieldByName("fechaE")->AsDateTime = TDateTime::CurrentDate();
|
||||
}
|
||||
TbFacturas->FieldByName("fechaS")->AsDateTime = DiasEnPeriodoDesde( TbFacturas->FieldByName("fechaE")->AsDateTime );
|
||||
TbFacturas->FieldByName("importe")->AsCurrency = ImporteDelPeriodo();
|
||||
TbFacturas->Post();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::TbFacturasBeforeOpen(TDataSet *DataSet)
|
||||
{
|
||||
if ( !FileExists( TbFacturas -> TableName ) )
|
||||
{
|
||||
// Usamos la propiedad FielDefs para definir
|
||||
// las columnas que contendr<64> la tabla
|
||||
TbFacturas -> FieldDefs -> Clear();
|
||||
|
||||
/********************\
|
||||
|* Datos B<>sicos *|
|
||||
\********************/
|
||||
TbFacturas -> FieldDefs -> Add("id", ftAutoInc, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("idc", ftInteger, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("fechaE", ftDate, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("fechaS", ftDate, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("horaE", ftTime, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("horaS", ftTime, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("importe", ftCurrency, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("pagado", ftBoolean, 0, false );
|
||||
TbFacturas -> FieldDefs -> Add("fechaP", ftDate, 0, false );
|
||||
|
||||
TbFacturas -> IndexDefs-> Clear();
|
||||
|
||||
TbFacturas->IndexDefs->Add("Primary", "id", TIndexOptions() << ixPrimary << ixUnique);
|
||||
TbFacturas->IndexDefs->Add("iOwner", "idc", TIndexOptions() << ixCaseInsensitive );
|
||||
TbFacturas->IndexDefs->Add("iExpira", "fechaS", TIndexOptions() << ixCaseInsensitive << ixDescending );
|
||||
// Creamos la base...
|
||||
TbFacturas -> CreateTable();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::DBGrid3DblClick(TObject *Sender)
|
||||
{
|
||||
// Confirmar abono de factura...
|
||||
if ( ! TbFacturas->FieldByName("pagado")->AsBoolean )
|
||||
{
|
||||
AnsiString NewString = TbFacturas->FieldByName("importe")->AsString;
|
||||
// Label1->Caption = NewString;
|
||||
if (InputQuery("Abono de la factura: "+TbFacturas->FieldByName("id")->AsString, "Importe:", NewString))
|
||||
{
|
||||
try { // NewString has been changed by the user, who clicked ok
|
||||
bool ConAcceso;
|
||||
Currency importe = NewString.ToDouble();
|
||||
TbFacturas->Edit();
|
||||
TbFacturas->FieldByName("importe")->AsCurrency = importe;
|
||||
TbFacturas->FieldByName("pagado")->AsBoolean = true;
|
||||
TbFacturas->FieldByName("fechaP")->AsDateTime = TDateTime::CurrentDate();
|
||||
TbFacturas->Post();
|
||||
TbAbonados->Edit();
|
||||
|
||||
TbAbonados->FieldByName("estado")->AsInteger = 0;
|
||||
ConAcceso = ( TDateTime::CurrentDate() <= TbFacturas->FieldByName("fechaS")->AsDateTime );
|
||||
|
||||
TbAbonados->Post();
|
||||
|
||||
|
||||
// Actualizamos la fecha maxima disponible de todas sus tarjetas
|
||||
TbVehiculos->First();
|
||||
int idc;
|
||||
while ( !TbVehiculos->Eof )
|
||||
{
|
||||
idc = TbVehiculos->FieldByName("idCard")->AsInteger;
|
||||
if ( TbCards->Locate( "id", idc, TLocateOptions() << loCaseInsensitive << loPartialKey ) )
|
||||
{
|
||||
TbCards->Edit();
|
||||
TbCards->FieldByName("fechaM")->AsDateTime = TbFacturas->FieldByName("fechaS")->AsDateTime;
|
||||
TbCards->FieldByName("acceso")->AsBoolean = true;
|
||||
TbCards->Post();
|
||||
}
|
||||
TbVehiculos->Next();
|
||||
}
|
||||
} catch (...) {
|
||||
ShowMessage( "El importe introducido no es correcto" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
|
||||
{
|
||||
if ( TbFacturas->FieldByName("pagado")->AsBoolean == false )
|
||||
{
|
||||
TbFacturas->Delete();
|
||||
} else {
|
||||
AnsiString PWD;
|
||||
if ( InputQuery("Password administrativo", "Password:", PWD ) && PWD == cfgPWD )
|
||||
TbFacturas->Delete();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
|
||||
{
|
||||
TqrLAbonados *qr;
|
||||
qr = new TqrLAbonados(this);
|
||||
qr->QuickRep1->Preview();
|
||||
delete qr;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user