Private Sub Baocao()
Dim Arr(), i As Long, j As Long, k As Long, tungay As Date, denngay As Date, EndR As Long
Dim HoaDon As String, tenbh As String, tenship As String, So_HD_BL As Long, So_HD_DL As Long
Dim TongTienBan As Double, TongTienShip As Double, TongTienBanNV As Double, TongTienShipNV As Double
Dim TongdtBL As Double, TongdtDL As Double, TongCongNo As Double, TongGiamTru As Double
If Me.txtTungay.Value = "" Then
MsgBox ("Hay nhap ngay bat dau")
Exit Sub
Else
tungay = Format(Me.txtTungay.Value, "dd/mm/yyyy")
End If
If Me.txtDenngay.Value = "" Then
MsgBox ("Hay nhap ngay ket thuc")
Exit Sub
Else
denngay = Format(Me.txtDenngay.Value, "dd/mm/yyyy")
End If
If Me.cobnvBH.Value <> "" Then tenbh = Me.cobnvBH.Value
If Me.cobnvBH.Value <> "" Then tenship = Me.cobnvGH.Value
With Sheets("Banle")
EndR = .Range("C" & Rows.Count).End(xlUp).Row
Arr = .Range("B4:R" & EndR).Value
End With
With CreateObject("scripting.dictionary")
For i = 1 To UBound(Arr)
If Arr(i, 2) >= tungay And Arr(i, 2) <= denngay Then
HoaDon = Arr(i, 1)
If Left(HoaDon, 2) = "HD" Then
TongdtBL = TongdtBL + Arr(i, 14)
If Not .exists(HoaDon) Then
So_HD_BL = So_HD_BL + 1
.Add HoaDon, ""
End If
ElseIf Left(HoaDon, 2) = "DL" Then
TongdtDL = TongdtDL + Arr(i, 14)
If Not .exists(HoaDon) Then
So_HD_DL = So_HD_DL + 1
.Add HoaDon, ""
End If
End If
If Arr(i, 17) = "" Then TongCongNo = TongCongNo + Arr(i, 14)
If Arr(i, 12) <> "" And IsNumeric(Arr(i, 12)) Then TongGiamTru = TongGiamTru + Arr(i, 12) * Arr(i, 14)
If Arr(i, 13) <> "" And IsNumeric(Arr(i, 13)) Then TongGiamTru = TongGiamTru + Arr(i, 13)
If Arr(i, 3) = tenbh Then TongTienBanNV = TongTienBanNV + Arr(i, 14)
TongTienBan = TongTienBan + Arr(i, 14)
If IsNumeric(Arr(i, 15)) Then
TongTienShip = TongTienShip + Arr(i, 15)
If Arr(i, 16) = tenship Then TongTienShipNV = TongTienShipNV + Arr(i, 15)
End If
End If
Next i
End With
Me.lbnvBH.Caption = Format(TongTienBanNV, " #.###")
Me.lbnvGH.Caption = Format(TongTienShipNV, " #.###")
Me.lbhdBL.Caption = Format(So_HD_BL, " #.###")
Me.lbhdDL.Caption = Format(So_HD_DL, " #.###")
Me.lbTongCongno.Caption = Format(TongCongNo, " #.###")
Me.lbKMGT.Caption = Format(TongGiamTru, " #.###")
Me.lbdtBL.Caption = Format(TongdtBL, " #.###")
Me.lbdtDL.Caption = Format(TongdtDL, " #.###")
Me.lbPhiShip.Caption = Format(TongTienShip, " #.###")
Me.lbTongDT.Caption = Format(TongTienBan, " #.###")
End Sub