<?php

/////////////////////    سداد ديون مورد معين
//the global file operation
session_start();
ob_start();

//global varable
global $showoutside;

//to check if the page from .htacess
//$showoutside = $_GET['sn'];
// get the config file
include_once("../public/config.php");

//here the db files that include in the file
include("../public/include_dao.php");
//Supplier
require_once('../models/dao/SupplierDAO.class.php');
require_once('../models/dto/Supplier.class.php');
require_once('../models/mysql/SupplierMySqlDAO.class.php');
require_once('../models/mysql/ext/SupplierMySqlExtDAO.class.php');
//Supplierdebtchange
require_once('../models/dao/SupplierdebtchangeDAO.class.php');
require_once('../models/dto/Supplierdebtchange.class.php');
require_once('../models/mysql/SupplierdebtchangeMySqlDAO.class.php');
require_once('../models/mysql/ext/SupplierdebtchangeMySqlExtDAO.class.php');

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

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

  Controller Name :- supplierPayedDeptController

  OPERTATION in Controller

  1- get supplier dept and last operation date
  ======================== */

//here goes the instances and general variables
//Supplier
$supplier = new Supplier();
$supplierDAO = new SupplierMySqlDAO();
$supplierExt = new SupplierMySqlExtDAO();
//Supplierdebtchange
$supplierDeptChange = new Supplierdebtchange();
$supplierDeptChangeDAO = new SupplierdebtchangeMySqlDAO();
$supplierDeptChangeExt = new SupplierdebtchangeMySqlExtDAO();

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

//check and use the condition that suite this action
if (empty($do) || $do == "show") {
    //here the permssion check


    $supplierData = getSupplierData();
}elseif ($do == 'checkserail') {

    $serail = $_GET["serail"];

    $mydata = $supplierDeptChangeExt->showbymodelid($serail);
    if (count($mydata) > 0) {
        echo '1';
    } else {
        echo '0';
    }
}

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

function getSupplierData() {
    global $supplierDAO;
    $supplierId = $_GET['id'];
    $supplierData = $supplierDAO->load($supplierId);
    $suppliercurrentDebt = $supplierData->suppliercurrentDebt;
    $supplierdate = $supplierData->supplierdate;

    $data = array('suppliercurrentDebt' => $suppliercurrentDebt, 'supplierdate' => $supplierdate);

    echo json_encode($data);
}

?>