Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- declare var jquery:any;
- declare var $ :any;
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- title = "Fakturky";
- towary: Array<Towar> = [];
- faktury: Array<Faktura> = [];
- towar: string = "";
- faktura: string = "";
- listaTowarow: Array<Towar> = [];
- iloscTowarow: number = 0;
- iloscFaktur: number = 0;
- DodajTowar () {
- let juzIstnieje = false;
- for (let i=0; i<this.towary.length; i++) {
- if (this.towary[i].nazwa === this.towar) {
- juzIstnieje = true;
- break;
- }
- }
- if (juzIstnieje)
- return;
- else if (this.towar!="") {
- this.iloscTowarow++;
- this.towary.push(new Towar(this.iloscTowarow,this.towar,new Czlowiek("Patryk","Komar"),[]));
- }
- this.towar = "";
- }
- UsunTowar (towar: Towar): void {
- let indeksik = -1;
- for (let i=0; i<this.towary.length; i++) {
- if (this.towary[i].nazwa === towar.nazwa) {
- indeksik = i;
- break; }
- }
- if (indeksik === -1)
- return;
- else {
- this.towary.splice(indeksik,1);
- }
- }
- DodajFakture () {
- let juzIstnieje = false;
- for (let i=0; i<this.faktury.length; i++) {
- if (this.faktury[i].nazwa === this.faktura) {
- juzIstnieje = true;
- break;
- }
- }
- if (juzIstnieje)
- return;
- else if (this.faktura!="") {
- this.iloscFaktur++;
- const nowaFakturka = new Faktura(this.iloscFaktur,this.faktura,this.listaTowarow);
- this.faktury.push(nowaFakturka);
- for (let k=0; k<nowaFakturka.towary.length; k++) {
- nowaFakturka.towary[k].fakturky.push(nowaFakturka);
- }
- }
- this.faktura = "";
- console.log(this.listaTowarow);
- this.listaTowarow = [];
- }
- UsunFakture (faktura: Faktura): void {
- let indeksik = -1;
- for (let i=0; i<this.faktury.length; i++) {
- if (this.faktury[i].nazwa === faktura.nazwa) {
- indeksik = i;
- break; }
- }
- if (indeksik === -1)
- return;
- else {
- this.faktury.splice(indeksik,1);
- }
- }
- UpdateListyTowarow () {
- let thisListaTowarow = this.listaTowarow;
- let thisTowary = this.towary;
- let nowaLista = [];
- const lista = $('select option').each(function() {
- if(this.selected) {
- const ID = this.id.replace('towarNr','');
- for (let i=0; i<thisTowary.length; i++) {
- if (thisTowary[i].numer == ID) {
- nowaLista.push(thisTowary[i]);
- }
- }
- }
- });
- this.listaTowarow = nowaLista;
- /*
- for (let i=1; i<=this.iloscTowarow; i++) {
- const ID = "#"+"towarNr"+i;
- const element = $(ID);
- console.log(element);
- if (element!=null) {
- if (element.selected) {
- console.log("TUTAJ2");
- this.towary.forEach(function(element,index){
- if (element.numer == i) {
- this.listaTowarow.push(element);
- }
- })
- }
- }
- }*/
- }
- }
- export class Towar {
- constructor(public numer: number, public nazwa: string, public owner: Czlowiek, public fakturky: Array<Faktura>) {}
- }
- export class Faktura {
- constructor(public numer: number, public nazwa: string, public towary: Array<Towar>) {}
- }
- export class Czlowiek {
- constructor(public imie: string, public nazwisko: string) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement