Ejemplo n.º 1
0
        private XsltArgumentList getXSLTArguments(PreviewTransformParams previewTransformParams,
                                                  List <Overdraft> overdrafts, List <PayrollCompanyConfiguration> payrollCompanyConfiguration,
                                                  PreviewTransformResultDetail previewTransformResultDetail,
                                                  string originalString, string stampingOriginalString)
        {
            var dateFormat        = new DateTimeUtil();
            var currencyConvert   = new CurrencyUtil();
            var catalogSatManager = new CatalogSATUtil(previewTransformParams.IdentityWorkID,
                                                       previewTransformParams.InstanceID, overdrafts, payrollCompanyConfiguration);

            //QRCode
            var qrData = base.GetQRCodeWithTemplate(new XMLGet(previewTransformResultDetail.XML));
            var qrCode = new QRutil().GetQRBase64(qrData, 20);

            XsltArgumentList xsltArgumentList = new XsltArgumentList();

            //default arguments - Logo
            xsltArgumentList.AddParam("logoCotorraTemplate", "", "data:image/png;base64," + GetLogoCotorra());

            xsltArgumentList.AddParam("overdraftID", "", previewTransformResultDetail.OverdraftID.ToString());

            //fiscal arguments
            xsltArgumentList.AddParam("cbbUriTemplate", "", !string.IsNullOrEmpty(qrCode) ? "data:image/png;base64," + qrCode : string.Empty);
            xsltArgumentList.AddParam("originalstring", "", !string.IsNullOrEmpty(originalString) ? originalString : string.Empty);
            xsltArgumentList.AddParam("stamporiginalstring", "", !string.IsNullOrEmpty(stampingOriginalString) ? stampingOriginalString : string.Empty);

            //object catalog argument
            xsltArgumentList.AddExtensionObject("urn:catalogSat", catalogSatManager);
            //object for convert total amount in words
            xsltArgumentList.AddExtensionObject("urn:convert", currencyConvert);
            xsltArgumentList.AddExtensionObject("urn:dateFormat", dateFormat);

            return(xsltArgumentList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transform overdraft to html - pdf
        /// </summary>
        /// <param name="previewTransformParams"></param>
        /// <returns></returns>
        public async Task <PreviewTransformResult> TransformAsync(PreviewTransformParams previewTransformParams)
        {
            //Get data to transform
            List <Overdraft> overdrafts = await getDataAsync(previewTransformParams);

            //Get payroll company configuration
            var payrollCompanyConfiguration = await getPayrollCompanyConfigurationAsync(previewTransformParams);

            //Download XML
            Dictionary <Guid, string> xmls = await getXMLAsync(previewTransformParams, overdrafts);

            var previewTransformResult = new PreviewTransformResult();
            var xsltUtil = new XsltUtil();
            var pdfUtil  = new PDFUtil();

            //Arrange
            var details = new ConcurrentBag <PreviewTransformResultDetail>();

            foreach (var previewTransformDetail in previewTransformParams.PreviewTransformParamsDetails)
            {
                var previewTransformResultDetail = new PreviewTransformResultDetail();

                //Get xml
                previewTransformDetail.Overdraft         = overdrafts.FirstOrDefault(p => p.ID == previewTransformDetail.OverdraftID);
                previewTransformResultDetail.OverdraftID = previewTransformDetail.OverdraftID;

                if (null == previewTransformDetail.Overdraft)
                {
                    throw new CotorraException(105, "105", "No se encontró el sobrerecibo proporcionado para generar su PDF.", null);
                }

                xmls.TryGetValue(previewTransformDetail.Overdraft.UUID, out string xml);
                previewTransformResultDetail.XML = xml;

                //Original strings
                (var originalString, var stampingOriginalString) = getOriginalStrings(xml);

                var xsltArgumentList = getXSLTArguments(previewTransformParams, overdrafts, payrollCompanyConfiguration,
                                                        previewTransformResultDetail, originalString, stampingOriginalString);

                //Transform HTML
                var htmlResult = xsltUtil.Transform(previewTransformResultDetail.XML, XsltPath, xsltArgumentList);

                //Transform PDF
                var pdfResult = pdfUtil.Convert(htmlResult);

                //Fill the result
                previewTransformResultDetail.TransformHTMLResult = htmlResult;
                previewTransformResultDetail.TransformPDFResult  = pdfResult;

                details.Add(previewTransformResultDetail);
            }
            //Fill the list
            previewTransformResult.PreviewTransformResultDetails.AddRange(details);

            return(previewTransformResult);
        }