Vous êtes sur la page 1sur 15

Imports System.

Data
Imports System.Data.OleDb
Imports System.Net.Mail
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even
tArgs) Handles MyBase.Load
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.Eve


ntArgs) Handles Timer1.Tick
Dim jamku As Date
Dim h, m, s, ms As String
jamku = DateTime.Now
h = jamku.Hour.ToString()
m = jamku.Minute.ToString()
s = jamku.Second.ToString()
ms = jamku.Millisecond.ToString()
If h = 8 And m = 1 And s = 1 Then
Call koneksi()
'untuk vs
cmd = New OleDbCommand("select to_char(add_months(sysdate-1,0-1),'MO
N')tgl from dual", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim bln_skrg As String = dr.Item(0)
cmd = New OleDbCommand("select to_char(add_months(sysdate-1,0-1),'MO
N')tgl from dual", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim bln_lalu As String = dr.Item(0)
'--------------------------------------'tampil bulan lalu
cmd = New OleDbCommand("select to_char(add_months(sysdate-1,0-1),'dd
MONyy')tgl from dual", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim bulan_lalu As String = dr.Item(0)
'tampil tanggal sekarang
cmd = New OleDbCommand("select to_char(add_months(sysdate-1,0-1),'dd
MON yyyy')tgl from dual", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim tgl_sekarang As String = dr.Item(0)
Dim gm_gc, net_sales_gc, sales_retailpl, jhk_rpl, tgl_trs_rpl, jml_t
oko_rpl, struk_rpl, net_sales_rpl, spd_rpl, std_rpl, apc_rpl, gm_rpl, per_gm_rpl
, sales_cabangpl, jhk_cpl, tgl_trs_cpl, jml_toko_cpl, struk_cpl, net_sales_cpl,
spd_cpl, std_cpl, apc_cpl, gm_cpl, per_gm_cpl As String
Dim jhk_rp, jhk_cp, dsi_at, jd_dsi_at, dsi_pt, jd_dsi_pt, jd_oosp, o
os_op, oos_fp, oos_mp, oos_bp, t_ofmbp, i_aktifp, per_oosp, tgl_trs_cp, jml_toko
_cp, struk_cp, net_sales_cp, spd_cp, std_cp, apc_cp, gm_cp, per_gm_cp, tgl_trs_r

p, jml_toko_rp, struk_rp, net_sales_rp, spd_rp, std_rp, apc_rp, gm_rp, per_gm_rp


, no1p, tgl_trs1p, kode_toko1p, nama_store1p, qty1p, struk1p, net_sales1p, spd1p
, std1p, apc1p, gm1p, per_gm1p, no2p, tgl_trs2p, kode_toko2p, nama_store2p, qty2
p, struk2p, net_sales2p, spd2p, std2p, apc2p, gm2p, per_gm2p, no3p, tgl_trs3p, k
ode_toko3p, nama_store3p, qty3p, struk3p, net_sales3p, spd3p, std3p, apc3p, gm3p
, per_gm3p, no4p, tgl_trs4p, kode_toko4p, nama_store4p, qty4p, struk4p, net_sale
s4p, spd4p, std4p, apc4p, gm4p, per_gm4p, no5p, tgl_trs5p, kode_toko5p, nama_sto
re5p, qty5p, struk5p, net_sales5p, spd5p, std5p, apc5p, gm5p, per_gm5p, no6p, tg
l_trs6p, kode_toko6p, nama_store6p, qty6p, struk6p, net_sales6p, spd6p, std6p, a
pc6p, gm6p, per_gm6p, no7p, tgl_trs7p, kode_toko7p, nama_store7p, qty7p, struk7p
, net_sales7p, spd7p, std7p, apc7p, gm7p, per_gm7p, no8p, tgl_trs8p, kode_toko8p
, nama_store8p, qty8p, struk8p, net_sales8p, spd8p, std8p, apc8p, gm8p, per_gm8p
, no9p, tgl_trs9p, kode_toko9p, nama_store9p, qty9p, struk9p, net_sales9p, spd9p
, std9p, apc9p, gm9p, per_gm9p, no10p, tgl_trs10p, kode_toko10p, nama_store10p,
qty10p, struk10p, net_sales10p, spd10p, std10p, apc10p, gm10p, per_gm10p As Stri
ng
Dim sales_cabangp, sales_retailp, bes1p, bes2p, bes3p, bes4p, bes5p,
bes6p, bes7p, bes8p, bes9p, bes10p As String
'-------------SALES CABANG PER TGL----------------------------------'SALES TOTAL BULAN SEKARANG
cmd = New OleDbCommand("SELECT tgl_trs, KODE_TOKO JML_TOKO,STRUK,ROU
ND(NET_SALES)NET_SALES,JHK, ROUND(SPD)SPD,ROUND(STD)STD,ROUND(APC)APC,ROUND(GM)G
M,ROUND(PER_GM,2)PER_GM FROM (SELECT tgl_trs,COUNT(DISTINCT(KODE_TOKO))KODE_TOKO
,sum(qty) qty,count(distinct(kode_toko||tgl_trs||no_bon||KODE_KASIR)) struk,coun
t(distinct tgl_trs)jhk,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL
(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(Q
TY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)
))/COUNT(DISTINCT KODE_TOKO||TGL_TRS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_
BON||KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY
,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))
/COUNT(DISTINCT KODE_TOKO||TGL_TRS)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||
KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DE
C,0),0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.
1))-NVL(AVG_COST,0))) GM,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE
,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(
NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PP
N,0),0,0,0.1)/1.1)))*100 PER_GM FROM AMU_TRANS_T where tgl_trs=TRUNC(SYSDATE-1)
group by tgl_trs having(sum(qty * price) <> 0)) a, (SELECT COUNT(DISTINCT(KD_STO
RE))KD_STORE FROM AMU_STORE_T WHERE DC='FALSE' AND AKTIF='T' AND TGL_BUKA<=TRUNC
(SYSDATE-1)) b", conn)
dr = cmd.ExecuteReader
dr.Read()
tgl_trs_cp = dr.Item(0)
jml_toko_cp = dr.Item(1)
struk_cp = Format(dr.Item(2), "#,###")
net_sales_cp = Format(dr.Item(3), "#,###")
jhk_cp = dr.Item(4)
spd_cp = Format(dr.Item(5), "#,###")
std_cp = dr.Item(6)
apc_cp = Format(dr.Item(7), "#,###")
gm_cp = Format(dr.Item(8), "#,###")
per_gm_cp = dr.Item(9)
sales_cabangp = "JML TOKO: "
TRUK: " & struk_cp & "" & Chr(10) & "NET
& "JHK: " & jhk_cp & Chr(10) & "SPD: " &
p & "" & Chr(10) & "APC: " & apc_cp & ""

& jml_toko_cp & "" & Chr(10) & "TOTAL S


SALES: " & net_sales_cp & "" & Chr(10)
spd_cp & "" & Chr(10) & "STD: " & std_c
& Chr(10) & "GM RP: " & gm_cp & " " & C

hr(10) & "GM %: " & per_gm_cp


'SALES TOTAL BULAN LALU
cmd = New OleDbCommand("SELECT tgl_trs, KODE_TOKO JML_TOKO,STRUK,ROU
ND(NET_SALES)NET_SALES,JHK, ROUND(SPD)SPD,ROUND(STD)STD,ROUND(APC)APC,ROUND(GM)G
M,ROUND(PER_GM,2)PER_GM FROM (SELECT tgl_trs,COUNT(DISTINCT(KODE_TOKO))KODE_TOKO
,sum(qty) qty,count(distinct(kode_toko||tgl_trs||no_bon||KODE_KASIR)) struk,coun
t(distinct tgl_trs)jhk,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL
(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(Q
TY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)
))/COUNT(DISTINCT KODE_TOKO||TGL_TRS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_
BON||KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY
,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))
/COUNT(DISTINCT KODE_TOKO||TGL_TRS)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||
KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DE
C,0),0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.
1))-NVL(AVG_COST,0))) GM,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE
,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(
NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PP
N,0),0,0,0.1)/1.1)))*100 PER_GM FROM AMU_TRANS_T where tgl_trs='" & bulan_lalu &
"' group by tgl_trs having(sum(qty * price) <> 0)) a, (SELECT COUNT(DISTINCT(KD
_STORE))KD_STORE FROM AMU_STORE_T WHERE DC='FALSE' AND AKTIF='T' AND TGL_BUKA<='
" & bulan_lalu & "') b", conn)
dr = cmd.ExecuteReader
dr.Read()
tgl_trs_cpl = dr.Item(0)
jml_toko_cpl = dr.Item(1)
struk_cpl = Format(dr.Item(2), "#,###")
net_sales_cpl = Format(dr.Item(3), "#,###")
jhk_cpl = dr.Item(4)
spd_cpl = Format(dr.Item(5), "#,###")
std_cpl = dr.Item(6)
apc_cpl = Format(dr.Item(7), "#,###")
gm_cpl = Format(dr.Item(8), "#,###")
per_gm_cpl = dr.Item(9)
'------------GROWTH-----------'CABANG / TOTAL
Dim struk_gc, spd_gc, std_gc, apc_gc, per_gm_gc As String
struk_gc = Format((struk_cp - struk_cpl) / struk_cpl * 100, "#.##")
net_sales_gc = Format((net_sales_cp - net_sales_cp) / net_sales_cpl
* 100, "#.##")
spd_gc = Format((spd_cp - spd_cpl) / spd_cpl * 100, "#.##")
std_gc = Format((std_cp - std_cpl) / std_cpl * 100, "#.##")
apc_gc = Format((apc_cp - apc_cpl) / apc_cpl * 100, "#.##")
gm_gc = Format((gm_cp - gm_cpl) / gm_cpl * 100, "#.##")
per_gm_gc = Format((per_gm_cp - per_gm_cpl) / per_gm_cpl * 100, "#.#
#")

'HASIL SALES CABANG / TOTAL


sales_cabangpl = " " & bln_lalu & "
" & bln_skrg & "
" & "GROWTH" & Chr(10) & "JML TOKO: " & jml_toko_cpl & "
" & jml_toko_cp & C
hr(10) & "TOTAL STRUK: " & struk_cpl & "
" & struk_cp & "
" & struk_gc &
Chr(10) & "NET SALES: " & net_sales_cpl & "
" & net_sales_cp & "
" & ne
t_sales_gc & Chr(10) & "JHK: " & jhk_cpl & Chr(10) & "
" & jhk_cp & "SPD: "
& spd_cpl & "
" & spd_cp & "
" & spd_gc & Chr(10) & "STD: " & std_cpl &

"
" & std_cp & "
" & std_gc & Chr(10) & "APC: " & apc_cpl & "
" & ap
c_cp & "
" & apc_gc & Chr(10) & "GM RP: " & gm_cpl & "
" & gm_cp & "
" & gm_gc & Chr(10) & "GM %: " & per_gm_cpl & "
" & per_gm_cp & "
" & p
er_gm_gc

'-------------SALES RETAIL PER TGL----------------------------------'SALES RETAIL BULAN SEKARANG


cmd = New OleDbCommand("SELECT tgl_trs, KODE_TOKO JML_TOKO,STRUK,ROU
ND(NET_SALES)NET_SALES,JHK, ROUND(SPD)SPD,ROUND(STD)STD,ROUND(APC)APC,ROUND(GM)G
M,ROUND(PER_GM,2)PER_GM FROM (SELECT tgl_trs,COUNT(DISTINCT(KODE_TOKO))KODE_TOKO
,sum(qty) qty,count(distinct(kode_toko||tgl_trs||no_bon||KODE_KASIR)) struk,coun
t(distinct tgl_trs)jhk,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL
(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(Q
TY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)
))/COUNT(DISTINCT KODE_TOKO||TGL_TRS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_
BON||KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY
,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))
/COUNT(DISTINCT KODE_TOKO||TGL_TRS)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||
KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DE
C,0),0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.
1))-NVL(AVG_COST,0))) GM,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE
,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(
NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PP
N,0),0,0,0.1)/1.1)))*100 PER_GM FROM AMU_TRANS_T where tgl_trs=TRUNC(SYSDATE-1)
and type not in ('S','B') AND KODE_TOKO NOT IN (SELECT KD_STORE FROM AMU_STORE_T
WHERE DC='FALSE' AND AKTIF='T' AND TGL_BUKA<=TRUNC(SYSDATE-1) AND STATUS='J') g
roup by tgl_trs having(sum(qty * price) <> 0)) a, (SELECT COUNT(DISTINCT(KD_STOR
E))KD_STORE FROM AMU_STORE_T WHERE DC='FALSE' AND AKTIF='T' AND TGL_BUKA<=TRUNC(
SYSDATE-1) AND STATUS <> 'J') b", conn)
dr = cmd.ExecuteReader
dr.Read()
tgl_trs_rp = dr.Item(0)
jml_toko_rp = dr.Item(1)
struk_rp = Format(dr.Item(2), "#,###")
net_sales_rp = Format(dr.Item(3), "#,###")
jhk_rp = dr.Item(4)
spd_rp = Format(dr.Item(5), "#,###")
std_rp = dr.Item(6)
apc_rp = Format(dr.Item(7), "#,###")
gm_rp = Format(dr.Item(8), "#,###")
per_gm_rp = dr.Item(9)
sales_retailp = "JML TOKO: "
TRUK: " & struk_rp & "" & Chr(10) & "NET
& "JHK: " & jhk_rp & Chr(10) & "SPD: " &
p & "" & Chr(10) & "APC: " & apc_rp & ""
hr(10) & "GM %: " & per_gm_rp

& jml_toko_rp & "" & Chr(10) & "TOTAL S


SALES: " & net_sales_rp & "" & Chr(10)
spd_rp & "" & Chr(10) & "STD: " & std_r
& Chr(10) & "GM RP: " & gm_rp & " " & C

'SALES RETAIL BULAN LALU


cmd = New OleDbCommand("SELECT tgl_trs, KODE_TOKO JML_TOKO,STRUK,ROU
ND(NET_SALES)NET_SALES,JHK, ROUND(SPD)SPD,ROUND(STD)STD,ROUND(APC)APC,ROUND(GM)G
M,ROUND(PER_GM,2)PER_GM FROM (SELECT tgl_trs,COUNT(DISTINCT(KODE_TOKO))KODE_TOKO
,sum(qty) qty,count(distinct(kode_toko||tgl_trs||no_bon||KODE_KASIR)) struk,coun
t(distinct tgl_trs)jhk,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL

(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(Q
TY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)
))/COUNT(DISTINCT KODE_TOKO||TGL_TRS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_
BON||KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY
,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))
/COUNT(DISTINCT KODE_TOKO||TGL_TRS)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||
KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DE
C,0),0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.
1))-NVL(AVG_COST,0))) GM,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE
,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(
NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PP
N,0),0,0,0.1)/1.1)))*100 PER_GM FROM AMU_TRANS_T where tgl_trs='" & bulan_lalu &
"' and type not in ('S','B') AND KODE_TOKO NOT IN (SELECT KD_STORE FROM AMU_STO
RE_T WHERE DC='FALSE' AND AKTIF='T' AND TGL_BUKA<=TRUNC(SYSDATE-1) AND STATUS='J
') group by tgl_trs having(sum(qty * price) <> 0)) a, (SELECT COUNT(DISTINCT(KD_
STORE))KD_STORE FROM AMU_STORE_T WHERE DC='FALSE' AND AKTIF='T' AND TGL_BUKA<='"
& bulan_lalu & "' AND STATUS <> 'J') b", conn)
dr = cmd.ExecuteReader
dr.Read()
tgl_trs_rpl = dr.Item(0)
jml_toko_rpl = dr.Item(1)
struk_rpl = Format(dr.Item(2), "#,###")
net_sales_rpl = Format(dr.Item(3), "#,###")
jhk_rpl = dr.Item(4)
spd_rpl = Format(dr.Item(5), "#,###")
std_rpl = dr.Item(6)
apc_rpl = Format(dr.Item(7), "#,###")
gm_rpl = Format(dr.Item(8), "#,###")
per_gm_rpl = dr.Item(9)
'------------GROWTH-----------'RETAIL
Dim struk_gr, spd_gr, std_gr, apc_gr, per_gm_gr As String
struk_gr = Format((struk_rp - struk_rpl) / struk_rpl * 100, "#.##")
net_sales_gc = Format((net_sales_rp - net_sales_rp) / net_sales_rpl
* 100, "#.##")
spd_gr = Format((spd_rp - spd_rpl) / spd_rpl * 100, "#.##")
std_gr = Format((std_rp - std_rpl) / std_rpl * 100, "#.##")
apc_gr = Format((apc_rp - apc_rpl) / apc_rpl * 100, "#.##")
gm_gc = Format((gm_rp - gm_rpl) / gm_rpl * 100, "#.##")
per_gm_gr = Format((per_gm_rp - per_gm_rpl) / per_gm_rpl * 100, "#.#
#")
sales_retailpl = "JML TOKO: " &
STRUK: " & struk_rpl & "" & Chr(10) & "NET
10) & "JHK: " & jhk_rpl & Chr(10) & "SPD: "
std_rpl & "" & Chr(10) & "APC: " & apc_rpl
& " " & Chr(10) & "GM %: " & per_gm_rpl

jml_toko_rpl & "" & Chr(10) & "TOTAL


SALES: " & net_sales_rpl & "" & Chr(
& spd_rpl & "" & Chr(10) & "STD: " &
& "" & Chr(10) & "GM RP: " & gm_rpl

'-----------------BEST SALES----------------------------------------

----------------------------------------------'BEST 10 SALES PER TGL


da = New OleDbDataAdapter("select BARIS NO,TGL_TRS TGL,kode_toko,(se
lect nama_store from amu_store_t where kd_store=kode_toko)nama_store,qty,struk,n
et_sales,spd,std,apc,gm,per_gm from (select row_number() over (order by net_sale
s desc) baris,kode_toko,TGL_TRS, qty, struk, round(net_sales)net_sales, round(sp
d)spd, std, round(apc)apc, round(gm)gm, round(per_gm,2)per_gm from (SELECT kode_
toko,TGL_TRS,sum(qty) qty,count(distinct(kode_toko||tgl_trs||no_bon||KODE_KASIR)
) struk,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(D
ECODE(NVL(PPN,0),0,0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DE
C,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/COUNT(DISTIN
CT KODE_TOKO||TGL_TRS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||KODE_KASIR
)/COUNT(DISTINCT KODE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,
1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/COUNT(DISTINCT
KODE_TOKO||TGL_TRS)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||KODE_KASIR)/COU
NT(DISTINCT KODE_TOKO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000
)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COS
T,0))) GM,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC
,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(NVL(PRICE,0)*NV
L(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1
.1)))*100 PER_GM FROM AMU_TRANS_T where tgl_trs=trunc(sysdate-1) having(sum(qty
* price) <> 0) group by kode_toko,TGL_TRS) order by net_sales desc) where baris
between 1 and 10", conn)
ds = New DataSet
da.Fill(ds, "bestp")
DataGridView2.DataSource = (ds.Tables("bestp"))
DataGridView2.ReadOnly = True
'header2 = "NO |" & "KD_TOKO " & "| NAMA_STORE
" & " | QT
Y " & " | STRUK " & " | NET_SALES " & " | SPD " & " | STD " & " | APC " &
" | GM RP " & " | GM % "
bes1p = DataGridView2.Rows(0).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(0).Cells(2).Value & " " & DataGridView2.Rows(0).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(0).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(0).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(0).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(0).Cells(8).Value & " APC: " & DataGridView2.Rows(0).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(0).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(0).Cells(11).Value & Chr(10)
bes2p = DataGridView2.Rows(1).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(1).Cells(2).Value & " " & DataGridView2.Rows(1).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(1).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(1).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(1).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(1).Cells(8).Value & " APC: " & DataGridView2.Rows(1).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(1).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(1).Cells(11).Value & Chr(10)
bes3p = DataGridView2.Rows(2).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(2).Cells(2).Value & " " & DataGridView2.Rows(2).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(2).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(2).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(2).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(2).Cells(8).Value & " APC: " & DataGridView2.Rows(2).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(2).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(2).Cells(11).Value & Chr(10)
bes4p = DataGridView2.Rows(3).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(3).Cells(2).Value & " " & DataGridView2.Rows(3).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(3).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(3).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri

dView2.Rows(3).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows


(3).Cells(8).Value & " APC: " & DataGridView2.Rows(3).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(3).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(3).Cells(11).Value & Chr(10)
bes5p = DataGridView2.Rows(4).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(4).Cells(2).Value & " " & DataGridView2.Rows(4).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(4).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(4).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(4).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(4).Cells(8).Value & " APC: " & DataGridView2.Rows(4).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(4).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(4).Cells(11).Value & Chr(10)
bes6p = DataGridView2.Rows(5).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(5).Cells(2).Value & " " & DataGridView2.Rows(5).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(5).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(5).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(5).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(5).Cells(8).Value & " APC: " & DataGridView2.Rows(5).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(5).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(5).Cells(11).Value & Chr(10)
bes7p = DataGridView2.Rows(6).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(6).Cells(2).Value & " " & DataGridView2.Rows(6).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(6).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(6).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(6).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(6).Cells(8).Value & " APC: " & DataGridView2.Rows(6).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(6).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(6).Cells(11).Value & Chr(10)
bes8p = DataGridView2.Rows(7).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(7).Cells(2).Value & " " & DataGridView2.Rows(7).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(7).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(7).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(7).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(7).Cells(8).Value & " APC: " & DataGridView2.Rows(7).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(7).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(7).Cells(11).Value & Chr(10)
bes9p = DataGridView2.Rows(8).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView2.Rows(8).Cells(2).Value & " " & DataGridView2.Rows(8).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView2.Rows(8).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView2.Rows(8).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView2.Rows(8).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Rows
(8).Cells(8).Value & " APC: " & DataGridView2.Rows(8).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(8).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View2.Rows(8).Cells(11).Value & Chr(10)
bes10p = DataGridView2.Rows(9).Cells(0).Value & ". KODE TOKO: " & Da
taGridView2.Rows(9).Cells(2).Value & " " & DataGridView2.Rows(9).Cells(3).Value
& Chr(10) & "STRUK: " & DataGridView2.Rows(9).Cells(5).Value & " NET SALES: " &
Format(DataGridView2.Rows(9).Cells(6).Value, "#,###") & " SPD: " & Format(DataGr
idView2.Rows(9).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView2.Row
s(9).Cells(8).Value & " APC: " & DataGridView2.Rows(9).Cells(9).Value & " GM.RP:
" & Format(DataGridView2.Rows(9).Cells(10).Value, "#,###") & " GM%: " & DataGri
dView2.Rows(9).Cells(11).Value & Chr(10)
'OOS PER TGL
cmd = New OleDbCommand("SELECT OOS_O, OOS_F, OOS_M, OOS_B, T_OFMB, I
_AKTIF, ROUND(T_OFMB / I_AKTIF * 100,2) PER_OOS FROM (SELECT ROUND(SUM(OOS_O)/CO
UNT(DISTINCT(TGL_KSF||KD_STORE))) OOS_O, ROUND(SUM(OOS_F)/COUNT(DISTINCT(TGL_KSF
||KD_STORE))) OOS_F, ROUND(SUM(OOS_M)/COUNT(DISTINCT(TGL_KSF||KD_STORE))) OOS_M,
ROUND(SUM(OOS_B)/COUNT(DISTINCT(TGL_KSF||KD_STORE))) OOS_B,ROUND((SUM(OOS_B)/CO

UNT(DISTINCT(TGL_KSF||KD_STORE))+SUM(OOS_M)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+
SUM(OOS_F)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+SUM(OOS_O)/COUNT(DISTINCT(TGL_KSF|
|KD_STORE)))) T_OFMB,ROUND((SUM(PLU_B)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+SUM(PL
U_M)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+ SUM(PLU_F)/COUNT(DISTINCT(TGL_KSF||KD_S
TORE))+SUM(PLU_O)/COUNT(DISTINCT(TGL_KSF||KD_STORE)))) I_AKTIF FROM AMU_KSF_T WH
ERE TGL_KSF=trunc(sysdate-1))", conn)
dr = cmd.ExecuteReader
dr.Read()
oos_op = dr.Item(0)
oos_fp = dr.Item(1)
oos_mp = dr.Item(2)
oos_bp = dr.Item(3)
t_ofmbp = dr.Item(4)
i_aktifp = dr.Item(5)
per_oosp = dr.Item(6)
jd_oosp = "TAG 0: " & oos_op & Chr(10) & "TAG F: " & oos_fp & Chr(10
) & "TAG M: " & oos_mp & Chr(10) & "TAG B: " & oos_bp & Chr(10) & "TOTAL OFMB: "
& t_ofmbp & Chr(10) & "ITEM AKTIF: " & i_aktifp & Chr(10) & "%OOS OFMB: " & per
_oosp
'DSI PER TGL
cmd = New OleDbCommand("select round(sum(dsi_ofmb)/ count(distinct k
d_store||tgl_ksf),2) DSI_TOKO from amu_ksf_t where tgl_ksf=TRUNC(SYSDATE-1)", co
nn)
dr = cmd.ExecuteReader
dr.Read()
dsi_pt = dr.Item(0)
jd_dsi_pt = "- TOKO
0) & "- CABANG : "

: " & dsi_pt & Chr(10) & "- DC

: " & Chr(1

'===================================================================
=================================================
Dim jd_oos, oos_o, oos_f, oos_m, oos_b, t_ofmb, i_aktif, per_oos, tg
l_trs_c, jml_toko_c, struk_c, net_sales_c, spd_c, std_c, apc_c, gm_c, per_gm_c,
tgl_trs_r, jml_toko_r, struk_r, net_sales_r, spd_r, std_r, apc_r, gm_r, per_gm_r
, no1, tgl_trs1, kode_toko1, nama_store1, qty1, struk1, net_sales1, spd1, std1,
apc1, gm1, per_gm1, no2, tgl_trs2, kode_toko2, nama_store2, qty2, struk2, net_sa
les2, spd2, std2, apc2, gm2, per_gm2, no3, tgl_trs3, kode_toko3, nama_store3, qt
y3, struk3, net_sales3, spd3, std3, apc3, gm3, per_gm3, no4, tgl_trs4, kode_toko
4, nama_store4, qty4, struk4, net_sales4, spd4, std4, apc4, gm4, per_gm4, no5, t
gl_trs5, kode_toko5, nama_store5, qty5, struk5, net_sales5, spd5, std5, apc5, gm
5, per_gm5, no6, tgl_trs6, kode_toko6, nama_store6, qty6, struk6, net_sales6, sp
d6, std6, apc6, gm6, per_gm6, no7, tgl_trs7, kode_toko7, nama_store7, qty7, stru
k7, net_sales7, spd7, std7, apc7, gm7, per_gm7, no8, tgl_trs8, kode_toko8, nama_
store8, qty8, struk8, net_sales8, spd8, std8, apc8, gm8, per_gm8, no9, tgl_trs9,
kode_toko9, nama_store9, qty9, struk9, net_sales9, spd9, std9, apc9, gm9, per_g
m9, no10, tgl_trs10, kode_toko10, nama_store10, qty10, struk10, net_sales10, spd
10, std10, apc10, gm10, per_gm10 As String
Dim sales_cabang, sales_retail, bes1, bes2, bes3, bes4, bes5, bes6,
bes7, bes8, bes9, bes10 As String

'SALES CABANG ALL TGL


cmd = New OleDbCommand("SELECT (select '01'||tgl from (select to_cha
r(add_months(sysdate-1,0),'-MON-yy')tgl from dual))||' - '||trunc(sysdate-1)TGL
,JML_TOKO,STRUK,ROUND(NET_SALES)NET_SALES, ROUND(SPD)SPD,ROUND(STD)STD,ROUND(APC
)APC,ROUND(GM)GM,ROUND(PER_GM,2)PER_GM FROM (SELECT count(distinct(kode_toko))JM
L_TOKO,count(distinct(kode_toko||tgl_trs||no_bon||KODE_KASIR)) struk,SUM(NVL(PRI
CE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,
0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NV
L(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/COUNT(DISTINCT KODE_TOKO||TGL_T
RS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||KODE_KASIR)/COUNT(DISTINCT KO
DE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(
DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/COUNT(DISTINCT KODE_TOKO||TGL_TRS
)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||KODE_KASIR)/COUNT(DISTINCT KODE_TO
KO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE,0)*(1NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) GM,SUM(NVL(Q
TY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL
(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC
,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))*100 PER_GM FR
OM AMU_TRANS_T where tgl_trs between (select '01'||tgl from (select to_char(add_
months(sysdate-1,0),'MONyy')tgl from dual)) and trunc(sysdate-1) having(sum(qty
* price) <> 0))", conn)
dr = cmd.ExecuteReader
dr.Read()
tgl_trs_c = dr.Item(0)
jml_toko_c = dr.Item(1)
struk_c = Format(dr.Item(2), "#,###")
net_sales_c = Format(dr.Item(3), "#,###")
spd_c = Format(dr.Item(4), "#,###")
std_c = dr.Item(5)
apc_c = Format(dr.Item(6), "#,###")
gm_c = Format(dr.Item(7), "#,###")
per_gm_c = dr.Item(8)
sales_cabang = "JML TOKO: " & jml_toko_c & "" & Chr(10) & "TOTAL STR
UK: " & struk_c & "" & Chr(10) & "NET SALES: " & net_sales_c & "" & Chr(10) & "S
PD: " & spd_c & "" & Chr(10) & "STD: " & std_c & "" & Chr(10) & "APC: " & apc_c
& "" & Chr(10) & " GM RP: " & gm_c & " " & Chr(10) & "GM %: " & per_gm_c

'SALES RETAIL ALL TGL


cmd = New OleDbCommand("SELECT (select '01'||tgl from (select to_cha
r(add_months(sysdate-1,0),'-MON-yy')tgl from dual))||' - '||trunc(sysdate-1)TGL
,JML_TOKO,STRUK,ROUND(NET_SALES)NET_SALES, ROUND(SPD)SPD,ROUND(STD)STD,ROUND(APC
)APC,ROUND(GM)GM,ROUND(PER_GM,2)PER_GM FROM (SELECT count(distinct(kode_toko))JM
L_TOKO,count(distinct(kode_toko||tgl_trs||no_bon||KODE_KASIR)) struk,SUM(NVL(PRI
CE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,
0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NV
L(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/COUNT(DISTINCT KODE_TOKO||TGL_T
RS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||KODE_KASIR)/COUNT(DISTINCT KO
DE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(
DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/COUNT(DISTINCT KODE_TOKO||TGL_TRS
)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||KODE_KASIR)/COUNT(DISTINCT KODE_TO
KO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE,0)*(1NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) GM,SUM(NVL(Q
TY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL
(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC
,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))*100 PER_GM FR
OM AMU_TRANS_T where tgl_trs between (select '01'||tgl from (select to_char(add_
months(sysdate-1,0),'MONyy')tgl from dual)) and trunc(sysdate-1) and type not i

n ('S','B') having(sum(qty * price) <> 0))", conn)


dr = cmd.ExecuteReader
dr.Read()
tgl_trs_r = dr.Item(0)
jml_toko_r = dr.Item(1)
struk_r = Format(dr.Item(2), "#,###")
net_sales_r = Format(dr.Item(3), "#,###")
spd_r = Format(dr.Item(4), "#,###")
std_r = dr.Item(5)
apc_r = Format(dr.Item(6), "#,###")
gm_r = Format(dr.Item(7), "#,###")
per_gm_r = dr.Item(8)
sales_retail = "JML TOKO: " & jml_toko_r & "" & Chr(10) & "TOTAL STR
UK: " & struk_r & "" & Chr(10) & "NET SALES: " & net_sales_r & "" & Chr(10) & "S
PD: " & spd_r & "" & Chr(10) & "STD: " & std_r & "" & Chr(10) & "APC: " & apc_r
& "" & Chr(10) & "GM RP: " & gm_r & " " & Chr(10) & "GM %: " & per_gm_r
'BEST 10 SALES ALL TGL
da = New OleDbDataAdapter("select BARIS NO,(select '01'||tgl from (s
elect to_char(add_months(sysdate-1,0),'-MON-yy')tgl from dual))||' - '||trunc(s
ysdate-1)TGL,kode_toko,(select nama_store from amu_store_t where kd_store=kode_t
oko)nama_store,qty,struk,net_sales,spd,std,apc,gm,per_gm from (select row_number
() over (order by net_sales desc) baris,kode_toko, qty, struk, round(net_sales)n
et_sales, round(spd)spd, std, round(apc)apc, round(gm)gm, round(per_gm,2)per_gm
from (SELECT kode_toko,sum(qty) qty,count(distinct(kode_toko||tgl_trs||no_bon||K
ODE_KASIR)) struk,SUM(NVL(PRICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC
,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))) NET_SALES,SUM(NVL(PRICE,0)*NVL(QTY,0)
*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/CO
UNT(DISTINCT KODE_TOKO||TGL_TRS) SPD,COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||
KODE_KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS) STD,SUM(NVL(PRICE,0)*NVL(QTY,0)*D
ECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1)))/COUN
T(DISTINCT KODE_TOKO||TGL_TRS)/(COUNT(DISTINCT KODE_TOKO||TGL_TRS||NO_BON||KODE_
KASIR)/COUNT(DISTINCT KODE_TOKO||TGL_TRS)) APC,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),
0,1,1/1000)*(NVL(PRICE,0)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-N
VL(AVG_COST,0))) GM,SUM(NVL(QTY,0)*DECODE(NVL(DEC,0),0,1,1/1000)*(NVL(PRICE,0)*(
1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),0,0,0.1)/1.1))-NVL(AVG_COST,0))) /SUM(NVL(P
RICE,0)*NVL(QTY,0)*DECODE(DEC,1,1/1000,1)*(1-NVL(DISC,0))*(1-(DECODE(NVL(PPN,0),
0,0,0.1)/1.1)))*100 PER_GM FROM AMU_TRANS_T where tgl_trs between (select '01'||
tgl from (select to_char(add_months(sysdate-1,0),'MONyy')tgl from dual)) and tr
unc(sysdate-1) having(sum(qty * price) <> 0) group by kode_toko) order by net_sa
les desc) where baris between 1 and 10", conn)
ds = New DataSet
da.Fill(ds, "best")
DataGridView1.DataSource = (ds.Tables("best"))
DataGridView1.ReadOnly = True
'header1 = "NO |" & "KD_TOKO " & "| NAMA_STORE
" & " | QT
Y " & " | STRUK " & " | NET_SALES " & " | SPD " & " | STD " & " | APC " &
" | GM RP " & " | GM % "
bes1 = DataGridView1.Rows(0).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(0).Cells(2).Value & " " & DataGridView1.Rows(0).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(0).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(0).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(0).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
0).Cells(8).Value & " APC: " & DataGridView1.Rows(0).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(0).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(0).Cells(11).Value & Chr(10)
bes2 = DataGridView1.Rows(1).Cells(0).Value & ". KODE TOKO: " & Data

GridView1.Rows(1).Cells(2).Value & " " & DataGridView1.Rows(1).Cells(3).Value &


Chr(10) & "STRUK: " & DataGridView1.Rows(1).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(1).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(1).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
1).Cells(8).Value & " APC: " & DataGridView1.Rows(1).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(1).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(1).Cells(11).Value & Chr(10)
bes3 = DataGridView1.Rows(2).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(2).Cells(2).Value & " " & DataGridView1.Rows(2).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(2).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(2).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(2).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
2).Cells(8).Value & " APC: " & DataGridView1.Rows(2).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(2).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(2).Cells(11).Value & Chr(10)
bes4 = DataGridView1.Rows(3).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(3).Cells(2).Value & " " & DataGridView1.Rows(3).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(3).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(3).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(3).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
3).Cells(8).Value & " APC: " & DataGridView1.Rows(3).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(3).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(3).Cells(11).Value & Chr(10)
bes5 = DataGridView1.Rows(4).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(4).Cells(2).Value & " " & DataGridView1.Rows(4).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(4).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(4).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(4).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
4).Cells(8).Value & " APC: " & DataGridView1.Rows(4).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(4).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(4).Cells(11).Value & Chr(10)
bes6 = DataGridView1.Rows(5).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(5).Cells(2).Value & " " & DataGridView1.Rows(5).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(5).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(5).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(5).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
5).Cells(8).Value & " APC: " & DataGridView1.Rows(5).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(5).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(5).Cells(11).Value & Chr(10)
bes7 = DataGridView1.Rows(6).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(6).Cells(2).Value & " " & DataGridView1.Rows(6).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(6).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(6).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(6).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
6).Cells(8).Value & " APC: " & DataGridView1.Rows(6).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(6).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(6).Cells(11).Value & Chr(10)
bes8 = DataGridView1.Rows(7).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(7).Cells(2).Value & " " & DataGridView1.Rows(7).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(7).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(7).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(7).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(
7).Cells(8).Value & " APC: " & DataGridView1.Rows(7).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(7).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(7).Cells(11).Value & Chr(10)
bes9 = DataGridView1.Rows(8).Cells(0).Value & ". KODE TOKO: " & Data
GridView1.Rows(8).Cells(2).Value & " " & DataGridView1.Rows(8).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(8).Cells(5).Value & " NET SALES: " & Fo
rmat(DataGridView1.Rows(8).Cells(6).Value, "#,###") & " SPD: " & Format(DataGrid
View1.Rows(8).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows(

8).Cells(8).Value & " APC: " & DataGridView1.Rows(8).Cells(9).Value & " GM.RP: "
& Format(DataGridView1.Rows(8).Cells(10).Value, "#,###") & " GM%: " & DataGridV
iew1.Rows(8).Cells(11).Value & Chr(10)
bes10 = DataGridView1.Rows(9).Cells(0).Value & ". KODE TOKO: " & Dat
aGridView1.Rows(9).Cells(2).Value & " " & DataGridView1.Rows(9).Cells(3).Value &
Chr(10) & "STRUK: " & DataGridView1.Rows(9).Cells(5).Value & " NET SALES: " & F
ormat(DataGridView1.Rows(9).Cells(6).Value, "#,###") & " SPD: " & Format(DataGri
dView1.Rows(9).Cells(7).Value, "#,###") & Chr(10) & "STD: " & DataGridView1.Rows
(9).Cells(8).Value & " APC: " & DataGridView1.Rows(9).Cells(9).Value & " GM.RP:
" & Format(DataGridView1.Rows(9).Cells(10).Value, "#,###") & " GM%: " & DataGrid
View1.Rows(9).Cells(11).Value & Chr(10)
'OOS ALL TGL
cmd = New OleDbCommand("SELECT OOS_O, OOS_F, OOS_M, OOS_B, T_OFMB, I
_AKTIF, ROUND(T_OFMB / I_AKTIF * 100,2) PER_OOS FROM (SELECT ROUND(SUM(OOS_O)/CO
UNT(DISTINCT(TGL_KSF||KD_STORE))) OOS_O, ROUND(SUM(OOS_F)/COUNT(DISTINCT(TGL_KSF
||KD_STORE))) OOS_F, ROUND(SUM(OOS_M)/COUNT(DISTINCT(TGL_KSF||KD_STORE))) OOS_M,
ROUND(SUM(OOS_B)/COUNT(DISTINCT(TGL_KSF||KD_STORE))) OOS_B,ROUND((SUM(OOS_B)/CO
UNT(DISTINCT(TGL_KSF||KD_STORE))+SUM(OOS_M)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+
SUM(OOS_F)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+SUM(OOS_O)/COUNT(DISTINCT(TGL_KSF|
|KD_STORE)))) T_OFMB,ROUND((SUM(PLU_B)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+SUM(PL
U_M)/COUNT(DISTINCT(TGL_KSF||KD_STORE))+ SUM(PLU_F)/COUNT(DISTINCT(TGL_KSF||KD_S
TORE))+SUM(PLU_O)/COUNT(DISTINCT(TGL_KSF||KD_STORE)))) I_AKTIF FROM AMU_KSF_T WH
ERE TGL_KSF between (select '01'||tgl from (select to_char(add_months(sysdate-1,
0),'MONyy')tgl from dual)) and trunc(sysdate-1))", conn)
dr = cmd.ExecuteReader
dr.Read()
oos_o = dr.Item(0)
oos_f = dr.Item(1)
oos_m = dr.Item(2)
oos_b = dr.Item(3)
t_ofmb = dr.Item(4)
i_aktif = dr.Item(5)
per_oos = dr.Item(6)
jd_oos = "TAG 0: " & oos_o & Chr(10) & "TAG F: " & oos_f & Chr(10) &
"TAG M: " & oos_m & Chr(10) & "TAG B: " & oos_b & Chr(10) & "TOTAL OFMB: " & t_
ofmb & Chr(10) & "ITEM AKTIF: " & i_aktif & Chr(10) & "%OOS OFMB: " & per_oos
'DSI ALL TGL
cmd = New OleDbCommand("select round(sum(dsi_ofmb)/ count(distinct k
d_store||tgl_ksf),2) DSI_TOKO from amu_ksf_t where tgl_ksf between (select '01'|
|tgl from (select to_char(add_months(sysdate-1,0),'MONyy')tgl from dual)) and t
runc(sysdate-1)", conn)
dr = cmd.ExecuteReader
dr.Read()
dsi_at = dr.Item(0)
jd_dsi_at = "- TOKO
0) & "- CABANG : "

: " & dsi_at & Chr(10) & "- DC

'TextBox2.Text = DataGridView1.Rows(1).Cells(0).Value
Try

: " & Chr(1

Dim mail As MailMessage = New MailMessage()


Dim SmtpServer As SmtpClient = New SmtpClient("10.234.144.10")
mail.From = New MailAddress("satdc_jember@jbr.sat.co.id")
mail.To.Add(TextBox1.Text)
mail.Subject = "REPORT SALES BRANCH JEMBER, PERIODE : " & tgl_tr
s_cp
mail.Body = "REPORT SALES BRANCH JEMBER, PERIODE : " & tgl_sekar
ang & Chr(10) & " " & Chr(10) & "# REPORT SALES TOTAL " & Chr(10) & "" & sales_c
abangp & " " & Chr(10) & " " & Chr(10) & "# REPORT SALES RETAIL " & Chr(10) & ""
& sales_retailp & " " & Chr(10) & " " & Chr(10) & "# 10 TOKO RANGKING SALES RET
AIL TERTINGGI " & Chr(10) & "" & Chr(10) & "" & bes1p & "" & Chr(10) & "" & bes2
p & "" & Chr(10) & "" & bes3p & "" & Chr(10) & "" & bes4p & "" & Chr(10) & "" &
bes5p & "" & Chr(10) & "" & bes6p & "" & Chr(10) & "" & bes7p & "" & Chr(10) & "
" & bes8p & "" & Chr(10) & "" & bes9p & "" & Chr(10) & "" & bes10p & "" & Chr(10
) & Chr(10) & "# REKAP OOS TOKO :" & Chr(10) & jd_oosp & Chr(10) & " " & Chr(10
) & "# REKAP DSI :" & Chr(10) & jd_dsi_pt & Chr(10) & " " & Chr(10) & Chr(10) &
"==============================================================" & Chr(10) & Chr
(10) & "REPORT SALES BRANCH JEMBER, PERIODE : " & tgl_trs_c & Chr(10) & Chr(10)
& "# REPORT SALES TOTAL " & Chr(10) & "" & sales_cabang & " " & Chr(10) & " " &
Chr(10) & "# REPORT SALES RETAIL " & Chr(10) & "" & sales_retail & " " & Chr(10)
& "" & Chr(10) & "# 10 TOKO RANGKING SALES RETAIL TERTINGGI " & Chr(10) & "" &
Chr(10) & "" & bes1 & "" & Chr(10) & "" & bes2 & "" & Chr(10) & "" & bes3 & "" &
Chr(10) & "" & bes4 & "" & Chr(10) & "" & bes5 & "" & Chr(10) & "" & bes6 & ""
& Chr(10) & "" & bes7 & "" & Chr(10) & "" & bes8 & "" & Chr(10) & "" & bes9 & ""
& Chr(10) & "" & bes10 & "" & Chr(10) & Chr(10) & "# REKAP OOS TOKO :" & Chr(10
) & jd_oos & Chr(10) & Chr(10) & "# REKAP DSI :" & Chr(10) & jd_dsi_at & Chr(10)
& Chr(10) & Chr(10)
SmtpServer.Port = 587
SmtpServer.Credentials = New System.Net.NetworkCredential("satdc
_jember@jbr.sat.co.id", "satdcjbr234")
SmtpServer.EnableSsl = False
SmtpServer.Send(mail)
Catch ex As Exception
MsgBox("KONEKSI JARINGAN BERMASALAH, HUB AFIF")
End Try
conn.Close()
ElseIf h = 8 And m = 17 And s = 1 Then
'TARIK DATA
ChDir("D:\")
Shell("C:\ORANT\BIN\ifrun60.EXE D:\SALES_KAB.FMX sat_edp/sat_edp@IM
Sjbr ", vbNormalFocus)

ElseIf h = 8 And m = 40 And s = 1 And ms < 100 Then


Call koneksi()
' tgl
cmd = New OleDbCommand("select to_char(to_date(sysdate-1),'dd')tgl_a
wal from dual", conn)
dr = cmd.ExecuteReader

dr.Read()
Dim tgl As String = dr.Item(0)
' tgl awal
cmd = New OleDbCommand("select to_char(to_date(sysdate-'" & tgl & "'
),'dd')tgl_awal from dual", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim tgl_awal As String = dr.Item(0)
'bulan
cmd = New OleDbCommand("select to_char(to_date(sysdate-1),'MON-yy')b
ulan from dual", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim bulan As String = dr.Item(0)
'tgl akhir
cmd = New OleDbCommand("select to_char(to_date(sysdate-1),'dd-MON-yy
')tgl_akhir from dual", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim tgl_akhir As String = dr.Item(0)
Dim hasil As String = "SALES_YZ01_Periode_" & tgl_awal & "-" & bulan
& " - " & tgl_akhir & ".xls"
If IO.File.Exists("D:\print\" & hasil) Then
TextBox2.Text = hasil
'MsgBox("File ada" & file)
Try
Dim mail As MailMessage = New MailMessage()
Dim SmtpServer As SmtpClient = New SmtpClient("10.234.144.10
")
mail.From = New MailAddress("satdc_jember@jbr.sat.co.id")
mail.To.Add(TextBox1.Text)
mail.Subject = "AUTO EMAIL SALES PER KABUPATEN BRANCH JEMBER
"
'mail.Body = "TESTING"
Dim Attachment As System.Net.Mail.Attachment
Attachment = New System.Net.Mail.Attachment("D:\print\" & ha
sil)
mail.Attachments.Add(Attachment)
SmtpServer.Port = 587
SmtpServer.Credentials = New System.Net.NetworkCredential("s
atdc_jember@jbr.sat.co.id", "satdcjbr234")
SmtpServer.EnableSsl = False
SmtpServer.Send(mail)
TextBox3.Text = "FILE TELAH TERKIRIM"
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Else

TextBox3.Text = "FILE GAGAL / TIDAK DITEMUKAN"


End If
conn.Close()
End If
End Sub
End Class

Vous aimerez peut-être aussi