246 lines
8.2 KiB
ObjectPascal
246 lines
8.2 KiB
ObjectPascal
|
|
unit uEditorFacturaCliente;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, uEditorDBItem, DB, uDADataTable, JvAppStorage,
|
|||
|
|
JvAppRegistryStorage, JvComponent, JvFormPlacement, ImgList,
|
|||
|
|
PngImageList, StdActns, ActnList, ComCtrls, TBX, TB2Item, TB2Dock,
|
|||
|
|
TB2Toolbar, ExtCtrls, JvExControls, JvNavigationPane,
|
|||
|
|
uViewFacturaCliente, uCustomView, uViewBase, uViewContenido, uViewTotales,
|
|||
|
|
StdCtrls, pngimage, AppEvnts,
|
|||
|
|
uBizFacturasCliente, uViewDetallesNormales, uViewDetallesFacturaCliente,
|
|||
|
|
uViewDetallesFamilias, dxLayoutLookAndFeels, JvComponentBase,
|
|||
|
|
dxLayoutControl;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
IEditorFacturaCliente = interface(IEditorDBItem)
|
|||
|
|
['{6989A930-FB5B-47E7-A836-7EEB8108128F}']
|
|||
|
|
function GetFacturaCliente: IBizFacturasCliente;
|
|||
|
|
procedure SetFacturaCliente(const Value: IBizFacturasCliente);
|
|||
|
|
property FacturaCliente: IBizFacturasCliente read GetFacturaCliente write
|
|||
|
|
SetFacturaCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TfEditorFacturaCliente = class(TfEditorDBItem, IEditorFacturaCliente)
|
|||
|
|
pagContenido: TTabSheet;
|
|||
|
|
frViewDetallesFacturaCliente1: TfrViewDetallesFacturaCliente;
|
|||
|
|
frViewFacturaCliente1: TfrViewFacturaCliente;
|
|||
|
|
TBXSeparatorItem14: TTBXSeparatorItem;
|
|||
|
|
TBXSubmenuItem2: TTBXSubmenuItem;
|
|||
|
|
TBXItem33: TTBXItem;
|
|||
|
|
frViewTotales1: TfrViewTotales;
|
|||
|
|
procedure actEliminarExecute(Sender: TObject);
|
|||
|
|
procedure dsDataTableDataChange(Sender: TObject; Field: TField);
|
|||
|
|
procedure FormShow(Sender: TObject); override;
|
|||
|
|
procedure frViewDatosYSeleccionContacto21edtlNombrePropertiesChange(Sender: TObject);
|
|||
|
|
procedure pgPaginasChanging(Sender: TObject; var AllowChange: Boolean);
|
|||
|
|
procedure frViewDatosFacturaCliente1eTipoPropertiesValidate(
|
|||
|
|
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|||
|
|
var Error: Boolean);
|
|||
|
|
private
|
|||
|
|
FFacturaCliente: IBizFacturasCliente;
|
|||
|
|
FViewFacturaCliente: IViewFacturaCliente;
|
|||
|
|
protected
|
|||
|
|
function GetFacturaCliente: IBizFacturasCliente;
|
|||
|
|
function GetViewFactura: IViewFacturaCliente;
|
|||
|
|
procedure SetFacturaCliente(const Value: IBizFacturasCliente); virtual;
|
|||
|
|
procedure SetViewFactura(const Value: IViewFacturaCliente);
|
|||
|
|
property ViewFacturaCliente: IViewFacturaCliente read GetViewFactura write
|
|||
|
|
SetViewFactura;
|
|||
|
|
public
|
|||
|
|
constructor Create(AOwner: TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
property FacturaCliente: IBizFacturasCliente read GetFacturaCliente write
|
|||
|
|
SetFacturaCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
var
|
|||
|
|
fEditorFacturaCliente: TfEditorFacturaCliente;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses uEditorUtils, uDataModuleFacturasCliente, uBizImportesDetalleBase,
|
|||
|
|
schFacturasClienteClient_Intf, uExceptions, LiteralesFacturasCliente,
|
|||
|
|
cxImageComboBox, cxDBEdit;
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
function ShowEditorFacturaCliente (ABizObject : TDADataTableRules) : TModalResult;
|
|||
|
|
var
|
|||
|
|
AEditor: TfEditorFacturaCliente;
|
|||
|
|
begin
|
|||
|
|
AEditor := TfEditorFacturaCliente.Create(Application);
|
|||
|
|
try
|
|||
|
|
AEditor.FacturaCliente := (ABizObject as IBizFacturasCliente);
|
|||
|
|
Result := AEditor.ShowModal;
|
|||
|
|
finally
|
|||
|
|
AEditor.Release;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
{ TfEditorFacturaCliente }
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
**************************** TfEditorFacturaCliente ****************************
|
|||
|
|
}
|
|||
|
|
constructor TfEditorFacturaCliente.Create(AOwner: TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
// ViewFacturaCliente := CreateView(TfrViewFacturaCliente) as IViewFacturaCliente;
|
|||
|
|
pgPaginas.ActivePageIndex := 0;
|
|||
|
|
ViewFacturaCliente := frViewFacturaCliente1;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TfEditorFacturaCliente.Destroy;
|
|||
|
|
begin
|
|||
|
|
FViewFacturaCliente := NIL;
|
|||
|
|
FFacturaCliente := NIL;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.actEliminarExecute(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
if (Application.MessageBox(PChar(msgLitBorrar), 'Atenci<63>n', MB_YESNO) = IDYES) then
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.dsDataTableDataChange(Sender: TObject; Field:
|
|||
|
|
TField);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if Assigned(FFacturaCliente) and (not (FFacturaCliente.DataTable.Fetching) or
|
|||
|
|
not (FFacturaCliente.DataTable.Opening) or not (FFacturaCliente.DataTable.Closing)) then
|
|||
|
|
begin
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.FormShow(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if not Assigned(FViewFacturaCliente) then
|
|||
|
|
raise Exception.Create('No hay ninguna vista asignada');
|
|||
|
|
|
|||
|
|
if not Assigned(FacturaCliente) then
|
|||
|
|
raise Exception.Create('No hay ning<6E>n albar<61>n asignado');
|
|||
|
|
|
|||
|
|
FacturaCliente.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
// FViewFacturaCliente.ShowEmbedded(pagGeneral);
|
|||
|
|
// FViewFacturaCliente.SetFocus;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorFacturaCliente.GetFacturaCliente: IBizFacturasCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FFacturaCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorFacturaCliente.GetViewFactura: IViewFacturaCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FViewFacturaCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.SetFacturaCliente(const Value:
|
|||
|
|
IBizFacturasCliente);
|
|||
|
|
begin
|
|||
|
|
FFacturaCliente := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FFacturaCliente) then
|
|||
|
|
begin
|
|||
|
|
dsDataTable.DataTable := FFacturaCliente.DataTable;
|
|||
|
|
frViewTotales1.DADataSource.DataTable := FFacturaCliente.DataTable;
|
|||
|
|
frViewDetallesFacturaCliente1.DADataSource.DataTable := FFacturaCliente.Detalles.DataTable;
|
|||
|
|
|
|||
|
|
if Assigned(FViewFacturaCliente) then
|
|||
|
|
FViewFacturaCliente.FacturaCliente := FFacturaCliente;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.SetViewFactura(const Value:
|
|||
|
|
IViewFacturaCliente);
|
|||
|
|
begin
|
|||
|
|
FViewFacturaCliente := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FViewFacturaCliente) and Assigned(FacturaCliente) then
|
|||
|
|
FViewFacturaCliente.FacturaCliente := FacturaCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.frViewDatosYSeleccionContacto21edtlNombrePropertiesChange(
|
|||
|
|
Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if Length(frViewFacturaCliente1.frViewDatosYSeleccionContacto21.edtlNombre.Text) = 0 then
|
|||
|
|
JvNavPanelHeader.Caption := 'Nueva factura de cliente'
|
|||
|
|
else
|
|||
|
|
JvNavPanelHeader.Caption := 'Factura de ' + frViewFacturaCliente1.frViewDatosYSeleccionContacto21.edtlNombre.Text;
|
|||
|
|
Caption := JvNavPanelHeader.Caption;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.pgPaginasChanging(Sender: TObject; var AllowChange: Boolean);
|
|||
|
|
begin
|
|||
|
|
if (FFacturaCliente.Cliente.NOMBRE = '') then
|
|||
|
|
begin
|
|||
|
|
AllowChange := False;
|
|||
|
|
showmessage(msgLitClienteObligatorio);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturaCliente.frViewDatosFacturaCliente1eTipoPropertiesValidate(
|
|||
|
|
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|||
|
|
var Error: Boolean);
|
|||
|
|
var
|
|||
|
|
i : Integer;
|
|||
|
|
ClaseFacturaAntes: String;
|
|||
|
|
ClaseFacturaDespues: String;
|
|||
|
|
begin
|
|||
|
|
with (Sender as TcxDBImageComboBox).Properties.Items do
|
|||
|
|
begin
|
|||
|
|
i := 0;
|
|||
|
|
while (Items[i].Description <> DisplayValue) do
|
|||
|
|
inc(i);
|
|||
|
|
|
|||
|
|
ClaseFacturaAntes := FacturaCliente.CLASEFACTURA;
|
|||
|
|
ClaseFacturaDespues := Items[i].Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
//Para establecer si se ve o no situaci<63>n de factura
|
|||
|
|
if (ClaseFacturaDespues = CTE_PROFORMA)
|
|||
|
|
then frViewFacturaCliente1.frViewDatosFacturaCliente1.dxLayoutControl1Item12.Visible := false
|
|||
|
|
else frViewFacturaCliente1.frViewDatosFacturaCliente1.dxLayoutControl1Item12.Visible := true;
|
|||
|
|
|
|||
|
|
//CAMBIO DE SIGNO DE LA FACTURA
|
|||
|
|
if (ClaseFacturaDespues = CTE_ABONO) then
|
|||
|
|
FacturaCliente.cambiarSigno
|
|||
|
|
else if (ClaseFacturaAntes = CTE_ABONO) then
|
|||
|
|
FacturaCliente.cambiarSigno;
|
|||
|
|
|
|||
|
|
//CAMBIO DE REFERENCIA
|
|||
|
|
//En el caso de cabiar una factura proforma a normal o abono se le debe asignar
|
|||
|
|
//una referencia nueva, y viceversa
|
|||
|
|
if (ClaseFacturaDespues = CTE_PROFORMA) then
|
|||
|
|
begin
|
|||
|
|
FacturaCliente.setReferencia(ClaseFacturaDespues);
|
|||
|
|
showmessage(msgLitCambioReferencia)
|
|||
|
|
end
|
|||
|
|
//En caso de que el tipo anterior no sea proforma no se cambia ya que de normal
|
|||
|
|
//a abono y al rev<65>s no se requiere la reasignacion de referencia
|
|||
|
|
else if (ClaseFacturaAntes = CTE_PROFORMA) then
|
|||
|
|
begin
|
|||
|
|
FacturaCliente.setReferencia(ClaseFacturaDespues);
|
|||
|
|
showmessage(msgLitCambioReferencia)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
//Importante no tocar ya que si no salimos no coge el nuevo valor y falla en
|
|||
|
|
//el siguiente cambio que se produzca
|
|||
|
|
// frViewFacturaCliente1.frViewDatosFacturaCliente1.eReferencia.SetFocus;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
initialization
|
|||
|
|
RegisterEditor(IBizFacturasCliente, ShowEditorFacturaCliente, etItem);
|
|||
|
|
|
|||
|
|
finalization
|
|||
|
|
|
|||
|
|
end.
|