#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:
parent
fefc254f1b
commit
eba6454bce
@ -40,7 +40,6 @@ function DarFicheroPDFTemporal(const AFileName : String) : String; overload;
|
||||
function DarVersionFichero (Executable : String) : String;
|
||||
function DarFechaFichero (Executable : String) : String;
|
||||
procedure CopiarFichero(const Origen, Destino: string);
|
||||
procedure DoDelTree( TheDir : String);
|
||||
procedure Deltree(DirToKill : String; KillChoosenDir : Boolean);
|
||||
function GetSpecialFolderPath(folder : integer) : string;
|
||||
function PreguntarRuta(const ATitulo: String; const AComentario: String; var ARuta: String): Boolean;
|
||||
@ -160,7 +159,7 @@ var
|
||||
begin
|
||||
if not EsCadenaVacia(AFileName) then
|
||||
begin
|
||||
RutaTmp := DarRutaTemporal + PathDelim;
|
||||
RutaTmp := DarRutaTemporal;
|
||||
Cadena := ExtractFileName(AFileName);
|
||||
Cadena := StringReplace(Cadena, ExtractFileExt(Cadena), '', []);
|
||||
Result := RutaTmp + Cadena + '.pdf';
|
||||
|
||||
@ -81,7 +81,6 @@ inherited fDialogElegirEMail: TfDialogElegirEMail
|
||||
Top = 39
|
||||
Properties.UsePrefix = upNever
|
||||
Properties.ValidateOnEnter = True
|
||||
Properties.OnValidate = edtEMailPropertiesValidate
|
||||
Properties.Prefix = ''
|
||||
Style.LookAndFeel.Kind = lfStandard
|
||||
Style.LookAndFeel.NativeStyle = True
|
||||
|
||||
@ -22,8 +22,6 @@ type
|
||||
procedure rbComboClick(Sender: TObject);
|
||||
procedure rbEditClick(Sender: TObject);
|
||||
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 FormDestroy(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
@ -92,17 +90,9 @@ begin
|
||||
cbEMail.Enabled := True;
|
||||
edtEMail.Enabled := False;
|
||||
rbEdit.Checked := False;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
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
|
||||
else
|
||||
rbEdit.Checked := True;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -110,11 +100,23 @@ procedure TfDialogElegirEMail.FormCloseQuery(Sender: TObject;
|
||||
var CanClose: Boolean);
|
||||
begin
|
||||
inherited;
|
||||
if (ModalResult = mrOk) and rbEdit.Checked and EsCadenaVacia(edtEMail.Text) then
|
||||
|
||||
if (ModalResult = mrOk) and rbEdit.Checked then
|
||||
begin
|
||||
ShowErrorMessage('Elegir dirección de correo electrónico', 'Debe indicar una dirección de correo electrónico.');
|
||||
edtEMail.SetFocus;
|
||||
CanClose := False;
|
||||
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.');
|
||||
edtEMail.SetFocus;
|
||||
CanClose := False;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -140,10 +142,8 @@ begin
|
||||
begin
|
||||
rbCombo.Enabled := False;
|
||||
rbEdit.Checked;
|
||||
end;
|
||||
|
||||
if cbEMail.Items.Count > 0 then
|
||||
begin
|
||||
end
|
||||
else begin
|
||||
cbEMail.ItemIndex := 0;
|
||||
rbCombo.Checked := True;
|
||||
end;
|
||||
|
||||
@ -48,6 +48,7 @@ type
|
||||
|
||||
function ElegirFacturas(AFacturas : IBizFacturaCliente; AMensaje: String; AMultiSelect: Boolean): IBizFacturaCliente;
|
||||
function ExtraerSeleccionados(ARecibosCliente: IBizFacturaCliente) : IBizFacturaCliente;
|
||||
procedure EnviarFacturaPorEMail(AFactura : IBizFacturaCliente);
|
||||
end;
|
||||
|
||||
TFacturasClienteController = class(TControllerBase, IFacturasClienteController)
|
||||
@ -106,6 +107,7 @@ type
|
||||
|
||||
function ElegirFacturas(AFacturas : IBizFacturaCliente; AMensaje: String; AMultiSelect: Boolean): IBizFacturaCliente;
|
||||
function ExtraerSeleccionados(AFacturasCliente: IBizFacturaCliente) : IBizFacturaCliente;
|
||||
procedure EnviarFacturaPorEMail(AFactura : IBizFacturaCliente);
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -118,7 +120,8 @@ uses
|
||||
uAlbaranesClienteController, schAlbaranesClienteClient_Intf, uROTypes, uDetallesAlbaranClienteController,
|
||||
uBizDetallesAlbaranCliente, uFacturasClienteReportController,
|
||||
DateUtils, Forms, uFormasPagoController, uBizFormasPago, uIEditorElegirFacturasCliente,
|
||||
uRecibosClienteController, uBizRecibosCliente, uIntegerListUtils;
|
||||
uRecibosClienteController, uBizRecibosCliente, uIntegerListUtils,
|
||||
uSistemaFunc, uDialogElegirEMail, uEMailUtils;
|
||||
|
||||
|
||||
{procedure CopiarArticulosPedido(AOrigen: IBizDetallesPedidoCliente;
|
||||
@ -727,6 +730,50 @@ begin
|
||||
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;
|
||||
begin
|
||||
Result := EsModificable(AFactura);
|
||||
|
||||
@ -13,6 +13,7 @@ type
|
||||
procedure Preview(const AListaID : TIntegerList);
|
||||
procedure Print(const AListaID : TIntegerList);
|
||||
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
|
||||
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
|
||||
end;
|
||||
|
||||
TFacturasClienteReportController = class(TControllerBase, IFacturasClienteReportController)
|
||||
@ -27,6 +28,7 @@ type
|
||||
procedure Preview(const AListaID : TIntegerList);
|
||||
procedure Print(const AListaID : TIntegerList);
|
||||
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
|
||||
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
|
||||
end;
|
||||
|
||||
|
||||
@ -57,6 +59,29 @@ begin
|
||||
inherited;
|
||||
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;
|
||||
const AFileName: String): Boolean;
|
||||
var
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -25,6 +25,11 @@ type
|
||||
frViewFacturaCliente1: TfrViewFacturaCliente;
|
||||
frViewTotales1: TfrViewTotales;
|
||||
frViewDetallesFacturaCliente1: TfrViewDetallesFacturaCliente;
|
||||
actEnviarEMail: TAction;
|
||||
TBXSeparatorItem6: TTBXSeparatorItem;
|
||||
TBXItem7: TTBXItem;
|
||||
TBXSubmenuItem2: TTBXSubmenuItem;
|
||||
TBXItem33: TTBXItem;
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure frViewClienteFactura1edtlNombrePropertiesEditValueChanged(Sender: TObject);
|
||||
procedure dsDataTableDataChange(Sender: TObject; Field: TField);
|
||||
@ -40,6 +45,8 @@ type
|
||||
procedure frViewTotales1ePortePropertiesValidate(Sender: TObject;
|
||||
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
|
||||
procedure frViewTotales1ePorteEditing(Sender: TObject; var CanEdit: Boolean);
|
||||
procedure actEnviarEMailExecute(Sender: TObject);
|
||||
procedure actEnviarEMailUpdate(Sender: TObject);
|
||||
|
||||
private
|
||||
procedure RecalcularPortePorUnidad;
|
||||
@ -91,6 +98,18 @@ uses
|
||||
**************************** 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);
|
||||
begin
|
||||
inherited;
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
Caption = 'Lista de facturas de cliente'
|
||||
ClientHeight = 666
|
||||
ClientWidth = 640
|
||||
ExplicitWidth = 648
|
||||
ClientWidth = 842
|
||||
ExplicitWidth = 850
|
||||
ExplicitHeight = 700
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
inherited JvNavPanelHeader: TJvNavPanelHeader
|
||||
Width = 640
|
||||
Width = 842
|
||||
Caption = 'Lista de facturas de cliente'
|
||||
ExplicitWidth = 640
|
||||
inherited Image1: TImage
|
||||
Left = 613
|
||||
Left = 815
|
||||
Picture.Data = {
|
||||
0A54504E474F626A65637489504E470D0A1A0A0000000D494844520000001800
|
||||
0000180806000000E0773DF80000000970485973000017120000171201679FD2
|
||||
@ -35,10 +35,10 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
end
|
||||
end
|
||||
inherited TBXDock: TTBXDock
|
||||
Width = 640
|
||||
Width = 842
|
||||
ExplicitWidth = 640
|
||||
inherited tbxMain: TTBXToolbar
|
||||
ExplicitWidth = 640
|
||||
ExplicitWidth = 842
|
||||
object TBXSubmenuItem2: TTBXSubmenuItem [0]
|
||||
Caption = 'Nuevo'
|
||||
DisplayMode = nbdmImageAndText
|
||||
@ -56,21 +56,25 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
inherited TBXItem2: TTBXItem
|
||||
Visible = False
|
||||
end
|
||||
object TBXItem40: TTBXItem [14]
|
||||
Action = actEnviarEMail
|
||||
DisplayMode = nbdmImageAndText
|
||||
end
|
||||
end
|
||||
inherited tbxMenu: TTBXToolbar
|
||||
ExplicitWidth = 640
|
||||
ExplicitWidth = 842
|
||||
end
|
||||
end
|
||||
inherited StatusBar: TJvStatusBar
|
||||
Top = 647
|
||||
Width = 640
|
||||
Width = 842
|
||||
ExplicitTop = 647
|
||||
ExplicitWidth = 640
|
||||
end
|
||||
inline frViewFacturasCliente1: TfrViewFacturasCliente [3]
|
||||
Left = 0
|
||||
Top = 102
|
||||
Width = 640
|
||||
Width = 842
|
||||
Height = 545
|
||||
Align = alClient
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
@ -85,7 +89,7 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
ExplicitWidth = 640
|
||||
ExplicitHeight = 545
|
||||
inherited cxGrid: TcxGrid
|
||||
Width = 640
|
||||
Width = 842
|
||||
Height = 417
|
||||
ExplicitWidth = 640
|
||||
ExplicitHeight = 417
|
||||
@ -125,12 +129,12 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
end
|
||||
end
|
||||
inherited frViewFiltroBase1: TfrViewFiltroBase
|
||||
Width = 640
|
||||
Width = 842
|
||||
ExplicitWidth = 640
|
||||
inherited TBXDockablePanel1: TTBXDockablePanel
|
||||
ExplicitWidth = 640
|
||||
inherited dxLayoutControl1: TdxLayoutControl
|
||||
Width = 640
|
||||
Width = 842
|
||||
ExplicitWidth = 640
|
||||
inherited txtFiltroTodo: TcxTextEdit
|
||||
ExplicitWidth = 600
|
||||
@ -154,10 +158,10 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
end
|
||||
end
|
||||
inherited TBXAlignmentPanel1: TTBXAlignmentPanel
|
||||
Width = 640
|
||||
Width = 842
|
||||
ExplicitWidth = 640
|
||||
inherited tbxBotones: TTBXToolbar
|
||||
Width = 630
|
||||
Width = 832
|
||||
ExplicitWidth = 630
|
||||
end
|
||||
end
|
||||
@ -168,10 +172,10 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
ExplicitTop = 519
|
||||
ExplicitWidth = 640
|
||||
inherited TBXAlignmentPanel1: TTBXAlignmentPanel
|
||||
Width = 640
|
||||
Width = 842
|
||||
ExplicitWidth = 640
|
||||
inherited TBXToolbar1: TTBXToolbar
|
||||
Width = 630
|
||||
Width = 832
|
||||
ExplicitWidth = 630
|
||||
end
|
||||
end
|
||||
@ -218,6 +222,12 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
ImageIndex = 24
|
||||
OnExecute = actNuevoAbonoExecute
|
||||
end
|
||||
object actEnviarEMail: TAction
|
||||
Category = 'Acciones'
|
||||
Caption = 'Enviar por e-mail...'
|
||||
OnExecute = actEnviarEMailExecute
|
||||
OnUpdate = actEnviarEMailUpdate
|
||||
end
|
||||
end
|
||||
inherited SmallImages: TPngImageList [5]
|
||||
PngImages = <
|
||||
@ -1777,6 +1787,9 @@ inherited fEditorFacturasCliente: TfEditorFacturasCliente
|
||||
'Cambiar la situaci'#243'n de la factura seleccionada (Pendiente/Pagad' +
|
||||
'a)'
|
||||
end
|
||||
object Enviarporemail1: TMenuItem [11]
|
||||
Action = actEnviarEMail
|
||||
end
|
||||
end
|
||||
object JsNuevaFacturaDialog: TJSDialog
|
||||
Content.Strings = (
|
||||
|
||||
@ -40,10 +40,15 @@ type
|
||||
actNuevoAbono: TAction;
|
||||
JsNuevoAbonoDialog: TJSDialog;
|
||||
JsListaFacturasNoEliminadas: TJSDialog;
|
||||
actEnviarEMail: TAction;
|
||||
TBXItem40: TTBXItem;
|
||||
Enviarporemail1: TMenuItem;
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure actEliminarUpdate(Sender: TObject);
|
||||
procedure actNuevaFacturaExecute(Sender: TObject);
|
||||
procedure actNuevoAbonoExecute(Sender: TObject);
|
||||
procedure actEnviarEMailUpdate(Sender: TObject);
|
||||
procedure actEnviarEMailExecute(Sender: TObject);
|
||||
private
|
||||
FFacturas: IBizFacturaCliente;
|
||||
FController : IFacturasClienteController;
|
||||
@ -88,6 +93,22 @@ begin
|
||||
(Sender as TAction).Enabled := (FFacturas.SITUACION = 'PENDIENTE');
|
||||
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);
|
||||
begin
|
||||
actNuevo.Execute;
|
||||
|
||||
@ -612,6 +612,9 @@ begin
|
||||
|
||||
AListaEmail := TStringList.Create;
|
||||
try
|
||||
RecuperarCliente(APresupuesto);
|
||||
APresupuesto.Cliente.DataTable.Active := True;
|
||||
|
||||
if not APresupuesto.Cliente.EMAIL_1IsNull then
|
||||
AListaEmail.Add(APresupuesto.Cliente.EMAIL_1);
|
||||
if not APresupuesto.Cliente.EMAIL_2IsNull then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user