|  |  |  | @ -4,18 +4,28 @@ USE Math; | 
			
		
	
		
			
				
					|  |  |  |  | USE date; | 
			
		
	
		
			
				
					|  |  |  |  | USE format ; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | MACRO date_format(dateval,noyear) BLOCK; | 
			
		
	
		
			
				
					|  |  |  |  | date.format(dateval,'%B'); ordinate(date.format(dateval,'%e')); IF !noyear; date.format(dateval,'%Y'); END; | 
			
		
	
		
			
				
					|  |  |  |  | END; | 
			
		
	
		
			
				
					|  |  |  |  | datenow.value = date.now(); | 
			
		
	
		
			
				
					|  |  |  |  | datenow.month_end   = date_format(month_end  (datenow.value), noyear = 1 ); | 
			
		
	
		
			
				
					|  |  |  |  | datenow.month_start = date_format(month_start(datenow.value), noyear = 1 ); | 
			
		
	
		
			
				
					|  |  |  |  | datenow.year=date.format(datenow.value,'%Y'); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | IF invoice.serial; | 
			
		
	
		
			
				
					|  |  |  |  |     invoice.serial=Math.int(ifz(invoice.serial))|format('%06d'); | 
			
		
	
		
			
				
					|  |  |  |  |     #invoice.date_start = '00:00:00 01-' _ invoice.month _ invoice.year; | 
			
		
	
		
			
				
					|  |  |  |  |     invoice.date_start = '00:00:00 01-05-2014'; | 
			
		
	
		
			
				
					|  |  |  |  |     invoice.date_end   = month_end(invoice.date_start); | 
			
		
	
		
			
				
					|  |  |  |  | END; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | dateval.value = date.now(); | 
			
		
	
		
			
				
					|  |  |  |  | dateval.month_end = date_format('00:00:00 00-' _ (Math.int(ifz(date.format(dateval.value,'%m'))) + 1) _ date.format(dateval.value,'-%Y'), noyear = 1 ); | 
			
		
	
		
			
				
					|  |  |  |  | dateval.month_start = date_format('00:00:00 01-' _ date.format(dateval.value,'%m-%Y'), noyear = 1 ); | 
			
		
	
		
			
				
					|  |  |  |  | dateval.year=date.format(dateval.value,'%Y'); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | invoice.serial=Math.int(ifz(invoice.serial))|format('%06d'); | 
			
		
	
		
			
				
					|  |  |  |  | invoice.month=date.format(invoice.start,'%B'); | 
			
		
	
		
			
				
					|  |  |  |  | MACRO date_format(dateval,noyear) BLOCK; | 
			
		
	
		
			
				
					|  |  |  |  | date.format(dateval,'%B'); ordinate(date.format(dateval,'%e')); IF !noyear; date.format(dateval,'%Y'); END; | 
			
		
	
		
			
				
					|  |  |  |  | END; | 
			
		
	
		
			
				
					|  |  |  |  | MACRO month_start(dateval) BLOCK; | 
			
		
	
		
			
				
					|  |  |  |  | '00:00:00 01-' _ date.format(dateval,'%m-%Y'); | 
			
		
	
		
			
				
					|  |  |  |  | END; | 
			
		
	
		
			
				
					|  |  |  |  | MACRO month_end(dateval) BLOCK; | 
			
		
	
		
			
				
					|  |  |  |  | '00:00:00 00-' _ (Math.int(ifz(date.format(dateval,'%m'))) + 1) _ date.format(dateval,'-%Y'); | 
			
		
	
		
			
				
					|  |  |  |  | END; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | MACRO ordinate(num) BLOCK; | 
			
		
	
		
			
				
					|  |  |  |  |       IF num.search('(?<!1)1$'); | 
			
		
	
	
		
			
				
					|  |  |  | @ -140,7 +150,7 @@ MACRO get_page_rows_number(pagetype, tt_type, rows_type) BLOCK; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     rows = matches.0 || matches.1 ; | 
			
		
	
		
			
				
					|  |  |  |  |     rows = Math.int(ifz(rows)); | 
			
		
	
		
			
				
					|  |  |  |  |     ifz(rows); | 
			
		
	
		
			
				
					|  |  |  |  |     rows; | 
			
		
	
		
			
				
					|  |  |  |  | END ; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -163,84 +173,84 @@ MACRO show_pages(invoice_details_zones, invoice_details_calls, pagetype, pagenum | 
			
		
	
		
			
				
					|  |  |  |  | #todo: remove copypast with some macro, later; | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |      total = {perpage => [], global => {}, pagetype => { call=> {perpage => [], global => {}}, zone => {perpage => [], global => {}} } } ; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |      allzonerowsnumber = invoice_details_zones.size() ; | 
			
		
	
		
			
				
					|  |  |  |  |      titlezonerows =  get_page_rows_number('titlepage','svg','zone') ; | 
			
		
	
		
			
				
					|  |  |  |  |      midzonerows = get_page_rows_number('zonepage','svg') ; | 
			
		
	
		
			
				
					|  |  |  |  |      titlezoneinterval =  get_page_interval('titlepage','svg','zone') ; | 
			
		
	
		
			
				
					|  |  |  |  |      midzoneinterval =  get_page_interval('zonepage','svg') ; | 
			
		
	
		
			
				
					|  |  |  |  |      midzonerows = Math.int(get_page_rows_number('zonepage','svg')) ; | 
			
		
	
		
			
				
					|  |  |  |  |      midzonerows = ( midzonerows < 1 ) ? 30 : midzonerows ; | 
			
		
	
		
			
				
					|  |  |  |  |     alltitlepages = ifz(alltitlepages) ? alltitlepages : 1; | 
			
		
	
		
			
				
					|  |  |  |  |     allzonerowsnumber = invoice_details_zones.size() ; | 
			
		
	
		
			
				
					|  |  |  |  |     titlezonerows =  get_page_rows_number('titlepage','svg','zone') ; | 
			
		
	
		
			
				
					|  |  |  |  |     midzonerows = get_page_rows_number('zonepage','svg') ; | 
			
		
	
		
			
				
					|  |  |  |  |     titlezoneinterval =  get_page_interval('titlepage','svg','zone') ; | 
			
		
	
		
			
				
					|  |  |  |  |     midzoneinterval =  get_page_interval('zonepage','svg') ; | 
			
		
	
		
			
				
					|  |  |  |  |     midzonerows = Math.int(get_page_rows_number('zonepage','svg')) ; | 
			
		
	
		
			
				
					|  |  |  |  |     midzonerows = ( midzonerows < 1 ) ? 30 : midzonerows ; | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |      allmidzonepages = ( (allzonerowsnumber - titlezonerows) / midzonerows )|format('%d') ; | 
			
		
	
		
			
				
					|  |  |  |  |      allmidzonerows = allmidzonepages * midzonerows ; | 
			
		
	
		
			
				
					|  |  |  |  |      lastzonerows = allzonerowsnumber - allmidzonerows - titlezonerows ; | 
			
		
	
		
			
				
					|  |  |  |  |      allzonepages = allmidzonepages + ( lastzonerows ? 1 : 0 ) ; | 
			
		
	
		
			
				
					|  |  |  |  |     allmidzonepages = ( (allzonerowsnumber - titlezonerows) / midzonerows )|format('%d') ; | 
			
		
	
		
			
				
					|  |  |  |  |     allmidzonerows = allmidzonepages * midzonerows ; | 
			
		
	
		
			
				
					|  |  |  |  |     lastzonerows = allzonerowsnumber - allmidzonerows - titlezonerows ; | 
			
		
	
		
			
				
					|  |  |  |  |     allzonepages = allmidzonepages + ( lastzonerows > 0 ? 1 : 0 ) ; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |      allcallrowsnumber = invoice_details_calls.size() ; | 
			
		
	
		
			
				
					|  |  |  |  |      titlecallrows =  get_page_rows_number('titlepage','svg','call') ; | 
			
		
	
		
			
				
					|  |  |  |  |      midcallrows = Math.int(get_page_rows_number('callpage','svg')) ; | 
			
		
	
		
			
				
					|  |  |  |  |      midcallrows = ( midcallrows < 1 ) ? 30 : midcallrows ; | 
			
		
	
		
			
				
					|  |  |  |  |      titlecallinterval =  get_page_interval('titlepage','svg', 'call') ; | 
			
		
	
		
			
				
					|  |  |  |  |      midcallinterval =  get_page_interval('callpage','svg') ; | 
			
		
	
		
			
				
					|  |  |  |  |     allcallrowsnumber = invoice_details_calls.size() ; | 
			
		
	
		
			
				
					|  |  |  |  |     titlecallrows =  get_page_rows_number('titlepage','svg','call') ; | 
			
		
	
		
			
				
					|  |  |  |  |     midcallrows = Math.int(get_page_rows_number('callpage','svg')) ; | 
			
		
	
		
			
				
					|  |  |  |  |     midcallrows = ( midcallrows < 1 ) ? 30 : midcallrows ; | 
			
		
	
		
			
				
					|  |  |  |  |     titlecallinterval =  get_page_interval('titlepage','svg', 'call') ; | 
			
		
	
		
			
				
					|  |  |  |  |     midcallinterval =  get_page_interval('callpage','svg') ; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |      allmidcallpages = ( (allcallrowsnumber - titlecallrows) / midcallrows )|format('%d') ; | 
			
		
	
		
			
				
					|  |  |  |  |      allmidcallrows = allmidcallpages * midcallrows ; | 
			
		
	
		
			
				
					|  |  |  |  |      lastcallrows = allcallrowsnumber - allmidcallrows - titlecallrows ; | 
			
		
	
		
			
				
					|  |  |  |  |      allcallpages = allmidcallpages + ( lastcallrows ? 1 : 0 ) ; | 
			
		
	
		
			
				
					|  |  |  |  |     allmidcallpages = ( (allcallrowsnumber - titlecallrows) / midcallrows )|format('%d') ; | 
			
		
	
		
			
				
					|  |  |  |  |     allmidcallrows = allmidcallpages * midcallrows ; | 
			
		
	
		
			
				
					|  |  |  |  |     lastcallrows = allcallrowsnumber - allmidcallrows - titlecallrows ; | 
			
		
	
		
			
				
					|  |  |  |  |     allcallpages = allmidcallpages + ( lastcallrows > 0 ? 1 : 0 ) ; | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     IF ( pagetype == 'zone' || pagetype=='all' ) && allzonerowsnumber ; | 
			
		
	
		
			
				
					|  |  |  |  |          pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidzonepages ] ; | 
			
		
	
		
			
				
					|  |  |  |  |         pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidzonepages ] ; | 
			
		
	
		
			
				
					|  |  |  |  |         FOREACH pagenum IN pages ; | 
			
		
	
		
			
				
					|  |  |  |  |              pagerowsstart = titlezonerows + midzonerows * ( pagenum - 1 ); | 
			
		
	
		
			
				
					|  |  |  |  |              pagerowsend = titlezonerows + midzonerows * pagenum - 1 ; | 
			
		
	
		
			
				
					|  |  |  |  |             pagerowsstart = titlezonerows + midzonerows * ( pagenum - 1 ); | 
			
		
	
		
			
				
					|  |  |  |  |             pagerowsend = titlezonerows + midzonerows * pagenum - 1 ; | 
			
		
	
		
			
				
					|  |  |  |  |             # pagerowsend = pagerowsend > invoice_details_zones.size() - 1 ? invoice_details_zones.size() - 1 : pagerowsend  ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ zonepage( invoice_details_zones.slice( pagerowsstart,  pagerowsend ), total, pagenum + 1, pagenum, allzonepages, midzoneinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ zonepage( invoice_details_zones.slice( pagerowsstart,  pagerowsend ), total, pagenum + alltitlepages, pagenum, allzonepages, midzoneinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |             #+1 because of 1 for titlepage ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ bgpage(pagenum + 1, pagenum, allzonepages) ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ bgpage(pagenum + 1, pagenum, allzonepages) ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |         END; | 
			
		
	
		
			
				
					|  |  |  |  |         IF lastzonerows > 0 ; | 
			
		
	
		
			
				
					|  |  |  |  |             #2 because zonepages started from 1, not from 0, and we need add 1 for titlepage ; | 
			
		
	
		
			
				
					|  |  |  |  |              pagenum = 2 + allmidzonepages ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ zonepage( invoice_details_zones.slice( allzonerowsnumber - lastzonerows ), total, pagenum, allzonepages, allzonepages, midzoneinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ bgpage(pagenum, allzonepages, allzonepages) ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |             #+1 is for last page number, so ( alltitlepages + allmidzonepages ) was previous page | 
			
		
	
		
			
				
					|  |  |  |  |             pagenum = 1 + alltitlepages + allmidzonepages ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ zonepage( invoice_details_zones.slice( allzonerowsnumber - lastzonerows ), total, pagenum, allzonepages, allzonepages, midzoneinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ bgpage(pagenum, allzonepages, allzonepages) ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |         END; | 
			
		
	
		
			
				
					|  |  |  |  |     END; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     #Dumper.dump(total); | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |      total.pagetype.call.global.import(total.global); | 
			
		
	
		
			
				
					|  |  |  |  |     total.pagetype.call.global.import(total.global); | 
			
		
	
		
			
				
					|  |  |  |  |     # total.pagetype.call.perpage.import(total.perpage); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     #Dumper.dump(total); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |      total.global = {}; | 
			
		
	
		
			
				
					|  |  |  |  |      total.perpage = [] ; | 
			
		
	
		
			
				
					|  |  |  |  |     total.global = {}; | 
			
		
	
		
			
				
					|  |  |  |  |     total.perpage = [] ; | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     IF ( pagetype == 'call' || pagetype=='all' ); | 
			
		
	
		
			
				
					|  |  |  |  |          pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidcallpages ] ; | 
			
		
	
		
			
				
					|  |  |  |  |         pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidcallpages ] ; | 
			
		
	
		
			
				
					|  |  |  |  |         FOREACH pagenum IN pages ; | 
			
		
	
		
			
				
					|  |  |  |  |              pagerowsstart = titlecallrows + midcallrows * ( pagenum - 1 ); | 
			
		
	
		
			
				
					|  |  |  |  |              pagerowsend = titlecallrows + midcallrows * pagenum - 1 ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ callpage( invoice_details_calls.slice( pagerowsstart,  pagerowsend ), total, pagenum + 1 + allzonepages, pagenum, allcallpages, midcallinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |             pagerowsstart = titlecallrows + midcallrows * ( pagenum - 1 ); | 
			
		
	
		
			
				
					|  |  |  |  |             pagerowsend = titlecallrows + midcallrows * pagenum - 1 ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ callpage( invoice_details_calls.slice( pagerowsstart,  pagerowsend ), total, pagenum + 1 + allzonepages, pagenum, allcallpages, midcallinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |             #+1 because of 1 for titlepage ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ bgpage(pagenum + 1 + allzonepages, pagenum, allcallpages ) ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ bgpage(pagenum + 1 + allzonepages, pagenum, allcallpages ) ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |         END; | 
			
		
	
		
			
				
					|  |  |  |  |         IF lastcallrows > 0 ; | 
			
		
	
		
			
				
					|  |  |  |  |             #2 because callpages started from 1, not from 0, and we need add 1 for titlepage ; | 
			
		
	
		
			
				
					|  |  |  |  |              pagenum = 1 + 1 + allmidcallpages + allzonepages ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ callpage( invoice_details_calls.slice( allcallrowsnumber - lastcallrows ), total, pagenum, allcallpages, allcallpages, midcallinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ bgpage(pagenum, allcallpages, allcallpages) ; | 
			
		
	
		
			
				
					|  |  |  |  |              output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |             pagenum = 1 + alltitlepages + allmidcallpages + allzonepages ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_header(); | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ callpage( invoice_details_calls.slice( allcallrowsnumber - lastcallrows ), total, pagenum, allcallpages, allcallpages, midcallinterval ) ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ bgpage(pagenum, allcallpages, allcallpages) ; | 
			
		
	
		
			
				
					|  |  |  |  |             output = output _ document_footer(); | 
			
		
	
		
			
				
					|  |  |  |  |         END; | 
			
		
	
		
			
				
					|  |  |  |  |     END; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |