mirror of
				https://github.com/RolandWH/SIPPCompare.git
				synced 2025-11-03 19:42:12 +00:00 
			
		
		
		
	implement deleting platforms and csv saving
This commit is contained in:
		@@ -218,7 +218,7 @@
 | 
				
			|||||||
       </font>
 | 
					       </font>
 | 
				
			||||||
      </property>
 | 
					      </property>
 | 
				
			||||||
      <property name="text">
 | 
					      <property name="text">
 | 
				
			||||||
       <string>Fund dealing fee*</string>
 | 
					       <string>Fund dealing fee</string>
 | 
				
			||||||
      </property>
 | 
					      </property>
 | 
				
			||||||
     </widget>
 | 
					     </widget>
 | 
				
			||||||
    </item>
 | 
					    </item>
 | 
				
			||||||
@@ -342,7 +342,7 @@
 | 
				
			|||||||
   <property name="geometry">
 | 
					   <property name="geometry">
 | 
				
			||||||
    <rect>
 | 
					    <rect>
 | 
				
			||||||
     <x>8</x>
 | 
					     <x>8</x>
 | 
				
			||||||
     <y>262</y>
 | 
					     <y>540</y>
 | 
				
			||||||
     <width>191</width>
 | 
					     <width>191</width>
 | 
				
			||||||
     <height>21</height>
 | 
					     <height>21</height>
 | 
				
			||||||
    </rect>
 | 
					    </rect>
 | 
				
			||||||
@@ -508,6 +508,24 @@
 | 
				
			|||||||
    <string>on the value above £ there is no charge</string>
 | 
					    <string>on the value above £ there is no charge</string>
 | 
				
			||||||
   </property>
 | 
					   </property>
 | 
				
			||||||
  </widget>
 | 
					  </widget>
 | 
				
			||||||
 | 
					  <widget class="QLabel" name="label">
 | 
				
			||||||
 | 
					   <property name="geometry">
 | 
				
			||||||
 | 
					    <rect>
 | 
				
			||||||
 | 
					     <x>10</x>
 | 
				
			||||||
 | 
					     <y>284</y>
 | 
				
			||||||
 | 
					     <width>151</width>
 | 
				
			||||||
 | 
					     <height>16</height>
 | 
				
			||||||
 | 
					    </rect>
 | 
				
			||||||
 | 
					   </property>
 | 
				
			||||||
 | 
					   <property name="font">
 | 
				
			||||||
 | 
					    <font>
 | 
				
			||||||
 | 
					     <pointsize>11</pointsize>
 | 
				
			||||||
 | 
					    </font>
 | 
				
			||||||
 | 
					   </property>
 | 
				
			||||||
 | 
					   <property name="text">
 | 
				
			||||||
 | 
					    <string>Fund platform fee*</string>
 | 
				
			||||||
 | 
					   </property>
 | 
				
			||||||
 | 
					  </widget>
 | 
				
			||||||
 </widget>
 | 
					 </widget>
 | 
				
			||||||
 <customwidgets>
 | 
					 <customwidgets>
 | 
				
			||||||
  <customwidget>
 | 
					  <customwidget>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -246,3 +246,20 @@ class DBHandler:
 | 
				
			|||||||
        state_data = [state, index]
 | 
					        state_data = [state, index]
 | 
				
			||||||
        self.cur.execute("UPDATE tblPlatforms SET IsEnabled = ? WHERE PlatformID = ?", state_data)
 | 
					        self.cur.execute("UPDATE tblPlatforms SET IsEnabled = ? WHERE PlatformID = ?", state_data)
 | 
				
			||||||
        self.conn.commit()
 | 
					        self.conn.commit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def remove_platform(self, index: int):
 | 
				
			||||||
 | 
					        tbl_list = ["tblPlatforms", "tblFlatPlatFees", "tblFlatDealFees", "tblFundPlatFee"]
 | 
				
			||||||
 | 
					        for tbl in tbl_list:
 | 
				
			||||||
 | 
					            self.cur.execute(f"DELETE FROM {tbl} WHERE PlatformID = {index}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        res = self.cur.execute("SELECT PlatformID from tblPlatforms").fetchall()
 | 
				
			||||||
 | 
					        n = len(res)
 | 
				
			||||||
 | 
					        for i in range(n):
 | 
				
			||||||
 | 
					            for tbl in tbl_list:
 | 
				
			||||||
 | 
					                self.cur.execute(f"""
 | 
				
			||||||
 | 
					                    UPDATE {tbl} 
 | 
				
			||||||
 | 
					                    SET PlatformID = {index + i} 
 | 
				
			||||||
 | 
					                    WHERE PlatformID = {index + 1 + i}
 | 
				
			||||||
 | 
					                """)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.conn.commit()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ class OutputWindow(QWidget):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # Handle events
 | 
					        # Handle events
 | 
				
			||||||
        self.save_graph_but.clicked.connect(self.save_graph)
 | 
					        self.save_graph_but.clicked.connect(self.save_graph)
 | 
				
			||||||
 | 
					        self.save_csv_but.clicked.connect(self.save_csv)
 | 
				
			||||||
        self.time_slider.valueChanged.connect(self.change_time)
 | 
					        self.time_slider.valueChanged.connect(self.change_time)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def display_output(self, results: list, years: int):
 | 
					    def display_output(self, results: list, years: int):
 | 
				
			||||||
@@ -43,14 +44,68 @@ class OutputWindow(QWidget):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def save_graph(self):
 | 
					    def save_graph(self):
 | 
				
			||||||
        file_picker = QFileDialog(self)
 | 
					        file_picker = QFileDialog(self)
 | 
				
			||||||
        file_picker.setFileMode(QFileDialog.FileMode.Directory)
 | 
					        file_picker.setFileMode(QFileDialog.FileMode.AnyFile)
 | 
				
			||||||
        folder_path = ""
 | 
					        file_picker.setDefaultSuffix("png")
 | 
				
			||||||
        if file_picker.exec():
 | 
					        file_picker.setWindowTitle("Save results as PNG")
 | 
				
			||||||
            folder_path = file_picker.selectedFiles()[0]
 | 
					        file_picker.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
 | 
				
			||||||
 | 
					        file_picker.setNameFilter("*.png")
 | 
				
			||||||
 | 
					        file_path = ""
 | 
				
			||||||
        cur_time = datetime.now()
 | 
					        cur_time = datetime.now()
 | 
				
			||||||
        filename_str = f"{folder_path}/SIPPCompare-{cur_time.year}.{cur_time.month}.{cur_time.day}.png"
 | 
					        filename_str = f"{file_path}/SIPPCompare-{cur_time.year}.{cur_time.month}.{cur_time.day}.png"
 | 
				
			||||||
        self.fig.savefig(filename_str, dpi=150)
 | 
					        file_picker.selectFile(filename_str)
 | 
				
			||||||
 | 
					        if file_picker.exec():
 | 
				
			||||||
 | 
					            file_path = file_picker.selectedFiles()[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            self.fig.savefig(file_path, dpi=150)
 | 
				
			||||||
 | 
					        except:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def save_csv(self):
 | 
				
			||||||
 | 
					        file_picker = QFileDialog(self)
 | 
				
			||||||
 | 
					        file_picker.setFileMode(QFileDialog.FileMode.AnyFile)
 | 
				
			||||||
 | 
					        file_picker.setDefaultSuffix("csv")
 | 
				
			||||||
 | 
					        file_picker.setWindowTitle("Save results as CSV")
 | 
				
			||||||
 | 
					        file_picker.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
 | 
				
			||||||
 | 
					        file_picker.setNameFilter("*.csv")
 | 
				
			||||||
 | 
					        file_path = ""
 | 
				
			||||||
 | 
					        cur_time = datetime.now()
 | 
				
			||||||
 | 
					        filename_str = f"{file_path}/SIPPCompare-{cur_time.year}.{cur_time.month}.{cur_time.day}.csv"
 | 
				
			||||||
 | 
					        file_picker.selectFile(filename_str)
 | 
				
			||||||
 | 
					        if file_picker.exec():
 | 
				
			||||||
 | 
					            file_path = file_picker.selectedFiles()[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            csvfile = open(file_path, "wt")
 | 
				
			||||||
 | 
					            csv_string = (
 | 
				
			||||||
 | 
					                "Platform Name,Fund Platform Fee,Share Platform Fee,Fund Dealing Fee,"
 | 
				
			||||||
 | 
					                "Share Dealing Fee,Total Platform Fees,Total Dealing Fees,Total Fund Fees,"
 | 
				
			||||||
 | 
					                "Total Share Fees,Total Fees"
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for result in self.results:
 | 
				
			||||||
 | 
					                csv_string += '\n'
 | 
				
			||||||
 | 
					                pn = result[4]
 | 
				
			||||||
 | 
					                fpf = result[0]
 | 
				
			||||||
 | 
					                spf = result[2]
 | 
				
			||||||
 | 
					                fdf = result[1]
 | 
				
			||||||
 | 
					                sdf = result[3]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                tpf = fpf + spf
 | 
				
			||||||
 | 
					                tdf = sdf + fdf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                tff = fpf + fdf
 | 
				
			||||||
 | 
					                tsf = spf + sdf
 | 
				
			||||||
 | 
					                tf = tff + tsf
 | 
				
			||||||
 | 
					                csv_string += (
 | 
				
			||||||
 | 
					                    f"{pn},\"£{fpf:,.2f}\",\"£{spf:,.2f}\",\"£{fdf:,.2f}\",\"£{sdf:,.2f}\","
 | 
				
			||||||
 | 
					                    f"\"£{tpf:,.2f}\",\"£{tdf:,.2f}\",\"£{tff:,.2f}\",\"£{tsf:,.2f}\",\"£{tf:,.2f}\""
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            csvfile.write(csv_string)
 | 
				
			||||||
 | 
					            csvfile.close()
 | 
				
			||||||
 | 
					        except OSError:
 | 
				
			||||||
 | 
					            print("ERROR FILE SAVE FAILED")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def change_time(self):
 | 
					    def change_time(self):
 | 
				
			||||||
        years: int = self.time_slider.value()
 | 
					        years: int = self.time_slider.value()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,7 +65,7 @@ class PlatformEdit(QWidget):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if self.plat.fund_deal_fee is None:
 | 
					        if self.plat.fund_deal_fee is None:
 | 
				
			||||||
            self.check_boxes_ticked[1] = False
 | 
					            self.check_boxes_ticked[1] = False
 | 
				
			||||||
            self.plat_fund_deal_fee_check.setChecked(False)
 | 
					            self.fund_deal_fee_check.setChecked(False)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.check_boxes_ticked[1] = True
 | 
					            self.check_boxes_ticked[1] = True
 | 
				
			||||||
            self.fund_deal_fee_check.setChecked(True)
 | 
					            self.fund_deal_fee_check.setChecked(True)
 | 
				
			||||||
@@ -317,8 +317,6 @@ class PlatformEdit(QWidget):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            prev_box_row = cur_box_pos[0] - 1
 | 
					            prev_box_row = cur_box_pos[0] - 1
 | 
				
			||||||
            prev_box_item = self.gridLayout_2.itemAtPosition(prev_box_row, cur_box_pos[1]).widget()
 | 
					            prev_box_item = self.gridLayout_2.itemAtPosition(prev_box_row, cur_box_pos[1]).widget()
 | 
				
			||||||
            #if loading:
 | 
					 | 
				
			||||||
            #    prev_box_item.setValue(self.plat.fund_plat_fee[0][x+1])
 | 
					 | 
				
			||||||
            cur_label_item = self.gridLayout_2.itemAtPosition(cur_label_pos[0], cur_label_pos[1]).widget()
 | 
					            cur_label_item = self.gridLayout_2.itemAtPosition(cur_label_pos[0], cur_label_pos[1]).widget()
 | 
				
			||||||
            cur_label_item.setText(f"between £{int(prev_box_item.value())} and")
 | 
					            cur_label_item.setText(f"between £{int(prev_box_item.value())} and")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
from PyQt6 import uic
 | 
					from PyQt6 import uic
 | 
				
			||||||
from PyQt6.QtCore import QRegularExpression
 | 
					from PyQt6.QtCore import QRegularExpression
 | 
				
			||||||
from PyQt6.QtGui import QIcon, QRegularExpressionValidator
 | 
					from PyQt6.QtGui import QIcon, QRegularExpressionValidator, QFont
 | 
				
			||||||
from PyQt6.QtWidgets import QWidget, QListWidgetItem, QDialog
 | 
					from PyQt6.QtWidgets import QWidget, QListWidgetItem, QDialog, QDialogButtonBox, QMessageBox
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import resource_finder
 | 
					import resource_finder
 | 
				
			||||||
from db_handler import DBHandler
 | 
					from db_handler import DBHandler
 | 
				
			||||||
@@ -34,6 +34,25 @@ class PlatformRename(QDialog):
 | 
				
			|||||||
        event.ignore()
 | 
					        event.ignore()
 | 
				
			||||||
        self.reject()
 | 
					        self.reject()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RemoveConfirm(QMessageBox):
 | 
				
			||||||
 | 
					    def __init__(self, parent=None):
 | 
				
			||||||
 | 
					        super().__init__(parent)
 | 
				
			||||||
 | 
					        self.setWindowIcon(QIcon(resource_finder.get_res_path("icon2.ico")))
 | 
				
			||||||
 | 
					        self.setWindowTitle("Remove platform?")
 | 
				
			||||||
 | 
					        self.setIcon(QMessageBox.Icon.Warning)
 | 
				
			||||||
 | 
					        font = QFont()
 | 
				
			||||||
 | 
					        font.setPointSize(11)
 | 
				
			||||||
 | 
					        self.setFont(font)
 | 
				
			||||||
 | 
					        self.setText("Are you sure you want to remove this platform?")
 | 
				
			||||||
 | 
					        self.setInformativeText("This action is immediate and permanent")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel)
 | 
				
			||||||
 | 
					        self.setDefaultButton(QMessageBox.StandardButton.Cancel)
 | 
				
			||||||
 | 
					        font.setPointSize(10)
 | 
				
			||||||
 | 
					        self.findChild(QDialogButtonBox).setFont(font)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PlatformList(QWidget):
 | 
					class PlatformList(QWidget):
 | 
				
			||||||
    def __init__(self, db: DBHandler):
 | 
					    def __init__(self, db: DBHandler):
 | 
				
			||||||
        super().__init__()
 | 
					        super().__init__()
 | 
				
			||||||
@@ -44,20 +63,12 @@ class PlatformList(QWidget):
 | 
				
			|||||||
        self.db = db
 | 
					        self.db = db
 | 
				
			||||||
        self.plat_edit_win = None
 | 
					        self.plat_edit_win = None
 | 
				
			||||||
        self.plat_list_dialog = PlatformRename()
 | 
					        self.plat_list_dialog = PlatformRename()
 | 
				
			||||||
 | 
					        self.del_plat_dialog = RemoveConfirm()
 | 
				
			||||||
        self.plat_list = []
 | 
					        self.plat_list = []
 | 
				
			||||||
        self.plat_name_list = []
 | 
					        self.plat_name_list = []
 | 
				
			||||||
        self.new_plat_name = ""
 | 
					        self.new_plat_name = ""
 | 
				
			||||||
        self.update_plat_list()
 | 
					        self.update_plat_list()
 | 
				
			||||||
 | 
					        self.db_indices = [x for x in range(len(self.plat_name_list))]
 | 
				
			||||||
        for i in range(len(self.plat_name_list)):
 | 
					 | 
				
			||||||
            plat_name = self.plat_name_list[i]
 | 
					 | 
				
			||||||
            item = QListWidgetItem()
 | 
					 | 
				
			||||||
            if plat_name is not None:
 | 
					 | 
				
			||||||
                item.setText(plat_name)
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                item.setText(f"Unnamed [ID: {i}]")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            self.platListWidget.addItem(item)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Handle events
 | 
					        # Handle events
 | 
				
			||||||
        self.add_plat_but.clicked.connect(self.add_platform)
 | 
					        self.add_plat_but.clicked.connect(self.add_platform)
 | 
				
			||||||
@@ -70,6 +81,17 @@ class PlatformList(QWidget):
 | 
				
			|||||||
    def update_plat_list(self):
 | 
					    def update_plat_list(self):
 | 
				
			||||||
        self.plat_name_list = self.db.retrieve_plat_list()
 | 
					        self.plat_name_list = self.db.retrieve_plat_list()
 | 
				
			||||||
        self.plat_list = self.db.retrieve_platforms()
 | 
					        self.plat_list = self.db.retrieve_platforms()
 | 
				
			||||||
 | 
					        self.platListWidget.clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for i in range(len(self.plat_name_list)):
 | 
				
			||||||
 | 
					            plat_name = self.plat_name_list[i]
 | 
				
			||||||
 | 
					            item = QListWidgetItem()
 | 
				
			||||||
 | 
					            if plat_name is not None:
 | 
				
			||||||
 | 
					                item.setText(plat_name)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                item.setText(f"Unnamed [ID: {i}]")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            self.platListWidget.addItem(item)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def add_platform(self):
 | 
					    def add_platform(self):
 | 
				
			||||||
        name_dialog_res = self.plat_list_dialog.exec()
 | 
					        name_dialog_res = self.plat_list_dialog.exec()
 | 
				
			||||||
@@ -97,6 +119,11 @@ class PlatformList(QWidget):
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.plat_enabled_check.setChecked(False)
 | 
					            self.plat_enabled_check.setChecked(False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if index in self.db_indices:
 | 
				
			||||||
 | 
					            self.del_plat_but.setEnabled(True)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            self.del_plat_but.setEnabled(False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def edit_platform(self):
 | 
					    def edit_platform(self):
 | 
				
			||||||
        index = self.platListWidget.currentRow()
 | 
					        index = self.platListWidget.currentRow()
 | 
				
			||||||
        self.plat_edit_win = PlatformEdit(self.plat_list[index])
 | 
					        self.plat_edit_win = PlatformEdit(self.plat_list[index])
 | 
				
			||||||
@@ -104,6 +131,8 @@ class PlatformList(QWidget):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def save_platforms(self):
 | 
					    def save_platforms(self):
 | 
				
			||||||
        self.db.write_platforms(self.plat_list)
 | 
					        self.db.write_platforms(self.plat_list)
 | 
				
			||||||
 | 
					        self.update_plat_list()
 | 
				
			||||||
 | 
					        self.db_indices = [x for x in range(len(self.plat_name_list))]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def toggle_platform_state(self):
 | 
					    def toggle_platform_state(self):
 | 
				
			||||||
        index = self.platListWidget.currentRow()
 | 
					        index = self.platListWidget.currentRow()
 | 
				
			||||||
@@ -111,4 +140,8 @@ class PlatformList(QWidget):
 | 
				
			|||||||
        self.db.toggle_platform_state(index, state)
 | 
					        self.db.toggle_platform_state(index, state)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def remove_platform(self):
 | 
					    def remove_platform(self):
 | 
				
			||||||
        return None
 | 
					        index = self.platListWidget.currentRow()
 | 
				
			||||||
 | 
					        del_dialog_res = self.del_plat_dialog.exec()
 | 
				
			||||||
 | 
					        if del_dialog_res == QMessageBox.StandardButton.Yes:
 | 
				
			||||||
 | 
					            self.db.remove_platform(index)
 | 
				
			||||||
 | 
					            self.update_plat_list()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user