#12 -> Enviar documentos por correo electrónico. Presupuestos y facturas de cliente.

git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@530 0c75b7a4-871f-7646-8a2f-f78d34cc349f
This commit is contained in:
David Arranz 2008-08-25 11:08:44 +00:00
parent fefc254f1b
commit eba6454bce
10 changed files with 1567 additions and 120 deletions

View File

@ -40,7 +40,6 @@ function DarFicheroPDFTemporal(const AFileName : String) : String; overload;
function DarVersionFichero (Executable : String) : String; function DarVersionFichero (Executable : String) : String;
function DarFechaFichero (Executable : String) : String; function DarFechaFichero (Executable : String) : String;
procedure CopiarFichero(const Origen, Destino: string); procedure CopiarFichero(const Origen, Destino: string);
procedure DoDelTree( TheDir : String);
procedure Deltree(DirToKill : String; KillChoosenDir : Boolean); procedure Deltree(DirToKill : String; KillChoosenDir : Boolean);
function GetSpecialFolderPath(folder : integer) : string; function GetSpecialFolderPath(folder : integer) : string;
function PreguntarRuta(const ATitulo: String; const AComentario: String; var ARuta: String): Boolean; function PreguntarRuta(const ATitulo: String; const AComentario: String; var ARuta: String): Boolean;
@ -160,7 +159,7 @@ var
begin begin
if not EsCadenaVacia(AFileName) then if not EsCadenaVacia(AFileName) then
begin begin
RutaTmp := DarRutaTemporal + PathDelim; RutaTmp := DarRutaTemporal;
Cadena := ExtractFileName(AFileName); Cadena := ExtractFileName(AFileName);
Cadena := StringReplace(Cadena, ExtractFileExt(Cadena), '', []); Cadena := StringReplace(Cadena, ExtractFileExt(Cadena), '', []);
Result := RutaTmp + Cadena + '.pdf'; Result := RutaTmp + Cadena + '.pdf';

View File

@ -81,7 +81,6 @@ inherited fDialogElegirEMail: TfDialogElegirEMail
Top = 39 Top = 39
Properties.UsePrefix = upNever Properties.UsePrefix = upNever
Properties.ValidateOnEnter = True Properties.ValidateOnEnter = True
Properties.OnValidate = edtEMailPropertiesValidate
Properties.Prefix = '' Properties.Prefix = ''
Style.LookAndFeel.Kind = lfStandard Style.LookAndFeel.Kind = lfStandard
Style.LookAndFeel.NativeStyle = True Style.LookAndFeel.NativeStyle = True

View File

@ -22,8 +22,6 @@ type
procedure rbComboClick(Sender: TObject); procedure rbComboClick(Sender: TObject);
procedure rbEditClick(Sender: TObject); procedure rbEditClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure edtEMailPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
@ -92,17 +90,9 @@ begin
cbEMail.Enabled := True; cbEMail.Enabled := True;
edtEMail.Enabled := False; edtEMail.Enabled := False;
rbEdit.Checked := False; rbEdit.Checked := False;
end; end
end; else
end; rbEdit.Checked := True;
procedure TfDialogElegirEMail.edtEMailPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
if not VarIsNull(DisplayValue) then
begin
Error := not IsValidEmail(DisplayValue);
ErrorText := 'La dirección de correo electrónica no es válida. Compruebe que está bien escrita.';
end; end;
end; end;
@ -110,12 +100,24 @@ procedure TfDialogElegirEMail.FormCloseQuery(Sender: TObject;
var CanClose: Boolean); var CanClose: Boolean);
begin begin
inherited; inherited;
if (ModalResult = mrOk) and rbEdit.Checked and EsCadenaVacia(edtEMail.Text) then
if (ModalResult = mrOk) and rbEdit.Checked then
begin begin
if not EsCadenaVacia(edtEMail.Text) then
begin
if not IsValidEmail(edtEMail.Text) then
begin
ShowErrorMessage('Elegir dirección de correo electrónico', 'La dirección de correo electrónica no es válida. Compruebe que está bien escrita.');
edtEMail.SetFocus;
CanClose := False;
end;
end
else begin
ShowErrorMessage('Elegir dirección de correo electrónico', 'Debe indicar una dirección de correo electrónico.'); ShowErrorMessage('Elegir dirección de correo electrónico', 'Debe indicar una dirección de correo electrónico.');
edtEMail.SetFocus; edtEMail.SetFocus;
CanClose := False; CanClose := False;
end; end;
end;
end; end;
procedure TfDialogElegirEMail.FormCreate(Sender: TObject); procedure TfDialogElegirEMail.FormCreate(Sender: TObject);
@ -140,10 +142,8 @@ begin
begin begin
rbCombo.Enabled := False; rbCombo.Enabled := False;
rbEdit.Checked; rbEdit.Checked;
end; end
else begin
if cbEMail.Items.Count > 0 then
begin
cbEMail.ItemIndex := 0; cbEMail.ItemIndex := 0;
rbCombo.Checked := True; rbCombo.Checked := True;
end; end;

View File

@ -48,6 +48,7 @@ type
function ElegirFacturas(AFacturas : IBizFacturaCliente; AMensaje: String; AMultiSelect: Boolean): IBizFacturaCliente; function ElegirFacturas(AFacturas : IBizFacturaCliente; AMensaje: String; AMultiSelect: Boolean): IBizFacturaCliente;
function ExtraerSeleccionados(ARecibosCliente: IBizFacturaCliente) : IBizFacturaCliente; function ExtraerSeleccionados(ARecibosCliente: IBizFacturaCliente) : IBizFacturaCliente;
procedure EnviarFacturaPorEMail(AFactura : IBizFacturaCliente);
end; end;
TFacturasClienteController = class(TControllerBase, IFacturasClienteController) TFacturasClienteController = class(TControllerBase, IFacturasClienteController)
@ -106,6 +107,7 @@ type
function ElegirFacturas(AFacturas : IBizFacturaCliente; AMensaje: String; AMultiSelect: Boolean): IBizFacturaCliente; function ElegirFacturas(AFacturas : IBizFacturaCliente; AMensaje: String; AMultiSelect: Boolean): IBizFacturaCliente;
function ExtraerSeleccionados(AFacturasCliente: IBizFacturaCliente) : IBizFacturaCliente; function ExtraerSeleccionados(AFacturasCliente: IBizFacturaCliente) : IBizFacturaCliente;
procedure EnviarFacturaPorEMail(AFactura : IBizFacturaCliente);
end; end;
implementation implementation
@ -118,7 +120,8 @@ uses
uAlbaranesClienteController, schAlbaranesClienteClient_Intf, uROTypes, uDetallesAlbaranClienteController, uAlbaranesClienteController, schAlbaranesClienteClient_Intf, uROTypes, uDetallesAlbaranClienteController,
uBizDetallesAlbaranCliente, uFacturasClienteReportController, uBizDetallesAlbaranCliente, uFacturasClienteReportController,
DateUtils, Forms, uFormasPagoController, uBizFormasPago, uIEditorElegirFacturasCliente, DateUtils, Forms, uFormasPagoController, uBizFormasPago, uIEditorElegirFacturasCliente,
uRecibosClienteController, uBizRecibosCliente, uIntegerListUtils; uRecibosClienteController, uBizRecibosCliente, uIntegerListUtils,
uSistemaFunc, uDialogElegirEMail, uEMailUtils;
{procedure CopiarArticulosPedido(AOrigen: IBizDetallesPedidoCliente; {procedure CopiarArticulosPedido(AOrigen: IBizDetallesPedidoCliente;
@ -727,6 +730,50 @@ begin
end; end;
end; end;
procedure TFacturasClienteController.EnviarFacturaPorEMail(
AFactura: IBizFacturaCliente);
var
AReportController : IFacturasClienteReportController;
AFicheroTMP : TFileName;
AEMail : String;
AListaEmail : TStringList;
begin
if not Assigned(AFactura) then
raise Exception.Create ('Factura no asignado (EnviarFacturaPorEMail)');
if AFactura.DataTable.Active then
AFactura.DataTable.Active := True;
AFicheroTMP := DarFicheroPDFTemporal(EscapeIllegalChars(AFactura.REFERENCIA));
AListaEmail := TStringList.Create;
try
RecuperarCliente(AFactura);
AFactura.Cliente.DataTable.Active := True;
if not AFactura.Cliente.EMAIL_1IsNull then
AListaEmail.Add(AFactura.Cliente.EMAIL_1);
if not AFactura.Cliente.EMAIL_2IsNull then
AListaEmail.Add(AFactura.Cliente.EMAIL_2);
if not ElegirEMail(AListaEmail, AEMail) then
Exit;
finally
FreeANDNIL(AListaEmail);
end;
ShowHourglassCursor;
AReportController := TFacturasClienteReportController.Create;
try
AReportController.ExportToPDF(AFactura.ID, AFicheroTMP);
SendMailMAPI('Factura ' + AFactura.REFERENCIA, '', AFicheroTMP, '', '', AFactura.Cliente.NOMBRE, AEMail);
finally
SysUtils.DeleteFile(AFicheroTMP);
AReportController := NIL;
HideHourglassCursor;
end;
end;
function TFacturasClienteController.EsEliminable(AFactura: IBizFacturaCliente): Boolean; function TFacturasClienteController.EsEliminable(AFactura: IBizFacturaCliente): Boolean;
begin begin
Result := EsModificable(AFactura); Result := EsModificable(AFactura);

View File

@ -13,6 +13,7 @@ type
procedure Preview(const AListaID : TIntegerList); procedure Preview(const AListaID : TIntegerList);
procedure Print(const AListaID : TIntegerList); procedure Print(const AListaID : TIntegerList);
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean; function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end; end;
TFacturasClienteReportController = class(TControllerBase, IFacturasClienteReportController) TFacturasClienteReportController = class(TControllerBase, IFacturasClienteReportController)
@ -27,6 +28,7 @@ type
procedure Preview(const AListaID : TIntegerList); procedure Preview(const AListaID : TIntegerList);
procedure Print(const AListaID : TIntegerList); procedure Print(const AListaID : TIntegerList);
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean; function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end; end;
@ -57,6 +59,29 @@ begin
inherited; inherited;
end; end;
function TFacturasClienteReportController.ExportToPDF(const AID: Integer;
const AFileName: String): Boolean;
var
AStream: Binary;
begin
Result := False;
if EsCadenaVacia(AFileName) then
Exit;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptPDFFactura(AID);
try
AStream.SaveToFile(AFileName);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
function TFacturasClienteReportController.ExportToWord(const AID: Integer; function TFacturasClienteReportController.ExportToWord(const AID: Integer;
const AFileName: String): Boolean; const AFileName: String): Boolean;
var var

View File

@ -25,6 +25,11 @@ type
frViewFacturaCliente1: TfrViewFacturaCliente; frViewFacturaCliente1: TfrViewFacturaCliente;
frViewTotales1: TfrViewTotales; frViewTotales1: TfrViewTotales;
frViewDetallesFacturaCliente1: TfrViewDetallesFacturaCliente; frViewDetallesFacturaCliente1: TfrViewDetallesFacturaCliente;
actEnviarEMail: TAction;
TBXSeparatorItem6: TTBXSeparatorItem;
TBXItem7: TTBXItem;
TBXSubmenuItem2: TTBXSubmenuItem;
TBXItem33: TTBXItem;
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure frViewClienteFactura1edtlNombrePropertiesEditValueChanged(Sender: TObject); procedure frViewClienteFactura1edtlNombrePropertiesEditValueChanged(Sender: TObject);
procedure dsDataTableDataChange(Sender: TObject; Field: TField); procedure dsDataTableDataChange(Sender: TObject; Field: TField);
@ -40,6 +45,8 @@ type
procedure frViewTotales1ePortePropertiesValidate(Sender: TObject; procedure frViewTotales1ePortePropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
procedure frViewTotales1ePorteEditing(Sender: TObject; var CanEdit: Boolean); procedure frViewTotales1ePorteEditing(Sender: TObject; var CanEdit: Boolean);
procedure actEnviarEMailExecute(Sender: TObject);
procedure actEnviarEMailUpdate(Sender: TObject);
private private
procedure RecalcularPortePorUnidad; procedure RecalcularPortePorUnidad;
@ -91,6 +98,18 @@ uses
**************************** TfEditorFacturaCliente **************************** **************************** TfEditorFacturaCliente ****************************
} }
procedure TfEditorFacturaCliente.actEnviarEMailExecute(Sender: TObject);
begin
inherited;
FController.EnviarFacturaPorEMail(Factura);
end;
procedure TfEditorFacturaCliente.actEnviarEMailUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Enabled := HayDatos;
end;
constructor TfEditorFacturaCliente.Create(AOwner: TComponent); constructor TfEditorFacturaCliente.Create(AOwner: TComponent);
begin begin
inherited; inherited;

View File

@ -1,17 +1,17 @@
inherited fEditorFacturasCliente: TfEditorFacturasCliente inherited fEditorFacturasCliente: TfEditorFacturasCliente
Caption = 'Lista de facturas de cliente' Caption = 'Lista de facturas de cliente'
ClientHeight = 666 ClientHeight = 666
ClientWidth = 640 ClientWidth = 842
ExplicitWidth = 648 ExplicitWidth = 850
ExplicitHeight = 700 ExplicitHeight = 700
PixelsPerInch = 96 PixelsPerInch = 96
TextHeight = 13 TextHeight = 13
inherited JvNavPanelHeader: TJvNavPanelHeader inherited JvNavPanelHeader: TJvNavPanelHeader
Width = 640 Width = 842
Caption = 'Lista de facturas de cliente' Caption = 'Lista de facturas de cliente'
ExplicitWidth = 640 ExplicitWidth = 640
inherited Image1: TImage inherited Image1: TImage
Left = 613 Left = 815
Picture.Data = { Picture.Data = {
0A54504E474F626A65637489504E470D0A1A0A0000000D494844520000001800 0A54504E474F626A65637489504E470D0A1A0A0000000D494844520000001800
0000180806000000E0773DF80000000970485973000017120000171201679FD2 0000180806000000E0773DF80000000970485973000017120000171201679FD2
@ -35,10 +35,10 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
end end
end end
inherited TBXDock: TTBXDock inherited TBXDock: TTBXDock
Width = 640 Width = 842
ExplicitWidth = 640 ExplicitWidth = 640
inherited tbxMain: TTBXToolbar inherited tbxMain: TTBXToolbar
ExplicitWidth = 640 ExplicitWidth = 842
object TBXSubmenuItem2: TTBXSubmenuItem [0] object TBXSubmenuItem2: TTBXSubmenuItem [0]
Caption = 'Nuevo' Caption = 'Nuevo'
DisplayMode = nbdmImageAndText DisplayMode = nbdmImageAndText
@ -56,21 +56,25 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
inherited TBXItem2: TTBXItem inherited TBXItem2: TTBXItem
Visible = False Visible = False
end end
object TBXItem40: TTBXItem [14]
Action = actEnviarEMail
DisplayMode = nbdmImageAndText
end
end end
inherited tbxMenu: TTBXToolbar inherited tbxMenu: TTBXToolbar
ExplicitWidth = 640 ExplicitWidth = 842
end end
end end
inherited StatusBar: TJvStatusBar inherited StatusBar: TJvStatusBar
Top = 647 Top = 647
Width = 640 Width = 842
ExplicitTop = 647 ExplicitTop = 647
ExplicitWidth = 640 ExplicitWidth = 640
end end
inline frViewFacturasCliente1: TfrViewFacturasCliente [3] inline frViewFacturasCliente1: TfrViewFacturasCliente [3]
Left = 0 Left = 0
Top = 102 Top = 102
Width = 640 Width = 842
Height = 545 Height = 545
Align = alClient Align = alClient
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
@ -85,7 +89,7 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
ExplicitWidth = 640 ExplicitWidth = 640
ExplicitHeight = 545 ExplicitHeight = 545
inherited cxGrid: TcxGrid inherited cxGrid: TcxGrid
Width = 640 Width = 842
Height = 417 Height = 417
ExplicitWidth = 640 ExplicitWidth = 640
ExplicitHeight = 417 ExplicitHeight = 417
@ -125,12 +129,12 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
end end
end end
inherited frViewFiltroBase1: TfrViewFiltroBase inherited frViewFiltroBase1: TfrViewFiltroBase
Width = 640 Width = 842
ExplicitWidth = 640 ExplicitWidth = 640
inherited TBXDockablePanel1: TTBXDockablePanel inherited TBXDockablePanel1: TTBXDockablePanel
ExplicitWidth = 640 ExplicitWidth = 640
inherited dxLayoutControl1: TdxLayoutControl inherited dxLayoutControl1: TdxLayoutControl
Width = 640 Width = 842
ExplicitWidth = 640 ExplicitWidth = 640
inherited txtFiltroTodo: TcxTextEdit inherited txtFiltroTodo: TcxTextEdit
ExplicitWidth = 600 ExplicitWidth = 600
@ -154,10 +158,10 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
end end
end end
inherited TBXAlignmentPanel1: TTBXAlignmentPanel inherited TBXAlignmentPanel1: TTBXAlignmentPanel
Width = 640 Width = 842
ExplicitWidth = 640 ExplicitWidth = 640
inherited tbxBotones: TTBXToolbar inherited tbxBotones: TTBXToolbar
Width = 630 Width = 832
ExplicitWidth = 630 ExplicitWidth = 630
end end
end end
@ -168,10 +172,10 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
ExplicitTop = 519 ExplicitTop = 519
ExplicitWidth = 640 ExplicitWidth = 640
inherited TBXAlignmentPanel1: TTBXAlignmentPanel inherited TBXAlignmentPanel1: TTBXAlignmentPanel
Width = 640 Width = 842
ExplicitWidth = 640 ExplicitWidth = 640
inherited TBXToolbar1: TTBXToolbar inherited TBXToolbar1: TTBXToolbar
Width = 630 Width = 832
ExplicitWidth = 630 ExplicitWidth = 630
end end
end end
@ -218,6 +222,12 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
ImageIndex = 24 ImageIndex = 24
OnExecute = actNuevoAbonoExecute OnExecute = actNuevoAbonoExecute
end end
object actEnviarEMail: TAction
Category = 'Acciones'
Caption = 'Enviar por e-mail...'
OnExecute = actEnviarEMailExecute
OnUpdate = actEnviarEMailUpdate
end
end end
inherited SmallImages: TPngImageList [5] inherited SmallImages: TPngImageList [5]
PngImages = < PngImages = <
@ -1777,6 +1787,9 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
'Cambiar la situaci'#243'n de la factura seleccionada (Pendiente/Pagad' + 'Cambiar la situaci'#243'n de la factura seleccionada (Pendiente/Pagad' +
'a)' 'a)'
end end
object Enviarporemail1: TMenuItem [11]
Action = actEnviarEMail
end
end end
object JsNuevaFacturaDialog: TJSDialog object JsNuevaFacturaDialog: TJSDialog
Content.Strings = ( Content.Strings = (

View File

@ -40,10 +40,15 @@ type
actNuevoAbono: TAction; actNuevoAbono: TAction;
JsNuevoAbonoDialog: TJSDialog; JsNuevoAbonoDialog: TJSDialog;
JsListaFacturasNoEliminadas: TJSDialog; JsListaFacturasNoEliminadas: TJSDialog;
actEnviarEMail: TAction;
TBXItem40: TTBXItem;
Enviarporemail1: TMenuItem;
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure actEliminarUpdate(Sender: TObject); procedure actEliminarUpdate(Sender: TObject);
procedure actNuevaFacturaExecute(Sender: TObject); procedure actNuevaFacturaExecute(Sender: TObject);
procedure actNuevoAbonoExecute(Sender: TObject); procedure actNuevoAbonoExecute(Sender: TObject);
procedure actEnviarEMailUpdate(Sender: TObject);
procedure actEnviarEMailExecute(Sender: TObject);
private private
FFacturas: IBizFacturaCliente; FFacturas: IBizFacturaCliente;
FController : IFacturasClienteController; FController : IFacturasClienteController;
@ -88,6 +93,22 @@ begin
(Sender as TAction).Enabled := (FFacturas.SITUACION = 'PENDIENTE'); (Sender as TAction).Enabled := (FFacturas.SITUACION = 'PENDIENTE');
end; end;
procedure TfEditorFacturasCliente.actEnviarEMailExecute(Sender: TObject);
begin
inherited;
FController.EnviarFacturaPorEMail(FFacturas);
end;
procedure TfEditorFacturasCliente.actEnviarEMailUpdate(Sender: TObject);
begin
inherited;
if HayDatos and Assigned(ViewGrid) then
(Sender as TAction).Enabled := ViewGrid.esSeleccionCeldaDatos
and (ViewGrid.NumSeleccionados > 0)
else
(Sender as TAction).Enabled := False;
end;
procedure TfEditorFacturasCliente.actNuevaFacturaExecute(Sender: TObject); procedure TfEditorFacturasCliente.actNuevaFacturaExecute(Sender: TObject);
begin begin
actNuevo.Execute; actNuevo.Execute;

View File

@ -612,6 +612,9 @@ begin
AListaEmail := TStringList.Create; AListaEmail := TStringList.Create;
try try
RecuperarCliente(APresupuesto);
APresupuesto.Cliente.DataTable.Active := True;
if not APresupuesto.Cliente.EMAIL_1IsNull then if not APresupuesto.Cliente.EMAIL_1IsNull then
AListaEmail.Add(APresupuesto.Cliente.EMAIL_1); AListaEmail.Add(APresupuesto.Cliente.EMAIL_1);
if not APresupuesto.Cliente.EMAIL_2IsNull then if not APresupuesto.Cliente.EMAIL_2IsNull then