SendNotify.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.sale.SendNotify', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views: ['core.form.Panel', 'scm.sale.Quotation', 'core.grid.Panel2', 'core.toolbar.Toolbar', 'core.form.MultiField',
  8. 'core.button.Save', 'core.button.Add', 'core.button.ResAudit', 'core.button.Audit',
  9. 'core.button.ResSubmit', 'core.button.Close', 'core.button.Delete', 'core.button.Update',
  10. 'core.button.DeleteDetail', 'core.button.Consign', 'core.button.Submit',
  11. 'core.button.TurnProdIO', 'core.button.Flow', 'core.button.Print','core.button.PrintHK','core.button.PrintInvoice', 'core.button.PrintBZT',
  12. 'core.button.TurnOtherOut','core.button.SaveShip','core.button.TurnProdAppropriationOut', 'core.button.TurnExOut',
  13. 'core.trigger.DbfindTrigger', 'core.trigger.TextAreaTrigger', 'core.form.YnField', 'core.grid.Panel5', 'core.form.FileField','core.grid.YnColumn','core.button.Split'],
  14. init: function() {
  15. var me = this;
  16. this.control({
  17. 'erpGridPanel2': {
  18. afterrender: function(grid) {
  19. var status = Ext.getCmp('sn_statuscode');
  20. if (status && status.value != 'ENTERING' && status.value != 'COMMITED') {
  21. Ext.each(grid.columns,
  22. function(c) {
  23. c.setEditor(null);
  24. });
  25. }
  26. },
  27. reconfigure: function(grid) {
  28. var f = Ext.getCmp('sn_id');
  29. if (f && !Ext.isEmpty(f.value)) {
  30. me.loadOnHandQty(grid, f.value);
  31. }
  32. },
  33. itemclick: this.onGridItemClick
  34. },
  35. '#splitButton': {
  36. click: function(btn){
  37. var record = btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  38. me.SaleSplit(record);
  39. }
  40. },
  41. 'field[name=sn_currency]': {
  42. beforetrigger: function(field) {
  43. var t = field.up('form').down('field[name=sn_date]'),
  44. value = t.getValue();
  45. if(value) {
  46. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  47. }
  48. }
  49. },
  50. 'erpSaveButton': {
  51. click: function(btn) {
  52. var form = me.getForm(btn);
  53. if (Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == '') {
  54. me.BaseUtil.getRandomNumber(); //自动添加编号
  55. }
  56. this.beforeSaveSendNotify();
  57. }
  58. },
  59. 'erpDeleteButton': {
  60. click: function(btn) {
  61. me.FormUtil.onDelete({
  62. id: Number(Ext.getCmp('sn_id').value)
  63. });
  64. }
  65. },
  66. 'erpUpdateButton': {
  67. afterrender: function(btn) {
  68. var status = Ext.getCmp('sn_statuscode');
  69. if (status && status.value != 'ENTERING') {
  70. btn.hide();
  71. }
  72. },
  73. click: function(btn) {
  74. me.beforeUpdate();
  75. }
  76. },
  77. 'erpAddButton': {
  78. click: function() {
  79. me.FormUtil.onAdd('addSendNotify', '新增出货通知单', 'jsps/scm/sale/sendNotify.jsp');
  80. }
  81. },
  82. 'erpCloseButton': {
  83. click: function(btn) {
  84. me.FormUtil.beforeClose(me);
  85. }
  86. },
  87. 'erpPrintButton': {
  88. click: function(btn) {
  89. var reportName = "SendNotify";
  90. var condition = '{SendNotify.sn_id}=' + Ext.getCmp('sn_id').value + '';
  91. me.FormUtil.onwindowsPrint2(Ext.getCmp('sn_id').value, reportName, condition);
  92. }
  93. },
  94. 'erpPrintBZTButton': {
  95. click: function(btn) {
  96. var reportName = "SendNotify_packing";
  97. var condition = '{SendNotify.sn_id}=' + Ext.getCmp('sn_id').value + '';
  98. me.FormUtil.onwindowsPrint(Ext.getCmp('sn_id').value, reportName, condition);
  99. }
  100. },
  101. 'erpPrintInvoiceButton': {
  102. click: function(btn) {
  103. var reportName = "SendNotify_invoice";
  104. var condition = '{SendNotify.sn_id}=' + Ext.getCmp('sn_id').value + '';
  105. me.FormUtil.onwindowsPrint(Ext.getCmp('sn_id').value, reportName, condition);
  106. }
  107. },
  108. 'erpPrintHKButton': {
  109. click: function(btn) {
  110. var reportName = "SendNotify_HK";
  111. var condition = '{SendNotify.sn_id}=' + Ext.getCmp('sn_id').value + '';
  112. me.FormUtil.onwindowsPrint(Ext.getCmp('sn_id').value, reportName, condition);
  113. }
  114. },
  115. 'erpSubmitButton': {
  116. afterrender: function(btn) {
  117. var status = Ext.getCmp('sn_statuscode');
  118. if (status && status.value != 'ENTERING') {
  119. btn.hide();
  120. }
  121. },
  122. click: function(btn) {
  123. var grid = Ext.getCmp('grid'),
  124. items = grid.store.data.items;
  125. var rateMsg = '';
  126. // 税率为0提示
  127. Ext.each(items,
  128. function(item) {
  129. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  130. if (item.data['snd_taxrate'] == 0) {
  131. rateMsg += item.data['snd_pdno'] + ' ';
  132. }
  133. }
  134. });
  135. if (rateMsg != '') {
  136. warnMsg('明细行:' + rateMsg + '的税率为0,是否继续?',
  137. function(btn) {
  138. if (btn == 'ok' || btn == 'yes') {
  139. me.FormUtil.onSubmit(Ext.getCmp('sn_id').value);
  140. }
  141. });
  142. } else {
  143. me.FormUtil.onSubmit(Ext.getCmp('sn_id').value, false, me.beforeUpdate, me);
  144. }
  145. }
  146. },
  147. 'erpResSubmitButton': {
  148. afterrender: function(btn) {
  149. var status = Ext.getCmp('sn_statuscode');
  150. if (status && status.value != 'COMMITED') {
  151. btn.hide();
  152. }
  153. },
  154. click: function(btn) {
  155. me.FormUtil.onResSubmit(Ext.getCmp('sn_id').value);
  156. }
  157. },
  158. 'erpAuditButton': {
  159. afterrender: function(btn) {
  160. var status = Ext.getCmp('sn_statuscode');
  161. if (status && status.value != 'COMMITED') {
  162. btn.hide();
  163. }
  164. },
  165. click: function(btn) {
  166. me.FormUtil.onAudit(Ext.getCmp('sn_id').value);
  167. }
  168. },
  169. 'erpResAuditButton': {
  170. afterrender: function(btn) {
  171. var status = Ext.getCmp('sn_statuscode');
  172. if (status && status.value != 'AUDITED') {
  173. btn.hide();
  174. }
  175. },
  176. click: function(btn) {
  177. me.FormUtil.onResAudit(Ext.getCmp('sn_id').value);
  178. }
  179. },
  180. 'erpTurnOtherOutButton':{//转其它出库
  181. afterrender: function(btn) {
  182. var status = Ext.getCmp('sn_statuscode');
  183. if (status && status.value != 'AUDITED') {
  184. btn.hide();
  185. }
  186. },
  187. click:function(){
  188. me.turn('SendNotify!ToProdIN!Deal', 'snd_snid=' + Ext.getCmp('sn_id').value +' and nvl(snd_yqty,0) < nvl(snd_outqty,0) and snd_statuscode=\'AUDITED\'', 'scm/sale/turnProdOut.action?type=ProdInOut!OtherOut');
  189. }
  190. },
  191. 'erpTurnExOutButton':{//转换货出库单
  192. afterrender: function(btn) {
  193. var status = Ext.getCmp('sn_statuscode');
  194. if (status && status.value != 'AUDITED') {
  195. btn.hide();
  196. }
  197. },
  198. click:function(){
  199. me.turn('SendNotify!ToProdIN!Deal', 'snd_snid=' + Ext.getCmp('sn_id').value +' and nvl(snd_yqty,0) < nvl(snd_outqty,0) and snd_statuscode=\'AUDITED\'', 'scm/sale/turnProdOut.action?type=ProdInOut!ExchangeOut');
  200. }
  201. },
  202. 'erpTurnProdAppropriationOutButton':{//转拨出单
  203. afterrender: function(btn) {
  204. var status = Ext.getCmp('sn_statuscode');
  205. if (status && status.value != 'AUDITED') {
  206. btn.hide();
  207. }
  208. },
  209. click:function(){
  210. me.turn('SendNotify!ToAppropriationOut!Deal', 'snd_snid=' + Ext.getCmp('sn_id').value + ' and snd_statuscode=\'AUDITED\'', 'scm/sale/turnProdOut.action?type=ProdInOut!AppropriationOut');
  211. }
  212. },
  213. 'erpTurnProdIOButton':{//转出货单
  214. afterrender: function(btn) {
  215. var status = Ext.getCmp('sn_statuscode');
  216. if (status && status.value != 'AUDITED') {
  217. btn.hide();
  218. }
  219. }
  220. },
  221. 'erpSaveShipButton':{
  222. afterrender:function(btn){
  223. var status = Ext.getCmp('sn_statuscode');
  224. if (status && status.value != 'COMMITED') {
  225. btn.hide();
  226. }else{
  227. Ext.each(Ext.getCmp('form').items.items,function(item){
  228. if(item.groupName=='船务信息'){
  229. item.setReadOnly(false);
  230. }
  231. });
  232. }
  233. },
  234. click:function(){
  235. var values=new Object();
  236. Ext.each(Ext.getCmp('form').items.items,function(item){
  237. if(item.groupName=='船务信息'){
  238. values[item.name]=item.value;
  239. }
  240. });
  241. values['sn_id']=Ext.getCmp('sn_id').value;
  242. var params=new Object();
  243. params.formStore = unescape(escape(Ext.JSON.encode(values)));
  244. var main = parent.Ext.getCmp("content-panel");
  245. main.getActiveTab().setLoading(true);//loading...
  246. Ext.Ajax.request({
  247. url : basePath + 'scm/sale/saveShip.action',//scm/sale/turnProdOut.action?type=ProdInOut!OtherOut
  248. params: params,
  249. method : 'post',
  250. timeout: 6000000,
  251. callback : function(options,success,response){
  252. main.getActiveTab().setLoading(false);
  253. var localJson = new Ext.decode(response.responseText);
  254. if(localJson.exceptionInfo){
  255. var str = localJson.exceptionInfo;
  256. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  257. str = str.replace('AFTERSUCCESS', '');
  258. }
  259. showError(str);return;
  260. }
  261. if(localJson.success){
  262. showMessage("提示","保存船务信息成功");
  263. window.location.reload();
  264. }
  265. }
  266. });
  267. }
  268. },
  269. 'dbfindtrigger[name=sn_toplace]': {
  270. afterrender: function(trigger) {
  271. trigger.dbKey = 'sn_custcode';
  272. trigger.mappingKey = 'cu_code';
  273. trigger.dbMessage = '请先选客户编号!';
  274. }
  275. },
  276. 'dbfindtrigger[name=sn_custcode2]': {
  277. afterrender: function(trigger) {
  278. trigger.dbKey = 'sn_custid';
  279. trigger.mappingKey = 'cu_id';
  280. trigger.dbMessage = '请先选客户编号!';
  281. }
  282. },
  283. 'dbfindtrigger[name=sn_invoiceremark]': {
  284. afterrender: function(trigger) {
  285. trigger.dbKey = 'sn_custid';
  286. trigger.mappingKey = 'cu_id';
  287. trigger.dbMessage = '请先选客户编号!';
  288. }
  289. },
  290. 'dbfindtrigger[name=sn_packingremark]': {
  291. afterrender: function(trigger) {
  292. trigger.dbKey = 'sn_custid';
  293. trigger.mappingKey = 'cu_id';
  294. trigger.dbMessage = '请先选客户编号!';
  295. }
  296. },
  297. 'dbfindtrigger[name=sn_receivecode]': {
  298. afterrender: function(trigger) {
  299. trigger.dbKey = 'sn_custid';
  300. trigger.mappingKey = 'cu_id';
  301. trigger.dbMessage = '请先选客户编号!';
  302. }
  303. },
  304. 'dbfindtrigger[name=sn_paymentscode]': {
  305. afterrender: function(trigger) {
  306. if (trigger.fieldConfig == 'PT') {
  307. trigger.dbKey = 'sn_custcode';
  308. trigger.mappingKey = 'cu_code';
  309. trigger.dbMessage = '请先选客户编号!';
  310. }
  311. }
  312. },
  313. 'field[name=snd_batchcode]': {
  314. beforetrigger: function(t) {
  315. var record = t.record,
  316. grid = t.owner;
  317. if (record && grid) {
  318. var form = grid.ownerCt.down('form'),
  319. p = grid.xtype == 'erpGridPanel2' ? record.get('snd_prodcode') : form.down('field[name=snd_prodcode]').value;
  320. var w = record.get('snd_warehousecode');
  321. t.dbBaseCondition = '';
  322. if (!Ext.isEmpty(w)) {
  323. t.dbBaseCondition = ' ba_whcode=\'' + w + '\'';
  324. }
  325. if (!Ext.isEmpty(p)) {
  326. if (t.dbBaseCondition.length > 0) {
  327. t.dbBaseCondition += ' and ';
  328. }
  329. t.dbBaseCondition += ' ba_prodcode=\'' + p + '\'';
  330. }
  331. }
  332. }
  333. },
  334. 'dbfindtrigger[name=snd_ordercode]': {
  335. focus: function(t) {
  336. t.setHideTrigger(false);
  337. t.setReadOnly(false);
  338. if (Ext.getCmp('sn_custcode')) {
  339. var code = Ext.getCmp('sn_custcode').value;
  340. if (code != null && code != '') {
  341. var obj = me.getCodeCondition();
  342. if (obj && obj.field) {
  343. t.dbBaseCondition = obj.field + "='" + code + "'";
  344. }
  345. if (!Ext.getCmp('sn_custcode').readOnly) {
  346. Ext.getCmp('sn_custcode').setReadOnly(true);
  347. Ext.getCmp('sn_custcode').setFieldStyle(Ext.getCmp('sn_custcode').fieldStyle + ';background:#f1f1f1;');
  348. }
  349. }
  350. }
  351. },
  352. aftertrigger: function(t) {
  353. var code = Ext.getCmp('sn_custcode').value;
  354. if (code == null || code.toString().trim() == '') {
  355. var obj = me.getCodeCondition();
  356. me.FormUtil.getFieldsValue(obj.tablename, obj.fields, obj.myfield + "='" + t.value + "'", obj.tFields);
  357. }
  358. }
  359. },
  360. 'dbfindtrigger[name=snd_orderdetno]': {
  361. focus: function(t) {
  362. t.setHideTrigger(false);
  363. t.setReadOnly(false);
  364. var record = Ext.getCmp('grid').selModel.getLastSelected();
  365. var code = record.data['snd_ordercode'];
  366. if (code == null || code == '') {
  367. showError("请先选择关联订单号!");
  368. t.setHideTrigger(true);
  369. t.setReadOnly(true);
  370. } else {
  371. t.dbBaseCondition = "sa_code='" + code + "'";
  372. }
  373. }
  374. },
  375. 'field[name=sn_statuscode]': {
  376. change: function(f) {
  377. var grid = Ext.getCmp('grid');
  378. if (grid && f.value != 'ENTERING' && f.value != 'COMMITED') {
  379. grid.setReadOnly(true); //只有未审核的订单,grid才能编辑
  380. }
  381. }
  382. },
  383. 'field[name=sn_outcredit]': {
  384. afterrender: function(f){
  385. if(f.value != null && f.value != '' && f.value != 0){
  386. f.inputEl.setStyle({color: 'OrangeRed'});
  387. }
  388. }
  389. },
  390. 'field[name=sn_outamount]': {
  391. afterrender: function(f){
  392. if(f.value != null && f.value != '' && f.value != 0){
  393. f.inputEl.setStyle({color: 'OrangeRed'});
  394. }
  395. }
  396. },
  397. 'dbfindtrigger[name=snd_batchcode]': {
  398. focus: function(t) {
  399. t.setHideTrigger(false);
  400. t.setReadOnly(false); //用disable()可以,但enable()无效
  401. var record = Ext.getCmp('grid').selModel.getLastSelected();
  402. var pr = record.data['snd_prodcode'];
  403. if (pr == null || pr == '') {
  404. showError("请先选择料号!");
  405. t.setHideTrigger(true);
  406. t.setReadOnly(true);
  407. }
  408. if (pr != null && pr != '') {
  409. var obj = me.getCodeCondition();
  410. if (obj && obj.field) {
  411. t.dbBaseCondition = "ba_prodcode='" + pr + "'";
  412. }
  413. }
  414. if (record.data['snd_warehousecode'] != null) {
  415. t.dbBaseCondition = t.dbBaseCondition + " and ba_whcode='" + record.data['snd_warehousecode'] + "'";
  416. }
  417. }
  418. }
  419. });
  420. },
  421. onGridItemClick: function(selModel, record) { //grid行选择
  422. var btn = Ext.getCmp('splitButton');
  423. if(!Ext.isEmpty(record.data.snd_id) && (record.data.snd_yqty == 0 || record.data.snd_yqty == null)){
  424. btn && btn.setDisabled(false);
  425. } else {
  426. btn && btn.setDisabled(true);
  427. }
  428. this.GridUtil.onGridItemClick(selModel, record);
  429. },
  430. getForm: function(btn) {
  431. return btn.ownerCt.ownerCt;
  432. },
  433. createSplitForm: function(record) {
  434. var me = this;
  435. return Ext.create('Ext.form.Panel', {
  436. xtype: 'form',
  437. layout: 'column',
  438. region: 'north',
  439. frame: true,
  440. defaults: {
  441. xtype: 'textfield',
  442. columnWidth: 0.5,
  443. readOnly: true,
  444. fieldStyle: 'background:#f0f0f0;border: 0px solid #8B8970;color:blue;'
  445. },
  446. items: [{
  447. fieldLabel: '订单编号',
  448. value: record.data.snd_ordercode
  449. },
  450. {
  451. fieldLabel: '序号',
  452. value: record.data.snd_pdno
  453. },
  454. {
  455. fieldLabel: '产品编号',
  456. name: 'snd_prodcode',
  457. value: record.data.snd_prodcode
  458. },
  459. {
  460. fieldLabel: '产品名称',
  461. value: record.data.pr_detail
  462. },
  463. {
  464. fieldLabel: '数量',
  465. value: record.data.snd_outqty
  466. }],
  467. buttonAlign: 'center',
  468. buttons: [{
  469. xtype: 'button',
  470. columnWidth: 0.12,
  471. text: '保存',
  472. width: 60,
  473. iconCls: 'x-button-icon-save',
  474. handler: function(btn) {
  475. me.saveSplit(btn.ownerCt.ownerCt.ownerCt.down('grid'), record);
  476. window.location.reload();
  477. }
  478. },
  479. {
  480. xtype: 'button',
  481. columnWidth: 0.1,
  482. text: '关闭',
  483. width: 60,
  484. iconCls: 'x-button-icon-close',
  485. margin: '0 0 0 10',
  486. handler: function(btn) {
  487. btn.ownerCt.ownerCt.ownerCt.close();
  488. }
  489. }]
  490. });
  491. },
  492. saveSplit: function(grid, record) {
  493. var store = grid.getStore(), form = Ext.getCmp('form');
  494. var count = 0;
  495. var jsonData = new Array();
  496. var dd;
  497. Ext.Array.each(store.data.items, function(item) {
  498. if (item.data.snd_outqty != 0 && item.data.snd_warehousecode != null && item.data.snd_outqty > 0) {
  499. dd = new Object();
  500. //说明是新增批次
  501. dd['snd_outqty'] = item.data.snd_outqty;
  502. dd['snd_id'] = item.data.snd_id;
  503. dd['snd_warehousecode'] = item.data.snd_warehousecode;
  504. dd['snd_warehouse'] = item.data.snd_warehouse;
  505. dd['snd_pdno'] = item.data.snd_pdno;
  506. dd['snd_batchid'] = item.data.snd_batchid;
  507. dd['snd_batchcode'] = item.data.snd_batchcode;
  508. jsonData.push(Ext.JSON.encode(dd));
  509. count += Number(item.data.snd_outqty);
  510. }
  511. });
  512. var assqty = Number(record.data.snd_outqty);
  513. if(Math.abs(form.BaseUtil.numberFormat(count,4)-form.BaseUtil.numberFormat(assqty, 4)) > 0.001){
  514. showError('分拆数量必须等于原数量!');
  515. return;
  516. } else {
  517. var r = new Object();
  518. r['snd_id'] = record.data.snd_id;
  519. r['snd_snid'] = record.data.snd_snid;
  520. r['snd_pdno'] = record.data.snd_pdno;
  521. var params = new Object();
  522. params.formdata = unescape(Ext.JSON.encode(r).replace(/\\/g, "%"));
  523. params.data = unescape(jsonData.toString().replace(/\\/g, "%"));
  524. Ext.Ajax.request({
  525. url: basePath + 'scm/sale/SendNotifyBatch.action',
  526. params: params,
  527. waitMsg: '拆分中...',
  528. method: 'post',
  529. callback: function(options, success, response) {
  530. var localJson = new Ext.decode(response.responseText);
  531. if (localJson.success) {
  532. saveSuccess(function() {
  533. //add成功后刷新页面进入可编辑的页面
  534. this.loadSplitData(originaldetno, said, record);
  535. });
  536. } else if (localJson.exceptionInfo) {
  537. var str = localJson.exceptionInfo;
  538. if (str.trim().substr(0, 12) == 'AFTERSUCCESS') { //特殊情况:操作成功,但是出现警告,允许刷新页面
  539. str = str.replace('AFTERSUCCESS', '');
  540. saveSuccess(function() {
  541. //add成功后刷新页面进入可编辑的页面
  542. this.loadSplitData(originaldetno, said, record);
  543. });
  544. showError(str);
  545. } else {
  546. showError(str);
  547. return;
  548. }
  549. } else {
  550. saveFailure();
  551. }
  552. }
  553. });
  554. }
  555. },
  556. createSplitGrid: function(record) {
  557. return Ext.create('Ext.grid.Panel', {
  558. region: 'south',
  559. layout: 'fit',
  560. id: 'smallgrid',
  561. height: '80%',
  562. features: [{
  563. ftype: 'summary'
  564. }],
  565. dbfinds: [{
  566. field: 'snd_batchcode',
  567. dbGridField: 'ba_code'
  568. },
  569. {
  570. field: 'snd_batchid',
  571. dbGridField: 'ba_id'
  572. },
  573. {
  574. field: 'snd_warehousecode',
  575. dbGridField: 'wh_code;ba_whcode'
  576. },
  577. {
  578. field: 'snd_warehouse',
  579. dbGridField: 'wh_description'
  580. },
  581. {
  582. field: 'ba_qty',
  583. dbGridField: 'ba_remain'
  584. }],
  585. columnLines: true,
  586. store: Ext.create('Ext.data.Store', {
  587. fields: [{
  588. name: 'snd_pdno',
  589. type: 'int'
  590. },
  591. {
  592. name: 'snd_outqty',
  593. type: 'number'
  594. },
  595. {
  596. name: 'snd_warehousecode',
  597. type: 'string'
  598. },
  599. {
  600. name: 'snd_warehouse',
  601. type: 'string'
  602. },
  603. {
  604. name: 'snd_batchcode',
  605. type: 'string'
  606. },
  607. {
  608. name: 'snd_batchid',
  609. type: 'int'
  610. },
  611. {
  612. name: 'snd_id',
  613. type: 'int'
  614. },
  615. {
  616. name: 'ba_qty',
  617. type: 'number'
  618. }],
  619. data: []
  620. }),
  621. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  622. clicksToEdit: 1
  623. })],
  624. tbar: [{
  625. tooltip: '添加批次',
  626. iconCls: 'x-button-icon-add',
  627. width: 25,
  628. handler: function() {
  629. var store = Ext.getCmp('smallgrid').getStore();
  630. var r = new Object();
  631. r.snd_outqty = 0;
  632. r.snd_id = 0;
  633. r.snd_pdno = store.getCount() + Number(record.data.snd_pdno);
  634. store.insert(store.getCount(), r);
  635. }
  636. },
  637. {
  638. tooltip: '删除批次',
  639. width: 25,
  640. itemId: 'delete',
  641. iconCls: 'x-button-icon-delete',
  642. handler: function(btn) {
  643. var sm = Ext.getCmp('smallgrid').getSelectionModel();
  644. var record = sm.getSelection();
  645. var snd_id = record[0].data.snd_id;
  646. if (snd_id && snd_id != 0) {
  647. Ext.Msg.alert('提示', '不能删除已拆批次或原始行号!');
  648. return;
  649. }
  650. var store = Ext.getCmp('smallgrid').getStore();
  651. store.remove(record);
  652. if (store.getCount() > 0) {
  653. sm.select(0);
  654. }
  655. },
  656. disabled: true
  657. }],
  658. listeners: {
  659. itemmousedown: function(selmodel, record) {
  660. selmodel.ownerCt.down('#delete').setDisabled(false);
  661. }
  662. },
  663. columns: [{
  664. dataIndex: 'snd_pdno',
  665. header: '序号',
  666. width: 60,
  667. format: '0',
  668. xtype: 'numbercolumn'
  669. },
  670. {
  671. dataIndex: 'snd_outqty',
  672. header: '数量',
  673. align: 'right',
  674. width: 120,
  675. summaryType: 'sum',
  676. xtype: 'numbercolumn',
  677. summaryRenderer: function(value, summaryData, dataIndex) {
  678. var store = this.view.store, v = store.sum(dataIndex);
  679. if(v != value) {
  680. store.fireEvent('datachanged', store);
  681. }
  682. return Ext.util.Format.number(value, '0,000.00');
  683. },
  684. editable: true,
  685. format: '0,000.00',
  686. editor: {
  687. xtype: 'numberfield',
  688. format: '0.00',
  689. hideTrigger: true
  690. }
  691. },
  692. {
  693. dataIndex: 'snd_warehousecode',
  694. header: '仓库编号',
  695. dbfind: 'WareHouse|wh_code',
  696. width: 100,
  697. editable: true,
  698. editor: {
  699. xtype: 'dbfindtrigger'
  700. }
  701. },
  702. {
  703. dataIndex: 'snd_warehouse',
  704. header: '仓库名称',
  705. width: 100,
  706. editable: false
  707. },
  708. {
  709. dataIndex: 'snd_batchcode',
  710. header: '批号',
  711. width: 100,
  712. dbfind: 'Batch|ba_code',
  713. editable: true,
  714. editor: {
  715. xtype: 'dbfindtrigger'
  716. }
  717. },
  718. {
  719. dataIndex: 'snd_batchid',
  720. header: '批号ID',
  721. xtype: 'numbercolumn',
  722. width: 100,
  723. editable: false
  724. },
  725. {
  726. dataIndex: 'snd_id',
  727. header: 'sndid',
  728. xtype: 'numbercolumn',
  729. width: 0
  730. },
  731. {
  732. dataIndex: 'ba_qty',
  733. header: '库存数',
  734. summaryType: 'sum',
  735. xtype: 'numbercolumn',
  736. summaryRenderer: function(value, summaryData, dataIndex) {
  737. return Ext.util.Format.number(value, '0,000.00');
  738. },
  739. width: 100
  740. }]
  741. });
  742. },
  743. SaleSplit: function(record) {
  744. var me = this,
  745. originaldetno = Number(record.data.snd_pdno);
  746. var said = Number(record.data.snd_snid);
  747. var win = Ext.create('Ext.window.Window', {
  748. width: 850,
  749. height: '80%',
  750. iconCls: 'x-grid-icon-partition',
  751. title: '<h1>出货通知单拆分</h1>',
  752. items: [me.createSplitForm(record), me.createSplitGrid(record)]
  753. });
  754. win.show();
  755. this.loadSplitData(originaldetno, said, record, win.down('grid'));
  756. },
  757. loadSplitData: function(detno, said, record, grid) {
  758. grid.setLoading(true); //loading...
  759. Ext.Ajax.request({ //拿到grid的columns
  760. url: basePath + "common/loadNewGridStore.action",
  761. params: {
  762. caller: 'SendnotifySplit',
  763. condition: 'snd_pdno=' + detno + " AND snd_snid=" + said + " order by snd_id desc"
  764. },
  765. method: 'post',
  766. callback: function(options, success, response) {
  767. grid.setLoading(false);
  768. var res = new Ext.decode(response.responseText);
  769. if (res.exceptionInfo) {
  770. showError(res.exceptionInfo);
  771. return;
  772. }
  773. var data = res.data;
  774. if (!data || data.length == 0) {
  775. grid.store.removeAll();
  776. var o = new Object();
  777. o.snd_pdno = detno;
  778. o.snd_outqty = record.data.snd_outqty;
  779. o.snd_id = record.data.snd_id;
  780. o.ba_qty = record.get('pw_onhand');
  781. data.push(o);
  782. }
  783. grid.store.loadData(data);
  784. //自定义event
  785. grid.addEvents({
  786. storeloaded: true
  787. });
  788. grid.fireEvent('storeloaded', grid, data);
  789. }
  790. });
  791. },
  792. beforeSaveSendNotify: function() {
  793. var grid = Ext.getCmp('grid'),
  794. items = grid.store.data.items;
  795. var bool = true;
  796. var cust = Ext.getCmp('sn_custid').value,
  797. sncode = Ext.getCmp('sn_code').value;
  798. if (cust == null || cust == '' || cust == '0' || cust == 0) {
  799. showError('未选择客户,或客户编号无效!');
  800. return;
  801. }
  802. Ext.Array.each(items,
  803. function(item) {
  804. item.set('snd_code', sncode);
  805. });
  806. var rateMsg = '';
  807. //数量不能为空或0
  808. Ext.each(items,
  809. function(item) {
  810. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  811. if (item.data['snd_outqty'] == null || item.data['snd_outqty'] == '' || item.data['snd_outqty'] == '0' || item.data['snd_outqty'] == 0) {
  812. bool = false;
  813. showError('明细表第' + item.data['snd_pdno'] + '行的数量为空');
  814. return;
  815. }
  816. if (item.data['snd_taxrate'] == 0) {
  817. rateMsg += item.data['snd_pdno'] + ' ';
  818. }
  819. }
  820. });
  821. if (rateMsg != '') {
  822. warnMsg('明细行:' + rateMsg + '的税率为0,是否继续?',
  823. function(btn) {
  824. if (btn != 'ok' && btn != 'yes') {
  825. bool = false;
  826. }
  827. });
  828. }
  829. //保存sale
  830. if (bool) this.FormUtil.beforeSave(this);
  831. },
  832. beforeUpdate: function() {
  833. var grid = Ext.getCmp('grid'),
  834. items = grid.store.data.items;
  835. var bool = true;
  836. var cust = Ext.getCmp('sn_custid').value,
  837. sncode = Ext.getCmp('sn_code').value;
  838. if (cust == null || cust == '' || cust == '0' || cust == 0) {
  839. showError('未选择客户,或客户编号无效!');
  840. return;
  841. }
  842. Ext.Array.each(items,
  843. function(item) {
  844. item.set('snd_code', sncode);
  845. });
  846. var rateMsg = '';
  847. //数量不能为空或0
  848. Ext.each(items,
  849. function(item) {
  850. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  851. if (item.data['snd_outqty'] == null || item.data['snd_outqty'] == '' || item.data['snd_outqty'] == '0' || item.data['snd_outqty'] == 0) {
  852. bool = false;
  853. showError('明细表第' + item.data['snd_pdno'] + '行的数量为空');
  854. return;
  855. }
  856. if (item.data['snd_taxrate'] == 0) {
  857. rateMsg += item.data['snd_pdno'] + ' ';
  858. }
  859. }
  860. });
  861. if (rateMsg != '') {
  862. warnMsg('明细行:' + rateMsg + '的税率为0,是否继续?',
  863. function(btn) {
  864. if (btn != 'ok' && btn != 'yes') {
  865. bool = false;
  866. }
  867. });
  868. }
  869. //保存
  870. if (bool) this.FormUtil.onUpdate(this);
  871. },
  872. /**
  873. * snd_ordercode的限制条件
  874. */
  875. getCodeCondition: function() {
  876. var field = null;
  877. var fields = '';
  878. var tablename = '';
  879. var myfield = '';
  880. var tFields = 'sn_custid,sn_custcode,sn_custname,sn_currency,sn_rate,sn_payments,sn_payment,sn_toplace,sn_sellerid,sn_sellername,sn_arcustcode,sn_arcustname';
  881. switch (caller) {
  882. case 'SendNotify':
  883. //出货通知单
  884. field = "sa_custcode";
  885. fields = 'sa_custid,sa_custcode,sa_custname,sa_currency,sa_rate,sa_paymentsid,sa_payments,sa_toplace,sa_sellerid,sa_seller,sa_apcustcode,sa_apcustname';
  886. tablename = 'Sale';
  887. myfield = 'sa_code';
  888. break;
  889. }
  890. var obj = new Object();
  891. obj.field = field;
  892. obj.fields = fields;
  893. obj.tFields = tFields;
  894. obj.tablename = tablename;
  895. obj.myfield = myfield;
  896. return obj;
  897. },
  898. loadOnHandQty: function(grid, id) {
  899. Ext.Ajax.request({
  900. url: basePath + 'scm/sale/loadOnHandQty.action',
  901. params: {
  902. caller: caller,
  903. id: id
  904. },
  905. callback: function(opt, s, r) {
  906. var rs = Ext.decode(r.responseText);
  907. if (rs.exceptionInfo) {
  908. showMessage('提示', rs.exceptionInfo.replace('AFTERSUCCESS', ''));
  909. } else {
  910. var data = [];
  911. if (!rs.data || rs.data.length == 2) {
  912. grid.GridUtil.add10EmptyData(grid.detno, data);
  913. grid.GridUtil.add10EmptyData(grid.detno, data);
  914. } else {
  915. data = Ext.decode(rs.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  916. }
  917. grid.store.loadData(data);
  918. }
  919. }
  920. });
  921. },
  922. turn: function(nCaller, condition, url){
  923. var win = new Ext.window.Window({
  924. id : 'win',
  925. height: "100%",
  926. width: "80%",
  927. maximizable : true,
  928. buttonAlign : 'center',
  929. layout : 'anchor',
  930. items: [{
  931. tag : 'iframe',
  932. frame : true,
  933. anchor : '100% 100%',
  934. layout : 'fit',
  935. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/common/editorColumn.jsp?caller=' + nCaller
  936. + "&condition=" + condition +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  937. }],
  938. buttons : [{
  939. name: 'confirm',
  940. text : $I18N.common.button.erpConfirmButton,
  941. iconCls: 'x-button-icon-confirm',
  942. cls: 'x-btn-gray',
  943. listeners: {
  944. buffer: 500,
  945. click: function(btn) {
  946. var grid = Ext.getCmp('win').items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow.Ext.getCmp("editorColumnGridPanel");
  947. btn.setDisabled(true);
  948. grid.updateAction(url);
  949. window.location.reload();
  950. }
  951. }
  952. }, {
  953. text : $I18N.common.button.erpCloseButton,
  954. iconCls: 'x-button-icon-close',
  955. cls: 'x-btn-gray',
  956. handler : function(){
  957. Ext.getCmp('win').close();
  958. }
  959. }]
  960. });
  961. win.show();
  962. }
  963. });