1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-13 23:20:12 +08:00

support for payment methods (#578)

This commit is contained in:
Elsio Sanchez 2021-02-03 00:35:27 -04:00 committed by GitHub
parent d83b109aef
commit 60223ecc14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 382 additions and 54 deletions

View File

@ -6,6 +6,7 @@ import {
/** /**
* method in api/price-checking.js as requestGetProductPrice * method in api/price-checking.js as requestGetProductPrice
* @author elsiosanchez <elsiosanches@gmail.com>
*/ */
export { requestGetProductPrice as findProduct } from '@/api/ADempiere/form/price-checking.js' export { requestGetProductPrice as findProduct } from '@/api/ADempiere/form/price-checking.js'
export { requestGetConversionRate } from '@/api/ADempiere/system-core.js' export { requestGetConversionRate } from '@/api/ADempiere/system-core.js'
@ -435,3 +436,110 @@ export function requestCashClosing({
}) { }) {
console.info(`Cash closing with POS id ${posId}, and uuid ${posUuid}`) console.info(`Cash closing with POS id ${posId}, and uuid ${posUuid}`)
} }
// Create Payment
export function requestCreatePayment({
posUuid,
orderUuid,
invoiceUuid,
bankUuid,
referenceNo,
description,
amount,
paymentDate,
tenderTypeCode,
currencyUuid
}) {
return requestRest({
url: '/pos/create-payment',
data: {
pos_uuid: posUuid,
order_uuid: orderUuid,
invoice_uuid: invoiceUuid,
bank_uuid: bankUuid,
reference_no: referenceNo,
description: description,
amount: amount,
payment_date: paymentDate,
tender_type_code: tenderTypeCode,
currency_uuid: currencyUuid
}
})
.then(evaluateResponse)
.then(createPaymentResponse => {
return createPaymentResponse
})
}
// Update Payment
export function requestUpdatePayment({
paymentUuid,
bankUuid,
referenceNo,
description,
amount,
paymentDate,
tenderTypeCode
}) {
return requestRest({
url: '/pos/update-payment',
data: {
payment_uuid: paymentUuid,
bank_uuid: bankUuid,
reference_no: referenceNo,
description: description,
amount: amount,
payment_date: paymentDate,
tender_type_code: tenderTypeCode
}
})
.then(evaluateResponse)
.then(updatePaymentResponse => {
return updatePaymentResponse
})
}
// Delete Payment
export function requestDeletePayment({
paymentUuid
}) {
return requestRest({
url: '/pos/delete-payment',
data: {
payment_uuid: paymentUuid
}
})
.then(evaluateResponse)
.then(deletePaymentResponse => {
return deletePaymentResponse
})
}
// List Payments
export function requestListPayments({
posUuid,
orderUuid
}) {
return requestRest({
url: '/pos/list-payments',
data: {
pos_uuid: posUuid,
order_uuid: orderUuid
}
})
.then(evaluateResponse)
.then(listPaymentsResponse => {
const { paymentsMethod } = require('@/utils/ADempiere/apiConverts/pos.js')
return {
nextPageToken: listPaymentsResponse.next_page_token,
recordCount: listPaymentsResponse.record_count,
listPayments: listPaymentsResponse.records.map(payments => {
return paymentsMethod(payments)
})
}
})
}

View File

@ -81,7 +81,7 @@
<el-main style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;"> <el-main style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">
<type-collection <type-collection
v-if="isLoaded" v-if="isLoaded"
:is-add-type-pay="paymentBox" :is-add-type-pay="listPayments"
:currency="currencyPoint" :currency="currencyPoint"
/> />
<div <div
@ -264,6 +264,9 @@ export default {
} }
return false return false
}, },
listPayments() {
return this.$store.getters.getListPayments
},
paymentBox() { paymentBox() {
const payment = this.isPaymentBox.filter(pay => { const payment = this.isPaymentBox.filter(pay => {
return pay.isVisible return pay.isVisible
@ -274,8 +277,8 @@ export default {
return payment return payment
}, },
cashPayment() { cashPayment() {
const cash = this.isPaymentBox.filter(pay => { const cash = this.listPayments.filter(pay => {
return pay.tenderType === 'X' return pay.tenderTypeCode === 'X'
}) })
return this.sumCash(cash) return this.sumCash(cash)
}, },
@ -319,9 +322,9 @@ export default {
return false return false
}, },
isCashAmt() { isCashAmt() {
const cashAmt = this.paymentBox.map(item => { const cashAmt = this.listPayments.map(item => {
if (item.tenderType === 'X') { if (item.tenderTypeCode === 'X') {
return item.payAmt return item.amount
} }
return 0 return 0
}) })
@ -331,8 +334,8 @@ export default {
return 0 return 0
}, },
isOtherPayAmt() { isOtherPayAmt() {
const cashAmt = this.paymentBox.map(item => { const cashAmt = this.listPayments.map(item => {
if (item.tenderType !== 'X') { if (item.tenderTypeCode !== 'X') {
return item.payAmt return item.payAmt
} }
return 0 return 0
@ -343,7 +346,7 @@ export default {
return 0 return 0
}, },
pay() { pay() {
return this.sumCash(this.isPaymentBox) return this.sumCash(this.listPayments)
}, },
pending() { pending() {
const missing = this.order.grandTotal - this.pay const missing = this.order.grandTotal - this.pay
@ -517,13 +520,18 @@ export default {
this.unsubscribe = this.subscribeChanges() this.unsubscribe = this.subscribeChanges()
this.defaultValueCurrency() this.defaultValueCurrency()
}, },
mounted() {
setTimeout(() => {
this.tenderTypeDisplaye()
}, 1000)
},
methods: { methods: {
formatDate, formatDate,
formatPrice, formatPrice,
sumCash(cash) { sumCash(cash) {
let sum = 0 let sum = 0
cash.forEach((pay) => { cash.forEach((pay) => {
sum += pay.payAmt sum += pay.amount
}) })
return sum return sum
}, },
@ -533,15 +541,21 @@ export default {
}, },
addCollectToList() { addCollectToList() {
const containerUuid = this.containerUuid const containerUuid = this.containerUuid
const posUuid = this.$store.getters.getCurrentPOS.uuid
const orderUuid = this.$route.query.action
const bankUuid = this.$store.getters.getValueOfField({
containerUuid,
columnName: 'C_Bank_ID_UUID'
})
const amount = this.$store.getters.getValueOfField({ const amount = this.$store.getters.getValueOfField({
containerUuid, containerUuid,
columnName: 'PayAmt' columnName: 'PayAmt'
}) })
const date = this.$store.getters.getValueOfField({ const paymentDate = this.$store.getters.getValueOfField({
containerUuid, containerUuid,
columnName: 'DateTrx' columnName: 'DateTrx'
}) })
const typePay = this.$store.getters.getValueOfField({ const tenderTypeCode = this.$store.getters.getValueOfField({
containerUuid, containerUuid,
columnName: 'TenderType' columnName: 'TenderType'
}) })
@ -549,31 +563,20 @@ export default {
containerUuid, containerUuid,
columnName: 'ReferenceNo' columnName: 'ReferenceNo'
}) })
let currency = this.$store.getters.getValueOfField({ const currencyUuid = this.$store.getters.getValueOfField({
containerUuid, containerUuid,
columnName: 'DisplayColumn_C_Currency_ID' columnName: 'C_Currency_ID_UUID'
}) })
const currencyId = this.$store.getters.getValueOfField({
containerUuid,
columnName: 'C_Currency_ID'
})
if (currency === this.currencyPoint.id) {
currency = this.currencyPoint.iSOCode
}
const displayType = this.labelTenderType this.$store.dispatch('createPayments', {
this.$store.dispatch('setPaymentBox', { posUuid,
isVisible: true, orderUuid,
quantityCahs: amount, bankUuid,
payAmt: amount * this.divideRate, referenceNo,
tenderType: typePay, amount,
referenceNo: referenceNo, paymentDate,
dateTrx: date, tenderTypeCode,
currency: { currencyUuid
currency,
id: currencyId
},
displayTenderType: displayType
}) })
this.addCollect() this.addCollect()
}, },
@ -690,6 +693,18 @@ export default {
value: this.$t('form.pos.collect.TenderType.cash') value: this.$t('form.pos.collect.TenderType.cash')
}) })
}, },
tenderTypeDisplaye() {
if (!this.isEmptyValue(this.fieldsList)) {
const tenderType = this.fieldsList[1].reference
this.$store.dispatch('getLookupListFromServer', {
tableName: tenderType.tableName,
query: tenderType.query
})
.then(response => {
this.$store.dispatch('tenderTypeDisplaye', response)
})
}
},
subscribeChanges() { subscribeChanges() {
return this.$store.subscribe((mutation, state) => { return this.$store.subscribe((mutation, state) => {
if (mutation.type === 'updateValueOfField') { if (mutation.type === 'updateValueOfField') {

View File

@ -3,7 +3,7 @@
<el-main style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;"> <el-main style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">
<el-row :gutter="24"> <el-row :gutter="24">
<template v-for="(value, key) in isAddTypePay"> <template v-for="(value, key) in isAddTypePay">
<el-col v-if="value.isVisible" :key="key" :span="12" style="padding-left: 5px; padding-right: 5px;"> <el-col :key="key" :span="12" style="padding-left: 5px; padding-right: 5px;">
<el-card :body-style="{ padding: '0px' }"> <el-card :body-style="{ padding: '0px' }">
<el-row> <el-row>
<el-col :span="6" style="padding: 10px"> <el-col :span="6" style="padding: 10px">
@ -14,11 +14,11 @@
type="text" type="text"
icon="el-icon-close" icon="el-icon-close"
style="float: right; margin-right: 10px; color: red; padding-top: 10px;" style="float: right; margin-right: 10px; color: red; padding-top: 10px;"
@click="deleteCollect(key)" @click="deleteCollect(value)"
/> />
<div style="padding-right: 10px; padding-top: 10%;"> <div style="padding-right: 10px; padding-top: 10%;">
<div class="top clearfix"> <div class="top clearfix">
<span>{{ value.displayTenderType }}</span> <span>{{ tenderTypeDisplay(value.tenderTypeCode) }}</span>
</div> </div>
<div class="bottom clearfix" style="margin-top: 0px !important!"> <div class="bottom clearfix" style="margin-top: 0px !important!">
<el-button <el-button
@ -26,28 +26,28 @@
class="button" class="button"
style="color: rgb(50, 54, 58); font-size: 13px; text-align: left; float: unset; padding-top: 5px;" style="color: rgb(50, 54, 58); font-size: 13px; text-align: left; float: unset; padding-top: 5px;"
> >
{{ value.referenceNo }} {{ value.documentNo }}
</el-button> </el-button>
<el-button <el-button
v-if="!isEmptyValue(value.dateTrx)" v-if="!isEmptyValue(value.paymentDate)"
type="text" type="text"
class="button" class="button"
style="color: rgb(50, 54, 58); font-size: 13px; text-align: left; float: unset; padding-top: 5px;" style="color: rgb(50, 54, 58); font-size: 13px; text-align: left; float: unset; padding-top: 5px;"
> >
{{ formatDate(value.dateTrx) }} {{ formatDate(value.paymentDate) }}
</el-button> </el-button>
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
<p class="total" :style="value.currency.id === currency.id ? 'padding-top: 5%;' : ''"> <p class="total" :style="value.currencyUuid === currency.id ? 'padding-top: 5%;' : ''">
<b style="float: right; padding-bottom: 10px"> <b style="float: right; padding-bottom: 10px">
{{ formatPrice(value.payAmt, currency.iSOCode) }} {{ formatPrice(value.amount, currency.iSOCode) }}
</b> </b>
</p> </p>
<br> <br>
<p v-if="value.currency.id !== currency.id" class="total"> <p v-if="value.currencyUuid !== currency.id" class="total">
<b style="float: right; padding-bottom: 10px"> <b style="float: right; padding-bottom: 10px">
{{ formatPrice(value.quantityCahs, value.currency.currency) }} {{ formatPrice(value.quantityCahs) }}
</b> </b>
</p> </p>
</div> </div>
@ -81,6 +81,11 @@ export default {
default: undefined default: undefined
} }
}, },
computed: {
label() {
return this.$store.getters.getTenderTypeDisplaye
}
},
methods: { methods: {
formatDate, formatDate,
formatPrice, formatPrice,
@ -127,7 +132,23 @@ export default {
return require('@/image/' + image + '.jpg') return require('@/image/' + image + '.jpg')
}, },
deleteCollect(key) { deleteCollect(key) {
this.$store.dispatch('deleteCollectBox', key) const orderUuid = key.orderUuid
const paymentUuid = key.uuid
this.$store.dispatch('deletetPayments', {
orderUuid,
paymentUuid
})
},
tenderTypeDisplay(payments) {
const display = this.label.find(item => {
if (item.tenderTypeCode === payments) {
return item.tenderTypeDisplay
}
})
if (display) {
return display.tenderTypeDisplay
}
return payments
} }
} }
} }

View File

@ -393,7 +393,9 @@ export default {
// documentStatus: {}, // documentStatus: {},
// salesRepresentative: this.currentPOS.salesRepresentative // salesRepresentative: this.currentPOS.salesRepresentative
// //
this.$store.commit('setListPayments', [])
this.$store.dispatch('listOrderLine', []) this.$store.dispatch('listOrderLine', [])
this.$store.commit('setShowPOSCollection', false)
}) })
}, },
printOrder() { printOrder() {

View File

@ -450,8 +450,13 @@ export default {
this.newOrder() this.newOrder()
}, },
openCollectionPanel() { openCollectionPanel() {
this.isShowedPOSKeyLayout = !this.isShowedPOSKeyLayout
this.$store.commit('setShowPOSCollection', true) this.$store.commit('setShowPOSCollection', true)
this.isShowedPOSKeyLayout = true // this.isShowedPOSKeyLayout = true
const posUuid = this.$store.getters.getCurrentPOS.uuid
const orderUuid = this.$route.query.action
this.$store.dispatch('listPayments', { posUuid, orderUuid })
this.isShowedPOSKeyLaout = !this.isShowedPOSKeyLaout
this.$store.commit('setShowPOSOptions', false) this.$store.commit('setShowPOSOptions', false)
}, },
newOrder() { newOrder() {

View File

@ -249,6 +249,9 @@ export default {
action: row.uuid action: row.uuid
} }
}, () => {}) }, () => {})
const posUuid = this.$store.getters.getCurrentPOS.uuid
const orderUuid = this.$route.query.action
this.$store.dispatch('listPayments', { posUuid, orderUuid })
} }
}, },
subscribeChanges() { subscribeChanges() {

View File

@ -1,5 +1,11 @@
import { requestGetConversionRate } from '@/api/ADempiere/form/point-of-sales.js' import {
requestGetConversionRate,
requestCreatePayment,
requestDeletePayment,
requestUpdatePayment,
requestListPayments
} from '@/api/ADempiere/form/point-of-sales.js'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js' import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { showMessage } from '@/utils/ADempiere/notification.js' import { showMessage } from '@/utils/ADempiere/notification.js'
@ -9,7 +15,9 @@ const collection = {
multiplyRate: 1, multiplyRate: 1,
divideRate: 1, divideRate: 1,
multiplyRateCollection: 1, multiplyRateCollection: 1,
divideRateCollection: 1 divideRateCollection: 1,
listPayments: [],
tenderTypeDisplaye: []
}, },
mutations: { mutations: {
addPaymentBox(state, paymentBox) { addPaymentBox(state, paymentBox) {
@ -26,27 +34,51 @@ const collection = {
}, },
currencyDivideRateCollection(state, divideRateCollection) { currencyDivideRateCollection(state, divideRateCollection) {
state.divideRateCollection = divideRateCollection state.divideRateCollection = divideRateCollection
},
setListPayments(state, list) {
state.listPayments = list
},
setTenderTypeDisplaye(state, tenderTypeDisplaye) {
state.tenderTypeDisplaye = tenderTypeDisplaye
} }
}, },
actions: { actions: {
/** /**
* creating boxes with the payment list * creating boxes with the payment list
*/ */
setPaymentBox({ state, commit, getters }, params) { setPaymentBox({ state, commit, getters }, {
quantityCahs,
bankUuid,
referenceNo,
description,
amount,
paymentDate,
tenderTypeCode,
currencyUuid
}) {
const payments = getters.getPaymentBox.find(element => { const payments = getters.getPaymentBox.find(element => {
if (params.tenderType === 'X' && element.currency.id === params.currency.id) { if (tenderTypeCode === 'X' && element.currencyUuid === currencyUuid) {
return element return element
} }
}) })
if (isEmptyValue(payments)) { if (isEmptyValue(payments)) {
commit('addPaymentBox', params) commit('addPaymentBox', {
quantityCahs,
bankUuid,
referenceNo,
description,
amount,
paymentDate,
tenderTypeCode,
currencyUuid
})
} else { } else {
const addPayment = getters.getPaymentBox.map(item => { const addPayment = getters.getPaymentBox.map(item => {
if ((item.tenderType === params.tenderType) && item.currency.id === params.currency.id) { if ((item.tenderTypeCode === tenderTypeCode) && item.currencyUuid === currencyUuid) {
return { return {
...item, ...item,
payAmt: item.payAmt + params.payAmt, payAmt: item.amount + amount,
quantityCahs: item.quantityCahs + params.quantityCahs quantityCahs: item.quantityCahs + quantityCahs
} }
} }
return item return item
@ -120,6 +152,121 @@ const collection = {
}, },
changeDivideRate({ commit }, divideRate) { changeDivideRate({ commit }, divideRate) {
commit('currencyDivideRate', divideRate) commit('currencyDivideRate', divideRate)
},
createPayments({ dispatch, state, getters }, {
posUuid,
orderUuid,
invoiceUuid,
bankUuid,
referenceNo,
description,
amount,
paymentDate,
tenderTypeCode,
currencyUuid
}) {
const listPayments = getters.getListPayments.find(payment => {
if ((payment.tenderTypeCode === tenderTypeCode) && (payment.tenderTypeCode === 'X') && (currencyUuid === payment.currencyUuid)) {
return payment
}
return undefined
})
if (isEmptyValue(listPayments)) {
requestCreatePayment({
posUuid,
orderUuid,
invoiceUuid,
bankUuid,
referenceNo,
description,
amount,
paymentDate,
tenderTypeCode,
currencyUuid
})
.then(response => {
const orderUuid = response.order_uuid
dispatch('listPayments', { orderUuid })
})
.catch(error => {
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
showMessage({
type: 'error',
message: error.message,
showClose: true
})
})
} else {
requestUpdatePayment({
paymentUuid: listPayments.uuid,
bankUuid,
referenceNo,
description,
amount: listPayments.amount + amount,
paymentDate,
tenderTypeCode
})
.then(response => {
const orderUuid = response.order_uuid
dispatch('listPayments', { orderUuid })
})
.catch(error => {
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
showMessage({
type: 'error',
message: error.message,
showClose: true
})
})
}
},
deletetPayments({ dispatch }, {
orderUuid,
paymentUuid
}) {
console.log(paymentUuid, orderUuid)
requestDeletePayment({
paymentUuid
})
.then(response => {
console.log(response.listPayments)
dispatch('listPayments', { orderUuid })
})
.catch(error => {
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
showMessage({
type: 'error',
message: error.message,
showClose: true
})
})
},
listPayments({ commit }, { posUuid, orderUuid }) {
requestListPayments({
posUuid,
orderUuid
})
.then(response => {
console.log(response.listPayments)
commit('setListPayments', response.listPayments)
})
.catch(error => {
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
showMessage({
type: 'error',
message: error.message,
showClose: true
})
})
},
tenderTypeDisplaye({ commit }, tenderType) {
const displayTenderType = tenderType.map(item => {
return {
tenderTypeCode: item.id,
tenderTypeDisplay: item.label
}
})
commit('setTenderTypeDisplaye', displayTenderType)
} }
}, },
getters: { getters: {
@ -137,6 +284,13 @@ const collection = {
}, },
getDivideRateCollection: (state) => { getDivideRateCollection: (state) => {
return state.divideRateCollection return state.divideRateCollection
},
getListPayments: (state) => {
console.log(state.listPayments)
return state.listPayments
},
getTenderTypeDisplaye: (state) => {
return state.tenderTypeDisplaye
} }
} }
} }

View File

@ -136,3 +136,23 @@ export function convertResourceReference(resourceReferenceToConvert) {
} }
return undefined return undefined
} }
export function paymentsMethod(payments) {
if (payments) {
return {
amount: payments.amount,
bankUuid: payments.bank_uuid,
businessPartner: payments.business_partner,
currencyUuid: payments.currency_uuid,
description: payments.description,
documentNo: payments.document_no,
documentStatus: payments.document_status,
id: payments.id,
orderUuid: payments.order_uuid,
paymentDate: payments.payment_date,
referenceNo: payments.reference_no,
tenderTypeCode: payments.tender_type_code,
uuid: payments.uuid
}
}
return undefined
}