public void Delete(LaundryDaySummaryDataEntity p_daysummary) { using(var session = NHibernateHelper.OpenSession()) { using(var transaction = session.BeginTransaction()) { try { session.Delete(p_daysummary); transaction.Commit(); } catch(Exception ex) { transaction.Rollback(); throw ex; } } } }
public void saveNewHeaderAndNewDaySummary() { // test for new header and new day // should create new record for daysummary LaundryHeaderDataEntity header = new LaundryHeaderDataEntity(); LaundryDetailDataEntity detail = new LaundryDetailDataEntity(); LaundryJobChargesDataEntity jobcharge = new LaundryJobChargesDataEntity(); LaundryCategoryDataEntity category = new LaundryCategoryDao().GetByName("Colored Garments"); LaundryServiceDataEntity service = new LaundryServiceDao().GetByName("Wash - Dry - Fold"); LaundryPriceSchemeDataEntity pricescheme = new LaundryPriceSchemeDao().GetByCategoryService(service,category); CustomerDao custdao = new CustomerDao(); CustomerDataEntity customer = custdao.GetByName("John Dee"); if(customer == null) { customer = new CustomerDataEntity(); customer.Name = "John Dee"; customer.Address = "Cebu"; customer.ContactNumber = "111-1111"; } header.Customer = customer; header.ReceivedDate = DateTime.Now; header.DueDate = DateTime.Now.AddDays(5); // add 5 days for due date detail.Header = header; // set header entity in detail for nhibernate to pickup and map detail.Category = category; detail.Service = service; detail.Kilo = 5; detail.Amount = pricescheme.Price * Convert.ToDecimal(detail.Kilo); detail.ItemQty = 20; jobcharge.Charge = new LaundryChargeDao().GetByName("Delivery"); jobcharge.Header = header; // set header entity in jobcharge for nhibernate to pickup and map header.DetailEntities.Add(detail); // add detail to header details list header.JobChargeEntities.Add(jobcharge); // add charges to header charges list header.ClaimFlag = false; header.AmountDue = detail.Amount; header.TotalItemQty = detail.ItemQty; header.TotalCharge = jobcharge.Charge.Amount; header.TotalDiscount = 0; header.TotalAmountDue = (header.AmountDue + header.TotalCharge) - header.TotalDiscount; header.TotalPayment = header.TotalAmountDue; if(header.TotalPayment == header.TotalAmountDue){ header.PaidFlag = true; } else{ header.PaidFlag = false; } // set paymentdetail LaundryPaymentDetailDataEntity paymentdetail = new LaundryPaymentDetailDataEntity(); paymentdetail.Amount = header.TotalPayment; paymentdetail.PaymentDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); paymentdetail.Header = header; header.PaymentDetailEntities.Add(paymentdetail); // set daysummary LaundryDaySummaryDataEntity daysummary = new LaundryDaySummaryDataEntity(); daysummary.DayStamp = Convert.ToDateTime(DateTime.Now.ToShortDateString()); daysummary.TotalSales += header.TotalPayment; daysummary.TransCount += 1; daysummary.HeaderEntities.Add(header); // set header entity in daysummary for nhibernate to pickup and map header.DaySummary = daysummary; // set daysummary entity in header for nhibernate to pickup and map custdao.SaveOrUpdate(customer); // save or update customer // save daysummary record; no need to explicitly save header,detail,jobcharges,paymentdetail, etc for new daysummary record // this will handle the saving for the linked tables // FIX: save new header & new daysummary thru laundrydao instead of laundrydaysummary LaundryDao dao = new LaundryDao(); dao.SaveOrUpdate(header); }
public void saveNewDaysummary() { LaundryDaySummaryDataEntity daysummary = new LaundryDaySummaryDataEntity(); }
private bool SaveDaySummary(LaundryHeaderDataEntity headerEntity) { try{ DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // daystamp in daysummary should be date only (no time); LaundryDaySummaryDataEntity daySummary = m_summaryDao.GetByDay(today); headerEntity.PaymentDetailEntities = m_headerEntity.PaymentDetailEntities; if(daySummary != null) { if(m_view.GetTitle().Contains("NEW")) daySummary.TransCount += 1; //TODO: totalsales should be totalamoutdue - balance if(headerEntity.PaymentDetailEntities[headerEntity.PaymentDetailEntities.Count-1] != null) daySummary.TotalSales += headerEntity.PaymentDetailEntities[headerEntity.PaymentDetailEntities.Count-1].Amount; else daySummary.TotalSales += 0; headerEntity.DaySummary = daySummary; // update daysummary with transcount and totalsales m_summaryDao.Update(daySummary); }else{ // set daysummary daySummary = new LaundryDaySummaryDataEntity(); daySummary.DayStamp = Convert.ToDateTime(DateTime.Now.ToShortDateString()); //TODO: totalsales should be amounttender - amount change. if(headerEntity.PaymentDetailEntities[headerEntity.PaymentDetailEntities.Count-1] != null) daySummary.TotalSales += headerEntity.PaymentDetailEntities[headerEntity.PaymentDetailEntities.Count-1].Amount; else daySummary.TotalSales += 0; if(m_view.GetTitle().Contains("NEW")) daySummary.TransCount += 1; // set header entity in daysummary for nhibernate to pickup and map daySummary.HeaderEntities.Add(headerEntity); // set daysummary entity in header for nhibernate to pickup and map m_headerEntity.DaySummary = daySummary; //m_chargeDao.SaveOrUpdate(headerEntity. //m_customerDao.SaveOrUpdate(headerEntity.Customer); // save daysummary record; no need to explicitly save header,detail,jobcharges,paymentdetail, etc for new daysummary record // this will handle the saving for the linked tables } m_laundryDao.SaveOrUpdate(headerEntity); }catch(Exception ex){ MessageService.ShowError("Unexpected exception occured while saving your entries.\nPlease see log file for technical details.","Error in Saving", ex); return false; } return true; }