Exemplo n.º 1
0
		private void ChangeOrderType()
		{
			if (mclsTerminalDetails.AutoPrint == PrintingPreference.Auto && mboIsInTransaction)
			{
				MessageBox.Show("Sorry you cannot change Order Type if Auto-print is ON an item is already purchased.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				return;
			}
			DialogResult loginresult = GetWriteAccessAndLogin(mclsSalesTransactionDetails.CashierID, AccessTypes.CloseTransaction, "Change Order Type");

            if (loginresult == DialogResult.OK)
			{
				try
				{
					clsEvent.AddEvent("[" + lblCashier.Text + "] Changing order type of trans. no. " + lblTransNo.Text);

                    OrderTypeWnd clsOrderTypeWnd = new OrderTypeWnd();
                    clsOrderTypeWnd.TerminalDetails = mclsTerminalDetails;
                    clsOrderTypeWnd.ShowDialog(this);
                    DialogResult result = clsOrderTypeWnd.Result;
                    OrderTypes clsOrderType = clsOrderTypeWnd.orderType;
                    clsOrderTypeWnd.Close();
                    clsOrderTypeWnd.Dispose();

					if (result == DialogResult.OK)
					{
						Cursor.Current = Cursors.WaitCursor;
						if (!mboIsInTransaction)
						{
							this.LoadOptions();
							if (!this.CreateTransaction()) return;
						}

                        mclsSalesTransactionDetails.OrderType = clsOrderType;

                        Data.SalesTransactions clsSalesTransactions = new Data.SalesTransactions(mConnection, mTransaction);
                        mConnection = clsSalesTransactions.Connection; mTransaction = clsSalesTransactions.Transaction;

                        clsSalesTransactions.UpdateOrderType(mclsSalesTransactionDetails.TransactionID, mclsSalesTransactionDetails.TransactionDate, mclsSalesTransactionDetails.OrderType);
                        InsertAuditLog(AccessTypes.ChargeType, "Change order type to " + mclsSalesTransactionDetails.OrderType.ToString("G") + ". Tran. #".PadRight(15) + ":" + lblTransNo.Text + " @ Branch: " + mclsTerminalDetails.BranchDetails.BranchCode);
                        clsEvent.AddEventLn("Done!", true);

                        if (clsOrderType != OrderTypes.DineIn && mclsSalesTransactionDetails.CustomerID == Constants.C_RETAILPLUS_CUSTOMERID)
                        {
                            Int64 iOldContactID = mclsSalesTransactionDetails.CustomerID;

                            SelectContact(AceSoft.RetailPlus.Data.ContactGroupCategory.CUSTOMER);

                            if (iOldContactID != mclsSalesTransactionDetails.CustomerID)
                            {
                                Data.Contacts clsContacts = new Data.Contacts(mConnection, mTransaction);
                                mConnection = clsContacts.Connection; mTransaction = clsContacts.Transaction;
                                clsContacts.UpdateLastCheckInDate(iOldContactID, Constants.C_DATE_MIN_VALUE);
                                clsContacts.UpdateLastCheckInDate(mclsSalesTransactionDetails.CustomerID, mclsSalesTransactionDetails.TransactionDate);
                                clsContacts.CommitAndDispose();
                            }
                        }
                        if (mclsSalesTransactionDetails.CustomerID == Constants.C_RETAILPLUS_CUSTOMERID)
                        {
                            mclsSalesTransactionDetails.OrderType = OrderTypes.DineIn;

                            clsSalesTransactions = new Data.SalesTransactions(mConnection, mTransaction);
                            mConnection = clsSalesTransactions.Connection; mTransaction = clsSalesTransactions.Transaction;

                            clsSalesTransactions.UpdateOrderType(mclsSalesTransactionDetails.TransactionID, mclsSalesTransactionDetails.TransactionDate, mclsSalesTransactionDetails.OrderType);
                            InsertAuditLog(AccessTypes.ChargeType, "System override order type to " + mclsSalesTransactionDetails.OrderType.ToString("G") + ". Tran. #".PadRight(15) + ":" + lblTransNo.Text + " @ Branch: " + mclsTerminalDetails.BranchDetails.BranchCode);

                        }

                        clsSalesTransactions.CommitAndDispose();

                        lblOrderType.Text = mclsSalesTransactionDetails.OrderType.ToString("G").ToUpper();

                        // [09/24/2014] apply the default charge if changed to dine in

                        Data.ChargeType clsChargeType = new Data.ChargeType(mConnection, mTransaction);
                        mConnection = clsChargeType.Connection; mTransaction = clsChargeType.Transaction;

                        Data.ChargeTypeDetails clsChargeTypeDetails = new Data.ChargeTypeDetails();
                        if (mclsSalesTransactionDetails.OrderType == OrderTypes.DineIn && !string.IsNullOrEmpty(mclsTerminalDetails.DineInChargeCode))
                        {
                            clsChargeTypeDetails = clsChargeType.Details(mclsTerminalDetails.DineInChargeCode);
                            setTransCharge(clsChargeTypeDetails, "Change Order Type to Dine-In. Charge Code:" + mclsTerminalDetails.DineInChargeCode);
                        }
                        else if (mclsSalesTransactionDetails.OrderType == OrderTypes.TakeOut && !string.IsNullOrEmpty(mclsTerminalDetails.TakeOutChargeCode))
                        {
                            clsChargeTypeDetails = clsChargeType.Details(mclsTerminalDetails.TakeOutChargeCode);
                            setTransCharge(clsChargeTypeDetails, "Change Order Type to Take-Out. Charge Code:" + mclsTerminalDetails.TakeOutChargeCode);
                        }
                        else if (mclsSalesTransactionDetails.OrderType == OrderTypes.Delivery && !string.IsNullOrEmpty(mclsTerminalDetails.DeliveryChargeCode))
                        {
                            clsChargeTypeDetails = clsChargeType.Details(mclsTerminalDetails.DeliveryChargeCode);
                            setTransCharge(clsChargeTypeDetails, "Change Order Type to Delivery. Charge Code:" + mclsTerminalDetails.DeliveryChargeCode);
                        }
                        else
                        {
                            ApplyTransZeroCharge();
                        }

                        clsChargeType.CommitAndDispose();
                    }
                    else { clsEvent.AddEventLn("Cancelled!"); }
				}
				catch (Exception ex)
				{ 
                    InsertErrorLogToFile(ex, "ERROR!!! Changing order type."); 
                }
				Cursor.Current = Cursors.Default;
			}
		}