Exemplo n.º 1
0
        internal static void ProcessWarehouseManagamentSystem(ShiftTransaction transaction)
        {
            if (transaction == null || !ConfigurationMapper.Instance.IsWmsEnabled)
            {
                return;
            }

            //ustawiamy odpowiednie id'ki jezeli jest powiazanie z linia

            /*
             * incomeWarehosueDocumentLineId - dla PZ i FZ kernel. WZ i FZ to panel
             * warehouseDocumentLineId - zawsze kernel
             * warehouseId - jezeli jest powiazanie z linia to jadro. moze byc null
             */
            foreach (Shift shift in transaction.Shifts.Children)
            {
                if (shift.RelatedWarehouseDocumentLine != null)
                {
                    if (shift.RelatedWarehouseDocumentLine.Parent.BOType == BusinessObjectType.WarehouseDocument &&
                        ((WarehouseDocument)shift.RelatedWarehouseDocumentLine.Parent).WarehouseDirection == WarehouseDirection.Income)
                    {
                        shift.IncomeWarehouseDocumentLineId = shift.RelatedWarehouseDocumentLine.Id.Value;
                    }

                    shift.WarehouseDocumentLineId = shift.RelatedWarehouseDocumentLine.Id.Value;
                    shift.WarehouseId             = shift.RelatedWarehouseDocumentLine.WarehouseId;
                }
            }

            using (WarehouseCoordinator c = new WarehouseCoordinator(false, false))
            {
                c.SaveBusinessObject(transaction);
            }
        }
Exemplo n.º 2
0
        internal ShiftTransaction CreateShiftTransactionFromCommercialShiftTransaction(ShiftTransaction transaction)
        {
            ShiftTransaction st = new ShiftTransaction(null);

            st.ReasonId = transaction.ReasonId;
            st.Status   = transaction.Status;

            return(st);
        }
Exemplo n.º 3
0
        public XDocument GetShiftTransactionByShiftId(XDocument requestXml)
        {
            if (requestXml.Root.Element("shiftId") == null)
            {
                throw new ArgumentException("No shiftId node in xml");
            }

            ShiftTransaction st = ((WarehouseMapper)this.Mapper).GetShiftTransactionByShiftId(new Guid(requestXml.Root.Element("shiftId").Value));

            return(st.FullXml);
        }
Exemplo n.º 4
0
        public override IBusinessObject CreateNewBusinessObject(BusinessObjectType type, XDocument requestXml)
        {
            IBusinessObject bo = null;

            switch (type)
            {
            case BusinessObjectType.ShiftTransaction:
                bo = new ShiftTransaction(null);
                break;

            case BusinessObjectType.Container:
                bo = new Container(null);
                break;

            default:
                throw new InvalidOperationException("WarehouseMapper cannot create this type of objects.");
            }

            bo.GenerateId();
            return(bo);
        }
Exemplo n.º 5
0
        public string SaveIndividualEmployeeShift(Int64 UserId, int Shift, DateTime FromDate, DateTime ToDate, Int64 MgrId)
        {
            try
            {
                int isSaved = 0;
                using (var context = new NLTDDbContext())
                {
                    var shiftMapping = context.ShiftMapping.Where(c => c.UserID == UserId && (c.ShiftDate >= FromDate && c.ShiftDate <= ToDate)).ToList();
                    shiftMapping.ForEach(u =>
                    {
                        u.ShiftID      = Shift;
                        u.ModifiedBy   = MgrId;
                        u.ModifiedDate = DateTime.Now;
                    });

                    isSaved = context.SaveChanges();

                    ShiftTransaction shiftTransaction = new ShiftTransaction
                    {
                        ShiftID     = Shift,
                        UserId      = UserId,
                        CreatedBy   = MgrId,
                        Createddate = DateTime.Now,
                        FromDate    = FromDate,
                        ToDate      = ToDate
                    };
                    context.ShiftTransaction.Add(shiftTransaction);
                    isSaved = context.SaveChanges();
                }

                return(isSaved > 0 ? "Saved" : "Failed");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks if the object has changed against <see cref="BusinessObject.AlternateVersion"/> and updates its own <see cref="BusinessObject.Status"/>.
        /// </summary>
        /// <param name="isNew">Value indicating whether the <see cref="BusinessObject"/> should be considered as the new one or the old one.</param>
        public override void UpdateStatus(bool isNew)
        {
            base.UpdateStatus(isNew);

            WarehouseDocument parent = (WarehouseDocument)this.Parent;

            WarehouseDocumentLine alternateLine = this.AlternateVersion as WarehouseDocumentLine;

            if (this.IncomeOutcomeRelations != null)
            {
                if (this.Status == BusinessObjectStatus.Deleted)
                {
                    this.IncomeOutcomeRelations.SetChildrenStatus(BusinessObjectStatus.Deleted);

                    //wywalamy wszystkie shifty ktore byly powiazane z ta pozycja bo zostana one usuniete w
                    //procedurze p_deleteWarehouseDocumentLine

                    ShiftTransaction st = ((WarehouseDocument)this.Parent).ShiftTransaction;

                    List <Shift> shiftsToDelete = new List <Shift>();

                    if (st != null)
                    {
                        foreach (var shift in st.Shifts.Children.Where(s => s.RelatedWarehouseDocumentLine == this))
                        {
                            //shift.Status = BusinessObjectStatus.Deleted;
                            shiftsToDelete.Add(shift);
                        }

                        foreach (var shift in shiftsToDelete)
                        {
                            st.Shifts.Remove(shift);
                        }

                        shiftsToDelete.Clear();
                    }

                    if (alternateLine != null)
                    {
                        WarehouseDocument alternateDocument = (WarehouseDocument)alternateLine.Parent;

                        if (alternateDocument.ShiftTransaction != null)
                        {
                            foreach (var shift in alternateDocument.ShiftTransaction.Shifts.Children.Where(ss => ss.RelatedWarehouseDocumentLine == alternateLine))
                            {
                                shiftsToDelete.Add(shift);
                            }

                            foreach (var shift in shiftsToDelete)
                            {
                                st.Shifts.Remove(shift);
                            }

                            shiftsToDelete.Clear();
                        }
                    }

                    //wywalamy wszystkie commercialWarehouseValuation
                    this.CommercialWarehouseValuations.RemoveAll();
                }
                else if (this.Status == BusinessObjectStatus.Modified &&
                         parent.WarehouseDirection == WarehouseDirection.Outcome &&
                         DictionaryMapper.Instance.GetWarehouse(this.WarehouseId).ValuationMethod == ValuationMethod.Fifo)
                {
                    ((WarehouseDocumentLine)this.AlternateVersion).IncomeOutcomeRelations.SetChildrenStatus(BusinessObjectStatus.Deleted);
                    this.IncomeOutcomeRelations.RemoveAll();
                }
                else if (this.IncomeOutcomeRelations != null)
                {
                    this.IncomeOutcomeRelations.UpdateStatus(isNew);
                }
            }

            if (this.CommercialWarehouseValuations != null)
            {
                this.CommercialWarehouseValuations.UpdateStatus(isNew);
            }

            if (this.CommercialWarehouseRelations != null)
            {
                this.CommercialWarehouseRelations.UpdateStatus(isNew);
            }

            if (this.Attributes != null)
            {
                this.Attributes.UpdateStatus(isNew);
            }

            //If RelatedLinesChangedPolicy is valueOnly, quantity and item cannot be changed
            if (parent.DocumentType.WarehouseDocumentOptions.RelatedLinesChangePolicy == RelatedLinesChangePolicy.ValueOnly)
            {
                bool throwException = false;

                if (alternateLine == null && !parent.IsNew && this.IsNew)
                {
                    throwException = true;
                }

                if (alternateLine != null &&
                    (this.Quantity != alternateLine.Quantity ||
                     this.ItemId != alternateLine.ItemId ||
                     this.ItemName != alternateLine.ItemName ||
                     this.ItemCode != alternateLine.ItemCode))
                {
                    throwException = true;
                }

                if (throwException)
                {
                    throw new ClientException(ClientExceptionId.OnlyLineValuesCanBeEdited);
                }
            }
        }
Exemplo n.º 7
0
        private void AddPositionToWarehouseDocument(ComplaintDocument complaintDocument, Guid warehouseId, List <WarehouseDocument> generatedWhDocs, Guid itemId, decimal quantity, Guid unitId, WarehouseDirection direction)
        {
            WarehouseDocument document = (from whDoc in generatedWhDocs
                                          where whDoc.WarehouseId == warehouseId &&
                                          whDoc.WarehouseDirection == direction
                                          select whDoc).FirstOrDefault();

            if (document == null)
            {
                string documentName = null;

                if (direction == WarehouseDirection.Outcome)
                {
                    documentName = "internalOutcome";
                }
                else
                {
                    documentName = "internalIncome";
                }

                string template = ProcessManager.Instance.GetDocumentTemplate(complaintDocument, documentName);

                using (DocumentCoordinator c = new DocumentCoordinator(false, false))
                {
                    document             = (WarehouseDocument)c.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, template, null);
                    document.WarehouseId = warehouseId;
                    string processType = complaintDocument.Attributes[DocumentFieldName.Attribute_ProcessType].Value.Value;
                    ProcessManager.Instance.AppendProcessAttributes(document, processType, documentName, null, null);
                    document.Contractor = complaintDocument.Contractor;
                    DuplicableAttributeFactory.DuplicateAttributes(complaintDocument, document);
                    complaintDocument.AddRelatedObject(document);
                    generatedWhDocs.Add(document);

                    var relation = complaintDocument.Relations.CreateNew();
                    relation.RelationType    = DocumentRelationType.ComplaintToInternalOutcome;
                    relation.RelatedDocument = document;

                    relation = document.Relations.CreateNew();
                    relation.RelationType    = DocumentRelationType.ComplaintToInternalOutcome;
                    relation.RelatedDocument = complaintDocument;
                    relation.DontSave        = true;
                }
            }

            WarehouseDocumentLine line = document.Lines.Children.Where(l => l.ItemId == itemId).FirstOrDefault();

            if (line == null)
            {
                line        = document.Lines.CreateNew();
                line.ItemId = itemId;
                line.UnitId = unitId;
            }

            line.Quantity += quantity;

            /* sprawdzamy czy jest to rozchod z magazynu wmsowego. jezeli tak to tworzymy shift transaction
             * dodajemy nowego shifta zgodnie z tym co jest w complaintDocument.Shifts, potem
             * shifta wiazemy z pozycja
             */

            if (DictionaryMapper.Instance.GetWarehouse(document.WarehouseId).ValuationMethod == ValuationMethod.DeliverySelection)
            {
                ShiftTransaction shiftTransaction = document.ShiftTransaction;

                if (shiftTransaction == null)
                {
                    shiftTransaction          = new ShiftTransaction(null);
                    document.ShiftTransaction = shiftTransaction;
                }

                //wyciagamy shifty z complaintDocumenta
                var shifts = complaintDocument.AllocationCollection.Allocations.Where(s => s.ItemId == itemId && s.WarehouseId == warehouseId).Select(x => x.AllocationShifts).FirstOrDefault();

                decimal quantityToGo = quantity; //kopiujemy shifty na ilosc niewieksza niz na pozycji jest wybrane

                foreach (var shift in shifts)
                {
                    if (shift.Quantity == 0)
                    {
                        continue;
                    }

                    decimal quantityTaken = 0;

                    if (quantityToGo > shift.Quantity)
                    {
                        quantityTaken = shift.Quantity;
                    }
                    else //quantityToGo <= shift.Quantity
                    {
                        quantityTaken = quantityToGo;
                    }

                    shift.Quantity -= quantityTaken;
                    quantityToGo   -= quantityTaken;

                    if (shift.SourceShiftId != null) //te ktore nie maja sourceShiftId pomijamy bo tutaj takie luzem w ogole nie maja shifta
                    {
                        var newShift = shiftTransaction.Shifts.CreateNew();
                        newShift.ItemId        = itemId;
                        newShift.WarehouseId   = warehouseId;
                        newShift.SourceShiftId = shift.SourceShiftId.Value;
                        newShift.IncomeWarehouseDocumentLineId = shift.IncomeWarehouseDocumentLineId;
                        newShift.Quantity = quantityTaken;
                        newShift.RelatedWarehouseDocumentLine = line;
                        newShift.LineOrdinalNumber            = line.OrdinalNumber;
                    }

                    //teraz incomeOutcomeRelation dodajemy
                    IncomeOutcomeRelation relation = line.IncomeOutcomeRelations.Children.Where(i => i.RelatedLine.Id.Value == shift.IncomeWarehouseDocumentLineId).FirstOrDefault();

                    if (relation == null)
                    {
                        relation = line.IncomeOutcomeRelations.CreateNew();

                        var incLine = new WarehouseDocumentLine(null);
                        incLine.Id           = shift.IncomeWarehouseDocumentLineId;
                        relation.RelatedLine = incLine;
                    }

                    relation.Quantity += quantityTaken;

                    if (quantityToGo == 0)
                    {
                        break;
                    }
                }
            }
        }
        public XDocument ProcessWarehouseCorrectiveDocument(WarehouseDocument document)
        {
            SqlConnectionManager.Instance.BeginTransaction();

            try
            {
                DictionaryMapper.Instance.CheckForChanges();

                this.MakeDifferentialDocument(document);

                if (document.DocumentType.WarehouseDocumentOptions.UpdateLastPurchasePrice)
                {
                    UpdateLastPurchasePriceRequest updateLastPurchasePriceRequest = new UpdateLastPurchasePriceRequest(document);
                    this.mapper.UpdateStock(updateLastPurchasePriceRequest);
                }

                //sprawdzamy czy nie zmniejszylismy gdzies ilosci ponizej ilosci ktora zostala juz rozchodowana
                bool outcomeCorrectionNeeded = this.CheckForQuantityBelowRelated(document);

                document.AlternateVersion = null;
                this.coordinator.UpdateStock(document);

                WarehouseDocument incomeCorrection = (WarehouseDocument)this.coordinator.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, document.Source.Attribute("template").Value, null);
                incomeCorrection.Contractor  = document.Contractor;
                incomeCorrection.WarehouseId = document.WarehouseId;
                DuplicableAttributeFactory.CopyAttributes(document, incomeCorrection);
                incomeCorrection.UpdateStatus(true);
                this.SaveDocumentHeaderAndAttributes(incomeCorrection);

                WarehouseDocument outcomeCorrection = null;
                int? outcomeCorrectionOrdinalNumber = null;
                Guid?outcomeCorrectionHeaderId      = null;

                if (outcomeCorrectionNeeded)
                {
                    DocumentType dt       = incomeCorrection.DocumentType;
                    string       template = dt.WarehouseDocumentOptions.AutomaticCostCorrectionTemplate;

                    if (String.IsNullOrEmpty(template))
                    {
                        throw new InvalidOperationException("automaticCostCorrectionTemplate is not set for the document type: " + dt.Symbol);
                    }

                    outcomeCorrection             = (WarehouseDocument)this.coordinator.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, template, null);
                    outcomeCorrection.WarehouseId = document.WarehouseId;
                    outcomeCorrection.UpdateStatus(true);
                    this.SaveDocumentHeaderAndAttributes(outcomeCorrection);
                    outcomeCorrectionOrdinalNumber = 0;
                    outcomeCorrectionHeaderId      = outcomeCorrection.Id.Value;
                }

                int       incomeCorrectionOrdinalNumber = 0;
                XDocument xml        = null;
                XDocument operations = XDocument.Parse("<root><incomeOutcomeRelation/><commercialWarehouseRelation/><commercialWarehouseValuation/></root>");

                foreach (WarehouseDocumentLine line in document.Lines.Children)
                {
                    Guid?commercialCorrectiveLineId = null;

                    if (line.CommercialCorrectiveLine != null)
                    {
                        commercialCorrectiveLineId = line.CommercialCorrectiveLine.Id;
                    }

                    xml = this.mapper.CreateIncomeQuantityCorrection(line.Id.Value, line.Version.Value, incomeCorrection.Id.Value,
                                                                     outcomeCorrectionHeaderId, line.Quantity, line.Value, line.IncomeDate.Value, incomeCorrectionOrdinalNumber,
                                                                     outcomeCorrectionOrdinalNumber, commercialCorrectiveLineId);

                    //Prowizorka umieszczona w celu wychwycenia trudnego do zlokalizowania błędu - przerzucam komunikat od Czarka w wyjątku
                    if (!xml.Root.HasElements)
                    {
                        throw new ClientException(ClientExceptionId.ForwardError, null
                                                  , String.Format("message:{0}", xml.Root.Value));
                    }

                    incomeCorrectionOrdinalNumber = Convert.ToInt32(xml.Root.Element("incomeOrdinalNumber").Value, CultureInfo.InvariantCulture);

                    if (outcomeCorrectionOrdinalNumber != null)
                    {
                        outcomeCorrectionOrdinalNumber = Convert.ToInt32(xml.Root.Element("outcomeOrdinalNumber").Value, CultureInfo.InvariantCulture);
                    }

                    if (xml.Root.Element("incomeOutcomeRelation") != null)
                    {
                        operations.Root.Element("incomeOutcomeRelation").Add(xml.Root.Element("incomeOutcomeRelation").Elements());
                    }

                    if (xml.Root.Element("commercialWarehouseRelation") != null)
                    {
                        operations.Root.Element("commercialWarehouseRelation").Add(xml.Root.Element("commercialWarehouseRelation").Elements());
                    }

                    if (xml.Root.Element("commercialWarehouseValuation") != null)
                    {
                        operations.Root.Element("commercialWarehouseValuation").Add(xml.Root.Element("commercialWarehouseValuation").Elements());
                    }
                }

                if (ConfigurationMapper.Instance.IsWmsEnabled &&
                    DictionaryMapper.Instance.GetWarehouse(incomeCorrection.WarehouseId).ValuationMethod == ValuationMethod.DeliverySelection)
                {
                    using (WarehouseCoordinator whC = new WarehouseCoordinator(false, false))
                    {
                        ShiftTransaction st = (ShiftTransaction)whC.CreateNewBusinessObject(BusinessObjectType.ShiftTransaction, null, null);
                        st.UpdateStatus(true);
                        XDocument shiftTransactionOperations = XDocument.Parse("<root/>");
                        st.SaveChanges(shiftTransactionOperations);
                        this.mapper.ExecuteOperations(shiftTransactionOperations);
                        this.mapper.CreateShiftCorrection(incomeCorrection.Id.Value, st.Id.Value);
                    }
                }

                if (outcomeCorrection != null)
                {
                    this.mapper.ValuateOutcomeWarehouseDocument(outcomeCorrection);
                }

                this.mapper.CreateCommunicationXml(incomeCorrection);

                if (outcomeCorrection != null)
                {
                    this.mapper.CreateCommunicationXml(outcomeCorrection);
                }

                this.mapper.CreateCommunicationXmlForDocumentRelations(operations);

                XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", incomeCorrection.Id.ToUpperString()));

                //Custom validation
                this.mapper.ExecuteOnCommitValidationCustomProcedure(incomeCorrection);
                if (outcomeCorrection != null)
                {
                    this.mapper.ExecuteOnCommitValidationCustomProcedure(outcomeCorrection);
                }

                if (this.coordinator.CanCommitTransaction)
                {
                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }

                return(returnXml);
            }
            catch (SqlException sqle)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:55");
                Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction);
                throw;
            }
            catch (Exception)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:56");
                if (this.coordinator.CanCommitTransaction)
                {
                    SqlConnectionManager.Instance.RollbackTransaction();
                }
                throw;
            }
        }