public HttpResponseMessage SaveCollection(Entities.TrnCollection objCollection, String id) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var collection = from d in db.TrnCollections where d.Id == Convert.ToInt32(id) select d; if (collection.Any()) { if (!collection.FirstOrDefault().IsLocked) { String oldObject = auditTrail.GetObjectString(collection.FirstOrDefault()); var saveCollection = collection.FirstOrDefault(); saveCollection.ORDate = Convert.ToDateTime(objCollection.ORDate); saveCollection.ManualORNumber = objCollection.ManualORNumber; saveCollection.CustomerId = objCollection.CustomerId; saveCollection.Particulars = objCollection.Particulars; saveCollection.CheckedById = objCollection.CheckedById; saveCollection.ApprovedById = objCollection.ApprovedById; saveCollection.Status = objCollection.Status; saveCollection.UpdatedById = currentUserId; saveCollection.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); String newObject = auditTrail.GetObjectString(collection.FirstOrDefault()); auditTrail.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, oldObject, newObject); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Saving Error. These collection details are already locked.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These collection details are not found in the server.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public HttpResponseMessage putCollection(String id, Entities.TrnCollection collection) { try { var collections = from d in db.TrnCollections where d.Id == Convert.ToInt32(id) select d; if (collections.Any()) { var updateCollection = collections.FirstOrDefault(); updateCollection.PeriodId = collection.PeriodId; updateCollection.CollectionDate = collection.CollectionDate; updateCollection.CollectionNumber = collection.CollectionNumber; updateCollection.TerminalId = collection.TerminalId; updateCollection.ManualORNumber = collection.ManualORNumber; updateCollection.CustomerId = collection.CustomerId; updateCollection.Remarks = collection.Remarks; updateCollection.SalesId = collection.SalesId; updateCollection.SalesBalanceAmount = collection.SalesBalanceAmount; updateCollection.Amount = collection.Amount; updateCollection.TenderAmount = collection.TenderAmount; updateCollection.ChangeAmount = collection.ChangeAmount; updateCollection.PreparedBy = UserId(); updateCollection.CheckedBy = UserId(); updateCollection.ApprovedBy = UserId(); updateCollection.IsCancelled = collection.IsCancelled; updateCollection.IsLocked = true; updateCollection.EntryUserId = UserId(); updateCollection.EntryDateTime = DateTime.Today; updateCollection.UpdateUserId = UserId(); updateCollection.UpdateDateTime = DateTime.Today; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch (Exception e) { // Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public HttpResponseMessage LockCollection(Entities.TrnCollection objCollection, String id) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("CollectionDetail") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanLock) { var collection = from d in db.TrnCollections where d.Id == Convert.ToInt32(id) select d; if (collection.Any()) { if (!collection.FirstOrDefault().IsLocked) { var lockCollection = collection.FirstOrDefault(); lockCollection.ORDate = Convert.ToDateTime(objCollection.ORDate); lockCollection.ManualORNumber = objCollection.ManualORNumber; lockCollection.CustomerId = objCollection.CustomerId; lockCollection.Particulars = objCollection.Particulars; lockCollection.CheckedById = objCollection.CheckedById; lockCollection.ApprovedById = objCollection.ApprovedById; lockCollection.IsLocked = true; lockCollection.UpdatedById = currentUserId; lockCollection.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); // =============================== // Journal and Accounts Receivable // =============================== Business.Journal journal = new Business.Journal(); if (lockCollection.IsLocked) { journal.InsertOfficialReceiptJournal(Convert.ToInt32(id)); UpdateAccountsReceivable(Convert.ToInt32(id)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Locking Error. These collection details are already locked.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These collection details are not found in the server.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to lock collection.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this collection page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public HttpResponseMessage LockCollection(Entities.TrnCollection objCollection, String id) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("CollectionDetail") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanLock) { var collection = from d in db.TrnCollections where d.Id == Convert.ToInt32(id) select d; if (collection.Any()) { int countInvalidSI = 0; var invalidSIs = from d in db.TrnCollectionLines where d.ORId == collection.FirstOrDefault().Id && d.TrnSalesInvoice.IsLocked == false && d.TrnSalesInvoice.IsCancelled == true select d; if (invalidSIs.Any()) { countInvalidSI = invalidSIs.Count(); } if (!collection.FirstOrDefault().IsLocked&& countInvalidSI == 0) { String oldObject = auditTrail.GetObjectString(collection.FirstOrDefault()); var lockCollection = collection.FirstOrDefault(); lockCollection.ORDate = Convert.ToDateTime(objCollection.ORDate); lockCollection.ManualORNumber = objCollection.ManualORNumber; lockCollection.CustomerId = objCollection.CustomerId; lockCollection.Particulars = objCollection.Particulars; lockCollection.CheckedById = objCollection.CheckedById; lockCollection.ApprovedById = objCollection.ApprovedById; lockCollection.Status = objCollection.Status; lockCollection.IsLocked = true; lockCollection.UpdatedById = currentUserId; lockCollection.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); if (lockCollection.IsLocked) { var collectionLines = from d in db.TrnCollectionLines where d.ORId == Convert.ToInt32(id) && d.SIId != null select d; if (collectionLines.Any()) { foreach (var collectionLine in collectionLines) { accountsReceivable.UpdateAccountsReceivable(Convert.ToInt32(collectionLine.SIId)); } } journal.InsertOfficialReceiptJournal(Convert.ToInt32(id)); } String newObject = auditTrail.GetObjectString(collection.FirstOrDefault()); auditTrail.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, oldObject, newObject); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Locking Error. These collection details are already locked or SI is invalid.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These collection details are not found in the server.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to lock collection.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this collection page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }