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.ApprovedBy = Membership.GetCurrentLoggedInUser().UserID;
                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;
                    log.DateCreated = DateTime.Now;
                    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);

            }
            Populate();
        }
 public void CreateAdjustmentVoucher(AdjustmentVoucher adjustmentVoucher)
 {
     try
     {
         adjustmentVoucherDAO.CreateAdjustmentVoucher(adjustmentVoucher);
     }
     catch (Exception ex)
     {
         throw new Exception("Adjustment Voucher Creation Failed" + 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 void CreateAdjustmentVoucher(AdjustmentVoucher AdjustmentVoucher)
 {
     try
     {
         //Create a transaction scope
         using (TransactionScope ts = new TransactionScope())
         {
             this.context.AdjustmentVouchers.AddObject(AdjustmentVoucher);
             this.context.SaveChanges();
             ts.Complete();
         }
     }
     catch (Exception ex)
     {
         //Exception thrown incase if insert fails
         throw new AdjustmentVoucherException("Create Adjustment Voucher Transaction failed." + ex.Message);
     }
 }
        public void UpdateAdjustmentVoucher(AdjustmentVoucher updateAdjustmentVoucher)
        {
            try
            {
                var tempReq = (from r in context.AdjustmentVouchers
                               where r.AdjustmentVoucherID == updateAdjustmentVoucher.AdjustmentVoucherID
                               select r).FirstOrDefault<AdjustmentVoucher>();

                tempReq = updateAdjustmentVoucher;
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new AdjustmentVoucherException("Update Adjustment Voucher failed." + ex.Message);

            }
        }
 public decimal GetTotalCostVoucher(AdjustmentVoucher adjustmentVoucher)
 {
     decimal totalCost = 0;
     foreach (StockLog log in adjustmentVoucher.StockLogs)
     {
         totalCost += log.Quantity * log.Price;
     }
     return totalCost;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the AdjustmentVouchers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAdjustmentVouchers(AdjustmentVoucher adjustmentVoucher)
 {
     base.AddObject("AdjustmentVouchers", adjustmentVoucher);
 }
 /// <summary>
 /// Create a new AdjustmentVoucher object.
 /// </summary>
 /// <param name="adjustmentVoucherID">Initial value of the AdjustmentVoucherID property.</param>
 /// <param name="voucherNumber">Initial value of the VoucherNumber property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="dateIssued">Initial value of the DateIssued property.</param>
 public static AdjustmentVoucher CreateAdjustmentVoucher(global::System.Int32 adjustmentVoucherID, global::System.String voucherNumber, global::System.Int32 createdBy, global::System.DateTime dateIssued)
 {
     AdjustmentVoucher adjustmentVoucher = new AdjustmentVoucher();
     adjustmentVoucher.AdjustmentVoucherID = adjustmentVoucherID;
     adjustmentVoucher.VoucherNumber = voucherNumber;
     adjustmentVoucher.CreatedBy = createdBy;
     adjustmentVoucher.DateIssued = dateIssued;
     return adjustmentVoucher;
 }