Показать сообщение отдельно
  #21 (permalink)  
Старый 09.12.2019, 05:07
Интересующийся
Отправить личное сообщение для vandalv Посмотреть профиль Найти все сообщения от vandalv
 
Регистрация: 08.12.2019
Сообщений: 19

Спасибо, благодаря вам подвинулся с места. Запихал все в html. Единственное, не сообразил как цену, общую стоимость, количество, товары отдельными полями добавить. Сортировку пока не победил. Не все в один лень делается. Спасибо вы очень помогли!
<!doctype html>
<html lang="en">
<head>
	<title>JavaScript Tutorial - Arrays and Loops</title>
	<link rel="stylesheet" href="css/foundation.min.css"></link>
	<style>
    th
    {
      background: white;
      height:50px;
    }
    table,th,td
    {
      border:2px solid green;
    }
    table
    {
      width:40%;
      color:solid green;
      text-align:center;
    }
  </style>
</head>
<body>

	<!-- JAVASCRIPT -->
	<script type="text/javascript">
	function randomValueBetween(min, max) {
    return Math.random() * (max - min) + min;
}
function randomDate(date1 = '01-01-2017', date2 = new Date().toLocaleDateString()) {
  date1 = new Date(date1).getTime();
  date2 = new Date(date2).getTime();
  return new Date(randomValueBetween(date2, date1)).toLocaleDateString()
}
function getElem(arr)
{
  return arr[randomValueBetween(0, arr.length)|0]
}
var sellern = "Dogserf";
var sellernip = "2254913384";
var selleradr = "2592  Davis Place";
var sellerpost = "87918997";
var selleracc = "85090922712148335820";
var firmString="Justsurf,DietyElephant,MetaHound,CuteOx,SweetFrank,PonyMice,BoarsAndInu,KrazyRat,GlumCats,ManedPie,ZipperPuppy,AKCStew,FoxFlock,NerdyLion,SnipeSkull,KittenFur,SilentRabbit,Pupski,BearSide,Mouse17C";
var firms = firmString.split(",");
var adressString="3118  Palmer Road,4996  Watson Lane,504  Hawks Nest Lane,3432  Glory Road,157  Crosswind Drive,3063  New York Avenue,997  Jadewood Drive,1630  Mulberry Lane,1710  Jehovah Drive,409  Monroe Street,3538  Hickman Street,68  Powder House Road,2449  Eagle Drive,1143  Collins Avenue,2848  Snyder Avenue,3797  Willis Avenue,4008  Alexander Avenue,3406  Wines Lane,1610  Gorby Lane";
var adress = adressString.split(",");
var numGen = function(length) {
return Array.from({length}, _=> Math.floor(Math.random()*10)).join("");
};
var vegString=["Apple","Apricots","Avocado","Banana","Blackberries", "Blueberries","Cantaloupe","Carambola","Cherimoya","Cherries","Clementine","Coconut Meat","Durian","Grapefruit","Jackfruit","Lemon","Mango","Mangosteen","Peaches","Raspberries","Tangerine"];
var bases = [];
for (var i = 0; i < 10; )
{
  var base = new Object();
  base.pref = (++i).toString().padStart(5, "0");
  base.sellern = sellern;
  base.sellernip = sellernip;
  base.selleradr = selleradr;
  base.sellerpost = sellerpost;
  base.selleracc = selleracc;
  base.repeated = getElem(firms);
  base.repeated1 = getElem(adress);
  base.account=numGen(20);
  base.postal=numGen(8);
  base.total = 0;
  base.netto = 0;
  base.produkt = Array.from({length : 10}, _ => {
  var num = randomValueBetween(100, 999)|0,
      price = randomValueBetween(1, 100).toFixed(2),
      count = randomValueBetween(1, 100)|0;
      base.total += price * count;
      base.netto = base.total * 1.23;
      return `\nPRODUCT - ${getElem(vegString)}    PRICE - ${randomValueBetween(1, 100).toFixed(2)}$   QUANTITY - ${randomValueBetween(1, 100)|0} p.`
  }).join('\n') + `\nTOTAL BRUTTO PRICE: ${base.total.toFixed(2)}$ ` + `  \nTOTAL NETTO PRICE: ${base.netto.toFixed(2)}$ `;
  
  

  bases.push(base);
}

	document.write('<table>');
	document.write('<tr><th>Faktura№</th><th>Date</th><th>Client</th><th>Adress</th><th>Account№</th></tr>');
	for (var k = 0; k < bases.length; k++)
	{
		document.write("<tr><td>" + bases[k].pref +  "</td>" + "<td>" + randomDate() + "</td>" + "<td>" + bases[k].repeated +"</td>" + "<td>" + bases[k].repeated1 + "<td>" + bases[k].account +"</td></tr>");
	}
	
	document.write('</table>');
	</script>
	<!-- END JAVASCRIPT -->
</body>
</html>
Ответить с цитированием