|
@@ -12,32 +12,128 @@ async function work (prefix, outfile) {
|
|
|
console.info(`Output file: ${outfile}`);
|
|
|
for await (let vestnik of eachVestnik(prefix)) {
|
|
|
for (let item of eachItem(vestnik)) {
|
|
|
+ const {id = '', url = "about:blank"} = item.zakazka && item.zakazka[0].$ || {};
|
|
|
if (hasCpv("45", item)) {
|
|
|
const v = oddiel_V(item);
|
|
|
if (v) {
|
|
|
- processV(v, item, async items => await writeFile(outfile, poorMansCsv(items) + "\r\n", {flag: "a"}));
|
|
|
+ processV(v, {
|
|
|
+ id,
|
|
|
+ url
|
|
|
+ }, item, async items => await writeFile(outfile, poorMansCsv(items) + "\r\n", {flag: "a"}));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function processV (v, item, out) {
|
|
|
- const zakazka = item.zakazka[0].$;
|
|
|
- const id = zakazka.id || '';
|
|
|
- const url = zakazka.url || "about:blank";
|
|
|
- const pocetPonuk = -1;
|
|
|
- const predpokladanaCena = '?';
|
|
|
- const konecnaCena = '?';
|
|
|
- const vitazIco = 0;
|
|
|
+const formComponentIdEndsWith = (value, searchString) => value.$.FormComponentId && value.$.FormComponentId.endsWith(searchString);
|
|
|
|
|
|
- out([id, url, pocetPonuk, predpokladanaCena, konecnaCena, vitazIco]);
|
|
|
+function processV ({value: oddielV, dive: diveV}, soFar, item, out) {
|
|
|
+ let processed = false;
|
|
|
+
|
|
|
+ for (let {tag, value, cancel, dive} of diveV()) {
|
|
|
+ if (tag === "RepeatingPart" && formComponentIdEndsWith(value, "-partZmluva")) {
|
|
|
+ cancel();
|
|
|
+ processed = processed || processZmluva({value, dive}, soFar, item, out);
|
|
|
+ }
|
|
|
+ if (tag === "Part" && (formComponentIdEndsWith(value, "-zadanieZakazky")||formComponentIdEndsWith(value, "-partV_2"))) {
|
|
|
+ cancel();
|
|
|
+ processed = processed || processZadanie({value, dive}, soFar, item, out);
|
|
|
+ }
|
|
|
+ if (tag === "Part" && formComponentIdEndsWith(value, "-partV_1")) {
|
|
|
+ cancel();
|
|
|
+ const {id, url} = soFar;
|
|
|
+ out([id, url, -1, 0, '-', 0, '-', 0]);
|
|
|
+ processed = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!processed) {
|
|
|
+ const {id, url} = soFar;
|
|
|
+ out([id, url, -1, '?', '?', '?', '?', 0]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function poorMansCsv (items) {
|
|
|
- return JSON.stringify(items).slice(1, -1);
|
|
|
+function processZmluva ({value: zmluva, dive: diveZmluva}, {id, url}, item, out) {
|
|
|
+ let pocetPonuk = 0;
|
|
|
+ let predpokladanaCena = '?';
|
|
|
+ let predpokladanaMena = '?';
|
|
|
+ let konecnaCena = '?';
|
|
|
+ let konecnaMena = '?';
|
|
|
+ let vitazIco = 0;
|
|
|
+
|
|
|
+ for (let {tag, value, cancel} of diveZmluva()) {
|
|
|
+ if (tag === "ShortText") {
|
|
|
+ if (formComponentIdEndsWith(value, "-pocetDorucenychPonuk") && value.$.Value) {
|
|
|
+ pocetPonuk = +value.$.Value;
|
|
|
+ }
|
|
|
+ if ((formComponentIdEndsWith(value, "-MN03_zmluvaPredpokladanaHodnota") || formComponentIdEndsWith(value, "-NM06_cena")) && value.$.Value) {
|
|
|
+ predpokladanaCena = value.$.Value
|
|
|
+ }
|
|
|
+ if (formComponentIdEndsWith(value, "-stCKHZ_Hodnota") && value.$.Value) {
|
|
|
+ konecnaCena = value.$.Value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tag === "DropDownList") {
|
|
|
+ if ((formComponentIdEndsWith(value, "-zmluvaMenaOd") || formComponentIdEndsWith(value, "-zmluvaCenaMena")) && value.SelectListValue) {
|
|
|
+ predpokladanaMena = value.SelectListValue[0].$.Code;
|
|
|
+ }
|
|
|
+ if ((formComponentIdEndsWith(value, "-zmluvaCenyMena") || formComponentIdEndsWith(value, "-zmluvaCenaMenaPonuky")) && value.SelectListValue) {
|
|
|
+ konecnaMena = value.SelectListValue[0].$.Code;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tag === "ContactSelectList" && formComponentIdEndsWith(value, "-zmluvaVitaz")) {
|
|
|
+ cancel();
|
|
|
+ vitazIco = (value.PersonData[0].CorporateBody[0].ICO||['?'])[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pocetPonuk === 0) return false;
|
|
|
+ out([id, url, pocetPonuk, predpokladanaCena, predpokladanaMena, konecnaCena, konecnaMena, vitazIco]);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+function processZadanie ({value: zmluva, dive: diveZmluva}, {id, url}, item, out) {
|
|
|
+ let pocetPonuk = 0;
|
|
|
+ let predpokladanaCena = '?';
|
|
|
+ let predpokladanaMena = '?';
|
|
|
+ let konecnaCena = '?';
|
|
|
+ let konecnaMena = '?';
|
|
|
+ let vitazIco = 0;
|
|
|
+
|
|
|
+ for (let {tag, value, cancel} of diveZmluva()) {
|
|
|
+ if (tag === "ShortText") {
|
|
|
+ if (formComponentIdEndsWith(value, "-pocetPrijatychPonuk") && value.$.Value) {
|
|
|
+ pocetPonuk = +value.$.Value;
|
|
|
+ }
|
|
|
+ if (formComponentIdEndsWith(value, "-prepokladanaHZ") && value.$.Value) {
|
|
|
+ predpokladanaCena = value.$.Value
|
|
|
+ }
|
|
|
+ if (formComponentIdEndsWith(value, "-konecnaHZ") && value.$.Value) {
|
|
|
+ konecnaCena = value.$.Value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tag === "DropDownList") {
|
|
|
+ if (formComponentIdEndsWith(value, "-menaHZ_SYNCHRONIZE") && value.SelectListValue) {
|
|
|
+ predpokladanaMena = value.SelectListValue[0].$.Code;
|
|
|
+ }
|
|
|
+ if (formComponentIdEndsWith(value, "-menaHZ") && value.SelectListValue) {
|
|
|
+ konecnaMena = value.SelectListValue[0].$.Code;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tag === "ContactSelectList" && formComponentIdEndsWith(value, "-kontaktNaDodavatela_alt")) {
|
|
|
+ cancel();
|
|
|
+ vitazIco = (value.PersonData[0].CorporateBody[0].ICO||['?'])[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pocetPonuk === 0) return false;
|
|
|
+ out([id, url, pocetPonuk, predpokladanaCena, predpokladanaMena, konecnaCena, konecnaMena, vitazIco]);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
+const poorMansCsv = items => JSON.stringify(items).slice(1, -1);
|
|
|
+
|
|
|
function hasCpv (prefix, item) {
|
|
|
for (let {tag, value, cancel} of eachFormElement(item)) {
|
|
|
if (tag === "Part") {
|
|
@@ -51,11 +147,11 @@ function hasCpv (prefix, item) {
|
|
|
}
|
|
|
|
|
|
function oddiel_V (item) {
|
|
|
- for (let {tag, value, cancel} of eachFormElement(item)) {
|
|
|
+ for (let {tag, value, cancel, dive} of eachFormElement(item)) {
|
|
|
if (tag === "Part") {
|
|
|
const match = value.$.Title && value.$.Title.match(/^ODDIEL\s+(\w+):/);
|
|
|
if (match)
|
|
|
- if (match[1] === "V") return value; else cancel();
|
|
|
+ if (match[1] === "V") return {value, dive}; else cancel();
|
|
|
}
|
|
|
}
|
|
|
|