Esempio n. 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
            }));
        }
Esempio n. 2
0
        // Author: Hanh Nguyen, KyawThiha
        //
        public string POListApi()
        {
            var dTOs = new List <PODTO>();

            var pOs = _context.POs
                      .Where(p => p.POStatus == POStatus.Processing || p.POStatus == POStatus.Completed).ToList();

            foreach (var po in pOs)
            {
                var dTO = new PODTO();
                dTO.Id           = po.Id;
                dTO.POStatus     = po.POStatus;
                dTO.SupplierName = po.Supplier.Name;
                dTO.OrderDate    = po.OrderDate;
                dTO.ReceiveDate  = po.ReceiveDate;
                dTO.poDetails    = new List <PODetailsDTO>();

                foreach (PODetail pdto in po.PODetails)
                {
                    PODetailsDTO p = new PODetailsDTO();
                    p.Id               = pdto.Id;
                    p.poID             = pdto.PO.Id;
                    p.stationery       = pdto.SupplierDetail.Stationery;
                    p.predictionQty    = pdto.prdictedAmount;
                    p.Qty              = pdto.Qty;
                    p.unitPrice        = pdto.SupplierDetail.UnitPrice;
                    p.supplierDetailId = pdto.SupplierDetail.Id;

                    dTO.poDetails.Add(p);
                }

                dTOs.Add(dTO);
            }

            return(JsonSerializer.Serialize(new
            {
                poS = dTOs
            }));
        }