예제 #1
0
 public void AppsApprove(PurchaseInvoiceApprove method)
 {
     this.PurchaseInvoiceState = new PurchaseInvoiceStates(this.Strategy.Session).InProcess;
 }
예제 #2
0
        public void BaseApprove(PurchaseInvoiceApprove method)
        {
            this.PurchaseInvoiceState = new PurchaseInvoiceStates(this.Strategy.Session).NotPaid;

            var openTasks = this.TasksWhereWorkItem.Where(v => !v.ExistDateClosed).ToArray();

            if (openTasks.OfType <PurchaseInvoiceApproval>().Any())
            {
                openTasks.First().DateClosed = this.Session().Now();
            }

            foreach (PurchaseInvoiceItem purchaseInvoiceItem in this.ValidInvoiceItems)
            {
                if (purchaseInvoiceItem.ExistPart)
                {
                    var previousOffering = purchaseInvoiceItem.Part.SupplierOfferingsWherePart.FirstOrDefault(v =>
                                                                                                              v.Supplier.Equals(this.BilledFrom) && v.FromDate <= this.Session().Now() &&
                                                                                                              (!v.ExistThroughDate || v.ThroughDate >= this.Session().Now()));

                    if (previousOffering != null)
                    {
                        if (purchaseInvoiceItem.UnitBasePrice != previousOffering.Price)
                        {
                            previousOffering.ThroughDate = this.Session().Now();

                            var newOffering = new SupplierOfferingBuilder(this.Session())
                                              .WithSupplier(this.BilledFrom)
                                              .WithPart(purchaseInvoiceItem.Part)
                                              .WithPrice(purchaseInvoiceItem.UnitBasePrice)
                                              .WithFromDate(this.Session().Now())
                                              .WithComment(previousOffering.Comment)
                                              .WithMinimalOrderQuantity(previousOffering.MinimalOrderQuantity)
                                              .WithPreference(previousOffering.Preference)
                                              .WithQuantityIncrements(previousOffering.QuantityIncrements)
                                              .WithRating(previousOffering.Rating)
                                              .WithStandardLeadTime(previousOffering.StandardLeadTime)
                                              .WithSupplierProductId(previousOffering.SupplierProductId)
                                              .WithSupplierProductName(previousOffering.SupplierProductName)
                                              .WithUnitOfMeasure(previousOffering.UnitOfMeasure)
                                              .Build();

                            newOffering.LocalisedComments = previousOffering.LocalisedComments;
                        }
                    }
                    else
                    {
                        new SupplierOfferingBuilder(this.Session())
                        .WithSupplier(this.BilledFrom)
                        .WithPart(purchaseInvoiceItem.Part)
                        .WithUnitOfMeasure(purchaseInvoiceItem.Part?.UnitOfMeasure)
                        .WithPrice(purchaseInvoiceItem.UnitBasePrice)
                        .WithFromDate(this.Session().Now())
                        .Build();
                    }

                    foreach (OrderItemBilling orderItemBilling in purchaseInvoiceItem.OrderItemBillingsWhereInvoiceItem)
                    {
                        foreach (ShipmentReceipt receipt in orderItemBilling.OrderItem.ShipmentReceiptsWhereOrderItem)
                        {
                            receipt.ShipmentItem.InventoryItemTransactionWhereShipmentItem.Cost = purchaseInvoiceItem.UnitBasePrice;
                        }
                    }
                }
            }
        }