예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Amount,RowDiscount,ProductId,ReceiptId,Id")]
                                               ReceiptRow receiptRow)
        {
            if (id != receiptRow.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _uow.ReceiptRows.Update(receiptRow);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var viewModel = new ReceiptRowViewModel
            {
                ReceiptRow = receiptRow,
                Products   = new SelectList(await _uow.Products.AllAsync(), nameof(Product.Id),
                                            nameof(Product.ProductName)),
                Receipts = new SelectList(await _uow.Receipts.AllAsync(), nameof(Receipt.Id), nameof(Receipt.Id))
            };

            return(View(viewModel));
        }
예제 #2
0
        /// <summary>
        /// Sells the specified baskets.
        /// </summary>
        /// <param name="baskets">The baskets.</param>
        /// <exception cref="TAS.Framework.Exceptions.ApplicationException"></exception>
        public void Sell(List <BasketModel> baskets)
        {
            try
            {
                List <ReceiptRow> receiptRows = new List <ReceiptRow>();

                var basketSelected = baskets.Where(b => b.IsSelected).OrderBy(b => b.Basket.Code);
                foreach (var basket in basketSelected)
                {
                    decimal salesTaxes = 0;
                    decimal total      = 0;

                    // Title
                    var receiptRow = new ReceiptRow {
                        Description = $"{basket.Basket.Description}:\r\n"
                    };

                    receiptRows.Add(receiptRow);
                    foreach (var item in basket.Basket.Items)
                    {
                        receiptRow = new ReceiptRow
                        {
                            Description = $"{1} {item.Description}: {item.TotalAmount.ToString("0.00")}\r\n"
                        };

                        receiptRows.Add(receiptRow);

                        salesTaxes += item.TaxAmount + item.ImportedTaxAmount;
                        total      += item.TotalAmount;
                    }
                    // Tax
                    receiptRow = new ReceiptRow {
                        Description = $"Sales Taxes: {salesTaxes.ToString("0.00")}\r\n"
                    };
                    receiptRows.Add(receiptRow);

                    // Total
                    receiptRow = new ReceiptRow {
                        Description = $"Total: {total.ToString("0.00")}\r\n"
                    };
                    receiptRows.Add(receiptRow);

                    // Line feed
                    receiptRow = new ReceiptRow {
                        Description = "\r\n"
                    };
                    receiptRows.Add(receiptRow);
                }

                PrintReceipt(receiptRows);
            }
            catch (Exception exception)
            {
                throw new Framework.Exceptions.ApplicationException(ApplicationExceptionMessages.SELL_BASKET_ERROR, exception);
            }
        }
예제 #3
0
        /// <summary>
        /// Maps Amount, Product(...), Changes(...), Participants(...), Discount, ReceiptId, RowId, Cost,
        /// </summary>
        /// <param name="row"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        /// <exception cref="NullReferenceException"></exception>
        public static DALReceiptRowDTO FromDomain(ReceiptRow row, DateTime time)
        {
            if (row == null)
            {
                throw new NullReferenceException("Can't map, row entity is null");
            }
            if (!row.Receipt.IsFinalized && (row.Product?.IsDeleted ?? true))
            {
                return(null);
            }

            var product = ProductMapper.FromDomain2(row.Product, time);
            var changes = new List <DALChangeDTO>();

            foreach (var rowChange in row.ReceiptRowChanges)
            {
                var changeDTO = ChangeMapper.FromDomain2(rowChange.Change, time);
                if (changeDTO == null || changeDTO.CurrentPrice == decimal.MinusOne)
                {
                    continue;
                }
                changes.Add(changeDTO);
            }

            var participants = new List <DALRowParticipantDTO>();

            foreach (var loanRow in row.RowParticipantLoanRows)
            {
                participants.Add(new DALRowParticipantDTO()
                {
                    Name         = loanRow.Loan.LoanTaker.UserNickname,
                    Involvement  = loanRow.Involvement,
                    ReceiptRowId = row.Id,
                    LoanId       = loanRow.LoanId,
                    AppUserId    = loanRow.Loan.LoanTakerId,
                    LoanRowId    = loanRow.Id
                });
            }

            return(new DALReceiptRowDTO()
            {
                Amount = row.Amount,
                Product = product,
                Changes = changes,
                Discount = row.RowDiscount,
                ReceiptId = row.ReceiptId,
                ReceiptRowId = row.Id,
                CurrentCost = row.RowSumCost(),
                Participants = participants
            });
        }
예제 #4
0
        /// <summary>
        /// Maps amount, discount, productId, receiptId, rowId
        /// </summary>
        /// <param name="row"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public static DALReceiptRowDTO FromDomain2(ReceiptRow row, DateTime time)
        {
            if (row == null)
            {
                throw new NullReferenceException("Can't map, row entity is null");
            }

            return(new DALReceiptRowDTO()
            {
                Amount = row.Amount,
                Discount = row.RowDiscount,
                ProductId = row.ProductId,
                ReceiptId = row.ReceiptId,
                ReceiptRowId = row.Id
            });
        }
예제 #5
0
 public ReceiptRowChangeEvent(ReceiptRow row, global::System.Data.DataRowAction action)
 {
     this.eventRow    = row;
     this.eventAction = action;
 }
예제 #6
0
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            bool   dataIsValid = true;
            int    priceFrom   = 0;
            int    priceTo     = 1;
            String CustomerID;


            // Validate
            if (!(txtCustomerId.Text.Length > 0))
            {
                MessageBox.Show("Customer ID can't be empty");
                dataIsValid = false;
            }
            if (/*(txtPriceFrom.Text.Length > 0 || txtPriceTo.Text.Length > 0) && */
                dataIsValid && (!Int32.TryParse(txtPriceFrom.Text, out priceFrom) ||
                                !Int32.TryParse(txtPriceTo.Text, out priceTo) || !(priceFrom >= 0 && priceTo > 0 && priceTo >= priceFrom)))
            {
                MessageBox.Show("Price is not valid");
                dataIsValid = false;
            }
            if (dataIsValid && dpkIssuedDate.SelectedDate == null)
            {
                dataIsValid = false;
                MessageBox.Show("Please select a date");
            }

            // Query Receipts

            if (dataIsValid)
            {
                CustomerID = txtCustomerId.Text;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = dbQLKS.dbConnection;
                cmd.CommandText = "TimKiemHoaDon";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MaNV", Auth.GetLoggedInUserId());
                cmd.Parameters.AddWithValue("@MaKH", CustomerID);
                cmd.Parameters.AddWithValue("@GiaBatDau", priceFrom);
                cmd.Parameters.AddWithValue("@GiaKetThuc", priceTo);
                cmd.Parameters.AddWithValue("@NgayXuatHoaDon", dpkIssuedDate.SelectedDate);

                SqlDataReader dr;

                dbQLKS.dbConnection.Open();
                dr = cmd.ExecuteReader();


                List <ReceiptRow> ReceiptList = new List <ReceiptRow>();

                // Fill Datagrid
                while (dr.Read())
                {
                    ReceiptRow row = new ReceiptRow();

                    row.MaHD     = dr["maHD"].ToString();
                    row.NgayLap  = (DateTime)dr["ngayThanhToan"];
                    row.TongTien = Math.Round((double)dr["tongTien"], 1);
                    row.MaDP     = dr["maDP"].ToString();

                    ReceiptList.Add(row);
                }

                dgReceipt.ItemsSource = ReceiptList;

                dbQLKS.dbConnection.Close();

                // Show status
                lblStatus.Content = "Found " + ReceiptList.Count;
            }
        }