HEX
Server: Apache
System: Linux server1.royalgt4.com 4.18.0-553.89.1.lve.el8.x86_64 #1 SMP Wed Dec 10 13:58:50 UTC 2025 x86_64
User: mostafedeg (1125)
PHP: 5.6.40
Disabled: mail,passthru,parse_ini_file,show_source,eval,assert,pcntl_exec,dl,putenv,proc_open,popen
Upload Files
File: /home/mostafedeg/public_html/erp/controllers/clientPayedDeptBillsController.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
include("../public/include_dao.php");
//Bill
require_once('../models/dao/BillsDAO.class.php');
require_once('../models/dto/Bill.class.php');
require_once('../models/mysql/BillsMySqlDAO.class.php');
require_once('../models/mysql/ext/BillsMySqlExtDAO.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');

//Clientdebtchange
require_once('../models/dao/ClientdebtchangeDAO.class.php');
require_once('../models/dto/Clientdebtchange.class.php');
require_once('../models/mysql/ClientdebtchangeMySqlDAO.class.php');
require_once('../models/mysql/ext/ClientdebtchangeMySqlExtDAO.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'];

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

  Controller Name :- clientPayedDeptReportController

  OPERTATION in Controller

  1- تقرير سداد ديون عميل بصاريات

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

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

//here goes the instances and general variables
//bill
$bills = new Bill();
$billsDAO = new BillsMySqlDAO();
$billsEX = new BillsMySqlExtDAO();

//Client
$client = new Client();
$clientDAO = new ClientMySqlDAO();
$clientExt = new ClientMySqlExtDAO();

//Clientdebtchange
$clientDeptChange = new Clientdebtchange();
$clientDeptChangeDAO = new ClientdebtchangeMySqlDAO();
$clientDeptChangeExt = new ClientdebtchangeMySqlExtDAO();

$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)) {// تقرير سداد ديون عميل بصاريات
    //here the permssion check
    include_once("../public/authentication.php");


    $start_date = $_REQUEST['from'];
    $end_date = $_REQUEST['to'];
    $client = $_POST['client'];
    $bill_no = $_POST['bill_no'];

    $where = '';
    $result_string = '';
    if ((isset($client) && $client != "-1" && $client != '')) {
        $where = ' clientid = ' . $client . ' ';


        $messageData = $clientDAO->load($client);
        $result_string .= " اسم العميل : " . $messageData->clientname;
        $smarty->assign("client_id", $messageData->clientid);
    }
    if ((isset($bill_no) && $bill_no != "")) {
        if (empty($where)) {
            $where .= ' id = ' . $bill_no . ' ';
        } else {
            $where .= ' and id = ' . $bill_no . ' ';
        }
    }

    if (isset($start_date) && $start_date != "" && isset($end_date) && $end_date != "") {

        if (empty($where)) {
            $where .= ' date(billdate) >= "' . $start_date . '" and date(billdate) <= "' . $end_date . '" ';
        } else {
            $where .= ' and  date(billdate) >= "' . $start_date . '" and date(billdate) <= "' . $end_date . '" ';
        }
        $result_string .= " التاريخ: من   :  " . $start_date . " إلى: " . $end_date;
    }


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

    // if ((isset($client) && $client != "-1")) {


    if (!empty($where)) {

        $message = $result_string;
        $smarty->assign("message", $message);

        $clientBills = $billsEX->queryAllforcondemnedbills($where);

        $client_bills = array();
        foreach ($clientBills as $cli_bill_val) {

            $bill_id = $cli_bill_val->billno;
            $client_dept_change = $clientDeptChangeExt->sumByBillId($bill_id);

            $waitvalue = $cli_bill_val->waitvalue - $client_dept_change->clientdebtchangeamount; //# قيمة الدين

            if ($waitvalue > 0) {
                $client_bills[] = array(
                    'id' => $cli_bill_val->id,
                    'billno' => $bill_id,
                    'finalnetbillvalue' => $cli_bill_val->finalnetbillvalue,
                    'waitvalue' => $cli_bill_val->waitvalue - $client_dept_change->clientdebtchangeamount,
                    'total_payed' => $cli_bill_val->cashvalue + $cli_bill_val->cardvalue + $cli_bill_val->companycarry + $client_dept_change->clientdebtchangeamount
                );
            }
        }
        //        print_r('<pre>');
        //                print_r($client_bills);
        //        print_r('<pre>');
        // $smarty->assign("clientBills", $clientBills);
        $smarty->assign("client_bills", $client_bills);

        //}
    }


    $smarty->assign("customClientDeptChangeReport", 1);
    $smarty->display("clientPayedDepBillsView/add.html");
} elseif ($do == "show") {

    //here the permssion check
    include_once("../public/authentication.php");


    $start_date = $_REQUEST['from'];
    $end_date = $_REQUEST['to'];
    $client = $_POST['client'];
    $bill_id = $_POST['bill_no'];

    $where = '';
    if ((isset($client) && $client != "-1" && $client != '')) {
        $where = 'and clientid = ' . $client . ' ';
    }
    if ((isset($bill_id) && $bill_id != "")) {
        $bill_data = $billsDAO->load($bill_id);
        $bill_id = $bill_data->billno;
        $where .= ' and billid = ' . $bill_id . ' ';
    }

    if (isset($start_date) && $start_date != "" && isset($end_date) && $end_date != "") {
        $where .= ' and  date(clientdebtchangedate) >= "' . $start_date . '" and  date(clientdebtchangedate) <= "' . $end_date . '" ';
    }

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

    $client_payed_bills = $clientDeptChangeExt->selectAllPayedBills($where);


    $client_bills = array();
    $total_bills = $total_wait_bills = $total_payed_bills = 0;

    foreach ($client_payed_bills as $cli_payed_bill) {

        $dept_Bill_detail = $clientDeptChangeExt->sumByBillId($cli_payed_bill->billid);

        $Bill_detail = $billsEX->selectBillNo($cli_payed_bill->billid);

        $waitvalue = $Bill_detail->waitvalue - $dept_Bill_detail->clientdebtchangeamount;

        //if( $waitvalue > 0){

        $client_bills[] = array(
            'id' => $Bill_detail->id,
            'billno' => $Bill_detail->billno,
            'finalnetbillvalue' => $Bill_detail->finalnetbillvalue,
            'waitvalue' => $waitvalue,
            'total_payed' => $Bill_detail->cashvalue + $Bill_detail->cardvalue + $Bill_detail->companycarry + $dept_Bill_detail->clientdebtchangeamount,
        );

        $total_bills += $Bill_detail->finalnetbillvalue;
        $total_wait_bills += $Bill_detail->waitvalue - $dept_Bill_detail->clientdebtchangeamount;
        $total_payed_bills += $Bill_detail->cashvalue + $Bill_detail->cardvalue + $Bill_detail->companycarry + $dept_Bill_detail->clientdebtchangeamount;
        //}
    }


    $smarty->assign("total_bills", $total_bills);
    $smarty->assign("total_wait_bills", $total_wait_bills);
    $smarty->assign("total_payed_bills", $total_payed_bills);

    $smarty->assign("client_bills", $client_bills);

    $smarty->assign("customClientDeptChangeReport", 1);
    $smarty->display("clientPayedDepBillsView/show.html");
} elseif ($do == "show_details") {



    $bill_no = $_GET['id'];

    $bill_data = $billsDAO->queryByBillno($bill_no);

    $bill_data = $bill_data[0];

    //# bill data .
    $finalnetbillvalue = $bill_data->finalnetbillvalue;
    $waitvalue = $bill_data->waitvalue;
    $cardvalue = $bill_data->cardvalue;
    $cashvalue = $bill_data->cashvalue;
    $companycarry = $bill_data->companycarry;

    //# load client data .
    $clientid = $bill_data->clientid;
    $messageData = $clientDAO->load($clientid);

    $message = " اسم العميل : " . $messageData->clientname;
    $smarty->assign("message", $message);


    //# select all rows which belongs to this bill no.
    $client_dept_Bills = $clientDeptChangeExt->selectByBillId($bill_no);


    $client_bills = array();
    $x = 1;
    foreach ($client_dept_Bills as $cli_bill_val) {

        $clientdebtchangeamount = $cli_bill_val->clientdebtchangeamount;
        $paytype = $cli_bill_val->paytype;
        $date = $cli_bill_val->clientdebtchangedate;

        if ($x == 1) {
            $wait_before = $waitvalue;
            $wait_aftre = $wait_before - ( $cardvalue + $cashvalue + $companycarry + $clientdebtchangeamount );
        } else {
            $wait_before = $wait_aftre;

            $wait_aftre = $wait_before - $clientdebtchangeamount;
        }
        //if( $waitvalue > 0 ){
        $client_bills[] = array(
            'itra' => $x,
            'finalnetbillvalue' => $finalnetbillvalue,
            'wait_before' => $wait_before,
            'clientdebtchangeamount' => $clientdebtchangeamount,
            'wait_after' => $wait_aftre,
            'date' => $date,
            'paytype' => $paytype,
        );

        $x++;
    }

    $smarty->assign("customClientDeptChangeReport", 1);

    $smarty->assign("client_bills", $client_bills);

    $smarty->display("clientPayedDepBillsView/show_details.html");
}
//here the global templates
$smarty->display("footer.html");
?>