Ejemplo n.º 1
0
        public bool IfExists(string identifier)
        {
            bool result;

            try
            {
                _sql.StartTransaction("AccountingConnStr");

                result = _sql.LoadDataInTransaction <int, dynamic>("spPayrollArchive_IfExists", new { UniqueId = identifier }).Count() != 0;
            }
            catch (Exception)
            {
                _sql.RollBackTransaction();
                throw;
            }
            _sql.Dispose();

            return(result);
        }
Ejemplo n.º 2
0
        public PayrollArchiveHeaderModel GetHeader(int id)
        {
            PayrollArchiveHeaderModel result;

            try
            {
                _sql.StartTransaction("AccountingConnStr");

                result = _sql.LoadDataInTransaction <PayrollArchiveHeaderModel, dynamic>("spPayrollArchive_GetHeader", new { Id = id }).FirstOrDefault();
            }
            catch (Exception)
            {
                _sql.RollBackTransaction();
                throw;
            }
            _sql.Dispose();
            return(result);
        }
Ejemplo n.º 3
0
        public void SaveSale(SaleModel saleInfo, string userId)
        {
            //TODO: Make this solid, dry / better

            List <DbSaleDetailModel> details = new List <DbSaleDetailModel>();

            foreach (var item in saleInfo.SaleDetails)
            {
                var detail = new DbSaleDetailModel
                {
                    ProductId = item.ProductId,
                    Quantity  = item.Quantity
                };

                //Get the information about this product
                var productInfo = _productData.GetProductById(item.ProductId);

                if (productInfo == null)
                {
                    throw new Exception($"The product Id of {item.ProductId } could not be found in the database.");
                }

                detail.PurchasePrice = (productInfo.RetailPrice * detail.Quantity);

                details.Add(detail);
            }

            // Create the Sale model
            DbSaleModel sale = new DbSaleModel
            {
                SubTotal  = details.Sum(x => x.PurchasePrice),
                Discount  = saleInfo.Discount,
                CashierId = userId
            };

            sale.Total = sale.SubTotal - sale.Discount;

            // Save the sale model in Transaction
            try
            {
                _sql.StartTransaction("RMData");

                _sql.SaveDataInTransaction("dbo.spSale_Insert", sale);

                // Get id from sale model
                sale.Id = _sql.LoadDataInTransaction <int, dynamic>("spSale_Lookup", new { sale.CashierId, sale.SaleDate }).FirstOrDefault();

                //Calculate Discount
                decimal discountPercent = (sale.Discount * 100) / sale.SubTotal;

                foreach (var item in details)
                {
                    item.SaleId   = sale.Id;
                    item.Discount = (item.PurchasePrice / 100) * discountPercent;

                    //Save the sale details models
                    _sql.SaveDataInTransaction("dbo.spSaleDetail_Insert", item);
                }

                _sql.CommitTransaction();
            }
            catch (Exception)
            {
                _sql.RollbackTransaction();
                throw;
            }

            _sql?.Dispose();
        }