first commit (2002-04-24)
This commit is contained in:
119
cap_gestion/capg_gfact.cpp
Normal file
119
cap_gestion/capg_gfact.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <vcl.h>
|
||||
#include <inifiles.hpp>
|
||||
#pragma hdrstop
|
||||
|
||||
#include "capg_gfact.h"
|
||||
//---------------------------------------------------------------------------
|
||||
#pragma package(smart_init)
|
||||
#pragma resource "*.dfm"
|
||||
TgFact *gFact;
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TgFact::TgFact(TComponent* Owner)
|
||||
: TForm(Owner)
|
||||
{
|
||||
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 );
|
||||
delete ini;
|
||||
|
||||
TbFacturas->Active = true;
|
||||
TbAbonados->Active = true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
TDateTime __fastcall TgFact::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 TgFact::ImporteDelPeriodo()
|
||||
{
|
||||
if ( TbAbonados->FieldByName("fperiodo")->AsInteger >= 0 &&
|
||||
TbAbonados->FieldByName("fperiodo")->AsInteger <= 3 )
|
||||
|
||||
return ImportesPeriodo[ TbAbonados->FieldByName("fperiodo" )->AsInteger ];
|
||||
|
||||
return 0;
|
||||
}//---------------------------------------------------------------------------
|
||||
void __fastcall TgFact::BitBtn1Click(TObject *Sender)
|
||||
{
|
||||
if ( ComboBox1->ItemIndex >=0 && ComboBox2->ItemIndex >= 0 )
|
||||
{
|
||||
TDateTime FechaInicioFacturas = EncodeDate( ComboBox2->ItemIndex+2002, ComboBox1->ItemIndex+1, 1 );
|
||||
|
||||
ComboBox1->Visible = false;
|
||||
ComboBox2->Visible = false;
|
||||
BitBtn1->Visible = false;
|
||||
ProgressBar1->Position=0;
|
||||
ProgressBar1->Visible=true;
|
||||
TbAbonados->Active = true;
|
||||
ProgressBar1->Max = TbAbonados->RecordCount;
|
||||
TbAbonados->First();
|
||||
while ( !TbAbonados->Eof )
|
||||
{
|
||||
// Si el estado es -ALTA-
|
||||
if ( TbAbonados->FieldByName("estado")->AsInteger == 0 )
|
||||
{
|
||||
TbFacturas->Filter = "[idc] = '" + TbAbonados->FieldByName("ida")->AsString+"'";
|
||||
TbFacturas->Filtered = true;
|
||||
|
||||
// Si tuviera alguna factura impagada
|
||||
if ( TbFacturas->Locate( "pagado", false, TLocateOptions() << loCaseInsensitive ) )
|
||||
{
|
||||
TbAbonados->Edit();
|
||||
TbAbonados->FieldByName("estado")->AsInteger = 2; // Baja-Temporal
|
||||
TbAbonados->Post();
|
||||
} else {
|
||||
// Todas las facturas las tiene pagadas...
|
||||
// Si su ultimo abono NO ESTARA VIGENTE en la fecha seleccionada
|
||||
if ( TbFacturas->FieldByName("fechaS")->AsDateTime <= FechaInicioFacturas )
|
||||
{
|
||||
// Insertamos la nueva factura...
|
||||
TbFacturas->Insert();
|
||||
TbFacturas->FieldByName("idc")->AsInteger = TbAbonados->FieldByName("ida")->AsInteger;
|
||||
TbFacturas->FieldByName("pagado")->AsBoolean = false;
|
||||
TbFacturas->FieldByName("fechaE")->AsDateTime = FechaInicioFacturas;
|
||||
TbFacturas->FieldByName("fechaS")->AsDateTime = DiasEnPeriodoDesde( FechaInicioFacturas );
|
||||
TbFacturas->FieldByName("importe")->AsCurrency = ImporteDelPeriodo();
|
||||
TbFacturas->Post();
|
||||
}
|
||||
TbFacturas->Filtered = false;
|
||||
}
|
||||
}
|
||||
ProgressBar1->Position++;
|
||||
TbAbonados->Next();
|
||||
}
|
||||
Close();
|
||||
} else {
|
||||
ShowMessage( "El Mes y/o A<>o seleccionados no son correctos" );
|
||||
}
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
Reference in New Issue
Block a user