This repository has been archived on 2024-12-02. You can view files and clone it, but cannot push or open issues or pull requests.
AlonsoYSal_FactuGES/Modulos/Contactos/Reglas/uBizComisiones.pas
2007-06-21 16:02:50 +00:00

207 lines
5.6 KiB
ObjectPascal

unit uBizComisiones;
interface
uses
uDAInterfaces, uDADataTable, schComisionesClient_Intf, Classes,
DBGrids, uDBSelectionList, DB, uExceptions, Controls;
const
BIZ_SELECCION = 'Client.Field.Seleccion';
BIZ_COBROSCOMISION = 'BizCobrosComision';
BIZ_VENDEDORESCOMISION = 'BizVendedoresComision';
type
IBizSeleccion = interface(IDAStronglyTypedDataTable)
['{E4CB36C8-4A41-4DDB-92DB-211517EB60DB}']
end;
IBizVendedoresComision = interface(IVendedoresComision)
['{4095FB35-E5FE-4C04-929A-480C29FC9436}']
procedure calcularComisiones(Total: Double);
end;
IBizCobrosComision = interface(ICobrosComision)
['{1CC63E18-6230-4421-96E8-26C011993F5C}']
function getVendedoresComision: IBizVendedoresComision;
procedure setVendedoresComision(const Value: IBizVendedoresComision);
property VendedoresComision: IBizVendedoresComision read getVendedoresComision
write setVendedoresComision;
function getTotal: Double;
procedure setTotal(const Value: Double);
property Total: Double read getTotal write setTotal;
function GetOnTotalChanged : TNotifyEvent;
procedure SetOnTotalChanged (const Value : TNotifyEvent);
property OnTotalChanged : TNotifyEvent read GetOnTotalChanged
write SetOnTotalChanged;
end;
TBizSeleccionFieldRules = class(TDAFieldRules)
protected
procedure OnChange(Sender: TDACustomField); override;
end;
TBizCobrosComisionDataTableRules = class(TCobrosComisionDataTableRules, IBizCobrosComision)
private
FVendedoresComision: IBizVendedoresComision;
FTotal: Double;
FOnTotalChanged : TNotifyEvent;
function getTotal: Double;
procedure setTotal(const Value: Double);
function GetOnTotalChanged: TNotifyEvent;
procedure SetOnTotalChanged(const Value: TNotifyEvent);
function getVendedoresComision: IBizVendedoresComision;
procedure setVendedoresComision(const Value: IBizVendedoresComision);
protected
procedure AfterOpen(Sender: TDADataTable); override;
public
property VendedoresComision: IBizVendedoresComision read getVendedoresComision
write setVendedoresComision;
property Total: Double read getTotal write setTotal;
property OnTotalChanged : TNotifyEvent read GetOnTotalChanged
write SetOnTotalChanged;
constructor Create(aDataTable: TDADataTable); override;
destructor Destroy; override;
end;
TBizVendedoresComisionDataTableRules = class(TVendedoresComisionDataTableRules, IBizVendedoresComision)
public
procedure calcularComisiones(Total: Double);
end;
implementation
uses
Windows, Dialogs, uDACDSDataTable, SysUtils, uDataModuleBase,
uEditorUtils, uDataModuleComisiones, Variants;
{ TBizCobrosComisionDataTableRules }
{
************************** TBizCobrosComisionDataTableRules **************************
}
procedure TBizCobrosComisionDataTableRules.AfterOpen(Sender: TDADataTable);
var
ldTotal : Double;
begin
inherited;
with (Sender as IBizCobrosComision) do
begin
DataTable.DisableControls;
ldTotal := 0;
First;
while not DataTable.Eof do
begin
ldTotal := ldTotal + IMPORTE;
Next;
end;
First;
Total := ldTotal;
DataTable.EnableControls;
end;
end;
constructor TBizCobrosComisionDataTableRules.Create(aDataTable: TDADataTable);
begin
inherited;
FVendedoresComision := Nil;
aDataTable.AfterOpen := AfterOpen;
end;
destructor TBizCobrosComisionDataTableRules.Destroy;
begin
FVendedoresComision := Nil;
inherited;
end;
function TBizCobrosComisionDataTableRules.GetOnTotalChanged: TNotifyEvent;
begin
Result := FOnTotalChanged;
end;
function TBizCobrosComisionDataTableRules.getTotal: Double;
begin
Result := FTotal;
end;
function TBizCobrosComisionDataTableRules.getVendedoresComision: IBizVendedoresComision;
begin
Result := FVendedoresComision;
end;
procedure TBizCobrosComisionDataTableRules.SetOnTotalChanged(const Value: TNotifyEvent);
begin
FOnTotalChanged := Value;
end;
procedure TBizCobrosComisionDataTableRules.setTotal(const Value: Double);
begin
FTotal := Value;
if Assigned(FOnTotalChanged) then
FOnTotalChanged(Self);
FVendedoresComision.CalcularComisiones(FTotal);
end;
{ TBizSeleccionFieldRules }
procedure TBizSeleccionFieldRules.OnChange(Sender: TDACustomField);
var
ACobrosComision : IBizCobrosComision;
begin
if Supports(DataTable, IBizCobrosComision, ACobrosComision) then
begin
if ACobrosComision.SELECCION = 1
then ACobrosComision.Total := ACobrosComision.Total + ACobrosComision.IMPORTE
else ACobrosComision.Total := ACobrosComision.Total - ACobrosComision.IMPORTE;
end;
end;
procedure TBizCobrosComisionDataTableRules.setVendedoresComision(const Value: IBizVendedoresComision);
begin
if Assigned(FVendedoresComision) then
FVendedoresComision := Nil;
FVendedoresComision := Value;
end;
{ TBizVendedoresComisionDataTableRules }
procedure TBizVendedoresComisionDataTableRules.calcularComisiones(Total: Double);
begin
with (Self as IBizVendedoresComision) do
begin
DataTable.DisableControls;
First;
while not DataTable.Eof do
begin
Edit;
COMISION := (Total * PORCENTAJE) / 100;
Post;
Next;
end;
First;
DataTable.EnableControls;
end;
end;
initialization
RegisterFieldRules(BIZ_SELECCION, TBizSeleccionFieldRules);
RegisterDataTableRules(BIZ_CobrosCOMISION, TBizCobrosComisionDataTableRules);
RegisterDataTableRules(BIZ_VENDEDORESCOMISION, TBizVendedoresComisionDataTableRules);
finalization
end.