Esempio n. 1
0
		private void LoadContact(AceSoft.RetailPlus.Data.ContactGroupCategory enumContactGroupCategory, Data.ContactDetails pContactDetails, bool isFromCreditPayment = false)
		{
			try
			{
                if ((mclsTerminalDetails.ShowCustomerSelection || pContactDetails.ContactID != 0) && 
                    (enumContactGroupCategory == Data.ContactGroupCategory.CUSTOMER || enumContactGroupCategory == Data.ContactGroupCategory.AGENT))
					mclsContactDetails = pContactDetails;
				else
				{
					string strContactCardNo = txtBarCode.Text.Replace(Constants.SWIPE_REWARD_CARD, "").Trim();

					Data.Contacts clsContact = new Data.Contacts(mConnection, mTransaction);
                    mConnection = clsContact.Connection; mTransaction = clsContact.Transaction;

					// check using reward card info
					mclsContactDetails = clsContact.DetailsByRewardCardNo(strContactCardNo);
					if (mclsContactDetails.ContactID != 0)
						mboRewardCardSwiped = true;
					else if (mclsContactDetails.ContactID == 0) 
					{
						// check using credit card info
						mclsContactDetails = clsContact.DetailsByCreditCardNo(strContactCardNo);
                        if (mclsContactDetails.ContactID == 0 && strContactCardNo.Length == 7) mclsContactDetails = clsContact.DetailsByCreditCardNo("888880" + strContactCardNo);
                        if (mclsContactDetails.ContactID == 0 && strContactCardNo.Length == 7) mclsContactDetails = clsContact.DetailsByCreditCardNo("800000" + strContactCardNo);
                        if (mclsContactDetails.ContactID == 0 && strContactCardNo.Length == 9) mclsContactDetails = clsContact.DetailsByCreditCardNo(BarcodeHelper.GroupCreditCard_Country_Code + BarcodeHelper.GroupCreditCard_ManufacturerCode + strContactCardNo);
                        if (mclsContactDetails.ContactID == 0 && strContactCardNo.Length == 9) mclsContactDetails = clsContact.DetailsByCreditCardNo(BarcodeHelper.CustomerCode_Country_Code + BarcodeHelper.CustomerCode_ManufacturerCode + strContactCardNo);
                        if (mclsContactDetails.ContactID == 0 && strContactCardNo.Length == 9) mclsContactDetails = clsContact.DetailsByCreditCardNo(BarcodeHelper.GroupCreditCard_Country_Code + BarcodeHelper.GroupCreditCard_ManufacturerCode_Manual + strContactCardNo);
                        if (mclsContactDetails.ContactID == 0 && strContactCardNo.Length == 9) mclsContactDetails = clsContact.DetailsByCreditCardNo(BarcodeHelper.CreditCard_Country_Code + BarcodeHelper.CreditCard_ManufacturerCode + strContactCardNo);

						if (mclsContactDetails.ContactID != 0)
							mboCreditCardSwiped = true;
						else if (mclsContactDetails.ContactID == 0) 
						{
							strContactCardNo = strContactCardNo.Remove(strContactCardNo.Length - 1);
							// check using reward card info
							mclsContactDetails = clsContact.DetailsByRewardCardNo(strContactCardNo);
							if (mclsContactDetails.ContactID != 0)
								mboRewardCardSwiped = true;
							else if (mclsContactDetails.ContactID == 0)
							{
								// check using credit card info
								mclsContactDetails = clsContact.DetailsByCreditCardNo(strContactCardNo);
								if (mclsContactDetails.ContactID != 0)
									mboCreditCardSwiped = true;
								else if (mclsContactDetails.ContactID == 0)
								{ clsContact.CommitAndDispose(); SelectContact(AceSoft.RetailPlus.Data.ContactGroupCategory.CUSTOMER); return;}
							}
						}

					}
					clsContact.CommitAndDispose();
				}

				// Sep 24, 2011      Lemuel E. Aceron
				// Added order slip wherein all punch items will not change sales and inventory
				// a customer named ORDER SLIP should be defined in contacts
				if (mclsContactDetails.ContactName.Trim().ToUpper() == Constants.C_RETAILPLUS_ORDER_SLIP_CUSTOMER && mboIsInTransaction && enumContactGroupCategory == AceSoft.RetailPlus.Data.ContactGroupCategory.CUSTOMER)
				{
					MessageBox.Show("Sorry you cannot select ORDER SLIP customer when an item is already purchased.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning);
					clsEvent.AddEventLn("Cancelled!"); return;
				}

				switch (enumContactGroupCategory)
				{
					case AceSoft.RetailPlus.Data.ContactGroupCategory.CUSTOMER:

                        // if not from CreditPayment-F3, do not overwrite 
                        if (!isFromCreditPayment)
                        {
                            lblCustomer.Tag = mclsContactDetails.ContactID;
                            lblCustomer.Text = mclsContactDetails.ContactName;
                        }

						if (!mclsTerminalDetails.ShowCustomerSelection) { txtBarCode.Text = string.Empty; txtBarCode.Focus(); }
						clsEvent.AddEventLn("Done! Selected customer: " + lblCustomer.Text);

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

                            if (mboRewardCardSwiped)
                            {
                                mclsSalesTransactionDetails.RewardsCustomerID = mclsContactDetails.ContactID;
                                mclsSalesTransactionDetails.RewardsCustomerName = mclsContactDetails.ContactName;
                                clsSalesTransactions.UpdateRewardsContactUpdate(mclsTerminalDetails.BranchDetails.BranchID, mclsTerminalDetails.TerminalNo, mclsSalesTransactionDetails.TransactionID, mclsContactDetails.ContactID, mclsContactDetails.ContactName);
                            }

							clsSalesTransactions.UpdateContact(mclsSalesTransactionDetails.TransactionID, mclsSalesTransactionDetails.TransactionDate, mclsContactDetails);
                            clsSalesTransactions.CommitAndDispose();
						}
                        if (mboRewardCardSwiped)
                        {
                            mclsSalesTransactionDetails.RewardsCustomerID = mclsContactDetails.ContactID;
                            mclsSalesTransactionDetails.RewardsCustomerName = mclsContactDetails.ContactName;
                            mclsSalesTransactionDetails.RewardCardActive = mclsContactDetails.RewardDetails.RewardActive;
                            mclsSalesTransactionDetails.RewardCardNo = mclsContactDetails.RewardDetails.RewardCardNo;
                            mclsSalesTransactionDetails.RewardPreviousPoints = mclsContactDetails.RewardDetails.RewardPoints;
                            mclsSalesTransactionDetails.RewardCurrentPoints = mclsSalesTransactionDetails.RewardPreviousPoints;

                            // no need to check if the current customer for the transaction is the default customer
                            //if (mclsSalesTransactionDetails.CustomerID == Constants.C_RETAILPLUS_CUSTOMERID)
                            //{
                            mclsSalesTransactionDetails.CustomerID = mclsContactDetails.ContactID;
                            mclsSalesTransactionDetails.CustomerName = mclsContactDetails.ContactName;
                            mclsSalesTransactionDetails.CustomerDetails = mclsContactDetails;
                            //}
                        }
                        else
                        {
                            mclsSalesTransactionDetails.CustomerID = mclsContactDetails.ContactID;
                            mclsSalesTransactionDetails.CustomerName = mclsContactDetails.ContactName;
                            mclsSalesTransactionDetails.CustomerDetails = mclsContactDetails;
                        }

						break;
					case AceSoft.RetailPlus.Data.ContactGroupCategory.AGENT:
                        lblAgent.Tag = pContactDetails.ContactID;
                        lblAgent.Text = pContactDetails.ContactName;
                        lblAgentPositionDepartment.Text = pContactDetails.PositionName;
                        lblAgentPositionDepartment.Tag = pContactDetails.DepartmentName;
						clsEvent.AddEventLn("Done! Selected agent: " + lblAgent.Text);

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

                            clsSalesTransactions.UpdateAgent(mclsSalesTransactionDetails.TransactionID, mclsSalesTransactionDetails.TransactionDate, pContactDetails);
							clsSalesTransactions.CommitAndDispose();
						}
                        mclsSalesTransactionDetails.AgentID = pContactDetails.ContactID;
                        mclsSalesTransactionDetails.AgentName = pContactDetails.ContactName;
						break;
				}
			}
			catch (Exception ex)
			{ 
                InsertErrorLogToFile(ex, "ERROR!!! Loading contact."); 
            }
		}