Jira Code: PROT-195
Description : Creates an Amazon SSCC label from IF.
TEMPLATE
<#list avcs.avcs as avc>
<#if .locale == “zh_CN”> <#elseif .locale == “zh_TW”> <#elseif .locale == “ja_JP”> <#elseif .locale == “ko_KR”> <#elseif .locale == “th_TH”>
|
Ship From ${avc.shipfrom} |
Ship To ${avc.shipto} |
<table width="100%" height="6in">
<tr>
<td style="width:30%;border-right:1px;border-bottom:1px">
<table width="100%">
<tr height="1.8in">
<td><b>UPC:</b><br/>${avc.avcitem}</td>
</tr>
<tr height="1.8in">
<td><b>Qty:</b><br/>${avc.qty}</td>
</tr>
<tr height="1.8in">
<td><b>Carton #:</b>${avc.carton}</td>
</tr>
</table>
</td>
<td style="width:70%;border-bottom:1px">
<table width="100%">
<tr height="2.7in">
<td width="30%"><b>PO#</b></td><td align="center"><b>Code39</b></td>
</tr>
<tr height="2.7in">
<td>${avc.soid}</td><td align="center"><barcode style="width:90%;align:left" codetype="code128" showtext="false" value="${avc.soid}"/></td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" height="2in"><tr>
<td style="border-bottom:1px">
<p><b>Amazon Container Code(Code 128):</b>${avc.containercode}</p>
<barcode style="height:1in;width:90%;align:center" codetype="code128" showtext="false" value="${avc.containercode}"/>
</td>
</tr></table>
Suitelet
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
/*******************************************************************************
*
* Author : Jobin and jismi created on:09/05/2019 SV
*
******************************************************************************/
define([ "N/search", "N/record","N/render","N/file" ], function(search, record,render,file) {
function onRequest(context) {
try{
var recId = context.request.parameters.recId;
var avc={};
var soid = search.lookupFields({
type:"itemfulfillment",
id:recId,
columns:["createdfrom.custbody_cust_po_number"]
})["createdfrom.custbody_cust_po_number"]
var routingInstructions = search.create({
type: "customrecord_cps_ecop_avc_rtinstr",
filters:[["custrecord_cps_ecop_avc_rtreq_id.internalidnumber","equalto",recId]],
columns:
[
search.createColumn({join: "custrecord_cps_ecop_avc_rtreq_id", name: "internalid", label: "IF" , summary:"GROUP"}),
// search.createColumn({join: "custrecord_cps_ecop_avc_rtreq_id", name : 'createdfrom',label: "createdfrom",summary:"MIN"}),
// search.createColumn({formula: "{custrecord_cps_ecop_avc_rtreq_id.createdfrom}", name : 'formulatext',label: "soid",summary:"MIN"}),
search.createColumn({name: "custrecord_cps_ecop_avc_shp_frm", label: "shipfrom",summary:"MIN"}),
search.createColumn({join : "custrecord_cps_ecop_avc_rtreq_id", name: "shipaddress", label: "shipto",summary:"MIN"})
]
});
var itemRouting={};
routingInstructions.run().each(function(result){
for(var i=0;i<routingInstructions.columns.length;i++)
itemRouting[routingInstructions.columns[i].label] = result.getValue(routingInstructions.columns[i]);
itemRouting.soid=soid;
itemRouting.shipfrom=itemRouting.shipfrom.replace(/\n/g,"<br/>");
itemRouting.shipto=itemRouting.shipto.replace(/\n/g,"<br/>");
return false;
});
//log.debug("itemRouting",itemRouting);
var acnAvsDetailsSearch = search.create({
type: "customrecord_cps_avc_asn_details",
filters:
[
["custrecord_cps_asn_if.internalid","anyof",recId]
],
columns:
[
search.createColumn({name: "internalid", label: "internalid",summary:"GROUP"}),
search.createColumn({name: "custrecord_cps_avc_asn_sscc", label: "containercode",summary:"MIN"}),
search.createColumn({name: "custrecord_cps_asn_item_sku", label: "avcitem",summary:"MIN"}),
search.createColumn({name: "custrecord_cps_avc_asn_quantity", label: "qty",summary:"MIN"}),
]
});
var index=1;
var containerCount=acnAvsDetailsSearch.runPaged().count;
if(containerCount==0){
context.response.write("<html><head></head><body><script>alert('This itemfulFillment Does not have any container code');window.close();</script></body></html>");
return;
}
var isMultiple = containerCount>1;
var qty=0;
var avsDetails=[];
acnAvsDetailsSearch.run().each(function(result){
var avsDetail=JSON.parse(JSON.stringify(itemRouting));
for(var i=0;i<acnAvsDetailsSearch.columns.length;i++)
avsDetail[acnAvsDetailsSearch.columns[i].label] = result.getValue(acnAvsDetailsSearch.columns[i]);
avsDetail.carton=index+" of "+containerCount;
var currentQty=parseInt(avsDetail.qty);
qty+=isNaN(currentQty)?0:currentQty;
index++;
isMultiple?avsDetail.avcitem="Mixed SKUs":"";
avsDetails.push(avsDetail);
return true;
});
var renderer = render.create();
renderer.templateContent = file.load(765148).getContents();
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "avcs",
data: {qty:qty,avcs:avsDetails}
});
var ssccLabel = renderer.renderAsPdf();
context.response.writeFile(ssccLabel,true);
}
catch(err)
{
log.debug("error@onRequest",err)
}
}
return {
onRequest : onRequest
}
});