コード例 #1
0
        private static OrderAdjustment Copy(OrderAdjustment adjustment, IAdjustmentPersister adjustmentPersister)
        {
            var newAdjustment = adjustmentPersister.CreateAdjustment(adjustmentPersister.GetAdjustmentType(adjustment));

            newAdjustment.Id            = adjustment.Id;
            newAdjustment.InitialPrice  = adjustment.InitialPrice;
            newAdjustment.AdjustedPrice = adjustment.AdjustedPrice;

            var amount = ((IPersistableAdjustment)adjustment).Amount;

            if (amount is PercentageAdjustmentAmount)
            {
                ((IPersistableAdjustment)newAdjustment).Amount = new PercentageAdjustmentAmount {
                    PercentageChange = ((PercentageAdjustmentAmount)amount).PercentageChange
                }
            }
            ;
            else
            {
                ((IPersistableAdjustment)newAdjustment).Amount = new FixedAdjustmentAmount {
                    FixedChange = ((FixedAdjustmentAmount)amount).FixedChange
                }
            };
            ((IPersistableAdjustment)newAdjustment).Code        = ((IPersistableAdjustment)adjustment).Code;
            ((IPersistableAdjustment)newAdjustment).ReferenceId = ((IPersistableAdjustment)adjustment).ReferenceId;
            return(newAdjustment);
        }
    }
コード例 #2
0
ファイル: OrdersRepository.cs プロジェクト: formist/LinkMe
 bool IOrdersRepository.DoesOrderAdjustmentExist(OrderAdjustment adjustment)
 {
     using (var dc = CreateContext().AsReadOnly())
     {
         return(DoesOrderAdjustmentExist(dc, _adjustmentPersister.GetAdjustmentType(adjustment), ((IPersistableAdjustment)adjustment).Code));
     }
 }
コード例 #3
0
        public static void BaseOnDerive(this OrderAdjustment @this, ObjectOnDerive method)
        {
            var derivation = method.Derivation;

            derivation.Validation.AssertAtLeastOne(@this, M.OrderAdjustment.Amount, M.ShippingAndHandlingCharge.Percentage);
            derivation.Validation.AssertExistsAtMostOne(@this, M.OrderAdjustment.Amount, M.ShippingAndHandlingCharge.Percentage);
        }
コード例 #4
0
        public void Should_be_able_to_add_an_adjustment_to_an_order()
        {
            var order = new Order();

            order.AddLine("widget 1", 1, new Money(12.34M), "abc", 102, "-");
            order.AddLine("gadget 1", 2, new Money(3.55M), "def", 101, "-");
            order.AddLine("gadget 1", 2, new Money(3.55M), "def", 101, "-");
            order.Postage = PostageResult.WithPrice(new Money(1.33M), "for London");

            var expectedAdjustedTotal = order.Total + new Money(-4.50M);

            var adjustment = new OrderAdjustment
            {
                Description = "4.50 off for slight scuffing",
                Amount      = new Money(-4.50M)
            };

            order.AddAdjustment(adjustment);

            order.Adjustments[0].ShouldBeTheSameAs(adjustment);
            adjustment.Order.ShouldBeTheSameAs(order);
            order.Adjustments[0].Description.ShouldEqual("4.50 off for slight scuffing");

            order.Total.ShouldEqual(expectedAdjustedTotal);
        }
コード例 #5
0
        public static string GetAdjustmentTypeString(this OrderAdjustment adjustment)
        {
            if (adjustment is TaxAdjustment)
            {
                return("tax");
            }
            var surchargeAdjustment = adjustment as SurchargeAdjustment;

            if (surchargeAdjustment != null)
            {
                if (surchargeAdjustment.CreditCardType == CreditCardType.Amex)
                {
                    return("surcharge");
                }
            }
            if (adjustment is DiscountAdjustment)
            {
                if (adjustment is VecciDiscountAdjustment)
                {
                    return("vecci-discount");
                }
                return("discount");
            }

            return(string.Empty);
        }
コード例 #6
0
ファイル: NewOrderTests.cs プロジェクト: formist/LinkMe
        private static string GetAdjustmentText(ICollection <Product> products, OrderAdjustment adjustment)
        {
            if (adjustment is TaxAdjustment)
            {
                return("Add GST");
            }
            if (adjustment is SurchargeAdjustment)
            {
                return("Add American Express surcharge (" + AmexSurcharge.ToString("P1") + ")");
            }
            if (adjustment is BundleAdjustment)
            {
                return("Less " + BundleDiscount.ToString("P0") + " bundle discount");
            }
            if (adjustment is VecciDiscountAdjustment)
            {
                return("Less VECCI Member discount (" + VecciDiscount.ToString("P0") + ")");
            }
            if (adjustment is CouponAdjustment)
            {
                var couponAdjustment = (CouponAdjustment)adjustment;
                var text             = couponAdjustment.Amount is PercentageAdjustmentAmount
                    ? "Less " + ((PercentageAdjustmentAmount)((CouponAdjustment)adjustment).Amount).PercentageChange.ToString("P0") + " coupon discount"
                    : "Less $" + ((FixedAdjustmentAmount)((CouponAdjustment)adjustment).Amount).FixedChange + " coupon discount";

                if (products.Count <= 1 || ((CouponAdjustment)adjustment).ProductId == null)
                {
                    return(text);
                }
                return(text + " (applied to " + (from p in products where p.Id == ((CouponAdjustment)adjustment).ProductId select p).Single().Description + " only)");
            }
            return(string.Empty);
        }
コード例 #7
0
ファイル: Mappings.cs プロジェクト: formist/LinkMe
        private static ProductOrderAdjustmentEntity Map(this OrderAdjustment adjustment, int rank, Guid orderId, IAdjustmentPersister adjustmentPersister)
        {
            var entity = new ProductOrderAdjustmentEntity
            {
                id            = adjustment.Id,
                rank          = rank,
                orderId       = orderId,
                type          = adjustmentPersister.GetAdjustmentType(adjustment),
                code          = ((IPersistableAdjustment)adjustment).Code,
                referenceId   = ((IPersistableAdjustment)adjustment).ReferenceId,
                initialPrice  = adjustment.InitialPrice,
                adjustedPrice = adjustment.AdjustedPrice,
            };

            var amount = ((IPersistableAdjustment)adjustment).Amount;

            if (amount is PercentageAdjustmentAmount)
            {
                entity.fixedAmount      = null;
                entity.percentageAmount = ((PercentageAdjustmentAmount)amount).PercentageChange;
            }
            else if (amount is FixedAdjustmentAmount)
            {
                entity.fixedAmount      = ((FixedAdjustmentAmount)amount).FixedChange;
                entity.percentageAmount = null;
            }

            return(entity);
        }
コード例 #8
0
        public OrderAdjustmentModel(OrderAdjustment orderAdjustment)
        {
            var invoice = orderAdjustment.InvoiceWhereOrderAdjustment;

            this.AdjustmentTypeName = orderAdjustment.GetType().Name;
            this.Description        = orderAdjustment.Description;

            if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
            {
                this.Amount = invoice.TotalDiscount.ToString("N2", new CultureInfo("nl-BE"));
            }

            if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
            {
                this.Amount = invoice.TotalSurcharge.ToString("N2", new CultureInfo("nl-BE"));
            }

            if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
            {
                this.Amount = invoice.TotalFee.ToString("N2", new CultureInfo("nl-BE"));
            }

            if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
            {
                this.Amount = invoice.TotalShippingAndHandling.ToString("N2", new CultureInfo("nl-BE"));
            }

            if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
            {
                var miscCharge = invoice.TotalExtraCharge - invoice.TotalFee - invoice.TotalShippingAndHandling;
                this.Amount = miscCharge.ToString("N2", new CultureInfo("nl-BE"));
            }
        }
コード例 #9
0
        public static void BaseOnPreDerive(this OrderAdjustment @this, ObjectOnPreDerive method)
        {
            var(iteration, changeSet, derivedObjects) = method;

            if (iteration.ChangeSet.Associations.Contains(@this.Id))
            {
                if (@this.ExistOrderWhereOrderAdjustment)
                {
                    var order = @this.OrderWhereOrderAdjustment;
                    iteration.AddDependency(@this, order);
                    iteration.Mark(order);
                }

                if (@this.ExistInvoiceWhereOrderAdjustment)
                {
                    var invoice = @this.InvoiceWhereOrderAdjustment;
                    iteration.AddDependency(@this, invoice);
                    iteration.Mark(invoice);
                }

                if (@this.ExistQuoteWhereOrderAdjustment)
                {
                    var quote = @this.QuoteWhereOrderAdjustment;
                    iteration.AddDependency(@this, quote);
                    iteration.Mark(quote);
                }
            }
        }
コード例 #10
0
        public static string GetAdjustmentLabelText(this Order order, OrderAdjustment adjustment, IEnumerable <Product> products)
        {
            if (adjustment is TaxAdjustment)
            {
                return("Add GST");
            }

            var surchargeAdjustment = adjustment as SurchargeAdjustment;

            if (surchargeAdjustment != null)
            {
                if (surchargeAdjustment.CreditCardType == CreditCardType.Amex)
                {
                    return("Add American Express surcharge (" + surchargeAdjustment.Surcharge.ToString("P1") + ")");
                }
            }

            var discountAdjustment = adjustment as DiscountAdjustment;

            if (discountAdjustment != null)
            {
                if (discountAdjustment is BundleAdjustment)
                {
                    return("Less " + discountAdjustment.Percentage.ToString("P0") + " bundle discount");
                }
                if (discountAdjustment is VecciDiscountAdjustment)
                {
                    return("Less VECCI Member discount (" + discountAdjustment.Percentage.ToString("P0") + ")");
                }
            }

            var couponAdjustment = adjustment as CouponAdjustment;

            if (couponAdjustment != null)
            {
                var text = couponAdjustment.Amount is PercentageAdjustmentAmount
                    ? "Less " + ((PercentageAdjustmentAmount)couponAdjustment.Amount).PercentageChange.ToString("P0") + " coupon discount"
                    : "Less " + ((FixedAdjustmentAmount)couponAdjustment.Amount).FixedChange.GetPriceDisplayText(order.Currency) + " coupon discount";

                // Add a distinguisher if the coupon was added to only part of the order.

                if (order.Items.Count > 1)
                {
                    var product = couponAdjustment.ProductId == null
                        ? null
                        : (from p in products where p.Id == couponAdjustment.ProductId.Value select p).SingleOrDefault();
                    if (product != null)
                    {
                        text += " (applied to " + product.Description + " only)";
                    }
                }

                return(text);
            }
            return(string.Empty);
        }
コード例 #11
0
        public ViewResult Add(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            var adjustment = new OrderAdjustment {Order = order};
            return View("Add", adjustment);
        }
コード例 #12
0
        public void Should_be_able_to_remove_adjustment()
        {
            var order      = new Order();
            var adjustment = new OrderAdjustment();

            order.AddAdjustment(adjustment);
            order.RemoveAdjustment(adjustment);

            adjustment.Order.ShouldBeNull();
            order.Adjustments.ShouldBeEmpty();
        }
コード例 #13
0
        public void Should_be_able_to_remove_adjustment()
        {
            var order = new Order();
            var adjustment = new OrderAdjustment();

            order.AddAdjustment(adjustment);
            order.RemoveAdjustment(adjustment);

            adjustment.Order.ShouldBeNull();
            order.Adjustments.ShouldBeEmpty();
        }
コード例 #14
0
        public ActionResult Delete(OrderAdjustment adjustment)
        {
            if (adjustment == null)
            {
                throw new ArgumentNullException("adjustment");
            }

            var order = adjustment.Order;
            order.RemoveAdjustment(adjustment);
            orderRepository.SaveOrUpdate(order);
            return RedirectToAction("Item", "Order", new { order.Id });
        }
コード例 #15
0
        public ActionResult Delete(OrderAdjustment adjustment)
        {
            if (adjustment == null)
            {
                throw new ArgumentNullException("adjustment");
            }

            var order = adjustment.Order;

            order.RemoveAdjustment(adjustment);
            orderRepository.SaveOrUpdate(order);
            return(RedirectToAction("Item", "Order", new { order.Id }));
        }
コード例 #16
0
        public ViewResult Add(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            var adjustment = new OrderAdjustment {
                Order = order
            };

            return(View("Add", adjustment));
        }
コード例 #17
0
        public void Delete_should_delete_adjustment()
        {
            var order = new Order { Id = 66 };
            var adjustment = new OrderAdjustment();
            order.AddAdjustment(adjustment);

            orderAdjustmentController.Delete(adjustment)
                .ReturnsRedirectToRouteResult()
                .ToAction("Item")
                .ToController("Order")
                .WithRouteValue("Id", "66");
            
            order.Adjustments.ShouldBeEmpty();
            orderRepository.AssertWasCalled(r => r.SaveOrUpdate(order));
        }
コード例 #18
0
 public ActionResult AddAdjustment(OrderAdjustment adjustment)
 {
     if (adjustment == null)
     {
         throw new ArgumentNullException("adjustment");
     }
     var order = adjustment.Order;
     if (ModelState.IsValid)
     {
         order.AddAdjustment(adjustment);
         orderRepository.SaveOrUpdate(order);
         Message = "Added Adjustment";
         return RedirectToAction("Item", "Order", new { order.Id });
     }
     Message = "Adjustment not created, No description or amount given";
     return RedirectToAction("Item", "Order", new {order.Id});
 }
コード例 #19
0
        public void AddAdjustment_POST_should_create_adjustment()
        {
            var order = new Order { Id = 66 };
            var adjustment = new OrderAdjustment
            {
                Order = order,
            };

            orderAdjustmentController.AddAdjustment(adjustment)
                .ReturnsRedirectToRouteResult()
                .ToAction("Item")
                .ToController("Order")
                .WithRouteValue("Id", "66");

            order.Adjustments[0].ShouldBeTheSameAs(adjustment);
            orderRepository.AssertWasCalled(r => r.SaveOrUpdate(order));
        }
コード例 #20
0
        public ActionResult AddAdjustment(OrderAdjustment adjustment)
        {
            if (adjustment == null)
            {
                throw new ArgumentNullException("adjustment");
            }
            var order = adjustment.Order;

            if (ModelState.IsValid)
            {
                order.AddAdjustment(adjustment);
                orderRepository.SaveOrUpdate(order);
                Message = "Added Adjustment";
                return(RedirectToAction("Item", "Order", new { order.Id }));
            }
            Message = "Adjustment not created, No description or amount given";
            return(RedirectToAction("Item", "Order", new { order.Id }));
        }
コード例 #21
0
        public void Delete_should_delete_adjustment()
        {
            var order = new Order {
                Id = 66
            };
            var adjustment = new OrderAdjustment();

            order.AddAdjustment(adjustment);

            orderAdjustmentController.Delete(adjustment)
            .ReturnsRedirectToRouteResult()
            .ToAction("Item")
            .ToController("Order")
            .WithRouteValue("Id", "66");

            order.Adjustments.ShouldBeEmpty();
            orderRepository.AssertWasCalled(r => r.SaveOrUpdate(order));
        }
コード例 #22
0
        public void AddAdjustment_POST_should_create_adjustment()
        {
            var order = new Order {
                Id = 66
            };
            var adjustment = new OrderAdjustment
            {
                Order = order,
            };

            orderAdjustmentController.AddAdjustment(adjustment)
            .ReturnsRedirectToRouteResult()
            .ToAction("Item")
            .ToController("Order")
            .WithRouteValue("Id", "66");

            order.Adjustments[0].ShouldBeTheSameAs(adjustment);
            orderRepository.AssertWasCalled(r => r.SaveOrUpdate(order));
        }
コード例 #23
0
        public void Should_be_able_to_add_an_adjustment_to_an_order()
        {
            var order = new Order();
            order.AddLine("widget 1", 1, new Money(12.34M), "abc", 102, "-");
            order.AddLine("gadget 1", 2, new Money(3.55M), "def", 101, "-");
            order.AddLine("gadget 1", 2, new Money(3.55M), "def", 101, "-");
            order.Postage = PostageResult.WithPrice(new Money(1.33M), "for London");

            var expectedAdjustedTotal = order.Total + new Money(-4.50M);

            var adjustment = new OrderAdjustment
            {
                Description = "4.50 off for slight scuffing",
                Amount = new Money(-4.50M)
            };

            order.AddAdjustment(adjustment);

            order.Adjustments[0].ShouldBeTheSameAs(adjustment);
            adjustment.Order.ShouldBeTheSameAs(order);
            order.Adjustments[0].Description.ShouldEqual("4.50 off for slight scuffing");

            order.Total.ShouldEqual(expectedAdjustedTotal);
        }
コード例 #24
0
 public static string AdjustmentLabelCssClass(this HtmlHelper htmlHelper, OrderAdjustment adjustment)
 {
     return(adjustment.GetAdjustmentTypeString() + "_order-adjustment order-adjustment");
 }
コード例 #25
0
ファイル: PurchaseOrder.cs プロジェクト: Allors/allors2
        public void BaseInvoice(PurchaseOrderInvoice method)
        {
            if (this.CanInvoice)
            {
                var purchaseInvoice = new PurchaseInvoiceBuilder(this.Strategy.Session)
                                      .WithBilledFrom(this.TakenViaSupplier)
                                      .WithAssignedBilledFromContactMechanism(this.DerivedTakenViaContactMechanism)
                                      .WithBilledFromContactPerson(this.TakenViaContactPerson)
                                      .WithBilledTo(this.OrderedBy)
                                      .WithBilledToContactPerson(this.BillToContactPerson)
                                      .WithDescription(this.Description)
                                      .WithInvoiceDate(this.Session().Now())
                                      .WithAssignedVatRegime(this.DerivedVatRegime)
                                      .WithAssignedIrpfRegime(this.DerivedIrpfRegime)
                                      .WithCustomerReference(this.CustomerReference)
                                      .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session()).PurchaseInvoice)
                                      .Build();

                foreach (OrderAdjustment orderAdjustment in this.OrderAdjustments)
                {
                    OrderAdjustment newAdjustment = null;
                    if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
                    {
                        newAdjustment = new DiscountAdjustmentBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
                    {
                        newAdjustment = new SurchargeAdjustmentBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
                    {
                        newAdjustment = new FeeBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
                    {
                        newAdjustment = new ShippingAndHandlingChargeBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
                    {
                        newAdjustment = new MiscellaneousChargeBuilder(this.Session()).Build();
                    }

                    newAdjustment.Amount ??= orderAdjustment.Amount;
                    newAdjustment.Percentage ??= orderAdjustment.Percentage;
                    purchaseInvoice.AddOrderAdjustment(newAdjustment);
                }

                foreach (PurchaseOrderItem orderItem in this.ValidOrderItems)
                {
                    if (orderItem.CanInvoice)
                    {
                        var invoiceItem = new PurchaseInvoiceItemBuilder(this.Strategy.Session)
                                          .WithAssignedUnitPrice(orderItem.UnitPrice)
                                          .WithInvoiceItemType(orderItem.InvoiceItemType)
                                          .WithPart(orderItem.Part)
                                          .WithQuantity(orderItem.QuantityOrdered)
                                          .WithAssignedVatRegime(orderItem.AssignedVatRegime)
                                          .WithAssignedIrpfRegime(orderItem.AssignedIrpfRegime)
                                          .WithDescription(orderItem.Description)
                                          .WithInternalComment(orderItem.InternalComment)
                                          .WithMessage(orderItem.Message)
                                          .Build();

                        purchaseInvoice.AddPurchaseInvoiceItem(invoiceItem);

                        new OrderItemBillingBuilder(this.Strategy.Session)
                        .WithQuantity(orderItem.QuantityOrdered)
                        .WithAmount(orderItem.TotalBasePrice)
                        .WithOrderItem(orderItem)
                        .WithInvoiceItem(invoiceItem)
                        .Build();
                    }
                }
            }
        }
コード例 #26
0
 string IAdjustmentPersister.GetAdjustmentType(OrderAdjustment adjustment)
 {
     return(adjustment.GetType().Name);
 }
コード例 #27
0
        public void BaseInvoice(CustomerShipmentInvoice method)
        {
            if (this.ShipmentState.Equals(new ShipmentStates(this.Strategy.Session).Shipped) &&
                Equals(this.Store.BillingProcess, new BillingProcesses(this.Strategy.Session).BillingForShipmentItems))
            {
                var invoiceByOrder = new Dictionary <SalesOrder, SalesInvoice>();
                var costsInvoiced  = false;

                foreach (ShipmentItem shipmentItem in this.ShipmentItems)
                {
                    foreach (OrderShipment orderShipment in shipmentItem.OrderShipmentsWhereShipmentItem)
                    {
                        var salesOrder = orderShipment.OrderItem.OrderWhereValidOrderItem as SalesOrder;

                        if (!invoiceByOrder.TryGetValue(salesOrder, out var salesInvoice))
                        {
                            salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                                           .WithStore(salesOrder.Store)
                                           .WithBilledFrom(salesOrder.TakenBy)
                                           .WithAssignedBilledFromContactMechanism(salesOrder.DerivedTakenByContactMechanism)
                                           .WithBilledFromContactPerson(salesOrder.TakenByContactPerson)
                                           .WithBillToCustomer(salesOrder.BillToCustomer)
                                           .WithAssignedBillToContactMechanism(salesOrder.DerivedBillToContactMechanism)
                                           .WithBillToContactPerson(salesOrder.BillToContactPerson)
                                           .WithBillToEndCustomer(salesOrder.BillToEndCustomer)
                                           .WithAssignedBillToEndCustomerContactMechanism(salesOrder.DerivedBillToEndCustomerContactMechanism)
                                           .WithBillToEndCustomerContactPerson(salesOrder.BillToEndCustomerContactPerson)
                                           .WithShipToCustomer(salesOrder.ShipToCustomer)
                                           .WithAssignedShipToAddress(salesOrder.DerivedShipToAddress)
                                           .WithShipToContactPerson(salesOrder.ShipToContactPerson)
                                           .WithShipToEndCustomer(salesOrder.ShipToEndCustomer)
                                           .WithAssignedShipToEndCustomerAddress(salesOrder.DerivedShipToEndCustomerAddress)
                                           .WithShipToEndCustomerContactPerson(salesOrder.ShipToEndCustomerContactPerson)
                                           .WithInvoiceDate(this.Session().Now())
                                           .WithSalesChannel(salesOrder.SalesChannel)
                                           .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                                           .WithAssignedVatRegime(salesOrder.DerivedVatRegime)
                                           .WithAssignedIrpfRegime(salesOrder.DerivedIrpfRegime)
                                           .WithCustomerReference(salesOrder.CustomerReference)
                                           .WithAssignedPaymentMethod(this.PaymentMethod)
                                           .Build();

                            invoiceByOrder.Add(salesOrder, salesInvoice);

                            foreach (OrderAdjustment orderAdjustment in salesOrder.OrderAdjustments)
                            {
                                OrderAdjustment newAdjustment = null;
                                if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
                                {
                                    newAdjustment = new DiscountAdjustmentBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
                                {
                                    newAdjustment = new SurchargeAdjustmentBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
                                {
                                    newAdjustment = new FeeBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
                                {
                                    newAdjustment = new ShippingAndHandlingChargeBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
                                {
                                    newAdjustment = new MiscellaneousChargeBuilder(this.Session()).Build();
                                }

                                newAdjustment.Amount ??= orderAdjustment.Amount;
                                newAdjustment.Percentage ??= orderAdjustment.Percentage;
                                salesInvoice.AddOrderAdjustment(newAdjustment);
                            }

                            if (!costsInvoiced)
                            {
                                var costs = this.BaseOnDeriveShippingAndHandlingCharges();
                                if (costs > 0)
                                {
                                    salesInvoice.AddOrderAdjustment(new ShippingAndHandlingChargeBuilder(this.Strategy.Session).WithAmount(costs).Build());
                                    costsInvoiced = true;
                                }
                            }

                            foreach (SalesTerm salesTerm in salesOrder.SalesTerms)
                            {
                                if (salesTerm.GetType().Name == typeof(IncoTerm).Name)
                                {
                                    salesInvoice.AddSalesTerm(new IncoTermBuilder(this.Strategy.Session)
                                                              .WithTermType(salesTerm.TermType)
                                                              .WithTermValue(salesTerm.TermValue)
                                                              .WithDescription(salesTerm.Description)
                                                              .Build());
                                }

                                if (salesTerm.GetType().Name == typeof(InvoiceTerm).Name)
                                {
                                    salesInvoice.AddSalesTerm(new InvoiceTermBuilder(this.Strategy.Session)
                                                              .WithTermType(salesTerm.TermType)
                                                              .WithTermValue(salesTerm.TermValue)
                                                              .WithDescription(salesTerm.Description)
                                                              .Build());
                                }

                                if (salesTerm.GetType().Name == typeof(OrderTerm).Name)
                                {
                                    salesInvoice.AddSalesTerm(new OrderTermBuilder(this.Strategy.Session)
                                                              .WithTermType(salesTerm.TermType)
                                                              .WithTermValue(salesTerm.TermValue)
                                                              .WithDescription(salesTerm.Description)
                                                              .Build());
                                }
                            }
                        }

                        var amountAlreadyInvoiced = shipmentItem.ShipmentItemBillingsWhereShipmentItem.Sum(v => v.Amount);
                        var leftToInvoice         = (orderShipment.OrderItem.QuantityOrdered * orderShipment.OrderItem.AssignedUnitPrice) - amountAlreadyInvoiced;

                        if (leftToInvoice > 0)
                        {
                            if (orderShipment.OrderItem is SalesOrderItem salesOrderItem)
                            {
                                var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                                  .WithInvoiceItemType(new InvoiceItemTypes(this.Strategy.Session).ProductItem)
                                                  .WithProduct(salesOrderItem.Product)
                                                  .WithQuantity(orderShipment.Quantity)
                                                  .WithAssignedUnitPrice(salesOrderItem.UnitPrice)
                                                  .WithAssignedVatRegime(salesOrderItem.AssignedVatRegime)
                                                  .WithDescription(salesOrderItem.Description)
                                                  .WithInternalComment(salesOrderItem.InternalComment)
                                                  .WithMessage(salesOrderItem.Message)
                                                  .Build();

                                salesInvoice.AddSalesInvoiceItem(invoiceItem);

                                new ShipmentItemBillingBuilder(this.Strategy.Session)
                                .WithQuantity(shipmentItem.Quantity)
                                .WithAmount(leftToInvoice)
                                .WithShipmentItem(shipmentItem)
                                .WithInvoiceItem(invoiceItem)
                                .Build();
                            }
                        }
                    }
                }
            }
        }
コード例 #28
0
        public static void DoOrderAdjustments(OrderAdjustment orderAdj, Basket basket)
        {
            TraceContext trace    = WebTrace.GetTraceContext();
            string       traceKey = "OrderAdjustmentHelper.DoOrderAdjustments";

            if (orderAdj == null)
            {
                throw new ArgumentNullException("orderAdj", "OrderAdjustment can't be null");
            }

            OrderAdjustmentMerchantcodes oamcs = orderAdj.merchantcodes;

            if (oamcs != null && oamcs.Items != null)
            {
                trace.Write(traceKey, "check merchant codes");
                Object[]                  merchantCodes = oamcs.Items;
                CouponAdjustment          coupAdj;
                GiftCertificateAdjustment giftCertAdj;

                //coupon and giftcertificate adjustment
                foreach (Object obj in merchantCodes)
                {
                    if (obj == null)
                    {
                        continue;
                    }
                    if (obj is CouponAdjustment)
                    {
                        coupAdj = (CouponAdjustment)obj;
                        trace.Write(traceKey, "Apply coupon: " + coupAdj.code + ", " + coupAdj.appliedamount);
                        OrderAdjustmentHelper.AdjustCoupon(basket, coupAdj);
                    }
                    else if (obj is GiftCertificateAdjustment)
                    {
                        giftCertAdj = (GiftCertificateAdjustment)obj;
                        trace.Write(traceKey, "Apply gift cert: " + giftCertAdj.code + " for " + giftCertAdj.appliedamount.Value);
                        OrderAdjustmentHelper.AdjustGiftCertificate(basket, giftCertAdj);
                    }
                }
            }

            OrderAdjustmentShipping oas = orderAdj.shipping;

            if (oas != null && oas.Item != null)
            {
                trace.Write(traceKey, "check shipping adjustments");
                Object shipAdj = oas.Item;
                if (shipAdj is MerchantCalculatedShippingAdjustment)
                {
                    MerchantCalculatedShippingAdjustment mcsa = (MerchantCalculatedShippingAdjustment)shipAdj;
                    OrderAdjustmentHelper.AdjustMerchantCalculatedShipping(basket, mcsa);
                }
                else if (shipAdj is FlatRateShippingAdjustment)
                {
                    FlatRateShippingAdjustment frsa = (FlatRateShippingAdjustment)shipAdj;
                    OrderAdjustmentHelper.AdjustFlatRateShipping(basket, frsa);
                }
                else if (shipAdj is PickupShippingAdjustment)
                {
                    PickupShippingAdjustment pusa = (PickupShippingAdjustment)shipAdj;
                    OrderAdjustmentHelper.AdjustPickupShipping(basket, pusa);
                }
            }

            //tax adjustments
            if (orderAdj.totaltax != null && orderAdj.totaltax.Value > 0)
            {
                trace.Write(traceKey, "process tax adjustments");
                OrderAdjustmentHelper.AdjustTax(basket, orderAdj.totaltax.Value);
            }
        }
コード例 #29
0
        public void Process()
        {
            TraceContext trace    = WebTrace.GetTraceContext();
            string       traceKey = "GoogleCheckout.AC.NewOrderHandler";

            trace.Write(traceKey, "Begin NewOrderHandler.Process, Google order number " + N1.googleordernumber);

            Order order = OrderDataSource.LoadForGoogleOrderNumber(N1.googleordernumber);

            if (order == null) // ordernumber not already entered
            {
                trace.Write(traceKey, "Google order not present in database, get basket");
                Basket basket = AcHelper.GetAcBasket(N1.shoppingcart, true);
                if (basket == null)
                {
                    trace.Write(traceKey, "Basket could not be obtained (End NewOrderHandler.Process)");
                    return;
                }

                //basket is ready. check if there are any order adjustments to be made
                trace.Write(traceKey, "Check for order adjustments");
                OrderAdjustment orderAdj = N1.orderadjustment;
                if (orderAdj != null)
                {
                    trace.Write(traceKey, "Order adjustments present, add to basket");
                    OrderAdjustmentHelper.DoOrderAdjustments(orderAdj, basket);
                }

                trace.Write(traceKey, "set billing address");
                Users.Address primaryAddress = basket.User.PrimaryAddress;
                AcHelper.PopulateAcAddress(primaryAddress, N1.buyerbillingaddress);
                trace.Write(traceKey, "set shipping address");
                Users.Address shipAddr = AcHelper.GetAcAddress(basket.User, N1.buyershippingaddress);
                basket.User.Addresses.Add(shipAddr);
                basket.User.Save();

                trace.Write(traceKey, "package the basket");
                basket.Package(false);

                if (basket.Shipments.Count > 0)
                {
                    //there are shippable items / shipments
                    //set shipment address and shipment method
                    trace.Write(traceKey, "shippable items present, get shipping method");
                    ShipMethod shipMethod = AcHelper.GetShipMethod(basket);
                    trace.Write(traceKey, "ship method is " + shipMethod.Name + " (ID" + shipMethod.ShipMethodId.ToString() + ")");
                    foreach (BasketShipment shipment in basket.Shipments)
                    {
                        shipment.AddressId    = shipAddr.AddressId;
                        shipment.ShipMethodId = shipMethod.ShipMethodId;
                        shipment.Save();
                    }
                    //have to link the shipping charges with some shipment.
                    //we can't know which shipment. Just link to the first.
                    trace.Write(traceKey, "assign shipping charges to first shipment");
                    BasketShipment basketShipment = basket.Shipments[0];
                    foreach (BasketItem item in basket.Items)
                    {
                        if (item.OrderItemType == OrderItemType.Shipping)
                        {
                            item.BasketShipmentId = basketShipment.BasketShipmentId;
                            //update the sku and shipping method name so that scrubbed name is not used
                            item.Name = shipMethod.Name;
                            item.Sku  = string.Empty;
                        }
                    }
                }

                trace.Write(traceKey, "save basket");
                basket.Save();

                //now checkout the order with null payment.
                //this will alow payment to be processed later
                trace.Write(traceKey, "submit basket checkout");
                CheckoutRequest  acCheckout = new CheckoutRequest(null);
                CheckoutResponse acResp     = basket.Checkout(acCheckout);
                if (acResp.Success)
                {
                    trace.Write(traceKey, "checkout was successful, update the google order number for AC order number " + acResp.OrderNumber.ToString());
                    order = OrderDataSource.Load(acResp.OrderId, false);
                    if (order != null)
                    {
                        //update email address associated with order
                        order.BillToEmail       = N1.buyerbillingaddress.email;
                        order.GoogleOrderNumber = N1.googleordernumber;

                        bool isPaidByGc = false;

                        //IF THERE IS ONE PAYMENT AND IT IS A GIFT CERTIFICATE
                        //AND IT COVERS THE BALANCE OF THE ORDER THEN THIS IS THE GOOGLE PAYMENT
                        if (order.Payments.Count == 1)
                        {
                            int     gcPayMethodId = PaymentEngine.GetGiftCertificatePaymentMethod().PaymentMethodId;
                            Payment payment       = order.Payments[0];
                            if (payment.PaymentMethodId == gcPayMethodId)
                            {
                                if (payment.Amount == order.TotalCharges)
                                {
                                    isPaidByGc = true;
                                }
                            }
                        }
                        if (!isPaidByGc)
                        {
                            //We need to create a new payment with status of authorization pending
                            Payment payment = new Payment();
                            payment.PaymentMethodId   = AcHelper.GetGCPaymentMethodId(this.GatewayInstance);
                            payment.Amount            = order.GetBalance(false);
                            payment.OrderId           = order.OrderId;
                            payment.PaymentMethodName = "GoogleCheckout";
                            Transaction trans = new Transaction();
                            trans.TransactionType       = TransactionType.Authorize;
                            trans.TransactionStatus     = TransactionStatus.Pending;
                            trans.Amount                = payment.Amount;
                            trans.PaymentGatewayId      = this.GatewayInstance.PaymentGatewayId;
                            trans.ProviderTransactionId = N1.googleordernumber;
                            trans.TransactionDate       = N1.timestamp;
                            payment.Transactions.Add(trans);
                            payment.PaymentStatus = PaymentStatus.AuthorizationPending;
                            order.Payments.Add(payment);
                        }
                        order.Save();
                    }
                    else
                    {
                        OrderDataSource.UpdateGoogleOrderNumber(acResp.OrderId, N1.googleordernumber);
                    }
                }
                else
                {
                    trace.Write(traceKey, "checkout failed for google order");
                    CommerceBuilder.Utility.Logger.Warn("GoogleCheckout : New Order Checkout Failed.");
                }

                trace.Write(traceKey, "Send AC order number back to Google");
                AcNotifier.AddMerchantOrderNumber(GatewayInstance, N1.googleordernumber, acResp.OrderNumber.ToString());
            }
            else
            {
                //order number already entered. Just send notification
                trace.Write(traceKey, "Google order in database, send AC order number back to Google");
                AcNotifier.AddMerchantOrderNumber(GatewayInstance, N1.googleordernumber, order.OrderNumber.ToString());
            }
            trace.Write(traceKey, "End NewOrderHandler.Process");
        }
コード例 #30
0
        public void BaseCreateSalesInvoice(PurchaseInvoiceCreateSalesInvoice method)
        {
            var salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                               .WithPurchaseInvoice(this)
                               .WithBilledFrom(this.BilledTo)
                               .WithBilledFromContactPerson(this.BilledToContactPerson)
                               .WithBillToCustomer(this.BillToEndCustomer)
                               .WithAssignedBillToContactMechanism(this.DerivedBillToEndCustomerContactMechanism)
                               .WithBillToContactPerson(this.BillToEndCustomerContactPerson)
                               .WithShipToCustomer(this.ShipToEndCustomer)
                               .WithAssignedShipToAddress(this.DerivedShipToEndCustomerAddress)
                               .WithShipToContactPerson(this.ShipToEndCustomerContactPerson)
                               .WithDescription(this.Description)
                               .WithInvoiceDate(this.Session().Now())
                               .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                               .WithCustomerReference(this.CustomerReference)
                               .WithAssignedPaymentMethod(this.DerivedBillToCustomerPaymentMethod)
                               .WithComment(this.Comment)
                               .WithInternalComment(this.InternalComment)
                               .Build();

            foreach (OrderAdjustment orderAdjustment in this.OrderAdjustments)
            {
                OrderAdjustment newAdjustment = null;
                if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
                {
                    newAdjustment = new DiscountAdjustmentBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
                {
                    newAdjustment = new SurchargeAdjustmentBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
                {
                    newAdjustment = new FeeBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
                {
                    newAdjustment = new ShippingAndHandlingChargeBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
                {
                    newAdjustment = new MiscellaneousChargeBuilder(this.Session()).Build();
                }

                newAdjustment.Amount ??= orderAdjustment.Amount;
                newAdjustment.Percentage ??= orderAdjustment.Percentage;
                salesInvoice.AddOrderAdjustment(newAdjustment);
            }

            foreach (PurchaseInvoiceItem purchaseInvoiceItem in this.PurchaseInvoiceItems)
            {
                var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                  .WithInvoiceItemType(purchaseInvoiceItem.InvoiceItemType)
                                  .WithAssignedUnitPrice(purchaseInvoiceItem.AssignedUnitPrice)
                                  .WithProduct(purchaseInvoiceItem.Part as UnifiedGood)
                                  .WithSerialisedItem(purchaseInvoiceItem.SerialisedItem)
                                  .WithNextSerialisedItemAvailability(new SerialisedItemAvailabilities(this.Session()).Sold)
                                  .WithQuantity(purchaseInvoiceItem.Quantity)
                                  .WithComment(purchaseInvoiceItem.Comment)
                                  .WithInternalComment(purchaseInvoiceItem.InternalComment)
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);
            }

            var internalOrganisation = (InternalOrganisation)salesInvoice.BilledFrom;

            if (!internalOrganisation.ActiveCustomers.Contains(salesInvoice.BillToCustomer))
            {
                new CustomerRelationshipBuilder(this.Strategy.Session)
                .WithCustomer(salesInvoice.BillToCustomer)
                .WithInternalOrganisation(internalOrganisation)
                .Build();
            }

            this.AddDeniedPermission(new Permissions(this.Strategy.Session).Get(this.Meta.ObjectType, this.Meta.CreateSalesInvoice, Operations.Execute));
        }
コード例 #31
0
 public static string AdjustmentLabelText(this HtmlHelper htmlHelper, Order order, OrderAdjustment adjustment, IEnumerable <Product> products)
 {
     return(order.GetAdjustmentLabelText(adjustment, products));
 }