private function updateParameters($model) { if ($model->reportparameters !== null && count($model->reportparameters) > 0) { $repParams = $model->reportparameters; foreach ($repParams as $n => $repParam) { //see if there is new data to be added.. if ($_POST['ReportParameters'][$n]) { $repParam->attributes = $_POST['ReportParameters'][$n]; //this is a bug in yii that requires me to do the next row $repParam->defaultValue = $_POST['ReportParameters'][$n]['defaultValue']; $repParam->isDefaultPhp = $_POST['ReportParameters'][$n]['isDefaultPhp']; $repParam->phpSecondaryInfo = $_POST['ReportParameters'][$n]['phpSecondaryInfo']; $repParam->dataType = $_POST['ReportParameters'][$n]['dataType']; //echo $repParam->dataType . ' ' . $_POST['ReportParameters'][$n]['dataType']; //die(); $repParam->save(); } } } if ($model->rows !== null && count($model->rows) > 0) { $repRows = $model->rows; foreach ($repRows as $n => $repRow) { $repRow->attributes = $_POST['ReportRows'][$n]; $repRow->save(); } } if ($model->groups !== null && count($model->groups) > 0) { $repGroups = $model->groups; foreach ($repGroups as $n => $repGroup) { //see if there is new data to be added.. if ($_POST['ReportGroups'][$n]) { $repGroup->attributes = $_POST['ReportGroups'][$n]; $repGroup->save(); if ($repGroup->fields !== null && count($repGroup->fields) > 0) { $repGroupFields = $repGroup->fields; foreach ($repGroupFields as $m => $repGroupField) { //see if there is new data to be added.. $repGroupField->attributes = $_POST['ReportGroupFields'][$n][$m]; //$repGroupField->sortOrder=$_POST['ReportGroupFields'][$n]['sortOrder'][$m]; //$repGroupField->fieldName=$_POST['ReportGroupFields'][$n]['fieldName'][$m]; //$repGroupField->fieldWidth=$_POST['ReportGroupFields'][$n]['fieldWidth'][$m]; //$repGroupField->row=$_POST['ReportGroupFields'][$n]['row'][$m]; //$repGroupField->isDate=$_POST['ReportGroupFields'][$n]['isDate'][$m]; //$repGroupField->isDecimal=$_POST['ReportGroupFields'][$n]['isDecimal'][$m]; //$repGroupField->fieldCalc=$_POST['ReportGroupFields'][$n]['fieldCalc'][$m]; $repGroupField->save(); } } } } } if (isset($_POST['AddRow'])) { $rowparam = new ReportParameters(); $rowparam->reportId = $model->id; $rowparam->save(); } if (isset($_POST['deleterow'])) { $deletes = $_POST['deleterow']; //there is only one item in this array, but I don't know //any other way to get at it without doing this.. foreach ($deletes as $key => $transrow) { $model->reportparameters[$key]->delete(); break; } } if (isset($_POST['AddReportRow'])) { $rowparam = new ReportRows(); $rowparam->reportId = $model->id; $rowparam->save(); } if (isset($_POST['AddGroupRow'])) { $rowparam = new ReportGroups(); $rowparam->reportId = $model->id; $rowparam->save(); } if (isset($_POST['deletereportrow'])) { $deletes = $_POST['deletereportrow']; //there is only one item in this array, but I don't know //any other way to get at it without doing this.. foreach ($deletes as $key => $transrow) { $model->rows[$key]->delete(); break; } } if (isset($_POST['deletegrouprow'])) { $deletes = $_POST['deletegrouprow']; //there is only one item in this array, but I don't know //any other way to get at it without doing this.. foreach ($deletes as $key => $transrow) { $groupFields = $model->groups[$key]->fields; $model->groups[$key]->delete(); break; } } if (isset($_POST['AddGroupFieldRow'])) { $adds = $_POST['AddGroupFieldRow']; //there is only one item in this array, but I don't know //any other way to get at it without doing this.. foreach ($adds as $key => $transrow) { $rowGroup = new ReportGroupFields(); $rowGroup->reportGroupId = $model->groups[$key]->id; $rowGroup->save(); break; } } if (isset($_POST['deletegroupfieldrow'])) { //print_r($_POST);echo "<br><br><br>"; //print_r($_POST['deletegroupfieldrow']); //die(); $deletes = $_POST['deletegroupfieldrow']; //there is only one item in this array, but I don't know //any other way to get at it without doing this.. foreach ($deletes as $key => $transrow) { $deletes2 = $_POST['deletegroupfieldrow'][$key]; foreach ($deletes2 as $key2 => $transrow2) { $model->groups[$key]->fields[$key2]->delete(); break; } break; } } if (isset($_POST['Export'])) { $dom = new DomDocument(); $dom->encoding = 'utf-8'; $root = $dom->createElement("lazy8webportreport"); $root->setAttribute("version", "1.00"); $this->ExportOneReport($model, $dom, $root); $dom->appendChild($root); $dom->formatOutput = true; $thefile = $dom->saveXML(); // set headers include 'CompanyController.php'; header("Pragma: no-cache"); header("Expires: 0"); header("Content-Description: File Transfer"); header("Content-Type: text/xml"); header("Content-Disposition: attachment; filename=\"lazy8webExport.Report." . CompanyController::replace_bad_filename_chars($model->name) . "." . date('Y-m-d_H.i.s') . ".xml\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . strlen($thefile)); //flush(); print $thefile; return; //we may not send any more to the screen or it will mess up the file we just sent! } }
/** * @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! }
public function actionExportall() { // 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.Templates." . CompanyController::replace_bad_filename_chars(Yii::app()->user->getState('selectedCompanyName')) . "." . date('Y-m-d_H.i.s') . ".xml\""); header("Content-Transfer-Encoding: binary"); $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0', 'utf-8'); $writer->setIndent(4); $writer->startElement('lazy8webtemplates'); $writer->writeAttribute('version', '1.00'); Template::exportAllTemplates($writer, Yii::app()->user->getState('selectedCompanyId')); $writer->endElement(); $writer->endDocument(); $writer->flush(); }
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! }