Пример #1
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string   code           = GridView1.DataKeys[e.RowIndex].Values["SupplierCode"].ToString();
        Supplier deleteSupplier = context.Suppliers.Where(x => x.SupplierCode == code).First();

        context.Suppliers.Remove(deleteSupplier);
        context.SaveChanges();
        GridView1.DataSource = context.Suppliers.ToList();
        GridView1.DataBind();
    }
Пример #2
0
        public static void SubmitAdjustmentVoucher(string itemNo, DateTime dateIssued, int qty, string reason, int issueEmpNo)
        {
            AdjustmentVoucher       aV;
            AdjustmentVoucherDetail aVD;

            LussisEntities context = new LussisEntities();

            using (var txn = new TransactionScope())
            {
                // Create AdjustmentVoucher
                aV            = new AdjustmentVoucher();
                aV.DateIssued = dateIssued;
                aV.IssueEmpNo = issueEmpNo;
                aV.Status     = "Pending";
                context.AdjustmentVouchers.Add(aV);
                context.SaveChanges();

                // Create AdjustmentVoucherDetails
                aVD        = new AdjustmentVoucherDetail();
                aVD.AvNo   = aV.AvNo;
                aVD.ItemNo = itemNo;
                aVD.Qty    = qty;
                aVD.Reason = reason;
                context.AdjustmentVoucherDetails.Add(aVD);
                context.SaveChanges();

                txn.Complete();
            }

            // Send Email
            var supplier1Code = context.StationeryCatalogues.Where(x => x.ItemNo.Equals(itemNo)).FirstOrDefault().Supplier1;
            var unitPrice     = context.SupplyTenders.Where(x => x.ItemNo.Equals(itemNo) && x.SupplierCode.Equals(supplier1Code)).FirstOrDefault().UnitPrice;
            var price         = qty * unitPrice;

            Employee recipient;

            if (price >= 250)
            {
                recipient = context.StoreAssignments.Where(x => x.Role.Equals("Manager")).FirstOrDefault().Employee;
            }
            else
            {
                recipient = context.StoreAssignments.Where(x => x.Role.Equals("Supervisor")).FirstOrDefault().Employee;
            }

            string recipientEmail = recipient.Email;
            string emailSubject   = EmailTemplate.GenerateAdjustmentVoucherSubject();
            string emailContent   = EmailTemplate.GenerateAdjustmentVoucherEmail(recipient.EmpName, aV.AvNo);

            EmailBackend.sendEmailStep(recipientEmail, emailSubject, emailContent);
        }
Пример #3
0
        private static void ProcessRequisitions(LussisEntities context, int retrievalNo)
        {
            // Get Approved Requisitions
            List <Requisition> requisitionList = GetApprovedRequisitions(context);

            if (requisitionList.Count == 0)
            {
                throw new Exception("No Requisitions to Process");
            }

            // For each Requisition
            for (int i = 0; i < requisitionList.Count; i++)
            {
                // Get RequisitionDetails
                List <RequisitionDetail> requisitionDetailList = requisitionList[i].RequisitionDetails.ToList <RequisitionDetail>();

                // For each RequisitionDetail
                for (int j = 0; j < requisitionDetailList.Count; j++)
                {
                    // Get deptCode & itemNo
                    string deptCode = requisitionDetailList[j].RequisitionInfo.EmployeeWhoIssued.DeptCode;
                    string itemNo   = requisitionDetailList[j].ItemNo;

                    // Get RetrievalDetail
                    RetrievalDetail retrievalDetail = GetRetrievalDetail(context, retrievalNo, deptCode, itemNo);

                    if (retrievalDetail != null)
                    {
                        // Update RetrievalDetail
                        retrievalDetail.Needed += requisitionDetailList[j].Qty;
                    }
                    else
                    {
                        // Create RetrievalDetail
                        retrievalDetail             = new RetrievalDetail();
                        retrievalDetail.RetrievalNo = retrievalNo;
                        retrievalDetail.DeptCode    = deptCode;
                        retrievalDetail.ItemNo      = requisitionDetailList[j].ItemNo;
                        retrievalDetail.Needed      = requisitionDetailList[j].Qty;
                        retrievalDetail.BackLogQty  = 0;
                        retrievalDetail.Actual      = 0;
                        retrievalDetail             = AddRetrievalDetail(context, retrievalDetail);
                        context.SaveChanges();
                    }
                }

                // Update Requisition Status
                requisitionList[i].Status = "Processed";
            }
            context.SaveChanges();
        }
Пример #4
0
        public static void IncreaseStockFromSupplier(String itemNo, int quantity, String supplierCode)
        {
            LussisEntities context = new LussisEntities();

            // Get Entities
            StationeryCatalogue stationeryItem = context.StationeryCatalogues.Where(item => item.ItemNo.Equals(itemNo)).FirstOrDefault();
            Supplier            supplier       = context.Suppliers.Where(supp => supp.SupplierCode.Equals(supplierCode)).FirstOrDefault();
            StockTxnDetail      detail         = new StockTxnDetail()
            {
                AdjustQty = quantity,
                Date      = DateTime.Today,
                ItemNo    = itemNo,
                Remarks   = "Supplied by " + supplierCode,
            };

            // If entities are found, update database
            if (stationeryItem != null && supplier != null)
            {
                detail.RecordedQty        = stationeryItem.CurrentQty + detail.AdjustQty;
                stationeryItem.CurrentQty = detail.RecordedQty;
                context.StockTxnDetails.Add(detail);

                context.SaveChanges();
            }
        }
Пример #5
0
        public static void UpdatePODQty(int pONo, string itemNo, int qty)
        {
            LussisEntities      context = new LussisEntities();
            PurchaseOrderDetail pOD     = context.PurchaseOrderDetails.Where(x => x.PONo == pONo && x.ItemNo.Equals(itemNo)).FirstOrDefault();

            pOD.Qty = qty;
            context.SaveChanges();
        }
Пример #6
0
        public static void DeletePOD(int pONo, string itemNo)
        {
            LussisEntities      context = new LussisEntities();
            PurchaseOrderDetail pOD     = context.PurchaseOrderDetails.Where(x => x.PONo == pONo && x.ItemNo.Equals(itemNo)).FirstOrDefault();

            context.PurchaseOrderDetails.Remove(pOD);
            context.SaveChanges();
        }
Пример #7
0
        public static void UpdateReceivedQty(int dNo, string itemNo, int qty)
        {
            LussisEntities     context = new LussisEntities();
            DisbursementDetail dDetail = context.DisbursementDetails.Where(x => x.DisbursementNo == dNo && x.ItemNo.Equals(itemNo)).FirstOrDefault();

            dDetail.Received = qty;
            context.SaveChanges();
        }
Пример #8
0
        public static void DeleteAVD(int aVNo, string itemNo)
        {
            LussisEntities          context = new LussisEntities();
            AdjustmentVoucherDetail aVD     = context.AdjustmentVoucherDetails.Where(x => x.AvNo == aVNo && x.ItemNo.Equals(itemNo)).FirstOrDefault();

            context.AdjustmentVoucherDetails.Remove(aVD);
            context.SaveChanges();
        }
Пример #9
0
        public static void UpdateAVDetailQty(int aVNo, string itemNo, int qty, string reason)
        {
            LussisEntities          context = new LussisEntities();
            AdjustmentVoucherDetail aVD     = context.AdjustmentVoucherDetails.Where(x => x.AvNo == aVNo && x.ItemNo.Equals(itemNo)).FirstOrDefault();

            aVD.Qty    = qty;
            aVD.Reason = reason;
            context.SaveChanges();
        }
Пример #10
0
        private static PurchaseOrderDetail CreatePurchaseOrderDetail(int pONo, string itemNo, int?qty)
        {
            LussisEntities context = new LussisEntities();

            // Create PurchaseOrderDetail
            PurchaseOrderDetail pOD = new PurchaseOrderDetail();

            pOD.PONo   = pONo;
            pOD.ItemNo = itemNo;
            pOD.Qty    = qty;
            context.PurchaseOrderDetails.Add(pOD);
            context.SaveChanges();
            return(pOD);
        }
Пример #11
0
        public static void DeleteAV(int aVNo)
        {
            LussisEntities context = new LussisEntities();

            using (var txn = new TransactionScope())
            {
                // Remove AdjustmentVoucherDetails
                List <AdjustmentVoucherDetail> result = context.AdjustmentVoucherDetails.Where(x => x.AvNo == aVNo).ToList <AdjustmentVoucherDetail>();
                foreach (AdjustmentVoucherDetail aVD in result)
                {
                    context.AdjustmentVoucherDetails.Remove(aVD);
                }

                // Remove AdjustmentVoucher
                AdjustmentVoucher aV = context.AdjustmentVouchers.Where(x => x.AvNo == aVNo).FirstOrDefault();
                context.AdjustmentVouchers.Remove(aV);

                context.SaveChanges();
                txn.Complete();
            }
        }
Пример #12
0
        public static void DeletePO(int pONo)
        {
            LussisEntities context = new LussisEntities();

            using (var txn = new TransactionScope())
            {
                // Remove PurchaseOrderDetails
                List <PurchaseOrderDetail> pODs = context.PurchaseOrders.Where(x => x.PONo == pONo).FirstOrDefault().PurchaseOrderDetails.ToList();
                foreach (PurchaseOrderDetail pOD in pODs)
                {
                    context.PurchaseOrderDetails.Remove(pOD);
                }

                // Remove PurchaseOrder
                PurchaseOrder pO = context.PurchaseOrders.Where(x => x.PONo == pONo).FirstOrDefault();
                context.PurchaseOrders.Remove(pO);

                context.SaveChanges();
                txn.Complete();
            }
        }
Пример #13
0
        private static PurchaseOrder CreatePurchaseOrder(string supplierCode, int orderedBy, DateTime dateIssued, List <PurchaseOrder> pOList)
        {
            LussisEntities context = new LussisEntities();

            // Check if SupplierCode inside pOList
            PurchaseOrder pO = pOList.Where(x => x.SupplierCode.Equals(supplierCode)).FirstOrDefault();

            if (pO == null)
            {
                // Create PurchaseOrder
                pO = new PurchaseOrder();
                pO.SupplierCode = supplierCode;
                pO.OrderedBy    = orderedBy;
                pO.DateIssued   = dateIssued;
                pO.Status       = "Pending";
                context.PurchaseOrders.Add(pO);
                context.SaveChanges();
                pOList.Add(pO);
            }

            return(pO);
        }
Пример #14
0
        public static DisbursementDetail AddDisbursementDetail(LussisEntities context, DisbursementDetail disbursementDetail)
        {
            // TODO : Put a filter for what kind of disbursement to edit
            DisbursementDetail detail = context.DisbursementDetails
                                        .Where(det => det.DisbursementNo.Equals(disbursementDetail.DisbursementNo) && det.ItemNo.Equals(disbursementDetail.ItemNo))
                                        .FirstOrDefault();

            if (detail != null)
            {
                // Append to existing if it already exists
                detail.Needed   += disbursementDetail.Needed;
                detail.Promised += disbursementDetail.Promised;
                detail.Received += disbursementDetail.Received;
            }
            else
            {
                // Add new detail
                context.DisbursementDetails.Add(disbursementDetail);
            }

            context.SaveChanges();
            return(disbursementDetail);
        }
Пример #15
0
        private static void ProcessBacklogs(LussisEntities context, int retrievalNo)
        {
            // Get Backlogs
            List <BackLog> backlogList = context.BackLogs.ToList <BackLog>();

            // For each Backlog
            for (int i = 0; i < backlogList.Count; i++)
            {
                // Get deptCode & itemNo
                string deptCode = backlogList[i].DeptCode;
                string itemNo   = backlogList[i].ItemNo;

                // Get RetrievalDetail
                RetrievalDetail retrievalDetail = GetRetrievalDetail(context, retrievalNo, deptCode, itemNo);

                if (retrievalDetail != null)
                {
                    // Update RetrievalDetail
                    retrievalDetail.BackLogQty += backlogList[i].BackLogQty;
                }
                else
                {
                    // Create RetrievalDetail
                    retrievalDetail             = new RetrievalDetail();
                    retrievalDetail.RetrievalNo = retrievalNo;
                    retrievalDetail.DeptCode    = deptCode;
                    retrievalDetail.ItemNo      = itemNo;
                    retrievalDetail.Needed      = 0;
                    retrievalDetail.BackLogQty  = backlogList[i].BackLogQty;
                    retrievalDetail.Actual      = 0;
                    retrievalDetail             = AddRetrievalDetail(context, retrievalDetail);
                }
            }

            context.SaveChanges();
        }
Пример #16
0
 public static void Clear(LussisEntities context)
 {
     context.SaveChanges();
 }
Пример #17
0
 public static Disbursement AddDisbursement(LussisEntities context, Disbursement disbursement)
 {
     context.Disbursements.Add(disbursement);
     context.SaveChanges();
     return(disbursement);
 }
Пример #18
0
 public static StockTxnDetail AddStockTxn(LussisEntities context, StockTxnDetail txn)
 {
     context.StockTxnDetails.Add(txn);
     context.SaveChanges();
     return(txn);
 }
Пример #19
0
        public static bool SubmitRetrieval(int retrievalNo, List <string> deptCodeList, List <string> itemNoList, List <int> actualList)
        {
            LussisEntities context          = new LussisEntities();
            DateTime       today            = DateTime.Today;
            int            daysUntilMonday  = ((int)DayOfWeek.Monday - (int)today.DayOfWeek + 7) % 7;
            DateTime       disbursementDate = today.Date.AddDays(daysUntilMonday);

            // Update RetrievalDate
            Retrieval retrieval = GetRetrieval(context, retrievalNo);

            retrieval.Date = DateTime.Now;

            // For each RetrievalDetail
            for (int i = 0; i < actualList.Count; i++)
            {
                string deptCode = deptCodeList[i];
                string itemNo   = itemNoList[i];
                int    actual   = actualList[i];

                // Update RetrievalDetail
                RetrievalDetail retrievalDetail = GetRetrievalDetail(context, retrievalNo, deptCode, itemNo);
                retrievalDetail.Actual = actual;

                // Update StationeryCatalogueCurrentyQty
                StationeryCatalogue stock = GetStock(context, itemNo);
                stock.CurrentQty -= actual;

                // Add StockTxnDetail
                StockTxnDetail txn = new StockTxnDetail();
                txn.ItemNo      = itemNo;
                txn.Date        = retrieval.Date;
                txn.AdjustQty   = -actual;
                txn.RecordedQty = stock.CurrentQty;
                txn.Remarks     = GetDepartment(context, deptCode).DeptName;
                txn             = AddStockTxn(context, txn);

                // Add Disbursement
                Disbursement disbursement = GetPendingDisbursement(context, deptCode, disbursementDate);
                if (disbursement == null)
                {
                    disbursement = new Disbursement();
                    disbursement.DisbursementNo    = int.MaxValue;
                    disbursement.DeptCode          = deptCode;
                    disbursement.DisbursementDate  = disbursementDate;
                    disbursement.RepEmpNo          = GetDepartment(context, deptCode).RepEmpNo;
                    disbursement.CollectionPointNo = GetDepartment(context, deptCode).CollectionPointNo;
                    disbursement.Pin    = new Random().Next(10000, 99999);
                    disbursement.Status = "Pending";
                    disbursement        = AddDisbursement(context, disbursement);
                }

                // Add DisbursementDetail
                DisbursementDetail disbursementDetail = new DisbursementDetail();
                disbursementDetail.DisbursementNo = disbursement.DisbursementNo;
                disbursementDetail.ItemNo         = itemNo;
                disbursementDetail.Needed         = retrievalDetail.Needed + retrievalDetail.BackLogQty;
                disbursementDetail.Promised       = actual;
                disbursementDetail.Received       = actual;
                disbursementDetail = AddDisbursementDetail(context, disbursementDetail);
            }

            context.SaveChanges();
            return(true);
        }
Пример #20
0
 public static Retrieval AddRetrieval(LussisEntities context, Retrieval retrieval)
 {
     context.Retrievals.Add(retrieval);
     context.SaveChanges();
     return(retrieval);
 }
Пример #21
0
        public static bool CompleteDisbursement(int dNo, decimal?pin)
        {
            LussisEntities            context  = new LussisEntities();
            Disbursement              d        = context.Disbursements.Where(x => x.DisbursementNo == dNo).FirstOrDefault();
            List <DisbursementDetail> dDetails = d.DisbursementDetails.ToList();

            // If Pin is Valid
            if (d.Pin == pin)
            {
                // Update Disbursement Status
                d.Status = "Completed";

                // Create Backlogs
                for (int i = 0; i < dDetails.Count; i++)
                {
                    String deptCode = dDetails[i].Disbursement.DeptCode;
                    String itemCode = dDetails[i].ItemNo;
                    if (dDetails[i].Needed - dDetails[i].Received > 0)
                    {
                        BackLog backlog = context
                                          .BackLogs
                                          .Where(x =>
                                                 x.DeptCode.Equals(deptCode) &&
                                                 x.ItemNo.Equals(itemCode))
                                          .FirstOrDefault();

                        if (backlog == null)
                        {
                            backlog            = new BackLog();
                            backlog.DeptCode   = dDetails[i].Disbursement.DeptCode;
                            backlog.ItemNo     = dDetails[i].ItemNo;
                            backlog.BackLogQty = dDetails[i].Needed - dDetails[i].Received;
                            context.BackLogs.Add(backlog);
                        }
                        else
                        {
                            backlog.BackLogQty += dDetails[i].Needed - dDetails[i].Received;
                        }
                    }
                }

                context.SaveChanges();

                // Send Email
                Employee recipient    = d.Employee;
                var      emailDetails = dDetails.Select(
                    dD => new
                {
                    ItemNo          = dD.ItemNo,
                    ItemDescription = dD.StationeryCatalogue.Description,
                    Needed          = dD.Needed,
                    Delivered       = dD.Received
                });

                string recipientEmail = recipient.Email;
                string emailSubject   = EmailTemplate.GenerateCompletedDisbursementSubject(d.DisbursementNo);
                string emailContent   = EmailTemplate.GenerateCompletedDisbursementEmail(recipient.EmpName, d.DisbursementNo, d.DisbursementDate);
                EmailBackend.sendEmailStep(recipientEmail, emailSubject, emailContent);

                return(true);
            }
            else
            {
                return(false);
            }
        }