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