Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -400,7 +400,68 @@ export const useOrderEntryStore = defineStore('orderentry', {
|
||||
}
|
||||
,
|
||||
|
||||
async sendOrderToMarketMails(orderId) {
|
||||
buildMailLineLabel(line) {
|
||||
if (!line || typeof line !== 'object') return ''
|
||||
|
||||
const item = String(line.ItemCode || '').trim()
|
||||
const color1 = String(line.ColorCode || '').trim()
|
||||
const color2 = String(line.ItemDim2Code || '').trim()
|
||||
const desc = String(line.LineDescription || '').trim()
|
||||
|
||||
if (!item) return ''
|
||||
|
||||
const colorPart = color2 ? `${color1}-${color2}` : color1
|
||||
return [item, colorPart, desc].filter(Boolean).join(' ')
|
||||
}
|
||||
,
|
||||
|
||||
buildOrderMailPayload(lines = [], isNew = false) {
|
||||
const uniq = (arr) => [...new Set((arr || []).map(v => String(v || '').trim()).filter(Boolean))]
|
||||
|
||||
const normalized = Array.isArray(lines) ? lines : []
|
||||
const mapLabel = (ln) => this.buildMailLineLabel(ln)
|
||||
|
||||
if (isNew) {
|
||||
return {
|
||||
operation: 'create',
|
||||
deletedItems: [],
|
||||
updatedItems: [],
|
||||
addedItems: uniq(
|
||||
normalized
|
||||
.filter(ln => !ln?._deleteSignal)
|
||||
.map(mapLabel)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const deletedItems = uniq(
|
||||
normalized
|
||||
.filter(ln => ln?._deleteSignal === true)
|
||||
.map(mapLabel)
|
||||
)
|
||||
|
||||
const updatedItems = uniq(
|
||||
normalized
|
||||
.filter(ln => !ln?._deleteSignal && !!ln?.OrderLineID && ln?._dirty === true)
|
||||
.map(mapLabel)
|
||||
)
|
||||
|
||||
const addedItems = uniq(
|
||||
normalized
|
||||
.filter(ln => !ln?._deleteSignal && !ln?.OrderLineID)
|
||||
.map(mapLabel)
|
||||
)
|
||||
|
||||
return {
|
||||
operation: 'update',
|
||||
deletedItems,
|
||||
updatedItems,
|
||||
addedItems
|
||||
}
|
||||
}
|
||||
,
|
||||
|
||||
async sendOrderToMarketMails(orderId, payload = {}) {
|
||||
const id = String(orderId || this.header?.OrderHeaderID || '').trim()
|
||||
if (!id) {
|
||||
throw new Error('Sipariş ID bulunamadı')
|
||||
@@ -408,7 +469,11 @@ export const useOrderEntryStore = defineStore('orderentry', {
|
||||
|
||||
try {
|
||||
const res = await api.post('/order/send-market-mail', {
|
||||
orderHeaderID: id
|
||||
orderHeaderID: id,
|
||||
operation: payload?.operation || 'create',
|
||||
deletedItems: Array.isArray(payload?.deletedItems) ? payload.deletedItems : [],
|
||||
updatedItems: Array.isArray(payload?.updatedItems) ? payload.updatedItems : [],
|
||||
addedItems: Array.isArray(payload?.addedItems) ? payload.addedItems : []
|
||||
})
|
||||
return res?.data || {}
|
||||
} catch (err) {
|
||||
@@ -2867,7 +2932,8 @@ export const useOrderEntryStore = defineStore('orderentry', {
|
||||
|
||||
// 📧 Piyasa eşleşen alıcılara sipariş PDF gönderimi (kayıt başarılı olduktan sonra)
|
||||
try {
|
||||
const mailRes = await this.sendOrderToMarketMails(serverOrderId)
|
||||
const mailPayload = this.buildOrderMailPayload(lines, isNew)
|
||||
const mailRes = await this.sendOrderToMarketMails(serverOrderId, mailPayload)
|
||||
const sentCount = Number(mailRes?.sentCount || 0)
|
||||
$q.notify({
|
||||
type: 'positive',
|
||||
|
||||
Reference in New Issue
Block a user