Sent PDF from consensus Form

Jira Code: MBS 13

On the consensus form, the user will select any number of rows from the List and click one of the Send E-mail buttons. Send E-mail button will send an e-mail to the selected rows with a PDF attachment.

Schedule script (MBS 13 SS JJ Send mail)

/**
 * @NApiVersion 2.x
 * @NScriptType ScheduledScript
 * @NModuleScope SameAccount
 */
/*******************************************************************************
 * CLIENTNAME:Moneta Business Solutions MBS -11 Create a SL for showing results
 * of SS "BA-BS Formu" ID:46
 * ************************************************************************ Date :
 * 12/02/2019
 * 
 * Author: Jobin & Jismi IT Services LLP Script Description : This is to Create
 * a SL for showing results of SS "BA-BS Formu" ID:46 Date created : 08/02/2019
 * 
 * REVISION HISTORY
 * 
 * Revision 1.0 ${12/02/2019} aj : created
 * 
 * 
 ******************************************************************************/
define(['N/email', 'N/record', 'N/search', 'N/runtime', 'N/render','N/file','N/config'],
/**
 * @param {email} email
 * @param {record} record
 * @param {search} search
 */
function(email, record, search,runtime,render,file,config) {
   
    /**
     * Definition of the Scheduled script trigger point.
     *
     * @param {Object} scriptContext
     * @param {string} scriptContext.type - The context in which the script is executed. It is one of the values from the scriptContext.InvocationType enum.
     * @Since 2015.2
     */
    function execute(scriptContext) {
    	try{
    		// to get the parameter
    		 var returnObj = runtime.getCurrentScript().getParameter("custscript_object");
    			
				returnObj = JSON.parse(returnObj);
				
				
					// to get the each files
					for(var key in returnObj)
						{
						
						//to set the PDF
						var name  = returnObj[key].name;
						var emailToSend = returnObj[key].email;
						var bsAmount = returnObj[key].bsAmount;
						var baAmount = returnObj[key].baAmount;
						var bsDocCount = returnObj[key].bsDocCount;
						var baDocCount = returnObj[key].baDocCount;
						var taxAdmin = returnObj[key].taxAdmin;
						var stringDate = returnObj[key].stringDate;
						// to set 
					var XML=getXMLContents(taxAdmin,baDocCount,bsDocCount,baAmount,bsAmount,name,stringDate);
					
		
                      
					// to render
					var pdfFile = render.xmlToPdf({
					    xmlString: XML
					});
					var aa = email.send({
					    author: -5,
                   recipients:emailToSend,
					    subject: 'BA- BS Forms',
					    body: 'Hi '+name+' ,Attached are BA BS Data',
					    attachments: [pdfFile]
					    
					});
					log.debug("send mail=",emailToSend);
			
					
					
						}
					
			
             
    		
    	}catch(e)
    	{
    		log.debug("Err@ Execute FN ",e);
    		
    	}

    }
    
    /****************************************************
	 * Function to get XML Contents
	 ****************************************************/
	function getXMLContents(taxAdmin,baDocCount,bsDocCount,baAmount,bsAmount,name,stringDate)
	{
		try{
			
		
			var XML='';
			XML = XML+'<pdf>'+
			'        <head>'+
			'    <style>'+
			'        .normalParagraph{'+
			'            '+
			'            font-size: 16px;'+
			'        }'+
			'         .boldParagraph{'+
			'            font-weight: bold;'+
			'            font-size: 16px;'+
			'        }'+
			'        table, th, td {'+
			'    border: 1px solid #6f6d6d;'+
			'                border-collapse: collapse;'+
			'}'+
			'        .with-no-border{'+
			'           border:0px;'+
			'            border-collapse: collapse;'+
			'        }'+
			'    </style>'+'             <macrolist>'+
			'        <macro id="nlheader">'+
			'            '+
			'<table class="with-no-border" data-page="1" data-table="1" border="0" style="align:left" width="100%" height="30%">'+
			' <tr  class="with-no-border" ><td  class="with-no-border" colspan="2" style="font-weight: bold;font-size: 18px;font-style:italic" >'+
			' Ba Bs<br />MutakabatMektubu'+
			'                '+
			'     </td>'+
			'        '+
			'        '+
			'    <td  class="with-no-border" >'+
			'        <img src="https://system.eu2.netsuite.com/core/media/media.nl?id=2424&c=4977528&h=8b9a72108b24a8eea071" />'+
			'        </td> </tr>'+
			'        <tr  class="with-no-border" >'+
			'        <td  class="with-no-border" >'+
			'            <p style="font-size: 16px;"> Tarih: '+stringDate+'</p>'+
			'        </td>'+
			'        </tr>'+
			'</table>'+
			'        </macro>'+
			'        </macrolist>'+
			'    </head>'+
			'    <body  header="nlheader" header-height="13.5%" >'+
			'    '+
			'  <p class="boldParagraph"> Konu  :  213  Sayılı  VUK un  362  Sıra  Nolu  Genel  Tebliği  Kapsamında  Bildirilmesi  Gereken  Form  Ba  ve  Form  BsMutabakatı Hk</p>'+
			'        <p class="normalParagraph">Firma Unvanı:'+escape_for_xml(name)+'</p>'+
			'    '+
			'        <p class="normalParagraph"> <b>Ekim</b> ayına ait Ba ve Bs formlarında karşılıklı mutabakatın sağlanması açısından firmanıza ait Alış ve Satışlarınıza ilişkinform bilgilerimiz aşağıda sunulmuştur. Konu ile ilgili durumunuzu bu mektubun alt kısmını onaylayarak tarafımıza faksgönderilmesini, eğer mutabık değilseniz Firmanız kayıtlarında gözüken fatura adedini ve faturaların toplam tutarını yazaraktarafımıza en kısa sürede göndermenizi rica ederiz.</p> '+
			'        <p class="normalParagraph">Saygılarımızla,</p>'+
			'    '+
			'            <p class="normalParagraph">Kaşe İmza</p>   '+
			'     '+
			'    <p><strong>Ba (Mal veya Hizmet Alımı) Formu Bilgilerimiz :</strong></p>'+
			'        <table style="border-style: solid;border-color: black">'+
			'            <tr>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                Soyadı/Adı veya Unvanı'+
			'                </td>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                    Vergi/T.C. Kimlik No'+
			'                </td>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                    Belge Adedi'+
			'                </td>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                    Toplam Bedeli  (KDVHariç)'+
			'                </td>'+
			'            </tr>'+
			'            <tr >'+
			'                <td>'+
			escape_for_xml(name)+
			'                </td>'+
			'                <td>'+
			taxAdmin+
			'                </td>'+
			'                <td>'+
			baDocCount+
			'                </td>'+
			'                <td>'+
			baAmount+
			'                </td>'+
			'            </tr>'+
			'            '+
			'        </table>'+
			'        '+
			'        '+
			'         <p><strong>Bs (Mal veya Hizmet Satışı) Formu Bilgilerimiz :</strong></p>'+
			'        <table style="border-style: solid;border-color: black">'+
			'            <tr>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'               Soyadı/Adı veya Unvanı'+
			'                </td>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                    Vergi/T.C. Kimlik No'+
			'                </td>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                    Belge Adedi'+
			'                </td>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                    Toplam Bedeli  (KDVHariç)'+
			'                </td>'+
			'            </tr>'+
			'            <tr >'+
			'                <td>'+
			escape_for_xml(name)+
			'                </td>'+
			'                <td>'+
			taxAdmin+
			'                </td>'+
			'                <td>'+
			bsDocCount+
			'                </td>'+
			'                <td>'+
			bsAmount+
			'                </td>'+
			'            </tr>'+
			'            '+
			'        </table>'+
			'        '+
			'        <p>'+
			'        <br />'+
			'        </p>'+
			'        <table style="border-style: solid;">'+
			'            <tr>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                Mutabık '+
			'                </td>'+
			'                <td style="width:30px;font-weight: bold;font-size: 16px;">'+
			'                     '+
			'                </td>'+
			'            </tr>'+
			'            <tr>'+
			'                <td style="font-weight: bold;font-size: 16px;">'+
			'                    Mutabık Değiliz'+
			'                </td>'+
			'               '+
			'                <td style="width:30px;font-weight: bold;font-size: 16px;">'+
			'                  '+
			'                </td>'+
			'            </tr>'+
			'            '+
			'            '+
			'        </table>'+
			
			'        <br />'+
			'        <p><strong> Firma Kaşe-İmza</strong></p>'+
			''+
			'    '+
			'    </body>'+
			'    </pdf>';
				

			
			

			return XML;
			
			
		}catch(e)
		{
	log.debug("Err@ FN getXMLContents=",e);
		}
	}
/*******************************************************************
			 * Fix text
			 * 
			 * @param argument
			 * @returns Created By JJ on 15-Nov-2017 4:30:21 PM
			 */
			function escape_for_xml(argument) {

				try {

					if (argument != "" && argument != null) {
						/*var newString = xml.escape({
							xmlText : argument
						});*/

						argument = argument.replace(/&/g,'&');
						argument = argument.replace(/</g, '<');
						argument = argument.replace(/>/g, '>');
						argument = argument.replace(/"/g, '"');
						argument = argument.replace(/'/g, ''');
						return argument;
					} else {
						return "";
					}

				} catch (e) {
					log.debug({
						title : e.name,
						details : e.message
					});
				}

			}
    return {
        execute: execute
    };
    
});

Leave a comment

Your email address will not be published. Required fields are marked *