Ejemplo n.º 1
0
        public OperationDetails DeleteDiscount(long Id)
        {
            var discount = _uitOfWork.DiscountRepository.GetByID(Id);

            if (discount == null)
            {
                return(new OperationDetails(false, "حدث خطأ بعملية الحذف", ""));
            }

            var discountSkus = discount.DiscountProducts.ToList();

            if (discountSkus.Count > 0)
            {
                return(new OperationDetails(false, "يرجى إلغاء التخفيض عن جميع المنتجات المرتبطة قبل القيام بحذف التخفيض", ""));
            }

            DiscountDescription arabicDesc  = discount.Descriptions.Where(c => c.LanguageId == (long)Langs.Arabic).FirstOrDefault();
            DiscountDescription englishDesc = discount.Descriptions.Where(c => c.LanguageId == (long)Langs.English).FirstOrDefault();

            _uitOfWork.DiscountDescriptionRepository.Delete(arabicDesc);
            _uitOfWork.DiscountDescriptionRepository.Delete(englishDesc);

            _uitOfWork.DiscountRepository.Delete(discount);
            _uitOfWork.Save();

            return(new OperationDetails(true, "تمت عملية الحذف بنجاح", ""));
        }
        private string GetDiscountDescription(DiscountDescription descriptionType)
        {
            switch (descriptionType)
            {
            case DiscountDescription.NONE:
                break;

            case DiscountDescription.SPECIAL:
                return("rabat spacjalny");

            case DiscountDescription.OCASIONAL:
                return("return okolicznościowy");

            case DiscountDescription.CHANCE:
                return("okazja");

            case DiscountDescription.CHRISTMAS:
                return("rabat świąteczny");

            case DiscountDescription.REGULAR_CUSTOMER:
                return("stały klient");

            case DiscountDescription.ANNIVERSARY:
                return("rabat jubileuszowy");

            case DiscountDescription.BIRTHDAY:
                return("rabat urodzinowy");

            case DiscountDescription.EMPLOYEE:
                return("rabat dla pracownika");

            case DiscountDescription.PROMOTION:
                return("promocja");

            case DiscountDescription.REWARD:
                return("nagroda");

            case DiscountDescription.SALE:
                return("wyprzedaż");

            case DiscountDescription.DISCOUNT:
                return("przecena");

            case DiscountDescription.SEASONAL:
                return("rabat sezonowy");

            case DiscountDescription.NIGHTLY:
                return("rabat nocny");

            case DiscountDescription.STAFF:
                return("obsługa");

            case DiscountDescription.CUSTOM:
                break;

            default:
                break;
            }
            return("rabat");
        }
Ejemplo n.º 3
0
        public OperationDetails EditDiscount(DiscountDTO dto)
        {
            Discount discount = _uitOfWork.DiscountRepository.GetByID(dto.Id);

            discount.DateModefied = DateTime.Now;

            if (!String.IsNullOrWhiteSpace(dto.StartDate))
            {
                discount.DateStart = DateTime.ParseExact(dto.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                discount.DateStart = DateTime.Now;
            }

            if (!String.IsNullOrWhiteSpace(dto.EndDate))
            {
                discount.DateEnd = DateTime.ParseExact(dto.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                discount.DateEnd = DateTime.Now;
            }

            discount.IsPercentage = dto.IsPercentage;
            discount.Value        = dto.Value;
            _uitOfWork.DiscountRepository.Update(discount);

            long arabicLang  = (long)Langs.Arabic;
            long englishLang = (long)Langs.English;

            DiscountDescription arabicDescreption  = discount.Descriptions.Where(c => c.LanguageId == arabicLang).FirstOrDefault();
            DiscountDescription englsihDescreption = discount.Descriptions.Where(c => c.LanguageId == englishLang).FirstOrDefault();


            arabicDescreption.DateModefied = DateTime.Now;
            arabicDescreption.Name         = dto.ArabicName;

            englsihDescreption.DateModefied = DateTime.Now;
            englsihDescreption.Name         = dto.EnglishName;
            _uitOfWork.DiscountDescriptionRepository.Update(arabicDescreption);
            _uitOfWork.DiscountDescriptionRepository.Update(englsihDescreption);

            _uitOfWork.Save();

            return(new OperationDetails(true, "تمت عملية التعديل بنجاح", discount.Id.ToString()));
        }
        public override CommandHandlerResponse Handle(IFiscalPrinterState fiscalPrinterState)
        {
            var state = fiscalPrinterState as FiscalPrinterState;

            if (state.TimeDiffrenceInMinutes == int.MinValue)
            {
                throw new FP_IllegalOperationException("RTC clock is not set up. Please do this before any actions.");
            }
            if (!state.IsInTransactionState)
            {
                throw new FP_IllegalOperationException("Fiscal Printer is not in transaction state.");
            }

            var slipLine = new SlipLine();


            DiscountType        discountType        = DiscountType.NO_DISCOUNT;
            DiscountDescription discountDescription = DiscountDescription.NONE;

            string discountDescriptionText = "";
            string productDescription      = "";
            double discountValueAmmount    = 0;



            if (!command.PnArguments.Any())
            {
                throw new FP_WrongNumberOfArgumentsException("This command required at least one argument");
            }

            if (command.PnArguments.Count() >= 1)
            {
                if (!int.TryParse(command.PnArguments.ElementAt(0), out int lineNumber))
                {
                    throw new FP_BadFormatOfArgumentException("first argument must be a number");
                }
            }
            if (command.PnArguments.Count() >= 2)
            {
                if (!Enum.TryParse <DiscountType>(command.PnArguments.ElementAt(1), out discountType))
                {
                    throw new FP_BadFormatOfArgumentException("Unknkown Pr command argument");
                }
            }

            if (command.PnArguments.Count() >= 3)
            {
                if (!Enum.TryParse <DiscountDescription>(command.PnArguments.ElementAt(2), out discountDescription))
                {
                    throw new FP_BadFormatOfArgumentException("Unknkown Po command argument");
                }
            }

            if (command.PnArguments.Count() == 4 && command.PnArguments.ElementAt(3) != "1")
            {
                throw new FP_BadFormatOfArgumentException("Bad command formatting. Check your arguments.");
            }
            if (command.PnArguments.Count() > 4)
            {
                throw new FP_BadFormatOfArgumentException("Bad number of arguments for this command.");
            }

            var commandParameters = command.Parameters.Split('/', (char)Constants.ASCICodeCR).Where(m => !string.IsNullOrEmpty(m)).ToArray();

            if (commandParameters.Length == 0)
            {
                throw new FP_WrongNumberOfArgumentsException("Cannot get any parameters from command.");
            }
            if (commandParameters.Length >= 1)
            {
                if (string.IsNullOrWhiteSpace(commandParameters[0]))
                {
                    throw new FP_BadFormatOfArgumentException("Product name cannot be null");
                }
                else if (commandParameters[0].Length > 40)
                {
                    throw new FP_BadFormatOfArgumentException("Product name cannot have more then 40 characters.");
                }
                else
                {
                    slipLine.ProductName = commandParameters[0];
                }
            }
            if (commandParameters.Length >= 2)
            {
                if (!double.TryParse(commandParameters[1], out double ammount))
                {
                    throw new FP_BadFormatOfArgumentException("Cannot parse ammount of product. Check formatting.");
                }
                else if (ammount == 0)
                {
                    throw new FP_BadFormatOfArgumentException("Ammoutn cannot be 0.");
                }
                else
                {
                    slipLine.Ammount = ammount;
                }
            }
            if (commandParameters.Length >= 3)
            {
                if (!Enum.TryParse <PTU>(commandParameters[2], out PTU ptu))
                {
                    throw new FP_BadFormatOfArgumentException("Cannot parse PTU type. Check if you pass right parameter.");
                }
                else
                {
                    slipLine.PTU = ptu;
                }
            }
            if (commandParameters.Length >= 4)
            {
                if (!double.TryParse(commandParameters[3], out double price))
                {
                    throw new FP_BadFormatOfArgumentException("Cannot parse product price. Check if you pass right parameter.");
                }
                else
                {
                    slipLine.ProductPrice = price;
                }
            }

            if (commandParameters.Length >= 5)
            {
                if (!double.TryParse(commandParameters[4], out double brutto))
                {
                    throw new FP_BadFormatOfArgumentException("Cannot parse product brutto price. Check if you pass right parameter.");
                }
                else
                {
                    slipLine.TotalPrice = brutto;
                }
            }

            if (commandParameters.Length >= 6)
            {
                if (!double.TryParse(commandParameters[5], out double discountAmmount))
                {
                    throw new FP_BadFormatOfArgumentException("Cannot parse product discount ammout. Check if you pass right parameter.");
                }
                else
                {
                    slipLine.DiscountValue = discountAmmount;
                }
            }

            if (commandParameters.Length >= 7)
            {
                if (discountDescription == DiscountDescription.CUSTOM && string.IsNullOrWhiteSpace(commandParameters[6]))
                {
                    throw new FP_BadFormatOfArgumentException("Description cannot be empty in custom type");
                }
                else if (discountDescription == DiscountDescription.CUSTOM && commandParameters[6].Length > 20)
                {
                    throw new FP_BadFormatOfArgumentException("Description cannot have more then 20 characters.");
                }
                else
                {
                    discountDescriptionText = commandParameters[6];
                }
            }

            if (commandParameters.Length == 8)
            {
                productDescription = commandParameters[7];
            }
            if (commandParameters.Length > 8)
            {
                throw new FP_WrongNumberOfArgumentsException("Too many parameters for this command.");
            }

            StringBuilder slipBuilder = new StringBuilder();


            if (!state.SlipLines.Any())
            {
                state.TransactionCounter += 1;

                var fiscalPrinterDate  = DateTime.Now.AddMinutes(state.TimeDiffrenceInMinutes).ToString("yyyy-MM-dd");
                var transactionCounter = state.TransactionCounter.ToString();

                slipBuilder.AppendLine(state.FiscalPrinterHeader);
                slipBuilder.AppendLine(fiscalPrinterDate.PadRight(Constants.ReciptWidth - transactionCounter.Length) + transactionCounter);
                slipBuilder.AppendLine("P A R A G O N  F I S K A L N Y".PadCenter(Constants.ReciptWidth));
                slipBuilder.AppendLine("".PadLeft(Constants.ReciptWidth, '-'));
            }


            if (slipLine.Ammount * slipLine.ProductPrice != slipLine.TotalPrice)
            {
                throw new FP_IllegalOperationException("Ammount x Price is not equal brutto value");
            }
            else
            {
                discountValueAmmount = slipLine.TotalPrice;
            }

            string financialSlipText = $"{slipLine.Ammount}x{slipLine.ProductPrice.ToString("0.00")}    {slipLine.TotalPrice.ToString("0.00")}{slipLine.PTU.ToString()}";

            if (Constants.ReciptWidth - financialSlipText.Length < slipLine.ProductName.Length)
            {
                slipBuilder.AppendLine(slipLine.ProductName.PadRight(Constants.ReciptWidth));
                slipBuilder.AppendLine(financialSlipText.PadLeft(Constants.ReciptWidth));
            }
            else
            {
                var paddingValue = Constants.ReciptWidth - financialSlipText.Length;
                slipBuilder.AppendLine(slipLine.ProductName.PadRight(paddingValue) + financialSlipText);
            }

            if (!string.IsNullOrWhiteSpace(productDescription))
            {
                slipBuilder.AppendLine("Opis: " + productDescription);
            }

            if (slipLine.DiscountValue != 0)
            {
                discountDescriptionText = discountDescription == DiscountDescription.CUSTOM
                                        ? discountDescriptionText
                                        : GetDiscountDescription(discountDescription);


                bool isPercentageDiscount = slipLine.DiscountValue < 1 && slipLine.DiscountValue > 0;


                var discountValueText = isPercentageDiscount
                                        ? (slipLine.DiscountValue * 100).ToString() + " %"
                                        : slipLine.DiscountValue.ToString("0.00");

                discountValueAmmount -= isPercentageDiscount ? slipLine.TotalPrice * slipLine.DiscountValue : slipLine.DiscountValue;


                var discountSlipLineLeftPart  = $"   {discountDescriptionText} {discountValueText} =";
                var discountSlipLineRightPart = $"-{(slipLine.TotalPrice - discountValueAmmount).ToString("0.00")} ";


                slipBuilder.AppendLine(discountSlipLineLeftPart.PadRight(
                                           Constants.ReciptWidth - discountSlipLineRightPart.Length)
                                       + discountSlipLineRightPart);

                slipBuilder.AppendLine($"{discountValueAmmount.ToString("0.00")}{slipLine.PTU.ToString()}".PadLeft(Constants.ReciptWidth));
            }

            state.SlipLines.Add(slipLine);
            return(new CommandHandlerResponse(slipBuilder.ToString()));
        }
Ejemplo n.º 5
0
        public ActionResult Create(Discount model, string DiscountNumber, string CouponCode, DiscountDescription discount)
        {
            if (ModelState.IsValid)
            {
                if (DiscountNumber != null && DiscountNumber != "")
                {
                    decimal numDiscount;
                    try
                    {
                        numDiscount = Convert.ToDecimal(DiscountNumber);
                    }
                    catch
                    {
                        ViewBag.Message = DiscountNumber + "is not a valid number. Please Try Again";
                        return(View("Create"));
                    }
                    switch (discount)
                    {
                    case DiscountDescription.Sh:
                        model.DiscountNum = numDiscount;
                        //discount = DiscountDescription.Sh;
                        model.DiscountType = DiscountDescription.Sh;
                        break;

                    case DiscountDescription.C:
                        model.DiscountNum = numDiscount;
                        //discount = DiscountDescription.C;
                        model.DiscountType = DiscountDescription.C;
                        break;
                    }
                }
                _context.Discounts.Add(model);
                _context.SaveChanges();
            }
            return(View("Index"));
        }