firmaapp.MainFormController.java Source code

Java tutorial

Introduction

Here is the source code for firmaapp.MainFormController.java

Source

/*
 * 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 firmaapp;

import org.apache.pdfbox.pdmodel.*;
import dao.mysql.NormMySQL;
import dao.mysql.ProductMySQL;
import dao.mysql.SupplyMySQL;
import dao.mysql.WorkOrderMySQL;
import dto.Norm;
import dto.Product;
import dto.Supply;
import dto.WorkOrder;
import java.awt.image.BufferedImage;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import javafx.scene.text.TextAlignment;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javax.imageio.ImageIO;
import javax.print.PrintServiceLookup;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.printing.PDFPageable;
import org.apache.pdfbox.printing.PDFPrintable;
import org.apache.pdfbox.rendering.PDFRenderer;
import pdf.DailyReportPDF;
import pdf.NormativPDF;
import pdf.StockItemsPDF;
import pdf.SuppliesListPDF;
import pdf.WorkOrderPDF;
import temp_classes.WeddingCakeProductsOut;

/**
 * FXML Controller class
 *
 * @author Bojan
 */
public class MainFormController implements Initializable {

    private static RootController rootController;
    private static boolean isFirstRun = true;
    private static String typedQuantity = "";
    private static String typedPrice = "";
    public static ObservableList<SupplyToTable> data = FXCollections.observableArrayList();
    private static int enterFunction = 0;
    //#### Side bar buttons ####//
    private static int selectedSideBarButton = -1;
    HashMap<Integer, String> sideBarIconsMap = new HashMap<>();
    //#### Products in ####//
    private static String selectedFloor = ""; // which floor selected
    //#### Products out ####//
    private static ObservableList<Product> dataCakesOut = FXCollections.observableArrayList();
    private static ObservableList<Product> dataProductsOut = FXCollections.observableArrayList();
    private static ObservableList<WeddingCakeProductsOut> dataWeddCakesOut = FXCollections.observableArrayList();
    //#### Work orders ####//
    private static ObservableList<WorkOrder> dataWorkOrders = FXCollections.observableArrayList();
    //#### Norms ####//
    private static ObservableList<Product> dataNormsCakes = FXCollections.observableArrayList();
    private static ObservableList<WeddingCakeProductsOut> dataNormsWeddCakes = FXCollections.observableArrayList();

    @FXML
    private AnchorPane suppliesRootAnchorPane;
    @FXML
    private VBox sideBarVBox;
    @FXML
    private AnchorPane welcomeAnchorPane;
    @FXML
    private Button suppliesSideBarButton;
    @FXML
    private Button productsInSideBarButton;
    @FXML
    private Button productsOutSideBarButton;
    @FXML
    private Button normsSideBarButton;
    @FXML
    private Button workOrderSideBarButton;
    @FXML
    private Button writeOffSideBarButton;
    @FXML
    private FlowPane suppliesFlowPane;
    @FXML
    private TextField popUpQuantityTextField;
    @FXML
    private TextField popUpPriceTextField;
    @FXML
    private Label popUpSupplyLabel;
    @FXML
    private TableView suppliesTableView;
    @FXML
    private AnchorPane productsInRootAnchorPane;
    @FXML
    private TableView productsInTableView;
    @FXML
    private TabPane productsInTabPane;
    @FXML
    private ToggleGroup cakeShapeToggleGroup;
    @FXML
    private ToggleGroup cakeTypeToggleGroup;
    @FXML
    private ToggleGroup cakeSizeToggleGroup;
    @FXML
    private ToggleGroup cakeGlazeToggleGroup;
    @FXML
    private ToggleGroup cakePictureToggleGroup;
    @FXML
    private ToggleGroup weddingCakeShapeToggleGroup;
    @FXML
    private ToggleGroup weddingCakeTypeToggleGroup;
    @FXML
    private ToggleGroup weddingCakeSizeToggleGroup;
    @FXML
    private ToggleGroup weddingCakeGlazeToggleGroup;
    @FXML
    private ToggleGroup weddingCakePictureToggleGroup;
    @FXML
    private TextField productsInCakeQuantityTextField;
    @FXML
    private TextField productsInCakePriceTextField;
    @FXML
    private VBox weddingCakeFloorsVBox;
    @FXML
    private TextField weddingCakeNumOfFloorsTextField;
    @FXML
    private TextField productsInCookieQuantityTextField;
    @FXML
    private TextField productsInCookiePriceTextField;
    @FXML
    private ToggleGroup weddingCakeFloorToogleGroup;
    @FXML
    private ToggleButton weddingCakeFloorsButton1, weddingCakeFloorsButton2, weddingCakeFloorsButton3,
            weddingCakeFloorsButton4, weddingCakeFloorsButton5, weddingCakeFloorsButton6, weddingCakeFloorsButton7;
    @FXML
    private Label promjeneNtogSprataLabel;
    @FXML
    private Label descriptionWeddingCakeLabel;
    @FXML
    private TextField productsInWCakePriceTextField;
    @FXML
    private TextField productsInWCakeQuantityTextField;
    @FXML
    private VBox weddingCakeFloorDesVBox;
    @FXML
    private AnchorPane productsOutRootAnchorPane;
    @FXML
    private TableView productsOutCakeTableView;
    @FXML
    private DatePicker workOrderDatePicker;
    @FXML
    private TableView productsOutTableView;
    @FXML
    private TableView productsOutWeddingCakeTableView;
    @FXML
    private AnchorPane workOrderRootAnchorPane;
    @FXML
    private TableView workOrdersTableView;
    @FXML
    private AnchorPane normsRootAnchorPane;
    @FXML
    private TableView normsCakeTableView;
    @FXML
    private TableView normsWeddingCakeTableView;
    @FXML
    private VBox normSideVBox;
    @FXML
    private ImageView workOrderImageView;
    @FXML
    private Button logoutButton;
    @FXML
    private ImageView userImageView;
    @FXML
    private Button confirmButton;
    @FXML
    private Button cancelButton;
    @FXML
    private Label supplyBillSumLabel;
    @FXML
    private Tab productsInCakesTab;
    @FXML
    private Tab productsInWeddingCakesTab;
    @FXML
    private Tab productsInCookiesTab;
    @FXML
    private Tab productsInPieceCookiesTab;
    @FXML
    private Button productsInConfirmButton;
    @FXML
    private Button productsInCancelButton;
    @FXML
    private Tab productsOutCakesTab;
    @FXML
    private Tab productsOutWeddingCakesTab;
    @FXML
    private Tab productsOutCookiesTab;
    @FXML
    private Tab productsOutPieceCookiesTab;
    @FXML
    private Button setProductInfoButton;
    @FXML
    private Button productsOutConfirmButton;
    @FXML
    private Button productsOutCancelButton;
    @FXML
    private Label productsInBillSumLabel;
    @FXML
    private Button setFloorParameterButton;
    @FXML
    private ToggleGroup cookieToggleGroup;
    @FXML
    private Label productsOutBillSumLabel;
    @FXML
    private AnchorPane mainFormMainAnchorPane;

    public static void printInformations() {
        System.out.println("****************** INFORMATIONS ******************");

        System.out.println("##### MATERIJAL (data obs list): #####");
        int cnt = 0;
        for (SupplyToTable stt : data) {
            ++cnt;
            System.out.println(cnt + " -> " + stt);

        }
        System.out.println("######################################");

        System.out.println("##### PROIZVODI (all products list): #####");
        cnt = 0;
        for (Product pr : RootController.allProducts) {
            ++cnt;
            System.out.println(cnt + " -> " + pr);
        }
        System.out.println("######################################");

        System.out.println("##### PROIZVODI (data bill products list): #####");
        cnt = 0;
        for (Product pr : RootController.dataBillProducts) {
            ++cnt;
            System.out.println(cnt + " -> " + pr);
        }
        System.out.println("######################################");

        System.out.println("##### RADNI NALOZI (all work orders list): #####");
        cnt = 0;
        for (WorkOrder pr : RootController.allWorkOrders) {
            ++cnt;
            System.out.println(cnt + " -> " + pr);
        }
        System.out.println("######################################");

        System.out.println("***************************************************");
    }

    public static void printSingleInformations() {
        System.out.println("");
        System.out.println("///");
        System.out.println("///");
        System.out.println("///");
        System.out.println("///");
        System.out.println("///");
        System.out.println("///");
        System.out.println("///");
        System.out.println("***************SINGLE INFORMATIONS*****************");
        System.out.println("ENTER FUNCTION: " + enterFunction);
        System.out.println("SELECTED SIDE BAR: " + selectedSideBarButton);
        System.out.println("SELECTED FLOOR: " + selectedFloor);
        System.out.println("FOCUS TEXT FIELD: " + RootController.focusTextField);
        System.out.println("SELECTED SIDE MENU (rootC): " + RootController.selectedSideMenu);
        System.out.println("SELECTED TAB PRODUCTS IN: " + RootController.selectedTabProductsIn);
        System.out.println("SELECTED FLOOR (root): " + RootController.selectedFloor);
        System.out.println("CURRENT NUM OF FLOORS: " + RootController.currentNumOfFloors);
        System.out.println("CURRENT PRODUCT: " + RootController.currProduct);
        System.out.println("CURRENT WEDDING CAKE: " + RootController.currWeddingCake);
        System.out.println("USING NUMPAD: " + RootController.usingNumpad);
        System.out.println("***************************************************");
        System.out.println("");
    }

    public void setProductsOutSumLabel() {
        double sum = 0;
        for (Product p : dataProductsOut) {
            sum += p.getTempQuantity() * p.getTempPrice();
        }
        if (sum == 0) {
            productsOutBillSumLabel.setText("0.00");
        } else {
            DecimalFormat f = new DecimalFormat("##.00");
            productsOutBillSumLabel.setText(f.format(sum));
        }

    }

    public double getProductPrice(Product p) {
        double ret = 0;
        for (Product temp : RootController.allProducts) {
            if (temp.getId() == p.getId()) {
                ret = temp.getTempPrice();
                break;
            }
        }
        return ret;
    }

    ///////////////////////////////// HELP /////////////////////////////////////
    @FXML
    void helpButtonAction(ActionEvent event) throws IOException {
        Stage stage = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("HelpForm.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.initModality(Modality.APPLICATION_MODAL);
        rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
        stage.setTitle("Pomoc");
        stage.showAndWait();
    }

    ////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////// SUPPLIES /////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    /////////////////////////// MAIN SUPPLY BUTTONS ////////////////////////////
    @FXML
    void confirmButtonAction(ActionEvent e) {
        SupplyMySQL s = new SupplyMySQL();
        ArrayList<Supply> sup = new ArrayList<>();
        for (int i = 0; i < data.size(); i++) {
            Supply ss = new Supply();
            int id = 0;
            for (Supply temp : rootController.getAllSupplies()) {
                if (data.get(i).getName().equals(temp.getName())) {
                    id = temp.getId();
                    break;
                }
            }
            ss.setId(id);
            ss.setTempQuantity(data.get(i).getQuanty());
            ss.setName(data.get(i).getName());
            ss.setPrice(data.get(i).getPrice());
            sup.add(ss);
        }
        s.confirmSuppliesTransaction(sup);
        suppliesTableView.getItems().clear();
        data.clear();

        supplyBillSumLabel.setText("0.00");
    }

    @FXML
    void cancelButtonAction(ActionEvent e) {
        suppliesTableView.getItems().clear();
        data.clear();
        supplyBillSumLabel.setText("0.00");
    }
    ////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////// NUMPAD ///////////////////////////////////
    @FXML
    void mainNumPadButtonAction(ActionEvent e) {
        if (RootController.focusTextField.equals("quantity")) {
            popUpQuantityTextField.requestFocus();
            String currentText = popUpQuantityTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            popUpQuantityTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("price")) {
            popUpPriceTextField.requestFocus();
            String currentText = popUpPriceTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            popUpPriceTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cakequantity")) {
            productsInCakeQuantityTextField.requestFocus();
            String currentText = productsInCakeQuantityTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            productsInCakeQuantityTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cakeprice")) {
            productsInCakePriceTextField.requestFocus();
            String currentText = productsInCakePriceTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            productsInCakePriceTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("weddingquantity")) {
            productsInCakeQuantityTextField.requestFocus();
            String currentText = productsInCakeQuantityTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            productsInCakeQuantityTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("weddingprice")) {
            productsInCakePriceTextField.requestFocus();
            String currentText = productsInCakePriceTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            productsInCakePriceTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cookiesquantity")) {
            productsInCakeQuantityTextField.requestFocus();
            String currentText = productsInCakeQuantityTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            productsInCakeQuantityTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cookiesprice")) {
            productsInCakePriceTextField.requestFocus();
            String currentText = productsInCakePriceTextField.getText();
            currentText += ((Button) e.getSource()).getText();
            rootController.setUsingNumpad(true);
            productsInCakePriceTextField.setText(currentText);
        }

        //printSingleInformations();
        //printInformations();
    }

    @FXML
    void mainNumpadBackspaceAction(ActionEvent e) {
        if (rootController.getFocusTextField().equals("quantity")) {
            popUpQuantityTextField.requestFocus();
            String currentText = popUpQuantityTextField.getText();
            currentText = popUpQuantityTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            popUpQuantityTextField.setText(currentText);
        } else if (rootController.getFocusTextField().equals("price")) {
            popUpPriceTextField.requestFocus();
            String currentText = popUpPriceTextField.getText();
            currentText = popUpPriceTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            popUpPriceTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cakequantity")) {
            productsInCakeQuantityTextField.requestFocus();
            String currentText = productsInCakeQuantityTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            productsInCakeQuantityTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cakeprice")) {
            productsInCakePriceTextField.requestFocus();
            String currentText = productsInCakePriceTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            productsInCakePriceTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("weddingquantity")) {
            productsInCakeQuantityTextField.requestFocus();
            String currentText = productsInCakeQuantityTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            productsInCakeQuantityTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("weddingprice")) {
            productsInCakePriceTextField.requestFocus();
            String currentText = productsInCakePriceTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            productsInCakePriceTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cookiesquantity")) {
            productsInCakeQuantityTextField.requestFocus();
            String currentText = productsInCakeQuantityTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            productsInCakeQuantityTextField.setText(currentText);
        } else if (RootController.focusTextField.equals("cookiesprice")) {
            productsInCakePriceTextField.requestFocus();
            String currentText = productsInCakePriceTextField.getText();
            currentText = currentText.substring(0, currentText.length() - 1);
            rootController.setUsingNumpad(true);
            productsInCakePriceTextField.setText(currentText);
        }
    }

    @FXML
    void enterNumpadButtonAction(ActionEvent e) throws IOException {

        //// NUMPAD MATERIJAL ////
        if (RootController.selectedSideMenu.equals("materijal")) {
            if (enterFunction == 1) {
                rootController.setFocusTextField("price");
                enterFunction = 2;
                popUpPriceTextField.requestFocus();
            } else if (enterFunction == 2) {
                rootController.setFocusTextField("");
                enterFunction = 0;
                String curSup = popUpSupplyLabel.getText();
                boolean isNew = true;
                int counter = 0;
                for (SupplyToTable s : data) {
                    if (s.getName().equals(curSup)) {
                        //s.quanty += Double.parseDouble(popUpQuantityTextField.getText());
                        double q = Double.parseDouble(popUpQuantityTextField.getText()) + data.get(counter).quanty;
                        SupplyToTable temp = new SupplyToTable();
                        temp.setAllAtribute(s);
                        temp.quanty = q;
                        data.remove(s);
                        data.add(counter, temp);
                        isNew = false;
                        counter++;
                        break;
                    }
                }
                if (isNew) {
                    data.add(new SupplyToTable(popUpSupplyLabel.getText(),
                            Double.parseDouble(popUpQuantityTextField.getText()),
                            Double.parseDouble(popUpPriceTextField.getText())));
                    suppliesTableView.setItems(data);
                }

                //RootController.sumOfSupplies += Double.parseDouble(popUpPriceTextField.getText()) * Double.parseDouble(popUpQuantityTextField.getText());
                double qu = 0;
                for (SupplyToTable ss : data) {
                    qu += ss.getPrice() * ss.getQuanty();
                }
                RootController.sumOfSupplies = qu;
                DecimalFormat f = new DecimalFormat("##.00");
                supplyBillSumLabel.setText(f.format(RootController.sumOfSupplies));
                typedQuantity = "";
                typedPrice = "";
                popUpSupplyLabel.setText("Materijal");
                popUpQuantityTextField.clear();
                popUpPriceTextField.clear();
            }
        } //// NUMPAD PROIZVODI ULAZ ////
        else if (RootController.selectedSideMenu.equals("proizvodiulaz")) {
            if (RootController.selectedTabProductsIn.equals("Torte")) {
                if (enterFunction == 1) {
                    RootController.focusTextField = "cakeprice";
                    enterFunction = 2;
                    productsInCakePriceTextField.requestFocus();
                } else if (enterFunction == 2) {
                    RootController.focusTextField = "";
                    enterFunction = 0;
                    //data.add(new SupplyToTable(popUpSupplyLabel.getText(), Double.parseDouble(popUpQuantityTextField.getText()), Double.parseDouble(popUpPriceTextField.getText())));
                    //suppliesTableView.setItems(data);
                    /*RootController.currProduct.setMeasureUnit("kom");
                    RootController.currProduct.setSelector("torta");
                    RootController.currProduct.setFloorNumber(1);*/
                    RootController.currProduct
                            .setTempQuantity(Double.parseDouble(productsInCakeQuantityTextField.getText()));
                    RootController.currProduct
                            .setTempPrice(Double.parseDouble(productsInCakePriceTextField.getText()));

                    boolean isNew = true;
                    for (Product p : RootController.getAllProducts()) {
                        // Check if product exists in all registred products //
                        if (RootController.currProduct.equals(p)) {
                            isNew = false;
                            break;
                        }
                    }

                    // If product do not exists need to open Norm form //
                    if (isNew) {
                        // Ne postoji proizvod u bazi pa treba kreirati normativ
                        // Otvaramo novu formu
                        RootController.sumLabelProductsIn = productsInBillSumLabel;
                        Stage stage = new Stage();
                        Parent root = FXMLLoader.load(getClass().getResource("NewNormsForm.fxml"));
                        Scene scene = new Scene(root);
                        stage.setScene(scene);
                        stage.initModality(Modality.APPLICATION_MODAL);
                        rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
                        stage.showAndWait();
                        deselectCakeToogleButtons();
                        ProductMySQL productMySQL = new ProductMySQL();
                        ArrayList<Product> products = productMySQL.allProductsFullInfo();
                        rootController.setAllProducts(products);
                    } else {
                        // Postoji u bazi, ne treba kreirati normativ jer postoji
                        // Dodati u TableView u ovom bloku
                        int counter = 0;
                        boolean isInTable = false;
                        for (Product p : RootController.dataBillProducts) {
                            if (p.equals(RootController.currProduct)) {
                                isInTable = true;
                                RootController.currProduct.setTempQuantity(
                                        RootController.currProduct.getTempQuantity() + p.getTempQuantity());
                                RootController.currProduct.createFormatName();
                                RootController.dataBillProducts.remove(p);
                                RootController.getDataBillProducts().add(counter, RootController.currProduct); // Add to observable list and tableView
                                //Refresh table data
                                ObservableList<Product> tmpList = FXCollections
                                        .observableArrayList(RootController.dataBillProducts);
                                RootController.dataBillProducts.removeAll(RootController.dataBillProducts);
                                for (Product pp : tmpList) {
                                    RootController.dataBillProducts.add(pp);
                                }
                                RootController.currProduct = new Product();
                                deselectCakeToogleButtons();
                                break;
                            }
                            ++counter;
                        }

                        if (!isInTable) {
                            RootController.currProduct.createFormatName();
                            RootController.getDataBillProducts().add(RootController.currProduct); // Add to observable list and tableView
                            RootController.currProduct = new Product();
                            deselectCakeToogleButtons();

                        }
                    }
                    typedQuantity = "";
                    typedPrice = "";
                    RootController.sumOfProductsIn += Double.parseDouble(productsInCakeQuantityTextField.getText())
                            * Double.parseDouble(productsInCakePriceTextField.getText());
                    DecimalFormat f = new DecimalFormat("#.00");
                    productsInBillSumLabel.setText(f.format(RootController.sumOfProductsIn));
                    productsInCakeQuantityTextField.clear();
                    productsInCakePriceTextField.clear();
                }
            } else if (RootController.selectedTabProductsIn.equals("Svadbene torte")) {

                if (RootController.productsInWeddingAction.equals("normativ")) {
                    double price = Double.parseDouble(productsInCakePriceTextField.getText());
                    RootController.currProduct.setTempPrice(price);
                    Stage stage = new Stage();
                    Parent root = FXMLLoader.load(getClass().getResource("NewNormsForm.fxml"));
                    Scene scene = new Scene(root);
                    stage.setScene(scene);
                    stage.initModality(Modality.APPLICATION_MODAL);
                    rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
                    stage.setTitle("Normativ");
                    stage.showAndWait();
                    deselectWeddingToogleButtons();
                    productsInCakeQuantityTextField.clear();
                    productsInCakePriceTextField.clear();
                } else if (RootController.productsInWeddingAction.equals("unostabela")) {
                    if (enterFunction == 1) {
                        productsInCakePriceTextField.requestFocus();
                        enterFunction = 2;
                        RootController.focusTextField = "weddingprice";
                    } else if (enterFunction == 2) {
                        if (!productsInCakePriceTextField.getText().equals("")) {
                            RootController.currWeddingCake
                                    .setTempQuantity(Double.parseDouble(productsInCakeQuantityTextField.getText()));
                            RootController.currWeddingCake
                                    .setTempPrice(Double.parseDouble(productsInCakePriceTextField.getText()));
                            RootController.currWeddingCake.setFormatName(
                                    "Svadbena, " + RootController.currWeddingCake.getFloorNumber() + " spratova");
                            ArrayList<Product> weddingCakeProductList = new ArrayList<>();
                            for (String s : RootController.currWeddingCake.getMoreFloorInfo().split("#")) {
                                int tempID = Integer.parseInt(s.split(",")[1]);
                                for (Product prod : RootController.allProducts) {
                                    if (prod.getId() == tempID) {
                                        weddingCakeProductList.add(prod);
                                        break;
                                    }
                                }
                            }
                            // Lista proizvoda koja sacinjava svadbenu tortu se nalazi u weddingCakeProductLit
                            // Potrbno je kreirati proizvod svadbena torta, zatim pokupiti i sabrati 
                            // normative od proizvoda koji se nalaze u listi i onda to dodati u 
                            // tabelu NAPRAVLJEN_OD. Takodje dodati cijenu u PROIZVOD_CIJENA.
                            // Iskoristiti metodu insertFullProductInfo, jer je jedina razlika 
                            // sto treba da se ucitaju normativi i saberu.
                            boolean isNew = true;
                            for (Product p : RootController.getAllProducts()) {
                                // Check if product exists in all registred products //
                                if (RootController.currWeddingCake.equals(p)) {
                                    isNew = false;
                                    break;
                                }
                            }
                            // If product do not exists need to open Norm form //
                            if (isNew) {
                                ProductMySQL pro = new ProductMySQL();
                                pro.addWeddCakeProd(RootController.currWeddingCake, weddingCakeProductList);
                                ProductMySQL productMySQL = new ProductMySQL();
                                ArrayList<Product> products = productMySQL.allProductsFullInfo();
                                rootController.setAllProducts(products);
                            }
                            // When add complete set currentWeddingCake to new Object
                            //if (!isNew) {
                            int counter = 0;
                            boolean isInTable = false;
                            for (Product p : RootController.dataBillProducts) {
                                if (p.equals(RootController.currWeddingCake)) {
                                    isInTable = true;
                                    RootController.currWeddingCake.setTempQuantity(
                                            RootController.currWeddingCake.getTempQuantity() + p.getTempQuantity());
                                    RootController.currWeddingCake.setFormatName("Svadbena, "
                                            + RootController.currWeddingCake.getFloorNumber() + " spratova");
                                    RootController.dataBillProducts.remove(p);
                                    RootController.getDataBillProducts().add(counter,
                                            RootController.currWeddingCake); // Add to observable list and tableView
                                    //Refresh table data
                                    ObservableList<Product> tmpList = FXCollections
                                            .observableArrayList(RootController.dataBillProducts);
                                    RootController.dataBillProducts.removeAll(RootController.dataBillProducts);
                                    for (Product pp : tmpList) {
                                        RootController.dataBillProducts.add(pp);
                                    }
                                    RootController.currWeddingCake = new Product();
                                    //deselectCakeToogleButtons();
                                    break;
                                }
                                ++counter;
                            }

                            if (!isInTable) {
                                RootController.currWeddingCake.setFormatName("Svadbena, "
                                        + RootController.currWeddingCake.getFloorNumber() + " spratova");
                                RootController.getDataBillProducts().add(RootController.currWeddingCake); // Add to observable list and tableView
                                RootController.currWeddingCake = new Product();
                                //deselectCakeToogleButtons();

                            }
                            // }
                            setWeddingFloorsColorVisible();
                            //RootController.currWeddingCake.setFormatName("Svadbena, " + RootController.currWeddingCake.getFloorNumber() + " spratova");
                            //RootController.getDataBillProducts().add(RootController.currWeddingCake); // Add to observable list and tableView
                            //RootController.currWeddingCake = new Product();

                            RootController.sumOfProductsIn += Double
                                    .parseDouble(productsInCakeQuantityTextField.getText())
                                    * Double.parseDouble(productsInCakePriceTextField.getText());
                            DecimalFormat f = new DecimalFormat("#.00");
                            productsInBillSumLabel.setText(f.format(RootController.sumOfProductsIn));
                            productsInCakePriceTextField.setText("");
                            productsInCakeQuantityTextField.setText("");
                        } else {
                            productsInCakePriceTextField.requestFocus();
                        }
                    }
                }

            } else if (RootController.selectedTabProductsIn.equals("Kolaci")) {
                if (enterFunction == 1) {
                    productsInCakePriceTextField.requestFocus();
                    enterFunction = 2;
                    RootController.focusTextField = "cookiesprice";
                } else if (enterFunction == 2) {
                    RootController.currProduct
                            .setTempPrice(Double.parseDouble(productsInCakePriceTextField.getText()));
                    RootController.currProduct
                            .setTempQuantity(Double.parseDouble(productsInCakeQuantityTextField.getText()));
                    RootController.currProduct.setFormatName(RootController.getCurrProduct().getName());

                    RootController.productsInQuantityTextField = productsInCakeQuantityTextField;
                    RootController.productsInPriceTextField = productsInCakePriceTextField;

                    boolean isNew = true;
                    for (Product p : RootController.allProducts) {
                        if (RootController.currProduct.getName().equals(p.getName())) {
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew) {
                        // Ne postoji proizvod u bazi pa treba kreirati normativ
                        // Otvaramo novu formu
                        Stage stage = new Stage();
                        Parent root = FXMLLoader.load(getClass().getResource("NewNormsForm.fxml"));
                        Scene scene = new Scene(root);
                        stage.setScene(scene);
                        stage.initModality(Modality.APPLICATION_MODAL);
                        rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
                        stage.setTitle("Normativ");
                        stage.showAndWait();
                    } else {
                        // Postoji u bazi, ne treba kreirati normativ jer postoji
                        // Dodati u TableView u ovom bloku
                        int counter = 0;
                        boolean isInTable = false;
                        for (Product p : RootController.dataBillProducts) {
                            if (p.equals(RootController.currProduct)) {
                                isInTable = true;
                                RootController.currProduct.setTempQuantity(
                                        RootController.currProduct.getTempQuantity() + p.getTempQuantity());
                                RootController.currProduct.setFormatName(RootController.currProduct.getName());
                                RootController.dataBillProducts.remove(p);
                                RootController.getDataBillProducts().add(counter, RootController.currProduct); // Add to observable list and tableView
                                //Refresh table data
                                ObservableList<Product> tmpList = FXCollections
                                        .observableArrayList(RootController.dataBillProducts);
                                RootController.dataBillProducts.removeAll(RootController.dataBillProducts);
                                for (Product pp : tmpList) {
                                    RootController.dataBillProducts.add(pp);
                                }
                                RootController.currProduct = new Product();
                                //deselectCakeToogleButtons();
                                cookieToggleGroup.getSelectedToggle().setSelected(false);
                                break;
                            }
                            ++counter;
                        }

                        if (!isInTable) {
                            RootController.currProduct.setFormatName(RootController.currProduct.getName());
                            RootController.getDataBillProducts().add(RootController.currProduct); // Add to observable list and tableView
                            RootController.currProduct = new Product();
                            //deselectCakeToogleButtons();
                            cookieToggleGroup.getSelectedToggle().setSelected(false);
                        }

                        //RootController.dataBillProducts.add(RootController.currProduct);
                        // Provjeriti da li se cijena promijenila
                        // Ili mozda omoguciti promjenu cijene samo preko odredjenog formulara
                    }
                    RootController.sumOfProductsIn += Double.parseDouble(productsInCakeQuantityTextField.getText())
                            * Double.parseDouble(productsInCakePriceTextField.getText());
                    DecimalFormat f = new DecimalFormat("#.00");
                    productsInBillSumLabel.setText(f.format(RootController.sumOfProductsIn));

                    productsInCakeQuantityTextField.setText("");
                    productsInCakePriceTextField.setText("");
                }
            }

        }

        //printSingleInformations();
        //printInformations();
    }

    @FXML
    void completeWeddingCakeAction(ActionEvent event) {
        boolean allSelected = false;

        if (RootController.currWeddingCake.getMoreFloorInfo().split("#").length == RootController.currWeddingCake
                .getFloorNumber()) {
            allSelected = true;
        }

        if (allSelected) {
            productsInCakeQuantityTextField.requestFocus();
            enterFunction = 1;
            RootController.focusTextField = "weddingquantity";
            RootController.productsInWeddingAction = "unostabela";

            boolean isNew = true;
            //

            for (Product p : RootController.allProducts) {
                if (p.equals(RootController.currWeddingCake)) {
                    isNew = false;
                    RootController.currWeddingCake.setTempPrice(p.getTempPrice());
                    break;
                }
            }
            //System.out.println("IS NEW PRODUCT: " + isNew);
            if (!isNew) {
                productsInCakePriceTextField
                        .setText(Double.toString(RootController.currWeddingCake.getTempPrice()));
            }
        }

    }
    ////////////////////////////////////////////////////////////////////////////

    @FXML
    void newSupplyButtonAction(ActionEvent e) throws IOException {
        Stage stage = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("NewSupplyForm.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.initModality(Modality.APPLICATION_MODAL);
        rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
        stage.setTitle("Novi materijal");
        stage.showAndWait();
    }

    @FXML
    void suppliesSideBarButtonAction(ActionEvent e) {
        suppliesRootAnchorPane.setVisible(true);
        productsInRootAnchorPane.setVisible(false);
        welcomeAnchorPane.setVisible(false);
        productsOutRootAnchorPane.setVisible(false);
        workOrderRootAnchorPane.setVisible(false);
        normsRootAnchorPane.setVisible(false);
        RootController.selectedSideMenu = "materijal";

        suppliesSideBarButton.setStyle("-fx-graphic: url('/icons/Materijal.png'); -fx-background-color: #38474E;\n"
                + "    -fx-border-color: #38474E;\n" + "    -fx-border-width: 1px;");

        if (selectedSideBarButton >= 0 && selectedSideBarButton != 0) {
            Button btn = (Button) (sideBarVBox.getChildren().get(selectedSideBarButton));
            btn.setStyle(null);
            btn.setStyle("-fx-graphic: url('/icons/" + sideBarIconsMap.get(selectedSideBarButton) + "');");
        }
        selectedSideBarButton = 0;

    }
    ////////////////////////////////////////////////////////////////////////////
    /////////////////////////////// END OF SUPPLIES ////////////////////////////
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////
    //////////////////////////////// PRODUCTS IN ///////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ///////// What happend when click on ProductsIn button in Side Menu ////////
    @FXML
    void productsInSideBarButtonAction(ActionEvent e) {
        // Visible productsIn AnchorPane and hide others AnchorPanes //
        productsInRootAnchorPane.setVisible(true);
        suppliesRootAnchorPane.setVisible(false);
        welcomeAnchorPane.setVisible(false);
        productsOutRootAnchorPane.setVisible(false);
        workOrderRootAnchorPane.setVisible(false);
        normsRootAnchorPane.setVisible(false);
        RootController.selectedSideMenu = "proizvodiulaz";
        RootController.selectedTabProductsIn = "Torte";

        productsInSideBarButton
                .setStyle("-fx-graphic: url('/icons/ProizvodiUlaz48.png'); -fx-background-color: #38474E;\n"
                        + "    -fx-border-color: #38474E;\n" + "    -fx-border-width: 1px;");
        if (selectedSideBarButton >= 0 && selectedSideBarButton != 1) {
            Button btn = (Button) (sideBarVBox.getChildren().get(selectedSideBarButton));
            btn.setStyle(null);
            btn.setStyle("-fx-graphic: url('/icons/" + sideBarIconsMap.get(selectedSideBarButton) + "');");
        }
        selectedSideBarButton = 1;

    }

    @FXML
    void productsOutSideBarButtonAction(ActionEvent event) {
        productsInRootAnchorPane.setVisible(false);
        suppliesRootAnchorPane.setVisible(false);
        welcomeAnchorPane.setVisible(false);
        productsOutRootAnchorPane.setVisible(true);
        workOrderRootAnchorPane.setVisible(false);
        normsRootAnchorPane.setVisible(false);

        RootController.selectedSideMenu = "proizvodiizlaz";

        productsOutSideBarButton
                .setStyle("-fx-graphic: url('/icons/ProizvodiIzlaz48.png'); -fx-background-color: #38474E;\n"
                        + "    -fx-border-color: #38474E;\n" + "    -fx-border-width: 1px;");
        if (selectedSideBarButton >= 0 && selectedSideBarButton != 2) {
            Button btn = (Button) (sideBarVBox.getChildren().get(selectedSideBarButton));
            btn.setStyle(null);
            btn.setStyle("-fx-graphic: url('/icons/" + sideBarIconsMap.get(selectedSideBarButton) + "');");
        }
        selectedSideBarButton = 2;

        this.resetProductsOutTables();
    }

    public void resetProductsOutTables() {
        dataCakesOut.clear();
        ProductMySQL pm = new ProductMySQL();
        ArrayList<Product> storeProducts = pm.getStoreHouse();
        for (Product tempP : storeProducts) {
            if (tempP.getSelector().equals("torta")) {
                dataCakesOut.add(tempP);
            }
        }

        dataWeddCakesOut.clear();
        for (Product tempP : storeProducts) {
            if (tempP.getSelector().equals("svadbena")) {
                WeddingCakeProductsOut wc = new WeddingCakeProductsOut();
                wc.setWeddingInfo(tempP);
                dataWeddCakesOut.add(wc);
                String[] info = tempP.getMoreFloorInfo().split("#");
                for (String str : info) {
                    String find = str.split(",")[1];
                    for (Product p : RootController.allProducts) {
                        if (p.getId() == Integer.parseInt(find)) {
                            WeddingCakeProductsOut temp = new WeddingCakeProductsOut();
                            temp.setCakeInfo(p);
                            dataWeddCakesOut.add(temp);
                            break;
                        }
                    }
                }
            }
        }

    }

    @FXML
    void normsSideBarButtonAction(ActionEvent event) {
        normsRootAnchorPane.setVisible(true);
        productsInRootAnchorPane.setVisible(false);
        suppliesRootAnchorPane.setVisible(false);
        welcomeAnchorPane.setVisible(false);
        productsOutRootAnchorPane.setVisible(false);
        workOrderRootAnchorPane.setVisible(false);

        RootController.selectedSideMenu = "normativi";

        normsSideBarButton.setStyle("-fx-graphic: url('/icons/Normativ48.png'); -fx-background-color: #38474E;\n"
                + "    -fx-border-color: #38474E;\n" + "    -fx-border-width: 1px;");
        if (selectedSideBarButton >= 0 && selectedSideBarButton != 3) {
            Button btn = (Button) (sideBarVBox.getChildren().get(selectedSideBarButton));
            btn.setStyle(null);
            btn.setStyle("-fx-graphic: url('/icons/" + sideBarIconsMap.get(selectedSideBarButton) + "');");
        }
        selectedSideBarButton = 3;

        dataNormsCakes.clear();
        dataNormsCakes.clear();
        for (Product tempP : RootController.allProducts) {
            if (tempP.getSelector().equals("torta")) {
                dataNormsCakes.add(tempP);
            }
        }

        this.resetProductsOutTables();
    }

    @FXML
    void workOrderSideBarButtonAction(ActionEvent event) {
        workOrderRootAnchorPane.setVisible(true);
        productsInRootAnchorPane.setVisible(false);
        suppliesRootAnchorPane.setVisible(false);
        welcomeAnchorPane.setVisible(false);
        productsOutRootAnchorPane.setVisible(false);
        normsRootAnchorPane.setVisible(false);

        RootController.selectedSideMenu = "radninalozi";

        workOrderSideBarButton
                .setStyle("-fx-graphic: url('/icons/RadniNalog48.png'); -fx-background-color: #38474E;\n"
                        + "    -fx-border-color: #38474E;\n" + "    -fx-border-width: 1px;");
        if (selectedSideBarButton >= 0 && selectedSideBarButton != 4) {
            Button btn = (Button) (sideBarVBox.getChildren().get(selectedSideBarButton));
            btn.setStyle(null);
            btn.setStyle("-fx-graphic: url('/icons/" + sideBarIconsMap.get(selectedSideBarButton) + "');");
        }
        selectedSideBarButton = 4;

        dataWorkOrders.clear();
        List<WorkOrder> tempList = new ArrayList<>();
        List<WorkOrder> sortedList = new ArrayList<>();
        for (WorkOrder wo : RootController.allWorkOrders) {
            tempList.add(wo);
        }

        Collections.sort(tempList, new WorkOrderCompare());

        for (WorkOrder wo : tempList) {
            dataWorkOrders.add(wo);
        }

    }

    class WorkOrderCompare implements Comparator<WorkOrder> {

        @Override
        public int compare(WorkOrder o1, WorkOrder o2) {
            String[] nizO1 = o1.getFormatNumber().split("/");
            String[] nizO2 = o2.getFormatNumber().split("/");
            int o1date = Integer.parseInt(nizO1[1]);
            int o2date = Integer.parseInt(nizO2[1]);
            int o1num = Integer.parseInt(nizO1[0]);
            int o2num = Integer.parseInt(nizO2[0]);

            if (o1date > o2date) {
                return -1;
            }
            if (o1date < o2date) {
                return 1;
            }
            if (o1num > o2num) {
                return -1;
            }
            if (o1num < o2num) {
                return 1;
            }
            return 0;
        }

    }

    @FXML
    void writeOffSideBarButtonAction(ActionEvent event) {
        productsInRootAnchorPane.setVisible(false);
        suppliesRootAnchorPane.setVisible(false);
        welcomeAnchorPane.setVisible(false);
        productsOutRootAnchorPane.setVisible(false);
        workOrderRootAnchorPane.setVisible(false);
        normsRootAnchorPane.setVisible(false);

        RootController.selectedSideMenu = "otpis";

        writeOffSideBarButton.setStyle("-fx-graphic: url('/icons/Otpis48.png');-fx-background-color: #38474E;\n"
                + "    -fx-border-color: #38474E;\n" + "    -fx-border-width: 1px;");
        if (selectedSideBarButton >= 0 && selectedSideBarButton != 5) {
            Button btn = (Button) (sideBarVBox.getChildren().get(selectedSideBarButton));
            btn.setStyle("-fx-graphic: url('/icons/" + sideBarIconsMap.get(selectedSideBarButton) + "');");
        }
        selectedSideBarButton = 5;

    }

    ///////// Confirm all added products to bill, and set to database //////////
    @FXML
    void productsInconfirmButtonAction(ActionEvent e) throws Exception {
        ProductMySQL productMySQL = new ProductMySQL();
        RootController.allProducts = productMySQL.allProductsFullInfo();
        for (Product p : RootController.dataBillProducts) {
            for (Product temp : RootController.allProducts) {
                if (p.equals(temp)) {
                    p.setId(temp.getId());
                    break;
                }
            }
        }
        System.err.println("PRODUCT TO INSERT: " + RootController.dataBillProducts.get(0));

        boolean isOK = productMySQL.confirmProductsInTransaction();
        if (!isOK) {
            System.out.println("NEMA DOVOLJNO MATERIJALA");
        } else {
            productsInBillSumLabel.setText("0.00");
        }
    }

    ///////////////////////////// Clear product bill ///////////////////////////
    @FXML
    void productsInCancelButtonAction(ActionEvent e) {
        RootController.dataBillProducts.clear();
        productsInBillSumLabel.setText("0.00");
    }

    ///// Action for toggle buttons to change currCAKE shape, type, size etc. /////
    @FXML
    void cakeItemButtonsAction(ActionEvent event) {
        ToggleButton tb = (ToggleButton) event.getSource(); // clicked ToggleButton
        if (tb.getToggleGroup().equals(cakeShapeToggleGroup)) {
            RootController.currProduct.setShape(tb.getText());
        } else if (tb.getToggleGroup().equals(cakeTypeToggleGroup)) {
            RootController.currProduct.setType(tb.getText());
        } else if (tb.getToggleGroup().equals(cakeSizeToggleGroup)) {
            RootController.currProduct.setSize(tb.getText());
        } else if (tb.getToggleGroup().equals(cakeGlazeToggleGroup)) {
            RootController.currProduct.setGlaze(tb.getText());
        } else if (tb.getToggleGroup().equals(cakePictureToggleGroup)) {
            RootController.currProduct.setPicture(tb.getText().equals("Da") ? true : false);
        }
        //printSingleInformations();
        //printInformations();

    }

    ///// Action for toggle buttons to change currWEDDINGCAKE shape, type, size etc. /////
    @FXML
    void weddingCakeItemButtonsAction(ActionEvent event) {
        ToggleButton tb = (ToggleButton) event.getSource(); // clicked ToggleButton
        int sf = Integer.parseInt(selectedFloor); // number of wedding cake floor
        if (tb.getToggleGroup().equals(weddingCakeShapeToggleGroup)) {
            RootController.currProduct.setShape(tb.getText());
        } else if (tb.getToggleGroup().equals(weddingCakeTypeToggleGroup)) {
            RootController.currProduct.setType(tb.getText());
        } else if (tb.getToggleGroup().equals(weddingCakeSizeToggleGroup)) {
            RootController.currProduct.setSize(tb.getText());
        } else if (tb.getToggleGroup().equals(weddingCakeGlazeToggleGroup)) {
            RootController.currProduct.setGlaze(tb.getText());
        } else if (tb.getToggleGroup().equals(weddingCakePictureToggleGroup)) {
            RootController.currProduct.setPicture(tb.getText().equals("Da") ? true : false);
        }
    }

    ///////////////////// Action to add cake to TableView //////////////////////
    /* This method add product in database if that product is new. Also, we   */
    /* will add norm for that product, and insert into database too.          */
    @FXML
    void addCakeButtonAction(ActionEvent event) throws IOException {
        RootController.currProduct.setMeasureUnit("kom");
        RootController.currProduct.setSelector("torta");
        RootController.currProduct.setFloorNumber(1);
        RootController.currProduct.setTempQuantity(Double.parseDouble(productsInCakeQuantityTextField.getText()));
        RootController.currProduct.setTempPrice(Double.parseDouble(productsInCakePriceTextField.getText()));

        boolean isNew = true;
        for (Product p : RootController.getAllProducts()) {
            // Check if product exists in all registred products //
            if (RootController.currProduct.equals(p)) {
                isNew = false;
                break;
            }
        }
        // If product do not exists need to open Norm form //
        if (isNew) {
            // Ne postoji proizvod u bazi pa treba kreirati normativ
            // Otvaramo novu formu
            Stage stage = new Stage();
            Parent root = FXMLLoader.load(getClass().getResource("NewNormsForm.fxml"));
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.initModality(Modality.APPLICATION_MODAL);
            rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
            stage.showAndWait();
            deselectCakeToogleButtons();
            ProductMySQL productMySQL = new ProductMySQL();
            ArrayList<Product> products = productMySQL.allProductsFullInfo();
            rootController.setAllProducts(products);
        } else {
            // Postoji u bazi, ne treba kreirati normativ jer postoji
            // Dodati u TableView u ovom bloku
            RootController.getDataBillProducts().add(RootController.currProduct); // Add to observable list and tableView
            RootController.currProduct = new Product();
            deselectCakeToogleButtons();
        }
    }

    @FXML
    void setFloorParameterButtonAction(ActionEvent event) throws IOException {
        if (RootController.currProduct.getGlaze() != null && RootController.currProduct.getShape() != null
                && RootController.currProduct.getSize() != null && RootController.currProduct.getType() != null) {
            weddingCakeFloorDesVBox.setDisable(true);
            int selFloor = Integer.parseInt(selectedFloor);
            RootController.selectedFloor = selFloor;
            RootController.currProduct.setSelector("torta");
            RootController.currProduct.setFloorNumber(1);
            RootController.currProduct.setMeasureUnit("kom");
            promjeneNtogSprataLabel.setText("");
            // Check if product exists in registred products //
            boolean isNew = true;
            Product pp = null;
            for (Product p : RootController.allProducts) {
                if (RootController.currProduct.equals(p)) {
                    isNew = false;
                    RootController.currProduct.setId(p.getId());
                    break;
                }
            }
            if (isNew) {
                // Ne postoji proizvod u bazi pa treba kreirati normativ
                // Otvaramo novu formu
                productsInCakePriceTextField.requestFocus();
                enterFunction = 1;
                RootController.focusTextField = "weddingprice";
                RootController.usingNumpad = true;
                RootController.productsInWeddingAction = "normativ";
                RootController.productsInQuantityTextField = productsInCakeQuantityTextField;
                RootController.productsInPriceTextField = productsInCakePriceTextField;
            } else {
                // Postoji u bazi, ne treba kreirati normativ jer postoji
                // Dodati u TableView u ovom bloku
                String str = RootController.currWeddingCake.getMoreFloorInfo();
                if (str.equals("")) {
                    str = selectedFloor + "," + RootController.currProduct.getId();
                } else {
                    str += "#" + selectedFloor + "," + RootController.currProduct.getId();
                }
                RootController.currWeddingCake.setMoreFloorInfo(str);
                ((ToggleButton) weddingCakeFloorsVBox.getChildren().get(7 - selFloor))
                        .setStyle("" + "-fx-background-color: #019788; -fx-text-fill: #111111");
                deselectWeddingToogleButtons();
            }
        }
    }

    @FXML
    void productsOutConfirmButtonAction(ActionEvent event) {
        ProductMySQL pmysql = new ProductMySQL();
        ArrayList<Product> prods = new ArrayList<>();
        for (Product p : dataProductsOut) {
            prods.add(p);
        }
        boolean isOK = pmysql.productsOutInsert(prods);

        dataProductsOut.clear();

        productsOutBillSumLabel.setText("0.00");
    }

    @FXML
    void productsOutCancelButtonAction(ActionEvent event) {
        dataProductsOut.clear();
        this.resetProductsOutTables();
        productsOutBillSumLabel.setText("0.00");
    }

    /////////// Drawing wedding cake floors based on typed number  /////////////
    @FXML
    void weddingCakeDrawFloorsButtonAction(ActionEvent event) {
        RootController.currentNumOfFloors = 0;
        RootController.currWeddingCake = new Product();
        if (!weddingCakeNumOfFloorsTextField.getText().equals("")) {
            RootController.currentNumOfFloors = Integer.parseInt(weddingCakeNumOfFloorsTextField.getText());
        }

        if (RootController.currentNumOfFloors > 1 && RootController.currentNumOfFloors < 8) {
            // Ovdje je potrebno iscrtati odredjen broj spratova, tj. sakriti one koji
            // nisu potrebni. 
            weddingCakeFloorsVBox.setDisable(false);
            setVisibleWeddingFloors();
            switch (RootController.currentNumOfFloors) {
            case 2: {
                weddingCakeFloorsButton3.setDisable(true);
                weddingCakeFloorsButton4.setDisable(true);
                weddingCakeFloorsButton5.setDisable(true);
                weddingCakeFloorsButton6.setDisable(true);
                weddingCakeFloorsButton7.setDisable(true);
                break;
            }
            case 3: {
                weddingCakeFloorsButton4.setDisable(true);
                weddingCakeFloorsButton5.setDisable(true);
                weddingCakeFloorsButton6.setDisable(true);
                weddingCakeFloorsButton7.setDisable(true);
                break;
            }
            case 4: {
                weddingCakeFloorsButton5.setDisable(true);
                weddingCakeFloorsButton6.setDisable(true);
                weddingCakeFloorsButton7.setDisable(true);
                break;
            }
            case 5: {
                weddingCakeFloorsButton6.setDisable(true);
                weddingCakeFloorsButton7.setDisable(true);
                break;
            }
            case 6: {
                weddingCakeFloorsButton7.setDisable(true);
                break;
            }
            default:
                break;
            }

            RootController.getCurrWeddingCake().setFloorNumber(RootController.currentNumOfFloors);
            RootController.currWeddingCake.setSelector("svadbena");
            RootController.currWeddingCake.setMeasureUnit("kom");
            RootController.currWeddingCake.setMoreFloorInfo("");
        } else {
            //Broj spratova nije u pravom opsegu!
        }

    }

    //////////////////////////// Action: Floor selected ////////////////////////
    @FXML
    void weddingCakeFloorsButtonAction(ActionEvent event) {

        weddingCakeFloorDesVBox.setDisable(false);
        setFloorParameterButton.setDisable(false);
        ToggleButton tb = (ToggleButton) event.getSource();
        promjeneNtogSprataLabel.setText("Vrsite promjene " + tb.getText() + ". sprata");
        selectedFloor = ((ToggleButton) event.getSource()).getText();
        RootController.selectedFloor = Integer.parseInt(tb.getText());
        String[] moreInf = RootController.currWeddingCake.getMoreFloorInfo().split("#");
        int idProd = 0;
        for (String s : moreInf) {
            if (s.startsWith(tb.getText() + ",")) {
                idProd = Integer.parseInt((s.split(","))[1]);
            }
        }
        if (idProd != 0) {
            for (Product p : RootController.allProducts) {
                if (p.getId() == idProd) {
                    descriptionWeddingCakeLabel.setText(tb.getText() + ". sprat: \n" + p.prodInfo());
                }
            }
        } else {
        }
    }

    /////////////////// Action of Toggle Buttons in cake tab ///////////////////
    @FXML
    void cookieToggleButtonsAction(ActionEvent event) {
        RootController.currProduct = new Product();
        RootController.currProduct.setSelector("kolac");
        RootController.currProduct.setMeasureUnit("kg");
        RootController.currProduct.setName(((ToggleButton) event.getSource()).getText());
        productsInCakeQuantityTextField.requestFocus();
        enterFunction = 1;
        RootController.focusTextField = "cookiesquantity";

        boolean isNew = true;
        for (Product p : RootController.allProducts) {
            if (p.equals(RootController.currProduct)) {
                isNew = false;
                RootController.currProduct.setTempPrice(p.getTempPrice());
                break;
            }
        }

        if (!isNew) {
            productsInCakePriceTextField.setText(Double.toString(RootController.currProduct.getTempPrice()));
        } else {
            productsInCakePriceTextField.setText("");
        }

    }

    @FXML
    void setProductInfoButtonAction(ActionEvent event) {
        boolean allSelected = true;

        if (cakeShapeToggleGroup.getSelectedToggle() == null) {
            allSelected = false;
        } else if (cakeTypeToggleGroup.getSelectedToggle() == null) {
            allSelected = false;
        } else if (cakeSizeToggleGroup.getSelectedToggle() == null) {
            allSelected = false;
        } else if (cakeGlazeToggleGroup.getSelectedToggle() == null) {
            allSelected = false;
        } else if (cakePictureToggleGroup.getSelectedToggle() == null) {
            allSelected = false;
        }

        if (allSelected) {
            productsInCakeQuantityTextField.requestFocus();
            enterFunction = 1;
            RootController.usingNumpad = true;
            RootController.focusTextField = "cakequantity";

            boolean isNew = true;
            RootController.currProduct.setSelector("torta");
            RootController.currProduct.setFloorNumber(1);
            RootController.currProduct.setMeasureUnit("kom");

            for (Product p : RootController.allProducts) {
                if (p.equals(RootController.currProduct)) {
                    isNew = false;
                    RootController.currProduct.setTempPrice(p.getTempPrice());
                    break;
                }
            }
            if (!isNew) {
                productsInCakePriceTextField.setText(Double.toString(RootController.currProduct.getTempPrice()));
            }

            //printSingleInformations();
            //printInformations();
        }

    }

    ///////////////////////////// LAGER LIST ///////////////////////////////////
    @FXML
    public AnchorPane lagerPopUpRootAnchorPane;

    @FXML
    void lagerButtonAction(ActionEvent event) {
        if (RootController.isLagerActive == false) {
            RootController.isLagerActive = true;
            lagerPopUpRootAnchorPane.setVisible(true);
            SupplyMySQL sql = new SupplyMySQL();
            RootController.currentLagerList = sql.getLagerList();
        } else {
            RootController.isLagerActive = false;
            lagerPopUpRootAnchorPane.setVisible(false);
        }
    }

    @FXML
    void previewLagerButtonAction(ActionEvent event) throws IOException {
        SupplyMySQL sql = new SupplyMySQL();
        RootController.currentLagerList = sql.getLagerList();

        Stage stage = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("LagerForm.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Lager lista");
        stage.initModality(Modality.APPLICATION_MODAL);
        rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
        stage.showAndWait();
        lagerPopUpRootAnchorPane.setVisible(false);
        RootController.isLagerActive = false;
    }

    @FXML
    void printLagerButtonAction(ActionEvent event) throws IOException, Exception {
        SuppliesListPDF pdf = new SuppliesListPDF(RootController.currentLagerList, new Date());
        String path = pdf.createSuppliesList();

        File file = new File(path);
        new MainFormController().printPDFDocument(file);
        lagerPopUpRootAnchorPane.setVisible(false);
        RootController.isLagerActive = false;
    }
    ////////////////////////////////////////////////////////////////////////////

    ///////////////////////////// DAILY REPORTS ////////////////////////////////
    @FXML
    private AnchorPane productInDailyReportRootAnchorPane;
    @FXML
    private AnchorPane dailyReportOutRootAnchorPane;

    @FXML
    void dailyReportButtonAction(ActionEvent event) {
        if (RootController.isProductDailyReportInActive == false) {
            RootController.isProductDailyReportInActive = true;
            productInDailyReportRootAnchorPane.setVisible(true);
            ProductMySQL sql = new ProductMySQL();
            RootController.currentProductDailyReportList = sql.getProductsForDailyReport(new Date());
        } else {
            RootController.isProductDailyReportInActive = false;
            productInDailyReportRootAnchorPane.setVisible(false);
        }
    }

    @FXML
    void dailyReportOutButtonAction(ActionEvent event) {
        if (RootController.isProductDailyReportOutActive == false) {
            RootController.isProductDailyReportOutActive = true;
            dailyReportOutRootAnchorPane.setVisible(true);
            ProductMySQL sql = new ProductMySQL();
            RootController.currentProductDailyReportList = sql.getProductsForDailyReport(new Date());
        } else {
            RootController.isProductDailyReportOutActive = false;
            dailyReportOutRootAnchorPane.setVisible(false);
        }
    }

    @FXML
    void previewDailyReportButtonAction(ActionEvent event) throws IOException {
        ProductMySQL sql = new ProductMySQL();
        RootController.currentProductDailyReportList = sql.getProductsForDailyReport(new Date());

        Stage stage = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("DailyReportForm.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Dnevni izvjestaj");
        stage.initModality(Modality.APPLICATION_MODAL);
        rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
        stage.showAndWait();
        productInDailyReportRootAnchorPane.setVisible(false);
        RootController.isProductDailyReportInActive = false;
        dailyReportOutRootAnchorPane.setVisible(false);
        RootController.isProductDailyReportOutActive = false;
    }

    @FXML
    void printDailyStoreButtonAction(ActionEvent event) throws IOException, Exception {
        for (Product p : RootController.currentProductDailyReportList) {
            p.createFormatName();
        }
        DailyReportPDF pdf = new DailyReportPDF(RootController.currentProductDailyReportList, new Date());
        String path = pdf.createDailyReport();

        File file = new File(path);
        new MainFormController().printPDFDocument(file);

        productInDailyReportRootAnchorPane.setVisible(false);
        RootController.isProductDailyReportInActive = false;
        dailyReportOutRootAnchorPane.setVisible(false);
        RootController.isProductDailyReportOutActive = false;
    }
    ////////////////////////////////////////////////////////////////////////////

    /////////////////////////// PRODUCTS STORE /////////////////////////////////
    @FXML
    private AnchorPane productsStoreInRootAnchorPane;
    @FXML
    private AnchorPane productsStoreOutRootAnchorPane;

    @FXML
    void productsStoreInButtonAction(ActionEvent event) {
        if (RootController.isProductStoreInActive == false) {
            RootController.isProductStoreInActive = true;
            productsStoreInRootAnchorPane.setVisible(true);
            ProductMySQL sql = new ProductMySQL();
            RootController.currentProductStoreList = sql.getStoreHouse();

        } else {
            RootController.isProductStoreInActive = false;
            productsStoreInRootAnchorPane.setVisible(false);
        }
    }

    @FXML
    void productsStoreOutButtonAction(ActionEvent event) {
        if (RootController.isProductStoreOutActive == false) {
            RootController.isProductStoreOutActive = true;
            productsStoreOutRootAnchorPane.setVisible(true);
            ProductMySQL sql = new ProductMySQL();
            RootController.currentProductStoreList = sql.getStoreHouse();
        } else {
            RootController.isProductStoreOutActive = false;
            productsStoreOutRootAnchorPane.setVisible(false);
        }
    }

    @FXML
    void previewProductsStoreButtonAction(ActionEvent event) throws IOException {
        ProductMySQL sql = new ProductMySQL();
        RootController.currentProductStoreList = sql.getStoreHouse();

        Stage stage = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("ProductsStore.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Trenutno stanje proizvoda");
        stage.initModality(Modality.APPLICATION_MODAL);
        rootController.setOwnerStage((Stage) suppliesSideBarButton.getScene().getWindow());
        stage.showAndWait();
        productsStoreInRootAnchorPane.setVisible(false);
        RootController.isProductStoreInActive = false;
        productsStoreOutRootAnchorPane.setVisible(false);
        RootController.isProductStoreOutActive = false;
    }

    @FXML
    void printProductStoreButtonAction(ActionEvent event) throws IOException, Exception {
        for (Product p : RootController.currentProductStoreList) {
            p.createFormatName();
        }
        StockItemsPDF pdf = new StockItemsPDF(RootController.currentProductStoreList, new Date());
        String path = pdf.createStockItems();

        File file = new File(path);
        new MainFormController().printPDFDocument(file);

        productsStoreInRootAnchorPane.setVisible(false);
        RootController.isProductStoreInActive = false;
        productsStoreOutRootAnchorPane.setVisible(false);
        RootController.isProductStoreOutActive = false;
    }
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////// END OF PRODUCTS IN //////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    @FXML
    void mainFormMinimizeButtonAction(ActionEvent event) {
        RootController.activeStage.setIconified(true);
    }

    @FXML
    void mainFormMaiximizeButtonAction(ActionEvent event) {
        Screen screen = Screen.getPrimary();
        Rectangle2D bounds = screen.getVisualBounds();

        RootController.activeStage.setX(bounds.getMinX());
        RootController.activeStage.setY(bounds.getMinY());
        RootController.activeStage.setWidth(bounds.getWidth());
        RootController.activeStage.setHeight(bounds.getHeight());
    }

    @FXML
    void mainFormCloseButtonAction(ActionEvent event) {
        RootController.activeStage.close();
    }

    ////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////// WORK ORDERS //////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    @FXML
    void workOrderDateButtonAction(ActionEvent event) throws IOException {
        LocalDate date = workOrderDatePicker.getValue();
        ProductMySQL prodMySQL = new ProductMySQL();
        String numOfWO = "";
        numOfWO = prodMySQL.createWorkOrder(Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()));

        WorkOrderPDF woPDF = new WorkOrderPDF(numOfWO,
                Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()), RootController.workOrderProducts,
                RootController.workOrderSupplies);
        woPDF.createWorkOrder();

        DateFormat df = new SimpleDateFormat("yy"); // Just the year, with 2 digits
        String formatedDate = df.format(woPDF.getDateOfWorkOrder());

        File file = new File("pdf_docs" + File.separator + "work_orders" + File.separator + "work_order_"
                + woPDF.getNumOfWorkOrder().split("/")[0] + "_" + formatedDate + ".pdf");

        PDDocument doc = PDDocument.load(file);
        PDFRenderer renderer = new PDFRenderer(doc);
        renderer.renderImageWithDPI(0, 300);
        //BufferedImage image = renderer.renderImage(0);
        BufferedImage image = renderer.renderImageWithDPI(0, 300);
        ImageIO.write(image, "PNG", new File("pdf_docs" + File.separator + "work_orders_picture" + File.separator
                + "work_order_" + woPDF.getNumOfWorkOrder().split("/")[0] + "_" + formatedDate + ".png"));
        doc.close();

        WorkOrderMySQL woMySQL = new WorkOrderMySQL();
        ArrayList<WorkOrder> orders = woMySQL.getAllWokrOrders();
        RootController.allWorkOrders = orders;
        Collections.sort(RootController.allWorkOrders, new WorkOrderCompare());
        dataWorkOrders.clear();
        for (WorkOrder w : RootController.allWorkOrders) {
            dataWorkOrders.add(w);
        }
    }

    ////////////////////////////////////////////////////////////////////////////
    /**
     * Initializes the controller class.
     */
    @FXML
    private Button completeWeddingCake;
    @FXML
    private Label dateWelcomeLabel;
    @FXML
    private ImageView welcomeImageView;
    @FXML
    private ImageView logoImageView;
    @FXML
    private TabPane normsTabPane;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        /////////// FIRST RUN //////////
        suppliesRootAnchorPane.setVisible(false);
        productsInRootAnchorPane.setVisible(false);
        weddingCakeFloorDesVBox.setDisable(true);

        if (isFirstRun) {
            rootController = FirmaApp.getRootController();
            isFirstRun = false;

            // Instance currProduct and currWeddingCake //
            RootController.currProduct = new Product();
            RootController.currWeddingCake = new Product();

            SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy.");
            dateWelcomeLabel.setText(sdf.format(new Date()));
            File ff = new File("icons/Dobrodosli.png");
            welcomeImageView.setImage(new Image(ff.toURI().toString()));
            ff = new File("icons/logo2.png");
            logoImageView.setImage(new Image(ff.toURI().toString()));

            sideBarIconsMap.put(0, "Materijal.png");
            sideBarIconsMap.put(1, "ProizvodiUlaz48.png");
            sideBarIconsMap.put(2, "ProizvodiIzlaz48.png");
            sideBarIconsMap.put(3, "Normativ48.png");
            sideBarIconsMap.put(4, "RadniNalog48.png");
            sideBarIconsMap.put(5, "Otpis48.png");

            File f = new File("images/icons/top_bar/Logout_Rounded.png");
            logoutButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 48, 48, true, true)));
            logoutButton.setPadding(Insets.EMPTY);
            logoutButton.setMaxHeight(48);
            f = new File("images/icons/top_bar/Circled_User_Male.png");
            userImageView.setImage(new Image(f.toURI().toString(), 48, 48, false, true));

            f = new File("images/icons/323232/Ok.png");
            confirmButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 48, 48, true, true)));
            productsInConfirmButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 48, 48, true, true)));
            productsOutConfirmButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 48, 48, true, true)));
            f = new File("images/icons/323232/Cancel.png");
            cancelButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 48, 48, true, true)));
            productsInCancelButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 48, 48, true, true)));
            productsOutCancelButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 48, 48, true, true)));
            confirmButton.setPadding(Insets.EMPTY);
            cancelButton.setPadding(Insets.EMPTY);
            productsInConfirmButton.setPadding(Insets.EMPTY);
            productsInCancelButton.setPadding(Insets.EMPTY);
            productsOutConfirmButton.setPadding(Insets.EMPTY);
            productsOutCancelButton.setPadding(Insets.EMPTY);
            completeWeddingCake.setPadding(Insets.EMPTY);
            setProductInfoButton.setPadding(Insets.EMPTY);

            popUpQuantityTextField.focusedProperty().addListener(new ChangeListener<Boolean>() {
                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
                        Boolean newValue) {
                    if (newValue) {
                        if (!rootController.isUsingNumpad()) {
                            RootController.focusTextField = "quantity";
                            enterFunction = 1;
                        } else {
                            rootController.setUsingNumpad(false);
                        }
                    } else {
                    }
                }
            });

            popUpPriceTextField.focusedProperty().addListener(new ChangeListener<Boolean>() {
                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
                        Boolean newValue) {
                    if (newValue) {
                        if (!rootController.isUsingNumpad()) {
                            RootController.focusTextField = "price";
                            enterFunction = 2;
                        } else {
                            rootController.setUsingNumpad(false);
                        }
                    } else {
                    }
                }
            });

            productsInCakeQuantityTextField.focusedProperty().addListener(new ChangeListener<Boolean>() {
                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
                        Boolean newValue) {
                    if (newValue) {
                        if (!rootController.isUsingNumpad()) {
                            RootController.focusTextField = "cakequantity";
                            enterFunction = 1;
                        } else {
                            rootController.setUsingNumpad(false);
                        }
                    } else {
                    }
                }
            });

            productsInCakePriceTextField.focusedProperty().addListener(new ChangeListener<Boolean>() {
                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
                        Boolean newValue) {
                    if (newValue) {
                        if (!rootController.isUsingNumpad()) {
                            RootController.focusTextField = "cakeprice";
                            enterFunction = 2;
                        } else {
                            rootController.setUsingNumpad(false);
                        }
                    } else {
                    }
                }
            });

            ArrayList<Supply> supplies = rootController.getAllSupplies();
            for (Supply s : supplies) {
                Button btn = new Button(s.getName());
                btn.getStyleClass().add("supplyButton");
                btn.setWrapText(true);
                btn.setTextAlignment(TextAlignment.CENTER);
                btn.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        popUpSupplyLabel.setText(((Button) event.getSource()).getText());
                        for (Supply tempS : RootController.allSupplies) {
                            if (tempS.getName().equals(((Button) event.getSource()).getText())) {
                                popUpPriceTextField.setText(Double.toString(tempS.getCurrentPrice()));
                                break;
                            }
                        }
                        popUpQuantityTextField.requestFocus();
                    }
                });
                suppliesFlowPane.getChildren().add(btn);
            }

            /**
             * ********* TABS CHANGES ********
             */
            productsInTabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
                @Override
                public void changed(ObservableValue<? extends Tab> ov, Tab t, Tab t1) {
                    RootController.selectedTabProductsIn = t1.getText();
                    if (t1.getText().equals("Torte")) {
                        File f = new File("images/icons/top_bar/BirthdayCake2.png");
                    }
                    if (!t.getText().equals(t1.getText())) {
                        RootController.currWeddingCake = new Product();
                        RootController.currProduct = new Product();
                    }
                }
            });

            normsTabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
                @Override
                public void changed(ObservableValue<? extends Tab> ov, Tab t, Tab t1) {
                    RootController.selectedTabNorms = t1.getText();
                    normSideVBox.setVisible(false);
                }
            });

            /////////////////////////Supplies TableView/////////////////////////
            suppliesTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            suppliesTableView.setEditable(true);
            suppliesTableView.setPlaceholder(new Label(""));
            TableColumn supplyNameCol = new TableColumn("Materijal");
            supplyNameCol.getStyleClass().add("table-column-left");
            TableColumn supplyQuantyCol = new TableColumn("Kolicina");
            supplyQuantyCol.getStyleClass().add("table-column-right");
            TableColumn supplyPriceCol = new TableColumn("Cijena");
            supplyPriceCol.getStyleClass().add("table-column-right");
            supplyNameCol.setMaxWidth(1f * Integer.MAX_VALUE * 40);
            supplyQuantyCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            supplyPriceCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);

            // REMOVE BUTTON
            TableColumn<SupplyToTable, SupplyToTable> removeCol = new TableColumn<>("Obrisi");
            removeCol.setStyle("-fx-alignment: CENTER;");
            removeCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            removeCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            removeCol.setCellFactory(param -> new TableCell<SupplyToTable, SupplyToTable>() {
                private final Button deleteButton = new Button("");

                @Override
                protected void updateItem(SupplyToTable sup, boolean empty) {
                    super.updateItem(sup, empty);

                    if (sup == null) {
                        setGraphic(null);
                        return;
                    }
                    deleteButton.setPrefHeight(35);
                    deleteButton.setPrefWidth(35);
                    File file = new File("icons/brisanjeSaracuna.png");
                    deleteButton.setGraphic(new ImageView(new Image(file.toURI().toString(), 30, 30, false, true)));
                    deleteButton.setStyle("-fx-background-color: #F3F6F7" + ";");
                    setGraphic(deleteButton);
                    deleteButton.setOnAction((ActionEvent event) -> {
                        //// IF CAKE unesi u dataCakesOut, IF WEDDING CAKE u dataWeddCakesOut...

                        double quant = 0;
                        for (SupplyToTable s : data) {
                            if (sup.getName().equals(s.getName())) {
                                quant = s.getQuanty();
                            }
                        }
                        data.remove(sup);
                        RootController.sumOfSupplies -= sup.getPrice() * quant;
                        if (RootController.sumOfSupplies == 0) {
                            supplyBillSumLabel.setText("0.00");
                        } else {
                            DecimalFormat f = new DecimalFormat("#.00");
                            supplyBillSumLabel.setText(f.format(RootController.sumOfSupplies));
                        }

                    });
                }
            });

            supplyNameCol.setCellValueFactory(new PropertyValueFactory<SupplyToTable, String>("name"));
            supplyQuantyCol.setCellValueFactory(new PropertyValueFactory<SupplyToTable, Double>("quanty"));
            supplyPriceCol.setCellValueFactory(new PropertyValueFactory<SupplyToTable, Double>("price"));
            suppliesTableView.setItems(data);
            suppliesTableView.getColumns().addAll(supplyNameCol, supplyQuantyCol, supplyPriceCol, removeCol);

            ///////////////////////////////////////////////////
            //ProductsIn TableView
            productsInTableView.setEditable(true);
            productsInTableView.setPlaceholder(new Label(""));
            productsInTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            TableColumn prodInNameCol = new TableColumn("Proizvod");
            TableColumn prodInQuantyCol = new TableColumn("Kolicina");
            TableColumn prodInPriceCol = new TableColumn("Cijena");
            TableColumn<Product, Product> removeProdInCol = new TableColumn<>("Obrisi");
            prodInNameCol.setStyle("-fx-alignment: CENTER-LEFT;");
            prodInQuantyCol.setStyle("-fx-alignment: CENTER-RIGHT;");
            prodInPriceCol.setStyle("-fx-alignment: CENTER-RIGHT;");
            removeProdInCol.setStyle("-fx-alignment: CENTER;");
            removeProdInCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            removeProdInCol.setCellFactory(param -> new TableCell<Product, Product>() {
                private final Button removeButton = new Button("");

                @Override
                protected void updateItem(Product pro, boolean empty) {
                    super.updateItem(pro, empty);

                    if (pro == null) {
                        setGraphic(null);
                        return;
                    } else {
                        removeButton.setPrefHeight(35);
                        removeButton.setPrefWidth(80);
                        File file = new File("images/icons/323232/Cancel.png");
                        removeButton
                                .setGraphic(new ImageView(new Image(file.toURI().toString(), 30, 30, false, true)));
                        removeButton.setStyle("-fx-background-color: #F3F6F7;");
                        setGraphic(removeButton);
                        removeButton.setOnAction((ActionEvent event) -> {
                            //// IF CAKE unesi u dataCakesOut, IF WEDDING CAKE u dataWeddCakesOut...
                            RootController.dataBillProducts.remove(pro);
                            RootController.sumOfProductsIn -= pro.getTempQuantity() * pro.getTempPrice();
                            if (RootController.sumOfProductsIn == 0) {
                                productsInBillSumLabel.setText("0.00");
                            } else {
                                DecimalFormat f = new DecimalFormat("##.00");
                                productsInBillSumLabel.setText(f.format(RootController.sumOfProductsIn));
                            }
                        });

                    }

                }

            });
            prodInNameCol.setMaxWidth(1f * Integer.MAX_VALUE * 40);
            prodInQuantyCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            prodInPriceCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            removeProdInCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            prodInNameCol.setCellValueFactory(new PropertyValueFactory<Product, String>("formatName"));
            prodInQuantyCol.setCellValueFactory(new PropertyValueFactory<Product, Double>("tempQuantity"));
            prodInPriceCol.setCellValueFactory(new PropertyValueFactory<>("tempPrice"));
            productsInTableView.setItems(RootController.dataBillProducts);
            productsInTableView.getColumns().addAll(prodInNameCol, prodInQuantyCol, prodInPriceCol,
                    removeProdInCol);
            ///////////////////////////////////////////////////////////////////

            //////////////////// PRODUCTS OUT TABLE VIEW //////////////////////
            productsOutTableView.setEditable(true);
            productsOutTableView.setPlaceholder(new Label(""));
            productsOutTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            TableColumn prodOutNameCol = new TableColumn("Proizvod");
            prodOutNameCol.setStyle("-fx-alignment: CENTER-LEFT;");
            TableColumn prodQuantyCol = new TableColumn("Kolicina");
            prodQuantyCol.setStyle("-fx-alignment: CENTER-RIGHT;");
            TableColumn prodPriceCol = new TableColumn("Cijena");
            prodPriceCol.setStyle("-fx-alignment: CENTER-RIGHT;");
            TableColumn<Product, Product> removeProdOutCol = new TableColumn<>("Obrisi");
            removeProdOutCol.setStyle("-fx-alignment: CENTER;");
            prodOutNameCol.setMaxWidth(1f * Integer.MAX_VALUE * 40);
            prodQuantyCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            prodPriceCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            removeProdOutCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            removeProdOutCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            removeProdOutCol.setCellFactory(param -> new TableCell<Product, Product>() {
                private final Button removeButton = new Button("");

                @Override
                protected void updateItem(Product pro, boolean empty) {
                    super.updateItem(pro, empty);

                    if (pro == null) {
                        setGraphic(null);
                        return;
                    } else {
                        removeButton.setPrefHeight(35);
                        removeButton.setPrefWidth(80);
                        File file = new File("icons/brisanjeSaracuna.png");
                        removeButton
                                .setGraphic(new ImageView(new Image(file.toURI().toString(), 30, 30, false, true)));
                        removeButton.setStyle(
                                "-fx-background-color: #CFD8DC; -fx-border-width: 1px; -fx-border-color: #455A64");
                        setGraphic(removeButton);
                        removeButton.setOnAction((ActionEvent event) -> {
                            //// IF CAKE unesi u dataCakesOut, IF WEDDING CAKE u dataWeddCakesOut...

                            if (pro.getSelector().equals("torta")) {
                                boolean isInTable = false;
                                for (Product test : dataCakesOut) {
                                    if (test.equals(pro)) {
                                        isInTable = true;
                                        double q = pro.getTempQuantity() + test.getTempQuantity();
                                        test.setTempQuantity(q);
                                        ObservableList<Product> tempList = FXCollections
                                                .observableArrayList(dataCakesOut);
                                        dataCakesOut.removeAll(dataCakesOut);
                                        for (Product tmp : tempList) {
                                            dataCakesOut.add(tmp);
                                        }
                                        break;
                                    }
                                }

                                if (!isInTable) {
                                    dataCakesOut.add(pro);
                                }

                                dataProductsOut.remove(pro);
                            } else if (pro.getSelector().equals("svadbena")) {
                                boolean isInTable = false;
                                for (WeddingCakeProductsOut test : dataWeddCakesOut) {
                                    if (test.equals(pro)) {
                                        isInTable = true;
                                        double q = pro.getTempQuantity() + Double.parseDouble(test.getQuantity());
                                        test.setQuantity(Double.toString(q));
                                        ObservableList<WeddingCakeProductsOut> tempList = FXCollections
                                                .observableArrayList(dataWeddCakesOut);
                                        dataWeddCakesOut.removeAll(dataWeddCakesOut);
                                        for (WeddingCakeProductsOut tmp : tempList) {
                                            dataWeddCakesOut.add(tmp);
                                        }
                                        break;
                                    }
                                }

                                if (!isInTable) {
                                    ProductMySQL pmsql = new ProductMySQL();
                                    ArrayList<Product> storeProducts = pmsql.getStoreHouse();
                                    dataWeddCakesOut.clear();
                                    for (Product tempP : storeProducts) {
                                        if (tempP.getSelector().equals("svadbena")) {
                                            WeddingCakeProductsOut wc = new WeddingCakeProductsOut();
                                            wc.setWeddingInfo(tempP);
                                            dataWeddCakesOut.add(wc);
                                            String[] info = tempP.getMoreFloorInfo().split("#");
                                            for (String str : info) {
                                                String find = str.split(",")[1];
                                                for (Product p : RootController.allProducts) {
                                                    if (p.getId() == Integer.parseInt(find)) {
                                                        WeddingCakeProductsOut temp = new WeddingCakeProductsOut();
                                                        temp.setCakeInfo(p);
                                                        dataWeddCakesOut.add(temp);
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                dataProductsOut.remove(pro);

                            }
                            setProductsOutSumLabel();
                        });

                    }

                }

            });

            prodOutNameCol.setCellValueFactory(new PropertyValueFactory<Product, String>("formatName"));
            prodQuantyCol.setCellValueFactory(new PropertyValueFactory<Product, Double>("tempQuantity"));
            prodPriceCol.setCellValueFactory(new PropertyValueFactory<Product, Double>("tempPrice"));
            productsOutTableView.setItems(dataProductsOut);
            productsOutTableView.getColumns().addAll(prodOutNameCol, prodQuantyCol, prodPriceCol, removeProdOutCol);

            ////////////////////// PRODUCTS OUT CAKE TABLE VIEW ////////////////
            productsOutCakeTableView.setEditable(true);
            productsOutCakeTableView.setPlaceholder(new Label(""));
            productsOutCakeTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            TableColumn prodOutShapeCol = new TableColumn("Oblik");
            prodOutShapeCol.getStyleClass().add("table-column-left");
            TableColumn prodOutTypeCol = new TableColumn("Vrsta");
            prodOutTypeCol.getStyleClass().add("table-column-left");
            TableColumn prodOutSizeCol = new TableColumn("Velicina");
            prodOutSizeCol.getStyleClass().add("table-column-left");
            TableColumn prodOutGlazeCol = new TableColumn("Glazura");
            prodOutGlazeCol.getStyleClass().add("table-column-left");
            TableColumn prodOutPictureCol = new TableColumn("Slika");
            prodOutPictureCol.getStyleClass().add("table-column-left");
            TableColumn prodOutQuantityCol = new TableColumn("Kolicina");
            prodOutQuantityCol.getStyleClass().add("table-column-right");
            TableColumn<Product, Product> addToBillCol = new TableColumn<>("Dodaj");
            prodOutShapeCol.setMaxWidth(1f * Integer.MAX_VALUE * 22);
            prodOutTypeCol.setMaxWidth(1f * Integer.MAX_VALUE * 22);
            prodOutSizeCol.setMaxWidth(1f * Integer.MAX_VALUE * 15);
            prodOutGlazeCol.setMaxWidth(1f * Integer.MAX_VALUE * 15);
            prodOutPictureCol.setMaxWidth(1f * Integer.MAX_VALUE * 10);
            prodOutQuantityCol.setMaxWidth(1f * Integer.MAX_VALUE * 6);
            addToBillCol.setMaxWidth(1f * Integer.MAX_VALUE * 10);
            addToBillCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            addToBillCol.setCellFactory(param -> new TableCell<Product, Product>() {
                private final Button addButton = new Button("");

                @Override
                protected void updateItem(Product pro, boolean empty) {
                    super.updateItem(pro, empty);

                    if (pro == null) {
                        setGraphic(null);
                        return;
                    } else {
                        addButton.setPrefHeight(35);
                        addButton.setPrefWidth(80);
                        File file = new File("icons/dodaj.png");
                        addButton
                                .setGraphic(new ImageView(new Image(file.toURI().toString(), 30, 30, false, true)));
                        addButton.setStyle(
                                "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                        setGraphic(addButton);
                        addButton.setOnAction((ActionEvent event) -> {

                            pro.createFormatName();
                            if (pro.getTempQuantity() == 1) {
                                dataCakesOut.remove(pro);
                            } else if (pro.getTempQuantity() > 1) {
                                double quant = pro.getTempQuantity() - 1;
                                pro.setTempQuantity(quant);
                                ObservableList<Product> tempList = FXCollections.observableArrayList(dataCakesOut);
                                dataCakesOut.removeAll(dataCakesOut);
                                for (Product tmp : tempList) {
                                    dataCakesOut.add(tmp);
                                }

                            }

                            boolean isInTable = false;
                            for (Product pTemp : dataProductsOut) {
                                if (pTemp.equals(pro)) {
                                    isInTable = true;
                                    double qTemp = pTemp.getTempQuantity() + 1;
                                    pTemp.setTempQuantity(qTemp);
                                    ObservableList<Product> prods = FXCollections
                                            .observableArrayList(dataProductsOut);
                                    dataProductsOut.removeAll(dataProductsOut);
                                    for (Product tp : prods) {
                                        dataProductsOut.add(tp);
                                    }
                                    break;
                                }
                            }

                            if (!isInTable) {
                                Product p = new Product();
                                p.setFullInfo(pro);
                                p.setTempQuantity(1);
                                p.createFormatName();
                                p.setTempPrice(getProductPrice(p));
                                dataProductsOut.add(p);
                            }

                            setProductsOutSumLabel();
                            for (Product tempor : dataProductsOut) {
                            }
                        });

                    }

                }

            });
            prodOutShapeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("shape"));
            prodOutTypeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("type"));
            prodOutSizeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("size"));
            prodOutGlazeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("glaze"));
            prodOutPictureCol.setCellValueFactory(new PropertyValueFactory<Product, Boolean>("picture"));
            prodOutQuantityCol.setCellValueFactory(new PropertyValueFactory<Product, Double>("tempQuantity"));
            productsOutCakeTableView.setItems(dataCakesOut);
            productsOutCakeTableView.getColumns().addAll(prodOutShapeCol, prodOutTypeCol, prodOutSizeCol,
                    prodOutGlazeCol, prodOutPictureCol, prodOutQuantityCol, addToBillCol);

            /////////////// PRODUCTS OUT WEDDING CAKE TABLE VIEW ///////////////
            productsOutWeddingCakeTableView.setEditable(true);
            productsOutWeddingCakeTableView.setPlaceholder(new Label(""));
            productsOutWeddingCakeTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            TableColumn prodOutWeddSelectorCol = new TableColumn("Selektor");
            TableColumn prodOutWeddFloorsCol = new TableColumn("BrojSpratova");
            TableColumn prodOutWeddShapeCol = new TableColumn("Oblik");
            TableColumn prodOutWeddTypeCol = new TableColumn("Vrsta");
            TableColumn prodOutWeddSizeCol = new TableColumn("Velicina");
            TableColumn prodOutWeddQuantityCol = new TableColumn("Kolicina");
            prodOutWeddSelectorCol.setStyle("-fx-alignment: CENTER-LEFT;");
            prodOutWeddFloorsCol.setStyle("-fx-alignment: CENTER;");
            prodOutWeddShapeCol.setStyle("-fx-alignment: CENTER-LEFT;");
            prodOutWeddTypeCol.setStyle("-fx-alignment: CENTER-LEFT;");
            prodOutWeddSizeCol.setStyle("-fx-alignment: CENTER-LEFT;");
            prodOutWeddQuantityCol.setStyle("-fx-alignment: CENTER-RIGHT;");
            TableColumn<WeddingCakeProductsOut, WeddingCakeProductsOut> addToBillWeddCol = new TableColumn<>("");
            prodOutWeddSelectorCol.setMaxWidth(1f * Integer.MAX_VALUE * 17);
            prodOutWeddFloorsCol.setMaxWidth(1f * Integer.MAX_VALUE * 7);
            prodOutWeddShapeCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            prodOutWeddTypeCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            prodOutWeddSizeCol.setMaxWidth(1f * Integer.MAX_VALUE * 16);
            prodOutWeddQuantityCol.setMaxWidth(1f * Integer.MAX_VALUE * 10);
            addToBillWeddCol.setMaxWidth(1f * Integer.MAX_VALUE * 10);
            addToBillWeddCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            addToBillWeddCol
                    .setCellFactory(param -> new TableCell<WeddingCakeProductsOut, WeddingCakeProductsOut>() {
                        private final Button addButton = new Button("");

                        @Override
                        protected void updateItem(WeddingCakeProductsOut pro, boolean empty) {
                            if (pro != null && pro.getSelector() != null && pro.getSelector().equals("svadbena")) {
                                super.updateItem(pro, empty);

                                if (pro == null) {
                                    setGraphic(null);
                                    return;
                                } else {
                                    addButton.setPrefHeight(35);
                                    addButton.setPrefWidth(80);
                                    File file = new File("icons/dodaj.png");
                                    addButton.setGraphic(
                                            new ImageView(new Image(file.toURI().toString(), 30, 30, false, true)));
                                    addButton.setStyle(
                                            "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                                    setGraphic(addButton);
                                    TableRow row = this.getTableRow();
                                    row.setStyle(
                                            "-fx-background-color: #C0C9CD; -fx-table-cell-border-color: #C0C9CD;");
                                    addButton.setOnAction((ActionEvent event) -> {
                                        Product currPro = pro.getProductFromWeddingCake();
                                        int num = currPro.getMoreFloorInfo().split("#").length;
                                        currPro.setFloorNumber(num);
                                        currPro.setFormatName("svadbena, " + num + " spratova");

                                        if (currPro.getTempQuantity() == 1) {
                                            int index = dataWeddCakesOut.indexOf(pro);
                                            int cnt = num;
                                            while (cnt >= 0) {
                                                dataWeddCakesOut.remove(index + cnt);
                                                --cnt;
                                            }

                                        } else if (currPro.getTempQuantity() > 1) {
                                            double q = currPro.getTempQuantity() - 1;
                                            currPro.setTempQuantity(q);
                                            for (WeddingCakeProductsOut w : dataWeddCakesOut) {
                                                if (w.getSelector() != null && w.getMoreFloorInfo()
                                                        .equals(currPro.getMoreFloorInfo())) {
                                                    w.setQuantity(Double.toString(currPro.getTempQuantity()));
                                                    break;
                                                }
                                            }
                                            ObservableList<WeddingCakeProductsOut> tempList = FXCollections
                                                    .observableArrayList(dataWeddCakesOut);
                                            dataWeddCakesOut.removeAll(dataWeddCakesOut);
                                            for (WeddingCakeProductsOut tmp : tempList) {
                                                dataWeddCakesOut.add(tmp);
                                            }
                                        }

                                        boolean isInTable = false;
                                        for (Product test : dataProductsOut) {
                                            if (test.getSelector().equals("svadbena")) {
                                                if (test.getMoreFloorInfo().equals(currPro.getMoreFloorInfo())) {
                                                    double q = test.getTempQuantity() + 1;
                                                    test.setTempQuantity(q);
                                                    ObservableList<Product> tempList = FXCollections
                                                            .observableArrayList(dataProductsOut);
                                                    dataProductsOut.removeAll(dataProductsOut);
                                                    for (Product p : tempList) {
                                                        dataProductsOut.add(p);
                                                    }
                                                    isInTable = true;
                                                    break;
                                                }
                                            }
                                        }

                                        if (!isInTable) {
                                            Product p = new Product();
                                            p.setFullInfo(currPro);
                                            p.setTempPrice(getProductPrice(p));
                                            p.setTempQuantity(1);
                                            p.setFormatName("svadbena, " + currPro.getFloorNumber() + " spratova");
                                            dataProductsOut.add(p);
                                        }

                                        setProductsOutSumLabel();
                                    });

                                }
                            } else {
                                setGraphic(null);
                                TableRow row = this.getTableRow();
                                row.setStyle("");
                            }

                        }

                    });
            prodOutWeddSelectorCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("selector"));
            prodOutWeddFloorsCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("numOfFloors"));
            prodOutWeddQuantityCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("quantity"));
            prodOutWeddShapeCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("shape"));
            prodOutWeddTypeCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("type"));
            prodOutWeddSizeCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("size"));
            productsOutWeddingCakeTableView.setItems(dataWeddCakesOut);
            productsOutWeddingCakeTableView.getColumns().addAll(prodOutWeddSelectorCol, prodOutWeddFloorsCol,
                    prodOutWeddQuantityCol, prodOutWeddShapeCol, prodOutWeddTypeCol, prodOutWeddSizeCol,
                    addToBillWeddCol);

            /////////////////////// WORK ORDER TABLE VIEW //////////////////////
            workOrdersTableView.setEditable(true);
            workOrdersTableView.setPlaceholder(new Label(""));
            workOrdersTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            TableColumn workOrderNumber = new TableColumn("Broj naloga");
            TableColumn workOrderDate = new TableColumn("Datum");
            TableColumn<WorkOrder, WorkOrder> viewWorkOrderCol = new TableColumn<>("Prikazi");
            workOrderNumber.setStyle("-fx-alignment: CENTER;");
            workOrderDate.setStyle("-fx-alignment: CENTER;");
            viewWorkOrderCol.setStyle("-fx-alignment: CENTER;");
            viewWorkOrderCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            viewWorkOrderCol.setCellFactory(param -> new TableCell<WorkOrder, WorkOrder>() {
                private final Button viewButton = new Button("");

                @Override
                protected void updateItem(WorkOrder wo, boolean empty) {
                    super.updateItem(wo, empty);

                    if (wo == null) {
                        setGraphic(null);
                        return;
                    } else {
                        viewButton.setPrefHeight(35);
                        viewButton.setPrefWidth(80);
                        File ff = new File("icons/view.png");
                        viewButton.setGraphic(new ImageView(new Image(ff.toURI().toString(), 30, 30, false, true)));
                        viewButton.setStyle(
                                "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                        setGraphic(viewButton);
                        viewButton.setOnAction((ActionEvent event) -> {

                            String woNum = wo.getFormatNumber();
                            String text = woNum.split("/")[0] + "_" + woNum.split("/")[1];

                            File f = new File("pdf_docs" + File.separator + "work_orders_picture" + File.separator
                                    + "work_order_" + text + ".png");
                            workOrderImageView.setImage(new Image(f.toURI().toString(), 1000, 707, true, true));
                        });

                    }

                }

            });

            TableColumn<WorkOrder, WorkOrder> printWorkOrderCol = new TableColumn<>("Stampaj");
            printWorkOrderCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            printWorkOrderCol.setCellFactory(param -> new TableCell<WorkOrder, WorkOrder>() {
                private final Button printButton = new Button("");

                @Override
                protected void updateItem(WorkOrder wo, boolean empty) {
                    super.updateItem(wo, empty);

                    if (wo == null) {
                        setGraphic(null);
                        return;
                    } else {
                        printButton.setPrefHeight(35);
                        printButton.setPrefWidth(80);
                        File f = new File("icons/Printer.png");
                        printButton.setGraphic(new ImageView(new Image(f.toURI().toString(), 30, 30, false, true)));
                        printButton.setStyle(
                                "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                        setGraphic(printButton);
                        printButton.setOnAction((ActionEvent event) -> {

                            String woNum = wo.getFormatNumber();
                            String text = woNum.split("/")[0] + "_" + woNum.split("/")[1];

                            try {
                                File file = new File("pdf_docs" + File.separator + "work_orders" + File.separator
                                        + "work_order_" + text + ".pdf");
                                printPDFDocument(file);
                            } catch (Exception ex) {
                                Logger.getLogger(MainFormController.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        });

                    }

                }

            });
            workOrderNumber.setCellValueFactory(new PropertyValueFactory<WorkOrder, String>("formatNumber"));
            workOrderDate.setCellValueFactory(new PropertyValueFactory<WorkOrder, String>("formatDate"));

            workOrderNumber.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            workOrderDate.setMaxWidth(1f * Integer.MAX_VALUE * 30);
            viewWorkOrderCol.setMaxWidth(1f * Integer.MAX_VALUE * 27);
            printWorkOrderCol.setMaxWidth(1f * Integer.MAX_VALUE * 27);

            workOrdersTableView.setItems(dataWorkOrders);
            workOrdersTableView.getColumns().addAll(workOrderNumber, workOrderDate, viewWorkOrderCol,
                    printWorkOrderCol);

            ////////////////////// NORMS CAKE TABLE VIEW ////////////////
            normsCakeTableView.setEditable(true);
            normsCakeTableView.setPlaceholder(new Label(""));
            normsCakeTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            TableColumn normCakeShapeCol = new TableColumn("Oblik");
            TableColumn normCakeTypeCol = new TableColumn("Vrsta");
            TableColumn normCakeSizeCol = new TableColumn("Velicina");
            TableColumn normCakeGlazeCol = new TableColumn("Glazura");
            TableColumn normCakePictureCol = new TableColumn("Slika");
            TableColumn<Product, Product> viewNormBillCol = new TableColumn<>("");
            TableColumn<Product, Product> printNormBillCol = new TableColumn<>("");
            normCakeGlazeCol.setMaxWidth(1f * Integer.MAX_VALUE * 13);
            normCakeSizeCol.setMaxWidth(1f * Integer.MAX_VALUE * 19);
            normCakeShapeCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            normCakeTypeCol.setMaxWidth(1f * Integer.MAX_VALUE * 20);
            normCakePictureCol.setMaxWidth(1f * Integer.MAX_VALUE * 8);
            viewNormBillCol.setMaxWidth(1f * Integer.MAX_VALUE * 10);
            printNormBillCol.setMaxWidth(1f * Integer.MAX_VALUE * 10);
            viewNormBillCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            viewNormBillCol.setCellFactory(param -> new TableCell<Product, Product>() {
                private final Button viewNorm = new Button("");

                @Override
                protected void updateItem(Product pro, boolean empty) {
                    super.updateItem(pro, empty);

                    if (pro == null) {
                        setGraphic(null);
                        return;
                    } else {
                        viewNorm.setPrefHeight(35);
                        viewNorm.setPrefWidth(80);
                        File f = new File("icons/view.png");
                        viewNorm.setGraphic(new ImageView(new Image(f.toURI().toString(), 30, 30, false, true)));
                        viewNorm.setStyle(
                                "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                        setGraphic(viewNorm);
                        viewNorm.setOnAction((ActionEvent event) -> {
                            normSideVBox.getChildren().clear();

                            NormMySQL normMySQL = new NormMySQL();
                            Norm norm = normMySQL.getNormForProduct(pro.getId());
                            for (Supply s : norm.getNormSupplies()) {
                                for (Supply ss : RootController.allSupplies) {
                                    if (s.getId() == ss.getId()) {
                                        s.setName(ss.getName());
                                        s.setMeasureUnit(ss.getMeasureUnit());
                                        s.setCurrentPrice(ss.getCurrentPrice());

                                    }
                                }
                            }
                            int count = 0;
                            for (Supply s : norm.getNormSupplies()) {
                                GridPane grid = new GridPane();
                                if (count == 0) {
                                    Label sastav = new Label("Normativ:");
                                    sastav.setStyle("-fx-font-size: 16pt; -fx-text-fill: #111111; "
                                            + "-fx-font-weight: bold;" + " -fx-margin: 0 0 5px 0;");
                                    grid.addRow(count, sastav);
                                    count++;
                                }
                                Label lab1 = new Label(s.getName());
                                Label lab2 = new Label(s.getMeasureUnit());
                                Label lab3 = new Label(Double.toString(s.getTempQuantity()));
                                lab1.setStyle("-fx-font-size: 14pt; -fx-text-fill: #111111;");
                                lab2.setStyle("-fx-font-size: 14pt; -fx-text-fill: #111111;");
                                lab3.setStyle("-fx-font-size: 14pt; -fx-text-fill: #111111;");
                                grid.addRow(count, lab1, lab2, lab3);
                                /*grid.add(lab1, 0, 1);
                                grid.add(lab2, 1, 1);
                                grid.add(lab3, 3, 1);*/
                                grid.getColumnConstraints().add(new ColumnConstraints(250));

                                grid.setHgap(20);
                                if (count % 2 == 0) {
                                    grid.setStyle("-fx-background-color: #CFD8DC;");
                                } else {
                                    grid.setStyle("-fx-background-color: #C0C9CD;");
                                }
                                ColumnConstraints cc = new ColumnConstraints();
                                cc.setFillWidth(true);
                                cc.setHgrow(Priority.ALWAYS);
                                grid.getColumnConstraints().add(cc);

                                RowConstraints rc = new RowConstraints();
                                rc.setFillHeight(true);
                                rc.setVgrow(Priority.ALWAYS);
                                grid.getRowConstraints().add(rc);

                                normSideVBox.getChildren().add(grid);
                                count++;
                            }
                            normSideVBox.setVisible(true);
                        });

                    }

                }

            });

            printNormBillCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            printNormBillCol.setCellFactory(param -> new TableCell<Product, Product>() {
                private final Button printNorm = new Button("");

                @Override
                protected void updateItem(Product pro, boolean empty) {
                    super.updateItem(pro, empty);

                    if (pro == null) {
                        setGraphic(null);
                        return;
                    } else {
                        printNorm.setPrefHeight(35);
                        printNorm.setPrefWidth(80);
                        File f = new File("icons/Printer.png");
                        printNorm.setGraphic(new ImageView(new Image(f.toURI().toString(), 30, 30, false, true)));
                        printNorm.setStyle(
                                "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                        setGraphic(printNorm);
                        printNorm.setOnAction((ActionEvent event) -> {
                            ArrayList<Product> temp = new ArrayList<>();
                            temp.add(pro);
                            ProductMySQL sql = new ProductMySQL();
                            ArrayList<Supply> supplies = sql.getNormForProducts(temp);
                            String path = "";
                            try {
                                NormativPDF pdf = new NormativPDF(pro, supplies, new Date());
                                path = pdf.createNormativ();
                            } catch (IOException ex) {
                                Logger.getLogger(MainFormController.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            File file = new File(path);
                            try {
                                printPDFDocument(file);
                            } catch (Exception ex) {
                                Logger.getLogger(MainFormController.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        });

                    }

                }

            });
            normCakeShapeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("shape"));
            normCakeTypeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("type"));
            normCakeSizeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("size"));
            normCakeGlazeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("glaze"));
            normCakePictureCol.setCellValueFactory(new PropertyValueFactory<Product, Boolean>("picture"));
            normsCakeTableView.setItems(dataNormsCakes);
            normsCakeTableView.getColumns().addAll(normCakeShapeCol, normCakeTypeCol, normCakeSizeCol,
                    normCakeGlazeCol, normCakePictureCol, viewNormBillCol, printNormBillCol);

            /////////////// NORMS WEDDING CAKE TABLE VIEW ///////////////
            normsWeddingCakeTableView.setEditable(true);
            normsWeddingCakeTableView.setPlaceholder(new Label(""));
            normsWeddingCakeTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            TableColumn normsWeddSelectorCol = new TableColumn("Selektor");
            TableColumn normsWeddFloorsCol = new TableColumn("BrojSpratova");
            TableColumn normsWeddShapeCol = new TableColumn("Oblik");
            TableColumn normsWeddTypeCol = new TableColumn("Vrsta");
            TableColumn normsWeddSizeCol = new TableColumn("Velicina");
            TableColumn normsWeddQuantityCol = new TableColumn("Kolicina");
            TableColumn<WeddingCakeProductsOut, WeddingCakeProductsOut> previewWeddNormCol = new TableColumn<>("");
            TableColumn<WeddingCakeProductsOut, WeddingCakeProductsOut> printWeddNormCol = new TableColumn<>("");
            normsWeddSelectorCol.setMaxWidth(1f * Integer.MAX_VALUE * 17);
            normsWeddFloorsCol.setMaxWidth(1f * Integer.MAX_VALUE * 7);
            normsWeddShapeCol.setMaxWidth(1f * Integer.MAX_VALUE * 18);
            normsWeddTypeCol.setMaxWidth(1f * Integer.MAX_VALUE * 18);
            normsWeddSizeCol.setMaxWidth(1f * Integer.MAX_VALUE * 16);
            normsWeddQuantityCol.setMaxWidth(1f * Integer.MAX_VALUE * 10);
            previewWeddNormCol.setMaxWidth(1f * Integer.MAX_VALUE * 7);
            printWeddNormCol.setMaxWidth(1f * Integer.MAX_VALUE * 7);
            previewWeddNormCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            previewWeddNormCol
                    .setCellFactory(param -> new TableCell<WeddingCakeProductsOut, WeddingCakeProductsOut>() {
                        private final Button viewNorm = new Button("Pogledaj");

                        @Override
                        protected void updateItem(WeddingCakeProductsOut pro, boolean empty) {
                            super.updateItem(pro, empty);

                            if (pro != null && pro.getSelector() != null && pro.getSelector().equals("svadbena")) {

                                if (pro == null) {
                                    setGraphic(null);
                                    return;
                                } else {
                                    viewNorm.setPrefHeight(35);
                                    viewNorm.setPrefWidth(80);
                                    File file = new File("icons/view.png");
                                    viewNorm.setGraphic(
                                            new ImageView(new Image(file.toURI().toString(), 30, 30, false, true)));
                                    viewNorm.setStyle(
                                            "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                                    setGraphic(viewNorm);
                                    TableRow row = this.getTableRow();
                                    row.setStyle(
                                            "-fx-background-color: #C0C9CD; -fx-table-cell-border-color: #C0C9CD;");
                                    viewNorm.setOnAction((ActionEvent event) -> {
                                        normSideVBox.getChildren().clear();
                                        System.out.println("ID: " + pro.getId());

                                        NormMySQL normMySQL = new NormMySQL();
                                        Norm norm = normMySQL.getNormForProduct(pro.getId());
                                        for (Supply s : norm.getNormSupplies()) {
                                            for (Supply ss : RootController.allSupplies) {
                                                if (s.getId() == ss.getId()) {
                                                    s.setName(ss.getName());
                                                    s.setMeasureUnit(ss.getMeasureUnit());
                                                    s.setCurrentPrice(ss.getCurrentPrice());

                                                }
                                            }
                                        }
                                        int count = 0;
                                        for (Supply s : norm.getNormSupplies()) {
                                            GridPane grid = new GridPane();
                                            if (count == 0) {
                                                Label sastav = new Label("Normativ:");
                                                sastav.setStyle("-fx-font-size: 16pt; -fx-text-fill: #111111; "
                                                        + "-fx-font-weight: bold;" + " -fx-margin: 0 0 5px 0;");
                                                grid.addRow(count, sastav);
                                                count++;
                                            }
                                            Label lab1 = new Label(s.getName());
                                            Label lab2 = new Label(s.getMeasureUnit());
                                            Label lab3 = new Label(Double.toString(s.getTempQuantity()));
                                            lab1.setStyle("-fx-font-size: 14pt; -fx-text-fill: #111111;");
                                            lab2.setStyle("-fx-font-size: 14pt; -fx-text-fill: #111111;");
                                            lab3.setStyle("-fx-font-size: 14pt; -fx-text-fill: #111111;");
                                            grid.addRow(count, lab1, lab2, lab3);
                                            /*grid.add(lab1, 0, 1);
                                            grid.add(lab2, 1, 1);
                                            grid.add(lab3, 3, 1);*/
                                            grid.getColumnConstraints().add(new ColumnConstraints(250));

                                            grid.setHgap(20);
                                            if (count % 2 == 0) {
                                                grid.setStyle("-fx-background-color: #CFD8DC;");
                                            } else {
                                                grid.setStyle("-fx-background-color: #C0C9CD;");
                                            }
                                            ColumnConstraints cc = new ColumnConstraints();
                                            cc.setFillWidth(true);
                                            cc.setHgrow(Priority.ALWAYS);
                                            grid.getColumnConstraints().add(cc);

                                            RowConstraints rc = new RowConstraints();
                                            rc.setFillHeight(true);
                                            rc.setVgrow(Priority.ALWAYS);
                                            grid.getRowConstraints().add(rc);

                                            normSideVBox.getChildren().add(grid);
                                            count++;
                                        }
                                        normSideVBox.setVisible(true);
                                    });

                                }

                            } else {
                                setGraphic(null);
                                TableRow row = this.getTableRow();
                                row.setStyle("");

                            }
                        }

                    });

            printWeddNormCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue()));
            printWeddNormCol
                    .setCellFactory(param -> new TableCell<WeddingCakeProductsOut, WeddingCakeProductsOut>() {
                        private final Button printNorm = new Button("Print");

                        @Override
                        protected void updateItem(WeddingCakeProductsOut pro, boolean empty) {
                            super.updateItem(pro, empty);

                            if (pro != null && pro.getSelector() != null && pro.getSelector().equals("svadbena")) {

                                if (pro == null) {
                                    setGraphic(null);
                                    return;
                                } else {
                                    printNorm.setPrefHeight(35);
                                    printNorm.setPrefWidth(80);
                                    File f = new File("icons/Printer.png");
                                    printNorm.setGraphic(
                                            new ImageView(new Image(f.toURI().toString(), 30, 30, false, true)));
                                    printNorm.setStyle(
                                            "-fx-background-color: #303E45; -fx-border-width: 1px; -fx-border-color: #CFD8DC");
                                    setGraphic(printNorm);
                                    printNorm.setOnAction((ActionEvent event) -> {
                                        ArrayList<WeddingCakeProductsOut> temp2 = new ArrayList<>();
                                        temp2.add(pro);
                                        ArrayList<Product> temp = new ArrayList<>();
                                        for (WeddingCakeProductsOut w : temp2) {
                                            temp.add(w.getProductFromWeddingCake());
                                        }
                                        ProductMySQL sql = new ProductMySQL();
                                        ArrayList<Supply> supplies = sql.getNormForProducts(temp);
                                        String path = "";
                                        Product pro2 = pro.getProductFromWeddingCake();
                                        try {
                                            NormativPDF pdf = new NormativPDF(pro2, supplies, new Date());
                                            path = pdf.createNormativ();
                                        } catch (IOException ex) {
                                            Logger.getLogger(MainFormController.class.getName()).log(Level.SEVERE,
                                                    null, ex);
                                        }
                                        File file = new File(path);
                                        try {
                                            printPDFDocument(file);
                                        } catch (Exception ex) {
                                            Logger.getLogger(MainFormController.class.getName()).log(Level.SEVERE,
                                                    null, ex);
                                        }
                                    });

                                }
                            } else {
                                setGraphic(null);
                                TableRow row = this.getTableRow();
                                row.setStyle("");

                            }
                        }

                    });
            normsWeddSelectorCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("selector"));
            normsWeddFloorsCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("numOfFloors"));
            normsWeddQuantityCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("quantity"));
            normsWeddShapeCol
                    .setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("shape"));
            normsWeddTypeCol.setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("type"));
            normsWeddSizeCol.setCellValueFactory(new PropertyValueFactory<WeddingCakeProductsOut, String>("size"));
            normsWeddingCakeTableView.setItems(dataWeddCakesOut);
            normsWeddingCakeTableView.getColumns().addAll(normsWeddSelectorCol, normsWeddFloorsCol,
                    normsWeddQuantityCol, normsWeddShapeCol, normsWeddTypeCol, normsWeddSizeCol, previewWeddNormCol,
                    printWeddNormCol);

        }

    }

    public void printPDFDocument(File file) throws Exception {
        PrinterJob job = PrinterJob.getPrinterJob();
        PageFormat pf = job.defaultPage();
        Paper paper = new Paper();
        //paper.setSize(8.5 * 72, 11 * 72);
        double margin = 20;
        paper.setImageableArea(0, 0, paper.getWidth() - margin, paper.getHeight() - margin);
        pf.setPaper(paper);
        pf.setOrientation(PageFormat.LANDSCAPE);
        // PDFBox
        PDDocument doc = PDDocument.load(file);
        Book book = new Book();
        book.append(new PDFPrintable(doc), pf);
        //job.setPageable(new PDFPageable(doc));
        job.setPageable(book);
        //Book b = new Book();

        //job.setJobName("Job");
        if (job.printDialog()) {
            job.print();
        }

        doc.close();
    }

    public class SupplyToTable {

        public String name;
        public double quanty;
        public double price;

        public SupplyToTable() {
        }

        public SupplyToTable(String name, double quanty, double price) {
            this.name = name;
            this.quanty = quanty;
            this.price = price;
        }

        public void setAllAtribute(SupplyToTable s) {
            this.name = s.name;
            this.quanty = s.quanty;
            this.price = s.price;
        }

        public String getName() {
            return this.name;
        }

        public double getQuanty() {
            return this.quanty;
        }

        public double getPrice() {
            return this.price;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setQuanty(double quanty) {
            this.quanty = quanty;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        @Override
        public String toString() {
            return this.name + " " + this.quanty + " " + this.price;
        }

    }

    public void deselectCakeToogleButtons() {
        ///// IF != NULL - baca exception ako nije kliknut
        if (cakeShapeToggleGroup.getSelectedToggle() != null) {
            cakeShapeToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (cakeGlazeToggleGroup.getSelectedToggle() != null) {
            cakeGlazeToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (cakePictureToggleGroup.getSelectedToggle() != null) {
            cakePictureToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (cakeSizeToggleGroup.getSelectedToggle() != null) {
            cakeSizeToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (cakeTypeToggleGroup.getSelectedToggle() != null) {
            cakeTypeToggleGroup.getSelectedToggle().setSelected(false);
        }
    }

    public void deselectWeddingToogleButtons() {
        ///// IF != NULL - baca exception ako nije kliknut
        if (weddingCakeGlazeToggleGroup.getSelectedToggle() != null) {
            weddingCakeGlazeToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (weddingCakePictureToggleGroup.getSelectedToggle() != null) {
            weddingCakePictureToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (weddingCakeShapeToggleGroup.getSelectedToggle() != null) {
            weddingCakeShapeToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (weddingCakeSizeToggleGroup.getSelectedToggle() != null) {
            weddingCakeSizeToggleGroup.getSelectedToggle().setSelected(false);
        }
        if (weddingCakeTypeToggleGroup.getSelectedToggle() != null) {
            weddingCakeTypeToggleGroup.getSelectedToggle().setSelected(false);
        }
        setFloorParameterButton.setDisable(true);
    }

    public void setVisibleWeddingFloors() {
        weddingCakeFloorsButton3.setDisable(false);
        weddingCakeFloorsButton4.setDisable(false);
        weddingCakeFloorsButton5.setDisable(false);
        weddingCakeFloorsButton6.setDisable(false);
        weddingCakeFloorsButton7.setDisable(false);
        setFloorParameterButton.setDisable(false);

    }

    public void setWeddingFloorsColorVisible() {
        weddingCakeFloorsVBox.setDisable(true);
        weddingCakeFloorDesVBox.setDisable(true);
        setFloorParameterButton.setDisable(true);
        //weddingCakeFloorToogleGroup.getSelectedToggle().setSelected(false);
        if (weddingCakeFloorToogleGroup.getSelectedToggle() != null) {
            weddingCakeFloorToogleGroup.getSelectedToggle().setSelected(false);
        }
        weddingCakeFloorsButton1.setStyle(null);
        weddingCakeFloorsButton2.setStyle(null);
        weddingCakeFloorsButton3.setStyle(null);
        weddingCakeFloorsButton4.setStyle(null);
        weddingCakeFloorsButton5.setStyle(null);
        weddingCakeFloorsButton6.setStyle(null);
        weddingCakeFloorsButton7.setStyle(null);
    }

}