@@ -242,8 +242,8 @@ module.exports = async ({ appSdk, storeId, auth }, orderId, opts = {}) => {
242242 throw err
243243 } )
244244 let isAllImportedItems = true
245- const discount = order . amount ?. discount || 0
246- const discountForProduct = discount ? ( discount / order . items . length ) : 0
245+ const amountDiscount = order . amount ?. discount || 0
246+ const amountSubtotal = order . amount ?. subtotal
247247 order . items ?. forEach ( ( item ) => {
248248 if ( item . sku . startsWith ( 'COD_ITEM' ) ) {
249249 const codItem = item . sku . replace ( 'COD_ITEM' , '' )
@@ -263,13 +263,12 @@ module.exports = async ({ appSdk, storeId, auth }, orderId, opts = {}) => {
263263 // console.log(`QTD_PEDIDA: ${body?.QTD_PEDIDA} itemHorus ${itemHorus?.QTD_PEDIDA} itemOrder: ${item?.quantity}`)
264264
265265 if ( isImportItem ) {
266- const discountItem = discountForProduct ? ( discountForProduct / item . quantity ) : 0
266+ const itemDiscount = amountSubtotal > 0 ? vlrBruto * amountDiscount / amountSubtotal : 0
267267 isAllImportedItems = false
268-
269- const vlrItem = parsePrice ( vlrBruto - discountItem )
270- subtotal += vlrItem * ( item . quantity || 1 )
268+ const vlrItem = parsePrice ( vlrBruto - itemDiscount )
269+ subtotal += ( vlrItem * ( item . quantity || 1 ) )
271270 body . VLR_LIQUIDO = vlrItem
272- console . log ( `>> vlrBruto: ${ vlrBruto } discount: ${ discountItem } total: ${ vlrItem } ` )
271+ console . log ( `>> vlrBruto: ${ vlrBruto } discount: ${ itemDiscount } total: ${ vlrItem } ` )
273272
274273 const params = new url . URLSearchParams ( body )
275274 const endpoint = `/InsItensPedidoVenda?${ params . toString ( ) } `
@@ -326,15 +325,6 @@ module.exports = async ({ appSdk, storeId, auth }, orderId, opts = {}) => {
326325 const paymentMethodCode = transaction && transaction . payment_method . code
327326 subtotal += subtotal ? ( amount . freight || 0 ) : 0
328327
329- /*
330- let vlr = subtotal || amount.total
331- let qnt = 1
332- if (transaction.installments) {
333- const { number } = transaction.installments
334- qnt = number
335- vlr = (subtotal || amount.total) / number
336- }
337- */
338328 const body = {
339329 COD_EMPRESA : companyCode ,
340330 COD_FILIAL : subsidiaryCode ,
0 commit comments