public async Task <IActionResult> PutBackOrder([FromRoute] int id, [FromBody] BackOrder backOrder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != backOrder.Id)
            {
                return(BadRequest());
            }

            _context.Entry(backOrder).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BackOrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostBackOrder([FromBody] BackOrder backOrder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.BackOrder.Add(backOrder);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBackOrder", new { id = backOrder.Id }, backOrder));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(InventoryInView inventoryInView)
        {
            //return Json(inventoryInView);
            //กรณีที่เป็น Complete
            //if (inventoryInView.purchase_type_id == 3)
            if (ModelState.IsValid)
            {
                //return Content("yes");
                if (inventoryInView.purchase_type_id == 3)
                {
                    var obj = new InventoryIn {
                        purchase_id       = inventoryInView.purchase_id,
                        product_id        = inventoryInView.product_id,
                        inventoryin_qty   = inventoryInView.inventoryin_qty,
                        manufacturer_week = inventoryInView.manufacturer_week,
                        manufacturer_year = inventoryInView.manufacturer_year,
                        purchaseItem_id   = inventoryInView.purchaseItem_id,
                        CompleteDate      = DateTime.Now
                    };
                    _context.InventoryIn.Add(obj);
                    //return Json(obj);
                    var row = new PActivity {
                        purchase_type_id = inventoryInView.purchase_type_id,
                        purchaseItem_id  = inventoryInView.purchaseItem_id,
                        activity_date    = DateTime.Now
                    };
                    _context.PActivities.Add(row);

                    //update purchase_type_id into purchase_items table
                    var found = await _context.PurchaseItems.FirstOrDefaultAsync(x => x.purchaseItem_id == inventoryInView.purchaseItem_id);

                    found.purchase_type_id = 3;
                    _context.PurchaseItems.Update(found);

                    var pproduct = await _context.ProductInfos.Where(x => x.product_id == inventoryInView.product_id).FirstOrDefaultAsync();

                    var found2 = await _context.Inventories
                                 .FirstOrDefaultAsync(x => x.product_name == pproduct.product_name);

                    found2.invento_qty += inventoryInView.inventoryin_qty;
                    _context.Inventories.Update(found2);

                    var po = _context.PurchaseOrders
                             .Where(x => x.purchase_id == inventoryInView.purchase_id)
                             .FirstOrDefault();
                    DateTime today     = DateTime.Now;
                    TimeSpan timeDiff  = today - po.purchase_date;
                    double   num_day   = timeDiff.TotalDays;
                    int      i_num_day = (int)Math.Round(num_day);
                    int      kpi       = 0;
                    if (i_num_day > 5)
                    {
                        kpi = 1;
                    }

                    //use kip to update performance table
                    var new_kpi = new SupplierPerformance {
                        leadTime        = kpi,
                        deliver_date    = today,
                        supplier_id     = inventoryInView.supplier_id,
                        purchaseItem_id = inventoryInView.purchaseItem_id,
                        backOrder       = 0
                    };
                    _context.SupplierPerformances.Add(new_kpi);

                    var p = await _context.SupplierInfos.Where(x => x.supplier_id == inventoryInView.supplier_id).FirstOrDefaultAsync();

                    p.leadtime += kpi;
                    _context.SupplierInfos.Update(p);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }

                //กรณีที่เป็น BackOrder
                if (inventoryInView.purchase_type_id == 2)
                {
                    var bo = new SupplierPerformance {
                        supplier_id     = inventoryInView.supplier_id,
                        purchaseItem_id = inventoryInView.purchaseItem_id,
                        deliver_date    = DateTime.Now,
                        leadTime        = 0,
                        backOrder       = 1
                    };
                    _context.SupplierPerformances.Add(bo);

                    var p = await _context.SupplierInfos.Where(x => x.supplier_id == inventoryInView.supplier_id).FirstOrDefaultAsync();

                    p.backorder += 1;
                    _context.SupplierInfos.Update(p);

                    var bol = new BackOrder {
                        purchaseItem_id = inventoryInView.purchaseItem_id
                    };
                    _context.BackOrders.Add(bol);

                    var found = await _context.PurchaseItems.FirstOrDefaultAsync(x => x.purchaseItem_id == inventoryInView.purchaseItem_id);

                    found.purchase_type_id = 2;
                    _context.PurchaseItems.Update(found);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }

            ViewData["product_id"]       = new SelectList(_context.ProductInfos, "product_id", "product_name", inventoryInView.product_id);
            ViewData["purchase_id"]      = new SelectList(_context.PurchaseOrders, "purchase_id", "purchase_id", inventoryInView.purchase_id);
            ViewData["purchase_type_id"] = new SelectList(_context.PurchaseOrderTypes, "Purchase_type_id", "Purchase_type_name");
            return(View());
        }
Exemplo n.º 4
0
 public static void BackOrderOperation(int remainingQuantity, ItemCategory item)
 {
     InvContext ctx       = new InvContext();
     BackOrder  backOrder = new BackOrder();
 }