处理数量、单价、金额之间的计算
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(),
|
||||
|
||||
Reference in New Issue
Block a user