357 lines
12 KiB
C++
357 lines
12 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#include <io.h>
|
|
#pragma hdrstop
|
|
|
|
#include "TpvVntGeneral.h"
|
|
#include "TpvVntCltQR.h"
|
|
#include "TDlgBuscar.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#pragma link "ElastFrm"
|
|
#pragma resource "*.dfm"
|
|
TVntGeneral *VntGeneral;
|
|
//---------------------------------------------------------------------------
|
|
__fastcall TVntGeneral::TVntGeneral(TComponent* Owner)
|
|
: TForm(Owner)
|
|
{
|
|
MinFechaFact = TDateTime::CurrentDate();
|
|
MaxFechaFact = TDateTime::CurrentDate();
|
|
|
|
// Cargamos la imagen OK!
|
|
try {
|
|
BtmOK = new Graphics::TBitmap();
|
|
BtmOK -> LoadFromFile( "Systm\\ok.bmp" );
|
|
|
|
BtmLockOpen = new Graphics::TBitmap();
|
|
BtmLockOpen -> LoadFromFile( "Systm\\lockopen.bmp" );
|
|
|
|
BtmLockShut = new Graphics::TBitmap();
|
|
BtmLockShut -> LoadFromFile( "Systm\\lockshut.bmp" );
|
|
|
|
} catch (...) {
|
|
ShowMessage( "Error: La imagen OK! está corrupta" );
|
|
}
|
|
|
|
|
|
MinFecha -> DateTime = MinFechaFact;
|
|
MaxFecha -> DateTime = MaxFechaFact;
|
|
|
|
// La cabecera/cuerpo de ventas se generan uno por año...
|
|
TbEmpl -> Active = true;
|
|
|
|
FirstTime = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
void __fastcall TVntGeneral::MinFechaChange(TObject *Sender)
|
|
{
|
|
MaxFechaFact = MaxFecha -> Date;
|
|
|
|
// Reajustamos el filtro...
|
|
MinFechaFact = MinFecha -> Date;
|
|
FiltrarFacturas();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::MaxFechaChange(TObject *Sender)
|
|
{
|
|
MinFechaFact = MinFecha -> Date;
|
|
|
|
// Reajustamos el filtro...
|
|
MaxFechaFact = MaxFecha -> Date;
|
|
FiltrarFacturas();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::SpeedButton1Click(TObject *Sender)
|
|
{
|
|
Close();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::FiltrarFacturas(void)
|
|
{
|
|
TbClientes->Close();
|
|
TbClientes->Active = true;
|
|
|
|
// Filtramos las facturas...
|
|
TbVentasC->FilterOptions = TbVentasC->FilterOptions << foCaseInsensitive;
|
|
TbVentasC->Filter = "([FechaFactura] >= '" + MinFechaFact + "' AND [FechaFactura] <= '" + MaxFechaFact +"')";
|
|
TbVentasC->Filtered = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::DBGrid3DrawColumnCell(TObject *Sender,
|
|
const TRect &Rect, int DataCol, TColumn *Column,
|
|
TGridDrawState State)
|
|
{
|
|
// Verde ] si el albaran/factura esta abiert@
|
|
// Rojo ] los abonos o albaranes con perdidas
|
|
if ( ! State.Contains(gdSelected) )
|
|
{
|
|
if ( TbVentasCFacturaAbierta -> AsInteger > 0 )
|
|
{
|
|
DBGrid3 -> Canvas -> Font -> Color = clGreen;
|
|
} else {
|
|
if ( TbVentasC->FieldByName("TotalSin")->AsCurrency < 0 )
|
|
DBGrid3 -> Canvas -> Font -> Color = clRed;
|
|
}
|
|
DBGrid3 -> DefaultDrawColumnCell( Rect, DataCol, Column, State );
|
|
}
|
|
if ( Column -> ID == 0 )
|
|
{
|
|
if ( TbVentasC->FieldByName("Contabilizada")->AsBoolean )
|
|
DBGrid3->Canvas->StretchDraw( Rect, BtmLockShut );
|
|
else
|
|
DBGrid3->Canvas->StretchDraw( Rect, BtmLockOpen );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::FormActivate(TObject *Sender)
|
|
{
|
|
if ( FirstTime )
|
|
FiltrarFacturas();
|
|
FirstTime = false;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::ImpagFactClick(TObject *Sender)
|
|
{
|
|
TodasFact->Enabled = true;
|
|
ImpagFact->Enabled = false;
|
|
|
|
MinFecha->Enabled = false;
|
|
MaxFecha->Enabled = false;
|
|
|
|
FiltrarFacturas();
|
|
|
|
PageControl1->ActivePage = (TTabSheet *)TabSheet2;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::TodasFactClick(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
|
|
TodasFact->Enabled = false;
|
|
ImpagFact->Enabled = true;
|
|
|
|
MinFecha->Enabled = true;
|
|
MaxFecha->Enabled = true;
|
|
|
|
// Atencion refiltrar base de datos
|
|
FiltrarFacturas();
|
|
#endif
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::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 TVntGeneral::dbgFraccionCellClick(TColumn *Column)
|
|
{
|
|
bool Pagado;
|
|
|
|
if ( Column -> ID == 0 )
|
|
{
|
|
if ( TbVentasCFacturaAbierta -> AsInteger > 0 )
|
|
{
|
|
ShowMessage( "Atención: La factura actual esta abierta en algún\nterminal. Cierrela antes de intentar modificarla.");
|
|
} else {
|
|
Pagado = TbCartera->FieldByName("Pagado")->AsBoolean;
|
|
if ( Pagado )
|
|
if( MessageDlg( "Atención, está apunto de desactivar el\npago correspondiente a esta línea...\n¿Realmente desea continuar?", mtWarning, TMsgDlgButtons() << mbNo << mbYes, 0 ) == mrNo )
|
|
return;
|
|
TbCartera -> Edit();
|
|
TbCartera -> FieldByName("Pagado") -> AsBoolean = !Pagado;
|
|
TbCartera -> Post();
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::FormClose(TObject *Sender, TCloseAction &Action)
|
|
{
|
|
// Destruimos la imagen de OK!
|
|
delete BtmOK;
|
|
delete BtmLockOpen;
|
|
delete BtmLockShut;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::TbVentasCCalcFields(TDataSet *DataSet)
|
|
{
|
|
TbVentasC->FieldByName("SumaTotal")->AsCurrency = TbVentasC->FieldByName("TotalSin")->AsCurrency + TbVentasC->FieldByName("TotalIva")->AsCurrency;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::DsVentasCDataChange(TObject *Sender,
|
|
TField *Field)
|
|
{
|
|
cbFormaPago->ItemIndex = TbCartera->FieldByName("FormaPago")->AsInteger;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::TbClientesBeforeOpen(TDataSet *DataSet)
|
|
{
|
|
TbClientes->SQL->Clear();
|
|
|
|
if ( TodasFact->Enabled )
|
|
{
|
|
// SOLO LOS CLIENTES QUE TENGAN FACTURAS IMPAGADAS....
|
|
TbClientes->SQL->Add( "SELECT DISTINCT VentasCabecera.Cod"+CodCliente+" ID, ((Personas.Nombre+', ')+Personas.Apellidos) Nombre, Personas.Empresa " );
|
|
TbClientes->SQL->Add( "FROM \"personas.DB\" Personas, \""+TbCartera->TableName+"\" Tb_cartera, \""+TbVentasC->TableName+"\" VentasCabecera" );
|
|
TbClientes->SQL->Add( "WHERE (Tb_cartera.Pagado = FALSE)");
|
|
TbClientes->SQL->Add( " AND (Tb_cartera.EnlaceFactura = VentasCabecera.EnlaceFactura)");
|
|
TbClientes->SQL->Add( " AND (Personas.CodCliente1 = VentasCabecera.Cod"+CodCliente+")");
|
|
} else {
|
|
TbClientes->SQL->Add( "SELECT DISTINCT VentasCabecera.Cod"+CodCliente+" ID, Personas.Nombre, Personas.Apellidos, Personas.Empresa, SUM( VentasCabecera.TotalSin + VentasCabecera.TotalIva ) VentasCabecera.\"Total Fact.\" " );
|
|
TbClientes->SQL->Add( "FROM \""+TbVentasC->TableName+"\" VentasCabecera" );
|
|
TbClientes->SQL->Add( " INNER JOIN \"personas.DB\" Personas");
|
|
TbClientes->SQL->Add( " ON (VentasCabecera.Cod"+CodCliente+" = Personas.CodCliente1)");
|
|
TbClientes->SQL->Add( "WHERE (VentasCabecera.FechaFactura >= '"+MinFechaFact.FormatString("mm/dd/yyyy")+"') \
|
|
AND (VentasCabecera.FechaFactura <= '"+MaxFechaFact.FormatString("mm/dd/yyyy")+"') ");
|
|
TbClientes->SQL->Add( "GROUP BY VentasCabecera.Cod"+CodCliente+", Personas.Nombre, Personas.Apellidos, Personas.Empresa");
|
|
TbClientes->SQL->Add( "ORDER BY VentasCabecera.\"Total Fact.\" DESC");
|
|
|
|
/*
|
|
SELECT DISTINCT VentasCabecera.CodCliente CodCliente1, ((Personas.Nombre+', ')+Personas.Apellidos) Nombre, Personas.Empresa
|
|
FROM "Ventas (cabecera).db" VentasCabecera, "personas.DB" Personas
|
|
WHERE (VentasCabecera.FechaFactura >= '01/27/2001')
|
|
AND (VentasCabecera.FechaFactura <= '01/27/2001')
|
|
AND (VentasCabecera.CodCliente = Personas.CodCliente1)
|
|
|
|
*/
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::TbCarteraBeforeDelete(TDataSet *DataSet)
|
|
{
|
|
Abort();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::TbCarteraBeforeInsert(TDataSet *DataSet)
|
|
{
|
|
Abort();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::FormResize(TObject *Sender)
|
|
{
|
|
if ( DBGrid3->Columns->Items[0]->Width != 16 )
|
|
DBGrid3->Columns->Items[0]->Width = 16;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TVntGeneral::SpeedButton7Click(TObject *Sender)
|
|
{
|
|
/*
|
|
TVntCltQR *QR;
|
|
QR = new TVntCltQR(this);
|
|
QR->QuickRep1->Preview();
|
|
delete QR;
|
|
*/
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::DBGrid3DblClick(TObject *Sender)
|
|
{
|
|
|
|
|
|
if ( ! TbVentasF -> Active ) return;
|
|
|
|
|
|
// Si no esta facturada...
|
|
if ( ! TbVentasC->FieldByName("Contabilizada")->AsBoolean )
|
|
{
|
|
VTabs[0] = TabSheet1->Visible;
|
|
VTabs[1] = TabSheet2->Visible;
|
|
TabSheet1->Visible = false;
|
|
TabSheet2->Visible = false;
|
|
TabSheet3->Visible = true;
|
|
// Mostrar la posibilidad de facturar
|
|
// cambiar el cliente asignado
|
|
// o ambas cosas
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::Button2Click(TObject *Sender)
|
|
{
|
|
TabSheet1->Visible = VTabs[0];
|
|
TabSheet2->Visible = VTabs[1];
|
|
TabSheet3->Visible = false;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::Button1Click(TObject *Sender)
|
|
{
|
|
TbVentasC -> Edit();
|
|
|
|
if ( Facturar->Checked )
|
|
{
|
|
if ( TbVentasF -> Active )
|
|
{
|
|
TbVentasF->Last();
|
|
int NumFactura;
|
|
NumFactura = TbVentasF->FieldByName( "idF" )->AsInteger + 1;
|
|
TbVentasF->InsertRecord( ARRAYOFCONST( ( NumFactura, TbVentasC->FieldByName( "EnlaceFactura" )->AsInteger, true ) ) );
|
|
|
|
if ( NewClient != -1 )
|
|
TbVentasC -> FieldByName( "CodCliente" ) -> AsInteger = NewClient;
|
|
TbVentasC -> FieldByName( "CodFactura" ) -> AsInteger = NumFactura;
|
|
TbVentasC -> FieldByName( "FechaFactura" ) -> AsDateTime = TDateTime::CurrentDate();
|
|
}
|
|
TbVentasC -> FieldByName("Contabilizada")->AsBoolean = true;
|
|
}
|
|
|
|
TbVentasC -> Post();
|
|
|
|
Button2Click(0);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
void __fastcall TVntGeneral::SpeedButton9Click(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 = "personas.DB";
|
|
DlgBuscar -> TbBusquedas -> Active = true;
|
|
|
|
DlgBuscar -> ShowModal();
|
|
|
|
if ( DlgBuscar -> ModalResult == mrOk )
|
|
{
|
|
Label12->Caption = DlgBuscar -> TbBusquedas -> FieldByName("Nombre")->AsString + " " +
|
|
DlgBuscar -> TbBusquedas -> FieldByName("Apellidos")->AsString;
|
|
NewClient = DlgBuscar -> TbBusquedas -> FieldByName("CodCliente1" ) -> AsInteger;
|
|
}
|
|
|
|
delete DlgBuscar;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TVntGeneral::TabSheet3Enter(TObject *Sender)
|
|
{
|
|
|
|
NewClient = -1;
|
|
Label12->Caption = "(sin cambios)";
|
|
|
|
Label11->Caption = "(sin cambios)";
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
|