Table of Content
HAL Forum
procedure AddNLToMail (
record MailVc Mail)
Description:
Performs carriage return on specified e-mail record.
Parameters:
Mail E-mail record that will receive the carriage return.
external procedure AddNLToMail(record MailVc);

global
updating function Integer CreateMailFromResAvD(record ResAvVc RAr,var record MailVc Mailr,var string warning,string pdfform)
begin
  Integer res;
  row ResAvVc RArw;
  record ResTypeVc RTr;
  record ResUsageVc RUr;
  record CUVc CUr;
  row MailVc Mailrw;
  record EmailBlock EMBr;
  string 200 tstr;
  string 60 mailboxcode;
  string 60 mailboxname;
  Integer wn;
  Integer rwcnt,i;
  row MailTextVc MTrw;
  record LTxtVc LTxtr;
  Integer IgnoreRecordDetails;
  string 255 docname,fname;

  res = 1353;
  FindUserMailboxName(CurrentUser,mailboxcode,mailboxname);
  if (blank(mailboxcode)) then begin
    res = 22010;
    warning = CurrentUser;
    goto LCreateMailFromResAvD;
  end;
  if (nonblank(mailboxcode)) then begin
    CUr.Code = RAr.CUCode;
    if (nonblank(RAr.SourceCode)) then begin
      CUr.Code = RAr.SourceCode;
    end;
    if (ReadFirstMain(CUr,1,true)) then begin
      if (nonblank(CUr.eMail)) then begin
        BlockLoad(EMBr);
        RecordNew(Mailr);
        Mailr.TransDate = CurrentDate;
        Mailr.TransTime = CurrentTime;
        Mailrw.RowTyp = 1;
        Mailrw.AddrCode = mailboxname;
        MatRowPut(Mailr,0,Mailrw);
        Mailrw.RowTyp = 0;
        Mailrw.AddrCode = CUr.eMail;
        MatRowPut(Mailr,1,Mailrw);

        MailTextRow("ResAvVc",RAr.LangCode,MTrw,IgnoreRecordDetails);
        Mailr.Header = MTrw.Header;
        if (nonblank(Mailr.Header)) then begin
          Mailr.Header = Mailr.Header & " ";
        end;
        Mailr.Header = Mailr.Header & USetStr(1941);
        Mailr.Header = Mailr.Header & " " & RAr.SerNr;
        LTxtr.Code = MTrw.FirstTxt;
        if (ReadFirstMain(LTxtr,1,true)) then begin
          rwcnt = LineTextCnt(LTxtr);
          for (i=0;i<rwcnt;i=i+1) begin
            tstr = LineTextGet(LTxtr,i);
            LineTextPut(Mailr,LineTextCnt(Mailr),tstr);
          end;    
          AddCRToText(Mailr);
        end;
        if (IgnoreRecordDetails==0) then begin
          if (nonblank(Cur.Name))     then begin AddTextLineToMail(CUr.Name,Mailr); end;
          if (nonblank(Cur.InvAddr0)) then begin AddTextLineToMail(Cur.InvAddr0,Mailr); end;
          if (nonblank(Cur.InvAddr1)) then begin AddTextLineToMail(Cur.InvAddr1,Mailr); end;
          if (nonblank(Cur.InvAddr2)) then begin AddTextLineToMail(Cur.InvAddr2,Mailr); end;
          if (nonblank(Cur.InvAddr3)) then begin AddTextLineToMail(Cur.InvAddr3,Mailr); end;
          if (nonblank(Cur.InvAddr4)) then begin AddTextLineToMail(Cur.InvAddr4,Mailr); end;
          if (nonblank(Cur.Phone))    then begin AddTextLineToMail(Cur.Phone,Mailr); end;
          if (nonblank(Cur.Fax))      then begin AddTextLineToMail(Cur.Fax,Mailr); end;
          AddNLToMail(Mailr);
          rwcnt = MatRowCnt(RAr);
          for (i=0;i<rwcnt;i=i+1) begin
            MatRowGet(RAr,i,RArw);
            if (nonblank(RArw.ResType)) then begin
              tstr = RArw.ResType;
              RTr.Code = RArw.ResType;
              if (ReadFirstMain(RTr,1,true)) then begin
                if (nonblank(RTr.Comment)) then begin
                  tstr = RTr.Comment;
                end;
              end;
              AddToText(tstr & Chr(9),Mailr);
              tstr = RArw.Usage;
              RUr.Code = RArw.Usage;
              if (ReadFirstMain(RUr,1,true)) then begin
                if (nonblank(RUr.Comment)) then begin
                  tstr = RUr.Comment;
                end;
              end;
              AddToText(tstr & Chr(9),Mailr);
              AddToText(ValToString(RArw.QtyWanted,M4UVal,"","",0) & Chr(9),Mailr);
              AddToText("" & RArw.AgentPrice & Chr(9),Mailr);
              AddToText("" & RArw.AgentSum & Chr(9),Mailr);
              AddNLToMail(Mailr);
            end;
          end;
        end;
        LTxtr.Code = MTrw.LastTxt;
        if (ReadFirstMain(LTxtr,1,true)) then begin
          rwcnt = LineTextCnt(LTxtr);
          for (i=0;i<rwcnt;i=i+1) begin
            tstr = LineTextGet(LTxtr,i);
            LineTextPut(Mailr,LineTextCnt(Mailr),tstr);
          end;    
          AddCRToText(Mailr);
        end;
        Mailr.SerNr = NextSerNr("MailVc",Mailr.TransDate,-1,false,"");
        if (RecordInsert(Mailr,false)) then begin
          CreateRecordLink(RAr,CurrentCompany,Mailr,CurrentCompany);  
          CreateRecordLink(Mailr,CurrentCompany,RAr,CurrentCompany);  
          res = 0;

          docname = pdfform;
          if (blank(docname)) then begin
            docname = "ResAvForm";
          end;
          fname = "tmp/" & USetStr(2288) & " " & RAr.SerNr & ".pdf";
          SetDocumentFilename(fname);
          SetMedia(mtPdf);
          PrintDocument(RAr,docname,false);
          if (FileExists(fname)) then begin
            RecordLinkFile(fname,0,Mailr,CurrentCompany);
          end;
          SetDocumentFilename("");
          Delete_File(fname);
        end;
      end else begin
        res = 1353;
      end;
    end;
  end else begin
    res = 1353;
  end;
LCreateMailFromResAvD:;
  CreateMailFromResAvD = res;
  return;
end;
Related topics:
««