<?xml version="1.0" encoding="utf-8"?>
<Forms>
    <Form>
        <FormName>Этикетки на лист A4 для товаров из заказа (24 на стр)</FormName>
        <FormType>0</FormType>
        <FormScript>/*max - 1*/
var maxrow=7;
var maxcol=2;

var row=0;
var col=0;

var q = query.newq();
function writeone(title)
{


doc.wl('&lt;table border="0" align="left" cellspacing="0" cellpadding="0" style="width: 70mm;" >');

/*title row*/
doc.wl('&lt;tr>&lt;td colspan="2" align="center" style="font-size: 8pt;">');
doc.wl('&lt;u>'+title+'&lt;/u>');
doc.wl('&lt;/td>&lt;/tr>');

/*item name row*/
doc.wl('&lt;tr>&lt;td colspan="2">');
doc.wl('&lt;div style="height:15mm; overflow:hidden;font-size: 12pt; ">');
doc.wl(q.getstring('item_name'));
doc.wl('&lt;/div>');
doc.wl('&lt;/td>');
doc.wl('&lt;/tr>');

/*barcode and logo row*/
doc.wl('&lt;tr>&lt;td style="font-family: \'BarFont\';font-size: 42pt; padding-left:25px;font-style:normal;" width="80%">');
doc.wl('*'+q.getstring('item_code')+'*');
doc.wl('&lt;/td>');
doc.wl('&lt;td>');
doc.wl('&lt;div style="width: 10mm; height:10mm">');

if(util.os()==0){/*android*/
	doc.wl('&lt;img  style="width: 10mm; height:10mm;padding-left:5px;"  border="0" src="http://vvs.ru/eac.png">&lt;/td>');
}
else{
	doc.wl('&lt;img  style="width: 10mm; height:10mm;padding-left:5px;"  border="0" src="eac.png">&lt;/td>');
}

doc.wl('&lt;/div>');
doc.wl('&lt;/td>&lt;/tr>');

/*price row*/
doc.wl('&lt;tr>&lt;td colspan="2" style="font-size: 16pt;">');
doc.wl('Цена: '+f.qty2str(q.getfloat('item_price'))+' р.');
doc.wl('&lt;/td>&lt;/tr>');

if(false &amp;&amp; q.getstring('item_expiry')!=""){
	doc.wl('&lt;tr>&lt;td colspan="2">');
	doc.wl('Годен до: '+f.datestr(q.getstring('item_expiry')));
	doc.wl('&lt;/td>&lt;/tr>');
}

mess.say(q.getstring('item_name'));


doc.wl('&lt;/table>');
	
}/*writeone function*/

var isFirst=true;

/*output labels for current record in query*/
function doit(kolPrint)
{
 for(i=0;i&lt;kolPrint;i++){
	if(col>maxcol){/*end of row*/
		col=0;
		row++;
		if(row&lt;=maxrow){
			doc.wl('&lt;/tr>');
			doc.wl('&lt;tr>');
		}
	}

	if(row>maxrow){/*end of page*/
		doc.wl('&lt;/tr>');
		doc.wl('&lt;/table>');

		doc.wl('&lt;br clear="all" />');
		doc.wl('&lt;div class="page-break">&lt;/div>');

		row=0;
		col=0;
	}

 	if(row==0 &amp;&amp; col==0){
		/*doc.wl('&lt;table border="0" align="left"  cellspacing="0" cellpadding="2" style="border-style:solid;border-width:1px;border-color:black">');*/
		doc.wl('&lt;table border="1" align="left"  cellspacing="0" cellpadding="2" style="border-style:solid;border-width:1px;border-color:black">');
		doc.wl('&lt;tr>');
	}
	doc.wl('&lt;td>');
 	writeone(titleStr);
	doc.wl('&lt;/td>');
	col++;
 }

}

kol=prompt('Количество этикеток на товар (0 - как в заказе):','0');

if(kol==null){
	throw('Обработка прервана!');
}
var titleStr;


/*idOrg = util.value("nums", "cnt", 5);*/
/*default own organiztion*/
qtmp=query.newq();
qtmp.select("select * from nums where _id = 5");
qtmp.first();
idOrg=qtmp.getint("cnt");
titleStr=util.value("accounts", "account_name", idOrg)+', ИНН: '+util.value("accounts", "account_inn", idOrg);
titleStr=prompt('Заголовок этикеток:',titleStr);
if(titleStr==null){
	throw('Обработка прервана!');
}


usl=false;
mess.show();
doc.copybarfont();

 doc.openoutfile("labels16.htm");
 doc.wl('&lt;html>');
 doc.wl('&lt;head>');
 doc.wl('&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');

doc.wl('&lt;STYLE TYPE="text/css">');
doc.wl('P.breakhere {page-break-before: always}');
doc.wl('&lt;/STYLE>');

doc.wl('	&lt;style type="text/css">');
doc.wl('	table		{font-size: 10pt;}');

doc.wl('		@media screen {');
doc.wl('			.page-break	{ height:10px;  border-top:1px dotted #999; margin-bottom:13px; }');
doc.wl('		}');
doc.wl('		@media print {');
doc.wl('			.page-break { height:0; page-break-before:always; margin:0; border-top:none; }');
doc.wl('		}');
doc.wl('	&lt;/style>');
doc.wl('');

doc.wl('&lt;style>@font-face {');
doc.wl(' font-family: \'BarFont\';');
/*doc.wl(' src: url(\'file:///android_asset/barfont1.ttf\') format(\'truetype\');');*/
doc.wl(' src: url(\'barfont1.ttf\') format(\'truetype\');');
doc.wl(' font-weight: normal;');
doc.wl(' font-style: normal;');
doc.wl(' -fs-pdf-font-embed: embed;');
doc.wl(' -fs-pdf-font-encoding: Identity-H;');
doc.wl('}&lt;/style>');


 doc.wl('&lt;/head>');
 doc.wl('&lt;body>');

var qstr= 'select items.*, group_name, unit_name, country_name '+
	' from items left outer join groups on groups._id = item_group_id '+
	' left outer join units on units._id = item_unit_id '+
	' left outer join countries on countries._id = item_country_id ';
var qOne;
/*get data for items*/
qItems=query.newinstance();
if(qItems.select("select invcitem_item_id, invcitem_qty from invcitem where invcitem_invoice_id="+doc.id()) &amp;&amp; qItems.first() ){
	do{
		qOne=qstr+'  where items._id='+qItems.value("invcitem_item_id");
 		if(q.select(qOne) &amp;&amp; q.first()){
			k=kol;
			if(kol==0) k=qItems.value("invcitem_qty");
			doit(k);
			/*doc.wl('&lt;/tr>');
			doc.wl('&lt;/table>');*/


			mess.say(q.getstring('item_name'));
		}

	}while( qItems.next());
}




doc.wl('&lt;/body>&lt;/html>');
doc.outclose();
mess.close();
doc.setExtEditor("vvshtml2");
doc.open();
</FormScript>
    </Form>


    <Form>
        <FormName>Этикетки на лист A4 для выделенных товаров (24 на стр)</FormName>
        <FormType>11</FormType>
        <FormScript>/*max - 1*/
var maxrow=7;
var maxcol=2;

var row=0;
var col=0;

var q = query.newq();
function writeone(title)
{


doc.wl('&lt;table border="0" align="left" cellspacing="0" cellpadding="0" style="width: 70mm;" >');

/*title row*/
doc.wl('&lt;tr>&lt;td colspan="2" align="center" style="font-size: 8pt;">');
doc.wl('&lt;u>'+title+'&lt;/u>');
doc.wl('&lt;/td>&lt;/tr>');

/*item name row*/
doc.wl('&lt;tr>&lt;td colspan="2">');
doc.wl('&lt;div style="height:15mm; overflow:hidden;font-size: 12pt; ">');
doc.wl(q.getstring('item_name'));
doc.wl('&lt;/div>');
doc.wl('&lt;/td>');
doc.wl('&lt;/tr>');

/*barcode and logo row*/
doc.wl('&lt;tr>&lt;td style="font-family: \'BarFont\';font-size: 42pt; padding-left:25px;font-style:normal;" width="80%">');
doc.wl('*'+q.getstring('item_code')+'*');
doc.wl('&lt;/td>');
doc.wl('&lt;td>');
doc.wl('&lt;div style="width: 10mm; height:10mm">');

if(util.os()==0){/*android*/
	doc.wl('&lt;img  style="width: 10mm; height:10mm;padding-left:5px;"  border="0" src="http://vvs.ru/eac.png">&lt;/td>');
}
else{
	doc.wl('&lt;img  style="width: 10mm; height:10mm;padding-left:5px;"  border="0" src="eac.png">&lt;/td>');
}

doc.wl('&lt;/div>');
doc.wl('&lt;/td>&lt;/tr>');

/*price row*/
doc.wl('&lt;tr>&lt;td colspan="2" style="font-size: 16pt;">');
doc.wl('Цена: '+f.qty2str(q.getfloat('item_price'))+' р.');
doc.wl('&lt;/td>&lt;/tr>');

if(false &amp;&amp; q.getstring('item_expiry')!=""){
	doc.wl('&lt;tr>&lt;td colspan="2">');
	doc.wl('Годен до: '+f.datestr(q.getstring('item_expiry')));
	doc.wl('&lt;/td>&lt;/tr>');
}

mess.say(q.getstring('item_name'));


doc.wl('&lt;/table>');
	
}/*writeone function*/

var isFirst=true;

/*output labels for current record in query*/
function doit(kolPrint)
{
 for(i=0;i&lt;kolPrint;i++){
	if(col>maxcol){/*end of row*/
		col=0;
		row++;
		if(row&lt;=maxrow){
			doc.wl('&lt;/tr>');
			doc.wl('&lt;tr>');
		}
	}

	if(row>maxrow){/*end of page*/
		doc.wl('&lt;/tr>');
		doc.wl('&lt;/table>');

		doc.wl('&lt;br clear="all" />');
		doc.wl('&lt;div class="page-break">&lt;/div>');

		row=0;
		col=0;
	}

 	if(row==0 &amp;&amp; col==0){
		/*doc.wl('&lt;table border="0" align="left"  cellspacing="0" cellpadding="2" style="border-style:solid;border-width:1px;border-color:black">');*/
		doc.wl('&lt;table border="1" align="left"  cellspacing="0" cellpadding="2" style="border-style:solid;border-width:1px;border-color:black">');
		doc.wl('&lt;tr>');
	}
	doc.wl('&lt;td>');
 	writeone(titleStr);
	doc.wl('&lt;/td>');
	col++;
 }

}


kol=prompt('Количество этикеток:','1');
if(kol==null){
	throw('Обработка прервана!');
}
var titleStr;


/*idOrg = util.value("nums", "cnt", 5);*/
/*default own organiztion*/
qtmp=query.newq();
qtmp.select("select * from nums where _id = 5");
qtmp.first();
idOrg=qtmp.getint("cnt");
titleStr=util.value("accounts", "account_name", idOrg)+', ИНН: '+util.value("accounts", "account_inn", idOrg);
titleStr=prompt('Заголовок этикеток:',titleStr);
if(titleStr==null){
	throw('Обработка прервана!');
}

var isSelected=false;
if(typeof idList != "undefined"){
	if(idList.length>0){
		isSelected=confirm("Выводить только для выделенных записей?");
	}
}


usl=false;
mess.show();
doc.copybarfont();

 doc.openoutfile("labels16.htm");
 doc.wl('&lt;html>');
 doc.wl('&lt;head>');
 doc.wl('&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');

doc.wl('&lt;STYLE TYPE="text/css">');
doc.wl('P.breakhere {page-break-before: always}');
doc.wl('&lt;/STYLE>');

doc.wl('	&lt;style type="text/css">');
doc.wl('	table		{font-size: 10pt;}');

doc.wl('		@media screen {');
doc.wl('			.page-break	{ height:10px;  border-top:1px dotted #999; margin-bottom:13px; }');
doc.wl('		}');
doc.wl('		@media print {');
doc.wl('			.page-break { height:0; page-break-before:always; margin:0; border-top:none; }');
doc.wl('		}');
doc.wl('	&lt;/style>');
doc.wl('');

doc.wl('&lt;style>@font-face {');
doc.wl(' font-family: \'BarFont\';');
/*doc.wl(' src: url(\'file:///android_asset/barfont1.ttf\') format(\'truetype\');');*/
doc.wl(' src: url(\'barfont1.ttf\') format(\'truetype\');');
doc.wl(' font-weight: normal;');
doc.wl(' font-style: normal;');
doc.wl(' -fs-pdf-font-embed: embed;');
doc.wl(' -fs-pdf-font-encoding: Identity-H;');
doc.wl('}&lt;/style>');


 doc.wl('&lt;/head>');
 doc.wl('&lt;body>');

var qstr= 'select items.*, group_name, unit_name, country_name '+
	' from items left outer join groups on groups._id = item_group_id '+
	' left outer join units on units._id = item_unit_id '+
	' left outer join countries on countries._id = item_country_id ';

var qOne;
/*get data for items*/
if(isSelected){
 for(k=0;k&lt;idList.length;k++){
	qOne=qstr+'  where items._id='+idList[k];
 	if(q.select(qOne) &amp;&amp; q.first()){
		doit(kol);
		mess.say(q.getstring('item_name'));
	}
 }

}
else{
 qstr+='  where '+doc.itemsfilter();

 isOk = q.select(qstr);

 if(isOk &amp;&amp; q.first()){
 do{
 if(mess.iscancel()) break;

	doit(kol);
 	mess.say(q.getstring('item_name'));
 }while(q.next());
 }
} 


doc.wl('&lt;/body>&lt;/html>');
doc.outclose();
mess.close();
doc.setExtEditor("vvshtml2");
doc.open();
</FormScript>
    </Form>



</Forms>
