Esempio n. 1
0
        private void BuildingForm_Load(object sender, EventArgs e)
        {
            try
            {
                siteAdapter = new SiteTableAdapter();
                customerAdapter = new CustomerTableAdapter();
                buildingAdapter = new BuildingTableAdapter();

                siteAdapter.Connection = cnSql;
                customerAdapter.Connection = cnSql;
                buildingAdapter.Connection = cnSql;

                siteDataTable = new DataSet.SiteDataTable();
                customerDataTable = new DataSet.CustomerDataTable();
                buildingDataTable = new DataSet.BuildingDataTable();

                siteAdapter.Fill(siteDataTable);
                customerAdapter.Fill(customerDataTable);
                buildingAdapter.Fill(buildingDataTable);

                enableForm(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            populateBuildingsList();
            populateSitesList();
            populateCustomersList();
        }
Esempio n. 2
0
        private void HardwareForm_Load(object sender, EventArgs e)
        {
            try
            {
                roomAdapter = new RoomTableAdapter();
                customerAdapter = new CustomerTableAdapter();
                hardwareAdapter = new HardwareTableAdapter();
                hardwareTypeAdapter = new HardwareTypeTableAdapter();

                roomAdapter.Connection = cnSql;
                customerAdapter.Connection = cnSql;
                hardwareAdapter.Connection = cnSql;
                hardwareTypeAdapter.Connection = cnSql;

                roomDataTable = new DataSet.RoomDataTable();
                customerDataTable = new DataSet.CustomerDataTable();
                hardwareDataTable = new DataSet.HardwareDataTable();
                hardwareTypeDataTable = new DataSet.HardwareTypeDataTable();

                roomAdapter.Fill(roomDataTable);
                customerAdapter.Fill(customerDataTable);
                hardwareAdapter.Fill(hardwareDataTable);
                hardwareTypeAdapter.Fill(hardwareTypeDataTable);

                enableForm(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            populateHardwaresList();
            populateRoomsList();
            populateCustomersList();
            populateRoomsList();
            populateHardwareTypesList();
        }
Esempio n. 3
0
        private void CustomerForm_Load(object sender, EventArgs e)
        {
            try
            {
                adapter = new CustomerTableAdapter();
                adapter.Connection = cnSql;
                dataTable = new DataSet.CustomerDataTable();
                adapter.Fill(dataTable);

                enableForm(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            populateCustomersList();
        }
Esempio n. 4
0
        public bool UpdateOrders(DateTime?startDate, int orderLimit = 0)
        {
            Log("\nLoading Orders from Shopify");
            object ordersJson = shop.GetOrders(startDate);
            //Log(ordersJson.ToString());

            JObject             ordersJ = JsonConvert.DeserializeObject <JObject>(ordersJson.ToString());
            List <ShopifyOrder> orders  = JsonConvert.DeserializeObject <List <ShopifyOrder> >(ordersJ["orders"].ToString());

            Log(string.Format("{0} orders loaded.", orders.Count));
            StatusUpdate(string.Format("Updating {0} orders.", orders.Count));


            for (int i = 0; i < orders.Count; i++)
            {
                ShopifyOrder order = orders[i];

                DataSet.OrderDataTable orderDT = orderTA.GetDataByOrderID(shop.ID, order.id);

                if ((orderDT.Count == 0)) // && (order.order_number == 1008)
                {
                    int salesOrderType = 0;
                    // Order Type - different values for pending and paid
                    if (order.financial_status == "pending")
                    {
                        salesOrderType = shop.data.OrderTypePending;
                    }
                    else
                    {
                        salesOrderType = shop.data.OrderType;
                    }

                    SalesOrder sales = SalesOrder.CreateNew(visma._context, 0); // Create with type 0 and update it later in the code, otherwise we might get exception from VismaSDK
                    sales.YourOrderNumber = order.name;
                    sales.OrderDate       = order.created_at;
                    sales.OrderType       = salesOrderType;


                    // Terms of Payment
                    int?termsOfPayment = shop.GetValueIDFromShopData(shop.termsOfPayment, order.gateway);
                    if (termsOfPayment.HasValue)
                    {
                        sales.TermsOfPaymentId = termsOfPayment.Value;
                    }

                    // Delivery Method
                    int?deliveryMethod = order.shipping_lines.Count() > 0 ? shop.GetValueIDFromShopData(shop.deliveryMethods, order.shipping_lines[0].code) : null;
                    if (deliveryMethod.HasValue)
                    {
                        sales.DeliveryMethodId = deliveryMethod.Value;
                    }


                    //Log(string.Format("  {0} > {1}", order.gateway, termsOfPayment.ToString()));
                    //Log(string.Format("  {0} > {1}", order.shipping_lines.Count() > 0 ? order.shipping_lines[0].code : "", deliveryMethod.ToString()));

                    // Customer
                    Customer orderCustomer = null;
                    if (order.customer != null)
                    {
                        string customerTags = order.customer.tags;
                        //Log(customerTags);
                        if (!string.IsNullOrEmpty(customerTags))
                        {
                            string customerTag = customerTags.Split(',').Where(x => x.Trim().StartsWith("+C")).FirstOrDefault();
                            customerTag = (!string.IsNullOrEmpty(customerTag)) ? customerTag.Replace("+C", "") : customerTag;
                            int customerID = -1;
                            if (int.TryParse(customerTag, out customerID))
                            {
                                // Use existing customer from Visma
                                orderCustomer        = visma.GetCustomerByNumber(customerID);
                                sales.CustomerNumber = customerID;
                            }
                            else
                            {
                                DataSet.CustomerDataTable customerDT = customerTA.GetDataByShopifyCustomerID(shop.ID, order.customer.id);

                                if (customerDT.Count > 0)
                                {
                                    customerID           = customerDT[0].VismaCustomerNumber;
                                    orderCustomer        = visma.GetCustomerByNumber(customerID);
                                    sales.CustomerNumber = customerID;

                                    Log(string.Format("   - Order customer [#{0}] already exists in Visma as Customer {1}", order.customer.id, orderCustomer.Number));
                                }
                            }
                        }


                        if (orderCustomer == null)
                        {
                            // Create new customer in Visma
                            orderCustomer = Customer.CreateNew(visma._context);
                            string orderCustomerName = string.Format("{0} {1}", order.customer.first_name, order.customer.last_name);
                            orderCustomer.Name1 = orderCustomerName;

                            orderCustomer.SellerID        = shop.data.Seller;
                            orderCustomer.CustomerGroupID = shop.customerGroup;

                            //orderCustomer.InvoiceEmail = order.customer.email;

                            Contact orderContact = orderCustomer.Contacts.AddNew();
                            orderContact.Email = order.customer.email;

                            // Default address
                            long addressID = 0;
                            if (order.customer.default_address != null)
                            {
                                ShopifyAddress address = order.customer.default_address;
                                addressID = address.id.HasValue ? address.id.Value : 0;
                                orderCustomer.StreetAddress = string.Format("{0} {1}", address.address1, address.address2).Trim();
                                orderCustomer.City          = string.Format("{0} {1}", address.zip, address.city).Trim();
                                orderCustomer.Country       = address.country_code;

                                // If customer has a company name -> store it as the main visma Customer name
                                if (!string.IsNullOrEmpty(address.company))
                                {
                                    orderContact.Name   = orderCustomerName;
                                    orderCustomer.Name1 = address.company;
                                }

                                orderCustomer.PhoneNumber = address.phone;
                                orderContact.Phone        = address.phone;
                            }

                            // Save additional customer tags such as VAT number


                            orderCustomer.Save();
                            sales.CustomerNumber = orderCustomer.Number;

                            // Save new customer mapping to ShopifyVisma database
                            customerTA.InsertCustomer(shop.ID, order.customer.id, orderCustomer.Number, addressID, 1);

                            Log(string.Format("   - Order customer [#{0}] saved to Visma as Customer {1}", order.customer.id, orderCustomer.Number));
                        }
                    }


                    sales.TermsOfDeliveryId = shop.data.TermsOfDelivery;
                    sales.SellerId          = orderCustomer != null ? orderCustomer.SellerID : shop.data.Seller;


                    // Order delivery date
                    DateTime orderDeliveryDate = order.created_at.AddYears(1);
                    sales.DeliveryDate = orderDeliveryDate;


                    // Unifaun
                    string locationIDText = order.GetNoteAttribute("Unifaun Location ID");
                    int    locationID     = 0;
                    if (int.TryParse(locationIDText, out locationID))
                    {
                        //sales.DriverId = locationID;
                        //sales.OrdererNumber = locationID;
                    }

                    string locationName          = order.GetNoteAttribute("Unifaun Location Name");
                    string locationStreetAddress = order.GetNoteAttribute("Unifaun Location Street");
                    string locationCity          = order.GetNoteAttribute("Unifaun Location City");
                    string locationZIP           = order.GetNoteAttribute("Unifaun Location ZIP");

                    //sales.OrdererNumber



                    // Billing address
                    if (order.billing_address != null)
                    {
                        ShopifyAddress address = order.billing_address;

                        sales.CustomerName          = sales.OrdererName;
                        sales.CustomerStreetAddress = sales.OrdererStreetAddress;
                        sales.CustomerCity          = sales.OrdererCity;

                        if (orderCustomer != null)
                        {
                            //sales.OrdererNumber = orderCustomer.Number;
                            sales.CustomerNumber = orderCustomer.Number;
                        }
                    }



                    // Shipping address
                    if (order.shipping_address != null)
                    {
                        ShopifyAddress address = order.shipping_address;
                        sales.DeliveryName          = string.Format("{0} {1}", address.first_name, address.last_name).Trim();
                        sales.DeliveryStreetAddress = string.Format("{0} {1}", address.address1, address.address2).Trim();
                        sales.DeliveryCity          = string.Format("{0} {1}", address.zip, address.city).Trim();

                        sales.OrdererName          = string.Format("{0} {1}", address.first_name, address.last_name).Trim();
                        sales.OrdererStreetAddress = string.Format("{0} {1}", address.address1, address.address2).Trim();
                        sales.OrdererCity          = string.Format("{0} {1}", address.zip, address.city).Trim();

                        if (locationID > 0)
                        {
                            sales.OrdererName  = locationID.ToString();
                            sales.OrdererName2 = locationName;
                        }

                        // Unifaun shipping address
                        if (!string.IsNullOrEmpty(locationStreetAddress) && !string.IsNullOrEmpty(locationCity))
                        {
                            sales.OrdererStreetAddress = string.Format("{0}", locationStreetAddress);
                            sales.OrdererCity          = string.Format("{0} {1}", locationZIP, locationCity);
                        }

                        if (orderCustomer != null)
                        {
                            sales.DeliveryNumber = orderCustomer.Number;
                        }
                    }


                    // Order items
                    foreach (var lineItem in order.line_items)
                    {
                        SalesOrderRow salesRow = sales.SalesorderRows.AddNew();
                        salesRow.ArticleCode   = lineItem.sku;
                        salesRow.ArticleName   = lineItem.title;
                        salesRow.Amount        = lineItem.quantity;
                        salesRow.DeliveryStart = orderDeliveryDate;
                        //salesRow.VatPercent = 0;
                        if (lineItem.price.HasValue)
                        {
                            salesRow.UnitPrice = visma.ToPrice(lineItem.price.Value);
                        }
                    }

                    // Shipping items
                    foreach (var lineItem in order.shipping_lines)
                    {
                        SalesOrderRow salesRow = sales.SalesorderRows.AddNew();
                        salesRow.ArticleCode   = "207";
                        salesRow.ArticleName   = lineItem.title.Length <= 50 ? lineItem.title : lineItem.title.Substring(0, 50);
                        salesRow.Amount        = 1; // lineItem.quantity;
                        salesRow.DeliveryStart = orderDeliveryDate;
                        salesRow.VatPercent    = shop.VatRate;
                        if (lineItem.price.HasValue)
                        {
                            salesRow.UnitPrice = visma.ToPrice(lineItem.price.Value);
                        }
                    }

                    // CoD payment method
                    if (sales.TermsOfPaymentId == 20) // TODO: Move value to Shop table
                    {
                        SalesOrderRow salesRow = sales.SalesorderRows.AddNew();
                        salesRow.ArticleCode   = "204";
                        salesRow.ArticleName   = order.gateway.Length <= 50 ? order.gateway : order.gateway.Substring(0, 50);
                        salesRow.Amount        = 1; // lineItem.quantity;
                        salesRow.DeliveryStart = orderDeliveryDate;
                        salesRow.VatPercent    = shop.VatRate;
                        salesRow.UnitPrice     = 5; // TODO: Move value to Shop table
                    }



                    if (orderCustomer == null)
                    {
                    }


                    sales.Save();
                    Log(string.Format(" - Sales Order {0} created from order {1} ({2}). ", sales.Number, order.id, order.name));

                    orderTA.InsertOrder(shop.ID, order.id, sales.Number);
                }
                else
                {
                    Log(string.Format(" - Order {0} ({1}) is already in Visma.", order.id, order.name));
                }
            }

            return(true);
        }
Esempio n. 5
0
        public bool UpdateSpecificPrices(DateTime?startDate, int pricelistrPricesLimit = 50, int customerPricesLimit = 0)
        {
            // Pricelist specific prices

            int pricelistPricesCount = 0;

            Log("\nLoading Pricelist specific prices.");
            StatusUpdate("Updating pricelist specific prices.");

            for (int pricelistNumber = 0; pricelistNumber <= pricelistrPricesLimit; pricelistNumber++)
            {
                try
                {
                    GeneralPricelist generalPricelist = GeneralPricelist.Read(visma._context, pricelistNumber);

                    var filteredPricelist = generalPricelist.Where(x => ((!startDate.HasValue) || (x.EditStamp >= startDate.Value)));

                    if (filteredPricelist.Count() > 0)
                    {
                        Log(string.Format("Pricelist {0} has {1} specific prices.", pricelistNumber, generalPricelist.Count));

                        foreach (PricelistItem pricelistItem in filteredPricelist)
                        {
                            UpdatePricelistItem(pricelistItem, pricelistNumber, null);
                        }
                    }
                    else
                    {
                        //Log(string.Format("No specific prices for Customer {0}.", customerSpecificNumber));
                    }
                }
                catch (Csla.DataPortalException ex)
                {
                    Log(string.Format("Pricelist {0} - no pricelist", pricelistNumber));
                }
            }



            // Customer specific prices

            int customerPricesCount = 0;

            Log("\nLoading Customer specific prices");
            StatusUpdate("Updating customer specific prices.");

            DataSet.CustomerDataTable customerRows = customerTA.GetDataByShopID(shop.ID);
            foreach (var customerRow in customerRows)
            {
                int customerSpecificNumber = customerRow.VismaCustomerNumber;

                CustomerPricelist customerSpecificPricelist = CustomerPricelist.Read(visma._context, customerSpecificNumber);

                var filteredPricelist = customerSpecificPricelist.Where(x => ((!startDate.HasValue) || (x.EditStamp >= startDate.Value)));


                if (filteredPricelist.Count() > 0)
                {
                    Log(string.Format("Customer {0} has {1} specific prices.", customerSpecificNumber, filteredPricelist.Count()));

                    foreach (PricelistItem pricelistItem in filteredPricelist)
                    {
                        UpdatePricelistItem(pricelistItem, null, customerSpecificNumber);
                    }
                }
                else
                {
                    //Log(string.Format("No specific prices for Customer {0}.", customerSpecificNumber));
                }

                customerPricesCount += 1;

                if ((customerPricesLimit > 0) && (customerPricesCount >= customerPricesLimit))
                {
                    break;
                }
            }


            return(true);
        }
Esempio n. 6
0
        public bool UpdateCustomers(DateTime?startDate, int customerLimit = 0)
        {
            int customerCount = 0;

            CustomerList customers = visma.GetCustomerList(startDate);

            Log(string.Format("\n{0} customers found in Visma database.", customers.Count));

            StatusUpdate(string.Format("Updating {0} customers.", customers.Count));


            foreach (CustomerInfo customerInfo in customers)
            {
                int customerNumber = customerInfo.Number;

                // Get full Customer object from Visma
                Customer customer = visma.GetCustomerByNumber(customerNumber);

                Customer invoiceCustomer = null;
                if (customer.InvoiceCustomerID > 0)
                {
                    invoiceCustomer = visma.GetCustomerByNumber(customer.InvoiceCustomerID);
                }

                int contactNumber = 0;

                foreach (Contact contact in customer.Contacts)
                {
                    contactNumber++;

                    Log(string.Format("- Customer {0} - {1} [{2}]", customer.FullName, contactNumber.ToString(), customer.Number));

                    // Save article as Shopify Product
                    string email = contact.Email;


                    if (!string.IsNullOrEmpty(email)) //   && (customerNumber == 28)
                    {
                        DataSet.CustomerDataTable customerDT = customerTA.GetDataByCustomerNumber(shop.ID, customerNumber, contactNumber);

                        try
                        {
                            if (customerDT.Count == 0)
                            {
                                string data = shop.GetCustomerDataFromVismaCustomer(customer, contact, invoiceCustomer, null);
                                //Log(data);
                                object response = shop.CreateCustomer(data);

                                //Log("Response " + response.ToString());
                                JObject customerResponse = JsonConvert.DeserializeObject <JObject>(response.ToString());
                                long    shopifyID        = 0;
                                long    addressID        = 0;
                                long.TryParse(customerResponse["customer"]["id"].ToString(), out shopifyID);
                                long.TryParse(customerResponse["customer"]["default_address"]["id"].ToString(), out addressID);
                                Log(string.Format(" - Shopify Customer [{0}] created.", shopifyID));

                                customerTA.InsertCustomer(shop.ID, shopifyID, customer.Number, addressID, contactNumber);
                            }
                            else
                            {
                                long   shopifyID = customerDT[0].ShopifyCustomerID;
                                long   addressID = customerDT[0].ShopifyAddressID;
                                string data      = shop.GetCustomerDataFromVismaCustomer(customer, contact, invoiceCustomer, addressID);
                                //Log(data);
                                object response = shop.UpdateCustomer(data, shopifyID);

                                Log(string.Format(" - Shopify Customer [{0}] updated.", shopifyID));
                            }
                        }
                        catch (System.Net.WebException ex)
                        {
                            LogError("Unable to create or update Customer", ex);
                        }
                    }
                    else
                    {
                        Log(" - Unable to create customer - No email value");
                    }
                }



                customerCount += 1;

                if ((customerLimit > 0) && (customerCount >= customerLimit))
                {
                    break;
                }
            }


            return(true);
        }