Compare commits

..

No commits in common. "43e2f41855f63fc5090978be0ad1354931459054" and "7d38525bd1a56d94f7d2347585064692ed62c74a" have entirely different histories.

4 changed files with 48 additions and 187 deletions

View File

@ -2,7 +2,7 @@
```javascript ```javascript
export default class Address { export default class Address {
constructor(uuid = "", name = "", company = "", street1 = "", street2 = "", zip = "", city = "", state = "", country = "", phone = "", email = "", taxid = "") { constructor(uuid = "", name = "", company = "", street1 = "", street2 = "", zip = "", city = "", state = "", country = "", phone = "", email = "") {
this.uuid = uuid; this.uuid = uuid;
this.name = name; this.name = name;
this.company = company; this.company = company;
@ -14,7 +14,6 @@ export default class Address {
this.country = country; this.country = country;
this.phone = phone; this.phone = phone;
this.email = email; this.email = email;
this.taxid = taxid;
this.residential = null; this.residential = null;
} }
@ -22,19 +21,14 @@ export default class Address {
if (address instanceof Address) { if (address instanceof Address) {
return address; return address;
} }
var a = new Address(address.uuid ?? "", address.name, address.company, address.street1, return new Address(address.uuid ?? "", address.name, address.company, address.street1,
address.street2, address.zip, address.city, address.state, address.country, address.street2, address.zip, address.city, address.state, address.country,
address.phone, address.email, address.taxid); address.phone, address.email);
return a;
} }
toStringArray(expandCountry = false) { toStringArray() {
var citystatezipLine = [this.city, this.state, this.zip].filter(Boolean); var citystatezipLine = [this.city, this.state, this.zip].filter(Boolean);
var country = this.country == defaultCountryCode() ? "" : this.country; return [this.name, this.company, this.street1, this.street2, `${citystatezipLine.join(" ")}`, (this.country == "US" ? "" : this.country)].filter(Boolean);
if (expandCountry && country != "") {
country = getCountryNameForISO(country);
}
return [this.name, this.company, this.street1, this.street2, `${citystatezipLine.join(" ")}`, country, (this.taxid ? "Tax ID " + this.taxid : "")].filter(Boolean);
} }
/** /**
@ -50,8 +44,7 @@ export default class Address {
&& this.city == address.city && this.city == address.city
&& this.state == address.state && this.state == address.state
&& this.zip == address.zip && this.zip == address.zip
&& this.country == address.country && this.country == address.country) {
&& this.taxid == address.taxid) {
return true; return true;
} }
return false; return false;

View File

@ -16,7 +16,6 @@ export class Package {
height: 999999, height: 999999,
weightOz: 999999, weightOz: 999999,
nonmachinable: false, nonmachinable: false,
additionalHandling: false,
internalid: 100, internalid: 100,
oversizeFlag: false oversizeFlag: false
}; };
@ -30,22 +29,10 @@ export class Package {
insurance: false, // can be a number in USD insurance: false, // can be a number in USD
signature: false, // can be false, "SIGNATURE", or "SIGNATURE_RESTRICTED" signature: false, // can be false, "SIGNATURE", or "SIGNATURE_RESTRICTED"
hazmat: false, hazmat: false,
perishable: false, liveAnimal: false, // DAY_OLD_POULTRY
crematedRemains: false,
liveAnimal: false, // BEES, DAY_OLD_POULTRY, ADULT_BIRDS, OTHER_LIVES
cod: false, // Collect on Delivery cod: false, // Collect on Delivery
codAmount: false, codAmount: false,
endorsement: "", // ADDRESS_SERVICE_REQUESTED, CHANGE_SERVICE_REQUESTED, FORWARDING_SERVICE_REQUESTED, LEAVE_IF_NO_RESPONSE, RETURN_SERVICE_REQUESTED endorsement: "" // ADDRESS_SERVICE_REQUESTED, CHANGE_SERVICE_REQUESTED, FORWARDING_SERVICE_REQUESTED, LEAVE_IF_NO_RESPONSE, RETURN_SERVICE_REQUESTED
carrier_billing_account: {// Bill a third party's account number for the label
type: "", // "" (ignores this entire option), "SENDER" (EasyPost default), "THIRD_PARTY", "RECEIVER", "COLLECT"
carrier: "", // Carrier ID (should be used to filter rates)
account_number: "", // Carrier account number to bill
country: "", // Country account is based in
postal_code: "" // Postal code of account
},
dryIce: false,
dryIceWeight: 0,
dryIceMedical: false
}; };
this.specialRateEligibility = false; this.specialRateEligibility = false;
this.customs = { this.customs = {
@ -55,8 +42,7 @@ export class Package {
restriction: "", restriction: "",
restrictionComments: "", // needed if restriction is "other" restrictionComments: "", // needed if restriction is "other"
nonDelivery: "return", // "return" or "abandon", nonDelivery: "return", // "return" or "abandon",
eel_pfc: "", items: [] // {index: 0, description: "", qty: "", weight: "", value: "", hscode: "", origin: US"}
items: [] // {index: 0, description: "", qty: "", lbs: "", oz: "", value: "", hscode: "", origin: US"}
}; };
this.toAddress = new Address(); this.toAddress = new Address();
this.returnAddress = new Address(); this.returnAddress = new Address();
@ -69,7 +55,7 @@ export class Package {
* @returns {Package.toEasyPostShipment.shipment} * @returns {Package.toEasyPostShipment.shipment}
*/ */
async toEasyPostShipment() { async toEasyPostShipment() {
// Not relevant to plugins // removed
} }
/** /**
@ -77,7 +63,21 @@ export class Package {
* @returns {Package.toSERAShipment.shipment} * @returns {Package.toSERAShipment.shipment}
*/ */
async toSERAShipment() { async toSERAShipment() {
// Not relevant to plugins // removed
}
toJSON() {
return {
prepaid: this.prepaid,
packaging: this.packaging,
extraServices: this.extraServices,
specialRateEligibility: this.specialRateEligibility,
customs: this.customs,
toAddress: this.toAddress,
returnAddress: this.returnAddress,
originAddress: this.originAddress,
trackingNumber: this.trackingNumber
};
} }
/** /**
@ -91,50 +91,16 @@ export class Package {
let weight = ozToLbsOz(this.packaging.weightOz); let weight = ozToLbsOz(this.packaging.weightOz);
let weightStr = this.packaging.weightOz >= 16 ? `${weight[0]} lbs ${weight[1]} oz` : `${weight[1]} oz`; let weightStr = this.packaging.weightOz >= 16 ? `${weight[0]} lbs ${weight[1]} oz` : `${weight[1]} oz`;
if (packaging != false) { if (packaging != false) {
if (packaging.irregular) {
if (packaging.weight === false) {
summary.push("Parcel");
} else {
summary.push(`${weightStr} Parcel`);
}
summary.push("Additional Handling");
} else {
if (packaging.weight === false) { if (packaging.weight === false) {
summary.push(packaging.name); summary.push(packaging.name);
} else { } else {
summary.push(`${weightStr} ${packaging.name}`); summary.push(`${weightStr} ${packaging.name}`);
} }
}
} else { } else {
summary.push(weightStr); summary.push(weightStr);
} }
if (this.extraServices.hazmat) { if (this.extraServices.liveAnimal) {
summary.push("HAZMAT"); summary.push("Contains Live Animals");
}
if (this.extraServices.liveAnimal === true) {
summary.push("Live Animals");
} else if (typeof this.extraServices.liveAnimal == "string") {
switch (this.extraServices.liveAnimal) {
case "BEES":
summary.push("Live Bees");
break;
case "DAY_OLD_POULTRY":
summary.push("Day-old Poultry");
break;
case "ADULT_BIRDS":
summary.push("Live Adult Birds");
break;
case "OTHER_LIVES":
default:
summary.push("Live Animals");
break;
}
}
if (this.extraServices.perishable) {
summary.push("Perishable");
}
if (this.extraServices.crematedRemains) {
summary.push("Cremated Remains");
} }
if (this.extraServices.certifiedMail) { if (this.extraServices.certifiedMail) {
summary.push("Certified Mail"); summary.push("Certified Mail");
@ -144,9 +110,6 @@ export class Package {
} else if (this.extraServices.signature == "SIGNATURE") { } else if (this.extraServices.signature == "SIGNATURE") {
summary.push("Signature Required"); summary.push("Signature Required");
} }
if (this.extraServices.signature == "ADULT_SIGNATURE") {
summary.push("Adult Signature Required");
}
if (this.extraServices.signature == "SIGNATURE_RESTRICTED") { if (this.extraServices.signature == "SIGNATURE_RESTRICTED") {
summary.push("Restricted Delivery"); summary.push("Restricted Delivery");
} }
@ -162,34 +125,6 @@ export class Package {
if (this.extraServices.cod) { if (this.extraServices.cod) {
summary.push("Collect on Delivery: $" + (this.extraServices.codAmount * 1.0).toFixed(2)); summary.push("Collect on Delivery: $" + (this.extraServices.codAmount * 1.0).toFixed(2));
} }
if (this.extraServices.dryIce && this.extraServices.dryIceWeight > 0) {
summary.push("Dry Ice: " + (this.extraServices.dryIceWeight * 1).toFixed(0) + " oz");
}
if (this.extraServices.carrier_billing_account?.type) {
if (this.extraServices.carrier_billing_account.type != "") {
var accountNumber = this.extraServices.carrier_billing_account.account_number;
var accountNumberCensored = accountNumber.substring(accountNumber.length - 4).padStart(accountNumber.length, "X");
var carrierName = this.extraServices.carrier_billing_account.carrier;
switch (this.extraServices.carrier_billing_account.type) {
case "SENDER":
summary.push(`Bill to sender ${carrierName} account #${accountNumberCensored}`);
break;
case "THIRD_PARTY":
summary.push(`Bill to third party ${carrierName} account #${accountNumberCensored}`);
break;
case "RECEIVER":
summary.push(`Bill to receiver ${carrierName} account #${accountNumberCensored}`);
break;
case "COLLECT":
if (accountNumber.length > 0) {
summary.push(`Bill collect ${carrierName} account #${accountNumberCensored}`);
} else {
summary.push(`Bill collect`);
}
break;
}
}
}
return summary.join("\n"); return summary.join("\n");
} }
@ -278,7 +213,7 @@ export class Package {
* @returns {boolean|string} true if okay, human-readable error message and instructions if not okay * @returns {boolean|string} true if okay, human-readable error message and instructions if not okay
*/ */
async isValid(kioskMode = false) { async isValid(kioskMode = false) {
// Removed from docs for brevity. Just a bunch of if statements to catch problems. // removed for brevity. Just a bunch of if statements.
} }
/** /**
@ -439,37 +374,21 @@ export class Package {
* @returns {address} * @returns {address}
*/ */
getReturnAddress() { getReturnAddress() {
var a = null;
if (typeof this.returnAddress == "object") { if (typeof this.returnAddress == "object") {
a = Address.fromObject(this.returnAddress); return this.returnAddress;
} else {
a = Address.fromObject(this.originAddress);
} }
if (a.country == "") { return this.originAddress;
a.country = defaultCountryCode();
}
return a;
} }
getToAddress() { getToAddress() {
var a = Address.fromObject(this.toAddress); return this.toAddress;
if (a.country == "") {
a.country = defaultCountryCode();
}
return a;
} }
getFromAddress() { getFromAddress() {
var a = null;
if (typeof this.originAddress == "object") { if (typeof this.originAddress == "object") {
a = Address.fromObject(this.originAddress); return this.originAddress;
} else {
a = Address.fromObject(this.returnAddress);
} }
if (a.country == "") { return this.returnAddress;
a.country = defaultCountryCode();
}
return a;
} }
} }
``` ```

View File

@ -13,10 +13,9 @@ export class ReceiptItem {
* @param {number} quantity Number of units * @param {number} quantity Number of units
* @param {number} cost Cost per unit. Used for automatic expense tracking. * @param {number} cost Cost per unit. Used for automatic expense tracking.
* @param {number} taxrate Examples: 0 (for 0%), 0.05 (for 5%), etc * @param {number} taxrate Examples: 0 (for 0%), 0.05 (for 5%), etc
* @param {string} taxableAmount The part of the sale price that's taxable. "" for default (all), "markup" for only taxing profit.
* @returns {ReceiptItem} * @returns {ReceiptItem}
*/ */
constructor(id, label, text, priceEach, quantity, cost, taxrate = 0.0, taxableAmount = "") { constructor(id, label, text, priceEach, quantity, cost, taxrate) {
this.id = id; this.id = id;
this.label = label; this.label = label;
if (text == null) { if (text == null) {
@ -32,36 +31,23 @@ export class ReceiptItem {
} else { } else {
this.taxRate = num(taxrate); this.taxRate = num(taxrate);
} }
this.taxableAmount = taxableAmount;
this.merch = false; this.merch = false;
this.merchid = null; this.merchid = null;
this.surcharge = false; this.surcharge = false;
this.retail = 0; // For ensuring PostalPoint fee collection on office mode shipments this.retail = 0; // For ensuring PostalPoint fee collection on office mode shipments
this.mailboxNumber = null;
this.mailboxDays = 0;
this.mailboxMonths = 0;
this.category = ""; // merch category
this.electronicReturnReceipt = false;
} }
static fromJSON(obj) { static fromJSON(obj) {
var item = new ReceiptItem(obj.id, obj.label, obj.text, obj.priceEach, obj.qty, obj.cost, obj.taxRate, obj.taxableAmount ?? ""); var item = new ReceiptItem(obj.id, obj.label, obj.text, obj.priceEach, obj.qty, obj.cost, obj.taxRate);
item.free = obj.free; item.free = obj.free;
item.barcode = obj.barcode; item.barcode = obj.barcode;
item.certifiedInfo = obj.certifiedInfo; item.certifiedInfo = obj.certifiedInfo;
item.toAddress = obj.toAddress; item.toAddress = obj.toAddress;
item.fromAddress = obj.fromAddress; item.fromAddress = obj.fromAddress;
item.merch = obj.isMerch == true || (typeof obj.merchid == "string" && obj.merchid.length > 0); item.merch = obj.isMerch == true;
item.merchid = obj.merchid ?? null; item.merchid = item.merch ? obj.merchid : null;
item.mailboxNumber = obj.mailboxNumber ?? null;
item.mailboxDays = obj.mailboxDays ?? 0;
item.mailboxMonths = obj.mailboxMonths ?? 0;
item.surcharge = obj.surcharge; item.surcharge = obj.surcharge;
item.retailPrice = obj.retail; item.retailPrice = obj.retail;
item.carrier = obj.carrier ?? null;
item.service = obj.service ?? null;
item.category = obj.category ?? "";
item.electronicReturnReceipt = obj.electronicReturnReceipt ?? false;
return item; return item;
} }
@ -75,8 +61,6 @@ export class ReceiptItem {
cost: num(this.cost), cost: num(this.cost),
retail: num(this.retail), retail: num(this.retail),
taxRate: num(this.taxRate), taxRate: num(this.taxRate),
taxableAmount: this.taxableAmount,
taxTotal: this.taxAmount,
free: this.free, free: this.free,
barcode: this.barcode, barcode: this.barcode,
certifiedInfo: this.certifiedInfo, certifiedInfo: this.certifiedInfo,
@ -84,14 +68,7 @@ export class ReceiptItem {
merchid: this.merchid, merchid: this.merchid,
surcharge: this.surcharge, surcharge: this.surcharge,
toAddress: this.toAddress, toAddress: this.toAddress,
fromAddress: this.fromAddress, fromAddress: this.fromAddress
mailboxNumber: this.mailboxNumber,
mailboxDays: this.mailboxDays,
mailboxMonths: this.mailboxMonths,
carrier: this.carrier,
service: this.service,
category: this.category,
electronicReturnReceipt: this.electronicReturnReceipt
}; };
} }
@ -161,11 +138,11 @@ export class ReceiptItem {
} }
get priceEachFormatted() { get priceEachFormatted() {
return getCurrencySymbol() + round(num(this.priceEach), 2).toFixed(2); return "$" + round(num(this.priceEach), 2).toFixed(2);
} }
get linePriceFormatted() { get linePriceFormatted() {
return getCurrencySymbol() + round(num(this.linePrice), 2).toFixed(2); return "$" + round(num(this.linePrice), 2).toFixed(2);
} }
get texthtml() { get texthtml() {
@ -183,17 +160,8 @@ export class ReceiptItem {
} }
get taxAmount() { get taxAmount() {
if (this.taxableAmount == "markup") {
var lineCost = m(this.cost, this.qty);
var margin = s(this.linePrice, lineCost);
if (margin <= 0) {
return 0;
}
return round(m(margin, this.taxRate), 2);
} else {
return round(m(this.linePrice, this.taxRate), 2); return round(m(this.linePrice, this.taxRate), 2);
} }
}
get retailPrice() { get retailPrice() {
if (typeof this.retail == "number") { if (typeof this.retail == "number") {
@ -251,7 +219,7 @@ export class ReceiptPayment {
} }
get amountFormatted() { get amountFormatted() {
return getCurrencySymbol() + this.amount.toFixed(2); return "$" + this.amount.toFixed(2);
} }
get label() { get label() {
@ -277,8 +245,6 @@ export class ReceiptPayment {
return "Cryptocurrency"; return "Cryptocurrency";
case "ach": case "ach":
return "ACH Debit"; return "ACH Debit";
case "rounding":
return "Cash Rounding";
default: default:
return this.type; return this.type;
} }

View File

@ -13,12 +13,10 @@ export class TrackingBarcode {
constructor(code) { constructor(code) {
// All data are optional except for the tracking number. Missing data is gracefully handled by the PostalPoint UI. // All data are optional except for the tracking number. Missing data is gracefully handled by the PostalPoint UI.
this.cleanCode = code; this.cleanCode = code;
// Original barcode data this was created from
this.barcode = code;
// Destination ZIP Code, for domestic shipments. The city and state are automatically added. If toAddress is specified, toZip is ignored in favor of it. // Destination ZIP Code, for domestic shipments. The city and state are automatically added. If toAddress is specified, toZip is ignored in favor of it.
this.toZip = ""; this.toZip = "";
// Two-letter destination country code. If not "US", toZip is ignored, and the full country name is appended to the displayed address information. // Two-letter destination country code. If not "US", toZip is ignored, and the full country name is appended to the displayed address information.
this.toCountry = defaultCountryCode(); this.toCountry = "US";
// If toAddress is set, it will be used instead of the toZip when displaying the destination. // If toAddress is set, it will be used instead of the toZip when displaying the destination.
// If both toZip and toAddress are empty strings, no destination will be displayed. // If both toZip and toAddress are empty strings, no destination will be displayed.
this.toAddress = ""; this.toAddress = "";
@ -35,10 +33,6 @@ export class TrackingBarcode {
this.serviceShort = ""; this.serviceShort = "";
// If set to false, the barcode will be rejected with a suitable message when PostalPoint is running in self-serve kiosk mode. // If set to false, the barcode will be rejected with a suitable message when PostalPoint is running in self-serve kiosk mode.
this.dropoff = true; this.dropoff = true;
// If false, app may prompt user to specify the shipping carrier
this.confidentCarrier = true;
// Extra description strings, like "Signature Required"
this.extraInfo = [];
} }
/** /**
@ -115,21 +109,14 @@ export class TrackingBarcode {
if (this.toAddress != "") { if (this.toAddress != "") {
addressLines.push(...this.toAddress.split("\n")); addressLines.push(...this.toAddress.split("\n"));
} }
if (defaultCountryCode() == this.toCountry.toUpperCase() && this.toCountry.toUpperCase() == "US" && this.toZip != "" && this.toAddress == "") { if (this.toCountry.toUpperCase() == "US" && this.toZip != "" && this.toAddress == "") {
// Domestic shipment within USA, look up ZIP code
var zipdata = getZIP(this.toZip); var zipdata = getZIP(this.toZip);
if (zipdata != false) { if (zipdata != false) {
addressLines.push(`${zipdata.city} ${zipdata.state} ${this.toZip}`); addressLines.push(`${zipdata.city} ${zipdata.state} ${this.toZip}`);
} else { } else {
addressLines.push(`${this.toZip}`); addressLines.push(`${this.toZip}`);
} }
} else if (defaultCountryCode() == this.toCountry.toUpperCase()) { } else if (this.toCountry.toUpperCase() != "US") {
// Domestic shipment, outside USA, add postal code line if we have one
if (this.toZip != "" && this.toAddress.includes(this.toZip) != true) {
addressLines.push(`${this.toZip}`);
}
} else {
// International shipment, add country name
addressLines.push(getCountryNameForISO(this.toCountry)); addressLines.push(getCountryNameForISO(this.toCountry));
} }
return addressLines.join("\n"); return addressLines.join("\n");
@ -156,10 +143,6 @@ export class TrackingBarcode {
lines.push(...destlines); lines.push(...destlines);
} }
if (typeof this.extraInfo == "object" && this.extraInfo.length > 0) {
lines.push(...this.extraInfo);
}
return lines.join("\n"); return lines.join("\n");
} }
} }