/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.apc.web.beans.admin;

import com.arrebol.apc.controller.admin.LoanRenovationDeliveryWeeklyController;
import com.arrebol.apc.model.views.LoanRenovationDeliveryWeeklyView;
import com.arrebol.apc.web.beans.Datatable;
import com.arrebol.apc.web.beans.GenericBean;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.event.ReorderEvent;
import org.primefaces.event.RowEditEvent;

/**
 *
 * @author Oscar
 */
@Named("loanRenovationWeeklyManager")
@ViewScoped
public class LoanRenovationDeliveryWeeklyBean extends GenericBean implements Serializable, Datatable {

    
    public List<LoanRenovationDeliveryWeeklyView> fillDatatableLoan() {
        return getLoanRenovationController().fillLoanRenovationDatatable();
    }
    
    public int getTotalRenovation() {
        int quantity = 0;
        for(LoanRenovationDeliveryWeeklyView p : loan) {
            if(p.getRenovation().equals("Renovable")){
                quantity++;
            }
           
        }
        return quantity;
    }
    
    
    public Double getTotalRenovationAmount() {
        Double quantity = 0.0;
        for(LoanRenovationDeliveryWeeklyView p : loan) {
            if(p.getRenovation().equals("Renovable")){
                quantity = quantity + Double.valueOf(p.getAmountLoan());
            }
           
        }
        return quantity;
    }
    @Override
    public void editRow(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowCancel(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowReorder(ReorderEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void addRow() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteRow() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    
    private LoanRenovationDeliveryWeeklyController LoanRenovationController;
    
    private List<LoanRenovationDeliveryWeeklyView> loan;
    
    private int totalRenovable;
    private Double totalRenovableAmount;

    public LoanRenovationDeliveryWeeklyController getLoanRenovationController() {
        return LoanRenovationController;
    }

    public void setLoanRenovationController(LoanRenovationDeliveryWeeklyController LoanRenovationController) {
        this.LoanRenovationController = LoanRenovationController;
    }

    public List<LoanRenovationDeliveryWeeklyView> getLoan() {
        return loan;
    }

    public void setLoan(List<LoanRenovationDeliveryWeeklyView> loan) {
        this.loan = loan;
    }

    public int getTotalRenovable() {
        return totalRenovable;
    }

    public void setTotalRenovable(int totalRenovable) {
        this.totalRenovable = totalRenovable;
    }

    public Double getTotalRenovableAmount() {
        return totalRenovableAmount;
    }

    public void setTotalRenovableAmount(Double totalRenovableAmount) {
        this.totalRenovableAmount = totalRenovableAmount;
    }

    
     
    
     
    
    @PostConstruct
    public void init() {
        loadBundlePropertyFile();
        
        LoanRenovationController = new LoanRenovationDeliveryWeeklyController();

        setLoan(fillDatatableLoan());
        setTotalRenovable(getTotalRenovation());
        setTotalRenovableAmount(getTotalRenovationAmount());
    }
    
    
}
