예제 #1
0
파일: SO.cs 프로젝트: marioricci/erp-luma
		public void GenerateItemsForReorder(Int32 TerminalID, long SOID)
		{
			try
			{
				GetConnection();

				Terminal clsTerminal = new Terminal(base.Connection, base.Transaction);
                TerminalDetails clsTerminalDetails = clsTerminal.Details(TerminalID);

				SODetails clsSODetails = Details(SOID);

				Products clsProduct = new Products(base.Connection, base.Transaction);
				System.Data.DataTable dt = clsProduct.ForReorder(clsSODetails.CustomerID);

				SOItem clsSOItem = new SOItem(base.Connection, base.Transaction);
				ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(base.Connection, base.Transaction);

				foreach (System.Data.DataRow dr in dt.Rows)
				{
					SOItemDetails clsDetails = new SOItemDetails();

					clsDetails.SOID = SOID;
					clsDetails.ProductID = Convert.ToInt64(dr["ProductID"]);
					clsDetails.ProductCode = dr["ProductCode"].ToString();
					clsDetails.BarCode = dr["BarCode"].ToString();
					clsDetails.Description = dr["ProductDesc"].ToString();
					clsDetails.ProductGroup = dr["ProductGroupCode"].ToString();
					clsDetails.ProductSubGroup = dr["ProductSubGroupCode"].ToString();
					clsDetails.ProductUnitID = Convert.ToInt32(dr["UnitID"]);
					clsDetails.ProductUnitCode = dr["UnitName"].ToString();
					clsDetails.Quantity = Convert.ToDecimal(dr["ReorderQty"]);
					clsDetails.UnitCost = Convert.ToDecimal(dr["Price"]);
					clsDetails.Discount = 0;
					clsDetails.DiscountApplied = 0;
					clsDetails.DiscountType = DiscountTypes.Percentage;
					clsDetails.Remarks = "added using auto generation";

					decimal amount = clsDetails.Quantity * clsDetails.UnitCost;

					if (Convert.ToDecimal(dr["VAT"]) > 0)
					{
						clsDetails.VatableAmount = amount;
						clsDetails.EVatableAmount = amount;
						clsDetails.LocalTax = amount;

						clsDetails.VAT = clsDetails.VatableAmount * (clsTerminalDetails.VAT / 100);
						clsDetails.EVAT = clsDetails.EVatableAmount * (clsTerminalDetails.EVAT / 100);
						clsDetails.LocalTax = clsDetails.LocalTax * (clsTerminalDetails.LocalTax / 100);
						clsDetails.IsVatable = true;
					}
					else
					{
						clsDetails.VAT = 0;
						clsDetails.VatableAmount = 0;
						clsDetails.EVAT = 0;
						clsDetails.EVatableAmount = 0;
						clsDetails.LocalTax = 0;
						clsDetails.IsVatable = false;
					}
					clsDetails.Amount = amount + clsDetails.VAT;

					System.Data.DataTable dtmatrix = clsProductVariationsMatrix.ForReorder(clsDetails.ProductID, clsSODetails.CustomerID);
					if (dtmatrix.Rows.Count > 0)
						foreach (System.Data.DataRow drmatrix in dtmatrix.Rows)
						{
							amount = clsDetails.Quantity * clsDetails.UnitCost;

							clsDetails.ProductUnitID = Convert.ToInt32(drmatrix["UnitID"]);
							clsDetails.ProductUnitCode = drmatrix["UnitName"].ToString();
							clsDetails.Quantity = Convert.ToDecimal(drmatrix["ReorderQty"]);
							clsDetails.UnitCost = Convert.ToDecimal(drmatrix["Price"]);

							if (Convert.ToDecimal(drmatrix["VAT"]) > 0)
							{
								clsDetails.VatableAmount = amount;
								clsDetails.EVatableAmount = amount;
								clsDetails.LocalTax = amount;

								clsDetails.VAT = clsDetails.VatableAmount * (clsTerminalDetails.VAT / 100);
								clsDetails.EVAT = clsDetails.EVatableAmount * (clsTerminalDetails.EVAT / 100);
								clsDetails.LocalTax = clsDetails.LocalTax * (clsTerminalDetails.LocalTax / 100);
								clsDetails.IsVatable = true;
							}
							else
							{
								clsDetails.VAT = 0;
								clsDetails.VatableAmount = 0;
								clsDetails.EVAT = 0;
								clsDetails.EVatableAmount = 0;
								clsDetails.LocalTax = 0;
								clsDetails.IsVatable = false;
							}
							clsDetails.Amount = amount + clsDetails.VAT;

							clsDetails.VariationMatrixID = Convert.ToInt64(drmatrix["MatrixID"]);
							clsDetails.MatrixDescription = drmatrix["VariationDesc"].ToString();
							clsSOItem.Insert(clsDetails);
						}
					else
					{
						clsDetails.VariationMatrixID = 0;
						clsDetails.MatrixDescription = string.Empty;
						clsSOItem.Insert(clsDetails);
					}

				}
			}

			catch (Exception ex)
			{
				throw base.ThrowException(ex);
			}
		}