public IHttpActionResult UpdatePOStatusComplete(PurchaseOrderModel po)
        {
            string error = "";

            po = PurchaseOrderRepo.GetPurchaseOrderByID(po.PoId, out error);

            // if the staff has already updated the status to "received"
            if (po.Status == ConPurchaseOrder.Status.RECEIVED)
            {
                return(Ok(po));
            }
            po.Status = ConPurchaseOrder.Status.RECEIVED;

            List <PurchaseOrderDetailModel> podms = PurchaseOrderDetailRepo.GetPurchaseOrderDetailByID(po.PoId, out error);

            // if the purchase order is completed, the stock must be updated according to deliver qty.
            foreach (PurchaseOrderDetailModel podm in podms)
            {
                // get the inventory using the item id from purchaseorder detail model
                InventoryModel invm = InventoryRepo.GetInventoryByItemid(podm.Itemid, out error);

                // adding the stock accoring to deliver qty
                invm.Stock += podm.DelivQty;

                // update the inventory
                invm = InventoryRepo.UpdateInventory(invm, out error);


                InventoryTransactionModel invtm = new InventoryTransactionModel();

                invtm.InvID     = invm.Invid;
                invtm.ItemID    = invm.Itemid;
                invtm.Qty       = podm.DelivQty;
                invtm.TransType = ConInventoryTransaction.TransType.PURCHASEORDER_RECEIEVED;
                invtm.TransDate = DateTime.Now;
                invtm.Remark    = podm.PoId.ToString();
                invtm           = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error);
            }

            // updating the status
            PurchaseOrderModel pom = PurchaseOrderRepo.UpdatePurchaseOrder(po, out error);

            if (error != "" || pom == null)
            {
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "PO Not Found"));
                }
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(pom));
        }
        public IHttpActionResult GetPurchaseOrderById(int poid)
        {
            string             error = "";
            PurchaseOrderModel orm   =
                PurchaseOrderRepo.GetPurchaseOrderByID(poid, out error);

            if (error != "" || orm == null)
            {
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "PO Not Found"));
                }
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(orm));
        }