Пример #1
0
 public void Delete(RefillHeaderDataEntity p_header)
 {
     using(var session = NHibernateHelper.OpenSession())
     {
         using(var transaction = session.BeginTransaction())
         {
             try
             {
                 session.Delete(p_header);
                 transaction.Commit();
             }
             catch(Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
Пример #2
0
        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);
            }
        }
Пример #3
0
        public void saveNewHeaderAndNewDaySummary()
        {
            // test for new header and new day
            // should create new record for daysummary
            RefillHeaderDataEntity header = new RefillHeaderDataEntity();
            RefillDetailDataEntity detail = new RefillDetailDataEntity();

            RefillTransactionTypeDataEntity transactionType = new RefillTransactionTypeDao().GetByName("Delivery");
            RefillProductTypeDataEntity productType = new RefillProductTypeDao().GetByName("5 Gal at 25");

            CustomerDao custdao = new CustomerDao();
            CustomerDataEntity customer = custdao.GetByName("Vanessa Dee");
            if(customer == null)
            {
                customer = new CustomerDataEntity();
                customer.Name = "Vanessa Dee";
                customer.Address = "Cebu";
                customer.ContactNumber = "111-1111";
            }

            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 = 10;
            detail.Amount = productType.Price * Convert.ToDecimal(detail.Qty);
            detail.StoreBottleQty = 10;
            detail.StoreCapQty = 10;

            // update main inventory
            // TODO: fix proper handling of inventory per type of bottle???
            RefillInventoryDao refillInvDao = new RefillInventoryDao();
            RefillInventoryHeaderDataEntity inv = new RefillInventoryHeaderDataEntity();
            //inv = refillInvDao.GetByName("Cap");
            //inv.TotalQty = 500;
            //inv.QtyOnHand -= detail.StoreCapQty;
            //inv.QtyReleased += detail.StoreCapQty;
            //refillInvDao.Update(inv);
            inv = refillInvDao.GetByName("5 Gal Bottle");
            inv.QtyOnHand -= detail.StoreBottleQty;
            inv.QtyReleased += detail.StoreBottleQty;
            refillInvDao.Update(inv);

            // update cust inventory
            RefillCustomerInventoryDao custInvDao = new RefillCustomerInventoryDao();
            RefillCustInventoryHeaderDataEntity custInv= new RefillCustInventoryHeaderDataEntity();
            custInv.Customer = customer;
            custInv.CapsOnHand += detail.StoreCapQty;
            custInv.BottlesOnHand += detail.StoreBottleQty;

            header.Customer = customer;

            header.DetailEntities.Add(detail); // add detail to header details list
            header.AmountDue = detail.Amount;
            header.TotalQty = detail.Qty;
            header.AmountTender = header.AmountDue;

            if(header.AmountTender == header.AmountTender){
                header.PaidFlag = true;
            }
            else{
                header.PaidFlag = false;
            }

            // set paymentdetail
            RefillPaymentDetailDataEntity paymentdetail = new RefillPaymentDetailDataEntity();
            paymentdetail.Amount = header.AmountTender;
            paymentdetail.PaymentDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            paymentdetail.Header = header;
            header.PaymentDetailEntities.Add(paymentdetail);

            // set daysummary
            RefillDaySummaryDataEntity daysummary = new RefillDaySummaryDataEntity();
            daysummary.DayStamp = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            daysummary.TotalSales += header.AmountTender;
            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
            custInvDao.SaveOrUpdate(custInv);
            // 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
            RefillDao ldao = new RefillDao();
            ldao.SaveOrUpdate(header);
        }
Пример #4
0
        public RefillHeaderDataEntity ProcessHeaderDataEntity()
        {
            int totalQty = 0;
            RefillHeaderDataEntity m_headerEntity = new RefillHeaderDataEntity();
            m_headerEntity.Date = dtDate.Value;
            m_headerEntity.Customer = m_presenter.getCustomerByName(cmbCustomers.Text);
            m_headerEntity.TransactionType = m_presenter.getTransactionTypeByName(cmbtransTypes.Text);
            m_headerEntity.AmountDue = decimal.Parse(txtamtdue.Text);
            //m_headerEntity.AmountTender = decimal.Parse(txtamttender.Text);
            List<RefillDetailDataEntity> refillDetails = new List<RefillDetailDataEntity>();
            foreach(DataGridViewRow row in this.dataGridView1.Rows){
                if(row.Cells[0].Value != null){
                    if(!string.IsNullOrEmpty(row.Cells[0].Value.ToString())){
                        RefillDetailDataEntity detail = new RefillDetailDataEntity();
                        detail.Header = m_headerEntity;
                        detail.ProductType = m_presenter.getProductByName(row.Cells[0].Value.ToString());
                        detail.StoreBottleQty = int.Parse(row.Cells[1].Value.ToString());
                        detail.StoreCapQty = int.Parse(row.Cells[2].Value.ToString());
                        detail.Qty = int.Parse(row.Cells[3].Value.ToString());
                        totalQty += detail.Qty;
                        detail.Amount = decimal.Parse(row.Cells[4].Value.ToString());
                        refillDetails.Add(detail);
                    }
                }
            }
            m_headerEntity.DetailEntities = refillDetails;
            m_headerEntity.PaidFlag = chkunpaid.Checked;
            RefillPaymentDetailDataEntity paymentDetail = new RefillPaymentDetailDataEntity();
            m_headerEntity.PaidFlag = false;

            if(decimal.Parse(txtamttender.Text) > 0){
                if(decimal.Parse(txtamttender.Text) >= m_headerEntity.AmountDue){
                    paymentDetail.Amount = m_headerEntity.AmountDue;
                    m_headerEntity.PaidFlag = true;
                }else{
                    paymentDetail.Amount = decimal.Parse(txtamttender.Text);
                }
            }else
                paymentDetail.Amount = 0M;

            m_headerEntity.AmountTender = paymentDetail.Amount;
            m_headerEntity.TotalQty = totalQty;
            paymentDetail.PaymentDate = Convert.ToDateTime(DateTime.Now);
            paymentDetail.Header = m_headerEntity;
            paymentDetail = paymentDetail.Amount > 0 ? paymentDetail : null;
            m_headerEntity.PaymentDetailEntities.Add(paymentDetail);

            return m_headerEntity;
        }
Пример #5
0
 public void LoadHeaderEntityData(RefillHeaderDataEntity p_headerEntity)
 {
     m_headerEntity = p_headerEntity;
     txtjonumber.Text = m_headerEntity.RefillHeaderID.ToString().PadLeft(6, '0');
     cmbCustomers.Text = m_headerEntity.Customer.Name;
     cmbtransTypes.Text = m_headerEntity.TransactionType.Name;
     dataGridView1.Rows.Clear();
     dtDate.Value = m_headerEntity.Date;
     foreach(RefillDetailDataEntity detail in m_headerEntity.DetailEntities){
         dataGridView1.Rows.Add(detail.ProductType.Name, detail.StoreBottleQty.ToString(), detail.StoreCapQty.ToString(), detail.Qty.ToString(), detail.Amount.ToString("N2"));
     }
     txtamtdue.Text = m_headerEntity.AmountDue.ToString("N2");
     txtbalance.Text = (m_headerEntity.AmountDue - m_headerEntity.AmountTender).ToString("N2");
     chkunpaid.Checked = decimal.Parse(txtbalance.Text) == 0 ? false : true;
     lblvoid.Visible = m_headerEntity.VoidFlag;
     if(m_headerEntity.VoidFlag){
         btndeleteclose.Enabled = false;
     }else{
         btndeleteclose.Enabled = true;
     }
 }
 private RefillPaymentDetailDataEntity CreateNewPayment(decimal amount, RefillHeaderDataEntity header, DateTime paymentDate)
 {
     RefillPaymentDetailDataEntity payment = new RefillPaymentDetailDataEntity();
     payment.Header = header;
     payment.Amount = amount;
     payment.PaymentDate = paymentDate;
     return payment;
 }
 private void UpdateDaySummary(decimal amount, DateTime paymentDate, RefillHeaderDataEntity header)
 {
     try
     {
         RefillDaySummaryDataEntity daysummary = m_daysummaryDao.GetByDay(paymentDate);
         if(daysummary == null)
         {
             daysummary = new RefillDaySummaryDataEntity();
             daysummary.HeaderEntities.Add(header);
             daysummary.TotalSales += amount;
             daysummary.DayStamp = paymentDate;
         }else{
             daysummary.TotalSales += amount;
         }
         m_daysummaryDao.SaveOrUpdate(daysummary);
     }
     catch(Exception ex)
     {
         throw ex;
     }
 }
 private bool UpdateRefillCustomerInventory(RefillHeaderDataEntity headerEntity)
 {
     try{
         RefillInventoryHeaderDataEntity inventoryHeader = new RefillInventoryHeaderDataEntity();
         RefillCustInventoryHeaderDataEntity customerInvHeader = m_customerInvDao.GetByCustomer(headerEntity.Customer);
         if(customerInvHeader == null){
             customerInvHeader = new RefillCustInventoryHeaderDataEntity();
             customerInvHeader.Customer = headerEntity.Customer;
         }
         foreach(RefillDetailDataEntity detail in headerEntity.DetailEntities){
             if(detail.ProductType.Name.StartsWith("5 Gal",true,null)){
                 inventoryHeader = m_refillInvDao.GetByName("5 Gal");
                 if(inventoryHeader != null){
                     inventoryHeader.QtyOnHand -= detail.StoreBottleQty;
                     inventoryHeader.QtyReleased += detail.StoreBottleQty;
                     customerInvHeader.CapsOnHand += detail.StoreCapQty;
                     customerInvHeader.BottlesOnHand += detail.StoreBottleQty;
                     m_refillInvDao.Update(inventoryHeader);
                     m_customerInvDao.SaveOrUpdate(customerInvHeader);
                     UpdateCapsQty(detail, customerInvHeader, false);
                     UpdateInventoryDetail(inventoryHeader);
                 }
             }
         }
     }catch(Exception ex){
         MessageService.ShowError("Unexpected exception occured while processing your request.\nPlease see log file for technical details","Error", ex);
         return false;
     }
     return true;
 }
 public RefillHeaderDataEntity getHeaderByJoNumber(int id)
 {
     m_OriginalHeaderEntity = m_refillDao.GetByID(id);
     return m_OriginalHeaderEntity;
 }
        private bool SaveDaySummary(RefillHeaderDataEntity headerEntity)
        {
            try{
                DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // daystamp in daysummary should be date only (no time);
                RefillDaySummaryDataEntity daySummary = m_summaryDao.GetByDay(today);
                if(daySummary != null)
                {
                    daySummary.TransCount += 1;
                    //TODO: totalsales should be totalamoutdue - balance
                    //daySummary.TotalSales += headerEntity.PaymentDetailEntities[0].Amount;
                    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 RefillDaySummaryDataEntity();
                    daySummary.DayStamp = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                    //TODO: totalsales should be amounttender - amount change.

                    //daySummary.TotalSales +=  headerEntity.PaymentDetailEntities[0].Amount;
                    if(headerEntity.PaymentDetailEntities[headerEntity.PaymentDetailEntities.Count-1] != null)
                        daySummary.TotalSales += headerEntity.PaymentDetailEntities[headerEntity.PaymentDetailEntities.Count-1].Amount;
                    else
                        daySummary.TotalSales += 0;
                    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
                    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_refillDao.SaveOrUpdate(headerEntity);
                return true;
            }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;
        }
        public void SaveClicked()
        {
            m_headerEntity = m_view.ProcessHeaderDataEntity();
            if(SaveDaySummary(m_headerEntity)){
                if(!UpdateRefillCustomerInventory(m_headerEntity))
                    return;
                if(MessageService.ShowYesNo("Successfully saved entries." + Environment.NewLine +
                                            "Do you want to print this transaction with JO number: " + m_headerEntity.RefillHeaderID.ToString().PadLeft(6, '0') + "?" ,"Information")){
                    try{
                        PrintService.PrintRefillSlip(GetPrinterInfo(), m_headerEntity, GetCompanyInfo());
                    }catch(Exception ex){
                        MessageService.ShowError("Unexpected exception has occurred during printing. Please verify whether printer is installed and online. \n Please check error logs for details.", "Error in Printing", ex);
                    }

                }
            }
        }
        public void PrintTransaction()
        {
            m_headerEntity = m_view.ProcessHeaderDataEntity();
            if(m_headerEntity != null){
                MessageService.ShowInfo("Printing transaction with JO number: " + m_OriginalHeaderEntity.RefillHeaderID.ToString().PadLeft(6, '0'));

                try{
                    PrintService.PrintRefillSlip(GetPrinterInfo(), m_headerEntity, GetCompanyInfo());
                }catch(Exception ex){
                    MessageService.ShowError("Unexpected exception has occurred during printing. Please verify whether printer is installed and online. \n Please check error logs for details.", "Error in Printing", ex);
                }
            }
        }
Пример #13
0
        private static void PrintRefillOrderSlip(ref StringBuilder sb, RefillHeaderDataEntity header,CompanyDataEntity company)
        {
            string[] itemArr;
            string item = "";

            PrintHeader(ref sb,company);
            sb.Append(SetFontSize(2));
            sb.AppendLine("ORDER SLIP");
            sb.Append(SetFontSize(0));
            sb.AppendLine("");
            sb.Append(SetAlignment("LEFT"));
            sb.AppendLine("SO# :              " + header.RefillHeaderID.ToString());
            sb.AppendLine("CUSTOMER :         " + header.Customer.Name.ToUpper());
            sb.AppendLine("DATE RECEIVED :    " + header.Date.ToShortDateString());
            sb.AppendLine("TRANSACTION TYPE : " + header.TransactionType.Name.ToUpper());
            sb.AppendLine("");

            sb.AppendLine("#OF ITEMS             " + SetAlignment("CENTER") +
                 "ITEM             TOTAL");
            int storebottle = 0;
            int storecap = 0;
            foreach(RefillDetailDataEntity detail in header.DetailEntities)
            {
                itemArr = detail.ProductType.Name.Split(' ');
                item = "";
                foreach(string st in itemArr)
                {
                    if(st.Equals("at")){
                        item += "@";
                        continue;
                    }
                    item += st;
                }
                sb.AppendLine(SetAlignment("LEFT") + "  " + FormatStringAlignment(detail.Qty.ToString(),"LEFT"));
                sb.AppendLine(SetAlignment("RIGHT") + FormatStringAlignment(item,"RIGHT") + FormatStringAlignment(detail.Amount.ToString("N2"),"LEFT"));
                storebottle += detail.StoreBottleQty;
                storecap += detail.StoreCapQty;
            }
            sb.AppendLine("");
            sb.AppendLine("");
            sb.Append(SetAlignment("CENTER"));
            sb.AppendLine(header.TotalQty.ToString() + " ITEMS");
            sb.Append(SetAlignment("LEFT"));
            sb.AppendLine("");
            sb.AppendLine("   STORE CAP: " + storecap);
            sb.AppendLine("STORE BOTTLE: " + storebottle);
            sb.AppendLine("");
            sb.Append(SetAlignment("RIGHT"));

            sb.AppendLine("  TOTAL: " + FormatStringAlignment(header.AmountDue.ToString("N2"),"RIGHT"));
            sb.AppendLine("DEPOSIT: " + FormatStringAlignment(header.AmountTender.ToString("N2"),"RIGHT"));
            sb.AppendLine("BALANCE: " + FormatStringAlignment((header.AmountDue - header.AmountTender).ToString("N2"),"RIGHT"));

            PrintFooter(ref sb);
            sb.Append(CutPaper());
        }
Пример #14
0
        public static bool PrintRefillSlip(PrinterDataEntity printer, RefillHeaderDataEntity header, CompanyDataEntity company)
        {
            try{
                SetPrinter(printer);
                if (ps == null) return false;

                StringBuilder sb = new StringBuilder();
                PrintRefillOrderSlip(ref sb, header,company);

                RawPrinterHelper.SendStringToPrinter(ps.PrinterName, sb.ToString());
                return true;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }