File: /home/mostafedeg/public_html/erp/controllers/premiumautomaticController.php
<?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");
//here the db files that include in the file
// GOES HERE ....................
include("../public/include_dao.php");
//user
require_once('../models/dao/UserDAO.class.php');
require_once('../models/dto/User.class.php');
require_once('../models/mysql/UserMySqlDAO.class.php');
require_once('../models/mysql/ext/UserMySqlExtDAO.class.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');
//Premiumclient
require_once('../models/dao/PremiumclientDAO.class.php');
require_once('../models/dto/Premiumclient.class.php');
require_once('../models/mysql/PremiumclientMySqlDAO.class.php');
require_once('../models/mysql/ext/PremiumclientMySqlExtDAO.class.php');
//Premium
require_once('../models/dao/PremiumDAO.class.php');
require_once('../models/dto/Premium.class.php');
require_once('../models/mysql/PremiumMySqlDAO.class.php');
require_once('../models/mysql/ext/PremiumMySqlExtDAO.class.php');
//PremiumInstallment
require_once('../models/dao/PremiumInstallmentsDAO.class.php');
require_once('../models/dto/PremiumInstallment.class.php');
require_once('../models/mysql/PremiumInstallmentsMySqlDAO.class.php');
require_once('../models/mysql/ext/PremiumInstallmentsMySqlExtDAO.class.php');
//Premiumautomatic
require_once('../models/dao/PremiumautomaticDAO.class.php');
require_once('../models/dto/Premiumautomatic.class.php');
require_once('../models/mysql/PremiumautomaticMySqlDAO.class.php');
require_once('../models/mysql/ext/PremiumautomaticMySqlExtDAO.class.php');
//typeClient
require_once('../models/dao/TypeClientDAO.class.php');
require_once('../models/dto/TypeClient.class.php');
require_once('../models/mysql/TypeClientMySqlDAO.class.php');
require_once('../models/mysql/ext/TypeClientMySqlExtDAO.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");
//here the global templates
$smarty->display("header.html");
//user
$user = new User();
$userDAO = new UserMySqlDAO();
$userEX = new UserMySqlExtDAO();
//Client
$client = new Client();
$clientDAO = new ClientMySqlDAO();
$clientExt = new ClientMySqlExtDAO();
//Premiumclient
$Premiumclient = new Premiumclient();
$PremiumclientDAO = new PremiumclientMySqlDAO();
$PremiumclientExt = new PremiumclientMySqlExtDAO();
//Premium
$premium = new Premium();
$premiumDAO = new PremiumMySqlDAO();
$premiumExt = new PremiumMySqlExtDAO();
$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();
//PremiumInstallment
$PremiumInstallment = new PremiumInstallment();
$PremiumInstallmentDAO = new PremiumInstallmentsMySqlDAO();
$PremiumInstallmentExt = new PremiumInstallmentsMySqlExtDAO();
//Premiumautomatic
$Premiumautomatic = new Premiumautomatic();
$PremiumautomaticDAO = new PremiumautomaticMySqlDAO();
$PremiumautomaticExt = new PremiumautomaticMySqlExtDAO();
//typeClient
$type = new TypeClient();
$TypeClientDAO = new TypeClientMySqlDAO();
$TypeClientEX = new TypeClientMySqlExtDAO();
//check and use the condetion that suite this action
if (empty($do)) {
include_once("../public/authentication.php");
$clientsData = $clientDAO->queryAll();
$smarty->assign("clientsData", $clientsData);
$smarty->display("premiumautomaticview/add.html");
$smarty->assign("clientPremium", 1);
}
elseif ($do == "add") {
include_once("../public/authentication.php");
try {
// here the function that do the action
addAutomatic();
header("location:?do=sucess");
} catch (Exception $e) {
// echo $e;
header("location:?do=error");
}
}
elseif ($do == "show") {
include_once("../public/authentication.php");
$allpremiums = show();
$smarty->assign("allpremiums", $allpremiums);
$youtubes = $youtubeLinkDAO->queryAll();
$smarty->assign("youtubes", $youtubes);
$smarty->display("premiumautomaticview/show.html");
$smarty->assign("clientPremium", 1);
}
elseif ($do == "details") {
include_once("../public/authentication.php");
$clientsData = $clientDAO->queryAll();
$smarty->assign("clientsData", $clientsData);
$id = $_GET['id'];
$alldata = $PremiumautomaticDAO->load($id);
$installments_dates = $PremiumInstallmentDAO->queryByPremiumauoId($id);
$client_id = $alldata->clientId;
$clientData = $clientExt->getalldata($client_id);
$clientData->typeclientid = explode(',', $clientData->typeclientid);
$typeClient = $TypeClientDAO->queryAll();
$azmy = array();
foreach ($typeClient as $item) {
//var_dump($item);
if (in_array($item->typeId, $clientData->typeclientid)) {
array_push($azmy, $item->typeName);
}
}
if (in_array('-20', $clientData->typeclientid)){
array_push($azmy, "كل انواع العملاء");
};
$aaaa = implode(",", $azmy);
$clientData->typeName = $aaaa ;
$smarty->assign("installments_dates", $installments_dates);
$smarty->assign("alldata", $alldata);
$smarty->assign("clientData", $clientData);
$smarty->display("premiumautomaticview/details.html");
$smarty->assign("clientPremium", 1);
}
elseif ($do == "addPremiumformreport") {
include_once("../public/authentication.php");
try {
// here the function that do the action
addPremiumformreport();
header("location:?do=sucess");
} catch (Exception $e) {
// echo $e;
header("location:?do=error");
}
}
elseif ($do == "edit") {
include_once("../public/authentication.php");
$clientsData = $clientDAO->queryAll();
$smarty->assign("clientsData", $clientsData);
$id = $_GET['id'];
$alldata = $PremiumautomaticDAO->load($id);
$installments_dates = $PremiumInstallmentDAO->queryByPremiumauoId($id);
$client_id = $alldata->clientId;
$clientData = $clientExt->getalldata($client_id);
$clientData->typeclientid = explode(',', $clientData->typeclientid);
$typeClient = $TypeClientDAO->queryAll();
$azmy = array();
foreach ($typeClient as $item) {
//var_dump($item);
if (in_array($item->typeId, $clientData->typeclientid)) {
array_push($azmy, $item->typeName);
}
}
if (in_array('-20', $clientData->typeclientid)){
array_push($azmy, "كل انواع العملاء");
};
$aaaa = implode(",", $azmy);
$clientData->typeName = $aaaa ;
$smarty->assign("installments_dates", $installments_dates);
$smarty->assign("alldata", $alldata);
$smarty->assign("clientData", $clientData);
$smarty->display("premiumautomaticview/edit.html");
$smarty->assign("clientPremium", 1);
}
elseif ($do == "update") {
include_once("../public/authentication.php");
try {
// here the function that do the action
update();
header("location:?do=sucess");
} catch (Exception $e) {
header("location:?do=error");
}
}
elseif ($do == "updatefromreport") {
include_once("../public/authentication.php");
try {
// here the function that do the action
updatefromreport();
header("location:?do=sucess");
} catch (Exception $e) {
header("location:?do=error");
}
}
elseif ($do == "delete") {
include_once("../public/authentication.php");
//add();
try {
// here the function that do the action
delete();
header("location:?do=sucess");
} catch (Exception $e) {
header("location:?do=error");
}
}
elseif ($do == "deletefromRemport") {
include_once("../public/authentication.php");
//add();
try {
// here the function that do the action
deletefromRemport();
header("location:allpremiumReportController.php");
} catch (Exception $e) {
header("location:?do=error");
}
}
elseif ($do == "sucess") {
//here the smarty templates
$smarty->display("succes.html");
}
elseif ($do == "error") {
//here the smarty templates
$smarty->display("error.html");
}
//here the global templates
$smarty->assign("customstage", 1);
//here the global templates
$smarty->display("footer.html");
/* ===============================
function in this CONTROLLER
================================ */
function addAutomatic() {
global $Premiumautomatic;
global $PremiumautomaticDAO;
$first_payment = filter_input(INPUT_POST, 'first_payment');
$payment_dir = filter_input(INPUT_POST, 'payment_dir');
$payment_Per = filter_input(INPUT_POST, 'payment_Per');
$rest_payment = filter_input(INPUT_POST, 'rest_payment');
$installment_every_date = filter_input(INPUT_POST, 'installment_every_date');
$installment_nos = filter_input(INPUT_POST, 'installment_nos');
$installment_months = filter_input(INPUT_POST, 'installment_months');
$installment_days = filter_input(INPUT_POST, 'installment_days');
$client = filter_input(INPUT_POST, 'clientID');
$Premiumautomatic->totalinstallment = $first_payment ;
$Premiumautomatic->presenterDir = $payment_dir ;
$Premiumautomatic->presenterPer = $payment_Per ;
$Premiumautomatic->remainAmount = $rest_payment ;
$Premiumautomatic->date = $installment_every_date ;
$Premiumautomatic->installmentNos = $installment_nos ;
$Premiumautomatic->installmentMonths = $installment_months ;
$Premiumautomatic->installmentDays = $installment_days ;
$Premiumautomatic->clientId = $client ;
$Premiumautomatic->userid = $_SESSION['userid'];
$Premiumautomatic_id = $PremiumautomaticDAO->insert($Premiumautomatic);
addPremiumAutomatic($Premiumautomatic_id);
}
function addPremiumAutomatic($Premiumautomatic_id) {
global $PremiumInstallment;
global $PremiumInstallmentDAO;
$premiumItr = filter_input(INPUT_POST, 'installmentitr');
for ($i = 1; $i <= $premiumItr; $i++) {
$date = filter_input(INPUT_POST, 'installment_payment_date_' . $i);
$amount = filter_input(INPUT_POST, 'installment_payment_' . $i);
$PremiumInstallment->date = $date;
$PremiumInstallment->value = $amount;
$PremiumInstallment->premiumauoId = $Premiumautomatic_id ;
$PremiumInstallment->payed = 0;
$PremiumInstallment->conditions = 0 ;
$PremiumInstallmentDAO->insert($PremiumInstallment);
}
}
function show() {
global $PremiumautomaticDAO;
global $clientExt;
global $userDAO;
$allpremiums = $PremiumautomaticDAO->queryAll();
foreach ($allpremiums as $item){
$user = $userDAO->load($item->userid);
$item->username = $user->username;
$client_id = $item->clientId;
$clientData = $clientExt->loadExt($client_id);
foreach ($clientData as $single)
$item->clientname = $single->clientname;
}
return $allpremiums;
}
///////////////////////////////update///////////////////////////////////
function update() {
global $Premiumautomatic;
global $PremiumautomaticDAO;
global $PremiumInstallmentDAO;
$Premiumcliented = filter_input(INPUT_POST, 'Premiumclientauto');
$first_payment = filter_input(INPUT_POST, 'first_payment');
$payment_dir = filter_input(INPUT_POST, 'payment_dir');
$payment_Per = filter_input(INPUT_POST, 'payment_Per');
$rest_payment = filter_input(INPUT_POST, 'rest_payment');
$installment_every_date = filter_input(INPUT_POST, 'installment_every_date');
$installment_nos = filter_input(INPUT_POST, 'installment_nos');
$installment_months = filter_input(INPUT_POST, 'installment_months');
$installment_days = filter_input(INPUT_POST, 'installment_days');
$client = filter_input(INPUT_POST, 'clientID');
$Premiumautomatic->id = $Premiumcliented ;
$Premiumautomatic->totalinstallment = $first_payment ;
$Premiumautomatic->presenterDir = $payment_dir ;
$Premiumautomatic->presenterPer = $payment_Per ;
$Premiumautomatic->remainAmount = $rest_payment ;
$Premiumautomatic->date = $installment_every_date ;
$Premiumautomatic->installmentNos = $installment_nos ;
$Premiumautomatic->installmentMonths = $installment_months ;
$Premiumautomatic->installmentDays = $installment_days ;
$Premiumautomatic->clientId = $client ;
$Premiumautomatic->userid = $_SESSION['userid'];
$PremiumautomaticDAO->update($Premiumautomatic);
$PremiumInstallmentDAO->deleteByPremiumauoId($Premiumautomatic->id);
addPremiumAutomatic($Premiumautomatic->id);
}
///////////////////////////////////////////delete///////////////////////////////////////
function delete() {
global $PremiumautomaticDAO;
global $PremiumInstallmentDAO;
$id = $_GET['id'];
$PremiumInstallmentDAO->deleteByPremiumauoId($id);
$PremiumautomaticDAO->delete($id);
}
//تأجيل
function addPremiumformreport() {
global $premium;
global $premiumDAO;
$id = filter_input(INPUT_POST, 'idInstallment');
$premiumauoId = filter_input(INPUT_POST, 'premiumauoId');
$date = filter_input(INPUT_POST, 'date');
$amount = filter_input(INPUT_POST, 'Amount');
$delayDate = filter_input(INPUT_POST, 'delayDate');
$premium->date = $delayDate;
$premium->value = $amount;
$premium->premiumauoId = $premiumauoId ;
$premium->payed = 0 ;
$premium->conditions = 0 ;
$premiumDAO->insert($premium);
$premium->id = $id;
$premium->date = $date;
$premium->value = $amount;
$premium->premiumauoId = $premiumauoId ;
$premium->payed = 0 ;
$premium->conditions = 1 ;
$premiumDAO->update($premium);
}
//تعديل
//function updatefromreport() {
//
// global $premium;
// global $premiumDAO;
//
//
//
//
//
// $id = filter_input(INPUT_POST, 'id');
// $Premiumcliented = filter_input(INPUT_POST, 'premiumclientId');
// $date = filter_input(INPUT_POST, 'date');
// $Amount = filter_input(INPUT_POST, 'Amount');
// $conditions = filter_input(INPUT_POST, 'conditions');
// $payed = filter_input(INPUT_POST, 'payed');
//
// $premium->id = $id ;
// $premium->premiumclientId = $Premiumcliented ;
// $premium->date = $date ;
// $premium->value = $Amount;
// $premium->conditions = $conditions;
// $premium->payed = $payed;
//
// $premiumDAO->update($premium);
//
//
//}
//حذف
//function deletefromRemport() {
// global $premiumExt;
// global $premiumDAO;
// global $PremiumclientDAO;
//
// $id = $_GET['id'];
// $premium = $premiumDAO->load($id);
// $premiumDAO->delete($id);
// $count = $premiumExt->selectallbyid($premium->premiumclientId);
// if ($count->countPremium <= 0){
// $PremiumclientDAO->delete($premium->premiumclientId);
// }
//}