コード例 #1
0
 public static decimal CalculateOrderTotal(Ticket ticket, Order order)
 {
     var discount = ticket.GetPreTaxServicesTotal();
     if (discount != 0)
     {
         var tsum = ticket.GetPlainSum();
         var rate = tsum > 0 ? (discount * 100) / tsum : 100;
         var tiTotal = order.GetTotal();
         var itemDiscount = (tiTotal * rate) / 100;
         return tiTotal + itemDiscount;
     }
     return order.GetTotal();
 }
コード例 #2
0
ファイル: PrinterService.cs プロジェクト: neapolis/SambaPOS-3
 private IEnumerable<Order> GroupLinesByValue(Ticket ticket, Func<MenuItem, string> selector, string defaultValue, bool calcDiscounts = false)
 {
     var discounts = calcDiscounts ? ticket.GetPreTaxServicesTotal() : 0;
     var di = discounts > 0 ? discounts / ticket.GetPlainSum() : 0;
     var cache = new Dictionary<string, decimal>();
     foreach (var order in ticket.Orders.OrderBy(x => x.Id).ToList())
     {
         var item = order;
         var value = _cacheService.GetMenuItemData(item.MenuItemId, selector);
         if (string.IsNullOrEmpty(value)) value = defaultValue;
         if (!cache.ContainsKey(value))
             cache.Add(value, 0);
         var total = (item.GetTotal());
         cache[value] += Decimal.Round(total - (total * di), 2);
     }
     return cache.Select(x => new Order
     {
         MenuItemName = x.Key,
         Price = x.Value,
         Quantity = 1,
         PortionCount = 1
     });
 }
コード例 #3
0
        private static string ReplaceDocumentVars(string document, Ticket ticket, int orderNo, string userName)
        {
            string result = document;
            if (string.IsNullOrEmpty(document)) return "";

            result = FormatData(result, TagNames.TicketDate, () => ticket.Date.ToShortDateString());
            result = FormatData(result, TagNames.TicketTime, () => ticket.Date.ToShortTimeString());
            result = FormatData(result, TagNames.Date, () => DateTime.Now.ToShortDateString());
            result = FormatData(result, TagNames.Time, () => DateTime.Now.ToShortTimeString());
            result = FormatData(result, TagNames.TicketId, () => ticket.Id.ToString());
            result = FormatData(result, TagNames.TicketNo, () => ticket.TicketNumber);
            result = FormatData(result, TagNames.OrderNo, orderNo.ToString);
            result = FormatData(result, TagNames.TicketTag, ticket.GetTagData);
            result = FormatDataIf(true, result, TagNames.Department, () => GetDepartmentName(ticket.DepartmentId));

            const string ticketTagPattern = TagNames.TicketTag2 + "[^}]+}";

            while (Regex.IsMatch(result, ticketTagPattern))
            {
                var value = Regex.Match(result, ticketTagPattern).Groups[0].Value;
                var tags = "";
                try
                {
                    var tag = value.Trim('{', '}').Split(':')[1];
                    tags = tag.Split(',').Aggregate(tags, (current, t) => current +
                        (!string.IsNullOrEmpty(ticket.GetTagValue(t.Trim()))
                        ? (t + ": " + ticket.GetTagValue(t.Trim()) + "\r")
                        : ""));
                    result = FormatData(result.Trim('\r'), value, () => tags);
                }
                catch (Exception)
                {
                    result = FormatData(result, value, () => "");
                }
            }

            const string ticketTag2Pattern = TagNames.TicketTag3 + "[^}]+}";

            while (Regex.IsMatch(result, ticketTag2Pattern))
            {
                var value = Regex.Match(result, ticketTag2Pattern).Groups[0].Value;
                var tag = value.Trim('{', '}').Split(':')[1];
                var tagValue = ticket.GetTagValue(tag);
                try
                {
                    result = FormatData(result, value, () => tagValue);
                }
                catch (Exception)
                {
                    result = FormatData(result, value, () => "");
                }
            }

            var title = userName;

            result = FormatData(result, TagNames.LocationUser, () => title);
            result = FormatData(result, TagNames.UserName, () => userName);
            result = FormatData(result, TagNames.Note, () => ticket.Note);
            result = FormatData(result, TagNames.AccName, () => ticket.AccountName);

            if (ticket.AccountId > 0 && (result.Contains(TagNames.AccAddress) || result.Contains(TagNames.AccPhone)))
            {
                var account = Dao.SingleWithCache<Resource>(x => x.Id == ticket.AccountId);
                result = FormatData(result, TagNames.AccPhone, () => account.SearchString);
            }

            result = RemoveTag(result, TagNames.AccAddress);
            result = RemoveTag(result, TagNames.AccPhone);

            var payment = ticket.GetPaymentAmount();
            var remaining = ticket.GetRemainingAmount();
            var plainTotal = ticket.GetPlainSum();
            var preTaxServices = ticket.GetPreTaxServicesTotal();
            var taxAmount = ticket.CalculateTax(plainTotal, preTaxServices);  //GetTaxTotal(ticket.Orders, plainTotal, ticket.GetDiscountTotal());
            var servicesTotal = ticket.GetPostTaxServicesTotal();
            //ticket.CalculateTax(plainTotal, preTaxServices);

            result = FormatDataIf(taxAmount > 0 || preTaxServices > 0 || servicesTotal > 0, result, TagNames.PlainTotal, () => plainTotal.ToString("#,#0.00"));
            result = FormatDataIf(preTaxServices > 0, result, TagNames.DiscountTotal, () => preTaxServices.ToString("#,#0.00"));
            result = FormatDataIf(taxAmount > 0, result, TagNames.TaxTotal, () => taxAmount.ToString("#,#0.00"));
            result = FormatDataIf(taxAmount > 0, result, TagNames.TaxDetails, () => GetTaxDetails(ticket.Orders, plainTotal, preTaxServices));
            result = FormatDataIf(servicesTotal > 0, result, TagNames.CalculationDetails, () => GetServiceDetails(ticket));

            result = FormatDataIf(payment > 0, result, TagNames.IfPaid,
                () => string.Format(Resources.RemainingAmountIfPaidValue_f, payment.ToString("#,#0.00"), remaining.ToString("#,#0.00")));

            result = FormatDataIf(preTaxServices > 0, result, TagNames.IfDiscount,
                () => string.Format(Resources.DiscountTotalAndTicketTotalValue_f, (plainTotal).ToString("#,#0.00"), preTaxServices.ToString("#,#0.00")));

            result = FormatDataIf(preTaxServices < 0, result, TagNames.IfFlatten, () => string.Format(Resources.IfNegativeDiscountValue_f, preTaxServices.ToString("#,#0.00")));

            result = FormatData(result, TagNames.TicketTotal, () => ticket.GetSum().ToString("#,#0.00"));
            result = FormatData(result, TagNames.PaymentTotal, () => ticket.GetPaymentAmount().ToString("#,#0.00"));
            result = FormatData(result, TagNames.Balance, () => ticket.GetRemainingAmount().ToString("#,#0.00"));

            result = FormatData(result, TagNames.TotalText, () => HumanFriendlyInteger.CurrencyToWritten(ticket.GetSum()));
            result = FormatData(result, TagNames.Totaltext, () => HumanFriendlyInteger.CurrencyToWritten(ticket.GetSum(), true));

            result = _settingReplacer.ReplaceSettingValue("{SETTING:([^}]+)}", result);

            return result;
        }
コード例 #4
0
ファイル: TicketPrinter.cs プロジェクト: basio/veropos
 private static IEnumerable<TicketItem> GroupLinesByValue(Ticket ticket, Func<MenuItem, object> selector, string defaultValue, bool calcDiscounts = false)
 {
     var discounts = calcDiscounts ? ticket.GetDiscountAndRoundingTotal() : 0;
     var di = discounts > 0 ? discounts / ticket.GetPlainSum() : 0;
     var cache = new Dictionary<string, decimal>();
     foreach (var ticketItem in ticket.TicketItems.OrderBy(x => x.Id).ToList())
     {
         var item = ticketItem;
         var value = selector(AppServices.DataAccessService.GetMenuItem(item.MenuItemId)).ToString();
         if (string.IsNullOrEmpty(value)) value = defaultValue;
         if (!cache.ContainsKey(value))
             cache.Add(value, 0);
         var total = (item.GetTotal());
         cache[value] += Decimal.Round(total - (total * di), 2);
     }
     return cache.Select(x => new TicketItem
                                  {
                                      MenuItemName = x.Key,
                                      Price = x.Value,
                                      Quantity = 1,
                                      PortionCount = 1,
                                      CurrencyCode = LocalSettings.CurrencySymbol
                                  });
 }
コード例 #5
0
ファイル: TicketFormatter.cs プロジェクト: basio/veropos
        private static string ReplaceDocumentVars(string document, Ticket ticket, int orderNo, int userNo, int departmentNo)
        {
            string result = document;
            if (string.IsNullOrEmpty(document)) return "";

            result = FormatData(result, Resources.TF_TicketDate, () => ticket.Date.ToShortDateString());
            result = FormatData(result, Resources.TF_TicketTime, () => ticket.Date.ToShortTimeString());
            result = FormatData(result, Resources.TF_DayDate, () => DateTime.Now.ToShortDateString());
            result = FormatData(result, Resources.TF_DayTime, () => DateTime.Now.ToShortTimeString());
            result = FormatData(result, Resources.TF_UniqueTicketId, () => ticket.Id.ToString());
            result = FormatData(result, Resources.TF_TicketNumber, () => ticket.TicketNumber);
            result = FormatData(result, Resources.TF_LineOrderNumber, orderNo.ToString);
            result = FormatData(result, Resources.TF_TicketTag, ticket.GetTagData);
            result = FormatDataIf(true, result, "{DEPARTMENT}", () => GetDepartmentName(departmentNo));

            var ticketTagPattern = Resources.TF_OptionalTicketTag + "[^}]+}";

            while (Regex.IsMatch(result, ticketTagPattern))
            {
                var value = Regex.Match(result, ticketTagPattern).Groups[0].Value;
                var tags = "";
                try
                {
                    var tag = value.Trim('{', '}').Split(':')[1];
                    tags = tag.Split(',').Aggregate(tags, (current, t) => current +
                        (!string.IsNullOrEmpty(ticket.GetTagValue(t.Trim()))
                        ? (t + ": " + ticket.GetTagValue(t.Trim()) + "\r")
                        : ""));
                    result = FormatData(result.Trim('\r'), value, () => tags);
                }
                catch (Exception)
                {
                    result = FormatData(result, value, () => "");
                }
            }

            const string ticketTag2Pattern = "{TICKETTAG:[^}]+}";

            while (Regex.IsMatch(result, ticketTag2Pattern))
            {
                var value = Regex.Match(result, ticketTag2Pattern).Groups[0].Value;
                var tag = value.Trim('{', '}').Split(':')[1];
                var tagValue = ticket.GetTagValue(tag);
                try
                {
                    result = FormatData(result, value, () => tagValue);
                }
                catch (Exception)
                {
                    result = FormatData(result, value, () => "");
                }
            }

            var userName = AppServices.MainDataContext.GetUserName(userNo);

            var title = ticket.LocationName;
            if (string.IsNullOrEmpty(ticket.LocationName))
                title = userName;

            result = FormatData(result, Resources.TF_TableOrUserName, () => title);
            result = FormatData(result, Resources.TF_UserName, () => userName);
            result = FormatData(result, Resources.TF_TableName, () => ticket.LocationName);
            result = FormatData(result, Resources.TF_TicketNote, () => ticket.Note ?? "");
            result = FormatData(result, Resources.TF_AccountName, () => ticket.CustomerName);
            result = FormatData(result, "{ACC GROUPCODE}", () => ticket.CustomerGroupCode);

            if (ticket.CustomerId > 0 && (result.Contains(Resources.TF_AccountAddress) || result.Contains(Resources.TF_AccountPhone) || result.Contains("{ACC NOTE}")))
            {
                var customer = Dao.SingleWithCache<Customer>(x => x.Id == ticket.CustomerId);
                result = FormatData(result, Resources.TF_AccountAddress, () => customer.Address);
                result = FormatData(result, Resources.TF_AccountPhone, () => customer.PhoneNumber);
                result = FormatData(result, "{ACC NOTE}", () => customer.Note);
            }

            if (ticket.CustomerId > 0 && result.Contains("{ACC BALANCE}"))
            {
                var accBalance = CashService.GetAccountBalance(ticket.CustomerId);
                result = FormatDataIf(accBalance != 0, result, "{ACC BALANCE}", () => accBalance.ToString("#,#0.00"));
            }

            result = RemoveTag(result, Resources.TF_AccountAddress);
            result = RemoveTag(result, Resources.TF_AccountPhone);

            var payment = ticket.GetPaymentAmount();
            var remaining = ticket.GetRemainingAmount();
            var discount = ticket.GetDiscountAndRoundingTotal();
            var plainTotal = ticket.GetPlainSum();
            var giftAmount = ticket.GetTotalGiftAmount();
            var vatAmount = GetTaxTotal(ticket.TicketItems, plainTotal, ticket.GetDiscountTotal());
            var taxServicesTotal = ticket.GetTaxServicesTotal();
            var ticketPaymentAmount = ticket.GetPaymentAmount();

            result = FormatDataIf(vatAmount > 0 || discount > 0 || taxServicesTotal > 0, result, "{PLAIN TOTAL}", () => plainTotal.ToString("#,#0.00"));
            result = FormatDataIf(discount > 0, result, "{DISCOUNT TOTAL}", () => discount.ToString("#,#0.00"));
            result = FormatDataIf(vatAmount > 0, result, "{TAX TOTAL}", () => vatAmount.ToString("#,#0.00"));
            result = FormatDataIf(taxServicesTotal > 0, result, "{SERVICE TOTAL}", () => taxServicesTotal.ToString("#,#0.00"));
            result = FormatDataIf(vatAmount > 0, result, "{TAX DETAILS}", () => GetTaxDetails(ticket.TicketItems, plainTotal, discount));
            result = FormatDataIf(taxServicesTotal > 0, result, "{SERVICE DETAILS}", () => GetServiceDetails(ticket));

            result = FormatDataIf(payment > 0, result, Resources.TF_RemainingAmountIfPaid,
                () => string.Format(Resources.RemainingAmountIfPaidValue_f, payment.ToString("#,#0.00"), remaining.ToString("#,#0.00")));

            result = FormatDataIf(discount > 0, result, Resources.TF_DiscountTotalAndTicketTotal,
                () => string.Format(Resources.DiscountTotalAndTicketTotalValue_f, (plainTotal).ToString("#,#0.00"), discount.ToString("#,#0.00")));

            result = FormatDataIf(giftAmount > 0, result, Resources.TF_GiftTotal, () => giftAmount.ToString("#,#0.00"));
            result = FormatDataIf(discount < 0, result, Resources.TF_IfFlatten, () => string.Format(Resources.IfNegativeDiscountValue_f, discount.ToString("#,#0.00")));

            result = FormatData(result, Resources.TF_TicketTotal, () => ticket.GetSum().ToString("#,#0.00"));

            result = FormatDataIf(ticketPaymentAmount > 0, result, Resources.TF_TicketPaidTotal, () => ticketPaymentAmount.ToString("#,#0.00"));
            result = FormatData(result, Resources.TF_TicketRemainingAmount, () => ticket.GetRemainingAmount().ToString("#,#0.00"));

            result = FormatData(result, "{TOTAL TEXT}", () => HumanFriendlyInteger.CurrencyToWritten(ticket.GetSum()));
            result = FormatData(result, "{TOTALTEXT}", () => HumanFriendlyInteger.CurrencyToWritten(ticket.GetSum(), true));

            result = UpdateGlobalValues(result);

            return result;
        }