/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the primary key value. Defaults to null, meaning using the 'id' GET variable */ public function loadAccountType($id = null) { if ($this->_model === null) { if ($id !== null || isset($_GET['id'])) { $this->_model = AccountType::model()->findbyPk($id !== null ? $id : $_GET['id']); } if ($this->_model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } } return $this->_model; }
/** * @return array Errors Export Account information */ public static function ExportAccounts() { $comp = Company::model()->findbyPk(Yii::app()->user->getState('selectedCompanyId')); // set headers header("Pragma: no-cache"); header("Expires: 0"); header("Content-Description: File Transfer"); header("Content-Type: text/xml"); header("Content-Disposition: attachment; filename=\"lazy8web.accounts." . CompanyController::replace_bad_filename_chars($comp->name) . "." . date('Y-m-d_H.i.s') . ".xml\""); header("Content-Transfer-Encoding: binary"); //header("Content-Length: " ); $writer = new XMLWriter(); // Output directly to the user $writer->openURI('php://output'); $writer->startDocument('1.0', 'utf-8'); $writer->setIndent(4); $writer->startElement('lazy8webportaccount'); $writer->writeAttribute('version', '1.00'); $accountTypes = AccountType::model()->findAll(array('condition' => 'companyId=' . Yii::app()->user->getState('selectedCompanyId'))); foreach ($accountTypes as $accountType) { $writer->startElement('accounttype'); $writer->writeAttribute("code", $accountType->code); $writer->writeAttribute("name", $accountType->name); $writer->writeAttribute("sortorder", $accountType->sortOrder); $writer->writeAttribute("isinbalance", $accountType->isInBalance); $accounts = Account::model()->findAll(array('condition' => 'companyId=' . Yii::app()->user->getState('selectedCompanyId') . ' AND accountTypeId=' . $accountType->id)); foreach ($accounts as $account) { $allAccounts[$account->id] = $account->code; $writer->startElement('account'); $writer->writeAttribute("code", $account->code); $writer->writeAttribute("name", $account->name); $writer->writeAttribute("email", $account->email); $writer->writeAttribute("balance_threshold", $account->balance_threshold); $writer->writeAttribute("days", $account->days); $writer->writeAttribute("report_id", $account->report_id); $writer->endElement(); } $writer->endElement(); } $writer->endElement(); $writer->endDocument(); $writer->flush(); return; //we may not send any more to the screen or it will mess up the file we just sent! }
<!-- <div id="legend"> <strong>Report Type Legend </strong><br /> Account Balance = 17 <br /> Project Expense = 16 <br /> Account Summary (default) = 3<br /> Account Summary (reconciled) = 14 <br /> </div> --> <?php } ?> <div class="simple"> <?php echo CHtml::activeLabelEx($model, 'accountTypeId', array('class' => 'help', 'title' => Yii::t('lazy8', 'contexthelp.accountTypeId'), 'onclick' => 'alert(this.title)')); echo CHtml::activeDropDownList($model, 'accountTypeId', CHtml::listData(AccountType::model()->findAll(array('order' => 'isInBalance DESC, sortOrder', 'condition' => 'companyId=' . Yii::app()->user->getState('selectedCompanyId'))), 'id', 'name'), array('onchange' => 'check(\'AccountEmail\');')); ?> </div> <?php if ($update) { ?> <center> <div class="selectTag" style="width: 90%;margin: 1em;"> <div style="font-weight: bold;text-align: center;margin-bottom: 1em;">Add a tag to this account: </div> <div class="tagList" style="float: left;margin-bottom: 1em;"> <?php echo CHtml::dropDownList('AddTagToAccount', 'customerId', CHtml::encodeArray(CHtml::listData(Customer::model()->findAll(array('condition' => 'companyId=' . Yii::app()->user->getState('selectedCompanyId'), 'select' => 'id, CAST(CONCAT(code, ": " ,name) AS CHAR CHARACTER SET utf8) as name', 'order' => 'code')), 'id', 'name'))); ?>
private function exportCompany($companyId = null) { $compName = "AllCompanies"; if ($companyId != null) { $compName = CompanyController::replace_bad_filename_chars(Company::model()->findbyPk($companyId)->name); } // set headers header("Pragma: no-cache"); header("Expires: 0"); header("Content-Description: File Transfer"); header("Content-Type: text/xml"); header("Content-Disposition: attachment; filename=\"lazy8webExport.Company." . $compName . "." . date('Y-m-d_H.i.s') . ".xml\""); header("Content-Transfer-Encoding: binary"); //safari can't deal with this header length zero // header("Content-Length: " ); $writer = new XMLWriter(); // Output directly to the user //dirname(__FILE__).DIRECTORY_SEPARATOR.'../..'.'/assets/upload.sql' $writer->openURI('php://output'); $writer->startDocument('1.0', 'utf-8'); $writer->setIndent(4); $writer->startElement('lazy8webport'); $writer->writeAttribute('version', '1.00'); $companies = array(); if (isset($companyId)) { $companies[] = Company::model()->findbyPk($companyId); } else { $companies = Company::model()->findAll(array('order' => 'code')); } foreach ($companies as $company) { ChangeLog::addLog('OTHER', 'Company', 'Exported company ' . $company->toString()); $writer->startElement('company'); $writer->writeAttribute("code", $company->code); $writer->writeAttribute("name", $company->name); $writer->writeAttribute("lastAbsTransNum", $company->lastAbsTransNum); $allAccounts = array(); $accountTypes = AccountType::model()->findAll(array('condition' => 'companyId=' . $company->id, 'order' => 'code')); foreach ($accountTypes as $accountType) { $writer->startElement('accounttype'); $writer->writeAttribute("code", $accountType->code); $writer->writeAttribute("name", $accountType->name); $writer->writeAttribute("sortorder", $accountType->sortOrder); $writer->writeAttribute("isinbalance", $accountType->isInBalance); $accounts = Account::model()->findAll(array('condition' => 'companyId=' . $company->id . ' AND accountTypeId=' . $accountType->id, 'order' => 'code')); foreach ($accounts as $account) { $allAccounts[$account->id] = $account->code; $writer->startElement('account'); $writer->writeAttribute("code", $account->code); $writer->writeAttribute("name", $account->name); $writer->endElement(); } $writer->endElement(); } $customers = Customer::model()->findAll(array('condition' => 'companyId=' . $company->id, 'order' => 'code')); $allCustomers = array(); foreach ($customers as $customer) { $writer->startElement('customer'); $allCustomers[$customer->id] = $customer->code; $writer->writeAttribute("code", $customer->code); $writer->writeAttribute("name", $customer->name); $writer->writeAttribute("desc", $customer->desc); if (isset($allAccounts[$customer->accountId])) { $writer->writeAttribute("accountcode", $allAccounts[$customer->accountId]); } else { $writer->writeAttribute("accountcode", 0); } $writer->endElement(); } $periods = Period::model()->findAll(array('condition' => 'companyId=' . $company->id, 'order' => 'dateStart')); foreach ($periods as $period) { $writer->startElement('period'); $writer->writeAttribute("datestart", $period->dateStart); $writer->writeAttribute("dateend", $period->dateEnd); $writer->writeAttribute("lastperiodtransnum", $period->lastPeriodTransNum); $transactions = Trans::model()->findAll(array('condition' => 'companyId=' . $company->id . ' AND periodId=' . $period->id, 'order' => 'companyNum')); foreach ($transactions as $transaction) { $writer->startElement('transaction'); $writer->writeAttribute("code", $transaction->companyNum); $writer->writeAttribute("periodnum", $transaction->periodNum); $writer->writeAttribute("regdate", $transaction->regDate); $writer->writeAttribute("invdate", $transaction->invDate); $writer->writeAttribute("notes", $transaction->notes); $writer->writeAttribute("fileinfo", $transaction->fileInfo); $transrows = TransRow::model()->findAll(array('condition' => 'transId=' . $transaction->id, 'order' => 'amount DESC')); foreach ($transrows as $transrow) { $writer->startElement('amount'); $writer->writeAttribute("accountcode", isset($allAccounts[$transrow->accountId]) ? $allAccounts[$transrow->accountId] : 0); $writer->writeAttribute("customercode", isset($allCustomers[$transrow->customerId]) ? $allCustomers[$transrow->customerId] : 0); $writer->writeAttribute("notes", $transrow->notes); $writer->writeAttribute("amount", $transrow->amount); $writer->endElement(); } $writer->endElement(); } $writer->endElement(); } yii::app()->onExport(new Lazy8Event(array('exportobject' => 'Company', 'writer' => $writer), $company->id)); $writer->endElement(); } $writer->endElement(); $writer->endDocument(); $writer->flush(); return; //we may not send any more to the screen or it will mess up the file we just sent! }