Skip to content

Instantly share code, notes, and snippets.

@skd1993
Last active September 16, 2018 14:24
Show Gist options
  • Save skd1993/eb96f05a14c2972e71f94b7527119e8d to your computer and use it in GitHub Desktop.
Save skd1993/eb96f05a14c2972e71f94b7527119e8d to your computer and use it in GitHub Desktop.
rent-list.component.ts
import { Component, OnInit } from '@angular/core';
import { RentItem } from '../../models/rent-item';
import { RentStruct } from '../../models/rent-struct';
@Component({
selector: 'rent-list',
templateUrl: './rent-list.component.html',
styleUrls: ['./rent-list.component.css']
})
export class RentListComponent implements OnInit {
rent_a: RentItem = new RentItem(120, 100, 7, 2018, 19500, 19500, 0);
rent_b: RentItem = new RentItem(150, 120, 8, 2018, 19500, 19500, 0);
rents = [this.rent_a, this.rent_b];
rentStruct: RentStruct = new RentStruct(12500, 8.5, 0, 300);
meterCurr: number;
meterPrev: number;
paid: number;
extraCost: number;
total: number;
constructor() {
this.meterCurr=0;
this.meterPrev=this.rents[this.rents.length-1].meterCurr;
this.paid=0;
this.extraCost=0;
this.total=0;
}
ngOnInit() {
}
submit() {
this.total = (this.rentStruct.getElectricityRate())*(this.meterCurr - this.meterPrev) + (this.rentStruct.getTotal())
this.rents.push(
new RentItem(
this.meterCurr,
this.meterPrev,
(new Date()).getMonth(),
(new Date()).getFullYear(),
this.paid,
this.total,
this.extraCost
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment