Skip to content

Commit

Permalink
TryAddAttachmentByExtension added
Browse files Browse the repository at this point in the history
  • Loading branch information
landrix committed Nov 19, 2020
1 parent 3660b89 commit dd562a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions intf.Invoice.pas
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ TInvoiceAttachment = class(TObject)
TInvoiceAttachmentList = class(TObjectList<TInvoiceAttachment>)
public
function AddAttachment(_AttachmentType : TInvoiceAttachmentType) : TInvoiceAttachment;
function TryAddAttachmentByExtension(const _Filename : String; out _Attachment : TInvoiceAttachment) : Boolean;
end;

TInvoiceUnitCodeHelper = class(TObject)
Expand Down Expand Up @@ -647,5 +648,41 @@ function TInvoiceAttachmentList.AddAttachment(_AttachmentType: TInvoiceAttachmen
Add(Result);
end;

function TInvoiceAttachmentList.TryAddAttachmentByExtension(const _Filename: String;
out _Attachment: TInvoiceAttachment): Boolean;
var
fileExt : String;
begin
Result := false;
if not FileExists(_Filename) then
exit;

fileExt := ExtractFileExt(_Filename);
if SameText(fileExt,'.xlsx') then
_Attachment := AddAttachment(iat_application_vnd_openxmlformats_officedocument_spreadsheetml_sheet)
else
if SameText(fileExt,'.ods') then
_Attachment := AddAttachment(iat_application_vnd_oasis_opendocument_spreadsheet)
else
if SameText(fileExt,'.csv') then
_Attachment := AddAttachment(iat_text_csv)
else
if SameText(fileExt,'.jpg') then
_Attachment := AddAttachment(iat_image_jpeg)
else
if SameText(fileExt,'.pdf') then
_Attachment := AddAttachment(iat_application_pdf)
else
if SameText(fileExt,'.png') then
_Attachment := AddAttachment(iat_image_png)
else
if SameText(fileExt,'.xml') then
_Attachment := AddAttachment(iat_application_xml)
else
exit;

Result := true;
end;

end.

2 changes: 1 addition & 1 deletion intf.XRechnung.pas
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class procedure TXRechnungInvoiceAdapter.SaveDocumentUBL(_Invoice: TInvoice;
precedingInvoiceReference : TInvoicePrecedingInvoiceReference;

function InternalExtensionEnabled : Boolean;
var a : Integer;
//var a : Integer;
begin
Result := false;
if _Invoice.InvoiceLines.Count > 0 then
Expand Down

0 comments on commit dd562a4

Please sign in to comment.