function changeButtonClick(ctrl, parentRow, podCtrlName, reportRowProperties, ctrlBtnEdit){ var removeRow = $(ctrl.parents('tr')[0]); if(ctrlBtnEdit != undefined){ parentRow = $('.fvCtrlName_'+podCtrlName).find('.' + $(ctrlBtnEdit).attr('name')); removeRow = $(ctrlBtnEdit).parents('tr'); } parentRow.removeClass(CONST_CSS_CLASS_HIDE_SESSION); parentRow.find('.ctrlPODCell_inputAction').removeClass('disable-btn-cell'); parentRow.find('.__Actual').removeAttr('disabled'); parentRow.find('.__Rejected').removeAttr('disabled'); parentRow.find('.__Damaged').removeAttr('disabled'); var parentControl = $('.fvControl.fvCtrlName_' + podCtrlName); var inputDamaged = parentRow.find('.__Damaged'); var inputActual = parentRow.find('.__Actual'); var inputRejected = parentRow.find('.__Rejected'); var inputStatus = parentRow.find('.__Status'); var inputQtyCell = parentRow.find('.__Qty'); // CO-1456: Update value for none datasource row data if(CONST_VALUE_NONE === reportRowProperties.podDataSource){ var $tds = removeRow.find('td'); for(var i=0; i<$tds.length; i++){ var $td = $($tds[i]); var tdClass = $td.attr('class'); var tdVal = $td.html(); if(tdClass.indexOf('_' + POD_DELIVER_COL_ID)>=0 || tdClass.indexOf('_' + POD_STATUS_COL_ID)>=0 || tdClass.indexOf('_' + POD_AUTO_ID_COL_ID)>=0 || tdClass.indexOf('_' + POD_QTY_COL_ID)>=0 || tdClass.indexOf('_' + POD_STOP_NO_COL_ID)>=0){ //ignore this column }else if(tdClass.indexOf('_' + POD_ACTUAL_COL_ID)>=0){ inputActual.val(tdVal); }else if(tdClass.indexOf('_' + POD_DAMAGED_COL_ID)>=0){ inputDamaged.val(tdVal); }else if(tdClass.indexOf('_' + POD_REJECTED_COL_ID)>=0){ inputRejected.val(tdVal); }else{ try{ var tmp = tdClass.split(' '); parentCtrlId = tmp[tmp.length-1]; parentRow.find('#'+parentCtrlId).children().val(tdVal); }catch(e){} } } } updateZebraTable(parentControl.find('.controlData table')); var status = 0; try{ status = parseInt(inputStatus.val()); if(isNaN(status)){ status = 0; } }catch(ex){ status = 0; } if(isHidden(status) || isRejected(status)){ inputStatus.val('' + POD_RECORD_STATUS_NOT_DELIVERED).change(); } var changeQty = 1; var orgQty = 1; try{ orgQty = parseInt(removeRow.find('.__Qty').attr('data')); if(isNaN(orgQty)){ orgQty = 1; } }catch(ex){ orgQty = 1; } var rejectedNo = 0; try{ rejectedNo = parseInt(inputRejected.val()); if(isNaN(rejectedNo)){ rejectedNo = 0; } }catch(ex){ rejectedNo = 0; } changeQty = orgQty; var actualNo = 0; try{ //actualNo = parseInt(removeRow.find('.__Actual').attr('data')); actualNo = parseInt(inputActual.val()); if(isNaN(actualNo)){ actualNo = orgQty - rejectedNo; }else{ actualNo -= rejectedNo; } }catch(ex){ actualNo = orgQty - rejectedNo;; } if(actualNo < 0){ actualNo = 0; } var changeOverCount = 0; if(actualNo > orgQty && (actualNo + rejectedNo)>orgQty){ changeOverCount = actualNo - orgQty; } if(actualNo < orgQty){ changeQty = actualNo; }else{ changeQty = orgQty; } var changeDamaged = ''; try{ changeDamaged = removeRow.find('.__Damaged').attr('data'); }catch(ex){ changeDamaged = ''; } if(inputDamaged && inputDamaged.is(':checkbox')){ if(inputDamaged.is(':checked')){ //damaged flag checked if(changeDamaged == 'yes'){ //damaged no change }else{ //inc total damaged fvDataNS.inputData.PODData[podCtrlName].Damaged += changeQty; } }else{ //damaged flag not check if(changeDamaged == 'yes'){ //dec total damaged fvDataNS.inputData.PODData[podCtrlName].Damaged -= changeQty; }else{ //damaged no change } } } if(CONST_VALUE_NONE === reportRowProperties.podDataSource){ fvDataNS.inputData.PODData[podCtrlName].Qty = 0; } else{ fvDataNS.inputData.PODData[podCtrlName].Qty += changeQty; } fvDataNS.inputData.PODData[podCtrlName].Over -= changeOverCount; parentControl.find('.OSDReportSession .OSDRShort').empty().append(fvDataNS.inputData.PODData[podCtrlName].Qty); //parentControl.find('.OSDReportSession .OSDROver').empty().append(fvDataNS.inputData.PODData[podCtrlName].Over); removeRow.remove(); updateZebraTable(parentControl.find('.DeliveredReportSession table')); // Over fvDataNS.inputData.PODData[podCtrlName].Over = calcualteDamaged(parentControl, reportRowProperties.podDataSource, '__Rejected'); parentControl.find('.OSDReportSession .OSDROver').empty().append(fvDataNS.inputData.PODData[podCtrlName].Over); // Damaged fvDataNS.inputData.PODData[podCtrlName].Damaged = calcualteDamaged(parentControl, reportRowProperties.podDataSource, ''); parentControl.find('.OSDReportSession .OSDRDamaged').empty().append(fvDataNS.inputData.PODData[podCtrlName].Damaged); var index = fvDataNS.inputData.PODExtData[reportRowProperties.name].indexOf(reportRowProperties); fvDataNS.inputData.PODExtData[reportRowProperties.name].splice(index, 1); // CO-1457: POD Inter Form Data Source // Reload Inter form after data changed try{ if(fvDataNS.ctrlPODRef != undefined && fvDataNS.ctrlPODRef[reportRowProperties.name] != undefined){ $('.fvWorkspace .fvCtrlName_'+ fvDataNS.ctrlPODRef[reportRowProperties.name]) .find('.controlData table') .trigger('InFormDataSourceChange'); } } catch(e){} } function updateOSDReport(podCtrlName){ var parentControl = $('.fvControl.fvCtrlName_' + podCtrlName); var manifestTable = parentControl.find('.controlData table'); var allRows = manifestTable.find('tbody tr:not(.hideFilter)'); var totalDamaged = 0; var totalOver = 0; var totalShort = 0; var reCalculate = true; var isSinglePod = parentControl.hasClass(CONST_SINGLE); if(fvDataNS.currentForm && fvDataNS.currentForm.editRecordData && fvDataNS.currentForm.editRecordData[podCtrlName + CONST_DAMAGED] && fvDataNS.currentForm.editRecordData[podCtrlName + CONST_OVER] && fvDataNS.currentForm.editRecordData[podCtrlName + CONST_QTY]){ var damage = fvDataNS.currentForm.editRecordData[podCtrlName + CONST_DAMAGED]; totalDamaged = parseInt(damage.value); var over = fvDataNS.currentForm.editRecordData[podCtrlName + CONST_OVER]; totalOver = parseInt(over.value); var qty = fvDataNS.currentForm.editRecordData[podCtrlName + CONST_QTY]; totalShort = parseInt(qty.value); if(!isNaN(totalDamaged) || !isNaN(totalOver) || !isNaN(totalShort)){ reCalculate = false; }else{ totalDamaged = 0; totalOver = 0; totalShort = 0; } } if(reCalculate){ for(var i=0;i 0){ if(inputDamaged.is(':checkbox')){ if(inputDamaged.is(':checked')){ damagedNo = 1; } }else{ try{ damagedNo = parseInt(inputDamaged.val()); if(isNaN(damagedNo)){ damagedNo = 0; } }catch(ex){ damagedNo = 0; } } } /*get rejected value*/ var rejectedNo = 0; try{ rejectedNo = parseInt(inputRejected.val()); if(isNaN(rejectedNo)){ rejectedNo = 0; } }catch(ex){ rejectedNo = 0; } /*get actual value*/ var actualNo = 0; try{ actualNo = parseInt(inputActual.val()); if(isNaN(actualNo)){ actualNo = qty - rejectedNo; }else{ actualNo -= rejectedNo; } }catch(ex){ actualNo = qty - rejectedNo; } totalDamaged += damagedNo; if(!isHidden(status) && !isRejected(status)){ totalShort += qty; } if(isRejected(status)){ if(actualNo + rejectedNo>qty && actualNo > qty){ totalOver += actualNo - qty; } if(actualNo < qty){ totalShort += qty - actualNo; } } } } fvDataNS.inputData.PODData[podCtrlName].Damaged = totalDamaged; fvDataNS.inputData.PODData[podCtrlName].Qty = totalShort; fvDataNS.inputData.PODData[podCtrlName].Over = totalOver; parentControl.find('.OSDReportSession .OSDRShort').empty().append(fvDataNS.inputData.PODData[podCtrlName].Qty); parentControl.find('.OSDReportSession .OSDRDamaged').empty().append(fvDataNS.inputData.PODData[podCtrlName].Damaged); parentControl.find('.OSDReportSession .OSDROver').empty().append(fvDataNS.inputData.PODData[podCtrlName].Over); } function loadDeliveredReportSession($control, ctrlPropreties){ if(!fvDataNS.inputData || !fvDataNS.inputData.PODExtData || !fvDataNS.inputData.PODExtData[ctrlPropreties.name]){ return; } var statusColIndex = 0; var deliverColIndex = 0; var autoColIndex = 0; var qtyColIndex = 0; var actualColIndex = 0; var damageColIndex = 0; var rejectColIndex = 0; var commentColIndex = 0; var autoIdColIndex = 0; var parrentProperties = fvDataNS.dataArray['data ' + ctrlPropreties.name]; _.each(fvDataNS.inputData.PODExtData[ctrlPropreties.name][0].children, function(child, i){ var id = ''+child.id; if(id.indexOf(POD_DELIVER_COL_ID)>=0){ deliverColIndex = i; }else if(id.indexOf(POD_STATUS_COL_ID)>=0){ statusColIndex = i; }else if(id.indexOf(POD_AUTO_ID_COL_ID)>=0){ autoColIndex = i; }else if(id.indexOf(POD_QTY_COL_ID)>=0){ qtyColIndex = i; }else if(id.indexOf(POD_DAMAGED_COL_ID)>=0){ damageColIndex = i; }else if(id.indexOf(POD_REJECTED_COL_ID)>=0){ rejectColIndex = i; }else if(id.indexOf(POD_ACTUAL_COL_ID)>=0){ actualColIndex = i; }else if(id.indexOf(POD_COMMENT_COL_ID)>=0){ commentColIndex = i; }else if(id.indexOf(POD_AUTO_ID_COL_ID)>=0){ autoIdColIndex = i; } }); var $parentControl = $control; var btnClass = ''; if($parentControl.find('.shadingButtonCtrlBackgrnd').length > 0){ btnClass += ' shadingButtonCtrlBackgrnd'; } if($parentControl.find('.shadingButtonCtrlColorBackgrnd').length > 0){ btnClass += ' shadingButtonCtrlColorBackgrnd'; } _.each(fvDataNS.inputData.PODExtData[ctrlPropreties.name], function(reportRowProperties, i){ var $reportRowProperties = reportRowProperties; var $parentRow = undefined; var $deliverCell = undefined; var $inputStatus = undefined; var $inputQtyCell = undefined; var $inputActualCell = undefined; if(reportRowProperties.classPath == ''){ //not in manifest var $reportRow = $(''); var overCount = 1; var rowStatus = 0; var podCtrlName = $reportRowProperties.name; var hasRejectCol = false; var headerIndex = 0 for(var i=0; i<$reportRowProperties.children.length; i++){ var child = $reportRowProperties.children[i]; var id = '_' + child.id; var $cell = $(''); try{ if($($parentControl.find('.tableDeliveredHeader th')[headerIndex]).hasClass('hideOnMobileApp')){ $cell.addClass('hideOnMobileApp'); } }catch(ex){} if(id.indexOf('_' + POD_DELIVER_COL_ID)>=0){ //ignore this column continue; } headerIndex ++; if(id.indexOf('_' + POD_ID_COL_ID)>=0){ $cell.attr('data', child.val); $cell.append(child.val); }else if(id.indexOf('_' + POD_STATUS_COL_ID)>=0){ $cell.attr('data', rowStatus); $cell.append(getPODDeliverStatusString(rowStatus, parrentProperties.manifestType)); //$cell.append(rowStatus); //$cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_AUTO_ID_COL_ID)>=0){ $cell.addClass('__AutoID'); $cell.attr('data', ''); $cell.append(''); $cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_QTY_COL_ID)>=0){ $cell.addClass('__Qty'); $cell.attr('data', qty); $cell.append(qty); }else if(id.indexOf('_' + POD_DAMAGED_COL_ID)>=0){ //damage column $cell.addClass('__Damaged'); $cell.append(''); }else if(id.indexOf('_' + POD_REJECTED_COL_ID)>=0){ $cell.addClass(CONST_REJECTED); $cell.append(''); /*if(rejectedNo > 0){ $cell.attr('data', rejectedNo); $cell.append(rejectedNo); }else{ $cell.append(''); }*/ }else if(id.indexOf('_' + POD_STOP_NO_COL_ID)>=0){ $cell.append('1'); }else { $cell.append(''); } $reportRow.append($cell); } if(!hasRejectCol){ var $cell = $(''); $cell.addClass('__Over'); $cell.attr('data', overCount); $cell.append(overCount==0?'':'Yes'); $reportRow.append($cell); } var $changeBtn = getSelectedQuery4CloneObjectWA('#formview_templates .ctrlPODCell_changeBtn', CONST_CTRL_TYPE_INPUTACTION, undefined).clone(); $changeBtn.find('.actionLabelText').empty().append('Change'); $changeCell = $('').append($changeBtn).addClass(btnClass); $reportRow.append($changeCell); var $ths = $parentControl.find('.DeliveredReportSession thead th'); $tdsTmp = $reportRow.find('td'); for(var i=0; i<$ths.length; i++){ var $th = $($ths[i]); var $td = $($tdsTmp[i]); if($th.hasClass(CONST_HIDEONMOBILEAPP)){ $td.addClass(CONST_HIDEONMOBILEAPP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION_IMP)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION_IMP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION); } if('none' == $th.css(CONST_CSS_KEY_DISPLAY)){ $td.css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); } } $parentControl.find('.DeliveredReportSession .tblDeliveredBody').append($reportRow); updateZebraTable($parentControl.find('.DeliveredReportSession table')); $changeCell.find('.actionBtn').click(function(){ var $removeRow = $($(this).parents('tr')[0]); var changeOverCount = 1; fvDataNS.inputData.PODData[podCtrlName].Over -= changeOverCount; $parentControl.find('.OSDReportSession .OSDRShort').empty().append(fvDataNS.inputData.PODData[podCtrlName].Qty); $parentControl.find('.OSDReportSession .OSDRDamaged').empty().append(fvDataNS.inputData.PODData[podCtrlName].Damaged); $parentControl.find('.OSDReportSession .OSDROver').empty().append(fvDataNS.inputData.PODData[podCtrlName].Over); $removeRow.remove(); updateZebraTable($parentControl.find('.DeliveredReportSession table')); var index = fvDataNS.inputData.PODExtData[$reportRowProperties.name].indexOf($reportRowProperties); fvDataNS.inputData.PODExtData[$reportRowProperties.name].splice(index, 1); }); }else{ $parentRow = fvDataNS.ctrlArray[reportRowProperties.classPath]; $deliverCell = $parentRow.find('.ctrlPODCell_inputAction'); $inputStatus = $parentRow.find('.__Status'); $inputQtyCell = $parentRow.find('.__Qty'); $inputActualCell = $parentRow.find('.__Actual'); var $tds = $parentRow.find('td'); var $reportRow = $(''); var hasRejectCol = false; for(var i=0; i<$tds.length; i++){ var $td = $($tds[i]); var id = $td.attr('id'); var $cell = $(''); if($td.hasClass('hideOnMobileApp')){ if(id.indexOf('_' + POD_STATUS_COL_ID)<0){ $cell.addClass('hideOnMobileApp'); } } if(id.indexOf('_' + POD_DELIVER_COL_ID)>=0){ //ignore this column continue; }else if(id.indexOf('_' + POD_STATUS_COL_ID)>=0){ var rowStatus = reportRowProperties.children[statusColIndex].val; $cell.attr('data', rowStatus); $cell.append(getPODDeliverStatusString(rowStatus, parrentProperties.manifestType)); //$cell.append(rowStatus); //$cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_AUTO_ID_COL_ID)>=0){ $cell.addClass('__AutoID'); $cell.attr('data', $td.find('input').val()); $cell.append($td.find('input').val()); $cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_QTY_COL_ID)>=0){ var qty = reportRowProperties.children[qtyColIndex].val; $cell.addClass('__Qty'); $cell.attr('data', qty); $cell.append(qty); }else if(id.indexOf('_' + POD_DAMAGED_COL_ID)>=0){ var damaged = reportRowProperties.children[damageColIndex].val; $cell.addClass('__Damaged'); $cell.attr('data', damaged); $cell.append(damaged); }else if(id.indexOf('_' + POD_REJECTED_COL_ID)>=0){ var rejectedNo = reportRowProperties.children[rejectColIndex].val; $cell.addClass(CONST_REJECTED); if(rejectedNo > 0){ $cell.attr('data', rejectedNo); $cell.append(rejectedNo); }else{ $cell.append(''); } /*hasRejectCol = true; //reject column -> over count var status = POD_RECORD_STATUS_DELIVERED; try{ status = parseInt(reportRowProperties.children[statusColIndex].val); }catch(ex){ status = POD_RECORD_STATUS_DELIVERED; } $cell.addClass('__Over'); var overCount = 0; try{ var actualCount = parseInt(reportRowProperties.children[actualColIndex].val); overCount = actualCount; }catch(ex){ overCount = 0; } try{ var qtyCount = parseInt(reportRowProperties.children[qtyColIndex].val); overCount -= qtyCount; }catch(ex){ } if(overCount<=0){ overCount = 0; $cell.append(''); }else{ $cell.attr('data', overCount); $cell.append('Yes'); }*/ }else if(id.indexOf('_' + POD_ACTUAL_COL_ID)>=0){ /*var actual = undefined; try{ actual = parseInt(reportRowProperties.children[actualColIndex].val); if(isNaN(actual)){ actual = undefined; } }catch(ex){ actual = undefined; } var rejectedNo = 0; try{ rejectedNo = parseInt(reportRowProperties.children[rejectColIndex].val); if(isNaN(rejectedNo)){ rejectedNo = 0; } }catch(ex){ rejectedNo = 0; } var qty = 0; try{ qty = parseInt(reportRowProperties.children[qtyColIndex].val); if(isNaN(qty)){ qty = 0; } }catch(ex){ qty = 0; } if(actual != undefined && !isNaN(parseFloat(actual))){ $cell.attr('data', actual - rejectedNo); $cell.append(actual - rejectedNo); }else{ $cell.attr('data', qty - rejectedNo); $cell.append(qty - rejectedNo); }*/ var actual = reportRowProperties.children[actualColIndex].val; $cell.attr('data', actual); $cell.append(actual); }else if(id.indexOf('_' + POD_COMMENT_COL_ID)>=0){ var comment = reportRowProperties.children[commentColIndex].val; $cell.append(comment); }else if($td.find('.ctrlPODCell_inputText').length > 0){ $cell.append($td.find('textarea').val()); }else if($td.find('.ctrlPODCell_inputNumeric').length > 0){ $cell.append($td.find('input').val()); } $reportRow.append($cell); } if(!hasRejectCol){ var status = POD_RECORD_STATUS_DELIVERED; try{ status = parseInt(reportRowProperties.children[statusColIndex].val); }catch(ex){ status = POD_RECORD_STATUS_DELIVERED; } var $cell = $(''); $cell.addClass('__Over'); var overCount = 0; try{ var actualCount = parseInt(reportRowProperties.children[actualColIndex].val); overCount = actualCount; }catch(ex){ overCount = 0; } try{ var qtyCount = parseInt(reportRowProperties.children[qtyColIndex].val); overCount -= qtyCount; }catch(ex){ } if(overCount<=0){ overCount = 0; $cell.append(''); }else{ $cell.attr('data', overCount); $cell.append('Yes'); } $reportRow.append($cell); } var $changeBtn = getSelectedQuery4CloneObjectWA('#formview_templates .ctrlPODCell_changeBtn', CONST_CTRL_TYPE_INPUTACTION, undefined).clone(); $changeBtn.find('.actionLabelText').empty().append('Change'); $changeCell = $('').append($changeBtn).addClass(btnClass); $reportRow.append($changeCell); var $ths = $parentControl.find('.DeliveredReportSession thead th'); $tdsTmp = $reportRow.find('td'); for(var i=0; i<$ths.length; i++){ var $th = $($ths[i]); var $td = $($tdsTmp[i]); if($th.hasClass(CONST_HIDEONMOBILEAPP)){ $td.addClass(CONST_HIDEONMOBILEAPP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION_IMP)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION_IMP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION); } if('none' == $th.css(CONST_CSS_KEY_DISPLAY)){ $td.css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); } } $parentControl.find('.DeliveredReportSession .tblDeliveredBody').append($reportRow); $changeCell.find('.actionBtn').click(function(){ changeButtonClick($changeCell, $parentRow, $reportRowProperties.name, $reportRowProperties, this); }); } }); } function updateZebraTable($ctrlTable){ var $trs = $ctrlTable.find('tbody tr'); $trs.removeClass('evenRow'); $trs.removeClass('oddRow'); var isOld = false; for(var i=0; i<$trs.length; i++){ $tr = $($trs[i]); if($tr.css(CONST_CSS_KEY_DISPLAY) == CONST_VALUE_NONE){ continue; } if(isOld){ $tr.addClass('oddRow'); }else{ $tr.addClass('evenRow'); } isOld = !isOld; } } function loadEditPodData(editRecordKey, cursor){ var ret = []; var cursorParam = ''; if(cursor){ cursorParam = '&startCursor=' + cursor; } $.ajax({ url: '/PODServlet?fnId=POD_DATA' + '&recordKey=' + editRecordKey + cursorParam, dataType: 'json', type: 'GET', cache: false, async: false, complete: function() { }, success: function(response, status) { if(response){ if(response['data']){ ret = response['data']; } if(response['continue'] && response['cursor']){ ret = $.merge(ret, loadEditPodData(editRecordKey, response['cursor'])); } } } }); return ret; } function processScanReadItem(podCtrlName, scanReadID, isDamaged, isRejected, callback){ var $parentControl = $('.fvControl.fvCtrlName_' + podCtrlName); var $idControl = $parentControl.find('.controlData table .data-id-' + scanReadID); var $parentRow = undefined; var parentClassPath = ''; if($idControl.length > 0){ $parentRow = $($idControl.parents('tr')[0]); if($parentRow.hasClass(CONST_CSS_CLASS_HIDE_SESSION)){ callback('AlreadyScanRead'); return; }else{ parentClassPath = $parentRow.attr('data-class-path'); } } if($parentRow && $parentRow.length>0){ var $inputRejected = $parentRow.find('.__Rejected'); if($inputRejected && $inputRejected.is(':checked')){ callback('AlreadyScanReadReject'); //ignore this item return; } var $deliverCell = $parentRow.find('.ctrlPODCell_inputAction'); var $inputStatus = $parentRow.find('.__Status'); var parrentRowProperties = fvDataNS.dataArray[parentClassPath]; var parrentProperties = fvDataNS.dataArray['data ' + podCtrlName]; if((parrentProperties.allowDamagedDelivery == false) && isDamaged){ isRejected = true; } if(isRejected){ $inputStatus.val('' + POD_RECORD_STATUS_REJECT).change(); $inputRejected.prop('checked', true); callback('Rejected'); return; } var $inputQtyCell = $parentRow.find('.__Qty'); var $inputActualCell = $parentRow.find('.__Actual'); var $inputDamaged = $parentRow.find('.__Damaged'); var $inputRejected = $parentRow.find('.__Rejected'); var overCount = 0; var shortCount = 0; var rowStatus = 0; var damagedNo = 0; var rejectedNo = 0; var qty = 1; var actual = undefined; try{ qty = parseInt($inputQtyCell.val()); if(isNaN(qty)){ qty = 1; } }catch(ex){ qty = 1; } if($inputDamaged.is(':checked') || ($inputDamaged[0] && $inputDamaged[0].type == 'checkbox' && isDamaged)){ damagedNo = 1; }else{ try{ damagedNo = parseInt($inputDamaged.val()); if(isNaN(damagedNo)){ damagedNo = 0; } }catch(ex){ damagedNo = 0; } } if($inputRejected.is(':checked')){ rejectedNo = 1; }else{ try{ rejectedNo = parseInt($inputRejected.val()); if(isNaN(rejectedNo)){ rejectedNo = 0; } }catch(ex){ rejectedNo = 0; } } if($inputActualCell.length > 0){ try{ actual = parseInt($inputActualCell.val()); if(isNaN(actual)){ actual = undefined; } }catch(ex){ actual = undefined; } } if(actual != undefined){ // change actual == 0 to actual < 0 in CO-91: POD if(actual < 0){ callback('NoBoxAvailable'); return; } if(actual qty){ overCount = actual - rejectedNo - qty; shortCount = 0; }else{ shortCount = qty - (actual - rejectedNo); } }else{ if(qty == rejectedNo){ return; } shortCount = rejectedNo; } if(rejectedNo >= qty){ if(actual == undefined || rejectedNo >= actual){ callback('AlreadyScanReadReject'); return; } } function deliverCallBack(result, data) { if(!result) { return; } if(!fvDataNS.inputData.PODData[podCtrlName].Damaged){ fvDataNS.inputData.PODData[podCtrlName].Damaged = 0; } if(!fvDataNS.inputData.PODData[podCtrlName].Over){ fvDataNS.inputData.PODData[podCtrlName].Over = 0; } if(!fvDataNS.inputData.PODExtData){ fvDataNS.inputData.PODExtData = {}; } var $parrentPropertiesCopy = jQuery.extend(true, {}, parrentRowProperties); if(!fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name]){ fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name] = []; } fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name].push($parrentPropertiesCopy); rowStatus = 0; if(damagedNo > 0 || isDamaged){ rowStatus = POD_RECORD_STATUS_DAMAGED; } var notDeliverQty = 0; if(rejectedNo > 0){ //notDeliverQty = rejectedNo; //shortCount += rejectedNo; } fvDataNS.inputData.PODData[podCtrlName].Qty -= qty - shortCount; fvDataNS.inputData.PODData[podCtrlName].Over += overCount; rowStatus += POD_RECORD_STATUS_DELIVERED; if(overCount > 0){ rowStatus += POD_RECORD_STATUS_OVER; } if(shortCount > 0){ rowStatus += POD_RECORD_STATUS_SHORT; } if(actual && actual > 0){ $inputActualCell.val(0).change(); } $inputQtyCell.val(notDeliverQty).change(); _.each($parrentPropertiesCopy.children, function(child){ if(child.name.indexOf('__Qty') >= 0){ child.val = qty; }else if(child.name.indexOf('__Status') >= 0){ child.val = rowStatus; }else if(child.name.indexOf('__Actual') >= 0){ if(actual != undefined && !isNaN(parseFloat(actual))){ child.val = actual; }else{ child.val = qty - rejectedNo; } } }); $parentControl.find('.OSDReportSession .OSDRShort').empty().append(fvDataNS.inputData.PODData[podCtrlName].Qty); $parentControl.find('.OSDReportSession .OSDRDamaged').empty().append(fvDataNS.inputData.PODData[podCtrlName].Damaged); $parentControl.find('.OSDReportSession .OSDROver').empty().append(fvDataNS.inputData.PODData[podCtrlName].Over); var $tds = $parentRow.find('td'); var $reportRow = $(''); var btnClass = ''; if($parentControl.find('.shadingButtonCtrlBackgrnd').length > 0){ btnClass += ' shadingButtonCtrlBackgrnd'; } if($parentControl.find('.shadingButtonCtrlColorBackgrnd').length > 0){ btnClass += ' shadingButtonCtrlColorBackgrnd'; } var hasRejectCol = false; for(var i=0; i<$tds.length; i++){ var $td = $($tds[i]); var id = $td.attr('id'); var $cell = $(''); if($td.hasClass('hideOnMobileApp')){ if(id.indexOf('_' + POD_STATUS_COL_ID)<0){ $cell.addClass('hideOnMobileApp'); } } if(id.indexOf('_' + POD_DELIVER_COL_ID)>=0){ //ignore this column continue; }else if(id.indexOf('_' + POD_ACTUAL_COL_ID)>=0){ $cell.addClass('__Actual'); if(actual != undefined && !isNaN(parseFloat(actual))){ $cell.attr('data', actual - rejectedNo); if(actual < rejectedNo){ $cell.append(0); }else{ $cell.append(actual - rejectedNo); } }else{ $cell.attr('data', qty - rejectedNo); $cell.append(qty - rejectedNo); } }else if(id.indexOf('_' + POD_STATUS_COL_ID)>=0){ $cell.attr('data', rowStatus); $cell.append(getPODDeliverStatusString(rowStatus, parrentProperties.manifestType)); //$cell.append(rowStatus); //$cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_AUTO_ID_COL_ID)>=0){ $cell.addClass('__AutoID'); $cell.attr('data', $td.find('input').val()); $cell.append($td.find('input').val()); $cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_QTY_COL_ID)>=0){ $cell.addClass('__Qty'); $cell.attr('data', qty); $cell.append(qty); }else if(id.indexOf('_' + POD_DAMAGED_COL_ID)>=0){ //damage column $cell.addClass('__Damaged'); if(damagedNo > 0){ $cell.attr('data', damagedNo); $cell.append(damagedNo); }else{ $cell.append(''); } }else if(id.indexOf('_' + POD_REJECTED_COL_ID)>=0){ $cell.addClass(CONST_REJECTED); if(rejectedNo > 0){ $cell.attr('data', rejectedNo); $cell.append(rejectedNo); }else{ $cell.append(''); } }else if(id.indexOf('_' + POD_STOP_NO_COL_ID)>=0){ $cell.append('1'); }else if($td.find('.ctrlPODCell_inputText').length > 0){ $cell.append($td.find('textarea').val()); }else if($td.find('.ctrlPODCell_inputNumeric').length > 0){ $cell.append($td.find('input').val()); } $reportRow.append($cell); } if(!hasRejectCol){ var $cell = $(''); $cell.addClass('__Over'); $cell.attr('data', overCount); $cell.append(overCount==0?'':'Yes'); $reportRow.append($cell); } var $changeBtn = getSelectedQuery4CloneObjectWA('#formview_templates .ctrlPODCell_changeBtn', CONST_CTRL_TYPE_INPUTACTION, undefined).clone(); $changeBtn.find('.actionLabelText').empty().append('Change'); $changeCell = $('').append($changeBtn).addClass(btnClass); $reportRow.append($changeCell); var $ths = $parentControl.find('.DeliveredReportSession thead th'); $tdsTmp = $reportRow.find('td'); for(var i=0; i<$ths.length; i++){ var $th = $($ths[i]); var $td = $($tdsTmp[i]); if($th.hasClass(CONST_HIDEONMOBILEAPP)){ $td.addClass(CONST_HIDEONMOBILEAPP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION_IMP)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION_IMP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION); } if('none' == $th.css(CONST_CSS_KEY_DISPLAY)){ $td.css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); } } $parentControl.find('.DeliveredReportSession .tblDeliveredBody').append($reportRow); if(notDeliverQty == 0){ $parentRow.addClass(CONST_CSS_CLASS_HIDE_SESSION); $inputStatus.val(POD_RECORD_STATUS_HIDDEN).change(); updateZebraTable($parentControl.find('.controlData table')); } updateZebraTable($parentControl.find('.DeliveredReportSession table')); fvDataNS.inputData.PODData[podCtrlName].Damaged = calcualteDamaged($parentControl, reportRowProperties.podDataSource, ''); $parentControl.find('.OSDReportSession .OSDRDamaged').empty().append(fvDataNS.inputData.PODData[podCtrlName].Damaged); $changeCell.find('.actionBtn').click(function(){ changeButtonClick($changeCell, $parentRow, $parrentPropertiesCopy.name, $parrentPropertiesCopy, this); }); callback(); } /*if(damagedNo > 0){ jConfirm(lbl_damaged_confirm_msg.replace('$1', parrentProperties.manifestType) ,"" , deliverCallBack); }else{ deliverCallBack(true, undefined); }*/ deliverCallBack(true, undefined); }else{ if(isRejected){ callback('AlreadyScanReadReject'); return; } if($parentControl.find('.tblDeliveredBody td[data="' + scanReadID + '"]').length > 0){ callback('AlreadyScanRead'); return; } //var parrentRowProperties = fvDataNS.dataArray['data ' + podCtrlName]; var parrentRowProperties = fvDataNS.podDataArrayOrg['data ' + podCtrlName]; if(parrentRowProperties.scannedNotFoundMsg){ jAlert(parrentRowProperties.scannedNotFoundMsg['eng'], '', executeNotInManifest); }else{ executeNotInManifest(); } function executeNotInManifest(){ var overCount = 1; var rowStatus = 0; var damagedNo = 0; // not in manifest if(!fvDataNS.inputData.PODData[podCtrlName].Damaged){ fvDataNS.inputData.PODData[podCtrlName].Damaged = 0; } if(!fvDataNS.inputData.PODData[podCtrlName].Over){ fvDataNS.inputData.PODData[podCtrlName].Over = 0; } if(!fvDataNS.inputData.PODExtData){ fvDataNS.inputData.PODExtData = {}; } var $parrentPropertiesCopy = jQuery.extend(true, {}, parrentRowProperties); if(!fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name]){ fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name] = []; } fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name].push($parrentPropertiesCopy); rowStatus = 0; rowStatus = POD_RECORD_STATUS_NOT_IN_MANIFEST; if(isDamaged){ damagedNo = 1; rowStatus += POD_RECORD_STATUS_DAMAGED; fvDataNS.inputData.PODData[podCtrlName].Damaged += 1; } fvDataNS.inputData.PODData[podCtrlName].Over += overCount; rowStatus += POD_RECORD_STATUS_DELIVERED; if(overCount > 0){ rowStatus += POD_RECORD_STATUS_OVER; } _.each($parrentPropertiesCopy.children, function(child){ if(child.name.indexOf('__Qty') >= 0){ child.val = qty; }else if(child.name.indexOf('__Status') >= 0){ child.val = rowStatus; }else if(child.name.indexOf('__Actual') >= 0){ child.val = 1; }else if(child.name.indexOf('__ID') >= 0){ child.val = scanReadID; }else if(child.name.indexOf('__AutoID') >= 0){ child.val = ''; } }); $parentControl.find('.OSDReportSession .OSDRShort').empty().append(fvDataNS.inputData.PODData[podCtrlName].Qty); $parentControl.find('.OSDReportSession .OSDRDamaged').empty().append(fvDataNS.inputData.PODData[podCtrlName].Damaged); $parentControl.find('.OSDReportSession .OSDROver').empty().append(fvDataNS.inputData.PODData[podCtrlName].Over); var $reportRow = $(''); var btnClass = ''; if($parentControl.find('.shadingButtonCtrlBackgrnd').length > 0){ btnClass += ' shadingButtonCtrlBackgrnd'; } if($parentControl.find('.shadingButtonCtrlColorBackgrnd').length > 0){ btnClass += ' shadingButtonCtrlColorBackgrnd'; } var hasRejectCol = false; for(var i=0; i<$parrentPropertiesCopy.children.length; i++){ var child = $parrentPropertiesCopy.children[i]; var id = '_' + child.id; var $cell = $(''); try{ if($($parentControl.find('.tableDeliveredHeader th')[i]).hasClass('hideOnMobileApp')){ $cell.addClass('hideOnMobileApp'); } }catch(ex){} if(id.indexOf('_' + POD_DELIVER_COL_ID)>=0){ //ignore this column continue; }else if(id.indexOf('_' + POD_ID_COL_ID)>=0){ $cell.attr('data', scanReadID); $cell.append(scanReadID); }else if(id.indexOf('_' + POD_STATUS_COL_ID)>=0){ $cell.attr('data', rowStatus); $cell.append(getPODDeliverStatusString(rowStatus, parrentRowProperties.manifestType)); //$cell.append(rowStatus); //$cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_AUTO_ID_COL_ID)>=0){ $cell.addClass('__AutoID'); $cell.attr('data', ''); $cell.append(''); $cell.addClass('hideOnMobileApp'); }else if(id.indexOf('_' + POD_QTY_COL_ID)>=0){ $cell.addClass('__Qty'); $cell.attr('data', qty); $cell.append(qty); }else if(id.indexOf('_' + POD_DAMAGED_COL_ID)>=0){ //damage column $cell.addClass('__Damaged'); $cell.attr('data', damagedNo); if(damagedNo>0){ $cell.append(damagedNo); }else{ $cell.append(''); } }else if(id.indexOf('_' + POD_REJECTED_COL_ID)>=0){ $cell.addClass(CONST_REJECTED); if(rejectedNo > 0){ $cell.attr('data', rejectedNo); $cell.append(rejectedNo); }else{ $cell.append(''); } }else if(id.indexOf('_' + POD_STOP_NO_COL_ID)>=0){ $cell.append('1'); }else { $cell.append(''); } $reportRow.append($cell); } if(!hasRejectCol){ var $cell = $(''); $cell.addClass('__Over'); $cell.attr('data', overCount); $cell.append(overCount==0?'':'Yes'); $reportRow.append($cell); } var $changeBtn = getSelectedQuery4CloneObjectWA('#formview_templates .ctrlPODCell_changeBtn', CONST_CTRL_TYPE_INPUTACTION, undefined).clone(); $changeBtn.find('.actionLabelText').empty().append('Change'); $changeCell = $('').append($changeBtn).addClass(btnClass); $reportRow.append($changeCell); var $ths = $parentControl.find('.DeliveredReportSession thead th'); $tdsTmp = $reportRow.find('td'); for(var i=0; i<$ths.length; i++){ var $th = $($ths[i]); var $td = $($tdsTmp[i]); if($th.hasClass(CONST_HIDEONMOBILEAPP)){ $td.addClass(CONST_HIDEONMOBILEAPP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION_IMP)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION_IMP); } if($th.hasClass(CONST_CSS_CLASS_HIDE_SESSION)){ $td.addClass(CONST_CSS_CLASS_HIDE_SESSION); } if('none' == $th.css(CONST_CSS_KEY_DISPLAY)){ $td.css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); } } $parentControl.find('.DeliveredReportSession .tblDeliveredBody').append($reportRow); updateZebraTable($parentControl.find('.DeliveredReportSession table')); $changeCell.find('.actionBtn').click(function(){ var $removeRow = $($(this).parents('tr')[0]); var changeOverCount = 1; fvDataNS.inputData.PODData[podCtrlName].Over -= changeOverCount; var changeDamaged = 0; try{ changeDamaged = $removeRow.find('.__Damaged').attr('data'); if(isNaN(changeDamaged)){ changeDamaged = 0; } }catch(ex){ changeDamaged = 0; } fvDataNS.inputData.PODData[podCtrlName].Damaged -= changeDamaged; $parentControl.find('.OSDReportSession .OSDRShort').empty().append(fvDataNS.inputData.PODData[podCtrlName].Qty); $parentControl.find('.OSDReportSession .OSDRDamaged').empty().append(fvDataNS.inputData.PODData[podCtrlName].Damaged); $parentControl.find('.OSDReportSession .OSDROver').empty().append(fvDataNS.inputData.PODData[podCtrlName].Over); $removeRow.remove(); updateZebraTable($parentControl.find('.DeliveredReportSession table')); var index = fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name].indexOf($parrentPropertiesCopy); fvDataNS.inputData.PODExtData[$parrentPropertiesCopy.name].splice(index, 1); }); callback(); } } }