Exemple #1
0
        public override List <ulong> ParseAddressIds(MySqlConnection connection, ulong supplierId, string archFileName, string currentFileName)
        {
            string supplierDeliveryId;

            try {
                supplierDeliveryId = Path.GetFileName(currentFileName).Split('_')[0];
            }
            catch (Exception ex) {
                throw new Exception("Не получилось сформировать код доставки из имени файла накладной.", ex);
            }

            return(AddressIdQuery.GetAddressIds(supplierId, supplierDeliveryId));
        }
        public override List <ulong> ParseAddressIds(MySqlConnection connection, ulong supplierId, string archFileName, string currentFileName)
        {
            string firmClientCode;

            try {
                firmClientCode = Path.GetFileName(currentFileName).Split('_')[0];
            }
            catch (Exception ex) {
                throw new Exception("Не получилось сформировать SupplierDeliveryId(FirmClientCode2) из имени накладной.", ex);
            }

            var list = AddressIdQuery.GetAddressIds(supplierId, firmClientCode);

            if (list.Count == 0)
            {
                throw new Exception("Не удалось найти клиентов с SupplierClientId(FirmClientCode) = " + firmClientCode + ".");
            }

            return(list);
        }
        public override List <ulong> ParseAddressIds(MySqlConnection connection, ulong supplierId, string archFileName, string currentFileName)
        {
            var list = new List <ulong>();

            string SQL = AddressIdQuery.SqlGetClientAddressId(true, true);

            string FirmClientCode, DeliveryCode;

            try {
                var dsWaybill = new DataSet();
                dsWaybill.ReadXml(currentFileName);
                DataTable dtCounteragent = dsWaybill.Tables["Контрагент"];
                FirmClientCode = dtCounteragent.Select("Роль = 'Плательщик'")[0]["Ид"].ToString();
                DeliveryCode   = dtCounteragent.Select("Роль = 'Получатель'")[0]["Ид"].ToString();
            }
            catch (Exception ex) {
                throw new Exception("Не получилось сформировать SupplierClientId(FirmClientCode) и SupplierDeliveryId(FirmClientCode2) из документа.", ex);
            }

            DataSet ds = MySqlHelper.ExecuteDataset(
                connection,
                SQL,
                new MySqlParameter("?SupplierId", supplierId),
                new MySqlParameter("?SupplierClientId", FirmClientCode),
                new MySqlParameter("?SupplierDeliveryId", DeliveryCode));

            foreach (DataRow drApteka in ds.Tables[0].Rows)
            {
                list.Add(Convert.ToUInt64(drApteka["AddressId"]));
            }

            if (list.Count == 0)
            {
                throw new Exception("Не удалось найти клиентов с SupplierClientId(FirmClientCode) = " + FirmClientCode +
                                    " и SupplierDeliveryId(FirmClientCode2) = " + DeliveryCode + ".");
            }

            return(list);
        }
        public override List <ulong> ParseAddressIds(MySqlConnection Connection, ulong FirmCode, string ArchFileName, string CurrentFileName)
        {
            var list = new List <ulong>();

            var SQL = AddressIdQuery.SqlGetClientAddressId(true, true);

            string FirmClientCode, DeliveryCode;

            try {
                string[] parts = Path.GetFileNameWithoutExtension(CurrentFileName).Split('_');
                FirmClientCode = parts[0];
                DeliveryCode   = parts[1];
            }
            catch (Exception ex) {
                throw new Exception("Не получилось сформировать SupplierClientId(FirmClientCode) и SupplierDeliveryId(FirmClientCode2) из документа.", ex);
            }

            var ds = MySqlHelper.ExecuteDataset(
                Connection,
                SQL,
                new MySqlParameter("?SupplierId", FirmCode),
                new MySqlParameter("?SupplierClientId", FirmClientCode),
                new MySqlParameter("?SupplierDeliveryId", DeliveryCode));

            foreach (DataRow drApteka in ds.Tables[0].Rows)
            {
                list.Add(Convert.ToUInt64(drApteka["AddressId"]));
            }

            if (list.Count == 0)
            {
                throw new Exception("Не удалось найти клиентов с SupplierClientId(FirmClientCode) = " + FirmClientCode +
                                    " и SupplierDeliveryId(FirmClientCode2) = " + DeliveryCode + ".");
            }

            return(list);
        }
        public Document ToDocument(blading blading, ProtekServiceConfig config)
        {
            Dump(ConfigurationManager.AppSettings["DebugProtekPath"], blading);

            var      order    = GetOrder(blading);
            Supplier supplier = null;
            Address  address  = null;

            if (order != null)
            {
                supplier = order.Price.Supplier;
                address  = order.Address;
            }
            else if (!String.IsNullOrEmpty(blading.recipientId.ToString()))
            {
                var query = new AddressIdQuery(config.SupplierId, false)
                {
                    SupplierDeliveryId = blading.recipientId.ToString(),
                };
                var addressIds = query.Query();
                if (addressIds.Count > 0)
                {
                    supplier = Supplier.Find(config.SupplierId);
                    address  = Address.Find(addressIds.First());
                }
            }

            if (address == null)
            {
                _logger.WarnFormat("Для накладной {0}({1}) не удалось определить получателя код клиента {2} код доставки {3}",
                                   blading.bladingId,
                                   blading.baseId,
                                   blading.payerId,
                                   blading.recipientId);
                return(null);
            }

            var log = new DocumentReceiveLog(supplier, address, DocType.Waybill)
            {
                IsFake  = true,
                Comment = "Получен через сервис Протек"
            };

            var document = new Document(log, "ProtekHandler")
            {
                OrderId            = order?.Id,
                ProviderDocumentId = blading.baseId,
                DocumentDate       = blading.date0,
            };

            document.SetInvoice();
            var invoice = document.Invoice;

            invoice.InvoiceDate             = blading.date0;
            invoice.InvoiceNumber           = blading.baseId;
            invoice.SellerName              = blading.protekNameAddr;
            invoice.SellerINN               = blading.protekInnKpp;
            invoice.ShipperInfo             = blading.protekAddr;
            invoice.RecipientId             = blading.recipientId;
            invoice.RecipientName           = blading.recipientName;
            invoice.RecipientAddress        = blading.recipientAddr;
            invoice.PaymentDocumentInfo     = blading.baseId;
            invoice.BuyerId                 = blading.payerId;
            invoice.BuyerName               = blading.payerName;
            invoice.BuyerINN                = blading.payerInn;
            invoice.CommissionFee           = (decimal?)blading.ksMin;
            invoice.CommissionFeeContractId = blading.ncontr2;
            invoice.AmountWithoutNDS        = (decimal?)blading.sumbyWonds;
            invoice.AmountWithoutNDS10      = (decimal?)blading.sumbyNdsrate10;
            invoice.NDSAmount10             = (decimal?)blading.nds10;
            invoice.AmountWithoutNDS18      = (decimal?)blading.sumbyNdsrate18;
            invoice.NDSAmount18             = (decimal?)blading.nds20;
            invoice.Amount = (decimal?)blading.rprice;
            invoice.DelayOfPaymentInBankDays = blading.dbd;
            invoice.DelayOfPaymentInDays     = blading.dkd;

            foreach (var bladingItem in blading.bladingItems)
            {
                var line = document.NewLine();
                line.Code     = bladingItem.itemId.ToString();
                line.Product  = bladingItem.itemName;
                line.Producer = bladingItem.manufacturerName;
                line.Quantity = (uint?)bladingItem.bitemQty;
                line.Country  = bladingItem.country;

                line.ExpireInMonths    = bladingItem.expiry;
                line.Period            = bladingItem.prodexpiry?.ToShortDateString();
                line.DateOfManufacture = bladingItem.proddt;

                line.RegistryCost = (decimal?)bladingItem.reestrPrice;
                line.RegistryDate = bladingItem.reestrDate;

                line.SupplierPriceMarkup = (decimal?)bladingItem.distrProc;
                line.NdsAmount           = (decimal?)bladingItem.sumVat;
                line.Nds = (uint?)bladingItem.vat;
                line.SupplierCostWithoutNDS = (decimal?)bladingItem.distrPriceWonds;
                line.SupplierCost           = (decimal?)bladingItem.distrPriceNds;
                line.ProducerCostWithoutNDS = (decimal?)bladingItem.prodPriceWonds;
                line.VitallyImportant       = bladingItem.vitalMed != null && bladingItem.vitalMed.Value == 1;
                line.Amount            = (decimal?)bladingItem.positionsum;
                line.SerialNumber      = bladingItem.prodseria;
                line.EAN13             = NullableConvert.ToUInt64(bladingItem.prodsbar);
                line.CountryCode       = bladingItem.countryCode;
                line.BillOfEntryNumber = bladingItem.gtdn;
                line.UnitCode          = bladingItem.cvpItemOkei.ToString();
                if (bladingItem.bladingItemSeries != null)
                {
                    var certificates = bladingItem.bladingItemSeries
                                       .Where(s => s.bladingItemSeriesCertificates != null)
                                       .SelectMany(s => s.bladingItemSeriesCertificates)
                                       .Where(c => c != null);

                    line.ProtekDocIds = certificates
                                        .Select(c => c.docId)
                                        .Where(id => id != null)
                                        .Select(id => new ProtekDoc(line, id.Value))
                                        .ToList();

                    line.Certificates         = certificates.FirstOrDefault()?.regNo;
                    line.CertificateAuthority = certificates.FirstOrDefault()?.regOrg;
                    line.CertificatesDate     = certificates.FirstOrDefault()?.regd?.ToString();
                    line.CertificatesEndDate  = certificates.FirstOrDefault()?.dateExpire;
                }
            }

            return(document);
        }