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