Esempio n. 1
0
 public function getBillingAddress($user_id = 0)
 {
     $helper = new redhelper();
     $option = JRequest::getVar('option');
     $user = JFactory::getUser();
     // Get Joomla Session
     $session = JFactory::getSession();
     // Get redCRM Contact person session array
     $isredcrmuser = $session->get('isredcrmuser', false);
     $list = array();
     if ($user_id == 0) {
         $user_id = $user->id;
     }
     if ($helper->isredCRM()) {
         $crmHelper = new crmHelper();
         $crmDebitorHelper = new crmDebitorHelper();
         $cp_user_id = $user_id;
         /*
          * function will check loign redshop user
          * is redCRM contact person or not
          *
          * @return: joomla user of redSHOP billing user belong to contact person
          */
         $crmusers = $crmHelper->getBillingUserId($user_id);
         if (isset($crmusers->user_id)) {
             $user_id = $crmusers->user_id;
         }
         $query = 'SELECT ui.*,CONCAT(firstname," ",lastname) AS text,d.*,ui.users_info_id FROM ' . $this->_table_prefix . 'users_info as ui ' . 'LEFT JOIN ' . $this->_table_prefix_crm . 'debitors as d ON d.users_info_id = ui.users_info_id ' . 'WHERE address_type like "BT" ' . 'AND user_id = ' . (int) $user_id;
         $this->_db->setQuery($query);
         $list = $this->_db->loadObject();
         if ($isredcrmuser) {
             $contact_person = $crmDebitorHelper->getContactPersons(0, 0, 0, $cp_user_id);
             if (count($contact_person) > 0) {
                 $contact_person = $contact_person[0];
                 $person_name = explode(" ", $contact_person->person_name);
                 $list->firstname = @$person_name[0];
                 $list->lastname = @$person_name[1];
                 $list->text = $contact_person->person_name;
                 $list->user_email = $contact_person->person_email;
             }
         }
         return $list;
     }
     $query = 'SELECT *,CONCAT(firstname," ",lastname) AS text FROM ' . $this->_table_prefix . 'users_info ' . 'WHERE address_type like "BT" ' . 'AND user_id = ' . (int) $user_id;
     $this->_db->setQuery($query);
     $list = $this->_db->loadObject();
     return $list;
 }