Example #1
0
        private ReconcileDocument GetReconcileDocument(ReconcileDocument request)
        {
            var id = request?.Id;
            ReconcileDocument ret = null;
            var query             = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <ReconcileDocument>(currentUser, "ReconcileDocument", request.Select);

            DocEntityReconcileDocument entity = null;

            if (id.HasValue)
            {
                entity = DocEntityReconcileDocument.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No ReconcileDocument found for Id {id.Value}");
            }

            if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route.");
            }

            ret = entity?.ToDto();
            return(ret);
        }
Example #2
0
        public ReconcileDocument Post(ReconcileDocument request)
        {
            if (request == null)
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be null.");
            }

            request.Select = request.Select ?? new List <string>();

            ReconcileDocument ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!DocPermissionFactory.HasPermissionTryAdd(currentUser, "ReconcileDocument"))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    ret = _AssignValues(request, DocConstantPermission.ADD, ssn);
                });
            }
            return(ret);
        }
Example #3
0
        public void Delete(ReconcileDocument request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityReconcileDocument.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No ReconcileDocument could be found for Id {request?.Id}.");
                    }
                    if (en.IsRemoved)
                    {
                        return;
                    }

                    if (!DocPermissionFactory.HasPermission(en, currentUser, DocConstantPermission.DELETE))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have DELETE permission for this route.");
                    }

                    en.Remove();

                    DocCacheClient.RemoveSearch(DocConstantModelName.RECONCILEDOCUMENT);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Example #4
0
        public ReconcileDocument Patch(ReconcileDocument request)
        {
            if (true != (request?.Id > 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the ReconcileDocument to patch.");
            }

            request.Select = request.Select ?? new List <string>();

            ReconcileDocument ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    ret = _AssignValues(request, DocConstantPermission.EDIT, ssn);
                });
            }
            return(ret);
        }
Example #5
0
        /// <summary>
        /// Save bank reconciliation
        /// </summary>
        public AjaxReturn ReconcileSave(ReconcileDocument json)
        {
            // Temporary indicates they haven't finished - no need to check balances, save Clr marks as "*" instead of "X"
            string  mark = json.Temporary ? "*" : "X";
            decimal bal  = json.header.OpeningBalance;

            Utils.Check(json.header.idAccount > 0, "Invalid account");
            Database.BeginTransaction();
            if (!json.Temporary)
            {
                Database.Audit(AuditType.Reconcile, "Reconciliation", json.header.idAccount, json.ToJson(), null);
            }
            Database.Execute("UPDATE Account SET EndingBalance = " + Database.Quote(json.Temporary ? json.header.EndingBalance : null)
                             + " WHERE idAccount = " + json.header.idAccount);
            foreach (ReconcileLine line in json.detail)
            {
                string mk;
                if (line.Cleared == "1" || line.Cleared == "*")
                {
                    bal += line.Amount;
                    mk   = mark;
                }
                else
                {
                    mk = "";
                }
                Database.Execute("UPDATE Journal SET Cleared = " + Database.Quote(mk) + " WHERE idJournal = " + line.idJournal);
            }
            Utils.Check(json.Temporary || json.header.EndingBalance != null, "You must enter an Ending Balance");
            Utils.Check(json.Temporary || bal == json.header.EndingBalance && bal == json.header.ClearedBalance, "Reconcile does not balance");
            Database.Commit();
            return(new AjaxReturn()
            {
                message = "Reconcile saved", redirect = json.print ? null : "/Banking/Detail?id=" + json.header.idAccount
            });
        }
Example #6
0
 /// <summary>
 /// Post bank reconciliation
 /// </summary>
 public AjaxReturn ReconcilePost(ReconcileDocument json)
 {
     // Temporary indicates they haven't finished - no need to check balances, save Clr marks as "*" instead of "X"
     string mark = json.Temporary ? "*" : "X";
     decimal bal = json.header.OpeningBalance;
     Utils.Check(json.header.idAccount > 0, "Invalid account");
     Database.BeginTransaction();
     if (!json.Temporary)
         Database.Audit(AuditType.Reconcile, "Reconciliation", json.header.idAccount, json.ToJson(), null);
     Database.Execute("UPDATE Account SET EndingBalance = " + Database.Quote(json.Temporary ? json.header.EndingBalance : null)
         + " WHERE idAccount = " + json.header.idAccount);
     foreach (ReconcileLine line in json.detail) {
         string mk;
         if (line.Cleared == "1" || line.Cleared == "*") {
             bal += line.Amount;
             mk = mark;
         } else {
             mk = "";
         }
         Database.Execute("UPDATE Journal SET Cleared = " + Database.Quote(mk) + " WHERE idJournal = " + line.idJournal);
     }
     Utils.Check(json.Temporary || json.header.EndingBalance != null, "You must enter an Ending Balance");
     Utils.Check(json.Temporary || bal == json.header.EndingBalance && bal == json.header.ClearedBalance, "Reconcile does not balance");
     Database.Commit();
     return new AjaxReturn() { message = "Reconcile saved", redirect = json.print ? null : "/Banking/Detail?id=" + json.header.idAccount };
 }
Example #7
0
 public ReconcileDocument Put(ReconcileDocument request)
 {
     return(Patch(request));
 }
Example #8
0
        public ReconcileDocument Post(ReconcileDocumentCopy request)
        {
            ReconcileDocument ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityReconcileDocument.Get(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pArticleId = entity.ArticleId;
                    if (!DocTools.IsNullOrEmpty(pArticleId))
                    {
                        pArticleId += " (Copy)";
                    }
                    var pArticleLink = entity.ArticleLink;
                    if (!DocTools.IsNullOrEmpty(pArticleLink))
                    {
                        pArticleLink += " (Copy)";
                    }
                    var pAssignee    = entity.Assignee;
                    var pData        = entity.Data;
                    var pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pDocument   = entity.Document;
                    var pDueDate    = entity.DueDate;
                    var pMatches    = entity.Matches;
                    var pReporter   = entity.Reporter;
                    var pSearchLink = entity.SearchLink;
                    if (!DocTools.IsNullOrEmpty(pSearchLink))
                    {
                        pSearchLink += " (Copy)";
                    }
                    var pStatus   = entity.Status;
                    var pType     = entity.Type;
                    var pWorkflow = entity.Workflow;
                    var copy      = new DocEntityReconcileDocument(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , ArticleId   = pArticleId
                        , ArticleLink = pArticleLink
                        , Assignee    = pAssignee
                        , Data        = pData
                        , Description = pDescription
                        , Document    = pDocument
                        , DueDate     = pDueDate
                        , Matches     = pMatches
                        , Reporter    = pReporter
                        , SearchLink  = pSearchLink
                        , Status      = pStatus
                        , Type        = pType
                        , Workflow    = pWorkflow
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
Example #9
0
        private ReconcileDocument _AssignValues(ReconcileDocument request, DocConstantPermission permission, Session session)
        {
            if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No record");
            }

            if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "ReconcileDocument"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            ReconcileDocument ret = null;

            request = _InitAssignValues <ReconcileDocument>(request, permission, session);
            //In case init assign handles create for us, return it
            if (permission == DocConstantPermission.ADD && request.Id > 0)
            {
                return(request);
            }

            var cacheKey = GetApiCacheKey <ReconcileDocument>(DocConstantModelName.RECONCILEDOCUMENT, nameof(ReconcileDocument), request);

            //First, assign all the variables, do database lookups and conversions
            var pArticleId   = request.ArticleId;
            var pArticleLink = request.ArticleLink;
            var pAssignee    = DocEntityUser.Get(request.Assignee?.Id, true, Execute) ?? DocEntityUser.Get(request.AssigneeId, true, Execute);
            var pData        = request.Data;
            var pDescription = request.Description;
            var pDocument    = DocEntityDocument.Get(request.Document?.Id, true, Execute) ?? DocEntityDocument.Get(request.DocumentId, true, Execute);
            var pDueDate     = request.DueDate;
            var pMatches     = request.Matches;
            var pReporter    = DocEntityUser.Get(request.Reporter?.Id, true, Execute) ?? DocEntityUser.Get(request.ReporterId, true, Execute);
            var pSearchLink  = request.SearchLink;
            var pStatus      = request.Status;
            var pType        = request.Type;
            var pWorkflow    = DocEntityWorkflow.Get(request.Workflow?.Id, true, Execute) ?? DocEntityWorkflow.Get(request.WorkflowId, true, Execute);
            var pArchived    = true == request.Archived;
            var pLocked      = request.Locked;

            var entity = InitEntity <DocEntityReconcileDocument, ReconcileDocument>(request, permission, session);

            if (AllowPatchValue <ReconcileDocument, bool>(request, DocConstantModelName.RECONCILEDOCUMENT, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <ReconcileDocument, string>(request, DocConstantModelName.RECONCILEDOCUMENT, pArticleId, permission, nameof(request.ArticleId), pArticleId != entity.ArticleId))
            {
                entity.ArticleId = pArticleId;
            }
            if (AllowPatchValue <ReconcileDocument, string>(request, DocConstantModelName.RECONCILEDOCUMENT, pArticleLink, permission, nameof(request.ArticleLink), pArticleLink != entity.ArticleLink))
            {
                entity.ArticleLink = pArticleLink;
            }
            if (AllowPatchValue <ReconcileDocument, DocEntityUser>(request, DocConstantModelName.RECONCILEDOCUMENT, pAssignee, permission, nameof(request.Assignee), pAssignee != entity.Assignee))
            {
                entity.Assignee = pAssignee;
            }
            if (AllowPatchValue <ReconcileDocument, string>(request, DocConstantModelName.RECONCILEDOCUMENT, pData, permission, nameof(request.Data), pData != entity.Data))
            {
                entity.Data = pData;
            }
            if (AllowPatchValue <ReconcileDocument, string>(request, DocConstantModelName.RECONCILEDOCUMENT, pDescription, permission, nameof(request.Description), pDescription != entity.Description))
            {
                entity.Description = pDescription;
            }
            if (AllowPatchValue <ReconcileDocument, DocEntityDocument>(request, DocConstantModelName.RECONCILEDOCUMENT, pDocument, permission, nameof(request.Document), pDocument != entity.Document))
            {
                entity.Document = pDocument;
            }
            if (AllowPatchValue <ReconcileDocument, DateTime?>(request, DocConstantModelName.RECONCILEDOCUMENT, pDueDate, permission, nameof(request.DueDate), pDueDate != entity.DueDate))
            {
                entity.DueDate = pDueDate;
            }
            if (AllowPatchValue <ReconcileDocument, int?>(request, DocConstantModelName.RECONCILEDOCUMENT, pMatches, permission, nameof(request.Matches), pMatches != entity.Matches))
            {
                if (null != pMatches)
                {
                    entity.Matches = (int)pMatches;
                }
            }
            if (AllowPatchValue <ReconcileDocument, DocEntityUser>(request, DocConstantModelName.RECONCILEDOCUMENT, pReporter, permission, nameof(request.Reporter), pReporter != entity.Reporter))
            {
                entity.Reporter = pReporter;
            }
            if (AllowPatchValue <ReconcileDocument, string>(request, DocConstantModelName.RECONCILEDOCUMENT, pSearchLink, permission, nameof(request.SearchLink), pSearchLink != entity.SearchLink))
            {
                entity.SearchLink = pSearchLink;
            }
            if (AllowPatchValue <ReconcileDocument, ReconciliationStatusEnm?>(request, DocConstantModelName.RECONCILEDOCUMENT, pStatus, permission, nameof(request.Status), pStatus != entity.Status))
            {
                if (null != pStatus)
                {
                    entity.Status = pStatus.Value;
                }
            }
            if (AllowPatchValue <ReconcileDocument, TaskTypeEnm?>(request, DocConstantModelName.RECONCILEDOCUMENT, pType, permission, nameof(request.Type), pType != entity.Type))
            {
                if (null != pType)
                {
                    entity.Type = pType.Value;
                }
            }
            if (AllowPatchValue <ReconcileDocument, DocEntityWorkflow>(request, DocConstantModelName.RECONCILEDOCUMENT, pWorkflow, permission, nameof(request.Workflow), pWorkflow != entity.Workflow))
            {
                entity.Workflow = pWorkflow;
            }
            if (request.Locked && AllowPatchValue <ReconcileDocument, bool>(request, DocConstantModelName.RECONCILEDOCUMENT, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.RECONCILEDOCUMENT);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <ReconcileDocument>(currentUser, nameof(ReconcileDocument), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.RECONCILEDOCUMENT);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.RECONCILEDOCUMENT, cacheExpires);

            return(ret);
        }
Example #10
0
 public object Get(ReconcileDocument request) => GetEntityWithCache <ReconcileDocument>(DocConstantModelName.RECONCILEDOCUMENT, request, GetReconcileDocument);