<?php

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
// GOES HERE ....................
include("../public/include_dao.php");

//Partner
require_once('../models/dao/PartnerDAO.class.php');
require_once('../models/dto/Partner.class.php');
require_once('../models/mysql/PartnerMySqlDAO.class.php');
require_once('../models/mysql/ext/PartnerMySqlExtDAO.class.php');

//Capital
require_once('../models/dao/CapitalDAO.class.php');
require_once('../models/dto/Capital.class.php');
require_once('../models/mysql/CapitalMySqlDAO.class.php');
require_once('../models/mysql/ext/CapitalMySqlExtDAO.class.php');



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


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

  Controller Name :- userCTRL

  OPERTATION in Controller

  1-display add form
  2- add in user tble
  3-display sucess or error
  4-display show form
  5-delete from user tbl
  6-edit in user data

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




//here goes the instances and general variables
//Partner
$myPartner = new Partner();
$myPartnerRecord = new PartnerMySqlDAO();
$myPartnerEx = new PartnerMySqlExtDAO();

//Capital
$myCapitalRecord = new CapitalMySqlDAO();
//check and use the condetion that suite this action



if ($do == "getPercentage") {

    $partnerMoney = $_GET['partnermoney'];

    $partnerPercentage = getPartnerPercentage($partnerMoney);

    echo $partnerPercentage;
} elseif ($do = 'checkName') {
    $partnername = $_POST['partnername'];
    $partData = $myPartnerRecord->queryByPartnername($partnername);
    if (!empty($partData)) {
        echo -1;
    } elseif (empty($partData)) {
        echo 0;
    }
}



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

// add in user tbl
function getPartnerPercentage($partnerMoney) {

    //to use the variable out side the funcion
    global $myCapitalRecord;

    $capitalData = $myCapitalRecord->load(1);

    $capitalAmount = $capitalData->capitalamount;

    $partnerPercentage = $partnerMoney / $capitalAmount;

    return $partnerPercentage;
}

?>