++ Cassa - parte 1
This commit is contained in:
@@ -5,6 +5,8 @@ const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
@@ -22,47 +24,29 @@ const CashSchema = new Schema({
|
||||
type: String,
|
||||
},
|
||||
idCashCategory: {
|
||||
type: String
|
||||
},
|
||||
idSubCashCategory: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
type: { // CashType: TYPE_IN, TYPE_OUT
|
||||
type: Number
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
fromUserId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
toUserId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
idOrdersCart: { type: Schema.Types.ObjectId, ref: 'OrdersCart' },
|
||||
date_created: {
|
||||
type: Date
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
date_payment: {
|
||||
type: Date
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
descr: {
|
||||
causale: {
|
||||
type: String,
|
||||
},
|
||||
price: {
|
||||
type: Number
|
||||
},
|
||||
quantity: {
|
||||
type: Number
|
||||
},
|
||||
total: {
|
||||
type: Number
|
||||
},
|
||||
fromWalletUserId: { // walletCommonCash or any Member
|
||||
type: String,
|
||||
},
|
||||
toWalletUserId: { // walletCommonCash or any Member
|
||||
type: String,
|
||||
},
|
||||
walletStatus: { // WalletFinalStatusType: None: 0, InCommonCash: 1, InMyWallet : 2
|
||||
type: Number,
|
||||
},
|
||||
walletTemporaryToUserId: { // WalletCommonCash
|
||||
type: String,
|
||||
},
|
||||
walletCashId: {
|
||||
type: String,
|
||||
},
|
||||
internal: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -71,9 +55,6 @@ const CashSchema = new Schema({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
notes: {
|
||||
type: String
|
||||
},
|
||||
confirmed: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -114,8 +95,22 @@ module.exports.getCashByID = function (id, callback) {
|
||||
Cash.findById(id, callback);
|
||||
}
|
||||
|
||||
module.exports.createCash = async function (Cash) {
|
||||
const CashModel = new Cash(Cash);
|
||||
module.exports.createMovementCashByOrdersCart = async function (ordersCart, userIdStore, req, internal) {
|
||||
|
||||
let casjobj = {
|
||||
idapp: req.user.iapp,
|
||||
idOrdersCart: ordersCart._id,
|
||||
creatorUserId: req.user ? req.user._id : null,
|
||||
type: shared_consts.TYPECASH.IN,
|
||||
fromUserId: ordersCart.userId,
|
||||
toUserId: userIdStore,
|
||||
causale: 'Pagato Ordine n.' + ordersCart.numorder,
|
||||
date_payment: new Date(),
|
||||
price: ordersCart.totalPrice,
|
||||
internal,
|
||||
}
|
||||
|
||||
const CashModel = new Cash(casjobj);
|
||||
|
||||
return await CashModel.save(Cash)
|
||||
.then((ris) => {
|
||||
|
||||
@@ -10,6 +10,7 @@ const Storehouse = require('../models/storehouse');
|
||||
const Provider = require('../models/provider');
|
||||
const Gasordine = require('../models/gasordine');
|
||||
const Product = require('../models/product');
|
||||
const Cash = require('../models/cash');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
@@ -469,12 +470,25 @@ module.exports.createOrdersCart = async function (newOrdersCart) {
|
||||
return await newOrdersCart.save()
|
||||
}
|
||||
|
||||
module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
|
||||
|
||||
module.exports.addOrderToCash = async function (idorderscart, userIdStore, req) {
|
||||
|
||||
try {
|
||||
|
||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||
|
||||
const mycash = await Cash.createMovementCashByOrdersCart(myorderscart, userIdStore, req);
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
|
||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||
if (myorderscart) {
|
||||
for (const idkey in myorderscart.items) {
|
||||
let order = myorderscart.items[idkey].order;
|
||||
@@ -633,8 +647,9 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
|
||||
|
||||
}
|
||||
|
||||
module.exports.updateCmd = async function (ordersCart, status, value) {
|
||||
module.exports.updateCmd = async function (ordersCart, status, value, req, options) {
|
||||
|
||||
const userIdStore = options.userIdStore ?? null;
|
||||
|
||||
let myOrderCart = await OrdersCart.findOne({ _id: ordersCart._id })
|
||||
.populate('items.order').lean();
|
||||
@@ -659,6 +674,10 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.PAYED) {
|
||||
|
||||
if (value) {
|
||||
await OrdersCart.addOrderToCash(id, userIdStore, req);
|
||||
}
|
||||
|
||||
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato
|
||||
|
||||
@@ -18,6 +18,11 @@ const storehouseSchema = new Schema({
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
|
||||
Reference in New Issue
Block a user