﻿/****************************** Uszczelniacz ******************************/
function Uszczelniacz(id, rabat, dl, szer_sz, typ) {
    //atrybuty
    var base = new Material(id)
    base.init()
    var _id         = base.dajId()
    var _nazwa      = base.dajNazwe()
    var _poj
    var _zuzycie    = 0         //tu oznacza liczbe kartuszy
    var ceny        = 0
    var _szer_sz    = szer_sz
    var _dl         = dl
    var _typ        = typ
    var _cena       = 0
    var _cena_r     = 0
    var _rabat      = rabat
          
    //metody
    this.dajId = base.dajId
    this.dajNazwe = base.dajNazwe
    var liczZuzycie = function() {
        if((_id == "CS 25") || (_id == "CS 29")) {
            if(_szer_sz > 0)
                _zuzycie = Math.ceil(dl / (3 * 100/(_szer_sz*_szer_sz*0.6)))
            else
                _zuzycie = 0
        }
        else if(_id == "CS 28") {
            if(_szer_sz > 0)
                _zuzycie = 1
        }
    } 
    //Inicjacja cen
    var inicjujCeny = function() {
        if(_id == "CS 28") {
            ceny = 1.0
            _poj = 1
        }
        else if(_id == "CS 29") {
            ceny = 19.20
            _poj = 300
        }
        else if(_id == "CS 25") {
            _poj = 280
            if(_typ == "bialy") 
                ceny = 10.20        
            else if(_typ == "kolorowy")
                ceny = 15.75
        }
    }
    this.dajCene = function() {
        var pom = _cena.toFixed(2)
        return pom
    }
    this.dajCeneR = function() {
        var pom = _cena_r.toFixed(2)
        return pom
    }    
    this.dajZuzycie = function() {
        return _zuzycie
    }
    this.obliczenia = function() {
        liczZuzycie()
        inicjujCeny()
    }
    this.pisz = function() {
        if((_dl > 0) && (_szer_sz > 0)) {
            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+" x "+_poj+" ml) 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>"                   
            }    
        }
    }
}

