public static bool UpdateSale(SalesAndCollectionModel previousSale, SalesAndCollectionModel newSale) { var found = SalesAndCollectionData.Find(x => x.Id.Equals(previousSale.Id)); if (found != null) { found.Address = newSale.Address; found.Contact = newSale.Contact; found.ClosingBalance = newSale.ClosingBalance; found.OpeningBalance = newSale.OpeningBalance; found.IC_NO = newSale.IC_NO; found.MR_NO = newSale.MR_NO; found.Remarks = newSale.Remarks; found.SyncType = newSale.SyncType; found.CollectionAmount = newSale.CollectionAmount; found.SalesAmount = newSale.SalesAmount; found.DealerCode = newSale.DealerCode; found.DealerName = newSale.DealerName; found.Date = newSale.Date; found.Sl = previousSale.Sl; SaveChange(); CalculateOpeningAndClosingBalance(found.DealerCode); return(true); } else { return(false); } }
private void PopupModelControl_Load(object sender, EventArgs e) { if (_dealer != null) { CB_PMC_SelectDealer.Text = _dealer.Code; } if (_dealerList != null) { LPMC_Title.Text = "ADD New Collection"; BPMC_Add.Text = "Add"; _collection = new SalesAndCollectionModel { Id = Guid.NewGuid().ToString("N"), Sl = (SalesAndCollectionManager.GetAllSalesAndCollectionsCount() + 1).ToString(), DealerName = "", Address = "", Contact = "", DealerCode = "", Date = DTP_PMC_Date.Value.Date, IC_NO = "", MR_NO = "", OpeningBalance = null, SalesAmount = 0, CollectionAmount = 0, ClosingBalance = null, Remarks = "", SyncType = "Collection" }; } BindObjectDataToInterface(); }
public static bool DeleteSaleOrCollection(SalesAndCollectionModel saleORCollection, bool isGroupedByDate) { if (isGroupedByDate) { var thatDaysSOC = SalesAndCollectionData.Where(x => x.DealerCode.ToLower().Equals(saleORCollection.DealerCode.ToLower()) && x.Date == saleORCollection.Date).ToList(); if (thatDaysSOC.Count > 0) { foreach (var soc in thatDaysSOC) { SalesAndCollectionData.Remove(soc); } SaveChange(); CalculateOpeningAndClosingBalance(saleORCollection.DealerCode); return(true); } return(false); } else { var findSOC = SalesAndCollectionData.Where(x => x.Id.Equals(saleORCollection.Id)).FirstOrDefault(); if (findSOC != null) { SalesAndCollectionData.Remove(findSOC); SaveChange(); CalculateOpeningAndClosingBalance(saleORCollection.DealerCode); return(true); } return(false); } }
private void BSAC_DeleteSOC_Click(object sender, EventArgs e) { if (_tempedSalesAndCollections.Count > 0) { DataGridViewRow row = this.DGV_SAC_SalesAndCollectionList.SelectedRows[0]; if (row != null) { DialogResult dialogResult = MessageBox.Show(" Are you sure? ", "Confirm Delete?", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SalesAndCollectionModel soc = row.DataBoundItem as SalesAndCollectionModel; if (CKB_GroupBy.Checked) { if (CB_SAC_DealerCode.Text.ToLower().Equals("any")) { MessageBox.Show("Please select a Dealer code!"); } else { if (SalesAndCollectionManager.DeleteSaleOrCollection(soc, true)) { MessageBox.Show("All sales and collections for Dealer :" + soc.DealerName + "(" + soc.DealerCode + ") on Date : " + soc.Date + " has been Deleated!"); BindAllFilters(); } else { MessageBox.Show("Error! Something went wrong while Deleting!!"); } } } else { if (SalesAndCollectionManager.DeleteSaleOrCollection(soc, false)) { MessageBox.Show("Deleated Successfully!"); BindAllFilters(); } else { MessageBox.Show("Error! Something went wrong while Deleting!!"); } } } else if (dialogResult == DialogResult.No) { //do something else } } else { MessageBox.Show("Select a row to delete!"); } } else { MessageBox.Show("List is Empty :("); } }
public static bool AddNewCollection(SalesAndCollectionModel collection) { if (CsvHelperUtility.InsertOneNewDataToFile(false, salesAndCollectionFilePath, ",", collection)) { LoadAllSalesAndCollections(); CalculateOpeningAndClosingBalance(collection.DealerCode); return(true); } else { return(false); } }
public static List <SalesAndCollectionModel> EverydaySalesAndCollections(string dealerCode) { var dealersHistory = new List <SalesAndCollectionModel>(); if (SalesAndCollectionData.Count > 0) { var dealer = DealerManager.FindDealer(dealerCode); dealersHistory = SalesAndCollectionData.Where(x => x.DealerCode.Equals(dealerCode)).ToList(); var everydayDealersHistory = new List <SalesAndCollectionModel>(); if (dealersHistory.Count > 0) { var allDates = dealersHistory.Select(x => x.Date).Distinct().ToList(); allDates = allDates.OrderBy(x => x.Value).ToList(); int count = 1; foreach (var date in allDates) { var thatDaysHistory = dealersHistory.Where(x => x.Date == date).ToList(); var mergeThatDaysHistory = new SalesAndCollectionModel(); mergeThatDaysHistory.Address = dealer.Address; mergeThatDaysHistory.Contact = dealer.Contact; mergeThatDaysHistory.DealerName = dealer.DealerName; mergeThatDaysHistory.DealerCode = dealer.Code; mergeThatDaysHistory.Date = date; mergeThatDaysHistory.IC_NO = ""; mergeThatDaysHistory.MR_NO = ""; mergeThatDaysHistory.Remarks = ""; mergeThatDaysHistory.SyncType = "Daily"; mergeThatDaysHistory.Sl = (count++).ToString(); mergeThatDaysHistory.OpeningBalance = thatDaysHistory.FirstOrDefault().OpeningBalance; mergeThatDaysHistory.SalesAmount = thatDaysHistory.Sum(x => x.SalesAmount); mergeThatDaysHistory.CollectionAmount = thatDaysHistory.Sum(x => x.CollectionAmount); mergeThatDaysHistory.ClosingBalance = thatDaysHistory.LastOrDefault().ClosingBalance; everydayDealersHistory.Add(mergeThatDaysHistory); } } return(everydayDealersHistory); } return(dealersHistory); }
private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { IC_ProgressPanel.Visible = false; InvoiceProgressBar.Visible = false; _vPanel.Enabled = true; _hPanel.Enabled = true; void UpdateProductStock() { foreach (var item in _invoicePage.AllProducts) { var product = _productList.Where(x => x.ProductCode.Equals(item.ProductCode)).FirstOrDefault(); if (product != null) { if (_itemList != null) { var previousItem = _itemList.Where(x => x.ProductCode.Equals(item.ProductCode)).FirstOrDefault(); product.StockAvailable += previousItem.Quantity; } product.StockAvailable -= item.Quantity; } } ProductManager.UpdateAllProducts(_productList); } void SaveInvoiceLogFile() { if (!string.IsNullOrEmpty(_invoicePage.CurrentLogFile)) { _invoicePage.PreviousLogFile = _invoicePage.CurrentLogFile; FileSystemUtility.DeleteFile(_invoicePage.CurrentLogFile); } Files invoiceLog = new Files(); invoiceLog.FileLocation = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Invoiceasy\InvoiceLog"; invoiceLog.FileName = "InvoiceLog-" + _invoicePage.No + "_" + DTP_IC_Date.Value.ToString("dd MMMM yyyy") + " " + DateTime.Now.ToString("HH-mm-ss") + ".txt"; _invoicePage.CurrentLogFile = invoiceLog.FileLocation + @"\" + invoiceLog.FileName; invoiceLog.FileText = JsonConvert.SerializeObject(_invoicePage); FileSystemUtility.DeleteFile(_invoicePage.CurrentLogFile); FileSystemUtility.Initialize(true, invoiceLog); FileSystemUtility.WriteFile(); var logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Invoiceasy" + @"\InvoiceItems\" + "Invoice-" + _invoicePage.No + "_" + "ItemList_" + DTP_IC_Date.Value.ToString("dd MMMM yyyy HH-mm-ss") + ".txt"; FileSystemUtility.CreateFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Invoiceasy" + @"\InvoiceItems"); CsvHelperUtility.WriteDataToFile <ItemModel>(true, logFilePath, ",", _invoicePage.AllProducts); } void AddSale() { var sale = new SalesAndCollectionModel { Id = Guid.NewGuid().ToString("N"), Sl = (SalesAndCollectionManager.GetAllSalesAndCollectionsCount() + 1).ToString(), DealerName = _invoicePage.Dealer.DealerName, Address = _invoicePage.Dealer.Address, Contact = _invoicePage.Dealer.Contact, DealerCode = _invoicePage.Dealer.Code, Date = DTP_IC_Date.Value, IC_NO = _invoicePage.No, MR_NO = "", OpeningBalance = null, SalesAmount = _invoicePage.PayableAmount, CollectionAmount = 0, ClosingBalance = null, Remarks = "", SyncType = "Sales" }; if (_invoicePage.sale == null) { _invoicePage.sale = sale; SalesAndCollectionManager.AddNewSale(sale); } else { SalesAndCollectionManager.UpdateSale(_invoicePage.sale, sale); } } BindInterfaceDataToObject(); UpdateProductStock(); AddSale(); SaveInvoiceLogFile(); if (_isSuccess) { MessageBox.Show("Invoice file has been saved successfully"); } else { MessageBox.Show("Error! Something Went Wrong while saving the file"); } LoadChallanForm(); }