Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
317 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Balance, IERPCore } from './ERPMeta.ts' | ||
import { DBCore } from './DBCore.ts' | ||
|
||
export class ERPCore extends DBCore implements IERPCore { | ||
static open(dbpath: string, no_cache: boolean = false): ERPCore { | ||
const db = new ERPCore(dbpath) | ||
db.init() | ||
return db | ||
} | ||
|
||
bal_key_from_ids(ids: string[]): string { | ||
let key = 'bal' | ||
for (const id of ids) { | ||
key += '|' + this.key_from_id(id) | ||
} | ||
return key | ||
} | ||
|
||
get_bal_by_key(key: string): Balance { | ||
let bal = this.get_top(key, true) | ||
if (bal === undefined) { | ||
bal = { | ||
type: 'bal', | ||
key: key, | ||
id: undefined, | ||
qty: 0, | ||
val: 0, | ||
iqty: 0, | ||
ival: 0, | ||
oqty: 0, | ||
oval: 0, | ||
} | ||
} else { | ||
bal = Object.assign({}, bal) | ||
} | ||
return bal | ||
} | ||
|
||
get_bal(ids: string[]): Balance { | ||
const key = this.bal_key_from_ids(ids) | ||
return this.get_bal_by_key(key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Document, Result, DocClass, IDBCore } from './DBMeta.ts' | ||
|
||
export { Document, Result, DocClass } | ||
|
||
export interface Balance { | ||
type?: string, | ||
key: string, | ||
id?: string, | ||
qty: number, // остаток в наличии | ||
val: number, | ||
iqty: number, // ожидаемый приход | ||
ival: number, | ||
oqty: number, // ожидаемый расход | ||
oval: number, | ||
} | ||
|
||
export interface IERPCore extends IDBCore { | ||
get_bal(ids: string[]): Balance | ||
get_bal_by_key(key: string): Balance | ||
bal_key_from_ids(ids: string[]): string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import { DocClass } from '../core/DBMeta.ts' | ||
import { DocClass } from '../core/ERPMeta.ts' | ||
|
||
import ref from './ref.ts' | ||
import bal from './bal.ts' | ||
import purch from './purch.ts' | ||
import sale from './sale.ts' | ||
import transfer from './transfer.ts' | ||
import post_purch from './post_purch.ts' | ||
import post_sale from './post_sale.ts' | ||
import post_transfer from './post_transfer.ts' | ||
import open_purch from './open_purch.ts' | ||
import open_sale from './open_sale.ts' | ||
|
||
export function get_doc_class(type: string) { // : DocClass { как указать что возвращается не инстанс, а сам класс ? | ||
switch (type) { | ||
case 'person': return ref | ||
case 'nomen': return ref | ||
case 'stock': return ref | ||
case 'bal': return bal | ||
case 'purch': return purch | ||
case 'sale': return sale | ||
case 'transfer': return transfer | ||
case 'post.purch': return post_purch | ||
case 'post.sale': return post_sale | ||
case 'post.transfer': return post_transfer | ||
case 'open.purch': return open_purch | ||
case 'open.sale': return open_sale | ||
default: throw `Error: document type "${type}" is not registered in doc_classes !` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Document, DocClass, IERPCore } from '../core/ERPMeta.ts' | ||
|
||
export default class OpenPurch extends DocClass { | ||
static after_add(doc: Document, db: IERPCore): void { | ||
doc.lines.forEach(line => { | ||
const bal = db.get_bal([line.nomen, doc.stock]) | ||
bal.iqty += line.qty | ||
bal.ival += line.qty * line.price | ||
db.add_mut(bal) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Document, DocClass, IERPCore } from '../core/ERPMeta.ts' | ||
|
||
export default class OpenSale extends DocClass { | ||
static after_add(doc: Document, db: IERPCore): void { | ||
doc.lines.forEach(line => { | ||
const bal = db.get_bal([line.nomen, doc.stock]) | ||
line.from = bal.id | ||
line.cost = (bal.val + bal.ival) / (bal.qty + bal.iqty) // себестоимость в момент списания с учетом ожидаемых приходов | ||
bal.oqty -= line.qty | ||
bal.oval -= line.qty * line.cost | ||
db.add_mut(bal) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Document, DocClass, IERPCore } from '../core/ERPMeta.ts' | ||
|
||
export default class PostPurch extends DocClass { | ||
static after_add(doc: Document, db: IERPCore): void { | ||
doc.lines.forEach(line => { | ||
const bal = db.get_bal([line.nomen, doc.stock]) | ||
bal.qty += line.qty | ||
bal.val += line.qty * line.price | ||
db.add_mut(bal) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Document, DocClass, IERPCore } from '../core/ERPMeta.ts' | ||
|
||
export default class PostSale extends DocClass { | ||
static before_add(doc: Document, db: IERPCore): [boolean, string?] { | ||
let err = '' | ||
doc.lines.forEach(line => { | ||
const key = [line.nomen, doc.stock] | ||
const bal = db.get_bal(key) | ||
if (bal.qty < line.qty) { | ||
err += '\n"' + key + '": requested ' + line.qty + ' but balance is only ' + bal.qty | ||
} | ||
}) | ||
return err !== '' ? [false, err] : [true,] | ||
} | ||
|
||
static after_add(doc: Document, db: IERPCore): void { | ||
doc.lines.forEach(line => { | ||
const bal = db.get_bal([line.nomen, doc.stock]) | ||
line.from = bal.id | ||
line.cost = (bal.val + bal.ival) / (bal.qty + bal.iqty) // себестоимость в момент списания с учетом ожидаемых приходов | ||
bal.qty -= line.qty | ||
bal.val -= line.qty * line.cost | ||
db.add_mut(bal) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Document, DocClass, IERPCore } from '../core/ERPMeta.ts' | ||
|
||
export default class PostTransfer extends DocClass { | ||
static before_add(doc: Document, db: IERPCore): [boolean, string?] { | ||
let err = '' | ||
doc.lines.forEach(line => { | ||
const key = [line.nomen, doc.stock1] | ||
const bal = db.get_bal(key) | ||
if (bal.qty < line.qty) { | ||
err += '\n"' + key + '": requested ' + line.qty + ' but balance is only ' + bal.qty | ||
} | ||
}) | ||
return err !== '' ? [false, err] : [true,] | ||
} | ||
|
||
static after_add(doc: Document, db: IERPCore): void { | ||
doc.lines.forEach(line => { | ||
let bal = db.get_bal([line.nomen, doc.stock1]) | ||
line.from = bal.id | ||
line.cost = (bal.val + bal.ival) / (bal.qty + bal.iqty) // себестоимость в момент списания с учетом ожидаемых приходов | ||
bal.qty -= line.qty | ||
bal.val -= line.qty * line.cost | ||
db.add_mut(bal) | ||
|
||
bal = db.get_bal([line.nomen, doc.stock2]) | ||
bal.qty += line.qty | ||
bal.val += line.qty * line.cost | ||
db.add_mut(bal) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.