Commit 2ea882fc authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 88004fa2
......@@ -7,15 +7,15 @@ const dbAddress = process.env.DEBUG === 'true' ? process.env.HOST_Local : proces
const dbPassword = process.env.DEBUG === 'true' ? 'root' : process.env.DB_PASS_SERVER;
const sequelize = new Sequelize('accounting', 'root', dbPassword, {
const sequelize = new Sequelize('accounting', 'root', 'mahan7797', {
define: {
charset: 'utf8',
charset: 'utf8',
collate: 'utf8_general_ci'
},
host: dbAddress,
host: '35.157.64.22',
dialect: 'mysql',
logging: false,
logging: true,
operatorsAliases: false
......@@ -31,6 +31,7 @@ const User = sequelize.define('user', {
euro_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
lir_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
aed_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
can_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
});
......@@ -104,6 +105,9 @@ function runCurrency(data, user) {
case 'aed':
user.aed_balance = user.aed_balance + (-1 * parseFloat(data.count))
break
case 'aed':
user.can_balance = user.can_balance + (-1 * parseFloat(data.count))
break
}
......@@ -131,6 +135,9 @@ function runCurrency(data, user) {
case 'aed':
user.aed_balance = user.aed_balance + (parseFloat(data.count))
break
case 'can':
user.can_balance = user.can_balance + (parseFloat(data.count))
break
}
......@@ -179,6 +186,14 @@ function runCurrency(data, user) {
}
else if (data.vahed === 'can') {
if (data.action === 'buy')
user.can_balance = user.can_balance + parseFloat(data.count)
else
user.can_balance = user.can_balance + (-1 * parseFloat(data.count))
}
if (data.to === 'toman') {
if (data.action === 'buy')
......@@ -223,6 +238,16 @@ function runCurrency(data, user) {
user.aed_balance = user.aed_balance + (parseFloat(data.count) * parseFloat(data.fee))
}
else if (data.vahed === 'can') {
if (data.action === 'buy')
user.can_balance = user.can_balance + (-1 * parseFloat(data.count) * parseFloat(data.fee))
else
user.can_balance = user.can_balance + (parseFloat(data.count) * parseFloat(data.fee))
}
return user
......@@ -238,7 +263,7 @@ async function getAllUsers() {
})
}
async function getRequestByDate(userId, date) {
async function getRequestByDate(userId, startDate,endDate) {
return await Request.findAll({
......@@ -246,7 +271,8 @@ async function getRequestByDate(userId, date) {
where: {
user_request: userId,
createdAt: {
[Op.gte]: moment().subtract(date, 'days').toDate()
[Op.gte]: startDate,
[Op.lte]:endDate
}
}
......@@ -273,7 +299,8 @@ async function updateBalance(user) {
dollar_balance: user.dollar_balance,
euro_balance: user.euro_balance,
lir_balance: user.lir_balance,
aed_balance: user.aed_balance
aed_balance: user.aed_balance,
can_balance: user.can_balance
},
......@@ -313,6 +340,8 @@ async function findRequest(id) {
}
module.exports = {
getAllUsers: getAllUsers,
......
......@@ -118,6 +118,9 @@ function userShowMessage(bot, msg, user) {
}
if (user.euro_balance !== 0) {
text += '💶 '
text += Math.abs(user.euro_balance) + ' ' + 'یورو' + ' '
......@@ -144,6 +147,16 @@ function userShowMessage(bot, msg, user) {
user.aed_balance > 0 ? 'بدهکار' : 'طلبکار'
}
if (user.can_balance !== 0) {
text += '💵 '
text += Math.abs(user.can_balance) + ' ' + 'دلار کانادا' + ' '
text += user.can_balance === 0 ? '' :
user.can_balance > 0 ? 'بدهکار' : 'طلبکار'
text += '\n'
text += '\n'
}
bot.editMessageText(text, opts)
}
......@@ -192,6 +205,14 @@ async function showCurrencyMessage(bot, msg, user) {
callback_data: 'aed_' + user.id
}
],
[
{
text: 'دلار کانادا',
callback_data: 'can_' + user.id
}
]
......@@ -390,13 +411,13 @@ async function listRequest(bot, msg, reqs) {
let text = ''
text += reqs[i].type.replace("variz", "واریز").replace("daryaft", "دریافت").replace("buy", "خرید").replace("sell", "فروش") + " "
text += reqs[i].count + " "
text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم') + " "
text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا') + " "
if (reqs[i].type !== 'variz' && reqs[i].type !== 'daryaft' ) {
text += 'با مبلغ '
text += ' '
text += reqs[i].fee
text += ' '
text += reqs[i].toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم')
text += reqs[i].toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا')
text += ' '
}
......@@ -433,13 +454,13 @@ async function showRequest(bot, msg, req) {
text += ' '
text += req.count
text += ' '
text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم')
text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا')
text += ' '
text += 'با مبلغ '
text += ' '
text += req.fee
text += ' '
text += req.toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم')
text += req.toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا')
text += ' '
}
else {
......@@ -449,7 +470,7 @@ async function showRequest(bot, msg, req) {
text += ' '
text += req.count
text += ' '
text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم')
text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا')
text += ' '
}
......
let d = Date()
let db=require('./db')
console.log(d.bold())
console.log(d.small().bold())
console.log("Hii ali name of god")
console.log(Date())
console.log(Date().fixed())
test()
async function test() {
let d=await db.getRequestByDate(4,new Date('2019-02-01'),new Date('2020-02-01'))
console.log(d)
}
......@@ -2,7 +2,7 @@
function initOs() {
if (process.platform === 'darwin' || process.platform === 'win32')
process.env.DEBUG = 'true';
process.env.DEBUG = 'false';
else
process.env.DEBUG = 'false'
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment