private function copyTempTransToNewTrans($periodNum, $companyNum, $isUpdateRegDate = false)
 {
     //everything is ok.  Make the new transaction
     $models = $this->getFromTempTrans();
     $cLoc = CLocale::getInstance('en');
     // CHECK IF USER CAN COMMIT NEGAIVE ASSET TRANSACTIONS
     $negativeAssetTrans = Yii::app()->user->getState('negativeAssetTrans');
     if ($negativeAssetTrans == 0) {
         foreach ($models as $model) {
             // only if account is 399999 or less
             $sql = "SELECT Account.code AS accountcode\n\t\t\t\t\t\t\t\tFROM Account\n\t\t\t\t\t\t\t\tWHERE Account.id = " . $model->accountId;
             $accounts = Yii::app()->db->createCommand($sql)->queryAll();
             if (!empty($accounts)) {
                 $account_code = intval($accounts[0]['accountcode']);
                 if ($account_code < 399999) {
                     $amountcredit = $this->parseNumber($model->amountcredit, $cLoc);
                     if ($amountcredit != 0) {
                         $pass = $this->checkAccountNegative($model->accountId, $amountcredit);
                         if (!$pass) {
                             return NULL;
                         }
                     }
                 }
             }
         }
     }
     $trans = new Trans();
     $tmpDate = date_create_from_format('d M Y', $models[0]->invDate);
     $trans->invDate = date_format($tmpDate, 'Y-m-d');
     // $trans->invDate=User::parseDate($models[0]->invDate,$cLoc);
     if ($isUpdateRegDate) {
         $trans->regDate = date('Y-m-d');
     } else {
         $tmpDate = date_create_from_format('d M Y', $models[0]->regDate);
         $trans->regDate = date_format($tmpDate, 'Y-m-d');
     }
     $trans->periodNum = $periodNum;
     $trans->companyNum = $companyNum;
     $trans->notes = $models[0]->notesheader;
     $trans->fileInfo = $models[0]->fileInfo;
     $trans->reconciled = $models[0]->reconciled;
     $trans->companyId = Yii::app()->user->getState('selectedCompanyId');
     $trans->periodId = Yii::app()->user->getState('selectedPeriodId');
     $trans->save();
     foreach ($models as $model) {
         $amountdebit = $this->parseNumber($model->amountdebit, $cLoc);
         $amountcredit = $this->parseNumber($model->amountcredit, $cLoc);
         if ($amountdebit != 0 || $amountcredit != 0) {
             $transrow = new TransRow();
             $transrow->transId = $trans->id;
             $transrow->accountId = $model->accountId;
             $transrow->customerId = $model->customerId;
             $transrow->donorId = $model->donorId;
             $transrow->notes = $model->notes;
             $transrow->amount = $amountdebit > 0 ? $amountdebit : -$amountcredit;
             $transrow->save();
         }
     }
     return $trans;
 }
Esempio n. 2
0
    ?>
</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>
  </tr>
<?php 
}
?>
  </tbody>
</table>
<br/>
<?php 
Esempio n. 3
0
    ?>
</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('accountId=' . $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>
  </tr>
<?php 
}
?>
  </tbody>
</table>
<br/>
<?php 
 /**
  * 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 loadTransRow($id = null)
 {
     if ($this->_model === null) {
         if ($id !== null || isset($_GET['id'])) {
             $this->_model = TransRow::model()->findbyPk($id !== null ? $id : $_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }
 private function copyTempTransToNewTrans($models, $template, $periodNum, $companyNum, $rowcount, $isUpdateRegDate = false)
 {
     //everything is ok.  Make the new transaction
     $models = $this->getFromTempTrans($template, $rowcount);
     $this->finalAdjustTransFromTemplate($models, $template);
     $trans = new Trans();
     $cLoc = CLocale::getInstance('en');
     $trans->invDate = User::parseDate($models[0]->invDate, $cLoc);
     if ($isUpdateRegDate) {
         $trans->regDate = date('Y-m-d');
     } else {
         $trans->regDate = User::parseDate($models[0]->regDate, $cLoc);
     }
     $trans->periodNum = $periodNum;
     $trans->companyNum = $companyNum;
     $trans->notes = $models[0]->notesheader;
     $trans->reconciled = $models[0]->reconciled;
     $trans->fileInfo = $models[0]->fileInfo;
     $trans->companyId = Yii::app()->user->getState('selectedCompanyId');
     $trans->periodId = Yii::app()->user->getState('selectedPeriodId');
     $trans->save();
     foreach ($models as $n => $model) {
         $amountdebit = TransController::parseNumber($model->amountdebit, $cLoc);
         $amountcredit = TransController::parseNumber($model->amountcredit, $cLoc);
         if ($amountdebit != 0 || $amountcredit != 0) {
             $transrow = new TransRow();
             $transrow->transId = $trans->id;
             $transrow->accountId = $model->accountId;
             $transrow->customerId = $model->customerId;
             $transrow->donorId = $model->donorId;
             $transrow->notes = $model->notes;
             $transrow->amount = $amountdebit > 0 ? $amountdebit : -$amountcredit;
             $transrow->save();
         }
     }
     return $trans;
 }
 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!
 }