APLIKASI PENJUALAN KENDARAAN TUNAI DAN KREDIT

 

 

 

 

 

 

 

 

 

 

Releasi tabel

 

 

Module koneksi database

 

Imports System.Data.OleDb

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

 

Module Module1

 

    Public Conn As OleDbConnection

    Public DA As OleDbDataAdapter

    Public DS As DataSet

    Public CMD As OleDbCommand

    Public DR As OleDbDataReader

 

 

    Public laporan As New ReportDocument

    Public TabelLogon As CrystalDecisions.Shared.TableLogOnInfo

 

    Public Sub SetingLaporan()

        Dim BacaTabel As CrystalDecisions.CrystalReports.Engine.Table

        For Each BacaTabel In laporan.Database.Tables

            TabelLogon = BacaTabel.LogOnInfo

            With TabelLogon.ConnectionInfo

                .ServerName = Application.StartupPath & "\dbkredit.mdb"

                .UserID = ""

                .Password = ""

                .DatabaseName = ""

            End With

            BacaTabel.ApplyLogOnInfo(TabelLogon)

        Next BacaTabel

    End Sub

 

 

    Public Sub Koneksi()

        Try

            Conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=dbkredit.mdb")

            Conn.Open()

 

        Catch ex As Exception

            MsgBox(ex.Message)

            End

        End Try

    End Sub

End Module

 

 

 

 

Imports System.Data.OleDb

 

Public Class MasterLogin

 

    Dim hitung As Integer

 

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        Me.CenterToScreen()

        Call Koneksi()

        CMD = New OleDbCommand("select * from users where nama_user='" & Tnama.Text & "' and pwd_user='" & Tpassword.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If DR.HasRows Then

            Me.Visible = False

            MasterMenu.Show()

 

            MasterMenu.panelkode.Text = DR.Item(0)

            MasterMenu.panelnama.Text = DR.Item(1)

            MasterMenu.panelstatus.Text = UCase(DR.Item(3))

 

        Else

            MsgBox("Login gagal")

            Tnama.Clear()

            Tpassword.Clear()

            Tnama.Focus()

 

            hitung = hitung + 1

            If hitung = 3 Then

                MsgBox("Login sudah 3x salah")

                End

            End If

        End If

 

    End Sub

 

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click

        End

    End Sub

 

    Private Sub tnama_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Tnama.KeyDown

        If e.KeyCode = Keys.Enter Then

            Tpassword.Focus()

        End If

    End Sub

 

    Private Sub tpassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Tpassword.KeyDown

        If e.KeyCode = Keys.Enter Then

            OK.Focus()

        End If

    End Sub

End Class

 

 

 

 

 

 

 

 

 

Imports System.Data.OleDb

 

Public Class PenjualanTunai

 

    Sub Notis()

        'Call Koneksi()

        CMD = New OleDbCommand("select nomor_jualtunai from tunai order by nomor_jualtunai desc", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If Not DR.HasRows Then

            tnomor.Text = Format(Today, "yyMMdd") + "0001"

        Else

            If Microsoft.VisualBasic.Left(DR(0), 6) = Format(Today, "yyMMdd") Then

                tnomor.Text = DR(0) + 1

            Else

                tnomor.Text = Format(Today, "yyMMdd") + "0001"

            End If

        End If

    End Sub

 

    Sub Kosongkan()

        Call Notis()

        cbokodekendaraan.Text = ""

        tmerk.Text = ""

        tjenis.Text = ""

        ttahunpembuatan.Text = ""

        tisiselinder.Text = ""

        tnorangka.Text = ""

        tnomesin.Text = ""

        twarna.Text = ""

        tbahanbakar.Text = ""

        tharga.Text = ""

 

        cbokodecustomer.Text = ""

        tnama.Text = ""

        talamat.Text = ""

        ttelprumah.Text = ""

        tnohp.Text = ""

        tketerangan.Text = ""

        CheckBox1.Checked = False

        CheckBox2.Checked = False

        CheckBox3.Checked = False

        tjumlahbayar.Text = ""

        tketeranganbayar.Text = ""

    End Sub

 

    Sub TampilKendaraan()

        CMD = New OleDbCommand("select * from kendaraan where status_kendaraan='TERSEDIA'", Conn)

        DR = CMD.ExecuteReader

        cbokodekendaraan.Items.Clear()

        Do While DR.Read

            cbokodekendaraan.Items.Add(DR(0))

        Loop

    End Sub

 

    Sub TampilCustomer()

        CMD = New OleDbCommand("select * from customer", Conn)

        DR = CMD.ExecuteReader

        cbokodecustomer.Items.Clear()

        Do While DR.Read

            cbokodecustomer.Items.Add(DR(0))

        Loop

    End Sub

 

    Sub TampilGrid()

        DA = New OleDbDataAdapter("select * from tunai", Conn)

        DS = New DataSet

        DA.Fill(DS)

        DGV.DataSource = DS.Tables(0)

        DGV.ReadOnly = True

    End Sub

 

    Sub CariKendaraan()

        CMD = New OleDbCommand("select * from kendaraan where kode_kendaraan='" & cbokodekendaraan.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

    End Sub

 

    Sub Ketemukendaraan()

        ttahunpembuatan.Text = DR.Item("tahun_pembuatan")

        tnorangka.Text = DR.Item("nomor_rangka")

        tnomesin.Text = DR.Item("nomor_mesin")

        tharga.Text = DR.Item("harga_jual")

        tharga.Text = FormatNumber(tharga.Text, 0)

        tmerk.Text = DR.Item("merk")

        tjenis.Text = DR.Item("jenis")

        tisiselinder.Text = DR.Item("isi_selinder")

        twarna.Text = DR.Item("warna")

        tbahanbakar.Text = DR.Item("bahan_bakar")

        'TextBox2.Focus()

    End Sub

 

    Sub cariCustomer()

        CMD = New OleDbCommand("select * from CUSTOMER where kode_customer='" & cbokodecustomer.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

    End Sub

 

    Sub Ketemucustomer()

        tnama.Text = DR.Item("nama_customer")

        talamat.Text = DR.Item("alamat")

        ttelprumah.Text = DR.Item("telepon")

        tnohp.Text = DR.Item("hp")

        tketerangan.Text = DR.Item("keterangan")

 

        If DR("ktp") <> 0 Then

            CheckBox1.Checked = True

        Else

            CheckBox1.Checked = False

        End If

 

        If DR("kk") <> 0 Then

            CheckBox2.Checked = True

        Else

            CheckBox2.Checked = False

        End If

 

        If DR("slipgaji") <> 0 Then

            CheckBox3.Checked = True

        Else

            CheckBox3.Checked = False

        End If

        Call Tampilketerangan()

    End Sub

 

    Sub Tampilketerangan()

        If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True Then

            tketerangan.Text = "Persyaratan lengkap"

        Else

            tketerangan.Text = "Persyaratan belum lengkap"

        End If

    End Sub

 

    Private Sub PenjualanTunai_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Me.CenterToScreen()

        Call Koneksi()

        Call Notis()

        Call TampilKendaraan()

        Call TampilCustomer()

        Call TampilGrid()

    End Sub

 

    Private Sub cbokodekendaraan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbokodekendaraan.SelectedIndexChanged

        Call CariKendaraan()

        If DR.HasRows Then

            Call Ketemukendaraan()

            tjumlahbayar.Text = tharga.Text

            If tjumlahbayar.Text < tharga.Text Then

                tketeranganbayar.Text = "Kurang " & tjumlahbayar.Text - tharga.Text & ""

            Else

                tketeranganbayar.Text = "Lunas"

            End If

        End If

    End Sub

 

 

    Private Sub cbokodecustomer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbokodecustomer.SelectedIndexChanged

        Call cariCustomer()

        If DR.HasRows Then

            Call Ketemucustomer()

        End If

    End Sub

 

    Private Sub tjumlahbayar_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tjumlahbayar.KeyDown

        If e.KeyCode = Keys.Enter Then

            If tjumlahbayar.Text < tharga.Text Then

                tketeranganbayar.Text = "Kurang " & FormatNumber(tharga.Text, 0) - FormatNumber(tjumlahbayar.Text, 0) & ""

            Else

                tketeranganbayar.Text = "Lunas"

            End If

        End If

    End Sub

 

    Private Sub tjumlahbayar_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tjumlahbayar.TextChanged

        On Error Resume Next

        tjumlahbayar.Text = FormatNumber(tjumlahbayar.Text, 0)

        tjumlahbayar.SelectionStart = Len(tjumlahbayar.Text)

    End Sub

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        If cbokodekendaraan.Text = "" Or cbokodecustomer.Text = "" Or tjumlahbayar.Text = "" Then

            MsgBox("Transaksi belum lengkap")

            Exit Sub

        End If

 

        Dim simpan As String = "insert into tunai values ('" & tnomor.Text & "','" & ttanggal.Text & "','" & cbokodecustomer.Text & "','" & cbokodekendaraan.Text & "','" & tharga.Text & "','" & tjumlahbayar.Text & "','" & tketeranganbayar.Text & "','USR01')"

        CMD = New OleDbCommand(simpan, Conn)

        CMD.ExecuteNonQuery()

 

        Dim editkendaraan As String = "update kendaraan set status_kendaraan='TERJUAL' where kode_kendaraan='" & cbokodekendaraan.Text & "'"

        CMD = New OleDbCommand(editkendaraan, Conn)

        CMD.ExecuteNonQuery()

 

        If MessageBox.Show("cetak faktur...?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

            Cetak.Show()

            laporan.Load("faktur tunai.rpt")

            Call SetingLaporan()

            Cetak.CRV.ReportSource = laporan

            Cetak.CRV.RefreshReport()

        End If

        Call Kosongkan()

        Call TampilKendaraan()

        Call TampilGrid()

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Me.Close()

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Call Kosongkan()

    End Sub

End Class

 

 

 

Imports System.Data.OleDb

Imports System.Math

 

Public Class PenjualanKredit

 

    Sub Notis()

        'Call Koneksi()

        CMD = New OleDbCommand("select nomor_jualkredit from kredit order by nomor_jualkredit desc", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If Not DR.HasRows Then

            tnomor.Text = Format(Today, "yyMMdd") + "0001"

        Else

            If Microsoft.VisualBasic.Left(DR(0), 6) = Format(Today, "yyMMdd") Then

                tnomor.Text = DR(0) + 1

            Else

                tnomor.Text = Format(Today, "yyMMdd") + "0001"

            End If

        End If

    End Sub

 

    Sub Kosongkan()

        Call Notis()

        cbokodekendaraan.Text = ""

        tmerk.Text = ""

        tjenis.Text = ""

        ttahunpembuatan.Text = ""

        tisiselinder.Text = ""

        tnorangka.Text = ""

        tnomesin.Text = ""

        twarna.Text = ""

        tbahanbakar.Text = ""

        thargacash.Text = ""

 

        cbokodecustomer.Text = ""

        tnama.Text = ""

        talamat.Text = ""

        ttelprumah.Text = ""

        tnohp.Text = ""

        tketerangan.Text = ""

        CheckBox1.Checked = False

        CheckBox2.Checked = False

        CheckBox3.Checked = False

        tuangmuka.Text = ""

        tlamacicilan.Text = ""

        tbunga.Text = ""

        tangsuran.Text = ""

        cbolamatahun.Text = ""

        tbiayaadm.Text = ""

        tbiayaasuransi.Text = ""

        Tpokok.Text = ""

        Ttotalbunga.Text = ""

        thargakredit.Text = ""

    End Sub

 

    Sub TampilKendaraan()

        CMD = New OleDbCommand("select * from kendaraan where status_kendaraan='TERSEDIA'", Conn)

        DR = CMD.ExecuteReader

        cbokodekendaraan.Items.Clear()

        Do While DR.Read

            cbokodekendaraan.Items.Add(DR(0))

        Loop

    End Sub

 

    Sub TampilCustomer()

        CMD = New OleDbCommand("select * from customer", Conn)

        DR = CMD.ExecuteReader

        cbokodecustomer.Items.Clear()

        Do While DR.Read

            cbokodecustomer.Items.Add(DR(0))

        Loop

    End Sub

 

    Sub TampilGrid()

        DA = New OleDbDataAdapter("select * from kredit", Conn)

        DS = New DataSet

        DA.Fill(DS)

        DGV.DataSource = DS.Tables(0)

        DGV.ReadOnly = True

    End Sub

 

    Sub CariKendaraan()

        CMD = New OleDbCommand("select * from kendaraan where kode_kendaraan='" & cbokodekendaraan.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

    End Sub

 

    Sub Ketemukendaraan()

        ttahunpembuatan.Text = DR.Item("tahun_pembuatan")

        tnorangka.Text = DR.Item("nomor_rangka")

        tnomesin.Text = DR.Item("nomor_mesin")

        thargacash.Text = DR.Item("harga_jual")

        'thargacash.Text=FormatNumber(thargacash.Text,0)

        tmerk.Text = DR.Item("merk")

        tjenis.Text = DR.Item("jenis")

        tisiselinder.Text = DR.Item("isi_selinder")

        twarna.Text = DR.Item("warna")

        tbahanbakar.Text = DR.Item("bahan_bakar")

        'TextBox2.Focus()

    End Sub

 

    Sub cariCustomer()

        CMD = New OleDbCommand("select * from CUSTOMER where kode_customer='" & cbokodecustomer.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

    End Sub

 

    Sub Ketemucustomer()

        tnama.Text = DR.Item("nama_customer")

        talamat.Text = DR.Item("alamat")

        ttelprumah.Text = DR.Item("telepon")

        tnohp.Text = DR.Item("hp")

        tketerangan.Text = DR.Item("keterangan")

 

        If DR("ktp") <> 0 Then

            CheckBox1.Checked = True

        Else

            CheckBox1.Checked = False

        End If

 

        If DR("kk") <> 0 Then

            CheckBox2.Checked = True

        Else

            CheckBox2.Checked = False

        End If

 

        If DR("slipgaji") <> 0 Then

            CheckBox3.Checked = True

        Else

            CheckBox3.Checked = False

        End If

        Call Tampilketerangan()

    End Sub

 

    Sub Tampilketerangan()

        If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True Then

            tketerangan.Text = "Persyaratan lengkap"

        Else

            tketerangan.Text = "Persyaratan belum lengkap"

        End If

    End Sub

 

    Private Sub PenjualanTunai_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Me.CenterToScreen()

        Call Koneksi()

        Call Notis()

        Call TampilKendaraan()

        Call TampilCustomer()

        Call TampilGrid()

    End Sub

 

    Private Sub cbokodekendaraan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbokodekendaraan.SelectedIndexChanged

        Call CariKendaraan()

        If DR.HasRows Then

            Call Ketemukendaraan()

        End If

    End Sub

 

 

    Private Sub cbokodecustomer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbokodecustomer.SelectedIndexChanged

        Call cariCustomer()

        If DR.HasRows Then

            Call Ketemucustomer()

        End If

    End Sub

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        If cbokodekendaraan.Text = "" Or cbokodecustomer.Text = "" Or tuangmuka.Text = "" Or tlamacicilan.Text = "" Or tbunga.Text = "" Or tangsuran.Text = "" Then

            MsgBox("Transaksi belum lengkap")

            Exit Sub

        End If

 

        Dim simpan As String = "insert into kredit values ('" & tnomor.Text & "','" & ttanggal.Text & "','" & cbokodecustomer.Text & "','" & cbokodekendaraan.Text & "','" & thargakredit.Text & "','" & tbiayaasuransi.Text & "','" & tbiayaadm.Text & "','" & tuangmuka.Text & "','" & tbunga.Text & "','" & tlamacicilan.Text & "',0,'" & tangsuran.Text & "',0,'" & thargakredit.Text & "','-','USR01')"

        CMD = New OleDbCommand(simpan, Conn)

        CMD.ExecuteNonQuery()

 

        Dim editkendaraan As String = "update kendaraan set status_kendaraan='TERJUAL' where kode_kendaraan='" & cbokodekendaraan.Text & "'"

        CMD = New OleDbCommand(editkendaraan, Conn)

        CMD.ExecuteNonQuery()

 

        If MessageBox.Show("cetak faktur...?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

            Cetak.Show()

            laporan.Load("faktur kredit.rpt")

            Call SetingLaporan()

            Cetak.CRV.ReportSource = laporan

            Cetak.CRV.RefreshReport()

        End If

        Call Kosongkan()

        Call TampilKendaraan()

        Call TampilGrid()

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Me.Close()

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Call Kosongkan()

    End Sub

 

    Private Sub tlamacicilan_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tlamacicilan.KeyDown

        If e.KeyCode = Keys.Enter Then

            tangsuran.Text = Round(Microsoft.VisualBasic.Pmt(Val(tbunga.Text) / 100 / 12, Val(tlamacicilan.Text), Val(thargacash.Text), 2) * -1)

        End If

    End Sub

 

 

    Private Sub cbolamatahun_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbolamatahun.SelectedIndexChanged

 

        Call CariKendaraan()

        If DR.HasRows Then

            Call Ketemukendaraan()

        End If

        If cbolamatahun.Text = 1 Then

            tbiayaasuransi.Text = Val(thargacash.Text) * 7.5 / 100

            tbiayaadm.Text = 300000

            tbunga.Text = 6

        ElseIf cbolamatahun.Text = 2 Then

            tbiayaasuransi.Text = Val(thargacash.Text) * 8.5 / 100

            tbiayaadm.Text = 400000

            tbunga.Text = 7

        ElseIf cbolamatahun.Text = 3 Then

            tbiayaasuransi.Text = Val(thargacash.Text) * 9.5 / 100

            tbiayaadm.Text = 500000

            tbunga.Text = 8

        Else

            MsgBox("Jangka waktu tidak valid")

            tbunga.Text = 0

            tbiayaadm.Text = 0

            tbiayaasuransi.Text = 0

        End If

 

 

        tuangmuka.Text = Val(thargacash.Text) * 20 / 100    'dp 20% dari harga cash

        tlamacicilan.Text = Val(cbolamatahun.Text) * 12     '1 thn = 12 bulan

        Tpokok.Text = Val(thargacash.Text) - Val(tuangmuka.Text)

        Ttotalbunga.Text = Val(Tpokok.Text) * (Val(tbunga.Text) / 100) * Val(cbolamatahun.Text)

        tangsuran.Text = (Val(Tpokok.Text) + Val(Ttotalbunga.Text)) / Val(tlamacicilan.Text)

        thargakredit.Text = Val(Tpokok.Text) + Val(tbiayaadm.Text) + Val(tbiayaasuransi.Text) + Val(Ttotalbunga.Text) + Val(tuangmuka.Text)

        Call formatangka()

    End Sub

 

    Sub formatangka()

        thargacash.Text = FormatNumber(thargacash.Text, 0)

        thargakredit.Text = FormatNumber(thargakredit.Text, 0)

        Tpokok.Text = FormatNumber(Tpokok.Text, 0)

        Ttotalbunga.Text = FormatNumber(Ttotalbunga.Text, 0)

        tbiayaadm.Text = FormatNumber(tbiayaadm.Text, 0)

        tbiayaasuransi.Text = FormatNumber(tbiayaasuransi.Text, 0)

        tuangmuka.Text = FormatNumber(tuangmuka.Text, 0)

        tangsuran.Text = FormatNumber(tangsuran.Text, 0)

    End Sub

 

    Private Sub Label29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

    End Sub

 

    Private Sub GroupBox5_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

    End Sub

End Class

 

 

 

Imports System.Data.OleDb

Imports System.Math

 

Public Class Pembayaran

 

    Sub Notis()

        CMD = New OleDbCommand("select nomor_bayar from bayarcicilan order by nomor_bayar desc", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If Not DR.HasRows Then

            tnomor.Text = Format(Today, "yyMMdd") + "0001"

        Else

            If Microsoft.VisualBasic.Left(DR(0), 6) = Format(Today, "yyMMdd") Then

                tnomor.Text = DR(0) + 1

            Else

                tnomor.Text = Format(Today, "yyMMdd") + "0001"

            End If

        End If

    End Sub

 

    Sub Tampilcboidkredit()

        CMD = New OleDbCommand("select nomor_jualkredit from kredit where keterangan_kredit='-'", Conn)

        DR = CMD.ExecuteReader

        cboIDKredit.Items.Clear()

        Do While DR.Read

            cboIDKredit.Items.Add(DR(0))

        Loop

    End Sub

 

    Sub Kosongkan()

        Call Notis()

        cboIDKredit.Text = ""

        Tkodekendaraan.Text = ""

        tmerk.Text = ""

        tjenis.Text = ""

        ttahunpembuatan.Text = ""

        tisiselinder.Text = ""

        tnorangka.Text = ""

        tnomesin.Text = ""

        twarna.Text = ""

        tbahanbakar.Text = ""

        thargakendaraan.Text = ""

        Ttanggalkredit.Text = ""

        Tpokokangsuran.Text = ""

 

        tkodecustomer.Text = ""

        tnama.Text = ""

        talamat.Text = ""

        ttelprumah.Text = ""

        tnohp.Text = ""

        tketerangan.Text = ""

        CheckBox1.Checked = False

        CheckBox2.Checked = False

        CheckBox3.Checked = False

 

        tjatuhtempo.Text = ""

        tjumlahhariterlambat.Text = ""

        tdenda.Text = ""

        ttelahbayar.Text = ""

        tsisabulanlalu.Text = ""

        tangsurandandenda.Text = ""

        tangsuranke.Text = ""

        tsisapembayaran.Text = ""

        Tketeranganbayar.Text = ""

 

    End Sub

 

    Sub TampilGrid()

        DA = New OleDbDataAdapter("select * from bayarcicilan", Conn)

        DS = New DataSet

        DA.Fill(DS)

        DGV.DataSource = DS.Tables(0)

        DGV.ReadOnly = True

    End Sub

 

    Sub CariKendaraan()

        CMD = New OleDbCommand("select * from kendaraan where kode_kendaraan='" & Tkodekendaraan.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

    End Sub

 

    Sub Ketemukendaraan()

        ttahunpembuatan.Text = DR.Item("tahun_pembuatan")

        tnorangka.Text = DR.Item("nomor_rangka")

        tnomesin.Text = DR.Item("nomor_mesin")

        thargakendaraan.Text = DR.Item("harga_jual")

 

        tmerk.Text = DR.Item("merk")

        tjenis.Text = DR.Item("jenis")

        tisiselinder.Text = DR.Item("isi_selinder")

        twarna.Text = DR.Item("warna")

        tbahanbakar.Text = DR.Item("bahan_bakar")

    End Sub

 

    Sub cariCustomer()

        CMD = New OleDbCommand("select * from CUSTOMER where kode_customer='" & tkodecustomer.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

    End Sub

 

    Sub Ketemucustomer()

        tnama.Text = DR.Item("nama_customer")

        talamat.Text = DR.Item("alamat")

        ttelprumah.Text = DR.Item("telepon")

        tnohp.Text = DR.Item("hp")

        tketerangan.Text = DR.Item("keterangan")

 

        If DR("ktp") <> 0 Then

            CheckBox1.Checked = True

        Else

            CheckBox1.Checked = False

        End If

 

        If DR("kk") <> 0 Then

            CheckBox2.Checked = True

        Else

            CheckBox2.Checked = False

        End If

 

        If DR("slipgaji") <> 0 Then

            CheckBox3.Checked = True

        Else

            CheckBox3.Checked = False

        End If

        Call Tampilketerangan()

    End Sub

 

    Sub Tampilketerangan()

        If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True Then

            tketerangan.Text = "Persyaratan lengkap"

        Else

            tketerangan.Text = "Persyaratan belum lengkap"

        End If

    End Sub

 

    Private Sub Pembayaran_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Me.CenterToScreen()

        Call Koneksi()

        Call Notis()

        Call Tampilcboidkredit()

        Call TampilGrid()

    End Sub

 

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        If Tkodekendaraan.Text = "" Then

            MsgBox("Transaksi belum lengkap")

            Exit Sub

        End If

 

        Dim simpan As String = "insert into bayarcicilan values ('" & tnomor.Text & "','" & ttanggalbayar.Text & "','" & cboIDKredit.Text & "','" & tjatuhtempo.Text & "','" & tjumlahhariterlambat.Text & "','" & tdenda.Text & "','" & tangsurandandenda.Text & "','" & tsisapembayaran.Text & "','" & tangsuranke.Text & "','" & Tketeranganbayar.Text & "','USR01')"

        CMD = New OleDbCommand(simpan, Conn)

        CMD.ExecuteNonQuery()

 

        '==================================

        CMD = New OleDbCommand("SELECT * FROM kredit WHERE nomor_jualkredit='" & cboIDKredit.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If DR.HasRows Then

            If tsisapembayaran.Text = 0 Then

                Dim edit1 As String = "UPDATE kredit SET SISA='" & tsisapembayaran.Text & "',telah_bayar= '" & DR("telah_bayar") + tangsurandandenda.Text & "',ANGSURAN_KE='" & tangsuranke.Text & "',keterangan_kredit='LUNAS' WHERE nomor_jualkredit='" & cboIDKredit.Text & "'"

                CMD = New OleDbCommand(edit1, Conn)

                CMD.ExecuteNonQuery()

            Else

                Dim edit2 = "UPDATE kredit SET SISA='" & DR("sisa") - tangsurandandenda.Text & "',telah_bayar= '" & DR("telah_bayar") + tangsurandandenda.Text & "',ANGSURAN_KE='" & tangsuranke.Text & "',keterangan_kredit='-' WHERE nomor_jualkredit='" & cboIDKredit.Text & "'"

                CMD = New OleDbCommand(edit2, Conn)

                CMD.ExecuteNonQuery()

            End If

 

            CMD = New OleDbCommand("SELECT * FROM kredit WHERE nomor_jualkredit='" & cboIDKredit.Text & "' AND SISA=0", Conn)

            DR = CMD.ExecuteReader

            DR.Read()

            If DR.HasRows Then

                Dim edit3 As String = "UPDATE kredit SET KETerangan_kredit='LUNAS' WHERE nomor_jualkredit='" & cboIDKredit.Text & "'"

                CMD = New OleDbCommand(edit3, Conn)

                CMD.ExecuteNonQuery()

            End If

        End If

 

        If MessageBox.Show("cetak faktur...?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

            Cetak.Show()

            laporan.Load("bayar cicilan.rpt")

            Call SetingLaporan()

            Cetak.CRV.ReportSource = laporan

            Cetak.CRV.RefreshReport()

        End If

        Call Kosongkan()

        Call Notis()

        Call TampilGrid()

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Me.Close()

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Call Kosongkan()

    End Sub

 

    Private Sub cboidkredit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboIDKredit.SelectedIndexChanged

        'On Error Resume Next

        CMD = New OleDbCommand("SELECT COUNT(nomor_jualkredit)  FROM bayarcicilan WHERE nomor_jualkredit='" & cboIDKredit.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If Not DR.HasRows Then

            tangsuranke.Text = 1

        Else

            tangsuranke.Text = DR(0) + 1

        End If

 

        CMD = New OleDbCommand("select * from kredit where nomor_jualkredit='" & cboIDKredit.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If DR.HasRows Then

 

            tkodecustomer.Text = DR("kode_customer")

            Tkodekendaraan.Text = DR("kode_kendaraan")

            Ttanggalkredit.Text = DR("tanggal_kredit")

            Tpokokangsuran.Text = DR("angsuran")

            'jika belum pernah membayar angsuran maka jatuh tempo pembayaran adalah dimulai dari tanggal beli + 30 hari atau tambah 1 bulan

            tjatuhtempo.Text = DateAdd(DateInterval.Month, Val(tangsuranke.Text), DateValue(Ttanggalkredit.Text))

 

            'jumlah denda adalah 5000 x hari keterlambatan dati tgl jatuh tempo

            If ttanggalbayar.Value > DateValue(tjatuhtempo.Text) Then

                'tterlambat.Text = Today() - DateValue(tjatuhtempo.Text)

                tjumlahhariterlambat.Text = DateDiff(DateInterval.Day, DateValue(tjatuhtempo.Text), ttanggalbayar.Value)

                tdenda.Text = 5000 * Val(tjumlahhariterlambat.Text)

                'tangsurandandenda.Text = Format(DR("angsuran") + Val(tdenda.Text), "###,###,###,###")

            Else

                tjumlahhariterlambat.Text = 0

                tdenda.Text = 0

                'tangsurandandenda.Text = Format(DR("angsuran") + Val(tdenda.Text), "###,###,###,###")

            End If

 

            tangsurandandenda.Text = Val(Tpokokangsuran.Text) + Val(tdenda.Text)

            tsisabulanlalu.Text = DR("sisa")

 

            If DR("telah_bayar") = 0 Then

                ttelahbayar.Text = 0

            Else

                ttelahbayar.Text = DR("telah_bayar")

            End If

 

            Call CariKendaraan()

            If DR.HasRows Then

                Call Ketemukendaraan()

            End If

 

            Call cariCustomer()

            If DR.HasRows Then

                Call Ketemucustomer()

            End If

        End If

 

        '======================================

 

        CMD = New OleDbCommand("SELECT * FROM kredit WHERE nomor_jualkredit='" & cboIDKredit.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        'jika angsuran melebihi sisa pembayaran,maka tampilkan dalam keterangan uang kembaliannya

        If Val(tangsurandandenda.Text) > DR("sisa") Then

            tangsurandandenda.Text = tangsurandandenda.Text

            Tketeranganbayar.Text = "kembali" & Space(1) & tangsurandandenda.Text - DR("sisa") & Space(1) & "LUNAS"

            tangsuranke.Text = 1

            tsisapembayaran.Text = 0

        Else

            'sisa sekarang tampil setelah dikurang angsuran

            'indikasi cicilan terus berubah yaitu cicilan bulan lalu + 1

            tsisapembayaran.Text = Val(tsisabulanlalu.Text) - Val(tangsurandandenda.Text) 'tampilkan dalam keterangan indikasi pembayaran bulan jatuh tempo

            Tketeranganbayar.Text = "Pembayaran Cicilan Untuk Bulan" & Space(1) & Format(DateValue(tjatuhtempo.Text), "MMMM yyyy")

        End If

        Call Formatangka()

    End Sub

 

    Sub Formatangka()

        thargakendaraan.Text = FormatNumber(thargakendaraan.Text, 0)

        Tpokokangsuran.Text = FormatNumber(Tpokokangsuran.Text, 0)

        tdenda.Text = FormatNumber(tdenda.Text, 0)

        ttelahbayar.Text = FormatNumber(ttelahbayar.Text, 0)

        tsisabulanlalu.Text = FormatNumber(tsisabulanlalu.Text, 0)

        tangsurandandenda.Text = FormatNumber(tangsurandandenda.Text, 0)

        tsisapembayaran.Text = FormatNumber(tsisapembayaran.Text, 0)

    End Sub

End Class

 

 

 

 

 

 

 

Imports System.Data.OleDb

 

Public Class LaporanTunggakan

 

    Dim angsuran As Double

    Dim jumlahbarisnol As Integer

    Dim barisvalid As Integer

    Dim tanggalsekarang As Date = Today

    Dim lamacicilan As Integer

    Dim tanggalkredit As Date

 

    Sub TampilNomorKredit()

        CMD = New OleDbCommand("select kredit.nomor_jualkredit,customer.nama_customer,kredit.tanggal_kredit,angsuran_ke from kredit,customer where customer.kode_customer=kredit.kode_customer and cdate(tanggal_kredit) < '" & tanggalsekarang & "'", Conn)

        DR = CMD.ExecuteReader

        ListBox1.Items.Clear()

        Do While DR.Read

            ListBox1.Items.Add(DR(0))

        Loop

    End Sub

 

    Private Sub LaporanPembayaran_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call Koneksi()

        Call TampilNomorKredit()

    End Sub

 

    Sub caribarisnol()

        Dim hitung As Integer = 0

        For baris As Integer = 0 To DGV.RowCount - 2

            If DGV.Rows(baris).Cells(2).Value = 0 Then

                hitung = hitung + 1

            End If

        Next

        jumlahbarisnol = hitung

    End Sub

 

    Private Sub Listbox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.Click

        CRV.ReportSource = Nothing

        CMD = New OleDbCommand("select * from kredit where nomor_jualkredit='" & ListBox1.Text & "'", Conn)

        DR = CMD.ExecuteReader

        DR.Read()

        If DR.HasRows Then

            lamacicilan = DR("lama_cicilan")

            tanggalkredit = DR("tanggal_kredit")

            angsuran = DR("angsuran")

        End If

 

        DGV.Columns.Clear()

        DGV.Columns.Add("Nomor", "Nomor")

        DGV.Columns.Add("Tempo", "Jatuh Tempo")

        DGV.Columns.Add("Terlambat", "Terlambat")

        DGV.Columns.Add("Denda", "Denda")

        DGV.Columns.Add("Angsuran", "Angsuran")

        DGV.Columns.Add("Tagihan", "Angsuran + Denda")

 

        For nomor As Integer = 0 To lamacicilan

            DGV.RowCount = DGV.RowCount + 1

            DGV.Rows(nomor).Cells(0).Value = DGV.RowCount - 1

            DGV.Rows(nomor).Cells(1).Value = Format(DateAdd(DateInterval.Month, DGV.Rows(nomor).Cells(0).Value, DateValue(tanggalkredit)), "dd MMMM yyyy")

 

            If DGV.Rows(nomor).Cells(1).Value >= Today Then

                DGV.Rows(nomor).Cells(2).Value = 0

            Else

                DGV.Rows(nomor).Cells(2).Value = DateDiff(DateInterval.Day, DGV.Rows(nomor).Cells(1).Value, Today())

            End If

            DGV.Rows(nomor).Cells(3).Value = 5000 * DGV.Rows(nomor).Cells(2).Value

            DGV.Rows(nomor).Cells(4).Value = angsuran

            DGV.Rows(nomor).Cells(5).Value = DGV.Rows(nomor).Cells(3).Value + DGV.Rows(nomor).Cells(4).Value

        Next

 

        DGV.Columns(2).DefaultCellStyle.Format = "#,###"

        DGV.Columns(3).DefaultCellStyle.Format = "#,###"

        DGV.Columns(4).DefaultCellStyle.Format = "#,###"

        DGV.Columns(5).DefaultCellStyle.Format = "#,###"

        DGV.Columns("Nomor").Width = 50

        DGV.Columns("Terlambat").Width = 75

        Call caribarisnol()

    End Sub

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        If ListBox1.Text = "" Then

            MsgBox("pilih nomor kredit...")

            Exit Sub

        End If

        CMD = New OleDbCommand("delete * from tunggakan", Conn)

        CMD.ExecuteNonQuery()

 

        Call caribarisnol()

        For baris As Integer = 0 To DGV.RowCount - (jumlahbarisnol + 2)

            Dim simpan As String = "insert into tunggakan values('" & ListBox1.Text + DGV.Rows(baris).Cells(0).Value.ToString & "','" & ListBox1.Text & "', '" & DGV.Rows(baris).Cells(1).Value & "','" & DGV.Rows(baris).Cells(2).Value & "','" & DGV.Rows(baris).Cells(3).Value & "','" & DGV.Rows(baris).Cells(5).Value & "')"

            CMD = New OleDbCommand(simpan, Conn)

            CMD.ExecuteNonQuery()

        Next

 

        MsgBox("data berhasil disimpan")

        laporan.Load("tunggakan.rpt")

        Call SetingLaporan()

        CRV.ReportSource = laporan

        CRV.RefreshReport()

        DGV.Columns.Clear()

    End Sub

 

    Private Sub ListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

 

    End Sub

End Class