diff --git a/Prices.txt b/Prices.txt
index 3588163..5a12983 100644
--- a/Prices.txt
+++ b/Prices.txt
@@ -29,8 +29,8 @@ Loc = Can
400 < W < 500 $5.05
Loc = US
Standard
- W < 30 $1.80
- 30 < W < 50 $1.20
+ W < 30 $1.20
+ 30 < W < 50 $1.80
Non-Standard
W < 100 $2.95
100 < W < 200 $5.15
diff --git a/app/pages/item-types/item-types.html b/app/pages/item-types/item-types.html
index 9336aac..8fa2769 100644
--- a/app/pages/item-types/item-types.html
+++ b/app/pages/item-types/item-types.html
@@ -9,5 +9,32 @@
-
+
+
+ Please enter information about your package (heh)
+
+
+
+
+
+
+
+
diff --git a/app/pages/item-types/item-types.js b/app/pages/item-types/item-types.js
index 13b9fe4..de80d98 100644
--- a/app/pages/item-types/item-types.js
+++ b/app/pages/item-types/item-types.js
@@ -1,4 +1,4 @@
-import {Page, NavController} from 'ionic/ionic';
+import {Page, NavController, Alert} from 'ionic/ionic';
import {PostalRateServices} from '../../providers/postal-rate-services/postal-rate-services'
@@ -14,6 +14,45 @@ import {PostalRateServices} from '../../providers/postal-rate-services/postal-ra
export class ItemTypesPage {
constructor(nav:NavController, dataServices: PostalRateServices) {
this.nav = nav;
+ this.service = dataServices;
this.data = dataServices.dest;
+ this.dimensions = {
+ length: 0,
+ thickness: 0,
+ width: 0,
+ weight: 0,
+ }
+ this.price = 0;
+ this.isStandard = true;
+ this.error = '';
+ }
+
+
+ calculatePrice(form) {
+ if (form.valid) {
+ this.error = this.service.getError(this.dimensions);
+ if (this.error === '') {
+ this.isStandard = this.service.getStandard(this.dimensions);
+ this.price = this.service.getPrice(this.dimensions, this.data, this.isStandard);
+ let alert = Alert.create({
+ title: 'PRICE',
+ subTitle: 'The price to ship your package is $' + this.price.toFixed(2) + '.',
+ buttons: ['Ok']
+ });
+ this.nav.present(alert);
+ } else {
+ let alert = Alert.create({
+ subTitle: this.error,
+ buttons: ['Ok']
+ });
+ this.nav.present(alert);
+ }
+ } else {
+ let alert = Alert.create({
+ subTitle: 'Please fill in all fields!',
+ buttons: ['Ok']
+ });
+ this.nav.present(alert);
+ }
}
}
diff --git a/app/pages/postage-destination/postage-destination.html b/app/pages/postage-destination/postage-destination.html
index 28d1509..74e21b0 100644
--- a/app/pages/postage-destination/postage-destination.html
+++ b/app/pages/postage-destination/postage-destination.html
@@ -19,7 +19,7 @@
(A Mobile Postal Rate Calculator)
-
+
Where would you like to send a package?
diff --git a/app/pages/postage-destination/postage-destination.js b/app/pages/postage-destination/postage-destination.js
index 08c2121..49a2cd5 100644
--- a/app/pages/postage-destination/postage-destination.js
+++ b/app/pages/postage-destination/postage-destination.js
@@ -20,6 +20,6 @@ export class PostageDestinationPage {
}
setDestination(dest) {
this.service.setDest(dest);
- this.nav.push(ItemTypesPage, {dest: dest, name: name});
+ this.nav.push(ItemTypesPage, {dest: dest});
}
}
diff --git a/app/providers/postal-rate-services/postal-rate-services.js b/app/providers/postal-rate-services/postal-rate-services.js
index b015dfb..1127067 100644
--- a/app/providers/postal-rate-services/postal-rate-services.js
+++ b/app/providers/postal-rate-services/postal-rate-services.js
@@ -35,15 +35,66 @@ export class PostalRateServices {
setDest(dest) {
this.dest = dest;
};
+ //
+ //L < 140 Error
+ //W < 90 Error
+ //T < 0.18 Error
+ //We < 2 Error
+ //L > 380 Error
+ //W > 270 Error
+ //T > 20 Error
+ //We > 500 Error
- getPrice(item, weight) {
- if (weight < 0) return 0;
- for(var i = 0; i < item.length; i++) {
- if(weight > item[i].minWeight && weight <= item[i].maxWeight) return item[i].price;
- }
- return 0;
+ getError(dim) {
+ if (dim.length < 140) return 'Length must be larger than 140 mm.';
+ if (dim.width < 90) return 'Width must be larger than 90 mm.';
+ if (dim.thickness < 0.18) return 'Thickness must be larger than 0.18 mm.';
+ if (dim.weight < 2) return 'Weight must be larger than 2 g.';
+ if (dim.length > 380) return 'Length must be smaller than 380 mm.';
+ if (dim.width > 270) return 'Width must be smaller than 270 mm.';
+ if (dim.thickness > 20) return 'Length must be smaller than 20 mm.';
+ if (dim.weight > 500) return 'Weight must be smaller than 500 g.';
+ else return '';
+ }
- };
+ getStandard(dim) {
+ if (140 < dim.length && dim.length < 245 && 90 < dim.width && dim.width < 156
+ && 0.18 < dim.thickness && dim.thickness < 5 && 2 < dim.weight && dim.weight < 50) return true;
+ else return false;
+ }
+ getPrice(dim, data, isStandard) {
+ if (data.name === 'Canada') {
+ if (isStandard) {
+ if (dim.weight < 30) return 0.85;
+ else return 1.2;
+ } else {
+ if (dim.weight < 100) return 1.8;
+ else if (100 < dim.weight && dim.weight < 200) return 2.95;
+ else if (200 < dim.weight && dim.weight < 300) return 4.1;
+ else if (300 < dim.weight && dim.weight < 400) return 4.7;
+ else return 5.05;
+ }
+ } else if (data.name === 'USA') {
+ if (isStandard) {
+ if (dim.weight < 30) return 1.2;
+ else return 1.8;
+ } else {
+ if (dim.weight < 100) return 2.95;
+ else if (100 < dim.weight && dim.weight < 200) return 5.15;
+ else return 10.3;
+ }
+ } else if (data.name === 'USA') {
+ if (isStandard) {
+ if (dim.weight < 30) return 2.5;
+ else return 3.6;
+ } else {
+ if (dim.weight < 100) return 5.9;
+ else if (100 < dim.weight && dim.weight < 200) return 10.3;
+ else return 20.6;
+ }
+ }
+ return 0;
+ }
}