code:
// Utility function to determine if leap year
isLeapYear = function(year){
return ( year % 4 == 0 &&
(year % 100 != 0 || year % 400 == 0) );
}
// Utility function to determine number of days in month
// (including leap years)
kmDays = [31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31];
getMonthDays = function(year,mNbr) {
return kmDays[mNbr] + (mNbr == 1 && isLeapYear(year));
}
// Sample Usage
// print end of month for next 52 pay periods
// read the date from a string
datAry = otplata.split('.');
yr = datAry[2] + 2000; // full year
mn = datAry[1] - 1; // month in 0-11 format
//Round up the numbers;
kDelimiter = '.';
RoundToQuarter = function(x)
{
return Math.round(x*2)/2;
}
EncodeCurrency = function(x)
{
var ix = Math.floor(x);
var fx = x - ix;
fx = String(fx*100+100).substr(1);
if (ix >= 1000) {
ix = String(ix);
var len = ix.length;
var ngroups = 1 + Math.floor((len-4)/3);
var ox = '';
while (ngroups--)
{
ox = kDelimiter + ix.substr(len-3,3) + ox;
ix = ix.substr(0,len-3);
len -= 3;
}
ix += ox;
}
return ix + '.' + fx;
}
// drawing the table;
function CreateTable(thename, x, y, width, height, no_of_rows, no_of_columns, data, parent){
c=0;
for(i=0;i<no_of_rows;i++){
for(j=0;j<no_of_columns;j++){
// Create the new name for the text field
__name=thename+"_"+i+"_"+j;
// Create the text field
parent. createTextField(__name,c++,j*width+x,i*height+y,wi dth,height);
// Set the data and other settings
temp=parent[__name];
temp.text=data[i][j];
temp.background=false;
temp.border=false;
myformat = new TextFormat();
myformat.color = 0x000000;
myformat.font = "Arial";
myformat.size = 9;
myformat.align = "right";
temp.setTextFormat(myformat);
}
}
}
//insert values into tables
var p = stapka;
var r = 1+p/1200;
var z = iznos;
var a = z*Math.pow(r,rati)*(r-1)/(Math.pow(r, rati)-1);
myData = [];
for (i=0; i < rati+1; i++){
m=i+1;
k=z*p/1200;
b = a-k;
//spliting a numbers;
k= RoundToQuarter(k);
b= RoundToQuarter(b);
a= RoundToQuarter(a);
z= RoundToQuarter(z);
var dat = new Date(yr,mn,getMonthDays(yr,mn));
var datString = dat.getDate() + '.' + (dat.getMonth()+1) + '.' + dat.getFullYear();
if (++mn >= 12) {
mn = 0;
yr++;
}
myData[i] = [m, datString, EncodeCurrency(z), EncodeCurrency(b), EncodeCurrency(k), EncodeCurrency(a)];
z=z-b;
}
CreateTable("MyTable", 50, 120, 100, 14, rati, 6, myData, this);