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
7 changes: 6 additions & 1 deletion api/src/controllers/sales.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7712,7 +7712,12 @@ class SalesController extends BaseController {
if (response.status === true) {
return this.success(res, response.data, response.message);
} else {
return this.error(res, response.message, 404);
return this.error(
res,
response.message,
response.data?.state ? 422 : 404,
response.data?.state ? response.data : null
);
}
} catch (error) {
console.error('Error in updateOrder:', error);
Expand Down
22 changes: 21 additions & 1 deletion api/src/models/sale.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,13 @@ saleSchema.pre('save', async function () {
const src = item && typeof item.toObject === 'function' ? item.toObject() : item || {};

return {
...(src.pricing
? {
pricing: src.pricing,
unit_price: src.unit_price,
item_base_price: src.item_base_price,
}
: {}),
sale_inline_item_price: src.sale_inline_item_price != null ? src.sale_inline_item_price : 0,
sale_inline_discount_value:
src.sale_inline_discount_value != null ? src.sale_inline_discount_value : 0,
Expand Down Expand Up @@ -2069,7 +2076,19 @@ Sale.kioskOrderModel = async function (data) {

const discountAmount = parseFloat(doc.discount_amount) || 0;
const discountPercentage = parseFloat(doc.discount_percentage) || 0;
const sellingPrice = parseFloat(doc.selling_price) || 0;
const authority = require('../services/pricing-authority');
let pricing;
try {
pricing = authority.resolve({
product: doc,
branch: branchDoc,
submitted: item.unit_price ?? item.item_price ?? item.price,
channel: 'kiosk',
});
} catch (error) {
return authority.failure(error);
}
const sellingPrice = pricing.selling_price;
const itemAmount = sellingPrice * itemQuantity;
const companyPrice = itemQuantity * (parseFloat(doc.company_price) || 0);
total_company_data.push({ company_amount: companyPrice });
Expand Down Expand Up @@ -2143,6 +2162,7 @@ Sale.kioskOrderModel = async function (data) {
});

itemsale.push({
pricing,
sale_inline_item_price: sellingPrice,
sale_inline_discount_value: discountAmount,
sale_inline_discount_pervalue: discountPercentage,
Expand Down
16 changes: 13 additions & 3 deletions api/src/models/setting.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3668,7 +3668,7 @@ class SettingModel extends BaseModel {
const items = await this.getCollection('items');
const used = await items.countDocuments({
license: this.normalizeId(this.licenseId),
modifier_group_ids: this.normalizeId(id),
modifier_group_ids: new ObjectId(String(id)),
});
if (used > 0) {
return {
Expand All @@ -3678,8 +3678,13 @@ class SettingModel extends BaseModel {
};
}
const collection = await this.getCollection('modifier_groups');
const removed = await collection.findOne({
_id: new ObjectId(String(id)),
license: this.normalizeId(this.licenseId),
});
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
if (removed) await BaseModel.deletedDocumentBackup('modifier_groups', removed);
const r = await collection.deleteOne({
_id: this.normalizeId(id),
_id: new ObjectId(String(id)),
license: this.normalizeId(this.licenseId),
});
if (!r.deletedCount) return { status: false, data: null, message: 'No such modifier group' };
Expand Down Expand Up @@ -3794,8 +3799,13 @@ class SettingModel extends BaseModel {
try {
if (!id) return { status: false, data: null, message: 'List id required' };
const collection = await this.getCollection('price_lists');
const removed = await collection.findOne({
_id: new ObjectId(String(id)),
license: this.normalizeId(this.licenseId),
});
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
if (removed) await BaseModel.deletedDocumentBackup('price_lists', removed);
const r = await collection.deleteOne({
_id: this.normalizeId(id),
_id: new ObjectId(String(id)),
license: this.normalizeId(this.licenseId),
});
if (!r.deletedCount) return { status: false, data: null, message: 'No such price list' };
Expand Down
41 changes: 19 additions & 22 deletions api/src/repositories/item.repository.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const pricingAuthority = require('../services/pricing-authority');
const itemText = require('../utils/item-localization');
const { searchPattern } = require('../utils/safe-search');
const tradingDay = require('../utils/trading-day');
Expand Down Expand Up @@ -4322,6 +4323,10 @@ class ItemRepository extends BaseModel {
{ table: params.table, venue: params.venue, unit: params.unit },
await this.shopVenues()
);
if (params.venue && !servicePoint.venue)
throw new Error(
'Venue pricing is unavailable. Refresh the menu or contact the restaurant.'
);

/* What sells and what sells beside it, from the last month of this
branch's own sales. A new shop gets empty maps and simply shows no
Expand Down Expand Up @@ -4373,7 +4378,7 @@ class ItemRepository extends BaseModel {
* in a list being scanned.
*/
photos: onlineOrdering.photoList(row),
price: partnerVenues.priceFor(Number(row.selling_price) || 0, servicePoint.venue),
...pricingAuthority.menuQuote(row, branchDoc, servicePoint.venue),
diet: String(row.diet || ''),
/*
* A picture for a dish nobody photographed.
Expand Down Expand Up @@ -5222,28 +5227,20 @@ class ItemRepository extends BaseModel {
{ table: params.table, venue: params.venue, unit: params.unit },
await this.shopVenues()
);
if (params.venue && !servicePoint.venue)
throw new Error(
'Venue pricing is unavailable. Refresh the menu or contact the restaurant.'
);

if (servicePoint.venue) {
const money = (n) => Math.round((Number(n) || 0) * 100) / 100;
for (const group of results) {
group.items = (group.items || []).map((item) => {
const price = partnerVenues.priceFor(item.price, servicePoint.venue);
const fixed = Number(item.discount_amount) || 0;
const discount = money(
fixed > 0 ? fixed : price * ((Number(item.discount_percentage) || 0) / 100)
);
const taxable = price - discount;
const rate = (Number(item.tax) || 0) / 100;
const taxPrice = item.tax_type === 'inclusive' ? 0 : money(taxable * rate);
return {
...item,
price,
discount_price: discount,
tax_price: taxPrice,
final_price: money(item.tax_type === 'exclusive' ? taxable + taxPrice : taxable),
};
});
}
for (const group of results) {
group.items = (group.items || []).map((item) => ({
...item,
...pricingAuthority.menuQuote(
{ ...item, _id: item.id, selling_price: item.price },
branchDoc,
servicePoint.venue
),
}));
}

/*
Expand Down
Loading
Loading