Created
October 4, 2016 08:53
-
-
Save kir-sf/84f6c868608d3aeb70b9993c7d042c37 to your computer and use it in GitHub Desktop.
SearchForInvoice
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
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