📄 frmlocalpurchaseae.frm
字号:
Alignment = 1 'Right Justify
Caption = "Discount"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000011D&
Height = 240
Left = 7440
TabIndex = 39
Top = 6930
Width = 2040
End
Begin VB.Shape Shape1
Height = 8235
Left = 120
Top = 630
Width = 10935
End
Begin VB.Shape Shape4
BorderColor = &H80000006&
BorderWidth = 2
Height = 8895
Left = 60
Top = 60
Width = 11085
End
End
Attribute VB_Name = "frmLocalPurchaseAE"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public State As FormState 'Variable used to determine on how the form used
Public PK As Long 'Variable used to get what record is going to edit
Public CloseMe As Boolean
Public ForCusAcc As Boolean
Dim cIGross As Currency 'Gross Amount
Dim cIAmount As Currency 'Current Invoice Amount
Dim cDAmount As Currency 'Current Invoice Discount Amount
Dim cIRowCount As Integer
Dim HaveAction As Boolean 'Variable used to detect if the user perform some action
Dim rs As New Recordset 'Main recordset for Invoice
Private Sub btnAdd_Click()
If nsdStock.Text = "" Then nsdStock.SetFocus: Exit Sub
If toNumber(txtUnitPrice.Text) <= 0 Then
MsgBox "Please enter a valid sales price.", vbExclamation
txtUnitPrice.SetFocus
Exit Sub
End If
Dim CurrRow As Integer
CurrRow = getFlexPos(Grid, 10, nsdStock.BoundText)
'Add to grid
With Grid
If CurrRow < 0 Then
'Perform if the record is not exist
If .Rows = 2 And .TextMatrix(1, 10) = "" Then
.TextMatrix(1, 1) = nsdStock.getSelValueAt(1)
.TextMatrix(1, 2) = nsdStock.Text
.TextMatrix(1, 3) = nsdStock.getSelValueAt(5)
.TextMatrix(1, 4) = txtQty.Text
.TextMatrix(1, 5) = dcUnit.Text
.TextMatrix(1, 6) = toMoney(txtUnitPrice.Text)
.TextMatrix(1, 7) = toMoney(txtGross(1).Text)
.TextMatrix(1, 8) = toNumber(txtDisc.Text)
.TextMatrix(1, 9) = toMoney(toNumber(txtNetAmount.Text))
.TextMatrix(1, 10) = nsdStock.BoundText
Else
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 1) = nsdStock.getSelValueAt(1)
.TextMatrix(.Rows - 1, 2) = nsdStock.Text
.TextMatrix(.Rows - 1, 3) = nsdStock.getSelValueAt(5)
.TextMatrix(.Rows - 1, 4) = txtQty.Text
.TextMatrix(.Rows - 1, 5) = dcUnit.Text
.TextMatrix(.Rows - 1, 6) = toMoney(txtUnitPrice.Text)
.TextMatrix(.Rows - 1, 7) = toMoney(txtGross(1).Text)
.TextMatrix(.Rows - 1, 8) = toNumber(txtDisc.Text)
.TextMatrix(.Rows - 1, 9) = toMoney(toNumber(txtNetAmount.Text))
.TextMatrix(.Rows - 1, 10) = nsdStock.BoundText
.Row = .Rows - 1
End If
'Increase the record count
cIRowCount = cIRowCount + 1
Else
If MsgBox("Invoice payment already exist. Do you want to replace it?", vbQuestion + vbYesNo) = vbYes Then
.Row = CurrRow
'Restore back the invoice amount and discount
cIGross = cIGross - toNumber(Grid.TextMatrix(.RowSel, 7))
txtGross(2).Text = Format$(cIGross, "#,##0.00")
cIAmount = cIAmount - toNumber(Grid.TextMatrix(.RowSel, 9))
txtNet.Text = Format$(cIAmount, "#,##0.00")
cDAmount = cDAmount - toNumber(toNumber(txtDisc.Text) / 100) * (toNumber(toNumber(Grid.TextMatrix(.RowSel, 4)) * toNumber(txtUnitPrice.Text)))
txtDesc.Text = Format$(cDAmount, "#,##0.00")
.TextMatrix(CurrRow, 1) = nsdStock.getSelValueAt(1)
.TextMatrix(CurrRow, 2) = nsdStock.Text
.TextMatrix(CurrRow, 3) = nsdStock.getSelValueAt(5)
.TextMatrix(CurrRow, 4) = txtQty.Text
.TextMatrix(CurrRow, 5) = dcUnit.Text
.TextMatrix(CurrRow, 6) = toMoney(txtUnitPrice.Text)
.TextMatrix(CurrRow, 7) = toMoney(txtGross(1).Text)
.TextMatrix(CurrRow, 8) = toNumber(txtDisc.Text)
.TextMatrix(CurrRow, 9) = toMoney(toNumber(txtNetAmount.Text))
.TextMatrix(CurrRow, 10) = nsdStock.BoundText
Else
Exit Sub
End If
End If
'Add the amount to current load amount
cIGross = cIGross + toNumber(txtGross(1).Text)
txtGross(2).Text = Format$(cIGross, "#,##0.00")
cIAmount = cIAmount + toNumber(txtNetAmount.Text)
cDAmount = cDAmount + toNumber(toNumber(txtDisc.Text) / 100) * (toNumber(toNumber(txtQty.Text) * toNumber(txtUnitPrice.Text)))
txtDesc.Text = Format$(cDAmount, "#,##0.00")
txtNet.Text = Format$(cIAmount, "#,##0.00")
txtTaxBase.Text = toMoney(txtNet.Text / 1.12)
txtVat.Text = toMoney(txtNet.Text - txtTaxBase.Text)
'Highlight the current row's column
.ColSel = 10
'Display a remove button
Grid_Click
'Reset the entry fields
ResetEntry
End With
End Sub
Private Sub btnRemove_Click()
'Remove selected load product
With Grid
'Update grooss to current purchase amount
cIGross = cIGross - toNumber(Grid.TextMatrix(.RowSel, 7))
txtGross(2).Text = Format$(cIGross, "#,##0.00")
'Update amount to current invoice amount
cIAmount = cIAmount - toNumber(Grid.TextMatrix(.RowSel, 9))
txtNet.Text = Format$(cIAmount, "#,##0.00")
'Update discount to current invoice disc
cDAmount = cDAmount - toNumber(toNumber(txtDisc.Text) / 100) * (toNumber(toNumber(Grid.TextMatrix(.RowSel, 4)) * toNumber(Grid.TextMatrix(.RowSel, 6))))
txtDesc.Text = Format$(cDAmount, "#,##0.00")
txtTaxBase.Text = toMoney(txtNet.Text / 1.12)
txtVat.Text = toMoney(txtNet.Text - txtTaxBase.Text)
'Update the record count
cIRowCount = cIRowCount - 1
If .Rows = 2 Then Grid.Rows = Grid.Rows + 1
.RemoveItem (.RowSel)
End With
btnRemove.Visible = False
Grid_Click
End Sub
Private Sub CmdReturn_Click()
'Display the details
Dim RSDetails As New Recordset
RSDetails.CursorLocation = adUseClient
RSDetails.Open "SELECT * FROM qry_Local_Purchase_Detail WHERE LocalPurchaseID=" & PK & " AND QtyDue > 0 ORDER BY Stock ASC", CN, adOpenStatic, adLockOptimistic
If RSDetails.RecordCount > 0 Then
With frmLocalPurchaseReturnAE
.State = adStateAddMode
.PK = PK
.show vbModal
End With
Else
MsgBox "All items are already returned.", vbInformation
End If
End Sub
Private Sub txtCheckAmount_Validate(Cancel As Boolean)
txtCheckAmount.Text = toMoney(toNumber(txtCheckAmount.Text))
End Sub
Private Sub txtdisc_Change()
txtQty_Change
End Sub
Private Sub txtdisc_Click()
txtQty_Change
End Sub
Private Sub cmbPaymentType_Click()
If cmbPaymentType.ListIndex = 0 Then 'if Cash
lblCash.Visible = True
txtCash.Visible = True
frmPayment.Visible = False
Else 'if Bank
frmPayment.Visible = True
lblCash.Visible = False
txtCash.Visible = False
End If
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub txtDisc_GotFocus()
HLText txtDisc
End Sub
Private Sub txtdisc_Validate(Cancel As Boolean)
txtDisc.Text = toNumber(txtDisc.Text)
End Sub
Private Sub cmdPH_Click()
'frmInvoiceViewerPH.INV_PK = PK
'frmInvoiceViewerPH.Caption = "Payment History Viewer"
'frmInvoiceViewerPH.lblTitle.Caption = "Payment History Viewer"
'frmInvoiceViewerPH.show vbModal
End Sub
Private Sub cmdSave_Click()
'Verify the entries
If txtInvoiceNo.Text = "" Then
MsgBox "Please enter Invoice No.", vbExclamation
txtInvoiceNo.SetFocus
Exit Sub
End If
If cIRowCount < 1 Then
MsgBox "Please enter item to purchase before you can save this record.", vbExclamation
nsdStock.SetFocus
Exit Sub
End If
If isRecordExist("Local_Purchase", "InvoiceNo", txtInvoiceNo.Text, True) = True Then
MsgBox "Invoice already exist. Please change it.", vbExclamation
txtInvoiceNo.SetFocus
Exit Sub
End If
If MsgBox("This save the record. Do you want to proceed?", vbQuestion + vbYesNo) = vbNo Then Exit Sub
Dim RSDetails As New Recordset
RSDetails.CursorLocation = adUseClient
RSDetails.Open "SELECT * FROM Local_Purchase_Detail WHERE LocalPurchaseID=" & PK, CN, adOpenStatic, adLockOptimistic
Screen.MousePointer = vbHourglass
Dim c As Integer
On Error GoTo err
CN.BeginTrans
'Save the record
With rs
If State = adStateAddMode Or State = adStatePopupMode Then
.AddNew
![LocalPurchaseID] = PK
![DateAdded] = Now
![AddedByFK] = CurrUser.USER_PK
Else
![DateModified] = Now
![LastUserFK] = CurrUser.USER_PK
End If
![InvoiceNo] = txtInvoiceNo.Text
![Date] = dtpDate.Value
![PurchaseFrom] = txtPurchaseFrom.Text
![PaymentType] = cmbPaymentType.Text
![PurchaseRequestNo] = txtPurchaseRequest.Text
![CanvasSheetNo] = txtCanvass.Text
![Gross] = toNumber(txtGross(2).Text)
![Discount] = txtDesc.Text
![TaxBase] = toNumber(txtTaxBase.Text)
![Vat] = toNumber(txtVat.Text)
![NetAmount] = toNumber(txtNet.Text)
If cmbPaymentType.ListIndex = 0 Then ![Cash] = toMoney(toNumber(txtCash.Text)) 'if cash
![Remarks] = txtRemarks.Text
.Update
End With
If cmbPaymentType.ListIndex = 1 Then 'if Bank
Dim RSChecks As New Recordset
RSChecks.CursorLocation = adUseClient
RSChecks.Open "SELECT * FROM Local_Purchase_Checks WHERE LocalPurchaseID=" & PK, CN, adOpenStatic, adLockOptimistic
With RSChecks
.AddNew
![LocalPurchaseID] = PK
![Bank] = txtBank.Text
![Checkdate] = dtpBankDate.Value
![CheckNo] = txtCheck.Text
![CheckAmount] = txtCheckAmount.Text
.Update
End With
End If
With Grid
'Save to stock card
Dim RSStockCard As New Recordset
RSStockCard.CursorLocation = adUseClient
RSStockCard.Open "Stock_Card", CN, , adLockOptimistic, adCmdTable
'Save to stocks table
Dim RSStocks As New Recordset
RSStocks.CursorLocation = adUseClient
RSStocks.Open "Stocks", CN, , adLockOptimistic
'Save the details of the records
For c = 1 To cIRowCount
.Row = c
If State = adStateAddMode Or State = adStatePopupMode Then
'Add qty received in Local Purchase Details
RSDetails.AddNew
RSDetails![LocalPurchaseID] = PK
RSDetails![StockID] = toNumber(.TextMatrix(c, 10))
RSDetails![Qty] = toNumber(.TextMatrix(c, 4))
RSDetails![Unit] = getUnitID(.TextMatrix(c, 5))
RSDetails![Price] = toNumber(.TextMatrix(c, 6))
RSDetails![Discount] = toNumber(.TextMatrix(c, 8)) / 100
RSDetails.Update
'Add qty in stock card
RSStockCard.AddNew
RSStockCard!Type = "CP"
RSStockCard!RefNo1 = txtInvoiceNo.Text
RSStockCard!Pieces1 = toNumber(.TextMatrix(c, 4))
RSStockCard!Cost = toNumber(.TextMatrix(c, 6))
RSStockCard!StockID = toNumber(.TextMatrix(c, 10))
RSStockCard.Update
'Add qty received in stocks
RSStocks.Find "[StockID] = " & toNumber(.TextMatrix(c, 10)), , adSearchForward, 1
RSStocks!OnHand = toNumber(RSStocks!OnHand) + toNumber(.TextMatrix(c, 4))
RSStocks.Update
End If
Next c
End With
'Clear variables
c = 0
Set RSDetails = Nothing
CN.CommitTrans
HaveAction = True
Screen.MousePointer = vbDefault
If State = adStateAddMode Then
MsgBox "New record has been successfully saved.", vbInformation
If MsgBox("Do you want to add another new record?", vbQuestion + vbYesNo) = vbYes Then
ResetFields
GeneratePK
Else
Unload Me
End If
Else
MsgBox "Changes in record has been successfully saved.", vbInformation
Unload Me
End If
Exit Sub
err:
CN.RollbackTrans
prompt_err err, Name, "cmdSave_Click"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -