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 { AlertController } from '@ionic/angular';
- import { DatetimeChangeEventDetail } from '@ionic/core';
- import { ViewState } from '@angular/core/src/view';
- 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';
- import { EmailComposer } from '@ionic-native/email-composer/ngx';
- import { SPINNERS } from '@ionic/core/dist/types/components/spinner/spinner-configs';
- import { Content } from '@angular/compiler/src/render3/r3_ast';
- @Component({
- selector: 'app-stock',
- templateUrl: './stock.page.html',
- styleUrls: ['./stock.page.scss'],
- })
- export class StockPage implements OnInit {
- mode: any = window.sessionStorage.getItem("mode");
- username: any = window.sessionStorage.getItem("username");
- userid: any = window.sessionStorage.getItem("userid");
- selectBox: any = null;
- set_selectBox: any = null;
- id_selectBox: any = null;
- box: any = null;
- set_box: any = null;
- boxState: string[] = ['Goala', 'Plina'];
- set_boxState: any = null;
- exista: any = null;
- serie: any = null;
- serie_show: any = null;
- volum: any = null;
- volum_total: any = null;
- diametru: any = null;
- lungime: any = null;
- tableDet: any = null;
- quality: any = null;
- stockList: any = [];
- sterge_serie: any = null;
- comment1: string = null;
- comment2: string = null;
- boxa_ini: any = null;
- //username: any = window.sessionStorage.getItem("username");
- receptie: any = null;
- server: any = null;
- pdfObj: any = null;
- pdfrow: any = [];
- pdfbody: any = [];
- lista_receptie: any = [];
- pdfspec: any = null;
- pdftype: any = null;
- pdffurnizor: any = null;
- pdfvaloarebustean: any = null;
- pdfvaloaretotala: any = null;
- pdfidrec: any = null;
- registerYes: number = 0;
- registerNo: number = 0;
- mailYes: number = 0;
- modeProvider: any = null;
- provider: any = null;
- set_provider: any = null;
- provider_result: any = null;
- providerAviz: any = null;
- getAllFurnizor: any = null;
- set_Furnizor: any = null;
- woodtype: any = null;
- finish_download: any = null;
- email: any = null;
- emailtosend: any;
- dateStorage: string = new Date().toISOString();
- constructor(public navCtrl: NavController, private barcodeScanner: BarcodeScanner, public http: HttpClient, public platform: Platform, private alertCtrl: AlertController,
- private file: File, private fileOpener: FileOpener, private emailComposer: EmailComposer) {
- this.backButtonEvent();
- this.getBox();
- }
- ngOnInit() {
- }
- meniu() {
- this.navCtrl.navigateRoot('/meniu');
- }
- backButtonEvent() {
- this.platform.backButton.subscribeWithPriority(999999, () => {
- //alert("Back Button");
- this.navCtrl.navigateRoot('/meniu');
- });
- }
- 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", "https://services.sat1.ro/smartwood/scanStock.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.exista = xhttp.response.exista;
- console.log("serie exista: " + this.exista)
- if (this.exista == "DA") {
- this.serie = barcodeData.text;
- this.getWoodBySeries();
- }
- else {
- alert("Serie incorecta!")
- }
- }
- }
- });
- })
- .catch(err => {
- console.log("Error", err);
- });
- this.serie = "";
- this.exista = ""; //a
- }
- getBox() {
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("action", "box");
- xhttp.open("POST", "https://services.sat1.ro/smartwood/get_box.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.box = xhttp.response;
- }
- }
- });
- }
- sterge_bustean(sterge_serie) {
- this.sterge_serie = sterge_serie;
- if (confirm("Sunteti sigur ca doriti sa stergeti 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);
- }
- }
- //volumul total
- //this.get_volum_total();
- }
- }
- /* get_volum_total() {
- this.volum_total = 0;
- for (var i = 0; i < this.stockList.length; i++) {
- this.volum_total = +this.volum_total;
- this.volum_total = +this.stockList[i]['volume'] + this.volum_total;
- this.volum_total = this.volum_total.toFixed(2);
- }
- }
- */
- get_selectBox() {
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("action", "selectBox");
- xhttp.open("POST", "https://services.sat1.ro/smartwood/get_receptie.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.selectBox = xhttp.response;
- }
- }
- });
- }
- stockListPush() {
- // alert('Seria introdusa nu exista in baza de date!')
- if (this.serie == null) {
- alert('Serie incorecta!');
- }
- else {
- this.stockList.push({ "series": this.serie, "diameter": this.diametru, "length": this.lungime, "quality": this.quality, "volume": this.volum, "box": this.boxa_ini});
- this.serie = +this.serie + 1;
- }
- }
- getWoodBySeries() {
- //this.stockListPush();
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("series", this.serie);
- xhttp.open("POST", "https://services.sat1.ro/smartwood/getWoodBySeries.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.serie = xhttp.response.series;
- this.diametru = xhttp.response.diameter;
- this.lungime = xhttp.response.length;
- this.quality = xhttp.response.quality;
- this.volum = xhttp.response.cubage;
- this.boxa_ini = xhttp.response.box;
- 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();
- }
- }
- }
- });
- this.serie = "";
- this.exista = "";
- //this.createpdf();
- }
- inregistrare() {
- console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- console.dir('sa vedem ce e cu array-ul' );
- console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- /*alert('comentariu 1 = ' + this.comment1 + 'comentariu 2 = ' + this.comment2)
- alert('serie = ' + this.serie + '' + 'diametru = ' + this.diametru + '' + 'lungime = ' + this.lungime + '' + 'quality = ' + this.quality + '' + 'volum = ' + this.volum )*/
- console.log(this.stockList.length);
- if (this.stockList.length > 0 && this.box) {
- this.createpdf();
- var xhttp = new XMLHttpRequest();
- xhttp.responseType = 'json';
- var mydata = new FormData();
- mydata.append("inregistrare", "inregistrare");
- console.log("stocklist din inregistrare este: " + this.stockList.length)
- this.stockList.forEach(function (item, i) {
- console.log("seria din stocklist" + item.series)
- console.log("diametru din stocklist" + item.diameter)
- mydata.append("stockList[" + i + "][serie]", item.series);
- });
- mydata.append("data", this.dateStorage);
- console.log("datestorage: "+this.dateStorage.toString());
- mydata.append("boxa", this.set_box);
- mydata.append("stareBoxa", this.set_boxState);
- mydata.append("comment1", this.comment1);
- mydata.append("comment2", this.comment2);
- xhttp.open("POST", "https://services.sat1.ro/smartwood/inregistrare.php", true);
- xhttp.send(mydata);
- var a = new Promise((resolve, reject) => {
- xhttp.onreadystatechange = () => {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- this.serie = "";
- this.set_boxState = '';
- this.set_box = '';
- this.comment1 = '';
- this.comment2 = '';
- this.stockList = [];
- alert('Busteanul a fost adaugat!');
- }
- }
- });
- }
- else {
- alert("Completati toate campurile!");
- }
- }
- async downloadAlert() {
- const alert = await this.alertCtrl.create({
- message: 'PDF Mailer',
- subHeader: 'Doriti sa trimiteti acest fisier?',
- buttons: [
- {
- text: 'Cancel',
- role: 'cancel',
- handler: () => {
- console.log('Cancel clicked');
- }
- },
- {
- text: 'Yes',
- handler: () => {
- console.log('Yes clicked');
- this.mailYes = 1;
- this.emailSender();
- }
- }
- ]
- });
- await alert.present();
- //setTimeout(() => alert.present(), 7000);
- }
- async openAlert() {
- const alert = await this.alertCtrl.create({
- message: 'PDF Viewer',
- subHeader: 'Doriti sa vizualizati acest fisier?',
- buttons: [
- {
- text: 'Cancel',
- role: 'cancel',
- handler: () => {
- console.log('Cancel clicked');
- }
- },
- {
- text: 'Yes',
- handler: () => {
- console.log('Yes clicked');
- this.openPDF();
- }
- }
- ]
- });
- await alert.present();
- //setTimeout(() => alert.present(), 7000);
- }
- getAttachment() {
- this.fileOpener.open('path/to/file.pdf', 'application/pdf')
- .then(() => console.log('File is opened'))
- .catch(e => console.log('Error opening file', e));
- }
- ionViewWillEnter() {
- this.server = JSON.parse(window.localStorage.getItem('phploc'));
- console.log("phploc sessionstorage= " + this.server);
- }
- createpdf() {
- //console.log("Create PDF");
- this.pdfbody = [];
- this.pdfrow = [];
- this.pdfvaloaretotala = 0;
- this.volum_total = 0;
- if (isonline == 'online') {
- this.providerAviz = window.sessionStorage.getItem("provider_result");
- this.providerAviz = this.providerAviz.replace(/['"]+/g, '');
- console.log("in pdf furnizorul din lista show notice = " + this.providerAviz);
- }
- var isonline = window.sessionStorage.getItem('mode');
- console.log("ONLINE PDF = " + isonline);
- console.log("furnizor inainte de if = " + this.modeProvider);
- this.pdfrow.push([
- '',
- 'Nr. Aviz',
- 'Data: ',
- 'Furnizor',
- 'Volum/mc'
- ]);
- for (var i = 0; i < this.stockList.length; i++) {
- this.pdfbody.push([
- i + 1,
- this.stockList[i]['series'],
- this.stockList[i]['diameter'],
- this.stockList[i]['length'],
- this.stockList[i]['volume']
- ]);
- ////this.volum_total += this.stockList[i]['volume']
- //this.volum_total = 0;
- }
- //this.stockList.forEach(function (item, key) {
- // this.pdfbody.push([
- // key + 1,
- // item.serie,
- // item.diameter,
- // item.length,
- // item.volume,
- // ]);
- //})
- console.log('asddasasddassdadas');
- console.log(this.pdfbody);
- //this.pdfbody.reverse();
- //this.pdfbody.push(this.pdfrow);
- var docDefinition = {
- content: [
- {
- table: {
- headerRows: 1,
- widths: ['*'],
- body: [
- [{ text: 'Asta e viata mea,mereu vreau sa fie asa', alignment: 'center'}],
- ],
- }
- },
- {
- table: {
- headerRows: 1,
- widths: ['*', '*'],
- body: [
- ['Furnizor:', 'Tip lemn'],
- ['Nr.aviz:', 'Nr. CMR'],
- ['Data aviz:', 'Transportator'],
- [{ text: 'Data receptie', alignment: 'left' }, ['Nr. remorca', 'Nr.remorca2200' ]],
- ],
- }
- },
- ],
- styles: {
- header: {
- fontSize: 24,
- bold: true,
- },
- subheader: {
- fontSize: 14,
- bold: true,
- margin: [0, 15, 0, 0]
- },
- margintop: {
- margin: [0, 20, 0, 0]
- },
- paddingtop: {
- margin: [0, 10, 0, 30]
- }
- }
- };
- this.pdfObj = pdfMake.createPdf(docDefinition);
- this.downloadPdf();
- }
- downloadPdf() {
- this.pdfObj.download();
- if (this.platform.is('android')) {
- this.file.checkDir(this.file.externalDataDirectory, 'SmartWood')
- .then()
- .catch(err =>
- this.file.createDir(this.file.externalDataDirectory, 'SmartWood', false)
- .then()
- .catch(err => alert('Nu sa putut crea directoriul'))
- );
- console.log("2");
- this.pdfObj.getBuffer((buffer) => {
- var blob = new Blob([buffer], { type: 'application/pdf' });
- this.file.writeFile(this.file.externalDataDirectory, "SmartWood/" + this.formatDate() + ".pdf", blob, { replace: true }).then((success) => {
- })
- });
- this.openAlert();
- this.downloadAlert();
- console.log("3");
- } else {
- this.pdfObj.download();
- }
- }
- openPDF() {
- this.fileOpener.open(this.file.externalDataDirectory + "SmartWood/" + this.formatDate() + ".pdf", 'application/pdf');
- }
- emailSender() {
- this.emailtosend = {
- to: this.email,
- attachments: [
- this.file.externalDataDirectory + "SmartWood/" + this.formatDate() + ".pdf"
- ],
- subject: 'AVIZ ' + this.formatDate(),
- body: 'Mai jos aveti pdf- ul cu avize:',
- isHtml: true
- };
- this.emailComposer.open(this.emailtosend);
- }
- formatDate() {
- var date = new Date();
- var monthNames = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"
- ];
- var day = date.getDate();
- var monthIndex = date.getMonth();
- var year = date.getFullYear();
- return day + '-' + monthNames[monthIndex] + '-' + year;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement