Esempio n. 1
0
        private void menuItem_Click(object sender, RoutedEventArgs e)
        {
            frmContent.NavigationService.RemoveBackEntry();
            SaleReport sale = new SaleReport();

            frmContent.Content = sale;
        }
Esempio n. 2
0
        private void btnPrinOnly_Click(object sender, EventArgs e)
        {
            //using (TransactionScope sc = new TransactionScope())
            //{

            //    try
            //    {
            //        Insertorderdetails(Convert.ToInt64(txtorder.Text),DatagridviewRunning);
            //        //KitchenForm kh = new KitchenForm();
            //        //kh.Show();

            SaleReport sr = new SaleReport();

            sr.Show();

            //    }
            //    catch (Exception)
            //    {

            //        throw;
            //    }

            //    sc.Complete();
            //    orderID = 0;


            //    datagridviewtaking.Rows.Clear();


            //}
        }
Esempio n. 3
0
        private void sALESREPORTToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            SaleReport C = new SaleReport();

            C.MdiParent = this;
            C.Show();
        }
Esempio n. 4
0
        public HttpResponseMessage GetSaleRpt(DateTime fromdate, DateTime Todate, string pcode, string ptcode, string vrtype)
        {
            if ((new Global()).CheckStarterService())
            {
                try
                {
                    DbConn    con     = new DbConn();
                    GBCDbConn gbc_con = new GBCDbConn();
                    List <VC> list_vc = gbc_con.Db_vc.ToList();
                    list_vc = gbc_con.Db_vc.Where(p => p.FDNAME == "SALE").ToList();
                    string series = "";
                    string name   = gbc_con.Database.Connection.Database + ".dbo.";
                    foreach (var item in list_vc)
                    {
                        series = series + ",'" + item.SER + "'";
                    }
                    series = series.Substring(1, series.Length - 1);
                    series = "(" + series + ")";
                    List <SaleReport> list_sale = new List <SaleReport>();


                    list_sale = con.Database.SqlQuery <SaleReport>("EXEC Sp_PartyWiseSaleBill @FromDate={0},@ToDate={1},@IsAllSer={2},@Series={3},@PCode={4},@PtCode={5},@RegdId={6},@VrType={7},@Less={8},@GdnCode={9},@OrderBy={10},@Summary={11},@ChkDr={12},@DrCode={13},@TSelectedNode={14},@FromVr={15},@ToVr={16},@GBCDBName={17}", fromdate, Todate, true, series, pcode, ptcode, "", vrtype, false, "", "Vrdate", false, false, "", "ACC070", "", "", name).Take(30).ToList();

                    list_sale = list_sale.OrderByDescending(p => p.Vrdate).OrderByDescending(p => p.Vrno).Take(30).ToList();
                    double crTotal = 0, cashTotal = 0;
                    foreach (var item in list_sale)
                    {
                        item.Vrdt = item.Vrdate.ToString("dd/MM/yyyy");
                        if (item.VrType == "C")
                        {
                            item.cashAmt = item.NetAmt.ToString("0.00");
                            item.crAmt   = "0.00";
                            cashTotal    = cashTotal + item.NetAmt;
                        }
                        else
                        {
                            item.crAmt   = item.NetAmt.ToString("0.00");
                            item.cashAmt = "0.00";
                            crTotal      = crTotal + item.NetAmt;
                        }
                    }

                    SaleReport obj = new SaleReport();
                    obj.Vrno    = "Total";
                    obj.cashAmt = cashTotal.ToString("0.00");
                    obj.crAmt   = crTotal.ToString("0.00");
                    list_sale.Add(obj);

                    return(Request.CreateResponse(HttpStatusCode.OK, list_sale));
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "There is some problem while getting information from server. Please try after some time." + ex.Message));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ""));
            }
        }
Esempio n. 5
0
        public List <SaleReport> Sales(string userId = "0", DateTime?fromDate = null, DateTime?toDate = null)
        {
            DateTime from;
            DateTime to;

            if (fromDate <= new DateTime(1 / 1 / 0001))
            {
                from = new DateTime(1899, 1, 1);
            }
            else
            {
                from = (DateTime)fromDate;
            }

            if (toDate <= new DateTime(1 / 1 / 0001))
            {
                to = new DateTime(2199, 1, 1);
            }
            else
            {
                to = (DateTime)toDate;
            }
            List <SaleReport> report = new List <SaleReport>();

            if (userId != "0")
            {
                var foundSales = _sales.Where(x => x.PurchaseDate > from).Where(x => x.PurchaseDate < to).ToList();
                foreach (var s in foundSales)
                {
                    SaleReport current = new SaleReport()
                    {
                        FullName          = s.Name,
                        TotalVehiclesSold = _sales.Count(x => x.UserId == s.UserId),
                        TotalSalesAmount  = _sales.Where(x => x.UserId == s.UserId).Sum(x => x.PurchasePrice)
                    };
                    report.Add(current);
                }
            }
            else
            {
                var foundSales = _sales.Where(x => x.PurchaseDate > from).Where(x => x.PurchaseDate < to).ToList();
                foreach (var s in foundSales)
                {
                    SaleReport current = new SaleReport()
                    {
                        FullName          = s.Name,
                        TotalVehiclesSold = _sales.Count(x => x.UserId == s.UserId),
                        TotalSalesAmount  = _sales.Where(x => x.UserId == s.UserId).Sum(x => x.PurchasePrice)
                    };
                    report.Add(current);
                }
            }
            return(report);
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            DAL.SaleReport reports = new SaleReport();
            reports.Search       = txtSearch.Text;
            reports.IsDateSearch = ucDateSearch1.IsDateEnable;
            reports.DateFrom     = ucDateSearch1.DateFrom;
            reports.DateTo       = ucDateSearch1.DateTo;
            reports.CustomerId   = Convert.ToInt32(cmbCustomer.SelectedValue);
            reports.EmployeeId   = Convert.ToInt32(cmbEmployee.SelectedValue);
            reports.ProductId    = Convert.ToInt32(cmbProduct.SelectedValue);


            myGrid1.DataSource = reports.Select().Tables[0];
        }
Esempio n. 7
0
 private void CalculateAmounts(SaleReport report, List <Sale> salesToday)
 {
     report.AmountProduct        = salesToday.Sum(x => x.ProductAmount);
     report.AmountDeliveryCharge = salesToday.Sum(x => x.DeliveryChargeAmount);
     report.AmountTax            = salesToday.Sum(x => x.TaxAmount);
     report.AmountOther          = salesToday.Sum(x => x.OtherAmount);
     report.AmountTotal          = salesToday.Sum(x => x.TotalAmount);
     report.AmountDiscount       = salesToday.Sum(x => x.DiscountAmount);
     report.AmountPayable        = salesToday.Sum(x => x.PayableTotalAmount);
     report.AmountPaid           = salesToday.Sum(x => x.PaidAmount);
     report.AmountDue            = salesToday.Sum(x => x.DueAmount);
     report.AmountCost           = salesToday.Sum(x => x.CostAmount);
     report.CountSaleCreated     = salesToday.Count;
     report.CountSaleCompleted   = salesToday.Count(x => x.OrderState == OrderState.Completed);
 }
Esempio n. 8
0
    public void CalculateTotalSaleReport()
    {
        SaleReport saleReport = new SaleReport();

        foreach (SaleReport item in saleReports)
        {
            saleReport.cost        += item.cost;
            saleReport.profit      += item.profit;
            saleReport.income      += item.income;
            saleReport.unitSelling += item.unitSelling;
            saleReport.fan         += item.fan;
        }

        totalSaleReport = saleReport;
    }
Esempio n. 9
0
    public void CalcurateSelling(Product product)
    {
        SaleReport saleReport  = new SaleReport();
        int        unitSelling = UnityEngine.Random.Range(10, 100000);
        int        price       = product.price;
        int        cost        = product.cost;
        int        income      = product.price * unitSelling;
        int        profit      = cost - income;
        int        fan         = (unitSelling / 100) * UnityEngine.Random.Range(1, 25);

        product.fan = fan;
        int allLevelComponent_temp = 0;

        foreach (ComponentData componentRequirements in product.genreDatas)
        {
            allLevelComponent_temp += componentRequirements.productLevel;
        }
        foreach (ComponentData componentRequirements in product.cameraDatas)
        {
            allLevelComponent_temp += componentRequirements.productLevel;
        }
        foreach (ComponentData componentRequirements in product.themeDatas)
        {
            allLevelComponent_temp += componentRequirements.productLevel;
        }
        foreach (ComponentData componentRequirements in product.graphicDatas)
        {
            allLevelComponent_temp += componentRequirements.productLevel;
        }
        foreach (ComponentData componentRequirements in product.featureDatas)
        {
            allLevelComponent_temp += componentRequirements.productLevel;
        }
        foreach (ComponentData componentRequirements in product.platformDatas)
        {
            allLevelComponent_temp += componentRequirements.productLevel;
        }

        product.income = allLevelComponent_temp * 10000;
        product.profit = allLevelComponent_temp * 10000;

        MessageSystem.instance.UpdateMessage("ได้รับเงินจาก Product[" + product.name + "] ในสัปดาห์นี้ " + allLevelComponent_temp * 10000 + " G");

        saleReport.Set(GameTimeStructure.instance.GetGameTimeStructure(), unitSelling, price, cost, income, profit, cost);
        product.timeStamp = GameTimeStructure.instance.GetFutureTime(1);
        product.AddSaleReport(saleReport);
    }
Esempio n. 10
0
        public IEnumerable <ReportViewModel> GetProductsTotals()
        {
            var data = from sp in DbSetContext.SaleProducts
                       group sp by sp.CodigoProduct into SaleReport
                       select new
            {
                c = SaleReport.Key,
                t = SaleReport.Sum(x => x.Quantity),
            };
            var q = from sg in data
                    join p in DbSetContext.Product on sg.c equals p.Codigo
                    select new ReportViewModel()
            {
                CodigoProduct = sg.c,
                Description   = p.Description,
                TotalSale     = sg.t
            };

            var list = q.ToList();

            return(list);
        }
Esempio n. 11
0
        public async Task <List <SaleReport> > GetSaleReports(string query)
        {
            var result = new List <SaleReport>();

            var billRepository = this.UnitOfWork.GetRepository <Bill>();
            var validBills     = await billRepository.GetQueryable().Where(query)
                                 .Select(b => new
                                         { b.SaleUserId, b.SalePrice, b.Profit, b.PurchasePriceAfterVatInVnd, b.PurchasePriceInVnd })
                                 .ToListAsync();

            var validGroupedBills = validBills.GroupBy(b => b.SaleUserId)
                                    .ToDictionary(x => x.Key, x => x.ToList());

            foreach (var groupedBill in validGroupedBills)
            {
                var saleUserId = groupedBill.Key;
                var bills      = groupedBill.Value;

                var saleReport = new SaleReport
                {
                    SaleUserId              = saleUserId,
                    TotalSalePrice          = bills.Sum(b => b.SalePrice),
                    TotalProfit             = bills.Sum(b => b.Profit) ?? 0,
                    TotalRawProfit          = bills.Sum(b => b.SalePrice - b.PurchasePriceAfterVatInVnd) ?? 0,
                    TotalRawProfitBeforeTax = bills.Sum(b => b.SalePrice - b.PurchasePriceInVnd) ?? 0,
                    TotalBill     = bills.Count,
                    TotalPurchase = new List <long>(bills.Select(b => (long)(b.PurchasePriceAfterVatInVnd ?? 0))).Sum()
                };

                var user = await this.auth.GetUserAsync(saleUserId);

                saleReport.SaleName = user?.DisplayName;

                result.Add(saleReport);
            }

            return(result.OrderByDescending(s => s.TotalSalePrice).ToList());
        }
Esempio n. 12
0
        public bool QuickUpdate(DateTime date, string shopId)
        {
            BusinessDbContext db       = BusinessDbContext.Create();
            ReportDbContext   reportDb = new ReportDbContext();

            date = date.Date;

            var salesToday = db.Sales.Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Created) == date)
                             .ToList();

            var report = reportDb.SaleReports.Where(x => x.ShopId == shopId).FirstOrDefault(x => x.Date == date);

            if (report == null)
            {
                bool b = ShopStart(date, shopId);
            }

            List <SaleReport> allReports        = reportDb.SaleReports.Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Date) == date).ToList();
            SaleReport        reportSaleTypeAll = allReports.First(x => x.SaleType == SaleType.All);

            CalculateAmounts(reportSaleTypeAll, salesToday);
            reportSaleTypeAll.Modified = DateTime.Now;
            reportDb.Entry(reportSaleTypeAll).State = EntityState.Modified;
            SaleReport  reportDealerSale = allReports.First(x => x.SaleType == SaleType.DealerSale);
            List <Sale> dealerSalesToday = salesToday.Where(x => x.IsDealerSale).ToList();

            CalculateAmounts(reportDealerSale, dealerSalesToday);
            reportDealerSale.Modified = DateTime.Now;
            reportDb.Entry(reportDealerSale).State = EntityState.Modified;
            SaleReport  reportCustomerSale = allReports.First(x => x.SaleType == SaleType.CustomerSale);
            List <Sale> customerSalesToday = salesToday.Where(x => x.IsDealerSale == false).ToList();

            CalculateAmounts(reportCustomerSale, customerSalesToday);
            reportCustomerSale.Modified = DateTime.Now;
            reportDb.Entry(reportCustomerSale).State = EntityState.Modified;
            reportDb.SaveChanges();
            return(true);
        }
Esempio n. 13
0
        public List <SaleReport> GetSalesReport(DateTime startDate, DateTime endDate)
        {
            List <SaleReport> saleReports = new List <SaleReport>();

            using (var context = new SMSDbContext())
            {
                var allProduct = context.Products.Include(x => x.Category).ToList();

                foreach (var product in allProduct)
                {
                    int productId = product.Id;
                    //int purchaseQty = _purchaseRepository.GetTotalProductByIdAndDate(productId, startDate);
                    //int salesQty = _saledetailsRepository.GetTotalProductByIdAndDate(productId, startDate);

                    //int inQty = _purchaseRepository.GetTotalProductByIdAndStartAndEndDate(productId, startDate, endDate);
                    int        outQty = _saledetailsRepository.GetTotalProductByIdAndStartAndEndDate(productId, startDate, endDate);
                    SaleReport model  = new SaleReport();

                    model.Code     = product.Code;
                    model.Product  = product.Name;
                    model.Category = product.Category.Name;
                    model.SoldQty  = outQty;
                    var pDetails = _purchaseDetailsRepository.GetPurchaseDetailByProductId(productId);
                    if (pDetails != null)
                    {
                        model.MRP = model.SoldQty * pDetails.MRP;
                        model.CP  = model.SoldQty * pDetails.UnitPrice;
                    }


                    model.Profit = model.MRP - model.CP;

                    saleReports.Add(model);
                }
            }

            return(saleReports);
        }
Esempio n. 14
0
        public bool ShopStart(DateTime date, string shopId)
        {
            ReportDbContext reportDb = ReportDbContext.Create();

            date = date.Date;

            SaleReport report = reportDb.SaleReports.Where(x => x.ShopId == shopId).FirstOrDefault(x => x.Date == date);

            if (report == null)
            {
                report = new SaleReport {
                    SaleType = SaleType.All
                };
                this.SetDefaults(report, shopId, date);

                var dealerReport = new SaleReport {
                    SaleType = SaleType.DealerSale
                };
                this.SetDefaults(dealerReport, shopId, date);

                var customerReport = new SaleReport {
                    SaleType = SaleType.CustomerSale
                };
                this.SetDefaults(customerReport, shopId, date);

                var collection = new List <SaleReport>()
                {
                    report, dealerReport, customerReport
                };
                reportDb.SaleReports.AddRange(collection);
                int i = reportDb.SaveChanges();
                return(i > 0);
            }

            return(true);
        }
Esempio n. 15
0
 public void AddSaleReport(SaleReport saleReport)
 {
     saleReports.Add(saleReport);
     CalculateTotalSaleReport();
 }
        private void ExecuteSave()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DateTime _dt = DateTime.Now;

            _newSale.RegistrationDate = _dt;
            _saleServ.AddSale(_newSale);
            int _saleID = _saleServ.GetLastSaleID();

            foreach (var item in _saleCategories)
            {
                SaleCategory _saleCategory = new SaleCategory
                {
                    CategoryID              = item.CategoryID,
                    Cost                    = item.Cost,
                    PriceAfterDiscount      = item.PriceAfterDiscount,
                    PriceTotalAfterDiscount = item.PriceTotalAfterDiscount,
                    CostTotal               = item.CostTotal,
                    Price                   = item.Price,
                    PriceTotal              = item.PriceTotal,
                    Discount                = item.Discount,
                    DiscountValue           = item.DiscountValue,
                    DiscountValueTotal      = item.DiscountValueTotal,
                    SaleID                  = _saleID,
                    Qty = item.Qty
                };
                _saleCategoryServ.AddSaleCategory(_saleCategory);

                Category cat = _categoryServ.GetCategory(item.CategoryID);
                cat.Qty = cat.Qty - item.Qty;
                _categoryServ.UpdateCategory(cat);
            }

            ClientAccount _account = new ClientAccount
            {
                ClientID         = _newSale.ClientID,
                Date             = _newSale.Date,
                RegistrationDate = _dt,
                Statement        = "فاتورة مبيعات رقم " + _saleID,
                Credit           = _newSale.Paid,
                Debit            = _newSale.PriceAfterDiscount + _newSale.TransportCost
            };

            _clientAccountServ.AddAccount(_account);

            if (_newSale.Paid > 0)
            {
                Safe _safe = new Safe
                {
                    Date             = _newSale.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مبيعات رقم " + _saleID + " للعميل: " + _selectedClient.Name,
                    Amount           = _newSale.Paid,
                    Source           = 4
                };
                _safeServ.AddSafe(_safe);
            }


            DS ds = new DS();

            ds.Sale.Rows.Clear();
            int i = 0;

            foreach (var item in _saleCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]            = _saleID;
                ds.Sale[i]["Date"]          = _newSale.Date;
                ds.Sale[i]["Client"]        = _selectedClient.Name;
                ds.Sale[i]["Serial"]        = i + 1;
                ds.Sale[i]["Category"]      = item.Category + " " + item.Company;
                ds.Sale[i]["Qty"]           = item.Qty;
                ds.Sale[i]["Price"]         = Math.Round(Convert.ToDecimal(item.PriceAfterDiscount), 2);
                ds.Sale[i]["TotalPrice"]    = Math.Round(Convert.ToDecimal(item.PriceTotalAfterDiscount), 2);
                ds.Sale[i]["BillPrice"]     = Math.Round(Convert.ToDecimal(_newSale.PriceAfterDiscount), 2);;
                ds.Sale[i]["OldDebt"]       = Math.Abs(Convert.ToDecimal(_newSale.OldDebt));
                ds.Sale[i]["TransportCost"] = _newSale.TransportCost;
                ds.Sale[i]["BillTotal"]     = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.PriceTotal), 2));
                ds.Sale[i]["Paid"]          = _newSale.Paid;
                ds.Sale[i]["NewDebt"]       = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.NewDebt), 2));
                if (_newSale.NewDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_newSale.NewDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }
                ds.Sale[i]["Salesperson"] = _selectedSalesperson.Name;
                ds.Sale[i]["PrintingMan"] = _newSale.PrintingMan;

                if (_newSale.OldDebt > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (_newSale.OldDebt < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                ds.Sale[i]["Address"] = _selectedClient.Address;
                try
                {
                    ToWord toWord = new ToWord(Math.Abs(Convert.ToDecimal(_newSale.NewDebt)), currencies[0]);
                    ds.Sale[i]["NewDebtAR"] = toWord.ConvertToArabic();
                }
                catch
                {
                    ds.Sale[i]["NewDebtAR"] = string.Empty;
                }
                i++;
            }
            ReportWindow rpt     = new ReportWindow();
            SaleReport   saleRPT = new SaleReport();

            saleRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = saleRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();
            NewSale         = new Sale();
            NewSaleCategory = new SaleCategoryVM();
            SaleCategories  = new ObservableCollection <SaleCategoryVM>();
            NewSale.Date    = DateTime.Now;
            OldPrices       = new ObservableCollection <SaleCategory>();
            _currentWindow.ShowDialog();
        }
Esempio n. 17
0
 public void RemoveSaleReport(SaleReport saleReport)
 {
     saleReports.Remove(saleReport);
 }
Esempio n. 18
0
        private void ExecuteSave(string parameter)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                DateTime _dt = DateTime.Now;
                _newSale.RegistrationDate = _dt;
                _saleServ.AddSale(_newSale);
                int _saleID = _saleServ.GetLastSaleID();

                foreach (var item in _saleCategories)
                {
                    SaleCategory _saleCategory = new SaleCategory
                    {
                        CategoryID = item.CategoryID,
                        Cost       = item.Cost,
                        CostTotal  = item.CostTotal,
                        Price      = item.Price,
                        PriceTotal = item.PriceTotal,
                        SaleID     = _saleID,
                        Qty        = item.Qty
                    };
                    _saleCategoryServ.AddSaleCategory(_saleCategory);

                    Category cat = _categoryServ.GetCategory(item.CategoryID);
                    cat.Qty = cat.Qty - item.Qty;
                    _categoryServ.UpdateCategory(cat);
                }

                ClientAccount _account = new ClientAccount
                {
                    ClientID         = _newSale.ClientID,
                    Date             = _newSale.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مبيعات رقم " + _saleID,
                    Credit           = _newSale.CashPaid + _newSale.DiscountPaid,
                    Debit            = _newSale.Price
                };
                _clientAccountServ.AddAccount(_account);

                if (_newSale.CashPaid > 0)
                {
                    Safe _safe = new Safe
                    {
                        Date             = _newSale.Date,
                        RegistrationDate = _dt,
                        Statement        = "فاتورة مبيعات رقم " + _saleID + " للعميل: " + _selectedClient.Name,
                        Amount           = _newSale.CashPaid,
                        Source           = 4
                    };
                    _safeServ.AddSafe(_safe);
                }

                DS ds = new DS();
                ds.Sale.Rows.Clear();
                int i = 0;
                foreach (var item in _saleCategories)
                {
                    ds.Sale.Rows.Add();
                    ds.Sale[i]["ID"]           = _saleID;
                    ds.Sale[i]["Date"]         = _newSale.Date;
                    ds.Sale[i]["Client"]       = _selectedClient.Name;
                    ds.Sale[i]["Serial"]       = i + 1;
                    ds.Sale[i]["Category"]     = item.Category + " " + item.Company;
                    ds.Sale[i]["Qty"]          = item.Qty;
                    ds.Sale[i]["Price"]        = Math.Round(Convert.ToDecimal(item.Price), 2);
                    ds.Sale[i]["TotalPrice"]   = Math.Round(Convert.ToDecimal(item.PriceTotal), 2);
                    ds.Sale[i]["BillPrice"]    = Math.Round(Convert.ToDecimal(_newSale.Price), 2);;
                    ds.Sale[i]["OldDebt"]      = Math.Abs(Convert.ToDecimal(_newSale.OldDebt));
                    ds.Sale[i]["BillTotal"]    = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.PriceTotal), 2));
                    ds.Sale[i]["Paid"]         = _newSale.CashPaid;
                    ds.Sale[i]["DiscountPaid"] = _newSale.DiscountPaid;
                    ds.Sale[i]["NewDebt"]      = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.NewDebt), 2));
                    if (_newSale.NewDebt > 0)
                    {
                        ds.Sale[i]["Type"] = "له";
                    }
                    else if (_newSale.NewDebt < 0)
                    {
                        ds.Sale[i]["Type"] = "عليه";
                    }

                    if (_newSale.OldDebt > 0)
                    {
                        ds.Sale[i]["Type2"] = "له";
                    }
                    else if (_newSale.OldDebt < 0)
                    {
                        ds.Sale[i]["Type2"] = "عليه";
                    }

                    i++;
                }
                ReportWindow rpt = new ReportWindow();
                if (parameter == "Client")
                {
                    SaleReport saleRPT = new SaleReport();
                    saleRPT.SetDataSource(ds.Tables["Sale"]);
                    rpt.crv.ViewerCore.ReportSource = saleRPT;
                    Mouse.OverrideCursor            = null;
                }
                else
                {
                    SaleReport2 saleRPT = new SaleReport2();
                    saleRPT.SetDataSource(ds.Tables["Sale"]);
                    rpt.crv.ViewerCore.ReportSource = saleRPT;
                    Mouse.OverrideCursor            = null;
                }
                _currentWindow.Hide();
                rpt.ShowDialog();
                NewSale         = new Sale();
                NewSaleCategory = new SaleCategoryVM();
                SaleCategories  = new ObservableCollection <SaleCategoryVM>();
                NewSale.Date    = DateTime.Now;
                OldPrices       = new ObservableCollection <SaleCategory>();
                _currentWindow.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public List <SaleReport> Sales(string userId, DateTime?fromDate, DateTime?toDate)
        {
            DateTime from;
            DateTime to;

            if (fromDate <= new DateTime(1 / 1 / 0001))
            {
                from = new DateTime(1899, 1, 1);
            }
            else
            {
                from = (DateTime)fromDate;
            }

            if (toDate <= new DateTime(1 / 1 / 0001))
            {
                to = new DateTime(2199, 1, 1);
            }
            else
            {
                to = (DateTime)toDate;
            }

            //DateTime from = fromDate ?? new DateTime(1899, 1, 1);
            //DateTime to = toDate ?? new DateTime(2299, 1, 1);

            List <SaleReport> reports = new List <SaleReport>();

            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = _connection;

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;

                if (userId != "")
                {
                    cmd.CommandText = "GetSalesReportOfSpecific";
                    cmd.Parameters.AddWithValue("@Id", userId);
                }
                else
                {
                    cmd.CommandText = "GetSalesReportOfAll";
                }

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@FromDate", from);
                cmd.Parameters.AddWithValue("@ToDate", to);

                conn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        SaleReport current = new SaleReport();

                        current.FullName          = dr["FullName"].ToString();
                        current.TotalSalesAmount  = (decimal)dr["TotalAmount"];
                        current.TotalVehiclesSold = (int)dr["Count"];

                        reports.Add(current);
                    }
                }
            }
            return(reports);
        }
Esempio n. 20
0
        private void PrintMethod(string parameter)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DS ds = new DS();

            ds.Sale.Rows.Clear();
            int i = 0;

            foreach (var item in _saleCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]           = ID;
                ds.Sale[i]["Date"]         = _selectedSale.Date;
                ds.Sale[i]["Client"]       = _selectedSale.Client.Name;
                ds.Sale[i]["Serial"]       = i + 1;
                ds.Sale[i]["Category"]     = item.Category + " " + item.Company;
                ds.Sale[i]["Qty"]          = item.Qty;
                ds.Sale[i]["Price"]        = Math.Round(Convert.ToDecimal(item.Price), 2);
                ds.Sale[i]["TotalPrice"]   = Math.Round(Convert.ToDecimal(item.PriceTotal), 2);
                ds.Sale[i]["BillPrice"]    = _selectedSale.Price;
                ds.Sale[i]["OldDebt"]      = Math.Abs(Convert.ToDecimal(_selectedSale.OldDebt));
                ds.Sale[i]["BillTotal"]    = Math.Abs(Convert.ToDecimal(_selectedSale.PriceTotal));
                ds.Sale[i]["Paid"]         = _selectedSale.CashPaid;
                ds.Sale[i]["DiscountPaid"] = _selectedSale.DiscountPaid;
                ds.Sale[i]["NewDebt"]      = Math.Abs(Convert.ToDecimal(_selectedSale.NewDebt));
                if (_selectedSale.NewDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_selectedSale.NewDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }

                if (_selectedSale.OldDebt > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (_selectedSale.OldDebt < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                i++;
            }
            ReportWindow rpt = new ReportWindow();

            if (parameter == "Client")
            {
                SaleReport saleRPT = new SaleReport();
                saleRPT.SetDataSource(ds.Tables["Sale"]);
                rpt.crv.ViewerCore.ReportSource = saleRPT;
                Mouse.OverrideCursor            = null;
            }
            else
            {
                SaleReport2 saleRPT = new SaleReport2();
                saleRPT.SetDataSource(ds.Tables["Sale"]);
                rpt.crv.ViewerCore.ReportSource = saleRPT;
                Mouse.OverrideCursor            = null;
            }
            _currentWindow.Hide();
            rpt.ShowDialog();
            _currentWindow.ShowDialog();
        }
        private void PrintMethod()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DS ds = new DS();

            ds.Sale.Rows.Clear();
            int i = 0;

            foreach (var item in _saleCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]            = ID;
                ds.Sale[i]["Date"]          = _selectedSale.Date;
                ds.Sale[i]["Client"]        = _selectedSale.Client.Name;
                ds.Sale[i]["Serial"]        = i + 1;
                ds.Sale[i]["Category"]      = item.Category + " " + item.Company;
                ds.Sale[i]["Qty"]           = item.Qty;
                ds.Sale[i]["Price"]         = Math.Round(Convert.ToDecimal(item.PriceAfterDiscount), 2);
                ds.Sale[i]["TotalPrice"]    = Math.Round(Convert.ToDecimal(item.PriceTotalAfterDiscount), 2);
                ds.Sale[i]["BillPrice"]     = _selectedSale.PriceAfterDiscount;
                ds.Sale[i]["OldDebt"]       = Math.Abs(Convert.ToDecimal(_selectedSale.OldDebt));
                ds.Sale[i]["TransportCost"] = _selectedSale.TransportCost;
                ds.Sale[i]["BillTotal"]     = Math.Abs(Convert.ToDecimal(_selectedSale.PriceTotal));
                ds.Sale[i]["Paid"]          = _selectedSale.Paid;
                ds.Sale[i]["NewDebt"]       = Math.Abs(Convert.ToDecimal(_selectedSale.NewDebt));
                if (_selectedSale.NewDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_selectedSale.NewDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }
                ds.Sale[i]["Salesperson"] = _selectedSale.Salesperson.Name;
                ds.Sale[i]["PrintingMan"] = _selectedSale.PrintingMan;

                if (_selectedSale.OldDebt > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (_selectedSale.OldDebt < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                ds.Sale[i]["Address"] = _selectedSale.Client.Address;
                try
                {
                    ToWord toWord = new ToWord(Math.Abs(Convert.ToDecimal(_selectedSale.NewDebt)), currencies[0]);
                    ds.Sale[i]["NewDebtAR"] = toWord.ConvertToArabic();
                }
                catch
                {
                    ds.Sale[i]["NewDebtAR"] = string.Empty;
                }
                i++;
            }
            ReportWindow rpt     = new ReportWindow();
            SaleReport   saleRPT = new SaleReport();

            saleRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = saleRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();
            _currentWindow.ShowDialog();

            //var dialog = new PrintDialog();
            //dialog.PrintVisual(_currentWindow, "ss");
            //bool? print = dialog.ShowDialog();
            //if (print.HasValue && print.Value)
            //{
            //    string startupPath = Environment.CurrentDirectory;
            //    printorderRPT.Load(startupPath + @"\..\..\PrintingOrderPaperRpt.rpt");
            //    printorderRPT.SetDataSource(ds.Tables["PrintOrder"]);
            //    printorderRPT.Subreports[0].SetDataSource(ds.Tables["PrintOrderRaws"]);
            //    printorderRPT.PrintOptions.PrinterName = dialog.PrintQueue.Name;
            //    try
            //    {
            //        printorderRPT.PrintToPrinter(1, true, 0, 0);
            //    }
            //    catch { }
            //}
        }