Ejemplo n.º 1
0
        public static List <AdjVoucher> GetAdjByStatus(int status)
        {
            List <AdjVoucher> adjVouchers = new List <AdjVoucher>();

            using (SqlConnection conn = new SqlConnection(Data.db_cfg))
            {
                conn.Open();

                string     q   = @"SELECT * from AdjVoucher WHERE status = '" + status + "'";
                SqlCommand cmd = new SqlCommand(q, conn);

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    AdjVoucher adjVoucher = new AdjVoucher()
                    {
                        AdjId        = (long)reader["adjId"],
                        ItemId       = (long)reader["itemId"],
                        Date         = (DateTime)reader["date"],
                        AuthorisedBy = (long)reader["authorisedBy"],
                        AdjQty       = (int)reader["adjQty"],
                        Reason       = (reader["reason"] == DBNull.Value) ? " " : (string)reader["reason"],
                        status       = (int)reader["status"]
                    };
                    adjVouchers.Add(adjVoucher);
                }
            }

            return(adjVouchers);
        }
Ejemplo n.º 2
0
        public static void UpdateReason(AdjVoucher adjVoucher)
        {
            using (SqlConnection conn = new SqlConnection(Data.db_cfg))
            {
                conn.Open();

                string q = @"UPDATE AdjVoucher SET reason = '" + adjVoucher.Reason +
                           "' WHERE itemId = '" + adjVoucher.ItemId + "' AND adjId = '" + adjVoucher.AdjId + "'";

                SqlCommand cmd = new SqlCommand(q, conn);
                cmd.ExecuteNonQuery();
            }
        }
        public ActionResult AllAdjVouchers(string sessionId)
        {
            long          totalAdjNumber = (long)AdjVoucherService.GetLastId();
            List <string> dates          = new List <string>();
            List <string> authorisedBys  = new List <string>();
            List <string> statuses       = new List <string>();
            List <string> adjIds         = new List <string>();

            for (long i = 1; i <= totalAdjNumber; i++)
            {
                string adjId = i.ToString("000/000/00");
                adjIds.Add(adjId);
                AdjVoucher adj  = AdjVoucherService.GetAdjByAdjId(i)[0];
                string     date = adj.Date.Day.ToString("00") + "/" + adj.Date.Month.ToString("00") + "/" + adj.Date.Year;
                dates.Add(date);
                string authorisedBy = "Nil";
                if (adj.AuthorisedBy != 0)
                {
                    authorisedBy = EmployeeService.GetEmployeeById(adj.AuthorisedBy).EmpName;
                }
                authorisedBys.Add(authorisedBy);
                string status = null;
                switch (adj.status)
                {
                case 0:
                    status = "Pending submit reason by Clerk";
                    break;

                case 1:
                    status = "Authorised";
                    break;

                case 2:
                    status = "Pending authorisation by Supervisor";
                    break;

                case 3:
                    status = "Pending authorisation by Manager";
                    break;
                }
                statuses.Add(status);
            }
            ViewData["sessionId"]     = sessionId;
            ViewData["dates"]         = dates;
            ViewData["authorisedBys"] = authorisedBys;
            ViewData["statuses"]      = statuses;
            ViewData["adjIds"]        = adjIds;


            return(View());
        }
            public Builder ForNewStockAdjustment(string fullName, AdjVoucher adjVoucher)
            {
                Subject = "A new adjustment of stationeries has been made by " + fullName;

                var body = new StringBuilder();

                body.AppendLine(fullName + " has made the following adjustment: ");
                body.AppendLine("Stationery: " + adjVoucher.Stationery.Description);
                body.AppendLine("Quantity: " + adjVoucher.Quantity);
                body.AppendLine();
                body.AppendLine("by " + fullName + "on" + DateTime.Now.ToString("dd-MM-yyyy"));

                Body = body.ToString();
                return(this);
            }
Ejemplo n.º 5
0
        public ActionResult CreateAdjustment([Bind(Include = "Quantity,Reason,ItemNum,Sign")]
                                             AdjustmentVoucherDTO adjVoucherDto)
        {
            if (ModelState.IsValid)
            {
                var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]);
                var self   = _employeeRepo.GetById(empNum);

                if (adjVoucherDto.Sign == false)
                {
                    adjVoucherDto.Quantity = adjVoucherDto.Quantity * -1;
                }

                var stationery = _stationeryRepo.GetById(adjVoucherDto.ItemNum);
                stationery.AvailableQty = stationery.AvailableQty + adjVoucherDto.Quantity;
                stationery.CurrentQty   = stationery.CurrentQty + adjVoucherDto.Quantity;
                _stationeryRepo.Update(stationery);

                var adjustment = new AdjVoucher
                {
                    ItemNum       = adjVoucherDto.ItemNum,
                    Quantity      = adjVoucherDto.Quantity,
                    Reason        = adjVoucherDto.Reason,
                    Status        = Pending,
                    RequestEmpNum = empNum,
                    CreateDate    = DateTime.Today
                };


                adjustment.Stationery = _stockAdjustmentRepo.AddStockAdjustment(adjustment);


                var managerEmail    = _employeeRepo.GetStoreManager().EmailAddress;
                var supervisorEmail = _employeeRepo.GetStoreSupervisor().EmailAddress;
                var email1          = new LUSSISEmail.Builder().From(self.EmailAddress)
                                      .To(managerEmail).ForNewStockAdjustment(self.FullName, adjustment).Build();
                var email2 = new LUSSISEmail.Builder().From(self.EmailAddress)
                             .To(supervisorEmail).ForNewStockAdjustment(self.FullName, adjustment).Build();

                new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email1); }).Start();
                new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email2); }).Start();

                return(RedirectToAction("History"));
            }

            adjVoucherDto.Stationery = _stationeryRepo.GetById(adjVoucherDto.ItemNum);
            return(View(adjVoucherDto));
        }
Ejemplo n.º 6
0
        public async Task <IHttpActionResult> Post([FromBody] AdjustmentDTO adjustment)
        {
            var adjVoucher = new AdjVoucher
            {
                ItemNum       = adjustment.ItemNum,
                CreateDate    = DateTime.Today,
                Quantity      = adjustment.Quantity,
                Reason        = adjustment.Reason,
                Status        = AdjustmentVoucherStatus.Pending,
                RequestEmpNum = adjustment.RequestEmpNum
            };

            await _stockadjustmentRepo.AddAsync(adjVoucher);

            return(Ok(new { Message = "New adjusment sent" }));
        }
Ejemplo n.º 7
0
 public static void UpdateReason(AdjVoucher adjVoucher)
 {
     AdjVoucherDAO.UpdateReason(adjVoucher);
 }
Ejemplo n.º 8
0
        public ActionResult CreateAdjustments(AdjVoucherColView adjVoucherColView)
        {
            var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]);
            var self   = _employeeRepo.GetById(empNum);

            if (ModelState.IsValid)
            {
                if (adjVoucherColView.MyList != null)
                {
                    var vouchers = new List <AdjVoucher>();
                    foreach (var adjVoucherDto in adjVoucherColView.MyList)
                    {
                        if (adjVoucherDto.Sign == false)
                        {
                            adjVoucherDto.Quantity = adjVoucherDto.Quantity * -1;
                        }

                        var stationery = _stationeryRepo.GetById(adjVoucherDto.ItemNum);
                        stationery.AvailableQty = stationery.AvailableQty + adjVoucherDto.Quantity;
                        stationery.CurrentQty   = stationery.CurrentQty + adjVoucherDto.Quantity;
                        _stationeryRepo.Update(stationery);

                        var adjustment = new AdjVoucher
                        {
                            ItemNum       = adjVoucherDto.ItemNum,
                            Quantity      = adjVoucherDto.Quantity,
                            Reason        = adjVoucherDto.Reason,
                            Status        = Pending,
                            RequestEmpNum = empNum,
                            CreateDate    = DateTime.Today
                        };

                        adjustment.Stationery = _stockAdjustmentRepo.AddStockAdjustment(adjustment);
                        vouchers.Add(adjustment);
                    }

                    //Although there is a threshold of $250, both supervisor and manager will be informed of all adjustments regardless of price
                    //If desired, the threshold can be applied by getting price * quantity and setting if (total price > 250)
                    foreach (AdjVoucher av in vouchers)
                    {
                        av.Stationery = _stationeryRepo.GetById(av.ItemNum);
                    }

                    var managerEmail    = _employeeRepo.GetStoreManager().EmailAddress;
                    var supervisorEmail = _employeeRepo.GetStoreSupervisor().EmailAddress;
                    var email1          = new LUSSISEmail.Builder().From(self.EmailAddress)
                                          .To(managerEmail).ForNewStockAdjustments(self.FullName, vouchers).Build();
                    var email2 = new LUSSISEmail.Builder().From(self.EmailAddress)
                                 .To(supervisorEmail).ForNewStockAdjustments(self.FullName, vouchers).Build();

                    new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email1); }).Start();
                    new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email2); }).Start();

                    return(RedirectToAction("History"));
                }

                return(View(adjVoucherColView));
            }

            return(View(adjVoucherColView));
        }