~soker/betcon/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import sys, os, inspect
from PyQt5.QtWidgets import QMessageBox, QWidget
from PyQt5 import uic
directory = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
sys.path.append(directory + "/lib")
from bbdd import Bbdd
from banks import Banks
from datetime import datetime
from PyQt5.QtCore import QDate
from gettext import gettext as _
import gettext
from libyaml import LibYaml

class NewBank(QWidget):
	def __init__(self, mainWindows):
		QWidget.__init__(self)
		uic.loadUi(directory + "/../ui/new_bank.ui", self)
		gettext.textdomain("betcon")
		gettext.bindtextdomain("betcon", "../lang/mo")
		gettext.bindtextdomain("betcon", "/usr/share/locale")
		self.mainWindows = mainWindows
		self.btnAccept.clicked.connect(self.accept)
		self.btnCancel.clicked.connect(self.cancel)
		self.mainWindows.setWindowTitle(_("New Movement") + " | Betcon v" + mainWindows.version)

		self.coin = LibYaml().interface["coin"]
		self.initData()
		self.translate()

	def translate(self):

		self.lblDate.setText(_("Date"))
		self.lblBookie.setText(_("Bookie"))
		self.lblType.setText(_("Type"))
		self.lblAccount.setText(_("Account"))
		self.lblAmount.setText(_("Amount"))

		self.cmbAccount.addItems([_("Bank"), "Paypal", "Skrill"])
		self.cmbType.addItems([_("Deposit")  + "(" + self.coin + ")", _("Withdraw") + "(" + self.coin + ")"])

		self.btnCancel.setText(_("Cancel"))
		self.btnAccept.setText(_("Accept"))

	def initData(self):
		sDate = datetime.now().strftime('%Y-%m-%d')
		dDate = QDate.fromString(sDate, "yyyy-MM-dd")
		self.txtDate.setDate(dDate)

		# cmbBookie
		bd = Bbdd()
		data = bd.select("bookie", "name")

		self.bookieIndexToId = {}
		index = 0
		for i in data:
			id = i[0]
			name = i[1]
			self.cmbBookie.addItem(name)
			self.bookieIndexToId[index] = id
			index += 1

		bd.close()

	def close(self):
		self.mainWindows.setCentralWidget(Banks(self.mainWindows))

	def cancel(self):
		self.close()

	def accept(self):
		data = []

		data.append(self.txtDate.text())
		data.append(self.cmbAccount.currentIndex()+1)
		idBookie = self.bookieIndexToId.get(self.cmbBookie.currentIndex())
		data.append(idBookie)
		if self.cmbType.currentIndex() == 1:
			type = "-"
		else:
			type = ""

		money = type+str(self.txtMoney.text())
		data.append(money)

		columns = ["date", "account", "bookie", "money"]

		bbdd = Bbdd()
		bbdd.insert(columns, data, "movement")

		money *= -1
		data = ["'+bank+'" + str(money)]
		columns = ["bank"]

		account = self.cmbAccount.currentIndex()
		bbdd.update(columns, data, "bank", "id="+str(account + 1))
		bbdd.close()

		QMessageBox.information(self, _("Added"), _("Added movement."))
		self.close()