Ejemplo n.º 1
0
        public async Task <bool> UpdateBankBalanceAsync(Transactions transaction)
        {
            if (transaction == null)
            {
                return(false);
            }


            // get latest bank balance in (transactions).
            var latestTrans = _context.Transactions.Where(t => t.Deleted == false && t.BankId == transaction.BankId).LastOrDefault();

            if (latestTrans != null)
            {
                transaction.Balance = latestTrans.Balance;
            }
            else
            {
                latestTrans = new Transactions();
            }

            // Add +Credit and - Debit.
            transaction.Balance = (latestTrans.Balance + transaction.Credit - transaction.Debit);


            // add as a new payment transaction.
            _context.Transactions.Add(transaction);
            await _context.SaveChangesAsync();


            return(true);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("PartId,ItemId,PartName,Qty,Barcode,AvgCost,LastCost,SalePrice,More,Active,Starred,Deleted,LastPurchasedDate,AddDate,PartId1")] ItemParts itemParts)
        {
            if (ModelState.IsValid)
            {
                itemParts.AvgCost = itemParts.Qty * itemParts.SalePrice; // totalPrice = UnitPrice * Quantity
                _context.Add(itemParts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { id = itemParts.ItemId }));
            }
            else
            {
                var invalid = ModelState.Where(p => p.Value.ValidationState == ModelValidationState.Invalid).FirstOrDefault();
                ViewData["ErrorMessage"] = "Error:!" + string.Join(",", invalid.Value.Errors.Select(i => i.ErrorMessage));
            }

            var model = new ItemPartsViewModel()
            {
                ItemParts = await _context.ItemParts.Include(i => i.Item).Where(p => p.ItemId == itemParts.ItemId).ToListAsync(),
                ItemPart  = new ItemParts()
                {
                    ItemId = (long)itemParts.ItemId
                },
                Car = await _context.Items.Include(p => p.Make).Include(p => p.Model).FirstOrDefaultAsync(i => i.ItemId == itemParts.ItemId)
            };

            return(View("Index.cshtml", model));
        }
Ejemplo n.º 3
0
 public async Task<IActionResult> Create([Bind("Id,Name")] Parts parts)
 {
     if (ModelState.IsValid)
     {
         _context.Add(parts);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(parts);
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Name,TypeId")] Banks banks)
        {
            if (ModelState.IsValid)
            {
                _context.Add(banks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(banks));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> DeleteConfirmed(long id)
        {
            var photos = await _context.Photos.FindAsync(id);

            var itemId = photos.ItemId;

            _context.Photos.Remove(photos);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index), new { id = itemId }));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("YearId")] Years years)
        {
            if (ModelState.IsValid)
            {
                _context.Add(years);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(years));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("AccountId,AccountTypeId,Title,BalanceIn,BalanceOut,Phone,Address,Category,Code,More")] Accounts accounts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(accounts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(accounts));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("MakeId,MakeName")] Makes makes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(makes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(makes));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,GroupName,Title,Value,Active")] Settings settings)
        {
            if (ModelState.IsValid)
            {
                _context.Add(settings);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(settings));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("ModelId,MakeId,ModelName")] Core.StoreModels.Models models)
        {
            if (ModelState.IsValid)
            {
                _context.Add(models);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MakeId"] = new SelectList(_context.Makes, "MakeId", "MakeName", models.MakeId);
            return(View(models));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("Id,AccountId,InvoiceNo,Notes,TotalAmount,Discount,Tax,NetAmount,UserId,Ip,IsCache,AddDate,AddTime,InvoiceTypeId")] Invoices invoices)
        {
            if (ModelState.IsValid)
            {
                _context.Add(invoices);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountId"] = new SelectList(_context.Accounts.Where(a => a.AccountTypeId == 1), "AccountId", "Title", invoices.AccountId);
            return(View(invoices));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("ItemsPk,ItemId,Barcode,AvgCost,LastCost,LastPurchasedDate,Qty,Starred,MakeId,ModelId,YearId,Vin,SalePrice,Discount,NetPrice,Active,Photo,More,LotNo,SupplierCarNo,RefNo,Sold")] Items items)
        {
            if (ModelState.IsValid)
            {   // Incresing the item no
                long serial     = 1;
                var  latestItem = await _context.Items.LastOrDefaultAsync();

                if (latestItem != null)
                {
                    serial = (latestItem.ItemsPk) + 1;
                }
                items.ItemsPk = serial;

                _context.Add(items);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MakeId"]  = new SelectList(_context.Makes, "MakeId", "MakeName", items.MakeId);
            ViewData["ModelId"] = new SelectList(_context.Models, "ModelId", "ModelName", items.MakeId);
            ViewData["YearId"]  = new SelectList(_context.Years, "YearId", "YearId", items.YearId);
            return(View(items));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("Id,InvoiceId,Amount,Discount,Tax,Extra,Total,AccountId,PaymentTypeId,OperationId,FromBankId,ToBankId,AddDate,AddTime,RefNo,Notes")] Payments payments)
        {
            var isValidtaedAmount = new TransactionsService(_context).ValidateBankBalance(payments.FromBankId, payments.Amount, payments.OperationId);

            if (ModelState.IsValid && isValidtaedAmount)
            {
                _context.Add(payments);
                await _context.SaveChangesAsync();

                #region "Update (Account/Banks) Balances"
                decimal _credit = 0, _debit = 0, _toCredit = 0, _toDebit = 0;
                var     _trans = new TransactionsService(_context);

                // قبض
                if (payments.OperationId == (int)PaymentTypesEnum.Credit || payments.OperationId == (int)PaymentTypesEnum.CheckCredit)
                {
                    _credit = _toCredit = payments.Amount;
                    //_debit = _toDebit = 0;
                }
                // صرف
                else if (payments.OperationId == (int)PaymentTypesEnum.Debit || payments.OperationId == (int)PaymentTypesEnum.CehckDebit)
                {
                    _debit  = _toDebit = payments.Amount;
                    _credit = _toCredit = 0;
                }
                // تحويل بنكى من بنك إلى بنك
                else if (payments.OperationId == (int)PaymentTypesEnum.BankTransfer)
                {
                    _debit    = payments.Amount; // Debit from
                    _toCredit = payments.Amount; // Debit to.

                    _toDebit = _credit = 0;
                }

                // Update account balance
                if (payments.AccountId > 0)
                {
                    var at = new Transactions()
                    {
                        AccountId     = payments.AccountId,
                        AddDate       = DateTime.Now,
                        Credit        = _credit,
                        Debit         = _debit,
                        TransactionId = payments.Id.ToString()
                    };
                    await _trans.UpdateAccountBalanceAsync(at);
                }
                // Update FromBank balance.
                if (payments.FromBankId > 0)
                {
                    var bt = new Transactions()
                    {
                        BankId        = payments.FromBankId,
                        AddDate       = DateTime.Now,
                        Credit        = _credit,
                        Debit         = _debit,
                        TransactionId = payments.Id.ToString()
                    };
                    await _trans.UpdateBankBalanceAsync(bt);
                }

                // Update ToBank balance.
                if (payments.ToBankId > 0)
                {
                    var bt = new Transactions()
                    {
                        BankId        = payments.ToBankId,
                        AddDate       = DateTime.Now,
                        Credit        = _toCredit,
                        Debit         = _toDebit,
                        TransactionId = payments.Id.ToString()
                    };
                    await _trans.UpdateBankBalanceAsync(bt);
                }
                #endregion


                // Archive client transactions in case he paying to us (قبض - قبض بشيك).
                if (payments.AccountId > 0 && (payments.OperationId == (int)PaymentTypesEnum.Credit || payments.OperationId == (int)PaymentTypesEnum.CheckCredit))
                {
                    await _trans.ArchiveAccountInvoicesPaymanetsAsync(payments.AccountId);
                }


                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountId"]     = new SelectList(_context.Accounts, "AccountId", "Title", payments.AccountId);
            ViewData["FromBankId"]    = new SelectList(_context.Banks, "Id", "Name", payments.FromBankId);
            ViewData["InvoiceId"]     = new SelectList(_context.Invoices, "Id", "InvoiceNo", payments.InvoiceId);
            ViewData["OperationId"]   = new SelectList(_context.Operations, "Id", "Name", payments.OperationId);
            ViewData["PaymentTypeId"] = new SelectList(_context.PaymentTypes, "Id", "Name", payments.PaymentTypeId);
            ViewData["ToBankId"]      = new SelectList(_context.Banks, "Id", "Name", payments.ToBankId);
            if (!isValidtaedAmount)
            {
                ViewData["BankAmountMessage"] = SysLanguages.Lang.ValidateBankBalanceMessage;
            }


            return(View(payments));
        }