Exemple #1
0
        public static void Mainsh(string[] arg)
        {
            MNC_Product_Sync.Navision_Shipment.PostedSalesShipment_PortClient client = new MNC_Product_Sync.Navision_Shipment.PostedSalesShipment_PortClient();

            client.ClientCredentials.Windows.ClientCredential.UserName = "******";

            client.ClientCredentials.Windows.ClientCredential.Password = "******";

            client.ClientCredentials.Windows.ClientCredential.Domain = "122.166.222.116";

            Navision_Shipment.PostedSalesShipment_Filter f = new Navision_Shipment.PostedSalesShipment_Filter();

            Navision_Shipment.PostedSalesShipment[] nv_PostedShipments;

            nv_PostedShipments = client.ReadMultiple(new Navision_Shipment.PostedSalesShipment_Filter[] { f }, null, 10000);

            DBConnect db = new DBConnect();

            MNC_Product_Sync.MagentoConnectService.PortTypeClient mage_client = new MNC_Product_Sync.MagentoConnectService.PortTypeClient();

            string token_id = null;

            // Create the shipment, and add tracking for it. Similar to invoicing, we don't stop for errors.
            try
            {
                Hashtable hsp = db.fetch_PendingShipments();
                token_id = mage_client.login("webserviceuser", "apikey");

                for (int i = 0; i < nv_PostedShipments.Length; i++)
                {
                    if (db.fetch_OnlineOrder(nv_PostedShipments[i].Order_No))
                    {
                        string   magorder   = (string)hsp[nv_PostedShipments[i].Order_No + "/" + 1];
                        string[] mageorders = magorder.Split('/');

                        string shipmentIncrementId = mage_client.salesOrderShipmentCreate(token_id, mageorders[0], null,
                                                                                          "Shipment via MagNaxt Connector/Navision Order" + nv_PostedShipments[i].Order_No, 1, 1);

                        associativeEntity[] validCarriers = mage_client.salesOrderShipmentGetCarriers(token_id, mageorders[0]);

                        try
                        {
                            mage_client.salesOrderShipmentAddTrack(token_id, shipmentIncrementId, "ups", "Shipment via Magnaxt Connector", nv_PostedShipments[i].Package_Tracking_No);
                            mage_client.salesOrderAddComment(token_id, mageorders[0], "complete", "Order Completed via API", "0");
                            db.UpdateShipment(magorder, shipmentIncrementId + "/" + nv_PostedShipments[i].No);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
    public static void MainOrders(string[] args)
    {
        MNC_Product_Sync.Navision_SalesOrder_Service.SalesOrder_PortClient client = new MNC_Product_Sync.Navision_SalesOrder_Service.SalesOrder_PortClient();



        client.ClientCredentials.Windows.ClientCredential.UserName = "******";

        client.ClientCredentials.Windows.ClientCredential.Password = "******";

        client.ClientCredentials.Windows.ClientCredential.Domain = "122.166.222.116";

        DBConnect db = new DBConnect();

        MNC_Product_Sync.MagentoConnectService.PortTypeClient mage_client = new MNC_Product_Sync.MagentoConnectService.PortTypeClient();

        string token_id = null;


        try
        {
            ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            token_id    = mage_client.login("webserviceuser", "apikey");
            _stateCodes = mage_client.directoryRegionList(token_id, "US");

            filters filtres = new filters();

            filtres.complex_filter = new complexFilter[]
            {
                new complexFilter()
                {
                    //key = "created_at",
                    //value = new associativeEntity
                    //{
                    //    key = "gt",
                    //    value = "2015-07-28 08:00:00"
                    //}

                    key   = "status",
                    value = new associativeEntity
                    {
                        key   = "eq",
                        value = "pending"
                    }
                }
            };

            salesOrderListEntity[] salesOrders = mage_client.salesOrderList(token_id, filtres);

            Hashtable hsc = db.fetch_Customer1Mapping();


            foreach (salesOrderListEntity orderHeader in salesOrders)
            {
                if (!db.fetch_Order(orderHeader.increment_id.ToString(), "1"))
                {
                    MNC_Product_Sync.Navision_SalesOrder_Service.SalesOrder so = new MNC_Product_Sync.Navision_SalesOrder_Service.SalesOrder();

                    MNC_Product_Sync.Navision_SalesOrder_Service.Sales_Order_Line[] sls = new MNC_Product_Sync.Navision_SalesOrder_Service.Sales_Order_Line[50];
                    salesOrderEntity        orderDetail   = mage_client.salesOrderInfo(token_id, orderHeader.increment_id);
                    salesOrderAddressEntity billToAddress = orderDetail.billing_address;
                    salesOrderAddressEntity shipToAddress = orderDetail.shipping_address;
                    so.Bill_to_Address       = billToAddress.street + " " + billToAddress.region + " " + billToAddress.postcode;
                    so.Ship_to_Address       = billToAddress.street + " " + billToAddress.region + " " + billToAddress.postcode;
                    so.Bill_to_Name          = billToAddress.firstname + " " + billToAddress.lastname + " ";
                    so.Ship_to_Name          = shipToAddress.firstname + " " + shipToAddress.lastname;
                    so.Bill_to_Contact       = billToAddress.telephone;
                    so.Sell_to_Customer_No   = hsc[orderDetail.customer_id].ToString();
                    so.Ship_to_Contact       = billToAddress.telephone;
                    so.External_Document_No  = orderHeader.increment_id;
                    so.Bill_to_Customer_No   = hsc[orderDetail.customer_id].ToString();
                    so.Sell_to_Customer_Name = orderHeader.customer_firstname + " " + orderHeader.customer_lastname;
                    so.Order_Date            = DateTime.Parse(orderHeader.created_at);
                    so.VAT_Bus_Posting_Group = "FOREIGN";



                    int i = 0;

                    foreach (salesOrderItemEntity li in orderDetail.items)
                    {
                        if (!db.fetch_Order(orderHeader.increment_id.ToString(), (i + 1).ToString()))
                        {
                            MNC_Product_Sync.Navision_SalesOrder_Service.Sales_Order_Line sl = new MNC_Product_Sync.Navision_SalesOrder_Service.Sales_Order_Line();
                            sl.Quantity = decimal.Parse(li.qty_ordered);
                            sl.VAT_Prod_Posting_Group = "DOMESTIC";
                            sl.No                = li.sku;
                            sl.Description       = li.name;
                            sl.Unit_Price        = decimal.Parse(li.base_price);
                            sl.Line_Amount       = decimal.Parse(li.base_row_total);
                            sl.TypeSpecified     = true;
                            sl.Sales_Header_Repl = decimal.Parse(li.base_price).ToString();
                            sl.QuantitySpecified = true;
                            sl.Type              = MNC_Product_Sync.Navision_SalesOrder_Service.Type.Item;
                            sl.Line_No           = i + 1;
                            sls[i]               = sl;


                            i = i + 1;
                            db.InsertOrderMapping(so.No, sl.Line_No.ToString(), orderHeader.increment_id, sl.Line_No.ToString(), orderHeader.customer_id);
                        }
                    }
                    if (!db.fetch_Order(orderHeader.increment_id.ToString(), (i + 1).ToString()))
                    {
                        try {
                            so.SalesLines = sls;
                            client.Create(ref so);
                            if (so.No != null)
                            {
                                db.UpdateOrder(orderHeader.increment_id, so.No);
                                db.InsertLog("Order", so.No, "Navision Order Number", "SUCCESS");
                            }
                        }
                        catch (Exception ex)
                        {
                            db.deleteOrder(orderHeader.increment_id);
                            db.InsertLog("Order", orderHeader.increment_id, ex.Message, "FAILED");
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            db.InsertLog("Order", "", ex.Message.ToString(), "FAILED");
            MNC_Product_Sync.ErrorLog errLog = new MNC_Product_Sync.ErrorLog();

            errLog.LogError("C:\\MNC_Logs", "Order : " + ex.Message);
        }
        finally
        {
            mage_client.endSession(token_id);
        }
    }
Exemple #3
0
        public static void MainInv(string[] args)
        {
            MNC_Product_Sync.Navision_Invoice.PostedSalesInvoice_PortClient client1 = new MNC_Product_Sync.Navision_Invoice.PostedSalesInvoice_PortClient();

            client1.ClientCredentials.Windows.ClientCredential.UserName = "******";

            client1.ClientCredentials.Windows.ClientCredential.Password = "******";

            client1.ClientCredentials.Windows.ClientCredential.Domain = "122.166.222.116";

            Navision_Invoice.PostedSalesInvoice_Filter f1 = new Navision_Invoice.PostedSalesInvoice_Filter();

            Navision_Invoice.PostedSalesInvoice[] nv_PostedInvoices;

            nv_PostedInvoices = client1.ReadMultiple(new Navision_Invoice.PostedSalesInvoice_Filter[] { f1 }, null, 10000);


            DBConnect db = new DBConnect();

            MNC_Product_Sync.MagentoConnectService.PortTypeClient mage_client = new MNC_Product_Sync.MagentoConnectService.PortTypeClient();

            string token_id = null;


            try
            {
                Hashtable hso = db.fetch_PendingInvoices();

                token_id = mage_client.login("webserviceuser", "apikey");
                orderItemIdQty[] invoiceQtys = null;
                for (int i = 0; i < nv_PostedInvoices.Length; i++)
                {
                    if (db.fetch_OnlineOrder(nv_PostedInvoices[i].Order_No))
                    {
                        string                magorder    = (string)hso[nv_PostedInvoices[i].Order_No + "/" + 1];
                        string[]              mageorders  = magorder.Split('/');
                        salesOrderEntity      orderDetail = mage_client.salesOrderInfo(token_id, mageorders[0]);
                        List <orderItemIdQty> invoiceInfo = new List <orderItemIdQty>();
                        foreach (salesOrderItemEntity li in orderDetail.items)
                        {
                            orderItemIdQty invoiceLineItem = new orderItemIdQty();
                            invoiceLineItem.order_item_id = Convert.ToInt32(li.item_id);
                            invoiceLineItem.qty           = Convert.ToDouble(li.qty_ordered);
                            invoiceInfo.Add(invoiceLineItem);
                        }
                        invoiceQtys = invoiceInfo.ToArray();

                        /* Create an invoice, and then capture it. Although we are reporting errors,
                         *  we don't do anything about them, Nor do we stop processing.
                         */


                        try
                        {
                            string invoiceIncrementId = mage_client.salesOrderInvoiceCreate(token_id, mageorders[0],
                                                                                            invoiceQtys, "Invoiced via API", "1", "1");
                            try
                            {
                                // mage_client.salesOrderInvoiceCapture(token_id, invoiceIncrementId);
                                mage_client.salesOrderAddComment(token_id, mageorders[0], "invoiced", "Order Invoiced via API", "0");
                                db.UpdateInvoice(magorder, invoiceIncrementId + "/" + nv_PostedInvoices[i].No);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }


                /* Assuming everything went well (which we do ASSume), this order has been Imported into ERP, Invoiced,
                 *  Captured, and Shipped Complete.
                 */

                mage_client.endSession(token_id);
            }
            catch (Exception ex)
            {
            }
        }