Aggiornamento modifiche preOrdini

This commit is contained in:
Surya Paolo
2023-12-20 21:56:30 +01:00
parent 265c8f4d9e
commit 56b433dae3
13 changed files with 252 additions and 71 deletions

View File

@@ -18,6 +18,10 @@
font-size: 1.2rem; font-size: 1.2rem;
} }
.prod_preorder{
font-size: 1.2rem;
}
.prod_qtywarn{ .prod_qtywarn{
padding-left: 10px; padding-left: 10px;
font-size: 1rem; font-size: 1rem;

View File

@@ -88,33 +88,39 @@ export default defineComponent({
} }
products.addToCart({ product: myproduct.value, order: myorder, addqty: add }).then((ris) => { if (myproduct.value) {
let strprod = t('ecomm.prodotto') products.addToCart({ product: myproduct.value, order: myorder, addqty: add }).then((ris: any) => {
let strprod = t('ecomm.prodotto')
if (myorder.quantity > 1 || myorder.quantity === 0) let msg = ''
strprod = t('ecomm.prodotti') console.log('ris', ris)
if (ris === null || ris.myord == null) {
let msg = '' msg = t('ecomm.error_cart')
if (ris === null) tools.showNegativeNotif($q, msg)
msg = t('ecomm.error_cart') return
else {
if (myorder.quantity === 0) {
msg = t('ecomm.prodotto_tolto')
} else { } else {
msg = t('ecomm.prod_sul_carrello', { strprod, qty: myorder.quantity })
let qta = ris.myord.quantity + ris.myord.quantitypreordered
if (qta > 1 || qta === 0)
strprod = t('ecomm.prodotti')
if (qta === 0) {
msg = t('ecomm.prodotto_tolto')
} else {
msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta })
}
} }
} updateproduct()
updateproduct() if (ris === null || ris.myord.quantity === 0)
tools.showNotif($q, msg)
else
tools.showPositiveNotif($q, msg)
if (ris === null || myorder.quantity === 0) })
tools.showNotif($q, msg) }
else
tools.showPositiveNotif($q, msg)
})
} }
function getnumstore() { function getnumstore() {
@@ -141,13 +147,13 @@ export default defineComponent({
function updateproduct() { function updateproduct() {
myproduct.value = products.getProduct(props.code) myproduct.value = products.getProduct(props.code)
products.updateQuantityAvailable(myproduct.value._id) // products.updateQuantityAvailable(myproduct.value._id)
} }
function getStorehouses() { function getStorehouses() {
if (!myproduct.value) if (!myproduct.value)
return [] return []
const myarr: any = [] const myarr: any = []
let ind = 1 let ind = 1
myproduct.value.storehouses.forEach((store) => { myproduct.value.storehouses.forEach((store) => {
@@ -175,6 +181,11 @@ export default defineComponent({
return qty return qty
} }
function getQtyBookableAvailable() {
let qty = myproduct.value.bookableAvailableQty!
return qty
}
function getQtyWarn() { function getQtyWarn() {
if (myorder.quantity > 0) { if (myorder.quantity > 0) {
return t('ecomm.di_cui_x_in_carrello', { qty: myorder.quantity }) return t('ecomm.di_cui_x_in_carrello', { qty: myorder.quantity })
@@ -182,6 +193,13 @@ export default defineComponent({
return '' return ''
} }
function getQtyWarnPreOrdered() {
if (myorder.quantitypreordered > 0) {
return t('ecomm.di_cui_x_in_carrello', { qty: myorder.quantitypreordered })
}
return ''
}
watch(() => props.code, (newval, oldval) => { watch(() => props.code, (newval, oldval) => {
console.log('change code') console.log('change code')
load() load()
@@ -206,6 +224,7 @@ export default defineComponent({
const ord = products.getOrderProductInCart(myproduct.value._id) const ord = products.getOrderProductInCart(myproduct.value._id)
if (ord) { if (ord) {
myorder.quantity = ord.quantity myorder.quantity = ord.quantity
myorder.quantitypreordered = ord.quantitypreordered
} }
} }
@@ -222,7 +241,8 @@ export default defineComponent({
} }
function enableSubQty() { function enableSubQty() {
return myorder.quantity ? myorder.quantity > 0 : false let qty = myorder.quantity + myorder.quantitypreordered
return qty ? qty > 0 : false
} }
function enableAddQty() { function enableAddQty() {
@@ -262,6 +282,8 @@ export default defineComponent({
endload, endload,
shared_consts, shared_consts,
site, site,
getQtyWarnPreOrdered,
getQtyBookableAvailable,
} }
} }
}) })

View File

@@ -51,16 +51,17 @@
myproduct.after_price myproduct.after_price
}}</span> }}</span>
</q-item-label> </q-item-label>
<q-item-label v-if="myproduct.scontisticas && myproduct.scontisticas.length > 0"> <q-item-label
v-if="myproduct.scontisticas && myproduct.scontisticas.length > 0"
>
<div <div
class="prod_sconti" class="prod_sconti"
v-for="(sconti, index) of myproduct.scontisticas" v-for="(sconti, index) of myproduct.scontisticas"
:key="index" :key="index"
> >
{{ sconti.description }} {{ sconti.description }}
</div> </div>
</q-item-label> </q-item-label>
</q-item-section> </q-item-section>
</q-item> </q-item>
</q-list> </q-list>
@@ -116,29 +117,18 @@
<q-item-section> <q-item-section>
<q-item-label> <q-item-label>
<span v-if="getQtyAvailable() < 0"> {{ t('ecomm.available') }}
{{ t('ecomm.preorders') }}
</span>
<span v-else>
{{ t('ecomm.available') }}
</span>
</q-item-label> </q-item-label>
<q-item-label> <q-item-label>
<span class="prod_disp"> <span class="prod_disp">
<span v-if="getQtyAvailable() < 0"> {{ getQtyAvailable() }}
{{ -getQtyAvailable() }}
</span>
<span v-else>
{{ getQtyAvailable() }}
</span>
</span> </span>
<div class="prod_qtywarn"> <div class="prod_qtywarn">
{{ getQtyWarn() }} {{ getQtyWarn() }}
<div <div
v-if=" v-if="
tools.isManager() && tools.isManager() && !!myproduct.QuantitaOrdinateInAttesa
!!myproduct.QuantitaOrdinateInAttesa
" "
> >
{{ {{
@@ -152,6 +142,43 @@
<q-item-label> </q-item-label> <q-item-label> </q-item-label>
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-item
v-if="getQtyBookableAvailable() > 0"
:clickable="tools.isManager()"
@click="tools.isManager() ? (openlistorders = true) : null"
>
<q-item-section avatar>
<q-icon color="blue" name="fas fa-edit" />
</q-item-section>
<q-item-section>
<q-item-label>
{{ t('ecomm.preorders') }}
</q-item-label>
<q-item-label>
<span class="prod_preorder">
{{ getQtyBookableAvailable() }}
</span>
<div class="prod_qtywarn">
<span v-if="getQtyWarnPreOrdered()">{{
getQtyWarnPreOrdered()
}}</span>
<div
v-if="
tools.isManager() && !!myproduct.QuantitaPrenotateInAttesa
"
>
{{
$t('ecomm.qta_prenotate_in_attesa', {
qty: myproduct.QuantitaPrenotateInAttesa,
})
}}
</div>
</div>
</q-item-label>
</q-item-section>
</q-item>
</q-list> </q-list>
<div class="row q-mb-sm no-wrap items-center centeritems"> <div class="row q-mb-sm no-wrap items-center centeritems">
<q-btn <q-btn
@@ -175,6 +202,13 @@
<div class="self-center no-outline" tabindex="0"> <div class="self-center no-outline" tabindex="0">
{{ myorder.quantity }} {{ myorder.quantity }}
</div> </div>
<div
v-if="myorder.quantitypreordered"
class="self-center no-outline"
tabindex="0"
>
Preord.: {{ myorder.quantitypreordered }}
</div>
</template> </template>
</q-field> </q-field>
@@ -221,7 +255,7 @@
<q-card-actions vertical align="center"> <q-card-actions vertical align="center">
<q-btn <q-btn
v-if="myorder.quantity > 0" v-if="myorder.quantity + myorder.quantitypreordered > 0"
rounded rounded
icon="fas fa-shopping-cart" icon="fas fa-shopping-cart"
color="primary" color="primary"
@@ -282,9 +316,22 @@
</td> </td>
<td class="text-center"> <td class="text-center">
<div v-for="(singleord, index) in ordcart.items" :key="index"> <div v-for="(singleord, index) in ordcart.items" :key="index">
<span v-if="singleord.order.idProduct === myproduct._id">{{ <span
singleord.order.quantity v-if="
}}</span> singleord.order.idProduct === myproduct._id &&
singleord.order.quantity > 0
"
>
{{ singleord.order.quantity }}</span
>
<span
v-if="
singleord.order.idProduct === myproduct._id &&
singleord.order.quantitypreordered > 0
"
>
{{ singleord.order.quantitypreordered }}</span
>
</div> </div>
</td> </td>
<td class="text-center"> <td class="text-center">

View File

@@ -40,14 +40,29 @@ export default defineComponent({
} }
function addsubqty(addqty: boolean, subqty: boolean) { function addsubqty(addqty: boolean, subqty: boolean) {
if (addqty) { if (products.isQtyAvailableByOrder(props.order)) {
if (props.order.quantity >= 10) if (addqty) {
return false if (props.order.quantity >= 20)
} return false
}
if (subqty) { if (subqty) {
if (props.order.quantity === 0) if (props.order.quantity === 0)
return false return false
}
} else {
if (products.isInPreorderByOrder(props.order)) {
if (addqty) {
if (props.order.quantitypreordered >= 20)
return false
}
if (subqty) {
if (props.order.quantitypreordered === 0)
return false
}
}
} }
products.addSubQtyToItem({ products.addSubQtyToItem({
@@ -56,14 +71,15 @@ export default defineComponent({
order: props.order, order: props.order,
}).then((res: any) => { }).then((res: any) => {
if (res.risult) { if (res.risult) {
order.value.quantity = res.qty order.value.quantity = res.myord.quantity
order.value.quantitypreordered = res.myord.quantitypreordered
} }
}) })
} }
function isApplicatoSconto() { function isApplicatoSconto() {
const totalipotetico = order.value.price! * order.value.quantity const totalipotetico = order.value.price * (order.value.quantity + order.value.quantitypreordered)
if (totalipotetico > order.value.TotalPriceProduct!) { if (totalipotetico > order.value.TotalPriceProduct) {
return true return true
} }
return false return false

View File

@@ -22,14 +22,14 @@
<div class="self-center no-outline" tabindex="0" >{{ order.quantity }}</div> <div class="self-center no-outline" tabindex="0" >{{ order.quantity }}</div>
</template> </template>
</q-field>--> </q-field>-->
<div :class="`q-mx-sm text-blue-14`">{{ order.quantity }}</div> <div v-if="order.quantity > 0" :class="`q-mx-sm text-blue-14`">{{ order.quantity + order.quantitypreordered }}</div>
<q-btn v-if="showall && !nomodif" round size="xs" text-color="grey" icon="fas fa-plus" <q-btn v-if="showall && !nomodif" round size="xs" text-color="grey" icon="fas fa-plus"
@click="addsubqty(true, false)"></q-btn> @click="addsubqty(true, false)"></q-btn>
</div> </div>
</div> </div>
<div class="col-2 no-wrap text-subtitle3 q-mr-sm"> <div class="col-2 no-wrap text-subtitle3 q-mr-sm">
<div v-if="isApplicatoSconto()"> <div v-if="isApplicatoSconto()">
<span class="ordine_scontato_barrato">&nbsp; {{ (order.price * order.quantity).toFixed(2) }}</span> <span class="ordine_scontato_barrato">&nbsp; {{ ((order.price * order.quantity) + (order.price * order.quantitypreordered)).toFixed(2) }}</span>
</div> </div>
&nbsp;{{ order.TotalPriceProduct ? order.TotalPriceProduct.toFixed(2) : 0 }} &nbsp;{{ order.TotalPriceProduct ? order.TotalPriceProduct.toFixed(2) : 0 }}
</div> </div>

View File

@@ -51,7 +51,7 @@ export default function () {
if (!!arrcart) { if (!!arrcart) {
if (!!arrcart.items) { if (!!arrcart.items) {
// @ts-ignore // @ts-ignore
const total = arrcart.items.reduce((sum, item) => sum + item.order.quantity, 0) const total = arrcart.items.reduce((sum, item) => sum + item.order.quantity + item.order.quantitypreordered , 0)
return total return total
} }
} }

View File

@@ -22,8 +22,11 @@ export interface IProduct {
color?: string, color?: string,
size?: string, size?: string,
quantityAvailable?: number, quantityAvailable?: number,
bookableAvailableQty?: number,
QuantitaOrdinateInAttesa?: number, QuantitaOrdinateInAttesa?: number,
stockQty?: number, QuantitaPrenotateInAttesa?: number,
stockQty: number,
bookableQty: number,
canBeShipped?: boolean, canBeShipped?: boolean,
canBeBuyOnline?: boolean, canBeBuyOnline?: boolean,
weight?: number, weight?: number,
@@ -54,6 +57,7 @@ export interface IOrder {
color?: string color?: string
size?: string size?: string
quantity: number quantity: number
quantitypreordered: number
weight?: number weight?: number
stars?: number stars?: number
product?: IProduct product?: IProduct

View File

@@ -62,6 +62,8 @@ const msg_it = {
quantity: 'Quantità', quantity: 'Quantità',
quantityAvailable: 'Disponibili', quantityAvailable: 'Disponibili',
stockQty: 'In Magazzino', stockQty: 'In Magazzino',
bookableQty: 'Prenotabili',
bookableAvailableQty: 'Disponib. Prenotabili',
weight: 'Peso', weight: 'Peso',
unit: 'Unità di Misura', unit: 'Unità di Misura',
stars: 'Voto', stars: 'Voto',
@@ -1661,6 +1663,7 @@ const msg_it = {
carrello: 'Carrello', carrello: 'Carrello',
settings: 'Impostazioni', settings: 'Impostazioni',
qta_in_attesa: '(Ordinati In attesa {qty})', qta_in_attesa: '(Ordinati In attesa {qty})',
qta_prenotate_in_attesa: '(Preordinate In attesa {qty})',
}, },
}, },

View File

@@ -1999,11 +1999,21 @@ export const colTableProducts = [
label_trans: 'products.quantityAvailable', label_trans: 'products.quantityAvailable',
fieldtype: costanti.FieldType.number fieldtype: costanti.FieldType.number
}), }),
AddCol({
name: 'bookableAvailableQty',
label_trans: 'products.bookableAvailableQty',
fieldtype: costanti.FieldType.number
}),
AddCol({ AddCol({
name: 'stockQty', name: 'stockQty',
label_trans: 'products.stockQty', label_trans: 'products.stockQty',
fieldtype: costanti.FieldType.number fieldtype: costanti.FieldType.number
}), }),
AddCol({
name: 'bookableQty',
label_trans: 'products.bookableQty',
fieldtype: costanti.FieldType.number
}),
AddCol({ name: 'canBeShipped', label_trans: 'products.canBeShipped', fieldtype: costanti.FieldType.boolean }), AddCol({ name: 'canBeShipped', label_trans: 'products.canBeShipped', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'canBeBuyOnline', label_trans: 'products.canBeBuyOnline', fieldtype: costanti.FieldType.boolean }), AddCol({ name: 'canBeBuyOnline', label_trans: 'products.canBeBuyOnline', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'weight', label_trans: 'products.weight', fieldtype: costanti.FieldType.number }), AddCol({ name: 'weight', label_trans: 'products.weight', fieldtype: costanti.FieldType.number }),

View File

@@ -8270,6 +8270,7 @@ export const tools = {
}, },
// FINE ! // FINE !
// getLocale() { // getLocale() {

View File

@@ -30,6 +30,17 @@ export const useProducts = defineStore('Products', {
const indelem = state.products.findIndex((prod: IProduct) => prod._id === res.data.product._id) const indelem = state.products.findIndex((prod: IProduct) => prod._id === res.data.product._id)
if (indelem >= 0) { if (indelem >= 0) {
state.products[indelem] = { ...res.data.product } state.products[indelem] = { ...res.data.product }
/*if (!res.data.orders) {
// aggiorna anche tutti i product negli ordini !
let ordcart: IOrderCart
for (ordcart of state.orders) {
for (const item of ordcart.items!) {
if (item.order.idProduct === res.data.product.idProduct)
item.order.product = res.data.product
}
}
}*/
} }
} }
if (res && res.data.orders) { if (res && res.data.orders) {
@@ -44,7 +55,10 @@ export const useProducts = defineStore('Products', {
getProduct: (state: IProductsState) => (code: string): IProduct => { getProduct: (state: IProductsState) => (code: string): IProduct => {
const prod = state.products.find((prod: IProduct) => prod.code === code) const prod = state.products.find((prod: IProduct) => prod.code === code)
return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0 } return prod ? prod : {
active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0,
stockQty: 0, bookableQty: 0
}
}, },
getCart: (state: IProductsState) => (): ICart => { getCart: (state: IProductsState) => (): ICart => {
@@ -115,7 +129,7 @@ export const useProducts = defineStore('Products', {
for (const item of myord.items) { for (const item of myord.items) {
if (item.order) { if (item.order) {
if (item.order.idProduct === idproduct) { if (item.order.idProduct === idproduct) {
totalQuantity += item.order.quantity || 0; totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0;
} }
} }
} }
@@ -146,7 +160,7 @@ export const useProducts = defineStore('Products', {
return [] return []
}, },
updateQuantityAvailable: (state: IProductsState) => (id: string): any => { /* updateQuantityAvailable: (state: IProductsState) => (id: string): any => {
const indelem = state.products.findIndex((prod: IProduct) => prod._id === id) const indelem = state.products.findIndex((prod: IProduct) => prod._id === id)
if (indelem >= 0) { if (indelem >= 0) {
@@ -154,9 +168,14 @@ export const useProducts = defineStore('Products', {
if (state.products[indelem].QuantitaOrdinateInAttesa! > 0) { if (state.products[indelem].QuantitaOrdinateInAttesa! > 0) {
state.products[indelem].quantityAvailable! -= state.products[indelem].QuantitaOrdinateInAttesa! state.products[indelem].quantityAvailable! -= state.products[indelem].QuantitaOrdinateInAttesa!
} }
state.products[indelem].bookableAvailableQty = state.products[indelem].bookableQty
if (state.products[indelem].QuantitaPrenotateInAttesa! > 0) {
state.products[indelem].bookableAvailableQty! -= state.products[indelem].QuantitaPrenotateInAttesa!
}
} }
}, },*/
getRecordEmpty: (state: IProductsState) => (): IProduct => { getRecordEmpty: (state: IProductsState) => (): IProduct => {
const tomorrow = tools.getDateNow() const tomorrow = tools.getDateNow()
@@ -182,9 +201,12 @@ export const useProducts = defineStore('Products', {
color: '', color: '',
size: '', size: '',
quantityAvailable: 0, quantityAvailable: 0,
bookableAvailableQty: 0,
stockQty: 0, stockQty: 0,
bookableQty: 0,
canBeShipped: false, canBeShipped: false,
QuantitaOrdinateInAttesa: 0, QuantitaOrdinateInAttesa: 0,
QuantitaPrenotateInAttesa: 0,
canBeBuyOnline: false, canBeBuyOnline: false,
weight: 0, weight: 0,
unit: 0, unit: 0,
@@ -218,6 +240,7 @@ export const useProducts = defineStore('Products', {
weight: product.weight, weight: product.weight,
quantity: order.quantity, quantity: order.quantity,
quantitypreordered: order.quantitypreordered,
idStorehouse: order.idStorehouse, idStorehouse: order.idStorehouse,
idScontisticas: product.idScontisticas, idScontisticas: product.idScontisticas,
} }
@@ -388,12 +411,13 @@ export const useProducts = defineStore('Products', {
const ordcart = this.getOrderProductInCart(product._id) const ordcart = this.getOrderProductInCart(product._id)
if (ordcart) { if (ordcart) {
if (!addqty && ordcart.quantity === 1) { if (!addqty && ((ordcart.quantity + ordcart.quantitypreordered) === 1)) {
// sto per rimuovere l'ultimo pezzo, quindi cancello direttamente // sto per rimuovere l'ultimo pezzo, quindi cancello direttamente
const risrem = await this.removeFromCart({ order: ordcart }) const risrem = await this.removeFromCart({ order: ordcart })
if (risrem) { if (risrem) {
order.quantity = 0 order.quantity = 0
order.quantitypreordered = 0
return true return true
} else { } else {
return false return false
@@ -406,14 +430,22 @@ export const useProducts = defineStore('Products', {
order: ordcart, order: ordcart,
}).then((res: any) => { }).then((res: any) => {
if (res && res.risult) { if (res && res.risult) {
order.quantity = res.qty order.quantity = res.myord.quantity
order.quantitypreordered = res.myord.quantitypreordered
} }
return res; return res;
}) })
} }
} else { } else {
if (order.quantity === 0) if (this.isQtyAvailableByProduct(product)) {
order.quantitypreordered = 0
order.quantity = 1 order.quantity = 1
} else {
if (this.isInPreorderByProduct(product)) {
order.quantity = 0
order.quantitypreordered = 1
}
}
neworder = this.createOrderByProduct(product, order) neworder = this.createOrderByProduct(product, order)
} }
@@ -434,7 +466,7 @@ export const useProducts = defineStore('Products', {
} }
this.updateDataProduct(res) this.updateDataProduct(res)
return { risult: !!res, qty: order.quantity } return { risult: !!res }
}) })
.catch((error) => { .catch((error) => {
console.log('error addToCart', error) console.log('error addToCart', error)
@@ -463,7 +495,7 @@ export const useProducts = defineStore('Products', {
.then((res) => { .then((res) => {
this.updateDataProduct(res) this.updateDataProduct(res)
return { risult: !!res, qty: res.data.qty } return { risult: !!res, myord: res.data.myord }
}) })
.catch((error) => { .catch((error) => {
console.log('error addSubQtyToItem', error) console.log('error addSubQtyToItem', error)
@@ -562,6 +594,47 @@ export const useProducts = defineStore('Products', {
return ris return ris
}, },
getQuantityByOrder(order: IOrder): string {
let mystr = '';
if (order.quantity > 0) {
mystr += order.quantity
}
if (order.quantitypreordered > 0) {
mystr += ' Prenotata :' + order.quantitypreordered
}
return mystr
},
isQtyAvailableByProduct(product: IProduct): boolean {
if (product) {
return (product.quantityAvailable! > 0)
}
return false;
},
isInPreorderByProduct(product: IProduct): boolean {
if (product) {
return (product.bookableAvailableQty! > 0)
}
return false;
},
isQtyAvailableByOrder(order: IOrder): boolean {
if (order && order.product) {
return this.isQtyAvailableByProduct(order.product)
}
return false;
},
isInPreorderByOrder(order: IOrder): boolean {
if (order && order.product) {
return this.isInPreorderByProduct(order.product)
}
return false;
},
}, },
}) })

View File

@@ -312,6 +312,7 @@ export default defineComponent({
getCols, getCols,
endload, endload,
getOrdersCartWithTotals, getOrdersCartWithTotals,
productStore,
} }
} }
}) })

View File

@@ -57,7 +57,7 @@
v-if="!!item && item.order && item.order.product" v-if="!!item && item.order && item.order.product"
> >
{{ item.order.product.name }} ({{ {{ item.order.product.name }} ({{
item.order.quantity productStore.getQuantityByOrder(item.order)
}})<br /> }})<br />
</div> </div>
</div> </div>
@@ -141,7 +141,7 @@
<div v-for="(item, index) of props.row.items" :key="index"> <div v-for="(item, index) of props.row.items" :key="index">
<div v-if="!!item.order && item.order.product"> <div v-if="!!item.order && item.order.product">
{{ item.order.product.name }} ({{ {{ item.order.product.name }} ({{
item.order.quantity productStore.getQuantityByOrder(item.order)
}})<br /> }})<br />
</div> </div>
</div> </div>