Esempio n. 1
0
        public bool UpdateRequisitionCollectionTime(Requisition r1)
        {
            try
            {
                Requisition original = rrepo.UpdateRequisitionCollectionTime(r1);
                Employee    drep     = erepo.FindEmpById((int)original.Department.RepId);
                Employee    deptemp  = erepo.FindEmpById(original.ReqByEmpId);
                EmailModel  email    = new EmailModel();

                Task.Run(async() =>
                {
                    EmailTemplates.CollectionTimeTemplate ctt = new EmailTemplates.CollectionTimeTemplate(original, drep);
                    email.emailTo      = drep.Email;
                    email.emailSubject = ctt.subject;
                    email.emailBody    = ctt.body;
                    await mailservice.SendEmailwithccAsync(email, deptemp);
                });
                return(true);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Esempio n. 2
0
        public bool UpdatePr(List <PurchaseRequestDetail> prdlist, int supid, long approveddate)
        {
            foreach (PurchaseRequestDetail prd in prdlist)
            {
                purreqrepo.UpdateApprovedPrItems(prd, supid, approveddate);
            }

            if (prdlist[0].Status == Status.PurchaseRequestStatus.approved)
            {
                List <PurchaseRequestDetail> prdlist2     = purreqrepo.FindPurchaseReq(prdlist[0].PurchaseRequestId);                //getting back all the PurchaseRequestDetail with extra information for Emailing
                List <PurchaseRequestDetail> sortedprlist = prdlist2.GroupBy(m => m.SupplierId).SelectMany(m => m).ToList();
                Dictionary <string, List <PurchaseRequestDetail> > pdict = new Dictionary <string, List <PurchaseRequestDetail> >(); //create dictionary of supplier Id as key, and List<PRD> as value for further creation of PO

                foreach (PurchaseRequestDetail prd in sortedprlist)
                {
                    if (!pdict.ContainsKey(prd.SupplierId))
                    {
                        List <PurchaseRequestDetail> prdlist1 = new List <PurchaseRequestDetail>();
                        prdlist1.Add(prd);
                        pdict.Add(prd.SupplierId, prdlist1);
                    }
                    else
                    {
                        //List<PurchaseRequestDetail> prdlist2 = pdict[prd.SupplierId];
                        pdict[prd.SupplierId].Add(prd);
                        //pdict[prd.SupplierId] = prdlist2;
                    }
                }

                foreach (var r in pdict) //for each supplierId in the dictionary, create PO
                {
                    PurchaseOrder po = new PurchaseOrder();
                    po.OrderedByClerkId  = r.Value[0].CreatedByClerkId;
                    po.SupplierId        = r.Value[0].SupplierId;
                    po.OrderedDate       = approveddate;
                    po.Status            = Status.PurchaseOrderStatus.pending;
                    po.CollectionPointId = crepo.GetStoreCollectionPoint().Id;
                    po.ApprovedBySupId   = supid;
                    po.SupplyByDate      = approveddate + 604800000; //Add 7 days to ordered date
                    double totalprice = 0;
                    foreach (PurchaseRequestDetail pr in pdict[r.Key])
                    {
                        totalprice += pr.TotalPrice;
                    }
                    po.TotalPrice = totalprice;
                    PurchaseOrder newpo = porepo.Create(po);
                    List <PurchaseRequestDetail> List_of_PRD_toaddinPO = pdict[r.Key];
                    foreach (PurchaseRequestDetail z in List_of_PRD_toaddinPO)
                    {
                        PurchaseOrderDetail pod = new PurchaseOrderDetail();
                        pod.PurchaseOrderId         = newpo.Id;
                        pod.PurchaseRequestDetailId = z.Id;
                        pod.ProductId    = z.ProductId;
                        pod.QtyPurchased = z.ReorderQty;
                        pod.TotalPrice   = z.TotalPrice;
                        pod.Status       = Status.PurchaseOrderDetailStatus.pending;
                        podrepo.CreatePurchaseOrderDetail(pod);
                    }

                    PurchaseOrder savedpo = porepo.FindPOByPOid(newpo.Id);                   //Latest PO after persisting
                    List <PurchaseOrderDetail> savedpod = podrepo.FindPoDetails(savedpo.Id); //Latest POD after persisting
                    Employee   clerk    = erepo.FindEmpById(r.Value[0].CreatedByClerkId);
                    Supplier   supplier = srepo.FindSupplierById(r.Value[0].SupplierId);
                    EmailModel email    = new EmailModel();
                    Task.Run(async() =>
                    {
                        EmailTemplates.ApprovedPRtemplate apt = new EmailTemplates.ApprovedPRtemplate(clerk, supplier, savedpod, savedpo);
                        email.emailTo      = supplier.Email;
                        email.emailSubject = apt.subject;
                        email.emailBody    = apt.body;
                        await mailservice.SendEmailwithccAsync(email, clerk);
                    });
                }
            }

            else //when rejected
            {
                // to pull out purchase request id and date
                List <PurchaseRequestDetail> prdlist2 = purreqrepo.FindPurchaseReq(prdlist[0].PurchaseRequestId); //getting back all the PurchaseRequestDetail with extra information for Emailing
                long       submitdate = (long)prdlist2[0].SubmitDate;
                int        prid       = prdlist2[0].Id;
                string     remarks    = prdlist2[0].Remarks;
                Employee   clerk      = erepo.FindEmpById(prdlist2[0].CreatedByClerkId);
                Employee   sup        = erepo.FindEmpById(supid);
                EmailModel email      = new EmailModel();
                Task.Run(async() =>
                {
                    EmailTemplates.RejectedPRtemplate apt = new EmailTemplates.RejectedPRtemplate(clerk, sup, prid, submitdate, remarks);
                    email.emailTo      = clerk.Email;
                    email.emailSubject = apt.subject;
                    email.emailBody    = apt.body;
                    await mailservice.SendEmailAsync(email);
                });
            }
            return(true);
        }