Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.92 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { NavController } from '@ionic/angular';
  3. import { HomePage } from '../home/home.page';
  4. import { BarcodeScannerOptions, BarcodeScanner } from "@ionic-native/barcode-scanner/ngx";
  5. import { HTTP } from '@ionic-native/http/ngx';
  6. import { HttpClient } from '@angular/common/http';
  7. import { Promise } from 'es6-promise';
  8. import { Platform } from '@ionic/angular';
  9. import { NgxBarcodeModule } from 'ngx-barcode';
  10. import { DatePipe } from '@angular/common';
  11. //import { Base64 } from '@ionic-native/base64';
  12.  
  13. //from PDF
  14. import pdfMake from 'pdfmake/build/pdfmake';
  15. import pdfFonts from 'pdfmake/build/vfs_fonts';
  16. pdfMake.vfs = pdfFonts.pdfMake.vfs;
  17.  
  18. import { File } from '@ionic-native/file/ngx';
  19. import { FileOpener } from '@ionic-native/file-opener/ngx';
  20. import { forEach } from '@angular/router/src/utils/collection';
  21.  
  22. @Component({
  23. selector: 'app-iesire-gatter',
  24. templateUrl: './iesire-gatter.page.html',
  25. styleUrls: ['./iesire-gatter.page.scss'],
  26. providers: [DatePipe],
  27. })
  28. export class IesireGatterPage implements OnInit {
  29. username: any = window.sessionStorage.getItem("username");
  30. userid: any = window.sessionStorage.getItem("userid");
  31. color_a: any = "medium";
  32. color_b: any = "medium";
  33. color_c: any = "medium";
  34. color_d: any = "medium";
  35. categorie: any = null;
  36. categorie_litera: any = null;
  37. pdfObj: any = null;
  38. datetime: String;
  39. data: any = null;
  40. specie: any = null;
  41. sursa: any = null;
  42. nrpalet: any = null;
  43. nrranduri: any = null;
  44. grosime: any = null;
  45. lungime: any = null;
  46. set_specia: any = null;
  47. set_sursa: any = null;
  48. encodeData: any = null;
  49. createdCode: any = null;
  50. numespecie: any = null;
  51. numesursa: any = null;
  52. lista_gater: any = [];
  53. nr_lista: any = null;
  54. getDefect: any = null;
  55.  
  56. set_Defect: any = null;
  57. defectLength: any = null;
  58.  
  59. comment1: any = null;
  60. comment2: any = null;
  61. boxZero: any = null;
  62. serie: any = null;
  63. serie_show: any = null;
  64. exista: any = null;
  65. getbox: any = null;
  66. stockList: any = [];
  67. defectList: any = [];
  68. defectList2: any = [];
  69. diametru: any = null;
  70. quality: any = null
  71. volum: any = null;
  72. sterge_serie: any = null;
  73. serieItem: any = null;
  74. deleteDefect: any = null;
  75. deleteDefectLength: any = null;
  76. defValue: any = null;
  77. defLengthValue: any = null;
  78. idWood: any = null;
  79. sendList: any = null;
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. constructor(public navCtrl: NavController, private barcodeScanner: BarcodeScanner, public http: HttpClient, public platform: Platform,
  89. private file: File, private fileOpener: FileOpener, public datepipe: DatePipe) {
  90. this.backButtonEvent();
  91. this.datetime = new Date().toISOString();
  92. this.defect();
  93. this.lista_gater = [];
  94. }
  95.  
  96. ngOnInit() {
  97. }
  98.  
  99. meniu() {
  100. this.navCtrl.navigateRoot('/meniu');
  101. }
  102. backButtonEvent() {
  103. this.platform.backButton.subscribeWithPriority(999999, () => {
  104. this.navCtrl.navigateRoot('/meniu');
  105. });
  106. }
  107.  
  108. boxZeroValue() {
  109. if (this.boxZero == true) {
  110. this.boxZero = 0;
  111. }
  112. else {
  113. this.boxZero == null;
  114. }
  115. }
  116.  
  117. defect() {
  118. var xhttp = new XMLHttpRequest();
  119. xhttp.responseType = 'json';
  120. var mydata = new FormData();
  121. mydata.append("defect", "defect");
  122.  
  123. xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/get_defect.php", true);
  124. xhttp.send(mydata);
  125.  
  126. var a = new Promise((resolve, reject) => {
  127. xhttp.onreadystatechange = () => {
  128. if (xhttp.readyState == 4 && xhttp.status == 200) {
  129. this.getDefect = xhttp.response;
  130.  
  131. }
  132. }
  133. });
  134.  
  135. }
  136.  
  137. /* defectDetails() {
  138. var xhttp = new XMLHttpRequest();
  139. xhttp.responseType = 'json';
  140. var mydata = new FormData();
  141. mydata.append("cautare", "cautare");
  142. mydata.append("set_Defect", this.set_Defect);
  143. mydata.append("defectLength", this.defectLength);
  144. mydata.append("boxZero", this.boxZero);
  145. mydata.append("comment1", this.comment1);
  146. mydata.append("comment2", this.comment2);
  147.  
  148. xhttp.open("POST", "http://www.satura.ro:8080/SmartWood/get_defect.php", true);
  149. xhttp.send(mydata);
  150.  
  151. var a = new Promise((resolve, reject) => {
  152. xhttp.onreadystatechange = () => {
  153. if (xhttp.readyState == 4 && xhttp.status == 200) {
  154. this.getDefect = xhttp.response;
  155.  
  156. }
  157. }
  158. });
  159. }*/
  160.  
  161. scanCode() {
  162. this.barcodeScanner
  163. .scan()
  164. .then(barcodeData => {
  165. this.serie_show = barcodeData.text;
  166. var xhttp = new XMLHttpRequest();
  167. xhttp.responseType = 'json';
  168. var mydata = new FormData();
  169. mydata.append("action", "cautare");
  170. mydata.append("serie", barcodeData.text);
  171.  
  172. xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/scan.php", true);
  173. xhttp.send(mydata);
  174.  
  175. var a = new Promise((resolve, reject) => {
  176. xhttp.onreadystatechange = () => {
  177. if (xhttp.readyState == 4 && xhttp.status == 200) {
  178. this.exista = xhttp.response;
  179. if (this.exista == "DA") {
  180.  
  181. var a = true;
  182.  
  183. if (this.stockList.length >= 0) {
  184. for (var item of this.stockList) {
  185. if (item.series == barcodeData.text) {
  186. alert('Seria exista deja!');
  187. a = false;
  188. break;
  189. }
  190. }
  191. }
  192. if (a) (<HTMLInputElement>document.getElementById('serie')).value = barcodeData.text;
  193.  
  194. }
  195. else {
  196. alert('Serie incorecta!');
  197. }
  198.  
  199. }
  200. }
  201. });
  202.  
  203. })
  204. .catch(err => {
  205. console.log("Error", err);
  206. });
  207.  
  208.  
  209. this.serie = "";
  210. this.exista = "";
  211.  
  212.  
  213. }
  214.  
  215. sterge_bustean(sterge_serie) {
  216. this.sterge_serie = sterge_serie;
  217.  
  218. if (confirm("Sunteti sigur ca doriti sa stergi busteanul cu seria = " + sterge_serie)) {
  219. for (var i = 0; i < this.stockList.length; i++) {
  220. if (this.stockList[i]['series'] == sterge_serie) {
  221. this.stockList.splice(i, 1);
  222. }
  223. }
  224. }
  225.  
  226. }
  227.  
  228. //&& this.defectList[i]['defectLength'] == deleteDefectLength
  229. delete_Defect(id) {
  230. console.log(this.defectList);
  231. if (confirm("Sunteti sigur ca doriti sa stergeti?")) {
  232. for (var i = 0; i < this.defectList.length; i++) {
  233. if (this.defectList[i]['id'] == id) {
  234. this.defectList.splice(i, 1);
  235. }
  236. }
  237.  
  238. }
  239.  
  240. }
  241.  
  242.  
  243. search() {
  244. var xhttp = new XMLHttpRequest();
  245. xhttp.responseType = 'json';
  246. var mydata = new FormData();
  247. mydata.append("action", "cautare");
  248. mydata.append("serie", this.serie);
  249.  
  250. xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/scanrezerva.php", true);
  251. xhttp.send(mydata);
  252.  
  253. var a = new Promise((resolve, reject) => {
  254. xhttp.onreadystatechange = () => {
  255. if (xhttp.readyState == 4 && xhttp.status == 200) {
  256. this.exista = xhttp.response.valid;
  257. if (this.exista == "DA" && this.serie != this.serieItem) {
  258. this.serie = xhttp.response.wood.series;
  259. this.diametru = xhttp.response.wood.diameter;
  260. this.lungime = xhttp.response.wood.length;
  261. this.quality = xhttp.response.wood.quality;
  262. this.volum = xhttp.response.wood.cubage;
  263. this.idWood = xhttp.response.wood.idWood;
  264.  
  265. var a = true;
  266.  
  267. if (this.stockList.length >= 0) {
  268. for (var item of this.stockList) {
  269. if (item.series == this.serie) {
  270. alert('Seria exista deja!');
  271. a = false;
  272. break;
  273. }
  274. }
  275. }
  276.  
  277. if (a) this.stockListPush();
  278.  
  279. }
  280. else {
  281. alert('Serie incorecta!');
  282. }
  283. }
  284. }
  285. });
  286.  
  287. this.serie = "";
  288. this.exista = "";
  289. }
  290.  
  291. stockListPush() {
  292. this.stockList.push({ "series": this.serie, "diameter": this.diametru, "length": this.lungime, "quality": this.quality, "volume": this.volum, "idWood": this.idWood });
  293.  
  294. this.serie = +this.serie + 1;
  295. }
  296.  
  297. defectIni() {
  298. var xhttp = new XMLHttpRequest();
  299. xhttp.responseType = 'json';
  300. var mydata = new FormData();
  301. mydata.append("defect", "defect");
  302.  
  303. xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/get_defect.php", true);
  304. xhttp.send(mydata);
  305.  
  306. var a = new Promise((resolve, reject) => {
  307. xhttp.onreadystatechange = () => {
  308. if (xhttp.readyState == 4 && xhttp.status == 200) {
  309. this.getDefect = xhttp.response;
  310.  
  311. }
  312. }
  313. });
  314.  
  315. }
  316.  
  317. defectListPush() {
  318. if (this.set_Defect && this.defectLength) {
  319. var id = 1;
  320.  
  321. if (this.defectList.length > 0) {
  322. id = this.defectList.slice(-1)[0].id + 1;
  323. }
  324.  
  325.  
  326. var a = true;
  327. for (var i = 0; i < this.getDefect.length; i++) {
  328. if (this.getDefect[i].id == this.set_Defect) {
  329. if (this.defectList.length >= 0) {
  330. for (var item of this.defectList) {
  331. if (item.set_Defect == this.getDefect[i].type && item.defectLength == this.defectLength) {
  332. console.log('Defectul item este : ' + item.set_Defect + " and length estw : " + item.defectLength)
  333. alert('Defectul exista deja!');
  334. a = false;
  335. break;
  336. }
  337. }
  338. }
  339. if (a) this.defectList.push({ "id": this.getDefect[i].id, "set_Defect": this.getDefect[i].type, "defectLength": this.defectLength });
  340. }
  341. }
  342. }
  343. else {
  344. alert('Completati campurile!')
  345. }
  346.  
  347. this.defectLength = "";
  348. this.set_Defect = "";
  349. }
  350.  
  351.  
  352. sendListofDefects() {
  353. this.boxZeroValue();
  354. var xhttp = new XMLHttpRequest();
  355. xhttp.responseType = 'json';
  356. var mydata = new FormData();
  357.  
  358. console.log(this.defectList);
  359.  
  360. this.defectList.forEach(function (item, key) {
  361. console.log("item setdefect" + item.set_Defect);
  362. mydata.append('defects[' + key + '][defect]', item.id);
  363. mydata.append('defects[' + key + '][length]', item.defectLength);
  364. });
  365.  
  366. this.stockList.forEach(function (item, key) {
  367. mydata.append('woods[' + key + ']', item.idWood);
  368. });
  369.  
  370. mydata.append("boxZero", this.boxZero);
  371. mydata.append("comment1", this.comment1);
  372. mydata.append("comment2", this.comment2);
  373.  
  374. xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/defectDetails.php", true);
  375. xhttp.send(mydata);
  376.  
  377. var a = new Promise((resolve, reject) => {
  378. xhttp.onreadystatechange = () => {
  379. if (xhttp.readyState == 4 && xhttp.status == 200) {
  380. //this.sendList = xhttp.response;
  381. this.serie = '';
  382. this.stockList = [];
  383. this.boxZero = null;
  384. this.set_Defect = '';
  385. this.defectLength = '';
  386. this.defectList = [];
  387. this.comment1 = '';
  388. this.comment2 = '';
  389.  
  390. alert('Busteanul a fost scos!');
  391. }
  392. }
  393. });
  394.  
  395. }
  396.  
  397.  
  398. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement