xref: /aoo42x/main/wizards/source/depot/Depot.xba (revision 3e02b54d)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Depot" script:language="StarBasic">Option Explicit
24cdf0e10cSrcweir
25cdf0e10cSrcweir
26cdf0e10cSrcweirSub Initialize(Optional bChooseMarketPlace as Boolean)
27cdf0e10cSrcweirDim bEnableHistory as Boolean
28cdf0e10cSrcweir	GlobalScope.BasicLibraries.LoadLibrary(&quot;Tools&quot;)
29cdf0e10cSrcweir&apos;	oMarketModel = GetControlModel(oDocument.Sheets(0), &quot;CmdHistory&quot;)
30cdf0e10cSrcweir&apos;	bEnableHistory = oMarketModel.Enabled
31cdf0e10cSrcweir	ToggleWindow(False)
32cdf0e10cSrcweir	Today = Date()
33cdf0e10cSrcweir	bDebugmode = False
34cdf0e10cSrcweir	oDocument = ThisComponent
35cdf0e10cSrcweir	oController = oDocument.GetCurrentController
36cdf0e10cSrcweir	oSheets = oDocument.Sheets
37cdf0e10cSrcweir	oFirstSheet = oSheets(0)
38cdf0e10cSrcweir	oMovementSheet = oSheets(1)
39cdf0e10cSrcweir	oBankSheet = oSheets(2)
40cdf0e10cSrcweir	oDocFormats = oDocument.NumberFormats
41cdf0e10cSrcweir	oNumberFormatter = CreateUnoService(&quot;com.sun.star.util.NumberFormatter&quot;)
42cdf0e10cSrcweir	oNumberFormatter.AttachNumberFormatsSupplier(oDocument)
43cdf0e10cSrcweir	oDocLocale = oDocument.CharLocale
44cdf0e10cSrcweir	sDocLanguage = oDocLocale.Language
45cdf0e10cSrcweir	sDocCountry = oDocLocale.Country
46cdf0e10cSrcweir	LoadLanguage()
47cdf0e10cSrcweir	ToggleWindow(True)
48cdf0e10cSrcweir&apos;	oMarketModel.Enabled = bEnableHistory
49cdf0e10cSrcweir	If Not IsMissing(bChooseMarketPlace) Then
50cdf0e10cSrcweir		If bChoosemarketPlace Then
51cdf0e10cSrcweir			ChooseMarket()
52cdf0e10cSrcweir		End If
53cdf0e10cSrcweir	Else
54cdf0e10cSrcweir		ChooseMarket()
55cdf0e10cSrcweir	End If
56cdf0e10cSrcweir	If Not IsMissing(bChooseMarketPlace) Then
57cdf0e10cSrcweir		If bChooseMarketPlace Then
58cdf0e10cSrcweir			oMarketModel.Enabled = bEnableMarket
59cdf0e10cSrcweir			oInternetModel.Enabled = bEnableInternet
60cdf0e10cSrcweir		End If
61cdf0e10cSrcweir	End If
62cdf0e10cSrcweirEnd Sub
63cdf0e10cSrcweir
64cdf0e10cSrcweir
65cdf0e10cSrcweirSub Buy()
66cdf0e10cSrcweir	Initialize(True)
67cdf0e10cSrcweir 	FillListbox(DlgTransaction.GetControl(&quot;lstBuyStocks&quot;), TransactTitle(SBDIALOGBUY), False)
68cdf0e10cSrcweir	SetupTransactionControls(SBDIALOGBUY)
69cdf0e10cSrcweir	EnableTransactionControls(False)
70cdf0e10cSrcweir	DlgTransaction.Execute()
71cdf0e10cSrcweirEnd Sub
72cdf0e10cSrcweir
73cdf0e10cSrcweir
74cdf0e10cSrcweirSub Sell()
75cdf0e10cSrcweir	Initialize(True)
76cdf0e10cSrcweir	If FillListbox(DlgTransaction.GetControl(&quot;lstSellStocks&quot;), TransactTitle(SBDIALOGSELL), True) Then
77cdf0e10cSrcweir		SetupTransactionControls(SBDIALOGSELL)
78cdf0e10cSrcweir		EnableTransactionControls(False)
79cdf0e10cSrcweir		DlgTransaction.Execute()
80cdf0e10cSrcweir	End If
81cdf0e10cSrcweirEnd Sub
82cdf0e10cSrcweir
83cdf0e10cSrcweir
84cdf0e10cSrcweirSub Reset()
85cdf0e10cSrcweirDim TransactionCount as Integer
86cdf0e10cSrcweirDim StockCount, iStartRow, i as Integer
87cdf0e10cSrcweirDim oRows, oRange as Object
88cdf0e10cSrcweirDim StockName as String
89cdf0e10cSrcweir	Initialize(True)
90cdf0e10cSrcweir	&apos; Delete transactions and reset overview
91cdf0e10cSrcweir	If MsgBox(sMsgDeleteAll, SBMSGYESNO+SBMSGQUESTION+SBMSGDEFAULTBTN2, sMsgAuthorization) = 6 Then
92cdf0e10cSrcweir		&apos; Assumption: If and only if there is an overview, then there are transactions, too
93cdf0e10cSrcweir		UnprotectSheets(oSheets)
94cdf0e10cSrcweir		StockCount = GetStocksCount(iStartRow)
95cdf0e10cSrcweir
96cdf0e10cSrcweir		For i = 1 To StockCount
97cdf0e10cSrcweir			StockName = oFirstSheet.GetCellbyPosition(SBCOLUMNNAME1, iStartRow + i).String
98cdf0e10cSrcweir			If oSheets.HasbyName(StockName) Then
99cdf0e10cSrcweir				oSheets.RemoveByName(StockName)
100cdf0e10cSrcweir			End If
101cdf0e10cSrcweir		Next
102cdf0e10cSrcweir		oDocument.AddActionLock
103cdf0e10cSrcweir		RemoveStockRows(oFirstSheet, iStartRow + 1, StockCount)
104cdf0e10cSrcweir		TransactionCount = GetTransactionCount(iStartRow)
105cdf0e10cSrcweir		RemoveStockRows(oMovementSheet, iStartRow + 2, TransactionCount)
106cdf0e10cSrcweir		ProtectSheets(oSheets)
107cdf0e10cSrcweir		oDocument.RemoveActionLock
108cdf0e10cSrcweir	End If
109cdf0e10cSrcweirEnd Sub
110cdf0e10cSrcweir
111cdf0e10cSrcweir
112cdf0e10cSrcweirSub TransactionOk
113cdf0e10cSrcweirDim Sold as Long
114cdf0e10cSrcweirDim RestQuantity, Value, PartialValue, Profit
115cdf0e10cSrcweirDim iNewRow as Integer, iRow as Integer
116cdf0e10cSrcweirDim iStockRow as Long, iRestQuantity as Long
117cdf0e10cSrcweirDim oNameCell as Object
118cdf0e10cSrcweirDim CellStockName as String, SelStockName as String
119cdf0e10cSrcweirDim CurRate as Double
120cdf0e10cSrcweirDim TransactDate as Date
121cdf0e10cSrcweirDim LocStockName as String
122cdf0e10cSrcweir	&apos; Check for rate entered
123cdf0e10cSrcweir	If TransactModel.txtRate.Value = 0 Then
124cdf0e10cSrcweir		If TransactModel.Step = SBDIALOGBUY Then
125cdf0e10cSrcweir			If MsgBox(sMsgFreeStock, SBMSGYESNO+SBMSGQUESTION, sMsgConfirm)=7 Then
126cdf0e10cSrcweir				Exit Sub
127cdf0e10cSrcweir			End If
128cdf0e10cSrcweir		Else
129cdf0e10cSrcweir			If MsgBox(sMsgTotalLoss, SBMSGYESNO+SBMSGQUESTION, sMsgConfirm)=7 Then
130cdf0e10cSrcweir				Exit Sub
131cdf0e10cSrcweir			End If
132cdf0e10cSrcweir		End If
133cdf0e10cSrcweir	End If
134cdf0e10cSrcweir	CurRate = TransactModel.txtRate.Value
135cdf0e10cSrcweir	TransactDate = CDateFromISO(TransactModel.txtDate.Date)
136cdf0e10cSrcweir	DlgTransaction.EndExecute()
137cdf0e10cSrcweir	UnprotectSheets(oSheets)
138cdf0e10cSrcweir
139cdf0e10cSrcweir	iNewRow = DuplicateRow(oMovementSheet, &quot;HiddenRow3&quot;)
140cdf0e10cSrcweir
141cdf0e10cSrcweir	If TransactModel.Step = SBDIALOGBUY Then
142cdf0e10cSrcweir		CellStockName = TransactModel.lstBuyStocks.Text
143cdf0e10cSrcweir		If Instr(1,CellStockName,&quot;$&quot;) &lt;&gt; 0 Then
144cdf0e10cSrcweir			CellStockName = &quot;&apos;&quot; &amp; CellStockName &amp; &quot;&apos;&quot;
145cdf0e10cSrcweir		End If
146cdf0e10cSrcweir		oMovementSheet.GetCellByPosition(SBCOLUMNNAME2, iNewRow).String = CellStockName
147cdf0e10cSrcweir		oMovementSheet.GetCellByPosition(SBCOLUMNQUANTITY2, iNewRow).Value = TransactModel.txtQuantity.Value
148cdf0e10cSrcweir	Else
149cdf0e10cSrcweir		CellStockName = DlgTransaction.GetControl(&quot;lstSellStocks&quot;).GetSelectedItem()
150cdf0e10cSrcweir		oMovementSheet.GetCellByPosition(SBCOLUMNNAME2, iNewRow).String = CellStockName
151cdf0e10cSrcweir		oMovementSheet.GetCellByPosition(SBCOLUMNQUANTITY2, iNewRow).Value = -TransactModel.txtQuantity.Value
152cdf0e10cSrcweir	End If
153cdf0e10cSrcweir
154cdf0e10cSrcweir	oMovementSheet.GetCellByPosition(SBCOLUMNDATE2, iNewRow).Value = CDateFromISO(TransactModel.txtDate.Date)
155cdf0e10cSrcweir	oMovementSheet.GetCellByPosition(SBCOLUMNRATE2, iNewRow).Value = TransactModel.txtRate.Value
156cdf0e10cSrcweir	oMovementSheet.GetCellByPosition(SBCOLUMNPROVPERCENT2, iNewRow).Value = TransactModel.txtCommission.EffectiveValue
157cdf0e10cSrcweir	oMovementSheet.GetCellByPosition(SBCOLUMNPROVMIN2, iNewRow).Value = TransactModel.txtMinimum.Value
158cdf0e10cSrcweir	oMovementSheet.GetCellByPosition(SBCOLUMNPROVFIX2, iNewRow).Value = TransactModel.txtFix.Value
159cdf0e10cSrcweir
160cdf0e10cSrcweir	&apos; Buy stocks: Update overview for new stocks
161cdf0e10cSrcweir	If TransactModel.Step = SBDIALOGBUY Then
162cdf0e10cSrcweir		iStockRow = GetStockRowIndex(CellStockName)
163cdf0e10cSrcweir		If iStockRow = -1 Then
164cdf0e10cSrcweir			iNewRow = DuplicateRow(oFirstSheet, &quot;HiddenRow2&quot;)
165cdf0e10cSrcweir			oFirstSheet.GetCellByPosition(SBCOLUMNNAME1, iNewRow).String = CellStockName
166cdf0e10cSrcweir			oFirstSheet.GetCellByPosition(SBCOLUMNID1, iNewRow).String = TransactModel.txtStockID.Text
167cdf0e10cSrcweir			iStockRow = GetStockRowIndex(CellStockName)
168cdf0e10cSrcweir		End If
169cdf0e10cSrcweir	&apos; Sell stocks: Get transaction value, then update Transaction sheet
170cdf0e10cSrcweir	ElseIf TransactModel.Step = SBDIALOGSELL Then
171cdf0e10cSrcweir		Profit = oMovementSheet.GetCellByPosition(SBCOLUMNPROCEEDS2, iNewRow).Value
172cdf0e10cSrcweir		Value = Profit
173cdf0e10cSrcweir		Sold = TransactModel.txtQuantity.Value
174cdf0e10cSrcweir		SelStockName = DlgTransaction.GetControl(&quot;lstSellStocks&quot;).GetSelectedItem()
175cdf0e10cSrcweir		&apos; Go to first name
176cdf0e10cSrcweir		If TransactMode = FIFO Then
177cdf0e10cSrcweir			iRow = SBROWFIRSTTRANSACT2
178cdf0e10cSrcweir		Else
179cdf0e10cSrcweir			iRow = iNewRow-1
180cdf0e10cSrcweir		End If
181cdf0e10cSrcweir
182cdf0e10cSrcweir		&apos; Check that no transaction after split date exists else cancel split
183cdf0e10cSrcweir		Do While Sold &gt; 0
184cdf0e10cSrcweir			oNameCell = oMovementSheet.GetCellByPosition(SBCOLUMNNAME2, iRow)
185cdf0e10cSrcweir			CellStockName = oNameCell.String
186cdf0e10cSrcweir			If CellStockName = SelStockName Then
187cdf0e10cSrcweir				&apos; Update transactions: Note quantity sold
188cdf0e10cSrcweir				RestQuantity = oMovementSheet.GetCellByPosition(SBCOLUMNQTYREST2, iRow).Value
189cdf0e10cSrcweir				&apos; If there still is a rest left ...
190cdf0e10cSrcweir				If RestQuantity &gt; 0 Then
191cdf0e10cSrcweir					If RestQuantity &lt; Sold Then
192cdf0e10cSrcweir						&apos; Recalculate profit of new transaction
193cdf0e10cSrcweir						Profit = Profit - oMovementSheet.GetCellByPosition(SBCOLUMNPRCREST2, iRow).Value
194cdf0e10cSrcweir						AddValueToCellContent(SBCOLUMNQTYSOLD2, iRow, RestQuantity)
195cdf0e10cSrcweir						PartialValue = RestQuantity / Sold * Value
196cdf0e10cSrcweir						AddValueToCellContent(SBCOLUMNREALPROC2, iRow, PartialValue)
197cdf0e10cSrcweir						Sold = Sold - RestQuantity
198cdf0e10cSrcweir						Value = Value - PartialValue
199cdf0e10cSrcweir					Else
200cdf0e10cSrcweir						&apos; Recalculate profit of neTransactModel.lstBuyStocks.Textw transaction
201cdf0e10cSrcweir						PartialValue = oMovementSheet.GetCellByPosition(SBCOLUMNPRCREST2, iRow).Value
202cdf0e10cSrcweir						Profit = Profit - PartialValue/RestQuantity * Sold
203cdf0e10cSrcweir						&apos; Update sold shares cell
204cdf0e10cSrcweir						AddValueToCellContent(SBCOLUMNQTYSOLD2, iRow, Sold)
205cdf0e10cSrcweir						&apos; Update sales turnover cell
206cdf0e10cSrcweir						AddValueToCellContent(SBCOLUMNREALPROC2, iRow, Value)
207cdf0e10cSrcweir						&apos; Update variables for rest of transaction
208cdf0e10cSrcweir						Sold = 0
209cdf0e10cSrcweir						Value = 0
210cdf0e10cSrcweir					End If
211cdf0e10cSrcweir				End If
212cdf0e10cSrcweir			End If
213cdf0e10cSrcweir			iRow = iRow + TransactMode
214cdf0e10cSrcweir		Loop
215cdf0e10cSrcweir		oMovementSheet.GetCellByPosition(SBCOLUMNREALPROFIT2,iNewRow).Value = Profit
216cdf0e10cSrcweir		iStockRow = GetStockRowIndex(SelStockName)
217cdf0e10cSrcweir		iRestQuantity = oFirstSheet.GetCellbyPosition(SBCOLUMNQUANTITY1, iStockRow).Value
218cdf0e10cSrcweir&apos;		If iRestQuantity = 0 Then
219cdf0e10cSrcweir&apos;			If oSheets.HasbyName(SelStockName) Then
220cdf0e10cSrcweir&apos;				oSheets.RemoveByName(SelStockName)
221cdf0e10cSrcweir&apos;			End If
222cdf0e10cSrcweir&apos;		Else
223cdf0e10cSrcweir
224cdf0e10cSrcweir&apos;		End If
225cdf0e10cSrcweir	End If
226cdf0e10cSrcweir	InsertCurrentValue(CurRate, iStockRow,TransactDate)
227cdf0e10cSrcweir	ProtectSheets(oSheets)
228cdf0e10cSrcweirEnd Sub
229cdf0e10cSrcweir
230cdf0e10cSrcweir
231cdf0e10cSrcweirSub SelectStockname(aEvent as Object)
232cdf0e10cSrcweirDim iCurRow as Integer
233cdf0e10cSrcweirDim CurStockName as String
234cdf0e10cSrcweir	With TransactModel
235cdf0e10cSrcweir		&apos; Find row with stock name
236cdf0e10cSrcweir		If TransactModel.Step = SBDIALOGBUY Then
237cdf0e10cSrcweir			CurStockName = .lstBuyStocks.Text
238cdf0e10cSrcweir			iCurRow = GetStockRowIndex(CurStockName)
239cdf0e10cSrcweir			.txtQuantity.ValueMax = 10000000
240cdf0e10cSrcweir		Else
241cdf0e10cSrcweir			Dim ListBoxList() as String
242cdf0e10cSrcweir			ListBoxList() = GetSelectedListboxItems(aEvent.Source.getModel())
243cdf0e10cSrcweir			CurStockName = ListBoxList(0)
244cdf0e10cSrcweir&apos;			CurStockName = DlgTransaction.GetControl(aEvent.Source.getModel.Name).GetSelectedItem()
245cdf0e10cSrcweir			iCurRow = GetStockRowIndex(CurStockName)
246cdf0e10cSrcweir			Dim fdouble as Double
247cdf0e10cSrcweir			fdouble = oFirstSheet.GetCellByPosition(SBCOLUMNQUANTITY1, iCurRow).Value
248cdf0e10cSrcweir			.txtQuantity.Value = fdouble
249cdf0e10cSrcweir			.txtQuantity.ValueMax = oFirstSheet.GetCellByPosition(SBCOLUMNQUANTITY1, iCurRow).Value
250cdf0e10cSrcweir			.txtRate.Value = oFirstSheet.GetCellbyPosition(SBCOLUMNRATE1, iCurRow).Value
251cdf0e10cSrcweir		End If
252cdf0e10cSrcweir		.txtStockID.Enabled = .Step = SBDIALOGBUY
253cdf0e10cSrcweir		.lblStockID.Enabled = .Step = SBDIALOGBUY
254cdf0e10cSrcweir		&apos; Default settings for quantity and rate
255cdf0e10cSrcweir		.txtStockID.Text = GetStockID(CurStockName, iCurRow)
256cdf0e10cSrcweir	End With
257cdf0e10cSrcweir	EnableTransactionControls(CurStockName &lt;&gt; &quot;&quot;)
258cdf0e10cSrcweir	TransactModel.cmdGoOn.DefaultButton = True
259cdf0e10cSrcweirEnd Sub
260cdf0e10cSrcweir
261cdf0e10cSrcweir
262cdf0e10cSrcweir
263cdf0e10cSrcweirSub HandleStocks(Mode as Integer, oDialog as Object)
264cdf0e10cSrcweirDim DividendPerShare, DividendTotal, RestQuantity, OldValue
265cdf0e10cSrcweirDim SelStockName, CellStockName as String
266cdf0e10cSrcweirDim oNameCell as Object, oDateCell as Object
267cdf0e10cSrcweirDim iRow as Integer
268cdf0e10cSrcweirDim oDividendCell as Object
269cdf0e10cSrcweirDim Amount
270cdf0e10cSrcweirDim OldNumber, NewNumber as Integer
271cdf0e10cSrcweirDim  NoteText as String
272cdf0e10cSrcweirDim TotalStocksCount as Long
273cdf0e10cSrcweirDim oModel as Object
274cdf0e10cSrcweir	oDocument.AddActionLock
275cdf0e10cSrcweir	oDialog.EndExecute()
276cdf0e10cSrcweir	oModel = oDialog.Model
277cdf0e10cSrcweir	SelStockName = DlgStockRates.GetControl(&quot;lstStockNames&quot;).GetSelectedItem()
278cdf0e10cSrcweir	Select Case Mode
279cdf0e10cSrcweir		Case HANDLEDIVIDEND
280cdf0e10cSrcweir			Dim bTakeTotal as Boolean
281cdf0e10cSrcweir			&apos; Update transactions: Enter dividend paid for all Buy transactions not sold completely
282cdf0e10cSrcweir			bTakeTotal = oModel.optTotal.State = 1
283cdf0e10cSrcweir			If bTakeTotal Then
284cdf0e10cSrcweir				DividendTotal = oModel.txtDividend.Value
285cdf0e10cSrcweir				iRow = GetStockRowIndex(SelStockName)
286cdf0e10cSrcweir				TotalStocksCount = oFirstSheet.GetCellByPosition(SBCOLUMNQUANTITY1,iRow).Value
287cdf0e10cSrcweir				DividendPerShare = DividendTotal/TotalStocksCount
288cdf0e10cSrcweir			Else
289cdf0e10cSrcweir				DividendPerShare = oModel.txtDividend.Value
290cdf0e10cSrcweir			End If
291cdf0e10cSrcweir
292cdf0e10cSrcweir		Case HANDLESPLIT
293cdf0e10cSrcweir			&apos; Store entered values in variables
294cdf0e10cSrcweir			OldNumber = oModel.txtOldRate.Value
295cdf0e10cSrcweir			NewNumber = oModel.txtNewRate.Value
296cdf0e10cSrcweir			SplitDate = CDateFromISO(oModel.txtDate.Date)
297cdf0e10cSrcweir			iRow = SBROWFIRSTTRANSACT2
298cdf0e10cSrcweir			NoteText = cSplit &amp; SplitDate &amp; &quot;, &quot; &amp; oModel.txtOldRate.Value &amp; oModel.lblColon.Label &amp; oModel.txtNewRate.Value
299cdf0e10cSrcweir			Do
300cdf0e10cSrcweir				oNameCell = oMovementSheet.GetCellByPosition(SBCOLUMNNAME2, iRow)
301cdf0e10cSrcweir				CellStockName = oNameCell.String
302cdf0e10cSrcweir				If CellStockName = SelStockName Then
303cdf0e10cSrcweir					oDateCell = oMovementSheet.GetCellByPosition(SBCOLUMNDATE2, iRow)
304cdf0e10cSrcweir					If oDateCell.Value &gt;= SplitDate Then
305cdf0e10cSrcweir						MsgBox sMsgWrongExchangeDate, SBMSGOK + SBMSGSTOP, sMsgError
306cdf0e10cSrcweir						Exit Sub
307cdf0e10cSrcweir					End If
308cdf0e10cSrcweir				End If
309cdf0e10cSrcweir				iRow = iRow + 1
310cdf0e10cSrcweir			Loop Until CellStockName = &quot;&quot;
311cdf0e10cSrcweir	End Select
312cdf0e10cSrcweir	iRow = SBROWFIRSTTRANSACT2
313cdf0e10cSrcweir	UnprotectSheets(oSheets)
314cdf0e10cSrcweir	Do
315cdf0e10cSrcweir		oNameCell = oMovementSheet.GetCellByPosition(SBCOLUMNNAME2, iRow)
316cdf0e10cSrcweir		CellStockName = oNameCell.String
317cdf0e10cSrcweir		If CellStockName = SelStockName Then
318cdf0e10cSrcweir			Select Case Mode
319cdf0e10cSrcweir				Case HANDLEDIVIDEND
320cdf0e10cSrcweir					RestQuantity = oMovementSheet.GetCellByPosition(SBCOLUMNQTYREST2, iRow).Value
321cdf0e10cSrcweir					If RestQuantity &gt; 0 Then
322cdf0e10cSrcweir						oDividendCell = oMovementSheet.GetCellByPosition(SBCOLUMNDIVIDEND2, iRow)
323cdf0e10cSrcweir						OldValue = oDividendCell.Value
324cdf0e10cSrcweir						oDividendCell.Value = OldValue + RestQuantity * DividendPerShare
325cdf0e10cSrcweir					End If
326cdf0e10cSrcweir				Case HANDLESPLIT
327cdf0e10cSrcweir					oDateCell = oMovementSheet.GetCellByPosition(SBCOLUMNDATE2, iRow)
328cdf0e10cSrcweir				 	SplitCellValue(oMovementSheet, NewNumber, OldNumber, SBCOLUMNQUANTITY2, iRow, NoteText)
329cdf0e10cSrcweir		 			SplitCellValue(oMovementSheet, OldNumber, NewNumber, SBCOLUMNRATE2, iRow, &quot;&quot;)
330cdf0e10cSrcweir				 	SplitCellValue(oMovementSheet, NewNumber, OldNumber, SBCOLUMNQTYSOLD2, iRow, &quot;&quot;)
331cdf0e10cSrcweir			End Select
332cdf0e10cSrcweir		End If
333cdf0e10cSrcweir		iRow = iRow + 1
334cdf0e10cSrcweir	Loop Until CellStockName = &quot;&quot;
335cdf0e10cSrcweir	If Mode = HANDLESPLIT Then
336cdf0e10cSrcweir	 	CalculateChartafterSplit(SelStockName, NewNumber, OldNumber, NoteText, SplitDate)
337cdf0e10cSrcweir	End If
338cdf0e10cSrcweir	oDocument.CalculateAll()
339cdf0e10cSrcweir	ProtectSheets(oSheets)
340cdf0e10cSrcweir	oDocument.RemoveActionLock
341cdf0e10cSrcweirEnd Sub
342cdf0e10cSrcweir
343cdf0e10cSrcweir
344cdf0e10cSrcweirSub CancelStockRate()
345cdf0e10cSrcweir	DlgStockRates.EndExecute()
346cdf0e10cSrcweirEnd Sub
347cdf0e10cSrcweir
348cdf0e10cSrcweir
349cdf0e10cSrcweirSub CancelTransaction()
350cdf0e10cSrcweir	DlgTransaction.EndExecute()
351cdf0e10cSrcweirEnd Sub
352cdf0e10cSrcweir
353cdf0e10cSrcweir
354cdf0e10cSrcweirSub CommitStockRate()
355cdf0e10cSrcweirDim CurStep as Integer
356cdf0e10cSrcweir	CurStep = StockRatesModel.Step
357cdf0e10cSrcweir	Select Case CurStep
358cdf0e10cSrcweir		Case 1
359cdf0e10cSrcweir			&apos; Check for quantity entered
360cdf0e10cSrcweir			If StockRatesModel.txtDividend.Value = 0 Then
361cdf0e10cSrcweir				MsgBox sMsgNoDividend, SBMSGSTOP+SBMSGSTOP, sMsgError
362cdf0e10cSrcweir				Exit Sub
363cdf0e10cSrcweir			End If
364cdf0e10cSrcweir			HandleStocks(HANDLEDIVIDEND, DlgStockRates)
365cdf0e10cSrcweir		Case 2
366cdf0e10cSrcweir			HandleStocks(HANDLESPLIT, DlgStockRates)
367cdf0e10cSrcweir		Case 3
368cdf0e10cSrcweir			InsertCompanyHistory()
369cdf0e10cSrcweir	End Select
370cdf0e10cSrcweirEnd Sub
371cdf0e10cSrcweir
372cdf0e10cSrcweir
373cdf0e10cSrcweirSub EnableTransactionControls(bEnable as Boolean)
374cdf0e10cSrcweir	With TransactModel
375cdf0e10cSrcweir		.lblQuantity.Enabled = bEnable
376cdf0e10cSrcweir		.txtQuantity.Enabled = bEnable
377cdf0e10cSrcweir		.lblRate.Enabled = bEnable
378cdf0e10cSrcweir		.txtRate.Enabled = bEnable
379cdf0e10cSrcweir		.lblDate.Enabled = bEnable
380cdf0e10cSrcweir		.txtDate.Enabled = bEnable
381cdf0e10cSrcweir		.lblCommission.Enabled = bEnable
382cdf0e10cSrcweir		.txtCommission.Enabled = bEnable
383cdf0e10cSrcweir		.lblMinimum.Enabled = bEnable
384cdf0e10cSrcweir		.txtMinimum.Enabled = bEnable
385cdf0e10cSrcweir		.lblFix.Enabled = bEnable
386cdf0e10cSrcweir		.txtFix.Enabled = bEnable
387cdf0e10cSrcweir		If TransactModel.Step = SBDIALOGSELL Then
388cdf0e10cSrcweir			.cmdGoOn.Enabled = Ubound(TransactModel.lstSellStocks.SelectedItems()) &gt; -1
389cdf0e10cSrcweir			DlgTransaction.GetControl(&quot;lstSellStocks&quot;).SetFocus()
390cdf0e10cSrcweir		Else
391cdf0e10cSrcweir			.cmdGoOn.Enabled = TransactModel.lstBuyStocks.Text &lt;&gt; &quot;&quot;
392cdf0e10cSrcweir			DlgTransaction.GetControl(&quot;lstBuyStocks&quot;).SetFocus()
393cdf0e10cSrcweir		End If
394cdf0e10cSrcweir		If bEnable Then
395cdf0e10cSrcweir			TransactModel.cmdGoOn.DefaultButton = True
396cdf0e10cSrcweir		End If
397cdf0e10cSrcweir	End With
398cdf0e10cSrcweirEnd Sub
399cdf0e10cSrcweir
400cdf0e10cSrcweir
401cdf0e10cSrcweirSub SetupTransactionControls(CurStep as Integer)
402cdf0e10cSrcweir	DlgReference = DlgTransaction
403cdf0e10cSrcweir	With TransactModel
404cdf0e10cSrcweir		.txtDate.Date = CDateToISO(Date())
405cdf0e10cSrcweir		.txtDate.DateMax = CDateToISO(Date())
406cdf0e10cSrcweir		.txtStockID.Enabled = False
407cdf0e10cSrcweir		.lblStockID.Enabled = False
408cdf0e10cSrcweir		.lblStockID.Label = sCurStockIDLabel
409cdf0e10cSrcweir		.txtRate.CurrencySymbol = sCurCurrency
410cdf0e10cSrcweir		.txtFix.CurrencySymbol = sCurCurrency
411cdf0e10cSrcweir		.Step = CurStep
412cdf0e10cSrcweir	End With
413cdf0e10cSrcweir	DlgTransaction.Title = TransactTitle(CurStep)
414cdf0e10cSrcweir	CellValuetoControl(oBankSheet, TransactModel.txtCommission, &quot;ProvisionPercent&quot;)
415cdf0e10cSrcweir	CellValuetoControl(oBankSheet, TransactModel.txtMinimum, &quot;ProvisionMinimum&quot;)
416cdf0e10cSrcweir	CellValuetoControl(oBankSheet, TransactModel.txtFix, &quot;ProvisionFix&quot;)
417cdf0e10cSrcweirEnd Sub
418cdf0e10cSrcweir
419cdf0e10cSrcweir
420cdf0e10cSrcweirSub AddShortCuttoControl()
421cdf0e10cSrcweirDim SelCompany as String
422cdf0e10cSrcweirDim iRow, SelIndex as Integer
423cdf0e10cSrcweir	SelIndex = DlgTransaction.GetControl(&quot;lstBuyStocks&quot;).GetSelectedItemPos()
424cdf0e10cSrcweir	If SelIndex &lt;&gt; -1 Then
425cdf0e10cSrcweir		SelCompany = TransactModel.lstBuyStocks.StringItemList(SelIndex)
426cdf0e10cSrcweir		iRow = GetStockRowIndex(SelCompany)
427cdf0e10cSrcweir		If iRow &lt;&gt; -1 Then
428cdf0e10cSrcweir			TransactModel.txtStockID.Text = oFirstSheet.GetCellByPosition(SBCOLUMNID1,iRow).String
429cdf0e10cSrcweir			TransactModel.txtRate.Value = oFirstSheet.GetCellByPosition(SBCOLUMNRATE1,iRow).Value
430cdf0e10cSrcweir		Else
431cdf0e10cSrcweir			TransactModel.txtStockID.Text = &quot;&quot;
432cdf0e10cSrcweir			TransactModel.txtRate.Value = 0
433cdf0e10cSrcweir		End If
434cdf0e10cSrcweir	Else
435cdf0e10cSrcweir		TransactModel.txtStockID.Text = &quot;&quot;
436cdf0e10cSrcweir		TransactModel.txtRate.Value = 0
437cdf0e10cSrcweir	End If
438cdf0e10cSrcweirEnd Sub
439cdf0e10cSrcweir
440cdf0e10cSrcweir
441cdf0e10cSrcweirSub OpenStockRatePage(aEvent)
442cdf0e10cSrcweirDim CurStep as Integer
443cdf0e10cSrcweir	Initialize(True)
444cdf0e10cSrcweir	CurStep = aEvent.Source.Model.Tag
445cdf0e10cSrcweir	If FillListbox(DlgStockRates.GetControl(&quot;lstStockNames&quot;), StockRatesTitle(CurStep), True) Then
446cdf0e10cSrcweir		StockRatesModel.Step = CurStep
447cdf0e10cSrcweir		ToggleStockRateControls(False, CurStep)
448cdf0e10cSrcweir		InitializeStockRatesControls(CurStep)
449cdf0e10cSrcweir		DlgStockRates.Execute()
450cdf0e10cSrcweir	End If
451cdf0e10cSrcweirEnd Sub
452cdf0e10cSrcweir
453cdf0e10cSrcweir
454cdf0e10cSrcweirSub SelectStockNameForRates()
455cdf0e10cSrcweirDim StockName as String
456cdf0e10cSrcweir	StockName = DlgStockRates.GetControl(&quot;lstStockNames&quot;).GetSelectedItem()
457cdf0e10cSrcweir	If StockName &lt;&gt; &quot;&quot; Then
458cdf0e10cSrcweir		StockRatesModel.txtStockID.Text = GetStockID(StockName)
459cdf0e10cSrcweir		ToggleStockRateControls(True, StockRatesModel.Step)
460cdf0e10cSrcweir	End If
461cdf0e10cSrcweir	StockRatesModel.cmdGoOn.DefaultButton = True
462cdf0e10cSrcweirEnd Sub
463cdf0e10cSrcweir
464cdf0e10cSrcweir
465cdf0e10cSrcweirSub ToggleStockRateControls(bDoEnable as Boolean, CurStep as Integer)
466cdf0e10cSrcweir	With StockRatesModel
467cdf0e10cSrcweir		.lblStockID.Enabled = False
468cdf0e10cSrcweir		.txtStockID.Enabled = False
469cdf0e10cSrcweir		.cmdGoOn.Enabled = Ubound(StockRatesModel.lstStockNames.SelectedItems()) &lt;&gt; -1
470cdf0e10cSrcweir		Select Case CurStep
471cdf0e10cSrcweir			Case 1
472cdf0e10cSrcweir				.optPerShare.Enabled = bDoEnable
473cdf0e10cSrcweir				.optTotal.Enabled = bDoEnable
474cdf0e10cSrcweir				.lblDividend.Enabled = bDoEnable
475cdf0e10cSrcweir				.txtDividend.Enabled = bDoEnable
476cdf0e10cSrcweir			Case 2
477cdf0e10cSrcweir				.lblExchangeRate.Enabled = bDoEnable
478cdf0e10cSrcweir				.lblDate.Enabled = bDoEnable
479cdf0e10cSrcweir				.lblColon.Enabled = bDoEnable
480cdf0e10cSrcweir				.txtOldRate.Enabled = bDoEnable
481cdf0e10cSrcweir				.txtNewRate.Enabled = bDoEnable
482cdf0e10cSrcweir				.txtDate.Enabled = bDoEnable
483cdf0e10cSrcweir			Case 3
484cdf0e10cSrcweir				.lblStartDate.Enabled = bDoEnable
485cdf0e10cSrcweir				.lblEndDate.Enabled = bDoEnable
486cdf0e10cSrcweir				.txtStartDate.Enabled = bDoEnable
487cdf0e10cSrcweir				.txtEndDate.Enabled = bDoEnable
488cdf0e10cSrcweir				.hlnInterval.Enabled = bDoEnable
489cdf0e10cSrcweir				.optDaily.Enabled = bDoEnable
490cdf0e10cSrcweir				.optWeekly.Enabled = bDoEnable
491cdf0e10cSrcweir		End Select
492cdf0e10cSrcweir	End With
493cdf0e10cSrcweirEnd Sub
494cdf0e10cSrcweir
495cdf0e10cSrcweir
496cdf0e10cSrcweirSub InitializeStockRatesControls(CurStep as Integer)
497cdf0e10cSrcweir	DlgReference = DlgStockRates
498cdf0e10cSrcweir	DlgStockRates.Title = StockRatesTitle(CurStep)
499cdf0e10cSrcweir	With StockRatesModel
500cdf0e10cSrcweir		.txtStockID.Text = &quot;&quot;
501cdf0e10cSrcweir		.lblStockID.Label = sCurStockIDLabel
502cdf0e10cSrcweir		Select Case CurStep
503cdf0e10cSrcweir			Case 1
504cdf0e10cSrcweir				.txtDividend.Value = 0
505cdf0e10cSrcweir				.optPerShare.State = 1
506cdf0e10cSrcweir				.txtDividend.CurrencySymbol = sCurCurrency
507cdf0e10cSrcweir			Case 2
508cdf0e10cSrcweir				.txtOldRate.Value = 1
509cdf0e10cSrcweir				.txtNewRate.Value = 1
510cdf0e10cSrcweir				.txtDate.Date = CDateToISO(Date())
511cdf0e10cSrcweir			Case 3
512cdf0e10cSrcweir				.txtStartDate.DateMax = CDateToISO(CDate(Date())-1)
513cdf0e10cSrcweir				.txtEndDate.DateMax = CDateToISO(CDate(Date())-1)
514cdf0e10cSrcweir				.txtStartDate.Date = CDateToISO(CDate(Date())-8)
515cdf0e10cSrcweir				.txtEndDate.Date = CDateToISO(CDate(Date())-1)
516cdf0e10cSrcweir				.optDaily.State = 1
517cdf0e10cSrcweir		End Select
518cdf0e10cSrcweir	End With
519cdf0e10cSrcweirEnd Sub
520*3e02b54dSAndrew Rist</script:module>
521