Compare commits

...

2 Commits

4 changed files with 187 additions and 48 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 = "") { constructor(uuid = "", name = "", company = "", street1 = "", street2 = "", zip = "", city = "", state = "", country = "", phone = "", email = "", taxid = "") {
this.uuid = uuid; this.uuid = uuid;
this.name = name; this.name = name;
this.company = company; this.company = company;
@ -14,6 +14,7 @@ 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;
} }
@ -21,14 +22,19 @@ export default class Address {
if (address instanceof Address) { if (address instanceof Address) {
return address; return address;
} }
return new Address(address.uuid ?? "", address.name, address.company, address.street1, var a = 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.phone, address.email, address.taxid);
return a;
} }
toStringArray() { toStringArray(expandCountry = false) {
var citystatezipLine = [this.city, this.state, this.zip].filter(Boolean); var citystatezipLine = [this.city, this.state, this.zip].filter(Boolean);
return [this.name, this.company, this.street1, this.street2, `${citystatezipLine.join(" ")}`, (this.country == "US" ? "" : this.country)].filter(Boolean); var country = this.country == defaultCountryCode() ? "" : this.country;
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);
} }
/** /**
@ -44,7 +50,8 @@ 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,6 +16,7 @@ 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
}; };
@ -29,10 +30,22 @@ 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,
liveAnimal: false, // DAY_OLD_POULTRY perishable: false,
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 = {
@ -42,7 +55,8 @@ 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",
items: [] // {index: 0, description: "", qty: "", weight: "", value: "", hscode: "", origin: US"} eel_pfc: "",
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();
@ -55,7 +69,7 @@ export class Package {
* @returns {Package.toEasyPostShipment.shipment} * @returns {Package.toEasyPostShipment.shipment}
*/ */
async toEasyPostShipment() { async toEasyPostShipment() {
// removed // Not relevant to plugins
} }
/** /**
@ -63,21 +77,7 @@ export class Package {
* @returns {Package.toSERAShipment.shipment} * @returns {Package.toSERAShipment.shipment}
*/ */
async toSERAShipment() { async toSERAShipment() {
// removed // Not relevant to plugins
}
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,16 +91,50 @@ 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.weight === false) { if (packaging.irregular) {
summary.push(packaging.name); if (packaging.weight === false) {
summary.push("Parcel");
} else {
summary.push(`${weightStr} Parcel`);
}
summary.push("Additional Handling");
} else { } else {
summary.push(`${weightStr} ${packaging.name}`); if (packaging.weight === false) {
summary.push(packaging.name);
} else {
summary.push(`${weightStr} ${packaging.name}`);
}
} }
} else { } else {
summary.push(weightStr); summary.push(weightStr);
} }
if (this.extraServices.liveAnimal) { if (this.extraServices.hazmat) {
summary.push("Contains Live Animals"); summary.push("HAZMAT");
}
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");
@ -110,6 +144,9 @@ 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");
} }
@ -125,6 +162,34 @@ 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");
} }
@ -213,7 +278,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 for brevity. Just a bunch of if statements. // Removed from docs for brevity. Just a bunch of if statements to catch problems.
} }
/** /**
@ -374,21 +439,37 @@ export class Package {
* @returns {address} * @returns {address}
*/ */
getReturnAddress() { getReturnAddress() {
var a = null;
if (typeof this.returnAddress == "object") { if (typeof this.returnAddress == "object") {
return this.returnAddress; a = Address.fromObject(this.returnAddress);
} else {
a = Address.fromObject(this.originAddress);
} }
return this.originAddress; if (a.country == "") {
a.country = defaultCountryCode();
}
return a;
} }
getToAddress() { getToAddress() {
return this.toAddress; var a = Address.fromObject(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") {
return this.originAddress; a = Address.fromObject(this.originAddress);
} else {
a = Address.fromObject(this.returnAddress);
} }
return this.returnAddress; if (a.country == "") {
a.country = defaultCountryCode();
}
return a;
} }
} }
``` ```

View File

@ -13,9 +13,10 @@ 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) { constructor(id, label, text, priceEach, quantity, cost, taxrate = 0.0, taxableAmount = "") {
this.id = id; this.id = id;
this.label = label; this.label = label;
if (text == null) { if (text == null) {
@ -31,23 +32,36 @@ 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); var item = new ReceiptItem(obj.id, obj.label, obj.text, obj.priceEach, obj.qty, obj.cost, obj.taxRate, obj.taxableAmount ?? "");
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; item.merch = obj.isMerch == true || (typeof obj.merchid == "string" && obj.merchid.length > 0);
item.merchid = item.merch ? obj.merchid : null; item.merchid = 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;
} }
@ -61,6 +75,8 @@ 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,
@ -68,7 +84,14 @@ 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
}; };
} }
@ -138,11 +161,11 @@ export class ReceiptItem {
} }
get priceEachFormatted() { get priceEachFormatted() {
return "$" + round(num(this.priceEach), 2).toFixed(2); return getCurrencySymbol() + round(num(this.priceEach), 2).toFixed(2);
} }
get linePriceFormatted() { get linePriceFormatted() {
return "$" + round(num(this.linePrice), 2).toFixed(2); return getCurrencySymbol() + round(num(this.linePrice), 2).toFixed(2);
} }
get texthtml() { get texthtml() {
@ -160,7 +183,16 @@ export class ReceiptItem {
} }
get taxAmount() { get taxAmount() {
return round(m(this.linePrice, this.taxRate), 2); 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);
}
} }
get retailPrice() { get retailPrice() {
@ -219,7 +251,7 @@ export class ReceiptPayment {
} }
get amountFormatted() { get amountFormatted() {
return "$" + this.amount.toFixed(2); return getCurrencySymbol() + this.amount.toFixed(2);
} }
get label() { get label() {
@ -245,6 +277,8 @@ 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,10 +13,12 @@ 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 = "US"; this.toCountry = defaultCountryCode();
// 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 = "";
@ -33,6 +35,10 @@ 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 = [];
} }
/** /**
@ -109,14 +115,21 @@ export class TrackingBarcode {
if (this.toAddress != "") { if (this.toAddress != "") {
addressLines.push(...this.toAddress.split("\n")); addressLines.push(...this.toAddress.split("\n"));
} }
if (this.toCountry.toUpperCase() == "US" && this.toZip != "" && this.toAddress == "") { if (defaultCountryCode() == this.toCountry.toUpperCase() && 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 (this.toCountry.toUpperCase() != "US") { } else if (defaultCountryCode() == this.toCountry.toUpperCase()) {
// 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");
@ -143,6 +156,10 @@ 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");
} }
} }