private void orderGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { btnAdd.Enabled = false; btnEdit.Enabled = true; txtOrderId.Text = Utility.CellValueByIndex(ZERO, orderGridView); customerCombo.Text = Utility.CellValueByIndex(1, orderGridView); itemCombo.Text = Utility.CellValueByIndex(2, orderGridView); txtInWeight.Text = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("in_weight"); txtOutWeight.Text = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("out_weight"); txtFine.Text = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("fine"); txtLabourRate.Text = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("labour_rate"); dateTimePicker.Value = ((DateTime)Utility.GetCells(orderGridView)["date"].Value); txtTotalAmt.Text = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("total_amount"); string customerName = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("Customer Name"); string itemName = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("Item Name"); string status = Utility.GetCells(orderGridView).GetCellValueFromColumnHeader("status"); DateTime creationDate = ((DateTime)Utility.GetCells(orderGridView)["creation_date"].Value); DateTime upadtedDate = ((DateTime)Utility.GetCells(orderGridView)["last_modified"].Value); lblCreated.Text = creationDate.TimeAgo(); lblUpdate.Text = upadtedDate.TimeAgo(); Model.Order order = new Model.Order { OrderId = txtOrderId.Text, InWeight = txtInWeight.Text.ConvertElseZero(), ItemId = itemCombo.SelectedValue.ToString(), ItemName = itemName, CustomerId = customerCombo.SelectedValue.ToString(), OutWeight = txtOutWeight.Text.ConvertElseZero(), Fine = txtFine.Text.ConvertElseZero(), TotalAmount = txtTotalAmt.Text.ConvertElseZero(), LabourRate = txtLabourRate.Text.ConvertElseZero(), Status = Utility.GetOrderStatus(txtOutWeight.Text.ConvertElseZero()), Date = dateTimePicker.Value, CreatedDate = creationDate }; List <Model.Order> orders = new(); orders.Add(order); statastics = new Model.Stat { CustomerId = customerCombo.SelectedValue.ToString(), CustomerName = customerName, TotalAmt = txtTotalAmt.Text.ConvertElseZero(), TotalFine = txtFine.Text.ConvertElseZero(), TotalInWeight = txtInWeight.Text.ConvertElseZero(), TotalOutWeight = txtOutWeight.Text.ConvertElseZero(), FromDate = DateTime.Now.ToString("MMMM dd, yyyy"), ToDate = DateTime.Now.ToString("MMMM dd, yyyy"), OrderStatus = status, Orders = orders, Address = Utility.GetShopAddress() }; }
void LoadStats() { // double totalAmt = orderService.FetchOrderByType(AppConstants.TOTAL_AMOUNT); // double totalFine = orderService.FetchOrderByType(AppConstants.TOTAL_FINE); Model.Stat stat = CalculateStats(); lblAmt.Text = "Rs. " + Math.Round(stat.TotalAmt, 2); lblInWeight.Text = stat.TotalInWeight.ToString(); lblOutWeight.Text = stat.TotalOutWeight.ToString(); lblFine.Text = stat.TotalFine.ToString(); }
void ClearForm() { btnEdit.Enabled = false; btnAdd.Enabled = true; txtOrderId.Clear(); txtFine.Clear(); txtInWeight.Clear(); txtOutWeight.Clear(); dateTimePicker.Value = DateTime.Now.Date; lblCreated.Text = "date"; lblUpdate.Text = "date"; statastics = null; isPaymentDone = false; }
void setStat() { statastics = CalculateStats(); if (customerAccount != null) { int res = Utility.checkAccountTypeAndReturnValue(customerAccount.Type); statastics.DebitAmt = res == 1 ? customerAccount.Amount : 0; statastics.CreditAmt = res == 2 ? customerAccount.Amount : 0; statastics.GrandAmt = res == 3 ? "0" : customerAccount.Amount.ToString("F") + "-" + customerAccount.Type; statastics.RemainingFine = customerAccount.RemainingFine; statastics.TotalAmt = customerAccount.OrderTotalAmt; statastics.TotalFine = statastics.RemainingFine; if (res == 0) { statastics.GrandAmt = statastics.TotalAmt.ToString("F"); } } statastics.Address = Utility.GetShopAddress(); statastics.FromDate = fromDatePicker.Value.ToString("MMMM dd, yyyy"); statastics.ToDate = toDatePicker.Value.ToString("MMMM dd, yyyy"); }
Model.Stat CalculateStats() { Model.Stat stat = new(); List <Model.Order> orderList = new(); double totalOutWeight = ZERO, totalFine = ZERO, totalInWeight = ZERO, totalAmt = ZERO; for (int i = ZERO; i < reportGridView.RowCount; i++) { DataGridViewRow dataGridViewRow = reportGridView.Rows[i]; string outWeightStr = dataGridViewRow.Cells["out_weight"].Value.ToString(); string inWeightStr = dataGridViewRow.Cells["in_weight"].Value.ToString(); string fineStr = dataGridViewRow.Cells["fine"].Value.ToString(); string amtStr = dataGridViewRow.Cells["total_amount"].Value.ToString(); DateTime date = ((DateTime)dataGridViewRow.Cells["date"].Value).Date; string customerName = dataGridViewRow.Cells.GetCellValueFromColumnHeader("Customer Name"); string itemName = dataGridViewRow.Cells.GetCellValueFromColumnHeader("Item Name"); double outWeight = outWeightStr.ConvertElseZero(); double inWeight = inWeightStr.ConvertElseZero(); double fine = fineStr.ConvertElseZero(); double amt = amtStr.ConvertElseZero(); // setting up order Model.Order order = new() { OutWeight = outWeight, InWeight = inWeight, Fine = fine, TotalAmount = amt, ItemName = itemName, Date = date }; orderList.Add(order); totalOutWeight += outWeight; totalInWeight += inWeight; totalFine += fine; totalAmt += amt; stat.CustomerName = customerName; stat.CustomerId = customerCombo.SelectedValue.ToString(); } stat.TotalInWeight = totalInWeight; stat.TotalOutWeight = totalOutWeight; stat.TotalFine = totalFine; stat.TotalAmt = totalAmt; stat.Orders = orderList; return(stat); } void LoadCustomers() { DataTable dataTable = new BaseDao().PopulateDataSourceData(Queries.CUSTOMER_SELECT_QUERY); this.customerCombo.DataSource = dataTable; this.customerCombo.DisplayMember = "name"; this.customerCombo.ValueMember = "customerId"; } void LoadCustomerAccount() { customerAccount = DataAccess.Instance.LoadSingleData <Model.CustomerAccount, dynamic>( Queries.SELECT_AMT_INVENTORY_BY_CUSTOMER, new { CustomerId = customerCombo.SelectedValue.ToString() }); int res = Utility.checkAccountTypeAndReturnValue(customerAccount.Type); lblAmt.Text = "Rs. " + customerAccount.OrderTotalAmt.ToString("F"); lblFine.Text = customerAccount.RemainingFine.ToString(); } void ClearForm() { fromDatePicker.Value = DateTime.Now.Date; toDatePicker.Value = DateTime.Now.Date; btnGenerate.Enabled = false; statastics = null; isPaymentDone = false; } void LoadStats() { // double totalAmt = orderService.FetchOrderByType(AppConstants.TOTAL_AMOUNT); // double totalFine = orderService.FetchOrderByType(AppConstants.TOTAL_FINE); Model.Stat stat = CalculateStats(); lblAmt.Text = "Rs. " + stat.TotalAmt.ToString("F"); lblInWeight.Text = stat.TotalInWeight.ToString(); lblOutWeight.Text = stat.TotalOutWeight.ToString(); lblFine.Text = stat.TotalFine.ToString(); string date = DataAccess.Instance.LoadSingleData <string, dynamic>( Queries.ORDER_LAST_PLACED_BY_CUSTOMER, new { customerId = customerCombo.SelectedValue.ToString() }); lblLastOrderPlaced.Text = date.FormatDate(); } void PopulateReportGrid() { DataTable dataTable; if (cmbType.SelectedItem.ToString() == "ALL") { dataTable = DataAccess.Instance.PopulateGrid <dynamic>( Queries.ORDER_SELECT_QUERY_BY_CUSTOMER, new { customerId = customerCombo.SelectedValue.ToString() }); } else { dataTable = DataAccess.Instance.PopulateGrid <dynamic>( Queries.ORDER_SELECT_QUERY_BY_CUSTOMER_AND_DATE, new { customerId = customerCombo.SelectedValue.ToString(), fromDate = fromDatePicker.Value.Date, toDate = toDatePicker.Value.Date }); } reportGridView.DataSource = dataTable; reportGridView.Columns["date"].DefaultCellStyle.Format = "dd-MMM-yyyy"; reportGridView.Columns["orderId"].Visible = false; reportGridView.Columns["customerId"].Visible = false; reportGridView.Columns["itemId"].Visible = false; reportGridView.Columns["creation_date"].Visible = false; reportGridView.Columns["last_modified"].Visible = false; reportGridView.Columns["date"].Visible = false; reportGridView.Columns["Customer Name"].Visible = false; reportGridView.Columns["labour_rate"].Visible = false; reportGridView.Columns["status"].Visible = false; LoadStats(); LoadCustomerAccount(); }
void DoPaymentPreProcess(bool isPayLater) { double paidAmt = txtPaidAmt.Text.ConvertElseZero(); double totalAmt = txtTotalAmt.Text.ConvertElseZero(); double paidFine = txtPaidFine.Text.ConvertElseZero(); double totalFine = customerAccount.RemainingFine; int res = Utility.checkAccountTypeAndReturnValue(customerAccount.Type); customerAccount.RemainingFine -= paidFine; if (paidAmt != 0 && !isPayLater) { if (paidAmt > totalAmt) { if (res == 1) { customerAccount.Amount = paidAmt - customerAccount.Amount; } else { customerAccount.Amount += (paidAmt - totalAmt); } customerAccount.OrderTotalAmt = 0; customerAccount.Type = "CREDIT"; } else if (totalAmt > paidAmt && checkBoxUseCredit.Checked == false) { double sub = totalAmt - paidAmt; customerAccount.Amount += sub; customerAccount.Type = "DEBIT"; customerAccount.OrderTotalAmt -= paidAmt; } else { customerAccount.Amount = 0; customerAccount.OrderTotalAmt = 0; customerAccount.Type = "N"; } } else if (isPayLater) { customerAccount.Amount = 0; customerAccount.Amount += paidAmt; customerAccount.Type = "DEBIT"; } paymentService.UpdateAmtInventory(customerAccount); // updating customer paymentStat = new Model.Stat { PaidAmt = txtPaidAmt.Text.ConvertElseZero(), PaidFine = txtPaidFine.Text.ConvertElseZero(), TotalFine = totalFine }; // inserting payment entry paymentService.MakePayment(new { OrderId = reportFormValues["orderId"], customerAccount.AmountId, amount_paid = paymentStat.PaidAmt, fine_paid = paymentStat.PaidFine, customerId = customerAccount.CustomerId }); MessageBox.Show("Payment completed..."); if (reportFormValues["routedFromOrder"] == "true") { isOrderPaymentCompleted = true; } else { isPaymentCompleted = true; } }