<?php
/****************************
 * File : enquiryreport.php
 * Author : Cygnusa
 * @2020
 ****************************/
/* cSpell:disable */
//SECURITY
if (!defined('APPLICATION_PATH')) {
    exit('No direct script access allowed');
}

//FUNCTION LISTS
class enquiryreport
{
    public function __construct($parent)
    {
        //GET PAGE MESSAGE
        $this->page_data = globalfunc::getMessage($parent, $parent->lang, 'enquiryreport');
        if (count($parent->params) == 0) {
            $this->enquirysubmit($parent);

        } else {
            $qry_params = explode("?", $parent->params[0]);
            $parameter_val = strtolower($qry_params[0]);

            switch ($parameter_val) {
                case "dashboard":
                case "export":
                    $this->$parameter_val($parent);
                    break;

                default:
                    $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
                    break;
            }
        }
        $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// DATE ARRAY //////////////////////////////////////////////// */
    private function getDateArray($parent, $period, $from, $to)
    {
        $date_arr = array();

        switch ($period) {
            case '6months':
                //$date_arr[]=array("from"=>$from_date,"to"=>$to_date);
                for ($i = 6; $i >= 1; $i--) {

                    $from_date = date('Y-m-', strtotime('-' . $i . ' month', strtotime(CUR_DATE))) . "01";
                    $to_date = date('Y-m-t', strtotime('-' . $i . ' month', strtotime(CUR_DATE)));
                    $label = date('M Y', strtotime($from_date));
                    $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                }
                //$from_date = date('Y-m-', strtotime(CUR_DATE)) . "01";
                //$to_date = date('Y-m-t', strtotime(CUR_DATE));
                //$date_arr[] = array("from" => $from_date, "to" => $to_date);
                break;
            case '7days':
                for ($i = 7; $i >= 1; $i--) {

                    $from_date = date('Y-m-d', strtotime('-' . $i . ' day', strtotime(CUR_DATE)));
                    $to_date = $from_date;
                    $label = date('d-m-Y', strtotime($from_date));
                    $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                }
                break;
            case 'quarter1':
                for ($i = 4; $i <= 6; $i++) {
                    if (date('n', strtotime(CUR_DATE)) > 3) {
                        $from_date = date('Y-', strtotime(CUR_DATE)) . "0$i-01";
                    } else {
                        $from_date = date('Y-', strtotime('-1 year', strtotime(CUR_DATE))) . "0$i-01";
                    }

                    $to_date = date('Y-m-t', strtotime($from_date));
                    $label = date('M Y', strtotime($from_date));
                    $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                }
                break;
            case 'quarter2':
                for ($i = 7; $i <= 9; $i++) {
                    if (date('n', strtotime(CUR_DATE)) > 3) {
                        $from_date = date('Y-', strtotime(CUR_DATE)) . "0$i-01";
                    } else {
                        $from_date = date('Y-', strtotime('-1 year', strtotime(CUR_DATE))) . "0$i-01";
                    }
                    $to_date = date('Y-m-t', strtotime($from_date));
                    $label = date('M Y', strtotime($from_date));
                    $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                }
                break;
            case 'quarter3':
                for ($i = 10; $i <= 12; $i++) {
                    if (date('n', strtotime(CUR_DATE)) > 3) {
                        $from_date = date('Y-', strtotime(CUR_DATE)) . "$i-01";
                    } else {
                        $from_date = date('Y-', strtotime('-1 year', strtotime(CUR_DATE))) . "$i-01";
                    }
                    $to_date = date('Y-m-t', strtotime($from_date));
                    $label = date('M Y', strtotime($from_date));
                    $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                }
                break;
            case 'quarter4':
                for ($i = 1; $i <= 3; $i++) {
                    $from_date = date('Y-', strtotime(CUR_DATE)) . "$i-01";
                    $to_date = date('Y-m-t', strtotime($from_date));
                    $label = date('M Y', strtotime($from_date));
                    $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                }
                break;
            case 'other':
                $date1 = new DateTime($from);
                $date2 = new DateTime($to);
                $date_diff = $date1->diff($date2);
                //month
                if ($date_diff->days > 30 && date('m', strtotime($from)) != date('m', strtotime($to))) {

                    $start = new DateTime(date('Y-m-', strtotime($from)) . "01");
                    $end = new DateTime(date('Y-m-t', strtotime($to)));

                    $interval = DateInterval::createFromDateString('1 month');
                    $period = new DatePeriod($start, $interval, $end);

                    foreach ($period as $dt) {
                        $from_date = $dt->format("Y-m-") . "01";
                        $to_date = $dt->format("Y-m-t");
                        $label = date('M Y', strtotime($from_date));
                        $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                    }

                } else { //day wise

                    for ($i = $date_diff->days; $i >= 0; $i--) {

                        $from_date = date('Y-m-d', strtotime('-' . $i . ' day', strtotime($to)));
                        $to_date = $from_date;
                        $label = date('d-m-Y', strtotime($from_date));
                        $date_arr[] = (object) array("from" => $from_date, "to" => $to_date, "label" => $label, "value" => "0", "salesvalue" => "0");
                    }
                }
                break;
        }
        return $date_arr;
    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// DASHBOARD //////////////////////////////////////////////// */
    private function dashboard($parent)
    {

        globalfunc::checkMethodType($parent, array('POST'));
        globalfunc::checkParamCount($parent, 1);
        globalfunc::checkAuthrozation($parent, array('type' => 'user'));

        $REQUEST_KEYS = array('period' => 'string', "segment" => "number");
        globalfunc::mandatoryKey($parent, $REQUEST_KEYS);

        $segment = escape_str($parent->_request['segment']);
        $period = escape_str($parent->_request['period']);
        $from = escape_str($parent->_request['from']);
        $to = escape_str($parent->_request['to']);
        $to = date('Y-m-t', strtotime($to));
        $history = escape_str($parent->_request['history']);
        $zmemail = escape_str($parent->_request['zmemail']);
        $rmemail = escape_str($parent->_request['rmemail']);
        $amemail = escape_str($parent->_request['amemail']);
        $dealer_code = escape_str($parent->_request['dealer_code']);
        $smpin = escape_str($parent->_request['smpin']);

        //GET MONTH ARRAY
        $graph = $this->getDateArray($parent, $period, $from, $to);
        $user_cond = "";
        $manager_cond_arr = array();
        switch ($parent->current_user_role) {
            case '3': //HO
                if ($zmemail != 'all' && $zmemail != '') {
                    $manager_cond_arr[] = " d.zm_email='" . $zmemail . "'";
                }
                if ($rmemail != 'all' && $rmemail != '') {
                    $manager_cond_arr[] = " d.rm_email='" . $rmemail . "'";
                }
                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }

                break;
            case '4': //ZM

                $manager_cond_arr[] = " d.zm_email='" . $parent->current_user_data->emailid . "'";

                if ($rmemail != 'all' && $rmemail != '') {
                    $manager_cond_arr[] = " d.rm_email='" . $rmemail . "'";
                }
                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }
                break;
            case '5': //TRAINER
                $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' LIMIT 1";
                $trainer_arr = $parent->getQueryValue($get_trainer_str);
                $zone_cond = (count($trainer_arr) > 0) ? " d.zone='" . $trainer_arr[0]->zone . "'" : " d.zone='0'";

                $manager_cond_arr[] = $zone_cond;
                if ($rmemail != 'all' && $rmemail != '') {
                    $manager_cond_arr[] = " d.rm_email='" . $rmemail . "'";
                }
                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }
                break;
            case '6': //RM

                $manager_cond_arr[] = " d.rm_email='" . $parent->current_user_data->emailid . "'";

                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }
                break;
            case '7': //AM

                $manager_cond_arr[] = " d.am_email='" . $parent->current_user_data->emailid . "'";
                break;
            case '14': //DEALER
                //$user_cond = " AND e.dealer_code='" . $parent->current_user_data->dealer_code . "'";
                $dealer_code = $parent->current_user_data->dealer_code;
                break;
        }

        if (($dealer_code != 'all' && $dealer_code != '') || ($smpin != 'all' && $smpin != '')) {
            if ($dealer_code != 'all' && $dealer_code != '') {
                $user_cond = " AND e.dealer_code='" . $dealer_code . "'";
            }

            if ($smpin != 'all' && $smpin != '') {
                $user_cond = " AND e.smpin='" . $smpin . "'";
            }
            $user_cond .= " AND d.is_deleted='0' AND d.status='1' ";
        } else {
            $manager_cond = (count($manager_cond_arr) > 0) ? " AND " . @implode(" AND ", $manager_cond_arr) : "";
            $user_cond = " AND d.is_deleted='0' AND d.status='1' " . $manager_cond;
        }

        $start_month = date('Y-m-', strtotime($graph[0]->from)) . "01";
        $end_month = date('Y-m-t', strtotime(end($graph)->to));

        $join_table = '';
        if ($history == '1') {
            $join_table = " JOIN " . TABLE_USER . " tu ON tu.smpin=e.smpin ";
        }

        $user_cond .= ($history == '1') ?   " AND tu.status='1' AND tu.is_deleted = 0 AND e.is_current='1'":"";
        switch ($segment) {
            case '1':$user_cond .= " AND e.segment='1'";
                break;
            case '2':$user_cond .= " AND e.segment='2'";
                break;
        }

        //TARGET BASED ON MONTHLY
        $user_target_str = "SELECT COALESCE(SUM(t.target),0) as data_count FROM " . TABLE_USER_SALETARGET . " t JOIN " . DMS_EMPLOYEE . " as e ON e.smpin=t.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND  t.sale_month>='" . date('Y-m-', strtotime($start_month)) . "' AND t.sale_month<='" . date('Y-m-t', strtotime($end_month)) . "' " . $user_cond;
        $user_target_arr = $parent->getQueryValue($user_target_str);

        $start_date = date('Y-m-d', strtotime($graph[0]->from));
        $end_date = date('Y-m-d', strtotime(end($graph)->to));
        $user_salesachieve_str = "SELECT COALESCE(SUM(s.sales_count),0) as data_count FROM " . DMS_EMPLOYEE_SALES . " s JOIN " . DMS_EMPLOYEE . " as e ON e.smpin=s.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND  s.sale_date>='" . $start_date . "' AND s.sale_date<='" . $end_date . "' " . $user_cond;
        $user_salesachieve_arr = $parent->getQueryValue($user_salesachieve_str);

        $user_enqachieve_str = "SELECT  COUNT(enq.id) as data_count FROM " . DMS_ENQUIRY_MASTER . " as enq LEFT JOIN " . DMS_EMPLOYEE . " e ON e.smpin=enq.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND enq.is_dms=1 AND  enq.created_on>='" . $start_date . " 00:00:00' AND enq.created_on<='" . $end_date . " 23:59:59' " . $user_cond;
        $user_enqachieve_arr = $parent->getQueryValue($user_enqachieve_str);

        $target_sales = (count($user_target_arr) > 0) ? $user_target_arr[0]->data_count : 0;

        switch ($segment) {
            case '1':$target_enquiry = $target_sales * 5;
                break;
            case '2':$target_enquiry = $target_sales * 3;
                break;
            default:
                //
                $m_user_target_str = "SELECT COALESCE(SUM(t.target),0) as data_count FROM " . TABLE_USER_SALETARGET . " t JOIN " . DMS_EMPLOYEE . " as e ON e.smpin=t.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND  t.sale_month>='" . date('Y-m-', strtotime($start_month)) . "' AND t.sale_month<='" . date('Y-m-t', strtotime($end_month)) . "'  AND e.segment=1 " . $user_cond;
                $m_user_target_arr = $parent->getQueryValue($m_user_target_str);
                $mtarget_sales = (count($m_user_target_arr) > 0) ? $m_user_target_arr[0]->data_count : 0;
                $mtarget_enquiry = $mtarget_sales * 5;
                //
                $s_user_target_str = "SELECT COALESCE(SUM(t.target),0) as data_count FROM " . TABLE_USER_SALETARGET . " t JOIN " . DMS_EMPLOYEE . " as e ON e.smpin=t.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND  t.sale_month>='" . date('Y-m-', strtotime($start_month)) . "' AND t.sale_month<='" . date('Y-m-t', strtotime($end_month)) . "'  AND e.segment=2 " . $user_cond;
                $s_user_target_arr = $parent->getQueryValue($s_user_target_str);
                $starget_sales = (count($s_user_target_arr) > 0) ? $s_user_target_arr[0]->data_count : 0;
                $starget_enquiry = $starget_sales * 3;
                //
                $o_user_target_str = "SELECT COALESCE(SUM(t.target),0) as data_count FROM " . TABLE_USER_SALETARGET . " t JOIN " . DMS_EMPLOYEE . " as e ON e.smpin=t.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND  t.sale_month>='" . date('Y-m-', strtotime($start_month)) . "' AND t.sale_month<='" . date('Y-m-t', strtotime($end_month)) . "'  AND e.segment=0 " . $user_cond;
                $o_user_target_arr = $parent->getQueryValue($o_user_target_str);
                $otarget_sales = (count($o_user_target_arr) > 0) ? $o_user_target_arr[0]->data_count : 0;
                $otarget_enquiry = $otarget_sales * 3;

                $target_enquiry = $mtarget_enquiry + $starget_enquiry + $otarget_enquiry;
                break;
        }

        $achieved_enquiry = (count($user_enqachieve_arr) > 0) ? $user_enqachieve_arr[0]->data_count : 0;
        $achieved_sales = (count($user_salesachieve_arr) > 0) ? $user_salesachieve_arr[0]->data_count : 0;

        //$sale_ratio = "5 : 1";
        switch ($segment) {
            case '1':
            case '2':$sale_ratio = projectfunc::enqratio($achieved_enquiry, $achieved_sales);
                break;
            default:$sale_ratio = '';
                break;
        }

        $hot_str = "SELECT  COUNT(enq.id)  as data_count FROM " . DMS_ENQUIRY_MASTER . " as enq LEFT JOIN " . DMS_EMPLOYEE . " e ON e.smpin=enq.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND enq.is_dms=1 AND enq.status='H' AND enq.created_on>='" . $start_date . " 00:00:00' AND enq.created_on<='" . $end_date . " 23:59:59' AND enq.enquiry_stage NOT IN ('Z','O','P','V') " . $user_cond;
        $hot_arr = $parent->getQueryValue($hot_str);

        $warm_str = "SELECT  COUNT(enq.id)  as data_count FROM " . DMS_ENQUIRY_MASTER . " as enq LEFT JOIN " . DMS_EMPLOYEE . " e ON e.smpin=enq.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND enq.is_dms=1 AND enq.status='W' AND  enq.created_on>='" . $start_date . " 00:00:00' AND enq.created_on<='" . $end_date . " 23:59:59' AND enq.enquiry_stage NOT IN ('Z','O','P','V') " . $user_cond;
        $warm_arr = $parent->getQueryValue($warm_str);

        $cold_str = "SELECT  COUNT(enq.id)  as data_count FROM " . DMS_ENQUIRY_MASTER . " as enq LEFT JOIN " . DMS_EMPLOYEE . " e ON e.smpin=enq.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND enq.is_dms=1 AND enq.status='P' AND  enq.created_on>='" . $start_date . " 00:00:00' AND enq.created_on<='" . $end_date . " 23:59:59' AND enq.enquiry_stage NOT IN ('Z','O','P','V')" . $user_cond;
        $cold_arr = $parent->getQueryValue($cold_str);

        $lost_str = "SELECT  COUNT(enq.id)  as data_count FROM " . DMS_ENQUIRY_MASTER . " as enq LEFT JOIN " . DMS_EMPLOYEE . " e ON e.smpin=enq.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND enq.is_dms=1 AND enq.status='L' AND  enq.created_on>='" . $start_date . " 00:00:00' AND enq.created_on<='" . $end_date . " 23:59:59'  " . $user_cond;
        $lost_arr = $parent->getQueryValue($lost_str);

        $postponed_str = "SELECT  COUNT(enq.id)  as data_count FROM " . DMS_ENQUIRY_MASTER . " as enq LEFT JOIN " . DMS_EMPLOYEE . " e ON e.smpin=enq.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND enq.is_dms=1 AND enq.status='E' AND  enq.created_on>='" . $start_date . " 00:00:00' AND enq.created_on<='" . $end_date . " 23:59:59' AND enq.enquiry_stage NOT IN ('Z','O','P','V')" . $user_cond;
        $postponed_arr = $parent->getQueryValue($postponed_str);

        $hot = (count($hot_arr) > 0) ? $hot_arr[0]->data_count : "0";
        $warm = (count($warm_arr) > 0) ? $warm_arr[0]->data_count : "0";
        $cold = (count($cold_arr) > 0) ? $cold_arr[0]->data_count : "0";
        $lost = (count($lost_arr) > 0) ? $lost_arr[0]->data_count : "0";
        $postponed = (count($postponed_arr) > 0) ? $postponed_arr[0]->data_count : "0";

        $leaddata = (object) array("hot" => $hot, "warm" => $warm, "cold" => $cold, "lost" => $lost, "postponed" => $postponed);

        $enquiry_per = ($target_enquiry > 0) ? round(($achieved_enquiry / $target_enquiry) * 100) : "0";
        $target_per = ($target_sales > 0) ? round(($achieved_sales / $target_sales) * 100) : "0";
        $conversion_per = ($achieved_enquiry > 0) ? round(($achieved_sales / $achieved_enquiry) * 100) : "0";

        // $enquiry_percentage = (object) array("percentage" => $enquiry_per, "zero" => "100");
        // $sales_percentage = (object) array("percentage" => $target_per, "zero" => "100");
        // $conversion_percentage = (object) array("percentage" => $conversion_per, "zero" => "100");

        $enquiry_percentage = (object) array("percentage" => $enquiry_per, "zero" => (100 - $enquiry_per));
        $sales_percentage = (object) array("percentage" => $target_per, "zero" => (100 - $target_per));
        $conversion_percentage = (object) array("percentage" => $conversion_per, "zero" => (100 - $conversion_per));

        //TOTAL COUNT
        $total_emp = "SELECT  COUNT(e.id) as data_count FROM  " . DMS_EMPLOYEE . " e JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 " . $user_cond;
        $total_emp_arr = $parent->getQueryValue($total_emp);

        $productive_str = "SELECT COUNT(DISTINCT e.smpin) as data_count FROM " . DMS_EMPLOYEE_SALES . " t JOIN " . DMS_EMPLOYEE . " as e ON e.smpin=t.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 AND  t.sale_date>='" . date('Y-m-', strtotime($start_month)) . "' AND t.sale_date<='" . date('Y-m-t', strtotime($end_month)) . "' " . $user_cond;
        $productive_arr = $parent->getQueryValue($productive_str);

        $total_emp = (count($total_emp_arr) > 0) ? $total_emp_arr[0]->data_count : "0";
        $pro_emp = (count($productive_arr) > 0) ? $productive_arr[0]->data_count : "0";

        $productivity_per = ($total_emp > 0) ? round(($pro_emp / $total_emp) * 100) : 0;
        $zero_per = 100 - $productivity_per;
        $productivity = (object) array("productivity" => $productivity_per, "zero" => $zero_per);

        if ($parent->current_user_role == '3') //HO
        {
            //ALL INDIA

        } else if ($parent->current_user_role == '4') //ZM
        {
            $dcond = " and d.zm_email='" . $parent->current_user_data->emailid . "'";
        } else if ($parent->current_user_role == '5') //TRAINER
        {
            $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
            $trainer_arr = $parent->getQueryValue($get_trainer_str);
            $dcond = (count($trainer_arr) > 0) ? " AND d.zone='" . $trainer_arr[0]->zone . "'" : ' AND id=0';

        } else if ($parent->current_user_role == '6') //RM
        {
            $dcond = " and d.rm_email='" . $parent->current_user_data->emailid . "'";

        } else if ($parent->current_user_role == '7') //AM
        {
            $dcond = " and d.am_email='" . $parent->current_user_data->emailid . "'";
        } else if ($parent->current_user_role == '14') //Dealer
        {
            $dcond = " and d.dealer_code='" . $parent->current_user_data->dealer_code . "'";
        }
        if ($period == 'other') {
            $REQUEST_KEYS = array('from' => 'date|Y-m-d', 'to' => 'date|Y-m-d');
            globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
            if (strtotime($from) > strtotime($to)) {
                $parent->response(array('response' => 'failed', 'message' => $this->page_data['error2']), 406);
            }
        }

        $dcond .= ($zmemail != 'all' && $zmemail != '') ? " AND d.zm_email='" . $zmemail . "'" : '';
        $dcond .= ($rmemail != 'all' && $rmemail != '') ? " AND d.rm_email='" . $rmemail . "'" : '';
        $dcond .= ($amemail != 'all' && $amemail != '') ? " AND d.am_email='" . $amemail . "'" : '';
        $dcond .= ($dealer_code != 'all' && $dealer_code != '') ? " AND d.dealer_code='" . $dealer_code . "'" : '';
        $dcond .= ($smpin != 'all' && $smpin != '') ? " AND e.smpin='" . $smpin . "'" : '';

        $dcond .= ($segment != '' && $segment > 0) ? " AND e.segment='" . $segment . "'" : "";
        $dcond .= ($history == '1') ?  " AND tu.status='1'  AND tu.is_deleted = 0 AND e.is_current='1'":"";

        $graph_data = array();
        //GET GRAPH VALUE
        foreach ($graph as $key => $value) {
            $data_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER . " enq JOIN " . DMS_EMPLOYEE . " e ON enq.smpin=e.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table, "COUNT(DISTINCT enq.id) enqcount", " enq.is_dms=1 AND enq.is_deleted=0 AND e.status=1 AND d.is_deleted=0  AND enq.created_on>='" . $value->from . " 00:00:00' AND enq.created_on<='" . $value->to . " 23:59:59' " . $dcond, "1");
            //$graph_data[] = " enq.is_dms=1 AND enq.is_deleted=0 AND e.status=1 AND d.is_deleted=0  AND enq.created_on>='" . $value->from . " 00:00:00' AND enq.created_on<='" . $value->to . " 23:59:59' " . $dcond;
            $graph[$key]->value = ($data_arr['nr'] > 0) ? $data_arr['result'][0]->enqcount : "0";

            $data_arr = $parent->selectQuery(DMS_EMPLOYEE_SALES . " s JOIN " . DMS_EMPLOYEE . " as e ON e.smpin=s.smpin JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table, "COALESCE(SUM(s.sales_count),0) as data_count", "d.is_deleted=0 AND e.status=1 AND s.sale_date>='" . $value->from . "' AND s.sale_date<='" . $value->to . "' " . $dcond, "1");

            $graph[$key]->salesvalue = ($data_arr['nr'] > 0) ? $data_arr['result'][0]->data_count : "0";
        }

        $data = array("graph" => $graph, "sale_ratio" => $sale_ratio, "target_enquiry" => $target_enquiry, "achieved_enquiry" => $achieved_enquiry, "target_sales" => $target_sales, "achieved_sales" => $achieved_sales, "leaddata" => $leaddata, "enquiry_percentage" => $enquiry_percentage, "sales_percentage" => $sales_percentage, "conversion_percentage" => $conversion_percentage, "productivity" => $productivity);

        //LOG
        $logstr = 'ENQUIRY REPORT DASHBOARD';
        globalfunc::insertUserLog($parent, $logstr);
        $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* //////////////////////////////////// EXPORT //////////////////////////////////////////////// */
    private function export($parent)
    {
        globalfunc::checkMethodType($parent, array('POST'));
        globalfunc::checkParamCount($parent, 1);
        globalfunc::checkAuthrozation($parent, array('type' => 'user'));

        $REQUEST_KEYS = array('period' => 'string', "segment" => "number");
        globalfunc::mandatoryKey($parent, $REQUEST_KEYS);

        $segment = escape_str($parent->_request['segment']);
        $period = escape_str($parent->_request['period']);

        $from = escape_str($parent->_request['from']);
        $to = escape_str($parent->_request['to']);
        $to = date('Y-m-t', strtotime($to));

        $history = escape_str($parent->_request['history']);
        $zmemail = escape_str($parent->_request['zmemail']);
        $rmemail = escape_str($parent->_request['rmemail']);
        $amemail = escape_str($parent->_request['amemail']);
        $dealer_code = escape_str($parent->_request['dealer_code']);
        $smpin = escape_str($parent->_request['smpin']);

        //Excel class library
        require_once dirname(__FILE__) . '/../../PHPExcel.php';
        require_once dirname(__FILE__) . '/../../PHPExcel/Writer/Excel2007.php';

        $objPHPExcel = new PHPExcel();
        $objPHPExcel->setActiveSheetIndex(0);

        //EXCEL HEADER
        $row += 2;
        $objPHPExcel->getActiveSheet()->SetCellValue('A' . $row, "SALES DASHBOARD");
        $objPHPExcel->getActiveSheet()->mergeCells("A" . $row . ":H" . $row);
        $objPHPExcel->getActiveSheet()->getStyle("A" . $row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle("A" . $row)->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle("A" . $row)->getFont()->setSize(14);

        $row += 2;
        $bordercells_arr = array("A" . $row, "B" . $row, "C" . $row, "D" . $row, "E" . $row, "F" . $row, "G" . $row, "H" . $row, "I" . $row, "J" . $row, "K" . $row, "L" . $row, "M" . $row, "N" . $row, "O" . $row, "P" . $row, "Q" . $row, "R" . $row, "S" . $row, "T" . $row, "U" . $row, "V" . $row, "W" . $row, "X" . $row, "Y" . $row);
        projectfunc::setCellBorder($bordercells_arr, $objPHPExcel);
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);

        //SET HEADER
        $header_arr = array('S.no', 'Segment', 'SMPIN', 'DSE Name', 'DOJ', 'From', 'To', 'No of Enquiry Target', 'No of Enquiry
        Achieved', 'No of follow-up (Call & Visit)', 'No of Test ride', 'No of postponed', 'No of Lost', 'Hot', 'Warm', 'Cold', 'Sales Target', 'Sales Achieved', 'Enquiry Achieved vs. Target', 'Sales Achieved vs. Target', 'Conversion % (Total Sales / Total Enquiries)', 'ZM', 'RM', 'AM', 'Zone');

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth('15');
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth('20');
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth('20');
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth('30');

        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth('30');
        $objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setWidth('30');

        $i = 0;
        foreach ($header_arr as $val) {
            $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $val);
        }

        //GET MONTH ARRAY
        $graph = $this->getDateArray($parent, $period, $from, $to);

        $user_cond = "";
        $manager_cond_arr = array();
        switch ($parent->current_user_role) {
            case '3': //HO
                if ($zmemail != 'all' && $zmemail != '') {
                    $manager_cond_arr[] = " d.zm_email='" . $zmemail . "'";
                }
                if ($rmemail != 'all' && $rmemail != '') {
                    $manager_cond_arr[] = " d.rm_email='" . $rmemail . "'";
                }
                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }

                break;
            case '4': //ZM

                $manager_cond_arr[] = " d.zm_email='" . $parent->current_user_data->emailid . "'";

                if ($rmemail != 'all' && $rmemail != '') {
                    $manager_cond_arr[] = " d.rm_email='" . $rmemail . "'";
                }
                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }
                break;
            case '5': //TRAINER
                $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' LIMIT 1";
                $trainer_arr = $parent->getQueryValue($get_trainer_str);
                $zone_cond = (count($trainer_arr) > 0) ? " d.zone='" . $trainer_arr[0]->zone . "'" : " d.zone='0'";

                $manager_cond_arr[] = $zone_cond;
                if ($rmemail != 'all' && $rmemail != '') {
                    $manager_cond_arr[] = " d.rm_email='" . $rmemail . "'";
                }
                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }
                break;
            case '6': //RM

                $manager_cond_arr[] = " d.rm_email='" . $parent->current_user_data->emailid . "'";

                if ($amemail != 'all' && $amemail != '') {
                    $manager_cond_arr[] = " d.am_email='" . $amemail . "'";
                }
                break;
            case '7': //AM

                $manager_cond_arr[] = " d.am_email='" . $parent->current_user_data->emailid . "'";
                break;
            case '14': //DEALER
                //$user_cond = " AND e.dealer_code='" . $parent->current_user_data->dealer_code . "'";
                $dealer_code = $parent->current_user_data->dealer_code;
                break;
        }

        if (($dealer_code != 'all' && $dealer_code != '') || ($smpin != 'all' && $smpin != '')) {
            if ($dealer_code != 'all' && $dealer_code != '') {
                $user_cond = " AND e.dealer_code='" . $dealer_code . "'";
            }

            if ($smpin != 'all' && $smpin != '') {
                $user_cond = " AND e.smpin='" . $smpin . "'";
            }
            $user_cond .= " AND d.is_deleted='0' AND d.status='1' ";
        } else {
            $manager_cond = (count($manager_cond_arr) > 0) ? " AND " . @implode(" AND ", $manager_cond_arr) : "";
            $user_cond = " AND d.is_deleted='0' AND d.status='1' " . $manager_cond;
        }

        if($period == '7days') {
            $start_month = date('Y-m-d', strtotime($graph[0]->from));
            $end_month = date('Y-m-d', strtotime(end($graph)->to));
        }
        else {
            $start_month = date('Y-m-', strtotime($graph[0]->from)) . "01";
            $end_month = date('Y-m-t', strtotime(end($graph)->to));
        }

        $start_date = $graph[0]->from;
        $end_date = end($graph)->to;

        $join_table = '';
        if ($history == '1') {
            $join_table = " JOIN " . TABLE_USER . " tu ON tu.smpin=e.smpin ";
        }

        $user_cond .= ($history == '1') ?   " AND tu.status='1'  AND tu.is_deleted = '0' AND e.is_current='1' ":"";
        switch ($segment) {

            case '1':$user_cond .= " AND e.segment='1'";
                break;
            case '2':$user_cond .= " AND e.segment='2'";
                break;
        }

        $user_str = "SELECT e.*,d.zm_name,d.rm_name,d.am_name,d.zone FROM  " . DMS_EMPLOYEE . " as e  JOIN " . DMS_DEALER . " d ON d.dealer_code=e.dealer_code " . $join_table . " WHERE d.is_deleted=0 AND e.status=1 " . $user_cond;

        $user_arr = $parent->getQueryValue($user_str);

        if (count($user_arr) > 0) {

            foreach ($user_arr as $mkey => $res_user) {
                $i = 0;
                $row++;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, ($mkey + 1));

                switch ($res_user->segment) {
                    case "1":$segment_str = "Parents/Guardian";
                        break;
                    case "2":$segment_str = "Instructor";
                        break;
                    default:$segment_str = "Student Learner";
                        break;
                }

                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $segment_str);
                $objPHPExcel->getActiveSheet()->getStyle('C' . $row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $res_user->smpin);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $res_user->fname . " " . $res_user->lname);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, date('d M Y', strtotime($res_user->date_of_join)) );

                $start_month_str = date('d M Y', strtotime($start_month));
                $end_month_str = date('d M Y', strtotime($end_month));

                if (strtotime($end_date) > strtotime(CUR_DATE)) {
                    $end_month_str = date('d M Y', strtotime(CUR_DATE));
                }

                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $start_month_str);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $end_month_str);

                $smpin = $res_user->smpin;
                $query_target = $parent->getQueryValue("SELECT COALESCE(SUM(target),0) as total_target FROM " . TABLE_USER_SALETARGET . "  WHERE  smpin='" . $res_user->smpin . "'   AND sale_month>='" . date('Y-m-', strtotime($start_month)) . "-01' AND sale_month<='" . date('Y-m-t', strtotime($end_month)) . "'  LIMIT 1");
                $sale_target = (count($query_target) > 0) ? (string) $query_target[0]->total_target : 0;

                switch ($res_user->segment) {
                    case "1":$enquiry_target = $sale_target * 5;
                        break;
                    case "2":$enquiry_target = $sale_target * 3;
                        break;
                    default:$enquiry_target = $sale_target * 3;
                        break;
                }

                //$enquiry_target = $sale_target * 3;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $enquiry_target);

                $achieved_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0", "1");
                $enquiry_achieved = ($achieved_arr['nr'] > 0) ? $achieved_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $enquiry_achieved);

                //$q = " smpin='" . $smpin . "' AND created_on>'" . $start_date . " 00:00:00' AND created_on<'" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0";
                // $parent->executeQuery("INSERT INTO `" . TABLE_QUERY_LOG . "`(  `query_str`, `query_type`, `created_on`) VALUES ('" . escape_str($q) . "', 'vishnu20210204', '" . NOW . "')");

                $callvisit_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0  AND modeofcontact IN ('E','F','O','T','S','V') ", "1");
                $callvisit = ($callvisit_arr['nr'] > 0) ? $callvisit_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $callvisit);

                $testride_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0  AND enquiry_stage IN ('T') ", "1");
                $testride = ($testride_arr['nr'] > 0) ? $testride_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $testride);

                $postponed_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0  AND status='E' AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
                $postponed = ($postponed_arr['nr'] > 0) ? $postponed_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $postponed);

                $lost_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0  AND status='L' ", "1");
                $lost = ($lost_arr['nr'] > 0) ? $lost_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $lost);

                $hot_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0  AND status='H' AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
                $hot = ($hot_arr['nr'] > 0) ? $hot_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $hot);

                $warm_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0  AND status='W' AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
                $warm = ($warm_arr['nr'] > 0) ? $warm_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $warm);

                $cold_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on>='" . $start_date . " 00:00:00' AND created_on<='" . $end_date . " 23:59:59'  AND is_dms=1 AND is_deleted=0  AND status='P' AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
                $cold = ($cold_arr['nr'] > 0) ? $cold_arr['result'][0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $cold);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $sale_target);

                $user_sale = $parent->getQueryValue("SELECT SUM(sales_count) as data_count FROM " . DMS_EMPLOYEE_SALES . "  WHERE smpin='" . $smpin . "' AND sale_date>='" . $start_date . "' AND sale_date<='" . $end_date . "' LIMIT 1");
                $sales_achieved = (count($user_sale) > 0 && $user_sale[0]->data_count > 0) ? $user_sale[0]->data_count : 0;
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $sales_achieved);

                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $enquiry_achieved . "/" . $enquiry_target);
                $objPHPExcel->getActiveSheet()->getStyle('R' . $row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $sales_achieved . "/" . $sale_target);
                $objPHPExcel->getActiveSheet()->getStyle('S' . $row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                $sale_ratio = projectfunc::enqratio($enquiry_achieved, $sales_achieved);

                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $sale_ratio);
                $objPHPExcel->getActiveSheet()->getStyle('T' . $row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                /*  'Enquiry Achieved vs. Target', 'Sales Achieved vs. Target', 'Conversion % (Total Sales / Total Enquiries)', 'ZM', 'RM', 'AM'
                 */
                //d.zm_name,d.rm_name,d.am_name
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $res_user->zm_name);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $res_user->rm_name);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $res_user->am_name);
                $objPHPExcel->getActiveSheet()->SetCellValue(getColumnFromNumber($i++) . $row, $res_user->zone);


            }
        }

        //LOG
        $logstr = 'SALES DASHBOARD EXPORT';
        globalfunc::insertUserLog($parent, $logstr);

        $objPHPExcel->getActiveSheet()->setTitle('SALES DASHBOARD');
        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        $fpath = "../../" . S3_REPORT_URL;
        $filename = "enquiry_report_" . uniqid() . ".xlsx";
        $objWriter->save($fpath . $filename);

        //CONNECT S3
        $s3 = awsfileserver::connectS3();
        awsfileserver::checkupload($parent, $s3, S3_BUCKET, S3_REPORT_URL . $filename, dirname(__FILE__) . "/../../../" . S3_REPORT_URL . $filename);
        //delete report
        @unlink(dirname(__FILE__) . "/../../../" . S3_REPORT_URL . $filename);
        $filename = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_REPORT_URL . $filename);
        $parent->response(array('response' => 'success', 'data' => $filename, 'message' => $this->page_data['success1']), 200);

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */
}
