Ejemplo n.º 1
0
        public async Task <SageOrderResponse> CreateSalesOrder(Hub.Models.SalesOrder so)
        {
            SageOrderResponse result = new SageOrderResponse();

            try
            {
                Dictionary <string, string> SystemKeys = new Dictionary <string, string>();

                SystemKeys = await _data.GetDBLoginDetails(_config.DatelSystemID);

                if (SystemKeys.Count == 0)
                {
                    _logger.Log("Error: Unable to find System Keys");
                    result.OrderPlaced  = false;
                    result.ErrorMessage = "Unable to find System Keys";
                    return(result);
                }


                FusionSDK.SalesOrder salesAPI = new FusionSDK.SalesOrder();
                salesAPI.setSQL(SystemKeys["dbServer"], SystemKeys["dbName"], SystemKeys["dbLogin"], SystemKeys["dbPassword"]);
                salesAPI.setDeveloperDebuggingMode(_config.SageLogging);
                salesAPI.setSchema(SystemKeys["dbScheme"]);
                salesAPI.setOrderPrefix(SystemKeys["orderPrefix"].Trim().ToUpper());

                salesAPI.setSalesOrderTrackingUser(SystemKeys["dbLogin"].Substring(0, 8));

                salesAPI.setAuditFile(Convert.ToBoolean(SystemKeys["auditMode"]));

                salesAPI.setHeaderValueString("customer_order_no", so.CustomerRef.ID);

                salesAPI.setHeaderValueString("lang", so.Delivery.DelAddr.DelCountry.Name);

                salesAPI.setHeaderValueString("transaction_anals1", so.Delivery.DelParty.EndPoint);

                salesAPI.setHeaderValueString("transaction_anals3", so.Delivery.DelParty.Logo);

                if (!String.IsNullOrEmpty(so.additionalData.alpha))
                {
                    salesAPI.setHeaderValueString("alpha", so.additionalData.alpha);
                }
                if (so.Delivery.DelParty.DelContact.Tel != "")
                {
                    salesAPI.setHeaderValueString("shipping_text", so.Delivery.DelParty.DelContact.Tel);
                }
                foreach (var line in so.OrderLines)
                {
                    salesAPI.addGoodsLineWithPrices(line.Item.ItemData.Warehouse, line.Item.ItemData.SKU, Convert.ToDouble(line.Item.Qty), line.Item.ItemData.ListPrice
                                                    , line.Item.ItemData.NetPrice, line.Item.ItemData.Discount, line.Item.ItemData.DiscountAllowed);

                    //salesAPI.setDetailValueString("packaging", JavaCast('string', arguments.accessories[k].pairid));
                    salesAPI.setDetailValueString("transaction_anals3", so.Delivery.DelParty.Logo);
                }
                foreach (var comment in so.additionalData.Comments)
                {
                    salesAPI.addCommentLine(comment.Type, comment.Text);
                }
                foreach (var service in so.additionalData.ServiceLines)
                {
                    salesAPI.addServiceLineWithPrices(service.Item.ItemData.SKU, Convert.ToDouble(service.Item.Qty), service.Item.ItemData.ListPrice, service.Item.ItemData.NetPrice
                                                      , service.Item.ItemData.Discount, service.Item.ItemData.DiscountAllowed);
                    salesAPI.setDetailValueString("long_description", service.Item.ItemData.Description);
                }

                salesAPI.addServiceLineWithPrices(so.DelTerms.DelCode, 1, 0, 0, 0, false);

                salesAPI.setHeaderValueString("address1", so.Address.ContactName);
                salesAPI.setHeaderValueString("address2", so.Address.Address1);
                salesAPI.setHeaderValueString("address3", so.Address.Address2);
                salesAPI.setHeaderValueString("address4", so.Address.City);
                salesAPI.setHeaderValueString("address5", so.Address.PostCode);

                salesAPI.setHeaderValueString("delivery_method", so.additionalData.DeliveryMethod);

                salesAPI.setHeaderValueString("hold_indicator", so.additionalData.hold_indicator);

                salesAPI.setHeaderValueString("date_entered", DateTime.Now.ToString("yyyy-MM-dd"));
                salesAPI.setHeaderValueString("date_received", DateTime.Now.ToString("yyyy-MM-dd"));

                string SageOrderRef = "";
                string ErrorDesc    = "";
                if (salesAPI.submitOrder(so.additionalData.CustomerID))
                {
                    SageOrderRef       = salesAPI.getOrderNumber();
                    result.OrderRef    = SageOrderRef;
                    result.OrderPlaced = true;

                    _logger.Log($"Sales Order creation successful: {SageOrderRef}");
                }
                else
                {
                    ErrorDesc = $"ErrorCode: {salesAPI.getLastErrorCode()}. ErrorMessage: {salesAPI.getLastErrorMessage()}. SQLError: {salesAPI.getLastSQLErrorCode()} ";

                    result.ErrorMessage = ErrorDesc;
                    _logger.Log($"Error: Sales Order creation failed: {so.CustomerRef.ID}. {ErrorDesc} ");
                    return(result);
                }

                if (SageOrderRef != "")
                {
                    if (await _data.StockAllocateAllowed(SageOrderRef))
                    {
                        OrderAllocation allocation = new OrderAllocation();

                        allocation.setSQL(SystemKeys["dbServer"], SystemKeys["dbName"], SystemKeys["dbLogin"], SystemKeys["dbPassword"]);
                        allocation.setDeveloperDebuggingMode(_config.SageLogging);
                        allocation.setSchema(SystemKeys["dbScheme"]);
                        allocation.allowSplitToBackOrder(so.additionalData.AllowBackOrder);
                        allocation.setSoftAllocationOnly(Convert.ToBoolean(SystemKeys["softAllocationOnly"]));
                        allocation.setSalesOrderTrackingUser(SystemKeys["dbLogin"].Substring(0, 8));
                        allocation.setAuditFile(Convert.ToBoolean(SystemKeys["auditMode"]));

                        result.StockAllocated = allocation.doAllocation(SageOrderRef);

                        if (!result.StockAllocated)
                        {
                            result.ErrorMessage = allocation.getLastErrorMessage();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.OrderPlaced  = false;
                result.ErrorMessage = ex.Message;
                _logger.Log(ex);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <SageOrderResponse> CreatePurchaseOrder(Hub.Models.PurchaseOrder po)
        {
            SageOrderResponse result = new SageOrderResponse();

            result.ErrorCode = "0";

            result.OrderPlaced = false;
            try
            {
                _logger.Log("Inside PurchaseOrder");

                result.ErrorCode = "-1";

                Dictionary <string, string> SystemKeys = new Dictionary <string, string>();
                SystemKeys = await _data.GetDBLoginDetails(_config.DatelSystemID);

                result.ErrorCode = "-2";
                if (SystemKeys.Count == 0)
                {
                    _logger.Error("Error: Unable to find System Keys");
                    return(result);
                }

                result.ErrorCode = "-3";
                FusionSDK.PurchaseOrder poAPI = new FusionSDK.PurchaseOrder();
                result.ErrorCode = "-4";
                poAPI.setSQL(SystemKeys["dbServer"], SystemKeys["dbName"], SystemKeys["dbLogin"], SystemKeys["dbPassword"]);
                poAPI.setDeveloperDebuggingMode(_config.SageLogging);
                poAPI.setSchema(SystemKeys["dbScheme"]);


                poAPI.setHeaderValueString("supplier_ref", po.CustomerRef.ID);

                poAPI.setHeaderValueString("status", "P");
                poAPI.setHeaderValueString("supplier", po.additionalData.Supplier);
                poAPI.setHeaderValueString("address1", po.Seller.Password);
                poAPI.setHeaderValueString("pl_company", SystemKeys["dbName"]);
                poAPI.setHeaderValueString("exchange_rate", "0");
                poAPI.setHeaderValueString("vat_type", "V");

                foreach (var line in po.OrderLines)
                {
                    poAPI.addGoodsLineValue(line.Item.ItemData.Warehouse, line.Item.ItemData.SKU, Convert.ToDouble(line.Item.Qty), line.Item.ItemData.ListPrice);
                    if (!String.IsNullOrEmpty(line.Item.Delivery.DeliveryDateValue))
                    {
                        poAPI.setDetailValueString("date_required", line.Item.Delivery.DeliveryDateValue);
                    }
                    /*Serials */
                    //for (m = 1; m lte ArrayLen(arguments.accessories[k].serial); m = m + 1)
                    //{
                    //po.addCommentLine(trim(arguments.accessories[k].serial[m].type), trim(arguments.accessories[k].serial[m].value));
                    //}
                }

                foreach (var comment in po.additionalData.Comments)
                {
                    poAPI.addCommentLine(comment.Type, comment.Text);
                }

                poAPI.setHeaderValueString("delivery_address1", po.Address.ContactName);
                poAPI.setHeaderValueString("delivery_address2", po.Address.Address1);
                poAPI.setHeaderValueString("delivery_address3", po.Address.Address2);
                poAPI.setHeaderValueString("delivery_address4", po.Address.City);
                poAPI.setHeaderValueString("delivery_address5", po.Address.PostCode);

                string SageOrderRef = "";
                string ErrorDesc    = "";

                result.ErrorCode = "1";

                if (poAPI.submitOrder(po.additionalData.Supplier))
                {
                    result.ErrorCode   = "2";
                    SageOrderRef       = poAPI.getOrderNumber();
                    result.ErrorCode   = "3";
                    result.OrderRef    = SageOrderRef;
                    result.OrderPlaced = true;
                    result.ErrorCode   = "4";
                    _logger.Log($"Purchase Order creation successful: {SageOrderRef}");
                }
                else
                {
                    ErrorDesc = $"ErrorCode: {poAPI.getLastErrorCode()}. ErrorMessage: {poAPI.getLastErrorMessage()}. SQLError: {poAPI.getLastSQLErrorCode()} ";

                    result.ErrorMessage = ErrorDesc;
                    _logger.Log($"Error: Purchase Order creation failed: {po.CustomerRef.ID}. {ErrorDesc} ");
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                result.ErrorMessage = ex.Message;
                throw ex;
            }
            return(result);
        }