AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.216.59
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_apps/leve/application/plugins/module_crm/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/leve/application/plugins/module_crm/controllers/BusinessController.php
<?php

include_once "Controller.php";
include_once __DIR__ . "/../models/BusinessModel.php";
include_once __DIR__ . "/../models/BusinessContactsModel.php";
include_once __DIR__ . "/../models/BusinessCompaniesModel.php";
include_once __DIR__ . "/../models/BusinessNotesModel.php";
include_once __DIR__ . "/../models/BusinessTypeActivityModel.php";

class BusinessController extends Controller
{
    /**
     * @var ID Business
     */
    protected $id;

    /**
     * @var BusinessModel
     */
    protected $model;

    /**
     * @var BusinessContactsModel
     */
    protected $modelContacts;

    /**
     * @var BusinessCompaniesModel
     */
    protected $modelCompanies;

    /**
     * @var BusinessNotesModel
     */
    protected $modelNotes;

    /**
     * @param $ui
     * @param array $_L
     * @param array $config
     * @param $_pd
     */
    public function __construct($ui, $_L, $config, $_pd)
    {
        parent::__construct($ui, $_L, $config, $_pd);

        $this->ui->assign('_title', $this->_L['CRM_Module'] . ' - ' . $this->config['CompanyName']);

        $this->model          = new BusinessModel();
        $this->modelContacts  = new BusinessContactsModel();
        $this->modelCompanies = new BusinessCompaniesModel();
        $this->modelNotes     = new BusinessNotesModel();

        $this->id = $this->routes[3];
    }

    /**
     * Show list to business
     */
    public function listBusiness()
    {
        // DIRETÓRIO RAIZ DO MÓDULO
        $dir = 'application/plugins/module_crm';

        // LISTA TODOS NEGÒCIOS ATIVOS
        $business = $this->model->all('id', true);
        $this->ui->assign('business', $business);

        // SELECTS PARA O BAR BOTTOM
        // TOTAL DE NEGOCIOS
        $business = $this->model->all('id', true);
        $count_business = count($business);
        $this->ui->assign('bar_total', $count_business);

        // TOTAL DE NEGOCIOS NOVOS
        $bar_new_business = ORM::for_table('module_crm_business')
            ->where('business_phase', 'novo')->where_null('deleted_at')->find_array();
        $count_new_business = count($bar_new_business);
        $this->ui->assign('bar_new_business', $count_new_business);

        // TOTAL DE NEGOCIOS QUALIFICAÇÃO
        $bar_qualification = ORM::for_table('module_crm_business')
            ->where('business_phase', 'qualificacao')->where_null('deleted_at')->find_array();
        $count_qualification = count($bar_qualification);
        $this->ui->assign('bar_qualification', $count_qualification);

        // TOTAL DE NEGOCIOS PROPOSTA
        $bar_proposal = ORM::for_table('module_crm_business')
            ->where('business_phase', 'novo')->where_null('deleted_at')->find_array();
        $count_proposal = count($bar_proposal);
        $this->ui->assign('bar_proposal', $count_proposal);

        // TOTAL DE NEGOCIOS NOVO
        $bar_win = ORM::for_table('module_crm_business')
            ->where('business_phase', 'ganhou')->where_null('deleted_at')->find_array();
        $count_win = count($bar_win);
        $this->ui->assign('bar_win', $count_win);

        // TOTAL DE NEGOCIOS PERDEU
        $bar_lost = ORM::for_table('module_crm_business')
            ->where('business_phase', 'perdeu')->where_null('deleted_at')->find_array();
        $count_lost = count($bar_lost);
        $this->ui->assign('bar_lost', $count_lost);

        // TOTAL DE NEGOCIOS FECHAMENTO
        $bar_closing = ORM::for_table('module_crm_business')
            ->where('business_phase', 'fechamento')->where_null('deleted_at')->find_array();
        $count_closing = count($bar_closing);
        $this->ui->assign('bar_closing', $count_closing);

        $this->ui->assign('xheader', '<link rel="stylesheet" type="text/css" href="'.$dir.'/assets/css/bottom_bar.css"/>');
        $this->ui->assign('xfooter', '<script type="text/javascript" src="' . $dir . '/assets/js/bottom_bar.js">');
        $this->ui->assign('dir', $dir);

        $this->ui->assign('_st', $this->_L['CRM_New_Business']);
        $this->ui->assign('_include', 'business/' . __FUNCTION__);
        $this->ui->display('wrapper.tpl');
    }

    /**
     * Show form to add business
     */
    public function add()
    {
        // CARREGA CSS E JS'S
        $css_arr = array('s2/css/select2.min','dp/dist/datepicker.min');
        $js_arr = array(
            's2/js/select2.min',
            'dp/dist/datepicker.min',
            'numeric',
            '/../../theme/lrsys/lib/jquery.maskMoney.min',
            's2/js/select2.min'
        );
        $assets_css = Asset::css($css_arr);
        $assets_js = Asset::js($js_arr);

        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js . '<script type="text/javascript" src="application/plugins/module_crm/assets/js/default.js">');

        //CARREGA A LISTA DE MOEDAS
        $currencies = ORM::for_table('sys_currencies')->order_by_asc('id')->find_many();
        $this->ui->assign('currencies', $currencies);

        // DEFININDO LAYOUT PADRÃO, TÍTULO
        $this->ui->assign('_st', $this->_L['CRM_New_Business']);
        $this->ui->assign('_include', 'business/' . __FUNCTION__);
        $this->ui->display('wrapper.tpl');
    }

    public function create()
    {
        $data = $_POST;

        if ($data['expected_at'] == '') {
            $data['expected_at'] = NULL;
        } else {
            $especifica = new DateTime($data['expected_at']);
            $data['expected_at'] = $especifica->format('Y-m-d');
        }

        if ($data['account_id'] == '')
            $data['account_id'] = NULL;

        if ($data['price'] == '')
            $data['price'] = NULL;

        $data['status'] = (int) !empty($data['status']) && $data['status'] == 'on';
        $idBusiness = $this->model->createBusiness($data);

        if ($data['contacts_id'] != '') {
            foreach ($data['contacts_id'] as $c) {
                $data_contacts = array(
                    'account_id'  => $c,
                    'business_id' => $idBusiness->id
                );

                $this->modelContacts->createBusinessContacts($data_contacts);
            }
        }

        if ($data['companies_id'] != '') {
            foreach ($data['companies_id'] as $cia) {
                $data_companies = array(
                    'companies_id'  => $cia,
                    'business_id' => $idBusiness->id
                );

                $this->modelCompanies->createBusinessCompany($data_companies);
            }
        }

        $this->ui->assign('_st', $this->_L['CRM_Business_Save']);
        r2(U . 'module_crm/business/listBusiness', 's', $this->_L['CRM_Business_Save']);
    }

    /**
     * Show form to edit category
     */
    public function edit()
    {
        // BUSCA O ID NA ROTA
        if (empty($this->routes[3]) || !is_numeric($this->routes[3])) {
            die($this->_L['Id_Required']);
        }

        // ARMAZENA O ID
        $this->id = $this->routes[3];
        // ASSINA O ID NA VIEW
        $this->ui->assign('id', $this->id);

        // SELECIONA DO NEGÓCIO
        $business = $this->model->getOne($this->id);

        // SE NÃO EXISTIR O NEGÓCIO
        if (!$business) {
            die($this->_L['Not_Found']);
        }

        // ESPECIFICA E CONVERTE A DATA
        $especifica = new DateTime($business->expected_at);
        $business->expected_at= $especifica->format('d-m-Y');

        //CARREGA O NEGOCIO
        $this->ui->assign('business', $business);

        //CARREGA A LISTA DE MOEDAS
        $currencies = ORM::for_table('sys_currencies')->order_by_asc('id')->find_many();
        $this->ui->assign('currencies', $currencies);

        //CARREGA OS TIPOS DE ATIVIDADES
        $type_activity = ORM::for_table('module_crm_business_type_activity')->order_by_asc('id')->find_array();
        $this->ui->assign('type_activity', $type_activity);

        // CARREGA OS IDS DOS CONTATOS PARA POPULAR O
        // SELECT2 DOS CONTATOS RELACIONADOS AO NEGÓCIO
        $business_contacts = ORM::for_table('module_crm_business_contacts')
            ->table_alias('c')
            ->select('c.*')
            ->select('u.account')
            ->join('crm_accounts', array('u.id', '=', 'c.account_id'), 'u')
            ->join('module_crm_business', array('b.id', '=', 'c.business_id'), 'b')
            ->where('c.business_id', $this->id)
            ->order_by_asc('c.id')->find_array();
        $this->ui->assign('contacts', $business_contacts);

        // CARREGA OS IDS DAS EMPRESAS PARA POPULAR O
        // SELECT2 DAS EMPRESAS RELACIONADAS AO NEGÓCIO
        $business_companies = ORM::for_table('module_crm_business_companies')
            ->table_alias('bc')
            ->select('bc.*')
            ->select('cia.account')
            ->join('crm_accounts', array('cia.id', '=', 'bc.companies_id'), 'cia')
            ->join('module_crm_business', array('b.id', '=', 'bc.business_id'), 'b')
            ->where('bc.business_id', $this->id)
            ->order_by_asc('bc.id')->find_array();
        $this->ui->assign('companies', $business_companies);

        // CARREGA OS IDS DOS CONTATOS PARA POPULAR O
        // SELECT2 DOS RESPONSÁVEIS RELACIONADOS AO NEGÓCIO
        $business_account = ORM::for_table('module_crm_business')
            ->table_alias('b')
            ->select('b.*')
            ->select('u.account')
            ->join('crm_accounts', array('u.id', '=', 'b.account_id'), 'u')
            ->where('b.id', $this->id)
            ->order_by_asc('b.id')->find_array();
        $this->ui->assign('account', $business_account);

        // CARREGA CSS E JS'S
        $css_arr = array(
            's2/css/select2.min',
            'dp/dist/datepicker.min',
            'ibilling/clockpicker/clockpicker',
        );

        $js_arr = array(
            's2/js/select2.min',
            'dp/dist/datepicker.min',
            'ibilling/clockpicker/clockpicker',
            'numeric',
            '/../../theme/lrsys/lib/jquery.maskMoney.min',
            's2/js/select2.min',
            '/../../../application/plugins/module_crm/assets/js/default',
            '/../../../application/plugins/module_crm/assets/js/edit'
        );
        $assets_css = Asset::css($css_arr);
        $assets_js = Asset::js($js_arr);

        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js);

        // DEFININDO LAYOUT PADRÃO, TÍTULO
        $this->ui->assign('_st', $this->_L['CRM_Module'] . ' - ' . $this->_L['CRM_Edit_Business']);
        $this->ui->assign('_include', 'business/' . __FUNCTION__);
        $this->ui->display('wrapper.tpl');
    }

    public function update()
    {
        $business = $this->validateBusiness();

        if ($this->data['expected_at'] == '') {
            $this->data['expected_at'] = NULL;
        } else {
            $especifica = new DateTime($this->data['expected_at']);
            $this->data['expected_at'] = $especifica->format('Y-m-d');
        }

        if ($this->data['account_id'] == '')
            $this->data['account_id'] = NULL;

        if ($this->data['price'] == '')
            $this->data['price'] = NULL;

        // VERIFICA CONTATO SE FOI EXCLUIDO
//        $this->verifyBusinessContacts($this->id, $this->data['contacts_id']);

        $this->data['status'] = (int) !empty($this->data['status']) && $this->data['status'] == 'on';
        $this->model->updateBusiness($this->data, $business);

        $this->ui->assign('_st', $this->_L['CRM_Edit_Business']);
        r2(U . 'module_crm/business/listbusiness', 's', $this->_L['CRM_Business_Edit']);
        $this->ui->display('wrapper.tpl');
    }

    public function notes()
    {
        if (empty($this->routes[3]) || !is_numeric($this->routes[3])) {
            die($this->_L['Id_Required']);
        }

        $this->id = $this->routes[3];

        $data = $_POST;

        if ($data) {
            $data['business_id'] = $this->id;

            $this->modelNotes->createBusinessNotes($data);

            $this->ui->assign('_st', $this->_L['CRM_Category_Save']);
            r2(U . 'module_crm/business/edit/' . $this->id, 's', $this->_L['CRM_Business_Note_Save']);
        } else {
            r2(U . 'module_crm/business/edit/' . $this->id, 's', $this->_L['CRM_Business_Save']);
        }
    }

    public function delete()
    {
        $business = $this->validateBusiness();
        $this->model->deleteBusiness($business);
        r2(U . 'module_crm/business/listBusiness', 's', $this->_L['CRM_Business_Delete']);
    }

    /**
     * @return ORM
     */
    protected function validateBusiness()
    {
        $this->data = $_POST;

        if (empty($this->data['id']) || !is_numeric($this->data['id'])) {
            die($this->_L['Id_Required']);
        }

        $business = $this->model->getOne($this->data['id']);

        if (!$business) {
            die($this->_L['Not_Found']);
        }

        return $business;
    }

    /**
     * @return ORM
     */
    protected function verifyBusinessContacts($business_id, $contacts_id)
    {
        if ($contacts_id != '') {
//            foreach ($data['contacts_id'] as $c) {
//                $data_contacts = array(
//                    'account_id'  => $c,
//                    'business_id' => $idBusiness->id
//                );
//
//                $this->modelContacts->createBusinessContacts($data_contacts);
//            }
        } else {
            die('teste');
            $this->modelContacts->deleteBusinessContacts($business_id);
        }

//        return $business;
    }
}

Anon7 - 2022
AnonSec Team