Пример #1
0
        public static void CreateCorrectiveDocument(XElement source, CommercialDocument destination)
        {
            Guid           sourceDocumentId = new Guid(source.Element("correctedDocumentId").Value);
            DocumentMapper mapper           = DependencyContainerManager.Container.Get <DocumentMapper>();

            ICollection <Guid> previousDocumentsId = mapper.GetCommercialCorrectiveDocumentsId(sourceDocumentId);

            CommercialDocument sourceDocument = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, sourceDocumentId);

            CommercialDocument lastDoc = sourceDocument;

            foreach (Guid corrId in previousDocumentsId)
            {
                CommercialDocument correctiveDoc = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, corrId);

                CommercialCorrectiveDocumentFactory.RelateTwoCorrectiveDocuments(lastDoc, correctiveDoc, true);

                lastDoc = correctiveDoc;
            }

            CommercialCorrectiveDocumentFactory.CalculateDocumentsAfterCorrection(lastDoc);
            CommercialCorrectiveDocumentFactory.CreateNextCorrectiveDocument(lastDoc, destination);
            DuplicableAttributeFactory.DuplicateAttributes(lastDoc, destination);

            var salesOrderRelation = sourceDocument.Relations.Where(r => r.RelationType == DocumentRelationType.SalesOrderToInvoice).FirstOrDefault();

            if (salesOrderRelation != null)             //dokument jest do ZS wiec korekte tez tam podpinamy
            {
                var relation = destination.Relations.CreateNew();
                relation.RelationType    = DocumentRelationType.SalesOrderToCorrectiveCommercialDocument;
                relation.RelatedDocument = salesOrderRelation.RelatedDocument;
            }
        }
Пример #2
0
        private static void CalculateLineAfterCorrection(CommercialDocumentLine line)
        {
            if (line.CorrectedLine != null)
            {
                CommercialDocument parent = (CommercialDocument)line.Parent;

                //if the corrected line is in the same document so it already has been corrected so dont do it again
                if (parent.Lines.Children.Where(l => l.Id.Value == line.CorrectedLine.Id.Value).FirstOrDefault() == null)
                {
                    CommercialCorrectiveDocumentFactory.CalculateLineAfterCorrection(line.CorrectedLine);
                }

                line.DiscountGrossValue += line.CorrectedLine.DiscountGrossValue;
                line.DiscountNetValue   += line.CorrectedLine.DiscountNetValue;
                line.DiscountRate       += line.CorrectedLine.DiscountRate;
                line.GrossPrice         += line.CorrectedLine.GrossPrice;
                line.GrossValue         += line.CorrectedLine.GrossValue;
                line.InitialGrossPrice  += line.CorrectedLine.InitialGrossPrice;
                line.InitialGrossValue  += line.CorrectedLine.InitialGrossValue;
                line.InitialNetPrice    += line.CorrectedLine.InitialNetPrice;
                line.InitialNetValue    += line.CorrectedLine.InitialNetValue;
                line.NetPrice           += line.CorrectedLine.NetPrice;
                line.NetValue           += line.CorrectedLine.NetValue;
                line.VatValue           += line.CorrectedLine.VatValue;
                line.Quantity           += line.CorrectedLine.Quantity;
            }
        }
Пример #3
0
        public static void CalculateDocumentsAfterCorrection(CommercialDocument lastCorrectiveDocument)
        {
            foreach (CommercialDocumentLine line in lastCorrectiveDocument.Lines.Children)
            {
                CommercialCorrectiveDocumentFactory.CalculateLineAfterCorrection(line);
            }

            CommercialCorrectiveDocumentFactory.CalculateHeaderAndVatTableAfterCorrection(lastCorrectiveDocument);
        }
Пример #4
0
        private static void CalculateHeaderAndVatTableAfterCorrection(CommercialDocument document)
        {
            CommercialDocumentLine firstLine = document.Lines.Children.First();

            if (firstLine.CorrectedLine != null)
            {
                CommercialDocument previousDoc = (CommercialDocument)firstLine.CorrectedLine.Parent;
                CommercialCorrectiveDocumentFactory.CalculateHeaderAndVatTableAfterCorrection(previousDoc);

                decimal netValue   = previousDoc.NetValue;
                decimal grossValue = previousDoc.GrossValue;
                decimal vatValue   = previousDoc.VatValue;

                if (previousDoc.IsSettlementDocument)
                {
                    netValue   = previousDoc.VatTableEntries.Where(ss => ss.NetValue > 0 && ss.GrossValue > 0 && ss.VatValue > 0).Sum(s => s.NetValue);
                    grossValue = previousDoc.VatTableEntries.Where(ss => ss.NetValue > 0 && ss.GrossValue > 0 && ss.VatValue > 0).Sum(s => s.GrossValue);
                    vatValue   = previousDoc.VatTableEntries.Where(ss => ss.NetValue > 0 && ss.GrossValue > 0 && ss.VatValue > 0).Sum(s => s.VatValue);
                }

                document.NetValue   += netValue;
                document.GrossValue += grossValue;
                document.VatValue   += vatValue;

                foreach (CommercialDocumentVatTableEntry vtEntry in previousDoc.VatTableEntries.Children)
                {
                    if (previousDoc.IsSettlementDocument && (vtEntry.NetValue < 0 || vtEntry.GrossValue < 0 || vtEntry.VatValue < 0))
                    {
                        continue;
                    }

                    CommercialDocumentVatTableEntry currentVtEntry = document.VatTableEntries.Children.Where(v => v.VatRateId == vtEntry.VatRateId).FirstOrDefault();

                    if (currentVtEntry != null)
                    {
                        currentVtEntry.GrossValue += vtEntry.GrossValue;
                        currentVtEntry.NetValue   += vtEntry.NetValue;
                        currentVtEntry.VatValue   += vtEntry.VatValue;
                    }
                }
            }
        }