سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 01:45 UTC
Add derived inventory and project profitability engine
davoodmehraban89 committed
Sep 28, 2026 at 15:17 UTC
c69f35e8530fdea16a123dc1701f8098044057cd
1 file changed
+21
js/accounting.js
new
+21
@@ -0,0 +1,21 @@
1
+// Derived inventory and project profitability. No mutable stock side effects.
2
+(function(){
3
+const n=v=>Number(v)||0;
4
+function productMovement(productId){
5
+ const opening=n(getMyProducts().find(p=>p.id===productId)?.stock);
6
+ const purchased=getMyPurchases().reduce((sum,p)=>sum+(p.items||[]).filter(i=>i.productId===productId).reduce((s,i)=>s+n(i.qty??i.quantity),0),0);
7
+ const sold=getMyInvoices().reduce((sum,p)=>sum+(p.items||[]).filter(i=>i.productId===productId).reduce((s,i)=>s+n(i.qty??i.quantity),0),0);
8
+ return {opening,purchased,sold,available:opening+purchased-sold};
9
+}
10
+function getInventorySnapshot(){return getMyProducts().map(p=>({productId:p.id,code:p.code,name:p.name,unit:p.unit||'عدد',...productMovement(p.id)}));}
11
+function getProjectFinancials(projectId){
12
+ const sales=getMyInvoices().filter(i=>i.projectId===projectId).reduce((s,i)=>s+n(i.grandTotal),0);
13
+ const purchases=getMyPurchases().filter(i=>i.costCenterId===projectId).reduce((s,i)=>s+n(i.grandTotal),0);
14
+ const expenses=getMyExpenses().filter(e=>e.projectId===projectId&&e.kind==='expense').reduce((s,e)=>s+n(e.amount),0);
15
+ const income=getMyExpenses().filter(e=>e.projectId===projectId&&e.kind==='income').reduce((s,e)=>s+n(e.amount),0);
16
+ const receipts=getMyPayments().filter(p=>p.projectId===projectId&&p.direction==='inbound').reduce((s,p)=>s+n(p.amount),0);
17
+ const payments=getMyPayments().filter(p=>p.projectId===projectId&&p.direction==='outbound').reduce((s,p)=>s+n(p.amount),0);
18
+ return {sales,purchases,expenses,income,receipts,payments,accrualProfit:sales+income-purchases-expenses,cashNet:receipts+income-payments-expenses};
19
+}
20
+window.productMovement=productMovement;window.getInventorySnapshot=getInventorySnapshot;window.getProjectFinancials=getProjectFinancials;
21
+})();
\ No newline at end of file