<?php

// get the config file
include_once("../public/config.php");
//the global file operation
//here the db files that include in the file
include("../public/include_dao.php");
//Productsetting
require_once('../models/dao/ProductsettingDAO.class.php');
require_once('../models/dto/Productsetting.class.php');
require_once('../models/mysql/ProductsettingMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductsettingMySqlExtDAO.class.php');
//Store
require_once('../models/dao/StoreDAO.class.php');
require_once('../models/dto/Store.class.php');
require_once('../models/mysql/StoreMySqlDAO.class.php');
require_once('../models/mysql/ext/StoreMySqlExtDAO.class.php');

//get the do the action
$do = $_GET['do'];

/* ======================

  Controller Name :- productSettingController

  OPERTATION in Controller

  1- edit productSetting
  ======================== */

//here goes the instances and general variables
//Productsetting
$productSetting = new Productsetting();
$productSettingDAO = new ProductsettingMySqlDAO();
$productSettingExt = new ProductsettingMySqlExtDAO();
//Store
$store = new Store();
$storeDAO = new StoreMySqlDAO();
$storeExt = new StoreMySqlExtDAO();

$today = date("Y-m-d");

//check and use the condition that suite this action
if (empty($do)) {
    //here the permission check
    getLeastValueAtStore();
}


/* ===============================
  function in this CONTROLLER
  ================================ */

function getLeastValueAtStore() {
    global $productSettingExt;
    $data;
    $storeid = $_GET['id'];
    if (!empty($storeid)) {
        $storeData = $productSettingExt->queryByStoreidExt($storeid);
        if (count($storeData) > 0) {
            $productsettingid = (int) $storeData->productsettingid;
            $leastValueAtStore = (int) $storeData->leastValueAtStore;
            $data = array('productsettingid' => $productsettingid, 'leastValueAtStore' => $leastValueAtStore);
        } else { //if there is no row for this store
            $data = array('productsettingid' => 0, 'leastValueAtStore' => 0);
        }
    }

    echo json_encode($data);
}

?>