asri PHPnewbie

Joined: 02 Jul 2010 Posts: 11
|
| Post subject: Function Ajax. |
|
|
Saya mempunyai script fungsi ajax sebagai berikut.
| Code: | <?php <?php <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Ajax extends Controller {
function Ajax ()
{
parent::Controller();
$this->load->model('tbltransaction');
$this->load->model('tblsaldo');
}
function listTransaction() {
$valid_fields = array('tanggal','mitra_name','saldo_awal','cash_in','nama_bank','amount','trx','destination_fee','gateway_fee','switching_fee','ppn','saldo_akhir');
$this->flexigrid->validate_post('tanggal','desc',$valid_fields);
$records = $this->tbltransaction->getList();
$this->output->set_header($this->config->item('json_header'));
if ($records['record_count']!=0) {
$qry = $this->db->query("SELECT * FROM config");
$obj = $qry->result();
foreach ($records['records']->result() as $row)
{
$gateway = $row->ttx*$obj[0]->config_value;
$aquirer = $row->ttx*$obj[1]->config_value;
$switching = $row->ttx*$obj[2]->config_value;
$ppn = $row->ttx*$obj[3]->config_value;
$destination = $row->ttx*$obj[4]->config_value;
$totalfee = $gateway+$aquirer+$switching+$ppn+$destination;
if ($row->mitraref_id==NULL)
$qry = $this->db->query("SELECT * FROM saldoawal WHERE mitraref_id=0");
else
$qry = $this->db->query("SELECT * FROM saldoawal WHERE mitraref_id=".$row->mitraref_id);
$obj2 = $qry->result();
$saldoakhir = $obj2[0]->saldo_awal - $row->amount - $totalfee;
$record_items[] = array($row->id,
date('d F Y',strtotime($row->tanggal)),
$row->mitra_name,
"Rp".number_format($obj2[0]->saldo_awal,2,',','.'),
$row->cashin,
$row->nama_bank,
"Rp".number_format($row->amount,2,',','.'),
$row->ttx,
"Rp".number_format($destination,2,',','.'),
"Rp".number_format($gateway,2,',','.'),
"Rp".number_format($aquirer,2,',','.'),
"Rp".number_format($switching,2,',','.'),
"Rp".number_format($ppn,2,',','.'),
"Rp".number_format($saldoakhir,2,',','.'),
"<a href=\"".site_url('transaction/dgAction/edit/'.$row->id)."\" title=\"edit data\"><img border=\"0\" src=\"".base_url()."images/flexgrid/b_edit.png\" /></a>"
);
}
} else {
$record_items[] = array(NULL);
}
$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
} ?> ?> |
Bagaimana membuat saldo awal = saldo akhir tanggal sebelumnya.
Dimana saldo awal itu berdasarkan mitraref_id.  |
|