コード例 #1
0
ファイル: MainWnd.cs プロジェクト: marioricci/erp-luma
		private void ApplyTransDiscount()
		{
			if (ItemDataTable.Rows.Count <= 0) return;

			if (mclsTerminalDetails.AutoPrint == PrintingPreference.Auto && mboIsInTransaction)
			{
				MessageBox.Show("Sorry you cannot apply a transaction discount if Auto-print is ON an item is already purchased.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				return;
			}
			DialogResult loginresult = GetWriteAccessAndLogin(mclsSalesTransactionDetails.CashierID, AccessTypes.ApplyTransDiscount);

			if (loginresult == DialogResult.OK)
			{
				//mboIsDiscountAuthorized = true;
				try
				{
					clsEvent.AddEvent("[" + lblCashier.Text + "] Applying transaction discount for trans. no. " + lblTransNo.Text);

				Back:
					DiscountTypes TransDiscountType = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), lblTransDiscount.Tag.ToString());
					DiscountWnd discount = new DiscountWnd();
					discount.Header = "Apply Transaction Discount"; 
					discount.BalanceAmount = mclsSalesTransactionDetails.SubTotal;
					discount.DiscountType = TransDiscountType;
					discount.DiscountAmount = mclsSalesTransactionDetails.TransDiscount;
					discount.DiscountCode = mclsSalesTransactionDetails.DiscountCode;
					discount.Remarks = mclsSalesTransactionDetails.DiscountRemarks;
					discount.IsDiscountEditable = mclsTerminalDetails.IsDiscountEditable;
                    discount.TerminalDetails = mclsTerminalDetails;
                    //discount.DisableVATExempt = false;
					discount.ShowDialog(this);
					DialogResult result = discount.Result;
					decimal DiscountAmount = discount.DiscountAmount;
					string TransDiscountCode = discount.DiscountCode;
					string TransDiscountRemarks = discount.Remarks;
					TransDiscountType = discount.DiscountType;
					discount.Close();
					discount.Dispose();

					if (result == DialogResult.OK)
					{
                        if (mclsSalesTransactionDetails.ItemsDiscount > 0)
                        {
                            MessageBox.Show("Sorry you cannot use the Senior Citizen, another discount is already applied to an item. Please separate the transaction for items with senior citizen discount.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                            return;
                        }

						int iCurrentSelectedRow = dgItems.CurrentRowIndex;

						Cursor.Current = Cursors.WaitCursor;
						if (!mboIsInTransaction) //false ito
						{
							this.LoadOptions();
							if (!this.CreateTransaction()) return;
						}

						decimal OldDiscount = mclsSalesTransactionDetails.TransDiscount;
						string OldTransDiscountType = lblTransDiscount.Tag.ToString();

						if (TransDiscountType == DiscountTypes.NotApplicable)
						{
							lblTransDiscount.Text = "Less 0% / 0.00";
						}
						lblTransDiscount.Tag = TransDiscountType.ToString("d");
						mclsSalesTransactionDetails.TransDiscountType = TransDiscountType;
						mclsSalesTransactionDetails.TransDiscount = DiscountAmount;
						mclsSalesTransactionDetails.DiscountCode = TransDiscountCode;
						mclsSalesTransactionDetails.DiscountRemarks = TransDiscountRemarks;

						ComputeSubTotal(); setTotalDetails();

						if (mclsSalesTransactionDetails.Discount <= mclsSalesTransactionDetails.DiscountableAmount)
						{
							Data.SalesTransactions clsSalesTransactions = new Data.SalesTransactions(mConnection, mTransaction);
                            mConnection = clsSalesTransactions.Connection; mTransaction = clsSalesTransactions.Transaction;

                            clsSalesTransactions.UpdateSubTotal(mclsSalesTransactionDetails.TransactionID, mclsSalesTransactionDetails.ItemSold, mclsSalesTransactionDetails.QuantitySold, mclsSalesTransactionDetails.GrossSales, mclsSalesTransactionDetails.SubTotal, mclsSalesTransactionDetails.NetSales, mclsSalesTransactionDetails.ItemsDiscount, mclsSalesTransactionDetails.SNRItemsDiscount, mclsSalesTransactionDetails.PWDItemsDiscount, mclsSalesTransactionDetails.OtherItemsDiscount, mclsSalesTransactionDetails.Discount, mclsSalesTransactionDetails.SNRDiscount, mclsSalesTransactionDetails.PWDDiscount, mclsSalesTransactionDetails.OtherDiscount, mclsSalesTransactionDetails.TransDiscount, mclsSalesTransactionDetails.TransDiscountType, mclsSalesTransactionDetails.VAT, mclsSalesTransactionDetails.VATableAmount, mclsSalesTransactionDetails.ZeroRatedSales, mclsSalesTransactionDetails.NonVATableAmount, mclsSalesTransactionDetails.VATExempt, mclsSalesTransactionDetails.EVAT, mclsSalesTransactionDetails.EVATableAmount, mclsSalesTransactionDetails.NonEVATableAmount, mclsSalesTransactionDetails.LocalTax, mclsSalesTransactionDetails.DiscountCode, mclsSalesTransactionDetails.DiscountRemarks, mclsSalesTransactionDetails.Charge, mclsSalesTransactionDetails.ChargeAmount, mclsSalesTransactionDetails.ChargeCode, mclsSalesTransactionDetails.ChargeRemarks, mclsSalesTransactionDetails.ChargeType);
                            clsSalesTransactions.CommitAndDispose();

                            InsertAuditLog(AccessTypes.Discounts, "Apply transaction discount for " + mclsSalesTransactionDetails.Discount.ToString("#,###.#0") + ". Tran. #".PadRight(15) + ":" + lblTransNo.Text + " @ Branch: " + mclsTerminalDetails.BranchDetails.BranchCode);
						}
						else
						{
							MessageBox.Show("Sorry the input discount will yield a less than ZERO amount. Please type another discount.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
							mclsSalesTransactionDetails.TransDiscount = OldDiscount;
							lblTransDiscount.Tag = OldTransDiscountType;

							ComputeSubTotal(); setTotalDetails();
							goto Back;
						}
						dgItems.Select(iCurrentSelectedRow);
						clsEvent.AddEventLn("Done! " + mclsSalesTransactionDetails.DiscountCode + " amount=" + mclsSalesTransactionDetails.Discount.ToString("#,###.#0"), true);
					}
					else { clsEvent.AddEventLn("Cancelled!"); }
				}
				catch (Exception ex)
				{ 
                    InsertErrorLogToFile(ex, "ERROR!!! Applying transaction discount."); 
                }
				Cursor.Current = Cursors.Default;
			}
		}
コード例 #2
0
ファイル: MainWnd.cs プロジェクト: marioricci/erp-luma
		private void ApplyItemDiscountForAllItem()
		{
			if (ItemDataTable.Rows.Count <= 0) return;

			if (mclsTerminalDetails.AutoPrint == PrintingPreference.Auto)
			{
				MessageBox.Show("Sorry you cannot apply a discount to an item if Auto-print is ON.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				return;
			}
			DialogResult loginresult = GetWriteAccessAndLogin(mclsSalesTransactionDetails.CashierID, AccessTypes.ApplyItemDiscount);

			if (loginresult == DialogResult.OK)
			{
				//mboIsDiscountAuthorized = true;

				DiscountTypes TransDiscountType = DiscountTypes.NotApplicable;
				DiscountWnd discount = new DiscountWnd();
				discount.Header = "Apply Discounts on punched items"; 
				discount.BalanceAmount = mclsSalesTransactionDetails.SubTotal;
				discount.DiscountType = DiscountTypes.Percentage;
				discount.DiscountAmount = mclsSalesTransactionDetails.TransDiscount;
				discount.DiscountCode = mclsSalesTransactionDetails.DiscountCode;
				discount.Remarks = mclsSalesTransactionDetails.DiscountRemarks;
				discount.IsDiscountEditable = mclsTerminalDetails.IsDiscountEditable;
                //discount.DisableVATExempt = true;
				discount.ShowDialog(this);
				DialogResult result = discount.Result;
				decimal DiscountAmount = discount.DiscountAmount;
				string TransDiscountCode = discount.DiscountCode;
				string TransDiscountRemarks = discount.Remarks;
				TransDiscountType = discount.DiscountType;
				discount.Close();
				discount.Dispose();

				if (result == DialogResult.OK)
				{
                    if (TransDiscountCode == mclsTerminalDetails.SeniorCitizenDiscountCode)
                    {
                        MessageBox.Show("Sorry you cannot use the Senior Citizen as item discount, Senior Citizen is applied thru transactions.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                        return;
                    }
                    else if (mclsSalesTransactionDetails.DiscountCode == mclsTerminalDetails.SeniorCitizenDiscountCode)
                    {
                        MessageBox.Show("Sorry Senior Citizen Discount is already applied in the transaction. Please separate the transaction for items without senior citizen discount.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                        return;
                    }

					Cursor.Current = Cursors.WaitCursor;

					int iCurrentSelectedRow = dgItems.CurrentRowIndex;

					for(int iRowCtr=0;iRowCtr<ItemDataTable.Rows.Count;iRowCtr++)
					{
						dgItems.Select(iRowCtr);
						dgItems.CurrentRowIndex = iRowCtr;
						if (dgItems[iRowCtr, 8].ToString() != "VOID")
						{
                            if (dgItems[iRowCtr, 8].ToString().IndexOf("RETURN") == -1 
                                && dgItems[iRowCtr, 8].ToString().IndexOf("DEMO") == -1)
							{
								try
								{
									Data.SalesTransactionItemDetails clsItemDetails;
									clsItemDetails = getCurrentRowItemDetails();
									clsEvent.AddEvent("[" + lblCashier.Text + "] Applying item discount for item. no. [" + clsItemDetails.TransactionItemsID + "]" + clsItemDetails.ProductCode);

									clsItemDetails.ItemDiscount = DiscountAmount;
									clsItemDetails.Discount = DiscountAmount;
									clsItemDetails.ItemDiscountType = TransDiscountType;
									clsItemDetails.DiscountCode = TransDiscountCode;
									clsItemDetails.DiscountRemarks = TransDiscountRemarks;

                                    clsItemDetails = ComputeItemTotal(clsItemDetails); // set the grossales, vat, discounts, etc.
                                    //if (clsItemDetails.Discount >= clsItemDetails.Amount)
									//{
									//    MessageBox.Show("Sorry the input discount will yield a less than ZERO amount. Please type another discount.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
									//    goto Back;
									//}

									clsEvent.AddEventLn("discount=" + clsItemDetails.Discount.ToString("#,###.#0"));

									System.Data.DataRow dr = (System.Data.DataRow)ItemDataTable.Rows[iRowCtr];

									dr = setCurrentRowItemDetails(dr, clsItemDetails);

									ComputeSubTotal(); setTotalDetails();

									if (mclsSalesTransactionDetails.DiscountableAmount == 0)
									{
										mclsSalesTransactionDetails.TransDiscountType = DiscountTypes.NotApplicable;
										mclsSalesTransactionDetails.TransDiscount = 0;
										ComputeSubTotal(); setTotalDetails();
									}

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

									/*******Added: April 12, 2010***********************
									* update purchase amount everytime there a change in 
									*  
									*  discount *********************************/
									clsItemDetails.PurchaseAmount = clsItemDetails.Quantity * clsItemDetails.PurchasePrice;
									dr["PurchaseAmount"] = clsItemDetails.PurchaseAmount;

                                    clsSalesTransactions.UpdateItem(mclsSalesTransactionDetails.TransactionID, mclsSalesTransactionDetails.ItemSold, mclsSalesTransactionDetails.QuantitySold, mclsSalesTransactionDetails.GrossSales, mclsSalesTransactionDetails.SubTotal, mclsSalesTransactionDetails.NetSales, mclsSalesTransactionDetails.ItemsDiscount, mclsSalesTransactionDetails.SNRItemsDiscount, mclsSalesTransactionDetails.PWDItemsDiscount, mclsSalesTransactionDetails.OtherItemsDiscount, mclsSalesTransactionDetails.Discount, mclsSalesTransactionDetails.SNRDiscount, mclsSalesTransactionDetails.PWDDiscount, mclsSalesTransactionDetails.OtherDiscount, mclsSalesTransactionDetails.TransDiscount, mclsSalesTransactionDetails.TransDiscountType, mclsSalesTransactionDetails.VAT, mclsSalesTransactionDetails.VATableAmount, mclsSalesTransactionDetails.ZeroRatedSales, mclsSalesTransactionDetails.NonVATableAmount, mclsSalesTransactionDetails.VATExempt, mclsSalesTransactionDetails.EVAT, mclsSalesTransactionDetails.EVATableAmount, mclsSalesTransactionDetails.NonEVATableAmount, mclsSalesTransactionDetails.LocalTax, mclsSalesTransactionDetails.DiscountCode, mclsSalesTransactionDetails.DiscountRemarks, mclsSalesTransactionDetails.Charge, mclsSalesTransactionDetails.ChargeAmount, mclsSalesTransactionDetails.ChargeCode, mclsSalesTransactionDetails.ChargeRemarks, mclsSalesTransactionDetails.ChargeType, clsItemDetails);
                                    clsSalesTransactions.CommitAndDispose();

                                    // 10Jul2015 : Update the item list
                                    mclsSalesTransactionDetails.TransactionItemsList[mclsSalesTransactionDetails.TransactionItemsList.FindIndex(x => x.ItemNo == clsItemDetails.ItemNo)] = clsItemDetails;

									InsertAuditLog(AccessTypes.Discounts, "Apply item discount for " + clsItemDetails.ProductCode + ". discount=" + clsItemDetails.Discount.ToString("#,###.#0") + " @ Branch: " + mclsTerminalDetails.BranchDetails.BranchCode);

									clsEvent.AddEventLn("Done applying item discount...", true);

									DisplayItemToTurretDelegate DisplayItemToTurretDel = new DisplayItemToTurretDelegate(DisplayItemToTurret);
									DisplayItemToTurretDel.BeginInvoke(clsItemDetails.Description, clsItemDetails.ProductUnitCode, clsItemDetails.Quantity, clsItemDetails.Price, clsItemDetails.Discount, clsItemDetails.PromoApplied, clsItemDetails.Amount, clsItemDetails.VAT, clsItemDetails.EVAT, null, null);
								}
								catch (Exception ex)
								{ 
                                    InsertErrorLogToFile(ex, "ERROR!!! Applying discount for all item."); 
                                }
								Cursor.Current = Cursors.Default;
							}
						}

						dgItems.UnSelect(iRowCtr);
					}
					dgItems.Select(iCurrentSelectedRow);
					dgItems.CurrentRowIndex = iCurrentSelectedRow;
				}
				else { clsEvent.AddEventLn("Cancelled!"); }
			}
		}