出入库功能改版
This commit is contained in:
@@ -5,6 +5,7 @@ import com.sw.inbound.ext.toFormattedString
|
||||
import com.sw.inbound.ext.toSafeBigDecimal
|
||||
import com.sw.inbound.ext.toSafeDouble
|
||||
import com.sw.inbound.ext.toSafeFloat
|
||||
import com.sw.inbound.model.request.PurchaseWarehouseParam
|
||||
import com.sw.inbound.model.request.UploadInfo
|
||||
import com.sw.inbound.model.response.DictType
|
||||
import com.sw.inbound.model.response.GoodsInfo
|
||||
@@ -99,11 +100,11 @@ class ReceiptViewModel @Inject constructor(
|
||||
_showReceiptDialog.value = showDialog
|
||||
}
|
||||
|
||||
fun updateSelectedItemWithSwitch(purchaseOrder: GoodsInfo?) {
|
||||
viewModelScope.launch {
|
||||
updateSelectedItem(purchaseOrder)
|
||||
}
|
||||
}
|
||||
// fun updateSelectedItemWithSwitch(purchaseOrder: GoodsInfo?) {
|
||||
// viewModelScope.launch {
|
||||
// updateSelectedItem(purchaseOrder)
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun handleIdentityItem(goodsInfo: SearchGoodsInfo.Record) {
|
||||
val firstItem = unadjustedOrders.value.find { order ->
|
||||
@@ -118,41 +119,42 @@ class ReceiptViewModel @Inject constructor(
|
||||
/**
|
||||
* 更新选中的item
|
||||
*/
|
||||
fun updateSelectedItem(purchaseOrder: GoodsInfo?) {
|
||||
if (purchaseOrder != null) {
|
||||
if (purchaseOrder.receivedNum != null && purchaseOrder.receivedNum != 0f) {
|
||||
if (purchaseOrder.newRecUnitPriceTaxInTemp.isNotEmpty()) { // 计算金额 单价不为空,并且金额没有手动输入
|
||||
val result =
|
||||
purchaseOrder.receivedNum!!.times(purchaseOrder.newRecUnitPriceTaxIn!!)
|
||||
purchaseOrder.recPriceExItem = result.toSafeFloat()
|
||||
purchaseOrder.recPriceExItemTemp = result.toFormattedString()
|
||||
} else if (purchaseOrder.recPriceExItemTemp.isNotEmpty()) { // 计算单价 金额不为空,并且单价没有手动输入
|
||||
val result =
|
||||
purchaseOrder.recPriceExItem!!.div(purchaseOrder.receivedNum!!)
|
||||
purchaseOrder.newRecUnitPriceTaxIn = result.toSafeFloat()
|
||||
purchaseOrder.newRecUnitPriceTaxInTemp = result.toFormattedString()
|
||||
}
|
||||
} else {
|
||||
if (_priceUserInput.value) {
|
||||
purchaseOrder.recPriceExItem = 0f
|
||||
purchaseOrder.recPriceExItemTemp = ""
|
||||
} else if (_amountUserInput.value) {
|
||||
purchaseOrder.newRecUnitPriceTaxIn = 0f
|
||||
purchaseOrder.newRecUnitPriceTaxInTemp = ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_countUserInput.value = false
|
||||
_priceUserInput.value = false
|
||||
_amountUserInput.value = false
|
||||
}
|
||||
_selectedItem.value = purchaseOrder
|
||||
}
|
||||
// fun updateSelectedItem(purchaseOrder: GoodsInfo?) {
|
||||
// if (purchaseOrder != null) {
|
||||
// if (purchaseOrder.receivedNum != null && purchaseOrder.receivedNum != 0f) {
|
||||
// if (purchaseOrder.newRecUnitPriceTaxInTemp.isNotEmpty()) { // 计算金额 单价不为空,并且金额没有手动输入
|
||||
// val result =
|
||||
// purchaseOrder.receivedNum!!.times(purchaseOrder.newRecUnitPriceTaxIn!!)
|
||||
// purchaseOrder.recPriceExItem = result.toSafeFloat()
|
||||
// purchaseOrder.recPriceExItemTemp = result.toFormattedString()
|
||||
// } else if (purchaseOrder.recPriceExItemTemp.isNotEmpty()) { // 计算单价 金额不为空,并且单价没有手动输入
|
||||
// val result =
|
||||
// purchaseOrder.recPriceExItem!!.div(purchaseOrder.receivedNum!!)
|
||||
// purchaseOrder.newRecUnitPriceTaxIn = result.toSafeFloat()
|
||||
// purchaseOrder.newRecUnitPriceTaxInTemp = result.toFormattedString()
|
||||
// }
|
||||
// } else {
|
||||
// if (_priceUserInput.value) {
|
||||
// purchaseOrder.recPriceExItem = 0f
|
||||
// purchaseOrder.recPriceExItemTemp = ""
|
||||
// } else if (_amountUserInput.value) {
|
||||
// purchaseOrder.newRecUnitPriceTaxIn = 0f
|
||||
// purchaseOrder.newRecUnitPriceTaxInTemp = ""
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// _countUserInput.value = false
|
||||
// _priceUserInput.value = false
|
||||
// _amountUserInput.value = false
|
||||
// }
|
||||
// _selectedItem.value = purchaseOrder
|
||||
// }
|
||||
|
||||
fun getReceiveDetail(id: Int) {
|
||||
fun getReceiveDetail(id: String, action:(PurchaseInfo?)->Unit = {}) {
|
||||
launchWithLoading {
|
||||
val response = repository.getReceiveDetail(id)
|
||||
if (parseResponse(response)) {
|
||||
action(response.result)
|
||||
_currentPurchaseInfo.value = response.result
|
||||
initOrders()
|
||||
}
|
||||
@@ -199,23 +201,23 @@ class ReceiptViewModel @Inject constructor(
|
||||
/**
|
||||
* 更新所有商品仓库
|
||||
*/
|
||||
fun updateAllPurchaseStore(warehouse: DictType, predicate: (GoodsInfo) -> Boolean = { true }) {
|
||||
_orders.update { currentList ->
|
||||
currentList.map { order ->
|
||||
if (predicate(order)) order.copy(
|
||||
warehouseId = warehouse.id,
|
||||
warehouseName = warehouse.value
|
||||
) else order
|
||||
}
|
||||
}
|
||||
}
|
||||
// fun updateAllPurchaseStore(warehouse: DictType, predicate: (GoodsInfo) -> Boolean = { true }) {
|
||||
// _orders.update { currentList ->
|
||||
// currentList.map { order ->
|
||||
// if (predicate(order)) order.copy(
|
||||
// warehouseId = warehouse.id,
|
||||
// warehouseName = warehouse.value
|
||||
// ) else order
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 删除订单
|
||||
fun removePurchaseOrder(orderId: Int) {
|
||||
_orders.update { current ->
|
||||
current.filterNot { it.goodId == orderId }
|
||||
}
|
||||
}
|
||||
// fun removePurchaseOrder(orderId: Int) {
|
||||
// _orders.update { current ->
|
||||
// current.filterNot { it.goodId == orderId }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 清空列表
|
||||
fun clearPurchaseOrders() {
|
||||
@@ -243,67 +245,72 @@ class ReceiptViewModel @Inject constructor(
|
||||
_amountUserInput.value = boolean
|
||||
}
|
||||
|
||||
private var weightCallback:((Int)->Unit)?=null
|
||||
fun readWeight(callback:(Int)->Unit) {
|
||||
weightCallback = callback
|
||||
}
|
||||
override fun handleSensorScale(weight: Double) {
|
||||
val currentItem = _selectedItem.value
|
||||
|
||||
currentItem?.let { info ->
|
||||
// 用户输入数量后不再通过重量反算
|
||||
if (_countUserInput.value) {
|
||||
_selectedItem.value = info.copy(
|
||||
goodsWeight = weight.toSafeBigDecimal(),
|
||||
)
|
||||
return
|
||||
}
|
||||
var consumeValue = currentItem.consumeValue?.toSafeDouble() ?: 1.0
|
||||
var purchaseValue = currentItem.purchaseValue?.toDouble() ?: 1.0
|
||||
if (consumeValue == 0.0) {
|
||||
consumeValue = 1.0
|
||||
}
|
||||
if (purchaseValue == 0.0) {
|
||||
purchaseValue = 1.0
|
||||
}
|
||||
val count =
|
||||
weight * 1000 / consumeValue / purchaseValue
|
||||
val finalCount = count.toSafeFloat(currentItem.unitName)
|
||||
Timber.d("startSensorScale weight = $weight, count = $count, finalCount = $finalCount, consumeValue = $consumeValue, purchaseValue = $purchaseValue")
|
||||
// 计算单价
|
||||
val finalPrice = when {
|
||||
finalCount == 0f -> {
|
||||
0f
|
||||
}
|
||||
|
||||
_amountUserInput.value && !_priceUserInput.value -> {
|
||||
info.recPriceExItem!!.div(finalCount).toSafeFloat()
|
||||
}
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
// 计算金额
|
||||
val finalAmount = when {
|
||||
finalCount == 0f -> {
|
||||
0f
|
||||
}
|
||||
|
||||
_priceUserInput.value && !_amountUserInput.value -> {
|
||||
finalCount.times(info.newRecUnitPriceTaxIn!!).toSafeFloat()
|
||||
}
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
|
||||
_selectedItem.value = info.copy(
|
||||
goodsWeight = weight.toSafeBigDecimal(),
|
||||
// 收货数量
|
||||
receivedNumTemp = finalCount.toFormattedString(),
|
||||
receivedNum = finalCount,
|
||||
// 单价
|
||||
newRecUnitPriceTaxIn = if (_priceUserInput.value) info.newRecUnitPriceTaxIn else finalPrice,
|
||||
newRecUnitPriceTaxInTemp = if (_priceUserInput.value) info.newRecUnitPriceTaxInTemp else finalPrice.toFormattedString(),
|
||||
// 金额
|
||||
recPriceExItem = if (_amountUserInput.value) info.recPriceExItem else finalAmount,
|
||||
recPriceExItemTemp = if (_amountUserInput.value) info.recPriceExItemTemp else finalAmount.toFormattedString(),
|
||||
)
|
||||
}
|
||||
weightCallback?.invoke((weight*1000).toInt())
|
||||
// val currentItem = _selectedItem.value
|
||||
//
|
||||
// currentItem?.let { info ->
|
||||
// // 用户输入数量后不再通过重量反算
|
||||
// if (_countUserInput.value) {
|
||||
// _selectedItem.value = info.copy(
|
||||
// goodsWeight = weight.toSafeBigDecimal(),
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
// var consumeValue = currentItem.consumeValue?.toSafeDouble() ?: 1.0
|
||||
// var purchaseValue = currentItem.purchaseValue?.toDouble() ?: 1.0
|
||||
// if (consumeValue == 0.0) {
|
||||
// consumeValue = 1.0
|
||||
// }
|
||||
// if (purchaseValue == 0.0) {
|
||||
// purchaseValue = 1.0
|
||||
// }
|
||||
// val count =
|
||||
// weight * 1000 / consumeValue / purchaseValue
|
||||
// val finalCount = count.toSafeFloat(currentItem.unitName)
|
||||
// Timber.d("startSensorScale weight = $weight, count = $count, finalCount = $finalCount, consumeValue = $consumeValue, purchaseValue = $purchaseValue")
|
||||
// // 计算单价
|
||||
// val finalPrice = when {
|
||||
// finalCount == 0f -> {
|
||||
// 0f
|
||||
// }
|
||||
//
|
||||
// _amountUserInput.value && !_priceUserInput.value -> {
|
||||
// info.recPriceExItem!!.div(finalCount).toSafeFloat()
|
||||
// }
|
||||
//
|
||||
// else -> 0f
|
||||
// }
|
||||
// // 计算金额
|
||||
// val finalAmount = when {
|
||||
// finalCount == 0f -> {
|
||||
// 0f
|
||||
// }
|
||||
//
|
||||
// _priceUserInput.value && !_amountUserInput.value -> {
|
||||
// finalCount.times(info.newRecUnitPriceTaxIn!!).toSafeFloat()
|
||||
// }
|
||||
//
|
||||
// else -> 0f
|
||||
// }
|
||||
//
|
||||
// _selectedItem.value = info.copy(
|
||||
// goodsWeight = weight.toSafeBigDecimal(),
|
||||
// // 收货数量
|
||||
// receivedNumTemp = finalCount.toFormattedString(),
|
||||
// receivedNum = finalCount,
|
||||
// // 单价
|
||||
// newRecUnitPriceTaxIn = if (_priceUserInput.value) info.newRecUnitPriceTaxIn else finalPrice,
|
||||
// newRecUnitPriceTaxInTemp = if (_priceUserInput.value) info.newRecUnitPriceTaxInTemp else finalPrice.toFormattedString(),
|
||||
// // 金额
|
||||
// recPriceExItem = if (_amountUserInput.value) info.recPriceExItem else finalAmount,
|
||||
// recPriceExItemTemp = if (_amountUserInput.value) info.recPriceExItemTemp else finalAmount.toFormattedString(),
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun partialReceipt(uploadInfo: UploadInfo) {
|
||||
@@ -325,4 +332,18 @@ class ReceiptViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun confirmReceipt(uploadInfo: UploadInfo, callback: (Boolean) -> Unit) {
|
||||
launchWithLoading {
|
||||
val resp = repository.confirmReceipt(uploadInfo)
|
||||
callback(resp.data == true)
|
||||
}
|
||||
}
|
||||
|
||||
fun addToWarehouse(list: List<PurchaseWarehouseParam>, callback: (Boolean) -> Unit) {
|
||||
launchWithLoading {
|
||||
val resp = repository.selfPurchaseWarehousing(list)
|
||||
callback(resp.data == true)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user