Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JS :
- //Смяна,промяна на contentEditables дивове и валидации
- table.onmousedown = function (e) {
- var t = e.target,
- startDate = document.getElementById('firstDate').value.split('-').reverse().join('');
- if (t.className.indexOf('table-cell') >= 0 && t.className.slice(t.className.lastIndexOf('c')) != 'c1') {
- var prevState = t.innerHTML;
- t.contentEditable = "true";
- t.onkeydown = function (e) {
- if (e.keyCode == 13) {
- t.blur();
- t.contentEditable = "false";
- }
- }
- t.onblur = function (e) {
- var cellPosition = t.className.slice(t.className.lastIndexOf('c') + 1);
- if (cellPosition > 9 || cellPosition == 4) {
- if (isNaN(t.innerHTML)) {
- t.innerHTML = prevState;
- return;
- }
- if (t.innerHTML && Number(cellPosition) != 4 && t.innerHTML != prevState) {
- t.innerHTML = Number(t.innerHTML).toFixed(2);
- calculateFooter();
- }
- }
- if (cellPosition == 3) {
- if (t.innerHTML != '01' || t.innerHTML != '02' || t.innerHTML != '03' || t.innerHTML != '07' || t.innerHTML != '09'
- || t.innerHTML != '11' || t.innerHTML != '12' || t.innerHTML != '13' || t.innerHTML != '91' || t.innerHTML != '92'
- || t.innerHTML != '93' || t.innerHTML != '94') {
- t.innerHTML = prevState;
- return;
- }
- }
- if (cellPosition == 2) {
- if (isNaN(t.innerHTML)) {
- t.innerHTML = prevState;
- return;
- } else {
- if (Number(t.innerHTML) < 0 || Number(t.innerHTML) > 9999) {
- t.innerHTML = prevState;
- return;
- }
- }
- }
- if (cellPosition == 5) {
- if (t.innerHTML.length != 10 || (t.innerHTML).match(/\w+/g).length != 3 || (t.innerHTML).match(/\//g).length != 2) {
- t.innerHTML = prevState;
- return;
- }
- }
- if (t.innerHTML != prevState) {
- changeTxtState(t.parentNode.children[0].innerHTML, cellPosition, t.innerHTML);
- startDeclaration(startDate);
- }
- }
- }
- }
- //Скриване/показване на празните клетки
- document.getElementById('pokupkiHideEmptyCells').onclick = function () {
- var strArray = [],
- styleTag = document.getElementById('pokupkiStyle'),
- headerWidth = 0;
- //Проверка дали вече не са скрити колоните
- if (this.innerHTML == 'Покажи празните колони') {
- styleTag.innerHTML = '';
- this.innerHTML = 'Скрии празните колони'
- return;
- }
- this.innerHTML = 'Покажи празните колони';
- for (var z = 6; z < table.children[0].children.length; z++) {
- headerWidth += table.children[0].children[z].offsetWidth;
- if (purchFooter[z - 6] == '0.00') {
- styleTag.innerHTML += '#main-wrapper .c' + (z + 4) + '{ width:0px; display:none; }';
- }
- if (z == 12) {
- strArray.push('#nameHeader > .table-cell:nth-child(2), #footer > .table-row:last-child > .table-cell:nth-child(2) { width:' + headerWidth + 'px;}');
- headerWidth = 0;
- }
- if (z == table.children[0].children.length - 1) {
- (headerWidth > 0) ? strArray.push('#nameHeader > .table-cell:nth-child(3), #footer > .table-row:last-child > .table-cell:nth-child(3) { width:' + headerWidth + 'px;}') :
- strArray.push('#nameHeader > .table-cell:nth-child(3), #footer > .table-row:last-child > .table-cell:nth-child(3) { display:none;}');
- }
- }
- strArray.push('@media print { #main-wrapper {width:133%;}');
- styleTag.innerHTML += strArray.join('');
- }
- //Построяване на таблицата с дневника на продажбите
- function buildPokupkiTable(arr, danPer) {
- var strArray = [],
- rowCounter = 1,
- cells = [];
- purchFooter = [];
- document.getElementById('InZDDS').textContent = 'BG175140782';
- document.getElementById('DanPer').textContent = danPer.substr(4, 2) + '/' + danPer.substr(0, 4);
- for (var i = 0; i < arr.length; i++) {
- var client = arr[i].partner.slice(arr[i].partner.lastIndexOf(':') + 1),
- date = arr[i].date.slice(6, 8) + '/' + arr[i].date.slice(4, 6) + '/' + arr[i].date.slice(0, 4),
- vat = Number(arr[i].vat).toFixed(2) || ' ',
- sumWithoutVat = ((Number(arr[i].sum) - Number(arr[i].vat)).toFixed(2)) || ' ',
- type = arr[i].type;
- if (isDateInRange(danPer, date)) continue;
- cells[i] = [];
- cells[i][0] = rowCounter;
- cells[i][1] = '9999';
- cells[i][2] = (arr[i].НОММД && arr[i].НОММД != 0 && arr[i].НОММД != '') ? arr[i].НОММД : arr[i].ВИДДОК;
- cells[i][3] = (arr[i].НОММД && arr[i].НОММД != 0 && arr[i].НОММД != '') ? arr[i].НОММД : arr[i].docNumber;
- cells[i][4] = date;
- cells[i][5] = '999999999999999'; // ако няма се поставят 999999999999999;
- cells[i][6] = client;
- cells[i][7] = arr[i].comment || 'Покупки';
- cells[i][8] = (type == 51) ? '01' : (type == 52) ? '02' : '';
- cells[i][9] = (type == 3 || type == 18 || type == 21 || type == 43) ? sumWithoutVat : (type == 35 || type == 36) ? arr[i].СУМАБДК : '';
- cells[i][10] = (type == 1 || type == 17 || type == 20 || type == 44 || type == 45) ? sumWithoutVat : (type == 35 || type == 36) ? arr[i].СУМАДК : '';
- cells[i][11] = (type == 1 || type == 17 || type == 20 || type == 44 || type == 45) ? vat : (type == 35 || type == 36) ? (arr[i].ДДСДК != 0) ? arr[i].ДДСДК : arr[i].СУМАДК * 0.2 : '';
- cells[i][12] = (type == 35 || type == 36) ? arr[i].СУМАЧДК : '';
- cells[i][13] = (type == 35 || type == 36) ? (arr[i].ДДСДК != 0) ? arr[i].ДДСДК : arr[i].СУМАЧДК * 0.2 : '';
- cells[i][14] = (type == 33 || type == 34) ? vat : '';
- cells[i][15] = (type == 4 || type == 38) ? arr[i].sum : '';
- filloutput(cells[i], danPer);
- strArray.push('<div class="table-row">')
- for (var a = 0; a < cells[i].length; a++) {
- var classCounter = a + 1;
- strArray.push('<div class="table-cell c' + classCounter + '">' + cells[i][a] + '</div>');
- }
- strArray.push('</div>');
- rowCounter++;
- }
- table.innerHTML = strArray.join('');
- pokupkiDone = true;
- calculateFooter();
- }
- //Попълване на стринга с информация за дневника на покупките, който ще бъде записан в .txt формат
- function filloutput(arr, danPer) {
- var NumberZDDS = document.getElementById('InZDDS').innerHTML;
- pokupkiTxt += (addSymbols('BG175140782', 15) + addSymbols(danPer.substr(0, 4) + danPer.substr(4, 2), 6) + addSymbols(arr[1], 4, true) + addSymbols(arr[0], 15, true) + addSymbols(arr[2], 2) +
- addSymbols(arr[3], 20) + addSymbols(arr[4], 10) + addSymbols(arr[5], 15) + addSymbols(arr[6], 50) + addSymbols(arr[7], 30) + addSymbols(Number(arr[9]).toFixed(2), 15, true) +
- addSymbols(Number(arr[10]).toFixed(2), 15, true) + addSymbols(Number(arr[11]).toFixed(2), 15, true) + addSymbols(Number(arr[12]).toFixed(2), 15, true) +
- addSymbols(Number(arr[13]).toFixed(2), 15, true) + addSymbols(Number(arr[14]).toFixed(2), 15, true) + addSymbols(Number(arr[15]).toFixed(2), 15, true) + addSymbols(arr[8], 2) + '\r\n');
- }
- // Преработва .txt файлът
- function cutLineFromFile(str) {
- var charLenght = [15, 6, 4, 15, 2, 20, 10, 15, 50, 30, 15, 15, 15, 15, 15, 15, 15, 2],
- lenOfLine = 274,
- lines = str.split('\r\n'),
- currentLine = [],
- begginingChar = 0,
- startDate = document.getElementById('firstDate').value.split('-').reverse().join('');
- lines.pop(1);
- for (var a = 0; a < lines.length; a++) {
- for (var b = 0; b < charLenght.length; b++) {
- currentLine.push(lines[a].substr(begginingChar, charLenght[b]))
- begginingChar += charLenght[b];
- if (b == charLenght.length - 1) {
- begginingChar = 0;
- printLine(currentLine);
- currentLine = [];
- }
- }
- }
- calculateFooter();
- startDeclaration(startDate);
- }
- // Добавя нов ред в таблицата от преработеният .txt файл
- function printLine(arr) {
- var strArray = [],
- isTakkenLastIndex = false,
- classCounter = 1,
- rowCounter = (table.children[0]) ? Number(table.children[table.children.length - 1].children[0].innerHTML) + 1 : 1;
- strArray.push('<div class="table-row">')
- for (var i = 4; i < arr.length - 1; i++) {
- arr[i] = arr[i].replace(/\s/g, '');
- if (arr[i] == '0.00') arr[i] = '';
- if (i == 4) {
- arr[3] = addSymbols(rowCounter, 15, true);
- pokupkiTxt += arr.join('') + '\r\n';
- strArray.push('<div class="table-cell c' + classCounter + '">' + rowCounter + '</div>');
- strArray.push('<div class="table-cell c' + (classCounter + 1) + '">' + arr[2] + '</div>')
- }
- if (i == 10) {
- if (!isTakkenLastIndex) {
- strArray.push('<div class="table-cell c' + (classCounter + 2) + '">' + arr[arr.length - 1] + '</div>')
- isTakkenLastIndex = true;
- i--;
- rowCounter++;
- classCounter++;
- continue;
- }
- }
- strArray.push('<div class="table-cell c' + (classCounter + 2) + '">' + arr[i] + '</div>');
- rowCounter++;
- classCounter++;
- }
- strArray.push('</div>');
- table.innerHTML += strArray.join('');
- }
- //след промяна на някоя от клетките промяната се отразява и в txt файлът
- function changeTxtState(rowNumber, cell, text) {
- var rowLenght = [15, 4, 2, 20, 10, 15, 50, 30, 2, 15, 15, 15, 15, 15, 15, 15],
- charLenght = [15, 6, 4, 15, 2, 20, 10, 15, 50, 30, 15, 15, 15, 15, 15, 15, 15, 2],
- //ИН по зддс, Дан.пер., c2, c1, c3, c4, c5 ,c6, c7, c8, c10, c11, c12, c13, c14, c15, c16, c9;
- // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
- positionInTxt = 0,
- len = (cell > 2 && cell < 9) ? Number(cell) + 1 : (cell == 2 || cell > 9 && cell < 17) ? Number(cell) : (cell == 9) ? 17 : 0,
- currentPokupkiTxt = pokupkiTxt.split('\r\n');
- for (var i = 0; i < len; i++) {
- positionInTxt += charLenght[i];
- }
- currentPokupkiTxt[rowNumber - 1] = currentPokupkiTxt[rowNumber - 1].slice(0, positionInTxt) + addSymbols(text, rowLenght[Number(cell) - 1], true) +
- currentPokupkiTxt[rowNumber - 1].slice(positionInTxt + Number(rowLenght[Number(cell) - 1]));
- pokupkiTxt = currentPokupkiTxt.join('\r\n');
- }
- //пресмята фоотера
- function calculateFooter() {
- var footerFullSum = document.getElementById('footerFullSum'),
- total = 0;
- for (var a = 9; a < 16; a++) {
- for (var b = 0; b < table.children.length; b++) {
- total += Number(table.children[b].children[a].innerHTML);
- }
- footerFullSum.children[a - 7].innerHTML = (total != 0) ? total.toFixed(2) : ' ';
- purchFooter[a - 9] = total.toFixed(2);
- total = 0;
- }
- }
- CSS :
- body {
- margin: 0;
- padding: 0;
- }
- div {
- display: inline-block;
- float: left;
- }
- body * {
- box-sizing: border-box;
- }
- #main-wrapper {
- width: 1750px;
- border-left: 1px solid #999999;
- font-size: 11px;
- }
- .table-row {
- width: 100%;
- }
- .table-cell {
- border-right: 1px solid #999999;
- }
- #nameHeader, #nameHeader > .table-cell {
- height: 60px;
- }
- #nameHeader > .table-cell:first-child, #nameHeader > .table-cell:nth-child(3) {
- width: 20%;
- }
- #nameHeader > .table-cell:nth-child(2) {
- width: 60%;
- }
- #nameHeader > .table-cell:first-child > div:first-child {
- font-size: 20px;
- font-weight: bold;
- padding-left: 10px;
- }
- #nameHeader > .table-cell:first-child > div:nth-child(2), #nameHeader > .table-cell:first-child > div:nth-child(4) {
- width: 51%;
- padding-left: 20%;
- }
- #nameHeader > .table-cell, #tableHeader > .table-cell, #tableHeadersFooter > .table-cell {
- border-bottom: 1px solid #999999;
- }
- #nameHeader > .table-cell {
- border-top: 1px solid #999999;
- }
- #tableHeader > .table-cell {
- height: 50px;
- }
- #tableHeader > .table-cell {
- text-align: center;
- }
- #tableHeader > .table-cell:first-child, #table > .table-row > .table-cell:first-child {
- width: 1.2%;
- }
- #tableHeader > .table-cell:nth-child(2), #table > .table-row > .table-cell:nth-child(2) {
- width: 1.8%;
- }
- #tableHeader > .table-cell:nth-child(3) {
- width: 11%;
- }
- #tableHeader > .table-cell:nth-child(4), #table > .table-row > .table-cell:nth-child(6) {
- width: 6%;
- }
- #tableHeader > .table-cell:nth-child(3) > .table-cell:first-child {
- height: 36px;
- }
- #tableHeader > .table-cell:nth-child(3) > .table-cell:nth-child(2), #tableHeader > .table-cell:nth-child(3) > .table-cell:nth-child(3), #tableHeader > .table-cell:nth-child(3) > .table-cell:nth-child(4) {
- height: 14px;
- }
- #tableHeader > .table-cell:nth-child(3) > .table-cell:first-child {
- width: 100%;
- border-right: none;
- border-bottom: 1px solid #999999;
- }
- #tableHeader > .table-cell:nth-child(3) > .table-cell:nth-child(2) {
- width: 12%;
- }
- #tableHeader > .table-cell:nth-child(3) > .table-cell:nth-child(3) {
- width: 50%;
- }
- #tableHeader > .table-cell:nth-child(3) > .table-cell:nth-child(4) {
- width: 38%;
- border-right: none;
- }
- #tableHeader > .table-cell:nth-child(5), #table > .table-row > .table-cell:nth-child(7) {
- width: 10%;
- }
- #tableHeader > .table-cell:nth-child(6), #tableHeader > .table-cell:nth-child(7), #table > .table-row > .table-cell:nth-child(8), #table > .table-row > .table-cell:nth-child(9) {
- width: 4%;
- }
- #tableHeader > .table-cell:nth-child(8), #tableHeadersFooter > .table-cell:nth-child(2), #footer .table-row > .table-cell:nth-child(3), #table > .table-row > .table-cell:nth-child(10) {
- width: 10%;
- }
- #tableHeader > .table-cell:nth-child(9), #tableHeadersFooter > .table-cell:nth-child(3), #footer .table-row > .table-cell:nth-child(4), #table > .table-row > .table-cell:nth-child(11) {
- width: 14%;
- }
- #tableHeader > .table-cell:nth-child(10), #tableHeadersFooter > .table-cell:nth-child(4), #footer .table-row > .table-cell:nth-child(5), #table > .table-row > .table-cell:nth-child(12) {
- width: 5%;
- }
- #tableHeader > .table-cell:nth-child(11), #tableHeadersFooter > .table-cell:nth-child(5), #footer .table-row > .table-cell:nth-child(6), #table > .table-row > .table-cell:nth-child(13) {
- width: 13%;
- }
- #tableHeader > .table-cell:nth-child(12), #tableHeadersFooter > .table-cell:nth-child(6), #footer .table-row > .table-cell:nth-child(7), #table > .table-row > .table-cell:nth-child(14) {
- width: 5%;
- }
- #tableHeader > .table-cell:nth-child(13), #tableHeadersFooter > .table-cell:nth-child(7), #footer .table-row > .table-cell:nth-child(8), #table > .table-row > .table-cell:nth-child(15) {
- width: 8%;
- }
- #tableHeader > .table-cell:nth-child(14), #tableHeadersFooter > .table-cell:nth-child(8), #footer .table-row > .table-cell:nth-child(9), #table > .table-row > .table-cell:nth-child(16) {
- width: 7%;
- }
- #tableHeadersFooter > .table-cell:first-child {
- width: 38%;
- text-align: right;
- padding-right: 2%;
- }
- #tableHeadersFooter > .table-cell {
- background: #d8d8ff;
- }
- #tableHeader > .table-cell:nth-child(5) {
- line-height: 50px;
- }
- #footer > .table-row:first-child > .table-cell, #footer .table-row:nth-child(2) > .table-cell {
- border-bottom: 1px solid #999999;
- height: 15px;
- background: #d8d8ff;
- }
- #footer .table-row > .table-cell:first-child {
- width: 30%;
- border-bottom: none;
- background-color: transparent;
- }
- #footer .table-row > .table-cell:nth-child(2) {
- width: 8%;
- text-align: right;
- padding-right: 5px;
- }
- #footer > .table-row:nth-child(3) > .table-cell {
- height: 50px;
- line-height: 50px;
- }
- #footer > .table-row:nth-child(3) > .table-cell:first-child, #footer > .table-row:nth-child(3) > .table-cell:nth-child(3) {
- width: 20%;
- border-right: none;
- }
- #footer > .table-row:nth-child(3) > .table-cell:nth-child(2) {
- width: 60%;
- text-align: left;
- }
- #footer > .table-row:nth-child(3) > .table-cell:nth-child(2) span {
- padding-left: 16.5%;
- }
- #footer > .table-row:nth-child(3) > .table-cell:first-child span:first-child {
- padding-left: 10px;
- }
- #footer > .table-row:nth-child(3) > .table-cell:first-child span:nth-child(2) {
- padding-left: 50%;
- }
- #footer > .table-row:last-child > .table-cell {
- border-bottom: 1px solid #999999;
- }
- #table > .table-row > .table-cell:nth-child(3) {
- width: 1.32%;
- }
- #table > .table-row > .table-cell:nth-child(4) {
- width: 5.5%;
- }
- #table > .table-row > .table-cell:nth-child(5) {
- width: 4.18%;
- }
- #table > .table-row > .table-cell, #tableHeadersFooter > .table-cell {
- border-bottom: 1px solid #999999;
- }
- #table > .table-row > .table-cell {
- overflow: hidden;
- height: 15px;
- }
- @media print {
- #main-wrapper {
- width:100%;
- }
- nav, #pokupkiHideEmptyCells {
- display: none;
- }
- #main-wrapper > * {
- font-size: 7px;
- }
- #main-wrapper #nameHeader > .table-row:first-child > .table-cell:first-child {
- font-size: 16.5px;
- }
- }
- html :
- <div id="main-wrapper">
- <div id="nameHeader" class="table-row">
- <div class="table-cell">
- <div>ДНЕВНИК НА ПОКУПКИТЕ</div>
- <div>ИН по ЗДДС:</div><div id="InZDDS"> </div>
- <div>Данъчен период:</div><div id="DanPer"> </div>
- </div>
- <div class="table-cell"><button id="pokupkiHideEmptyCells" class="pokupkiBtns">Скрии празните колони</button></div>
- <div class="table-cell"></div>
- </div>
- <div id="tableHeader" class="table-row">
- <div class="table-cell c1">N по ред</div>
- <div class="table-cell c2">Клон</div>
- <div class="table-cell">
- <div class="table-cell">Документ</div>
- <div class="table-cell c3">Вид</div>
- <div class="table-cell c4">Номер</div>
- <div class="table-cell c5">Дата</div>
- </div>
- <div class="table-cell c6">Идентиф. номер на контр. доставчик</div>
- <div class="table-cell c7">Име на контрагента (доставчик)</div>
- <div class="table-cell c8">Вид на стоката услугата</div>
- <div class="table-cell c9">Доставка по чл. 163а от ЗДДС</div>
- <div class="table-cell c10">ДО и данък на получ.дост. ВОП, чл.82,ал2-5 ЗДДС и внос без право на дан.кред. или без данък</div>
- <div class="table-cell c11">ДО на пол.дост ВОП,чл.82 ал.2-5 ЗДДС,внос, ДО на получ. дост. използвани за дост. по чл.69 ал 2 ЗДДС с право на ПДК</div>
- <div class="table-cell c12">ДДС с право на пълен данъчен кредит</div>
- <div class="table-cell c13">ДО на пол.дост ВОП,чл.82 ал.2-5 ЗДДС, внос, ДО на получ. дост. използвани за дост.по чл.69 ал.2 ЗДДС с право на ЧДК</div>
- <div class="table-cell c14">ДДС с право на частичен данъчен кредит</div>
- <div class="table-cell c15">Годишна корекция по чл. 73, ал8 ЗДДС</div>
- <div class="table-cell c16">ДО при придобиване на стоки от тристр.операция</div>
- </div>
- <div id="tableHeadersFooter" class="table-row">
- <div class="table-cell">ОБЩО:</div>
- <div class="table-cell c10"> </div>
- <div class="table-cell c11"> </div>
- <div class="table-cell c12"> </div>
- <div class="table-cell c13"> </div>
- <div class="table-cell c14"> </div>
- <div class="table-cell c15"> </div>
- <div class="table-cell c16"> </div>
- </div>
- <div id="table" class="table-row"></div>
- <div id="footer" class="table-row">
- <div class="table-row">
- <div class="table-cell"> </div>
- <div class="table-cell c8c9">Общо без вид 11,12,13:</div>
- <div class="table-cell c10"> </div>
- <div class="table-cell c11"> </div>
- <div class="table-cell c12"> </div>
- <div class="table-cell c13"> </div>
- <div class="table-cell c14"> </div>
- <div class="table-cell c15"> </div>
- <div class="table-cell c16"> </div>
- </div>
- <div class="table-row" id="footerFullSum">
- <div class="table-cell"> </div>
- <div class="table-cell c8c9">Общо:</div>
- <div class="table-cell c10"> </div>
- <div class="table-cell c11"> </div>
- <div class="table-cell c12"> </div>
- <div class="table-cell c13"> </div>
- <div class="table-cell c14"> </div>
- <div class="table-cell c15"> </div>
- <div class="table-cell c16"> </div>
- </div>
- <div class="table-row">
- <div class="table-cell">
- <span>Длъжност:</span>
- <span>Управител:</span>
- </div>
- <div class="table-cell">
- <span>Подпис и печат:</span>
- </div>
- <div class="table-cell" style="border-right:1px solid #999999;"></div>
- </div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement