Exemplo n.º 1
0
        public Invoice Map(InvoiceXml dto)
        {
            var entity = EntityFactory.Create <Invoice>();

            if (dto.ZagolovokDokumenta != null)
            {
                var header = dto.ZagolovokDokumenta;
                entity.Guid = dto.Identifikator;
                //header.TipDok
                entity.Code              = header.NomerDok;
                entity.DocDateTime       = header.DataDok;
                entity.ShipmentDateTime  = header.DataOtgruzki;
                entity.Supplier          = FindOrCreate <Organization>(header.Postavshhik);
                entity.Receiver          = FindOrCreate <Organization>(header.Poluchatel);
                entity.Consignee         = FindOrCreate <Organization>(header.Gruzopoluchatel);
                entity.PaymentConditions = header.UslovijaOplaty;
                entity.ProductGroup      = header.TovarnajaGruppa;
                //header.Pozicij
                //entity.SupplierPrice = header.SummaOpt;
                //entity.ValueAddedTaxAmount = header.SummaNDS;
                //invoice.TotalPrice = header.SummaOptVklNDS;
                entity.Note = header.Primechanie;
                if (entity.Supplier != null && header.RekvizityPostavshhika != null)
                {
                    var postavshik = header.RekvizityPostavshhika;
                    var city       = FindOrCreate <City>(postavshik.Gorod);
                    if (city != null)
                    {
                        entity.Supplier.Address      = EntityFactory.Create <Address>();
                        entity.Supplier.Address.City = city;
                    }
                    if (!String.IsNullOrWhiteSpace(postavshik.Adres))
                    {
                        if (entity.Supplier.Address == null)
                        {
                            entity.Supplier.Address = EntityFactory.Create <Address>();
                        }
                        entity.Supplier.Address.Description = postavshik.Adres;
                    }
                    entity.Supplier.TaxpayerCode = postavshik.INN;
                    entity.Supplier.PhoneNumber  = postavshik.Telefony;
                    entity.Supplier.Email        = postavshik.JelPochta;
                    entity.SupplierBankAccount   = FindOrCreateBankAccount(entity.Supplier,
                                                                           postavshik.BIK, postavshik.Bank, postavshik.OtdelenieBanka,
                                                                           postavshik.KorSchet, postavshik.RaschetnyjSchet);
                }
            }
            if (dto.TovarnyePozicii != null)
            {
                entity.Items.AddRange(dto.TovarnyePozicii.Select(Map));
            }
            return(entity);
        }
Exemplo n.º 2
0
        public IActionResult Create(InvoiceXml invoiceXml)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var mapper = new InvoiceXmlMapper(new EntityFactory(_context));
            var entity = mapper.Map(invoiceXml);

            OnCreating(entity);
            _context.Set <Invoice>().Add(entity);
            _context.SaveChanges();
            //return CreatedAtAction(nameof(GetByGuid), new { guid = entity.Guid }, entity);
            return(Ok());
        }
Exemplo n.º 3
0
        public InvoiceXml Map(Invoice entity)
        {
            var dto = new InvoiceXml
            {
                Identifikator      = entity.Guid,
                ZagolovokDokumenta = new InvoiceXmlHeader
                {
                    TipDok          = "ПРХ",
                    NomerDok        = entity.Code,
                    DataDok         = entity.DocDateTime,
                    DataOtgruzki    = entity.ShipmentDateTime,
                    Postavshhik     = entity.Supplier?.Name,
                    Poluchatel      = entity.Receiver?.Name,
                    Gruzopoluchatel = entity.Consignee?.Name,
                    UslovijaOplaty  = entity.PaymentConditions,
                    TovarnajaGruppa = entity.ProductGroup,
                    Pozicij         = entity.ItemCount,
                    SummaOpt        = entity.SupplierPrice,
                    SummaNDS        = entity.ValueAddedTaxAmount,
                    SummaOptVklNDS  = entity.TotalPrice,
                    Primechanie     = entity.Note
                }
            };

            if (entity.Supplier != null)
            {
                dto.ZagolovokDokumenta.RekvizityPostavshhika = new InvoiceXmlSupplier()
                {
                    Adres           = entity.Supplier.Address?.Description,
                    INN             = entity.Supplier.TaxpayerCode,
                    Telefony        = entity.Supplier.PhoneNumber,
                    RaschetnyjSchet = entity.SupplierBankAccount?.CheckingAccount,
                    Gorod           = entity.Supplier.Address?.City?.Name,
                    Bank            = entity.SupplierBankAccount?.BankName,
                    OtdelenieBanka  = entity.SupplierBankAccount?.BankBranchName,
                    BIK             = entity.SupplierBankAccount?.BankCode,
                    KorSchet        = entity.SupplierBankAccount?.CorrespondentAccount,
                    JelPochta       = entity.Supplier.Email,
                };
            }
            dto.TovarnyePozicii = new List <InvoiceXmlItem>(entity.Items.Select(Map));
            return(dto);
        }