سامانه صدور فاکتور و حسابداری
Bound chart Excel import size and row count
davoodmehraban89 committed
Sep 29, 2026 at 22:34 UTC
648b8fb041609bb1295aaca377177878dfeb3a0f
1 file changed
+1
-1
js/accounting-foundation.js
+1
-1
@@ -90,7 +90,7 @@ function afNormalizeAccountImportRows(rows){
90
if(!out.length)throw new Error('فایل کدینگ فاقد ردیف معتبر است.');const byCode=new Map(out.map(x=>[x.code,x]));for(const a of out){const need=a.level==='subsidiary'?'gl':a.level==='detail'?'subsidiary':'';if(!need){if(a.parentCode)throw new Error('حساب کل '+a.code+' نباید والد داشته باشد.');continue}const p=byCode.get(a.parentCode);if(!p||p.level!==need)throw new Error('والد '+a.code+' باید '+(need==='gl'?'حساب کل':'حساب معین')+' معتبر داخل همان فایل باشد.')}return out;
91
}
92
function afImportAccountsFromExcel(event){
93
- if(!requireWrite())return;const file=event.target.files?.[0];if(!file)return;if(getMyAccounts().length){event.target.value='';return alert('ورود کدینگ فقط روی کدینگ خالی مجاز است؛ برای جلوگیری از ادغام ناامن، ابتدا شرکت با «شروع با کدینگ خالی» ایجاد شود.')}if(typeof XLSX==='undefined'){event.target.value='';return alert('موتور Excel در دسترس نیست.')}const reader=new FileReader();reader.onload=()=>{try{const wb=XLSX.read(reader.result,{type:'array'}),ws=wb.Sheets[wb.SheetNames[0]],rows=XLSX.utils.sheet_to_json(ws,{defval:''}),items=afNormalizeAccountImportRows(rows),counts=items.reduce((m,x)=>(m[x.level]=(m[x.level]||0)+1,m),{});if(!confirm('پیشنمایش کدینگ: '+items.length.toLocaleString('fa-IR')+' حساب — کل '+(counts.gl||0).toLocaleString('fa-IR')+'، معین '+(counts.subsidiary||0).toLocaleString('fa-IR')+'، تفصیلی '+(counts.detail||0).toLocaleString('fa-IR')+'.\nپس از تأیید، فایل بهصورت افزایشی روی کدینگ خالی وارد میشود.'))return;const cid=afNeedCompany();if(!cid)return;const byCode={};['gl','subsidiary','detail'].forEach(level=>items.filter(x=>x.level===level).forEach(x=>{const parentId=x.parentCode?byCode[x.parentCode]?.id||'':'';const a={id:afId('ACC'),ownerUserId:currentUser.id,companyId:cid,code:x.code,title:x.title,level,parentId,normalBalance:x.normalBalance,accountType:x.accountType||afAccountTypeForCode(x.code),postingAllowed:level==='detail',active:true,importedFrom:'excel',createdAt:new Date().toISOString()};datastore.accounts.push(a);byCode[x.code]=a}));saveDatastore();if(typeof jeEnsureDefaultProfiles==='function')jeEnsureDefaultProfiles();renderAccountingFoundation();alert(items.length.toLocaleString('fa-IR')+' حساب با موفقیت وارد شد.')}catch(e){alert('ورود کدینگ انجام نشد: '+e.message)}finally{event.target.value=''}};reader.readAsArrayBuffer(file);
93
+ if(!requireWrite())return;const file=event.target.files?.[0];if(!file)return;if(file.size>5*1024*1024){event.target.value='';return alert('حجم فایل کدینگ نباید بیشتر از ۵ مگابایت باشد.')}if(getMyAccounts().length){event.target.value='';return alert('ورود کدینگ فقط روی کدینگ خالی مجاز است؛ برای جلوگیری از ادغام ناامن، ابتدا شرکت با «شروع با کدینگ خالی» ایجاد شود.')}if(typeof XLSX==='undefined'){event.target.value='';return alert('موتور Excel در دسترس نیست.')}const reader=new FileReader();reader.onload=()=>{try{const wb=XLSX.read(reader.result,{type:'array'}),ws=wb.Sheets[wb.SheetNames[0]],rows=XLSX.utils.sheet_to_json(ws,{defval:''});if(rows.length>10000)throw new Error('حداکثر ۱۰٬۰۰۰ ردیف کدینگ در هر فایل مجاز است.');const items=afNormalizeAccountImportRows(rows),counts=items.reduce((m,x)=>(m[x.level]=(m[x.level]||0)+1,m),{});if(!confirm('پیشنمایش کدینگ: '+items.length.toLocaleString('fa-IR')+' حساب — کل '+(counts.gl||0).toLocaleString('fa-IR')+'، معین '+(counts.subsidiary||0).toLocaleString('fa-IR')+'، تفصیلی '+(counts.detail||0).toLocaleString('fa-IR')+'.\nپس از تأیید، فایل بهصورت افزایشی روی کدینگ خالی وارد میشود.'))return;const cid=afNeedCompany();if(!cid)return;const byCode={};['gl','subsidiary','detail'].forEach(level=>items.filter(x=>x.level===level).forEach(x=>{const parentId=x.parentCode?byCode[x.parentCode]?.id||'':'';const a={id:afId('ACC'),ownerUserId:currentUser.id,companyId:cid,code:x.code,title:x.title,level,parentId,normalBalance:x.normalBalance,accountType:x.accountType||afAccountTypeForCode(x.code),postingAllowed:level==='detail',active:true,importedFrom:'excel',createdAt:new Date().toISOString()};datastore.accounts.push(a);byCode[x.code]=a}));saveDatastore();if(typeof jeEnsureDefaultProfiles==='function')jeEnsureDefaultProfiles();renderAccountingFoundation();alert(items.length.toLocaleString('fa-IR')+' حساب با موفقیت وارد شد.')}catch(e){alert('ورود کدینگ انجام نشد: '+e.message)}finally{event.target.value=''}};reader.readAsArrayBuffer(file);
94
}
95
function downloadAccountsExcelTemplate(){if(typeof XLSX==='undefined')return alert('موتور Excel در دسترس نیست.');const rows=[{code:'1',title:'داراییها',level:'کل',parent_code:'',normal_balance:'بدهکار',account_type:'دارایی'},{code:'11',title:'داراییهای جاری',level:'معین',parent_code:'1',normal_balance:'بدهکار',account_type:'دارایی'},{code:'1101',title:'بانک',level:'تفصیلی',parent_code:'11',normal_balance:'بدهکار',account_type:'دارایی'}],ws=XLSX.utils.json_to_sheet(rows),wb=XLSX.utils.book_new();XLSX.utils.book_append_sheet(wb,ws,'ChartOfAccounts');XLSX.writeFile(wb,'Finora-Chart-Of-Accounts-Template.xlsx')}
96
function afSaveAccount(){