Пример #1
0
        public async Task <bool> CreateImportPermitAsync([FromBody] ImportPermitBusinessModel importPermit)
        {
            var result = await _service.CreateImportPermitAsync(importPermit);

            if (result && !importPermit.IsDraft)
            {
                var savedIPermit = await _service.GetAsync(i => i.RowGuid == importPermit.Identifier, true);

                var subFolder = savedIPermit.ImportPermitType.ImportPermitTypeCode == "PIP" ? "pip" : "ipermit";

                //Use a separate Template for Medical Device
                var fileName = savedIPermit.ImportPermitDetails.FirstOrDefault().Product.ProductType.ProductTypeCode == "MDS" ? "Submit-Medical-Device.html" : "Submit.html";
                var filePath = $".{Path.DirectorySeparatorChar}external{Path.DirectorySeparatorChar}templates{Path.DirectorySeparatorChar}{subFolder}{Path.DirectorySeparatorChar}{fileName}";

                var ipermit = new ImportStatusLog
                {
                    ID        = savedIPermit.ID,
                    ChangedBy = savedIPermit.CreatedByUserID,
                    Comment   = "New Import Permit Created"
                };
                var documentTypeCode = savedIPermit.ImportPermitType.ImportPermitTypeCode == "PIP" ? "PIPAK" : "ACKL";
                await _generateDocument.GeneratePDFDocument(filePath, ipermit, _nodeServices, documentTypeCode, importPermit.SubmoduleCode, savedIPermit);
            }
            return(result);
        }
Пример #2
0
        public async Task <bool> UpdateImportPermitAsync(ImportPermitBusinessModel ipermit)
        {
            var savedImportPermit = (await base.GetAsync(ipermit.ImportPermit.ID));

            ipermit.ImportPermit.Amount = ipermit.ImportPermit.FreightCost + (ipermit.ImportPermit.Insurance ?? 0) + (ipermit.ImportPermit.ImportPermitDetails.Sum(x => ((x.Quantity * x.UnitPrice) - (x.Discount ?? 0)))) - (ipermit.ImportPermit.Discount ?? 0);

            var result = await base.UpdateAsync(ipermit.ImportPermit);

            bool docResult = true, docUpdateResult = true, logStatus = true;

            if (result)
            {
                //Detach saved reference
                docUpdateResult = await _documentService.DetachDocumentReferenceAsync(ipermit.ImportPermit.ID);

                if (docUpdateResult)
                {
                    foreach (var doc in ipermit.Documents)
                    {
                        doc.ReferenceID = savedImportPermit.ID;
                        var savedDoc = await _documentService.GetAsync(doc.ID);

                        savedDoc.CopyProperties(doc);
                        docResult = docResult && await _documentService.UpdateAsync(savedDoc);
                    }
                }
            }

            return(result && docResult && docUpdateResult && logStatus);
        }
Пример #3
0
        public async Task <ApiResponse> CreateAutomaticImportPermitAsync([FromBody] ImportPermitBusinessModel importPermit)
        {
            var result = await _service.CreateAutomaticImportPermitAsync(importPermit, this.HttpContext.GetUserID());

            if (!result.IsSuccess || importPermit.IsDraft || importPermit.CurrentStatusCode == ImportPermitStatuses.SFA)
            {
                return(result);
            }

            var savedIPermit = importPermit.Identifier == Guid.Empty ? await _service.GetAsync(i => i.RowGuid == importPermit.ImportPermit.RowGuid, true) : await _service.GetAsync(i => i.RowGuid == importPermit.Identifier, true);

            var subFolder = savedIPermit.ImportPermitType.ImportPermitTypeCode == "PIP" ? "pip" : "ipermit";

            var ipermit = new ImportStatusLog
            {
                ID        = savedIPermit.ID,
                ChangedBy = savedIPermit.CreatedByUserID
            };

            var    productType = savedIPermit.ImportPermitDetails.FirstOrDefault().Product.ProductType;
            string filePath = "", fileName = "", documentTypeCode = "";

            switch (importPermit.CurrentStatusCode)
            {
            case ImportPermitStatuses.RQST:
                ipermit.Comment = "New Import Permit Created";
                //Use a separate Template for Medical Device
                fileName         = (productType != null && productType.ProductTypeCode == "MDS") ? "Submit-Medical-Device.html" : "Submit.html";
                documentTypeCode = savedIPermit.ImportPermitType.ImportPermitTypeCode == "PIP" ? "PIPAK" : "ACKL";
                break;

            case ImportPermitStatuses.APR:
                ipermit.Comment = "New Import Permit Approved Automatically";
                //Use a separate Template for Medical Device
                fileName         = (productType != null && productType.ProductTypeCode == "MDS") ? "Approve-Medical-Device.html" : "Approve.html";
                documentTypeCode = savedIPermit.ImportPermitType.ImportPermitTypeCode == "PIP" ? "PIPCR" : "POCR";
                break;
            }
            filePath = $".{Path.DirectorySeparatorChar}external{Path.DirectorySeparatorChar}templates{Path.DirectorySeparatorChar}{subFolder}{Path.DirectorySeparatorChar}{fileName}";
            await _generateDocument.GeneratePDFDocument(filePath, ipermit, _nodeServices, documentTypeCode, importPermit.SubmoduleCode, savedIPermit);

            return(result);
        }
Пример #4
0
        public async Task <ApiResponse> CreateAutomaticImportPermitAsync(ImportPermitBusinessModel importPermit, int createdBy)
        {
            var result = false;

            createdBy = importPermit.CurrentStatusCode == ImportPermitStatuses.RQST? createdBy: (int)(await _userRoleService.GetAsync(us => us.User.Username == _systemUser.Username))?.UserID;
            var ipermit = new ImportStatusLog()
            {
                ChangedBy = createdBy, ID = importPermit.ImportPermit.ID
            };
            var returnResponse = new ApiResponse();

            switch (importPermit.CurrentStatusCode)
            {
            case ImportPermitStatuses.RQST:
                result = await this.CreateImportPermitAsync(importPermit);

                returnResponse.Message = result? "Import Permit Created": "Unable to create Import Permit";
                break;

            case ImportPermitStatuses.SFA:
                ipermit.Comment = "Import Permit Automatically submitted For Approval";
                result          = await this.ChangeIPermitStatus(ipermit, ImportPermitStatuses.SFA);

                returnResponse.Message = result? "Import Permit Submitted For Approval": "Unable to submit Import Permit";
                break;

            case ImportPermitStatuses.APR:
                ipermit.Comment = "Import Permit Automatically Approved";
                result          = await this.ChangeIPermitStatus(ipermit, ImportPermitStatuses.APR);

                returnResponse.Message = result? "Import Permit Approved": "Unable to approve Import Permit";
                break;
            }
            var savedID           = importPermit.ImportPermit.ID != 0 ? importPermit.ImportPermit.ID : (await this.GetAsync(i => i.RowGuid == importPermit.Identifier, true))?.ID;
            var savedImportPermit = await this.GetImportPermitBusinessModel((int)savedID);

            returnResponse.IsSuccess  = result;
            returnResponse.StatusCode = result?StatusCodes.Status200OK : StatusCodes.Status400BadRequest;
            returnResponse.Result     = result? savedImportPermit : null;
            return(returnResponse);
        }
Пример #5
0
        public async Task <bool> UpdateImportPermitAsync([FromBody] ImportPermitBusinessModel importPermit)
        {
            var result = await _service.UpdateImportPermitAsync(importPermit);

            return(result);
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ipermit"></param>
        /// <returns></returns>
        public async Task <bool> CreateImportPermitAsync(ImportPermitBusinessModel ipermit)
        {
            //Calculate Amount from Details
            ipermit.ImportPermit.Amount = ipermit.ImportPermit.FreightCost + (ipermit.ImportPermit.Insurance ?? 0) + (ipermit.ImportPermit.ImportPermitDetails.Sum(x => ((x.Quantity * x.UnitPrice) - (x.Discount ?? 0)))) - (ipermit.ImportPermit.Discount ?? 0);

            string statusCode = ipermit.IsDraft ? "DRFT" : "RQST";
            var    status     = await _importPermitStatus.GetAsync(s => s.ImportPermitStatusCode == statusCode);

            ipermit.ImportPermit.ImportPermitStatusID = status.ID;
            ipermit.ImportPermit.RowGuid = ipermit.Identifier;

            //Set RequestedDate if application is not draft
            ipermit.ImportPermit.RequestedDate = ipermit.IsDraft ? (Nullable <DateTime>)null : DateTime.UtcNow;
            ipermit.ImportPermit.ExpiryDate    = await GetExpiryDate(ipermit.ImportPermit.SupplierID, ipermit.ImportPermit.ImportPermitDetails);

            ipermit.ImportPermit.CreatedDate = ipermit.ImportPermit.ModifiedDate = DateTime.UtcNow;

            //Set SubmoduleID for PIP Type
            var ipType = await _importPermitTypeService.GetAsync(ipermit.ImportPermit.ImportPermitTypeID);

            if (ipType.ImportPermitTypeCode == "PIP")
            {
                var agent = await _agentService.GetAsync(ipermit.ImportPermit.AgentID);

                var submodule = await _submoduleService.GetAsync(s => s.SubmoduleCode == agent.AgentType.AgentTypeCode);

                ipermit.ImportPermit.SubmoduleID = submodule?.ID;
            }

            var result = await base.CreateAsync(ipermit.ImportPermit);

            bool docResult = true, logStatus = true;

            if (result)
            {
                var savedImportPermit = (await base.GetAsync(ip => ip.RowGuid == ipermit.ImportPermit.RowGuid, true));
                foreach (var doc in ipermit.Documents)
                {
                    doc.ReferenceID = savedImportPermit.ID;
                    var savedDoc = await _documentService.GetAsync(doc.ID);

                    savedDoc.CopyProperties(doc);
                    docResult = docResult && await _documentService.UpdateAsync(savedDoc);
                }

                var importLog = new ImportPermitLogStatus()
                {
                    ToStatusID       = status.ID,
                    IsCurrent        = true,
                    Comment          = $"New {savedImportPermit.ImportPermitType.Name} Created",
                    ModifiedByUserID = savedImportPermit.CreatedByUserID,
                    ImportPermitID   = savedImportPermit.ID
                };

                logStatus = await _importLog.CreateAsync(importLog);

                //Send email
                if (!ipermit.IsDraft)
                {
                    //bring CST user
                    var cst   = (await _userRoleService.FindByAsync(us => us.Role.RoleCode == "CST" && us.IsActive)).Select(u => u.User).Where(u => u.IsActive);
                    var users = new List <User> ()
                    {
                        savedImportPermit.User
                    };
                    users.AddRange(cst);
                    Notify(savedImportPermit.ImportPermitStatus.ImportPermitStatusCode, savedImportPermit.ImportPermitStatus.Name, savedImportPermit.ImportPermitNumber, users);
                }

                //Delete Related WIP
                var wip = await _wipService.GetAsync(w => w.RowGuid == ipermit.Identifier);

                if (wip != null)
                {
                    await _wipService.DeleteAsync(wip.ID);
                }
            }
            return(result && docResult && logStatus);
        }