@davoodmehraban89 / Factor-easy / commits / 87dcf6e
Fork 0

سامانه صدور فاکتور و حسابداری

Test chart import and floating-dimension contract

davoodmehraban89 committed Sep 29, 2026 at 22:15 UTC 87dcf6e93ed8eb323420298568336d3e77c6299b
1 file changed +17 -2
scripts/phase2-check.mjs
+17 -2
@@ -1,20 +1,35 @@
1 import fs from 'node:fs';
2 +import vm from 'node:vm';
3 const af=fs.readFileSync('js/accounting-foundation.js','utf8');
4 const render=fs.readFileSync('js/accounting-foundation-render.js','utf8');
5 const companies=fs.readFileSync('js/companies.js','utf8');
6 const index=fs.readFileSync('index.html','utf8');
7 const core=fs.readFileSync('js/core.js','utf8');
8 const backup=fs.readFileSync('js/backup.js','utf8');
9 +const journal=fs.readFileSync('js/journal-engine.js','utf8');
10 +const phase4=fs.readFileSync('js/phase4-contracting.js','utf8');
11 const sync=fs.readFileSync('js/sync.js','utf8');
12 const must=(src,needles,label)=>{for(const n of needles)if(!src.includes(n))throw new Error(label+' missing '+n)};
10 -must(af,['AF_COMPANY_TYPES','AF_BASE_ACCOUNTS','AF_SPECIAL_ACCOUNTS','afApplyTemplate','afDimensionValuePostable','afDimensionHasValues','afDimensionValueReferenced','afChangeDimensionDepth','depthLocked','maxDepth','startDate>=endDate'],'accounting foundation');
11 -must(render,['afDimensionValuePostable','afChangeDimensionDepth','عمق قفل شده','قابل ثبت','گروه/غیرقابل ثبت'],'dimension rendering');
13 +must(af,['AF_COMPANY_TYPES','AF_BASE_ACCOUNTS','AF_SPECIAL_ACCOUNTS','afApplyTemplate','afDimensionValuePostable','afDimensionHasValues','afDimensionValueReferenced','afChangeDimensionDepth','depthLocked','maxDepth','startDate>=endDate','afNormalizeAccountImportRows','afImportAccountsFromExcel','downloadAccountsExcelTemplate',"'CONTRACT','قرارداد / پیمان','contract',1,4",'slot:Number(slot)||0'],'accounting foundation');
14 +must(render,['afDimensionValuePostable','afChangeDimensionDepth','عمق قفل شده','قابل ثبت','گروه/غیرقابل ثبت','تفصیلی شناور'],'dimension rendering');
15 must(companies,['company-activity-type','company-accounting-template','afApplyTemplate(newComp.id,activityType)'],'company onboarding');
16 must(index,['company-activity-type','company-accounting-template','بازرگانی','خدماتی','تولیدی','پیمانکاری','فروشگاهی','پخش','غیرانتفاعی','خدمات حرفه‌ای'],'company activity UI');
17 +must(fs.readFileSync('js/accounting-foundation-ui.js','utf8'),['ورود کدینگ از Excel','نمونه Excel کدینگ','شناور ۱ شعبه','شناور ۴ قرارداد/پیمان','value="contract"'],'accounting contract UI');
18 +must(journal,["t.sourceEntity==='contract'","contractId:source.contractId||''"],'contract analytic posting context');
19 +must(phase4,['contractId:c.id'],'contracting analytic source context');
20 for(const coll of ['fiscalYears','accounts','dimensionTypes','dimensionValues','accountDimensionRules','branches','projects','projectLinks']){
21 if(!core.includes("'"+coll+"'")||!sync.includes(coll)||!backup.includes(coll))throw new Error('Phase 2 persistence missing '+coll);
22 }
23 if(!af.includes("(v.depth||1)===Number(t.maxDepth||1)"))throw new Error('Only configured terminal depth may post');
24 if(!af.includes("if(afDimensionHasValues(id))return alert"))throw new Error('Hierarchy depth must lock after values exist');
25 if(!af.includes("afDimensionValueReferenced(id)"))throw new Error('Referenced analytic values must be protected');
26 +const ctx={console};vm.createContext(ctx);vm.runInContext(af,ctx);
27 +const imported=vm.runInContext(`afNormalizeAccountImportRows([
28 + {'کد':'1','عنوان':'دارایی‌ها','سطح':'کل','ماهیت':'بدهکار'},
29 + {'کد':'11','عنوان':'دارایی جاری','سطح':'معین','کد والد':'1','ماهیت':'بدهکار'},
30 + {'کد':'1101','عنوان':'بانک','سطح':'تفصیلی','کد والد':'11','ماهیت':'بدهکار'}
31 +])`,ctx);
32 +if(imported.length!==3||imported[2].level!=='detail'||imported[2].parentCode!=='11')throw new Error('Chart Excel normalization behavior failed');
33 +let badParent=false;try{vm.runInContext(`afNormalizeAccountImportRows([{'کد':'1101','عنوان':'بانک','سطح':'تفصیلی','کد والد':'99'}])`,ctx)}catch(_){badParent=true}
34 +if(!badParent)throw new Error('Chart import must reject invalid hierarchy');
35 console.log('Phase 2 accounting foundation invariants passed.');