Ask bagaimana cara menjumlahkan tabel debit kredit dan saldo

malam brother, mau tanya gimana ya membuat penjumlahan dari debit kredit dan tampil di form saldo? ane udh buat db dan codingannya spt berikut :

db rb cashflow.png

<?php if ($_GET[act]==''){ ?>
            <div class="col-xs-12">
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">Catatan Cashflow</h3>
                  <?php if($_SESSION[level]!='kepala'){ ?>
                  <a class='pull-right btn btn-primary btn-sm' href='index.php?view=ebukucashflow&act=tambah'>Tambahkan Data</a>
                  <?php } ?>
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th style='width:40px'>No</th>
                        <th>Kode Anggaran</th>
                        <th>Keterangan</th>
                        <th>No Bukti</th>
                        <th>Tanggal</th>
                        <th>Debit</th>
                        <th>Credit</th>
                        <th>Saldo</th>
                        <?php if($_SESSION[level]!='kepala'){ ?>
                        <th style='width:70px'>Action</th>
                        <?php } ?>
                      </tr>
                    </thead>
                    <tbody>
                  <?php
                    $tampil = mysql_query("SELECT * FROM rb_cashflow ORDER BY kode_ma DESC");
                    $no = 1;
                    while($r=mysql_fetch_array($tampil)){
                    echo "<tr><td>$no</td>
                              <td>$r[kode_ma]</td>
                              <td>$r[keterangan]</td>
                              <td>$r[no_bkt]</td>
                              <td>$r[tgl]</td>
                              <td>$r[debit]</td>
                              <td>$r[credit]</td>
                              <td>$r[saldo]</td>";
                              if($_SESSION[level]!='kepala'){
                        echo "<td><center>
                                <a class='btn btn-success btn-xs' title='Edit Data' href='index.php?view=ebukucashflow&act=edit&id=$r[kode_ma]'><span class='glyphicon glyphicon-edit'></span></a>
                                <a class='btn btn-danger btn-xs' title='Delete Data' href='index.php?view=ebukucashflow&hapus=$r[kode_ma]'><span class='glyphicon glyphicon-remove'></span></a>
                              </center></td>";
                              }
                            echo "</tr>";
                      $no++;
                      }
                      if (isset($_GET[hapus])){
                          mysql_query("DELETE FROM rb_cashflow where kode_ma='$_GET[hapus]'");
                          echo "<script>document.location='index.php?view=ebukucashflow';</script>";
                      }

                  ?>
                    </tbody>
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div>
<?php
}elseif($_GET[act]=='edit'){
    if (isset($_POST[update])){
        mysql_query("UPDATE rb_cashflow SET
                                         kode_ma = '$_POST[a]',
                                         keterangan = '$_POST[b]',
                                         no_bkt = '$_POST[c]',
                                         tgl = '$_POST[d]',
                                         debit = '$_POST[e]',
                                         Credit = '$_POST[f]' where kode_ma='$_GET[id]'");
      echo "<script>document.location='index.php?view=ebukucashflow';</script>";
    }
    $edit = mysql_query("SELECT * FROM rb_cashflow where kode_ma='$_GET[id]'");
    $s = mysql_fetch_array($edit);
    echo "<div class='col-md-12'>
              <div class='box box-info'>
                <div class='box-header with-border'>
                  <h3 class='box-title'>Edit Data Cashflow</h3>
                </div>
              <div class='box-body'>
              <form method='POST' class='form-horizontal' action='' enctype='multipart/form-data'>
                <div class='col-md-6'>
                  <table class='table table-condensed table-bordered'>
                  <tbody>
                    <tr><th scope='row'>Kode Anggaran</th> <td><select class='form-control' name='a'>
                                                                            <option value='0' selected>- Pilih Kode -</option>";
                                                                              $kode_ma = mysql_query("SELECT * FROM rb_anggaran");
                                                                              while($a = mysql_fetch_array($kode_ma)){
                                                                                  echo "<option value='$a[kode_ma]'>$a[kode_ma] $a[keterangan]</option>";
                                                                              }
                                                                    echo "</select></td></tr>
                    <tr><th width='120px' scope='row'>Keterangan</th> <td><input type='text' class='form-control' name='b' value='$s[keterangan]'></td></tr>
                    <tr><th width='120px' scope='row'>No Bukti</th> <td><input type='text' class='form-control' name='c' value='$s[no_bkt]'></td></tr>
                    <tr><th width='120px' scope='row'>Tanggal</th> <td><input type='date' class='form-control' name='d' value='$s[tgl]'> </td></tr>
                    <tr><th width='120px' scope='row'>Debit</th> <td><input type='text' class='form-control' name='e' value='$s[debit]'></td></tr>
                    <tr><th width='120px' scope='row'>Credit</th> <td><input type='text' class='form-control' name='f' value='$s[credit]'></td></tr>
                    </tbody>
                  </table>
                </div>
              </div>
              <div class='box-footer'>
                    <button type='submit' name='update' class='btn btn-info'>Update</button>
                    <a href='index.php?view=ebukucashflow'><button type='button' class='btn btn-default pull-right'>Cancel</button></a>

                  </div>
              </form>
            </div>";
}elseif($_GET[act]=='tambah'){
    if (isset($_POST[tambah])){
        mysql_query("INSERT INTO rb_cashflow VALUES('$_POST[a]','$_POST[b]','$_POST[c]','$_POST[d]','$_POST[e]','$_POST[f]')");
        echo "<script>document.location='index.php?view=ebukucashflow';</script>";
    }

    echo "<div class='col-md-12'>
              <div class='box box-info'>
                <div class='box-header with-border'>
                  <h3 class='box-title'>Tambah Data Cashflow</h3>
                </div>
              <div class='box-body'>
              <form method='POST' class='form-horizontal' action='' enctype='multipart/form-data'>
                <div class='col-md-6'>
                  <table class='table table-condensed table-bordered'>
                  <tbody>
                    <tr><th scope='row'>Kode Anggaran</th> <td><select class='form-control' name='a'>
                                                                            <option value='0' selected>- Pilih Kode -</option>";
                                                                              $kode_ma = mysql_query("SELECT * FROM rb_anggaran");
                                                                              while($a = mysql_fetch_array($kode_ma)){
                                                                                  echo "<option value='$a[kode_ma]'>$a[kode_ma] $a[keterangan]</option>";
                                                                              }
                                                                    echo "</select></td></tr>
                    <tr><th width='120px' scope='row'>Keterangan</th> <td><input type='text' class='form-control' name='b'> </td></tr>
                    <tr><th width='120px' scope='row'>No Bukti</th> <td><input type='text' class='form-control' name='c'></td></tr>
                    <tr><th width='120px' scope='row'>Tanggal</th> <td><input type='date' class='form-control' name='d'> </td></tr>
                    <tr><th width='120px' scope='row'>Debit</th> <td><input type='text' class='form-control' name='e'></td></tr>
                    <tr><th width='120px' scope='row'>Credit</th> <td><input type='text' class='form-control' name='f'></td></tr>
                    <tr><th width='120px' scope='row'>Saldo Akhir Bulan Lalu</th> <td><input type='text' class='form-control' name='g'></td></tr>
                  </tbody>
                  </table>
                </div>
              </div>
              <div class='box-footer'>
                    <button type='submit' name='tambah' class='btn btn-info'>Tambahkan</button>
                    <a href='index.php?view=ebukucashflow'><button type='button' class='btn btn-default pull-right'>Cancel</button></a>

                  </div>
              </form>
            </div>";
}
?>
avatar hikamauthar
@hikamauthar

6 Kontribusi 0 Poin

Diperbarui 3 tahun yang lalu

2 Jawaban:

<div>Coba bagian ini :&nbsp;</div><pre>&lt;?php if ($_GET[act]==''){ ?&gt; &lt;div class="col-xs-12"&gt;
&lt;div class="box"&gt; &lt;div class="box-header"&gt; &lt;h3 class="box-title"&gt;Catatan Cashflow&lt;/h3&gt; &lt;?php if($_SESSION[level]!='kepala'){ ?&gt; &lt;a class='pull-right btn btn-primary btn-sm' href='index.php?view=ebukucashflow&amp;act=tambah'&gt;Tambahkan Data&lt;/a&gt; &lt;?php } ?&gt; &lt;/div&gt;&lt;!-- /.box-header --&gt; &lt;div class="box-body"&gt; &lt;table id="example1" class="table table-bordered table-striped"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style='width:40px'&gt;No&lt;/th&gt; &lt;th&gt;Kode Anggaran&lt;/th&gt; &lt;th&gt;Keterangan&lt;/th&gt; &lt;th&gt;No Bukti&lt;/th&gt; &lt;th&gt;Tanggal&lt;/th&gt; &lt;th&gt;Debit&lt;/th&gt; &lt;th&gt;Credit&lt;/th&gt; &lt;th&gt;Saldo&lt;/th&gt; &lt;?php if($_SESSION[level]!='kepala'){ ?&gt; &lt;th style='width:70px'&gt;Action&lt;/th&gt; &lt;?php } ?&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $tampil = mysql_query("SELECT * FROM rb_cashflow ORDER BY kode_ma DESC"); $no = 1; while($r=mysql_fetch_array($tampil)){ echo "&lt;tr&gt;&lt;td&gt;$no&lt;/td&gt; &lt;td&gt;$r[kode_ma]&lt;/td&gt; &lt;td&gt;$r[keterangan]&lt;/td&gt; &lt;td&gt;$r[no_bkt]&lt;/td&gt; &lt;td&gt;$r[tgl]&lt;/td&gt; &lt;td&gt;$r[debit]&lt;/td&gt; &lt;td&gt;$r[credit]&lt;/td&gt; &lt;td&gt;$r[saldo]&lt;/td&gt;"; if($_SESSION[level]!='kepala'){ echo "&lt;td&gt;&lt;center&gt; &lt;a class='btn btn-success btn-xs' title='Edit Data' href='index.php?view=ebukucashflow&amp;act=edit&amp;id=$r[kode_ma]'&gt;&lt;span class='glyphicon glyphicon-edit'&gt;&lt;/span&gt;&lt;/a&gt; &lt;a class='btn btn-danger btn-xs' title='Delete Data' href='index.php?view=ebukucashflow&amp;hapus=$r[kode_ma]'&gt;&lt;span class='glyphicon glyphicon-remove'&gt;&lt;/span&gt;&lt;/a&gt; &lt;/center&gt;&lt;/td&gt;"; } echo "&lt;/tr&gt;"; $no++; }</pre><div><br>Di ubah menjadi :<br><br></div><pre>&lt;?php if ($_GET[act]==''){ ?&gt; &lt;div class="col-xs-12"&gt;
&lt;div class="box"&gt; &lt;div class="box-header"&gt; &lt;h3 class="box-title"&gt;Catatan Cashflow&lt;/h3&gt; &lt;?php if($_SESSION[level]!='kepala'){ ?&gt; &lt;a class='pull-right btn btn-primary btn-sm' href='index.php?view=ebukucashflow&amp;act=tambah'&gt;Tambahkan Data&lt;/a&gt; &lt;?php } ?&gt; &lt;/div&gt;&lt;!-- /.box-header --&gt; &lt;div class="box-body"&gt; &lt;table id="example1" class="table table-bordered table-striped"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style='width:40px'&gt;No&lt;/th&gt; &lt;th&gt;Kode Anggaran&lt;/th&gt; &lt;th&gt;Keterangan&lt;/th&gt; &lt;th&gt;No Bukti&lt;/th&gt; &lt;th&gt;Tanggal&lt;/th&gt; &lt;th&gt;Debit&lt;/th&gt; &lt;th&gt;Credit&lt;/th&gt; &lt;th&gt;Saldo&lt;/th&gt; &lt;?php if($_SESSION[level]!='kepala'){ ?&gt; &lt;th style='width:70px'&gt;Action&lt;/th&gt; &lt;?php } ?&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $tampil = mysql_query("SELECT * FROM rb_cashflow ORDER BY kode_ma DESC"); $no = 1; $saldo = 0; while($r=mysql_fetch_array($tampil)){ $saldo = $saldo + $r['debit']; $saldo = $saldo - $r['credit']; echo "&lt;tr&gt;&lt;td&gt;$no&lt;/td&gt; &lt;td&gt;$r[kode_ma]&lt;/td&gt; &lt;td&gt;$r[keterangan]&lt;/td&gt; &lt;td&gt;$r[no_bkt]&lt;/td&gt; &lt;td&gt;$r[tgl]&lt;/td&gt; &lt;td&gt;$r[debit]&lt;/td&gt; &lt;td&gt;$r[credit]&lt;/td&gt; &lt;td&gt;$saldo&lt;/td&gt;"; if($_SESSION[level]!='kepala'){ echo "&lt;td&gt;&lt;center&gt; &lt;a class='btn btn-success btn-xs' title='Edit Data' href='index.php?view=ebukucashflow&amp;act=edit&amp;id=$r[kode_ma]'&gt;&lt;span class='glyphicon glyphicon-edit'&gt;&lt;/span&gt;&lt;/a&gt; &lt;a class='btn btn-danger btn-xs' title='Delete Data' href='index.php?view=ebukucashflow&amp;hapus=$r[kode_ma]'&gt;&lt;span class='glyphicon glyphicon-remove'&gt;&lt;/span&gt;&lt;/a&gt; &lt;/center&gt;&lt;/td&gt;"; } echo "&lt;/tr&gt;"; $no++; }</pre><div><br>Semoga berhasil</div>

avatar ahanafi
@ahanafi

815 Kontribusi 554 Poin

Dipost 3 tahun yang lalu

<div>setelah ane rubah &amp; dicoba gak ada perubahan bang..? apa karna di tabel databasenya gk dibuat kolom saldo ya bang?</div>

avatar hikamauthar
@hikamauthar

6 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Tanggapan

ngga ada kolom di database juga ga ngaruh, mungkin di bagian echo-nya.

Login untuk ikut Jawaban