Last active
October 5, 2016 11:11
-
-
Save kir-sf/d25bad31d73afc42cd37268758c9b3c2 to your computer and use it in GitHub Desktop.
Согласование реестров платежей
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> | |
<base target="_top"> | |
</head> | |
<script> | |
function Okay() { | |
document.getElementById("butOkay").disabled=true; | |
document.getElementById("output").innerHTML="Идет обработка..."; | |
google.script.run.withSuccessHandler(onOkaySuccess).withFailureHandler(onOkayFailure).Okay(); | |
} | |
function onOkaySuccess(status) { | |
document.getElementById("butOkay").disabled=false; | |
document.getElementById("output").innerHTML="_"; | |
} | |
function onOkayFailure(status) { | |
alert("У Вас нет прав согласовывать данный реестр"); | |
document.getElementById("butOkay").disabled=false; | |
document.getElementById("output").innerHTML="_"; | |
} | |
function Pay() { | |
document.getElementById("butPay").disabled=true; | |
document.getElementById("output").innerHTML="Идет обработка..."; | |
google.script.run.withSuccessHandler(onPaySuccess).withFailureHandler(onPayFailure).Pay(); | |
} | |
function onPaySuccess(status) { | |
document.getElementById("butPay").disabled=false; | |
document.getElementById("output").innerHTML="_"; | |
} | |
function onPayFailure(status) { | |
alert(status); | |
document.getElementById("butPay").disabled=false; | |
document.getElementById("output").innerHTML="_"; | |
} | |
</script> | |
<body> | |
<div id="panel" > | |
<button id="butOkay" class="action" onclick="Okay()"> Согласование </button> | |
<button id="butPay" class="action" onclick="Pay()"> Утверждение </button> | |
<button id="butCheck" class="share" onclick="google.script.run.checkOrders()"> Проверить </button> | |
</div> | |
<div id="output">_</div> | |
<br> | |
<a href='<?!= getListLink(); ?>'>Открыть РЕЕСТР для редактирования в отдельном окне</a> | |
<br> | |
<iframe width=1000 height=400 src='https://docs.google.com/spreadsheets/d/<?!= getListId(); ?>/edit#gid=0'></iframe> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var LIST_ID='тут поставить ID таблицы реестра платежей'; | |
Array.prototype.findByPropName = function(name){ | |
for(var i = 0; i < this.length; i++){ | |
if(this[i].key == name) return this[i] | |
} | |
return {value: undefined}; | |
} | |
function doGet(e) { | |
var t=HtmlService.createTemplateFromFile('index'); | |
return t.evaluate(); | |
} | |
function getListLink() { | |
var listFile=DriveApp.getFileById(LIST_ID); | |
return listFile.getUrl(); | |
} | |
function getListId() { | |
return LIST_ID; | |
} | |
function Okay() { | |
var newText=""; | |
var sh=SpreadsheetApp.openById(LIST_ID); | |
var signed=sh.getSheets()[0].getRange(1, 6).getValue(); | |
if (signed=='OK') newText='Откатить' | |
else newText='Согласовать'; | |
sh.getSheets()[0].getRange(1, 6).setValue(newText); | |
if (sh.getSheets()[0].getRange(1, 6).getValue()==newText) | |
var res=UrlFetchApp.fetch('https://script.google.com/macros/s/тут надо поставить ID скрипта API/exec'); | |
return true; | |
} | |
function Pay() { | |
var sh=SpreadsheetApp.openById(LIST_ID); | |
sh.getSheets()[0].getRange(2, 6).setValue('OK'); | |
if (sh.getSheets()[0].getRange(2, 6).getValue()=='OK') { | |
var addrTo=sh.getSheets()[0].getRange(3, 7).getValue(); | |
var file=DriveApp.getFileById(LIST_ID); | |
var fileToSend=file.getAs('application/pdf').setName("fileToSend"); | |
var mail={ | |
htmlBody: '<b>Во вложении согласованный реестр платежей</b>', | |
to: addrTo, | |
subject: file.getName()+' - плати', | |
attachments: [fileToSend] | |
} | |
MailApp.sendEmail(mail); | |
} | |
} | |
function checkOrders() { | |
var sh=SpreadsheetApp.openById(LIST_ID).getSheets()[0]; | |
var numRows=sh.getDataRange().getNumRows(); | |
for (var index=2; index<=numRows; index++) { | |
var orderNum=sh.getRange(index, 4).getValue(); | |
var orderDate=new Date(sh.getRange(index, 5).getValue()); | |
var query="properties has {key='orderNum' and value='"+orderNum+"' and visibility='PUBLIC'}"; | |
var files=Drive.Files.list({q: query}); | |
for (var i=0; i<files.items.length; i++) { | |
var currfile=files.items[i]; | |
var fileUrl=currfile.alternateLink; | |
var savedDate=new Date(currfile.properties.findByPropName('orderDate').value); | |
if ((orderDate.getDate()==savedDate.getDate())&&(orderDate.getMonth()==savedDate.getMonth())&&(orderDate.getFullYear()==savedDate.getFullYear())) | |
sh.getRange(index, 9).setValue(fileUrl); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment