public void InsertContact(ContactSQLite contact)
 {
     lock (locker)
     {
         database.Insert(contact);
     }
 }
 public void UpdateContactPosition(ContactSQLite contact)
 {
     lock (locker)
     {
         database.Update(contact);
     }
 }
Ejemplo n.º 3
0
        } // Mark As Completed

        public void UpdateStatus(Invoice invoiceSelected)
        {
            bool googleAPICallRequired = true;

            _invoicesCollection.Remove(invoiceSelected);
            _invoices.Remove(invoiceSelected);
            DeliveryItemView.ItemsSource = _invoicesCollection;
            Pin thePin = _pins.Where(pinX => pinX.Label == invoiceSelected.InvoiceNumber).FirstOrDefault();

            map.Pins.Remove(thePin);
            _waypoints.Remove($"{thePin.Position.Latitude}%2C{thePin.Position.Longitude}");

            InvoiceSQLite invoiceSQLite = App.InvoiceDatabase.GetInvoiceByInvoiceNumber(invoiceSelected.InvoiceNumber);

            if (invoiceSQLite != null)
            {
                ContactSQLite contact = App.ContactDatabase.GetContactByID(invoiceSQLite.ContactID);
                double        distanceToInvoiceInKm = Location.CalculateDistance(_currentLocation, new Location((double)contact.Latitude, (double)contact.Longitude), DistanceUnits.Kilometers);

                if (distanceToInvoiceInKm * 1000 < 30)
                {
                    googleAPICallRequired = false;
                }
            }

            if (googleAPICallRequired)
            {
                MapDirections("(Force-Refresh) ");
            }
            _counter--;
        }
Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        //get data from database when the order page started
        public void SupplyOrder()
        {
            _deliveryOrders.Clear();
            //load data from database
            List <InvoiceSQLite> invoices = App.InvoiceDatabase.GetAllIncompleteInvoices();

            foreach (InvoiceSQLite invoiceSqlite in invoices)
            {
                if (Constants.TenantID != "" && invoiceSqlite.TenantID != Constants.TenantID)
                {
                    continue;
                }
                ContactSQLite  contactSqlite = App.ContactDatabase.GetContactByID(invoiceSqlite.ContactID);
                List <Address> address       = new List <Address>();
                //add emtpy one to mimic the structure of our xero
                address.Add(new Address());
                if (contactSqlite.City != "")
                {
                    contactSqlite.City = string.Format(", {0}", contactSqlite.City);
                }
                address.Add(new Address()
                {
                    AddressLine1 = contactSqlite.Address, City = contactSqlite.City
                });

                List <Phone> phones = new List <Phone>();
                phones.Add(new Phone());
                phones.Add(new Phone()
                {
                    PhoneNumber = contactSqlite.PhoneNumber
                });
                Contact contact = new Contact()
                {
                    ContactID = contactSqlite.ContactID,
                    Name      = contactSqlite.Fullname,
                    Addresses = address,
                    Phones    = phones,
                };

                Invoice invoice = new Invoice()
                {
                    Type          = invoiceSqlite.InvoiceType,
                    InvoiceID     = invoiceSqlite.InvoiceID,
                    InvoiceNumber = invoiceSqlite.InvoiceNumber,
                    Contact       = contact,
                    TypeColor     = invoiceSqlite.InvoiceType == "ACCREC" ? Constants.IsDropOffColor : Constants.IsPickUpColor,
                    UpdateAppTick = invoiceSqlite.UpdateTimeTicksApp,
                };
                _deliveryOrders.Add(invoice);
            }
            DeliveryInvoice.ItemsSource = _deliveryOrders.OrderByDescending(invoiceX => invoiceX.UpdateAppTick);

            CheckHasDataLabel();
        }
Ejemplo n.º 6
0
        public ContactSQLite PrepareContactSQLite(Contact contact)
        {
            Address       address       = contact.Addresses[1];
            ContactSQLite contactSQLite = new ContactSQLite()
            {
                ContactID  = contact.ContactID,
                Fullname   = contact.Name,
                Address    = (address.AddressLine1.Trim() + " " + address.AddressLine2.Trim() + " " + address.AddressLine3.Trim() + " " + address.AddressLine4.Trim()).Trim(),
                City       = contact.Addresses[1].City,
                PostalCode = contact.Addresses[1].PostalCode,
                Type       = contact.IsCustomer ? ContactType.Customer : ContactType.Supplier
            };

            return(contactSQLite);
        }
        public ContactSQLite PrepareContactSQLite(Contact contact)
        {
            Address address;

            if (contact.Addresses.Count > 1)
            {
                address = contact.Addresses[1];
            }
            else
            {
                address = new Address()
                {
                    AddressLine1 = "",
                    AddressLine2 = "",
                    AddressLine3 = "",
                    AddressLine4 = "",
                    City         = "",
                    PostalCode   = "",
                };
                contact.Addresses.Add(new Address());
                contact.Addresses.Add(address);
            }

            string phoneNumber = "";

            foreach (Phone phone in contact.Phones)
            {
                if (phone.PhoneNumber != "")
                {
                    phoneNumber = phone.PhoneCountryCode + phone.PhoneNumber;
                    break;
                }
            }

            ContactSQLite contactSQLite = new ContactSQLite()
            {
                ContactID   = contact.ContactID,
                Fullname    = contact.Name,
                Address     = (address.AddressLine1.Trim() + " " + address.AddressLine2.Trim() + " " + address.AddressLine3.Trim() + " " + address.AddressLine4.Trim()).Trim(),
                City        = contact.Addresses[1].City,
                PostalCode  = contact.Addresses[1].PostalCode,
                PhoneNumber = phoneNumber,
                Type        = contact.IsCustomer ? ContactType.Customer : ContactType.Supplier
            };

            return(contactSQLite);
        }
Ejemplo n.º 8
0
        } // Mark As Completed

        public bool IsGoogleAPICallRequired(Invoice invoiceSelected)
        {
            bool          googleAPICallRequired = true;
            InvoiceSQLite invoiceSQLite         = App.InvoiceDatabase.GetInvoiceByInvoiceNumber(invoiceSelected.InvoiceNumber);

            if (invoiceSQLite != null)
            {
                ContactSQLite contact = App.ContactDatabase.GetContactByID(invoiceSQLite.ContactID);
                double        distanceToInvoiceInKm = Location.CalculateDistance(_currentLocation, new Location((double)contact.Latitude, (double)contact.Longitude), DistanceUnits.Kilometers);

                if (distanceToInvoiceInKm < 0.045)
                {
                    googleAPICallRequired = false;
                }
            }
            return(googleAPICallRequired);
        }
Ejemplo n.º 9
0
        //get data from database when the order page started
        public void SupplyOrder()
        {
            _deliveryOrders.Clear();
            //load data from database
            //do foreach
            //orderTemp.Add(new OrderTemp("INV-011", "Kappa smith", "Morning rd 132, Otago","30", "BLackstuff", 3, 3.5));
            foreach (InvoiceSQLite invoiceSqlite in App.InvoiceDatabase.GetAllIncompleteInvoices())
            {
                ContactSQLite  contactSqlite = App.ContactDatabase.GetContactByID(invoiceSqlite.ContactID);
                List <Address> address       = new List <Address>();
                //add emtpy one to mimic the structure of our client
                address.Add(new Address());
                if (contactSqlite.City != "")
                {
                    contactSqlite.City = string.Format(", {0}", contactSqlite.City);
                }
                address.Add(new Address()
                {
                    AddressLine1 = contactSqlite.Address, City = contactSqlite.City
                });

                Contact contact = new Contact()
                {
                    ContactID = contactSqlite.ContactID,
                    Name      = contactSqlite.Fullname,
                    Addresses = address
                };

                Invoice invoice = new Invoice()
                {
                    Type          = invoiceSqlite.InvoiceType,
                    InvoiceID     = invoiceSqlite.InvoiceID,
                    InvoiceNumber = invoiceSqlite.InvoiceNumber,
                    Contact       = contact,
                    TypeColor     = contactSqlite.Type == ContactType.Customer ? Constants.IsDropOffColor : Constants.IsPickUpColor
                };
                _deliveryOrders.Add(invoice);
            }
            DeliveryInvoice.ItemsSource = _deliveryOrders;
        }
Ejemplo n.º 10
0
        public ContactDetailPage(ContactSQLite contact)
        {
            // Note the use of nameof() operator in C# 6.
            if (contact == null)
            {
                throw new ArgumentNullException(nameof(contact));
            }

            InitializeComponent();

            _connection = DependencyService.Get <ISQLiteDb>().GetConnection();

            //crea un nuevo objeto para que no se pierdan los cambios si vuelve sin grabar.
            //Requiere los eventos para notificar cuando hay cambios.
            BindingContext = new ContactSQLite
            {
                Id        = contact.Id,
                FirstName = contact.FirstName,
                LastName  = contact.LastName,
                Phone     = contact.Phone,
                Email     = contact.Email,
                IsBlocked = contact.IsBlocked
            };
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        //initialize markers on map and position into _waypoints
        private async Task <bool> InitPins()
        {
            _pins.Clear();
            map.Pins.Clear();
            _waypoints.Clear();

            for (int i = 0; i < _invoiceSQLite.Count; i++)
            {
                ContactSQLite customerContact = App.ContactDatabase.GetContactByID(_invoiceSQLite[i].ContactID);
                Position      position;

                if (!customerContact.Latitude.HasValue)
                {
                    //Get better format from address
                    #region Format the Address
                    string fullAddress = customerContact.Address;
                    if (fullAddress == "")
                    {
                        continue;
                    }
                    else if (customerContact.City != "")
                    {
                        fullAddress += $", {customerContact.City}";
                    }
                    fullAddress += $", New Zealand";
                    #endregion

                    if (App.CheckIfInternet())
                    {
                        //Get location by calling google geolocation API / each invoice
                        position = await GoogleMapsAPI.GetPositionFromKnownAddress(fullAddress);

                        customerContact.Latitude  = position.Latitude;
                        customerContact.Longitude = position.Longitude;
                    }
                    else
                    {
                        try {
                            Location location = Geocoding.GetLocationsAsync(fullAddress).Result.FirstOrDefault();
                            position = new Position(location.Latitude, location.Longitude);
                            customerContact.Latitude  = position.Latitude;
                            customerContact.Longitude = position.Longitude;
                        }
                        catch
                        {
                            position = new Position(0, 0);
                            await DisplayAlert("Alert", String.Format("Couldnt map the position of {0}", _invoiceSQLite[i].InvoiceNumber), "OK");
                        }
                    }

                    if (customerContact.Latitude.HasValue)
                    {
                        App.ContactDatabase.UpdateContactPosition(customerContact);
                    }
                }
                else
                {
                    position = new Position(customerContact.Latitude.Value, customerContact.Longitude.Value);
                }

                if (position.Latitude != 0 && position.Longitude != 0)
                {
                    //Add it to the waypoints list later to be used on the googleDirection API
                    //Formatted by Comma separator for latitude,longitude
                    _waypoints.Add($"{position.Latitude}%2C{position.Longitude}");

                    //Set pin on map
                    #region SetPin
                    var pin = new Pin()
                    {
                        Position = position,
                        Label    = $"{_invoiceSQLite[i].InvoiceNumber}",
                        //set tag so i can reference it when a pin is clicked
                        Tag  = _invoiceSQLite[i].InvoiceID,
                        Icon = BitmapDescriptorFactory.FromBundle(_invoiceSQLite[i].InvoiceType),
                    };
                    pin.Address = "Click for Details";
                    _pins.Add(pin);

                    map.SelectedPinChanged += Map_SelectedPinChanged;
                    map.InfoWindowClicked  += Map_InfoWindowClicked;
                    map.Pins.Add(pin);
                    #endregion

                    _invoices.Add(_storageInvoice[i]);
                }
            }
            return(true);
        }
Ejemplo n.º 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();
        }