예제 #1
0
 public void UpdateItem(ItemSQLite item)
 {
     lock (locker)
     {
         database.Update(item);
     }
 }
예제 #2
0
        public static Dictionary <string, Stock> GetStock(List <InvoiceSQLite> invoiceSQLite)
        {
            Dictionary <string, Stock> itemDictionary = new Dictionary <string, Stock>();

            foreach (InvoiceSQLite invoice in invoiceSQLite)
            {
                List <LineItemSQLite> lineItemSQLite = App.LineItemDatabase.GetLineItemByInvoiceID(invoice.InvoiceID);
                foreach (LineItemSQLite lineItem in lineItemSQLite)
                {
                    string     codeX      = lineItem.ItemCode;
                    ItemSQLite itemSQLite = App.ItemDatabase.GetItemByID(lineItem.ItemCode);
                    if (!itemDictionary.ContainsKey(codeX))
                    {
                        Stock stock = new Stock(codeX, itemSQLite.Description, itemSQLite.Weight * lineItem.Quantity, lineItem.Quantity);
                        itemDictionary.Add(codeX, stock);
                    }
                    else
                    {
                        itemDictionary[codeX].AddStockQuantity(Convert.ToInt32(lineItem.Quantity));
                        itemDictionary[codeX].Weight += itemSQLite.Weight * lineItem.Quantity;
                    }
                }
            }

            return(itemDictionary);
        }
예제 #3
0
 public void InsertItem(ItemSQLite item)
 {
     lock (locker)
     {
         database.Insert(item);
     }
 }
예제 #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 Task <int> SaveItemAsync(ItemSQLite item)
 {
     if (!string.IsNullOrEmpty(item.ID))
     {
         return(Database.UpdateAsync(item));
     }
     else
     {
         item.ID = Guid.NewGuid().ToString();
         return(Database.InsertAsync(item));
     }
 }
예제 #6
0
 public ItemViewModel(ItemSQLite item)
 {
     Item = item;
     if (string.IsNullOrEmpty(item.ID))
     {
         Text = "Agregar";
     }
     else
     {
         Text     = "Actualizar";
         IsDelete = true;
     }
     UpdateCommand = new Command(OnUpdate);
     DeleteCommand = new Command(OnDelete);
 }
        private void SaveItem()
        {
            int quantityF;

            int.TryParse(QuantityEntry.Text, out quantityF);

            double weightF;

            double.TryParse(WeightEntry.Text, out weightF);

            double unitCostF;

            double.TryParse(UnitPriceEntry.Text, out unitCostF);

            ItemSQLite item = itemsSQLite.Where(
                itemX =>
                itemX.Weight == weightF &&
                itemX.Description == ItemAutoSuggestBox.Text).FirstOrDefault();

            if (item == null)
            {
                item = new ItemSQLite()
                {
                    ItemCode    = DateTime.Now.ToString(),
                    Description = ItemAutoSuggestBox.Text,
                    Weight      = weightF,
                    UnitCost    = unitCostF,
                };
            }
            else if (item.UnitCost == 0 || item.UnitCost != unitCostF)
            {
                item.UnitCost = unitCostF;
            }

            LineItem lineItem = new LineItem()
            {
                ItemCode    = item.ItemCode,
                Description = item.Description,
                Quantity    = quantityF,
                Weight      = item.Weight,
                UnitAmount  = unitCostF
            };

            pickupPage._itemsCollection.Add(lineItem);

            Navigation.PopModalAsync();
        }
예제 #8
0
        private void MapItemList()
        {
            Dictionary <string, Stock> itemDictionary = new Dictionary <string, Stock>();

            List <InvoiceSQLite> invoiceSQLite = App.InvoiceDatabase.GetAllIncompleteInvoices();

            foreach (InvoiceSQLite invoice in invoiceSQLite)
            {
                List <LineItemSQLite> lineItemSQLite = App.LineItemDatabase.GetLineItemByInvoiceID(invoice.InvoiceID);
                foreach (LineItemSQLite lineItem in lineItemSQLite)
                {
                    string     codeX      = lineItem.ItemCode;
                    ItemSQLite itemSQLite = App.ItemDatabase.GetItemByID(lineItem.ItemCode);
                    if (!itemDictionary.ContainsKey(codeX))
                    {
                        Stock stock = new Stock(codeX, itemSQLite.Description, itemSQLite.Weight, lineItem.Quantity);
                        itemDictionary.Add(codeX, stock);
                    }
                    else
                    {
                        itemDictionary[codeX].AddStockQuantity(Convert.ToInt32(lineItem.Quantity));
                        itemDictionary[codeX].AddStockWeight(itemSQLite.Weight);
                    }
                }
            }

            double totalWeight = 0;

            foreach (KeyValuePair <string, Stock> stock in itemDictionary)
            {
                Stock stockX = stock.Value;
                stockX.SetColor();
                _stockInfo.Add(stockX);
                totalWeight += stockX.Weight;
            }
            WeightTotalLabel.Text            = string.Format($"{totalWeight:F2} Kg");
            DeliveryItemListView.ItemsSource = _stockInfo;
        }
        private void BindItemData()
        {
            double itemsSubtotal = 0;
            double GstAmount     = DeliveryAppWhiterocks.Models.Constants.taxAmount;
            double GstTotal      = 0;

            List <LineItemSQLite> lineItems = App.LineItemDatabase.GetLineItemByInvoiceID(_selectedInvoice.InvoiceID);

            foreach (LineItemSQLite lineItemsSql in lineItems)
            {
                ItemSQLite itemSql = App.ItemDatabase.GetItemByID(lineItemsSql.ItemCode);
                LineItem   item    = new LineItem()
                {
                    Description = itemSql.Description,
                    Quantity    = lineItemsSql.Quantity,
                    UnitAmount  = lineItemsSql.UnitAmount,
                    TotalAmount = lineItemsSql.Quantity * lineItemsSql.UnitAmount
                };
                itemsSubtotal += item.TotalAmount;
                _itemsCollection.Add(item);
            }

            GstTotal = GstAmount * itemsSubtotal;
            LineItem GST = new LineItem()
            {
                Description = string.Format("GST: {0} %", GstAmount * 100),
                Quantity    = 1,
                UnitAmount  = GstTotal,
                TotalAmount = GstTotal,
            };

            _itemsCollection.Add(GST);

            LblTotalPrice.Text        = string.Format("{0:F2}", GstTotal + itemsSubtotal);
            ItemsListView.ItemsSource = _itemsCollection;
        }
예제 #10
0
 public Task <int> DeleteItemAsync(ItemSQLite item)
 {
     return(Database.DeleteAsync(item));
 }
예제 #11
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);
        }
예제 #12
0
 public ItemView(ItemSQLite item)
 {
     InitializeComponent();
     BindingContext = viewModel = new ItemViewModel(item);
 }
예제 #13
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);
        }
예제 #14
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();
        }