<?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");
//Client
require_once('../models/dao/ClientDAO.class.php');
require_once('../models/dto/Client.class.php');
require_once('../models/mysql/ClientMySqlDAO.class.php');
require_once('../models/mysql/ext/ClientMySqlExtDAO.class.php');

//MComreceipt
require_once('../models/dao/MComreceiptDAO.class.php');
require_once('../models/dto/MComreceipt.class.php');
require_once('../models/mysql/MComreceiptMySqlDAO.class.php');
require_once('../models/mysql/ext/MComreceiptMySqlExtDAO.class.php');

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

/* ======================
  Controller Name :- clientDeficitControllerAjax
  OPERTATION in Controller
  1- get current client dept
  ======================== */

//here goes the instances and general variables
//Client
$client = new Client();
$clientDAO = new ClientMySqlDAO();
$clientExt = new ClientMySqlExtDAO();

//MComreceipt
$MComreceipt = new MComreceipt();
$MComreceiptDAO = new MComreceiptMySqlDAO();
$MComreceiptEx = new MComreceiptMySqlExtDAO();

$today = date("Y-m-d H:i:s");

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


    getClientDept();
} elseif ($do == 'getreceipt') {
    $alldata = getreceiptdata();
    $smarty->assign('alldata', $alldata);

    $smarty->display("receiptview/reciept.html");
}

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

function getClientDept() {
    global $clientDAO;
    $clientid = $_GET['id'];
    $clientData = $clientDAO->load($clientid);
    $clientCurrentDept = $clientData->clientdebt;
    echo $clientCurrentDept; //output
}

function getreceiptdata() {
    global $MComreceiptEx;

    $clientid = $_GET['id'];

    $alldata = $MComreceiptEx->queryByClientidforrecipt($clientid);

    return $alldata;
}

?>