Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { NavController } from '@ionic/angular';
- import { HomePage } from '../home/home.page';
- import { BarcodeScannerOptions, BarcodeScanner } from "@ionic-native/barcode-scanner/ngx";
- import { HTTP } from '@ionic-native/http/ngx';
- import { HttpClient } from '@angular/common/http';
- import { Promise } from 'es6-promise';
- import { Platform } from '@ionic/angular';
- import { NgxBarcodeModule } from 'ngx-barcode';
- import { DatePipe } from '@angular/common';
- //import { Base64 } from '@ionic-native/base64';
- //from PDF
- import pdfMake from 'pdfmake/build/pdfmake';
- import pdfFonts from 'pdfmake/build/vfs_fonts';
- pdfMake.vfs = pdfFonts.pdfMake.vfs;
- import { File } from '@ionic-native/file/ngx';
- import { FileOpener } from '@ionic-native/file-opener/ngx';
- import { forEach } from '@angular/router/src/utils/collection';
- @Component({
- selector: 'app-iesire-gatter',
- templateUrl: './iesire-gatter.page.html',
- styleUrls: ['./iesire-gatter.page.scss'],
- providers: [DatePipe],
- })
- export class IesireGatterPage implements OnInit {
- username: any = window.sessionStorage.getItem("username");
- userid: any = window.sessionStorage.getItem("userid");
- color_a: any = "medium";
- color_b: any = "medium";
- color_c: any = "medium";
- color_d: any = "medium";
- categorie: any = null;
- categorie_litera: any = null;
- pdfObj: any = null;
- datetime: String;
- data: any = null;
- specie: any = null;
- sursa: any = null;
- nrpalet: any = null;
- nrranduri: any = null;
- grosime: any = null;
- lungime: any = null;
- set_specia: any = null;
- set_sursa: any = null;
- encodeData: any = null;
- createdCode: any = null;
- numespecie: any = null;
- numesursa: any = null;
- lista_gater: any = [];
- nr_lista: any = null;
- getDefect: any = null;
- set_Defect: any = null;
- defectLength: any = null;
- comment1: any = null;
- comment2: any = null;
- boxZero: any = null;
- serie: any = null;
- serie_show: any = null;
- exista: any = null;
- getbox: any = null;
- stockList: any = [];
- defectList: any = [];
- defectList2: any = [];
- diametru: any = null;
- quality: any = null
- volum: any = null;
- sterge_serie: any = null;
- serieItem: any = null;
- deleteDefect: any = null;
- deleteDefectLength: any = null;
- defValue: any = null;
- defLengthValue: any = null;
- idWood: any = null;
- sendList: any = null;
- constructor(public navCtrl: NavController, private barcodeScanner: BarcodeScanner, public http: HttpClient, public platform: Platform,
- private file: File, private fileOpener: FileOpener, public datepipe: DatePipe) {
- this.backButtonEvent();
- this.datetime = new Date().toISOString();
- this.defect();
- this.lista_gater = [];
- }
- ngOnInit() {
- }
- meniu() {
- this.navCtrl.navigateRoot('/meniu');
- }
- backButtonEvent() {
- this.platform.backButton.subscribeWithPriority(999999, () => {
- this.navCtrl.navigateRoot('/meniu');
- });
- }
- boxZeroValue() {
- if (this.boxZero == true) {
- this.boxZero = 0;
- }
- else {
- this.boxZero == null;
- }
- }
- defect() {
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("defect", "defect");
- xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/get_defect.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.getDefect = xhttp.response;
- }
- }
- });
- }
- /* defectDetails() {
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("cautare", "cautare");
- mydata.append("set_Defect", this.set_Defect);
- mydata.append("defectLength", this.defectLength);
- mydata.append("boxZero", this.boxZero);
- mydata.append("comment1", this.comment1);
- mydata.append("comment2", this.comment2);
- xhttp.open("POST", "http://www.satura.ro:8080/SmartWood/get_defect.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.getDefect = xhttp.response;
- }
- }
- });
- }*/
- scanCode() {
- this.barcodeScanner
- .scan()
- .then(barcodeData => {
- this.serie_show = barcodeData.text;
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("action", "cautare");
- mydata.append("serie", barcodeData.text);
- xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/scan.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.exista = xhttp.response;
- if (this.exista == "DA") {
- var a = true;
- if (this.stockList.length >= 0) {
- for (var item of this.stockList) {
- if (item.series == barcodeData.text) {
- alert('Seria exista deja!');
- a = false;
- break;
- }
- }
- }
- if (a) (<HTMLInputElement>document.getElementById('serie')).value = barcodeData.text;
- }
- else {
- alert('Serie incorecta!');
- }
- }
- }
- });
- })
- .catch(err => {
- console.log("Error", err);
- });
- this.serie = "";
- this.exista = "";
- }
- sterge_bustean(sterge_serie) {
- this.sterge_serie = sterge_serie;
- if (confirm("Sunteti sigur ca doriti sa stergi busteanul cu seria = " + sterge_serie)) {
- for (var i = 0; i < this.stockList.length; i++) {
- if (this.stockList[i]['series'] == sterge_serie) {
- this.stockList.splice(i, 1);
- }
- }
- }
- }
- //&& this.defectList[i]['defectLength'] == deleteDefectLength
- delete_Defect(id) {
- console.log(this.defectList);
- if (confirm("Sunteti sigur ca doriti sa stergeti?")) {
- for (var i = 0; i < this.defectList.length; i++) {
- if (this.defectList[i]['id'] == id) {
- this.defectList.splice(i, 1);
- }
- }
- }
- }
- search() {
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("action", "cautare");
- mydata.append("serie", this.serie);
- xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/scanrezerva.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.exista = xhttp.response.valid;
- if (this.exista == "DA" && this.serie != this.serieItem) {
- this.serie = xhttp.response.wood.series;
- this.diametru = xhttp.response.wood.diameter;
- this.lungime = xhttp.response.wood.length;
- this.quality = xhttp.response.wood.quality;
- this.volum = xhttp.response.wood.cubage;
- this.idWood = xhttp.response.wood.idWood;
- var a = true;
- if (this.stockList.length >= 0) {
- for (var item of this.stockList) {
- if (item.series == this.serie) {
- alert('Seria exista deja!');
- a = false;
- break;
- }
- }
- }
- if (a) this.stockListPush();
- }
- else {
- alert('Serie incorecta!');
- }
- }
- }
- });
- this.serie = "";
- this.exista = "";
- }
- stockListPush() {
- this.stockList.push({ "series": this.serie, "diameter": this.diametru, "length": this.lungime, "quality": this.quality, "volume": this.volum, "idWood": this.idWood });
- this.serie = +this.serie + 1;
- }
- defectIni() {
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("defect", "defect");
- xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/get_defect.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.getDefect = xhttp.response;
- }
- }
- });
- }
- defectListPush() {
- if (this.set_Defect && this.defectLength) {
- var id = 1;
- if (this.defectList.length > 0) {
- id = this.defectList.slice(-1)[0].id + 1;
- }
- var a = true;
- for (var i = 0; i < this.getDefect.length; i++) {
- if (this.getDefect[i].id == this.set_Defect) {
- if (this.defectList.length >= 0) {
- for (var item of this.defectList) {
- if (item.set_Defect == this.getDefect[i].type && item.defectLength == this.defectLength) {
- console.log('Defectul item este : ' + item.set_Defect + " and length estw : " + item.defectLength)
- alert('Defectul exista deja!');
- a = false;
- break;
- }
- }
- }
- if (a) this.defectList.push({ "id": this.getDefect[i].id, "set_Defect": this.getDefect[i].type, "defectLength": this.defectLength });
- }
- }
- }
- else {
- alert('Completati campurile!')
- }
- this.defectLength = "";
- this.set_Defect = "";
- }
- sendListofDefects() {
- this.boxZeroValue();
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- console.log(this.defectList);
- this.defectList.forEach(function (item, key) {
- console.log("item setdefect" + item.set_Defect);
- mydata.append('defects[' + key + '][defect]', item.id);
- mydata.append('defects[' + key + '][length]', item.defectLength);
- });
- this.stockList.forEach(function (item, key) {
- mydata.append('woods[' + key + ']', item.idWood);
- });
- mydata.append("boxZero", this.boxZero);
- mydata.append("comment1", this.comment1);
- mydata.append("comment2", this.comment2);
- xhttp.open("POST", "http://iis.satura.ro/SmartWood/PHP/defectDetails.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- //this.sendList = xhttp.response;
- this.serie = '';
- this.stockList = [];
- this.boxZero = null;
- this.set_Defect = '';
- this.defectLength = '';
- this.defectList = [];
- this.comment1 = '';
- this.comment2 = '';
- alert('Busteanul a fost scos!');
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement