# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
import tambahPesananWindow, windowubahPesanan
import pandas as pd


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(961, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        # Tombol Tambah Pesanan
        self.button_tambahPesanan = QtWidgets.QPushButton(self.centralwidget)
        self.button_tambahPesanan.setGeometry(QtCore.QRect(110, 40, 191, 23))
        self.button_tambahPesanan.setStyleSheet("background-color: rgb(170, 170, 255);\n"
"font: 12pt \"MS Shell Dlg 2\";\n"
"background-color: rgb(229, 251, 255);")
        self.button_tambahPesanan.setObjectName("button_tambahPesanan")
        self.button_tambahPesanan.clicked.connect(self.tambahPesanan_clicked)
        
        # Tombol Ubah Pesanan
        self.button_ubahPesanan = QtWidgets.QPushButton(self.centralwidget)
        self.button_ubahPesanan.setGeometry(QtCore.QRect(380, 40, 191, 23))
        self.button_ubahPesanan.setStyleSheet("background-color: rgb(170, 170, 255);\n"
"font: 12pt \"MS Shell Dlg 2\";\n"
"background-color: rgb(229, 251, 255);")
        self.button_ubahPesanan.setObjectName("button_ubahPesanan")
        self.button_ubahPesanan.clicked.connect(self.ubahPesanan_clicked)

        # Tombol Rekapitulasi Penjualan
        self.button_rekapitulasiPenjualan = QtWidgets.QPushButton(self.centralwidget)
        self.button_rekapitulasiPenjualan.setGeometry(QtCore.QRect(620, 40, 191, 23))
        self.button_rekapitulasiPenjualan.setStyleSheet("background-color: rgb(170, 170, 255);\n"
"font: 12pt \"MS Shell Dlg 2\";\n"
"background-color: rgb(229, 251, 255);")
        self.button_rekapitulasiPenjualan.setObjectName("button_rekapitulasiPenjualan")
        # self.button_rekapitulasiPenjualan.clicked.connect(self.rekapPenjualan_clicked)
        
        # Tabel Pesanan
        self.tabelPesanan = QtWidgets.QTableWidget(self.centralwidget)
        self.tabelPesanan.setGeometry(QtCore.QRect(50, 100, 861, 381))
        self.tabelPesanan.setObjectName("tabelPesanan")

        # baca dan masukin csv di tabel
        self.load_data()

        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def load_data(self):
        # Baca CSV
        self.all_data = pd.read_csv('pesanan.csv')

        # Tulis data di tabel
        self.tabelPesanan.setColumnCount(len(self.all_data.columns))
        self.tabelPesanan.setRowCount(len(self.all_data.index))
        self.tabelPesanan.setHorizontalHeaderLabels(self.all_data.columns)

        for i in range(len(self.all_data.index)):
            for j in range(len(self.all_data.columns)):
                self.tabelPesanan.setItem(i, j, QtWidgets.QTableWidgetItem(str(self.all_data.iat[i, j])))

        self.tabelPesanan.resizeColumnsToContents()
        self.tabelPesanan.resizeRowsToContents()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.button_rekapitulasiPenjualan.setText(_translate("MainWindow", "Rekapitulasi Penjualan"))
        self.button_ubahPesanan.setText(_translate("MainWindow", "Ubah Pesanan"))
        self.button_tambahPesanan.setText(_translate("MainWindow", "+ Tambah Pesanan"))
        
    def tambahPesanan_clicked(self):
        self.tambahpesananwindow = QtWidgets.QMainWindow()
        self.ui = tambahPesananWindow.tambahPesananUI()
        self.ui.setupUi(self.tambahpesananwindow)
        self.tambahpesananwindow.show()
        self.ui.submitPesanan.clicked.connect(self.load_data)
        
    def ubahPesanan_clicked(self):
        self.ubahpesananwindow = QtWidgets.QMainWindow()
        self.ui = windowubahPesanan.Ui_MainWindow()
        self.ui.setupUi(self.ubahpesananwindow)
        self.ubahpesananwindow.show()
        self.ui.ubah.clicked.connect(self.load_data)

    '''def rekapPenjualan_clicked(self):
        self.rekappenjualannwindow = QtWidgets.QMainWindow()
        self.ui = rpl.Ui_MainWindow()
        self.ui.setupUi(self.rekappenjualanwindow)
        self.rekappenjualannwindow.show()'''


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
