public HttpResponseMessage unlockCollection(String id, Models.TrnCollection collection) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var collections = from d in db.TrnCollections where d.Id == Convert.ToInt32(id) select d; if (collections.Any()) { var updateCollection = collections.FirstOrDefault(); updateCollection.IsLocked = false; updateCollection.UpdatedById = userId; updateCollection.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); journal.DeleteOfficialReceiptJournal(Convert.ToInt32(id)); UpdateARCollection(Convert.ToInt32(id)); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public HttpResponseMessage UnlockCollection(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().CanUnlock) { var collection = from d in db.TrnCollections where d.Id == Convert.ToInt32(id) select d; if (collection.Any()) { if (collection.FirstOrDefault().IsLocked) { var unlockCollection = collection.FirstOrDefault(); unlockCollection.IsLocked = false; unlockCollection.UpdatedById = currentUserId; unlockCollection.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); // =============================== // Journal and Accounts Receivable // =============================== Business.Journal journal = new Business.Journal(); if (!unlockCollection.IsLocked) { journal.DeleteOfficialReceiptJournal(Convert.ToInt32(id)); UpdateAccountsReceivable(Convert.ToInt32(id)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Unlocking Error. These collection details are already unlocked.")); } } 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 unlock 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 AddFolderMonitoringCollection(List <Entities.FolderMonitoringTrnCollection> folderMonitoringTrnCollectionObjects) { try { if (folderMonitoringTrnCollectionObjects.Any()) { foreach (var folderMonitoringTrnCollectionObject in folderMonitoringTrnCollectionObjects) { Boolean isBranchExist = false, isCustomerExist = false, isUserExist = false, isAccountExist = false, isArticleExist = false, isSalesInvoiceExist = false, isPayTypeExist = false, isDepositoryBankExist = false; IQueryable <Data.TrnSalesInvoice> salesInvoice = null; var branch = from d in db.MstBranches where d.BranchCode.Equals(folderMonitoringTrnCollectionObject.BranchCode) select d; if (branch.Any()) { isBranchExist = true; if (!folderMonitoringTrnCollectionObject.SINumber.Equals("") || !folderMonitoringTrnCollectionObject.SINumber.Equals("NA")) { salesInvoice = from d in db.TrnSalesInvoices where d.BranchId == branch.FirstOrDefault().Id&& d.SINumber.Equals(folderMonitoringTrnCollectionObject.SINumber) && d.IsLocked == true select d; if (salesInvoice.Any()) { isSalesInvoiceExist = true; } } } var customer = from d in db.MstArticles where d.ArticleTypeId == 2 && d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.CustomerCode) && d.IsLocked == true select d; if (customer.Any()) { isCustomerExist = true; } var user = from d in db.MstUsers where d.UserName.Equals(folderMonitoringTrnCollectionObject.UserCode) select d; if (user.Any()) { isUserExist = true; } List <easyfis.Entities.MstArticle> listArticles = new List <easyfis.Entities.MstArticle>(); var account = from d in db.MstAccounts where d.AccountCode.Equals(folderMonitoringTrnCollectionObject.AccountCode) select d; if (account.Any()) { isAccountExist = true; var accountArticleTypes = from d in db.MstAccountArticleTypes where d.AccountId == Convert.ToInt32(account.FirstOrDefault().Id) select d; if (accountArticleTypes.Any()) { foreach (var accountArticleType in accountArticleTypes) { var articles = from d in db.MstArticles where d.ArticleTypeId == accountArticleType.ArticleTypeId && d.IsLocked == true select d; if (articles.Any()) { foreach (var articleObject in articles) { listArticles.Add(new easyfis.Entities.MstArticle() { Id = articleObject.Id, ManualArticleCode = articleObject.ManualArticleCode, Article = articleObject.Article }); } } } } } var article = from d in listArticles where d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.ArticleCode) select d; if (article.Any()) { isArticleExist = true; } var payType = from d in db.MstPayTypes where d.PayType.Equals(folderMonitoringTrnCollectionObject.PayType) select d; if (payType.Any()) { isPayTypeExist = true; } var depositoryBank = from d in db.MstArticles where d.ArticleTypeId == 5 && d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.DepositoryBankCode) select d; if (depositoryBank.Any()) { isDepositoryBankExist = true; } if (isBranchExist && isCustomerExist && isUserExist && isAccountExist && isArticleExist && isPayTypeExist && isDepositoryBankExist) { Int32 ORId = 0; var currentCollection = from d in db.TrnCollections where d.BranchId == branch.FirstOrDefault().Id&& d.ManualORNumber.Equals(folderMonitoringTrnCollectionObject.ManualORNumber) && d.IsLocked == true select d; if (currentCollection.Any()) { ORId = currentCollection.FirstOrDefault().Id; var unlockCollection = currentCollection.FirstOrDefault(); unlockCollection.IsLocked = false; unlockCollection.UpdatedById = user.FirstOrDefault().Id; unlockCollection.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime); db.SubmitChanges(); journal.DeleteOfficialReceiptJournal(ORId); } else { var defaultORNumber = "0000000001"; var lastCollection = from d in db.TrnCollections.OrderByDescending(d => d.Id) where d.BranchId == branch.FirstOrDefault().Id select d; if (lastCollection.Any()) { var ORNumber = Convert.ToInt32(lastCollection.FirstOrDefault().ORNumber) + 0000000001; defaultORNumber = FillLeadingZeroes(ORNumber, 10); } Data.TrnCollection newCollection = new Data.TrnCollection { BranchId = branch.FirstOrDefault().Id, ORNumber = defaultORNumber, ORDate = Convert.ToDateTime(folderMonitoringTrnCollectionObject.ORDate), ManualORNumber = folderMonitoringTrnCollectionObject.ManualORNumber, CustomerId = customer.FirstOrDefault().Id, Particulars = folderMonitoringTrnCollectionObject.Remarks, PreparedById = user.FirstOrDefault().Id, CheckedById = user.FirstOrDefault().Id, ApprovedById = user.FirstOrDefault().Id, Status = null, IsCancelled = false, IsPrinted = false, IsLocked = false, CreatedById = user.FirstOrDefault().Id, CreatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime), UpdatedById = user.FirstOrDefault().Id, UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime) }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); ORId = newCollection.Id; } Int32?SIId = null; if (isSalesInvoiceExist) { SIId = salesInvoice.FirstOrDefault().Id; } Data.TrnCollectionLine newCollectionLine = new Data.TrnCollectionLine { ORId = ORId, BranchId = branch.FirstOrDefault().Id, AccountId = account.FirstOrDefault().Id, ArticleId = article.FirstOrDefault().Id, SIId = SIId, Particulars = folderMonitoringTrnCollectionObject.Particulars, Amount = folderMonitoringTrnCollectionObject.Amount, PayTypeId = payType.FirstOrDefault().Id, CheckNumber = folderMonitoringTrnCollectionObject.CheckNumber, CheckDate = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CheckDate), CheckBank = folderMonitoringTrnCollectionObject.CheckBank, DepositoryBankId = depositoryBank.FirstOrDefault().Id, IsClear = folderMonitoringTrnCollectionObject.IsClear }; db.TrnCollectionLines.InsertOnSubmit(newCollectionLine); db.SubmitChanges(); var collection = from d in db.TrnCollections where d.Id == ORId && d.IsLocked == false select d; if (collection.Any()) { var lockCollection = collection.FirstOrDefault(); lockCollection.IsLocked = true; lockCollection.UpdatedById = user.FirstOrDefault().Id; lockCollection.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime); db.SubmitChanges(); var collectionLines = from d in lockCollection.TrnCollectionLines where d.SIId != null select d; if (collectionLines.Any()) { foreach (var collectionLine in collectionLines) { accountsReceivable.UpdateAccountsReceivable(Convert.ToInt32(collectionLine.SIId)); } } journal.InsertOfficialReceiptJournal(ORId); } } } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No data found.")); } } catch (Exception ex) { Debug.WriteLine(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public HttpResponseMessage UnlockCollection(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().CanUnlock) { var collection = from d in db.TrnCollections where d.Id == Convert.ToInt32(id) select d; if (collection.Any()) { if (!collection.FirstOrDefault().IsCancelled) { if (collection.FirstOrDefault().IsLocked) { String oldObject = auditTrail.GetObjectString(collection.FirstOrDefault()); var unlockCollection = collection.FirstOrDefault(); unlockCollection.IsLocked = false; unlockCollection.UpdatedById = currentUserId; unlockCollection.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); if (!unlockCollection.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.DeleteOfficialReceiptJournal(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, "Unlocking Error. These collection details are already unlocked.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Unlocking Error. These collection details are already cancelled.")); } } 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 unlock 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.")); } }