2018-08-24 16:11:33 +05:30
|
|
|
|
using RestSharp;
|
|
|
|
|
using System;
|
2011-12-05 15:11:02 +05:30
|
|
|
|
using System.Collections.Generic;
|
2011-03-12 00:19:48 +05:30
|
|
|
|
using System.Linq;
|
2018-08-24 16:11:33 +05:30
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-02-18 22:24:48 +05:30
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static class VoucherBI
|
2011-02-18 22:24:48 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Voucher Insert(Voucher voucher, bool updateTable)
|
2011-02-18 22:24:48 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.PUT);
|
|
|
|
|
request.Resource = "Voucher.json";
|
|
|
|
|
request.AddJsonBody(GetVoucherJson(voucher));
|
|
|
|
|
request.AddQueryParameter("u", true.ToString());
|
|
|
|
|
return JsonStore.Execute<Voucher>(request);
|
2014-10-12 15:11:45 +05:30
|
|
|
|
}
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Guid? Update(Voucher voucher, bool updateTable)
|
2011-02-18 22:24:48 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "Voucher/{id}.json";
|
|
|
|
|
request.AddParameter("id", voucher.VoucherID, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(GetVoucherJson(voucher));
|
|
|
|
|
request.AddQueryParameter("u", true.ToString());
|
|
|
|
|
voucher = JsonStore.Execute<Voucher>(request);
|
|
|
|
|
return voucher.Kots.Last().KotID;
|
2011-02-18 22:24:48 +05:30
|
|
|
|
}
|
2018-08-24 16:11:33 +05:30
|
|
|
|
|
|
|
|
|
public static Voucher Get(Guid id)
|
2014-10-12 15:11:45 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest();
|
|
|
|
|
request.Resource = "Voucher/{id}.json";
|
|
|
|
|
request.AddParameter("id", id, ParameterType.UrlSegment);
|
|
|
|
|
return JsonStore.Execute<Voucher>(request);
|
2011-02-18 22:24:48 +05:30
|
|
|
|
}
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Voucher Get(string billID)
|
2011-12-05 15:11:02 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest();
|
|
|
|
|
request.Resource = "Voucher.json";
|
|
|
|
|
request.AddQueryParameter("b", billID);
|
|
|
|
|
return JsonStore.Execute<Voucher>(request);
|
2014-11-20 13:42:20 +05:30
|
|
|
|
}
|
2011-02-18 22:24:48 +05:30
|
|
|
|
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static void VoidBill(Guid voucherID, string reason, bool updateTable)
|
2014-11-20 13:42:20 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "Void/{id}.json";
|
|
|
|
|
request.AddParameter("id", voucherID, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(new { Reason = reason });
|
|
|
|
|
request.AddQueryParameter("u", true.ToString());
|
|
|
|
|
JsonStore.Execute<Voucher>(request);
|
2011-02-18 22:24:48 +05:30
|
|
|
|
}
|
2014-10-12 15:11:45 +05:30
|
|
|
|
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Guid MergeKot(Guid kotID, Guid newVoucherID)
|
2011-12-05 15:11:02 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "MergeKot.json";
|
|
|
|
|
request.AddJsonBody(new { KotID = kotID, NewVoucherID = newVoucherID });
|
|
|
|
|
return JsonStore.Execute<Guid>(request);
|
2011-12-05 15:11:02 +05:30
|
|
|
|
}
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Guid MergeTables(Guid voucherID, Guid newVoucherID)
|
2011-06-23 18:17:48 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "MergeTable.json";
|
|
|
|
|
request.AddJsonBody(new { VoucherID = voucherID, NewVoucherID = newVoucherID });
|
|
|
|
|
return JsonStore.Execute<Guid>(request);
|
2014-10-12 15:11:45 +05:30
|
|
|
|
}
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Guid MoveKot(Guid kotID, Guid tableID)
|
2011-12-05 15:11:02 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "MoveKot.json";
|
|
|
|
|
request.AddJsonBody(new { KotID = kotID, FoodTableID = tableID });
|
|
|
|
|
return JsonStore.Execute<Guid>(request);
|
2011-12-05 15:11:02 +05:30
|
|
|
|
}
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Guid MoveTable(Guid voucherID, Guid tableID)
|
2014-10-12 15:11:45 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "MoveTable.json";
|
|
|
|
|
request.AddJsonBody(new { VoucherID = voucherID, FoodTableID = tableID });
|
|
|
|
|
JsonStore.Execute(request);
|
|
|
|
|
return voucherID;
|
2014-10-12 15:11:45 +05:30
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static void SplitBill(Guid oldVoucherID, Voucher first, Voucher second)
|
2014-10-12 15:11:45 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "Split/{id}.json";
|
|
|
|
|
request.AddParameter("id", oldVoucherID, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(new
|
|
|
|
|
{
|
|
|
|
|
One = GetVoucherJson(first),
|
|
|
|
|
Two = GetVoucherJson(second)
|
|
|
|
|
});
|
|
|
|
|
JsonStore.Execute(request);
|
2014-10-12 15:11:45 +05:30
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static Voucher DiscountPrintedBill(Guid oldVoucherID, Voucher newVoucher)
|
2014-10-12 15:11:45 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "ReprintVoucher/{id}.json";
|
|
|
|
|
request.AddParameter("id", oldVoucherID, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(GetVoucherJson(newVoucher));
|
|
|
|
|
return JsonStore.Execute<Voucher>(request);
|
|
|
|
|
}
|
2018-05-17 15:52:27 +05:30
|
|
|
|
|
2018-08-24 16:11:33 +05:30
|
|
|
|
public static void SettleVoucher(User user, Guid voucherID, IDictionary<SettleOption, decimal> values, bool updateTable)
|
|
|
|
|
{
|
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "Settle/{id}.json";
|
|
|
|
|
request.AddParameter("id", voucherID, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(values.Select(x => new { Settled = x.Key, Amount = x.Value }));
|
|
|
|
|
request.AddQueryParameter("u", true.ToString());
|
|
|
|
|
JsonStore.Execute<Voucher>(request);
|
2014-10-12 15:11:45 +05:30
|
|
|
|
}
|
2018-08-24 16:11:33 +05:30
|
|
|
|
|
|
|
|
|
private static dynamic GetVoucherJson(Voucher voucher)
|
2014-10-12 15:11:45 +05:30
|
|
|
|
{
|
2018-08-24 16:11:33 +05:30
|
|
|
|
return new
|
|
|
|
|
{
|
|
|
|
|
Pax = voucher.Pax,
|
|
|
|
|
Table = new { FoodTableID = voucher.Table.FoodTableID },
|
|
|
|
|
Customer = new { CustomerID = voucher.Customer.CustomerID },
|
|
|
|
|
Printed = voucher.Printed,
|
|
|
|
|
VoucherType = voucher.VoucherType,
|
|
|
|
|
User = new { UserID = voucher.User.UserID },
|
|
|
|
|
Kots = voucher.Kots.Select(k => new
|
|
|
|
|
{
|
|
|
|
|
KotID = k.KotID,
|
|
|
|
|
Inventories = k.Inventories.Select(i => new
|
|
|
|
|
{
|
|
|
|
|
InventoryID = i.InventoryID,
|
|
|
|
|
ProductID = i.Product.ProductID,
|
|
|
|
|
Quantity = i.Quantity,
|
|
|
|
|
Price = i.Price,
|
|
|
|
|
Discount = i.Discount,
|
|
|
|
|
IsHappyHour = i.IsHappyHour,
|
|
|
|
|
ServiceCharge = i.ServiceCharge,
|
|
|
|
|
IsScTaxable = i.IsScTaxable,
|
|
|
|
|
ServiceTaxID = i.ServiceTax.TaxID,
|
|
|
|
|
ServiceTaxRate = i.ServiceTaxRate,
|
|
|
|
|
VatID = i.Vat.TaxID,
|
|
|
|
|
VatRate = i.VatRate,
|
|
|
|
|
Modifiers = i.InventoryModifier.Select(m => new
|
|
|
|
|
{
|
|
|
|
|
ModifierID = m.Modifier.ModifierID,
|
|
|
|
|
Price = m.Price
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}),
|
|
|
|
|
Settlements = voucher.Settlements.Select(s => new { Settled = s.Settled, Amount = s.Amount })
|
|
|
|
|
};
|
2014-10-12 15:11:45 +05:30
|
|
|
|
}
|
2011-02-18 22:24:48 +05:30
|
|
|
|
}
|
|
|
|
|
}
|