// nc-backend/preference/form/nc/nc-warehouse/parcel-convert.js
import { amountStock1ToStock2, amountStock2ToStock1 } from '/plugin/convert/product-convert.js'

// ObjectMethods/_lbOK.4dm converted
/* if (rec.amountPerParcel <= 0) {
  _errCry(_langCurrent("Please give amount per parcel"));
} else {
  acceptC269(); // Assuming ACCEPT:C269 is a function call
}
 */
// ObjectMethods/_lbReturn.4dm converted
// This file contains only a comment and a literal string, no conversion needed.
// Assuming _but RETURN is a button click or similar, it might need further handling in the JS context.
// For now, I'll leave a placeholder comment.
// Placeholder: Handle button RETURN click event

// ObjectMethods/stpa_add_rAmount.4dm converted
// Ignoring Case of statement
rec.remainingAmount = 0
if (rec.parcels != 0) {
	rec.amountPerParcel = rec.amount / rec.parcels
} else {
	rec.amountPerParcel = 0
}
amountStock1ToStock2() // stpa_add_AMOUNT1_TO_AMOUNT2() // Assuming this is a function call

// ObjectMethods/stpa_add_rAmount2.4dm converted
// Ignoring Case of statement
rec.remainingAmount2 = 0
if (rec.parcels != 0) {
	rec.amountPerParcel2 = rec.amount2 / rec.parcels
} else {
	rec.amountPerParcel2 = 0
}
amountStock2ToStock1() // stpa_add_AMOUNT2_TO_AMOUNT1() // Assuming this is a function call

// ObjectMethods/stpa_add_rAmountPerParcel.4dm converted
// Ignoring Case of statement
if (rec.amountPerParcel != 0) {
	if (rec.parcels * rec.amountPerParcel < rec.amount) {
		rec.remainingAmount = rec.amount - rec.parcels * rec.amountPerParcel
		if (rec.remainingAmount < 0) {
			rec.remainingAmount = 0
		} else if (rec.remainingAmount > 0) {
			rec.remainingAmount = rec.remainingAmount + rec.amountPerParcel
		}
	} else {
		rec.parcels = Math.trunc(rec.amount / rec.amountPerParcel) // Assuming Trunc:C95 is truncate
		rec.remainingAmount = rec.amount - rec.parcels * rec.amountPerParcel
		if (rec.remainingAmount != 0) {
			rec.parcels = rec.parcels + 1
		}
	}
} else {
	rec.amount = 0
	rec.remainingAmount = 0
}
amountStock1ToStock2() // stpa_add_AMOUNT1_TO_AMOUNT2() // Assuming this is a function call
