private void _txtSalePrice_Leave(object sender, EventArgs e) { if (!string.IsNullOrEmpty(_txtSalePrice.Text) && CurrencyUtil.ToDecimal(_model.NewPrice) != 0 && (string.IsNullOrEmpty(_txtImportPrice.Text) || CurrencyUtil.ToDecimal(_model.NewCost) == 0)) { _model.NewCost = CurrencyUtil.ToString(CurrencyUtil.ToDecimal(_model.NewPrice) / (decimal)1.3); } }
private decimal CaculateProfit() { decimal expense = string.IsNullOrEmpty(tbExpense.Text) ? 0 : CurrencyUtil.ToDecimal(tbExpense.Text); decimal adjustment = string.IsNullOrEmpty(tbAdjustmentAmount.Text) ? 0 : CurrencyUtil.ToDecimal(tbAdjustmentAmount.Text); return(_totalRevenue + adjustment - expense); }
private void tbPrice_Leave(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbPrice.Text) && CurrencyUtil.ToDecimal(_model.Price) != 0 && (string.IsNullOrEmpty(tbCost.Text) || CurrencyUtil.ToDecimal(_model.Cost) == 0)) { _model.Cost = CurrencyUtil.ToString(CurrencyUtil.ToDecimal(_model.Price) / (decimal)1.3); } }
private bool ValidateInput() { if (_checkedRows.Count == 0) { MessageBox.Show("Hãy chọn hóa đơn cần quyết toán.", "Không có hóa đơn"); return(false); } if (chkUseAdjustment.Checked) { if (CurrencyUtil.ToDecimal(tbAdjustmentAmount.Text) == 0) { MessageBox.Show("Tiền điều chỉnh phải khác 0.", "Tiền điều chỉnh không hợp lệ"); return(false); } if (string.IsNullOrWhiteSpace(tbAdjustmentReason.Text)) { MessageBox.Show("Vui lòng ghi rõ lý do sử dụng tiền điều chỉnh.", "Thiếu lý do sử dụng tiền điều chỉnh"); return(false); } } if (CurrencyUtil.ToDecimal(lblPaymentBalanceText.Text) < 0) { MessageBox.Show("Số tiền thanh toán không hợp lệ. Hãy sử dụng tiền điều chỉnh nếu cần.", "Không thể quyết toán"); return(false); } return(true); }
protected override void btnSave_Click(object sender, EventArgs e) { try { string errorMessage = ValidInput(); if (string.IsNullOrEmpty(errorMessage) == false) { MessageBox.Show(errorMessage, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (MessageBox.Show("Thay đổi thông tin chi tiết của Doanh thu có thể làm thay đổi tổng doanh thu.\r\n Bạn có chắc chắn muốn thay đổi không?" , "Chú ý" , MessageBoxButtons.YesNo , MessageBoxIcon.Warning , MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No) { return; } base.btnSave_Click(sender, e); using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) { RevenueDetail expenseDetail = _isUpdating ? context.RevenueDetails.SingleOrDefault(i => i.id == tbId.Text.Trim()) : new RevenueDetail(); expenseDetail.id = IsUpdating ? tbId.Text : IDGenerator.ExpenseId(); expenseDetail.object_id = tbObjectId.Text; expenseDetail.revenue_id = _revenueId; expenseDetail.amount = CurrencyUtil.ToDecimal(tbAmount.Text); expenseDetail.created_by = _isUpdating ? expenseDetail.created_by : SystemParam.CurrentUser.id; expenseDetail.created_date = _isUpdating ? expenseDetail.created_date : dtpCreateDate.Value; expenseDetail.description = tbRemark.Text; expenseDetail.type = cbType.SelectedValue.ToString(); expenseDetail.title = string.Empty; AppLogger.logInfo("btnSave_Click", IsUpdating ? "UPDATE" : "INSERT", expenseDetail); if (IsUpdating == false) { context.RevenueDetails.AddObject(expenseDetail); } context.SaveChanges(); ChangeViewStatus(false); } UpdateExpenseAmount(); LoadExpenseDetail(); } catch (Exception exc) { AppLogger.logError("btnSave_Click", exc); } }
public StringBuilder UpdatePrice() { StringBuilder errorMessage = new StringBuilder(); try { AppLogger.logInfo(" UpdatePrice "); errorMessage = checkData(); if (errorMessage.Length != 0) { return(errorMessage); } ProductPrice oldPrice = _model.Product.ProductPrices.FirstOrDefault(i => i.IsCurrentPrice); //_businessPrice.GetProductAvailablePrice(product.Id); if (oldPrice != null) { oldPrice.IsCurrentPrice = false; } ProductPrice price = new ProductPrice(); price.ProductId = _model.Product.Id; price.Price = CurrencyUtil.ToDecimal(_model.NewPrice); price.Cost = CurrencyUtil.ToDecimal(_model.NewCost); price.IsCurrentPrice = true; _model.Product.Price = price.Price; _model.Product.Cost = price.Cost; _model.Product.ChangedDate = DateTime.Now; _model.Product.ChangedBy = SystemParam.CurrentUser.Id; _model.Product.ProductPrices.Add(price); try { //_businessPrice.Insert(price, false); //_businessPrice.Update(oldPrice, true); _businessProduct.Update(_model.Product); } catch (Exception exc) { AppLogger.logError(exc.Message); errorMessage.AppendLine(exc.Message); } return(errorMessage); } catch (Exception exc) { AppLogger.logError(exc.Message); return(errorMessage.AppendLine(exc.Message)); } }
private void btnPayPrint_Click(object sender, EventArgs e) { if (CurrencyUtil.ToDecimal(_model.CusChange) < 0) { return; } Result = PaymentResult.PayandPrint; this.Close(); }
private bool ValidateInput() { bool valid = true; if (CurrencyUtil.ToDecimal(tbPaymentBalance.Text) < 0) { MessageBox.Show("Số tiền thanh toán không hợp lệ.", "Không thể quyết toán", MessageBoxButtons.OK, MessageBoxIcon.Warning); valid = false; } return(valid); }
public StringBuilder HandleQuickAddProduct() { StringBuilder errorMessage = new StringBuilder(); try { AppLogger.logInfo(" AddNewProduct "); errorMessage = QuickAddCheckData(); if (errorMessage.Length != 0) { return(errorMessage); } _model.Product.ManufacturerId = _model.SelectedManufacturer != null ? (int?)_model.SelectedManufacturer.Id : null; _model.Product.UnitId = _model.SelectedUnit != null ? (int?)_model.SelectedUnit.Id : null; _model.Product.CategoryId = 1; _model.Product.ChangedBy = SystemParam.CurrentUser.Id; //ProductPrice price = new ProductPrice(); //price.ProductId = _model.Product.Id; //price.Cost = CurrencyUtil.ToDecimal(_model.Cost); //price.Price = CurrencyUtil.ToDecimal(_model.Price); //price.IsCurrentPrice = true; ProductPrice price = new ProductPrice(); price.ProductId = _model.Product.Id; price.Cost = CurrencyUtil.ToDecimal(_model.Cost); price.Price = CurrencyUtil.ToDecimal(_model.Price); price.IsCurrentPrice = true; _model.Product.Price = price.Price; _model.Product.ProductPrices = new List <ProductPrice>() { price }; _business.Insert(_model.Product); //_model.Product.ProductPrices.Add(price); //_business.Insert(_model.Product); return(errorMessage); } catch (Exception exc) { AppLogger.logError(exc.Message); return(errorMessage.AppendLine(exc.Message)); } }
protected string ValidInput() { StringBuilder errorMessage = new StringBuilder(); ClearControlError(tbPrice); if (string.IsNullOrEmpty(tbPrice.Text) || CurrencyUtil.ToDecimal(tbPrice.Text) < 0) { errorMessage.AppendLine("Giá bán không hợp lệ!"); SetControlError(tbPrice, ""); } return(errorMessage.ToString()); }
private void tbPaidAmount_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbPaidAmount.Text)) { tbPaymentChange.Text = CurrencyUtil.ToString((CurrencyUtil.ToDecimal(tbPaidAmount.Text) - CurrencyUtil.ToDecimal(tbTotalPayment.Text))); btnSellAndPrintReceipt.Enabled = CurrencyUtil.ToDecimal(tbPaidAmount.Text) >= CurrencyUtil.ToDecimal(tbTotalPayment.Text); btnSell.Enabled = CurrencyUtil.ToDecimal(tbPaidAmount.Text) >= CurrencyUtil.ToDecimal(tbTotalPayment.Text); CurrencyTextBox_TextChanged(sender, e); } else { tbPaymentChange.Text = "0"; } }
private void tbAdjustmentAmount_TextChanged(object sender, EventArgs e) { try { base.CurrencyTextBox_TextChanged(sender, e); tbIncludeAdjustment.Text = CurrencyUtil.ToString(CurrencyUtil.ToDecimal(tbTotalPayment.Text) + CurrencyUtil.ToDecimal(tbAdjustmentAmount.Text)); lblPaymentChange.Text = CurrencyUtil.ToString(CaculatePaymentChange()); } catch (Exception exc) { AppLogger.logError(this.ToString(), exc); } }
protected override void btnSave_Click(object sender, EventArgs e) { try { string errorMessage = ValidInput(); if (string.IsNullOrEmpty(errorMessage) == false) { MessageBox.Show(errorMessage, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } base.btnSave_Click(sender, e); using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) { TicketPriceConfiguration priceConfig = context.TicketPriceConfigurations.SingleOrDefault(i => i.id == _selectedId && i.seat_class == _selectedClass); IsUpdating = priceConfig != null; if (priceConfig == null) { priceConfig = new TicketPriceConfiguration(); } priceConfig.id = IsUpdating ? _selectedId : IDGenerator.TicketPriceConfigId(); priceConfig.price = CurrencyUtil.ToDecimal(tbPrice.Text); priceConfig.seat_class = _selectedClass.ToString(); priceConfig.description = tbRemark.Text.Trim(); AppLogger.logInfo("btnSave_Click", IsUpdating ? "UPDATE" : "INSERT", priceConfig); if (IsUpdating == false) { context.TicketPriceConfigurations.AddObject(priceConfig); } context.SaveChanges(); ChangeViewStatus(false); LoadTicketPriceConfig(); } } catch (Exception exc) { AppLogger.logError("btnSave_Click", exc); } }
protected override void btnSave_Click(object sender, EventArgs e) { try { string errorMessage = ValidInput(); if (string.IsNullOrEmpty(errorMessage) == false) { MessageBox.Show(errorMessage, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } base.btnSave_Click(sender, e); using (TicketReturnFeeConfigurationBusiness business = new TicketReturnFeeConfigurationBusiness()) { TicketReturnFeeConfiguration config = _isUpdating == false ? new TicketReturnFeeConfiguration() : business.Get(tbId.Text); if (config == null) { return; } config.id = _isUpdating == false?IDGenerator.TicketReturnFeeConfigId() : tbId.Text; config.before_day = int.Parse(tbBeforeDate.Text); config.before_hour = string.IsNullOrEmpty(tbBeforeHour.Text) ? 0 : int.Parse(tbBeforeHour.Text); config.fee_amount = rbAmount.Checked ? CurrencyUtil.ToDecimal(tbAmount.Text) : 0; config.fee_percent = rbPercent.Checked ? int.Parse(tbPercent.Text) : 0; business.Insert(config); LoadTicketReturnFee(); ChangeViewStatus(false); } } catch (Exception exc) { AppLogger.logError("btnSave_Click", exc); } }
private void btnOK_Click(object sender, EventArgs e) { try { string result = ValidateInput(); if (string.IsNullOrEmpty(result)) { string msg = CurrencyUtil.ToDecimal(tbExpense.Text) <= 0 ? "" : string.Format("Hiện tại chi phí là {0} VND \r\n", tbExpense.Text); if (MessageBox.Show(msg + "Bạn có muốn kết sổ danh sách vé này không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.OK) { result = CompleteTickets(_tickets); } else { return; } } if (string.IsNullOrEmpty(result)) { MessageBox.Show("Kết sổ thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); SearchTicket(); } else { MessageBox.Show(result, Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception exc) { AppLogger.logError(this.ToString(), exc); MessageBox.Show(Constants.Messages.ERROR_OPERATION_NOT_PERFORMED, Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string CompleteTickets(List <Ticket> tickets) { string result = string.Empty; decimal totalPayment = 0; decimal totalExpense = CurrencyUtil.ToDecimal(tbExpense.Text); decimal adjustment = CurrencyUtil.ToDecimal(tbAdjustmentAmount.Text); string adjustmentReason = tbAdjustmentReason.Text; Revenue revenue = new Revenue(); revenue.id = IDGenerator.RevenueId(); revenue.type = Constants.RevenueType.Ticket.ToString(); revenue.name = "Bán vé"; revenue.description = string.Empty; revenue.created_date = DateTime.Now; revenue.created_by = SystemParam.CurrentUser.id; List <RevenueDetail> revenueDetails = new List <RevenueDetail>(); foreach (var ticket in tickets) { ticket.status = Constants.TicketStatus.Closed.ToString(); // Updates tickets result = _ticketBusiness.CompleteTicket(ticket.id); RevenueDetail detail = new RevenueDetail(); detail.id = IDGenerator.RevenueDetailId(); detail.revenue_id = revenue.id; detail.object_id = ticket.id; detail.title = "Bán vé"; detail.type = Constants.RevenueType.Ticket.ToString(); detail.amount = ticket.cost; totalPayment += ticket.cost; detail.description = string.Empty; detail.created_date = DateTime.Now; detail.created_by = SystemParam.CurrentUser.id; revenueDetails.Add(detail); } revenue.amount = totalPayment; // Inserts revenue & details if (string.IsNullOrEmpty(result)) { result = _revenueBusiness.Insert(revenue, revenueDetails); } // Inserts expense if (string.IsNullOrEmpty(result)) { if (totalExpense != 0) { Expense expense = new Expense(); expense.id = IDGenerator.RevenueId(); expense.type = Constants.RevenueType.Ticket.ToString(); expense.name = "Bán vé"; expense.amount = totalExpense; expense.description = string.Empty; expense.created_date = DateTime.Now; expense.created_by = SystemParam.CurrentUser.id; result = _expenseBusiness.Insert(expense); } } // Inserts adjustment if (string.IsNullOrEmpty(result)) { if (adjustment > 0) { Revenue adjustmentRevenue = new Revenue(); adjustmentRevenue.id = IDGenerator.RevenueId(); adjustmentRevenue.type = Constants.RevenueType.Adjustment.ToString(); adjustmentRevenue.name = "Điều chỉnh - Bán vé"; adjustmentRevenue.amount = Math.Abs(adjustment); adjustmentRevenue.description = adjustmentReason; adjustmentRevenue.created_date = DateTime.Now; adjustmentRevenue.created_by = SystemParam.CurrentUser.id; result = _revenueBusiness.Insert(adjustmentRevenue); } else if (adjustment < 0) { Expense adjustmentExpense = new Expense(); adjustmentExpense.id = IDGenerator.RevenueId(); adjustmentExpense.type = Constants.RevenueType.Adjustment.ToString(); adjustmentExpense.name = "Điều chỉnh - Bán vé"; adjustmentExpense.amount = Math.Abs(adjustment); adjustmentExpense.description = adjustmentReason; adjustmentExpense.created_date = DateTime.Now; adjustmentExpense.created_by = SystemParam.CurrentUser.id; result = _expenseBusiness.Insert(adjustmentExpense); } } return(result); }
public StringBuilder InsertUpdateProduct(bool isUpdating) { StringBuilder errorMessage = new StringBuilder(); try { AppLogger.logInfo("InsertUpdateProduct"); errorMessage.Append(checkInputData(isUpdating)); if (errorMessage.Length != 0) { return(errorMessage); } if (_model.SelectedManufacturer != null) { _model.Product.ManufacturerId = _model.SelectedManufacturer.Id; } if (_model.SelectedUnit != null) { _model.Product.UnitId = _model.SelectedUnit.Id; } if (_model.SelectedCategory != null) { _model.Product.CategoryId = _model.SelectedCategory.Id; } else { _model.Product.CategoryId = 1; } _model.Product.ChangedBy = SystemParam.CurrentUser.Id; if (isUpdating) { _business.Update(_model.Product); } else { ProductPrice price = new ProductPrice(); price.ProductId = _model.Product.Id; price.Cost = CurrencyUtil.ToDecimal(_model.Cost); price.Price = CurrencyUtil.ToDecimal(_model.Price); price.IsCurrentPrice = true; _model.Product.Price = price.Price; _model.Product.ProductPrices = new List <ProductPrice>() { price }; _business.Insert(_model.Product); } } catch (Exception exc) { AppLogger.logError(exc); errorMessage.AppendLine(exc.Message); } return(errorMessage); }
private decimal CaculatePaymentChange() { decimal adjustment = string.IsNullOrEmpty(tbAdjustmentAmount.Text) ? 0 : CurrencyUtil.ToDecimal(tbAdjustmentAmount.Text); return(CurrencyUtil.ToDecimal(tbRealAmount.Text) - (CurrencyUtil.ToDecimal(tbTotalPayment.Text) + adjustment)); }
protected override void btnSave_Click(object sender, EventArgs e) { try { string errorMessage = ValidInput(); if (string.IsNullOrEmpty(errorMessage) == false) { MessageBox.Show(errorMessage, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } base.btnSave_Click(sender, e); using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) { if (_isRevenue) { Revenue revenue = IsUpdating ? context.Revenues.SingleOrDefault(i => i.id == tbId.Text.Trim()) : new Revenue(); revenue.id = IsUpdating ? tbId.Text : IDGenerator.RevenueId(); revenue.name = tbName.Text; revenue.amount = CurrencyUtil.ToDecimal(tbAmount.Text); revenue.created_by = _isUpdating ? revenue.created_by : SystemParam.CurrentUser.id; revenue.created_date = _isUpdating ? revenue.created_date : dtpCreateDate.Value; revenue.description = tbRemark.Text; revenue.type = Constants.RevenueType.Other.ToString(); AppLogger.logInfo("btnSave_Click", IsUpdating ? "UPDATE" : "INSERT", revenue); if (IsUpdating == false) { context.Revenues.AddObject(revenue); } } else { Expense expense = IsUpdating ? context.Expenses.SingleOrDefault(i => i.id == tbId.Text.Trim()) : new Expense(); expense.id = IsUpdating ? tbId.Text : IDGenerator.ExpenseId(); expense.name = tbName.Text; expense.amount = CurrencyUtil.ToDecimal(tbAmount.Text); expense.created_by = _isUpdating ? expense.created_by : SystemParam.CurrentUser.id; expense.created_date = _isUpdating ? expense.created_date : dtpCreateDate.Value; expense.description = tbRemark.Text; expense.type = string.Empty; AppLogger.logInfo("btnSave_Click", IsUpdating ? "UPDATE" : "INSERT", expense); if (IsUpdating == false) { context.Expenses.AddObject(expense); } } context.SaveChanges(); ChangeViewStatus(false); btnSearch_Click(sender, e); } } catch (Exception exc) { AppLogger.logError("btnSave_Click", exc); } }