Files
OMS/app/console/view/admin/iostock/instock_add.html
2025-12-28 23:13:25 +08:00

638 lines
27 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
Copyright © ShopeX http://www.shopex.cn. All rights reserved.
See LICENSE file for license details.
-->
<{capture name="header"}>
<{css app="ome" src="ome.css"}>
<{css app="ome" src="style.css"}>
<{script src="coms/autocompleter.js" app="desktop"}>
<{script src="coms/pager.js" app="desktop"}>
<{/capture}>
<form method="post" id="form1" action="index.php?app=console&ctl=admin_iostockorder&act=do_save_iostockorder">
<input type="hidden" name="io" value="<{$io}>" />
<div class="tableform">
<h3>入库单新建</h3>
<div class="division">
<h5>基本信息</h5>
<table border="0" cellspacing="0" cellpadding="0" class="gridlist">
<thead>
<tr>
<td width="10%" align="right" nowrap="nowrap">入库单名称:</td>
<td width="40%"><span id="exigence" style="color:red; display:none"></span>
<input type="text" size="32" onblur="checkName(this.value);" id="iostockorder_name" name="iostockorder_name" value="<{$cur_date}>" />
<input type="checkbox" name="emergency" value="true" onchange="chgexigence(this);" />
紧急入库</td>
<{if $act='allocate_iostock'}>
<td width="10%" align="right">来源地:</td>
<td>
<{input type="select" name="extrabranch_id" vtype="required" rows=$extrabranch valueColumn="branch_id" labelColumn="name" value=""}>
</td>
<{/if}>
</tr>
<tr>
<td align="right">供应商:</td>
<td width="40%">
<span id="auto_supp" style="position:relative;">
<{img class="pointer btn_supplier" title="查看供应商列表" app="desktop" src="bundle/zoom_btn.gif"}>
<input type="text" id="supplier" name="supplier" />
<input type="hidden" name="supplier_id" id="supplier_id" value="" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: #999">(若有供应商,但点击按钮无反应请先浏览器兼容性设置,详见帮助中心)</span>
</span>
</td>
<td width="10%" align="right">仓库:</td>
<td>
<{if $is_super}>
<{if count($branch)=='1'}>
<{$branch.0.name}>
<input type="hidden" name="branch" value="<{$branch.0.branch_id}>" />
<{elseif count($branch)>'5' }>
<{input type="select" name="branch" vtype="required" rows=$branch valueColumn="branch_id" labelColumn="name" value=""}> <span style="color:red">*</span>
<{else}>
<{foreach from=$branch item=items key=keys}>
<input type="radio" name="branch" vtype="requiredradio" value="<{$items.branch_id}>" <{if $keys==0}>checked="checked"<{/if}> />
<{$items.name}>
<{/foreach}> <span style="color:red">*</span>
<{/if}>
<{else}>
<{if !$branch_list}>
<font color="red">* 当前没有操作仓库的权限,请联系管理员分配。 *</font>
<script>
$$("input","button","select").set('disabled',true);
</script>
<{else}>
<{if count($branch_list)==1}>
<{$branch_list.0.name}>
<input type="hidden" name="branch" value="<{$branch_list.0.branch_id}>" />
<{elseif count($branch_list)>5}>
<{input type="select" name="branch" vtype="required" rows=$branch_list valueColumn="branch_id" labelColumn="name" value=""}> <span style="color:red">*</span>
<{else}>
<{foreach from=$branch_list item=items key=keys}>
<input type="radio" name="branch" vtype="requiredradio" <{if $keys==0}>checked="checked"<{/if}> value="<{$items.branch_id}>" />
<{$items.name}>
<{/foreach}> <span style="color:red">*</span>
<{/if}>
<{/if}>
<{/if}>
</td>
</tr>
<tr>
<td align="right">入库类型:</td>
<td><select name="type_id" id="type_id">
<{foreach from=$iostock_types key=type_id item=type_name}>
<option value='<{$type_id}>'><{$type_name}></option>
<{/foreach}>
</select>
</td>
<td align="right" nowrap="nowrap">入库费用:</td>
<td>
<input type="text" size="2" id="iso_price" name="iso_price" />
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap">领用部门:</td>
<td><{input name="cost_department" type="text"}></td>
</tr>
<tr>
<td align="right">业务类型:</td>
<td id="bill_type_td">
</td>
<td align="right" nowrap="nowrap">业务单号:</td>
<td>
<input type="text" id="business_bn" name="business_bn" />
</td>
</tr>
</thead>
</table>
</div>
<div class="division">
<h5>发货人信息</h5>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th>联系地区:</th>
<td colspan="3"><{input type="region" name="extra_ship_area" value=$iso.extra_ship_area}></td>
</tr>
<tr>
<th>联系姓名:</th>
<td><{input type="text" name="extra_ship_name" value=$iso.extra_ship_name size="32"}></td>
<th>联系邮编:</th>
<td><{input type="text" name="extra_ship_zip" value=$iso.extra_ship_zip size="32"}></td>
</tr>
<tr>
<th>联系手机:</th>
<td><{input type="text" name="extra_ship_mobile" value=$iso.extra_ship_mobile size="32"}></td>
<th>联系Email</th>
<td><{input type="text" name="extra_ship_email" value=$iso.extra_ship_email size="32"}></td>
</tr>
<tr>
<th>联系详细地址:</th>
<td colspan="3"><{input type="text" name="extra_ship_addr" value=$iso.extra_ship_addr size="32"}></td>
</tr>
</table>
</div>
<div class="division">
<h5 style="margin-top:10px;">入库商品</h5>
<{button label="供应商频道" id="supplier-find-btn" }>
<{button label="基础物料库频道" id="iostockorder-find-btn" }>
<span id='pfba3'>
<label>按条形码索引:</label>
<input type="text" name="barcode" />
</span>
<span id='pfba'>
<label>按基础物料编码索引:</label>
<input type="text" name="bn" />
</span>
<span id='pfba2'>
<label>按基础物料名称索引:</label>
<input name="name" type="text" size="35" />
</span>
<table class="gridlist" id="iostockorder_table" style="margin:4px 0;">
<thead>
<tr>
<th><input type="checkbox" class='selectall' onclick="this.blur()"></th>
<th>基础物料编码</th>
<th style="width:240px;">基础物料名称</th>
<th>规格</th>
<th>条形码</th>
<th>结存单位成本</th>
<th>数量</th>
<th>单价</th>
<th>合计</th>
<th style="width:30px;">删除</th>
</tr>
</thead>
<tbody id="dataNode">
<tr>
<td colspan="10" style="padding:0;"><div class="note" style="margin:0;"> 暂无入库货品信息 </div></td>
</tr>
</tbody>
</table>
<div align="right">
入库总量: <span id="buy_count">0</span> 总金额: <span id="buy_amount">0</span> &nbsp; <{button label="删除选中" id="iostockorder-del-btn"}> &nbsp;<{button type="button" id="iostockorder-delall-btn" label="全部删除" }></div> </div>
<div class="division">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-top:10px;">
<tr>
<td align="right">经办人:</td>
<td align="left"><input class="x-input" name="operator" type="text" value="<{$operator}>" size="15" vtype="required"/></td>
<td width="10%" align="right">备注:</td>
<td align="left"><textarea class="x-input" id="memo" maxth="255" rows="3" cols="80%" name="memo" type="textarea"></textarea></td>
</tr>
</table>
</div>
<div id="cc" class="noprint table-action"> <{button type="button" id="iostockorder-save-btn" label="保 存"}> &nbsp; <{button type="button" class="btn-secondary" id="return-btn" label="关 闭" onclick="javascript:void(window.close());"}></div>
</div>
</form>
<script>
(function(){
var visiTips = new Tips({
onShow:function(tip,el){
el.addClass('active');
tip.setStyle('display','block');
},
text: function(element){
if(element.get('visibility')=='false'){
return '不可售商品';
}else{
return '';
}
}
});
var branchVal = branchValue();
var callurl='index.php?app=purchase&ctl=admin_purchase&act=getProducts' + '&p[0]=' + branchVal,store=[];
var options={
'getVar':'bn',
'fxOptions':false,
callJSON:function(){return window.autocompleter_json;},
injectChoice:function(json){
var choice = new Element('li', {'html': this.markQueryValue(json[this.options.getVar])});
choice.store('_data',json);
choice.inputValue = json[this.options.getVar];
this.addChoiceEvents(choice).inject(this.choices);
},
onHide:function(ipt){
if(!this.selected || ipt.value=='')return;
var json=this.selected.retrieve('_data');
json=$splat(json);
init(json);
MessageBox.success('加载商品成功!!');
},
onFocus:function(ipt){
ipt.value='';
var branchVal = branchValue();
this.url += '&p[0]=' + branchVal;
}
};
new Autocompleter.script($E('#auto_supp input[type=text]'),"index.php?app=purchase&ctl=admin_supplier&act=getSupplier", $merge(options,{
'getVar':'name',
injectChoice:function(json){
var brief=json["brief"]?"("+json["brief"]+")":"";
var choice = new Element('li', {'html': this.markQueryValue(json[this.options.getVar]+brief)});
choice.store('_data',json);
choice.inputValue = json[this.options.getVar];
this.addChoiceEvents(choice).inject(this.choices);
$('supplier_id').set("value",json["supplier_id"]);
},
onHide:function(){
if(!this.selected)return;
var json=this.selected.retrieve('_data');
$('supplier_id').set("value",json["supplier_id"]);
},
onFocus:$empty
}));
new Autocompleter.script($E('#pfba input'),callurl, options);
new Autocompleter.script($E('#pfba2 input'),callurl,$merge(options,{'getVar':'name'}));
new Autocompleter.script($E('#pfba3 input'),callurl,$merge(options,{'getVar':'barcode'}));
var tpl='<tr key="{product_id}" id="product_{product_id}" title="点击选取/反选此条记录">'+
' <td><input type="checkbox" class="product_select"></td> <td>{bn}</td><td class="product-name" visibility="{visibility}"><input type="hidden" name="product_name[{product_id}]" value="{name}" /><input type="hidden" name="bn[{product_id}]" value="{bn}" /><input type="hidden" name="unit[{product_id}]" value="{unit}" />{name}</td><td>{spec_info}</td><td>{barcode}</td><td>{unit_cost}</td>'+
' <td><input type="text" value="{num}" key="num" vtype="unsigned&amp;&amp;required" tname="at[_PRIMARY_]" size="6"></td>'+
' <td><input type="text" vtype="number&amp;&amp;required" tname="pr[_PRIMARY_]" key="price" value="{price}" size="8">元</td>'+
' <td class="count">{count}</td>'+
' <td><{img src="bundle/delecate.gif" app="desktop" key="state" class="pointer btn-delete-item"}></td>'+
'</tr>';
function branchValue() {
var bid = 0;
$$('input[name="branch"]','select[name="branch"]').each(function(item){
var type = item.type;
if(type == 'radio'){
if(item.checked){
bid = item.value;
}
}else if(type=='hidden'){
bid = item.value;
}else{
bid = item.value;
}
});
return bid;
}
$('iostockorder-find-btn').addEvent('click',function(e){
var url='index.php?app=desktop&act=alertpages&goto='+encodeURIComponent('index.php?app=console&ctl=admin_purchase&act=findMaterial');
Ex_Loader('modedialog',function() {
var branchVal = branchValue();
new finderDialog(url,{params:{url:callurl + '&p[0]=' + branchVal,name:'product_id[]'},width:1000,height:660,
onCallback:function(rs){
if(!rs)return;
rs=JSON.decode(rs);
init(rs);
}
});
});
});
//从供应商查找商品
$('supplier-find-btn').addEvent('click',function(){
if ($("supplier_id").get("value").trim().length===0){
$('supplier').addClass("error_supplier");
return MessageBox.error("请先填写正确的供应商");
}
$('supplier').removeClass("error_supplier");
var supplier_id = $('supplier_id').value;
var url='index.php?app=desktop&act=alertpages&goto='+encodeURIComponent('index.php?app=console&ctl=admin_purchase&act=findMaterial&p[0]='+supplier_id);
Ex_Loader('modedialog',function() {
var branchVal = branchValue();
return new finderDialog(url,{params:{url:callurl + '&p[0]=' + branchVal,name:'product_id[]'},width:1000,height:650,
onCallback:function(rs){
if(!rs)return;
rs=JSON.decode(rs);
init(rs);
}});
});
});
$E(".btn_supplier").addEvent('click',function(e){
var url='?app=desktop&act=alertpages&goto='+encodeURIComponent("index.php?app=console&ctl=admin_supplier&singleselect=1");
Ex_Loader('modedialog',function() {
new finderDialog(url,{params:{url:'index.php?app=console&ctl=admin_supplier&act=getSupplierById',name:'id',type:'radio'},handle:'supplier',width:1000,height:500});
});
});
var pag;
function emptyData(){
var noData='<tr>'+
'<td colspan="8" style="padding:0;"><div class="note" style="margin:0;"> 暂无入库货品信息 </div></td>'+
'</tr>';
$('dataNode').set('html',noData);
}
function createProduct(data){
pag=new PageData(tpl,data,{'updateMain':$('dataNode'),'pageNum':10000,
'format': function(d) {
d.count = (d.num * d.price).toFixed(3);
},
'onShow':function(){
var _this=this;
/*$$('#dataNode input[type]').addEvent('change',function(e){
var pid=this.getParent('tr').get('key'),value=this.value;
_this.editData(pid,[this.get('key'),value]);
});*/
$$('#dataNode input[tname$="[_PRIMARY_]"]').each(function(item){
item.store('initval',item.value).addEvent('change',function(e){
var patten,
parent = this.getParent('tr'),
pid= parent.get('key'),
value= this.value,
diffval = this.retrieve('initval') - value;
if (/^at\[/.test(this.get('tname'))){
patten = /^[1-9]\d*$/;
}else{
patten = /^\d+(\.*)\d*$/;
}
if(!patten.test(value)){
this.focus();
this.select();
return MessageBox.error('输入格式有误!');
}
this.store('initval', value);
_this.editData(pid,[this.get('key'),value]);
var count = parent.getElement('td.count'),
num = _this.selectData(pid).num.toInt(),
pr = _this.selectData(pid).price.toFloat(),
sums = (num * pr).toFixed(3);
count.set('text',sums);
_this.editData(pid,['count',sums]);
if (/^at\[/.test(this.get('tname'))){
$('buy_count').set('text', $('buy_count').get('text') - diffval);
$('buy_amount').set('text', ($('buy_amount').get('text') - diffval * pr).toFixed(3));
}else{
$('buy_amount').set('text', ($('buy_amount').get('text') - diffval * num).toFixed(3));
}
});
});
/*var state=this.curdata.every(function(d){return d['state']=='checked';});
$('iostockorder-delall-btn').checked=!state?false:true;
attachEsayCheck($('dataNode'),'input[type=checkbox]');*/
$$('#dataNode tr').each(function(item,i){
item.addEvent('click',function(e){
// e.stop();
this.toggleClass('selected');
_this.selectData(this.get('key')).selected = _this.selectData(this.get('key')).selected && _this.selectData(this.get('key')).selected === true ? false : true;
var selectflag = _this.selectData(this.get('key')).selected;
var selectproduct = item.getElement('.product_select');
if (selectflag)
{
selectproduct.set('checked','checked');
}else{
selectproduct.set('checked','');
}
});
item.getElement('.btn-delete-item').addEvent('click',function(e){
e.stop();
if(_this.selectData(item.get('key')) && confirm('确定要删除 '+ _this.selectData(item.get('key'))['name'] +' 吗?')){
compute(item);
_this.delData(item.get('key'));
}
if(!$E('#dataNode tr')) emptyData();
});
item.getElement('input[tname^=at]').addEvent('enter',function(e){
$E('#pfba3 input').focus();
});
});
//var len = this.data.length ? (this.data.length > this.options.pageNum ? (this.options.current == this.getTotal() ? this.data.length-this.options.pageNum*(this.options.current-1) : this.options.pageNum) : this.data.length) : 0;
if(this.data.length) $E('#dataNode input[key^=num]').focus();
$ES('.product-name').each(function(item){
if(item.get('visibility')=='false'){
item.setStyle('color','#808080');
}
});
$ES('.product-name').removeEvent('mouseover').addEvent('mouseover',function(e){
if (this.get('visibility')=='false')
{
var e = new Event(e), el = e.target;
visiTips.attach(el);
el.addEvent('mouseleave',function(){
this.removeClass('active');
});
el.fireEvent('mouseenter',e);
}
});
}
});
}
$('iostockorder-delall-btn').addEvent('click',function(e){
if(!pag||!pag.data)return;
var delarr=[];
pag.data.each(function(d){
delarr.push(d['product_id']);
});
if(delarr.length && confirm('确认删除全部入库商品吗?')){
delProduct(pag,delarr);
$('buy_count').set('text',0);
$('buy_amount').set('text',0);
emptyData();
}
});
$E('.selectall').addEvent('click',function(e){
if (this.checked)
{
$ES('.product_select').set('checked','checked');
$$('.product_select').each(function(item){
protr = item.getParent('tr');
product_id = protr.get('key');
protr.addClass('selected');
pag.selectData(product_id).selected=true;
});
}else{
$ES('.product_select').set('checked','');
$$('.product_select').each(function(item){
protr = item.getParent('tr');
product_id = protr.get('key');
protr.removeClass('selected');
pag.selectData(product_id).selected=false;
});
}
});
$('iostockorder-del-btn').addEvent('click',function(e){
if(!pag||!pag.data)return;
var delarr=[];
pag.data.each(function(d,i){
if(pag.selectData(d['product_id']).selected && pag.selectData(d['product_id']).selected === true) delarr.push(d['product_id']);
});
if(delarr.length){
if(confirm('确认删除选定的入库商品吗?')){
var nums=0,prices=0,sums=0;
delarr.each(function(id,i){
nums += pag.selectData(id).num.toInt();
prices += pag.selectData(id).price.toFloat();
sums += pag.selectData(id).num.toInt() * pag.selectData(id).price.toFloat();
});
$('buy_count').set('text',$('buy_count').get('text') - nums);
$('buy_amount').set('text',($('buy_amount').get('text') - sums).toFixed(3));
delProduct(pag,delarr);
}
if(!$E('#dataNode tr')) emptyData();
}
else MessageBox.error("请先选择欲删除的入库商品!");
});
function compute(e){
var num = e.getElement('input[tname="at[_PRIMARY_]"]').value.toInt();
var pr = e.getElement('input[tname="pr[_PRIMARY_]"]').value.toFloat();
var sum = num * pr;
$('buy_count').set('text',$('buy_count').get('text') - num);
$('buy_amount').set('text',($('buy_amount').get('text') - sum).toFixed(3));
}
function init(rs){
var tmparr=findProduct(rs,'product_id');
store.unshift.apply(store,tmparr);
createProduct(store);
}
function findProduct(arr,PRIMARY){
if(!store.length)return arr;
store.each(function(a){
arr.each(function(b){
if(a[PRIMARY]==b[PRIMARY])arr.erase(b);
});
});
return arr;
}
function delProduct(obj,arr){
arr.each(function(d){obj.delData(d);});
}
$('iostockorder-save-btn').addEvent('click',function(e){
var _this = this;
var form = _this.getParent('form');
if(pag){
var data=pag.toHideInput($('dataNode').getElement('tr'));
form.store('target',{extraData:data,
onRequest:function(){
_this.disabled=true;
},
onComplete:function(jsontext){
try{
var json = JSON.decode(jsontext);
if (typeof(json.error)!='undefined'){
_this.disabled=false;
}else{
_this.disabled=true;
if(opener.finderGroup['<{$env.get.finder_id}>']) opener.finderGroup['<{$env.get.finder_id}>'].refresh.delay(100,opener.finderGroup['<{$env.get.finder_id}>']);
setTimeout('window.close()',200);
}
}catch(e){}
}
});
}
if(!data) {
MessageBox.error("请先选择入库商品!");
return false;
}
if(data.indexOf('=0&pr')>=0) {
MessageBox.error("入库商品的数量不能为0");
return false;
}else{
form.fireEvent('submit',e);
}
});
var pre_etv_brandVal;
$$('input[name="branch"]','select[name="branch"]').each(function(item){
var type = item.type;
if(type == 'radio'){
pre_etv_brandVal = branchValue();
$$(item).addEvent('click', function(e,a,b){
if(e.target.value != pre_etv_brandVal) {
updateFreezeProducts();
pre_etv_brandVal = e.target.value;
}
});
}else if(type=='hidden'){
return true;
}else{
$$(item).addEvent('change', function(e){
updateFreezeProducts();
});
}
});
function updateFreezeProducts(){
if(!pag||!pag.data)return;
var delarr=[];
var delNum = [];
var delPrice = [];
var branchVal = branchValue();
pag.data.each(function(d){
delarr.push(d['product_id']);
delNum[d['product_id']] = d['num'];
delPrice[d['product_id']] = d['price'];
});
if(delarr.length){
delProduct(pag,delarr);
new Request({
url:callurl + '&p[0]=' + branchVal,
method:'post',
data:{'product_id':delarr},
onSuccess:function(json){
if(!json) return;
rs=JSON.decode(json);
rs.each(function(item,index){
rs[index].num = delNum[item.product_id];
// rs[index].price = delPrice[item.product_id];
});
init(rs);
}
}).send();
}
};
var ioProduct = JSON.decode('<{$io_product}>');
if(ioProduct) {
createProduct(ioProduct);
var oNum = 0;
var oPr = 0;
$$('input[key=num]').each(function(item, index) {
oNum += item.value.toInt();
oPr += item.getParent('tr').getElement('input[key=price]').value.toFloat() * item.value.toInt();
});
$('buy_count').set('text', oNum);
$('buy_amount').set('text',oPr.toFixed(3));
}
$('type_id').addEvent('change', function(){
let oVal = this.value;
new Request.JSON({
url: 'index.php?app=ome&ctl=admin_iso_type&act=getBillType',
data: {
type_id:oVal,
},
onSuccess: function(json) {
if(json.data) {
let sHtml = '<select name="bill_type"><option></option>';
Object.each(json.data, function(item){
sHtml += '<option value="'+item.bill_type+'">'+item.bill_type_name+'</option>';
})
sHtml += "</select>";
$('bill_type_td').setHTML(sHtml);
} else {
$('bill_type_td').setHTML('没有可选项');
}
}
}).send();
});
$('type_id').fireEvent('change', {});
})();
function chgexigence(o){
o.checked?$("exigence").show():$("exigence").hide();
}
function checkName(thisval){
if(/!|/.test(thisval)){
var val = thisval.replace("!","");
val = val.replace("","");
$('iostockorder_name').set('value', val);
}
}
</script>