public void BuildAndRegisterReduction(IReduction reduction)
 {
     if (reduction.Validate())
     {
         Reductions.Add(reduction);
     }
 }
Пример #2
0
        public Offer ApiToDomain(Api.Offer value)
        {
            if (value == null)
            {
                return(null);
            }

            IReduction reduction = null;

            if (!string.IsNullOrEmpty(value.Reduction))
            {
                if (value.Reduction.EndsWith("%"))
                {
                    reduction = new PercentReduction
                    {
                        Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture)
                    };
                }
                else
                {
                    reduction = new AbsoluteReduction
                    {
                        Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture)
                    };
                }
            }

            return(new Offer
            {
                Id = int.Parse(value.Id, CultureInfo.InvariantCulture),
                TemplateId = value.TemplateId.ToOptionalInt(),
                CustomerPortalUrl = value.CustomerPortalUrl,
                ClientId = int.Parse(value.ClientId, CultureInfo.InvariantCulture),
                ContactId = value.ContactId.ToOptionalInt(),
                OfferNumber = value.OfferNumber,
                Number = value.Number.ToOptionalInt(),
                NumberPre = value.NumberPre,
                NumberLength = int.Parse(value.NumberLength, CultureInfo.InvariantCulture),
                Title = value.Title,
                Date = DateTime.Parse(value.Date, CultureInfo.InvariantCulture),
                Address = value.Address,
                Label = value.Label,
                Intro = value.Intro,
                Note = value.Note,
                TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture),
                TotalNet = float.Parse(value.TotalNet, CultureInfo.InvariantCulture),
                CurrencyCode = value.CurrencyCode,
                TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture),
                TotalNetUnreduced = float.Parse(value.TotalNetUnreduced, CultureInfo.InvariantCulture),
                Created = DateTime.Parse(value.Created, CultureInfo.InvariantCulture),
                Updated = DateTime.Parse(value.Updated, CultureInfo.InvariantCulture),
                NetGross = value.NetGross.ToNetGrossType(),
                Status = value.Status.ToOfferStatus(),
                //Taxes = _taxMapper.ApiToDomain(value.Taxes),
                Quote = float.Parse(value.Quote, CultureInfo.InvariantCulture),
                Reduction = reduction,
            });
        }
Пример #3
0
 public Production(ParseTree.Identifier name,
                   int id,
                   int ruleId,
                   ITerminals right,
                   IReduction reduction)
 {
     this.name      = name;
     Id             = id;
     RuleId         = ruleId;
     Right          = right;
     this.reduction = reduction;
 }
Пример #4
0
        public override bool Parse(string source, out IReduction reduction)
        {
            NonterminalToken token = parser.Parse(source);

            if (token == null)
            {
                reduction = null;
                return(false);
            }
            else
            {
                reduction = new CalithaReduction(token);
                return(true);
            }
        }
        public OfferItem ApiToDomain(Api.OfferItem value)
        {
            if (value == null)
            {
                return(null);
            }

            IReduction reduction = null;

            if (!string.IsNullOrEmpty(value.Reduction) && value.Reduction != "null")
            {
                if (value.Reduction.EndsWith("%"))
                {
                    reduction = new PercentReduction
                    {
                        Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture)
                    };
                }
                else
                {
                    reduction = new AbsoluteReduction
                    {
                        Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture)
                    };
                }
            }

            return(new OfferItem
            {
                Id = int.Parse(value.Id, CultureInfo.InvariantCulture),
                Reduction = reduction,
                OfferId = int.Parse(value.OfferId, CultureInfo.InvariantCulture),
                ArticleId = value.ArticleId.ToOptionalInt(),
                Description = value.Description,
                Position = int.Parse(value.Position, CultureInfo.InvariantCulture),
                Title = value.Title,
                Unit = value.Unit,
                TaxName = value.TaxName,
                TotalNet = float.Parse(value.TotalNet, CultureInfo.InvariantCulture),
                Quantity = float.Parse(value.Quantity, CultureInfo.InvariantCulture),
                TotalNetUnreduced = float.Parse(value.TotalNetUnreduced, CultureInfo.InvariantCulture),
                TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture),
                TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture),
                UnitPrice = float.Parse(value.UnitPrice, CultureInfo.InvariantCulture),
                TaxRate = value.TaxRate.ToOptionalFloat()
            });
        }
Пример #6
0
        public Invoice ApiToDomain(Api.Invoice value)
        {
            if (value == null)
            {
                return(null);
            }

            SupplyDateType?supplyDateType;
            ISupplyDate    supplyDate;

            switch (value.SupplyDateType.ToLowerInvariant())
            {
            case "supply_date":
                supplyDateType = SupplyDateType.SupplyDate;
                supplyDate     = new DateSupplyDate
                {
                    Date = value.SupplyDate.ToOptionalDateTime()
                };
                break;

            case "delivery_date":
                supplyDateType = SupplyDateType.DeliveryDate;
                supplyDate     = new DateSupplyDate
                {
                    Date = value.SupplyDate.ToOptionalDateTime()
                };
                break;

            case "supply_text":
                supplyDateType = SupplyDateType.SupplyDate;
                supplyDate     = new FreeTextSupplyDate
                {
                    Text = value.SupplyDate
                };
                break;

            case "delivery_text":
                supplyDateType = SupplyDateType.DeliveryDate;
                supplyDate     = new FreeTextSupplyDate
                {
                    Text = value.SupplyDate
                };
                break;

            case "":
                supplyDateType = null;
                supplyDate     = null;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            IReduction reduction = null;

            if (!string.IsNullOrEmpty(value.Reduction))
            {
                if (value.Reduction.EndsWith("%"))
                {
                    reduction = new PercentReduction
                    {
                        Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture)
                    };
                }
                else
                {
                    reduction = new AbsoluteReduction
                    {
                        Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture)
                    };
                }
            }

            return(new Invoice
            {
                Id = value.Id.ToInt(),
                InvoiceId = value.InvoiceId.ToOptionalInt(),
                ConfirmationId = value.ConfirmationId.ToOptionalInt(),
                OfferId = value.OfferId.ToOptionalInt(),
                RecurringId = value.RecurringId.ToOptionalInt(),
                TemplateId = value.TemplateId.ToOptionalInt(),
                CustomerPortalUrl = value.CustomerPortalUrl.Sanitize(),
                ClientId = value.ClientId.ToInt(),
                ContactId = value.ContactId.ToOptionalInt(),
                InvoiceNumber = value.InvoiceNumber,
                Number = value.Number.ToOptionalInt(),
                NumberPre = value.NumberPre.Sanitize(),
                NumberLength = value.NumberLength.ToInt(),
                Title = value.Title.Sanitize(),
                Date = value.Date.ToOptionalDateTime(),
                Address = value.Address.Sanitize(),
                Label = value.Label.Sanitize(),
                Intro = value.Intro.Sanitize(),
                Note = value.Note.Sanitize(),
                TotalGross = value.TotalGross.ToFloat(),
                TotalNet = value.TotalNet.ToFloat(),
                CurrencyCode = value.CurrencyCode,
                TotalGrossUnreduced = value.TotalGrossUnreduced.ToFloat(),
                TotalNetUnreduced = value.TotalNetUnreduced.ToFloat(),
                Created = value.Created.ToDateTime(),
                DueDate = value.DueDate.ToOptionalDateTime(),
                DueDays = value.DueDays.ToOptionalInt(),
                NetGross = value.NetGross.ToNetGrossType(),
                SupplyDate = supplyDate,
                SupplyDateType = supplyDateType,
                Status = value.Status.ToInvoiceStatus(),
                PaymentTypes = value.PaymentTypes.ToStringList(),
                Taxes = _taxMapper.ApiToDomain(value.Taxes),
                Quote = value.Quote.ToFloat(),
                Reduction = reduction,
                DiscountRate = value.DiscountRate.ToOptionalFloat(),
                DiscountDate = value.DiscountDate.ToOptionalDateTime(),
                DiscountDays = value.DiscountDays.ToOptionalInt(),
                DiscountAmount = value.DiscountAmount.ToOptionalFloat(),
                PaidAmount = value.PaidAmount.ToFloat(),
                OpenAmount = value.OpenAmount.ToFloat()
            });
        }
Пример #7
0
        public override bool Parse(string source, out IReduction root)
        {
            //This procedure starts the GOLD Parser Engine and handles each of the
            //messages it returns. Each time a reduction is made, you can create new
            //custom object and reassign the .CurrentReduction property. Otherwise,
            //the system will use the Reduction object that was returned.
            //
            //The resulting tree will be a pure representation of the language
            //and will be ready to implement.

            GOLD.ParseMessage response;
            bool done;                      //Controls when we leave the loop
            bool accepted = false;          //Was the parse successful?

            root = null;

            StringReader reader = new StringReader(source);

            parser.Open(reader);
            parser.TrimReductions = false;  //Please read about this feature before enabling

            done = false;
            while (!done)
            {
                response = parser.Parse();

                switch (response)
                {
                case GOLD.ParseMessage.LexicalError:
                    //Cannot recognize token
                    failLineNumber   = parser.CurrentPosition().Line;
                    failColumnNumber = parser.CurrentPosition().Column;
                    failLength       = parser.CurrentToken().Data.ToString().Length;
                    failMessage      = "Lexical Error:" + Environment.NewLine +
                                       "Line " + (failLineNumber + 1) + ", Column " + (failColumnNumber + 1) + Environment.NewLine +
                                       "Read: " + parser.CurrentToken().Data;
                    done = true;
                    break;

                case GOLD.ParseMessage.SyntaxError:
                    //Expecting a different token
                    failLineNumber   = parser.CurrentPosition().Line;
                    failColumnNumber = parser.CurrentPosition().Column;
                    failLength       = parser.CurrentToken().Data.ToString().Length;
                    failMessage      = "Syntax Error:" + Environment.NewLine +
                                       "Line " + (failLineNumber + 1) + ", Column " + (failColumnNumber + 1) + Environment.NewLine +
                                       "Read: " + parser.CurrentToken().Data + Environment.NewLine +
                                       "Expecting one of: " + parser.ExpectedSymbols().Text();
                    done = true;
                    break;

                case GOLD.ParseMessage.Reduction:
                    //For this project, we will let the parser build a tree of Reduction objects
                    // parser.CurrentReduction = CreateNewObject(parser.CurrentReduction);
                    break;

                case GOLD.ParseMessage.Accept:
                    //Accepted!
                    root     = new CookV5Reduction((GOLD.Reduction)parser.CurrentReduction);    //The root node!
                    done     = true;
                    accepted = true;
                    break;

                case GOLD.ParseMessage.TokenRead:
                    //You don't have to do anything here.
                    break;

                case GOLD.ParseMessage.InternalError:
                    //INTERNAL ERROR! Something is horribly wrong.
                    done = true;
                    break;

                case GOLD.ParseMessage.NotLoadedError:
                    //This error occurs if the CGT was not loaded.
                    failLineNumber   = 0;
                    failColumnNumber = 0;
                    failLength       = 0;
                    failMessage      = "Tables not loaded";
                    done             = true;
                    break;

                case GOLD.ParseMessage.GroupError:
                    //GROUP ERROR! Unexpected end of file
                    failLineNumber   = 0;
                    failColumnNumber = 0;
                    failLength       = 0;
                    failMessage      = "COMMENT ERROR! Unexpected end of file";
                    done             = true;
                    break;
                }
            } //while

            return(accepted);
        }
        private static Invoice ToDomain(this Api.Invoice value)
        {
            if (value == null)
            {
                return(null);
            }

            NetGrossType netGrossType;

            switch (value.NetGross.ToLowerInvariant())
            {
            case "net":
                netGrossType = NetGrossType.Net;
                break;

            case "gross":
                netGrossType = NetGrossType.Gross;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SupplyDateType?supplyDateType;
            ISupplyDate    supplyDate;

            switch (value.SupplyDateType.ToLowerInvariant())
            {
            case "supply_date":
                supplyDateType = SupplyDateType.SupplyDate;
                supplyDate     = new DateSupplyDate
                {
                    Date = value.SupplyDate.ToOptionalDateTime()
                };
                break;

            case "delivery_date":
                supplyDateType = SupplyDateType.DeliveryDate;
                supplyDate     = new DateSupplyDate
                {
                    Date = value.SupplyDate.ToOptionalDateTime()
                };
                break;

            case "supply_text":
                supplyDateType = SupplyDateType.SupplyDate;
                supplyDate     = new FreeTextSupplyDate
                {
                    Text = value.SupplyDate
                };
                break;

            case "delivery_text":
                supplyDateType = SupplyDateType.DeliveryDate;
                supplyDate     = new FreeTextSupplyDate
                {
                    Text = value.SupplyDate
                };
                break;

            case "":
                supplyDateType = null;
                supplyDate     = null;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            InvoiceStatus status;

            switch (value.Status.ToLowerInvariant())
            {
            case "draft":
                status = InvoiceStatus.Draft;
                break;

            case "open":
                status = InvoiceStatus.Open;
                break;

            case "overdue":
                status = InvoiceStatus.Overdue;
                break;

            case "paid":
                status = InvoiceStatus.Paid;
                break;

            case "canceled":
                status = InvoiceStatus.Canceled;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            IReduction reduction = null;

            if (!string.IsNullOrEmpty(value.Reduction))
            {
                if (value.Reduction.EndsWith("%"))
                {
                    reduction = new PercentReduction
                    {
                        Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture)
                    };
                }
                else
                {
                    reduction = new AbsoluteReduction
                    {
                        Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture)
                    };
                }
            }

            return(new Invoice
            {
                Id = int.Parse(value.Id, CultureInfo.InvariantCulture),
                InvoiceId = value.InvoiceId.ToOptionalInt(),
                ConfirmationId = value.ConfirmationId.ToOptionalInt(),
                OfferId = value.OfferId.ToOptionalInt(),
                RecurringId = value.RecurringId.ToOptionalInt(),
                TemplateId = value.TemplateId.ToOptionalInt(),
                CustomerPortalUrl = value.CustomerPortalUrl,
                ClientId = int.Parse(value.ClientId, CultureInfo.InvariantCulture),
                ContactId = value.ContactId.ToOptionalInt(),
                InvoiceNumber = value.InvoiceNumber,
                Number = value.Number.ToOptionalInt(),
                NumberPre = value.NumberPre,
                NumberLength = int.Parse(value.NumberLength, CultureInfo.InvariantCulture),
                Title = value.Title,
                Date = DateTime.Parse(value.Date, CultureInfo.InvariantCulture),
                Address = value.Address,
                Label = value.Label,
                Intro = value.Intro,
                Note = value.Note,
                TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture),
                TotalNet = float.Parse(value.TotalNet, CultureInfo.InvariantCulture),
                CurrencyCode = value.CurrencyCode,
                TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture),
                TotalNetUnreduced = float.Parse(value.TotalNetUnreduced, CultureInfo.InvariantCulture),
                Created = DateTime.Parse(value.Created, CultureInfo.InvariantCulture),
                DueDate = DateTime.Parse(value.DueDate, CultureInfo.InvariantCulture),
                DueDays = int.Parse(value.DueDays, CultureInfo.InvariantCulture),
                NetGross = netGrossType,
                SupplyDate = supplyDate,
                SupplyDateType = supplyDateType,
                Status = status,
                PaymentTypes = value.PaymentTypes.ToStringList(),
                Taxes = value.Taxes.ToDomain(),
                Quote = float.Parse(value.Quote, CultureInfo.InvariantCulture),
                Reduction = reduction,
                DiscountRate = float.Parse(value.DiscountRate, CultureInfo.InvariantCulture),
                DiscountDate = value.DiscountDate.ToOptionalDateTime(),
                DiscountDays = value.DiscountDays.ToOptionalInt(),
                DiscountAmount = value.DiscountAmount.ToOptionalFloat(),
                PaidAmount = value.PaidAmount.ToOptionalFloat() ?? 0,
                OpenAmount = float.Parse(value.OpenAmount, CultureInfo.InvariantCulture)
            });
        }