setDBO(VoxelCareDB::getDatabase()); }//function function SetId($id) { $this->_id = (int)$id; $this->_item = null; } function storeByFranchise(&$data) { $table =& $this->getTable('franchiseagency'); $table->reset(); $id = (int)$data['id']; $table->load($id); if (!$table->bind($data)) return false; if (!$table->check()) return false; if (!$table->store(true)) return false; $data['id'] = $this->_id; return true; } function store(&$data) { $table =& $this->getTable('agency'); $db =& $this->_db; $table->reset(); $id = (int)$data['id']; $table->load($id); if (!$table->bind($data)) return false; if (!$table->check()) return false; if (!$table->store(true)) return false; $this->SetId($table->id); $data['id'] = $this->_id; return true; } function getData($userId =0) { if (empty($this->_item)) { $db =& $this->_db; if ($userId==0) { $userId = LegacyHelper::getUserId(); } $sql = "SELECT a.id id, a.name name, fa.description description, fa.price price, fa.vat vat FROM #__vxc_agency a LEFT JOIN #__vxc_userfranchise uf ON uf.userid = ".$userId." LEFT JOIN #__vxc_franchiseagency fa ON fa.agency = a.id AND fa.franchise = uf.franchise WHERE a.id =".$this->_id; $db->setQuery($sql); $row = $db->loadObject(); if (!$row) { $row = new stdClass(); $row->id = 0; } if (!$row->price) $row->price = 0; if (!$row->vat) $row->vat = 0; $this->_item = $row; } return $this->_item; } function getOrders() { $sql = "SELECT o.id id, o.reference reference, os.name statename, os.nameid statenameid, CONCAT_WS(' ',NULLIF(c.name,''),NULLIF(c.middlename,''),NULLIF(c.surname,'')) customerfullname FROM #__vxc_order o LEFT JOIN #__vxc_orderstate os ON os.id = o.state LEFT JOIN #__vxc_customer c ON c.id = o.customer WHERE o.deleted is not true and o.batch = ".$this->_id; $this->_db->setQuery($sql); return $this->_db->loadObjectList(); } function deleteByFranchise($id) { if (!$id) return; $sql = "DELETE FROM #__vxc_franchiseagency WHERE id = ". $id; $this->_db->Execute($sql); } function SetStateName($state) { $data = array(); $data['id'] = $this->_id; $modelBatchStates = new vxcModelBatchStates(); $data['state'] = $modelBatchStates->getIdFromName($state); if ($state=='SHIPPED') { $dateNow = new JDate(); $data['shipping_date'] = $dateNow->toMySQL(); } $this->store($data); } function UpdateState() { $item =& $this->getData(); if ($item->statenameid=='SHIPPED') return; $orders = $this->getOrders(); $allmanufactured = true; foreach($orders as $order) if ($order->statenameid != 'MANUFACTURED') { $allmanufactured= false; break; } if ($allmanufactured) $state ='COMPLETED'; else $state ='INCOMPLETED'; if ($state!=$item->statenameid) { $this->SetStateName($state); } } function getShippingCostInfo(&$modelUser, $orderCount) { $price = 0; $vat = 0; $franchiseName = SiteOptionsHelper::getFranchiseName(); $userShippingVAT = $modelUser->getShippingVAT(); $agencyData = $this->getData($modelUser->GetId()); if ($agencyData && $agencyData->price!==null) { if (!($franchiseName == "tecnoinsole" && $orderCount>=3)) $price = $agencyData->price; $vat = ($userShippingVAT!==null) ? $userShippingVAT : $agencyData->vat; } return array('price'=> $price, 'vat'=> $vat); } }// class