<?php
/**
 * OrdersController controls the actions for orders
 */
class OrdersController{
    private $model;

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

    /**
     * returns json array with table headers for orders
     * @return list all columns headers
     */
    public function getOngoingOrdersHeaders(){
        echo json_encode($this->model->getOngoingOrdersHeaders('array'));
    }

    /**
     * returns json response for orders
     * @return list prders json
     */
    public function getOngoingOrders(){
        $data = ['data' => $this->model->getOngoingOrders()];
        echo json_encode($data);
    }

    /**
     * returns json array with table headers for orders history
     * @return list all columns headers
     */
    public function getOrdersHistoryHeaders(){
        echo json_encode($this->model->getOrdersHistoryHeaders('array'));
    }

    /**
     * returns json response for orders history
     * @return list prders json
     */
    public function getOrdersHistory(){
        $data = ['data' => $this->model->getOrdersHistory()];
        echo json_encode($data);
    }

    /**
     * gets the info for an order
     * @return [json] returns order info
     */
    public function getOrderInfo() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        echo json_encode($this->model->getOrderInfo($idOrder));
    }

    /**
     * returns json with steps for a specific order
     * @return array order steps
     */
    public function getOrderSteps() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        echo json_encode($this->model->getOrderSteps($idOrder));
    }

    /**
     * change step for orders
     * @return json result of the update
     */
    public function goToNextStep() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        $ordersDetailsMail = isset($_REQUEST['ordersDetailsMail']) ? $_REQUEST['ordersDetailsMail'] : '[]';
        echo json_encode($this->model->goToNextStep($idOrder, $idProcessStep, $ordersDetailsMail));
    }

    /**
     * undo step for orders
     * @return json result of the update
     */
    public function undoStep() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        echo json_encode($this->model->undoStep($idOrder, $idProcessStep));
    }

    /**
     * update the estimation for an order
     * @return json json message for update result
     */
    public function updateOrderEstimation() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $estimationDate = isset($_REQUEST['estimationDate']) ? $_REQUEST['estimationDate'] : '';
        echo json_encode($this->model->updateOrderEstimation($idOrder, $estimationDate));
    }

    /**
     * update the end of life date for a package and change order status if required
     * @return json message for update result
     */
    public function updatePackageEndOfLife(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $endOfLife = isset($_REQUEST['endOfLife']) ? $_REQUEST['endOfLife'] : '';
        $ordersDetailsMail = isset($_REQUEST['ordersDetailsMail']) ? $_REQUEST['ordersDetailsMail'] : '[]';
        echo json_encode($this->model->updatePackageEndOfLife($idOrder, $idPackage, $endOfLife, $ordersDetailsMail));
    }

    /**
     * update the estimation for an order step
     * @return json json message for update result
     */
    public function updateScheduledDates() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $idProcess = isset($_REQUEST['idProcess']) ? $_REQUEST['idProcess'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        $idSchedule = isset($_REQUEST['idSchedule']) ? $_REQUEST['idSchedule'] : 0;
        $newDate = isset($_REQUEST['newDate']) ? $_REQUEST['newDate'] : '';
        echo json_encode($this->model->updateScheduledDates($idOrder, $idPackage, $idProcess, $idProcessStep, $idSchedule, $newDate));
    }

    /**
     * update the status for an existing schedule date
     * @return json update message
     */
    public function updateScheduleDateStatus(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $actionCode = isset($_REQUEST['actionCode']) ? $_REQUEST['actionCode'] : '';
        $idSchedule = isset($_REQUEST['idSchedule']) ? $_REQUEST['idSchedule'] : 0;
        $status = isset($_REQUEST['status']) ? $_REQUEST['status'] : '';
        echo json_encode($this->model->updateScheduleDateStatus($idSchedule, $status, $idOrder, $idPackage, $actionCode));
    }

    /**
     * get scheduled dates for a step
     * @return json list of scheduled dates
     */
    public function getScheduledDates(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        echo json_encode($this->model->getScheduledDates($idOrder, $idPackage, $idProcessStep));
    }

    /**
     * update the actual date for an order step
     * @return json message for update result
     */
    public function updateStepActualDate() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        $actualDate = isset($_REQUEST['actualDate']) ? $_REQUEST['actualDate'] : '';
        $ordersDetailsMail = isset($_REQUEST['ordersDetailsMail']) ? $_REQUEST['ordersDetailsMail'] : '[]';
        echo json_encode($this->model->updateStepActualDate($idOrder, $idProcessStep, $actualDate, $ordersDetailsMail));
    }

    /**
     * update comment for an order
     * @return json update message
     */
    public function updateOrderComment() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $comment = isset($_REQUEST['comment']) ? $_REQUEST['comment'] : null;
        $ordersDetailsMail = isset($_REQUEST['ordersDetailsMail']) ? $_REQUEST['ordersDetailsMail'] : '[]';
        echo json_encode($this->model->updateOrderComment($idOrder, $comment, $ordersDetailsMail));
    }

    /**
     * update commnets for an order
     * @return json json message for update result
     */
    public function updateStepComment() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        $comment = isset($_REQUEST['comment']) ? $_REQUEST['comment'] : null;
        $isVisible = isset($_REQUEST['isVisible']) ? intval($_REQUEST['isVisible']) : 0;
        $ordersDetailsMail = isset($_REQUEST['ordersDetailsMail']) ? $_REQUEST['ordersDetailsMail'] : '[]';
        echo json_encode($this->model->updateStepComment($idOrder, $idProcessStep, $comment, $isVisible, $ordersDetailsMail));
    }

    /**
     * cancel one order
     * @return json json message for cancel result
     */
    public function cancelOrder() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $ordersDetailsMail = isset($_REQUEST['ordersDetailsMail']) ? $_REQUEST['ordersDetailsMail'] : '[]';
        echo json_encode($this->model->cancelOrder($idOrder, $ordersDetailsMail));
    }

    /**
     * set a selected process for an orders package
     * @return json update message
     */
    public function setProcessForOrder(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idProcess = isset($_REQUEST['idProcess']) ? $_REQUEST['idProcess'] : 0;
        $ordersDetailsMail = isset($_REQUEST['ordersDetailsMail']) ? $_REQUEST['ordersDetailsMail'] : '[]';
        echo json_encode($this->model->setProcessForOrder($idOrder, $idProcess, $ordersDetailsMail));
    }

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

    /**
     * update visibility for a comment
     * @return json update message
     */
    public function updateStepCommentVisibility(){
        $idComment = isset($_REQUEST['idComment']) ? $_REQUEST['idComment'] : 0;
        $isVisible = isset($_REQUEST['isVisible']) ? intval($_REQUEST['isVisible']) : 0;
        echo json_encode($this->model->updateStepCommentVisibility($idComment, $isVisible));
    }

    /**
     * gets the system allowed languages from the DB
     * @return json array with allowed languages in the system
     */
    public function getSystemAllowedLanguages() {
        echo json_encode($this->model->getSystemAllowedLanguages());
    }

    /**
     * get brokers list
     * @return json list of brokers
     */
    public function getBrokers(){
        echo json_encode($this->model->getBrokers());
    }

    /**
     * update status for packages and orders in case of end of life
     * @return text update message for statuses
     */
    public function updateOrdersEndOfLife(){
        echo $this->model->updateOrdersEndOfLife();
    }

    /**
     * genereate file for procurement report
     * @return file file for procurement report
     */
    public function generateProcurementExcel(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $this->model->generateProcurementExcel($idOrder);
    }

    /**
     * gets all thge installation companies for the order and package selected
     * @return Array with the installation companies
     */
    public function getInstallCompaniesForPackage() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        echo json_encode($this->model->getInstallCompaniesForPackage($idOrder, $idPackage));
    }

    /**
     * save installation company for order and package
     * @return Array with confirmation messages
     */
    public function saveInstallationCompany() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $idInstallation = isset($_REQUEST['idInstallation']) ? $_REQUEST['idInstallation'] : 0;
        echo json_encode($this->model->saveInstallationCompany($idOrder, $idPackage, $idInstallation));
    }

    /**
     * get customer questionnaires documents
     * @return json list of documents
     */
    public function getOrderDocumentsPerType(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $documentType = isset($_REQUEST['documentType']) ? $_REQUEST['documentType'] : '';
        echo json_encode($this->model->getOrderDocumentsPerType($idOrder, $idPackage, $documentType));
    }

    /**
     * update status for a questionnaire
     * @return json update message
     */
    public function validateQuestionaire(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $idDocument = isset($_REQUEST['idDocument']) ? $_REQUEST['idDocument'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        $validationStatus = isset($_REQUEST['validationStatus']) ? $_REQUEST['validationStatus'] : '';
        $invalidQuestionaireReason = isset($_REQUEST['invalidQuestionaireReason']) ? $_REQUEST['invalidQuestionaireReason'] : '';
        echo json_encode($this->model->validateQuestionaire($idOrder, $idPackage, $idDocument, $idProcessStep, $validationStatus, $invalidQuestionaireReason));
    }

    /**
     * upload againa questionnaire
     * @return json upload message
     */
    public function reUploadQuestionaire(){
        $file = isset($_FILES['file']) ? $_FILES['file'] : [];
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $idDocument = isset($_REQUEST['idDocument']) ? $_REQUEST['idDocument'] : 0;
        echo json_encode($this->model->reUploadQuestionaire($idOrder, $idPackage, $idDocument, $file));
    }

    /**
     * get estimation and confirmation dates for products
     * @return json list of dates for products in procurement step
     */
    public function getSupplierEstimations(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        echo json_encode($this->model->getSupplierEstimations($idOrder));
    }

    /**
     * update date values for products in an order (procurement step)
     * @return json update message
     */
    public function updateSupplierEstimation(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idSupplier = isset($_REQUEST['idSupplier']) ? $_REQUEST['idSupplier'] : 0;
        $estimatedDate = isset($_REQUEST['estimatedDate']) ? $_REQUEST['estimatedDate'] : '';
        $confirmedDate = isset($_REQUEST['confirmedDate']) ? $_REQUEST['confirmedDate'] : '';
        echo json_encode($this->model->updateSupplierEstimation($idOrder, $idSupplier, $estimatedDate, $confirmedDate));
    }

    /**
     * remove estimation or confirm date
     * @return json update message
     */
    public function removeSupplierEstimation(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idSupplier = isset($_REQUEST['idSupplier']) ? $_REQUEST['idSupplier'] : 0;
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
        echo json_encode($this->model->removeSupplierEstimation($idOrder, $idSupplier, $type));
    }

    /**
     * adds traking info
     * @return json update message
     */
    public function addTracking(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idSupplier = isset($_REQUEST['idSupplier']) ? $_REQUEST['idSupplier'] : 0;
        $trackingNumber = isset($_REQUEST['trackingNumber']) ? $_REQUEST['trackingNumber'] : '';
        $trackingUrl = isset($_REQUEST['trackingUrl']) ? $_REQUEST['trackingUrl'] : '';
        echo json_encode($this->model->addTracking($idOrder, $idSupplier, $trackingNumber, $trackingUrl));
    }

    /**
     * update traking id
     * @return json update message
     */
    public function updateTracking(){
        $idTracking = isset($_REQUEST['idTracking']) ? $_REQUEST['idTracking'] : 0;
        $trackingNumber = isset($_REQUEST['trackingNumber']) ? $_REQUEST['trackingNumber'] : '';
        $trackingUrl = isset($_REQUEST['trackingUrl']) ? $_REQUEST['trackingUrl'] : '';
        echo json_encode($this->model->updateTracking($idTracking, $trackingNumber, $trackingUrl));
    }

    /**
     * delete traking information
     * @return json update message
     */
    public function removeTracking() {
        $idTracking = isset($_REQUEST['idTracking']) ? $_REQUEST['idTracking'] : 0;
        echo json_encode($this->model->removeTracking($idTracking));
    }

    /**
     * upload required files for suppliers (configuration or installation)
     * @return json upload message
     */
    public function uploadConfigurationDocument(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $file = isset($_FILES['file']) ? $_FILES['file'] : [];
        $idSupplier = isset($_REQUEST['idSupplier']) ? $_REQUEST['idSupplier'] : 0;
        $fileType = isset($_REQUEST['fileType']) ? $_REQUEST['fileType'] : '';
        echo json_encode($this->model->uploadConfigurationDocument($idOrder, $idPackage, $idSupplier, $fileType, $file));
    }

    /**
     * upload required files for suppliers (configuration or installation)
     * @return json upload message
     */
    public function uploadInstallationDocument(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $file = isset($_FILES['file']) ? $_FILES['file'] : [];
        $idSupplier = isset($_REQUEST['idSupplier']) ? $_REQUEST['idSupplier'] : 0;
        $fileType = isset($_REQUEST['fileType']) ? $_REQUEST['fileType'] : '';
        echo json_encode($this->model->uploadConfigurationDocument($idOrder, $idPackage, $idSupplier, $fileType, $file));
    }

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

    public function getCustomerAcceptance(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        echo json_encode($this->model->getCustomerAcceptance($idOrder));
    }

    public function uploadAcceptanceDocument(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $file = isset($_FILES['file']) ? $_FILES['file'] : [];
        echo json_encode($this->model->uploadAcceptanceDocument($idOrder, $idPackage, $file));
    }

    /**
     * customer change acceptance status for a package
     * @return Array message confirmation
     */
    public function acceptDeclineInstallation(){
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $actionType = isset($_REQUEST['actionType']) ? $_REQUEST['actionType'] : '';
        $declineReason = isset($_REQUEST['declineReason']) ? $_REQUEST['declineReason'] : '';
        echo json_encode($this->model->acceptDeclineInstallation($idOrder, $idPackage, $actionType, $declineReason));
    }

    /**
     * get availability if send support mail button is visible
     * @return boolean value if send mail is available or not
     */
    public function getAvailabilityForSendSupportMail() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        echo json_encode($this->model->getAvailabilityForSendSupportMail($idOrder));
    }

    /**
     * sends a mail to the support team
     * @return json confirmation message
     */
    public function sendSupportMail() {
        $ordersInfo = isset($_REQUEST['ordersInfo']) ? $_REQUEST['ordersInfo'] : '[]';
        $orderPackages = isset($_REQUEST['orderPackages']) ? $_REQUEST['orderPackages'] : '[]';
        $userText = isset($_REQUEST['userText']) ? $_REQUEST['userText'] : '';
        echo json_encode($this->model->sendSupportMail($ordersInfo, $orderPackages, $userText));
    }

    /**
     * returns the comments and the user id based on the comment type
     * @return json array with comments
     */
    public function getCommentsByType() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $idProcessStep = isset($_REQUEST['idProcessStep']) ? $_REQUEST['idProcessStep'] : 0;
        $commentType = isset($_REQUEST['commentType']) ? $_REQUEST['commentType'] : '';
        echo json_encode($this->model->getCommentsByType($idOrder, $idPackage, $idProcessStep, $commentType));
    }

    /**
     * returns the suppliers for order
     * @return json array with suppliers
     */
    public function getSuppliersByPackageOrder() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $documentType = isset($_REQUEST['documentType']) ? $_REQUEST['documentType'] : '';
        echo json_encode($this->model->getSuppliersByPackageOrder($idOrder, $idPackage, $documentType));
    }

    /**
     * removes the document wanted
     * @return json array with confirmation messages
     */
    public function removeOrderDocument() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $idDocument = isset($_REQUEST['idDocument']) ? $_REQUEST['idDocument'] : 0;
        echo json_encode($this->model->removeOrderDocument($idOrder, $idPackage, $idDocument));
    }

    /**
     * sets the earliest installation
     * @return json array with id order and package
     */
    public function setEarliestInstallationDateInDb() {
        $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
        $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
        $maxDeliveryDate = isset($_REQUEST['maxDeliveryDate']) ? $_REQUEST['maxDeliveryDate'] : '';
        echo json_encode($this->model->setEarliestInstallationDateInDb($idOrder, $idPackage, $maxDeliveryDate));
    }

    /**
     * returns the earliest installation date based on the maximum delivery date plus the additional days
     * @return json array with earliest installation date
     */
     public function getEarliestInstallationDate() {
         $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
         $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
         echo json_encode($this->model->getEarliestInstallationDate($idOrder, $idPackage));
     }

     /**
      * returns the installation dates proposed/accepted/rejected by users
      * @return json array with installation dates
      */
      public function getInstallationDates() {
          $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
          $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
          echo json_encode($this->model->getInstallationDates($idOrder, $idPackage));
      }

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

      /**
       * returns a message if the new date for the installation was successfully added
       * @return json array with confirmation messages
       */
       public function updateInstallationDate() {
           $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
           $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
           $installationDate = isset($_REQUEST['installationDate']) ? $_REQUEST['installationDate'] : '';
           $status = isset($_REQUEST['status']) ? $_REQUEST['status'] : '';
           echo json_encode($this->model->updateInstallationDate($idOrder, $idPackage, $installationDate, $status));
       }

       /**
        * returns a message if the date was removed successfully
        * @return json array with confirmation messages
        */
       public function removeMyDate() {
           $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
           $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
           $installationDate = isset($_REQUEST['installationDate']) ? $_REQUEST['installationDate'] : '';
           echo json_encode($this->model->removeMyDate($idOrder, $idPackage, $installationDate));
       }

       /**
        * returns a bool value if it is the step we are searching for
        * @return boolean value with confirmation if it's what we want
        */
       public function checkIfIsNextStepWanted() {
           $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
           $stepIds = isset($_REQUEST['stepIds']) ? $_REQUEST['stepIds'] : '[]';
           echo json_encode($this->model->checkIfIsNextStepWanted($idOrder, $stepIds));
       }

       /**
        * upload a document for order and per package
        * @return json array with update messages
        */
       public function uploadOrderDocument() {
           $idOrder = isset($_REQUEST['idOrder']) ? $_REQUEST['idOrder'] : 0;
           $idPackage = isset($_REQUEST['idPackage']) ? $_REQUEST['idPackage'] : 0;
           $idDocumentType = isset($_REQUEST['idDocumentType']) ? $_REQUEST['idDocumentType'] : 0;
           $fileName = isset($_REQUEST['fileName']) ? $_REQUEST['fileName'] : '';
           $file = isset($_FILES['file']) ? $_FILES['file'] : [];
           echo json_encode($this->model->uploadOrderDocument($idOrder, $idPackage, $idDocumentType, $fileName, $file));
       }

        /**
         * gives template for updating orders
         * @return json json for orers updatemodel like for webshop
         */
        public function updateOrdersJson(){
            require_once('orders_update_template/orders_update_template.json');
        }

        /**
         * include orders template
         */
        public function ordersTemplate() {
            global $user;
            require_once('templates/OrdersTemplate.php');
        }

        /**
         * include orders ongoing details template
         */
        public function ordersDetailsTemplate() {
            global $user;
            require_once('templates/OrdersDetailsTemplate.php');
        }

        /**
         * incldes template for orders steps
         */
        public function changeOrdersStepsTemplate() {
            global $user;
            require_once('templates/ChangeOrdersStepsTemplate.php');
        }

        /**
         * includes template for assign broker
         */
        public function assignBrokerTemplate() {
            require_once('templates/AssignBrokerTemplate.html');
        }

        /**
         * includes template for components procurement extra action
         */
        public function procurementTemplate() {
            global $user;
            require_once('templates/extra-actions/procurementTemplate.php');
        }

        /**
         * includes template for choosing installation company extra action
         */
        public function chooseInstallationTemplate() {
            global $user;
            require_once('templates/extra-actions/chooseInstallationTemplate.php');
        }

        /**
         * includes template for scheduling follow up meeting extra action
         */
        public function scheduleMeetingTemplate() {
            global $user;
            require_once('templates/extra-actions/scheduleMeetingTemplate.php');
        }

        /**
         * includes template for validate questionnaire extra action
         */
        public function validateQuestionnaireTemplate(){
            global $user;
            require_once('templates/extra-actions/validateQuestionnaireTemplate.php');
        }

        public function suppliersProcurementViewTemplate(){
            global $user;
            require_once('templates/SuppliersProcurementViewTemplate.php');
        }

        /**
         * includes template for customer acceptance extra action
         */
        public function customerAcceptanceTemplate(){
            global $user;
            require_once('templates/extra-actions/customerAcceptanceTemplate.php');
        }

        /**
         * includes template for the email to the support team
         */
        public function supportMailTemplate() {
            require_once('templates/SupportMailTemplate.html');
        }

        /**
         * open orders page
         */
        public function showPage() {
            require_once('OrdersPage.php');
        }

}
