'+''+''+"\u0418\u0442\u043e\u0433\u043e \u0441\u0443\u043c\u043c\u0430 \u0431\u0435\u0437 \u041d\u0414\u0421, \u0440\u0443\u0431: "+''+"{[ this.priceFormat(values.price_without_nds) ]}"+""+""+
''+''+"\u0418\u0442\u043e\u0433\u043e \u0441\u0443\u043c\u043c\u0430 c \u041d\u0414\u0421, \u0440\u0443\u0431: "+''+"{[ this.priceFormat(values.price_with_nds) ]}"+""+""+"
"+"",{disableFormats:true,priceFormat:function(v){return Application.models.UtilNsiSettings.priceRenderer()(v)}})}]},listeners:{scope:component,
beforeedit:function(edit){var editable=component.isEditableByCustomer(edit)||component.isEditableBySupplier(edit)||component.isEditableByAdminEtp(edit);this.getColumnModel().setEditable(edit.column,editable)},setsummary:this.setSummary},colModel:this.createColModel()});Application.components.nsiOrderItemGrid.superclass.initComponent.call(this)},setSummary:function(value){if(value){this.setTotalValues(value);this.fireEvent("aftersetsummary",value)}},createStore:function(){var component=this;var fields=
[{name:"id",type:"int",hidden:true},{name:"dictionary_position_name",type:"string"},{name:"dictionary_position_id",type:"int",hidden:true},{name:"position_id",type:"int",hidden:true},{name:"name",type:"string"},{name:"contragent_code",type:"string"},{name:"price",type:"float"},{name:"price_order_price",type:"float"},{name:"nds",type:"float"},{name:"price_order_nds",type:"float"},{name:"quantity",type:"numeric"},{name:"price_order_quantity",type:"numeric"},{name:"okei_name",type:"string"},{name:"order_status",
type:"int",hidden:true}];var reader=new Ext.data.JsonReader({idProperty:"id",root:"rows",totalProperty:"totalCount",messageProperty:"\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435",fields:fields});var proxy=new Ext.data.DirectProxy({api:{read:RPC_nsi.Order.getItems,update:RPC_nsi.Order.updateItems,destroy:RPC_nsi.Order.deleteItems},paramsAsHash:true});return new Ext.data.DirectStore({baseParams:{limit:this.limit,orderId:this.orderId,withDictionaryPosition:1,withOkei:1,withOrder:1,withPriceOrderInfo:1},
autoDestroy:true,autoLoad:false,autoSave:true,reader:reader,writer:new Ext.data.JsonWriter({encode:false,writeAllFields:true}),proxy:proxy,listeners:{load:{fn:function(stor,records,options){this.fireEvent("changed",this);this.updateTotal(records)},scope:this},save:{fn:function(store){this.fireEvent("changed",this)},scope:this},update:{fn:function(stor,records,options){this.fireEvent("changed",this);this.updateTotal(stor.data.items)},scope:this}}})},createColModel:function(){var listenersFields={change:{fn:function(field,
newValue,oldValue){this.fireEvent("changed",this)},scope:this}};var component=this;var renderer=Application.models.UtilNsiSettings;var columns=[new Ext.grid.RowNumberer,{header:"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043a\u043e\u0434 \u041f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430",tooltip:"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043a\u043e\u0434 \u041f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430",dataIndex:"contragent_code",renderer:Ext.util.htmlEncode,
width:50},{header:"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 "+t("\u041a\u0418\u041c"),tooltip:"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 "+t("\u041a\u0418\u041c"),dataIndex:"dictionary_position_name"},{header:"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430",
tooltip:"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430",hidden:true,dataIndex:"name"},{header:"\u0415\u0418",dataIndex:"okei_name",width:10},{header:"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e",tooltip:"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e",dataIndex:"quantity",width:20,editor:new Ext.form.NumberField({allowNegative:false,allowDecimals:true,
decimalPrecision:2,listeners:listenersFields})},{header:"\u0426\u0435\u043d\u0430 \u0437\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443, "+RUB_SIGN,tooltip:"\u0426\u0435\u043d\u0430 \u0437\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443, "+RUB_SIGN,dataIndex:"price",width:40,renderer:renderer.priceRenderer(),editor:new Ext.form.NumberField({allowDecimals:true,allowNegative:false,listeners:listenersFields})},{header:"\u0421\u0443\u043c\u043c\u0430 \u0431\u0435\u0437 \u041d\u0414\u0421, "+RUB_SIGN,
tooltip:"\u0421\u0443\u043c\u043c\u0430 \u0431\u0435\u0437 \u041d\u0414\u0421, "+RUB_SIGN,width:50,dataIndex:"sum_without_nds",scope:this,renderer:function(value,meta,record){return this.getSumNoNds(record.get("price"),record.get("nds"),record.get("quantity"))}},{header:"\u0421\u0442\u0430\u0432\u043a\u0430 \u041d\u0414\u0421, %",tooltip:"\u0421\u0442\u0430\u0432\u043a\u0430 \u041d\u0414\u0421, %",dataIndex:"nds",renderer:renderer.ndsRenderer(),width:20},{header:"\u0421\u0443\u043c\u043c\u0430 \u0441 \u041d\u0414\u0421, "+
RUB_SIGN,tooltip:"\u0421\u0443\u043c\u043c\u0430 \u0441 \u041d\u0414\u0421, "+RUB_SIGN,dataIndex:"sum_with_nds",width:50,scope:this,renderer:function(value,meta,record){return this.getSumNds(record.get("price"),record.get("quantity"))}},{header:"\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438",tooltip:"\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438",xtype:"textactioncolumn",width:30,items:[{icon:"/ico/delete.png",tooltip:"\u0423\u0434\u0430\u043b\u0438\u0442\u044c",isHidden:function(v,meta,rec){if(this.order.customer_contragent_id!=
Main.contragent.id||this.order.status!=Application.models.Order.STATUS_APPROVAL_BY_CUSTOMER&&this.order.status!=Application.models.Order.STATUS_PROJECT)return true;return this.getStore().getCount()==1},handler:function(grid,rowIndex,colIndex,item,eventObject){var data=grid.getStore().data.items[rowIndex].data;var price,qty,nds,priceNotNds,priceWithNds=0;price=data.price;qty=data.quantity;nds=data.price_order_nds;priceNotNds=this.calcSumNoNds(price,nds,qty);priceWithNds=this.calcSumNds(price,qty);
var totalValues=component.getTotalValues();Ext.Msg.confirm("\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435","\u0412\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u044c?",function(btn){if("yes"==btn){component.fireEvent("setsummary",{price_with_nds:Ext.extension.Math.sum(totalValues.price_with_nds,-priceWithNds),price_without_nds:Ext.extension.Math.sum(totalValues.price_without_nds,
-priceNotNds)});grid.getStore().removeAt(rowIndex);grid.getStore().save();grid.getStore().reload();grid.getBottomToolbar().getComponent("summary").tpl.apply(component.getTotalValues());grid.fireEvent("changed",component)}})},scope:component},{icon:"/ico/calendar.png",tooltip:"\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043e\u043a",isHidden:component.isPluralDeliveries,handler:function(grid,rowIndex,colIndex,item,eventObject){var WinId=
Ext.id();var winSize=Ext.getBody().getViewSize();var win=new Ext.Window({layout:"fit",autoScroll:true,resizable:true,height:winSize.height-200,width:winSize.width-200,title:"\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043e\u043a",id:WinId,items:[{xtype:"Application.components.nsiDistributeForm",cmpParams:{itemId:grid.getStore().getAt(rowIndex).get("id"),orderId:grid.orderId,orderQuantity:grid.getStore().getAt(rowIndex).get("quantity"),
WinId:WinId,editionAllowed:(component.orderStatus===Application.models.Order.STATUS_PROJECT||component.orderStatus===Application.models.Order.STATUS_DECLINED_BY_SUPPLIER)&&component.contragentType===Application.models.Request.CONTRAGENT_CUSTOMER}}]});win.show()},scope:component},{icon:"/ico/document.png",tooltip:"\u041a\u0430\u0440\u0442\u043e\u0447\u043a\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438",handler:function(grid,rowIndex){var rec=component.getStore().getAt(rowIndex);var win=new Application.components.NsiCardPositionsWindow({isSupplierMode:false,
positionId:rec.get("position_id"),dictionaryPositionId:rec.get("dictionary_position_id"),dictionaryPositionName:rec.get("dictionary_position_name")});win.show();this.on("destroy",function(){win.close()})},isHidden:function(obj,btn,row){return!(row.get("dictionary_position_id")&&row.get("position_id"))}},{icon:"/ico/nsi/delete-disabled.png",tooltip:"\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e. \u0412 "+t("NSI_ORDER_P6")+" \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043e\u0434\u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u044f.",
isHidden:function(v,meta,rec){if(this.order.customer_contragent_id!=Main.contragent.id||this.order.status==Application.models.Order.STATUS_APPROVAL_BY_SUPPLIER)return true;return this.getStore().getCount()!=1},scope:component}]}];return new Ext.grid.ColumnModel({defaults:{width:120,sortable:true},columns:columns})},showDistributionButtons:function(isPluralDeliveries){var lastIdx=this.getColumnModel().getColumnCount()-1;this.getColumnModel().getColumnById(lastIdx).items[1].isHidden=isPluralDeliveries;
this.getStore().reload()},showColumnsWindow:function(){var grid=this,items=[],cm=grid.getColumnModel();Ext.each(cm.columns,function(column){if(!(column instanceof Ext.ux.grid.TextActionColumn||column.header==""))items.push({boxLabel:column.header,name:column.dataIndex,checked:true})},grid);var checkBox=new Ext.form.CheckboxGroup({xtype:"checkboxgroup",columns:1,items:items});var win=new Ext.Window({title:"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430",
width:400,autoDestroy:true,modal:true,autoHeight:true,bodyStyle:"padding: 4px;",items:[checkBox],buttons:[renderStoreDownloadButton(grid.store,"nsi/Order/getItemsExport",null,false,{tooltip:"\u0421\u043a\u0430\u0447\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Excel.",text:"\u0421\u043a\u0430\u0447\u0430\u0442\u044c"},function(params){var values={};collectComponentValues(checkBox,
values,true);Ext.apply(params,values);return params}),{text:"\u041e\u0442\u043c\u0435\u043d\u0430",handler:function(){win.close()}}]});win.show()},isEditableBySupplier:function(edit){var editable=false,status=edit.record.get("order_status");if(this.order.price_order_id)return false;if(this.contragentType==Application.models.Request.CONTRAGENT_SUPPLIER)editable=status==Application.models.Order.STATUS_APPROVAL_BY_SUPPLIER||status==Application.models.Order.STATUS_DECLINED_BY_CUSTOMER;editable=editable&&
["price"].indexOf(edit.field)>-1;return editable},isEditableByCustomer:function(edit){var editable=false,status=edit.record.get("order_status");if(this.order.price_order_id&&!in_array(edit.field,this.editColoumsInPriceOrder))return false;if(this.contragentType==Application.models.Request.CONTRAGENT_CUSTOMER)editable=status==Application.models.Order.STATUS_PROJECT||status==Application.models.Order.STATUS_DECLINED_BY_SUPPLIER||status==Application.models.Order.STATUS_APPROVAL_BY_CUSTOMER;return editable},
isEditableByAdminEtp:function(edit){var editable=false,status=edit.record.get("order_status");if(isAdminEtp())editable=Application.models.Order.isEditableByAdminEtp({status:status});return editable},calcSumNoNds:function(price,nds,quantity){return Ext.extension.Finance.calcCostNoVAT(price,quantity,nds)},calcSumNds:function(price,quantity){return Ext.extension.Math.multiply(price,quantity)},getSumNoNds:function(price,nds,quantity){return Application.models.UtilNsiSettings.priceRenderer()(this.calcSumNoNds(price,
nds,quantity))},getSumNds:function(price,quantity){return Application.models.UtilNsiSettings.priceRenderer()(this.calcSumNds(price,quantity))},updateTotal:function(items){this.fireEvent("setsummary",{price_with_nds:0,price_without_nds:0});var priceAfter,priceNdsAfter;Ext.each(items,function(item,i){var quantity=parseFloat(item.get("quantity"));priceAfter=parseFloat(this.calcSumNoNds(item.get("price"),item.get("nds"),quantity));priceNdsAfter=parseFloat(this.calcSumNds(item.get("price"),quantity));
var totals=this.getTotalValues();this.fireEvent("setsummary",{price_with_nds:Ext.extension.Math.sum(totals.price_with_nds,priceNdsAfter),price_without_nds:Ext.extension.Math.sum(totals.price_without_nds,priceAfter)})},this)},setTotalValues:function(suminfo){var summary=this.getBottomToolbar().getComponent("summary");if(summary)summary.getStore().loadData([[suminfo.price_with_nds,suminfo.price_without_nds]],false)},getTotalValues:function(){var summary=this.getBottomToolbar().getComponent("summary");
if(summary){var ret={price_with_nds:0,price_without_nds:0};if(summary.getStore().getCount()>0)ret=summary.getStore().getAt(0).data;return ret}}});Ext.define("Application.components.nsiOrderDocumentsGrid",{extend:"Ext.grid.GridPanel",orderId:null,order:null,initComponent:function(){var component=this;Ext.apply(component,{border:false,store:component.createStore(),bbar:new Ext.Toolbar,viewConfig:{forceFit:true,emptyText:"\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442."},columns:component.getColumns(),listeners:{afterrender:component.loadOrder}});Application.components.nsiOrderDocumentsGrid.superclass.initComponent.call(component)},
createStore:function(){var component=this;return new Ext.data.DirectStore({autoLoad:true,autoDestroy:true,baseParams:{orderId:component.orderId},proxy:new Ext.data.DirectProxy({api:{read:RPC_nsi.Order.documentsList},listeners:{exception:function(proxy,type,action,options,response){if(!response.result.success)Ext.MessageBox.alert("\u041e\u0448\u0438\u0431\u043a\u0430",response.result.message)}}}),reader:new Ext.data.JsonReader({root:"rows",fields:[{name:"id",type:"int"},{name:"name",type:"string"},
{name:"link",type:"string"},{name:"descr",type:"string"},{name:"doc_type_name",type:"string"},{name:"doc_type",type:"string"},{name:"source_name",type:"string"},{name:"supplier_eds_state",type:"string"},{name:"customer_eds_state",type:"string"},{name:"supplier_eds_info",type:"string"},{name:"customer_eds_info",type:"string"},{name:"supplier_eds",type:"string"},{name:"customer_eds",type:"string"},{name:"contragent_id",type:"int"},{name:"nsi_vocab_order_document_type_code",type:"string"},{name:"date_created",
type:"date",dateFormat:"c"},{name:"created_in_order_status",type:"int"}]})})},getColumns:function(){var component=this;return[{header:"\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435",dataIndex:"name",renderer:function(value,metaData,record){if(record.get("link")==="")return value;return'