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