2016-07-07 2 views
0

중소기업에서 일하기 때문에 보스는 비용 및 송장 제출 승인 시스템을 개선하기를 원합니다. 분명히 SaaS 옵션을 온라인으로 제공하는 여러 가지 방법이 있지만 거의 모든 비용이 들며 우리가 필요로하는 것보다 더 복잡합니다. 단순한 Google 양식이 이상적 일 수 있으며 대부분의 업무용으로 Google Apps를 사용합니다.하지만 파일을 첨부 할 수는 없습니다. 그래서 Google Apps Script를 발견하고 Google 페이지에서 좋은 예를 발견했으며 여기에서 나를 도왔습니다.Google Apps Script - 시트를 업데이트하고 인보이스/경비를 전자 메일로 보냅니다.

내가 할 노력하고있어 설명 할 경우

직원의 회원이 양식에 간다

는 자신의 세부 사항을두고

  • 값 비용의 , 무엇을 위해 그리고 것은 파일을 첨부 (pdf 또는 사진 ).

  • 제출을 누르면이 파일이 Google의 공유 된 Google 드라이브 폴더에 업로드됩니다.

  • 또한 모든 이러한 세부 사항 및 각 제출의 상태 및 비용의 비용에 따라 드라이브

  • 의 파일에 대한 링크가 포함 된 공유 스프레드 시트에 기록됩니다, 그것을 Google 계정 담당자에게 즉시 으로 이메일을 보내거나 지불하기 전에 승인을 위해 보스로 전송됩니다.

이제 양식 제출을 위해 작동하는 스크립트가 있으며 파일을 올바르게 업로드하고 시트에 기록합니다. 그러나 이것을 MailApp.sendEmail/GmailApp.sendEmail 기능과 결합하는 방법을 알아낼 수는 없습니다.

아래 코드는 작동합니다. Code.gs 파일 :

var submissionSSKey = 'xxxxxxx'; 
var folderId = "xyxyxyx"; 


function doGet(e) { 
    var template = HtmlService.createTemplateFromFile('Form.html'); 
    template.action = ScriptApp.getService().getUrl(); 
    return template.evaluate(); 
} 


function processForm(theForm) { 
    var fileBlob = theForm.myFile; 
    var folder = DriveApp.getFolderById(folderId); 
    var doc = folder.createFile(fileBlob); 
    var template = HtmlService.createTemplateFromFile('Thanks.html'); 
    var name = template.name = theForm.name; 
    var reason = template.reason = theForm.reason; 
    var email = template.email = theForm.email; 
    var cost = template.cost = theForm.cost; 
    var payee = template.payee = theForm.payee; 
    var fileUrl = template.fileUrl = doc.getUrl(); 
    var threshold = 100; 

    if (cost > threshold) 
    { 
    var approval = "YES" 
    } 
    else 
    { 
    var approval = "NO" 
    } 
    var timestamp = new Date() 
    var sheet = SpreadsheetApp.openById(submissionSSKey).getSheets()[0]; 
    var lastRow = sheet.getLastRow(); 
    var targetRange = sheet.getRange(lastRow+1, 1, 1, 8).setValues([[timestamp,name,cost,payee,reason,approval,"Submitted",fileUrl]]); 

    // Return HTML text for display in page. 
    return template.evaluate().getContent(); 

} 

그리고 Form.Html 파일 :

<script> 
    // Javascript function called by "submit" button handler, 
    // to show results. 
    function updateOutput(resultHtml) { 
    toggle_visibility('inProgress'); 
    var outputDiv = document.getElementById('output'); 
    outputDiv.innerHTML = resultHtml; 
    } 

    // From blog.movalog.com/a/javascript-toggle-visibility/ 
    function toggle_visibility(id) { 
    var e = document.getElementById(id); 
    if(e.style.display == 'block') 
     e.style.display = 'none'; 
    else 
     e.style.display = 'block'; 
    } 
</script> 

<div id="formDiv"> 
<!-- Form div will be hidden after form submission --> 
<form id="myForm"> 

    Name: <input name="name" type="text" /><br/> 
    Email: <input name="email" type="text" /><br/> 
    Payee: <input name="payee" type="text" /><br/> 
    Cost of invoice/expense: <input name="cost" type="number" /><br/> 
    Reason: <textarea name="reason" style="margin: 2px; height: 148px; width: 354px;"></textarea><br/> 
    Upload file/image: <input name="myFile" type="file" /><br/> 
    <input type="button" value="Submit" 
     onclick="toggle_visibility('formDiv'); toggle_visibility('inProgress'); 
     google.script.run 
      .withSuccessHandler(updateOutput) 
      .processForm(this.parentNode)" /> 
</form> 
</div> 

<div id="inProgress" style="display: none;"> 
<!-- Progress starts hidden, but will be shown after form submission. --> 
Uploading. Please wait... 
</div> 

<div id="output"> 
    <!-- Blank div will be filled with "Thanks.html" after form submission. --> 
</div> 

그리고 이것이 내가 작성하고 다음 단계로 보낼 이메일 기능이지만, 나는 몇 가지 시도 다른 것들과 내가 위에 무엇을 이걸에 맞게하는 방법을 해결할 수 없습니다.

function sendEmails() { 
    //New vars 

    var bossEmail = "email address1"; 
    var accountsEmail = "email address2"; 
    var messageBoss = "<html><body>" 
    + "<p>" + "Hi Boss," 
    + "<p>" + name + " has submitted an invoice/expense that needs your approval since it is above £." + threshold 
    + "<p>" + "This is to pay £" + cost + "to" + reason 
    + "<p>" + reason 
    + "<p>" + "The invoice can be found attached to this email or here in our google drive:" + fileUrl 
    + "<p>" + "Please approve or reject the expense report here:" + approvalUrl 
    + "</body></html>"; 

    var messageAccounts = "<html><body>" 
    + "<p>" + "Hi XX," 
    + "<p>" + name + " has submitted an invoice/expense that needs to be paid." 
    + "<p>Amount" + "This is to pay £" + cost + "to" + payee 
    + "<p>Reason:" + reason 
    + "<p>" + "The invoice can be found attached to this email or here in our google drive:" + fileUrl 
    + '<p>Please approve or reject the expense report <a href="' + approvalUrl + '">here</a>.' 
    + "</body></html>"; 
    if (cost > threshold) 
    { 
    var recipient = bossEmail 
    var subject = name + "has submitted an invoice that needs your approval" 
    var emailText = messageBoss 
    } 
    else 
    { 
    var recipient = accountsEmail 
    var subject = name + "has submitted an invoice to be paid" 
    var emailText = messageAccounts; 
    } 

    MailApp.sendEmail(recipient,subject,emailText); 
} 

어떤 도움이나 조언을 주시면 감사하겠습니다. 그런 다음

sendEmails(accountsEmail,name,cost,threshold,payee,reason,fileUrl) 

, 당신은 다만 적당한 변수와 processForm() 함수가 끝나기 전에 호출 :

답변

0

난 당신이 같은 sendEmails() 함수에 몇 가지 매개 변수를 추가 할 생각

sendEmails(email,name,cost,threshold,payee,reason,fileUrl); 

또한 바로 문 "만약"전에 processForm에서 "승인"var에()는 setValues를 (호출 할 때 함수가 표시되지 않습니다) ... 나는 그것을 선언하는 것이 좋습니다 유의하시기 바랍니다 :

var approval; 
    if (cost > threshold) 
    { 
    approval = "YES" 
    } 
    else 
    { 
    approval = "NO" 
    }