Merge branch 'test' into release/2021-08-27

This commit is contained in:
Patrick Fic
2021-08-23 08:34:25 -07:00
2 changed files with 11 additions and 16 deletions

View File

@@ -1,13 +1,8 @@
import Dinero from "dinero.js"; import Dinero from "dinero.js";
export const CalculateBillTotal = (invoice) => { export const CalculateBillTotal = (invoice) => {
const { const { total, billlines, federal_tax_rate, local_tax_rate, state_tax_rate } =
total, invoice;
billlines,
federal_tax_rate,
local_tax_rate,
state_tax_rate,
} = invoice;
//TODO Determine why this recalculates so many times. //TODO Determine why this recalculates so many times.
let subtotal = Dinero({ amount: 0 }); let subtotal = Dinero({ amount: 0 });
@@ -20,8 +15,7 @@ export const CalculateBillTotal = (invoice) => {
billlines.forEach((i) => { billlines.forEach((i) => {
if (!!i) { if (!!i) {
const itemTotal = Dinero({ const itemTotal = Dinero({
amount: amount: Math.round((i.actual_cost || 0) * 100),
Math.round(((i.actual_cost || 0) * 100 + Number.EPSILON) * 100) / 100,
}).multiply(i.quantity || 1); }).multiply(i.quantity || 1);
subtotal = subtotal.add(itemTotal); subtotal = subtotal.add(itemTotal);

View File

@@ -8,7 +8,6 @@ import {
import { Col, notification, Row } from "antd"; import { Col, notification, Row } from "antd";
import Axios from "axios"; import Axios from "axios";
import Dinero from "dinero.js"; import Dinero from "dinero.js";
import _ from "lodash";
import moment from "moment"; import moment from "moment";
import queryString from "query-string"; import queryString from "query-string";
import React, { useCallback, useEffect, useState } from "react"; import React, { useCallback, useEffect, useState } from "react";
@@ -187,7 +186,9 @@ export function JobsAvailableContainer({
setJobModalVisible(false); setJobModalVisible(false);
setInsertLoading(true); setInsertLoading(true);
const estData = replaceEmpty(estDataRaw.data.available_jobs_by_pk);
const estData = estDataRaw.data.available_jobs_by_pk;
if (!(estData && estData.est_data)) { if (!(estData && estData.est_data)) {
//We don't have the right data. Error! //We don't have the right data. Error!
setInsertLoading(false); setInsertLoading(false);
@@ -196,7 +197,7 @@ export function JobsAvailableContainer({
}); });
} else { } else {
//create upsert job //create upsert job
let supp = _.cloneDeep(estData.est_data); let supp = replaceEmpty({ ...estData.est_data });
delete supp.owner; delete supp.owner;
delete supp.vehicle; delete supp.vehicle;
@@ -208,7 +209,7 @@ export function JobsAvailableContainer({
let suppDelta = await GetSupplementDelta( let suppDelta = await GetSupplementDelta(
client, client,
selectedJob, selectedJob,
estData.est_data.joblines.data supp.joblines.data
); );
delete supp.joblines; delete supp.joblines;
@@ -380,10 +381,10 @@ export default connect(
)(JobsAvailableContainer); )(JobsAvailableContainer);
function replaceEmpty(someObj, replaceValue = null) { function replaceEmpty(someObj, replaceValue = null) {
const replacer = (key, value) => (value === "" ? replaceValue : value); const replacer = (key, value) =>
value === "" ? replaceValue || null : value;
//^ because you seem to want to replace (strings) "null" or "undefined" too //^ because you seem to want to replace (strings) "null" or "undefined" too
console.log(someObj);
const temp = JSON.stringify(someObj, replacer); const temp = JSON.stringify(someObj, replacer);
console.log(`temp`, temp); console.log("Parsed", JSON.parse(temp));
return JSON.parse(temp); return JSON.parse(temp);
} }