Esempio n. 1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("InvenTranId,Number,Description,ProductId,TranSourceId,TranSourceNumber,TranSourceType,Quantity,InvenTranDate")] InvenTran invenTran)
        {
            if (id != invenTran.InvenTranId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(invenTran);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InvenTranExists(invenTran.InvenTranId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "Name", invenTran.ProductId);
            return(View(invenTran));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutGoodsReceiveLine(Guid id, GoodsReceiveLine goodsReceiveLine)
        {
            if (id != goodsReceiveLine.GoodsReceiveLineId)
            {
                return(BadRequest());
            }

            GoodsReceiveLine update = new GoodsReceiveLine();

            update = await _context.GoodsReceiveLine.FindAsync(id);

            InvenTran tran = new InvenTran();

            tran = await _context.InvenTran.Where(x => x.TranSourceId.Equals(id)).FirstOrDefaultAsync();

            if (update != null && tran != null)
            {
                update.QtyReceive = goodsReceiveLine.QtyReceive;
                tran.Quantity     = update.QtyReceive * 1;
                _context.Update(tran);
                _context.Update(update);
                await _context.SaveChangesAsync();
            }

            return(Ok(new { data = update }));
        }
Esempio n. 3
0
        public async Task <ActionResult <InvenTran> > PostInvenTran(InvenTran invenTran)
        {
            _context.InvenTran.Add(invenTran);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetInvenTran", new { id = invenTran.InvenTranId }, invenTran));
        }
Esempio n. 4
0
        public async Task <IActionResult> PutInvenTran(Guid id, InvenTran invenTran)
        {
            if (id != invenTran.InvenTranId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("InvenTranId,Number,Description,TranSourceNumber,TranSourceType,Quantity,InvenTranDate")] InvenTran invenTran)
        {
            if (ModelState.IsValid)
            {
                invenTran.InvenTranId = Guid.NewGuid();
                _context.Add(invenTran);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(invenTran));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("InvenTranId,Number,Description,ProductId,TranSourceId,TranSourceNumber,TranSourceType,Quantity,InvenTranDate")] InvenTran invenTran)
        {
            if (ModelState.IsValid)
            {
                invenTran.InvenTranId = Guid.NewGuid();
                _context.Add(invenTran);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "Name", invenTran.ProductId);
            return(View(invenTran));
        }
        public async Task <IActionResult> Create([Bind("GoodsReceiveId,Number,Description,GoodsReceiveDate,PurchaseOrderId")] GoodsReceive goodsReceive)
        {
            if (ModelState.IsValid)
            {
                goodsReceive.GoodsReceiveId = Guid.NewGuid();
                _context.Add(goodsReceive);
                List <PurchaseOrderLine> purchLines = new List <PurchaseOrderLine>();
                purchLines = await _context.PurchaseOrderLine.Where(x => x.PurchaseOrderId.Equals(goodsReceive.PurchaseOrderId)).ToListAsync();

                foreach (var item in purchLines)
                {
                    GoodsReceiveLine line = new GoodsReceiveLine();
                    line.GoodsReceiveId      = goodsReceive.GoodsReceiveId;
                    line.PurchaseOrderLineId = item.PurchaseOrderLineId;
                    line.ProductId           = item.ProductId;
                    line.QtyPurchase         = item.Quantity;
                    line.QtyReceive          = 0;
                    List <GoodsReceiveLine> received = new List <GoodsReceiveLine>();
                    received = await _context.GoodsReceiveLine.Where(x => x.PurchaseOrderLineId.Equals(item.PurchaseOrderLineId)).ToListAsync();

                    line.QtyReceived = received.Sum(x => x.QtyReceive);
                    _context.Add(line);

                    InvenTran tran = new InvenTran();
                    tran.InvenTranId      = Guid.NewGuid();
                    tran.Number           = _pos.GenerateInvenTranNumber();
                    tran.ProductId        = line.ProductId;
                    tran.TranSourceId     = line.GoodsReceiveLineId;
                    tran.TranSourceNumber = goodsReceive.Number;
                    tran.TranSourceType   = "GR";
                    tran.Quantity         = line.QtyReceive * 1;
                    tran.InvenTranDate    = DateTime.Now;
                    _context.Add(tran);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Edit), new { id = goodsReceive.GoodsReceiveId }));
            }
            ViewData["PurchaseOrderId"] = new SelectList(_context.PurchaseOrder, "PurchaseOrderId", "Number", goodsReceive.PurchaseOrderId);
            return(View(goodsReceive));
        }
Esempio n. 8
0
        public async Task <ActionResult <SalesOrderLine> > PostSalesOrderLine(SalesOrderLine salesOrderLine)
        {
            _context.SalesOrderLine.Add(salesOrderLine);

            SalesOrder salesOrder = _context.SalesOrder.Where(x => x.SalesOrderId.Equals(salesOrderLine.SalesOrderId)).FirstOrDefault();
            InvenTran  tran       = new InvenTran();

            tran.InvenTranId      = Guid.NewGuid();
            tran.Number           = _pos.GenerateInvenTranNumber();
            tran.ProductId        = salesOrderLine.ProductId;
            tran.TranSourceId     = salesOrderLine.SalesOrderLineId;
            tran.TranSourceNumber = salesOrder != null ? salesOrder.Number : "-";
            tran.TranSourceType   = "SO";
            tran.Quantity         = salesOrderLine.Quantity * -1; //minus for inventory deduction
            tran.InvenTranDate    = DateTime.Now;
            _context.InvenTran.Add(tran);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSalesOrderLine", new { id = salesOrderLine.SalesOrderLineId }, salesOrderLine));
        }