Exemplo n.º 1
0
        private MYOBCustomer MakeMyobCustomer(MYOBCustomerContact myobCust)
        {
            var myobCustomer = new MYOBCustomer
            {
                CompanyName  = myobCust.CompanyName,
                IsIndividual = myobCust.IsIndividual,
                FirstName    = myobCust.FirstName,
                LastName     = myobCust.LastName,
                Uid          = myobCust.UID
            };

            return(myobCustomer);
        }
Exemplo n.º 2
0
        private static MYOBCustomerContact MakeMyobCustomerContact(MYOBCustomer myobCustomer)
        {
            var myobContact = new MYOBCustomerContact
            {
                CompanyName  = myobCustomer.CompanyName,
                IsIndividual = myobCustomer.IsIndividual,
                FirstName    = myobCustomer.FirstName,
                LastName     = myobCustomer.LastName,
                UID          = myobCustomer.Uid
            };

            return(myobContact);
        }
Exemplo n.º 3
0
        public static CustomerLink MakeCustomerLink(MYOBCustomer customer)
        {
            var c = new CustomerLink
            {
                DisplayID = customer.DisplayID,
                Name      = customer.CompanyName,
                UID       = customer.Uid,
                URI       = new Uri(customer.URI)
            };

            if (c.UID == null)
            {
                throw new Exception($"UID not set for customer {customer.DisplayID}");
            }
            if (c.URI == null)
            {
                throw new Exception($"URI not set for {customer.DisplayID}  ");
            }
            return(c);
        }
Exemplo n.º 4
0
        private static void CopyRecordFromMyob(AMSDbContext connect, MYOBCustomer jtItem, Customer item)
        {
            jtItem.CompanyName  = item.IsIndividual ? HandyContactFunctions.FormattedLastAndFirstName(item.LastName, item.FirstName) : item.CompanyName;
            jtItem.DisplayID    = item.DisplayID;
            jtItem.FirstName    = item.FirstName;
            jtItem.LastName     = item.LastName;
            jtItem.IsIndividual = item.IsIndividual;
            jtItem.IsActive     = item.IsActive;
            jtItem.RowVersion   = item.RowVersion;
            jtItem.Uid          = item.UID;
            jtItem.LastModified = item.LastModified;
            jtItem.URI          = item.URI.ToString();



            if (item.SellingDetails?.InvoiceDelivery != null)
            {
                jtItem.DocumentAction = (DocumentAction)item.SellingDetails.InvoiceDelivery;
            }
            SyncAddresses(connect, jtItem, item);
        }
Exemplo n.º 5
0
        public async void AddItemToMyob(
            AMSDbContext connect,
            MYOBCustomer jtMyobCustomer,
            CompanyFile myCompanyFile,
            CompanyFileCredentials myCredentials,
            CancellationToken ct)
        {
            var item = new Customer
            {
                IsActive    = jtMyobCustomer.IsActive,
                CompanyName = jtMyobCustomer.CompanyName,
                FirstName   = jtMyobCustomer.FirstName,
                LastName    = jtMyobCustomer.LastName
            };

            HandyFunctions.Log(item.ToJson2());
            var   task = _myService.InsertAsync(myCompanyFile, item, myCredentials, ct, ErrorLevel.WarningsAsErrors);
            await task;

            jtMyobCustomer.Uid = item.UID;
            connect.SaveChanges();
        }
Exemplo n.º 6
0
        private static void AddNewUpdateExistingRecords(
            Customer[] ar,
            AMSDbContext connect,
            IProgress <int> progressCallback)
        {
            var sb       = new StringBuilder();
            var info     = "";
            var stepNum  = 1;
            var numSteps = ar.Count();

            foreach (var item in ar)
            {
                if (MakeKey(item) == info)
                {
                    // skip this one
                    //throw new ExceptionDuplicateKey($"Unable to import. Duplicate key exists in MYOB for: {info}");
                    sb.AppendLine(info);
                    continue;
                }
                info = MakeKey(item);
                HandyFunctions.Log(info);
                var jtCustomer = connect.MYOBCustomers.SingleOrDefault(x => x.Uid == item.UID);

                //unique idex should ensure only 1
                if (jtCustomer == null)
                {
                    jtCustomer = new MYOBCustomer();
                    connect.MYOBCustomers.Add(jtCustomer);
                }
                CopyRecordFromMyob(connect, jtCustomer, item);
                progressCallback.Report((100 * stepNum) / numSteps);
                stepNum++;
            }
            connect.SaveChanges();
            if (sb.Length > 0)
            {
                MessageBox.Show("Duplicate customers skipped /n" + sb);
            }
        }
Exemplo n.º 7
0
        private static void SyncAddresses(AMSDbContext connect, MYOBCustomer jtItem, Customer item)
        {
            foreach (var a in jtItem.Addresses)
            {
                a.TaggedToDelete = true;
            }
            if (item.Addresses != null)
            {
                foreach (var address in item.Addresses)
                {
                    var addresses         = jtItem.Addresses.AsQueryable();
                    var tempAddress       = address;
                    var existingAddresses = addresses.Where(x => x.Location == tempAddress.Location).ToArray();
                    if (existingAddresses.Count() == 1)
                    {
                        var existingAddress = existingAddresses[0];
                        ModifyIfNeeded(
                            connect,
                            existingAddress,
                            "ContactName",
                            existingAddress.ContactName,
                            tempAddress.ContactName);
                        ModifyIfNeeded(connect, existingAddress, "Street", existingAddress.Street, tempAddress.Street);
                        ModifyIfNeeded(connect, existingAddress, "City", existingAddress.City, tempAddress.City);
                        ModifyIfNeeded(connect, existingAddress, "State", existingAddress.State, tempAddress.State);
                        ModifyIfNeeded(
                            connect,
                            existingAddress,
                            "Postcode",
                            existingAddress.Postcode,
                            tempAddress.PostCode);
                        ModifyIfNeeded(
                            connect,
                            existingAddress,
                            "Country",
                            existingAddress.Country,
                            tempAddress.Country);
                        ModifyIfNeeded(connect, existingAddress, "Email", existingAddress.Email, tempAddress.Email);
                        ModifyIfNeeded(connect, existingAddress, "Phone1", existingAddress.Phone1, tempAddress.Phone1);
                        ModifyIfNeeded(connect, existingAddress, "Phone2", existingAddress.Phone2, tempAddress.Phone2);
                        ModifyIfNeeded(connect, existingAddress, "Fax", existingAddress.Fax, tempAddress.Fax);
                        ModifyIfNeeded(connect, existingAddress, "WebSite", existingAddress.WebSite, tempAddress.Website);

                        existingAddress.TaggedToDelete = false;
                        if (existingAddress.ContactName != tempAddress.ContactName)
                        {
                            existingAddress.ContactName          = tempAddress.ContactName;
                            connect.Entry(existingAddress).State = EntityState.Modified;
                        }
                    }
                    else
                    {
                        foreach (var duplAddress in existingAddresses)
                        {
                            duplAddress.TaggedToDelete = true;
                        }
                        if (string.IsNullOrEmpty(address.Street))
                        {
                            continue;
                        }
                        var newAddress = new MYOBCustomerAddress();
                        HandyFunctions.PopulateMyobAddress(newAddress, address);
                        jtItem.Addresses.Add(newAddress);
                        newAddress.MyobCustomer = jtItem;
                    }
                }
            }
            var deleteQueue = jtItem.Addresses.Where(x => x.TaggedToDelete).ToArray();

            foreach (var a in deleteQueue)
            {
                var entry = connect.Entry(a);
                entry.State = EntityState.Deleted;
            }
        }