Пример #1
0
        private void LogPurchaseOrder(PurchaseOrderDocument document)
        {
            var url      = $"{Constants.ServerUrl}/api/resource/Sage 50 Export Log";
            var resource = new Resource(url);

            resource.LogPurchaseOrder(document);
        }
Пример #2
0
        public IRestResponse LogPurchaseOrder(PurchaseOrderDocument document)
        {
            var log = new Log
            {
                document_name = document.Name,
                export_date   = DateTime.Now.ToString("yyyy-MM-dd"),
                document_date = document.TransactionDate.ToString("yyyy-MM-dd"),
                document_type = "Purchase Order"
            };
            var request = new RestRequest(Method.POST);

            request.AddJsonBody(log);
            var response = _restClient.Execute(request);

            return(response);
        }
Пример #3
0
        private PurchaseOrder CreateNewPurchaseOrder(PurchaseOrderDocument purchaseOrderDocument)
        {
            var supplierDocument        = GetSupplierFromErpNext(purchaseOrderDocument.Supplier);
            var supplierEntityReference = GetVendorEntityReference(supplierDocument?.VendorId);
            var purchaseOrder           = Company.Factories.PurchaseOrderFactory.Create();

            if (supplierEntityReference == null)
            {
                Logger.Debug("Supplier {@name} in {@Document} was not found in Sage.", purchaseOrderDocument.Supplier, purchaseOrderDocument.Name);
                purchaseOrder = null;
                SetNext(new CreateSupplierHandler(Company, Logger));
                Logger.Debug("Supplier {@name} has been queued for creation in Sage", purchaseOrderDocument.Supplier);
            }
            else if (purchaseOrder != null)
            {
                try
                {
                    purchaseOrder.Date            = purchaseOrderDocument.TransactionDate;
                    purchaseOrder.GoodThroughDate = purchaseOrderDocument.ScheduleDate;
                    purchaseOrder.ReferenceNumber = purchaseOrderDocument.Name;
                    // purchaseOrder.VendorReference = VendorReferences[purchaseOrderDocument.Supplier];
                    purchaseOrder.VendorReference  = supplierEntityReference;
                    purchaseOrder.TermsDescription = purchaseOrderDocument.PaymentTermsTemplate;
                    purchaseOrder.ShipVia          = purchaseOrderDocument.ShipMethod;

                    foreach (var line in purchaseOrderDocument.Items)
                    {
                        AddLine(purchaseOrder, line);
                    }

                    purchaseOrder.Save();
                    Logger.Information("Purchase Order - {PurchaseOrderDocument} saved successfully", purchaseOrderDocument.Name);
                }
                catch (KeyNotFoundException)
                {
                    purchaseOrder = null;
                    Logger.Debug("Vendor {@Name} in {@Document} was not found", purchaseOrderDocument.Supplier, purchaseOrderDocument.Name);
                    SetNext(new CreateSupplierHandler(Company, Logger));
                    Logger.Debug("Customer {@name} has been queued for creation in Sage", purchaseOrderDocument.Supplier);
                }
                catch (Sage.Peachtree.API.Exceptions.ValidationException e)
                {
                    Logger.Debug("Validation failed.");
                    Logger.Debug(e.Message);
                    Logger.Debug("{@Name} will be sent back to the queue", purchaseOrderDocument.Name);
                    purchaseOrder = null;
                }
                catch (Sage.Peachtree.API.Exceptions.RecordInUseException)
                {
                    purchaseOrder = null;
                    Logger.Debug("Record is in use. {@Name} will be sent back to the queue", purchaseOrderDocument.Name);
                }
                catch (Exception e)
                {
                    purchaseOrder = null;
                    Logger.Debug(e, e.Message);
                    Logger.Debug("{@E}", e);
                }
            }
            return(purchaseOrder);
        }