Пример #1
0
        private void CreateReport(BillDto billDto, float tongTien, float khachTt, string tenNhanVien)
        {
            var columnNames = new List <string> {
                "MonAn", "SoLuong", "DonGia", "Tong", "ChietKhau"
            };

            var dataTable = new DataTable();

            dataTable.Columns.Add(columnNames[0], Type.GetType("System.String"));
            dataTable.Columns.Add(columnNames[1], Type.GetType("System.String"));
            dataTable.Columns.Add(columnNames[2], Type.GetType("System.String"));
            dataTable.Columns.Add(columnNames[3], Type.GetType("System.String"));
            dataTable.Columns.Add(columnNames[4], Type.GetType("System.String"));

            var allResOrderDtos = _billingDao.GetAllResOrderBy(billDto.Id);

            foreach (var dto in allResOrderDtos)
            {
                DataRow dataRow = dataTable.NewRow();
                dataRow[columnNames[0]] = dto.MenuName;
                dataRow[columnNames[1]] = dto.Amount;
                dataRow[columnNames[2]] = dto.MenuPrice.ToString("#,###,###");
                float total = dto.Amount * dto.MenuPrice * (1 - dto.Discount);
                dataRow[columnNames[3]] = total.ToString("#,###,###");
                dataRow[columnNames[4]] = dto.Discount == 0 ? String.Empty : "CK" + (100 * dto.Discount) + "%";
                dataTable.Rows.Add(dataRow);
            }

            ReportClass report = new BillingReport();

            report.Database.Tables["BillDto"].SetDataSource(dataTable);
            report.SetParameterValue("TenCongTy", ThamSo.TenCongTy);
            report.SetParameterValue("DiaChi", ThamSo.DiaChi);
            report.SetParameterValue("BillNumber", billDto.BillingNumber.ToString());
            report.SetParameterValue("TenKhach", String.Empty);
            report.SetParameterValue("NhanVien", tenNhanVien);
            report.SetParameterValue("TongTien", tongTien.ToString("#,###,###"));
            report.SetParameterValue("KhachTT", khachTt.ToString("#,###,###"));
            report.SetParameterValue("KhachThua", (khachTt - tongTien).ToString("#,###,###"));

            report.PrintOptions.PrinterName      = ThamSo.PrinterName;
            report.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
            report.PrintToPrinter(1, false, 0, 0);

            //var frm = new FrmReport(report, false);
            //frm.Text = "In hóa đơn";
            //frm.ShowDialog(this);
            //frm.BringToFront();
        }
        public void Setup()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
            _shimsContext    = ShimsContext.Create();
            _fakeHttpContext = new FakeHttpContext.FakeHttpContext();

            MockBillingProxy();
            MockBillingNoteProxy();
            MockReportContentGenerator();

            _page = new BillingReport(
                _billingProxyMock.Object,
                _billingNoteProxyMock.Object,
                _reportContentGeneratorMock.Object);

            InitializePage(_page);
            RetrievePageControls();
        }
Пример #3
0
        public JsonNetResult GetReport(int sinceHoursAgo)
        {
            #region Get data from WCF


            var PlatformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();
            var billingReport = new BillingReport();

            try
            {
                PlatformManagementServiceClient.Open();
                billingReport = PlatformManagementServiceClient.GetBillingReport(sinceHoursAgo, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(PlatformManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(PlatformManagementServiceClient, exceptionMessage, currentMethodString);

                #endregion
            }

            #endregion

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = billingReport;

            return(jsonNetResult);
        }
Пример #4
0
        public void Constructor_BillingReport_5_Objects_Creation_No_Paramters_Test()
        {
            // Arrange
            var firstBillingReport  = new BillingReport();
            var secondBillingReport = new BillingReport();
            var thirdBillingReport  = new BillingReport();
            var fourthBillingReport = new BillingReport();
            var fifthBillingReport  = new BillingReport();
            var sixthBillingReport  = new BillingReport();

            // Act, Assert
            firstBillingReport.ShouldNotBeNull();
            secondBillingReport.ShouldNotBeNull();
            thirdBillingReport.ShouldNotBeNull();
            fourthBillingReport.ShouldNotBeNull();
            fifthBillingReport.ShouldNotBeNull();
            sixthBillingReport.ShouldNotBeNull();
            firstBillingReport.ShouldNotBeSameAs(secondBillingReport);
            thirdBillingReport.ShouldNotBeSameAs(firstBillingReport);
            fourthBillingReport.ShouldNotBeSameAs(firstBillingReport);
            fifthBillingReport.ShouldNotBeSameAs(firstBillingReport);
            sixthBillingReport.ShouldNotBeSameAs(firstBillingReport);
            sixthBillingReport.ShouldNotBeSameAs(fourthBillingReport);
        }
Пример #5
0
        public static BillingReport GetBillingReport(int sinceHoursAgo)
        {
            var billingReport = new BillingReport();

            #region get from Redis

            //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.PlatformManager_Multiplexer.GetDatabase();
            IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();

            Object cachedBillingReport = null;

            try
            {
                cachedBillingReport = cache.HashGet(
                    Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.ReportsHash.Key,
                    Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.ReportsHash.Fields.Billing(sinceHoursAgo)
                    );

                if (((RedisValue)cachedBillingReport).HasValue)
                {
                    billingReport = JsonConvert.DeserializeObject <BillingReport>((RedisValue)cachedBillingReport);
                }
            }
            catch
            {
            }

            #endregion

            #region Generate report

            if (((RedisValue)cachedBillingReport).IsNullOrEmpty)
            {
                var stripeManager = new StripeManager();


                //Counts & Totals:
                var chargeCount = 0;
                //var failedChargeCount = 0;
                var refundCount            = 0;
                var transferCount          = 0;
                var transferCount_Pending  = 0;
                var transferCount_Complete = 0;

                decimal totalGross              = 0;
                decimal totalFees               = 0;
                decimal totalRefunds            = 0;
                decimal totalNet                = 0;
                decimal totalTransfers          = 0;
                decimal totalTransfers_Pending  = 0;
                decimal totalTransfers_Complete = 0;


                //Get charges from time period:

                /*var stripeCharges = new List<StripeCharge>();
                 *
                 *
                 * //Since Stripe limit is 100 we break up the call into 100 item increments until we reach the last item:
                 * var stripeChargesPending = stripeManager.GetCharges_SinceHoursAgo(sinceHoursAgo, null, null, true).ToList();
                 *
                 * stripeCharges.AddRange(stripeChargesPending);
                 * while (stripeChargesPending.Count == 100)
                 * {
                 *  stripeChargesPending = stripeManager.GetCharges_SinceHoursAgo(sinceHoursAgo, stripeChargesPending[99].Id, null, true).ToList();
                 *  stripeCharges.AddRange(stripeChargesPending);
                 * }
                 */



                //Loop through all charges from time period and generate report data

                /*
                 * foreach(StripeCharge stripeCharge in stripeCharges)
                 * {
                 *  if (stripeCharge.Paid.HasValue)
                 *  {
                 *      if (stripeCharge.Paid.Value)
                 *      {
                 *          chargeCount++;
                 *          /*totalGross = totalGross + Sahara.Core.Common.Methods.Billing.ConvertStripeAmountToDecimals(stripeCharge.Amount.ToString());
                 *          totalFees = totalFees + Sahara.Core.Common.Methods.Billing.ConvertStripeAmountToDecimals(stripeCharge.BalanceTransaction.Fee.ToString());
                 *          totalNet = totalNet + Sahara.Core.Common.Methods.Billing.ConvertStripeAmountToDecimals(stripeCharge.BalanceTransaction.Net.ToString());
                 *          if (stripeCharge.AmountRefunded.HasValue)
                 *          {
                 *              totalRefunds = totalRefunds + Sahara.Core.Common.Methods.Billing.ConvertStripeAmountToDecimals(stripeCharge.AmountRefunded.Value.ToString());
                 *          }
                 *          if (stripeCharge.Refunded.HasValue)
                 *          {
                 *              if (stripeCharge.Refunded.Value)
                 *              {
                 *                  refundCount++;
                 *              }
                 *          }* /
                 *      }
                 *      else if (!stripeCharge.Paid.Value)
                 *      {
                 *          failedChargeCount++;
                 *      }
                 *  }
                 *
                 * }*/

                billingReport.BalanceTransactions           = new List <Billing.Models.BalanceTransaction>();
                billingReport.BalanceTransactions_Created   = new List <Billing.Models.BalanceTransaction>();
                billingReport.BalanceTransactions_Available = new List <Billing.Models.BalanceTransaction>();

                //Since Stripe limit is 100 we break up the call into 100 item increments until we reach the last item:
                var balanceTransactions = PlatformBillingManager.GetBalanceTransaction_AvailableSinceHourssAgo(sinceHoursAgo);

                billingReport.BalanceTransactions.AddRange(balanceTransactions);
                while (balanceTransactions.Count == 100)
                {
                    balanceTransactions = PlatformBillingManager.GetBalanceTransaction_AvailableSinceHourssAgo(sinceHoursAgo, balanceTransactions[99].BalanceTransactionID);
                    billingReport.BalanceTransactions.AddRange(balanceTransactions);
                }



                //Split all results into 2 camps ===============================================

                foreach (var balanceTransaction in billingReport.BalanceTransactions)
                {
                    if (balanceTransaction.Created >= DateTime.UtcNow.AddHours(sinceHoursAgo * -1))
                    {
                        billingReport.BalanceTransactions_Created.Add(balanceTransaction);
                    }
                    else
                    {
                        billingReport.BalanceTransactions_Available.Add(balanceTransaction);
                    }
                }

                //=================================================================================================
                //Loop through all balance transactions from ENTIRE time period to generate daily activity data for transactions


                foreach (var btr in billingReport.BalanceTransactions)
                {
                    if (btr.Type == "transfer")
                    {
                        transferCount++;
                        totalTransfers = totalTransfers + btr.Amount;

                        if (btr.Status == "pending")
                        {
                            transferCount_Pending++;
                            totalTransfers_Pending = totalTransfers_Pending + btr.Amount;
                        }
                        else
                        {
                            transferCount_Complete++;
                            totalTransfers_Complete = totalTransfers_Complete + btr.Amount;
                        }
                    }
                }


                //=================================================================================================
                //Loop through all balance transactions from the CREATED time period to generate daily activity data for charges & refunds

                foreach (var btr in billingReport.BalanceTransactions_Created)
                {
                    if (btr.Type == "charge")
                    {
                        chargeCount++;

                        totalGross = totalGross + btr.Amount;
                        totalFees  = totalFees + btr.Fee;
                        totalNet   = totalNet + btr.Net;
                    }
                    else if (btr.Type == "refund")
                    {
                        refundCount++;

                        totalRefunds = totalRefunds + btr.Amount;

                        //totalGross = totalGross + btr.Amount;
                        totalFees = totalFees + btr.Fee;
                        totalNet  = totalNet + btr.Net;
                    }
                    else if (btr.Type == "adjustment")
                    {
                        totalGross = totalGross + btr.Amount;
                        totalFees  = totalFees + btr.Fee;
                        totalNet   = totalNet + btr.Net;
                    }
                    else if (btr.Type == "application_fee" || btr.Type == "application_fee_refund")
                    {
                        totalGross = totalGross + btr.Amount;
                        totalFees  = totalFees + btr.Fee;
                        totalNet   = totalNet + btr.Net;
                    }

                    /*
                     * else if (btr.Type == "transfer")
                     * {
                     *
                     * transferCount++;
                     * totalTransfers = totalTransfers + btr.Amount;
                     * if (btr.Status == "pending")
                     * {
                     *  transferCount_Pending++;
                     *  totalTransfers_Pending = totalTransfers_Pending + btr.Amount;
                     * }
                     * else
                     * {
                     *  transferCount_Complete++;
                     *  totalTransfers_Complete = totalTransfers_Complete + btr.Amount;
                     * }
                     * }*/
                }

                billingReport.ChargeCount = chargeCount;
                billingReport.RefundCount = refundCount;
                //billingReport.FailedChargeCount = failedChargeCount;
                billingReport.TransferCount          = transferCount;
                billingReport.TransferCount_Pending  = transferCount_Pending;
                billingReport.TransferCount_Complete = transferCount_Complete;

                billingReport.TotalGross              = totalGross;
                billingReport.TotalFees               = Math.Abs(totalFees);
                billingReport.TotalRefunds            = Math.Abs(totalRefunds);
                billingReport.TotalNet                = totalNet;
                billingReport.TotalTransfers          = Math.Abs(totalTransfers);
                billingReport.TotalTransfers_Pending  = Math.Abs(totalTransfers_Pending);
                billingReport.TotalTransfers_Complete = Math.Abs(totalTransfers_Complete);

                //============================================


                billingReport.BillingIssues = false;

                //Check for any billing issues during this time period
                var latestBillingIssue = PlatformLogManager.GetPlatformLogByActivity(Logging.PlatformLogs.Types.ActivityType.Billing_Issue, 1);
                if (latestBillingIssue.Count > 0)
                {
                    if (latestBillingIssue[0].Timestamp >= DateTime.UtcNow.AddHours(sinceHoursAgo * -1))
                    {
                        billingReport.BillingIssues = true;
                    }
                }


                #region Store into Redis

                try
                {
                    //Store a copy in the Redis cache
                    cache.HashSet(
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.ReportsHash.Key,
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.ReportsHash.Fields.Billing(sinceHoursAgo),
                        JsonConvert.SerializeObject(billingReport),
                        When.Always,
                        CommandFlags.FireAndForget
                        );

                    //Expire cache after set time
                    cache.KeyExpire(
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.ReportsHash.Key,
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.ReportsHash.Expiration,
                        CommandFlags.FireAndForget
                        );
                }
                catch
                {
                }


                #endregion
            }



            /*/TESTS!
             * billingReport.BalanceTransactions.Add(new BalanceTransaction { Type = "adjustment", Amount = Convert.ToDecimal(20.77), Fee = Convert.ToDecimal(20.77), Net = Convert.ToDecimal(20.77) });
             * billingReport.BalanceTransactions.Add(new BalanceTransaction { Type = "application_fee", Amount = Convert.ToDecimal(20.77), Fee = Convert.ToDecimal(20.77), Net = Convert.ToDecimal(20.77) });
             * billingReport.BalanceTransactions.Add(new BalanceTransaction { Type = "application_fee_refund", Amount = Convert.ToDecimal(20.77), Fee = Convert.ToDecimal(20.77), Net = Convert.ToDecimal(20.77) });
             * billingReport.BalanceTransactions.Add(new BalanceTransaction { Type = "transfer_cancel", Amount = Convert.ToDecimal(20.77), Fee = Convert.ToDecimal(20.77), Net = Convert.ToDecimal(20.77) });
             * billingReport.BalanceTransactions.Add(new BalanceTransaction { Type = "transfer_failure", Amount = Convert.ToDecimal(20.77), Fee = Convert.ToDecimal(20.77), Net = Convert.ToDecimal(20.77) });
             */


            #endregion

            return(billingReport);
        }
 private void btnPrintPage_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         BillingReport report = new BillingReport(txtFileNo.Text, txtFirstName.Text, txtLastName.Text, txtAssignedAttorney.Text);
     }
     catch (Exception ex)
     {
         Helper.LogException(ex);
     }
 }