private void ApproveSingleAdj(int AdjID)
        {
            using (AdjustmentVoucherManager avm = new AdjustmentVoucherManager())
            {
                AdjustmentVoucherTransaction tran = avm.GetAdjustmentVoucherTransactionByID(AdjID);
                SA33.Team12.SSIS.DAL.AdjustmentVoucher voucher = new SA33.Team12.SSIS.DAL.AdjustmentVoucher();

                voucher.CreatedBy = tran.CreatedBy;
                voucher.ApprovedByUser = Utilities.Membership.LoggedInuser;
                voucher.DateApproved = DateTime.Now;
                voucher.DateIssued = tran.DateIssued;
                voucher.VoucherNumber = tran.VoucherNumber;
                avm.DeleteAdjustmentVoucherTransaction(tran);
                foreach (StockLogTransaction logTran in tran.StockLogTransactions)
                {
                    StockLog log = new StockLog();
                    log.AdjustmentVoucher = voucher;
                    log.Balance = logTran.Balance;
                    log.Quantity = logTran.Quantity;
                    log.Reason = logTran.Reason;
                    log.StationeryID = logTran.StationeryID;
                    log.Type = logTran.Type;
                    log.Price = logTran.Price;
                    avm.CreateStockLog(log);
                    avm.DeleteStockLogTransaction(logTran);
                }
                avm.CreateAdjustmentVoucher(voucher);
                //          UtilityFunctions.SendEmail(voucher.AdjustmentVoucherID + " - Your adjustment voucher has been approved", "Dear " + voucher.CreatedByUser.FirstName + "<br />" + "Your request has been approved.", voucher.ApprovedByUser);

            }
        }
 public StockLog CreateStockLog(StockLog stockLog)
 {
     try
     {
         return adjustmentVoucherDAO.CreateStockLog(stockLog);
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Creation Failed" + ex.Message);
     }
 }
 public StockLog CreateStockLog(StockLog stockLog)
 {
     try
     {
         context.AddToStockLogs(stockLog);
         return stockLog;
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Creation Error" + ex.Message);
     }
 }
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            using (PurchaseOrderManager pom = new PurchaseOrderManager())
            {
                PurchaseOrder po = pom.FindPurchaseOrderByID(int.Parse(Request.QueryString["ID"]));
                po.DONumber = txtDONumber.Text.ToString();
                po.IsDelivered = true;
                po.DateReceived = Convert.ToDateTime(txtReceivedDate.Text.ToString());
                po.ReceivedBy = Membership.GetCurrentLoggedInUser().UserID;
                pom.UpdatePurchaseOrder(po);

                using (AdjustmentVoucherManager avm = new AdjustmentVoucherManager())
                {
                    SA33.Team12.SSIS.DAL.AdjustmentVoucher av = new SA33.Team12.SSIS.DAL.AdjustmentVoucher();
                    av.VoucherNumber = avm.GenerateVoucherNumber();
                    av.CreatedBy = Membership.GetCurrentLoggedInUser().UserID;
                    av.DateIssued = po.DateOfOrder;
                    av.DateApproved = DateTime.Now;
                    av.ApprovedBy = Membership.GetCurrentLoggedInUser().UserID;

                    foreach (PurchaseOrderItem item in po.PurchaseOrderItems)
                    {
                        // generate stocklog for each poItem
                        StockLog log = new StockLog();
                        log.AdjustmentVoucher = av;
                        log.Balance = item.Stationery.QuantityInHand;
                        log.Quantity = item.QuantityToOrder;
                        log.Reason = "Supplier - " + po.Supplier.CompanyName;
                        log.StationeryID = item.StationeryID;
                        log.Type = 3;           // "replenishment" accroding to enu in DAL.AdjustmentVoucherDAO
                        log.Price = item.Price;
                        log.DateCreated = DateTime.Now;
                        av.StockLogs.Add(log);

                        // update replensih stationery stock
                         using (CatalogManager cm = new CatalogManager())
                        {
                            item.Stationery.QuantityInHand = item.Stationery.QuantityInHand + item.QuantityToOrder;
                            cm.UpdateStationery(item.Stationery);
                        }
                    }
                    avm.CreateAdjustmentVoucher(av);
                }
            }

            Response.Redirect("ViewPurchaseOrder.aspx");
        }
 public StockLog UpdateStockLog(StockLog stockLog)
 {
     try
     {
         var temp = (from ri in context.StockLogs
                     where ri.StockLogID == stockLog.StockLogID
                     select ri).FirstOrDefault<StockLog>();
         temp.Type = stockLog.Type;
         temp.Reason = stockLog.Reason;
         temp.Quantity = stockLog.Quantity;
         temp.Balance = stockLog.Balance;
         context.SaveChanges();
         return stockLog;
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Transaction Update Error" + ex.Message);
     }
 }
        public void DeleteStockLog(StockLog stockLog)
        {
            try
            {
                var temp = (from ri in context.StockLogs
                            where ri.StockLogID == stockLog.StockLogID
                            select ri).FirstOrDefault<StockLog>();

                context.StockLogs.DeleteObject(temp);
            }
            catch (Exception ex)
            {
                throw new Exception("Stock Log Delete Error" + ex.Message);
            }
        }
 public void DeleteStockLog(StockLog stockLog)
 {
     try
     {
         adjustmentVoucherDAO.DeleteStockLog(stockLog);
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Delete Failed" + ex.Message);
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the StockLogs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStockLogs(StockLog stockLog)
 {
     base.AddObject("StockLogs", stockLog);
 }
 /// <summary>
 /// Create a new StockLog object.
 /// </summary>
 /// <param name="stockLogID">Initial value of the StockLogID property.</param>
 /// <param name="adjustmentVoucherID">Initial value of the AdjustmentVoucherID property.</param>
 /// <param name="type">Initial value of the Type property.</param>
 /// <param name="reason">Initial value of the Reason property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="balance">Initial value of the Balance property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 public static StockLog CreateStockLog(global::System.Int32 stockLogID, global::System.Int32 adjustmentVoucherID, global::System.Int32 type, global::System.String reason, global::System.Int32 quantity, global::System.Int32 balance, global::System.Decimal price, global::System.DateTime dateCreated)
 {
     StockLog stockLog = new StockLog();
     stockLog.StockLogID = stockLogID;
     stockLog.AdjustmentVoucherID = adjustmentVoucherID;
     stockLog.Type = type;
     stockLog.Reason = reason;
     stockLog.Quantity = quantity;
     stockLog.Balance = balance;
     stockLog.Price = price;
     stockLog.DateCreated = dateCreated;
     return stockLog;
 }