Reply To: Increase all prices by percentage

#91486
Anonymous
Inactive

< code >var main = function() {
var doc = app.properties.activeDocument;
if ( !doc ) return;
var fgp = app.findGrepPreferences.properties,
found = [], n, p, t;
app.findGrepPreferences = null;

app.findGrepPreferences.properties = {
findWhat:”€sd{1,3}(.d{3})*(,d+)”,
appliedParagraphStyle:doc.paragraphStyles.itemByName(“prezzo”),
}

found = doc.findGrep();
n = found.length;

while ( n– ) {
t = found[n];
p = Number ( t.contents.replace ( /€+/, “”).replace ( /\./g, “” ).replace ( “,”, “.” ) );
t.contents = “€ “+sepThousands( String(Math.ceil(p*1.02)) )+ “,00″;
}
}

function sepThousands ( contents ) {
var a = contents.split(‘.’);
var dec = a[1];
var integer = a[0].split(”);

var na = [];
while ( sp = integer.splice ( -3, 3 ) ) {
na[na.length] = sp.join(”);
}

return na.reverse().join(“.”)+(dec? ‘,’+dec : ”);
}

var u;

app.doScript ( “main()”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );

This article was last modified on January 23, 2017

Comments (0)

Loading comments...