Aggiornamento modifiche preOrdini

This commit is contained in:
Surya Paolo
2023-12-20 22:11:52 +01:00
16 changed files with 211 additions and 107 deletions

View File

@@ -10,17 +10,15 @@
</q-btn> </q-btn>
</div> </div>
<div class="col-6" style="text-align: right"> <div class="col-6" style="text-align: right">
<span v-if="myTotalPrice" class="text-grey q-mr-xs">Totale:</span> <span <span v-if="myTotalPrice" class="text-grey q-mr-xs">Totale:</span> <span class="text-subtitle1 q-mr-sm "> {{
class="text-subtitle1 q-mr-sm "> {{ myTotalPrice ? myTotalPrice.toFixed(2) : 0 }}</span> myTotalPrice ? myTotalPrice.toFixed(2) : 0 }}</span>
</div> </div>
</div> </div>
<q-separator></q-separator> <q-separator></q-separator>
<div id="mybody"> <div id="mybody">
<div v-for="(rec, index) in ordersCart" :key="index" class="col"> <div v-for="(rec, index) in ordersCart" :key="index" class="col">
<CSingleCart <CSingleCart :order="rec.order" :showall="false">
:order="rec.order"
:showall="false">
</CSingleCart> </CSingleCart>
</div> </div>
@@ -29,10 +27,13 @@
{{ $t('ecomm.carrello_vuoto') }} {{ $t('ecomm.carrello_vuoto') }}
</div> </div>
<div v-else style="text-align: center"> <div v-else style="text-align: center">
<q-btn <div class="text-center">
rounded icon="fas fa-shopping-cart" color="green" :label="$t('ecomm.btn_cassa')" class="q-mb-sm" to="/checkout" <q-btn rounded icon="fas fa-shopping-cart" color="primary" :label="$t('ecomm.btn_cassa')"
@click="closecart"></q-btn> class="q-mb-sm" to="/checkout">
</q-btn>
</div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>

View File

@@ -6,15 +6,20 @@
font-size: 0.9rem; font-size: 0.9rem;
} }
.centeritems{ .centeritems {
place-content: center; place-content: center;
} }
.prod_price{ .prod_price {
font-size: 1.25rem; font-size: 1.25rem;
} }
.prod_disp{ .prod_disp {
font-size: 1.2rem;
}
.prod_preorder{
font-size: 1.2rem; font-size: 1.2rem;
} }
@@ -22,13 +27,13 @@
font-size: 1.2rem; font-size: 1.2rem;
} }
.prod_qtywarn{ .prod_qtywarn {
padding-left: 10px; padding-left: 10px;
font-size: 1rem; font-size: 1rem;
color: grey; color: grey;
} }
.totali{ .totali {
font-weight: bold; font-weight: bold;
font-size: 1.2rem; font-size: 1.2rem;
} }
@@ -37,3 +42,8 @@
font-size: 1.1rem; font-size: 1.1rem;
color: blue; color: blue;
} }
.product_code {
font-size: 0.75rem;
color: gray;
}

View File

@@ -79,7 +79,7 @@ export default defineComponent({
return 'fas fa-heart' return 'fas fa-heart'
} }
} }
function addtoCart(add: boolean) { async function addtoCart(add: boolean) {
if (!userStore.isLogged) { if (!userStore.isLogged) {
tools.showNeutralNotif($q, t('ecomm.area_personale')) tools.showNeutralNotif($q, t('ecomm.area_personale'))
@@ -87,40 +87,7 @@ export default defineComponent({
return false return false
} }
await products.addtoCartBase({ $q, t, code: myproduct.value.code!, order: myorder, addqty: add })
if (myproduct.value) {
products.addToCart({ product: myproduct.value, order: myorder, addqty: add }).then((ris: any) => {
let strprod = t('ecomm.prodotto')
let msg = ''
console.log('ris', ris)
if (ris === null || ris.myord == null) {
msg = t('ecomm.error_cart')
tools.showNegativeNotif($q, msg)
return
} else {
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()
if (ris === null || ris.myord.quantity === 0)
tools.showNotif($q, msg)
else
tools.showPositiveNotif($q, msg)
})
}
} }
function getnumstore() { function getnumstore() {
@@ -146,7 +113,7 @@ export default defineComponent({
} }
function updateproduct() { function updateproduct() {
myproduct.value = products.getProduct(props.code) myproduct.value = products.getProductByCode(props.code)
// products.updateQuantityAvailable(myproduct.value._id) // products.updateQuantityAvailable(myproduct.value._id)
} }
@@ -214,7 +181,7 @@ export default defineComponent({
// console.log('Load', myproduct.value.name) // console.log('Load', myproduct.value.name)
// console.log('created Cproductcard', code) // console.log('created Cproductcard', code)
arrordersCart.value = products.getOrdersCartByIdProduct(myproduct.value._id) arrordersCart.value = products.getOrdersCartInAttesaByIdProduct(myproduct.value._id)
if (!!myproduct.value) { if (!!myproduct.value) {
if (myproduct.value.storehouses && myproduct.value.storehouses.length === 1) { if (myproduct.value.storehouses && myproduct.value.storehouses.length === 1) {
@@ -246,7 +213,7 @@ export default defineComponent({
} }
function enableAddQty() { function enableAddQty() {
if (site.value.ecomm!.enablePreOrders) { if (site.value.ecomm && site.value.ecomm.enablePreOrders) {
return true return true
} else { } else {
return getQtyAvailable() > 0 return getQtyAvailable() > 0

View File

@@ -25,6 +25,9 @@
<div class="text-h7 boldhigh"> <div class="text-h7 boldhigh">
{{ myproduct.name }} {{ myproduct.name }}
</div> </div>
<div class="product_code">
&nbsp; {{$t('ecomm.codice')}}: {{ myproduct.code }}
</div>
</div> </div>
</q-item> </q-item>
<q-item> <q-item>

View File

@@ -15,7 +15,19 @@
width: 50px; width: 50px;
} }
.ordine_scontato_barrato{ .ordine_scontato{
text-decoration: line-through;
color: gray; color: gray;
font-size: 0.85rem;
}
.barrato {
text-decoration: line-through;
}
.ordine_scontato_nuovo{
font-size: 1.1rem;
font-weight: bold;
}
.ordine_scritta_sconto{
font-style: italic;
color: green;
font-weight: bold;
} }

View File

@@ -89,11 +89,16 @@ export default defineComponent({
products.removeFromCart({ order: order.value }) products.removeFromCart({ order: order.value })
} }
function getRisparmio(): string {
return ((order.value.price * order.value.quantity) - order.value.TotalPriceProduct).toFixed(2)
}
return { return {
myimgclass, myimgclass,
addsubqty, addsubqty,
removeFromCard, removeFromCard,
isApplicatoSconto, isApplicatoSconto,
getRisparmio,
} }
}, },
}) })

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="q-pa-xs q-gutter-xs"> <div v-if="order && order.product" class="q-pa-xs q-gutter-xs">
<div v-if="order.product" class="row items-center justify-evenly no-wrap"> <div v-if="order.product" class="row items-center justify-evenly no-wrap">
<div class="col-2 text-h6 ellipsis"> <div class="col-2 text-h6 ellipsis">
@@ -27,11 +27,12 @@
@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_short q-mr-sm">
<div v-if="isApplicatoSconto()"> <span :class="isApplicatoSconto() ? 'ordine_scontato_nuovo' : ''">&nbsp;{{ order.TotalPriceProduct ? order.TotalPriceProduct.toFixed(2) : 0 }}</span>
<span class="ordine_scontato_barrato">&nbsp; {{ ((order.price * order.quantity) + (order.price * order.quantitypreordered)).toFixed(2) }}</span> <span v-if="isApplicatoSconto()">
</div> &nbsp;<span class="ordine_scontato">(<span class="barrato"> {{((order.price * order.quantity) + (order.price * order.quantitypreordered)).toFixed(2) }}</span>)</span>&nbsp;
&nbsp;{{ order.TotalPriceProduct ? order.TotalPriceProduct.toFixed(2) : 0 }} </span>
<span v-if="isApplicatoSconto()" class="ordine_scritta_sconto">{{ $t('ecomm.sconto_applicato', {risparmio: getRisparmio()}) }}</span>
</div> </div>
<div class="col-1"> <div class="col-1">
<q-btn v-if="!nomodif" icon="fas fa-times" color="negative" round size="xs" @click="removeFromCard"> <q-btn v-if="!nomodif" icon="fas fa-times" color="negative" round size="xs" @click="removeFromCard">

View File

@@ -263,6 +263,13 @@ h3 {
letter-spacing: .00937em; letter-spacing: .00937em;
} }
.text-subtitle3_short {
font-size: 1rem;
font-weight: 400;
line-height: 1.25rem;
letter-spacing: .00937em;
}
.text-3d { .text-3d {
letter-spacing: .00937em; letter-spacing: .00937em;
font-size: 1rem; font-size: 1rem;

View File

@@ -45,12 +45,11 @@ export default function () {
return '' return ''
} }
function getnumItemsCart(): any { function getnumItemsCart(): number {
const products = useProducts() const products = useProducts()
const arrcart = products.cart const arrcart = products.cart
if (!!arrcart) { if (!!arrcart) {
if (!!arrcart.items) { if (!!arrcart.items) {
// @ts-ignore
const total = arrcart.items.reduce((sum, item) => sum + item.order.quantity + item.order.quantitypreordered , 0) const total = arrcart.items.reduce((sum, item) => sum + item.order.quantity + item.order.quantitypreordered , 0)
return total return total
} }

View File

@@ -258,6 +258,9 @@ const msg_it = {
}, },
db: { db: {
recupdated: 'Record Aggiornato', recupdated: 'Record Aggiornato',
records_imported: '{num} Record Importati',
records_updated: '{num} Record Aggiornati',
records_errors: '{num} Record con Errori',
recfailed: 'Errore durante aggiornamento Record', recfailed: 'Errore durante aggiornamento Record',
reccanceled: 'Annullato Aggiornamento. Ripristinato valore precendente', reccanceled: 'Annullato Aggiornamento. Ripristinato valore precendente',
deleterecord: 'Elimina Record', deleterecord: 'Elimina Record',
@@ -1663,6 +1666,10 @@ 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})',
sconto_applicato: 'Risparmi {risparmio} € !',
codice: 'Codice',
code_o_text_search: 'Inserisci il codice o il testo',
code_add_to_cart: 'Aggiungi un codice al carrello',
qta_prenotate_in_attesa: '(Preordinate In attesa {qty})', qta_prenotate_in_attesa: '(Preordinate In attesa {qty})',
}, },
}, },

View File

@@ -53,7 +53,12 @@ export const useProducts = defineStore('Products', {
}, },
getProduct: (state: IProductsState) => (code: string): IProduct => { getProductById: (state: IProductsState) => (id: string): IProduct => {
const prod = state.products.find((prod: IProduct) => prod._id === id)
return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0, stockQty: 0, bookableQty: 0 }
},
getProductByCode: (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 : { return prod ? prod : {
active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0, active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0,
@@ -128,7 +133,7 @@ export const useProducts = defineStore('Products', {
if (myord.items) { if (myord.items) {
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) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) {
totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0; totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0;
} }
} }
@@ -141,14 +146,32 @@ export const useProducts = defineStore('Products', {
}, },
getOrdersCartByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => { getOrdersCartByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => {
// console.log('getOrdersCartByIdProduct')
// console.log('.cart.items', this.cart.items)
try { try {
if (state.orders) { if (state.orders) {
const ris = state.orders.filter((ordercart: IOrderCart) => { const ris = state.orders.filter((ordercart: IOrderCart) => {
return ordercart.items!.some(item => { return ordercart.items!.some(item => {
if (item.order) if (item.order)
return item.order.idProduct === idproduct return (item.order.idProduct === idproduct)
&& (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)
})
})
// console.log('Ordini ', ris)
return ris ? ris : []
}
} catch (e) {
console.error('Err', e)
}
return []
},
getOrdersCartInAttesaByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => {
try {
if (state.orders) {
const ris = state.orders.filter((ordercart: IOrderCart) => {
return ordercart.items!.some(item => {
if (item.order)
return (item.order.idProduct === idproduct)
&& (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)
}) })
}) })
// console.log('Ordini ', ris) // console.log('Ordini ', ris)
@@ -447,11 +470,22 @@ export const useProducts = defineStore('Products', {
} }
} }
neworder = this.createOrderByProduct(product, order)
if (!order.idStorehouse) {
if (product.storehouses.length === 1) {
order.idStorehouse = product.storehouses[0]._id
} else {
order.idStorehouse = globalStore.storehouses ? globalStore.storehouses[0]._id : ''
}
}
if (order.idStorehouse) {
neworder = this.createOrderByProduct(product, order)
}
} }
if (neworder && !neworder.idStorehouse) // if (neworder && !neworder.idStorehouse)
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store') // return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store')
console.log('addToCart', 'userid=', userStore.my._id, neworder) console.log('addToCart', 'userid=', userStore.my._id, neworder)
@@ -594,6 +628,41 @@ export const useProducts = defineStore('Products', {
return ris return ris
}, },
async addtoCartBase({ $q, t, code, order, addqty }: { $q: any, t: any, code: string, order: IOrder, addqty: boolean }) {
let product = this.getProductByCode(code)
return this.addToCart({ product, order, addqty }).then((ris) => {
let strprod = t('ecomm.prodotto')
let msg = ''
console.log('ris', ris)
if (ris === null || ris.myord == null) {
msg = t('ecomm.error_cart')
tools.showNegativeNotif($q, msg)
return
} else {
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()
if (ris === null || ris.myord.quantity === 0)
tools.showNotif($q, msg)
else
tools.showPositiveNotif($q, msg)
})
},
getQuantityByOrder(order: IOrder): string { getQuantityByOrder(order: IOrder): string {
let mystr = ''; let mystr = '';
@@ -605,36 +674,6 @@ export const useProducts = defineStore('Products', {
} }
return mystr 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

@@ -1754,9 +1754,23 @@ export const useUserStore = defineStore('UserStore', {
async importToServerCmd($q: any, t: any, cmd: number, data: any) { async importToServerCmd($q: any, t: any, cmd: number, data: any) {
return Api.SendReq('/admin/import', 'POST', { cmd, data }) return Api.SendReq('/admin/import', 'POST', { cmd, data })
.then((res) => { .then((res: any) => {
if (res) { if (res) {
tools.showPositiveNotif($q, t('db.recupdated')) let msg = ''
if (res.data.imported) {
msg += ' ' + t('db.records_imported', {num: res.data.imported})
}
if (res.data.errors) {
msg += ' ' + t('db.records_errors', {num: res.data.errors})
}
if (res.data.updated) {
msg += ' ' + t('db.records_updated', {num: res.data.updated})
}
if (!msg) {
msg = t('db.recupdated')
}
tools.showPositiveNotif($q, msg)
} }
}).catch((error) => { }).catch((error) => {
tools.showNegativeNotif($q, t('db.recfailed')) tools.showNegativeNotif($q, t('db.recfailed'))

View File

@@ -3,3 +3,6 @@ $heightBtn: 100%;
.card .product-image { .card .product-image {
height: 300px; height: 300px;
} }
.insert{
cursor:pointer;
}

View File

@@ -8,7 +8,7 @@ import { useI18n } from '@/boot/i18n'
import { toolsext } from '@store/Modules/toolsext' import { toolsext } from '@store/Modules/toolsext'
import { useQuasar } from 'quasar' import { useQuasar } from 'quasar'
import { costanti } from '@costanti' import { costanti } from '@costanti'
import { ICart, IOrderCart, IShareWithUs } from '@src/model/Products' import { ICart, IOrder, IOrderCart, IShareWithUs } from '@src/model/Products'
import { shared_consts } from '@src/common/shared_vuejs' import { shared_consts } from '@src/common/shared_vuejs'
@@ -34,6 +34,8 @@ export default defineComponent({
const endload = ref(false) const endload = ref(false)
const recOrderCart = ref(<IOrderCart>{}) const recOrderCart = ref(<IOrderCart>{})
const search = ref('')
const statusnow = computed(() => (): number => { const statusnow = computed(() => (): number => {
if (recOrderCart.value) { if (recOrderCart.value) {
return recOrderCart.value.status return recOrderCart.value.status
@@ -176,6 +178,17 @@ export default defineComponent({
}) })
} }
async function insertArticolo() {
let lowerSearchText = search.value.trim();
const myprod = productStore.getProductByCode(lowerSearchText);
if (myprod && myprod.active) {
let myorder: IOrder = { quantity: 1, price: 0, TotalPriceProduct: 0 }
await productStore.addtoCartBase({ $q, t, code: myprod.code!, order: myorder, addqty: true })
search.value = ''
load()
}
}
onMounted(mounted) onMounted(mounted)
@@ -197,6 +210,8 @@ export default defineComponent({
recOrderCart, recOrderCart,
mycart, mycart,
endload, endload,
search,
insertArticolo,
} }
} }
}) })

View File

@@ -55,6 +55,27 @@
<div v-else style="text-align: center" class="text-grey"> <div v-else style="text-align: center" class="text-grey">
{{ $t('ecomm.carrello_vuoto') }} {{ $t('ecomm.carrello_vuoto') }}
</div> </div>
<br >
<div
class="q-gutter-y-md column text-center q-mx-auto"
style="width: 350px; max-width: 100%"
>
<q-input
filled
stack-label
dense
:label="$t('ecomm.code_add_to_cart')"
v-model="search"
class="q-ml-md"
@keyup.enter="insertArticolo()"
>
<template v-slot:append>
<q-icon class="insert" name="fas fa-shopping-cart" color="green" @click="insertArticolo()"/>
</template>
</q-input>
</div>
</div> </div>
</q-page> </q-page>
</template> </template>

View File

@@ -9,7 +9,7 @@
<q-input <q-input
filled filled
stack-label stack-label
label="Inserisci il codice o il testo" :label="$t('ecomm.code_o_text_search')"
v-model="search" v-model="search"
class="q-ml-md" class="q-ml-md"
> >