<?php

/////////////////////    تسوية عجز عميل
//the global file operation
include("../public/impOpreation.php");

//global varable
global $showoutside;

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

//here the db files that include in the file
include("../public/include_dao.php");

//AccountmovementkindDAO
require_once('../models/dao/TypesimpotencetreatmentDAO.class.php');
require_once('../models/dto/Typesimpotencetreatment.class.php');
require_once('../models/mysql/TypesimpotencetreatmentMySqlDAO.class.php');
require_once('../models/mysql/ext/TypesimpotencetreatmentMySqlExtDAO.class.php');

require_once('../models/dao/YoutubeLinkDAO.class.php');
require_once('../models/dto/YoutubeLink.class.php');
require_once('../models/mysql/YoutubeLinkMySqlDAO.class.php');
require_once('../models/mysql/ext/YoutubeLinkMySqlExtDAO.class.php');

//get the do the action
$do = $_GET['do'];
$langs = $_SESSION['erp_lang'];
include_once("../views/languages/$langs/success.php");
include_once("../views/languages/$langs/error.php");
/* ======================

  Controller Name :- clientDeficitController

  OPERTATION in Controller

  1- display add form
  2- add in clientdebtchange tbl (subtracting or adding client debt)
  3- update client dept in client tbl
  ======================== */

//here the global templates
$smarty->display("header.html");

//here goes the instances and general variables

//AccountmovementkindDAO
$myTypesimpotencetreatment = new Typesimpotencetreatment();
$myTypesimpotencetreatmentRecord = new TypesimpotencetreatmentMySqlDAO();
$myTypesimpotencetreatmentEx = new TypesimpotencetreatmentMySqlExtDAO();

$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();

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


//check and use the condition that suite this action
if (empty($do)) {
    include_once("../public/authentication.php");

   
    $smarty->display("settlementkindsaveview/add.html");

    //$smarty->assign("customClientDeficit", 1);
} elseif ($do == "add") {
    include_once("../public/authentication.php");
    try {
        add();
        header("location:?do=sucess");
    } catch (Exception $e) {
        // print_r($e);
        $mytransactions->rollback();
        header("location:?do=error");
    }
} elseif ($do == "show") {
    include_once("../public/authentication.php");

    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);

    $shownData = $myTypesimpotencetreatmentRecord->queryAll();
    $smarty->assign("shownData", $shownData);
    $smarty->display("settlementkindsaveview/show.html");
}elseif ($do == "tempdelete") {
    include_once("../public/authentication.php");

    $typesimpotencetreatmentid = $_GET['typesimpotencetreatmentid'];

    try {
       R::exec("UPDATE `typesimpotencetreatment` SET `conditions`= 1 WHERE typesimpotencetreatmentid = '".$typesimpotencetreatmentid."' ");
        header("location:?do=sucess");
    } catch (Exception $e) {
        header("location:?do=error");
    }
} elseif ($do == "edit") {
    include_once("../public/authentication.php");
    $id = $_GET['id'];
    $loadData = edit($id);
    $smarty->assign("loadData", $loadData);

    $smarty->display("settlementkindsaveview/edit.html");
} elseif ($do == "sucess") {
    //here the smarty templates
    $smarty->display("succes.html");
} elseif ($do == "error") {
    //here the smarty templates
    $smarty->display("error.html");
}

$smarty->assign("customValidation", 1);
//here the global templates
$smarty->display("footer.html");

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

// add in clientdebtchange tbl
function add() {
    global $myTypesimpotencetreatment;
    global $myTypesimpotencetreatmentRecord;


    $typesimpotencetreatmentname = $_POST["typesimpotencetreatmentname"];
    $typesimpotencetreatmentcomment = $_POST["typesimpotencetreatmentcomment"];

    $myTypesimpotencetreatment->typesimpotencetreatmentname = $typesimpotencetreatmentname;
    $myTypesimpotencetreatment->typesimpotencetreatmentcomment = $typesimpotencetreatmentcomment;
    $myTypesimpotencetreatment->conditions = 0;
    $myTypesimpotencetreatment->typesimpotencetreatmentdate = date('Y-m-d H:i:s');
    $myTypesimpotencetreatment->userid = $_SESSION['userid'];
    $accountMovementId = $myTypesimpotencetreatmentRecord->insert($myTypesimpotencetreatment);
    return $accountMovementId;
}

function edit($id) {
    global $myAccountmovementRecord;
    global $myAccountmovementEx;


    $data = $myAccountmovementEx->loadMovementEX($id);

    return $data;
}



?>