++ Cassa - parte 1
This commit is contained in:
@@ -5,6 +5,8 @@ const tools = require('../tools/general');
|
|||||||
|
|
||||||
const { ObjectID } = require('mongodb');
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
mongoose.level = "F";
|
mongoose.level = "F";
|
||||||
|
|
||||||
@@ -22,47 +24,29 @@ const CashSchema = new Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
idCashCategory: {
|
idCashCategory: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
|
||||||
idSubCashCategory: {
|
|
||||||
type: String
|
|
||||||
},
|
},
|
||||||
type: { // CashType: TYPE_IN, TYPE_OUT
|
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: {
|
date_created: {
|
||||||
type: Date
|
type: Date,
|
||||||
|
default: Date.now,
|
||||||
},
|
},
|
||||||
date_payment: {
|
date_payment: {
|
||||||
type: Date
|
type: Date,
|
||||||
|
default: Date.now,
|
||||||
},
|
},
|
||||||
descr: {
|
causale: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
price: {
|
price: {
|
||||||
type: Number
|
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: {
|
internal: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
@@ -71,9 +55,6 @@ const CashSchema = new Schema({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
notes: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
confirmed: {
|
confirmed: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
@@ -114,8 +95,22 @@ module.exports.getCashByID = function (id, callback) {
|
|||||||
Cash.findById(id, callback);
|
Cash.findById(id, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.createCash = async function (Cash) {
|
module.exports.createMovementCashByOrdersCart = async function (ordersCart, userIdStore, req, internal) {
|
||||||
const CashModel = new Cash(Cash);
|
|
||||||
|
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)
|
return await CashModel.save(Cash)
|
||||||
.then((ris) => {
|
.then((ris) => {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const Storehouse = require('../models/storehouse');
|
|||||||
const Provider = require('../models/provider');
|
const Provider = require('../models/provider');
|
||||||
const Gasordine = require('../models/gasordine');
|
const Gasordine = require('../models/gasordine');
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
const Cash = require('../models/cash');
|
||||||
const ProductInfo = require('../models/productInfo');
|
const ProductInfo = require('../models/productInfo');
|
||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
@@ -469,12 +470,25 @@ module.exports.createOrdersCart = async function (newOrdersCart) {
|
|||||||
return await newOrdersCart.save()
|
return await newOrdersCart.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
|
|
||||||
|
module.exports.addOrderToCash = async function (idorderscart, userIdStore, req) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
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) {
|
if (myorderscart) {
|
||||||
for (const idkey in myorderscart.items) {
|
for (const idkey in myorderscart.items) {
|
||||||
let order = myorderscart.items[idkey].order;
|
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 })
|
let myOrderCart = await OrdersCart.findOne({ _id: ordersCart._id })
|
||||||
.populate('items.order').lean();
|
.populate('items.order').lean();
|
||||||
@@ -659,6 +674,10 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
|
|||||||
|
|
||||||
} else if (status === shared_consts.OrderStatus.PAYED) {
|
} else if (status === shared_consts.OrderStatus.PAYED) {
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
await OrdersCart.addOrderToCash(id, userIdStore, req);
|
||||||
|
}
|
||||||
|
|
||||||
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
||||||
|
|
||||||
} else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato
|
} else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ const storehouseSchema = new Schema({
|
|||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
username: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
const user = req.user;
|
const user = req.user;
|
||||||
let status = req.body.status;
|
let status = req.body.status;
|
||||||
let note = req.body.note;
|
let note = req.body.note;
|
||||||
|
let options = req.body.options;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let mycart = await Cart.findOne({ _id: cart_id });
|
let mycart = await Cart.findOne({ _id: cart_id });
|
||||||
@@ -299,10 +300,10 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
.then((ris) => {
|
.then((ris) => {
|
||||||
|
|
||||||
return OrdersCart.getOrdersCartByUserId(userId, idapp, numorder)
|
return OrdersCart.getOrdersCartByUserId(userId, idapp, numorder)
|
||||||
.then((orders) => {
|
.then(async (orders) => {
|
||||||
if (!!orders) {
|
if (!!orders) {
|
||||||
|
|
||||||
OrdersCart.updateCmd(orders[0], status, true);
|
await OrdersCart.updateCmd(orders[0], status, true, req, options);
|
||||||
|
|
||||||
// Invia la email dell'Ordine
|
// Invia la email dell'Ordine
|
||||||
sendemail.sendEmail_OrderProduct(user.lang, idapp, orders[0], user)
|
sendemail.sendEmail_OrderProduct(user.lang, idapp, orders[0], user)
|
||||||
@@ -351,6 +352,7 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
|||||||
let order_id = req.body.order_id;
|
let order_id = req.body.order_id;
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
let status = req.body.status;
|
let status = req.body.status;
|
||||||
|
let options = req.body.options;
|
||||||
|
|
||||||
const { User } = require('../models/user');
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
@@ -373,7 +375,7 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
|||||||
if (ris) {
|
if (ris) {
|
||||||
|
|
||||||
// Aggiorna gli Stati Interni !
|
// Aggiorna gli Stati Interni !
|
||||||
orderCart = await OrdersCart.updateCmd(orderCart, status, true);
|
orderCart = await OrdersCart.updateCmd(orderCart, status, true, options);
|
||||||
|
|
||||||
let ordertype = '';
|
let ordertype = '';
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ const Storehouse = require('../models/storehouse');
|
|||||||
const Provider = require('../models/provider');
|
const Provider = require('../models/provider');
|
||||||
const CatProd = require('../models/catprod');
|
const CatProd = require('../models/catprod');
|
||||||
const Gasordine = require('../models/gasordine');
|
const Gasordine = require('../models/gasordine');
|
||||||
|
const Product = require('../models/product');
|
||||||
const ProductInfo = require('../models/productInfo');
|
const ProductInfo = require('../models/productInfo');
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
const Department = require('../models/department');
|
const Department = require('../models/department');
|
||||||
@@ -1440,6 +1441,7 @@ function load(req, res, version) {
|
|||||||
let providers = Provider.findAllIdApp(idapp);
|
let providers = Provider.findAllIdApp(idapp);
|
||||||
let catprods = CatProd.findAllIdApp(idapp);
|
let catprods = CatProd.findAllIdApp(idapp);
|
||||||
let gasordines = Gasordine.findAllIdApp(idapp);
|
let gasordines = Gasordine.findAllIdApp(idapp);
|
||||||
|
let products = Product.findAllIdApp(idapp);
|
||||||
let productInfos = ProductInfo.findAllIdApp(idapp);
|
let productInfos = ProductInfo.findAllIdApp(idapp);
|
||||||
let scontisticas = Scontistica.findAllIdApp(idapp);
|
let scontisticas = Scontistica.findAllIdApp(idapp);
|
||||||
let departments = Department.findAllIdApp(idapp);
|
let departments = Department.findAllIdApp(idapp);
|
||||||
@@ -1531,6 +1533,7 @@ function load(req, res, version) {
|
|||||||
providers,
|
providers,
|
||||||
scontisticas,
|
scontisticas,
|
||||||
gasordines,
|
gasordines,
|
||||||
|
products,
|
||||||
productInfos,
|
productInfos,
|
||||||
catprods,
|
catprods,
|
||||||
]).then((arrdata) => {
|
]).then((arrdata) => {
|
||||||
@@ -1618,8 +1621,9 @@ function load(req, res, version) {
|
|||||||
providers: arrdata[40],
|
providers: arrdata[40],
|
||||||
scontisticas: arrdata[41],
|
scontisticas: arrdata[41],
|
||||||
gasordines: arrdata[42],
|
gasordines: arrdata[42],
|
||||||
productInfos: arrdata[43],
|
products: arrdata[43],
|
||||||
catprods: arrdata[44],
|
productInfos: arrdata[44],
|
||||||
|
catprods: arrdata[45],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prova = 1;
|
const prova = 1;
|
||||||
|
|||||||
@@ -337,6 +337,27 @@ module.exports = {
|
|||||||
OPZ1_2: 2,
|
OPZ1_2: 2,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
TYPECASH: {
|
||||||
|
NESSUNO: 0,
|
||||||
|
IN: 1,
|
||||||
|
OUT: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
TypeCashStr: [
|
||||||
|
{
|
||||||
|
label: '[Nessuno]',
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Ingresso',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Uscita',
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
UNITS_OF_MEASURE: {
|
UNITS_OF_MEASURE: {
|
||||||
NESSUNO: 0,
|
NESSUNO: 0,
|
||||||
GRAMMI: 1,
|
GRAMMI: 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user