Example #1
0
        public async Task <CreateResult> Cin7SalesOrderRequest(Domain.Models.Orders.Order order)
        {
            var api         = new Cin7Api(new ApiUser("StationeryinMotionSA", "1251ada5191046238405f5a66ebbac8f"));
            var createdDate = order.Created;

            var sale = new Cin7ApiWrapper.Models.SalesOrder()
            {
                CreatedDate        = order.Created,
                ModifiedDate       = DateTime.UtcNow,
                CurrencyCode       = "ZAR",
                CurrencySymbol     = "R",
                TaxStatus          = TaxStatus.Excl,
                TaxRate            = 0.14m,
                Total              = order.OrderProducts.Sum(x => x.Qty * x.Product.Price) ?? 0,
                FirstName          = order.User.FirstName,
                LastName           = order.User.LastName,
                Company            = order.Account.CompanyName,
                Email              = order.User.Email,
                Phone              = order.User.PhoneNumber,
                CustomerOrderNo    = order.OrderNumber,
                IsApproved         = (order.Status == Domain.Enums.OrderStatus.Complete) ? true : false,
                MemberEmail        = order.User.Email,
                DeliveryAddress1   = order.Address.Address1,
                DeliveryAddress2   = order.Address.Address2,
                DeliveryCity       = order.Address.City,
                DeliveryPostalCode = order.Address.PostCode,
                //MemberCostCenter = order.Address.
                ProductTotal = order.OrderProducts.Sum(x => x.Qty * x.Product.Price) ?? 0,
                //LineItems = order.OrderProducts. add products to this array
                LineItems        = getLineItems(order).ToArray(),
                InternalComments = "DO NOT PROCESS, NEW SITE TESTS"
            };

            CreateResult result = api.SalesOrders.Create(sale);

            return(result);
        }
Example #2
0
        public async Task <CreateResult> DoCin7Req(string id)
        {
            //make connection to CIN7
            var api = new Cin7Api(new ApiUser("StationeryinMotionSA", "1251ada5191046238405f5a66ebbac8f"));

            //Get Order
            var order = _ctx.Orders
                        .Include(x => x.OrderProducts)

                        .Include(x => x.Account)
                        .ThenInclude(x => x.Locations)
                        .Include(x => x.Address)
                        .Include(x => x.User)
                        .FirstOrDefault(x => x.OrderNumber == id);

            if (order.Account == null)
            {
                order = _ctx.Orders
                        .Include(x => x.OrderProducts)
                        .Include(x => x.Address)
                        .Include(x => x.User)
                        .FirstOrDefault(x => x.OrderNumber == id);
            }

            var products = _ctx.Products;

            Cin7ApiWrapper.Models.SalesOrder saleO = new Cin7ApiWrapper.Models.SalesOrder();

            saleO.CreatedDate  = order.Created;
            saleO.ModifiedDate = order.Created;
            saleO.Reference    = order.OrderNumber;

            saleO.CurrencyCode   = "ZAR";
            saleO.CurrencySymbol = "R";
            saleO.TaxStatus      = TaxStatus.Excl;
            saleO.TaxRate        = 0.14m;
            saleO.Total          = Convert.ToDecimal(order.SubTotal);

            if (order.Account != null)
            {
                saleO.BillingCompany  = order.Account.CompanyName;
                saleO.DeliveryCompany = order.Account.CompanyName;
                saleO.Company         = order.Account.CompanyName;
            }
            else
            {
                saleO.BillingCompany  = "Undefined";
                saleO.DeliveryCompany = "Undefined";
                saleO.Company         = "Individual User Account";
            }

            if (order.Address != null)
            {
                saleO.BillingAddress1    = order.Address.Address1;
                saleO.BillingAddress2    = order.Address.Address2;
                saleO.BillingCity        = order.Address.City;
                saleO.BillingPostalCode  = order.Address.PostCode;
                saleO.DeliveryAddress1   = order.Address.Address1;
                saleO.DeliveryAddress2   = order.Address.Address2;
                saleO.DeliveryCity       = order.Address.City;
                saleO.DeliveryPostalCode = order.Address.PostCode;
            }
            else
            {
                saleO.BillingAddress1    = "Undefined";
                saleO.BillingAddress2    = "Undefined";
                saleO.BillingCity        = "Undefined";
                saleO.BillingPostalCode  = "Undefined";
                saleO.DeliveryAddress1   = "Undefined";
                saleO.DeliveryAddress2   = "Undefined";
                saleO.DeliveryCity       = "Undefined";
                saleO.DeliveryPostalCode = "Undefined";
            }

            if (order.CostCenter != null)
            {
                saleO.MemberCostCenter = order.CostCenter.Name;
            }
            else if (order.Location != null)
            {
                saleO.MemberCostCenter = order.Location.Name;
            }
            else
            {
                saleO.MemberCostCenter = "Undefined";
            }

            if (order.User != null)
            {
                saleO.FirstName   = order.User.FirstName;
                saleO.LastName    = order.User.LastName;
                saleO.Email       = order.User.Email;
                saleO.Phone       = order.User.PhoneNumber;
                saleO.MemberEmail = order.User.Email;
            }
            else
            {
                saleO.FirstName   = "Undefined";
                saleO.LastName    = "Undefined";
                saleO.Email       = "Undefined";
                saleO.Phone       = "Undefined";
                saleO.MemberEmail = "Undefined";
            }

            if (string.IsNullOrEmpty(order.OrderRef))
            {
                saleO.CustomerOrderNo = "Undefined";
            }
            else
            {
                saleO.CustomerOrderNo = order.OrderRef;
            }
            saleO.IsApproved       = true;
            saleO.ProductTotal     = order.OriginalSubtotal;
            saleO.DiscountTotal    = Convert.ToDecimal(order.Discount);
            saleO.LineItems        = getLineItems(GetProducts(order), order).ToArray();
            saleO.InternalComments = "";
            CreateResult result = api.SalesOrders.Create(saleO);

            return(result);
        }