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); }
private AdjustmentVoucherViewModel ConvertDetailToViewModel(Voucher_Detail detail) { Stationery stationery = stationeryService.FindStationeryByItemCode(detail.itemCode); AdjustmentVoucherViewModel vm = new AdjustmentVoucherViewModel(); // Stationery information vm.ItemCode = detail.itemCode; vm.StationeryDescription = stationery.description; vm.UOM = stationery.unitOfMeasure; vm.Price = stationery.price; // Voucher Record information vm.VoucherNo = detail.voucherID; vm.Requester = userService.FindNameByID(detail.Adjustment_Voucher_Record.handlingStaffID); vm.VoucherTotalAmount = 0.00M; vm.IssueDate = detail.Adjustment_Voucher_Record.issueDate; vm.ApprovalDate = detail.Adjustment_Voucher_Record.approvalDate; if (!String.IsNullOrEmpty(detail.Adjustment_Voucher_Record.authorisingStaffID)) { vm.Approver = userService.FindNameByID(detail.Adjustment_Voucher_Record.authorisingStaffID); } vm.Causes = detail.Adjustment_Voucher_Record.remarks; vm.Status = detail.Adjustment_Voucher_Record.status; // Voucher Detail information vm.Quantity = detail.adjustedQty; vm.Reason = detail.remarks; return(vm); }
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(); } }