Circuits OK

Accounts Ok
Movements OK
This commit is contained in:
Paolo Arena
2022-09-14 11:31:48 +02:00
parent 44c75768c6
commit 25a60472ab
34 changed files with 299 additions and 119 deletions

View File

@@ -13,6 +13,7 @@ import { serv_constants } from '@store/Modules/serv_constants'
import { Api } from '@api'
import { toolsext } from '@store/Modules/toolsext'
import { static_data } from '@src/db/static_data'
import { useUserStore } from '@store/UserStore'
import { shared_consts } from '@/common/shared_vuejs'
@@ -31,10 +32,24 @@ export const useCircuitStore = defineStore('CircuitStore', {
actions: {
getRemainingCoinsToSend(account: IAccount) {
return tools.roundDec2(account.saldo + account.fidoConcesso)
if (account)
return tools.roundDec2(account.saldo + account.fidoConcesso)
else
return 0
},
getMaxCoinsToSend(account: IAccount) {
return tools.roundDec2(account.qta_maxConcessa - account.saldo)
if (account)
return tools.roundDec2(account.qta_maxConcessa - account.saldo)
else
return 0
},
getSaldoByCircuitId(circuitId: string): number {
const userStore = useUserStore()
const account = userStore.my.profile.useraccounts.find((rec: IAccount) => rec.circuitId === circuitId)
if (account)
return account.saldo
else
return 0
},
async loadCircuits() {

View File

@@ -34,9 +34,9 @@ export const DB = {
}
export function allTables() {
const myarr = OtherTables
for (const tab of MainTables) {
for (const method of allMethod) {
const myarr = costanti.OtherTables
for (const tab of costanti.MainTables) {
for (const method of costanti.allMethod) {
myarr.push(method + tab)
}
}

View File

@@ -161,6 +161,18 @@ export const costanti = {
small: true,
visuonstat: true,
},
{
visible: false,
title: 'Circuiti',
to: '/circuits',
table: 'circuits',
icon: 'fas fa-coins',
color: 'orange-6',
hint: '',
disable: true,
small: true,
visuonstat: true,
},
],
BINARY_CHECK: 1,

View File

@@ -2417,7 +2417,6 @@ export const colTableSubCashCategory = [
]
export const colTableCircuitComplete = [
AddCol({ name: 'Num', label_trans: 'circuit.num', fieldtype: costanti.FieldType.number }),
// AddCol({ name: 'groupnameId', label_trans: 'circuit.groupnameId', fieldtype: costanti.FieldType.select, jointable: 'mygroups' }), // da togliere poi
AddCol({ name: 'name', label_trans: 'circuit.name',
maxlength: 40,
@@ -2521,8 +2520,8 @@ export const colTableCircuit = [
fieldtype: costanti.FieldType.currency, required: true, visulabel: true }),
AddCol({ name: 'qta_max_default', label_trans: 'circuit.qta_max_default',
fieldtype: costanti.FieldType.currency, required: true, visulabel: true }),
AddCol({ name: 'regulation', label_trans: 'circuit.regulation', fieldtype: costanti.FieldType.html }),
AddCol({ name: 'deperimento', label_trans: 'circuit.deperimento', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'regulation', label_trans: 'circuit.regulation', fieldtype: costanti.FieldType.html, required: true }),
// AddCol({ name: 'deperimento', label_trans: 'circuit.deperimento', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'data_costituz', label_trans: 'circuit.data_costituz', fieldtype: costanti.FieldType.date }),
AddCol({
name: 'photos',
@@ -2537,7 +2536,7 @@ export const colTableCircuit = [
]
export const colmyUserCircuit = [
AddCol({ name: 'circuitId', label_trans: 'account.circuitId', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'circuitId', label_trans: 'account.circuitId', fieldtype: costanti.FieldType.string }),
AddCol({ name: 'userId', label_trans: 'account.users', fieldtype: costanti.FieldType.select, jointable: 'users', }),
AddCol({ name: 'name', label_trans: 'circuit.name' }),
AddCol({ name: 'deperibile', label_trans: 'account.deperibile', fieldtype: costanti.FieldType.boolean }),
@@ -2552,8 +2551,8 @@ export const colmyUserCircuit = [
export const colTableMovement = [
AddCol({ name: 'transactionDate', label_trans: 'movement.transactionDate', fieldtype: costanti.FieldType.date }),
AddCol({ name: 'accountFromId', label_trans: 'movement.accountFromId', fieldtype: costanti.FieldType.number, required: true }),
AddCol({ name: 'accountToId', label_trans: 'movement.accountToId', fieldtype: costanti.FieldType.number, required: true }),
AddCol({ name: 'accountFromId', label_trans: 'movement.accountFromId', fieldtype: costanti.FieldType.string, required: true }),
AddCol({ name: 'accountToId', label_trans: 'movement.accountToId', fieldtype: costanti.FieldType.string, required: true }),
AddCol({ name: 'amount', label_trans: 'movement.amount', fieldtype: costanti.FieldType.number, required: true }),
AddCol({ name: 'causal', label_trans: 'movement.causal' }),
AddCol({ name: 'causal_table', label_trans: 'movement.causal_table' }),

View File

@@ -67,6 +67,7 @@ export const tools = {
FRIENDS_SEARCH: 'FR_SE',
GROUP_SEARCH: 'GR_SE',
CIRCUIT_SEARCH: 'CI_SE',
CIRCUIT_USE: 'CIR_U',
getprefCountries: ['it', 'es', 'us'],
@@ -4328,6 +4329,7 @@ export const tools = {
'blue': '#0000ff',
'blue-3': '#90caf9',
'blue-4': '#64b5f6',
'amber-10': '#ff6f00',
'blue-6': '#2196f3',
'blueviolet': '#8a2be2',
'brown': '#a52a2a',
@@ -4796,6 +4798,10 @@ export const tools = {
.then((res: any) => {
if (res) {
if (res.cansend) {
if (res.user) {
userStore.my = res.user
}
console.log('useraccounts', userStore.my.profile.useraccounts)
tools.showPositiveNotif($q, t('circuit.coins_accepted'))
} else {
tools.showNegativeNotif($q, res.errormsg)
@@ -4804,10 +4810,11 @@ export const tools = {
})
},
refuseCoins($q: any, username: string, recsendcoin: ISendCoin) {
refuseCoins($q: any, username: string, notif: any) {
const userStore = useUserStore()
userStore.setCircuitCmd($q, t, username, recsendcoin.circuitname, shared_consts.CIRCUITCMD.SENDCOINS_REFUSE, recsendcoin)
notif.extrarec.notifId = notif._id
userStore.setCircuitCmd($q, t, username, notif.extrarec.circuitname, shared_consts.CIRCUITCMD.SENDCOINS_REFUSE, 0, notif.extrarec)
.then((res: any) => {
if (res) {
tools.showPositiveNotif($q, t('circuit.coins_refused'))
@@ -5295,6 +5302,9 @@ export const tools = {
if (res.useraccounts && res.useraccounts.length > 0) {
userStore.my.profile.useraccounts = res.useraccounts
}
if (res.user) {
userStore.my = res.user
}
tools.showPositiveNotif($q, t('circuit.coins_sendrequest_sent'))
} else {
tools.showNegativeNotif($q, res.errormsg)
@@ -5344,7 +5354,7 @@ export const tools = {
if (username === userStore.my.username) {
userStore.my.profile.asked_circuits = userStore.my.profile.asked_circuits.filter((rec: ICircuit) => rec.name !== circuitname)
}
tools.showPositiveNotif($q, t('db.refusedcircuit', { username }))
tools.showPositiveNotif($q, t('circuit.refusedcircuit', { username }))
}
})
})
@@ -5653,8 +5663,18 @@ export const tools = {
tools.addToMyCircuits($q, username, dest)
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
tools.setRequestCircuit($q, username, dest, value)
} else if (cmd === shared_consts.CIRCUITCMD.CANCEL_REQ) {
tools.cancelReqCircuit($q, username, dest)
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
tools.refuseReqCircuit($q, username, dest)
} else if (cmd === shared_consts.CIRCUITCMD.DELETE) {
tools.DeleteCircuit($q, username, dest)
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
tools.addtoAdminOfCircuit($q, username, dest)
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
tools.removeAdminOfCircuit($q, username, dest)
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
tools.removeFromMyCircuits($q, username, dest)
}
},
isCallable(anything: any) {
@@ -6257,8 +6277,13 @@ export const tools = {
// Function to return commonElements
getCommon(arr1: any, arr2: any, field: string): any[] {
arr1.sort((a: any, b: any) => b[field] - a[field]) // Sort both the arrays
arr2.sort((a: any, b: any) => b[field] - a[field])
// @ts-ignore
arr1.sort((a: any, b: any) => (a[field] > b[field]) - (a[field] < b[field])) // Sort both the arrays
// @ts-ignore
arr2.sort((a: any, b: any) => (a[field] > b[field]) - (a[field] < b[field]))
// console.log('arr1', arr1)
// console.log('arr2', arr2)
let common = [] // Array to contain common elements
let i = 0, j = 0 // i points to arr1 and j to arr2
// Break if one of them runs out
@@ -6284,9 +6309,9 @@ export const tools = {
if (rec && rec.userfrom) {
const userStore = useUserStore()
if (userStore.my.username === rec.userfrom.username) {
type = rec.amount > 0 ? costanti.TypeMov.Uscita : (rec.amount < 0 ? costanti.TypeMov.Entrata : costanti.TypeMov.Nessuno)
type = costanti.TypeMov.Uscita
} else if (userStore.my.username === rec.userto.username) {
type = rec.amount > 0 ? costanti.TypeMov.Entrata : (rec.amount < 0 ? costanti.TypeMov.Uscita : costanti.TypeMov.Nessuno)
type = costanti.TypeMov.Entrata
}
}

View File

@@ -312,11 +312,11 @@ export const useUserStore = defineStore('UserStore', {
if (!this.my.profile.mycircuits || !user.profile.mycircuits)
return []
return tools.getCommon(this.my.profile.mycircuits, user.profile.mycircuits, 'circuitname')
return tools.getCommon([...this.my.profile.mycircuits], [...user.profile.mycircuits], 'circuitname')
},
getAccountByCircuitId(circuitId: number): any {
getAccountByCircuitId(circuitId: string): any {
return this.my.profile.useraccounts.find((rec: IAccount) => rec.circuitId === circuitId)
},

View File

@@ -692,8 +692,12 @@ export const useGlobalStore = defineStore('GlobalStore', {
async clearDataAfterLogout() {
// console.log('clearDataAfterLogout')
for (const table of ApiTables.allTables()) {
await globalroutines('clearalldata', table, null)
try {
for (const table of ApiTables.allTables()) {
await globalroutines('clearalldata', table, null)
}
}catch (e) {
//
}
if (static_data.functionality.PWA) {
@@ -1676,7 +1680,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
myserv = window.location.host
if (process.env.DEBUGGING) {
myserv = 'http://192.168.1.103:3000'; // 'http://192.168.1.54:3000'
myserv = 'http://localhost:3000'; // 'http://192.168.1.54:3000'
}
if (!myserv) {