Пример #1
0
        // Author: KyawThiha
        // PO API
        public string POItemApi()
        {
            var max = _context.TempItems.OrderByDescending(p => p.id).FirstOrDefault();
            PurchaseOrderItemDTO pdto = new PurchaseOrderItemDTO();

            if (max != null)
            {
                pdto.supplierID = max.supplierId;
                pdto.POStatus   = POStatus.Processing;
                pdto.OrderDate  = max.orderDate;
            }

            List <PODetailsDTO> poDetailsList = new List <PODetailsDTO>();

            var sd = _context.SupplierDetails.ToList();

            foreach (SupplierDetail s in sd)
            {
                if (s.Supplier.Id == pdto.supplierID)
                {
                    PODetailsDTO temp = new PODetailsDTO();
                    temp.stationeryId          = s.Stationery.Id;
                    temp.stationeryDescription = s.Stationery.Description;
                    temp.supplierDetailId      = s.Id;
                    temp.unitPrice             = s.UnitPrice;

                    //prediction
                    int    id            = s.Stationery.Id;
                    int    cat           = (int)s.Stationery.Category;
                    String b             = "False";
                    double predictResult = prediction(id, cat, b, pdto.OrderDate);

                    double final = 0.0;

                    Double safetyStock  = s.Stationery.ReorderLevel;
                    Stock  stock        = _context.Stocks.SingleOrDefault(s => s.Stationery.Id == id);
                    double currentStock = stock.Qty;
                    if (((predictResult + safetyStock) > currentStock))
                    {
                        final = (predictResult + safetyStock) - currentStock;
                    }
                    else if ((predictResult + safetyStock) < currentStock)
                    {
                        final = 0;
                    }
                    temp.predictionQty    = final;
                    temp.supplierDetailId = s.Id;

                    poDetailsList.Add(temp);
                }
            }
            pdto.poDetailsList = poDetailsList;

            return(JsonSerializer.Serialize(new
            {
                items = pdto
            }));
        }
Пример #2
0
        public string POSave([FromBody] PurchaseOrderItemDTO input)
        {
            var newPo = new PO();

            newPo.OrderDate = input.OrderDate;
            newPo.POStatus  = POStatus.Processing;
            var supplier = _context.Suppliers.FirstOrDefault(s => s.Id == input.supplierID);

            newPo.Supplier = supplier;
            _context.Add(newPo);

            foreach (PODetailsDTO pd in input.poDetailsList)
            {
                PODetail poD = new PODetail();
                poD.SupplierDetail = _context.SupplierDetails.FirstOrDefault(s => s.Id == pd.supplierDetailId);
                poD.PO             = newPo;
                _context.Add(poD);
            }
            _context.SaveChanges();

            //sending mail
            String items = "";

            foreach (PODetailsDTO p in input.poDetailsList)
            {
                PODetail poD = new PODetail();
                poD.SupplierDetail = _context.SupplierDetails.FirstOrDefault(s => s.Id == p.supplierDetailId);
                poD.PO             = newPo;
                items += poD.SupplierDetail.Stationery.Description.ToString() + ": "
                         + p.Qty + " \n";
            }
            int         poId        = _context.SupplierDetails.OrderByDescending(p => p.Id).First().Id;
            MailAddress FromEmail   = new MailAddress("*****@*****.**", "Store");
            MailAddress ToEmail     = new MailAddress("*****@*****.**", "Supplier");
            string      Subject     = "Purchase Order";
            string      MessageBody = "Title: PO Number " + poId + "\n\n" + "You have orders from Store. The items list are:\n\n"
                                      + items + "\n\n" + "Regards,\n Store Clerk";

            EmailService.SendEmail(FromEmail, ToEmail, Subject, MessageBody);
            //(Mail fromMail, Mail toMail, String acknowledgementCode, String flag)

            //Json Response

            var response = new ResponseDTO();

            response.Message = "Create Successfully";

            return(JsonSerializer.Serialize(new
            {
                result = response
            }));
        }