Пример #1
0
        /// <summary>
        /// Loads the <see cref="BusinessObject"/> with a specified Id. It appends modification user name.
        /// </summary>
        /// <param name="type">The type of <see cref="IBusinessObject"/> to load.</param>
        /// <param name="id">The id of the <see cref="IBusinessObject"/> to load.</param>
        /// <returns>Loaded <see cref="BusinessObject"/></returns>
        internal override IBusinessObject LoadBusinessObject(BusinessObjectType type, Guid id)
        {
            Item             result           = (Item)this.MapperTyped.LoadBusinessObject(BusinessObjectType.Item, id);
            ContractorMapper contractorMapper = new ContractorMapper();

            if (result.ModificationUserId.HasValue)
            {
                Contractor modificationUser = contractorMapper.LoadBusinessObject(result.ModificationUserId.Value);
                result.ModificationUser = modificationUser.FullName;
            }

            if (result.CreationUserId.HasValue)
            {
                Contractor creationUser = contractorMapper.LoadBusinessObject(result.CreationUserId.Value);
                result.CreationUser = creationUser.FullName;
            }

            return(result);
        }
Пример #2
0
        private void CreateOrUpdateNegativePayment(FinancialDocument document)
        {
            Guid?payerId = document.DocumentType.FinancialDocumentOptions.PayerId;

            if (payerId == null)
            {
                return;
            }

            Payment negativePayment = document.Payments.Where(p => p.Amount < 0).FirstOrDefault();

            if (negativePayment == null)
            {
                negativePayment = document.Payments.CreateNew(BusinessObjectStatus.New);
                ContractorMapper contractorMapper = DependencyContainerManager.Container.Get <ContractorMapper>();
                Contractor       payer            = (Contractor)contractorMapper.LoadBusinessObject(BusinessObjectType.Contractor, payerId.Value);
                negativePayment.Contractor = payer;
                var addr = payer.Addresses.GetDefaultAddress();

                if (addr != null)
                {
                    negativePayment.ContractorAddressId = addr.Id.Value;
                }

                negativePayment.Direction         = document.Payments[0].Direction;
                negativePayment.PaymentCurrencyId = document.DocumentCurrencyId;
                negativePayment.SystemCurrencyId  = document.SystemCurrencyId;
                negativePayment.ExchangeDate      = document.ExchangeDate;
                negativePayment.ExchangeRate      = document.ExchangeRate;
                negativePayment.ExchangeScale     = document.ExchangeScale;
                negativePayment.Date    = document.IssueDate;
                negativePayment.DueDate = document.IssueDate;
            }

            if (!ConfigurationMapper.Instance.OnePositionFinancialDocuments)
            {
                negativePayment.Description = this.MergeDescriptions(document);
            }
            else
            {
                negativePayment.Description = document.Payments[0].Description;
            }

            string beginning = "Za dokument: ";

            if (negativePayment.Description.StartsWith(beginning))
            {
                negativePayment.Description = negativePayment.Description.Substring(beginning.Length);
            }

            negativePayment.Amount = -document.Payments.Where(pp => pp.Amount > 0).Sum(a => a.Amount);
        }
Пример #3
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;
            }
        }