public function actionClosingPeriodExecution()
 {
     uJournal::model()->updateAll(array('state_id' => 3, 'updated_date' => time(), 'updated_id' => Yii::app()->user->id), 'state_id !=4 AND yearmonth_periode = ' . Yii::app()->settings->get("System", "cCurrentPeriod"));
     $this->transferNewPeriod();
     $_nextPeriod = sParameter::cBeginDateAfter(Yii::app()->settings->get("System", "cCurrentPeriod"));
     Yii::app()->settings->set("System", "cCurrentPeriod", $_nextPeriod, $toDatabase = true);
 }
 public function actionViewJournal($id)
 {
     //----- begin new code --------------------
     if (!empty($_GET['asDialog'])) {
         $this->layout = '//layouts/iframe';
     }
     //----- end new code --------------------
     $model = uJournal::model()->findByPk($id);
     $this->render('/uJournal/view', array('model' => $model));
 }
 public function actionClosingPeriodExecution()
 {
     uJournal::model()->updateAll(array('state_id' => 3, 'updated_date' => time(), 'updated_by' => Yii::app()->user->id), 'state_id !=4 AND yearmonth_periode = ' . Yii::app()->settings->get("System", "cCurrentPeriod"));
     $_curPeriod = Yii::app()->settings->get("System", "cCurrentPeriod");
     $_nextPeriod = sParameter::cBeginDateAfter(Yii::app()->settings->get("System", "cCurrentPeriod"));
     $models = tBalanceSheet::model()->findAll('yearmonth_periode = ' . $_curPeriod);
     foreach ($models as $model) {
         if ($model->account->getTypeValue() == 1) {
             $sql = 'INSERT INTO t_balance_sheet (parent_id, yearmonth_periode, type_balance_id, remark, budget, beginning_balance,debit,credit,end_balance) VALUES (' . $model->parent_id . ',' . $_nextPeriod . ', 1, \'Automated posted\', 0,' . $model->end_balance . ',0,0,' . $model->end_balance . ')';
         } else {
             $sql = 'INSERT INTO t_balance_sheet (parent_id, yearmonth_periode, type_balance_id, remark, budget, beginning_balance,debit,credit,end_balance) VALUES (' . $model->parent_id . ',' . $_nextPeriod . ', 1, \'Automated posted\', 0,0,0,0,0)';
         }
         $command = Yii::app()->db->createCommand($sql);
         $command->execute();
         tBalanceSheet::model()->updateAll(array('type_balance_id' => 2), 'yearmonth_periode = ' . $_curPeriod);
     }
     $_nextPeriod = sParameter::cBeginDateAfter(Yii::app()->settings->get("System", "cCurrentPeriod"));
     Yii::app()->settings->set("System", "cCurrentPeriod", $_nextPeriod, $toDatabase = true);
     Yii::app()->user->setFlash('success', '<strong>Great!</strong> Closing Period has been successful...');
     $this->redirect(array('index'));
 }
 public function loadModel($id)
 {
     $model = uJournal::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 function report($acc_id, $begin_date, $end_date)
 {
     $this->myHeader($acc_id, $begin_date, $end_date);
     $_count = 0;
     $_total = 0;
     $_counter = 1;
     $_countert = 1;
     $criteria = new CDbCriteria();
     $criteria->with = array('journalDetail');
     $criteria->compare('journalDetail.account_no_id', $acc_id);
     $criteria->addBetweenCondition('input_date', Yii::app()->dateFormatter->format('yyyy-MM-dd', $begin_date), Yii::app()->dateFormatter->format('yyyy-MM-dd', $end_date));
     $models = uJournal::model()->findAll($criteria);
     $_mdate = "";
     $_tdebet = 0;
     $_tcredit = 0;
     //Color and font restoration
     $this->SetFillColor(224, 224, 224);
     $this->SetTextColor(0);
     $this->SetFont('');
     //Data
     $fill = false;
     $w = array(7, 18, 14, 33, 18, 18, 70, 15);
     foreach ($models as $mod) {
         foreach ($mod->journalDetail as $mm) {
             $this->SetFont('Arial', '', 8);
             $this->Cell($w[0], 6, number_format($_countert, 0, ',', '.'), 'L', 0, 'R', $fill);
             if ($_mdate != $mod->input_date) {
                 $this->Cell($w[1], 6, $mod->input_date, 'LT', 0, 'L', $fill);
             } else {
                 $this->Cell($w[1], 6, '', 'L');
             }
             $_mdate = $mod->input_date;
             $this->Cell($w[2], 6, $mod->yearmonth_periode, 'L', 0, 'L', $fill);
             $this->Cell($w[3], 6, $mod->system_ref, 'L', 0, 'L', $fill);
             $this->Cell($w[4], 6, number_format($mm->debit, 0, ',', '.'), 'L', 0, 'R', $fill);
             $this->Cell($w[5], 6, number_format($mm->credit, 0, ',', '.'), 'L', 0, 'R', $fill);
             $this->Cell($w[6], 6, strlen($mod->remark) >= 40 ? substr($mod->remark, 0, 38) . " ... " : $mod->remark, 'L', 0, 'L', $fill);
             $this->Cell($w[7], 6, $mod->status->name, 'LR', 0, 'L', $fill);
             $this->Ln();
             $_tdebet = $_tdebet + $mm->debit;
             $_tcredit = $_tcredit + $mm->credit;
             $_counter++;
             $_countert++;
             if ($_counter == 34) {
                 $this->Cell(array_sum($w), 0, '', 'T');
                 $this->AddPage();
                 $this->myHeader($acc_id, $begin_date, $end_date);
                 $_counter = 1;
             }
             $fill = !$fill;
         }
     }
     //Closure line
     $this->Cell(array_sum($w), 0, '', 'T');
     $this->Ln(1);
     $this->SetFont('Arial', 'B', 8);
     $this->Cell($w[0], 8, '', 'TLB');
     $this->Cell($w[1], 8, 'T O T A L', 'TLB', 0, 'C');
     $this->Cell($w[2], 8, '', 'TLB');
     $this->Cell($w[3], 8, '', 'TLB');
     $this->Cell($w[4], 8, number_format($_tdebet, 0, ',', '.'), 'TLB', 0, 'R');
     $this->Cell($w[5], 8, number_format($_tcredit, 0, ',', '.'), 'TLB', 0, 'R');
     $this->Cell($w[6], 8, '', 'TLB');
     $this->Cell($w[7], 8, '', 'TLBR', 0, 'R');
     $this->Ln();
 }
	</h2>
</div>
</div>

<div class="row-fluid">
<div class="span10 well">
	<p>When Button "Closing Month Period" executed, it will do this 3
		following steps.</p>
	<p>#1. It will check, of any unposted journal on Current Period, will
		marked as Locked</p>
	<p>#2. It will move each End-Balance Account on Current Month Period and
		transfer into following Month Period.</p>
	<p>#3. Change Current Period into following Month Period. When this
		process done, all existing journal become unavailable to edit and
		delete</p>
</div>
</div>

<p>
	<?php 
$this->widget('zii.widgets.jui.CJuiButton', array('buttonType' => 'link', 'id' => 'myCap', 'name' => 'btnGo7', 'url' => Yii::app()->createUrl("/m2/tClosing/closingPeriodExecution"), 'caption' => 'Closing Month Period', 'options' => array(), 'htmlOptions' => array('class' => 'ui-button-primary')));
?>
</p>


<h2>Unposted Journal</h2>
<?php 
//$this->widget('bootstrap.widgets.BootGridView', array(
$this->widget('ext.groupgridview.GroupGridView', array('mergeColumns' => array('input_date'), 'id' => 'u-journal-grid', 'dataProvider' => uJournal::model()->search(), 'itemsCssClass' => 'table table-striped table-bordered', 'template' => '{items}{pager}{summary}', 'columns' => array(array('class' => 'bootstrap.widgets.BootButtonColumn', 'template' => '{delete}', 'deleteButtonUrl' => 'Yii::app()->createUrl("/m2/tPosting/delete",array("id"=>$data->id))'), 'input_date', 'system_ref', array('header' => 'Module', 'value' => 'sParameter::item("cModule",$data->module_id)'), array('header' => 'Status', 'value' => '$data->status->name'), array('header' => 'Total', 'type' => 'number', 'value' => '$data->journalSum', 'htmlOptions' => array('style' => 'text-align: right; padding-right: 5px;')))));
//$_nextPeriod = sParameter::cBeginDateAfter(Yii::app()->settings->get("System", "cCurrentPeriod"));
//Yii::app()->settings->set("System", "cCurrentPeriod", $_nextPeriod, $toDatabase=true);
$this->widget('bootstrap.widgets.BootDetailView', array('data' => $model, 'attributes' => array('input_date', 'periode_date', 'system_ref', array('label' => 'Purchasing Type', 'value' => $model->po_type->name), array('label' => 'Entity', 'value' => $model->organization->name), array('label' => 'Supplier', 'value' => $model->supplier->company_name), 'remark', array('label' => 'Payment Status', 'value' => $model->paymentCheck()), array('label' => 'Journal Status', 'value' => $model->journal_state->name))));
?>

<br />

<?php 
$this->widget('bootstrap.widgets.BootGridView', array('id' => 'u-order-detail-grid', 'dataProvider' => bPorderDetail::model()->search($model->id), 'template' => '{items}{pager}', 'itemsCssClass' => 'table table-striped table-bordered', 'columns' => array(array('header' => 'Item.', 'value' => '$data->item_id'), 'description', 'qty', 'uom', array('value' => '$data->amountf()', 'name' => 'amount', 'htmlOptions' => array('style' => 'text-align: right; padding-right: 5px;')), array('header' => 'Total', 'value' => '$data->totalf()', 'name' => 'amount', 'htmlOptions' => array('style' => 'text-align: right; padding-right: 5px;')))));
?>
<br />
<b> Total: <?php 
echo $model->sum_pof();
?>
</b>

<hr />

<h2>Purchased Journal</h2>
<?php 
$this->widget('bootstrap.widgets.BootDetailView', array('data' => uJournal::model()->searchTagPurchasing($model->system_ref), 'attributes' => array('input_date', 'yearmonth_periode', 'user_ref', 'system_ref', 'remark')));
echo $this->renderPartial('/uJournal/_viewDetail', array('id' => uJournal::model()->searchTagPurchasing($model->system_ref)->id));
?>

<?php 
if ($model->journal_state_id == 3) {
    ?>
<hr />
<h2>Payment Journal</h2>
<?php 
    $this->widget('bootstrap.widgets.BootDetailView', array('data' => uJournal::model()->searchTagPayment($model->system_ref), 'attributes' => array('input_date', 'yearmonth_periode', 'user_ref', 'system_ref', 'remark')));
    echo $this->renderPartial('/uJournal/_viewDetail', array('id' => uJournal::model()->searchTagPayment($model->system_ref)->id));
}
<?php

$this->widget('bootstrap.widgets.BootGridView', array('id' => 'u-journal-detail-grid', 'dataProvider' => uJournalDetail::model()->search($id), 'template' => '{items}{pager}', 'itemsCssClass' => 'table table-striped table-bordered', 'columns' => array(array('name' => 'account_no_id', 'type' => 'raw', 'value' => 'CHtml::link($data->account->account_no.". ".$data->account->account_name,Yii::app()->createUrl("/m2/tAccount/view",array("id"=>$data->account->id)))'), array('class' => 'ext.gridcolumns.TotalColumn', 'name' => 'debit', 'output' => 'Yii::app()->indoFormat->number($value)', 'type' => 'raw', 'footer' => true, 'htmlOptions' => array('style' => 'text-align: right; padding-right: 5px;'), 'footerHtmlOptions' => array('style' => 'text-align: right; padding-right: 5px;')), array('class' => 'ext.gridcolumns.TotalColumn', 'name' => 'credit', 'output' => 'Yii::app()->indoFormat->number($value)', 'type' => 'raw', 'footer' => true, 'htmlOptions' => array('style' => 'text-align: right; padding-right: 5px;'), 'footerHtmlOptions' => array('style' => 'text-align: right; padding-right: 5px;')), 'user_remark')));
?>


<?php 
$this->widget('bootstrap.widgets.BootDetailView', array('data' => uJournal::model()->findByPk((int) $id), 'attributes' => array(array('label' => 'Total', 'value' => Yii::app()->indoFormat->number(uJournal::model()->findByPk((int) $id)->journalSum)), array('label' => 'Check', 'value' => 'WARNING!!! NOT BALANCE... CONTACT DEVELOPER', 'visible' => uJournal::model()->findByPk((int) $id)->journalSum != uJournal::model()->findByPk((int) $id)->journalSumCek))));
 public function loadModel($id)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('module_id', 2);
     $criteria->with = array('entity');
     if (Yii::app()->user->name != "admin") {
         //$criteria->compare('entity_id',sUser::model()->getGroup());
         $criteria->addInCondition('entity_id', sUser::model()->getGroupArray());
     }
     $model = uJournal::model()->findByPk($id, $criteria);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
<?php

$this->widget('bootstrap.widgets.BootGridView', array('id' => 'u-journal-detail-grid', 'dataProvider' => uJournalDetail::model()->search($id), 'itemsCssClass' => 'table table-striped table-bordered', 'template' => '{items}{pager}', 'columns' => array(array('name' => 'account_no_id', 'type' => 'raw', 'value' => 'CHtml::link($data->account->account_no.". ".$data->account->account_name,Yii::app()->createUrl("/tAccount/view",array("id"=>$data->account->id)))'), array('name' => 'debit', 'value' => '$data->debitf()', 'htmlOptions' => array('style' => 'text-align: right; padding-right: 5px;')), array('name' => 'credit', 'value' => '$data->creditf()', 'htmlOptions' => array('style' => 'text-align: right; padding-right: 5px;')), 'user_remark')));
$this->widget('bootstrap.widgets.BootDetailView', array('data' => uJournal::model()->findByPk((int) $id), 'attributes' => array(array('label' => 'Total', 'value' => Yii::app()->numberFormatter->format("#,##0.00", uJournal::model()->findByPk((int) $id)->journalSum)))));
?>

<?php 
if ($data->state_id == 1 || $data->state_id == 2) {
    $this->widget('zii.widgets.jui.CJuiButton', array('buttonType' => 'link', 'id' => 'myCap' . $id, 'name' => 'btnGo' . $id, 'url' => Yii::app()->createUrl("/tPosting/posting", array("id" => $id)), 'caption' => $data->state_id == 1 ? 'Post' : 'Re-Post', 'options' => array(), 'htmlOptions' => array('class' => 'ui-button-primary')));
} elseif ($data->state_id == 4) {
    $this->widget('zii.widgets.jui.CJuiButton', array('buttonType' => 'link', 'id' => 'myCap' . $id, 'name' => 'btnGo' . $id, 'url' => Yii::app()->createUrl("/tPosting/unposting", array("id" => $id)), 'caption' => 'Un-Post', 'options' => array(), 'htmlOptions' => array('class' => 'ui-button-primary')));
} else {
    $this->widget('zii.widgets.jui.CJuiButton', array('buttonType' => 'link', 'id' => 'myCap' . $id, 'name' => 'btnGo' . $id, 'url' => Yii::app()->createUrl("/tPosting/unlock", array("id" => $id)), 'caption' => 'Un-Lock', 'options' => array()));
}
?>
<hr />
 function report($id)
 {
     $this->SetFont('Arial', 'B', 12);
     $this->Cell(0, 8, 'JOURNAL VOUCHER', '', 0, 'C');
     $this->Ln(8);
     $model = uJournal::model()->findByPk((int) $id);
     //Header
     $this->SetFont('Arial', '', 10);
     $this->Cell(25, 4, 'Voucher No.');
     $this->SetFont('Arial', 'B', 10);
     $this->Cell(50, 4, ': ' . $model->system_ref);
     $this->Ln();
     $this->SetFont('Arial', '', 10);
     $this->Cell(25, 4, 'Date');
     $this->SetFont('Arial', 'B', 10);
     $this->Cell(60, 4, ': ' . $model->input_date);
     $this->Ln();
     $this->SetFont('Arial', '', 10);
     $this->Cell(25, 4, 'Periode');
     $this->SetFont('Arial', 'B', 10);
     $this->Cell(60, 4, ': ' . $model->yearmonth_periode);
     $this->Ln(4);
     $this->SetFont('Arial', '', 10);
     $this->Cell(25, 4, 'Description');
     $this->Cell(60, 4, ': ' . $model->remark);
     $this->Ln(6);
     $w = array(70, 25, 25, 70);
     //Header
     $this->SetFont('Arial', 'B', 10);
     $this->Cell($w[0], 9, 'Account Name', 'LTBR', 0, 'C');
     $this->Cell($w[1], 9, 'Debit', 'TBR', 0, 'C');
     $this->Cell($w[2], 9, 'Credit', 'TBR', 0, 'C');
     $this->Cell($w[3], 9, 'Remark', 'TBR', 0, 'C');
     $this->Ln();
     $modelD = uJournalDetail::model()->findAll('parent_id = ' . (int) $id);
     //Detail
     foreach ($modelD as $mod) {
         $this->SetFont('Arial', '', 10);
         $this->Cell($w[0], 5, $mod->account->account_no . ". " . $mod->account->account_name, 'LR');
         $this->Cell($w[1], 5, number_format($mod->debit, 0, ',', '.'), 'LR', 0, 'R');
         $this->Cell($w[2], 5, number_format($mod->credit, 0, ',', '.'), 'R', 0, 'R');
         $this->Cell($w[3], 5, $mod->user_remark, 'R');
         $this->Ln();
     }
     $this->SetFont('Arial', 'B', 10);
     $this->Cell($w[0], 6, 'TOTAL', 'TLR', 0, 'R');
     $this->Cell($w[1], 6, number_format($model->journalSum, 0, ',', '.'), 'TLR', 0, 'R');
     $this->Cell($w[2], 6, number_format($model->journalSum, 0, ',', '.'), 'TR', 0, 'R');
     $this->Cell($w[3], 6, '', 'TR');
     $this->Ln();
     //Closure line
     $this->Cell(array_sum($w), 0, '', 'T');
     $this->Ln(2);
     $bilangan = new terbilang();
     $this->SetFont('Arial', 'B', 10);
     $this->Cell(0, 4, 'Say: ' . $bilangan->eja($model->journalSum) . "Rupiah");
     $this->Ln(10);
     $w = array(63, 63, 63);
     $this->SetFont('Arial', '', 10);
     $this->Cell($w[0], 6, 'Created By', 'LTR', 0, 'C');
     $this->Cell($w[1], 6, 'Approved By', 'TR', 0, 'C');
     $this->Cell($w[2], 6, 'Receiver', 'TR', 0, 'C');
     $this->Ln();
     $this->Cell($w[0], 18, '', 'LR');
     $this->Cell($w[1], 18, '', 'R');
     $this->Cell($w[2], 18, '', 'R');
     $this->Ln();
     $this->Cell($w[1], 6, '', 'LBR', 0, 'C');
     $this->Cell($w[1], 6, '', 'BR', 0, 'C');
     $this->Cell($w[2], 6, $model->user_ref, 'RB', 0, 'C');
     $this->Ln(5);
     $this->SetFont('Arial', '', 10);
     $this->Cell($w[0], 6, '', 'LBR');
     $this->Cell($w[1], 6, '', 'BR', 0, 'C');
     $this->Cell($w[2], 6, '', 'BR', 0, 'C');
     $this->Ln();
 }
 function report($acc_id, $begin_date, $end_date)
 {
     $this->myHeader($acc_id, $begin_date, $end_date);
     $criteria = new CDbCriteria();
     $criteria->with = array('journalDetail');
     $criteria->group = 't.id, module_id, input_date, yearmonth_periode, system_ref, state_id';
     $criteria->join = 'INNER JOIN u_journal_detail tt ON t.id = tt.parent_id';
     $criteria->compare('tt.account_no_id', $acc_id);
     $criteria->addBetweenCondition('input_date', Yii::app()->dateFormatter->format('yyyy-MM-dd', $begin_date), Yii::app()->dateFormatter->format('yyyy-MM-dd', $end_date));
     $models = uJournal::model()->findAll($criteria);
     foreach ($models as $model) {
         //Header
         $this->SetFont('Arial', '', 10);
         $this->Cell(25, 4, 'Voucher No.');
         $this->SetFont('Arial', 'B', 10);
         $this->Cell(50, 4, ': ' . $model->system_ref);
         $this->Ln();
         $this->SetFont('Arial', '', 10);
         $this->Cell(25, 4, 'Date');
         $this->SetFont('Arial', 'B', 10);
         $this->Cell(60, 4, ': ' . $model->input_date);
         $this->Ln();
         $this->SetFont('Arial', '', 10);
         $this->Cell(25, 4, 'Periode');
         $this->SetFont('Arial', 'B', 10);
         $this->Cell(60, 4, ': ' . $model->yearmonth_periode);
         $this->Ln(4);
         $this->SetFont('Arial', '', 10);
         $this->Cell(25, 4, 'Description');
         $this->Cell(60, 4, ': ' . $model->remark);
         $this->Ln(6);
         $w = array(70, 25, 25, 70);
         //Header
         $this->SetFont('Arial', 'B', 10);
         $this->Cell($w[0], 9, 'Account Name', 'LTBR', 0, 'C');
         $this->Cell($w[1], 9, 'Debit', 'TBR', 0, 'C');
         $this->Cell($w[2], 9, 'Credit', 'TBR', 0, 'C');
         $this->Cell($w[3], 9, 'Remark', 'TBR', 0, 'C');
         $this->Ln();
         $modeld = uJournalDetail::model()->findAll('parent_id = ' . $model->id);
         foreach ($modeld as $mod) {
             $this->SetFont('Arial', '', 10);
             $this->Cell($w[0], 5, $mod->account->account_concat(), 'LR');
             $this->Cell($w[1], 5, number_format($mod->debit, 0, ',', '.'), 'LR', 0, 'R');
             $this->Cell($w[2], 5, number_format($mod->credit, 0, ',', '.'), 'R', 0, 'R');
             $this->Cell($w[3], 5, $mod->user_remark, 'R');
             $this->Ln();
         }
         $this->SetFont('Arial', 'B', 10);
         $this->Cell($w[0], 6, 'TOTAL', 'TLR', 0, 'R');
         $this->Cell($w[1], 6, number_format($model->journalSum, 0, ',', '.'), 'TLR', 0, 'R');
         $this->Cell($w[2], 6, number_format($model->journalSum, 0, ',', '.'), 'TR', 0, 'R');
         $this->Cell($w[3], 6, '', 'TR');
         $this->Ln();
         $this->Cell(array_sum($w), 6, '', 'T');
         $this->Ln(8);
         if ($this->GetY() >= 215) {
             $this->AddPage();
             $this->myHeader($acc_id, $begin_date, $end_date);
         }
     }
 }