/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'show' page.
*/
public function actionCreate()
{
$model = new AccountType();
if (isset($_POST['American']) || isset($_POST['Swedish'])) {
$filename = "DefaultAccountTypes.US.xml";
if (isset($_POST['Swedish'])) {
$filename = "DefaultAccountTypes.SE.xml";
}
ChangeLog::addLog('ADD', 'AccountType', 'Added default AccountTypes ' . $filename);
$errors = Account::ImportAccounts(dirname(__FILE__) . DIRECTORY_SEPARATOR . $filename);
if (isset($errors) && count($errors) > 0) {
foreach ($errors as $error) {
$model->addError('id', $error);
}
} else {
$this->redirect(array('account/create'));
}
} elseif (isset($_POST['AccountType'])) {
$model->attributes = $_POST['AccountType'];
$model->companyId = Yii::app()->user->getState('selectedCompanyId');
if ($model->save()) {
ChangeLog::addLog('ADD', 'AccountType', $model->toString());
$this->redirect(array('admin', 'id' => $model->id));
}
}
$criteria = new CDbCriteria();
$criteria->addSearchCondition('companyId', Yii::app()->user->getState('selectedCompanyId'));
$models = AccountType::model()->findAll($criteria);
$isAccountTypesInCompany = isset($models) && count($models) > 0;
$model->dateChanged = User::getDateFormatted(date('Y-m-d'));
$this->render('create', array('model' => $model, 'isAccountTypesInCompany' => $isAccountTypesInCompany));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'show' page.
*/
public function actionCreate()
{
$model = new Donor();
if (isset($_POST['Donor'])) {
$model->attributes = $_POST['Donor'];
$model->companyId = Yii::app()->user->getState('selectedCompanyId');
if ($model->save()) {
ChangeLog::addLog('ADD', 'Donor', $model->toString());
$this->redirect(array('admin', 'id' => $model->id));
}
}
$model->dateChanged = User::getDateFormatted(date('Y-m-d'));
$this->render('create', array('model' => $model));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'show' page.
*/
public function actionCreate()
{
$model = new Company();
if (isset($_POST['Company'])) {
$model->attributes = $_POST['Company'];
if ($model->save()) {
User::updateOptionTemplate(User::optionsCompanyTemplate(), 0, $model->id);
ChangeLog::addLog('ADD', 'Company', $model->toString());
$this->updateUserEditingRightsForCompany($model->id, 0);
$this->redirect(array('period/create'));
}
}
$compOptions = User::optionsCompanyTemplate();
$options = array();
foreach ($compOptions as $key => $option) {
$newOp = new Options();
$newOp->name = $key;
$newOp->datavalue = $option[1];
$options[] = $newOp;
}
$model->dateChanged = User::getDateFormatted(date('Y-m-d'));
$this->render('create', array('model' => $model, 'options' => $options));
}
<div class="simple">
<?php
echo CHtml::activeLabelEx($model, 'desc', array('class' => 'help', 'title' => Yii::t('lazy8', 'contexthelp.desc'), 'onclick' => 'alert(this.title)'));
echo CHtml::activeTextField($model, 'desc', array('size' => 35, 'maxlength' => 255));
?>
</div>
<div class="simple">
<?php
echo CHtml::activeLabelEx($model, 'changedBy', array('class' => 'help', 'title' => Yii::t('lazy8', 'contexthelp.changedBy'), 'onclick' => 'alert(this.title)'));
echo CHtml::label($model->changedBy, false);
?>
</div>
<div class="simple">
<?php
echo CHtml::activeLabelEx($model, 'dateChanged', array('class' => 'help', 'title' => Yii::t('lazy8', 'contexthelp.dateChanged'), 'onclick' => 'alert(this.title)'));
echo CHtml::label(User::getDateFormatted($model->dateChanged, $cLoc, $dateformatter), false);
?>
</div>
<div class="action">
<?php
echo CHtml::submitButton($update ? Yii::t('lazy8', 'Save') : Yii::t('lazy8', 'Create'), array('title' => $update ? Yii::t('lazy8', 'contexthelp.Save') : Yii::t('lazy8', 'contexthelp.Create')));
?>
</div>
<?php
echo CHtml::endForm();
?>
</div><!-- yiiForm -->
private function getBlankTempTrans($rownum, $invDate = null)
{
$comp = Company::model()->findbyPk(Yii::app()->user->getState('selectedCompanyId'));
$per = Period::model()->findbyPk(Yii::app()->user->getState('selectedPeriodId'));
$model = new TempTrans();
$model->rownum = $rownum;
$model->regDate = date('Y-m-d');
if ($invDate == null) {
$invDate = $model->regDate;
}
$model->invDate = $invDate;
$model->changedBy = Yii::app()->user->getState('displayname');
$model->dateChanged = $model->regDate;
$model->periodNum = $per->lastPeriodTransNum + 1;
$model->companyNum = $comp->lastAbsTransNum + 1;
$model->notesheader = '';
$model->fileInfo = '';
$model->fileInfo = 1;
$model->accountId = 0;
$model->customerId = 0;
$model->donorId = 0;
$model->notes = '';
$model->amountdebit = "";
$model->amountcredit = "";
$model->userId = Yii::app()->user->id;
$model->save();
$cLoc = CLocale::getInstance('en');
$model->invDate = User::getDateFormatted($model->invDate, $cLoc);
$model->regDate = User::getDateFormatted($model->regDate, $cLoc);
$model->dateChanged = $model->regDate;
return $model;
}
?>
</td>
<td><?php
echo CHtml::encode($model->name);
?>
</td>
<td><?php
echo CHtml::encode($model->desc);
?>
</td>
<td><?php
echo CHtml::encode($model->changedBy);
?>
</td>
<td><?php
echo CHtml::encode(User::getDateFormatted($model->dateChanged, $cLoc, $dateformatter));
?>
</td>
<td>
<?php
echo CHtml::link(Yii::t('lazy8', 'Update'), array('update', 'id' => $model->id));
?>
<?php
if (TransRow::model()->find('customerId=' . $model->id) == null) {
$deletebutton = CHtml::linkButton(Yii::t('lazy8', 'Delete'), array('submit' => '', 'params' => array('command' => 'delete', 'id' => $model->id), 'confirm' => Yii::t('lazy8', "Are you sure to delete?") . ' - ' . $model->name));
} else {
$deletebutton = CHtml::linkButton(Yii::t('lazy8', 'Delete'), array('submit' => '', 'params' => array('command' => 'admin', 'id' => $model->id), 'confirm' => Yii::t('lazy8', "You cannot delete this record because other records are dependent on it.")));
}
echo $deletebutton;
?>
</td>
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'show' page.
*/
public function actionCreate()
{
$model = new User();
if (isset($_POST['User'])) {
$model->attributes = $_POST['User'];
$model->salt = hash('sha1', uniqid(rand(), true));
$model->password = hash('sha1', $model->password . $model->salt);
$model->confirmPassword = hash('sha1', $model->confirmPassword . $model->salt);
if ($model->save()) {
$this->setOptionsByTemplate(true);
$companies = array();
if (isset($_POST['companies'])) {
$companies = $_POST['companies'];
}
User::updateOptionTemplate(User::optionsUserTemplate(), $model->id, 0);
foreach ($companies as $comp) {
User::model()->dbConnection->createCommand("INSERT INTO CompanyUser (userId, companyId) VALUES ({$model->id},{$comp})")->execute();
User::updateOptionTemplate(User::optionsCompanyUserTemplate(), $model->id, $comp);
}
$model->setStates();
ChangeLog::addLog('ADD', 'User', $model->toString());
$this->redirect(array('admin', 'id' => $model->id));
} else {
unset($this->_model->password);
unset($this->_model->confirmPassword);
}
}
$usersModel = User::model()->findbyPk($model->id);
//put all the user companies in an array
if (isset($usersModel) && $usersModel != null) {
$companiesUsers = $usersModel->companies;
}
$selectedCompanies = array();
if (isset($companiesUsers)) {
foreach ($companiesUsers as $companyUser) {
$selectedCompanies[] = $companyUser->id;
}
}
$allCompanies = Company::model()->findAll();
$compOptions = User::optionsUserTemplate();
$UsersOptions = array();
foreach ($compOptions as $key => $option) {
$newOp = new Options();
$newOp->name = $key;
$newOp->datavalue = $option[1];
$UsersOptions[] = $newOp;
}
$model->useroptions = $UsersOptions;
$model->dateChanged = User::getDateFormatted(date('Y-m-d'));
$this->render('create', array('model' => $model, 'allCompanies' => $allCompanies, 'selectedCompanies' => $selectedCompanies));
}
/**
* Displays the requested report
*
*/
public function actionReport()
{
//throw(new Exception('just die'));
if ((isset($_POST['ShowReport']) || isset($_POST['DownloadPDF']) || isset($_POST['DownloadExcel'])) && isset($_POST['reportId'])) {
$this->_model = Report::model()->findbyPk($_POST['reportId']);
if ($this->_model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
//delete all the old report parameter values
ReportUserLastUsedParams::model()->dbConnection->createCommand('DELETE FROM ReportUserLastUsedParams WHERE reportId=' . $this->_model->id . ' AND userId=' . Yii::app()->user->id)->execute();
//build the Sql sats
$aliases = array();
$replacements = array();
$repParams = $this->_model->reportparameters;
$parameterValues = array();
$graphicFilename = "";
$title = "";
if (isset($repParams) && count($repParams) > 0) {
foreach ($repParams as $n => $repParam) {
//get the new parameter values
if ($repParam->dataType == 'HIDDEN_NO_SHOW_HEAD' || $repParam->dataType == 'HIDDEN_SHOW_HEAD') {
if (strlen($repParam->phpSecondaryInfo) > 0) {
eval($repParam->phpSecondaryInfo);
} else {
$defaultValue = $repParam->defaultValue;
if ($repParam->isDefaultPhp) {
eval($defaultValue);
}
}
$parameterValues[$n] = $defaultValue;
} else {
if (isset($_POST[$n])) {
if ($repParam->dataType == 'DATE') {
$parameterValues[$n] = User::parseDate($_POST[$n]);
} else {
$parameterValues[$n] = $_POST[$n];
}
if (strlen($title) == 0) {
$title = $_POST[$n];
}
$negateGraphicValues = false;
if ($repParam->name == 'Negate values for graphics') {
$negateGraphicValues = (int) $_POST[$n];
}
//save the parameter values
$saveLast = new ReportUserLastUsedParams();
$saveLast->reportId = $this->_model->id;
$saveLast->userId = Yii::app()->user->id;
$saveLast->paramId = $n;
$saveLast->LastUsedValue = $parameterValues[$n];
$saveLast->save();
}
}
//get the aliases
if (strlen($repParam->alias) > 0) {
$aliases[] = $repParam->alias;
if ($repParam->dataType == 'HIDDEN_NO_SHOW_HEAD' || $repParam->dataType == 'HIDDEN_SHOW_HEAD') {
$defaultValue = $repParam->defaultValue;
if ($repParam->isDefaultPhp) {
eval($defaultValue);
}
$replacements[] = $defaultValue;
} else {
if ($repParam->dataType == 'DATE') {
$replacements[] = User::parseDate($_POST[$n]);
} else {
$replacements[] = $_POST[$n];
}
}
if ($repParam->alias == '{ShowGraph}' && strlen($_POST[$n]) > 0) {
$graphicFilename = $_POST[$n];
}
}
}
}
$sqlSelect = str_replace($aliases, $replacements, $this->_model->selectSql);
// var_dump($aliases);
// var_dump($replacements);
//echo $sqlSelect.'<br><br>';
// echo $sqlSelect; die();
//execute the Sql sats
//Yii::log($sqlSelect, CLogger::LEVEL_INFO, 'system.web.CController');
$command = Report::model()->dbConnection->createCommand($sqlSelect);
try {
$reader = $command->query();
//foreach($reader as $row)print_r($row);
//die();
} catch (Exception $e) {
echo '<h2>Died on Sql execution</h2>' . $sqlSelect;
throw $e;
}
$imageFileNames = array();
$imageFilePaths = array();
if (strlen($graphicFilename) > 0) {
$images = $this->readXmlGraphicFile($graphicFilename, false, $reader, $title, $negateGraphicValues, $imageFileNames);
$imageFileNames = $images[1];
$imageFilePaths = $images[0];
//must do this again because the reader can only go forwards
$reader = $command->query();
}
//update last used report for printout
$printoutview = "";
if (isset($_POST['printoutview'])) {
$printoutview = $_POST['printoutview'];
}
$option = Options::model()->find('name=\'isReportForPrintout\' AND companyId=0 AND userId=' . Yii::app()->user->id);
$option->datavalue = $printoutview == 1 ? 'true' : 'false';
$option->save();
Yii::app()->user->setState('isReportForPrintout', $printoutview);
//update last used black and white
$option = Options::model()->find('name=\'isReportBlackAndWhite\' AND companyId=0 AND userId=' . Yii::app()->user->id);
$option->datavalue = false;
$option->datavalue = isset($_POST['blackandwhite']) && $_POST['blackandwhite'] == 1 ? 'true' : 'false';
$option->save();
Yii::app()->user->setState('isReportBlackAndWhite', isset($_POST['blackandwhite']) && $_POST['blackandwhite'] == 1 ? 1 : 0);
if (isset($_POST['blackandwhite']) && $_POST['blackandwhite'] == 1) {
Yii::app()->user->setState('reportCssFile', $this->_model->cssBwFileName);
} else {
Yii::app()->user->setState('reportCssFile', $this->_model->cssColorFileName);
}
//get the number and date formats
$cLoc = CLocale::getInstance('en');
$numberFormatter = $cLoc->getNumberFormatter();
$dateFormatter = $cLoc->getDateFormatter();
// echo "<pre>";
// var_dump($dateFormatter);
// echo "</pre>";
// die();
$numberFormat = User::getNumberFormat();
$pdf_name = "";
$cron_job = FALSE;
// if from cron job
if (isset($_POST['cron'])) {
$pdf_name = "reports/lazy8report_" . date('Y-m-d_H.i.s');
$cron_job = TRUE;
}
if (isset($_POST['DownloadExcel'])) {
Yii::import('application.controllers.excel.*');
require_once "exportExcel.php";
new exportExcel($this->_model, $reader, $pdf_name, $numberFormatter, $dateFormatter, $numberFormat, $printoutview, $parameterValues);
die;
} else {
if (isset($_POST['DownloadPDF'])) {
// var_dump($numberFormat);
// die();
Yii::import('application.controllers.tcpdf.*');
require_once "lazy8tcpdf.php";
new lazy8tcpdf($this->_model, $reader, $pdf_name, $cron_job, $numberFormatter, $dateFormatter, $numberFormat, $printoutview, $parameterValues, $imageFileNames, isset($_POST['blackandwhite']) && $_POST['blackandwhite'] == 1 ? 1 : 0, strpos(Yii::app()->user->getState('reportCssFile'), "wide") === false);
// if cron job was run then email user with the pdf attatchment
if (isset($_POST['cron'])) {
$accountID = $_POST['accountID'];
$sql = "SELECT Account.code AS accountcode, Account.name AS accountname, Account.email AS email, Account.balance_threshold AS threshold, Account.days AS days\n\t\t\t\t\t\t\t\tFROM Account\n\t\t\t\t\t\t\t\tWHERE Account.code = '{$accountID}'";
$account = Yii::app()->db->createCommand($sql)->queryAll();
$to = $account['email'];
$subject = 'Weekly Report';
$headers = "From: Accounting@thaiconnections.org \r\n";
$headers .= "Reply-To: no-reply@thaiconnections.org\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<p>Hello,</p>';
$message .= '<p>This a automated notification from Thaiconnections Accounting website that your weekly report for: <strong>' . $account['accountname'] . ' </strong>is ready to be downloaded. Please click the link to view your report.<p>';
$message .= '<phttp://accounting.thaiconnections.org/' . $pdf_name . '.pdf<p>';
$message .= '<p>Kindest Regards,<br>';
$message .= 'Thaiconnections Accounting</p>';
$message .= '</body></html>';
if (mail($to, $subject, $message, $headers)) {
echo "Email sent...<br>";
} else {
echo "Mail did not send. Error occurred";
}
}
} else {
//show the report
$this->render('report', array('model' => $this->_model, 'reader' => $reader, 'numberFormatter' => $numberFormatter, 'dateFormatter' => $dateFormatter, 'numberFormat' => $numberFormat, 'printoutview' => $printoutview, 'parameterValues' => $parameterValues, 'imageFileNames' => $imageFilePaths));
}
}
} else {
//show the report parameter selection page.
$noActivityLogSelectionString = "";
if (!Yii::app()->user->getState('allowChangeLog')) {
$noActivityLogSelectionString = " AND name<>'Activity log'";
}
$allRepModels = Report::model()->findAll(array('select' => 'id,name', 'order' => 'sortOrder', 'condition' => '(companyId=' . Yii::app()->user->getState('selectedCompanyId') . ' OR companyId=0)' . $noActivityLogSelectionString));
$reports = CHtml::listData($allRepModels, 'id', 'name');
foreach ($reports as $n => $reportsTrans) {
$reports[$n] = Yii::t('lazy8', $reportsTrans);
}
if (isset($_POST['reportId']) && $_POST['reportId']) {
$model = Report::model()->findbyPk($_POST['reportId']);
//update last used report
$option = Options::model()->find('name=\'lastPrintedReportId\' AND companyId=0 AND userId=' . Yii::app()->user->id);
$option->datavalue = $_POST['reportId'];
$option->save();
Yii::app()->user->setState('lastPrintedReportId', $_POST['reportId']);
} else {
//always try to select any report
$selectReport = Yii::app()->user->getState('lastPrintedReportId');
$model = Report::model()->findbyPk($selectReport);
if (isset($model)) {
$_POST['reportId'] = $selectReport;
} elseif (isset($allRepModels) && count($allRepModels) > 0) {
$_POST['reportId'] = $allRepModels[0]->id;
$model = $allRepModels[0];
}
}
//preselect the values to what was done before...
$repParams = $model->reportparameters;
if (isset($repParams) && count($repParams) > 0) {
foreach ($repParams as $n => $repParam) {
if ($repParam->dataType == 'FREE_TEXT' || $repParam->dataType == 'DROP_DOWN' || $repParam->dataType == 'DATE' || $repParam->dataType == 'BOOLEAN') {
$lastChosen = ReportUserLastUsedParams::model()->find('reportId=' . $model->id . ' AND userId=' . Yii::app()->user->id . ' AND paramId=' . $n);
if (isset($lastChosen)) {
$defaultValue = $lastChosen->LastUsedValue;
} else {
$defaultValue = $repParam->defaultValue;
if ($repParam->isDefaultPhp) {
eval($defaultValue);
}
}
if ($repParam->dataType == 'DATE') {
$_POST[$n] = User::getDateFormatted($defaultValue);
} else {
$_POST[$n] = $defaultValue;
}
}
}
}
$_POST['blackandwhite'] = Yii::app()->user->getState('isReportBlackAndWhite') ? 1 : 0;
$_POST['printoutview'] = Yii::app()->user->getState('isReportForPrintout') ? 1 : 0;
$this->render('reportparams', array('reports' => $reports, 'model' => $model));
}
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Template'])) {
$model->attributes = $_POST['Template'];
if ($model->save()) {
if ($this->updateRows($model)) {
if (isset($_POST['AddRow']) || isset($_POST['deleterow'])) {
$this->redirect(array('update', 'id' => $model->id));
} else {
$this->redirect(array('admin'));
}
}
}
}
$model->dateChanged = User::getDateFormatted(date('Y-m-d'));
$this->render('update', array('model' => $model, 'update' => true));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'show' page.
*/
public function actionUpdate()
{
$model = $this->loadPeriod();
if (isset($_POST['Period'])) {
$modelBeforeChange = $model->toString();
$model->attributes = $_POST['Period'];
$model->dateStart = User::parseDate($model->dateStart);
$model->dateEnd = User::parseDate($model->dateEnd);
$model->companyId = Yii::app()->user->getState('selectedCompanyId');
if ($model->save()) {
$stringModel = $model->toString();
if ($modelBeforeChange != $stringModel) {
ChangeLog::addLog('UPDATE', 'Period', 'BEFORE<br />' . $modelBeforeChange . '<br />AFTER<br />' . $stringModel);
}
$this->redirect(array('admin', 'id' => $model->id));
}
}
$model->dateStart = User::getDateFormatted($model->dateStart);
$model->dateEnd = User::getDateFormatted($model->dateEnd);
$model->dateChanged = User::getDateFormatted($model->dateChanged);
$this->render('update', array('model' => $model));
}
$linkhtml = "";
$linkendhtml = "";
if (!Yii::app()->user->isGuest) {
if (Yii::app()->user->getState('allowPeriodSelection')) {
$linkhtml = '<a href="' . Yii::app()->request->hostInfo . Yii::app()->request->scriptUrl . "?r=user/selectcompany&id=" . Yii::app()->user->id . '">';
$linkendhtml = '</a>';
}
if (strlen(Yii::app()->user->getState('selectedCompany')) == 0) {
echo '<div id="titleperioderror">' . $linkhtml . CHtml::encode(Yii::t("lazy8", 'Error: No company is selected for editing')) . $linkendhtml . '</div>';
} else {
echo '<div id="titleperiod">' . $linkhtml . CHtml::encode(Yii::t("lazy8", 'Now editing Company/period'));
?>
<br /><?php
$cLoc = CLocale::getInstance('en');
$dateformatter = new CDateFormatter($cLoc);
echo CHtml::encode(Yii::app()->user->getState('selectedCompany') . ' / ' . User::getDateFormatted(Yii::app()->user->getState('selectedPeriodStart'), $cLoc, $dateformatter) . ' - ' . User::getDateFormatted(Yii::app()->user->getState('selectedPeriodEnd'), $cLoc, $dateformatter)) . $linkendhtml . '</div>';
}
}
?>
</td><td style="text-align:right">
<?php
if (!Yii::app()->user->isGuest) {
?>
<div id="logo">
<?php
if (Yii::app()->user->getState('allowSelf') || Yii::app()->user->getState('allowAdmin')) {
?>
<a href="<?php
echo Yii::app()->request->hostInfo . Yii::app()->request->scriptUrl . "?r=user/update&id=" . Yii::app()->user->id;
?>
">
echo CHtml::encode($model->getAttributelabel(Yii::t("lazy8", 'changedBy')));
?>
:
<?php
echo CHtml::encode($model->changedBy);
?>
<br/>
<?php
echo CHtml::encode($model->getAttributeLabel('userChangedId'));
?>
:
<?php
echo CHtml::encode($model->userChangedId);
?>
<br/>
<?php
echo CHtml::encode($model->getAttributelabel(Yii::t("lazy8", 'dateChanged')));
?>
:
<?php
echo CHtml::encode(User::getDateFormatted($model->dateChanged));
?>
<br/>
</div>
<?php
}
?>
<br/>
<?php
$this->widget('CLinkPager', array('pages' => $pages));