Delivery challan print from Sales order.

Jira Code: ME-189

Customized solution for printing the delivery challan from the sales order record using a custom button. The delivery challan print out looks exactly like packing slip which will be printed after the item fulfilment is created.

XML Template

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
	<link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
	<#if .locale == "zh_CN">
		<link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
	<#elseif .locale == "zh_TW">
		<link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
	<#elseif .locale == "ja_JP">
		<link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
	<#elseif .locale == "ko_KR">
		<link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
	<#elseif .locale == "th_TH">
		<link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
	</#if>
    <macrolist>
        <macro id="nlheader">
            <table class="header" style="width: 100%; font-size: 10pt;"><tr>
	  <td align="left"> <img src="https://system.netsuite.com/core/media/media.nl?id=4406&c=5318034_SB1&h=d6cfe6693b342d031655" style="padding-left:-5px;width:220px;height:80px;padding-top:-10px;padding-left:2px;" />
       <p align="left" font-size="9" style="padding-top:-5px;padding-left:6px;"><b>${companyInformation.companyName}</b></p>
	<p align="left" font-size="9" style="padding-top:-10px;padding-left:6px;
">1826/II/23 New Amarnath Building</p>

	<p align="left" font-size="9" style="padding-top:-10px;padding-left:6px;
">Bhagirath Palace</p>

	<p align="left" font-size="9" style="padding-top:-10px;padding-left:6px;
">Chandni Chowk Delhi 110006</p>

	<p align="left" font-size="9" style="padding-top:-10px;padding-left:6px;
">India</p>

	<p align="left" font-size="9" style="padding-top:-10px;padding-left:6px;
"><b>GSTIN:</b> 07AAJPK0556E1ZX</p>

	<p align="left" font-size="9" style="padding-top:-10px;padding-left:6px;
"><b>State Code:</b> 07</p>
       <p align="left" font-size="9" style="padding-top:-10px;padding-left:6px;"><b>Email:</b> sales@manglamelectricals.com</p>
	</td>
	<td align="right"><span class="title">DELIVERY CHALLAN</span></td>
	</tr>
	<tr>
    <td align="right" font-size="10">
<!-- <p>Your Order Ref. :${record.tranid}</p>
         <p>PO Date  :${record.tranid}</p> <p>Gross Weight :${record.tranid}</p>
         <p>Net Weight :${record.tranid}</p>-->
      </td> </tr>
	</table>
        </macro>
        <macro id="nlfooter">
            <table width="100%" class="footer"><tr>
	<td align="right"><pagenumber/> of <totalpages/></td>
	</tr></table>
        </macro>
    </macrolist>
    <style type="text/css">* {
		<#if .locale == "zh_CN">
			font-family: NotoSans, NotoSansCJKsc, sans-serif;
		<#elseif .locale == "zh_TW">
			font-family: NotoSans, NotoSansCJKtc, sans-serif;
		<#elseif .locale == "ja_JP">
			font-family: NotoSans, NotoSansCJKjp, sans-serif;
		<#elseif .locale == "ko_KR">
			font-family: NotoSans, NotoSansCJKkr, sans-serif;
		<#elseif .locale == "th_TH">
			font-family: NotoSans, NotoSansThai, sans-serif;
		<#else>
			font-family: NotoSans, sans-serif;
		</#if>
		}
		table {
			font-size: 9pt;
			table-layout: fixed;
		}
        th {
            font-weight: bold;
            font-size: 8pt;
            vertical-align: middle;
            padding: 5px 6px 3px;
            background-color: #e3e3e3;
            color: #333333;
        }
        td {
            padding: 4px 6px;
        }
		td p { align:left }
        b {
            font-weight: bold;
            color: #333333;
        }
        table.header td {
            padding: 0;
            font-size: 10pt;
        }
        table.footer td {
            padding: 0;
            font-size: 8pt;
        }
        table.itemtable th {
            padding-bottom: 10px;
            padding-top: 10px;
        }
        table.body td {
            padding-top: 2px;
        }
        td.addressheader {
            font-size: 8pt;
            font-weight: bold;
            padding-top: 6px;
            padding-bottom: 2px;
        }
        td.address {
            padding-top: 0;
        }
        span.title {
            font-size: 28pt;
        }
        span.number {
            font-size: 16pt;
        }
        span.itemname {
            font-weight: bold;
            line-height: 150%;
        }
        div.returnform {
            width: 100%;
            /* To ensure minimal height of return form */
            height: 200pt;
            page-break-inside: avoid;
            page-break-after: avoid;
        }
        hr {
            border-top: 1px dashed #d3d3d3;
            width: 100%;
            color: #ffffff;
            background-color: #ffffff;
            height: 1px;
        }
</style>
</head>
<body header="nlheader" header-height="22%" footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
  
    <table style="width: 100%; margin-top: 10px;"><tr>
	<td class="addressheader">${salesorder.shipaddress@label}</td>
	<td class="addressheader">${salesorder.billaddress@label}</td>
	</tr>
	<tr>
	<td class="address">${salesorder.custbody_jj_assembler.shipaddress}</td>
	<td class="address">${salesorder.custbody_jj_assembler.billaddress}</td>
	</tr></table>
<table class="body" style="width: 100%; margin-top: 10px;"><tr>
	<th>Your PO Ref.</th>
	<th>PO Date </th>
	<th>Gross Weight</th>
  <th>Net Weight</th>

	</tr>
	<tr>
	<td>${salesorder.otherrefnum}</td>
	<td>${salesorder.custbody3}</td>
	<td>${salesorder.custbody4}</td>
    <td>${salesorder.custbody5}</td>
	</tr></table>
<p style="font-size: 8pt;">Tracking No.:${salesorder.custbody_jj_tracking_no}</p>
<#if salesorder.item?has_content>

<table class="itemtable" style="width: 100%; margin-top: 10px;">
<thead>
	<tr>
      <th colspan="12">Item Description</th>
	<th colspan="3">Quantity</th>
	<th colspan="3">UOM</th>
	<th  colspan="3">${salesorder.item[0].quantity@label}</th>
	</tr>
</thead>
<#list salesorder.item as tranline>

 <#if tranline.custcol_jj_substitute_item?contains("Yes")> <tr>
	<td colspan="12"><span class="itemname">${tranline.custcol_jj_me102_substitute_item}</span><#if tranline.inventorydetail?has_content ><br/>${tranline.inventorydetail}</#if><br />${tranline.custcol_jj_me102_substitute_item_des}</td>
	<td colspan="3">${tranline.quantity}</td>
	<td colspan="3">${tranline.units}</td>
	<td colspan="3">${tranline.quantity}</td>
      </tr><#else>
  <tr>
    <td colspan="12"><span class="itemname"><#if tranline.item?has_content>${tranline.item}<#else>${tranline.item}</#if></span><#if tranline.inventorydetail?has_content ><br/>${tranline.inventorydetail}</#if><br />${tranline.description}</td>
	<td colspan="3">${tranline.quantity}</td>
	<td colspan="3">${tranline.units}</td>
	<td colspan="3">${tranline.quantity}</td>
      </tr></#if>
	</#list></table>
</#if><#if preferences.RETURNFORM && returnForm??>

<hr />
<div class="returnform">
<table style="width: 100%; margin-top: 10px;"><tr>
	<td><span class="nameandaddress">${companyInformation.companyName}</span></td>
	<td align="right"><span class="number">${returnForm@title}</span></td>
	</tr></table>

<table style="width: 100%; margin-top: 10px;"><tr>
	<td class="addressheader" colspan="4">${returnForm.returnAddress}</td>
	<th>${returnForm.rmaNum}</th>
	<th colspan="2">${returnForm.customerName}</th>
	<th>${salesorder.tranid@label}</th>
	</tr>
	<tr>
	<td class="address" colspan="4" rowspan="2"> </td>
	<td> </td>
	<td colspan="2">${salesorder.entity}</td>
	<td>${salesorder.tranid}</td>
	</tr>
	<tr>
	<td colspan="4"> </td>
	</tr></table>

<table class="itemtable" style="width: 100%; margin-top: 10px;">
<thead>
	<tr>
	<th colspan="2">${returnForm.item}</th>
	<th colspan="1">${returnForm.quantity}</th>
	<th colspan="5">${returnForm.reason}</th>
	</tr>
</thead><tr>
	<td colspan="8"> </td>
	</tr></table>
</div>
</#if>
</body>
</pdf>

Suitelet

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */
define(['N/render','N/record'],

function(render,record) {
   
    /**
     * Definition of the Suitelet script trigger point.
     *
     * @param {Object} context
     * @param {ServerRequest} context.request - Encapsulation of the incoming request
     * @param {ServerResponse} context.response - Encapsulation of the Suitelet response
     * @Since 2015.2
     */
    function onRequest(context) {
    	  var recId = context.request.parameters.recId;
    	  
    	  log.debug('recId',recId);
    	  
    	  var tempalate = 142;
          //render The Quote to End user Form
          var renderer = render.create();
          renderer.setTemplateById(tempalate);

        /*  var companyInfo = config.load({
              type: config.Type.COMPANY_INFORMATION
          });
*/
          renderer.addRecord({
              templateName: 'salesorder',
              record: record.load({
                  type: record.Type.SALES_ORDER,
                  id: recId
              })
          });

          /*renderer.addRecord({
              templateName: 'subsidiary',
              record: record.load({
                  type: record.Type.SUBSIDIARY,
                  id: subsidiaryId
              })
          });

          renderer.addRecord({
              templateName: 'companyInformation',
              record: companyInfo
          });*/

          var endUserForm = renderer.renderAsPdf();
        // endUserForm.folder = 2273;
          //  endUserForm.name = 'Proforma_invoice_SO' + recId + '.pdf';
         
          //endUserForm.name = names + '_' + recId + '.pdf';
         // endUserForm.name =  'Delivery chellan _' + recId + '.pdf';
        //  var fileId = endUserForm.save();
          
        //  log.debug('fileId',fileId);
  
          context.response.writeFile(endUserForm,true);
    	  

    }

    return {
        onRequest: onRequest
    };
    
});

User Event

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */

/**
 * 
 */

/*******************************************************************************
 * * ME * *
 * **************************************************************************
 * Date:01/03/19
 * 
 * Author : Jobin and Jismi IT Services LLP
 * Script Description: This script defines disabling buttons, adding buttons and on save actions in SO
 * Script name: ME-71 JJ UE SO Actions
 * Script id: customscript_me71_jj_ue_so_actions
 * Deployment id: customdeploy_me71_jj_ue_so_actions
 * 
 ******************************************************************************/

define(['N/search','N/record'],

function(search,record) {
	   
    /**
     * Function definition to be triggered before record is loaded.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.newRecord - New record
     * @param {string} scriptContext.type - Trigger type
     * @param {Form} scriptContext.form - Current form
     * @Since 2015.2
     */
    function beforeLoad(scriptContext) {
    	
    	try {
    		if (scriptContext.type == 'view') {
    		var custRec=scriptContext.form;
    		var recId=scriptContext.newRecord.id;
			log.debug({    
				title: 'recId',
                details: recId
            });
			
			//Getting the SO fields
			var soRecDtls = search.lookupFields({
                type: record.Type.SALES_ORDER,
                id: recId,
                columns: ['customform']
            });
			
			var customForm=null;
			
			if(soRecDtls.customform[0]!=null && soRecDtls.customform[0]!="" && soRecDtls.customform[0]!=undefined){       
				customForm=soRecDtls.customform[0].value;
			}
			
				custRec.clientScriptFileId = 969;
			//If SO form is Integrated SO form
			if(customForm==168){
				
			
				
					    			
             					 //Set Delivery Challan button
		    	    			custRec.addButton({
		    	    				id:'custpage_so_send_to_assembler_btn',
		    	    				label:'Delivery Challan',
		    	    				functionName:'deliveryChellan' 
		    	    			});
              					

		    	    			//Set annexture Invoice button
		    	    			/*custRec.addButton({
		    	    				id:'custpage_so_send_to_annexture',
		    	    				label:'Annexure',
		    	    				functionName:'annexure' 
		    	    			});*/


		    	    			//Set SO print button
		    	    			custRec.addButton({
		    	    				id:'custpage_salesorder_print',
		    	    				label:'Print Sales Order',
		    	    				functionName:'printSalesOrder' 
		    	    			});

			}//Set Proforma Invoice button
		    	    			custRec.addButton({
		    	    				id:'custpage_so_send_to_assembler_btn',
		    	    				label:'Proforma Invoice',
		    	    				functionName:'proformaInvoice' 
		    	    			});
    		}
    		
		} catch (e) {
			log.debug(e.name,e.message);
		}

    }

 

    return {
        beforeLoad: beforeLoad
      
    };
    
});

Client

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */

define(['N/currentRecord','N/url','N/https'],

function(currentRecord,url,https) {
    
    /**
     * Function to be executed after page is initialized.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
     *
     * @since 2015.2
     */
    function pageInit(scriptContext) {
    	try {
    		console.log('in');

		} catch (e) {
			console.log(e.name, e.message);
		}


    }

    

    
    function deliveryChellan()
    {
    	try{
    		  var currentRec = currentRecord.get();
              var id = currentRec.id;
    		console.log('id',id);
    		//Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_me_82_jj_sl_delivery_chella',
                deploymentId: 'customdeploy_me_82_jj_sl_delivery_chella',
                returnExternalUrl: false,
            }) + '&recId=' + id;

       
            //Opens url on a new Window
          newWindow = window.open(output);
    		
    	}
    	catch (e) {
			console.log(e.name, e.message);
		}

    }


function annexure()
    {
        try{
              var currentRec = currentRecord.get();
              var id = currentRec.id;
            console.log('id',id);
            //Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_jj_me_117_sl_annexure',
                deploymentId: 'customdeploy_jj_me_117_sl_annexure',
                returnExternalUrl: false,
            }) + '&recId=' + id;

       
            //Opens url on a new Window
          newWindow = window.open(output);
            
        }
        catch (e) {
            console.log(e.name, e.message);
        }

    }

function proformaInvoice()
    {console.log('inn');
        try{
             var recID = currentRecord.get().id;
           console.log("recID", recID);
            var parameterObj = {
                intenalId: recID
            };
            //Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_me_print_proforma_invoice',
                deploymentId: 'customdeploy_me_print_proforma_invoice',
                 params: parameterObj
            }) 

       
            //Opens url on a new Window
          newWindow = window.open(output);
            
        }
        catch (e) {
            console.log(e.name, e.message);
        }

    }

  function printSalesOrder()
    {console.log('inn');
        try{
             var recID = currentRecord.get().id;
           console.log("recID", recID);
            var parameterObj = {
                intenalId: recID
            };
            //Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_me_printintegrateditem_so',
                deploymentId: 'customdeploy_sl_printintegrateditem_so',
                 params: parameterObj
            }) 

       
            //Opens url on a new Window
          newWindow = window.open(output);
            
        }
        catch (e) {
            console.log(e.name, e.message);
        }

    }


  return {
        pageInit: pageInit,
        deliveryChellan : deliveryChellan,
       annexure:annexure,
       proformaInvoice:proformaInvoice,
       printSalesOrder:printSalesOrder
    };
    
});

Leave a comment

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