function pRequestR1($id)
 {
     $this->myheader4($id);
     $criteria = new CDbCriteria();
     $criteria->compare('parent_id', $id);
     $models = aPorderDetail::model()->findAll($criteria);
     $_counter = 1;
     $_countert = 1;
     $_totalc = 0;
     $_totals = 0;
     $w = array(6, 65, 40, 10, 10, 20, 20, 25, 15, 10, 10, 10, 10, 20);
     $x = $this->GetX();
     $y = $this->GetY();
     foreach ($models as $mod) {
         $this->SetFont('Arial', '', 8);
         $x0 = $this->GetX();
         $y0 = $this->GetY();
         $this->Cell($w[0], 4, number_format($_countert, 0, ',', '.'), 'L', 0, 'R');
         $y1 = $this->GetY();
         $this->MultiCell($w[1], 4, aBudget::model()->findByPk($mod->budget_id)->code . " " . $mod->description, 'LB');
         $y2 = $this->GetY();
         $yH = $y2 - $y1;
         $yC = $this->GetY();
         $this->SetXY($x0, $y0);
         $this->Cell($w[0], $yH, '', 'LB');
         //Garis samping
         $this->SetXY($x + $w[0] + $w[1], $yC - $yH);
         $this->Cell($w[2], $yH, $mod->user, 'LB');
         $this->Cell($w[3], $yH, $mod->uom, 'LB');
         $this->Cell($w[4], $yH, $mod->qty, 'LB', 0, 'R');
         $this->Cell($w[5], $yH, '', 'LB', 0, 'R');
         $this->Cell($w[6], $yH, sParameter::cDateDisplay(strtotime($mod->need_date)), 'LB', 0, 'R');
         $this->Cell($w[7], $yH, '', 'LB', 0, 'R');
         $this->Cell($w[8], $yH, '', 'LB', 0, 'R');
         $this->Cell($w[9], $yH, '', 'LB', 0, 'R');
         $this->Cell($w[10], $yH, '', 'LB', 0, 'R');
         $this->Cell($w[11], $yH, '', 'LB', 0, 'R');
         $this->Cell($w[12], $yH, '', 'LB', 0, 'R');
         $this->Cell($w[13], $yH, '', 'LBR', 0, 'R');
         $this->Ln();
         $_totalc = $_totalc + $mod->qty;
         $_totals = $_totals + aBudget::model()->findByPk($mod->budget_id)->amount;
         $_counter++;
         $_countert++;
         //if ($_counter==34) {
         //	$this->AddPage();
         //	$this->myheader4($id);
         //	$_counter = 1;
         //}
     }
     //Closure line
     $this->Cell(array_sum($w), 0, '', 'T');
     $this->Ln(2);
     $this->SetFont('Arial', 'B', 8);
     $this->Cell($w[0], 5, '', 'TLB');
     $this->Cell($w[1], 5, 'T O T A L', 'TLB', 0, 'C');
     $this->Cell($w[2], 5, '', 'TLB');
     $this->Cell($w[3], 5, '', 'TLB');
     $this->Cell($w[4], 5, number_format($_totalc, 0, ',', '.'), 'TLBR', 0, 'R');
     $this->Cell($w[5], 5, '', 'TLBR', 0, 'R');
     $this->Cell($w[6], 5, '', 'TLB');
     $this->Cell($w[7], 5, '', 'TLB');
     $this->Cell($w[8], 5, '', 'TLB');
     $this->Cell($w[9], 5, '', 'TLB');
     $this->Cell($w[10], 5, '', 'TLB');
     $this->Cell($w[11], 5, '', 'TLB');
     $this->Cell($w[12], 5, '', 'TLB');
     $this->Cell($w[13], 5, '', 1);
     $this->Ln(10);
     $this->SetFont('Arial', '', 8);
     $this->Cell(30, 6, 'Keterangan:');
     $this->Ln(4);
     $this->Cell(0, 6, aPorder::model()->findByPk($mod->parent_id)->remark);
     $this->Ln(14);
     $this->SetFont('Arial', '', 10);
     $this->Cell($w[0], 6, '', 'LT');
     $this->Cell($w[1], 6, 'Requested By', 'TR', 0, 'C');
     $this->Cell($w[2], 6, '', 'T', 0, 'C');
     $this->Cell($w[3], 6, '', 'T', 0, 'C');
     $this->Cell($w[4], 6, '', 'T', 0, 'C');
     $this->Cell($w[5], 6, '', 'T', 0, 'C');
     $this->Cell($w[6], 6, '', 'T', 0, 'C');
     $this->Cell($w[7], 6, 'Acknowledge By:', 'T', 0, 'C');
     $this->Cell($w[8], 6, '', 'T', 0, 'C');
     $this->Cell($w[9], 6, '', 'T', 0, 'C');
     $this->Cell($w[10], 6, '', 'T', 0, 'C');
     $this->Cell($w[11], 6, '', 'T', 0, 'C');
     $this->Cell($w[12], 6, '', 'T', 0, 'C');
     $this->Cell($w[13], 6, '', 'TR', 0, 'C');
     $this->Ln();
     $this->Cell($w[0], 18, '', 'L');
     $this->Cell($w[1], 18, '', 'R');
     $this->Cell($w[2], 18);
     $this->Cell($w[3], 18);
     $this->Cell($w[4], 18);
     $this->Cell($w[5], 18);
     $this->Cell($w[6], 18);
     $this->Cell($w[7], 18);
     $this->Cell($w[8], 18);
     $this->Cell($w[9], 18);
     $this->Cell($w[10], 18);
     $this->Cell($w[11], 18);
     $this->Cell($w[12], 18);
     $this->Cell($w[13], 18, '', 'R');
     $this->Ln();
     $this->Cell($w[0], 6, '', 'L');
     $this->Cell($w[1], 6, 'Silvia Theresia', 'R', 0, 'C');
     $this->Cell($w[2], 6, '', 0, 0, 'C');
     $this->Cell($w[3], 6, '', 0, 0, 'C');
     $this->Cell($w[4] + $w[5], 6, 'Hadi Sutanto', 0, 0, 'C');
     $this->Cell($w[6], 6, '', 0, 0, 'C');
     $this->Cell($w[7], 6, '', 0, 0, 'C');
     $this->Cell($w[8], 6, '', 0, 0, 'C');
     $this->Cell($w[9] + $w[10] + $w[11], 6, 'Indra W. Antono', 0, 0, 'C');
     $this->Cell($w[12], 6, '', 0, 0, 'C');
     $this->Cell($w[13], 6, '', 'R', 'C');
     $this->Ln(3);
     $this->SetFont('Arial', '', 8);
     $this->Cell($w[0], 6, '', 'LB');
     $this->Cell($w[1], 6, 'Office Support Manager', 'BR', 0, 'C');
     $this->Cell($w[2], 6, '', 'B', 0, 'C');
     $this->Cell($w[3], 6, '', 'B', 0, 'C');
     $this->Cell($w[4] + $w[5], 6, 'Fin & Acc Deputy Director', 'B', 0, 'C');
     $this->Cell($w[6], 6, '', 'B', 0, 'C');
     $this->Cell($w[7], 6, '', 'B', 0, 'C');
     $this->Cell($w[8], 6, '', 'B', 0, 'C');
     $this->Cell($w[9] + $w[10] + $w[11], 6, 'Marketing Director', 'B', 0, 'C');
     $this->Cell($w[12], 6, '', 'B', 0, 'C');
     $this->Cell($w[13], 6, '', 'BR', 'C');
     $this->Ln();
     $this->SetFont('Arial', 'BI', 8);
     $this->Cell(0, 6, aPorder::model()->findByPk($mod->parent_id)->no_ref . "         ", 0, 0, 'R');
     $this->Ln();
 }
<div class="page-header">
	<h1>
		<?php 
echo CHtml::image(Yii::app()->request->baseUrl . '/images/icon/payment.png');
?>
		Approval Form
	</h1>
</div>

<?php 
//----- begin new code --------------------
if (empty($_GET['asDialog'])) {
    //$this->widget('bootstrap.widgets.BootDetailView', array(
    $this->widget('ext.XDetailView', array('ItemColumns' => 2, 'data' => $model, 'attributes' => array(array('label' => 'Entity', 'value' => $model->organization->name), 'input_date', 'af_date', 'no_ref', 'periode_date', array('label' => 'Budget Component', 'value' => $model->budgetcomp->name), 'approved_date', 'remark', array('label' => 'Issued By', 'value' => $model->issuer->name), array('label' => 'Payment Status', 'value' => $model->payment->name), 'payment_date')));
}
//----- end new code --------------------
?>

<?php 
$this->widget('bootstrap.widgets.BootGridView', array('id' => 'aPorder-detail-grid', 'dataProvider' => aPorderDetail::model()->search($_GET['id']), 'itemsCssClass' => 'table table-striped table-bordered', 'template' => '{items}{pager}', 'columns' => array(array('class' => 'BootButtonColumn', 'template' => '{payment}', 'buttons' => array('payment' => array('label' => 'Paid', 'url' => 'Yii::app()->createUrl("/m1/aApprovalForm/updateDetailPaid", array("id"=>$data->id))', 'visible' => '$data->detail_payment_id ==1', 'options' => array('ajax' => array('type' => 'GET', 'url' => "js:\$(this).attr('href')", 'success' => 'js:function(data){
														$.fn.yiiGridView.update("aPorder-detail-grid", {
														data: $(this).serialize()
});
}'))))), array('header' => 'Department', 'value' => 'isset($data->department) ? $data->department->name : "ALL"'), array('header' => 'Budget SubComp.', 'value' => '$data->budget->code .". ".$data->budget->name'), 'description', 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;')), array('header' => 'Payment', 'value' => '$data->payment->name'))));
?>
<br />
<b> Total: <?php 
echo $model->sum_pof();
?>
</b>
 public function actionUpdateDetailPaid($id)
 {
     aPorderDetail::model()->updateByPk((int) $id, array('detail_payment_id' => 3));
 }
?>

<div class="page-header">
	<h1>
		<?php 
echo CHtml::image(Yii::app()->request->baseUrl . '/images/icon/cash.png');
?>
		<?php 
echo "PO: " . $model->no_ref;
?>
	</h1>
</div>

<?php 
//----- begin new code --------------------
if (empty($_GET['asDialog'])) {
    //$this->widget('bootstrap.widgets.BootDetailView', array(
    $this->widget('ext.XDetailView', array('ItemColumns' => 2, 'data' => $model, 'attributes' => array(array('label' => 'Entity', 'value' => $model->organization->name), 'input_date', 'af_date', 'no_ref', 'periode_date', array('label' => 'Budget Component', 'value' => $model->budgetcomp->name), 'approved_date', 'remark', array('label' => 'Issued By', 'value' => $model->issuer->name), array('label' => 'Payment Status', 'value' => $model->payment->name), 'payment_date')));
}
//----- end new code --------------------
?>

<?php 
$this->widget('bootstrap.widgets.BootGridView', array('id' => 'aPorder-detail-grid', 'dataProvider' => aPorderDetail::model()->search($_GET['id']), 'itemsCssClass' => 'table table-striped table-bordered', 'template' => '{items}{pager}', 'columns' => array(array('class' => 'BootButtonColumn', 'template' => '{my_delete}', 'buttons' => array('my_delete' => array('label' => '<i class="icon-trash"></i', 'url' => 'Yii::app()->createUrl("/m1/aPorder/deleteDetail", array("id"=>$data->id))', 'visible' => '$data->po->approved_date == null'))), array('header' => 'Department', 'value' => 'isset($data->department) ? $data->department->name : "ALL"'), array('header' => 'Budget SubComp.', 'value' => '$data->budget->code .". ".$data->budget->name'), 'description', 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>
    function report($id, $pro_id)
    {
        $criteria = new CDbCriteria();
        $criteria->order = 'code';
        $criteria->compare('department_id', $pro_id);
        $criteria->compare('parent_id', $id);
        //$criteria->compare('amount!',0);
        $criteria->addNotInCondition('id', array(193, 119, 164, 198));
        $models = aBudget::model()->findAll($criteria);
        $this->myheader($id, $pro_id);
        //$w=array(15,40,23,23,23,23,23,23);
        $w = array(15, 60, 23, 23, 23, 23, 23, 23);
        $this->SetFont('Arial', '', 8);
        foreach ($models as $model) {
            $_amount = $model->amount;
            $_real = aBudget::model()->allComponent($model->id, 2012, 1);
            $_paid = aBudget::model()->allComponentPaid($model->id, 2012, 1);
            $_unpaid = $_real - $_paid;
            $_endBalance = isset($model->end_balance) ? $model->end_balance->balance : $_amount;
            $this->SetFont('Arial', 'B', 8);
            $this->Cell($w[0] + $w[1], 6, $model->code . ". " . $model->name, 'LT');
            $this->Cell($w[2], 6, '', 'T');
            $this->Cell($w[3], 6, number_format($_amount, 0, ',', '.'), 'TLR', 0, 'R');
            $this->Cell($w[4], 6, '', 'T', 0, 'R');
            //$this->Cell($w[5],6,number_format($_paid,2,',','.'),'T',0,'R');
            //$this->Cell($w[6],6,number_format($_unpaid,2,',','.'),'T',0,'R');
            //$this->Cell($w[5],6,'','T',0,'R');
            //$this->Cell($w[6],6,'','T',0,'R');
            $this->Cell($w[7], 6, number_format($_endBalance, 0, ',', '.'), 'TLR', 0, 'R');
            $this->Ln();
            $_total = 0;
            foreach ($model->ch as $mod) {
                $this->SetFont('Arial', '', 6);
                $this->Cell($w[0] + $w[1], 4, '        ' . $mod->name, 'L');
                $this->Cell($w[2], 4, '');
                $this->Cell($w[3], 4, number_format($mod->amount, 0, ',', '.'), 'LR', 0, 'R');
                $crit = new CDbCriteria();
                $crit->with = array('po_detail');
                $crit->condition = 'approved_date is not null';
                $crit->compare('po_detail.budget_id', $mod->id);
                $modelT1 = aPorderDetail::model()->countBySql('
						SELECT SUM(a.amount) AS total
						FROM a_porder_detail a INNER JOIN a_porder b ON a.parent_id = b.id
						WHERE b.approved_date IS NOT NULL
						GROUP BY a.budget_id
						HAVING a.budget_id =
						' . $mod->id);
                $this->Cell($w[4], 4, number_format($modelT1, 0, ',', '.'), 0, 0, 'R');
                $_balance1 = $mod->amount - $modelT1;
                //$this->Cell($w[5],4,'',0,0,'R');
                //$this->Cell($w[6],4,'',0,0,'R');
                $this->Cell($w[7], 4, number_format($_balance1, 0, ',', '.'), 'LR', 0, 'R');
                $this->Ln();
                $_total = $_total + $modelT1;
                foreach ($mod->ch as $m) {
                    $this->SetFont('Arial', '', 6);
                    $this->Cell($w[0] + $w[1], 4, '                ' . $m->name, 'L');
                    $this->Cell($w[2], 4, '');
                    $this->Cell($w[3], 4, number_format($m->amount, 0, ',', '.'), 'LR', 0, 'R');
                    $modelT2 = aPorderDetail::model()->countBySql('
							SELECT SUM(a.amount) AS total
							FROM a_porder_detail a INNER JOIN a_porder b ON a.parent_id = b.id
							WHERE b.approved_date IS NOT NULL
							GROUP BY a.budget_id
							HAVING a.budget_id =
							' . $m->id);
                    $this->Cell($w[4], 4, number_format($modelT2, 0, ',', '.'), 0, 0, 'R');
                    $_balance2 = $m->amount - $modelT2;
                    //$this->Cell($w[5],4,'',0,0,'R');
                    //$this->Cell($w[6],4,'',0,0,'R');
                    $this->Cell($w[7], 4, number_format($_balance2, 0, ',', '.'), 'LR', 0, 'R');
                    $this->Ln();
                    $_total = $_total + $modelT2;
                    if ($this->GetY() >= 250) {
                        $this->Cell(array_sum($w) - 46, 4, '', 'T');
                        $this->AddPage();
                        $this->myheader($id, $pro_id);
                    }
                }
                if ($this->GetY() >= 250) {
                    $this->Cell(array_sum($w) - 46, 4, '', 'T');
                    $this->AddPage();
                    $this->myheader($id, $pro_id);
                }
            }
            //*
            $this->SetFont('Arial', 'B', 6);
            $this->Cell($w[0] + $w[1], 4, 'Check Balance', 'L');
            $this->Cell($w[2], 4, '');
            $this->Cell($w[3], 4, '', 'L');
            $this->Cell($w[4], 4, number_format($_total, 0, ',', '.'), 'L', 0, 'R');
            $_checkbalance = $model->amount - $_total;
            //$this->Cell($w[5],4,'',0,0,'R');
            //$this->Cell($w[6],4,'',0,0,'R');
            $this->Cell($w[7], 4, number_format($_checkbalance, 0, ',', '.'), 'LR', 0, 'R');
            $this->Ln();
            //*/
            $this->Cell(array_sum($w) - 46, 4, '', 'T');
            $this->Ln(1);
        }
    }
 public function actionDeleteDetail($id)
 {
     $model = aPorderDetail::model()->with('po')->findByPk($id);
     if ($model->po->approved_date == null) {
         $model->delete();
     }
     $this->redirect(array('/aPorder/view', 'id' => $model->parent_id));
 }