Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2013 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6203848 to your computer and use it in GitHub Desktop.
Save anonymous/6203848 to your computer and use it in GitHub Desktop.
Pago de comisiones de programa de Gestión desde 0
unit UCRECOMI;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DBCtrls, Buttons, ExtCtrls, DB, IBCustomDataSet,
IBQuery, Spin, rpcompobase, rpvclreport, Mask, JvExMask, JvSpin, Mneweditjl,
NewSpinEditDouble;
type
TFCRECOMI = class(TForm)
Panel1: TPanel;
SB_Salir: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
SpeedButton1: TSpeedButton;
DBText1: TDBText;
Edit1: TEdit;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
Button1: TButton;
Panel4: TPanel;
Panel6: TPanel;
ListView2: TListView;
Panel7: TPanel;
SpeedButton6: TSpeedButton;
Label4: TLabel;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
Edit2: TEdit;
Panel2: TPanel;
Panel5: TPanel;
ListView1: TListView;
Panel8: TPanel;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
Memo1: TMemo;
Panel3: TPanel;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton12: TSpeedButton;
Label5: TLabel;
Label8: TLabel;
Label9: TLabel;
DateTimePicker3: TDateTimePicker;
IbqCOMI: TIBQuery;
DSIBQPedidos: TDataSource;
IBQbuscomer: TIBQuery;
DSIBQbuscli: TDataSource;
SpinEdit1: TSpinEdit;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Label6: TLabel;
DSRCOMI: TDataSource;
VCLReport1: TVCLReport;
Label10: TLabel;
IBQbuscomerID: TIntegerField;
IBQbuscomerCODIGO: TIBStringField;
IBQbuscomerAGENTE: TIBStringField;
IBQbuscomerMEDIACOMISION: TIBBCDField;
IBQbuscomerFECHAALTA: TDateField;
IBQbuscomerFECHABAJA: TDateField;
IBQbuscomerNUMEROSEGURIDADSOCIAL: TIBStringField;
IBQbuscomerNUMERODOCUMENTO: TIBStringField;
IBQbuscomerCOMISIONDTO1: TIBBCDField;
IBQbuscomerCOMISIONDTORAPEL2: TIBBCDField;
IBQbuscomerCOMISIONDTORAPEL3: TIBBCDField;
IBQbuscomerCOMISIONDTORAPEL4: TIBBCDField;
IBQbuscomerCOMISIONDTORAPEL5: TIBBCDField;
IBQbuscomerPUESTO: TIBStringField;
IBQbuscomerNOMBRE: TIBStringField;
IBQbuscomerSALARIO: TIBBCDField;
IBQbuscomerNIF: TIBStringField;
IbqCOMIID: TIntegerField;
IbqCOMICODIGOEMPLEADO: TIBStringField;
IbqCOMINUMERODOCUMENTO: TIBStringField;
IbqCOMITIPODOCUMENTO: TIBStringField;
IbqCOMISERIE: TIBStringField;
IbqCOMICOMISION: TIBBCDField;
IbqCOMIIMPORTECOMISION: TIBBCDField;
IbqCOMIMININOTA: TIBStringField;
IbqCOMIPAGADAS: TIBStringField;
IbqCOMIFECHAPAGO: TDateField;
IbqCOMINUMEROPAGO: TIBStringField;
IbqCOMIFECHA: TDateField;
IbqCOMIRETENCIONES: TIBBCDField;
IbqCOMIIMPORTEDOCUMENTO: TIBBCDField;
NSEDRetenciones: TNewSpinEditDouble;
procedure FormActivate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SB_SalirClick(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Calcular;
procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
procedure ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem;
State: TCustomDrawState; var DefaultDraw: Boolean);
procedure ListView2ColumnClick(Sender: TObject; Column: TListColumn);
procedure ListView2CustomDrawItem(Sender: TCustomListView; Item: TListItem;
State: TCustomDrawState; var DefaultDraw: Boolean);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure SpeedButton10Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FCRECOMI: TFCRECOMI;
implementation
{$R *.dfm}
uses UDM, Fun, FUN_DBGRID, umenu;
procedure TFCRECOMI.Button1Click(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ Datos del mes actual ]****
//------------------------------------------------------------------------------
begin
DateTimePicker1.Date:=StrToDate(PrFiMes(now));
DateTimePicker2.Date:=StrToDate(PrFiMes(now,False));
DateTimePicker3.Date:=StrToDate(PrFiMes(now,False));
end;
procedure TFCRECOMI.Calcular;
//------------------------------------------------------------------------------
//**************************************************************[ Calcular ]****
//------------------------------------------------------------------------------
var VarIcontFor:Integer;
VarItotal:Real;
begin
VarItotal:=0;
for VarIcontFor := 0 to ListView2.Items.Count-1 do
begin
VarItotal:=VarItotal+StrToFloat(NumDecimalsStr(2,ListView2.Items.Item[VarIcontFor].SubItems[2]));
end;
Edit2.Text:=FormatFloat('#,##0.00', VarItotal);
end;
procedure TFCRECOMI.Edit1Change(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ OnChange ]****
//------------------------------------------------------------------------------
begin
if FCRECOMI.Active then
begin
ActQuery(IBQbuscomer,'Select * from EMPLEADOS where UPPER(CODIGO) like UPPER('+QuotedStr('%'+Edit1.Text+'%')+')');
if Edit1.Text='' then DBText1.Visible:=false
else DBText1.Visible:=True;
end;
end;
procedure TFCRECOMI.FormActivate(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ ONACTIVE ]****
//------------------------------------------------------------------------------
begin
QuerryOC(IbqCOMI,true);
QuerryOC(IBQbuscomer,True);
DateTimePicker1.Date:=Now;
DateTimePicker2.date:=now;
DateTimePicker3.Date:=Now;
if Edit1.Text='' then DBText1.Visible:=false
else DBText1.Visible:=True;
end;
procedure TFCRECOMI.ListView1ColumnClick(Sender: TObject; Column: TListColumn);
//------------------------------------------------------------------------------
//*************************************************************[ Ordenamos ]****
//------------------------------------------------------------------------------
begin
Column.Index:= 1;
Ascendente := True;
TListView(Sender).CustomSort(@SortByColumn, Column.Index);
ListView1.ItemIndex:=0;
end;
procedure TFCRECOMI.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
//------------------------------------------------------------------------------
//**************************************************[ Dibujamos el Zebrado ]****
//------------------------------------------------------------------------------
begin
ListviewZebra(ListView1,COLOR1GRID,COLOR2GRID,item);
end;
procedure TFCRECOMI.ListView2ColumnClick(Sender: TObject; Column: TListColumn);
//------------------------------------------------------------------------------
//*************************************************************[ Ordenamos ]****
//------------------------------------------------------------------------------
begin
Column.Index:= 1;
Ascendente := True;
TListView(Sender).CustomSort(@SortByColumn, Column.Index);
ListView2.ItemIndex:=0;
end;
procedure TFCRECOMI.ListView2CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
//------------------------------------------------------------------------------
//**************************************************[ Dibujamos el Zebrado ]****
//------------------------------------------------------------------------------
begin
ListviewZebra(ListView2,COLOR1GRID,COLOR2GRID,item);
end;
procedure TFCRECOMI.SB_SalirClick(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************************[ Salir ]****
//------------------------------------------------------------------------------
begin
FCRECOMI.Close;
end;
procedure TFCRECOMI.SpeedButton10Click(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************************[ Subir 1 ]****
// Sube 1 elemento en el listview
//------------------------------------------------------------------------------
begin
if ListView2.Selected.Index>0 then PosiListView(ListView2,ListView2.Selected.Index-1); //Este sube al elemento anterior
end;
procedure TFCRECOMI.SpeedButton11Click(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************************[ Borrar ]****
//------------------------------------------------------------------------------
begin
ListView2.Clear;
end;
procedure TFCRECOMI.SpeedButton12Click(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************************[ Recargar datos ]****
//------------------------------------------------------------------------------
begin
ListView1.Clear;
ListView2.Clear;
SpeedButton1Click(Sender);
end;
procedure TFCRECOMI.SpeedButton1Click(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************************[ Buscar ]****
//------------------------------------------------------------------------------
var variNumdoc:Integer;
LI : TListItem;
VarRCalcTotal, VarRComi:Real;
begin
if Edit1.Text<>'' then
begin
VarRCalcTotal:=0;
VarRComi:=0;
variNumdoc:=0;
ActQuery(IbqCOMI,'SELECT * FROM COMISIONES WHERE (COMISIONES.CODIGOEMPLEADO = '+QuotedStr(Edit1.text)+') AND'+
' (COMISIONES.PAGADAS = '+QuotedStr('N')+') AND (COMISIONES.FECHA BETWEEN '+QuotedStr(Cambiafecha(DateTimePicker1.Date))+
' AND '+QuotedStr(Cambiafecha(DateTimePicker2.Date))+') ORDER BY COMISIONES.NUMERODOCUMENTO',True,True,False);
ListView1.Clear;
if not IbqCOMI.IsEmpty then
begin
IbqCOMI.First;
while not IbqCOMI.Eof do
begin
LI:=ListView1.Items.Add;
LI.Caption:='';
LI.SubItems.Add(IbqCOMI.FieldByName('NUMERODOCUMENTO').AsString);
LI.SubItems.Add(IbqCOMI.FieldByName('FECHA').AsString);
LI.SubItems.Add(FormatFloat('#,##0.00',IbqCOMI.FieldByName('IMPORTECOMISION').Value));
IbqCOMI.Next;
end;
Panel3.Visible:=True;
if DM.IBDCONFINUMEROCOMISION.IsNull then variNumdoc:=1
else variNumdoc:=(SoloInteger(DM.IBDCONFINUMEROCOMISION.AsString)+1);
if IbqCOMI.fieldbyname('RETENCIONES').IsNull then NSEDRetenciones.Value:=0
else NSEDRetenciones.Value:=IbqCOMI.fieldbyname('RETENCIONES').Value;
Label8.Caption:= IntToStr(VarINumDoc);
ListView1ColumnClick(Sender,ListView1.Columns.Items[1]);
PosiListView(ListView1,0);
calcular;
end else ShowMessage('No existen datos que poder introducir');
end else ShowMessage('No ha selelccionado el cliente');
end;
procedure TFCRECOMI.SpeedButton2Click(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Copiar 1 elemento ]****
//------------------------------------------------------------------------------
var Item, LI: TListItem;
begin
if ListView1.ItemIndex<>-1 then
begin
Item := ListView1.Items.Item[ListView1.ItemIndex];
LI:=ListView2.Items.Add;
LI.Caption:=Item.Caption;
LI.SubItems.Add(Item.SubItems[0]);
LI.SubItems.Add(Item.SubItems[1]);
LI.SubItems.Add(Item.SubItems[2]);
ListView1.Items.Delete(ListView1.ItemIndex);
ListView2ColumnClick(Sender,ListView2.Columns.Items[1]);
if ListView1.Items.Count>0 then ListView1.ItemIndex:=0
else
begin
ListView2.ItemIndex:=ListView2.Items.Count-1;
end;
calcular;
end;
end;
procedure TFCRECOMI.SpeedButton3Click(Sender: TObject);
//------------------------------------------------------------------------------
//*********************************************[ Copiar todos los elemento ]****
//------------------------------------------------------------------------------
var Item, LI: TListItem;
VarIContFor:Integer;
begin
if ListView1.ItemIndex<>-1 then
begin
for VarIContFor := 1 to ListView1.Items.Count do
begin
Item := ListView1.Items.Item[0];
LI:=ListView2.Items.Add;
LI.Caption:=Item.Caption;
LI.SubItems.Add(Item.SubItems[0]);
LI.SubItems.Add(Item.SubItems[1]);
LI.SubItems.Add(Item.SubItems[2]);
ListView1.Items.Delete(ListView1.ItemIndex);
if ListView1.Items.Count>0 then ListView1.ItemIndex:=0
else ListView2.ItemIndex:=ListView2.Items.Count-1;
end;
ListView2.ItemIndex:=0;
ListView2ColumnClick(Sender,ListView2.Columns.Items[1]);
calcular;
end;
end;
procedure TFCRECOMI.SpeedButton4Click(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Copiar 1 elemento ]****
//------------------------------------------------------------------------------
var Item, LI: TListItem;
begin
if ListView2.ItemIndex<>-1 then
begin
Item := ListView2.Items.Item[ListView2.ItemIndex];
LI:=ListView1.Items.Add;
LI.Caption:=Item.Caption;
LI.SubItems.Add(Item.SubItems[0]);
LI.SubItems.Add(Item.SubItems[1]);
LI.SubItems.Add(Item.SubItems[2]);
ListView2.Items.Delete(ListView2.ItemIndex);
ListView1ColumnClick(Sender,ListView1.Columns.Items[1]);
if ListView2.Items.Count>0 then ListView2.ItemIndex:=0
else
begin
ListView1.ItemIndex:=ListView1.Items.Count-1;
end;
calcular;
end;
end;
procedure TFCRECOMI.SpeedButton5Click(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************[ Copiar Todos los elementos ]****
//------------------------------------------------------------------------------
var Item, LI: TListItem;
varIcontFort:Integer;
begin
if ListView2.ItemIndex<>-1 then
begin
for varIcontFort := 1 to ListView2.Items.Count do
begin
Item := ListView2.Items.Item[0];
LI:=ListView1.Items.Add;
LI.Caption:=Item.Caption;
LI.SubItems.Add(Item.SubItems[0]);
LI.SubItems.Add(Item.SubItems[1]);
LI.SubItems.Add(Item.SubItems[2]);
ListView2.Items.Delete(ListView2.ItemIndex);
if ListView2.Items.Count>0 then ListView2.ItemIndex:=0
else ListView1.ItemIndex:=ListView1.Items.Count-1;
end;
ListView1.ItemIndex:=0;
ListView1ColumnClick(Sender,ListView1.Columns.Items[1]);
calcular;
end;
end;
procedure TFCRECOMI.SpeedButton6Click(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************************[ Grabar ]****
//------------------------------------------------------------------------------
var Item: TListItem;
VariCont3ForNotas,I:Integer;
VArRCalcIRPF, VarRSubTotal:Real;
begin
try
Memo1.Lines.Clear;
if ListView2.ItemIndex<>-1 then
begin
for VariCont3ForNotas := 0 to ListView2.Items.Count -1 do //Contador del listview
begin
Item := ListView2.Items.Item[VariCont3ForNotas];
if DSRCOMI.DataSet.Locate('CODIGOEMPLEADO;NUMERODOCUMENTO', VarArrayOf([Edit1.Text,Item.SubItems[0]]), [LoCaseInsensitive, LoPartialKey]) then //Buscamos el nº R.F, si no lo encuentra
begin
DSRCOMI.DataSet.Edit; //Editamos el registro
DSRCOMI.DataSet.FieldByName('PAGADAS').Value:='S';
DSRCOMI.DataSet.FieldByName('FECHAPAGO').Value:=DateTimePicker3.Date;
DSRCOMI.DataSet.FieldByName('NUMEROPAGO').Value:=Label8.Caption;
DSRCOMI.DataSet.FieldByName('RETENCIONES').Value:=NSEDRetenciones.Value;
if DSRCOMI.DataSet.State in [dsInsert, dsEdit] then DSRCOMI.DataSet.Post;
end;
end;
DM.IBDCONFI.Edit;
if DM.IBDCONFINUMEROCOMISION.IsNull then DM.IBDCONFINUMEROCOMISION.Value:=IntToStr(1)
else DM.IBDCONFINUMEROCOMISION.Value:=IntToStr(SoloInteger(DM.IBDCONFINUMEROCOMISION.value)+1);
if DM.IBDCONFI.State in [dsInsert, dsEdit] then DM.IBDCONFI.Post;
DM.IBTransaction1.commitRetaining;
if CheckBox1.Checked then
begin
if CheckBox2.Checked then VCLReport1.Preview:=True
else VCLReport1.Preview:=False;
//Calculamos la retención
VarRSubTotal:=StrToFloat(NumDecimalsStr(2,Edit2.Text));
VArRCalcIRPF:=Porcentaje(VarRSubTotal,NSEDRetenciones.Value);
//Imprimimos original
for I := 0 to SpinEdit1.Value -1 do
begin
//Reporte
end;
end;
Case Application.MessageBox(pchar('¿Desea crear un pago de comisiones nuevo o salir?'+#13#10+#13#10+'[ S I ] Crear uno nuevo'+#13#10+'[ NO ] Salir'),
pchar('El pago de comisiones se ha creado con exito'),MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2+MB_SYSTEMMODAL) of
IDYES:begin //Si
Panel3.Visible:=False;
SpeedButton11Click(SEnder);
Edit1.Text:='';
ActQuery(IbqCOMI,'select * from COMISIONES');
Edit1.SetFocus;
end;
IDNO: Begin //No
SB_SalirClick(Sender);
End;
end;
end;
except
on E: Exception do
begin
MessageBeep(1000);
ShowMessage(
'Se ha producido un error y el proceso no se ha podido terminar Unidad:[ UCRECOMI ] Modulo:[ Grabar ]'
+ Chr(13) + Chr(13) + 'Clase de error: ' + E.ClassName + Chr(13) + Chr(13)
+ 'Mensaje del error:' + E.Message + Chr(13) + Chr(13) + ' ' + Chr(13) + Chr(13)
+ 'El proceso ha quedado interrumpido');
if DSRCOMI.DataSet.State in [dsInsert,dsEdit] then DSRCOMI.DataSet.Cancel;
DM.IBTransaction1.RollbackRetaining;
end;
end;
end;
procedure TFCRECOMI.SpeedButton7Click(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************************[ Subir 1 ]****
// Sube 1 elemento en el listview
//------------------------------------------------------------------------------
begin
if ListView1.Selected.Index>0 then PosiListView(ListView1,ListView1.Selected.Index-1); //Este sube al elemento anterior
end;
procedure TFCRECOMI.SpeedButton8Click(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************************[ Bajar 1 ]****
// Baja 1 elemento en el listview
//------------------------------------------------------------------------------
begin
if ListView1.Selected.Index<ListView1.Items.Count-1 then PosiListView(ListView1,ListView1.Selected.Index+1); //Este baja al siguiente registro
end;
procedure TFCRECOMI.SpeedButton9Click(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************************[ Bajar 1 ]****
// Baja 1 elemento en el listview
//------------------------------------------------------------------------------
begin
if ListView2.Selected.Index<ListView2.Items.Count-1 then PosiListView(ListView2,ListView2.Selected.Index+1); //Este baja al siguiente registro
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment