public void saveNewPaymentDetail() { // test for saving new paymentdetail for partial payments RefillHeaderDataEntity header = new RefillDao().GetByID(2); header.AmountTender += 10.00M; // accumulate amount tender with current payment // set paymentdetail RefillPaymentDetailDataEntity paymentdetail = new RefillPaymentDetailDataEntity(); paymentdetail.Amount = 10.00M; // current amount tender or payment paymentdetail.PaymentDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); paymentdetail.Header = header; // TODO: should update paidflag in header if total balance = 0. // update daysummary DateTime daysummaryDay = Convert.ToDateTime(DateTime.Now.ToShortDateString()); RefillDaySummaryDataEntity daysummary = new RefillDaySummaryDao().GetByDay(daysummaryDay); if(daysummary != null) { daysummary.TotalSales += paymentdetail.Amount; daysummary.DayStamp = daysummaryDay; } RefillDaySummaryDao dao = new RefillDaySummaryDao(); dao.SaveOrUpdate(daysummary); // update header, save payment detail etc. header.PaymentDetailEntities.Add(paymentdetail); RefillDao ldao = new RefillDao(); ldao.Update(header); }
public void saveNewHeaderAndUpdateDaySummary() { // test for new header but with existing daysummary // should not save new record for daysummary // should only update existing daysummary with transcount and sales DateTime sampleDay = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // daystamp in daysummary should be date only (no time); RefillDaySummaryDao summarydao = new RefillDaySummaryDao(); RefillDaySummaryDataEntity summary = summarydao.GetByDay(sampleDay); if(summary!= null) { RefillHeaderDataEntity header = new RefillHeaderDataEntity(); RefillDetailDataEntity detail = new RefillDetailDataEntity(); RefillTransactionTypeDataEntity transactionType = new RefillTransactionTypeDao().GetByName("Delivery"); RefillProductTypeDataEntity productType = new RefillProductTypeDao().GetByName("5 Gal at 15"); 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.Date = DateTime.Now; header.TransactionType = transactionType; detail.Header = header; // set header entity in detail for nhibernate to pickup and map detail.ProductType = productType; detail.Qty = 20; detail.Amount = productType.Price * Convert.ToDecimal(detail.Qty); detail.StoreBottleQty = 10; detail.StoreCapQty = 10; header.DetailEntities.Add(detail); // add detail to header details list header.AmountDue = detail.Amount; header.TotalQty = detail.Qty; header.AmountTender += 25.00M; // accumulate amount tender with current amount tender // TODO: should update paidflag in header if total balance = 0. // set paymentdetail RefillPaymentDetailDataEntity paymentdetail = new RefillPaymentDetailDataEntity(); paymentdetail.Amount = header.AmountTender; paymentdetail.PaymentDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); paymentdetail.Header = header; header.PaymentDetailEntities.Add(paymentdetail); summary.TransCount += 1; summary.TotalSales += header.AmountTender; header.DaySummary = summary; // update daysummary with transcount and totalsales RefillDaySummaryDao dao = new RefillDaySummaryDao(); dao.Update(summary); // save header,details,etc. RefillDao ldao = new RefillDao(); ldao.SaveOrUpdate(header); } }