Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var requests = 0,
- requestMonthSorted = {};
- document.getElementById('start-procedura').onclick = function () {
- var fromDate = document.getElementById('procedura-from-date').innerHTML,
- toDate = document.getElementById('procedura-to-date').innerHTML,
- toDateAsDate = new Date(toDate.slice(0, 4), Number(toDate.slice(4)), 0, 0, 0, 0, 0, 0),
- month = (String(toDateAsDate.getMonth()).length == 1) ? '0' + (toDateAsDate.getMonth() + 1) : String(toDateAsDate.getMonth() + 1),
- day = (String(toDateAsDate.getDate()).length == 1) ? '0' + toDateAsDate.getDate() : String(toDateAsDate.getDate());
- document.getElementById('col-wrapper').innerHTML = '';
- var allRequests = ['{"doc":"-Ф"}', '{"doc":"-ФЕ"}', '{"doc":"-П"}', '{"doc":"-ФИ"}', '{"doc":"-ФИЕ"}', '{"doc":"-КП"}', '{"doc":"-НА"}', '{"doc":"+Ф"}', '{"doc":"+ФЕ"}', '{"doc":"-П"}', '{"doc":"+МД"}'];
- console.time('Изпращане на заявките')
- for (var i = 0; i < allRequests.length; i++) {
- sendRequest(["documents", "ЛЕЙДИ СОФИЯ АД", fromDate + '01', toDateAsDate.getFullYear() + month + day, "", "forward", allRequests[i], "false"], false, function (pokupki, prodagbi) {
- console.timeEnd('Изпращане на заявките')
- console.time('Обработка на заявките');
- calculateDataToMonths(pokupki, prodagbi, fromDate, toDate);
- console.timeEnd('Обработка на заявките');
- });
- }
- };
- function calculateDataToMonths(pokupki, prodagbi, startDate, endDate) {
- var proceduraData = {};
- proceduraData['pokupki'] = {};
- proceduraData['prodagbi'] = {};
- for (var a = 0; a < pokupki.length; a++) {
- var month = pokupki[a].date.slice(4, 6),
- year = pokupki[a].date.slice(0, 4);
- if (year == startDate.slice(0, 4) || year == endDate.slice(0, 4)) {
- if (proceduraData.pokupki[month]) {
- proceduraData.pokupki[month].push(pokupki[a]);
- } else {
- proceduraData.pokupki[month] = [];
- proceduraData.pokupki[month].push(pokupki[a]);
- }
- }
- }
- for (var a = 0; a < prodagbi.length; a++) {
- var month = prodagbi[a].date.slice(4, 6),
- year = prodagbi[a].date.slice(0, 4);
- if (year == startDate.slice(0, 4) || year == endDate.slice(0, 4)) {
- if (proceduraData.prodagbi[month]) {
- proceduraData.prodagbi[month].push(prodagbi[a]);
- } else {
- proceduraData.prodagbi[month] = [];
- proceduraData.prodagbi[month].push(prodagbi[a]);
- }
- }
- }
- calculateDeclarationData(proceduraData, startDate, endDate);
- }
- function calculateDeclarationData(proceduraData, startDate, endDate) {
- var posiblePeriods = calculatePosiblePeriods(startDate.slice(4,6), endDate.slice(4,6)),
- pokupkiFooter = [0, 0, 0, 0, 0, 0, 0],
- prodagbiFooter = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
- for (var i = 0; i < posiblePeriods.length; i++) {
- var pokupkiForPer = proceduraData.pokupki[posiblePeriods[i]],
- prodagbiForPer = proceduraData.prodagbi[posiblePeriods[i]];
- if (pokupkiForPer) {
- for (var a = 0; a < pokupkiForPer.length; a++) {
- var currentDoc = calculatePokupkiInput(0, pokupkiForPer[a].header);
- pokupkiFooter[0] = (currentDoc[9]) ? pokupkiFooter[0] + Number(currentDoc[9]) : pokupkiFooter[0];
- pokupkiFooter[1] = (currentDoc[10]) ? pokupkiFooter[1] + Number(currentDoc[10]) : pokupkiFooter[1];
- pokupkiFooter[2] = (currentDoc[11]) ? pokupkiFooter[2] + Number(currentDoc[11]) : pokupkiFooter[2];
- pokupkiFooter[3] = (currentDoc[12]) ? pokupkiFooter[3] + Number(currentDoc[12]) : pokupkiFooter[3];
- pokupkiFooter[4] = (currentDoc[13]) ? pokupkiFooter[4] + Number(currentDoc[13]) : pokupkiFooter[4];
- pokupkiFooter[5] = (currentDoc[14]) ? pokupkiFooter[5] + Number(currentDoc[14]) : pokupkiFooter[5];
- pokupkiFooter[6] = (currentDoc[15]) ? pokupkiFooter[6] + Number(currentDoc[15]) : pokupkiFooter[6];
- }
- }
- if (prodagbiForPer) {
- for (var b = 0; b < prodagbiForPer.length; b++) {
- var currentDoc = calculateInputDocuments(prodagbiForPer[b]);
- prodagbiFooter[1] = (currentDoc[9]) ? prodagbiFooter[1] + Number(currentDoc[9]) : prodagbiFooter[1];
- prodagbiFooter[2] = (currentDoc[10]) ? prodagbiFooter[2] + Number(currentDoc[10]) : prodagbiFooter[2];
- prodagbiFooter[3] = (currentDoc[11]) ? prodagbiFooter[3] + Number(currentDoc[11]) : prodagbiFooter[3];
- prodagbiFooter[4] = (currentDoc[12]) ? prodagbiFooter[4] + Number(currentDoc[12]) : prodagbiFooter[4];
- prodagbiFooter[5] = (currentDoc[13]) ? prodagbiFooter[5] + Number(currentDoc[13]) : prodagbiFooter[5];
- prodagbiFooter[6] = (currentDoc[14]) ? prodagbiFooter[6] + Number(currentDoc[14]) : prodagbiFooter[6];
- prodagbiFooter[7] = (currentDoc[15]) ? prodagbiFooter[7] + Number(currentDoc[15]) : prodagbiFooter[7];
- prodagbiFooter[8] = (currentDoc[16]) ? prodagbiFooter[8] + Number(currentDoc[16]) : prodagbiFooter[8];
- prodagbiFooter[9] = (currentDoc[17]) ? prodagbiFooter[9] + Number(currentDoc[17]) : prodagbiFooter[9];
- prodagbiFooter[10] = (currentDoc[18]) ? prodagbiFooter[10] + Number(currentDoc[18]) : prodagbiFooter[10];
- prodagbiFooter[11] = (currentDoc[19]) ? prodagbiFooter[11] + Number(currentDoc[19]) : prodagbiFooter[11];
- prodagbiFooter[12] = (currentDoc[20]) ? prodagbiFooter[12] + Number(currentDoc[20]) : prodagbiFooter[12];
- prodagbiFooter[13] = (currentDoc[21]) ? prodagbiFooter[13] + Number(currentDoc[21]) : prodagbiFooter[13];
- prodagbiFooter[14] = (currentDoc[22]) ? prodagbiFooter[14] + Number(currentDoc[22]) : prodagbiFooter[14];
- prodagbiFooter[15] = (currentDoc[23]) ? prodagbiFooter[15] + Number(currentDoc[23]) : prodagbiFooter[15];
- prodagbiFooter[16] = (currentDoc[24]) ? prodagbiFooter[16] + Number(currentDoc[24]) : prodagbiFooter[16];
- prodagbiFooter[17] = (currentDoc[25]) ? prodagbiFooter[17] + Number(currentDoc[25]) : prodagbiFooter[17];
- }
- }
- startDeclaration('11111111', prodagbiFooter, pokupkiFooter, function (obj) {
- buildProceduraCol(obj, posiblePeriods[i]);
- });
- pokupkiFooter = [0, 0, 0, 0, 0, 0, 0];
- prodagbiFooter = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
- }
- }
- function calculatePosiblePeriods(startMonth, endMonth) {
- var arr = [],
- counter = 0;
- for (var i = Number(startMonth) ; i <= Number(endMonth) ; i++) {
- var month = (String(Number(startMonth) + counter).length == 1) ? '0' + (Number(startMonth) + counter) : String(Number(startMonth) + counter);
- arr.push(month);
- counter++;
- }
- return arr;
- }
- function buildProceduraCol(obj, month) {
- var colWrapper = document.getElementById('col-wrapper'),
- months = { '01': 'Януари', '02': 'Февруари', '03': 'Март', '04': 'Април', '05': 'Май', '06': 'Юни', '07': 'Юли', '08': 'Август', '09': 'Септември', '10': 'Октомври', '11': 'Ноември', '12': 'Декември' };
- var str = '<div class="procedura-col"><div class="procedura-col-cell">' + months[month] + '</div><div class="procedura-col-cell"> </div><div class="procedura-col-cell">' + obj['01'] + '</div>' +
- '<div class="procedura-col-cell">' + obj['20'] + '</div><div class="procedura-col-cell">' + obj['11'] + '</div><div class="procedura-col-cell">' + obj['21'] + '</div><div class="procedura-col-cell">' + obj['12'] + '</div>' +
- '<div class="procedura-col-cell">' + obj['22'] + '</div><div class="procedura-col-cell">' + obj['23'] + '</div><div class="procedura-col-cell">' + obj['13'] + '</div><div class="procedura-col-cell">' + obj['24'] + '</div>' +
- '<div class="procedura-col-cell">' + obj['14'] + '</div><div class="procedura-col-cell">' + obj['15'] + '</div><div class="procedura-col-cell">' + obj['16'] + '</div><div class="procedura-col-cell">' + obj['17'] + '</div>' +
- '<div class="procedura-col-cell">' + obj['18'] + '</div><div class="procedura-col-cell">' + obj['19'] + '</div><div class="procedura-col-cell">' + obj['30'] + '</div><div class="procedura-col-cell">' + obj['31'] + '</div>' +
- '<div class="procedura-col-cell">' + obj['41'] + '</div><div class="procedura-col-cell">' + obj['32'] + '</div><div class="procedura-col-cell">' + obj['42'] + '</div><div class="procedura-col-cell">' + obj['43'] + '</div>' +
- '<div class="procedura-col-cell">' + obj['33'] + '</div><div class="procedura-col-cell">' + obj['40'] + '</div><div class="procedura-col-cell">' + obj['50'] + '</div><div class="procedura-col-cell">' + obj['60'] + '</div>' +
- '<div class="procedura-col-cell">' + obj['70'] + '</div><div class="procedura-col-cell">' + obj['71'] + '</div></div>';
- colWrapper.innerHTML += str;
- }
- function calculatePokupkiInput(rowCounter, doc, ID, date) {
- var arr = [],
- type = doc.type,
- sumWithoutVat = ((Number(doc.sum) - ((doc.vat) ? Number(doc.vat) : 0))).toFixed(2) || ' ',
- client = doc.partner.slice(doc.partner.lastIndexOf(':') + 1),
- vat = Number(doc.vat).toFixed(2) || ' ';
- arr[0] = rowCounter;
- arr[1] = '9999';
- arr[2] = (doc.НОММД && doc.НОММД != 0 && doc.НОММД != '') ? doc.НОММД : doc.ВИДДОК;
- arr[3] = (doc.НОММД && doc.НОММД != 0 && doc.НОММД != '') ? doc.НОММД : doc.docNumber;
- arr[4] = date;
- arr[5] = (ID != '') ? ID : '999999999999999'; // ако няма се поставят 999999999999999;
- arr[6] = client;
- arr[7] = doc.comment || 'Покупки';
- arr[8] = (type == 51) ? '01' : (type == 52) ? '02' : '';
- arr[9] = (type == 3 || type == 18 || type == 21 || type == 43) ? sumWithoutVat : (type == 35 || type == 36) ? doc.СУМАБДК : '';
- arr[10] = (type == 1 || type == 17 || type == 20 || type == 44 || type == 45) ? sumWithoutVat : (type == 35 || type == 36) ? doc.СУМАДК : '';
- arr[11] = (type == 1 || type == 17 || type == 20 || type == 44 || type == 45) ? vat : (type == 35 || type == 36) ? (doc.ДДСДК != 0) ? doc.ДДСДК : doc.СУМАДК * 0.2 : '';
- arr[12] = (type == 35 || type == 36) ? doc.СУМАЧДК : '';
- arr[13] = (type == 35 || type == 36) ? (doc.ДДСДК != 0) ? doc.ДДСДК : doc.СУМАЧДК * 0.2 : '';
- arr[14] = (type == 33 || type == 34) ? vat : '';
- arr[15] = (type == 4 || type == 38) ? doc.sum : '';
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement