这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ coverage/
typings/
*.d.ts
*.log
*.tgz
*.tgz
/samples/node/mongooseStoreSampleProject
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.0.0

- Fix UMD lib. Add browser usage sample (breaking changes will go to 2.x)

## 1.0.0-alpha.1

- Prepare for asynchronous storages (api/db).

## 0.0.7

- Adding nomenclature
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billing",
"version": "0.0.7",
"version": "1.0.0",
"description": "Billing Module Js",
"author": "AlexV",
"repository": {
Expand All @@ -20,10 +20,10 @@
"typings": "typings install",
"test": "karma start karma.conf.js",
"build": "tsc -d",
"dist": "webpack -p"
"dist": "webpack --progress --profile --bail"
},
"devDependencies": {
"@types/jasmine": "^2.2.31",
"awesome-typescript-loader": "^2.2.4",
"istanbul": "^0.4.5",
"jasmine-core": "^2.4.1",
"karma": "^1.2.0",
Expand All @@ -33,7 +33,6 @@
"karma-phantomjs-launcher": "^1.0.2",
"karma-typescript": "^2.0.5",
"source-map": "^0.5.6",
"ts-loader": "^0.8.2",
"typescript": "^2.0.0",
"typings": "^1.3.3",
"webpack": "^1.13.2"
Expand Down
21 changes: 21 additions & 0 deletions samples/browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Billing test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src='../../dist/billing.js'></script>
<script>
if (window.billingJs) {
var bill = billingJs.Billing.bills.new();
bill.charges.new({ price: 1 });
bill.modifiers.new({ percentRatio: 0.5 });
bill.payments.new()
document.write(JSON.stringify(bill.toJson()));
} else document.write('billingJs unavailable (exec "npm run dist" first)')
</script>
</head>
<body>

</body>
</html>
10 changes: 9 additions & 1 deletion src/billing/bill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,15 @@ export class Bill extends ValidationModel {
}

get operator() {
if (this.operatorId) return Operator.find(this.operatorId);
let _operator :Operator;
if (this.operatorId) {
Operator.find(this.operatorId, (operator)=> {
_operator = operator;
}).catch((err)=> {
console.warn(`Bill#operator ${this.operatorId} ${err.message}`);
});
}
return _operator;
}

static new(attributes :any = {}) :Bill {
Expand Down
16 changes: 11 additions & 5 deletions src/billing/charge/charge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ describe('Charge', () => {
expect(charge.description).toEqual('Fresh');
});

it('set price', function() {
it('set price', function(done) {
let charge = new Charge({ pluId: 1 });
expect(charge.price).toEqual(0);
charge.price = 1.26;
expect(charge.price).toEqual(1.26);
done();
});

it('set modifier', function() {
Expand Down Expand Up @@ -310,10 +311,11 @@ describe('Charge', () => {
expect(charge.taxRatio).toEqual(0.09);
});

it('missing nomenclature should not throw exteptions', function() {
it('missing nomenclature should not throw exteptions', function(done) {
let charge = new Charge({ pluId: 2 });
expect(()=> { charge.taxRatio; }).not.toThrow();
expect(charge.department).toBeUndefined();
done();
});

it('direct department', function() {
Expand All @@ -334,11 +336,15 @@ describe('Charge', () => {

it('update nomenclature direct', function() {
let charge = new Charge({ price: 3 });
charge.update({ plu: Nomenclature.Plu.find(1) });
let plu: Nomenclature.Plu, taxGroup :Nomenclature.TaxGroup, department: Nomenclature.Department;
Nomenclature.Plu.find(1, (r)=> plu = r );
charge.update({ plu: plu });
expect(charge.pluId).toEqual(1);
charge.update({ taxGroup: Nomenclature.TaxGroup.find(1) });
Nomenclature.TaxGroup.find(1, (r)=> taxGroup = r );
charge.update({ taxGroup: taxGroup });
expect(charge.taxGroupId).toEqual(1);
charge.update({ department: Nomenclature.Department.find(2) });
Nomenclature.Department.find(2, (r)=> department = r );
charge.update({ department: department });
expect(charge.departmentId).toEqual(2);
});
});
Expand Down
27 changes: 23 additions & 4 deletions src/billing/charge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BillItem } from '../concerns/billItem';
import { Modifier } from '../modifier';
import { IChargeAttributes } from './interface';
import { IModifierAttributes } from '../modifier/interface';
import { ChargesCollection } from './collection';

import { Plu, TaxGroup, Department } from '../nomenclature';

Expand Down Expand Up @@ -194,21 +195,39 @@ export class Charge extends BillItem {
}

get plu() :Plu {
if (this.pluId) return Plu.find(this.pluId);
let _plu :Plu;
if (this.pluId) Plu.find(this.pluId, (plu)=> {
_plu = plu;
}).catch((err)=> {
console.warn(`Charge#plu ${this.pluId} ${err.message}`);
});
return _plu;
}
set plu(plu :Plu) {
this.pluId = plu.id;
}

get taxGroup() {
if (this.taxGroupId) return TaxGroup.find(this.taxGroupId);
let _taxGroup :TaxGroup;
if (this.taxGroupId) TaxGroup.find(this.taxGroupId, (taxGroup)=> {
_taxGroup = taxGroup;
}).catch((err)=> {
console.warn(`Charge#taxGroup ${this.taxGroupId} ${err.message}`);
});
return _taxGroup;
}
set taxGroup(taxGroup :TaxGroup) {
this.taxGroupId = taxGroup.id;
}

get department() {
if (this.departmentId) return Department.find(this.departmentId);
let _department :Department;
if (this.departmentId) Department.find(this.departmentId, (department)=> {
_department = department;
}).catch((err)=> {
console.warn(`Charge#department ${this.departmentId} ${err.message}`);
});
return _department;
}
set department(department :Department) {
this.departmentId = department.id;
Expand All @@ -222,4 +241,4 @@ Charge.validates('modifier', { invalid: (self)=> {
return self.modifier && !self.modifier.isValid;
}});

export { ChargesCollection } from './collection';
export { ChargesCollection };
5 changes: 5 additions & 0 deletions src/billing/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import * as NObjects from './nomenclature';

export interface IBillAttributes {
Expand Down
3 changes: 2 additions & 1 deletion src/billing/modifier/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { BillItem } from '../concerns/billItem';
import { Charge } from '../charge';
import { IModifierAttributes } from './interface';
import { ModifiersCollection } from './collection';

/**
*
Expand Down Expand Up @@ -128,4 +129,4 @@ Modifier.validates('value', { notEqualTo: 0,
}
});

export { ModifiersCollection } from './collection';
export { ModifiersCollection };
13 changes: 12 additions & 1 deletion src/billing/nomenclature/department/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { Storable } from '../../storable';
import { IDepartment } from './interface';
import { TaxGroup } from '../index';
Expand All @@ -13,7 +18,13 @@ export class Department extends Storable {
}

get taxGroup() :TaxGroup {
if (this.taxGroupId) return TaxGroup.find(this.taxGroupId);
let _taxGroup :TaxGroup
if (this.taxGroupId) TaxGroup.find(this.taxGroupId, (taxGroup)=> {
_taxGroup = taxGroup;
}).catch((err)=> {
console.warn(`Plu#taxGroup ${this.taxGroupId} ${err.message}`);
});
return _taxGroup;
}

constructor(attributes :IDepartment) {
Expand Down
5 changes: 5 additions & 0 deletions src/billing/nomenclature/department/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { IStoreRecord, IStoreConfig } from '../../storable/interface';

export declare type TDepartmentConfig = Array<IDepartment> | IStoreConfig;
Expand Down
5 changes: 5 additions & 0 deletions src/billing/nomenclature/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { TOperatorsConfig } from './operator/interface';
import { TTaxGroupConfig } from './taxGroup/interface';
import { TPaymentTypeConfig } from './paymentType/interface';
Expand Down
5 changes: 3 additions & 2 deletions src/billing/nomenclature/nomenclature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// <reference path="../../../typings/index.d.ts" />

import * as Nomenclature from './index';
import { MemoryStore } from '../store';
import { MemoryStore } from '../storable';

describe('Nomenclature', ()=> {
it('stores', function() {
Expand All @@ -17,7 +17,8 @@ describe('Nomenclature', ()=> {
departments: [],
plus: [{ id: 1, code: '2', name: 'Test Plu', departmentId: 3, price: 4 }]
});
let plu = Nomenclature.Plu.find(1);
let plu :Nomenclature.Plu;
Nomenclature.Plu.find(1, (r)=> plu = r );
expect(plu instanceof Nomenclature.Plu).toBeTruthy();
expect([plu.id, plu.code, plu.name, plu.departmentId, plu.price]).toEqual([1, '2', 'Test Plu',3, 4]);
});
Expand Down
5 changes: 5 additions & 0 deletions src/billing/nomenclature/operator/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { IOperator } from './interface';
import { Storable } from '../../storable';

Expand Down
5 changes: 5 additions & 0 deletions src/billing/nomenclature/operator/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { IStoreRecord, IStoreConfig } from '../../storable/interface';

export declare type TOperatorsConfig = Array<IOperator> | IStoreConfig;
Expand Down
5 changes: 5 additions & 0 deletions src/billing/nomenclature/paymentType/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { IStoreRecord, IStoreConfig } from '../../storable/interface';

export declare type TPaymentTypeConfig = Array<IPaymentType> | IStoreConfig;
Expand Down
8 changes: 7 additions & 1 deletion src/billing/nomenclature/plu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export class Plu extends Storable {
}

get department() :Department {
if (this.departmentId) return Department.find(this.departmentId);
let _departpent :Department;
if (this.departmentId) Department.find(this.departmentId, (department)=> {
_departpent = department;
}).catch((err)=> {
console.warn(`Plu#department ${this.departmentId} ${err.message}`);
});
return _departpent;
}

constructor(attributes :IPlu) {
Expand Down
5 changes: 5 additions & 0 deletions src/billing/nomenclature/plu/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { IStoreRecord, IStoreConfig } from '../../storable/interface';

export declare type TPluConfig = Array<IPlu> | IStoreConfig;
Expand Down
5 changes: 5 additions & 0 deletions src/billing/nomenclature/taxGroup/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2016 AlexV <email@data.bg>
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

import { IStoreRecord, IStoreConfig } from '../../storable/interface';

export declare type TTaxGroupConfig = Array<ITaxGroup> | IStoreConfig;
Expand Down
11 changes: 9 additions & 2 deletions src/billing/payment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BillItem } from '../concerns/billItem';
import { IPaymentAttributes } from './interface';

import { PaymentType } from '../nomenclature';
import { PaymentsCollection } from './collection';

/**
*
Expand Down Expand Up @@ -101,7 +102,13 @@ export class Payment extends BillItem {
}

get paymentType() {
if (this.paymentTypeId) return PaymentType.find(this.paymentTypeId);
let _paymentType :PaymentType;
if (this.paymentTypeId) PaymentType.find(this.paymentTypeId, (r)=> {
_paymentType = r;
}).catch((err)=> {
console.warn(`Payment#paymentType ${this.paymentTypeId} ${err.message}`);
});;
return _paymentType;
}
set paymentType(paymentType :PaymentType) {
this.paymentTypeId = paymentType.id;
Expand All @@ -118,4 +125,4 @@ Payment.validates('paymentType', {
}
});

export { PaymentsCollection } from './collection';
export { PaymentsCollection };
Loading