Skip to content

Instantly share code, notes, and snippets.

@kir-sf
Last active October 5, 2016 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kir-sf/ed5acfa1138af340fd1fef728b22e09b to your computer and use it in GitHub Desktop.
Save kir-sf/ed5acfa1138af340fd1fef728b22e09b to your computer and use it in GitHub Desktop.
API реестра платежей
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 callTrigger() {
clearList();
}
function clearList() {
var ss=SpreadsheetApp.openById(LIST_ID);
var sh=ss.getSheetByName("List").getRange(6, 1, 250, 9);
sh.clear();
openList();
}
function doGet(e) {
var sh=SpreadsheetApp.openById(LIST_ID);
var signed=sh.getSheets()[0].getRange(1, 6).getValue();
if (signed=="Откатить") openList();
if (signed=="Согласовать") closeList();
return HtmlService.createHtmlOutput();
}
function closeList() {
var sh=SpreadsheetApp.openById(LIST_ID);
sh.getSheets()[0].getRange(1, 6).setValue('OK');
var fsh=DriveApp.getFileById(LIST_ID);
var editors=fsh.getEditors();
for (var i=0; i<editors.length; i++) {
fsh.removeEditor(editors[i].getEmail());
fsh.addViewer(editors[i].getEmail());
}
fsh.addEditor(sh.getSheets()[0].getRange(1, 7).getValue());
fsh.addEditor(sh.getSheets()[0].getRange(2, 7).getValue());
checkOrders();
}
function openList() {
var sh=SpreadsheetApp.openById(LIST_ID);
sh.getSheets()[0].getRange(1, 6).setValue('');
var fsh=DriveApp.getFileById(LIST_ID);
var viewers=fsh.getViewers();
for (var i=0; i<viewers.length; i++) {
fsh.removeViewer(viewers[i].getEmail());
fsh.addEditor(viewers[i].getEmail());
}
fsh.addEditor(sh.getSheets()[0].getRange(1, 7).getValue());
fsh.addEditor(sh.getSheets()[0].getRange(2, 7).getValue());
}
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