increase quantity when adding fee multiple times

deepsource-autofix-76c6eb20
Dan Gowans 2022-08-24 16:28:02 -04:00
parent 9287f1cb8e
commit 6c73609857
7 changed files with 66 additions and 35 deletions

View File

@ -5,6 +5,19 @@ import { getFee } from "./getFee.js";
import { getLotOccupancy } from "./getLotOccupancy.js"; import { getLotOccupancy } from "./getLotOccupancy.js";
export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => { export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
const database = sqlite(databasePath); const database = sqlite(databasePath);
const rightNowMillis = Date.now();
let feeAmount;
let taxAmount;
if (lotOccupancyFeeForm.feeAmount) {
feeAmount = typeof (lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
taxAmount = typeof (lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
}
else {
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
const fee = getFee(lotOccupancyFeeForm.feeId);
feeAmount = calculateFeeAmount(fee, lotOccupancy);
taxAmount = calculateTaxAmount(fee, feeAmount);
}
const record = database.prepare("select recordDelete_timeMillis" + const record = database.prepare("select recordDelete_timeMillis" +
" from LotOccupancyFees" + " from LotOccupancyFees" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
@ -19,23 +32,19 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); .run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
} }
else { else {
database.prepare("update LotOccupancyFees" +
" set quantity = quantity + ?," +
" feeAmount = feeAmount + ?," +
" taxAmount = taxAmount + ?," +
" recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" +
" where lotOccupancyId = ?" +
" and feeId = ?")
.run(lotOccupancyFeeForm.quantity, feeAmount, taxAmount, requestSession.user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
database.close(); database.close();
return false; return false;
} }
} }
let feeAmount;
let taxAmount;
if (lotOccupancyFeeForm.feeAmount) {
feeAmount = typeof (lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
taxAmount = typeof (lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
}
else {
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
const fee = getFee(lotOccupancyFeeForm.feeId);
feeAmount = calculateFeeAmount(fee, lotOccupancy);
taxAmount = calculateTaxAmount(fee, feeAmount);
}
const rightNowMillis = Date.now();
const result = database const result = database
.prepare("insert into LotOccupancyFees (" + .prepare("insert into LotOccupancyFees (" +
"lotOccupancyId, feeId," + "lotOccupancyId, feeId," +

View File

@ -34,6 +34,25 @@ export const addLotOccupancyFee =
const database = sqlite(databasePath); const database = sqlite(databasePath);
const rightNowMillis = Date.now();
// Calculate fee and tax (if not set)
let feeAmount: number;
let taxAmount: number;
if (lotOccupancyFeeForm.feeAmount) {
feeAmount = typeof(lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
taxAmount = typeof(lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
} else {
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
const fee = getFee(lotOccupancyFeeForm.feeId);
feeAmount = calculateFeeAmount(fee, lotOccupancy);
taxAmount = calculateTaxAmount(fee, feeAmount);
}
// Check if record already exists // Check if record already exists
const record: { const record: {
@ -53,6 +72,24 @@ export const addLotOccupancyFee =
" and feeId = ?") " and feeId = ?")
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); .run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
} else { } else {
database.prepare("update LotOccupancyFees" +
" set quantity = quantity + ?," +
" feeAmount = feeAmount + ?," +
" taxAmount = taxAmount + ?," +
" recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" +
" where lotOccupancyId = ?" +
" and feeId = ?")
.run(
lotOccupancyFeeForm.quantity,
feeAmount,
taxAmount,
requestSession.user.userName,
rightNowMillis,
lotOccupancyFeeForm.lotOccupancyId,
lotOccupancyFeeForm.feeId);
database.close(); database.close();
return false; return false;
} }
@ -60,23 +97,6 @@ export const addLotOccupancyFee =
// Create new record // Create new record
let feeAmount: number;
let taxAmount: number;
if (lotOccupancyFeeForm.feeAmount) {
feeAmount = typeof(lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
taxAmount = typeof(lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
} else {
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
const fee = getFee(lotOccupancyFeeForm.feeId);
feeAmount = calculateFeeAmount(fee, lotOccupancy);
taxAmount = calculateTaxAmount(fee, feeAmount);
}
const rightNowMillis = Date.now();
const result = database const result = database
.prepare("insert into LotOccupancyFees (" + .prepare("insert into LotOccupancyFees (" +
"lotOccupancyId, feeId," + "lotOccupancyId, feeId," +

View File

@ -6,7 +6,7 @@ export const getLotOccupancyFees = (lotOccupancyId, connectedDatabase) => {
}); });
const lotOccupancyFees = database const lotOccupancyFees = database
.prepare("select o.lotOccupancyId," + .prepare("select o.lotOccupancyId," +
" o.feeId, c.feeCategory, f.feeName," + " o.feeId, c.feeCategory, f.feeName, f.includeQuantity," +
" o.feeAmount, o.taxAmount, o.quantity" + " o.feeAmount, o.taxAmount, o.quantity" +
" from LotOccupancyFees o" + " from LotOccupancyFees o" +
" left join Fees f on o.feeId = f.feeId" + " left join Fees f on o.feeId = f.feeId" +

View File

@ -16,7 +16,7 @@ export const getLotOccupancyFees = (lotOccupancyId: number | string,
const lotOccupancyFees: recordTypes.LotOccupancyFee[] = database const lotOccupancyFees: recordTypes.LotOccupancyFee[] = database
.prepare("select o.lotOccupancyId," + .prepare("select o.lotOccupancyId," +
" o.feeId, c.feeCategory, f.feeName," + " o.feeId, c.feeCategory, f.feeName, f.includeQuantity," +
" o.feeAmount, o.taxAmount, o.quantity" + " o.feeAmount, o.taxAmount, o.quantity" +
" from LotOccupancyFees o" + " from LotOccupancyFees o" +
" left join Fees f on o.feeId = f.feeId" + " left join Fees f on o.feeId = f.feeId" +

View File

@ -670,6 +670,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const tableRowElement = document.createElement("tr"); const tableRowElement = document.createElement("tr");
tableRowElement.className = "container--lotOccupancyFee"; tableRowElement.className = "container--lotOccupancyFee";
tableRowElement.dataset.feeId = lotOccupancyFee.feeId.toString(); tableRowElement.dataset.feeId = lotOccupancyFee.feeId.toString();
tableRowElement.dataset.includeQuantity = (lotOccupancyFee.includeQuantity ? "1" : "0");
tableRowElement.innerHTML = ("<td colspan=\"" + (lotOccupancyFee.quantity === 1 ? "5" : "1") + "\">" + tableRowElement.innerHTML = ("<td colspan=\"" + (lotOccupancyFee.quantity === 1 ? "5" : "1") + "\">" +
cityssm.escapeHTML(lotOccupancyFee.feeName) + cityssm.escapeHTML(lotOccupancyFee.feeName) +
"</td>") + "</td>") +
@ -773,7 +774,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
"<div class=\"panel mb-5\"></div>"; "<div class=\"panel mb-5\"></div>";
let hasFees = false; let hasFees = false;
for (const fee of feeCategory.fees) { for (const fee of feeCategory.fees) {
if (lotOccupancyFeesContainerElement.querySelector(".container--lotOccupancyFee[data-fee-id='" + fee.feeId + "']")) { if (lotOccupancyFeesContainerElement.querySelector(".container--lotOccupancyFee[data-fee-id='" + fee.feeId + "'][data-include-quantity='0']")) {
continue; continue;
} }
let includeFee = true; let includeFee = true;

View File

@ -942,6 +942,7 @@ declare const bulmaJS: BulmaJS;
const tableRowElement = document.createElement("tr"); const tableRowElement = document.createElement("tr");
tableRowElement.className = "container--lotOccupancyFee"; tableRowElement.className = "container--lotOccupancyFee";
tableRowElement.dataset.feeId = lotOccupancyFee.feeId.toString(); tableRowElement.dataset.feeId = lotOccupancyFee.feeId.toString();
tableRowElement.dataset.includeQuantity = (lotOccupancyFee.includeQuantity ? "1" : "0");
tableRowElement.innerHTML = ("<td colspan=\"" + (lotOccupancyFee.quantity === 1 ? "5" : "1") + "\">" + tableRowElement.innerHTML = ("<td colspan=\"" + (lotOccupancyFee.quantity === 1 ? "5" : "1") + "\">" +
cityssm.escapeHTML(lotOccupancyFee.feeName) + cityssm.escapeHTML(lotOccupancyFee.feeName) +
@ -1080,7 +1081,7 @@ declare const bulmaJS: BulmaJS;
for (const fee of feeCategory.fees) { for (const fee of feeCategory.fees) {
if (lotOccupancyFeesContainerElement.querySelector(".container--lotOccupancyFee[data-fee-id='" + fee.feeId + "']")) { if (lotOccupancyFeesContainerElement.querySelector(".container--lotOccupancyFee[data-fee-id='" + fee.feeId + "'][data-include-quantity='0']")) {
continue; continue;
} }

File diff suppressed because one or more lines are too long