Skip to content

Instantly share code, notes, and snippets.

@kir-sf
Created October 4, 2016 08:53
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/84f6c868608d3aeb70b9993c7d042c37 to your computer and use it in GitHub Desktop.
Save kir-sf/84f6c868608d3aeb70b9993c7d042c37 to your computer and use it in GitHub Desktop.
SearchForInvoice
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 onOpen() {
addMenu();
}
function addMenu() {
SpreadsheetApp.getUi()
.createMenu('Оплаты')
.addItem('Проверить', 'checkOrders')
.addToUi();
}
function checkOrders() {
var sh=SpreadsheetApp.getActive().getActiveSheet();
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