处理数量、单价、金额之间的计算
This commit is contained in:
@@ -114,23 +114,26 @@ class ReceiptViewModel @Inject constructor(
|
||||
*/
|
||||
fun updateSelectedItem(purchaseOrder: GoodsInfo?) {
|
||||
if (purchaseOrder != null) {
|
||||
purchaseOrder.receivedNum.takeIf { it != 0f }?.let { receivedNum ->
|
||||
// 计算金额 单价不为空,并且金额没有手动输入
|
||||
// if (purchaseOrder.recUnitPriceTaxIn != null && purchaseOrder.recUnitPriceTaxIn == 0f && !_amountUserInput.value) {
|
||||
if (purchaseOrder.recUnitPriceTaxIn != null && !_amountUserInput.value) {
|
||||
if (purchaseOrder.receivedNum != null && purchaseOrder.receivedNum != 0f) {
|
||||
if (purchaseOrder.recUnitPriceTaxInTemp.isNotEmpty()) { // 计算金额 单价不为空,并且金额没有手动输入
|
||||
val result =
|
||||
receivedNum.times(purchaseOrder.recUnitPriceTaxIn!!)
|
||||
purchaseOrder.receivedNum!!.times(purchaseOrder.recUnitPriceTaxIn!!)
|
||||
purchaseOrder.recPriceExItem = result.toSafeFloat()
|
||||
purchaseOrder.recPriceExItemTemp = result.toFormattedString()
|
||||
}
|
||||
// 计算单价 金额不为空,并且单价没有手动输入
|
||||
// if (purchaseOrder.recPriceExItem != null && purchaseOrder.recPriceExItem == 0f && !_priceUserInput.value) {
|
||||
if (purchaseOrder.recPriceExItem != null && !_priceUserInput.value) {
|
||||
} else if (purchaseOrder.recPriceExItemTemp.isNotEmpty()) { // 计算单价 金额不为空,并且单价没有手动输入
|
||||
val result =
|
||||
purchaseOrder.recPriceExItem!!.div(receivedNum)
|
||||
purchaseOrder.recPriceExItem!!.div(purchaseOrder.receivedNum!!)
|
||||
purchaseOrder.recUnitPriceTaxIn = result.toSafeFloat()
|
||||
purchaseOrder.recUnitPriceTaxInTemp = result.toFormattedString()
|
||||
}
|
||||
} else {
|
||||
if (_priceUserInput.value) {
|
||||
purchaseOrder.recPriceExItem = 0f
|
||||
purchaseOrder.recPriceExItemTemp = ""
|
||||
} else if (_amountUserInput.value) {
|
||||
purchaseOrder.recUnitPriceTaxIn = 0f
|
||||
purchaseOrder.recUnitPriceTaxInTemp = ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_countUserInput.value = false
|
||||
@@ -254,31 +257,35 @@ class ReceiptViewModel @Inject constructor(
|
||||
val finalCount = count.toSafeFloat(currentItem.unitName)
|
||||
Timber.d("startSensorScale weight = $weight, count = $count, finalCount = $finalCount, consumeValue = $consumeValue, purchaseValue = $purchaseValue")
|
||||
// 计算单价
|
||||
val finalPrice = if (count == 0.0) {
|
||||
0f
|
||||
} else if (!_countUserInput.value && !_priceUserInput.value) {
|
||||
if (info.recPriceExItemTemp.isNotEmpty()) {
|
||||
val finalPrice = when {
|
||||
count == 0.0 -> {
|
||||
0f
|
||||
}
|
||||
|
||||
_amountUserInput.value && !_priceUserInput.value -> {
|
||||
info.recPriceExItem!!.div(count).toSafeFloat()
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
} else info.recUnitPriceTaxIn ?: 0f
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
// 计算金额
|
||||
val finalAmount = if (count == 0.0) {
|
||||
0f
|
||||
} else if (!_countUserInput.value && !_amountUserInput.value) {
|
||||
if (info.recUnitPriceTaxInTemp.isNotEmpty()) {
|
||||
count.times(info.recUnitPriceTaxIn!!).toSafeFloat()
|
||||
} else {
|
||||
val finalAmount = when {
|
||||
count == 0.0 -> {
|
||||
0f
|
||||
}
|
||||
} else info.recPriceExItem ?: 0f
|
||||
|
||||
_priceUserInput.value && !_amountUserInput.value -> {
|
||||
count.times(info.recUnitPriceTaxIn!!).toSafeFloat()
|
||||
}
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
|
||||
_selectedItem.value = info.copy(
|
||||
goodsWeight = weight.toSafeBigDecimal(),
|
||||
// 收货数量
|
||||
receivedNumTemp = if (_countUserInput.value) info.receivedNumTemp else count.toFormattedString(),
|
||||
receivedNum = if (_countUserInput.value) info.receivedNum else finalCount,
|
||||
receivedNumTemp = count.toFormattedString(),
|
||||
receivedNum = finalCount,
|
||||
// 单价
|
||||
recUnitPriceTaxIn = if (_priceUserInput.value) info.recUnitPriceTaxIn else finalPrice,
|
||||
recUnitPriceTaxInTemp = if (_priceUserInput.value) info.recUnitPriceTaxInTemp else finalPrice.toFormattedString(),
|
||||
|
||||
@@ -113,31 +113,23 @@ class SelfProcurementViewModel @Inject constructor(
|
||||
val finalPrice =
|
||||
if (count == 0.0) {
|
||||
0.0
|
||||
} else if (!_countUserInput.value && !_priceUserInput.value) {
|
||||
if (info.goodsPriceTemp.isNotEmpty()) {
|
||||
info.goodsPrice.div(count).toSafeDouble()
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
} else info.goodsUnitPrice
|
||||
} else if (_amountUserInput.value && !_priceUserInput.value) {
|
||||
info.goodsPrice.div(count).toSafeDouble()
|
||||
} else 0.0
|
||||
|
||||
// 计算金额 单价不为空,不是数量输入 也不是金额输入
|
||||
val finalAmount =
|
||||
if (count == 0.0) {
|
||||
0.0
|
||||
} else if (!_countUserInput.value && !_amountUserInput.value) {
|
||||
if (info.goodsUnitPriceTemp.isNotEmpty()) {
|
||||
count.times(info.goodsUnitPrice).toSafeDouble()
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
} else info.goodsPrice
|
||||
} else if (_priceUserInput.value && !_amountUserInput.value) {
|
||||
count.times(info.goodsUnitPrice).toSafeDouble()
|
||||
} else 0.0
|
||||
Timber.d("startSensorScale finalPrice = $finalPrice, finalAmount = $finalAmount ")
|
||||
_selectedItem.value = info.copy(
|
||||
goodsWeight = weight.toSafeBigDecimal(),
|
||||
// 数量
|
||||
goodsCountTemp = if (_countUserInput.value) info.goodsCountTemp else finalCount.toFormattedString(),
|
||||
goodsCount = if (_countUserInput.value) info.goodsCount else finalCount,
|
||||
goodsCountTemp = finalCount.toFormattedString(),
|
||||
goodsCount = finalCount,
|
||||
// 单价
|
||||
goodsUnitPrice = if (_priceUserInput.value) info.goodsUnitPrice else finalPrice,
|
||||
goodsUnitPriceTemp = if (_priceUserInput.value) info.goodsUnitPriceTemp else finalPrice.toFormattedString(),
|
||||
@@ -160,25 +152,28 @@ class SelfProcurementViewModel @Inject constructor(
|
||||
|
||||
fun updateSelectedItem(purchaseOrder: PurchaseWarehouseParam?) {
|
||||
if (purchaseOrder != null) {
|
||||
purchaseOrder.goodsCount.takeIf { it != 0.0 }?.let { receivedNum ->
|
||||
// 计算金额 单价不为空,并且金额没有手动输入
|
||||
// if (purchaseOrder.goodsUnitPrice == 0.0 && !_amountUserInput.value) {
|
||||
if (!_amountUserInput.value) {
|
||||
if (purchaseOrder.goodsCount != 0.0) {
|
||||
if (purchaseOrder.goodsUnitPriceTemp.isNotEmpty()) { // 计算金额 单价不为空,并且金额没有手动输入
|
||||
Timber.d("updateSelectedItem 计算金额")
|
||||
val result =
|
||||
receivedNum.times(purchaseOrder.goodsUnitPrice)
|
||||
purchaseOrder.goodsCount.times(purchaseOrder.goodsUnitPrice)
|
||||
purchaseOrder.goodsPrice = result.toSafeDouble()
|
||||
purchaseOrder.goodsPriceTemp = result.toFormattedString()
|
||||
}
|
||||
// 计算单价 金额不为空,并且单价没有手动输入
|
||||
// if (purchaseOrder.goodsPrice == 0.0 && !_priceUserInput.value) {
|
||||
if (!_priceUserInput.value) {
|
||||
} else if (purchaseOrder.goodsPriceTemp.isNotEmpty()) { // 计算单价 金额不为空,并且单价没有手动输入
|
||||
Timber.d("updateSelectedItem 计算单价")
|
||||
val result =
|
||||
purchaseOrder.goodsPrice.div(receivedNum)
|
||||
purchaseOrder.goodsPrice.div(purchaseOrder.goodsCount)
|
||||
purchaseOrder.goodsUnitPrice = result.toSafeDouble()
|
||||
purchaseOrder.goodsUnitPriceTemp = result.toFormattedString()
|
||||
}
|
||||
} else {
|
||||
if (_priceUserInput.value) {
|
||||
purchaseOrder.goodsPrice = 0.0
|
||||
purchaseOrder.goodsPriceTemp = ""
|
||||
} else if (_amountUserInput.value) {
|
||||
purchaseOrder.goodsUnitPrice = 0.0
|
||||
purchaseOrder.goodsUnitPriceTemp = ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 重置输入状态
|
||||
|
||||
Reference in New Issue
Block a user