public override void Synchronize(Func <TreatmentOrderKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var treatmentOrderKey = getInput();

            var treatmentOrder = UnitOfWork.TreatmentOrderRepository.FindByKey(treatmentOrderKey, o => o.InventoryShipmentOrder.PickedInventory.Items.Select(i => i.CurrentLocation));

            if (treatmentOrder == null)
            {
                throw new Exception(string.Format("Could not find TreatmentOrder[{0}].", treatmentOrderKey));
            }

            var oldOrder = OldContext.tblMoves.Where(m => m.MoveNum == treatmentOrder.InventoryShipmentOrder.MoveNum)
                           .Select(m => new
            {
                tblMove = m,
                details = m.tblMoveDetails.Select(d => d.tblPackaging)
            }).FirstOrDefault();

            if (oldOrder == null)
            {
                throw new Exception(string.Format("Could not find tblMove[{0}].", treatmentOrder.InventoryShipmentOrder.MoveNum));
            }

            var oldTreatment = OldContextHelper.GetTreatment(treatmentOrder);
            var firstItem    = treatmentOrder.InventoryShipmentOrder.PickedInventory.Items.FirstOrDefault();

            if (firstItem == null)
            {
                throw new Exception("No PickedInventoryItems in TreatmentOrder.");
            }

            foreach (var oldDetail in oldOrder.tblMove.tblMoveDetails)
            {
                OldContext.tblOutgoings.AddObject(CreateOutgoing(treatmentOrder, oldDetail));

                oldDetail.TrtmtID = oldTreatment.TrtmtID;
                oldDetail.LocID   = firstItem.CurrentLocation.LocID.Value;
                OldContext.tblOutgoings.AddObject(CreateOutgoing(treatmentOrder, oldDetail, -1));
            }

            oldOrder.tblMove.Returned = treatmentOrder.Returned.ConvertUTCToLocal();
            oldOrder.tblMove.Status   = (int?)tblOrderStatus.Treated;

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.ReceivedTreatmentOrder, oldOrder.tblMove.MoveNum);
        }
Exemple #2
0
        private void SetPickedInventory(InventoryShipmentOrder newOrder, tblMove oldOrder, ref bool commitNewContext)
        {
            var MDetail            = OldContext.tblMoveDetails.Any() ? OldContext.tblMoveDetails.Max(m => m.MDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal();
            var oldDetailsToRemove = oldOrder.tblMoveDetails.ToList();

            foreach (var newItem in newOrder.PickedInventory.Items)
            {
                var oldItem = oldDetailsToRemove.FirstOrDefault(d => d.MDetail == newItem.DetailID) ?? oldDetailsToRemove.FirstOrDefault();
                if (oldItem == null)
                {
                    oldItem = new tblMoveDetail
                    {
                        MDetail = MDetail
                    };
                    OldContext.tblMoveDetails.AddObject(oldItem);
                    MDetail = MDetail.AddSeconds(1);
                }
                else
                {
                    oldDetailsToRemove.Remove(oldItem);
                }

                oldItem.MoveNum         = newOrder.MoveNum.Value;
                oldItem.Lot             = LotNumberParser.BuildLotNumber(newItem);
                oldItem.TTypeID         = (int?)newOrder.OrderType.ToTransType();
                oldItem.PkgID           = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID;
                oldItem.Quantity        = newItem.Quantity;
                oldItem.NetWgt          = (decimal?)newItem.PackagingProduct.Weight;
                oldItem.TtlWgt          = (decimal?)(newItem.Quantity * newItem.PackagingProduct.Weight);
                oldItem.LocID           = newItem.FromLocation.LocID.Value;
                oldItem.Move2           = newItem.CurrentLocation.LocID.Value;
                oldItem.TrtmtID         = OldContextHelper.GetTreatment(newItem).TrtmtID;
                oldItem.EmployeeID      = newOrder.PickedInventory.EmployeeId;
                oldItem.CustProductCode = newItem.CustomerProductCode;
                oldItem.CustLot         = newItem.CustomerLotCode;

                if (newItem.DetailID != oldItem.MDetail)
                {
                    commitNewContext = true;
                    newItem.DetailID = oldItem.MDetail;
                }
            }

            foreach (var o in oldDetailsToRemove)
            {
                OldContext.tblMoveDetails.DeleteObject(o);
            }
        }
Exemple #3
0
        private void SyncIncomingRecords(ChileMaterialsReceived received, tblLot tblLot, ICollection <tblVariety> varieties)
        {
            foreach (var incoming in tblLot.tblIncomings.ToList())
            {
                OldContext.tblIncomings.DeleteObject(incoming);
            }

            var treatment = OldContextHelper.GetTreatment(received);
            var varietyId = varieties.Select(v => v.VarietyID).DefaultIfEmpty(0).Max() + 1;

            foreach (var item in received.Items)
            {
                var packaging = OldContextHelper.GetPackaging(item.PackagingProduct);

                var variety = varieties.FirstOrDefault(v => v.Variety == item.ChileVariety);
                if (variety == null)
                {
                    variety = new tblVariety
                    {
                        VarietyID = varietyId++,
                        Variety   = item.ChileVariety,
                        EntryDate = DateTime.Now,
                        InActive  = false,
                        SortOrder = varietyId.ToString()
                    };
                    OldContextHelper.OldContext.tblVarieties.AddObject(variety);
                    varieties.Add(variety);
                }

                tblLot.tblIncomings.Add(new tblIncoming
                {
                    EmployeeID = tblLot.EmployeeID,
                    EntryDate  = tblLot.EntryDate.Value,

                    TTypeID    = (int?)(received.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated ? TransType.DeHy : TransType.Other),
                    Quantity   = item.Quantity,
                    TrtmtID    = treatment.TrtmtID,
                    Tote       = item.ToteKey,
                    VarietyID  = variety.VarietyID,
                    Company_IA = tblLot.Company_IA,
                    LocID      = item.Location.LocID.Value,
                    DehyLocale = item.GrowerCode,
                    PkgID      = packaging.PkgID,
                    NetWgt     = packaging.NetWgt,
                    TtlWgt     = item.Quantity * packaging.NetWgt
                });
            }
        }
Exemple #4
0
        private void SetPickOrder(InventoryShipmentOrder newOrder, tblMove oldOrder)
        {
            var MOrderDetail       = OldContext.tblMoveOrderDetails.Any() ? OldContext.tblMoveOrderDetails.Max(m => m.MOrderDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal();
            var oldDetailsToRemove = oldOrder.tblMoveOrderDetails.ToList();

            foreach (var newItem in newOrder.InventoryPickOrder.Items)
            {
                var oldItem = oldDetailsToRemove.FirstOrDefault();
                if (oldItem == null)
                {
                    oldItem = new tblMoveOrderDetail
                    {
                        MOrderDetail = MOrderDetail
                    };
                    OldContext.tblMoveOrderDetails.AddObject(oldItem);
                    MOrderDetail = MOrderDetail.AddSeconds(1);
                }
                else
                {
                    oldDetailsToRemove.Remove(oldItem);
                }

                oldItem.MoveNum  = newOrder.MoveNum.Value;
                oldItem.Quantity = newItem.Quantity;
                oldItem.ProdID   = OldContextHelper.GetProduct(newItem.Product.ProductCode).ProdID;
                oldItem.PkgID    = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID;
                oldItem.NetWgt   = (decimal?)newItem.PackagingProduct.Weight;
                oldItem.TtlWgt   = (decimal?)(newItem.PackagingProduct.Weight * newItem.Quantity);
                oldItem.TrtmtID  = OldContextHelper.GetTreatment(newItem).TrtmtID;

                oldItem.EmployeeID      = null;
                oldItem.CustProductCode = newItem.CustomerProductCode;
                oldItem.CustLot         = newItem.CustomerLotCode;
                oldItem.CustomerID      = newItem.Customer != null ? newItem.Customer.Company.Name : null;
            }

            foreach (var o in oldDetailsToRemove)
            {
                OldContext.tblMoveOrderDetails.DeleteObject(o);
            }
        }
Exemple #5
0
 private tblOutgoing CreateOutgoing(InventoryShipmentOrder order, PickedInventoryItem item, Location location, int quantity, bool forMove)
 {
     return(new tblOutgoing
     {
         EntryDate = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),
         Lot = LotNumberParser.BuildLotNumber(item),
         TTypeID = (int?)order.OrderType.ToTransType(),
         PkgID = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID,
         Tote = item.ToteKey,
         Quantity = quantity,
         NetWgt = (decimal?)item.PackagingProduct.Weight,
         TtlWgt = (decimal?)(quantity * item.PackagingProduct.Weight),
         LocID = (int)location.LocID,
         TrtmtID = OldContextHelper.GetTreatment(item).TrtmtID,
         EmployeeID = order.EmployeeId,
         BOMID = 0,
         BatchLot = 0,
         MoveNum = forMove ? order.MoveNum : null,
         MDetail = forMove ? item.DetailID : null,
         OrderNum = !forMove ? order.MoveNum : null,
         ODetail = !forMove ? item.DetailID : null,
         CustProductCode = item.CustomerProductCode
     });
 }
Exemple #6
0
        public override void Synchronize(Func <SyncSalesQuoteParameters> getInput)
        {
            var parameters = getInput();
            var key        = parameters.SalesQuoteKey;
            var salesQuote = UnitOfWork.SalesQuoteRepository.FindByKey(key,
                                                                       q => q.SourceFacility,
                                                                       q => q.Customer.Company,
                                                                       q => q.Broker,
                                                                       q => q.ShipmentInformation,
                                                                       q => q.Items.Select(i => i.Product),
                                                                       q => q.Items.Select(i => i.PackagingProduct.Product),
                                                                       q => q.Items.Select(i => i.Treatment));

            if (salesQuote == null)
            {
                throw new Exception(string.Format("Could not find SalesQuote[{0}].", key));
            }

            var      commitNewContext = false;
            tblQuote tblQuote;

            if (salesQuote.QuoteNum == null || parameters.New)
            {
                var quoteNum = (salesQuote.TimeStamp.Year * 100) - 1;
                quoteNum = OldContext.tblQuotes.Select(q => q.QuoteNum)
                           .Where(q => q > quoteNum)
                           .DefaultIfEmpty(quoteNum)
                           .Max() + 1;
                tblQuote = new tblQuote
                {
                    QuoteNum   = quoteNum,
                    TTypeID    = 19,
                    Status     = 1,
                    PreSample  = false,
                    s_GUID     = Guid.NewGuid(),
                    EmployeeID = salesQuote.EmployeeId,
                    EntryDate  = salesQuote.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL()
                };
                OldContext.tblQuotes.AddObject(tblQuote);

                salesQuote.QuoteNum = quoteNum;
                commitNewContext    = true;
            }
            else
            {
                tblQuote = OldContext.tblQuotes
                           .Include(q => q.tblQuoteDetails)
                           .FirstOrDefault(q => q.QuoteNum == salesQuote.QuoteNum);
                if (tblQuote == null)
                {
                    throw new Exception(string.Format("Could not find tblQuote[{0}]", salesQuote.QuoteNum));
                }
            }

            tblQuote.Date       = salesQuote.QuoteDate;
            tblQuote.DateRecd   = salesQuote.DateReceived;
            tblQuote.From       = salesQuote.CalledBy;
            tblQuote.TakenBy    = salesQuote.TakenBy;
            tblQuote.WHID       = salesQuote.SourceFacility == null ? null : salesQuote.SourceFacility.WHID;
            tblQuote.Company_IA = salesQuote.Customer == null ? null : salesQuote.Customer.Company.Name;
            tblQuote.Broker     = salesQuote.Broker == null ? null : salesQuote.Broker.Name;

            tblQuote.PalletOR        = (decimal?)salesQuote.ShipmentInformation.PalletWeight;
            tblQuote.PalletQty       = salesQuote.ShipmentInformation.PalletQuantity;
            tblQuote.FreightBillType = salesQuote.ShipmentInformation.FreightBillType;
            tblQuote.ShipVia         = salesQuote.ShipmentInformation.ShipmentMethod;
            tblQuote.Driver          = salesQuote.ShipmentInformation.DriverName;
            tblQuote.Carrier         = salesQuote.ShipmentInformation.CarrierName;
            tblQuote.TrlNbr          = salesQuote.ShipmentInformation.TrailerLicenseNumber;
            tblQuote.ContSeal        = salesQuote.ShipmentInformation.ContainerSeal;
            tblQuote.DelDueDate      = salesQuote.ShipmentInformation.RequiredDeliveryDate.ConvertUTCToLocal().RoundMillisecondsForSQL();
            tblQuote.SchdShipDate    = salesQuote.ShipmentInformation.ShipmentDate.ConvertUTCToLocal().RoundMillisecondsForSQL();

            tblQuote.CCompany  = salesQuote.SoldTo.Name;
            tblQuote.CAddress1 = salesQuote.SoldTo.Address.AddressLine1;
            tblQuote.CAddress2 = salesQuote.SoldTo.Address.AddressLine2;
            tblQuote.CAddress3 = salesQuote.SoldTo.Address.AddressLine3;
            tblQuote.CCity     = salesQuote.SoldTo.Address.City;
            tblQuote.CState    = salesQuote.SoldTo.Address.State;
            tblQuote.CZip      = salesQuote.SoldTo.Address.PostalCode;
            tblQuote.CCountry  = salesQuote.SoldTo.Address.Country;

            tblQuote.SCompany  = salesQuote.ShipmentInformation.ShipTo.Name;
            tblQuote.SPhone    = salesQuote.ShipmentInformation.ShipTo.Phone;
            tblQuote.SAddress1 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine1;
            tblQuote.SAddress2 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine2;
            tblQuote.SAddress3 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine3;
            tblQuote.SCity     = salesQuote.ShipmentInformation.ShipTo.Address.City;
            tblQuote.SState    = salesQuote.ShipmentInformation.ShipTo.Address.State;
            tblQuote.SZip      = salesQuote.ShipmentInformation.ShipTo.Address.PostalCode;
            tblQuote.SCountry  = salesQuote.ShipmentInformation.ShipTo.Address.Country;

            tblQuote.Company  = salesQuote.ShipmentInformation.FreightBill.Name;
            tblQuote.Phone    = salesQuote.ShipmentInformation.FreightBill.Phone;
            tblQuote.Email    = salesQuote.ShipmentInformation.FreightBill.EMail;
            tblQuote.Address1 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine1;
            tblQuote.Address2 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine2;
            tblQuote.Address3 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine3;
            tblQuote.City     = salesQuote.ShipmentInformation.FreightBill.Address.City;
            tblQuote.State    = salesQuote.ShipmentInformation.FreightBill.Address.State;
            tblQuote.Zip      = salesQuote.ShipmentInformation.FreightBill.Address.PostalCode;
            tblQuote.Country  = salesQuote.ShipmentInformation.FreightBill.Address.Country;

            var QDetail         = OldContext.tblQuoteDetails.Select(d => d.QDetail).DefaultIfEmpty(DateTime.Now).Max();
            var detailsToRemove = tblQuote.tblQuoteDetails.ToDictionary(d => d.QDetail);

            foreach (var item in salesQuote.Items)
            {
                tblQuoteDetail detail;
                if (item.QDetailID != null)
                {
                    if (detailsToRemove.TryGetValue(item.QDetailID.Value, out detail))
                    {
                        detailsToRemove.Remove(item.QDetailID.Value);
                    }
                    else
                    {
                        throw new Exception(string.Format("Could not find tblQuoteDetail[{0}]", item.QDetailID));
                    }
                }
                else
                {
                    QDetail = QDetail.AddSeconds(1).RoundMillisecondsForSQL();
                    detail  = new tblQuoteDetail
                    {
                        QDetail  = QDetail,
                        QuoteNum = tblQuote.QuoteNum,
                        s_GUID   = Guid.NewGuid()
                    };
                    OldContext.tblQuoteDetails.AddObject(detail);

                    item.QDetailID   = detail.QDetail;
                    commitNewContext = true;
                }

                var product   = OldContextHelper.GetProduct(item.Product.ProductCode);
                var packaging = OldContextHelper.GetPackaging(item.PackagingProduct);
                var treatment = OldContextHelper.GetTreatment(item.Treatment);

                detail.ProdID  = product.ProdID;
                detail.PkgID   = packaging.PkgID;
                detail.TrtmtID = treatment.TrtmtID;

                detail.Quantity        = item.Quantity;
                detail.Price           = (decimal?)item.PriceBase;
                detail.FreightP        = (decimal?)item.PriceFreight;
                detail.TrtnmntP        = (decimal?)item.PriceTreatment;
                detail.WHCostP         = (decimal?)item.PriceWarehouse;
                detail.Rebate          = (decimal?)item.PriceRebate;
                detail.CustProductCode = item.CustomerProductCode;
            }

            foreach (var detail in detailsToRemove.Values)
            {
                OldContext.tblQuoteDetails.DeleteObject(detail);
            }

            OldContext.SaveChanges();
            if (commitNewContext)
            {
                UnitOfWork.Commit();
            }

            Console.WriteLine(ConsoleOutput.SyncTblQuote, tblQuote.QuoteNum);
        }
Exemple #7
0
        private void SynchronizeOldContract(Contract contract, tblContract oldContract)
        {
            var warehouse = OldContextHelper.GetWarehouse(contract.DefaultPickFromFacility.Name);

            if (warehouse == null)
            {
                throw new Exception(string.Format("Could not find tblWarehouse with WhouseAbbr[{0}].", contract.DefaultPickFromFacility.Name));
            }

            oldContract.EmployeeID = contract.EmployeeId;
            oldContract.KDate      = contract.ContractDate;
            oldContract.BegDate    = contract.TermBegin;
            oldContract.EndDate    = contract.TermEnd;

            oldContract.Contact_IA  = contract.ContactName;
            oldContract.Company_IA  = contract.Customer.Company.Name;
            oldContract.Address1_IA = contract.ContactAddress.AddressLine1;
            oldContract.Address2_IA = contract.ContactAddress.AddressLine2;
            oldContract.Address3_IA = contract.ContactAddress.AddressLine3;
            oldContract.City_IA     = contract.ContactAddress.City;
            oldContract.State_IA    = contract.ContactAddress.State;
            oldContract.Zip_IA      = contract.ContactAddress.PostalCode;
            oldContract.Country_IA  = contract.ContactAddress.Country;
            oldContract.Broker      = contract.Broker.Name;
            oldContract.PmtTerms    = contract.PaymentTerms;
            oldContract.PONum       = contract.CustomerPurchaseOrder;
            oldContract.KType       = contract.ContractType.ToString();
            oldContract.KStatus     = contract.ContractStatus.ToString();
            oldContract.FOB         = contract.FOB;
            oldContract.Comments    = contract.Comments.Notes.AggregateNotes();
            oldContract.Notes2Print = contract.NotesToPrint;
            oldContract.WHID        = warehouse.WHID;

            oldContract.Serialized = SerializableContract.Serialize(contract);

            var existingDetails = oldContract.tblContractDetails != null?oldContract.tblContractDetails.ToList() : new List <tblContractDetail>();

            var kDetailId = OldContext.tblContractDetails.Any() ? OldContext.tblContractDetails.Max(d => d.KDetailID) : DateTime.UtcNow.ConvertUTCToLocal();

            foreach (var item in contract.ContractItems)
            {
                var detail = item.KDetailID == null ? null : existingDetails.FirstOrDefault(d => d.KDetailID == item.KDetailID.Value);
                if (detail == null)
                {
                    kDetailId = kDetailId.AddSeconds(1);
                    detail    = new tblContractDetail
                    {
                        KDetailID  = kDetailId,
                        ContractID = oldContract.ContractID
                    };
                    OldContext.tblContractDetails.AddObject(detail);
                    item.KDetailID    = kDetailId;
                    _commitNewContext = true;
                }
                else
                {
                    existingDetails.Remove(detail);
                }

                detail.ProdID          = OldContextHelper.GetProduct(item.ChileProduct).ProdID;
                detail.PkgID           = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID;
                detail.Quantity        = item.Quantity;
                detail.TrtmtID         = OldContextHelper.GetTreatment(item).TrtmtID;
                detail.Price           = (decimal?)item.PriceBase;
                detail.FreightP        = (decimal?)item.PriceFreight;
                detail.TrtnmntP        = (decimal?)item.PriceTreatment;
                detail.WHCostP         = (decimal?)item.PriceWarehouse;
                detail.Rebate          = (decimal?)item.PriceRebate;
                detail.CustProductCode = item.CustomerProductCode;
                detail.Spec            = item.UseCustomerSpec ? "Cust" : "RVC";
                detail.TtlWgt          = (decimal?)(item.Quantity * item.PackagingProduct.Weight);
            }

            foreach (var detail in existingDetails)
            {
                OldContext.tblContractDetails.DeleteObject(detail);
            }
        }
Exemple #8
0
        private void SyncPickedItems(tblOrder tblOrder, SalesOrderItem orderItem, ref DateTime lastEntryDate, tblOrderDetail detail)
        {
            var stagedToDelete = detail.tblStagedFGs.ToDictionary(s => s.EntryDate);

            foreach (var picked in orderItem.PickedItems ?? new List <SalesOrderPickedItem>())
            {
                tblStagedFG staged;
                if (picked.PickedInventoryItem.DetailID != null && stagedToDelete.TryGetValue(picked.PickedInventoryItem.DetailID.Value, out staged))
                {
                    stagedToDelete.Remove(staged.EntryDate);
                }
                else
                {
                    lastEntryDate = lastEntryDate.AddSeconds(1);
                    staged        = new tblStagedFG
                    {
                        EntryDate = lastEntryDate,
                        s_GUID    = Guid.NewGuid()
                    };
                    detail.tblStagedFGs.Add(staged);
                    picked.PickedInventoryItem.DetailID = staged.EntryDate;
                    _commitNewContext = true;
                }

                var packaging = OldContextHelper.GetPackaging(picked.PickedInventoryItem.PackagingProduct);
                var treatment = OldContextHelper.GetTreatment(picked.PickedInventoryItem);

                staged.OrderNum        = tblOrder.OrderNum;
                staged.ODetail         = detail.ODetail;
                staged.Lot             = LotNumberParser.BuildLotNumber(picked.PickedInventoryItem);
                staged.TTypeID         = (int?)TransType.Batching; //To match logic found in Access (apnd_PickProdTemp) - RI 2016-3-15
                staged.PkgID           = packaging.PkgID;
                staged.Quantity        = picked.PickedInventoryItem.Quantity;
                staged.NetWgt          = packaging.NetWgt;
                staged.TtlWgt          = picked.PickedInventoryItem.Quantity * packaging.NetWgt;
                staged.LocID           = picked.PickedInventoryItem.CurrentLocation.LocID.Value;
                staged.TrtmtID         = treatment.TrtmtID;
                staged.EmployeeID      = picked.PickedInventoryItem.PickedInventory.EmployeeId;
                staged.CustProductCode = picked.PickedInventoryItem.CustomerProductCode;
                staged.CustLot         = picked.PickedInventoryItem.CustomerLotCode;

                staged.AstaCalc = null;
                var asta = picked.PickedInventoryItem.Lot.Attributes.FirstOrDefault(a => a.AttributeShortName == GlobalKeyHelpers.AstaAttributeNameKey.AttributeNameKey_ShortName);
                if (asta != null)
                {
                    var productionEnd = asta.AttributeDate;
                    if (picked.PickedInventoryItem.Lot.ChileLot != null && picked.PickedInventoryItem.Lot.ChileLot.Production != null && picked.PickedInventoryItem.Lot.ChileLot.Production.Results != null)
                    {
                        productionEnd = picked.PickedInventoryItem.Lot.ChileLot.Production.Results.ProductionEnd;
                    }
                    staged.AstaCalc = AstaCalculator.CalculateAsta(asta.AttributeValue, asta.AttributeDate, productionEnd, DateTime.UtcNow);
                }

                staged.LoBac = false;
                if (picked.PickedInventoryItem.Lot.ChileLot != null)
                {
                    staged.LoBac = picked.PickedInventoryItem.Lot.ChileLot.AllAttributesAreLoBac;
                }
            }

            foreach (var staged in stagedToDelete.Values)
            {
                OldContext.tblStagedFGs.DeleteObject(staged);
            }
        }
Exemple #9
0
        private void SyncOrderItems(SalesOrder salesOrder, tblOrder tblOrder)
        {
            var detailsToDelete = tblOrder.tblOrderDetails.ToList();

            var nowODetail = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var oDetail    = OldContext.tblOrderDetails.Any() ? OldContext.tblOrderDetails.Max(o => o.ODetail) : nowODetail;

            if (oDetail < nowODetail)
            {
                oDetail = nowODetail;
            }

            var nowEntryDate  = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var lastEntryDate = OldContext.tblStagedFGs.Select(f => f.EntryDate).DefaultIfEmpty(nowEntryDate).Max();

            if (lastEntryDate < nowEntryDate)
            {
                lastEntryDate = nowEntryDate;
            }

            foreach (var orderItem in salesOrder.SalesOrderItems)
            {
                var detail = detailsToDelete.FirstOrDefault(d => d.ODetail == orderItem.ODetail);
                if (detail != null)
                {
                    detailsToDelete.Remove(detail);
                }
                else
                {
                    oDetail = oDetail.AddSeconds(1);
                    detail  = new tblOrderDetail
                    {
                        ODetail      = oDetail,
                        s_GUID       = Guid.NewGuid(),
                        tblStagedFGs = new EntityCollection <tblStagedFG>()
                    };
                    tblOrder.tblOrderDetails.Add(detail);
                    orderItem.ODetail = detail.ODetail;
                    _commitNewContext = true;
                }

                var product   = OldContextHelper.GetProduct(orderItem.InventoryPickOrderItem.Product.ProductCode);
                var packaging = OldContextHelper.GetPackaging(orderItem.InventoryPickOrderItem.PackagingProduct);
                var treatment = OldContextHelper.GetTreatment(orderItem.InventoryPickOrderItem);

                detail.OrderNum        = orderItem.Order.InventoryShipmentOrder.MoveNum.Value;
                detail.ProdID          = product.ProdID;
                detail.PkgID           = packaging.PkgID;
                detail.Quantity        = orderItem.InventoryPickOrderItem.Quantity;
                detail.TrtmtID         = treatment.TrtmtID;
                detail.Price           = (decimal?)orderItem.PriceBase;
                detail.FreightP        = (decimal?)orderItem.PriceFreight;
                detail.TrtnmntP        = (decimal?)orderItem.PriceTreatment;
                detail.WHCostP         = (decimal?)orderItem.PriceWarehouse;
                detail.Rebate          = (decimal?)orderItem.PriceRebate;
                detail.KDetailID       = orderItem.ContractItem == null ? null : orderItem.ContractItem.KDetailID;
                detail.CustProductCode = orderItem.InventoryPickOrderItem.CustomerProductCode;
                detail.CustLot         = orderItem.InventoryPickOrderItem.CustomerLotCode;

                SyncPickedItems(tblOrder, orderItem, ref lastEntryDate, detail);
            }

            foreach (var detail in detailsToDelete)
            {
                foreach (var staged in detail.tblStagedFGs)
                {
                    OldContext.tblStagedFGs.DeleteObject(staged);
                }
                OldContext.tblOrderDetails.DeleteObject(detail);
            }
        }