示例#1
0
        public void Run(string customDataJson)
        {
            m_log.Info("Zacinam zpracovani dobirek a plateb z Pay Pal");

            var toBePaid = new List <IPurchaseOrder>();

            AddPayOnDeliveryOrders(toBePaid);
            AddOrdersToBeSetPaidByMapping(toBePaid);
            AddOrdersToBePaidByPaymentMethod(toBePaid);

            foreach (var order in toBePaid.Distinct(new PropEqualityComparer <IPurchaseOrder>(o => o.Id)))
            {
                try
                {
                    var podText = order.IsPayOnDelivery ? "DOBIRKA" : string.Empty;

                    m_log.Info(
                        $"Nastavuji objednavku {order.OrderNumber} '{order.ErpStatusName}' {podText} PayMethod='{order.PaymentMethodName}' jako zaplacenou");
                    m_ordersFacade.SetOrderPaid(order.Id, null);
                    m_log.Info($"Objednavka {order.OrderNumber} '{order.ErpStatusName}' {podText} nastavena OK");
                }
                catch (Exception ex)
                {
                    m_log.Error($"Pokus o nastaveni objednavky {order.Erp.Description}:{order.OrderNumber} jako 'Zaplaceno' selhal", ex);
                }
            }
        }
示例#2
0
        public IEnumerable <SuggestedPairModel> Pair(int orderId, long paymentId)
        {
            m_ordersFacade.SetOrderPaid(orderId, paymentId);

            return(GetUnpaidOrders());
        }
示例#3
0
        public void Run(string customDataJson)
        {
            m_log.Info("Zacinam job \"Parovani objednavek\"");
            DownloadPayments();

            m_log.Info("Hledam objednavky cekajici na platbu");
            var ordersToBePaired =
                m_orderRepository.GetOrdersByStatus(OrderStatus.PendingPayment).Where(o => !o.IsPayOnDelivery).ToList();

            m_log.Info($"Nalezeno {ordersToBePaired.Count} zaznamu");

            if (ordersToBePaired.Count == 0)
            {
                m_log.Info("Zadne objednavky k parovani");
                return;
            }

            var minDt = ordersToBePaired.Min(o => o.PurchaseDate);

            m_paymentRepository.PreloadCache(minDt.AddDays(-1), DateTime.Now);

            foreach (var order in ordersToBePaired)
            {
                m_log.Info($"Zacinam parovat objednavku OrderNo={order.OrderNumber} OrderId={order.Id}");
                try
                {
                    if (string.IsNullOrWhiteSpace(order.VarSymbol))
                    {
                        throw new InvalidOperationException($"Objednavka {order.OrderNumber} ze systemu {order.Erp?.Description} nema variabilni symbol");
                    }

                    m_log.Info($"Hledam platbu k objednavce {order.OrderNumber} podle VS={order.VarSymbol}");

                    var payments = m_paymentRepository.GetPaymentsByVarSymb(order.VarSymbol).Where(p => p.Orders == null || !p.Orders.Any()).ToList();
                    if (!payments.Any())
                    {
                        m_log.Info("Platba nenalezena");
                        continue;
                    }

                    if (payments.Count > 1)
                    {
                        m_log.Info($"Existuje vice nez jedna platba VS={order.VarSymbol}. Nelze parovat.");
                        continue;
                    }

                    var payment = payments.First();

                    m_log.Info($"Platba k objednavce {order.OrderNumber} nalezena, paruji...");

                    //TODO currencies
                    if (Math.Abs(payment.Value - order.PriceWithVat) > 0.01m)
                    {
                        m_log.Info("Neshoduje se castka, nelze parovat");
                        continue;
                    }

                    m_orders.SetOrderPaid(order.Id, payment.Id);

                    m_log.Info($"Sparovano: Objednavka OrderNo={order.OrderNumber} OrderId={order.Id}");
                }
                catch (Exception ex)
                {
                    m_log.Error("Chyba:", ex);
                }
            }
        }