﻿/****************************** Membrana ******************************/
function Membrana(id, pow, rabat) {
    //atrybuty
    var base = new Material(id)
    base.init()
    var _id         = base.dajId()
    var _nazwa      = base.dajNazwe()
    var _pow        = pow
    var _zuzycie    = 0
    var ceny        = 0
    var _cena       = 0
    var _cena_r     = 0
    var _rabat      = rabat
          
    //metody
    this.dajId = base.dajId
    this.dajNazwe = base.dajNazwe
    var liczZuzycie = function() {
        if(_id == "BT 12")
            pom = Math.ceil(_pow / (25 * 0.9))
        else if(_id == "BT 21")
            pom = Math.ceil(_pow / (15 * 0.9))
        _zuzycie = pom
    } 
    //Inicjacja cen
    var inicjujCeny = function() {
        if(_id == "BT 12") 
                ceny = 665.0
        else if(_id == "BT 21")
                ceny = 725.0
    }
    this.dajCene = function(i) {
        var pom = _cena.toFixed(2)
        return pom
    }
    this.dajCeneR = function(i) {
        var pom = _cena_r.toFixed(2)
        return pom
    }    
    this.dajPow = function() {
        return _pow
    }
    this.dajZuzycie = function() {
        return _zuzycie
    }
    //ta metoda realizuje obliczenia dla materialu
    this.obliczenia = function() {
        liczZuzycie()
        inicjujCeny()
    }
    //Zwraca koncowke dla tematu slowa rolka
    var koncowka = function() {
        if(_zuzycie == 1)
            return "ka"
        else if(_zuzycie < 5)
            return "ki"
        else if(_zuzycie < 22)
            return "ek"
        else {
            var reszta = _zuzycie % 10
            if((reszta > 1) && (reszta < 5))
                return "ki"
            else
                return "ek"
        }
    }
    this.pisz = function() {
        var kontrolka = document.getElementById("wyniki");
        kontrolka.innerHTML += "<div class='out_mat'>"
        +_id+" ("+_nazwa+")</div>"
        
        _cena = ceny*1.22*_zuzycie
        kontrolka.innerHTML += "<div class='out_ile'>"
            +"("+_zuzycie+" rol"+koncowka()+") x "
            +floatToCurr(ceny*1.22)+"</div>" 
        if(_rabat == 0) {
            _cena_r = 0
            kontrolka.innerHTML += "<div class='out_cn_bez_r'>"
                +floatToCurr(ceny*1.22*_zuzycie)+"</div>";
        }
        else {
            _cena_r += ceny * (1 - (_rabat/100)) * _zuzycie * 1.22
            kontrolka.innerHTML += "<div class='out_cn_minus_r'>"
                +floatToCurr(ceny * (1 - (_rabat/100)) * _zuzycie * 1.22)+"</div>"
            kontrolka.innerHTML += "<div class='out_cn'>"
                +floatToCurr(ceny*1.22*_zuzycie)+"</div>"                   
        }    
    }
}  

