@apptimate/core-lib 4.9.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apptimate/core-lib",
3
- "version": "4.9.0",
3
+ "version": "5.1.0",
4
4
  "main": "src/index.ts",
5
5
  "types": "src/index.ts",
6
6
  "publishConfig": {
@@ -15,6 +15,14 @@ export async function getItemBatches(itemId: number, params: Record<string, stri
15
15
  return response.responseData as IApiResponse;
16
16
  }
17
17
 
18
+ export async function checkHasActivePriceLists(): Promise<IApiResponse> {
19
+ const response = await sendRequest({
20
+ url: `${process.env.NEXT_PUBLIC_API_URL}/api/sales/price-lists/has-active?t=${new Date().getTime()}`,
21
+ method: "GET"
22
+ });
23
+ return response.responseData as IApiResponse;
24
+ }
25
+
18
26
  export async function evaluatePriceLists(data: {
19
27
  party_id?: number | null;
20
28
  transaction_type: string;
@@ -249,15 +249,8 @@ export const MENU_ITEM_REGISTRY: RegistryItem[] = [
249
249
  { key: 'construction__ipcs', label: 'Progress Billing', path: '/construction/contracts/ipcs', module: 'Construction', defaultGroup: 'Contracts & Billing', permission: null },
250
250
  { key: 'construction__variations', label: 'Subcontractor Variations', path: '/construction/variations', module: 'Construction', defaultGroup: 'Contracts & Billing', permission: null },
251
251
 
252
- { key: 'construction__prs', label: 'Purchase Requisitions', path: '/construction/procurement/prs', module: 'Construction', defaultGroup: 'Procurement', permission: null },
253
- { key: 'construction__pos', label: 'Purchase Orders', path: '/construction/procurement/pos', module: 'Construction', defaultGroup: 'Procurement', permission: null },
254
- { key: 'construction__grns', label: 'Goods Receipt', path: '/construction/procurement/grns', module: 'Construction', defaultGroup: 'Procurement', permission: null },
255
- { key: 'construction__mtrs', label: 'Transfer Requests', path: '/construction/procurement/mtrs', module: 'Construction', defaultGroup: 'Procurement', permission: null },
256
-
257
- { key: 'construction__site_ledger', label: 'Project Ledger', path: '/construction/site-inventory/ledger', module: 'Construction', defaultGroup: 'Project Inventory', permission: null },
258
- { key: 'construction__site_issues', label: 'Project Issues', path: '/construction/site-inventory/issues', module: 'Construction', defaultGroup: 'Project Inventory', permission: null },
259
- { key: 'construction__wastage_returns', label: 'Wastage & Returns', path: '/construction/site-inventory/wastage-returns', module: 'Construction', defaultGroup: 'Project Inventory', permission: null },
260
-
252
+
253
+
261
254
  { key: 'construction__workforce', label: 'Workforce Master', path: '/construction/workforce', module: 'Construction', defaultGroup: 'Workforce', permission: null },
262
255
  { key: 'construction__shifts', label: 'Shift Master', path: '/construction/shifts', module: 'Construction', defaultGroup: 'Workforce', permission: null },
263
256
  { key: 'construction__attendance', label: 'Attendance & Timesheets', path: '/construction/attendance', module: 'Construction', defaultGroup: 'Workforce', permission: null },
@@ -4,6 +4,7 @@ export interface IPricingRule {
4
4
  min_quantity: number;
5
5
  rate: number | null;
6
6
  markdown_percentage: number | null;
7
+ batch_id?: number | null;
7
8
  final_rate?: number;
8
9
  }
9
10
 
@@ -14,21 +15,30 @@ export class PriceCalculationService {
14
15
  public static calculatePriceDetails(
15
16
  basePrice: number,
16
17
  quantity: number,
17
- rules?: IPricingRule[]
18
+ rules?: IPricingRule[],
19
+ batchId?: number | null
18
20
  ): { unitPrice: number; discountPercent: number; discountAmount: number; appliedRule?: IPricingRule } {
19
21
  if (!rules || rules.length === 0) {
20
22
  return { unitPrice: basePrice, discountPercent: 0, discountAmount: 0 };
21
23
  }
22
24
 
23
- // Filter rules that match the quantity condition
24
- const applicableRules = rules.filter(r => quantity >= r.min_quantity);
25
+ // Filter rules that match the quantity condition and batch condition
26
+ const applicableRules = rules.filter(r => {
27
+ if (quantity < r.min_quantity) return false;
28
+ if (r.batch_id && String(r.batch_id) !== String(batchId)) return false;
29
+ return true;
30
+ });
25
31
 
26
32
  if (applicableRules.length === 0) {
27
33
  return { unitPrice: basePrice, discountPercent: 0, discountAmount: 0 };
28
34
  }
29
35
 
30
- // Sort by min_quantity descending (highest threshold wins)
31
- applicableRules.sort((a, b) => b.min_quantity - a.min_quantity);
36
+ // Sort by batch specificity first, then min_quantity descending (highest threshold wins)
37
+ applicableRules.sort((a, b) => {
38
+ if (a.batch_id && !b.batch_id) return -1;
39
+ if (!a.batch_id && b.batch_id) return 1;
40
+ return b.min_quantity - a.min_quantity;
41
+ });
32
42
 
33
43
  const activeRule = applicableRules[0];
34
44