public static InventoryTransactionModel CreateInventoryTransaction(InventoryTransactionModel invtm, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); inventorytransaction d = new inventorytransaction(); try { d.datetime = DateTime.Now; d.invid = invtm.InvID; d.itemid = invtm.ItemID; d.trantype = invtm.TransType; d.qty = invtm.Qty; d.remark = invtm.Remark; d = entities.inventorytransactions.Add(d); entities.SaveChanges(); invtm = GetInventoryTransactionByTransID(d.tranid, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(invtm); }
public IHttpActionResult CreateDisbursementDetails(DisbursementDetailsModel dism) { string error = ""; DisbursementDetailsModel disbm = DisbursementDetailsRepo.CreateDisbursementDetails(dism, out error); // get the inventory using the item id from Requisition details InventoryModel invm = InventoryRepo.GetInventoryByItemid(dism.Itemid, out error); // subtract the stock accoring to qty invm.Stock -= dism.Qty; // update the inventory invm = InventoryRepo.UpdateInventory(invm, out error); InventoryTransactionModel invtm = new InventoryTransactionModel { InvID = invm.Invid, ItemID = invm.Itemid, Qty = dism.Qty * -1, TransType = ConInventoryTransaction.TransType.DISBURSEMENT, TransDate = DateTime.Now, Remark = dism.Disid.ToString() }; invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error); if (error != "" || disbm == null) { return(Content(HttpStatusCode.BadRequest, error)); } return(Ok(disbm)); }
public static InventoryTransactionModel GetInventoryTransactionByInvtID(string token, int invtranid, out string error) { string url = APIHelper.Baseurl + "/inventorytransaction/" + invtranid; InventoryTransactionModel invtran = APIHelper.Execute <InventoryTransactionModel>(token, url, out error); return(invtran); }
public IHttpActionResult CreateInventoryTransaction(InventoryTransactionModel invt) { string error = ""; InventoryTransactionModel invtm = InventoryTransactionRepo.CreateInventoryTransaction(invt, out error); if (error != "" || invtm == null) { return(Content(HttpStatusCode.BadRequest, error)); } return(Ok(invtm)); }
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 GetInventoryTransactionByInvtID(int invtid) { string error = ""; InventoryTransactionModel invtm = InventoryTransactionRepo.GetInventoryTransactionByTransID(invtid, out error); if (error != "" || invtm == null) { if (error == ConError.Status.NOTFOUND) { return(Content(HttpStatusCode.NotFound, "InventoryTransaction Not Found")); } return(Content(HttpStatusCode.BadRequest, error)); } return(Ok(invtm)); }
public static InventoryTransactionModel GetInventoryTransactionByTransID(int transid, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; inventorytransaction invt = new inventorytransaction(); InventoryTransactionModel invtm = new InventoryTransactionModel(); try { invt = entities.inventorytransactions.Where(p => p.tranid == transid).FirstOrDefault <inventorytransaction>(); invtm = ConvertDBModeltoAPIModel(invt); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(invtm); }
public static InventoryTransactionModel UpdateInventoryTransaction(InventoryTransactionModel invtm, out string error) { error = ""; // declare and initialize new LUSSISEntities to perform update LUSSISEntities entities = new LUSSISEntities(); inventorytransaction d = new inventorytransaction(); try { // finding the inventorytransaction object using InventoryTransaction API model d = entities.inventorytransactions.Where(p => p.tranid == invtm.TranID).First <inventorytransaction>(); // transfering data from API model to DB Model d.datetime = DateTime.Now; d.invid = invtm.InvID; d.itemid = invtm.ItemID; d.trantype = invtm.TransType; d.qty = invtm.Qty; d.remark = invtm.Remark; // saving the update entities.SaveChanges(); // return the updated model invtm = GetInventoryTransactionByTransID(d.tranid, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(invtm); }
// To Update Outstanding Requisition public static OutstandingReqModel UpdateOutReq (OutstandingReqModel ordm, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; OutstandingReqModel outreqm = new OutstandingReqModel(); outstandingrequisition outreq = new outstandingrequisition(); try { // finding the db object using API model outreq = entities.outstandingrequisitions .Where(x => x.outreqid == ordm.OutReqId) .FirstOrDefault(); // transfering data from API model to DB Model outreq.reqid = ordm.ReqId; outreq.reason = ordm.Reason; var TempStatus = outreq.status; outreq.status = ordm.Status; // saving the update entities.SaveChanges(); if (TempStatus != ordm.Status && ordm.Status == ConOutstandingsRequisition.Status.DELIVERED) { foreach (outstandingrequisitiondetail outrd in outreq.outstandingrequisitiondetails) { InventoryModel invm = InventoryRepo.GetInventoryByItemid(outrd.itemid, out error); invm.Stock -= outrd.qty; invm = InventoryRepo.UpdateInventory(invm, out error); InventoryTransactionModel invtm = new InventoryTransactionModel(); invtm.ItemID = outrd.itemid; invtm.InvID = invm.Invid; invtm.Qty = (outrd.qty) * -1; invtm.TransDate = DateTime.Now; invtm.Remark = "Fulfill Outstanding" + outrd.outreqid; invtm.TransType = ConInventoryTransaction.TransType.OUTSTANDING; invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error); } } // return the updated model outreqm = ConvertDBOutReqToAPIOutReq(outreq); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(outreqm); }
public static InventoryTransactionModel CreateInventoryTransaction(string token, InventoryTransactionModel itm, out string error) { error = ""; string url = APIHelper.Baseurl + "/inventorytransaction/create"; string objectstring = JsonConvert.SerializeObject(itm); itm = APIHelper.Execute <InventoryTransactionModel>(token, objectstring, url, out error); return(itm); }
//Update Adjustment public static AdjustmentModel UpdateAdjustment(AdjustmentModel adjm, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); NotificationModel nom = new NotificationModel(); adjustment adj = new adjustment(); try { adj = entities.adjustments.Where(a => a.adjid == adjm.Adjid).First <adjustment>(); adj.raisedby = adjm.Raisedby; adj.raisedto = adjm.Raisedto; adj.issueddate = adjm.Issueddate; adj.status = adjm.Status; nom.Remark = "The Adjustment Voucher has been Rejected!"; if (adj.status == ConAdjustment.Active.APPROVED) { nom.Remark = "The Adjustment Voucher has been Approved!"; } List <AdjustmentDetailModel> adjustds = AdjustmentDetailRepo.GetAdjustmentDetailByAdjID(adj.adjid, out error); foreach (AdjustmentDetailModel adjustd in adjustds) { InventoryModel inventm = InventoryRepo.GetInventoryByItemid(adjustd.Itemid, out error); inventory invent = entities.inventories.Where(i => i.invid == inventm.Invid).First <inventory>(); invent.stock += adjustd.Adjustedqty; InventoryTransactionModel invtm = new InventoryTransactionModel(); invtm.InvID = invent.invid; invtm.ItemID = invent.itemid; invtm.Qty = adjustd.Adjustedqty; invtm.TransType = ConInventoryTransaction.TransType.ADJUSTMENT; invtm.TransDate = DateTime.Now; invtm.Remark = adjustd.Reason; invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error); } entities.SaveChanges(); adjm = GetAdjustmentByID(adj.adjid, out error); nom.Deptid = DepartmentRepo.GetDepartmentByUserid(adj.raisedto ?? default(int), out error).Deptid; nom.Role = UserRepo.GetUserByUserID(adj.raisedby ?? default(int)).Role; nom.Title = "Adjustment Approval"; nom.NotiType = ConNotification.NotiType.Adjustment; nom.ResID = adj.adjid; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(adjm); }
// Convert From Auto Generated DB Model to APIModel private static InventoryTransactionModel ConvertDBModeltoAPIModel(inventorytransaction invt) { InventoryTransactionModel invtm = new InventoryTransactionModel(invt.tranid, invt.datetime, invt.invid, invt.itemid, invt.item.description, invt.item.uom, invt.item.category.name, invt.trantype, invt.qty, invt.remark); return(invtm); }