Scratch
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* THIS IS A COPY of CDKCalculateAllocations, modified to:
|
||||
* - Only calculate allocations needed for Reynolds & RR exports
|
||||
* - Keep sales broken down into buckets (parts, taxable labor, non-taxable labor, extras)
|
||||
* - Keep sales broken down into buckets (parts, taxable / non-taxable parts, taxable labor, non-taxable labor, extras)
|
||||
* - Add extra logging for easier debugging
|
||||
*
|
||||
* Original comments follow.
|
||||
@@ -49,14 +49,21 @@ const summarizeAllocationsArray = (arr) =>
|
||||
/**
|
||||
* Internal per-center bucket shape for *sales*.
|
||||
* We keep separate buckets for RR so we can split
|
||||
* taxable vs non-taxable labor lines later.
|
||||
* taxable vs non-taxable parts and labor lines later.
|
||||
*/
|
||||
function emptyCenterBucket() {
|
||||
const zero = Dinero();
|
||||
return {
|
||||
partsSale: zero, // parts sale
|
||||
// Parts
|
||||
partsSale: zero, // total parts (taxable + non-taxable)
|
||||
partsTaxableSale: zero, // parts that should be taxed in RR
|
||||
partsNonTaxableSale: zero, // parts that should NOT be taxed in RR
|
||||
|
||||
// Labor
|
||||
laborTaxableSale: zero, // labor that should be taxed in RR
|
||||
laborNonTaxableSale: zero, // labor that should NOT be taxed in RR
|
||||
|
||||
// Extras
|
||||
extrasSale: zero // MAPA/MASH/towing/storage/PAO/etc
|
||||
};
|
||||
}
|
||||
@@ -161,6 +168,15 @@ function isLaborTaxable(line) {
|
||||
return line.tax_part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide if a *part* line is taxable vs non-taxable for RR.
|
||||
* For now we mirror the same flag; this can be extended with CAD-specific
|
||||
* logic (federal_tax_rate, parts_tax_rate, prt_tax_in, etc.) later.
|
||||
*/
|
||||
function isPartTaxable(line) {
|
||||
return line.tax_part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build profitCenterHash from joblines (parts + labor) and detect MAPA/MASH presence.
|
||||
* Now stores *buckets* instead of a single Dinero per center.
|
||||
@@ -215,6 +231,15 @@ function buildProfitCenterHash(job, debugLog) {
|
||||
amount = amount.add(discount);
|
||||
}
|
||||
|
||||
const taxable = isPartTaxable(val);
|
||||
|
||||
if (taxable) {
|
||||
bucket.partsTaxableSale = bucket.partsTaxableSale.add(amount);
|
||||
} else {
|
||||
bucket.partsNonTaxableSale = bucket.partsNonTaxableSale.add(amount);
|
||||
}
|
||||
|
||||
// Keep total parts for compatibility / convenience
|
||||
bucket.partsSale = bucket.partsSale.add(amount);
|
||||
}
|
||||
|
||||
@@ -245,6 +270,8 @@ function buildProfitCenterHash(job, debugLog) {
|
||||
centers: Object.entries(profitCenterHash).map(([center, b]) => ({
|
||||
center,
|
||||
parts: summarizeMoney(b.partsSale),
|
||||
partsTaxable: summarizeMoney(b.partsTaxableSale),
|
||||
partsNonTaxable: summarizeMoney(b.partsNonTaxableSale),
|
||||
laborTaxable: summarizeMoney(b.laborTaxableSale),
|
||||
laborNonTaxable: summarizeMoney(b.laborNonTaxableSale),
|
||||
extras: summarizeMoney(b.extrasSale)
|
||||
@@ -521,14 +548,6 @@ function applyExtras({ job, bodyshop, selectedDmsAllocationConfig, profitCenterH
|
||||
return { profitCenterHash, taxAllocations };
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Rome-specific profile adjustments (parts + rates).
|
||||
* These also feed into the *sales* buckets.
|
||||
*/
|
||||
/**
|
||||
* Apply Rome-specific profile adjustments (parts + rates).
|
||||
* These also feed into the *sales* buckets.
|
||||
*/
|
||||
/**
|
||||
* Apply Rome-specific profile adjustments (parts + rates).
|
||||
* These also feed into the *sales* buckets.
|
||||
@@ -627,6 +646,8 @@ function applyRomeProfileAdjustments({
|
||||
* {
|
||||
* center,
|
||||
* partsSale,
|
||||
* partsTaxableSale,
|
||||
* partsNonTaxableSale,
|
||||
* laborTaxableSale,
|
||||
* laborNonTaxableSale,
|
||||
* extrasSale,
|
||||
@@ -653,10 +674,18 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
|
||||
return {
|
||||
center,
|
||||
|
||||
// Parts
|
||||
partsSale: bucket.partsSale,
|
||||
partsTaxableSale: bucket.partsTaxableSale,
|
||||
partsNonTaxableSale: bucket.partsNonTaxableSale,
|
||||
|
||||
// Labor
|
||||
laborTaxableSale: bucket.laborTaxableSale,
|
||||
laborNonTaxableSale: bucket.laborNonTaxableSale,
|
||||
|
||||
// Extras
|
||||
extrasSale: bucket.extrasSale,
|
||||
|
||||
totalSale,
|
||||
|
||||
cost: costCenterHash[center] || Dinero(),
|
||||
@@ -671,6 +700,8 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
|
||||
jobAllocations.map((row) => ({
|
||||
center: row.center,
|
||||
parts: summarizeMoney(row.partsSale),
|
||||
partsTaxable: summarizeMoney(row.partsTaxableSale),
|
||||
partsNonTaxable: summarizeMoney(row.partsNonTaxableSale),
|
||||
laborTaxable: summarizeMoney(row.laborTaxableSale),
|
||||
laborNonTaxable: summarizeMoney(row.laborNonTaxableSale),
|
||||
extras: summarizeMoney(row.extrasSale),
|
||||
@@ -847,6 +878,8 @@ function calculateAllocations(connectionData, job) {
|
||||
centers: Object.entries(profitCenterHash || {}).map(([center, b]) => ({
|
||||
center,
|
||||
parts: summarizeMoney(b.partsSale),
|
||||
partsTaxable: summarizeMoney(b.partsTaxableSale),
|
||||
partsNonTaxable: summarizeMoney(b.partsNonTaxableSale),
|
||||
laborTaxable: summarizeMoney(b.laborTaxableSale),
|
||||
laborNonTaxable: summarizeMoney(b.laborNonTaxableSale),
|
||||
extras: summarizeMoney(b.extrasSale)
|
||||
|
||||
Reference in New Issue
Block a user