コード例 #1
0
        private void CancelItems(sales_flat_order order, Connector connector, OrderResponse ediResponse, int cancelledLines, int totalLines, OrderHelper helper)
        {
            log.Info("For order " + order.increment_id + " , trying to call the cancel shipment url ");
            if (((ConnectorSystemType)connector.ConnectorSystemType).Has(ConnectorSystemType.CallShipmentLink))
            {
                JsonOrder orderJson = new JsonOrder();
                orderJson.id             = order.increment_id;
                orderJson.tracking_codes = new string[0];

                int ediOrderLines = ediResponse.OrderDetails.Count();

                orderJson.lines = new JsonOrderLine[ediOrderLines];

                var isIgnorable = (ediOrderLines == 1 && (ediResponse.OrderDetails.First().ProductIdentifier.ProductNumber.ToLower() == "ShippingCostProductID_IDEAL".ToLower() || ediResponse.OrderDetails.First().ProductIdentifier.ProductNumber.ToLower() == "ShippingCostProductID_CREDITCARD".ToLower()));
                if (!isIgnorable)
                {
                    for (int i = 0; i < ediOrderLines; i++)
                    {
                        var line = ediResponse.OrderDetails[i];

                        orderJson.lines[i] = new JsonOrderLine()
                        {
                            lineid = line.ProductIdentifier.ManufacturerItemID,
                            qty    = line.Quantity.QuantityCancelled,
                            status = "C"
                        };
                    }
                }
                SendGenericUpdate(orderJson, connector, helper);
            }
        }
コード例 #2
0
        internal bool UpdateOrderLine(sales_flat_order order, OrderResponseDetail line)
        {
            using (var cm = Connection.CreateCommand())
            {
                cm.CommandText = "UPDATE sales_flat_order_item SET qty_canceled = ?qty_cancelled, qty_backordered =?qty_backordered WHERE order_id = ?order_id AND sku = '?sku'";
                cm.CommandType = CommandType.Text;
                cm.Parameters.AddWithValue("?order_id", order.entity_id);
                cm.Parameters.AddWithValue("?sku", line.ProductIdentifier.ManufacturerItemID);
                cm.Parameters.AddWithValue("?qty_backordered", line.Quantity.QuantityBackordered);
                cm.Parameters.AddWithValue("?qty_cancelled", line.Quantity.QuantityCancelled);

                return(cm.ExecuteNonQuery() > 0);
            }
        }
コード例 #3
0
        internal sales_flat_order_item GetOrderLine(sales_flat_order order, string lineSku, bool checkConfigurable = false)
        {
            using (var cm = Connection.CreateCommand())
            {
                cm.CommandText = "SELECT * FROM sales_flat_order_item WHERE order_id = ?order_id AND sku = ?sku AND product_type = ?product_type";
                cm.CommandType = CommandType.Text;
                cm.Parameters.AddWithValue("?order_id", order.entity_id);
                cm.Parameters.AddWithValue("?sku", lineSku);
                cm.Parameters.AddWithValue("?product_type", checkConfigurable ? "configurable" : "simple");

                using (var reader = cm.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        return(Mapper.Map <IDataRecord, sales_flat_order_item>(reader));
                    }

                    return(null);
                }
            }
        }
コード例 #4
0
        //internal sales_flat_order_item GetOrderLine(sales_flat_order order, InvoiceOrderDetail line)
        //{
        //  using (var cm = Connection.CreateCommand())
        //  {

        //    cm.CommandText = "SELECT * From sales_flat_order_item WHERE   order_id = ?order_id AND item_id = ?item_id";
        //    cm.CommandType = CommandType.Text;
        //    cm.Parameters.AddWithValue("?order_id", order.entity_id);
        //    cm.Parameters.AddWithValue("?item_id", line.LineNumber);

        //    using (var reader = cm.ExecuteReader())
        //    {
        //      if (reader.Read())
        //      {
        //        return Mapper.Map<IDataRecord, sales_flat_order_item>(reader);
        //      }

        //      return null;

        //    }
        //  }
        //}

        internal int GetOrderLinesCount(sales_flat_order order, bool checkConfigurable = false)
        {
            using (var cm = Connection.CreateCommand())
            {
                cm.CommandText = "SELECT count(*) FROM sales_flat_order_item WHERE order_id = ?order_id AND product_type = ?product_type";
                cm.CommandType = CommandType.Text;
                cm.Parameters.AddWithValue("?order_id", order.entity_id);
                cm.Parameters.AddWithValue("?product_type", checkConfigurable ? "configurable" : "simple");

                //using (var reader = cm.ExecuteScalar())
                //{

                //  if (reader.Read())
                //  {
                //    return Mapper.Map<IDataRecord, List<sales_flat_order_item>>(reader);
                //  }

                //  return null;
                //}

                return(Convert.ToInt32(cm.ExecuteScalar()));
            }
        }
コード例 #5
0
        public override void Init(HttpListenerContext ctx = null)
        {
            if (ctx.Request.Cookies["guid"] != null &&
                Sessions.sessions.ContainsKey(
                    (from s in Sessions.sessions where s.Value.Item2 == ctx.Request.Cookies["guid"].Value select s.Key)
                    .First()))
            {
            }

            sales_catalog_car car = DB.GetModel("sales_catalog_car").Select("*").AddFieldToFilter("car_license_plate", new Tuple <string, Expression>("eq", new Expression(Url.Split('/')[1]))).Load().ToDataSet <sales_catalog_car>().First();

            int customerID = (from s in Sessions.sessions where s.Value.Item2 == ctx.Request.Cookies["guid"].Value select s.Key).First();

            core_customer customer = DB.GetModel("core_customer").Select("*").AddFieldToFilter("customer_id", new Tuple <string, Expression>("eq", new Expression(customerID.ToString()))).Load().ToDataSet <core_customer>().First();

            Model insertModel = DB.GetModel("sales_flat_order").Insert();

            insertModel
            .AddDataToInsert(new KeyValuePair <string, string>("customer_id", customer.customer_id.ToString()))
            .AddDataToInsert(new KeyValuePair <string, string>("treated_by", "PIET"));

            insertModel.Load();

            sales_flat_order order = DB.GetModel("sales_flat_order").Select("*").AddFieldToFilter("order_id", Tuple.Create <string, Expression>("eq", new Expression("LAST_INSERT_ID()", false))).Load().ToDataSet <sales_flat_order>().First();

            DB.GetModel("sales_flat_order")
            .Update()
            .AddKeyValueToUpdate(new KeyValuePair <string, string>("invoice_link",
                                                                   "pdf/1000" + order.order_id + ".pdf"))
            .AddFieldToFilter("order_id",
                              Tuple.Create <string, Expression>("eq", new Expression(order.order_id.ToString())))
            .Load();

            DB.GetModel("sales_order_item").Insert()
            .AddDataToInsert(new KeyValuePair <string, string>("order_id", order.order_id.ToString()))
            .AddDataToInsert(new KeyValuePair <string, string>("car_id", car.car_id.ToString()))
            .AddDataToInsert(new KeyValuePair <string, string>("hired_from", _POST["date_1"]))
            .AddDataToInsert(new KeyValuePair <string, string>("hired_to", _POST["date_2"]))
            .Load();

            int days =
                Convert.ToInt16(
                    (DateTime.ParseExact(_POST["date_2"], "yyyy/MM/dd", CultureInfo.InvariantCulture) -
                     DateTime.ParseExact(_POST["date_1"], "yyyy/MM/dd", CultureInfo.InvariantCulture)).TotalDays);

            new InvoicerApi(SizeOption.A4, OrientationOption.Landscape, "€")
            .TextColor("#0000CC")
            .BackColor("#87ceeb")
            .Title("Factuur")
            .BillingDate(DateTime.Now)
            .Reference("1000" + order.order_id)
            .Company(Address.Make("VAN", new string[] { "Rent-a-Car", "Almere" }))
            .Client(Address.Make("FACTUUR ADRES",
                                 new string[]
            {
                customer.customer_name, customer.address_street + " " + customer.address_number,
                customer.address_city, customer.address_postal
            }))
            .Items(new List <ItemRow>
            {
                ItemRow.Make(car.car_type + " - " + car.car_brand, "van: " + _POST["date_1"] + " tot: " + _POST["date_2"],
                             (decimal)days, days * decimal.Multiply(car.car_day_price, (decimal)0.25), (decimal)car.car_day_price,
                             decimal.Multiply(days, car.car_day_price)),
            })
            .Totals(new List <TotalRow>
            {
                TotalRow.Make("Subtotaal", days * decimal.Multiply(car.car_day_price, (decimal)0.75)),
                TotalRow.Make("BTW @ 25%", days * decimal.Multiply(car.car_day_price, (decimal)0.25)),
                TotalRow.Make("Totaal", decimal.Multiply(days, car.car_day_price), true),
            })
            .Details(new List <DetailRow>
            {
                DetailRow.Make("BETALINGS INFORMATIE",
                               "U kunt achteraf betalen bij de medewerker die uw order afhandeld.", "",
                               "Als u nog verdere vragen heeft kunt u mailen naar [email protected]", "",
                               "Bedankt voor uw bestelling",
                               "U kunt de auto ophalen op: " + _POST["date_1"],
                               "En de auto dient op zijn laatst om 17:00 op: " + _POST["date_2"] + " terug gebracht te worden.")
            })
            .Footer("http://www.rent-a-car.com")
            .Save(FileManager.BaseDir + "pdf/1000" + order.order_id + ".pdf");

            string path = FileManager.BaseDir + "pdf/1000" + order.order_id + ".pdf";

            Location = "/pdf/1000" + order.order_id + ".pdf";

            this.response    = "";
            this.ContentType = Constants.CONTENT_PDF;
        }
コード例 #6
0
        private void ProcessResponse(XmlDocument responseString, string prefix)
        {
            object ediDocument   = null;
            int    bskIdentifier = 0;

            switch (prefix)
            {
            case "OrderResponse":
                ediDocument   = ExtractResponseMessage <OrderResponse>(responseString);
                bskIdentifier = ((OrderResponse)ediDocument).OrderHeader.BSKIdentifier;
                break;

            case "ShippingNotification":
                ediDocument   = ExtractResponseMessage <ShippingNotification>(responseString);
                bskIdentifier = ((ShippingNotification)ediDocument).ShipmentOrderHeader.BSKIdentifier;

                break;

            case "InvoiceNotification":
                ediDocument   = ExtractResponseMessage <InvoiceNotification>(responseString);
                bskIdentifier = ((InvoiceNotification)ediDocument).InvoiceOrderHeader.BSKIdentifier;
                break;

            case "Statuses":
                ediDocument = XDocument.Parse(responseString.OuterXml);
                break;
            }

            Connector connector = null;

            using (var unit = GetUnitOfWork())
            {
                if (bskIdentifier != 0)
                {
                    connector = unit.Scope.Repository <Connector>().GetSingle(x => x.BSKIdentifier == bskIdentifier);
                }
                else
                {
                    if (ediDocument != null)
                    {
                        var connectorid = int.Parse(((XDocument)ediDocument).Root.Attribute("ConnectorID").Value);
                        connector = unit.Scope.Repository <Connector>().GetSingle(x => x.ConnectorID == connectorid);
                    }
                }

                if (connector == null)
                {
                    string bsk     = bskIdentifier.ToString();
                    var    setting = unit.Scope.Repository <ConnectorSetting>().GetSingle(x => x.SettingKey == "ShopOrderBSK" && x.Value == bsk);

                    if (setting != null)
                    {
                        connector = setting.Connector;
                    }

                    if (connector == null)
                    {
                        log.WarnFormat("Process response failed for {0} message", prefix);
                        return;
                    }
                }
            }

            OrderHelper      helper = new OrderHelper(connector.Connection);
            sales_flat_order order  = null;

            switch (prefix)
            {
            case "OrderResponse":
                OrderResponse ediResponse = ediDocument as OrderResponse;



                order = helper.GetSalesOrder(ediResponse.OrderHeader.WebSiteOrderNumber);

                if (order != null)
                {
                    order.state  = "processing";
                    order.status = "concentrator";


                    log.Info("For order " + order.increment_id + " updating the status to concentrator ");
                    helper.UpdateOrderStatus(ediResponse.OrderHeader.WebSiteOrderNumber, MagentoOrderState.Processing, MagentoOrderStatus.concentrator);

                    int cancelledlines = 0;
                    int backorderLines = 0;
                    int lines          = 0;

                    foreach (var line in ediResponse.OrderDetails)
                    {
                        //var responseLine = (from r in mctx.sales_flat_order_item
                        //                    where r.item_id == line.LineNumber
                        //                    select r).FirstOrDefault();



                        helper.UpdateOrderLine(order, line);
                        lines++;
                        var lineEntity = helper.GetOrderLine(order, line.ProductIdentifier.ManufacturerItemID);

                        //if (responseLine != null)
                        //{
                        //  lines++;

                        if (line.Quantity.QuantityCancelled > 0)
                        {
                            cancelledlines++;
                        }

                        if (line.Quantity.QuantityBackordered > 0)
                        {
                            backorderLines++;
                        }
                    }

                    #region REPLACED WITH FUNCTION : DiSCUSS WITH FREEK

                    //if (cancelledlines == lines)
                    //{
                    //  // helper.UpdateOrderStatus(order.increment_id, MagentoOrderState.canceled, MagentoOrderStatus.canceled);
                    //  log.Info("For order " + order.increment_id + " , trying to call the cancel shipment url ");
                    //  if (((ConnectorSystemType)connector.ConnectorSystemType).Has(ConnectorSystemType.CallShipmentLink))
                    //  {

                    //    int ediOrderLines = ediResponse.OrderDetails.Count();

                    //    var isIgnorable = (ediOrderLines == 1 && (ediResponse.OrderDetails.First().ProductIdentifier.ProductNumber.ToLower() == "ShippingCostProductID_IDEAL".ToLower() || ediResponse.OrderDetails.First().ProductIdentifier.ProductNumber.ToLower() == "ShippingCostProductID_CREDITCARD".ToLower()));
                    //    if (!isIgnorable)
                    //    {
                    //      string url = connector.ConnectorSettings.GetValueByKey("CancelShipmentUrl", string.Empty);
                    //      if (!string.IsNullOrEmpty(url))
                    //      {
                    //        var skus = new Dictionary<string, int>();
                    //        StringBuilder sb = new StringBuilder();


                    //        for (int i = 0; i < ediOrderLines; i++)
                    //        {
                    //          var line = ediResponse.OrderDetails[i];

                    //          sb.Append(HttpUtility.HtmlEncode(line.ProductIdentifier.ManufacturerItemID) + "," + line.Quantity.QuantityShipped);
                    //          if (i != ediOrderLines - 1) sb.Append(";");
                    //        }

                    //        ///basstock/shipment/shippartialorder/order_id/100000342/items/SKU1,5;SKU2,7/trackin_code/123,2345

                    //        url = string.Format(url, ediResponse.OrderHeader.WebSiteOrderNumber, HttpUtility.UrlEncode(sb.ToString()));
                    //        log.Info("For order " + order.increment_id + " , called cancel shipment url " + url);
                    //        WebRequest req = WebRequest.Create(url);
                    //        using (WebResponse resp = req.GetResponse())
                    //        {
                    //          log.AuditInfo("Url for partial shipment called for " + connector.Name + " returned:" + (((HttpWebResponse)resp).StatusDescription));
                    //        }
                    //      }
                    //    }
                    //  }
                    //}

                    #endregion

                    if (cancelledlines > 0)
                    {
                        int totalLines = 0;
                        totalLines = helper.GetOrderLinesCount(order, true);
                        CancelItems(order, connector, ediResponse, cancelledlines, totalLines, helper);
                    }

                    //if (backorderLines == lines)
                    //{
                    //  //helper.UpdateOrderStatus(order.increment_id, MagentoOrderState.Processing, MagentoOrderStatus.backorder);
                    //}
                }
                log.DebugFormat("Processed OrderResponse for order {0} (Connector : {1})", ediResponse.OrderHeader.WebSiteOrderNumber, connector.Name);

                break;

            case "ShippingNotification":
                ShippingNotification ediShipment = ediDocument as ShippingNotification;
                log.Info("Shipment order for " + ediShipment.ShipmentOrderHeader.WebSiteOrderNumber);

                bool shopOrder = false;
                order = helper.GetSalesOrder(ediShipment.ShipmentOrderHeader.WebSiteOrderNumber);


                if (order != null)
                {
                    if (ediShipment.ShipmentOrderHeader.CustomerOrder.Contains("Winkel#") ||
                        ediShipment.ShipmentOrderHeader.CustomerOrder.Contains("#winkel"))
                    {
                        shopOrder = true;
                    }

                    int cancelledlines = 0;
                    int lines          = 0;
                    foreach (var line in ediShipment.ShipmentOrderDetails)
                    {
                        long lineNumber = 0;

                        if (long.TryParse(line.LineNumber, out lineNumber))
                        {
                            var responseLine = helper.GetOrderLine(order, line.ProductIdentifier.ManufacturerItemID);

                            if (responseLine != null)
                            {
                                lines++;

                                if (line.Quantity.QuantityCancelled > 0)
                                {
                                    cancelledlines++;
                                }

                                helper.UpdateOrderLine(order, line);
                            }
                        }
                    }

                    log.Info("Number of cancelled lines " + cancelledlines);

                    log.Info("For order " + order.increment_id + " trying to call shipment url");
                    if (((ConnectorSystemType)connector.ConnectorSystemType).Has(ConnectorSystemType.CallShipmentLink))
                    {
                        int ediOrderLines = ediShipment.ShipmentOrderDetails.Count();

                        JsonOrder orderJson = new JsonOrder();
                        orderJson.id             = order.increment_id;
                        orderJson.tracking_codes = ediShipment.ShipmentOrderDetails.Select(x => x.ShipmentInformation.TrackAndTraceNumber).Distinct().ToArray();
                        orderJson.lines          = new JsonOrderLine[ediOrderLines];

                        var isIgnorable = (ediOrderLines == 1 && (ediShipment.ShipmentOrderDetails.First().ProductIdentifier.ManufacturerItemID.ToLower() == "ShippingCostProductID_IDEAL".ToLower() || ediShipment.ShipmentOrderDetails.First().ProductIdentifier.ManufacturerItemID.ToLower() == "ShippingCostProductID_CREDITCARD".ToLower()));
                        if (!isIgnorable)
                        {
                            string url = connector.ConnectorSettings.GetValueByKey("SCBUrl", string.Empty);
                            if (!string.IsNullOrEmpty(url))
                            {
                                var skus = new Dictionary <string, int>();

                                for (int i = 0; i < ediOrderLines; i++)
                                {
                                    var line = ediShipment.ShipmentOrderDetails[i];

                                    orderJson.lines[i] = new JsonOrderLine()
                                    {
                                        lineid = line.ProductIdentifier.ManufacturerItemID,
                                        qty    = line.Quantity.QuantityShipped,
                                        status = "S"
                                    };
                                }

                                SendGenericUpdate(orderJson, connector, helper);
                            }
                        }
                    }
                }

                log.DebugFormat("Processed ShippingNotification for order {0} (Connector : {1})", ediShipment.ShipmentOrderHeader.WebSiteOrderNumber, connector.Name);

                break;

            case "InvoiceNotification":
                InvoiceNotification ediInvoice = ediDocument as InvoiceNotification;

                order = helper.GetSalesOrder(ediInvoice.InvoiceOrderHeader.WebSiteOrderNumber);

                if (order != null)
                {
                    foreach (var line in ediInvoice.InvoiceOrderDetails)
                    {
                        long lineNumber = 0;

                        if (long.TryParse(line.LineNumber, out lineNumber))
                        {
                            var responseLine = helper.GetOrderLine(order, line.ProductIdentifier.ManufacturerItemID);

                            if (responseLine != null)
                            {
                                helper.UpdateOrderLine(order, line);
                            }
                        }
                    }
                }
                log.DebugFormat("Processed InvoiceNotification for order {0} (Connector : {1})", ediInvoice.InvoiceOrderHeader.WebSiteOrderNumber, connector.Name);

                break;

            case "Statuses":
                string websiteOrderNumber = ((XDocument)ediDocument).Root.Attribute("WebsiteOrderNumber").Value;

                Dictionary <string, string> urls = new Dictionary <string, string>();

                var statuses = ((XDocument)ediDocument).Root.Elements("Status").GroupBy(x => x.Element("StatusDescription").Value).ToArray();

                foreach (var statusGroup in statuses)
                {
                    var count     = statusGroup.Count();
                    var statusId  = statusGroup.Key;
                    var statusUrl = connector.ConnectorSettings.GetValueByKey(statusGroup.Key, string.Empty);

                    JsonOrder ord = new JsonOrder();
                    ord.id             = websiteOrderNumber;
                    ord.tracking_codes = new string[0];
                    ord.lines          = new JsonOrderLine[count];

                    int c = 0;

                    foreach (var stat in statusGroup)
                    {
                        ord.lines[c] = new JsonOrderLine()
                        {
                            lineid = stat.Element("VendorItemNumber").Value,
                            qty    = int.Parse(stat.Element("Quantity").Value),
                            status = statusId[0].ToString().ToUpper()
                        };
                        c++;
                    }
                    SendGenericUpdate(ord, connector, helper, statusUrl);
                }
                break;
            }
        }