示例#1
0
        /// <summary>
        /// Check if name of technology name is unique
        /// </summary>
        /// <param name="document"></param>
        private void _CheckTechnologyNameExistence(CommercialDocument document)
        {
            if (document.DocumentType.DocumentCategory == DocumentCategory.Technology)
            {
                DocumentAttrValue technologyNameAttribute = document.Attributes[DocumentFieldName.Attribute_ProductionTechnologyName];
                if (technologyNameAttribute != null)
                {
                    //gdy nowy to walidujemy, gdy edytowany będziemy walidować tylko gdy nazwa się zmieniła
                    bool   validateTechnologyName = document.IsNew;
                    string technologyName         = technologyNameAttribute.Value.Value;
                    if (!document.IsNew && document.AlternateVersion != null)
                    {
                        DocumentAttrValue altTechnologyNameAttribute = ((CommercialDocument)document.AlternateVersion).Attributes[DocumentFieldName.Attribute_ProductionTechnologyName];
                        if (altTechnologyNameAttribute != null && technologyName == altTechnologyNameAttribute.Value.Value)
                        {
                            validateTechnologyName = false;
                        }
                    }
                    if (validateTechnologyName)
                    {
                        XDocument xml = XDocument.Parse(String.Format("<root><name>{0}</name></root>", technologyName));

                        xml = this.mapper.ExecuteStoredProcedure(StoredProcedure.document_p_checkTechnologyNameExistence, true, xml);

                        string result = xml.Root.Value;

                        if (result == "TRUE")
                        {
                            throw new ClientException(ClientExceptionId.ExistingTechnologyName, null, "name:" + technologyName);
                        }
                    }
                }
            }
        }
示例#2
0
        public void SetProcessStateChangeDate(Document document)
        {
            DocumentAttrValue processStateChangeDateAttr = document.Attributes.GetOrCreateNew(DocumentFieldName.Attribute_ProcessStateChangeDate);

            processStateChangeDateAttr.Value.Value =
                SessionManager.VolatileElements.CurrentDateTime.ToString(CultureInfo.InvariantCulture);
        }
示例#3
0
        public void Execute(Document document)
        {
            if (document.IsBeforeSystemStart)
            {
                return;
            }

            DocumentAttrValue attr = document.Attributes[DocumentFieldName.Attribute_ProcessState];

            if (attr != null)
            {
                ComplaintDocument complaintDocument = (ComplaintDocument)document;

                foreach (var line in complaintDocument.Lines)
                {
                    decimal decisionQuantity = line.ComplaintDecisions.Children.Sum(d => d.Quantity);

                    if (line.Quantity != decisionQuantity)
                    {
                        throw new ClientException(ClientExceptionId.ComplaintDocumentCloseError);
                    }

                    if (line.ComplaintDecisions.Children.Where(dd => dd.RealizeOption != RealizationStage.Realized).FirstOrDefault() != null)
                    {
                        throw new ClientException(ClientExceptionId.ComplaintDocumentCloseError);
                    }
                }

                attr.Value.Value = "closed";
                complaintDocument.DocumentStatus = DocumentStatus.Committed;
            }
        }
示例#4
0
        //istniejący obiekt
        public static void DuplicateShiftAttributes(XElement source, Document destination)
        {
            var attrsToDuplicate = DuplicableAttributeFactory.ShiftDuplicableAttributesList(source);

            if (attrsToDuplicate.Count > 0)
            {
                foreach (XElement attrToDuplicate in attrsToDuplicate)
                {
                    string            documentFieldId   = attrToDuplicate.Element(XmlName.DocumentFieldId).Value;
                    DocumentField     documentField     = DictionaryMapper.Instance.GetDocumentField(new Guid(documentFieldId));
                    DocumentFieldName documentFieldName = documentField.TypeName;
                    DocumentAttrValue destAttr          = destination.Attributes.GetOrCreateNew(documentFieldName);
                    destAttr.Value = new XElement(XmlName.Value, attrToDuplicate.Element(XmlName.Value).Nodes());
                }
            }
        }
示例#5
0
 /// <summary>
 /// Skopiowanie atrybutów o określonych documentTypeId
 /// </summary>
 /// <param name="source"></param>
 /// <param name="destination"></param>
 /// <param name="attributesToCopy"></param>
 public static void CopyAttributes(Document source, Document destination, List <Guid> attributesToCopy)
 {
     if (attributesToCopy != null)
     {
         foreach (Guid documentFieldId in attributesToCopy)
         {
             DocumentAttrValue sAttr = source.Attributes.Children.Where(a => a.DocumentFieldId == documentFieldId).FirstOrDefault();
             DocumentAttrValue dAttr = source.Attributes.Children.Where(a => a.DocumentFieldId == documentFieldId).FirstOrDefault();
             if (sAttr != null && !sAttr.Automatic && (dAttr == null || dAttr != null && !dAttr.Automatic))
             {
                 DocumentAttrValue newAttr = destination.Attributes.GetOrCreateNew(sAttr.DocumentFieldName);
                 newAttr.Value           = new XElement(sAttr.Value);
                 newAttr.DocumentFieldId = sAttr.DocumentFieldId;
             }
         }
     }
 }
示例#6
0
        public static void CopyAttributes(Document source, Document destination)
        {
            if (source == null || destination == null)
            {
                return;
            }

            //nie kopiujemy automatycznych bo i tak są już wstawione przez CreateNewBusinessObject
            foreach (DocumentAttrValue attr in source.Attributes.Where(_attr => !_attr.Automatic))
            {
                DocumentAttrValue dstAttr = destination.Attributes[attr.DocumentFieldName];
                if (dstAttr == null || !dstAttr.Automatic)
                {
                    DocumentAttrValue newAttr = destination.Attributes.CreateNew(attr.DocumentFieldName);
                    newAttr.Value           = new XElement(attr.Value);
                    newAttr.DocumentFieldId = attr.DocumentFieldId;
                }
            }
        }
示例#7
0
 private static void UpdateDocumentStatus(XDocument commPkg)
 {
     using (DocumentCoordinator cord = new DocumentCoordinator(false, false))
     {
         Guid documentId = new Guid(commPkg.Root.Element("shiftDocumentStatus").Attribute("outcomeShiftId").Value);
         WarehouseDocument outcomeShiftDocument = (WarehouseDocument)cord.LoadBusinessObject(Makolab.Fractus.Kernel.Enums.BusinessObjectType.WarehouseDocument, documentId);
         DocumentAttrValue oppositeDocStatus    = outcomeShiftDocument.Attributes.Children.Where(attr => attr.DocumentFieldName == Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus).SingleOrDefault();
         if (oppositeDocStatus == null)
         {
             oppositeDocStatus = outcomeShiftDocument.Attributes.CreateNew();
             oppositeDocStatus.DocumentFieldName = Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus;
         }
         DocumentAttrValue oppositeDocId = outcomeShiftDocument.Attributes.Children.Where(attr => attr.DocumentFieldName == Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId).SingleOrDefault();
         if (oppositeDocId == null)
         {
             oppositeDocId = outcomeShiftDocument.Attributes.CreateNew();
             oppositeDocId.DocumentFieldName = Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId;
             oppositeDocId.Value.Value       = commPkg.Root.Element("shiftDocumentStatus").Attribute("incomeShiftId").Value;
         }
         oppositeDocStatus.Value.Value = commPkg.Root.Element("shiftDocumentStatus").Attribute("status").Value;
         cord.SaveBusinessObject(outcomeShiftDocument);
     }
 }
示例#8
0
        public static bool IsSalesOrderClosed(CommercialDocument order)
        {
            DocumentAttrValue attrValue = order.Attributes[DocumentFieldName.Attribute_ProcessState];

            return(attrValue != null && attrValue.Value.Value == "closed");
        }
示例#9
0
        private static void CreateNextCorrectiveDocument(CommercialDocument lastCorrectiveDoc, CommercialDocument destination)
        {
            destination.CorrectedDocument = lastCorrectiveDoc;

            //copy header
            destination.CalculationType    = lastCorrectiveDoc.CalculationType;
            destination.DocumentCurrencyId = lastCorrectiveDoc.DocumentCurrencyId;
            destination.GrossValue         = lastCorrectiveDoc.GrossValue;
            destination.NetValue           = lastCorrectiveDoc.NetValue;
            destination.SummationType      = lastCorrectiveDoc.SummationType;
            destination.VatValue           = lastCorrectiveDoc.VatValue;
            //Jednak event date powinien być podpowiadany jako bieżąca data
            destination.EventDate = SessionManager.VolatileElements.CurrentDateTime;            //lastCorrectiveDoc.EventDate;

            if (lastCorrectiveDoc.Contractor != null)
            {
                ContractorMapper contractorMapper = DependencyContainerManager.Container.Get <ContractorMapper>();
                Contractor       contractor       = (Contractor)contractorMapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, lastCorrectiveDoc.Contractor.Id.Value);

                destination.Contractor          = contractor;
                destination.ContractorAddressId = lastCorrectiveDoc.ContractorAddressId;
            }

            //copy attributes if specified
            foreach (DocumentAttrValue attr in lastCorrectiveDoc.Attributes.Children)
            {
                if (attr.DocumentFieldName == DocumentFieldName.Attribute_SupplierDocumentDate ||
                    attr.DocumentFieldName == DocumentFieldName.Attribute_SupplierDocumentNumber)
                {
                    DocumentAttrValue dstAttr = destination.Attributes.CreateNew();
                    dstAttr.DocumentFieldName = attr.DocumentFieldName;
                    dstAttr.Value             = new XElement(attr.Value);
                }
            }

            //create vat tables
            foreach (CommercialDocumentVatTableEntry vtEntry in lastCorrectiveDoc.VatTableEntries.Children)
            {
                if (lastCorrectiveDoc.IsSettlementDocument && (vtEntry.GrossValue < 0 || vtEntry.NetValue < 0 || vtEntry.VatValue < 0))
                {
                    continue;
                }

                if (vtEntry.GrossValue != 0 || vtEntry.NetValue != 0 || vtEntry.VatValue != 0)
                {
                    CommercialDocumentVatTableEntry dstVtEntry = destination.VatTableEntries.CreateNew();

                    dstVtEntry.GrossValue = vtEntry.GrossValue;
                    dstVtEntry.NetValue   = vtEntry.NetValue;
                    dstVtEntry.VatValue   = vtEntry.VatValue;
                    dstVtEntry.VatRateId  = vtEntry.VatRateId;
                }
            }

            if (lastCorrectiveDoc.IsSettlementDocument)
            {
                destination.NetValue   = destination.VatTableEntries.Sum(s => s.NetValue);
                destination.GrossValue = destination.VatTableEntries.Sum(s => s.GrossValue);
                destination.VatValue   = destination.VatTableEntries.Sum(s => s.VatValue);
            }

            //create only these lines that werent corrected inside the same document
            var linesToCopy = from line in lastCorrectiveDoc.Lines.Children
                              where (lastCorrectiveDoc.Lines.Children.Where(w => w.CorrectedLine != null).Select(s => s.CorrectedLine.Id.Value)).Contains(line.Id.Value) == false
                              select line;

            foreach (CommercialDocumentLine srcLine in linesToCopy)
            {
                CommercialDocumentLine line = destination.Lines.CreateNew();
                line.CorrectedLine      = srcLine;
                line.DiscountGrossValue = srcLine.DiscountGrossValue;
                line.DiscountNetValue   = srcLine.DiscountNetValue;
                line.DiscountRate       = srcLine.DiscountRate;
                line.GrossPrice         = srcLine.GrossPrice;
                line.GrossValue         = srcLine.GrossValue;
                line.InitialGrossPrice  = srcLine.InitialGrossPrice;
                line.InitialGrossValue  = srcLine.InitialGrossValue;
                line.InitialNetPrice    = srcLine.InitialNetPrice;
                line.InitialNetValue    = srcLine.InitialNetValue;
                line.ItemId             = srcLine.ItemId;
                line.ItemName           = srcLine.ItemName;
                line.ItemVersion        = srcLine.ItemVersion;
                line.NetPrice           = srcLine.NetPrice;
                line.NetValue           = srcLine.NetValue;
                line.Quantity           = srcLine.Quantity;
                line.UnitId             = srcLine.UnitId;
                line.VatRateId          = srcLine.VatRateId;
                line.VatValue           = srcLine.VatValue;
                line.WarehouseId        = srcLine.WarehouseId;
                line.ItemCode           = srcLine.ItemCode;
                line.ItemTypeId         = srcLine.ItemTypeId;
            }
        }
        private void ValuateIncomeFromOutcome(IEnumerable <IGrouping <string, DBRow> > shiftLines)
        {
            XDocument valuationTemplate = XDocument.Parse("<root><warehouseDocumentValuation /></root>");

            using (var whDocCoord = new DocumentCoordinator(false, false))
            {
                foreach (var warehouseDocGroup in shiftLines)
                {
                    WarehouseDocument shift = null;
                    try
                    {
                        shift = (WarehouseDocument)whDocCoord.LoadBusinessObject(Makolab.Fractus.Kernel.Enums.BusinessObjectType.WarehouseDocument,
                                                                                 new Guid(warehouseDocGroup.Key));
                    }
                    catch (ClientException) { }

                    //there is a valuated document in database so we can forward valuation - no document = skip income valuation for this doc
                    if (shift != null)
                    {
                        DocumentAttrValue oppositeWarehouseIdAttr = shift.Attributes.Children.Where(attr => attr.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId).SingleOrDefault();
                        string            oppositeWarehouseId     = oppositeWarehouseIdAttr != null ? oppositeWarehouseIdAttr.Value.Value : null;
                        if (oppositeWarehouseId != null)
                        {
                            Warehouse oppositeWarehouse = DictionaryMapper.Instance.GetWarehouse(new Guid(oppositeWarehouseId));
                            Warehouse warehouse         = DictionaryMapper.Instance.GetWarehouse(shift.WarehouseId);

                            //skip local shift document valuations
                            if (warehouse.BranchId == oppositeWarehouse.BranchId)
                            {
                                continue;
                            }

                            // skip valuation in headquarter if not a target branch
                            if (this.IsHeadquarter == true && DictionaryMapper.Instance.GetBranch(oppositeWarehouse.BranchId).DatabaseId != Makolab.Fractus.Kernel.Mappers.ConfigurationMapper.Instance.DatabaseId)
                            {
                                continue;
                            }

                            foreach (var valuation in warehouseDocGroup)
                            {
                                var whDocLine = shift.Lines.Children.Where(line => line.Id.ToString()
                                                                           .Equals(valuation.Element("outcomeWarehouseDocumentLineId").Value, StringComparison.OrdinalIgnoreCase))
                                                .SingleOrDefault();
                                valuation.Xml.Add(new XAttribute("outcomeShiftOrdinalNumber", whDocLine.OrdinalNumber));
                            }

                            var valuationPkg = new XDocument(valuationTemplate);
                            valuationPkg.Root.Element("warehouseDocumentValuation").Add(new XAttribute("outcomeShiftId", shift.Id));
                            valuationPkg.Root.Element("warehouseDocumentValuation").Add(warehouseDocGroup);

                            try
                            {
                                whDocCoord.ValuateIncomeShiftDocument(valuationPkg.Root);
                            }
                            catch (ClientException e)
                            {
                                if (e.Id != Makolab.Fractus.Kernel.Enums.ClientExceptionId.ObjectNotFound)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#11
0
        internal static void DuplicateAttributes(Document source, Document destination, List <Guid> blockedAttributes)
        {
            List <DocumentAttrValue> attrsToRemove = new List <DocumentAttrValue>();

            foreach (DocumentAttrValue attr in source.Attributes.Children)
            {
                //zapamiętujemy czy atrybut wystepuje na dok. docelowym
                var dstAttribs = destination.Attributes.Children.Where(a => a.DocumentFieldId == attr.DocumentFieldId);
                if (attr.IsDuplicableTo(destination.DocumentTypeId) &&
                    (blockedAttributes == null ||
                     blockedAttributes != null && !blockedAttributes.Contains(attr.DocumentFieldId)))
                {
                    //kreowanie nowego
                    if (dstAttribs.Count() == 0)
                    {
                        DocumentAttrValue newAttr = destination.Attributes.CreateNew();
                        newAttr.DocumentFieldId = attr.DocumentFieldId;
                        newAttr.Value           = new XElement(attr.Value);
                    }
                    else
                    {
                        DuplicatedAttributeAction action = attr.DuplicateAction;

                        if (action == DuplicatedAttributeAction.OneInstance)
                        {
                            //sprawdzamy czy jest taka sama wartosc
                            if (attr.Value.ToString() != dstAttribs.First().Value.ToString())
                            {
                                if (blockedAttributes != null)
                                {
                                    blockedAttributes.Add(attr.DocumentFieldId);
                                }
                                destination.Attributes.Remove(dstAttribs.First());
                            }
                        }
                        else if (action == DuplicatedAttributeAction.Concatenate)
                        {
                            DocumentAttrValue dstAttr = dstAttribs.First();

                            if (!dstAttr.Value.Value.Contains(attr.Value.Value))
                            {
                                if (dstAttr.Value.Value.Length > 0)
                                {
                                    dstAttr.Value.Value += ", ";
                                }

                                dstAttr.Value.Value += attr.Value.Value;
                            }
                        }
                        else if (action == DuplicatedAttributeAction.Duplicate)
                        {
                            var existingAttribs = destination.Attributes.Children.Where(a => a.DocumentFieldId == attr.DocumentFieldId && a.Value.ToString() == attr.Value.ToString()).FirstOrDefault();

                            if (existingAttribs == null)
                            {
                                DocumentAttrValue newAttr = destination.Attributes.CreateNew();
                                newAttr.DocumentFieldId = attr.DocumentFieldId;
                                newAttr.Value           = new XElement(attr.Value);
                            }
                        }
                    }
                }
                //Jeśli atrybut nie ma być duplikowany a już jest w dokumencie (przyszedł do klienta) to jest usuwany.
                //Chyba, że ustawiono flagę wymuszającą jego pozostawienie
                else if (dstAttribs.Count() != 0)
                {
                    foreach (DocumentAttrValue dstAttr in dstAttribs.Where(_attr => !_attr.Automatic))
                    {
                        attrsToRemove.Add(dstAttr);
                    }
                }

                foreach (DocumentAttrValue attrToRemove in attrsToRemove)
                {
                    destination.Attributes.Children.Remove(attrToRemove);
                }
            }
        }
示例#12
0
        public static void CreateIncomeShiftDocumentFromOutcomeShift(XElement source, WarehouseDocument destination)
        {
            //TODO: tutaj powinno byc odczytywanie z MM- jaki jest typ dokumentu lustrzanego
            destination.DocumentTypeId = DictionaryMapper.Instance.GetDocumentType("MM+").Id.Value;

            if (source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("contractorId") != null)
            {
                ContractorMapper contractorMapper = DependencyContainerManager.Container.Get <ContractorMapper>();
                Contractor       contractor       = (Contractor)contractorMapper.CreateNewBusinessObject(BusinessObjectType.Contractor, null);
                contractor.Id          = new Guid(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("contractorId").Value);
                destination.Contractor = contractor;
            }

            destination.Number.FullNumber = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("fullNumber").Value;
            destination.Number.Number     = Convert.ToInt32(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("number").Value, CultureInfo.InvariantCulture);
            destination.Number.SeriesId   = new Guid(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("seriesId").Value);
            destination.Value             = Convert.ToDecimal(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("value").Value, CultureInfo.InvariantCulture);
            destination.DocumentStatus    = DocumentStatus.Saved;

            //set warehouse as destination wh in the source
            Guid whDocumentFieldId = DictionaryMapper.Instance.GetDocumentField(DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId).Id.Value;

            string warehouseId = (from node in source.Element("root").Element("documentAttrValue").Elements()
                                  where node.Element("documentFieldId").Value == whDocumentFieldId.ToUpperString()
                                  select node).ElementAt(0).Element("textValue").Value;

            destination.WarehouseId = new Guid(warehouseId);

            //create attributes
            DocumentAttrValue attr = null;

            var attrs = destination.Attributes.Children.Where(a => a.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId);

            if (attrs.Count() == 1)
            {
                attr = attrs.ElementAt(0);
            }
            else
            {
                attr = destination.Attributes.CreateNew();
                attr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId;
            }

            attr.Value.Value = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("warehouseId").Value;

            attr = destination.Attributes.CreateNew();
            attr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus;
            attr.Value.Value       = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("status").Value;

            attr = destination.Attributes.CreateNew();
            attr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId;
            attr.Value.Value       = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("id").Value;

            DocumentField df = DictionaryMapper.Instance.GetDocumentField(DocumentFieldName.Attribute_IncomeShiftOrderId);

            if (df != null)
            {
                var srcAttr = source.Element("root").Element("documentAttrValue").Elements("entry").Where(e => e.Element("documentFieldId").Value == df.Id.ToUpperString()).FirstOrDefault();

                if (srcAttr != null)
                {
                    attr = destination.Attributes.CreateNew();
                    attr.DocumentFieldName = DocumentFieldName.Attribute_IncomeShiftOrderId;
                    attr.Value.Value       = srcAttr.Element("textValue").Value;
                }
            }
            //

            bool isLocalShift = destination.IsLocalShift();

            if (isLocalShift)
            {
                destination.DocumentStatus = DocumentStatus.Committed;
            }

            //create lines
            foreach (XElement entry in source.Element("root").Element("warehouseDocumentLine").Elements().OrderBy(e => Convert.ToInt32(e.Element("ordinalNumber").Value, CultureInfo.InvariantCulture)))
            {
                WarehouseDocumentLine line = destination.Lines.CreateNew();

                if (!isLocalShift)
                {
                    line.Direction = 0;
                }

                line.ItemId      = new Guid(entry.Element("itemId").Value);
                line.IncomeDate  = DateTime.Parse(entry.Element("outcomeDate").Value, CultureInfo.InvariantCulture);
                line.Quantity    = Convert.ToDecimal(entry.Element("quantity").Value, CultureInfo.InvariantCulture);
                line.Price       = Convert.ToDecimal(entry.Element("price").Value, CultureInfo.InvariantCulture);
                line.Value       = Convert.ToDecimal(entry.Element("value").Value, CultureInfo.InvariantCulture);
                line.UnitId      = new Guid(entry.Element("unitId").Value);
                line.WarehouseId = destination.WarehouseId;
            }
            //
        }