Example #1
0
        public IpermitPDFData(ImportPermit ipermit, LetterHeading letterHeading, Letter letter, string comment = null)
        {
            this.ipermitId         = ipermit.ID;
            this.company           = letterHeading.CompanyName;
            this.logoUrl           = letterHeading.LogoUrl;
            this.header            = letter.Title;
            this.address           = ipermit.Agent?.Address?.City;
            this.to                = ipermit.Agent?.Name;
            this.date              = DateTime.Now.ToString();
            this.body              = letter.Body;
            this.submissionDate    = ipermit.CreatedDate.ToString();
            this.applicationNumber = ipermit.ImportPermitNumber;
            this.totalPrice        = String.Format("{0:n2}", ipermit.Amount);
            this.shippingMethod    = ipermit.ShippingMethod.Name;
            this.delivery          = ipermit.Delivery;
            this.freight           = String.Format("{0:n2}", ipermit.FreightCost);
            this.insurance         = ipermit.Insurance != null?String.Format("{0:n2}", ipermit.Insurance) : "0";

            this.discount = ipermit.Discount != null?String.Format("{0:n2}", ipermit.Discount) : "0";

            this.comment               = ipermit.Remark;
            this.portOfEntry           = ipermit.PortOfEntry.Name;
            this.paymentMode           = ipermit.PaymentMode.Name;
            this.performaInvoiceNumber = ipermit.PerformaInvoiceNumber;
            this.fileName              = letter.ModuleDocument.DocumentType.Name + ".pdf";
            this.tempFolderName        = ipermit.RowGuid.ToString();
            this.rejectedDate          = ipermit.ImportPermitStatus.CreatedDate.ToString();
            this.approvedDate          = ipermit.ImportPermitStatus.CreatedDate.ToString();
            this.expiryDate            = ipermit.ImportPermitStatus.CreatedDate.ToString();
            this.currency              = ipermit.Currency?.Symbol;
            this.currencyName          = ipermit.Currency?.Name;
            this.items = ipermit.ImportPermitDetails.ToList().Select(d => new IpermitPDFDataDetail(d)).ToList();
        }
Example #2
0
        public async Task <bool> ChangeIPermitStatus(ImportStatusLog ipermit, ImportPermitStatuses status)
        {
            var toStatus = (await _importPermitStatus.GetAsync(s => s.ImportPermitStatusCode == status.ToString()));

            var iimport = await base.GetAsync(ipermit.ID);

            var fromId = iimport.ImportPermitStatusID;

            iimport.ImportPermitStatusID = toStatus.ID;

            if (toStatus.ImportPermitStatusCode == "APR")
            {
                iimport.ExpiryDate = await GetExpiryDate(iimport.SupplierID, iimport.ImportPermitDetails);
            }
            var originaliimport = new ImportPermit();

            originaliimport.CopyProperties(iimport);

            //users for notification
            var users = new List <User> ()
            {
                originaliimport.User
            };

            if (toStatus.ImportPermitStatusCode == "RQST")
            {
                iimport.RequestedDate = DateTime.UtcNow;
                var cst = (await _userRoleService.FindByAsync(us => us.Role.RoleCode == "CST" && us.IsActive && us.User.IsActive)).Select(u => u.User);
                users.AddRange(cst);
            }

            var resultUpdate = await base.UpdateAsync(iimport);

            var result = false;

            if (resultUpdate)
            {
                var importLog = new ImportPermitLogStatus()
                {
                    FromStatusID     = fromId,
                    ToStatusID       = toStatus.ID,
                    IsCurrent        = true,
                    Comment          = ipermit.Comment,
                    ModifiedByUserID = ipermit.ChangedBy,
                    ImportPermitID   = ipermit.ID
                };

                result = await _importLog.CreateAsync(importLog);
            }
            if (resultUpdate && result)
            {
                Notify(toStatus.ImportPermitStatusCode, toStatus.Name, iimport.ImportPermitNumber, users);
            }

            return(resultUpdate && result);
        }
Example #3
0
        public async Task <bool> AssignImportPermitAsync(ImportPermit importPermit)
        {
            var savedImportPermit = await GetAsync(importPermit.ID);

            var result = await UpdateAsync(importPermit);

            //Notify to assigned cso
            if (result && importPermit.AssignedUserID != null && savedImportPermit.AssignedUserID != importPermit.AssignedUserID)
            {
                var assignedUser = await _userService.GetAsync((int)importPermit.AssignedUserID);

                var users = new List <User> ()
                {
                    assignedUser
                };
                var pushNotifier = _notificationFactory.GetNotification(NotificationType.PUSHNOTIFICATION);
                await pushNotifier.Notify(users, new { body = string.Format("Import Permit with number of {0} has been assigned to you.", importPermit.ImportPermitNumber), subject = "Import Permit Assigned" }, "IPSC");
            }

            return(result);
        }
Example #4
0
        public async Task GeneratePDFDocument(string htmlFilePath, ImportStatusLog ipermit, INodeServices nodeServices, string documenttypeCode, string submoduleCode, ImportPermit iipermit)
        {
            try {
                var letterHeading = await _letterHeadingService.GetAsync(1);

                var letter         = (await _letterService.GetAsync(x => x.ModuleDocument.DocumentType.DocumentTypeCode == documenttypeCode && x.ModuleDocument.Submodule.SubmoduleCode == submoduleCode));
                var moduleDocument = await _moduleDocumentService.GetAsync(letter.ModuleDocumentID);

                var moduleCode = moduleDocument.Submodule.Module.ModuleCode;

                IpermitPDFData data          = new IpermitPDFData(iipermit, letterHeading, letter, ipermit.Comment);
                var            ipemitStatues = (await _statusService.GetIPermitStatus(iipermit.ID));

                data.submissionDate = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "RQST")?.CreatedDate.ToString();
                data.approvedDate   = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "APR")?.CreatedDate.ToString();
                data.rejectedDate   = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "REJ")?.CreatedDate.ToString();
                data.expiryDate     = iipermit.ExpiryDate?.ToString();;
                data.reason         = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "REJ")?.Comment;

                var htmlString = string.Join(" ", System.IO.File.ReadAllLines(htmlFilePath));
                htmlString = buildCSS(htmlString);

                var pdfPath = $".{Path.DirectorySeparatorChar}external{Path.DirectorySeparatorChar}js{Path.DirectorySeparatorChar}pdf";

                var result = await nodeServices.InvokeAsync <byte[]> (pdfPath, htmlString, data);

                var relativeDirectory = $"{Path.DirectorySeparatorChar}{moduleCode}{Path.DirectorySeparatorChar}{data.tempFolderName}";
                var directory         = $"{_rootUrl}{relativeDirectory}";
                var filePath          = $"{relativeDirectory}{Path.DirectorySeparatorChar}{data.fileName}";

                await FileHelper.SaveFileAsync(directory, data.fileName, result);

                Domain.Document.Document docEntity = new Domain.Document.Document()
                {
                    ModuleDocumentID = letter.ModuleDocumentID,
                    FilePath         = filePath,
                    FileType         = "application/pdf",
                    ReferenceID      = ipermit.ID,
                    CreatedBy        = ipermit.ChangedBy,
                    UpdatedBy        = ipermit.ChangedBy
                };
                await _documentService.CreateOrUpdateAsync(docEntity, true, r => r.ModuleDocumentID == docEntity.ModuleDocumentID && r.FilePath == docEntity.FilePath && r.ReferenceID == docEntity.ReferenceID);
            } catch (Exception ex) {
                _logger.Log(ex);
            }
        }