Example #1
0
        public DataTable TestImportExcel(eStoreDbContext db, string fileName)
        {
            Console.WriteLine(fileName);
            XSReader xS = new XSReader(fileName);

            var ws = xS.GetWS("Employees");
            var dt = XSReader.ReadSheetToDt(ws, 6);
            int c  = dt.Columns.IndexOf("UserName");

            dt.Columns[c].ColumnName = "UserId";
            dt.Columns.Add("EntryStatus");
            dt.Columns.Add("IsReadOnly");
            int c1 = 101;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["EntryStatus"] = EntryStatus.Added;
                dt.Rows[i]["IsReadOnly"]  = true;
                dt.Rows[i][0]             = ((i + 1 * 201) * c1 / 3) * i;
                c1 = c1 + new Random(c1).Next();
            }
            dt.AcceptChanges();
            //JsonConvert.SerializeObject(dt);
            //
            var lst = CommonMethod.ConvertToList <Employee>(dt);

            //var lst = DAL.CreateListFromTable<Employee>(dt);
            db.Employees.AddRange(lst);
            Console.WriteLine(JsonConvert.SerializeObject(dt));
            Console.WriteLine("Save: " + db.SaveChanges());
            return(dt);
        }
Example #2
0
        public ActionResult DeleteBillNo(int?id)
        {
            string errMsg = "Error!";
            int    ret    = 0;

            if (id == null)
            {
                errMsg = "Kindly send Invoice No!";
                return(Json(new { Count = ret, Msg = errMsg }));
            }

            var inv = aprajitaContext.RegularInvoices.Include(c => c.PaymentDetail).Include(c => c.SaleItems).Include(c => c.PaymentDetail.CardDetail).Where(c => c.RegularInvoiceId == id).FirstOrDefault();

            if (inv == null)
            {
                errMsg = "Invoice Number Not found!";
            }
            else
            {
                aprajitaContext.RegularInvoices.Remove(inv);
                ret = aprajitaContext.SaveChanges();
                if (ret > 0)
                {
                    errMsg = "Invoice is Deleted!";
                }
                else
                {
                    errMsg = "It fails to delete Invoice!";
                }
            }

            return(Json(new { Count = ret, Msg = errMsg }));
        }
Example #3
0
        //StoreBased Action
        public void CashInBankCorrectionForMonth(eStoreDbContext db, DateTime forDate, int StoreId)
        {
            IEnumerable <CashInBank> cashs = db.CashInBanks.Where(c => c.CIBDate.Month == forDate.Month && c.CIBDate.Year == forDate.Year && c.StoreId == StoreId).OrderBy(c => c.CIBDate);

            decimal cBal = 0;

            if (cashs != null && cashs.Any())
            {
                cBal = GetClosingBalance(db, cashs.First().CIBDate, StoreId);
                if (cBal == 0)
                {
                    cBal = cashs.First().OpenningBalance;
                }

                foreach (var cash in cashs)
                {
                    cash.OpenningBalance = cBal;

                    cash.ClosingBalance = cash.OpenningBalance + cash.CashIn - cash.CashOut;
                    cBal = cash.ClosingBalance;

                    db.Entry(cash).State = EntityState.Modified;
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    // Log.Info("CashInBank Correction failed");
                }
            }
        }
Example #4
0
        // Correct Cash In Hand In Database
        /// <summary>
        /// Delete Cash In Hand For Particular Month & Year and Store
        /// </summary>
        /// <param name="db"></param>
        /// <param name="date"></param>
        private void DeleteCashInHandForMonth(eStoreDbContext db, DateTime date, int Store)
        {
            var cih = db.CashInHands.Where(c => c.CIHDate.Month == date.Month && c.CIHDate.Year == date.Year && c.StoreId == Store);

            db.CashInHands.RemoveRange(cih);
            db.SaveChanges();
        }
Example #5
0
        //StoreBased Action
        public void ProcessBankOpenningBalance(eStoreDbContext db, DateTime date, int StoreId, bool saveit = false)
        {
            CashInBank today;

            today = db.CashInBanks.Where(c => c.CIBDate.Date == date.Date && c.StoreId == StoreId).FirstOrDefault();

            DateTime   yDate     = date.AddDays(-1);
            CashInBank yesterday = db.CashInBanks.Where(c => c.CIBDate.Date == yDate.Date && c.StoreId == StoreId).FirstOrDefault();

            bool isNew = false;

            if (today == null)
            {
                today = new CashInBank()
                {
                    CashIn = 0, CashOut = 0, CIBDate = date, ClosingBalance = 0, OpenningBalance = 0, StoreId = StoreId
                };
                isNew = true;
            }

            if (yesterday == null)
            {
                yesterday = new CashInBank()
                {
                    CashIn = 0, CashOut = 0, CIBDate = yDate, ClosingBalance = 0, OpenningBalance = 0, StoreId = StoreId
                };
                today.OpenningBalance = 0;
                today.ClosingBalance  = today.OpenningBalance + today.CashIn - today.CashOut;
                db.CashInBanks.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.CashInBanks.Add(today);
            }
            else
            {
                db.Entry(today).State = EntityState.Modified;
            }

            if (saveit)
            {
                db.SaveChanges();
            }
        }
Example #6
0
        public static void CreateCashInBank(eStoreDbContext db, DateTime date, decimal inAmt, decimal outAmt, bool saveit = false)
        {
            //throw new NotImplementedException();

            CashInBank today;

            DateTime   yDate     = date.AddDays(-1);
            CashInBank yesterday = db.CashInBanks.Where(c => c.CIBDate == yDate).FirstOrDefault();


            today = new CashInBank()
            {
                CashIn = inAmt, CashOut = outAmt, CIBDate = date, ClosingBalance = 0, OpenningBalance = 0
            };

            if (yesterday != null)
            {
                yesterday.ClosingBalance = yesterday.OpenningBalance + yesterday.CashIn - yesterday.CashOut;
                today.ClosingBalance     = today.OpenningBalance = yesterday.ClosingBalance;
                db.CashInBanks.Add(today);
                if (saveit)
                {
                    db.SaveChanges();
                }
            }
            else
            {
                //TODO: need to option to create cashinbank entry for all missing entry and correct
                //if (db.CashInBanks.Count() > 0)
                //    throw new Exception();
                //else
                {
                    today.ClosingBalance = today.OpenningBalance = 0;
                    db.CashInBanks.Add(today);
                    if (saveit)
                    {
                        db.SaveChanges();
                    }
                }
            }
        }
Example #7
0
 public static int AddExpLedgerType(eStoreDbContext db)
 {
     string[] lists = { "Electricity", "Postage", "HomeExpenses", "Out of Store", "Assests", "Freight", "Serivces", "Tax & Duties" };
     foreach (var item in lists)
     {
         LedgerType lt = new LedgerType {
             LedgerNameType = item, Remark = item, Category = LedgerCategory.Expenses
         };
         db.LedgerTypes.Add(lt);
     }
     return(db.SaveChanges());
 }
Example #8
0
        public static int CreateLedgerMaster(eStoreDbContext db, Party party)
        {
            LedgerMaster master = new LedgerMaster
            {
                CreatingDate = DateTime.Today,
                PartyId      = party.PartyId,
                LedgerTypeId = party.LedgerTypeId
            };

            db.Add(master);
            return(db.SaveChanges());
        }
Example #9
0
        //Edit Based on Required Below Function
        //Create CashInHand/Bank
        public static void CreateCashInHand(eStoreDbContext db, DateTime date, decimal inAmt, decimal outAmt, bool saveit = false)
        {
            // throw new NotImplementedException();
            //TODO: make new age function error free
            //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();
                    }
                }
            }
        }
Example #10
0
        public void AddToDoList(eStoreDbContext db, string title, string msg, DateTime duedate)
        {
            ToDoMessage todo = new ToDoMessage
            {
                IsOver  = false,
                OnDate  = DateTime.Now,
                Message = msg,
                DueDate = duedate,
                Status  = "Pending",
                Title   = title
            };

            db.ToDoMessages.Add(todo);
            db.SaveChanges();
        }
Example #11
0
        public static int UpdateLedgerMaster(eStoreDbContext db, Party party)
        {
            var master = db.LedgerMasters.Where(c => c.PartyId == party.PartyId).FirstOrDefault();

            if (master != null)
            {
                master.LedgerTypeId = party.LedgerTypeId;
                db.Update(master);
                return(db.SaveChanges());
            }
            else
            {
                return(-1);
            }
        }
Example #12
0
        public static int AddPartyList(eStoreDbContext db)
        {
            foreach (var item in Head)
            {
                Party p = new Party
                {
                    Address      = "Dumka",
                    PartyName    = item, OpenningDate = DateTime.Today, OpenningBalance = 0,
                    LedgerTypeId = 7
                };

                db.Parties.Add(p);
            }
            return(db.SaveChanges());
        }
Example #13
0
        public async System.Threading.Tasks.Task ReadPayRollAsync(string fileName)
        {
            xS = new XSReader(fileName);

            if (xS.WorkBookName == "PayRoll")
            {
                db.Attendances.RemoveRange(db.Attendances);
                db.SalaryPayments.RemoveRange(db.SalaryPayments);
                db.Salesmen.RemoveRange(db.Salesmen);
                db.Employees.RemoveRange(db.Employees);

                db.SaveChanges();


                await AddEmployeesAsync(xS.GetWS("Employees"));

                // await AddAllSheetAsync();
                // await AddCurrentSalarAsync(xS.GetWS("CurrentSalaries"));
            }
            else
            {
                throw new Exception();
            }
        }
Example #14
0
        public static void UpdateCashInBank(eStoreDbContext db, DateTime dateTime, decimal Amount, bool saveit = false)
        {
            //throw new NotImplementedException();
            CashInBank cashIn = db.CashInBanks.Where(d => d.CIBDate == dateTime).FirstOrDefault();

            if (cashIn != null)
            {
                cashIn.CashIn += Amount;
                db.SaveChanges();
            }
            else
            {
                CreateCashInBank(db, dateTime, Amount, 0, saveit);
            }
        }
Example #15
0
        //StoreBased Action
        public void ProcessBankClosingBalance(eStoreDbContext db, DateTime date, int StoreId, bool saveit = false)
        {
            CashInBank today;

            today = db.CashInBanks.Where(c => c.CIBDate.Date == date.Date && c.StoreId == StoreId).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();
                    }
                }
            }
        }
Example #16
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);
            }
        }
Example #17
0
        public InvoiceSaveReturn OnEdit(eStoreDbContext db, EditOrderDTO sales, int StoreId = 1)
        {
            Customer cust = db.Customers.Where(c => c.MobileNo == sales.MobileNo).FirstOrDefault();

            if (cust == null)
            {
                string[] names = sales.Name.Split(" ");
                string   FName = names[0];
                string   LName = "";
                for (int i = 1; i < names.Length; i++)
                {
                    LName += names[i] + " ";
                }

                cust = new Customer
                {
                    City        = "",
                    Age         = 30,
                    FirstName   = FName,
                    Gender      = Gender.Male,
                    LastName    = LName,
                    MobileNo    = sales.MobileNo,
                    NoOfBills   = 0,
                    TotalAmount = 0,
                    CreatedDate = DateTime.Now.Date
                };
                db.Customers.Add(cust);
                db.SaveChanges();
            }
            RegularInvoice inv = db.RegularInvoices.Find(sales.InvoiceNo);

            if (inv == null)
            {
                return(null);
            }
            inv.SaleItems     = db.RegularSaleItems.Where(c => c.InvoiceNo == sales.InvoiceNo).ToList();
            inv.PaymentDetail = db.PaymentDetails.Include(c => c.CardAmount).Where(c => c.InvoiceNo == sales.InvoiceNo).FirstOrDefault();

            return(null);//TODO: temp
        }
Example #18
0
        public InvoiceSaveReturn OnInsert(eStoreDbContext db, SaveOrderDTO sales, string userName, int StoreId = 1)
        {
            Customer cust = db.Customers.Where(c => c.MobileNo == sales.MobileNo).FirstOrDefault();

            if (cust == null)
            {
                string[] names = sales.Name.Split(" ");
                string   FName = names[0];
                string   LName = "";
                for (int i = 1; i < names.Length; i++)
                {
                    LName += names[i] + " ";
                }

                cust = new Customer
                {
                    City        = sales.Address,
                    Age         = 30,
                    FirstName   = FName,
                    Gender      = Gender.Male,
                    LastName    = LName,
                    MobileNo    = sales.MobileNo,
                    NoOfBills   = 0,
                    TotalAmount = 0,
                    CreatedDate = DateTime.Now.Date
                };
                db.Customers.Add(cust);
            }
            string InvNo = GenerateInvoiceNo(db, StoreId, true);
            List <RegularSaleItem> itemList  = new List <RegularSaleItem>();
            List <Stock>           stockList = new List <Stock>();

            foreach (var item in sales.SaleItems)
            {
                RegularSaleItem sItem = new RegularSaleItem
                {
                    BarCode       = item.BarCode,
                    MRP           = item.Price,
                    Qty           = item.Quantity,
                    Discount      = 0,
                    SalesmanId    = item.Salesman,
                    Units         = item.Units,
                    InvoiceNo     = InvNo,
                    BasicAmount   = item.Amount,
                    TaxAmount     = 0,
                    ProductItemId = -1,
                    BillAmount    = 0,
                    SaleTaxTypeId = 1, //TODO: default tax id needed
                };
                ProductItem pItem = db.ProductItems.Where(c => c.Barcode == item.BarCode).FirstOrDefault();
                Stock       stock = db.Stocks.Where(c => c.ProductItemId == pItem.ProductItemId && c.StoreId == StoreId).FirstOrDefault();

                sItem.ProductItemId = pItem.ProductItemId;
                decimal amt = (decimal)item.Quantity * item.Price;
                sItem.BasicAmount = (amt * 100) / (100 + pItem.TaxRate);
                sItem.TaxAmount   = (sItem.BasicAmount * pItem.TaxRate) / 100;
                sItem.BillAmount  = sItem.BasicAmount + sItem.TaxAmount;
                //SaleTax Id
                var taxid = db.SaleTaxTypes.Where(c => c.CompositeRate == pItem.TaxRate).Select(c => c.SaleTaxTypeId).FirstOrDefault();
                if (taxid <= 0)
                {
                    taxid = 1; //TODO: Handle it for creating new saletax id
                }
                sItem.SaleTaxTypeId = taxid;

                itemList.Add(sItem);


                stock.SaleQty  += item.Quantity;
                stock.Quantity -= item.Quantity;
                stockList.Add(stock);
            }
            var           totalBillamt  = itemList.Sum(c => c.BillAmount);
            var           totaltaxamt   = itemList.Sum(c => c.TaxAmount);
            var           totalDiscount = itemList.Sum(c => c.Discount);
            var           totalQty      = itemList.Sum(c => c.Qty);
            var           totalitem     = itemList.Count;
            decimal       roundoffamt   = Math.Round(totalBillamt) - totalBillamt;
            PaymentDetail pd            = new PaymentDetail
            {
                CardAmount   = sales.PaymentInfo.CardAmount,
                CashAmount   = sales.PaymentInfo.CashAmount,
                InvoiceNo    = InvNo,
                IsManualBill = true,
                MixAmount    = 0,
                PayMode      = SalePayMode.Cash
            };

            if (sales.PaymentInfo.CardAmount > 0)
            {
                if (sales.PaymentInfo.CashAmount > 0)
                {
                    pd.PayMode = SalePayMode.Mix;
                }
                else
                {
                    pd.PayMode = SalePayMode.Card;
                }

                CardDetail cd = new CardDetail
                {
                    CardCode  = CardType.Visa,//TODO: default
                    Amount    = sales.PaymentInfo.CardAmount,
                    AuthCode  = (int)Int64.Parse(sales.PaymentInfo.AuthCode),
                    InvoiceNo = InvNo,
                    LastDigit = (int)Int64.Parse(sales.PaymentInfo.CardNo),
                    CardType  = CardMode.DebitCard//TODO: default
                };

                if (sales.PaymentInfo.CardType.Contains("Debit") || sales.PaymentInfo.CardType.Contains("debit") || sales.PaymentInfo.CardType.Contains("DEBIT"))
                {
                    cd.CardType = CardMode.DebitCard;
                }
                else if (sales.PaymentInfo.CardType.Contains("Credit") || sales.PaymentInfo.CardType.Contains("credit") || sales.PaymentInfo.CardType.Contains("CREDIT"))
                {
                    cd.CardType = CardMode.CreditCard;
                }

                if (sales.PaymentInfo.CardType.Contains("visa") || sales.PaymentInfo.CardType.Contains("Visa") || sales.PaymentInfo.CardType.Contains("VISA"))
                {
                    cd.CardCode = CardType.Visa;
                }
                else if (sales.PaymentInfo.CardType.Contains("MasterCard") || sales.PaymentInfo.CardType.Contains("mastercard") || sales.PaymentInfo.CardType.Contains("MASTERCARD"))
                {
                    cd.CardCode = CardType.MasterCard;
                }
                else if (sales.PaymentInfo.CardType.Contains("Rupay") || sales.PaymentInfo.CardType.Contains("rupay") || sales.PaymentInfo.CardType.Contains("RUPAY"))
                {
                    cd.CardCode = CardType.Rupay;
                }
                else if (sales.PaymentInfo.CardType.Contains("MASTRO") || sales.PaymentInfo.CardType.Contains("mastro") || sales.PaymentInfo.CardType.Contains("Mastro"))
                {
                    cd.CardCode = CardType.Rupay;
                }

                pd.CardDetail = cd;
            }
            RegularInvoice Invoice = new RegularInvoice
            {
                Customer            = cust,
                InvoiceNo           = InvNo,
                OnDate              = sales.OnDate,
                IsManualBill        = true,
                StoreId             = StoreId,
                SaleItems           = itemList,
                CustomerId          = cust.CustomerId,
                TotalBillAmount     = totalBillamt + roundoffamt,
                TotalDiscountAmount = totalDiscount,
                TotalItems          = totalitem,
                TotalQty            = totalQty,
                TotalTaxAmount      = totaltaxamt,
                RoundOffAmount      = roundoffamt,
                PaymentDetail       = pd,
                UserId              = userName
            };

            db.RegularInvoices.Add(Invoice);
            db.Stocks.UpdateRange(stockList);
            InvoiceSaveReturn returnData = new InvoiceSaveReturn
            {
                NoOfRecord = db.SaveChanges(),
                FileName   = "NotSaved"
            };

            if (returnData.NoOfRecord > 0)
            {
                ReceiptHeader             header         = PrinterHelper.GetReceiptHeader(db, StoreId);
                ReceiptDetails            details        = PrinterHelper.GetReceiptDetails(Invoice.InvoiceNo, Invoice.OnDate, DateTime.Now.ToShortTimeString(), sales.Name);
                ReceiptItemTotal          itemtotal      = PrinterHelper.GetReceiptItemTotal(Invoice);
                List <ReceiptItemDetails> itemDetailList = PrinterHelper.GetInvoiceDetails(db, itemList);
                returnData.FileName = "/" + InvoicePrinter.PrintManaulInvoice(header, itemtotal, details, itemDetailList, false);
            }
            return(returnData);
        }
Example #19
0
        //StoreBased Action
        private List <CashInHand> CreateCashInHands(eStoreDbContext db, List <CashBook> orderBook, int Store)
        {
            List <CashInHand> inHandList = new List <CashInHand>();

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

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

            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,
                    StoreId         = Store
                };
                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,
                        StoreId         = Store
                    };
                }
                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,
                                StoreId         = Store
                            };
                            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,
                        StoreId         = Store
                    };
                    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,
                            StoreId         = Store
                        };
                        db.CashInHands.Add(cashInHand);
                        inHandList.Add(cashInHand);
                        db.SaveChanges();
                    }
                }

                cashInHand = new CashInHand()
                {
                    CIHDate         = endDate,
                    OpenningBalance = 0,
                    CashIn          = 0,
                    CashOut         = 0,
                    ClosingBalance  = 0,
                    StoreId         = Store
                };
                db.CashInHands.Add(cashInHand);
                inHandList.Add(cashInHand);
                db.SaveChanges();
            }
            return(inHandList);
        }
Example #20
0
        //StoreBased Action
        private List <CashBook> CreateCashInHands(eStoreDbContext db, List <CashBook> books, int Store)
        {
            IEnumerable <CashBook> orderBook = books.OrderBy(c => c.EDate);

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

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

            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,
                        StoreId         = Store
                    };
                }
                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,
                                StoreId         = Store
                            };
                            db.CashInHands.Add(cashInHand);
                        }
                    }
                    db.SaveChanges();
                    cashInHand = new CashInHand()
                    {
                        CIHDate         = item.EDate,
                        OpenningBalance = 0,
                        CashIn          = item.CashIn,
                        CashOut         = item.CashOut,
                        ClosingBalance  = 0,
                        StoreId         = Store
                    };
                    startDate = item.EDate;
                }
                else
                {
                    cashInHand.CashIn  += item.CashIn;
                    cashInHand.CashOut += item.CashOut;
                }
            }
            db.CashInHands.Add(cashInHand);
            db.SaveChanges();

            return(orderBook.ToList());
        }
Example #21
0
 public void UpDateToDoList(eStoreDbContext db, ToDoMessage todo)
 {
     db.Update(todo);
     db.SaveChanges();
 }
Example #22
0
        public static async System.Threading.Tasks.Task <string> ProcessExpensesAsync(eStoreDbContext db)
        {
            string Message = "";

            int PartyId     = 0;
            int TotalUpdate = 0;

            var exps = await db.Expenses.Where(c => c.PartyName.Contains("KITES") && c.PartyId == null).ToListAsync();

            PartyId = GetPartyId(db, "Kites");
            foreach (var e in exps)
            {
                e.PartyId     = PartyId;
                e.EntryStatus = EntryStatus.Updated;
                db.Expenses.Update(e);
            }
            PartyId = 0;
            exps    = await db.Expenses.Where(c => c.Particulars.Contains("water") && c.PartyId == null).ToListAsync();

            PartyId = GetPartyId(db, "Kites");
            foreach (var e in exps)
            {
                e.PartyId     = PartyId;
                e.EntryStatus = EntryStatus.Updated;
                db.Expenses.Update(e);
            }
            PartyId      = 0;
            TotalUpdate += db.SaveChanges();

            foreach (var h in Head)
            {
                if (h == "maa bhawani art")
                {
                    PartyId = GetPartyId(db, "Maa Bhawani Art");
                }
                else if (h == "painter")
                {
                    PartyId = GetPartyId(db, "Painter");
                }
                else if (h == "store renovation cost")
                {
                    PartyId = GetPartyId(db, "Store Renovation");
                }
                else if (h == "telephone")
                {
                    PartyId = GetPartyId(db, "Telephone Bill");
                }


                else if (h == "Kites")
                {
                    var exp1 = await db.Expenses.Where(c => c.Particulars.Contains("water") && c.PartyId == null).ToListAsync();

                    foreach (var e in exp1)
                    {
                        e.PartyId     = PartyId;
                        e.EntryStatus = EntryStatus.Updated;
                        db.Expenses.Update(e);
                    }
                    PartyId = 0;
                }
                else
                {
                    PartyId = GetPartyId(db, h);
                }

                if (PartyId > 0)
                {
                    var exp = await db.Expenses.Where(c => c.Particulars.ToLower().Contains(h.ToLower()) && c.PartyId == null).ToListAsync();

                    foreach (var e in exp)
                    {
                        e.PartyId     = PartyId;
                        e.EntryStatus = EntryStatus.Updated;
                        db.Expenses.Update(e);
                    }
                    PartyId      = 0;
                    TotalUpdate += db.SaveChanges();
                }
                else
                {
                    Console.WriteLine("PartyName: " + h);
                    Message += "PartyName: " + h;
                }
            }

            var exp12 = await db.Expenses.Where(c => c.PartyId == null).ToListAsync();

            foreach (var e in exp12)
            {
                e.PartyId     = 43;
                e.EntryStatus = EntryStatus.Updated;
                db.Expenses.Update(e);
            }
            TotalUpdate += db.SaveChanges();
            Message     += "    #Total Update: " + TotalUpdate;
            return(Message);
        }