private void ExportSoldItemInfoToExcel()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "Excel File (*.xlsx)|*.xlsx";
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            saveFileDialog.FileName         = "Stock-Info-Sold-Items-Report-" + SelectedStockReportFirstDate.ToString("yyyy-MM-dd-h-mm-ss-tt")
                                              + "-" + SelectedStockReportSecondDate.ToString("yyyy-MM-dd-h-mm-ss-tt");
            var lastExcelLocation = Properties.Settings.Default.LastExcelReportSaveLocation;

            if (!string.IsNullOrWhiteSpace(lastExcelLocation) && Directory.Exists(Path.GetDirectoryName(lastExcelLocation)))
            {
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.InitialDirectory = lastExcelLocation;
            }
            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    var soldItemIDs = ItemSoldInfo.LoadItemIDsSoldBetweenDateAndItemUntilDate(SelectedStockReportFirstDate, SelectedStockReportSecondDate);
                    // we only want items in the excel sheet that have been sold in between the two dates
                    var soldItemIDHashSet = new HashSet <int>(soldItemIDs);
                    var itemsToExport     = DetailedStockReport.Where(x => soldItemIDHashSet.Contains(x.Item.ID));
                    // export data to excel
                    var excelGenerator = new StockInfoExcelGenerator();
                    excelGenerator.ExportStockInfo(itemsToExport.ToList(), SelectedStockReportFirstDate, SelectedStockReportSecondDate, saveFileDialog.FileName);
                    Properties.Settings.Default.LastExcelReportSaveLocation = Path.GetDirectoryName(saveFileDialog.FileName);
                }
                catch (Exception)
                {
                    MessageBox.Show("Error generating file! Please make sure to close the file with the same name" +
                                    " if it is open in Excel or other software before generating a file report.", "Error!", MessageBoxButton.OK);
                }
            }
        }
예제 #2
0
        public void DeleteItemSoldInfo(ItemSoldInfo info)
        {
            var item = InventoryItem.LoadItemByID(info.InventoryItemID);

            item.AdjustQuantityByAmount(info.QuantitySold);
            info.Delete();
            ItemSoldInfoData.Remove(info);
            ReportForItem = DeletedItemSoldInfoListener?.ItemSoldInfoWasDeleted(info);
            if (ReportForItem == null)
            {
                PopViewModel();
            }
        }
예제 #3
0
        private void LoadData()
        {
            int userID = _userToFilterBy == null ? -1 : _userToFilterBy.ID;

            if (_endDate != null && _endDate > _startDate && _startDate.Date != _endDate?.Date)
            {
                ItemSoldInfoData = new ObservableCollection <ItemSoldInfo>(ItemSoldInfo.LoadInfoForDateAndItemUntilDate(_startDate, _endDate.Value,
                                                                                                                        _inventoryItemID, userID));
            }
            else
            {
                ItemSoldInfoData = new ObservableCollection <ItemSoldInfo>(ItemSoldInfo.LoadInfoForDateAndItem(_startDate, _inventoryItemID, userID));
            }
        }
        /// <summary>
        /// returns null if no updated report (e.g. you deleted the last item of that type that was sold)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ReportItemSold ItemSoldInfoWasDeleted(ItemSoldInfo model)
        {
            // need to rerun all reports!!
            RunDayReport();
            RunWeeklyReport();
            RunStockReport();
            ReportItemSold report     = null;
            var            reportList = _isViewingDailyReportInfo ? CurrentDaySalesReport.ItemsSold : CurrentWeeklySalesReport.AllItemsSold;

            foreach (ReportItemSold itemReport in reportList)
            {
                if (itemReport.InventoryItemID == _lastDailyReportInfoInventoryID)
                {
                    report = itemReport;
                    break;
                }
            }
            return(report);
        }
예제 #5
0
 private void CheckBeforeDeletingItemSoldInfo(ItemSoldInfo item)
 {
     DeleteItemSoldInfoConfirmer?.ConfirmDelete(item);
 }
예제 #6
0
 private void ItemWasPurchased()
 {
     if (!string.IsNullOrWhiteSpace(BarcodeNumber))
     {
         var item = InventoryItem.LoadItemByBarcode(BarcodeNumber);
         if (item != null)
         {
             if (item.Quantity <= 0)
             {
                 ItemPurchaseStatusBrush   = new SolidColorBrush(Colors.Red);
                 ItemPurchaseStatusMessage = "There are no items left to purchase for this item! Barcode: " + BarcodeNumber;
                 PurchaseInfoIsVisible     = false;
                 // play failure sound
                 _failureSoundPlayer.Play();
             }
             else
             {
                 _hasPaidAmountChangedForCurrentItem = false;
                 ItemPurchaseStatusBrush             = new SolidColorBrush(Colors.Green);
                 ItemPurchaseStatusMessage           = "Item successfully found and purchased! Barcode: " + BarcodeNumber;
                 PurchasedItem = item;
                 // create purchase data object and save to the db
                 var purchaseData = new ItemSoldInfo();
                 purchaseData.DateTimeSold    = DateTime.Now;
                 DateTimePurchased            = purchaseData.DateTimeSold.ToString("dddd, d MMMM 'at' h:mm:ss tt");
                 purchaseData.InventoryItemID = item.ID;
                 purchaseData.QuantitySold    = 1;
                 var userID = CurrentUser != null ? CurrentUser.ID : 1;
                 purchaseData.SoldByUserID          = userID;
                 purchaseData.Cost                  = item.Cost;
                 purchaseData.CostCurrency          = item.CostCurrency;
                 purchaseData.Paid                  = item.Cost; // default the amount the user paid to the exact cost
                 purchaseData.PaidCurrency          = item.CostCurrency;
                 purchaseData.Change                = 0;         // by default, no change
                 purchaseData.ChangeCurrency        = item.CostCurrency;
                 purchaseData.ProfitPerItem         = item.ProfitPerItem;
                 purchaseData.ProfitPerItemCurrency = item.ProfitPerItemCurrency;
                 purchaseData.CreateNewSoldInfo();
                 PurchaseInfo = purchaseData;
                 // decrease quantity by 1
                 _amountInventoryChanged = 1;
                 item.AdjustQuantityByAmount(-_amountInventoryChanged);
                 // show info to the user for possible future editing
                 ChangeNeeded = "0"; // TODO: update if paid updated -- might want to bind to a different property for set {} updates
                 SelectedChangeCurrencyIndex = _currencyIDToIndex[purchaseData.ChangeCurrency.ID];
                 SelectedPaidCurrencyIndex   = _currencyIDToIndex[purchaseData.PaidCurrency.ID];
                 Quantity = 1;
                 PurchaseInfoIsVisible = true;
                 // play success sound
                 _successSoundPlayer.Play();
             }
         }
         else
         {
             ItemPurchaseStatusBrush   = new SolidColorBrush(Colors.Red);
             ItemPurchaseStatusMessage = "Item not found! Barcode: " + BarcodeNumber;
             PurchaseInfoIsVisible     = false;
             // play failure sound
             _failureSoundPlayer.Play();
         }
     }
     BarcodeNumber        = ""; // empty the field so that something can be scanned again
     QuantityErrorMessage = "";
 }