コード例 #1
0
        public async Task <IActionResult> PutCashInHand(int id, CashInHand cashInHand)
        {
            if (id != cashInHand.CashInHandId)
            {
                return(BadRequest());
            }

            _context.Entry(cashInHand).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CashInHandExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <CashInHand> > PostCashInHand(CashInHand cashInHand)
        {
            _context.CashInHands.Add(cashInHand);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCashInHand", new { id = cashInHand.CashInHandId }, cashInHand));
        }
コード例 #3
0
        public static AccountsInfo GetAccoutingRecord(AprajitaRetailsContext db)
        {
            AccountsInfo info = new AccountsInfo();
            CashInHand   cih  = db.CashInHands.Where(c => (c.CIHDate) == (DateTime.Today)).FirstOrDefault();

            if (cih != null)
            {
                info.CashInHand  = cih.InHand; info.CashIn = cih.CashIn; info.CashOut = cih.CashOut;
                info.OpenningBal = cih.OpenningBalance;
            }

            CashInBank cib = db.CashInBanks.Where(c => (c.CIBDate) == (DateTime.Today)).FirstOrDefault();

            if (cib != null)
            {
                info.CashToBank = cib.CashIn; info.CashFromBank = cib.CashOut;
                info.CashInBank = cib.InHand;
            }

            var CashExp = db.PettyCashExpenses.Where(c => (c.ExpDate) == (DateTime.Today));
            var CashPay = db.CashPayments.Where(c => (c.PaymentDate) == (DateTime.Today));

            if (CashExp != null)
            {
                info.TotalCashPayments = (decimal?)CashExp.Sum(c => (decimal?)c.Amount) ?? 0;
            }
            if (CashPay != null)
            {
                info.TotalCashPayments += (decimal?)CashPay.Sum(c => (decimal?)c.Amount) ?? 0;
            }
            return(info);
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("CashInHandId,CIHDate,OpenningBalance,ClosingBalance,CashIn,CashOut,StoreId")] CashInHand cashInHand)
        {
            if (id != cashInHand.CashInHandId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cashInHand);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CashInHandExists(cashInHand.CashInHandId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StoreId"] = new SelectList(_context.Stores, "StoreId", "StoreId", cashInHand.StoreId);
            return(View(cashInHand));
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            CashInHand cashInHand = db.CashInHands.Find(id);

            db.CashInHands.Remove(cashInHand);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "CashInHandId,CIHDate,OpenningBalance,ClosingBalance,CashIn,CashOut")] CashInHand cashInHand)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cashInHand).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cashInHand));
 }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("CashInHandId,CIHDate,OpenningBalance,ClosingBalance,CashIn,CashOut")] CashInHand cashInHand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cashInHand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView(cashInHand));
        }
コード例 #8
0
        public ActionResult Create([Bind(Include = "CashInHandId,CIHDate,OpenningBalance,ClosingBalance,CashIn,CashOut")] CashInHand cashInHand)
        {
            if (ModelState.IsValid)
            {
                db.CashInHands.Add(cashInHand);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cashInHand));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("CashInHandId,CIHDate,OpenningBalance,ClosingBalance,CashIn,CashOut,StoreId")] CashInHand cashInHand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cashInHand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StoreId"] = new SelectList(_context.Stores, "StoreId", "StoreId", cashInHand.StoreId);
            return(View(cashInHand));
        }
コード例 #10
0
        public void Process_OpenningBalance(AprajitaRetailsContext db, DateTime date, bool saveit = false)
        {
            CashInHand today;

            today = db.CashInHands.Where(c => c.CIHDate.Date == date.Date).FirstOrDefault();

            DateTime   yDate     = date.AddDays(-1);
            CashInHand yesterday = db.CashInHands.Where(c => (c.CIHDate.Date) == (yDate.Date)).FirstOrDefault();
            bool       isNew     = false;

            if (today == null)
            {
                today = new CashInHand()
                {
                    CashIn = 0, CashOut = 0, CIHDate = date, ClosingBalance = 0, OpenningBalance = 0
                };
                isNew = true;
            }

            if (yesterday == null)
            {
                yesterday = new CashInHand()
                {
                    CashIn = 0, CashOut = 0, CIHDate = yDate, ClosingBalance = 0, OpenningBalance = 0
                };
                today.OpenningBalance = 0;
                today.ClosingBalance  = today.OpenningBalance + today.CashIn - today.CashOut;
                db.CashInHands.Add(yesterday);
            }
            else
            {
                yesterday.ClosingBalance = yesterday.OpenningBalance + yesterday.CashIn - yesterday.CashOut;

                today.OpenningBalance = yesterday.ClosingBalance;
                today.ClosingBalance  = today.OpenningBalance + today.CashIn - today.CashOut;

                db.Entry(yesterday).State = EntityState.Modified;
            }

            if (isNew)
            {
                db.CashInHands.Add(today);
            }
            else
            {
                db.Entry(today).State = EntityState.Modified;
            }

            if (saveit)
            {
                db.SaveChanges();
            }
        }
コード例 #11
0
        // GET: CashInHands/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CashInHand cashInHand = db.CashInHands.Find(id);

            if (cashInHand == null)
            {
                return(HttpNotFound());
            }
            return(View(cashInHand));
        }
コード例 #12
0
        //Function used
        public static List <CashBook> UpdateCashInHand_DB(AprajitaRetailsContext db, List <CashBook> books)
        {
            IEnumerable <CashBook> orderBook  = books.OrderBy(c => c.EDate);
            CashInHand             cashInHand = null;
            DateTime startDate = orderBook.First().EDate;

            DeleteCashInHandForMonth(db, startDate);

            foreach (var item in orderBook)
            {
                if (cashInHand == null)
                {
                    db.SaveChanges();
                    cashInHand = new CashInHand()
                    {
                        CIHDate         = item.EDate,
                        OpenningBalance = 0,
                        CashIn          = item.CashIn,
                        CashOut         = item.CashOut,
                        ClosingBalance  = 0
                    };
                }
                else if (startDate != item.EDate && cashInHand != null)
                {
                    db.CashInHands.Add(cashInHand);
                    db.SaveChanges();
                    cashInHand = new CashInHand()
                    {
                        CIHDate         = item.EDate,
                        OpenningBalance = 0,
                        CashIn          = item.CashIn,
                        CashOut         = item.CashOut,
                        ClosingBalance  = 0
                    };
                    startDate = item.EDate;
                }
                else
                {
                    cashInHand.CashIn  += item.CashIn;
                    cashInHand.CashOut += item.CashOut;
                }
            }
            db.CashInHands.Add(cashInHand);
            db.SaveChanges();

            return(orderBook.ToList());
        }
コード例 #13
0
        //Update CashInHand/Bank
        public static void UpdateCashInHand(AprajitaRetailsContext db, DateTime dateTime, decimal Amount, bool saveit = false)
        {
            CashInHand cashIn = db.CashInHands.Where(d => d.CIHDate == dateTime).FirstOrDefault();

            if (cashIn != null)
            {
                cashIn.CashIn         += Amount;
                db.Entry(cashIn).State = EntityState.Modified;
                if (saveit)
                {
                    db.SaveChanges();
                }
            }
            else
            {
                CreateCashInHand(db, dateTime, Amount, 0, saveit);
            }
        }
コード例 #14
0
        //Update CashOutHand/Bank
        public static void UpDateCashOutHand(eStoreDbContext db, DateTime dateTime, decimal Amount, bool saveit = false)
        {
            //throw new NotImplementedException();
            CashInHand cashIn = db.CashInHands.Where(d => d.CIHDate == dateTime).FirstOrDefault();

            if (cashIn != null)
            {
                cashIn.CashOut        += Amount;
                db.Entry(cashIn).State = EntityState.Modified;
                if (saveit)
                {
                    db.SaveChanges();
                }
            }
            else
            {
                CreateCashInHand(db, dateTime, 0, Amount, saveit);
            }
        }
コード例 #15
0
ファイル: Utils.cs プロジェクト: war-man/TAS_AprajiataRetails
 public static void UpDateCashOutHand(AprajitaRetailsContext db, DateTime dateTime, decimal Amount, bool saveit = false)
 {
     {
         CashInHand cashIn = db.CashInHands.Where(d => d.CIHDate == dateTime).FirstOrDefault();
         if (cashIn != null)
         {
             cashIn.CashOut        += Amount;
             db.Entry(cashIn).State = EntityState.Modified;
             if (saveit)
             {
                 db.SaveChanges();
             }
         }
         else
         {
             //db.CashInHands.Add(new CashInHand() { CIHDate = dateTime, CashIn = 0, OpenningBalance = 0, ClosingBalance = 0, CashOut = Amount });
             //if (saveit) db.SaveChanges();
             CreateCashInHand(db, dateTime, 0, Amount, saveit);
         }
     }
 }
コード例 #16
0
ファイル: Utils.cs プロジェクト: war-man/TAS_AprajiataRetails
        public static void CreateCashInHand(AprajitaRetailsContext db, DateTime date, decimal inAmt, decimal outAmt, bool saveit = false)
        {
            //One Day Back
            DateTime   yDate     = date.AddDays(-1);
            CashInHand yesterday = db.CashInHands.Where(c => c.CIHDate == yDate).FirstOrDefault();
            CashInHand today     = new CashInHand()
            {
                CashIn = inAmt, CashOut = outAmt, CIHDate = date, ClosingBalance = 0, OpenningBalance = 0
            };

            if (yesterday != null)
            {
                yesterday.ClosingBalance = yesterday.OpenningBalance + yesterday.CashIn - yesterday.CashOut;
                today.ClosingBalance     = today.OpenningBalance = yesterday.ClosingBalance;
                db.CashInHands.Add(today);
                if (saveit)
                {
                    db.SaveChanges();
                }
            }
            else
            {
                if (db.CashInHands.Count() > 0)
                {
                    throw new Exception();
                }
                //TODO: if yesterday one or day back data not present handel this
                else
                {
                    today.ClosingBalance = today.OpenningBalance = 0;
                    db.CashInHands.Add(today);
                    if (saveit)
                    {
                        db.SaveChanges();
                    }
                }
            }
        }
コード例 #17
0
ファイル: Utils.cs プロジェクト: war-man/TAS_AprajiataRetails
        public static void ProcessOpenningClosingBalance(AprajitaRetailsContext db, DateTime date, bool isclosing = false, bool saveit = false)
        {
            if (!isclosing)
            {
                CashInHand today;
                today = db.CashInHands.Where(c => DbFunctions.TruncateTime(c.CIHDate) == DbFunctions.TruncateTime(date)).FirstOrDefault();

                DateTime   yDate     = date.AddDays(-1);
                CashInHand yesterday = db.CashInHands.Where(c => DbFunctions.TruncateTime(c.CIHDate) == DbFunctions.TruncateTime(yDate)).FirstOrDefault();

                if (today == null)
                {
                    today = new CashInHand()
                    {
                        CashIn = 0, CashOut = 0, CIHDate = date, ClosingBalance = 0, OpenningBalance = 0
                    };

                    if (yesterday != null)
                    {
                        yesterday.ClosingBalance = yesterday.OpenningBalance + yesterday.CashIn - yesterday.CashOut;
                        today.ClosingBalance     = today.OpenningBalance = yesterday.ClosingBalance;
                        db.CashInHands.Add(today);
                        if (saveit)
                        {
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        if (db.CashInHands.Count() > 0)
                        {
                            throw new Exception();
                        }
                        //TODO: if yesterday one or day back data not present handel this
                        else
                        {
                            today.ClosingBalance = today.OpenningBalance = 0;
                            db.CashInHands.Add(today);
                            if (saveit)
                            {
                                db.SaveChanges();
                            }
                        }
                    }
                }
                else
                {
                    if (yesterday != null)
                    {
                        today.ClosingBalance  = today.OpenningBalance = yesterday.ClosingBalance;
                        db.Entry(today).State = EntityState.Modified;
                        if (saveit)
                        {
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        if (db.CashInHands.Count() > 1)
                        {
                            throw new Exception();
                        }
                        //TODO: if yesterday one or day back data not present handel this
                        else
                        {
                            today.ClosingBalance  = today.OpenningBalance = 0;
                            db.Entry(today).State = EntityState.Modified;
                            if (saveit)
                            {
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
            else
            {
                //ClosingBalance;
                CashInHand today;
                today = db.CashInHands.Where(c => DbFunctions.TruncateTime(c.CIHDate) == DbFunctions.TruncateTime(date)).FirstOrDefault();
                if (today != null)
                {
                    if (today.ClosingBalance != today.OpenningBalance + today.CashIn - today.CashOut)
                    {
                        today.ClosingBalance  = today.OpenningBalance + today.CashIn - today.CashOut;
                        db.Entry(today).State = EntityState.Modified;
                        if (saveit)
                        {
                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
        }
コード例 #18
0
        private List <CashBook> CreateCashInHands(AprajitaRetailsContext db, List <CashBook> books)
        {
            IEnumerable <CashBook> orderBook = books.OrderBy(c => c.EDate);

            CashInHand cashInHand = null;
            DateTime   startDate  = orderBook.First().EDate;

            //Remove CashInHand from Database
            DeleteCashInHandForMonth(db, startDate);

            foreach (var item in orderBook)
            {
                if (cashInHand == null)
                {
                    db.SaveChanges();
                    cashInHand = new CashInHand()
                    {
                        CIHDate         = item.EDate,
                        OpenningBalance = 0,
                        CashIn          = item.CashIn,
                        CashOut         = item.CashOut,
                        ClosingBalance  = 0
                    };
                }
                else if (startDate != item.EDate && cashInHand != null)
                {
                    db.CashInHands.Add(cashInHand);

                    var datediff = startDate - item.EDate;
                    if (datediff.TotalDays > 1)
                    {
                        for (int xo = 1; xo < datediff.TotalDays; xo++)
                        {
                            cashInHand = new CashInHand()
                            {
                                CIHDate         = startDate.AddDays(xo),
                                OpenningBalance = 0,
                                CashIn          = 0,
                                CashOut         = 0,
                                ClosingBalance  = 0
                            };
                            db.CashInHands.Add(cashInHand);
                        }
                    }
                    db.SaveChanges();
                    cashInHand = new CashInHand()
                    {
                        CIHDate         = item.EDate,
                        OpenningBalance = 0,
                        CashIn          = item.CashIn,
                        CashOut         = item.CashOut,
                        ClosingBalance  = 0
                    };
                    startDate = item.EDate;
                }
                else
                {
                    cashInHand.CashIn  += item.CashIn;
                    cashInHand.CashOut += item.CashOut;
                }
            }
            db.CashInHands.Add(cashInHand);
            db.SaveChanges();

            return(orderBook.ToList());
        }
コード例 #19
0
        private List <CashInHand> CreateCashInHands(AprajitaRetailsContext db, List <CashBook> orderBook)
        {
            List <CashInHand> inHandList = new List <CashInHand> ();

            CashInHand cashInHand = null;
            DateTime   startDate  = orderBook.First().EDate;

            //Remove CashInHand from Database
            DeleteCashInHandForMonth(db, startDate);

            if (startDate.Date != new DateTime(startDate.Year, startDate.Month, 1))
            {
                CashInHand first = new CashInHand()
                {
                    CIHDate         = new DateTime(startDate.Year, startDate.Month, 1),
                    OpenningBalance = 0,
                    CashIn          = 0,
                    CashOut         = 0,
                    ClosingBalance  = 0
                };
                db.CashInHands.Add(first);
                inHandList.Add(first);
                db.SaveChanges();
            }

            foreach (var item in orderBook)
            {
                if (cashInHand == null)
                {
                    db.SaveChanges();
                    cashInHand = new CashInHand()
                    {
                        CIHDate         = item.EDate,
                        OpenningBalance = 0,
                        CashIn          = item.CashIn,
                        CashOut         = item.CashOut,
                        ClosingBalance  = 0
                    };
                }
                else if (startDate != item.EDate && cashInHand != null)
                {
                    db.CashInHands.Add(cashInHand);
                    inHandList.Add(cashInHand);
                    db.SaveChanges();
                    var datediff = item.EDate - startDate;
                    if (datediff.TotalDays > 1)
                    {
                        for (int xo = 1; xo < datediff.TotalDays; xo++)
                        {
                            cashInHand = new CashInHand()
                            {
                                CIHDate         = startDate.AddDays(xo),
                                OpenningBalance = 0,
                                CashIn          = 0,
                                CashOut         = 0,
                                ClosingBalance  = 0
                            };
                            db.CashInHands.Add(cashInHand);
                            inHandList.Add(cashInHand);
                            db.SaveChanges();
                        }
                    }

                    cashInHand = new CashInHand()
                    {
                        CIHDate         = item.EDate,
                        OpenningBalance = 0,
                        CashIn          = item.CashIn,
                        CashOut         = item.CashOut,
                        ClosingBalance  = 0
                    };
                    startDate = item.EDate;
                }
                else
                {
                    cashInHand.CashIn  += item.CashIn;
                    cashInHand.CashOut += item.CashOut;
                }
            }
            db.CashInHands.Add(cashInHand);
            inHandList.Add(cashInHand);
            db.SaveChanges();
            DateTime endDate;

            endDate = new DateTime(startDate.Year, startDate.Month, DateTime.DaysInMonth(startDate.Year, startDate.Month));
            if (startDate != endDate)
            {
                var datediff = endDate - startDate;
                if (datediff.TotalDays > 1)
                {
                    for (int xo = 1; xo < datediff.TotalDays; xo++)
                    {
                        cashInHand = new CashInHand()
                        {
                            CIHDate         = startDate.AddDays(xo),
                            OpenningBalance = 0,
                            CashIn          = 0,
                            CashOut         = 0,
                            ClosingBalance  = 0
                        };
                        db.CashInHands.Add(cashInHand);
                        inHandList.Add(cashInHand);
                        db.SaveChanges();
                    }
                }

                cashInHand = new CashInHand()
                {
                    CIHDate         = endDate,
                    OpenningBalance = 0,
                    CashIn          = 0,
                    CashOut         = 0,
                    ClosingBalance  = 0
                };
                db.CashInHands.Add(cashInHand);
                inHandList.Add(cashInHand);
                db.SaveChanges();
            }
            return(inHandList);
        }
コード例 #20
0
    protected void btnBuy_Click(object sender, EventArgs e)
    {
        decimal CustomerBalance;
        decimal Price = 0;
        decimal CashInHand;
        decimal AdminBalance  = 0;
        decimal SellerBalance = 0;
        decimal AgencyFee;


        //Retrieve Customer Balance which meet account number and security code from Account
        DataView dv = (DataView)AccountDS.Select(DataSourceSelectArguments.Empty);

        foreach (DataRowView dr in dv)
        {
            if (txtAccountNumber.Text == dr[0].ToString() && txtSecurityCode.Text == dr[1].ToString())
            {
                CustomerBalance = decimal.Parse(dr[2].ToString());
                //Retrieve Price from Item
                DataView dv1 = (DataView)ItemDS.Select(DataSourceSelectArguments.Empty);
                foreach (DataRowView dr1 in dv1)
                {
                    Price = decimal.Parse(dr1[5].ToString());     //Retrieve Price From Item
                }
                if (CustomerBalance > Price)
                {
                    CashInHand = CustomerBalance - Price;

                    if (CashInHand >= 1000)
                    {
                        Session["Balance"] = CashInHand.ToString();
                        AccountDS.Update();

                        txtAccountNumber.Text = "";
                        txtSecurityCode.Text  = "";

                        //Retrieve Admin Balance from Account and plus agency fee and update it
                        DataView dv2 = (DataView)AccountForAdminDS.Select(DataSourceSelectArguments.Empty);
                        foreach (DataRowView dr2 in dv2)
                        {
                            AdminBalance = decimal.Parse(dr2[0].ToString());
                            break;
                        }
                        AdminBalance       = AdminBalance + (Price * (decimal)0.05);
                        Session["Balance"] = AdminBalance.ToString();
                        AccountForAdminDS.Update();

                        //Retrieve Seller Balance and plus item's amount
                        DataView dv3 = (DataView)AccountForSellerDS.Select(DataSourceSelectArguments.Empty);
                        foreach (DataRowView dr3 in dv3)
                        {
                            SellerBalance = decimal.Parse(dr3[0].ToString());
                        }

                        SellerBalance      = SellerBalance + (Price - (Price * (decimal)0.05));
                        Session["Balance"] = SellerBalance.ToString();
                        AccountForSellerDS.Update();



                        Session["PurchaseDate"] = DateTime.Now.ToShortDateString();

                        SqlDataSourceUpdate.Update();

                        int pid;
                        try
                        {
                            SqlConnection conn = new SqlConnection(@"Data Source=LAEMON-PC\GROUP3_SERVER;Initial Catalog=ITSocietyDB;User ID=sa;Password=group3");
                            SqlCommand    cmd  = new SqlCommand("select max(purchaseID) from PurchaseInfo", conn);
                            conn.Open();
                            SqlDataReader rader1 = cmd.ExecuteReader();
                            rader1.Read();
                            pid = int.Parse(rader1[0].ToString());
                            pid++;
                            conn.Close();
                        }
                        catch (Exception)
                        {
                            pid = 1;
                        }

                        Session["pid"] = pid;
                        PurchaseDS.Insert();

                        lblMsg.Text = "Successfully Purchased! Thank You For Purchasing";

                        lbtnPurchase.Visible = false;
                        pnlPurchase.Visible  = false;
                        break;
                    }
                    else
                    {
                        lblMsg.Text = "Your Balance is lower than 1000 Kyats!";
                    }
                }
                else
                {
                    lblMsg.Text = "Your Balance is not enough for purchase!";
                }
                break;
            }
            else
            {
                lblMsg.Text = "Your Informatin is not Valid!";
            }
        }
    }