public void UpdateLineItem(LineItemSQLite lineItemSQLite)
 {
     lock (locker)
     {
         database.Update(lineItemSQLite);
     }
 }
 public void DeleteLineItem(LineItemSQLite itemLine)
 {
     lock (locker)
     {
         database.Delete(itemLine);
     }
 }
 public void InsertLineItem(LineItemSQLite lineItem)
 {
     lock (locker)
     {
         database.Insert(lineItem);
     }
 }
Пример #4
0
        public void InsertInvoice(InvoiceSQLite invoice, List <LineItem> lineitem, Contact contact)
        {
            lock (locker)
            {
                database.Insert(invoice);
                //create LineItem to associate it with the invoice

                if (!App.ContactDatabase.CheckContactIfExisted(contact.ContactID))
                {
                    ContactSQLite contactSQLite = App.ContactDatabase.PrepareContactSQLite(contact);
                    App.ContactDatabase.InsertContact(contactSQLite);
                }

                //sort desc by ID, get the first one (biggest id number)
                var maxItemLineID = App.LineItemDatabase.GetLastLineItem();
                int itemLineID    = maxItemLineID == null ? 1 : maxItemLineID.ItemLineID;

                foreach (LineItem item in lineitem)
                {
                    itemLineID++;
                    //create the id by referencing lineitemtable
                    LineItemSQLite lineItemSQLite = new LineItemSQLite()
                    {
                        // if it's not set set the itemline id to 1 else increment 1 from the biggest value
                        ItemLineID = itemLineID,
                        InvoiceID  = invoice.InvoiceID,
                        ItemCode   = item.ItemCode,
                        Quantity   = (int)item.Quantity,
                        UnitAmount = item.UnitAmount,
                    };
                    //Save to db
                    App.LineItemDatabase.InsertLineItem(lineItemSQLite);

                    ItemSQLite itemSQLite = App.ItemDatabase.GetItemByID(item.ItemCode);
                    //check if item already exist, if not add it into database
                    if (itemSQLite == null)
                    {
                        ItemSQLite newItem = new ItemSQLite()
                        {
                            ItemCode        = item.ItemCode,
                            Description     = item.Description,
                            Weight          = item.Weight,
                            UnitCost        = invoice.InvoiceType == "ACCPAY" ? item.UnitAmount : 0,
                            UpdateTimeTicks = invoice.UpdateTimeTicksXERO,
                        };
                        App.ItemDatabase.InsertItem(newItem);
                    }
                    else if (invoice.UpdateTimeTicksXERO > itemSQLite.UpdateTimeTicks)
                    {
                        itemSQLite.Weight          = item.Weight;
                        itemSQLite.Description     = item.Description;
                        itemSQLite.UnitCost        = invoice.InvoiceType == "ACCPAY" ? item.UnitAmount : 0;
                        itemSQLite.UpdateTimeTicks = invoice.UpdateTimeTicksXERO;
                        App.ItemDatabase.UpdateItem(itemSQLite);
                    }
                }
            }
        }
Пример #5
0
        public static async Task <bool> FillData()
        {
            var tenantID = Preferences.Get("TenantID", string.Empty);
            Dictionary <string, InvoiceSQLite> allInvoicesInDatabase = App.InvoiceDatabase.GetAllInvoices().ToDictionary(invX => invX.InvoiceID, invX => invX);

            for (int i = 0; i < _InvoiceResponse.Invoices.Count; i++)
            {
                InvoiceSQLite invoiceInDatabase = null;

                if (allInvoicesInDatabase.ContainsKey(_InvoiceResponse.Invoices[i].InvoiceID))
                {
                    invoiceInDatabase = allInvoicesInDatabase[_InvoiceResponse.Invoices[i].InvoiceID];
                    allInvoicesInDatabase.Remove(_InvoiceResponse.Invoices[i].InvoiceID);
                }

                if (invoiceInDatabase != null && invoiceInDatabase.CompletedDeliveryStatus)
                {
                    continue;
                }

                if (_InvoiceResponse.Invoices[i].Status == "AUTHORISED" || _InvoiceResponse.Invoices[i].Status == "PAID")
                {
                    await FillItems(_InvoiceResponse.Invoices[i], i);
                    await FillContactAddress(_InvoiceResponse.Invoices[i].Contact, i);

                    //Insert data normally if the data doesnt exist else check for update
                    if (invoiceInDatabase == null)
                    {
                        InvoiceSQLite invoiceSqlite = new InvoiceSQLite()
                        {
                            InvoiceType             = _InvoiceResponse.Invoices[i].Type,
                            InvoiceID               = _InvoiceResponse.Invoices[i].InvoiceID,
                            TenantID                = tenantID,
                            InvoiceNumber           = _InvoiceResponse.Invoices[i].InvoiceNumber,
                            CompletedDeliveryStatus = false,
                            ContactID               = _InvoiceResponse.Invoices[i].Contact.ContactID,
                            Subtotal                = _InvoiceResponse.Invoices[i].SubTotal,
                            UpdateTimeTicksXERO     = _InvoiceResponse.Invoices[i].UpdatedDateUTC.Ticks,
                            UpdateTimeTicksApp      = _InvoiceResponse.Invoices[i].UpdatedDateUTC.Ticks,
                        };
                        App.InvoiceDatabase.InsertInvoice(invoiceSqlite, _InvoiceResponse.Invoices[i].LineItems, _InvoiceResponse.Invoices[i].Contact);
                    }
                    else
                    {
                        ContactSQLite contactInDatabase = App.ContactDatabase.GetContactByID(invoiceInDatabase.ContactID);
                        ContactSQLite newContact        = App.ContactDatabase.PrepareContactSQLite(_InvoiceResponse.Invoices[i].Contact);

                        if (contactInDatabase.Address != newContact.Address || contactInDatabase.Fullname != newContact.Fullname ||
                            contactInDatabase.City != newContact.City || contactInDatabase.PhoneNumber != newContact.PhoneNumber)
                        {
                            App.ContactDatabase.UpdateContactPosition(newContact);
                        }


                        if (_InvoiceResponse.Invoices[i].UpdatedDateUTC.Ticks == invoiceInDatabase.UpdateTimeTicksXERO)
                        {
                            continue;
                        }

                        if (invoiceInDatabase.InvoiceNumber != _InvoiceResponse.Invoices[i].InvoiceNumber)
                        {
                            invoiceInDatabase.InvoiceNumber = _InvoiceResponse.Invoices[i].InvoiceNumber;
                        }
                        invoiceInDatabase.UpdateTimeTicksXERO = _InvoiceResponse.Invoices[i].UpdatedDateUTC.Ticks;
                        App.InvoiceDatabase.UpdateInvoiceNumber(invoiceInDatabase);

                        List <LineItemSQLite> lineItemSQLiteList = App.LineItemDatabase.GetLineItemByInvoiceID(_InvoiceResponse.Invoices[i].InvoiceID);

                        var maxItemLineID = App.LineItemDatabase.GetLastLineItem();
                        int itemLineID    = maxItemLineID == null ? 1 : maxItemLineID.ItemLineID;

                        foreach (LineItem lineItem in _InvoiceResponse.Invoices[i].LineItems)
                        {
                            ItemSQLite itemSQLite = App.ItemDatabase.GetItemByID(lineItem.ItemCode);
                            if (itemSQLite == null)
                            {
                                ItemSQLite newItem = new ItemSQLite()
                                {
                                    ItemCode    = lineItem.ItemCode,
                                    Description = lineItem.Description,
                                    Weight      = lineItem.Weight,
                                };
                                if (_InvoiceResponse.Invoices[i].Type == "ACCPAY")
                                {
                                    newItem.UnitCost = lineItem.UnitAmount;
                                }
                                App.ItemDatabase.InsertItem(newItem);

                                itemLineID++;
                                //create the id by referencing lineitemtable
                                LineItemSQLite lineItemSQLite = new LineItemSQLite()
                                {
                                    // if it's not set set the itemline id to 1 else increment 1 from the biggest value
                                    ItemLineID = itemLineID,
                                    InvoiceID  = _InvoiceResponse.Invoices[i].InvoiceID,
                                    ItemCode   = lineItem.ItemCode,
                                    Quantity   = (int)lineItem.Quantity,
                                    UnitAmount = lineItem.UnitAmount,
                                };
                                //Save to db
                                App.LineItemDatabase.InsertLineItem(lineItemSQLite);
                            }
                            else
                            {
                                itemSQLite.Description = lineItem.Description;
                                itemSQLite.ItemCode    = lineItem.ItemCode;
                                itemSQLite.Weight      = lineItem.Weight;
                                if (_InvoiceResponse.Invoices[i].Type == "ACCPAY")
                                {
                                    itemSQLite.UnitCost = lineItem.UnitAmount;
                                }
                                App.ItemDatabase.UpdateItem(itemSQLite);
                                LineItemSQLite theLineItem = lineItemSQLiteList.Where(lineItemX => lineItemX.ItemCode == lineItem.ItemCode).FirstOrDefault();
                                if (theLineItem == null)
                                {
                                    itemLineID++;
                                    //create the id by referencing lineitemtable
                                    theLineItem = new LineItemSQLite()
                                    {
                                        // if it's not set set the itemline id to 1 else increment 1 from the biggest value
                                        ItemLineID = itemLineID,
                                        InvoiceID  = _InvoiceResponse.Invoices[i].InvoiceID,
                                        ItemCode   = lineItem.ItemCode,
                                        Quantity   = (int)lineItem.Quantity,
                                        UnitAmount = lineItem.UnitAmount,
                                    };
                                    //Save to db
                                    App.LineItemDatabase.InsertLineItem(theLineItem);
                                }
                                else
                                {
                                    theLineItem.Quantity   = (int)lineItem.Quantity;
                                    theLineItem.UnitAmount = lineItem.UnitAmount;
                                    App.LineItemDatabase.UpdateLineItem(theLineItem);
                                    lineItemSQLiteList.Remove(theLineItem);
                                }
                            }
                        }

                        if (lineItemSQLiteList.Count > 0)
                        {
                            foreach (LineItemSQLite lineItemSQLite in lineItemSQLiteList)
                            {
                                App.LineItemDatabase.DeleteLineItem(lineItemSQLite);
                            }
                        }
                    }
                }
                else if (_InvoiceResponse.Invoices[i].Status == "VOIDED" && invoiceInDatabase != null)
                {
                    App.InvoiceDatabase.DeleteInvoiceByInvoice(invoiceInDatabase);
                }
            }
            return(true);
        }
Пример #6
0
        public static async Task <bool> FillData()
        {
            for (int i = 0; i < _InvoiceResponse.Invoices.Count; i++)
            {
                InvoiceSQLite invoiceInDatabase = App.InvoiceDatabase.GetInvoiceByInvoiceID(_InvoiceResponse.Invoices[i].InvoiceID);

                if (invoiceInDatabase != null && invoiceInDatabase.CompletedDeliveryStatus)
                {
                    continue;
                }

                if (_InvoiceResponse.Invoices[i].Status == "AUTHORISED" || _InvoiceResponse.Invoices[i].Status == "PAID")
                {
                    await FillItems(_InvoiceResponse.Invoices[i], i);
                    await FillContactAddress(_InvoiceResponse.Invoices[i].Contact, i);

                    InvoiceSQLite invoiceSqlite = new InvoiceSQLite()
                    {
                        InvoiceType             = _InvoiceResponse.Invoices[i].Type,
                        InvoiceID               = _InvoiceResponse.Invoices[i].InvoiceID,
                        InvoiceNumber           = _InvoiceResponse.Invoices[i].InvoiceNumber,
                        CompletedDeliveryStatus = false,
                        ContactID               = _InvoiceResponse.Invoices[i].Contact.ContactID,
                        Subtotal = _InvoiceResponse.Invoices[i].SubTotal
                    };

                    //Insert data normally if the data doesnt exist else check for update
                    if (invoiceInDatabase == null)
                    {
                        App.InvoiceDatabase.InsertInvoice(invoiceSqlite, _InvoiceResponse.Invoices[i].LineItems, _InvoiceResponse.Invoices[i].Contact);
                    }
                    else
                    {
                        ContactSQLite contactInDatabase = App.ContactDatabase.GetContactByID(invoiceInDatabase.ContactID);
                        ContactSQLite newContact        = App.ContactDatabase.PrepareContactSQLite(_InvoiceResponse.Invoices[i].Contact);

                        if (contactInDatabase.Address != newContact.Address)
                        {
                            App.ContactDatabase.UpdateContactPosition(newContact);
                        }

                        List <LineItemSQLite> lineItemSQLiteList = App.LineItemDatabase.GetLineItemByInvoiceID(_InvoiceResponse.Invoices[i].InvoiceID);

                        foreach (LineItem lineItem in _InvoiceResponse.Invoices[i].LineItems)
                        {
                            //check if item already exist, if not add it into database
                            ItemSQLite itemSQLite = App.ItemDatabase.GetItemByID(lineItem.ItemCode);
                            if (itemSQLite == null)
                            {
                                ItemSQLite newItem = new ItemSQLite()
                                {
                                    ItemCode    = lineItem.ItemCode,
                                    Description = lineItem.Description,
                                    Weight      = lineItem.Weight
                                };
                                App.ItemDatabase.InsertItem(newItem);
                            }
                            else if (itemSQLite.Weight != lineItem.Weight)
                            {
                                itemSQLite.Weight      = lineItem.Weight;
                                itemSQLite.Description = lineItem.Description;
                                App.ItemDatabase.UpdateItem(itemSQLite);
                            }

                            LineItemSQLite lineItemSQLite = lineItemSQLiteList.Where(lineItemX => lineItemX.ItemCode == lineItem.ItemCode).FirstOrDefault();
                            if (lineItemSQLite == null)
                            {
                                continue;
                            }
                            if (lineItemSQLite.UnitAmount != lineItem.UnitAmount || lineItemSQLite.Quantity != lineItemSQLite.Quantity)
                            {
                                lineItemSQLite.UnitAmount = lineItem.UnitAmount;
                                lineItemSQLite.Quantity   = (int)lineItem.Quantity;
                                App.LineItemDatabase.UpdateLineItem(lineItemSQLite);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Пример #7
0
        private void SavePickupButton_Clicked(object sender, EventArgs e)
        {
            if (!ValidateInput())
            {
                DisplayAlert("Alert", "Please Fill All the Input Field", "OK");
                return;
            }

            int           pickupInvoiceCount = App.InvoiceDatabase.CountPickupInvoice();
            ContactSQLite contact            = App.ContactDatabase.GetContactByName(ContactAutoSuggestBox.Text);

            if (contact == null)
            {
                contact = new ContactSQLite()
                {
                    ContactID = DateTime.Now.ToString(),
                    Fullname  = ContactAutoSuggestBox.Text,
                    City      = CityEntry.Text,
                    Type      = ContactType.Supplier,
                    Address   = AddressEntry.Text,
                };
                App.ContactDatabase.InsertContact(contact);
            }

            InvoiceSQLite invoice = new InvoiceSQLite()
            {
                InvoiceID               = DateTime.Now.ToString(),
                InvoiceNumber           = "OPC-" + pickupInvoiceCount,
                InvoiceType             = "ACCPAY",
                CompletedDeliveryStatus = false,
                ContactID               = contact.ContactID,
                TenantID           = Preferences.Get("TenantID", string.Empty),
                UpdateTimeTicksApp = DateTime.Now.Ticks,
            };

            App.InvoiceDatabase.InsertInvoice(invoice);

            foreach (LineItem item in _itemsCollection)
            {
                var maxItemLineID = App.LineItemDatabase.GetLastLineItem();
                //create the id by referencing lineitemtable
                LineItemSQLite lineItemSQLite = new LineItemSQLite()
                {
                    // if it's not set set the itemline id to 1 else increment 1 from the biggest value
                    ItemLineID = (maxItemLineID == null ? 1 : maxItemLineID.ItemLineID + 1),
                    InvoiceID  = invoice.InvoiceID,
                    ItemCode   = item.ItemCode,
                    Quantity   = (int)item.Quantity,
                    UnitAmount = item.UnitAmount,
                };
                //Save to db
                App.LineItemDatabase.InsertLineItem(lineItemSQLite);

                //check if item already exist, if not add it into database

                if (!App.ItemDatabase.CheckIfExisted(item.ItemCode))
                {
                    ItemSQLite newItem = new ItemSQLite()
                    {
                        ItemCode    = item.ItemCode,
                        Description = item.Description,
                        Weight      = item.Weight,
                        UnitCost    = item.UnitAmount
                    };
                    App.ItemDatabase.InsertItem(newItem);
                }
            }

            Navigation.PopModalAsync();
        }