• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED]Wrong Sum

#1
[eluser]redraw[/eluser]
dear all,

I want print a report

i have view :
Code:
<body>
<div class='title' align="center">Jurnal Transaksi Harian <br />Periode &lt;?php echo $tanggal_mulai. " S/D " . $tanggal_sampai; ?&gt;</div>
    <table align="center" width="27%" border='0' cellpadding='0' cellspacing='0' class="display" id="example">
<thead>
    <tr>
        <th align="center" width="7%">Tanggal</th>
        <th align="center" width="7%">Nota</th>
        <th align="center" width="7%">Code</th>
        <th align="left" width="23%">Account</th>
        <th align="left" width="23%">Keterangan</th>
        <th align="right" width="10%">Debet</th>
          <th align="right" width="10%">Kredit</th>
    </tr>
</thead>
    &lt;?php
        $i = 0;
        $xnota = "";
        $row1 = 'Y';
        $v_debet = 0;
        $v_kredit = 0;
    ?&gt;
    
    &lt;?php foreach($detail->result() as $rows):?&gt;
    &lt;?php

        $v_debet = $v_debet + $rows->debet;
        $v_kredit = $v_kredit + $rows->kredit;

     ?&gt;
    &lt;?php
    if($xnota != $rows->no_bukti and $row1 != 'Y'){
        echo "<tr><td colspan='7'><hr></td>";
        echo "<tr><td></td></tr>";
        echo "<tr><td colspan='5' align='right'>";
        echo "BALANCE";
        echo "</td>";
        $v_debet = number_format($v_debet);
        $v_kredit = number_format($v_kredit);
        echo "<td align='right'>". $v_debet ."</td>";
        echo "<td align='right'>". $v_kredit ."</td></tr>";
        echo "<tr><td colspan='5'></td><td colspan='2' valign='colspan'><hr></td><td></td></tr>";
        
        $v_debet = 0;
        $v_kredit = 0;
    }

        ?&gt;
        <tr>
        <td colspan="7"></td>    
        </tr>
        <tr>
          <td height="19" align="center" >&lt;?php echo $rows->tanggal;?&gt;</td>
          <td height="19" align="center" >&lt;?php echo $rows->no_bukti;?&gt;</td>
          <td height="19" align="center" >&lt;?php echo $rows->code;?&gt;</td>
          <td height="19" align="left" >&lt;?php
        $jenis = $rows->jenis;
        if($jenis == 'k')
        {
            echo "&nbsp;&nbsp;&nbsp;&nbsp;".$rows->account;
        }
        else
        {
            echo $rows->account;
        }
        ?&gt;</td>
          <td align="left" >&lt;?php echo $rows->keterangan;?&gt;</td>
          <td align="right">&lt;?php
            $debet = $rows->debet;
            $debet= number_format($debet);
            echo $debet;
        ?&gt;
        </td>
          <td height="19" align="right">&lt;?php
              $kredit = $rows->kredit;
            $kredit= number_format($kredit);
            echo $kredit;
        ?&gt;</td>
          <td align="center">&lt;input type='hidden' id='code_&lt;?php echo $rows-&gt;master_id;?&gt;'        value='&lt;?php echo $rows->code;?&gt;' />
            &lt;input type='hidden' id='tanggal_&lt;?php echo $rows-&gt;master_id;?&gt;'     value='&lt;?php echo $rows->tanggal;?&gt;' />
            &lt;input type='hidden' id='keterangan_&lt;?php echo $rows-&gt;master_id;?&gt;' value='&lt;?php echo $rows->keterangan;?&gt;'/>
          &lt;input type='hidden' id='nilai_&lt;?php echo $rows-&gt;master_id;?&gt;'         value='&lt;?php echo $rows->nilai;?&gt;'/></td>
        </tr>
       &lt;?php
       $xnota = $rows->no_bukti;
       $row1 = 'N';
      
       ?&gt;
    &lt;?php
    endforeach;
    if($row1 == 'N'){
        echo "<tr><td colspan='7'><hr></td>";
        echo "<tr><td></td></tr>";
        echo "<tr><td colspan='5' align='right'>";
        echo "BALANCE";
        echo "</td>";
        //$v_debet = $nilaitrn;
        $v_debet = number_format($v_debet);
        $v_kredit = number_format($v_kredit);
        echo "<td align='right'>".$v_debet."</td>";
        echo "<td align='right'>".$v_kredit."</td></tr>";
        echo "<tr><td colspan='5'></td><td colspan='2' valign='colspan'><hr></td><td></td></tr>";
    }
    ?&gt;
      
</table>
&lt;/body&gt;

but that display wrong summaries.
I just attached a picture the print preview, so it will be easy to understand.

#2
[eluser]toopay[/eluser]
Coba di model kamu, return nya jangan berupa object, tapi array... Lalu di view pakai count dan while...

#3
[eluser]redraw[/eluser]
untuk seperti itu gimna caranya mas?
model sya kya gini :
Code:
function cetak_master()
    {
        $data = $this->fungsi->accept_data(array_keys($_POST));
        //$this->gl_model->gl_browse_trans($data);
        $data['tanggal_mulai'] = $_POST['tanggal_mulai'];
        $this->session->set_userdata('tanggal_mulai', $this->input->post('tanggal_mulai'));
        
        $data['tanggal_sampai'] =  $_POST['tanggal_sampai'];
        $this->session->set_userdata('tanggal_sampai', $this->input->post('tanggal_sampai'));


        $data['detail'] = $this->gl_model->gl_browse_trans();
        $data['detail_nomer'] = $this->gl_model->ambil_nomer();
        $data['detail_batasan'] = $this->gl_model->ambil_batasan_list();
        $this->load->view('haluser/cetak_trans', $data);
    }

model saya :
Code:
function ambil_master()
    {        
        
       $tanggal_mulai = $this->input->post('tanggal_mulai');
       $tanggal_sampai = $this->input->post('tanggal_sampai');
        
        $sql = "SELECT gl_master.master_id, gl_master.no_bukti, gl_master.tanggal, gl_akun.code, gl_akun.account,"
               ."gl_master.keterangan, gl_master.nilai, if(gl_master.jenis='d', gl_master.nilai,0) as debet, if(gl_master.jenis='k', gl_master.nilai,0) as kredit,"
               ."gl_master.jenis, gl_master.awal, gl_master.aktif "
               ."FROM gl_master JOIN gl_akun "
               ."ON gl_akun.code = gl_master.code "
               ."WHERE gl_master.tanggal BETWEEN '".$tanggal_mulai."' AND DATE '".$tanggal_sampai."'"
               ."order by gl_master.tanggal,gl_master.no_bukti,gl_master.jenis ASC";
        $data = $this->db->query($sql);
        return $data;
        
      }

#4
[eluser]InsiteFX[/eluser]
This will also help you with formating money values.

php.net - money_format

InsiteFX

#5
[eluser]redraw[/eluser]
[quote author="InsiteFX" date="1304500967"]This will also help you with formating money values.

php.net - money_format

InsiteFX[/quote]

thanks for your reply, but the problem is not currency format..
the problem is how to get correct summaries of the script above.

thanks you

#6
[eluser]toopay[/eluser]
[quote author="redraw" date="1304499527"]
model sya kya gini :
Code:
function cetak_master()
    {
        $data = $this->fungsi->accept_data(array_keys($_POST));
        //$this->gl_model->gl_browse_trans($data);
        $data['tanggal_mulai'] = $_POST['tanggal_mulai'];
        $this->session->set_userdata('tanggal_mulai', $this->input->post('tanggal_mulai'));
        
        $data['tanggal_sampai'] =  $_POST['tanggal_sampai'];
        $this->session->set_userdata('tanggal_sampai', $this->input->post('tanggal_sampai'));


        $data['detail'] = $this->gl_model->gl_browse_trans();
        $data['detail_nomer'] = $this->gl_model->ambil_nomer();
        $data['detail_batasan'] = $this->gl_model->ambil_batasan_list();
        $this->load->view('haluser/cetak_trans', $data);
    }
[/quote]
Fungsi diatas, harusnya kamu taruh di controller, bukan model!
Code:
// Taruh ini di controller
    function cetak_master()
    {
        $data = $this->fungsi->accept_data(array_keys($_POST));
        //$this->gl_model->gl_browse_trans($data);
        $data['tanggal_mulai'] = $_POST['tanggal_mulai'];
        // Ini disimpan di session untuk apa?
        $this->session->set_userdata('tanggal_mulai', $this->input->post('tanggal_mulai'));
        
        $data['tanggal_sampai'] =  $_POST['tanggal_sampai'];
        // Ini juga. Kalau mau dikirim ke model atau view, tdk perlu disimpan di session kan?
        $this->session->set_userdata('tanggal_sampai', $this->input->post('tanggal_sampai'));


        $data['detail'] = $this->gl_model->gl_browse_trans();
        $data['detail_nomer'] = $this->gl_model->ambil_nomer();
        $data['detail_batasan'] = $this->gl_model->ambil_batasan_list();
        $this->load->view('haluser/cetak_trans', $data);
    }
Untuk model
Code:
function ambil_master()
    {        
        
       $tanggal_mulai = $this->input->post('tanggal_mulai');
       $tanggal_sampai = $this->input->post('tanggal_sampai');
        
        $sql = "SELECT gl_master.master_id, gl_master.no_bukti, gl_master.tanggal, gl_akun.code, gl_akun.account,"
               ."gl_master.keterangan, gl_master.nilai, if(gl_master.jenis='d', gl_master.nilai,0) as debet, if(gl_master.jenis='k', gl_master.nilai,0) as kredit,"
               ."gl_master.jenis, gl_master.awal, gl_master.aktif "
               ."FROM gl_master JOIN gl_akun "
               ."ON gl_akun.code = gl_master.code "
               ."WHERE gl_master.tanggal BETWEEN '".$tanggal_mulai."' AND DATE '".$tanggal_sampai."'"
               ."order by gl_master.tanggal,gl_master.no_bukti,gl_master.jenis ASC";
        $data = $this->db->query($sql);
        // Semua model kamu, mestinya mengembalikan array sebagai hasil akhir
        // Bukan object lagi!
        return $data->result_array();
      }
Sehingga di view, kamu bisa lakukan sesuatu seperti ini
Code:
// Di sahal satu bagian view...
    &lt;?php
        $i = 0;
        $xnota = "";
        $row1 = 'Y';
        $v_debet = 0;
        $v_kredit = 0;
        // Untuk statement while
        $x = 0
        while($x<count($variabel_yang_menyimpan_array_dari_model))
        {
           $v_debet = $v_debet + $variabel_yang_menyimpan_array_dari_model[$x]['debet'];
           $v_kredit = $v_kredit + $variabel_yang_menyimpan_array_dari_model[$x]['kredit'];
           // Lanjutkan prosesnya sesuai kebutuhan
           // ...
           $x++;
        }
     ?&gt;

#7
[eluser]redraw[/eluser]
maaf mas baru sempet bales..
setelah sya rubah sesuai dengan koding yg mas kasih sya dapet eror disini:
Code:
while($x<count($detail))

katanya : Fatal error: Cannot use object of type CI_DB_mysql_result as array

yang sya ingin tanyakan coding dibawah ini apakah benar :
Code:
$rows->debet;

atau harus di ganti dengan yang lain ? soalnya saya liat variable rows belum di definisikan.

terimakasih

#8
[eluser]toopay[/eluser]
Sudah kuupdate diatas. Jangan lupa, di model yang kamu pakai, di statement 'return'-nya , pakai result_array()...

#9
[eluser]redraw[/eluser]
ok terimaksih banyak mas... solved


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.