<?php
/**
 * BidssController controls the actions for bids
 */
class BidsController{
    private $model;

    function __construct(){
        $this->model = new BidsModel();
    }

    /**
     * get bids for bids view
     * @return json list of bids
     */
    public function getBids(){
        $filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : '[]';
        echo json_encode($this->model->getBids($filter), JSON_NUMERIC_CHECK);
    }

    public function removeBid(){
        $idBid = isset($_REQUEST['idBid']) ? $_REQUEST['idBid'] : 0;
        echo json_encode($this->model->removeBid($idBid), JSON_NUMERIC_CHECK);
    }

    public function getClCustomers(){
        echo json_encode($this->model->getClCustomers(), JSON_NUMERIC_CHECK);
    }

    public function getPayTypes(){
        $idCommercialLead = isset($_REQUEST['idCommercialLead']) ? $_REQUEST['idCommercialLead'] : 0;
        $idCustomer = isset($_REQUEST['idCustomer']) ? $_REQUEST['idCustomer'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        echo json_encode($this->model->getPayTypes($idCommercialLead, $idCustomer, $idPackage), JSON_NUMERIC_CHECK);
    }

    public function getPackages(){
        $idCommercialLead = isset($_REQUEST['idCommercialLead']) ? $_REQUEST['idCommercialLead'] : 0;
        $idCustomer = isset($_REQUEST['idCustomer']) ? $_REQUEST['idCustomer'] : 0;
        echo json_encode($this->model->getPackages($idCommercialLead, $idCustomer), JSON_NUMERIC_CHECK);
    }

    public function getSuppliers(){
        echo json_encode($this->model->getSuppliers(), JSON_NUMERIC_CHECK);
    }

    public function getProducts(){
        $idSupplier = isset($_REQUEST['idSupplier']) ? $_REQUEST['idSupplier'] : 0;

        echo json_encode($this->model->getProducts($idSupplier), JSON_NUMERIC_CHECK);
    }

    public function addSupplierBid(){
        $supplierBid = isset($_REQUEST['supplierBid']) ? $_REQUEST['supplierBid'] : '[]';

        echo json_encode($this->model->addSupplierBid($supplierBid), JSON_NUMERIC_CHECK);
    }

    public function getUnlinkedSupplierBids() {
        echo json_encode($this->model->getUnlinkedSupplierBids(), JSON_NUMERIC_CHECK);
    }

    public function addBid(){
        $bid = isset($_REQUEST['bid']) ? $_REQUEST['bid'] : '[]';

        echo json_encode($this->model->addBid($bid), JSON_NUMERIC_CHECK);
    }

    public function addBidMargin() {
        $idBid = isset($_REQUEST['idBid']) ? $_REQUEST['idBid'] : 0;
        $bidMargin = isset($_REQUEST['bidMargin']) ? $_REQUEST['bidMargin'] : '[]';

        echo json_encode($this->model->addBidMargin($idBid, $bidMargin), JSON_NUMERIC_CHECK);
    }

    /**
     * include bids template
     */
    public function bidsViewTemplate(){
        global $user;
        require_once('templates/BidsViewTemplate.php');
    }

    /**
     * include bids add template
     */
    public function addBidTemplate(){
        require_once('templates/AddBidTemplate.php');
    }

    public function addBidMarginTemplate(){
        require_once('templates/AddBidMarginTemplate.php');
    }

    /**
     * include bids template
     */
    public function bidsTemplate(){
        global $user;
        require_once('templates/BidsTemplate.php');
    }

    public function showPage(){
        require_once('BidsPage.php');
    }
}
