Beispiel #1
0
 private void setNextMonth()
 {
     SelectedMonth = SelectedMonth.AddMonths(1);
     RaisePropertyChanged("SelectedMonth");
     RaisePropertyChanged("SelectedMonthStr");
     RaisePropertyChanged("RelativeSelectedMonth");
 }
Beispiel #2
0
        private bool IsCheckedSelectedMonthForMonthRecords(Record record)
        {
            var prevMonth = SelectedMonth.AddMonths(-1);

            while (prevMonth.Date.DayOfWeek != DayOfWeek.Monday)
            {
                prevMonth = prevMonth.AddDays(-1);
            }

            var nextMonth = SelectedMonth.AddMonths(1);

            while (nextMonth.Date.DayOfWeek != DayOfWeek.Sunday)
            {
                nextMonth = nextMonth.AddDays(1);
            }

            if (prevMonth <= record.Date && record.Date <= nextMonth)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void DrawBarChart()
        {
            List <BarEntry> datalist = new List <BarEntry>();

            labelnames = new List <string>();
            for (int i = 0; i < lstbarChartData.Count; i++)
            {
                string month = lstbarChartData[i].Month;
                double total = lstbarChartData[i].Total;
                datalist.Add(new BarEntry(i, (float)total));
                labelnames.Add(month);
            }
            var SelectedMonthindex = labelnames.IndexOf(SelectedMonth.Substring(0, 3));

            int[] colors = new int[12];
            for (int i = 0; i < labelnames.Count; i++)
            {
                if (i == SelectedMonthindex)
                {
                    colors[i] = Android.Graphics.Color.ParseColor("#efbe5d");
                }
                else
                {
                    colors[i] = Android.Graphics.Color.ParseColor("#204060");
                }
            }


            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            MikePhil.Charting.Data.BarDataSet barDataSet = new MikePhil.Charting.Data.BarDataSet(datalist, "Months");
            barDataSet.SetColors(colors);
            barDataSet.ValueTextSize = 8.5f;
            BarData barData = new BarData(barDataSet);

            barData.HighlightEnabled = false;
            barchartStats.Data       = barData;

            // YAxis yAxis = barchartStats.AxisLeft;
            // yAxis.ValueFormatter = new IndexAxisValueFormatter(labelnames);
            XAxis xAxis = barchartStats.XAxis;

            xAxis.ValueFormatter = new IndexAxisValueFormatter(labelnames);

            xAxis.Position = XAxis.XAxisPosition.Top;
            xAxis.YOffset  = -4f;
            xAxis.SetDrawAxisLine(false);
            xAxis.SetDrawGridLines(false);
            xAxis.Granularity = 1f;
            xAxis.SetLabelCount(lstbarChartData.Count, false);
            xAxis.LabelRotationAngle = 270f;
            barchartStats.AnimateY(1000);

            barchartStats.Invalidate();

            progressBarStats.Visibility = ViewStates.Invisible;
            barchartStats.Visibility    = ViewStates.Visible;
            statsdata.Visibility        = ViewStates.Invisible;
            statstype.Text = "Total expense for the year" + "(" + SelectedYear + ")" + " = " + prefs.GetString("CurrencySymbolSelected", "") + lstbarChartData.Sum(x => Convert.ToDouble(x.Total));
        }
Beispiel #4
0
        /// <summary>
        /// Takes the month selected and stores it in a varaible reformting the string so that it always repsresents the month as the first day of the month selected
        /// </summary>
        /// <param></param>
        /// <returns>The selected month as a string</returns>
        protected void calDate_SelectionChanged(object sender, EventArgs e)
        {
            string SelectedMonth;

            SelectedMonth         = calDate.SelectedDate.ToString("d");
            SelectedMonth         = "01" + SelectedMonth.Substring(2, 8);
            txtDate.Text          = SelectedMonth;
            dateField.Style.Value = "display:none;";
        }
Beispiel #5
0
        /// <summary>
        /// Takes the month selected and stores it in a varaible reformating the string so that it always repsresents the month as the first day of the month selected
        /// </summary>
        /// <param></param>
        /// <returns>The selected month as a string</returns>
        protected void calDate_SelectionChanged(object sender, EventArgs e)
        {
            //Clear the validation text in case a previous selection caused an error message
            validateTxtDate.Text = "";

            string SelectedMonth;

            SelectedMonth         = calDate.SelectedDate.ToString("d");
            SelectedMonth         = "01" + SelectedMonth.Substring(2, 8);
            txtDate.Text          = SelectedMonth;
            dateField.Style.Value = "display:none;";
        }
 public void SetupMonthSpinner()
 {
     adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, months);
     adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
     monthspinner.Adapter       = adapter;
     monthspinner.ItemSelected += Monthspinner_ItemSelected;
     if (SelectedMonth != null)
     {
         int spinnerPosition = adapter.GetPosition(SelectedMonth.Substring(0, 3));
         monthspinner.SetSelection(spinnerPosition);
     }
 }
 public void LoadCardsOnPopup(PaymentListModel paymentListModel)
 {
     Number        = (paymentListModel.CARD_NUMBER ?? "").ToString();
     Chname        = paymentListModel.CARD_HOLDER_NAME;
     SelectedMonth = paymentListModel.CARD_EXP_DATE;
     if (!(SelectedMonth == null))
     {
         SelectedMonth = SelectedMonth.Substring(0, 2);
     }
     SelectedYear = paymentListModel.CARD_EXP_DATE;
     if (!(SelectedYear == null))
     {
         SelectedYear = "20" + SelectedYear.Substring(2, 2);
     }
 }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TesterViewModel"/> class.
        /// </summary>
        public TesterViewModel()
        {
            _selectedExportType = ExportType.BooksToCsv;
            _outputFile         = string.Empty;
            SetupExportTypesByTitle();
            LastMonth     = DateTime.Now;
            SelectedMonth = LastMonth.AddDays(-2);
            FirstMonth    = SelectedMonth.AddDays(-2);

            _selectedImportType = ImportType.BooksFromCsv;
            _inputFile          = string.Empty;
            SetupImportTypesByTitle();
            ImportDataTable = new DataTable();

            _countryCodesReadFromDatabase
                = new ObservableCollection <CountryCodeIso3166>();
        }
        private void FilterByMonth(object sender, FilterEventArgs e)
        {
            // see Notes on Filter Methods:
            var src = e.Item as RouteVideoViewModel;

            if (src == null)
            {
                e.Accepted = false;
            }
            else if (_monthListFirstItem != null && SelectedMonth == _monthListFirstItem)
            {
                e.Accepted = true;
            }
            else if (SelectedMonth.CompareTo(src.CreateDT.Month.ToString(MonthToStringFormat)) != 0)
            {
                e.Accepted = false;
            }
        }
        private IEnumerable <CategoryAmount> calculateSelectedMonthData(FinanceDb db)
        {
            var search = new Search()
            {
                DateFrom = SelectedMonth.ToDateTime(MonthAndYear.PositionInMonth.Start),
                DateTo   = SelectedMonth.ToDateTime(MonthAndYear.PositionInMonth.End),
            };
            var selectedMonthTotals = db.Transactions
                                      .Where(search.IsMatch())
                                      .GroupBy(x => x.Category)
                                      .ToList()
                                      .Select(group => new CategoryMonthAmount(group.Key, SelectedMonth, group.Sum(x => x.Amount)));
            var selectedMonthData = new AverageOverMonthsCategoryRoller(Category, SelectedMonth, SelectedMonth)
                                    .RollUpByCategoriesOfInterest(db, selectedMonthTotals)
                                    .ToList();

            return(filter(selectedMonthData));
        }
Beispiel #11
0
        private void Export()
        {
            string       fileName = AppSettings.InvoiceTemplate;
            XLWorkbook   workbook = new XLWorkbook(fileName);
            IXLWorksheet ws       = workbook.Worksheet(SelectedCustomer.InvoiceFormat);

            Output(ws, 7);
            if (SelectedCustomer.InvoiceFormat == 2)
            {
                Output(ws, 32);
            }

            //delete other sheets
            for (int i = workbook.Worksheets.Count; i >= 1; i--)
            {
                if (i != SelectedCustomer.InvoiceFormat)
                {
                    workbook.Worksheet(i).Delete();
                }
            }

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = string.Format("{0}-{1}", SelectedCustomer.Name, SelectedMonth.ToString("yyyyMM")); // Default file name
            dlg.DefaultExt = ".xlsx";                                                                           // Default file extension

            // Show save file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                workbook.SaveAs(filename);
            }
        }
        private void DrawPieChart()
        {
            List <PieEntry> datalist = new List <PieEntry>();

            int[] colors = new int[14];
            for (int i = 0; i < lstPieChartDataValue.Count; i++)
            {
                string expensecategory = lstPieChartDataValue[i].ExpenseCategory;
                double total           = lstPieChartDataValue[i].Total;
                datalist.Add(new PieEntry((float)total, expensecategory));

                switch (expensecategory)
                {
                case "Food and Dining":
                    colors[i] = Android.Graphics.Color.ParseColor("#FFA500");
                    break;

                case "Shopping":
                    colors[i] = Android.Graphics.Color.ParseColor("#40C4FF");
                    break;

                case "Travelling":
                    colors[i] = Android.Graphics.Color.ParseColor("#00BFA5");
                    break;

                case "Entertainment":
                    colors[i] = Android.Graphics.Color.ParseColor("#e49ef0");
                    break;

                case "Medical":
                    colors[i] = Android.Graphics.Color.ParseColor("#FF0000");
                    break;

                case "Personal Care":
                    colors[i] = Android.Graphics.Color.ParseColor("#0EDBDB");
                    break;

                case "Education":
                    colors[i] = Android.Graphics.Color.ParseColor("#1b49f2");
                    break;

                case "Bills and Utilities":
                    colors[i] = Android.Graphics.Color.ParseColor("#006600");
                    break;

                case "Banking":
                    colors[i] = Android.Graphics.Color.ParseColor("#FFAB91");
                    break;

                case "Rent":
                    colors[i] = Android.Graphics.Color.ParseColor("#9E9D24");
                    break;

                case "Taxes":
                    colors[i] = Android.Graphics.Color.ParseColor("#DB32B1");
                    break;

                case "Insurance":
                    colors[i] = Android.Graphics.Color.ParseColor("#AA00FF");
                    break;

                case "Gifts and Donations":
                    colors[i] = Android.Graphics.Color.ParseColor("#8699E3");
                    break;

                case "Other":
                    colors[i] = Android.Graphics.Color.ParseColor("#695e5e");
                    break;
                }
            }
            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            MikePhil.Charting.Data.PieDataSet pieDataSet = new MikePhil.Charting.Data.PieDataSet(datalist, "");
            pieDataSet.YValuePosition = PieDataSet.ValuePosition.OutsideSlice;
            //pieDataSet.ValueLinePart1OffsetPercentage=100f; /** When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size */
            pieDataSet.ValueLinePart1Length = 0.4f; /** When valuePosition is OutsideSlice, indicates length of first half of the line */
            pieDataSet.ValueLinePart2Length = 0.4f;
            pieDataSet.SliceSpace           = 0.5f;
            pieDataSet.SelectionShift       = 5f;
            Java.Util.Random rnd = new Java.Util.Random();
            //int[] colors = new int[lstExpenseCategories.Count];
            //for (int i = 0; i < lstExpenseCategories.Count; i++)
            //{
            //    Android.Graphics.Color randomColor = Android.Graphics.Color.Rgb(rnd.NextInt(256), rnd.NextInt(256), rnd.NextInt(256));
            //    colors[i] = randomColor;
            //}


            pieDataSet.SetColors(colors);
            // pieDataSet.SetColors(PieChartColors.piecharcolors.Take(lstExpenseCategories.Count).ToArray());
            // pieDataSet.Colors = ColorTemplate.MaterialColors.Select(c => new Java.Lang.Integer(c)).ToList();
            pieDataSet.ValueTextSize          = 10f;
            pieDataSet.ValueTextColor         = Android.Graphics.Color.Black;
            piechartStats.Description.Enabled = false;
            piechartStats.CenterText          = "";

            Legend l = piechartStats.Legend;

            l.VerticalAlignment   = Legend.LegendVerticalAlignment.Bottom;
            l.HorizontalAlignment = Legend.LegendHorizontalAlignment.Left;
            l.Orientation         = Legend.LegendOrientation.Horizontal;
            l.WordWrapEnabled     = true;
            l.SetDrawInside(false);
            l.Enabled = true;
            piechartStats.SetExtraOffsets(0f, 2f, 0f, 2f);
            piechartStats.SetDrawEntryLabels(false);

            PieData pieData = new PieData(pieDataSet);

            piechartStats.Data = pieData;

            piechartStats.AnimateXY(1000, 1000);
            piechartStats.Invalidate();
            progressBarStats.Visibility = ViewStates.Invisible;
            piechartStats.Visibility    = ViewStates.Visible;
            statsdata.Visibility        = ViewStates.Invisible;
            generatePDF.Visibility      = ViewStates.Visible;
            statstype.Text = "Total expense for the month" + "(" + SelectedMonth.Substring(0, 3) + ")" + " = " + prefs.GetString("CurrencySymbolSelected", "") + lstPieChartDataValue.Sum(x => Convert.ToDouble(x.Total));
        }
        public void OnSuccess(Java.Lang.Object result)
        {
            if (IsPieChartSeleted)
            {
                lstExpenseCategories = new List <string>();
                lstPieChartData      = new List <PieChartData>();
                lstPieChartDataValue = new List <PieChartDataValue>();

                var snapshot = (QuerySnapshot)result;

                if (!snapshot.IsEmpty)
                {
                    var documents = snapshot.Documents;
                    foreach (DocumentSnapshot docitem in documents)
                    {
                        var itemName = docitem.Get("ItemName").ToString();
                        if (!lstExpenseCategories.Contains(itemName))
                        {
                            lstExpenseCategories.Add(itemName);
                        }
                        lstPieChartData.Add(new PieChartData {
                            ExpenseCategory = docitem.Get("ItemName").ToString(), ExpenseDescription = docitem.Get("Description").ToString(), ExpenseDate = docitem.Get("Date").ToString(), Amount = docitem.Get("Amount").ToString()
                        });
                    }

                    foreach (var item in lstExpenseCategories)
                    {
                        var ExpenseCategoryItem = item;
                        lstPieChartDataValue.Add(new PieChartDataValue {
                            ExpenseCategory = ExpenseCategoryItem, Total = lstPieChartData.Where(x => x.ExpenseCategory == ExpenseCategoryItem).Select(x => x.Amount).Sum(x => Convert.ToDouble(x))
                        });
                    }
                    DrawPieChart();
                }
                else
                {
                    generatePDF.Visibility      = ViewStates.Invisible;
                    progressBarStats.Visibility = ViewStates.Invisible;
                    statsdata.Visibility        = ViewStates.Visible;
                    statstype.Text = "Total expense for the month" + "(" + SelectedMonth.Substring(0, 3) + ")" + " = " + prefs.GetString("CurrencySymbolSelected", "") + lstPieChartDataValue.Sum(x => Convert.ToDouble(x.Total));
                }
            }
            else
            {
                TotalExpenseJan = new List <string>();
                TotalExpenseFeb = new List <string>();
                TotalExpenseMar = new List <string>();
                TotalExpenseApr = new List <string>();
                TotalExpenseMay = new List <string>();
                TotalExpenseJun = new List <string>();
                TotalExpenseJul = new List <string>();
                TotalExpenseAug = new List <string>();
                TotalExpenseSep = new List <string>();
                TotalExpenseOct = new List <string>();
                TotalExpenseNov = new List <string>();
                TotalExpenseDec = new List <string>();
                lstbarChartData = new List <BarChartData>();
                var snapshot = (QuerySnapshot)result;

                if (!snapshot.IsEmpty)
                {
                    var documents = snapshot.Documents;
                    foreach (DocumentSnapshot docitem in documents)
                    {
                        var month = docitem.Get("DateMonth").ToString();
                        switch (month)
                        {
                        case "January":
                            TotalExpenseJan.Add(docitem.Get("Amount").ToString());
                            break;

                        case "February":
                            TotalExpenseFeb.Add(docitem.Get("Amount").ToString());
                            break;

                        case "March":
                            TotalExpenseMar.Add(docitem.Get("Amount").ToString());
                            break;

                        case "April":
                            TotalExpenseApr.Add(docitem.Get("Amount").ToString());
                            break;

                        case "May":
                            TotalExpenseMay.Add(docitem.Get("Amount").ToString());
                            break;

                        case "June":
                            TotalExpenseJun.Add(docitem.Get("Amount").ToString());
                            break;

                        case "July":
                            TotalExpenseJul.Add(docitem.Get("Amount").ToString());
                            break;

                        case "August":
                            TotalExpenseAug.Add(docitem.Get("Amount").ToString());
                            break;

                        case "September":
                            TotalExpenseSep.Add(docitem.Get("Amount").ToString());
                            break;

                        case "October":
                            TotalExpenseOct.Add(docitem.Get("Amount").ToString());
                            break;

                        case "November":
                            TotalExpenseNov.Add(docitem.Get("Amount").ToString());
                            break;

                        case "December":
                            TotalExpenseDec.Add(docitem.Get("Amount").ToString());
                            break;
                        }
                    }
                    lstbarChartData.Add(new BarChartData {
                        Month = "Jan", Total = TotalExpenseJan.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Feb", Total = TotalExpenseFeb.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Mar", Total = TotalExpenseMar.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Apr", Total = TotalExpenseApr.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "May", Total = TotalExpenseMay.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Jun", Total = TotalExpenseJun.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Jul", Total = TotalExpenseJul.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Aug", Total = TotalExpenseAug.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Sep", Total = TotalExpenseSep.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Oct", Total = TotalExpenseOct.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Nov", Total = TotalExpenseNov.Sum(x => Convert.ToDouble(x))
                    });
                    lstbarChartData.Add(new BarChartData {
                        Month = "Dec", Total = TotalExpenseDec.Sum(x => Convert.ToDouble(x))
                    });
                    DrawBarChart();
                    generatePDF.Visibility = ViewStates.Invisible;
                }
                else
                {
                    generatePDF.Visibility      = ViewStates.Invisible;
                    progressBarStats.Visibility = ViewStates.Invisible;
                    statsdata.Visibility        = ViewStates.Visible;
                    statstype.Text = "Total expense for the year" + "(" + SelectedYear + ")" + " = " + prefs.GetString("CurrencySymbolSelected", "") + lstbarChartData.Sum(x => Convert.ToDouble(x.Total));
                }
            }
        }
Beispiel #14
0
        public void CreateMReport()
        {
            // 取得儲存檔案名稱, 並刪除舊有資料
            string filepath = GlobalConfig.MReportFileName(Store, int.Parse(Year), SelectedMonth);

            if (File.Exists(filepath))
            {
                try
                {
                    File.Delete(filepath);
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show($"刪除原有檔案失敗,請確認檔案是否開啟中.( { e.Message } )");
                    return;
                }
            }

            // 匯入所選年月發票資料
            List <Invoice> monthInvoices = GlobalConfig.Connection.GetAllInvoice(Store, int.Parse(Year), SelectedMonth);

            // 產生月報資料
            XLWorkbook wb = new XLWorkbook();
            var        ws = wb.AddWorksheet("Sheet1");

            ws.Style.Font.FontName        = "微軟正黑體";
            ws.Style.Alignment.Vertical   = XLAlignmentVerticalValues.Center;
            ws.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            ws.Rows().AdjustToContents();
            ws.Style.Font.SetFontSize(10);
            ws.Row(4).Height = 5;
            ws.Row(8).Height = 5;

            using (var row = ws.Range("B2:M2"))
            {
                row.Value = "營業人使用二聯式收銀機統一發票明細表";
                row.Style.Font.SetFontSize(16);
                row.Merge();
            }

            using (var row = ws.Range("B3:M3"))
            {
                row.SetValue <string>($"中華民國{ (int.Parse(Year) - 1911).ToString() }年{ SelectedMonth.ToString() }月");
                row.Style.Font.SetFontSize(16);
                row.Merge();
            }

            using (var block = ws.Range("B5:E7"))
            {
                using (var row = ws.Range("B5:D5"))
                {
                    row.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
                    row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    row.Value = "統一編號";
                    row.Merge();
                }

                using (var row = ws.Range("B6:D6"))
                {
                    row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    row.Value = "營業人名稱";
                    row.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
                    row.Merge();
                }

                using (var row = ws.Range("B7:D7"))
                {
                    row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    row.Value = "稅籍編號";
                    row.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
                    row.Merge();
                }

                using (var row = ws.Range("E5:E7"))
                {
                    row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                }

                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Style.Border.InsideBorder  = XLBorderStyleValues.Thin;

                // 統一編號
                ws.Range("E5").SetValue(Store.UniformNumber);
                // 營業人名稱
                ws.Range("E6").SetValue(Store.Name);
                ws.Range("E6").Style.Font.FontSize = 6;
                // 稅籍編號
                ws.Range("E7").SetValue(Store.TaxId);
            }

            using (var row = ws.Range("F7:I7"))
            {
                row.Value = "所屬年月及發票字軌請營業人填註";
                row.Merge();
            }

            using (var block = ws.Range("J5:J7"))
            {
                using (var row = ws.Range("J6:J7"))
                {
                    row.Merge();
                    // 收銀機編號
                    row.SetValue(Store.CashierNumber);
                    row.Style.Font.FontSize = 9;
                }

                ws.Cell("J5").Value = "收銀機編號";
                ws.Cell("J5").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Style.Border.OutsideBorder         = XLBorderStyleValues.Thin;
            }

            using (var block = ws.Range("L5:M7"))
            {
                using (var col = ws.Range("L5:L7"))
                {
                    col.Value = "發票字軌";
                    col.Style.Alignment.WrapText = true;
                    col.Style.Border.RightBorder = XLBorderStyleValues.Thin;
                    col.Merge();
                }

                using (var col = ws.Range("M5:M7"))
                {
                    col.SetValue(Track);
                    col.Style.Font.Bold = true;
                    col.Merge();
                }

                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Style.Border.InsideBorder  = XLBorderStyleValues.Thin;
            }

            using (var block = ws.Range("B9:C10"))
            {
                block.Value = "開立日期";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range("D9:E10"))
            {
                block.Value = "開立發票起訖號碼";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range("F9:G9"))
            {
                block.Value = "應       稅";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range("F10:G10"))
            {
                block.Value = "發 票 總 金 額";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range("H9:H10"))
            {
                block.Value = "免   稅銷 售 額";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range("I9:M10"))
            {
                block.Value = "誤開作廢發票號碼";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            int rowIndex = 11;

            for (var i = 1; i <= DateTime.DaysInMonth(int.Parse(Year), SelectedMonth); i++)
            {
                List <Invoice> dayInovices = monthInvoices.Where(x => x.CreateTime.Day == i).ToList();

                using (var block = ws.Range(rowIndex, 2, rowIndex + 1, 3))
                {
                    block.Value = i;
                    block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    block.Merge();
                }

                using (var block = ws.Range(rowIndex, 4, rowIndex + 1, 5))
                {
                    List <int> invoiceNumber = new List <int>();

                    foreach (Invoice invoice in dayInovices)
                    {
                        invoiceNumber.Add(int.Parse(invoice.Number));
                    }

                    var result = String.Join(",", invoiceNumber
                                             .Distinct()
                                             .OrderBy(x => x)
                                             .GroupAdjacentBy((x, y) => x + 1 == y)
                                             .Select(g => new int[] { g.First(), g.Last() }.Distinct())
                                             .Select(g => String.Join("-", g)));

                    string[] cols = result.Split(',');

                    using (var row = ws.Range(rowIndex, 4, rowIndex, 5))
                    {
                        // 開立發票起訖號碼
                        // if (invoice[i].Count() > 0)
                        if (cols.Length > 0)
                        {
                            // row.SetValue<string>(invoice[i].First() + " - " + invoice[i].Last());
                            row.SetValue(cols[0]);
                        }
                        row.Style.Font.FontSize = 9;
                        row.Merge();
                    }

                    using (var row = ws.Range(rowIndex + 1, 4, rowIndex + 1, 5))
                    {
                        // 開立發票起訖號碼
                        if (cols.Length > 1)
                        {
                            row.SetValue(cols[1]);
                        }
                        row.Style.Font.FontSize = 9;
                        row.Merge();
                    }
                    block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                }

                using (var block = ws.Range(rowIndex, 6, rowIndex + 1, 7))
                {
                    if (dayInovices.Count > 0)
                    {
                        // 發票總金額
                        block.SetValue(dayInovices.Where(x => !x.InValid).Select(x => x.Amount).Sum().ToString("###,##0"));
                    }
                    block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    block.Merge();
                }

                using (var block = ws.Range(rowIndex, 8, rowIndex + 1, 8))
                {
                    block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    block.Merge();
                }

                using (var block = ws.Range(rowIndex, 9, rowIndex + 1, 13))
                {
                    // 作廢發票號碼
                    if (dayInovices.Where(x => x.InValid == true).Count() > 0)
                    {
                        string invalid = String.Join(",", dayInovices.Where(x => x.InValid).Select(x => x.Number).ToList());

                        block.SetValue(invalid);
                    }
                    block.Style.Alignment.WrapText   = true;
                    block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    block.Merge();
                }

                rowIndex += 2;
            }

            using (var block = ws.Range(rowIndex, 2, rowIndex + 10, 2))
            {
                block.Value = "申報            單位";
                block.Style.Alignment.WrapText = true;
                block.Style.Font.SetFontSize(5);
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex, 3, rowIndex + 10, 5))
            {
                using (var row = ws.Range(rowIndex, 3, rowIndex + 8, 5))
                {
                    row.Merge();
                }

                using (var row = ws.Range(rowIndex + 9, 3, rowIndex + 9, 5))
                {
                    row.Value = "(請蓋用統一發票專用章)";
                    row.Merge();
                }

                using (var row = ws.Range(rowIndex + 10, 3, rowIndex + 10, 5))
                {
                    row.Value = "申報日期: 年 月 日";
                    row.Merge();
                }

                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
            }

            using (var row = ws.Range(rowIndex, 6, rowIndex, 7))
            {
                row.Value = "作   廢   份   數";
                row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                row.Merge();
            }

            using (var row = ws.Range(rowIndex, 8, rowIndex, 13))
            {
                // 作廢份數
                row.SetValue(monthInvoices.Where(x => x.InValid == true).Count().ToString("###,##0"));
                row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                row.Merge();
            }

            using (var row = ws.Range(rowIndex + 1, 6, rowIndex + 1, 7))
            {
                row.Value = "空  白  發  票  起  訖  號  碼";
                row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                row.Merge();
            }

            using (var row = ws.Range(rowIndex + 1, 8, rowIndex + 1, 13))
            {
                row.Value = "      號      號共   份";
                row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                row.Merge();
            }

            using (var row = ws.Range(rowIndex + 2, 6, rowIndex + 3, 13))
            {
                row.Value = "銷  售  額  及  稅  額  計  算";
                row.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                row.Merge();
            }

            using (var block = ws.Range(rowIndex + 4, 6, rowIndex + 6, 6))
            {
                block.Value = "          區分項目";
                block.Style.Alignment.WrapText   = true;
                block.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
                block.Merge();
                block.Style.Border.DiagonalDown   = true;
                block.Style.Border.OutsideBorder  = XLBorderStyleValues.Thin;
                block.Style.Border.DiagonalBorder = XLBorderStyleValues.Thin;
            }

            using (var block = ws.Range(rowIndex + 4, 7, rowIndex + 4, 11))
            {
                block.Value = "應            稅";
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 5, 7, rowIndex + 6, 7))
            {
                ws.Cell(rowIndex + 5, 7).Value = "發票總金額";
                ws.Cell(rowIndex + 6, 7).Value = "(1)";
                ws.Cell(rowIndex + 6, 7).Style.Font.SetFontSize(6);
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
            }

            using (var block = ws.Range(rowIndex + 5, 8, rowIndex + 6, 9))
            {
                using (var row = ws.Range(rowIndex + 5, 8, rowIndex + 5, 9))
                {
                    row.Value = "銷售額";
                    row.Merge();
                }

                using (var row = ws.Range(rowIndex + 6, 8, rowIndex + 6, 9))
                {
                    row.Value = "(2) = (1) x (100/105)";
                    row.Style.Font.SetFontSize(6);
                    row.Merge();
                }
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
            }

            using (var block = ws.Range(rowIndex + 5, 10, rowIndex + 6, 11))
            {
                using (var row = ws.Range(rowIndex + 5, 10, rowIndex + 5, 11))
                {
                    row.Value = "稅額";
                    row.Merge();
                }

                using (var row = ws.Range(rowIndex + 6, 10, rowIndex + 6, 11))
                {
                    row.Value = "(3) = (2) x 5%";
                    row.Style.Font.SetFontSize(6);
                    row.Merge();
                }
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
            }

            using (var block = ws.Range(rowIndex + 4, 12, rowIndex + 6, 13))
            {
                block.Value = "免          稅銷   售   額";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 7, 6, rowIndex + 8, 6))
            {
                block.Value = "本  表合  計";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 7, 7, rowIndex + 8, 7))
            {
                // 本表合計
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 7, 8, rowIndex + 8, 9))
            {
                block.Style.Alignment.WrapText    = true;
                block.Style.Border.OutsideBorder  = XLBorderStyleValues.Thin;
                block.Style.Border.DiagonalUp     = true;
                block.Style.Border.DiagonalBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 7, 10, rowIndex + 8, 11))
            {
                block.Style.Alignment.WrapText    = true;
                block.Style.Border.OutsideBorder  = XLBorderStyleValues.Thin;
                block.Style.Border.DiagonalUp     = true;
                block.Style.Border.DiagonalBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 7, 12, rowIndex + 8, 13))
            {
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 9, 6, rowIndex + 10, 6))
            {
                block.Value = "本期(月) 總  計";
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            // 本月發票總金額
            int    total   = monthInvoices.Where(x => x.InValid == false).Select(x => x.Amount).Sum();
            double taxFree = 0;

            using (var block = ws.Range(rowIndex + 9, 7, rowIndex + 10, 7))
            {
                // 本期(月)總計
                block.SetValue(total.ToString("###,##0"));
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 9, 8, rowIndex + 10, 9))
            {
                taxFree = total / 1.05;
                // 銷售額
                block.SetValue(Math.Round(taxFree).ToString("###,##0"));
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 9, 10, rowIndex + 10, 11))
            {
                double tax = taxFree * 0.05;
                // 稅額
                block.SetValue(Math.Round(tax).ToString("###,##0"));
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            using (var block = ws.Range(rowIndex + 9, 12, rowIndex + 10, 13))
            {
                block.Style.Alignment.WrapText   = true;
                block.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                block.Merge();
            }

            ws.Column(1).Width  = 1;
            ws.Column(2).Width  = 2;
            ws.Column(3).Width  = 2;
            ws.Column(4).Width  = 6;
            ws.Column(5).Width  = 12;
            ws.Column(6).Width  = 8;
            ws.Column(7).Width  = 12;
            ws.Column(8).Width  = 10;
            ws.Column(9).Width  = 2;
            ws.Column(10).Width = 10;
            ws.Column(11).Width = 2;
            ws.Column(12).Width = 4;
            ws.Column(13).Width = 4;
            wb.SaveAs(filepath);

            System.Windows.MessageBox.Show($"月報資料已產生至 { filepath } .");
        }
Beispiel #15
0
        private async void GeneratePDF(object obj)
        {
            int      year     = Convert.ToInt32(SelectedYear);
            int      month    = DateTime.ParseExact(SelectedMonth.ToLower(), "MMMM", CultureInfo.CurrentCulture).Month;
            DateTime dateFrom = new DateTime(year, month, 1, 0, 0, 0);
            DateTime dateTo   = new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59);
            var      products = await ProductRepository.FindAllByFiltering(dateFrom, dateTo);

            if (products.Count == 0)
            {
                CrossToastPopUp.Current.ShowToastMessage("Brak wyprodukowanych receptur w danym miesiącu");
                return;
            }
            List <Product> list = new List <Product>();

            foreach (var item in products)
            {
                if (list.Where(p => p.Name == item.Name).Any())
                {
                    var pr = list.Where(p => p.Name == item.Name).FirstOrDefault();
                    pr.Quantity = pr.Quantity + item.Quantity;
                }
                else
                {
                    list.Add(new Product(item.Quantity, item.Name));
                }
            }

            PdfDocument pdf = new PdfDocument();

            pdf.Info.Title = "Podsumowanie Miesięczne";
            PdfPage   pdfPage = pdf.AddPage();
            XGraphics graph   = XGraphics.FromPdfPage(pdfPage);
            XFont     font    = new XFont("Verdana", 24, XFontStyle.Bold);

            graph.DrawString("Podsumowanie miesięczne - " + SelectedMonth + " " + SelectedYear, font, XBrushes.Black, 30, 60);
            double y = 100;

            font = new XFont("Verdana", 14, XFontStyle.Regular);
            decimal sum = 0;

            foreach (var item in list)
            {
                graph.DrawString(item.Name, font, XBrushes.Black, 60, y);
                graph.DrawString((item.Quantity / 1000) + " kg", font, XBrushes.Black, 300, y);
                y   += 30;
                sum += item.Quantity;
                if (y > 700)
                {
                    graph = XGraphics.FromPdfPage(pdf.AddPage());
                    y     = 100;
                }
            }
            font = new XFont("Verdana", 24, XFontStyle.Bold);
            graph.DrawString("Suma: " + (sum / 1000) + " kg", font, XBrushes.Black, 30, y + 20);

            var filename = selectedYear + "-" + selectedMonth + "_" + DateTime.Now.ToString("HH-mm-ss") + ".pdf";

            pdf.Save(Path.Combine("/storage/emulated/0/MintIceApp/Summaries", filename));
            CrossToastPopUp.Current.ShowToastMessage("Wygenerowano podsumowanie miesiąca (Pamięć wewnętrzna/MintIceApp/Summaries/" + filename + ")");
        }
Beispiel #16
0
        public void MonthForwardButton_Clicked(object sender, RoutedEventArgs e)
        {
            SelectedMonth = SelectedMonth.AddMonths(1);

            ChangeMonth(SelectedMonth);
        }
Beispiel #17
0
        private void NextMonth()
        {
            SelectedMonth = SelectedMonth.AddMonths(1);

            UpdateWeekRecords();
        }
Beispiel #18
0
        private void PreviousMonth()
        {
            SelectedMonth = SelectedMonth.AddMonths(-1);

            UpdateWeekRecords();
        }