Imports RSS.ClassDB
Imports RSS.CFunction1
Imports RSS.CConstant
Public Class frmExDateMakeExcise
Dim date1 As Date
Dim inv, srno As Integer
Dim PerId As Integer
Dim PerName As String
Dim PerLicence As Integer
Dim PerValidity As String
Dim PerAddress As String
Dim ml As Double = 0
Dim Tml As Double = 0
Dim amt As Double = 0
Dim limit As Integer = 0
Dim qtylimit As Integer = 0
Private Sub txtmonth_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtmonth.KeyDown
Try
If e.KeyCode = Keys.Enter Then
If Val(txtmonth.Text) < 1 Or Val(txtmonth.Text) > 12 Then
txtmonth.Text = ""
Else
txtyear.Focus()
End If
End If
If e.KeyData = Keys.Escape Then
txtdate.Focus()
End If
If e.KeyData = Keys.F12 Then
Me.Close()
End If
Catch ex As Exception
End Try
End Sub
Private Sub frmExDateMakeExcise_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Try
DATACLOSE()
ExDateCheck = False
Me.Dispose()
Catch ex As Exception
End Try
End Sub
Private Sub frmExDateMakeExcise_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
End Sub
Private Sub txtdate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtdate.KeyDown
Try
If e.KeyCode = Keys.Enter Then
If Val(txtdate.Text) < 1 Or Val(txtdate.Text) > 31 Then
txtdate.Text = ""
Else
txtmonth.Focus()
End If
End If
If e.KeyData = Keys.Escape Then
Me.Close()
End If
If e.KeyData = Keys.F12 Then
Me.Close()
End If
Catch ex As Exception
End Try
End Sub
Private Sub txtdate_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtdate.TextChanged
Try
If txtdate.TextLength = 2 Then
If Val(txtdate.Text) < 1 Or Val(txtdate.Text) > 31 Then
txtdate.Text = ""
Else
txtmonth.Focus()
End If
End If
Catch ex As Exception
End Try
End Sub
Private Sub txtyear_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtyear.KeyDown
Try
If e.KeyCode = Keys.Enter Then
If Val(txtyear.TextLength) = 4 Then
Dim date11 As String = Val(txtdate.Text) & "/" & Val(txtmonth.Text) & "/" & Val(txtyear.Text)
dtpdatesetCB.Value = FormatDateTime(date11, DateFormat.ShortDate)
DatePresent(dtpdatesetCB.Value)
Me.Dispose()
Else
txtyear.Text = ""
End If
End If
If e.KeyData = Keys.Escape Then
txtmonth.Focus()
End If
If e.KeyData = Keys.F12 Then
Me.Close()
End If
Catch ex As Exception
MsgBox("Date Is Not Valid")
txtyear.Text = Date.Today.Year
txtmonth.Text = Date.Today.Month
txtdate.Text = Date.Today.Day
txtdate.Focus()
End Try
End Sub
Private Sub txtyear_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtyear.TextChanged
Try
If txtyear.TextLength <= 4 Then
Else
txtyear.Text = ""
End If
Catch ex As Exception
End Try
End Sub
Private Sub txtmonth_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtmonth.TextChanged
Try
If txtmonth.TextLength <= 2 Then
If Val(txtmonth.Text) < 1 Or Val(txtmonth.Text) > 12 Then
txtmonth.Text = ""
End If
End If
Catch ex As Exception
End Try
End Sub
Public Function DatePresent(ByVal dateF As Date)
Try
Dim dt As New DataTable
GetDataTable("select date from ExFinalBillDetails", dt)
For i = 0 To dt.Rows.Count - 1
If FormatDateTime(dt.Rows(i).Item(0), DateFormat.ShortDate) = dateF Then
ExDateCheck = True
End If
Next
If ExDateCheck = True Then
If DialogResult.Yes = MsgBox("Allready Excise Done For " & dateF & " Do U Want To Repalce It.????", MsgBoxStyle.YesNo) Then
DeleteExBill(dateF)
FrmName = "DelEx"
frmExBill_Correction.Rearrange()
CreateExBill(dateF)
Else
End If
Else
CreateExBill(dateF)
MsgBox("excise created for " & dateF)
End If
Catch ex As Exception
End Try
Return False
End Function
Public Function DeleteExBill(ByVal dateE As Date)
Try
Dim dateDel As Date = FormatDateTime(dateE.Date, DateFormat.ShortDate)
Dim dt As New DataTable
GetDataTable("select * from ExFinalBill", dt)
For i = 0 To dt.Rows.Count - 1
If dt.Rows(i).Item(2) = dateDel Then
GetDataTable("delete * from ExFinalBillDetails where invoice=" & dt.Rows(i).Item(1))
GetDataTable("delete * from ExFinalBill where invoice=" & dt.Rows(i).Item(1))
End If
Next
Catch ex As Exception
End Try
Return False
End Function
Public Function CreateExBill(ByVal dated As Date)
Try
date1 = dated
date1 = FormatDateTime(date1, DateFormat.ShortDate)
GetDataTable("delete * from ExTemp")
Dim ADD As Boolean = False
Dim dt As New DataTable
GetDataTable("select * from BILLFINAL", dt)
Dim dtMain As New DataTable
GetDataTable("select DATE, BILLNO from BILLFINAL where TABLE_NO<>'XYZ' AND TYPE<>'Cancel'", dtMain)
For K = 0 To dtMain.Rows.Count - 1
ADD = False
dtMain.Rows(K).Item(0) = FormatDateTime(dtMain.Rows(K).Item(0), DateFormat.ShortDate)
date1 = FormatDateTime(date1, DateFormat.ShortDate)
Dim datetemp As New Date
datetemp = FormatDateTime(dtMain.Rows(K).Item(0), DateFormat.ShortDate)
If datetemp = date1 Then
Dim dtBillRet As New DataTable
GetDataTable("select * from finalbill where DEPT='Liquior' AND BILLNO=" & Val(dtMain.Rows(K).Item(1)), dtBillRet)
Dim BILLNO = Val(dtMain.Rows(K).Item(1))
For I = 0 To dtBillRet.Rows.Count - 1
If dtBillRet.Rows(I).Item(11) <> "NIP 1/2" And dtBillRet.Rows(I).Item(11) <> "PEG_L" And dtBillRet.Rows(I).Item(11) <> "PEG_S" Then
Dim dtExTemp As New DataTable
GetDataTable("select * from ExTemp", dtExTemp)
Dim dtInner As New DataTable
GetDataTable("select ITEM from ExTemp", dtInner)
If dtInner.Rows.Count > 0 Then
For J = 0 To dtInner.Rows.Count - 1
If dtBillRet.Rows(I).Item(3).ToString = dtInner.Rows(J).Item(0).ToString Then
dtBillRet.Rows(I).Item(0).ToString()
MsgBox(dtBillRet.Rows(I).Item(3).ToString)
Dim addQty As Integer = 0
Dim dtInAlready As New DataTable
GetDataTable("select * from ExTemp where ITEM='" & dtInner.Rows(J).Item(0) & "'", dtInAlready)
If dtInAlready.Rows.Count > 0 Then
addQty = Val(dtInAlready.Rows(0).Item(1)) + Val(dtBillRet.Rows(I).Item(4))
dtInAlready.Rows(0).Item(1) = Val(addQty)
dtInAlready.Rows(0).Item(3) = Val(dtInAlready.Rows(0).Item(2)) * Val(addQty)
SaveData(dtInAlready, CConstant.DBOpeartion.MODIFY, "ExTemp", "ITEM", False)
ADD = True
End If
End If
Next
End If
If ADD = False Then
Dim exRate As New DataTable
GetDataTable("select exciserate from item where item='" & dtBillRet.Rows(I).Item(3) & "'", exRate)
dtExTemp.Rows.Add()
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(0) = dtBillRet.Rows(I).Item(3)
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(1) = dtBillRet.Rows(I).Item(4)
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(2) = Val(exRate.Rows(0).Item(0))
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(3) = Val(dtBillRet.Rows(I).Item(4)) * Val(exRate.Rows(0).Item(0))
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(4) = dtBillRet.Rows(I).Item(7)
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(5) = dtBillRet.Rows(I).Item(8)
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(6) = dtBillRet.Rows(I).Item(9)
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(7) = dtBillRet.Rows(I).Item(10)
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(8) = dtBillRet.Rows(I).Item(11)
dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(9) = dtBillRet.Rows(I).Item(12)
SaveData(dtExTemp, CConstant.DBOpeartion.ADD, "ExTemp", "ITEM", False)
End If
End If
Next
End If
Next
Dim qty As Integer
Dim dtDis As New DataTable
GetDataTable("select * from ExTemp", dtDis)
Dim ml As Integer = 0
Dim tml As Integer = 0
For p = 0 To dtDis.Rows.Count - 1
qty = Val(dtDis.Rows(p).Item(1))
Dim x As Integer = 1
Dim cnt180 As Integer = 0
Dim dtlimt As New DataTable
GetDataTable("Select limit from ExUnitLimit where Unit=" & Val(dtDis.Rows(p).Item(7)), dtlimt)
If dtlimt.Rows.Count > 0 Then
qtylimit = Val(dtlimt.Rows(0).Item(0))
Else
Dim dtlimt2 As New DataTable
GetDataTable("select * from ExStoreInfo where code=1", dtlimt2)
If dtlimt2.Rows.Count > 0 Then
limit = Val(dtlimt2.Rows(0).Item(4))
qtylimit = Val(dtlimt2.Rows(0).Item(5))
End If
End If
While Val(qty) >= x
Dim exit1 As Boolean = False
ml = Val(ml) + Val(dtDis.Rows(p).Item(7))
tml = Val(tml) + Val(dtDis.Rows(p).Item(7))
If Val(dtDis.Rows(p).Item(7)) = 180 Then
If Val(Val(tml) / Val(dtDis.Rows(p).Item(7))) < qtylimit Then
If Val(Val(tml) / Val(dtDis.Rows(p).Item(7))) = qty Then
GetPerHld()
SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), Val(Val(ml) / Val(dtDis.Rows(p).Item(7))))
SaveBill()
qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
ml = 0
tml = 0
Exit While
End If
Else
SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), Val(Val(ml) / Val(dtDis.Rows(p).Item(7))))
GetPerHld()
SaveBill()
qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
ml = 0
tml = 0
If tml <= limit And qty = x Then
exit1 = True
End If
End If
End If
If tml <= limit And qty = x Or qty = Val(Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))) Then
If exit1 = True Then
Else
GetPerHld()
End If
SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), qty)
GetPerHld()
SaveBill()
qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
ml = 0
tml = 0
If exit1 = True Then
Exit While
qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
End If
End If
If tml >= limit And Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) > 1 Then
If tml <= limit And Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) < qtylimit Then
Else
If Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) < qtylimit Then
If tml > limit Then
ml = ml - Val(Val(dtDis.Rows(p).Item(7)))
End If
Else
Dim a As Integer
a = Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
a = a - qtylimit
ml = ml - Val(Val(dtDis.Rows(p).Item(7)) * a)
End If
End If
GetPerHld()
SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), Val(Val(ml) / Val(dtDis.Rows(p).Item(7))))
SaveBill()
qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
ml = 0
tml = 0
End If
If ml >= limit And Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) = 1 Then
GetPerHld()
Dim dtx, dt1 As New DataTable
tml = 0
If Val(dtDis.Rows(p).Item(7)) > limit Then
dtx = New DataTable
GetDataTable("select max(invoice) from ExFinalBillDetails", dtx)
If IsDBNull(dtx) = True Then
Else
dt1 = New DataTable
GetDataTable("select * from ExFinalBillDetails where invoice=" & Val(dtx.Rows(0).Item(0)), dt1)
If dt1.Rows.Count > 0 Then
If Val(dt1.Rows(0).Item(7)) <= limit Then
tml = Val(dt1.Rows(0).Item(2))
SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), 1)
GetPerHld()
SaveBill()
qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
ml = 0
End If
End If
End If
End If
If ml > 0 Then
SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), 1)
GetPerHld()
SaveBill()
qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
ml = 0
End If
End If
End While
Next
GetDataTable("delete * from ExTemp")
MsgBox("Excise Bill Completed...", vbInformation)
Catch ex As Exception
End Try
Return False
End Function
Public Function GetPerHld()
Try
Dim dtHldId As New DataTable
GetDataTable("select PerHldId from ExStoreInfo where code=1", dtHldId)
RetrivePerHldName(dtHldId.Rows(0).Item(0))
PerId = dtHldId.Rows(0).Item(0)
RetriveInvoiceNo()
Catch ex As Exception
End Try
Return False
End Function
Public Function SaveBillDetail(ByVal packing As String, ByVal brand As String, ByVal qty As Integer)
Try
Dim dtSDetail As New DataTable
GetDataTable("select * from ExFinalBillDetails", dtSDetail)
dtSDetail.Rows.Add()
Dim dtsr As New DataTable
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(0) = GETSRNO()
inv = RetriveInvoiceNo()
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(1) = RetriveInvoiceNo()
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(2) = date1
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(4) = qty
Dim dtItem As New DataTable
GetDataTable("select * from item where BRAND='" & brand & "' AND PACKING='" & packing & "'", dtItem)
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(3) = dtItem.Rows(0).Item(1)
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(5) = Val(dtItem.Rows(0).Item(8))
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(6) = Val(dtItem.Rows(0).Item(8)) * Val(qty)
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(7) = dtItem.Rows(0).Item(4)
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(8) = Val(dtItem.Rows(0).Item(5))
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(9) = dtItem.Rows(0).Item(6)
dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(10) = dtItem.Rows(0).Item(16)
SaveData(dtSDetail, CConstant.DBOpeartion.ADD, "ExFinalBillDetails", "invoice", False)
Catch ex As Exception
End Try
Return False
End Function
Public Function GETSRNO()
Try
Dim dtn As New DataTable
GetDataTable("select max(srno) from ExFinalBill", dtn)
If IsDBNull(dtn.Rows(0).Item(0)) Then
Return 1
Else
Return Val(dtn.Rows(0).Item(0)) + 1
End If
Catch ex As Exception
End Try
Return False
End Function
Public Function SaveBill()
Try
Dim dtSBill As New DataTable
GetDataTable("select * from ExFinalBill", dtSBill)
dtSBill.Rows.Add()
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(0) = GETSRNO()
inv = RetriveInvoiceNo()
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(1) = RetriveInvoiceNo()
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(2) = date1
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(3) = PerName
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(4) = PerLicence
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(5) = PerValidity
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(6) = PerAddress
Dim sum As Double = 0
Dim dtTotal As New DataTable
GetDataTable("select invoice,date,amt from ExFinalBillDetails where invoice=" & inv, dtTotal)
For i = 0 To dtTotal.Rows.Count - 1
dtTotal.Rows(i).Item(1) = FormatDateTime(dtTotal.Rows(i).Item(1), DateFormat.ShortDate)
date1 = FormatDateTime(date1, DateFormat.ShortDate)
If dtTotal.Rows(i).Item(1) = date1 Then
sum = Val(sum) + Val(dtTotal.Rows(i).Item(2))
End If
Next
dtSBill.Rows(dtSBill.Rows.Count - 1).Item(7) = Val(sum)
SaveData(dtSBill, CConstant.DBOpeartion.ADD, "ExFinalBill", "invoice", False)
Dim dtHldNO As New DataTable
GetDataTable("select code from ExPremiteHolder where name='" & PerName & "'", dtHldNO)
Dim dtHldSave As New DataTable
GetDataTable("select PerHldId,date,code from ExStoreInfo where code=1", dtHldSave)
Dim dtMaxCode As New DataTable
GetDataTable("select max(code) from ExPremiteHolder", dtMaxCode)
If Val(dtHldNO.Rows(0).Item(0)) = Val(dtMaxCode.Rows(0).Item(0)) Then
dtHldSave.Rows(0).Item(0) = 1
Else
dtHldSave.Rows(0).Item(0) = Val(dtHldNO.Rows(0).Item(0)) + 1
End If
SaveData(dtHldSave, CConstant.DBOpeartion.MODIFY, "ExStoreInfo", "code", False)
Catch ex As Exception
End Try
Return False
End Function
Public Function RetrivePerHldName(ByRef id As Integer)
Try
Dim d1 As New DataTable
GetDataTable("select * from ExPremiteHolder where code=" & id, d1)
PerName = d1.Rows(0).Item(1)
PerLicence = d1.Rows(0).Item(2)
PerValidity = d1.Rows(0).Item(3)
PerAddress = d1.Rows(0).Item(5)
Catch ex As Exception
End Try
Return False
End Function
Public Function RetriveInvoiceNo()
Try
Dim dtEx1, dtEx2 As New DataTable
GetDataTable("select max(invoice) from ExFinalBill", dtEx1)
If IsDBNull(dtEx1.Rows(0).Item(0)) Then
Return 1
Else
Return Val(dtEx1.Rows(0).Item(0)) + 1
End If
Catch ex As Exception
End Try
Return False
End Function
Private Sub frmExDateMakeExcise_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim dt As New DataTable
GetDataTable("select * from ExStoreInfo where code=1", dt)
If dt.Rows.Count > 0 Then
limit = Val(dt.Rows(0).Item(4))
qtylimit = Val(dt.Rows(0).Item(5))
End If
dtpdateset.Format = DateTimePickerFormat.Short
dtpdateset.Value = FormatDateTime(Now.Date, DateFormat.ShortDate)
txtdate.Text = dtpdateset.Value.Day
txtmonth.Text = dtpdateset.Value.Month
txtyear.Text = dtpdateset.Value.Year
Catch ex As Exception
End Try
End Sub
End Class