correct adding multiple fees
parent
ed2af5f23d
commit
37c2f39ea0
|
|
@ -18,7 +18,7 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
|
||||||
feeAmount = calculateFeeAmount(fee, lotOccupancy);
|
feeAmount = calculateFeeAmount(fee, lotOccupancy);
|
||||||
taxAmount = calculateTaxAmount(fee, feeAmount);
|
taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||||
}
|
}
|
||||||
const record = database.prepare("select recordDelete_timeMillis" +
|
const record = database.prepare("select feeAmount, taxAmount, recordDelete_timeMillis" +
|
||||||
" from LotOccupancyFees" +
|
" from LotOccupancyFees" +
|
||||||
" where lotOccupancyId = ?" +
|
" where lotOccupancyId = ?" +
|
||||||
" and feeId = ?")
|
" and feeId = ?")
|
||||||
|
|
@ -31,18 +31,32 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
|
||||||
" and feeId = ?")
|
" and feeId = ?")
|
||||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||||
}
|
}
|
||||||
else {
|
else if (record.feeAmount === feeAmount && record.taxAmount === taxAmount) {
|
||||||
database.prepare("update LotOccupancyFees" +
|
database.prepare("update LotOccupancyFees" +
|
||||||
" set quantity = quantity + ?," +
|
" set quantity = quantity + ?," +
|
||||||
" feeAmount = feeAmount + ?," +
|
|
||||||
" taxAmount = taxAmount + ?," +
|
|
||||||
" recordUpdate_userName = ?," +
|
" recordUpdate_userName = ?," +
|
||||||
" recordUpdate_timeMillis = ?" +
|
" recordUpdate_timeMillis = ?" +
|
||||||
" where lotOccupancyId = ?" +
|
" where lotOccupancyId = ?" +
|
||||||
" and feeId = ?")
|
" and feeId = ?")
|
||||||
.run(lotOccupancyFeeForm.quantity, feeAmount, taxAmount, requestSession.user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
.run(lotOccupancyFeeForm.quantity, requestSession.user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||||
database.close();
|
database.close();
|
||||||
return false;
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const quantity = typeof (lotOccupancyFeeForm.quantity) === "string" ?
|
||||||
|
Number.parseFloat(lotOccupancyFeeForm.quantity) :
|
||||||
|
lotOccupancyFeeForm.quantity;
|
||||||
|
database.prepare("update LotOccupancyFees" +
|
||||||
|
" set feeAmount = (feeAmount * quantity) + ?," +
|
||||||
|
" taxAmount = (taxAmount * quantity) + ?," +
|
||||||
|
" quantity = 1," +
|
||||||
|
" recordUpdate_userName = ?," +
|
||||||
|
" recordUpdate_timeMillis = ?" +
|
||||||
|
" where lotOccupancyId = ?" +
|
||||||
|
" and feeId = ?")
|
||||||
|
.run((feeAmount * quantity), (taxAmount * quantity), requestSession.user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||||
|
database.close();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const result = database
|
const result = database
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ export const addLotOccupancyFee =
|
||||||
let taxAmount: number;
|
let taxAmount: number;
|
||||||
|
|
||||||
if (lotOccupancyFeeForm.feeAmount) {
|
if (lotOccupancyFeeForm.feeAmount) {
|
||||||
feeAmount = typeof(lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
|
feeAmount = typeof (lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
|
||||||
taxAmount = typeof(lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
|
taxAmount = typeof (lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
|
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
|
||||||
|
|
@ -56,8 +56,10 @@ export const addLotOccupancyFee =
|
||||||
// Check if record already exists
|
// Check if record already exists
|
||||||
|
|
||||||
const record: {
|
const record: {
|
||||||
|
feeAmount ? : number;
|
||||||
|
taxAmount ? : number;
|
||||||
recordDelete_timeMillis ? : number
|
recordDelete_timeMillis ? : number
|
||||||
} = database.prepare("select recordDelete_timeMillis" +
|
} = database.prepare("select feeAmount, taxAmount, recordDelete_timeMillis" +
|
||||||
" from LotOccupancyFees" +
|
" from LotOccupancyFees" +
|
||||||
" where lotOccupancyId = ?" +
|
" where lotOccupancyId = ?" +
|
||||||
" and feeId = ?")
|
" and feeId = ?")
|
||||||
|
|
@ -71,28 +73,53 @@ export const addLotOccupancyFee =
|
||||||
" and lotOccupancyId = ?" +
|
" and lotOccupancyId = ?" +
|
||||||
" and feeId = ?")
|
" and feeId = ?")
|
||||||
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
|
||||||
} else {
|
|
||||||
|
} else if (record.feeAmount === feeAmount && record.taxAmount === taxAmount) {
|
||||||
|
|
||||||
database.prepare("update LotOccupancyFees" +
|
database.prepare("update LotOccupancyFees" +
|
||||||
" set quantity = quantity + ?," +
|
" set quantity = quantity + ?," +
|
||||||
" feeAmount = feeAmount + ?," +
|
|
||||||
" taxAmount = taxAmount + ?," +
|
|
||||||
" recordUpdate_userName = ?," +
|
" recordUpdate_userName = ?," +
|
||||||
" recordUpdate_timeMillis = ?" +
|
" recordUpdate_timeMillis = ?" +
|
||||||
" where lotOccupancyId = ?" +
|
" where lotOccupancyId = ?" +
|
||||||
" and feeId = ?")
|
" and feeId = ?")
|
||||||
.run(
|
.run(
|
||||||
lotOccupancyFeeForm.quantity,
|
lotOccupancyFeeForm.quantity,
|
||||||
feeAmount,
|
|
||||||
taxAmount,
|
|
||||||
requestSession.user.userName,
|
requestSession.user.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
lotOccupancyFeeForm.lotOccupancyId,
|
lotOccupancyFeeForm.lotOccupancyId,
|
||||||
lotOccupancyFeeForm.feeId);
|
lotOccupancyFeeForm.feeId);
|
||||||
|
|
||||||
database.close();
|
database.close();
|
||||||
return false;
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const quantity = typeof (lotOccupancyFeeForm.quantity) === "string" ?
|
||||||
|
Number.parseFloat(lotOccupancyFeeForm.quantity) :
|
||||||
|
lotOccupancyFeeForm.quantity;
|
||||||
|
|
||||||
|
database.prepare("update LotOccupancyFees" +
|
||||||
|
" set feeAmount = (feeAmount * quantity) + ?," +
|
||||||
|
" taxAmount = (taxAmount * quantity) + ?," +
|
||||||
|
" quantity = 1," +
|
||||||
|
" recordUpdate_userName = ?," +
|
||||||
|
" recordUpdate_timeMillis = ?" +
|
||||||
|
" where lotOccupancyId = ?" +
|
||||||
|
" and feeId = ?")
|
||||||
|
.run(
|
||||||
|
(feeAmount * quantity),
|
||||||
|
(taxAmount * quantity),
|
||||||
|
requestSession.user.userName,
|
||||||
|
rightNowMillis,
|
||||||
|
lotOccupancyFeeForm.lotOccupancyId,
|
||||||
|
lotOccupancyFeeForm.feeId);
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new record
|
// Create new record
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue