public bool SubmitNewAdjustmentVoucher(List <AdjustmentVoucherViewModel> vmList, string remarks, string requesterID)
        {
            Adjustment_Voucher_Record vourcherRecord = new Adjustment_Voucher_Record();

            vourcherRecord.issueDate       = DateTime.Today;
            vourcherRecord.handlingStaffID = requesterID;
            vourcherRecord.status          = AdjustmentVoucherStatus.PENDING;
            vourcherRecord.remarks         = remarks;

            List <Voucher_Detail> details = new List <Voucher_Detail>();

            foreach (var vm in vmList)
            {
                if (vm.Quantity != 0) // ignore quantity which is equal to 0
                {
                    Voucher_Detail detail = new Voucher_Detail();
                    detail.itemCode    = vm.ItemCode;
                    detail.adjustedQty = vm.Quantity;
                    detail.remarks     = vm.Reason;
                    details.Add(detail);
                }
            }

            vourcherRecord.Voucher_Details = details;
            decimal voucherAmount = GetVoucherRecordTotalAmount(vourcherRecord);

            adjustmentVoucherDAO.AddNewAdjustmentVoucher(vourcherRecord);
            EmailNotification.EmailNotificationForNewAdjustmentVoucher(requesterID, voucherAmount);
            return(true);
        }
Ejemplo n.º 2
0
        public int UpdateAdjustmentVoucherInfo(Adjustment_Voucher_Record voucher)
        {
            using (StationeryModel context = new StationeryModel())
            {
                try
                {
                    Adjustment_Voucher_Record record = (from r in context.Adjustment_Voucher_Records
                                                        where r.voucherID == voucher.voucherID
                                                        select r).First();

                    record.approvalDate       = voucher.approvalDate;
                    record.authorisingStaffID = voucher.authorisingStaffID;
                    record.handlingStaffID    = voucher.handlingStaffID;
                    record.issueDate          = voucher.issueDate;
                    record.remarks            = voucher.remarks;
                    record.status             = voucher.status;

                    return(context.SaveChanges());
                }
                catch (Exception e)
                {
                    string errorMessage = String.Format("Error occurs when updating adjustment voucher. ({0})", e.Message);
                    throw new Exception(errorMessage);
                }
            }
        }
Ejemplo n.º 3
0
 public bool AddNewAdjustmentVoucher(Adjustment_Voucher_Record voucher)
 {
     using (StationeryModel context = new StationeryModel())
     {
         context.Adjustment_Voucher_Records.Add(voucher);
         context.SaveChanges();
         return(true);
     }
 }
        public bool RejectVoucherRecord(int voucherNo, string approverID, string remark)
        {
            Adjustment_Voucher_Record record = FindVoucherRecordByVoucherNo(voucherNo);

            record.authorisingStaffID = approverID;
            record.status             = AdjustmentVoucherStatus.REJECTED;
            record.approvalDate       = DateTime.Today;

            adjustmentVoucherDAO.UpdateAdjustmentVoucherInfo(record);

            EmailNotification.EmailNotificatioForAdjustmentVoucherApprovalStatus(voucherNo, AdjustmentVoucherStatus.REJECTED, remark);
            return(true);
        }
        public decimal GetVoucherRecordTotalAmount(Adjustment_Voucher_Record record)
        {
            decimal totalAmount = 0.00M;

            foreach (var detail in record.Voucher_Details)
            {
                if (detail.adjustedQty < 0)
                {
                    Stationery stationery = stationeryService.FindStationeryByItemCode(detail.itemCode);
                    totalAmount += detail.adjustedQty * stationery.price;
                }
            }

            return(totalAmount);
        }
        public bool ValidateAdjustmentVoucherBeforeApprove(int voucherNo, out string errorMessage)
        {
            errorMessage = null;

            Adjustment_Voucher_Record record = FindVoucherRecordByVoucherNo(voucherNo);

            foreach (var item in record.Voucher_Details)
            {
                Stationery s = stationeryService.FindStationeryByItemCode(item.itemCode);
                if ((s.stockQty + item.adjustedQty) < 0)
                {
                    errorMessage = String.Format("Cannot process voucher due to negative adjustment quantity of {0} is greater than current stock.", item.itemCode);
                    return(false);
                }
            }
            return(true);
        }
        private AdjustmentVoucherViewModel ConvertRecordToViewModel(Adjustment_Voucher_Record record)
        {
            AdjustmentVoucherViewModel vm = new AdjustmentVoucherViewModel();

            vm.VoucherNo          = record.voucherID;
            vm.Requester          = userService.FindNameByID(record.handlingStaffID);
            vm.IssueDate          = record.issueDate;
            vm.VoucherTotalAmount = 0.00M; // only Pending need this info
            vm.ApprovalDate       = record.approvalDate;
            if (!String.IsNullOrEmpty(record.authorisingStaffID))
            {
                vm.Approver = userService.FindNameByID(record.authorisingStaffID);
            }
            vm.Causes = record.remarks;
            vm.Status = record.status;

            return(vm);
        }
        public decimal GetVoucherRecordTotalAmount(int voucherNo)
        {
            // to retrieve voucher_details associated with this voucherNo
            Adjustment_Voucher_Record record = FindVoucherRecordByVoucherNo(voucherNo);

            decimal totalAmount = 0.00M;

            foreach (var detail in record.Voucher_Details)
            {
                if (detail.adjustedQty < 0)
                {
                    Stationery stationery = stationeryService.FindStationeryByItemCode(detail.itemCode);
                    totalAmount += detail.adjustedQty * stationery.price;
                }
            }

            return(totalAmount);
        }
        /// <summary>
        /// Return voucher details if user is authorized to view the record
        /// </summary>
        /// <param name="voucherNo"></param>
        /// <param name="userID"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public List <AdjustmentVoucherViewModel> IsUserAuthorizedToViewVoucherDetail(int voucherNo, string userID, out string errorMessage)
        {
            errorMessage = null;
            List <AdjustmentVoucherViewModel> vmList = new List <AdjustmentVoucherViewModel>();

            Adjustment_Voucher_Record record = FindVoucherRecordByVoucherNo(voucherNo);

            if (record == null)
            {
                errorMessage = String.Format("Non-existing voucher.");
                return(null);
            }


            decimal voucherTotalAmount = GetVoucherRecordTotalAmount(record);

            if (record.status == AdjustmentVoucherStatus.PENDING)
            {
                // check for current user
                bool isManager    = userService.IsStoreManager(userID);
                bool isSupervisor = userService.IsStoreSupervisor(userID);

                if (isSupervisor && !(voucherTotalAmount * -1 <= 250))
                {
                    errorMessage = String.Format("You have not right to approve this voucher.");
                    return(null);
                }
            }

            foreach (var detail in record.Voucher_Details)
            {
                AdjustmentVoucherViewModel vm = ConvertDetailToViewModel(detail);
                vm.VoucherTotalAmount = voucherTotalAmount;
                vmList.Add(vm);
            }

            return(vmList);
        }
        public bool ApproveVoucherRecord(int voucherNo, string approverID, string remark)
        {
            bool result = false;

            // Update Adjustment_Voucher_Record
            Adjustment_Voucher_Record voucherRecord = FindVoucherRecordByVoucherNo(voucherNo);

            voucherRecord.authorisingStaffID = approverID;
            voucherRecord.status             = AdjustmentVoucherStatus.APPROVED;
            voucherRecord.approvalDate       = DateTime.Today;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    adjustmentVoucherDAO.UpdateAdjustmentVoucherInfo(voucherRecord);

                    // Update Stationery Quantity
                    foreach (Voucher_Detail detail in voucherRecord.Voucher_Details)
                    {
                        // throw Exception if stationery quantity become zero
                        stationeryService.UpdateStationeryQuantity(detail.itemCode, detail.adjustedQty);
                    }

                    // Insert Record into Transaction table
                    Transaction_Record transRecord = new Transaction_Record();
                    transRecord.clerkID = voucherRecord.handlingStaffID;
                    transRecord.date    = voucherRecord.approvalDate;
                    transRecord.type    = TransactionTypes.STOCK_ADJUSTMENT;

                    transRecord.Transaction_Details = new List <Transaction_Detail>();
                    foreach (Voucher_Detail voucherDetail in voucherRecord.Voucher_Details)
                    {
                        Transaction_Detail transDetail = new Transaction_Detail();
                        transDetail.itemCode    = voucherDetail.itemCode;
                        transDetail.adjustedQty = voucherDetail.adjustedQty;
                        transDetail.balanceQty  = stationeryService.FindStationeryByItemCode(voucherDetail.itemCode).stockQty; // stock after adjustment
                        transDetail.remarks     = String.Format("Voucher no.: {0} ({1})", voucherRecord.voucherID, voucherRecord.remarks);

                        transRecord.Transaction_Details.Add(transDetail);
                    }
                    // throw Exception if error occur when writing to database
                    transactionService.AddNewTransactionRecord(transRecord);

                    ts.Complete();
                    result = true;
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }

            if (result)
            {
                // send email notification
                EmailNotification.EmailNotificatioForAdjustmentVoucherApprovalStatus(voucherNo, AdjustmentVoucherStatus.APPROVED, remark);
            }

            return(result);
        }
Ejemplo n.º 11
0
        public void UpdateDisbursement(string itemCode, int actualQty, string deptCode, int needQty, int count, string staffID)
        {
            int actualTmp = actualQty;

            using (StationeryModel model = new StationeryModel())
            {
                Stationery s = model.Stationeries.Where(x => x.itemCode == itemCode).First();
                s.stockQty = s.stockQty - actualQty;
                model.SaveChanges();
            }
            List <Requisition_Record> list = new List <Requisition_Record>();

            list = GetRecordByItemCode(itemCode).Where(x => x.Department.departmentCode == deptCode && (x.status == RequisitionStatus.APPROVED_PROCESSING || x.status == RequisitionStatus.PARTIALLY_FULFILLED)).ToList();

            list.Sort();
            for (int i = 0; i < list.Count(); i++)
            {
                var b = list[i].Requisition_Detail.Where(x => x.itemCode == itemCode).First();
                if (b.allocatedQty > 0)
                {
                    if (actualQty - b.allocatedQty >= 0)
                    {
                        actualQty = actualQty - (int)b.allocatedQty;
                        UpdateDetails(itemCode, list[i].requisitionNo, 0, b.allocatedQty + b.fulfilledQty);
                    }
                    else
                    {
                        UpdateDetails(itemCode, list[i].requisitionNo, 0, actualQty + b.fulfilledQty);
                        actualQty = 0;
                    }
                }
            }

            for (int i = 0; i < list.Count(); i++)
            {
                int             status = 1;//Collected
                int             sum    = 0;
                StationeryModel entity = new StationeryModel();

                var NO          = list[i].requisitionNo;
                var detailslist = entity.Requisition_Detail.Where(x => x.requisitionNo == NO).ToList();
                foreach (var l in detailslist)
                {
                    sum = sum + (int)l.fulfilledQty;
                    if (l.fulfilledQty == l.qty)
                    {
                    }
                    else
                    {
                        status = 2;//partially fulfilled
                    }
                }
                if (status == 2)
                {
                    if (sum == 0)
                    {
                        status = 3;
                    }
                }
                updatestatus(list[i].requisitionNo, status);
            }

            if (count == 0)
            {
                if (needQty - actualTmp > 0)
                {
                    using (StationeryModel model = new StationeryModel())
                    {
                        Adjustment_Voucher_Record adjustment = new Adjustment_Voucher_Record();
                        adjustment.issueDate       = DateTime.Now;
                        adjustment.status          = AdjustmentVoucherStatus.PENDING;
                        adjustment.remarks         = "NA";
                        adjustment.handlingStaffID = staffID;
                        model.Adjustment_Voucher_Records.Add(adjustment);
                        model.SaveChanges();
                    }
                }
                using (StationeryModel model = new StationeryModel())
                {
                    Transaction_Record tr = new Transaction_Record();
                    tr.clerkID = staffID;
                    tr.date    = DateTime.Now;
                    tr.type    = TransactionTypes.DISBURSEMENT;
                    model.Transaction_Records.Add(tr);
                    model.SaveChanges();
                }
            }

            using (StationeryModel model = new StationeryModel())
            {
                int max = 0;
                if (needQty - actualTmp > 0)
                {
                    max = 0;
                    foreach (var item in model.Adjustment_Voucher_Records.ToList())
                    {
                        if (item.voucherID > max)
                        {
                            max = item.voucherID;
                        }
                    }
                    Voucher_Detail voucher = new Voucher_Detail();
                    voucher.voucherID   = max;
                    voucher.itemCode    = itemCode;
                    voucher.adjustedQty = actualTmp - needQty;
                    voucher.remarks     = "";
                    model.Voucher_Details.Add(voucher);
                    model.SaveChanges();
                }
                max = 0;
                foreach (var item in model.Transaction_Records.ToList())
                {
                    if (item.transactionNo > max)
                    {
                        max = item.transactionNo;
                    }
                }
                Transaction_Detail detail = new Transaction_Detail();
                detail.transactionNo = max;
                detail.itemCode      = itemCode;
                detail.adjustedQty   = -actualTmp;
                detail.balanceQty    = model.Stationeries.Where(x => x.itemCode == itemCode).First().stockQty;
                detail.remarks       = "";
                model.Transaction_Details.Add(detail);
                model.SaveChanges();
            }
        }