SendNotify.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.drp.distribution.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:[
  8. 'core.form.Panel','drp.distribution.SendNotify','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.ResAudit','core.button.Audit','core.button.ResSubmit',
  10. 'core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.Consign',
  11. 'core.button.Submit','core.button.TurnProdIO','core.button.Flow','core.button.Print',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField'
  13. ],
  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, function(c){
  22. c.setEditor(null);
  23. });
  24. }
  25. },
  26. itemclick: this.onGridItemClick
  27. },
  28. 'erpSaveButton': {
  29. click: function(btn){
  30. var form = me.getForm(btn);
  31. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  32. me.BaseUtil.getRandomNumber();//自动添加编号
  33. }
  34. this.beforeSaveSendNotify();
  35. var bool = true;
  36. //数量不能为空或0
  37. Ext.each(items, function(item){
  38. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  39. if(item.data['snd_outqty'] == null){
  40. bool = false;
  41. showError('明细表第' + item.data['snd_pdno'] + '行的数量为空');return;
  42. }
  43. }
  44. });
  45. //价格不能为0
  46. Ext.each(items, function(item){
  47. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  48. if(item.data['snd_sendprice'] == null){
  49. bool = false;
  50. showError('明细表第' + item.data['snd_pdno'] + '行的价格为空');return;
  51. } else if(item.data['snd_sendprice'] == 0 || item.data['snd_sendprice'] == '0'){
  52. bool = false;
  53. showError('明细表第' + item.data['snd_pdno'] + '行的价格为0');return;
  54. }
  55. }
  56. });
  57. if(bool){
  58. this.FormUtil.beforeSave(me);//保存
  59. }
  60. }
  61. },
  62. 'erpDeleteButton' : {
  63. click: function(btn){
  64. me.FormUtil.onDelete({id: Number(Ext.getCmp('sn_id').value)});
  65. }
  66. },
  67. 'erpUpdateButton': {
  68. afterrender: function(btn){
  69. var status = Ext.getCmp('sn_statuscode');
  70. if(status && status.value != 'ENTERING'){
  71. btn.hide();
  72. }
  73. },
  74. click: function(btn){
  75. me.beforeUpdate();
  76. }
  77. },
  78. 'erpAddButton': {
  79. click: function(){
  80. me.FormUtil.onAdd('addSendNotify', '新增付款方式', 'jsps/scm/sale/sendNotify.jsp');
  81. }
  82. },
  83. 'erpCloseButton': {
  84. click: function(btn){
  85. me.FormUtil.beforeClose(me);
  86. }
  87. },
  88. 'erpPrintButton':{
  89. click:function(btn){
  90. var reportName="SendNotify";
  91. var condition='{SendNotify.sn_id}='+Ext.getCmp('sn_id').value+'';
  92. me.FormUtil.onwindowsPrint(Ext.getCmp('sn_id').value, reportName,condition);
  93. }
  94. },
  95. 'erpSubmitButton': {
  96. afterrender: function(btn){
  97. var status = Ext.getCmp('sn_statuscode');
  98. if(status && status.value != 'ENTERING'){
  99. btn.hide();
  100. }
  101. },
  102. click: function(btn){
  103. me.FormUtil.onSubmit(Ext.getCmp('sn_id').value);
  104. }
  105. },
  106. 'erpResSubmitButton': {
  107. afterrender: function(btn){
  108. var status = Ext.getCmp('sn_statuscode');
  109. if(status && status.value != 'COMMITED'){
  110. btn.hide();
  111. }
  112. },
  113. click: function(btn){
  114. me.FormUtil.onResSubmit(Ext.getCmp('sn_id').value);
  115. }
  116. },
  117. 'erpAuditButton': {
  118. afterrender: function(btn){
  119. var status = Ext.getCmp('sn_statuscode');
  120. if(status && status.value != 'COMMITED'){
  121. btn.hide();
  122. }
  123. },
  124. click: function(btn){
  125. me.FormUtil.onAudit(Ext.getCmp('sn_id').value);
  126. }
  127. },
  128. 'erpResAuditButton': {
  129. afterrender: function(btn){
  130. var status = Ext.getCmp('sn_statuscode');
  131. if(status && status.value != 'AUDITED'){
  132. btn.hide();
  133. }
  134. },
  135. click: function(btn){
  136. me.FormUtil.onResAudit(Ext.getCmp('sn_id').value);
  137. }
  138. },
  139. 'erpTurnProdIOButton': {
  140. afterrender: function(btn){
  141. var status = Ext.getCmp('sn_statuscode');
  142. if(status && status.value != 'AUDITED' && status.value != 'PARTOUT'){
  143. btn.hide();
  144. }
  145. }
  146. },
  147. 'dbfindtrigger[name=snd_ordercode]': {
  148. focus: function(t){
  149. t.setHideTrigger(false);
  150. t.setReadOnly(false);
  151. if(Ext.getCmp('sn_custcode')){
  152. var code = Ext.getCmp('sn_custcode').value;
  153. if(code != null && code != ''){
  154. var obj = me.getCodeCondition();
  155. if(obj && obj.field){
  156. t.dbBaseCondition = obj.field + "='" + code + "'";
  157. }
  158. if(!Ext.getCmp('sn_custcode').readOnly){
  159. Ext.getCmp('sn_custcode').setReadOnly(true);
  160. Ext.getCmp('sn_custcode').setFieldStyle(Ext.getCmp('sn_custcode').fieldStyle + ';background:#f1f1f1;');
  161. }
  162. }
  163. }
  164. },
  165. aftertrigger: function(t){
  166. var code = Ext.getCmp('sn_custcode').value;
  167. if(code == null || code.toString().trim() == ''){
  168. var obj = me.getCodeCondition();
  169. me.FormUtil.getFieldsValue(obj.tablename, obj.fields, obj.myfield + "='" + t.value + "'", obj.tFields);
  170. }
  171. }
  172. },
  173. 'dbfindtrigger[name=snd_orderdetno]': {
  174. focus: function(t){
  175. t.setHideTrigger(false);
  176. t.setReadOnly(false);
  177. var record = Ext.getCmp('grid').selModel.getLastSelected();
  178. var code = record.data['snd_ordercode'];
  179. if(code == null || code == ''){
  180. showError("请先选择关联订单号!");
  181. t.setHideTrigger(true);
  182. t.setReadOnly(true);
  183. } else {
  184. t.dbBaseCondition = "sa_code='" + code + "'";
  185. }
  186. }
  187. },
  188. 'field[name=sn_statuscode]': {
  189. change: function(f){
  190. var grid = Ext.getCmp('grid');
  191. console.log(grid);
  192. if(grid && f.value != 'ENTERING' && f.value != 'COMMITED'){
  193. grid.setReadOnly(true);//只有未审核的订单,grid才能编辑
  194. }
  195. }
  196. },
  197. 'dbfindtrigger[name=snd_batchcode]': {
  198. focus: function(t){
  199. t.setHideTrigger(false);
  200. t.setReadOnly(false);//用disable()可以,但enable()无效
  201. var record = Ext.getCmp('grid').selModel.getLastSelected();
  202. var pr = record.data['snd_prodcode'];
  203. if(pr == null || pr == ''){
  204. showError("请先选择料号!");
  205. t.setHideTrigger(true);
  206. t.setReadOnly(true);
  207. }
  208. }
  209. },
  210. 'erpConsignButton': {
  211. afterrender: function(btn){
  212. var status = Ext.getCmp('sn_statuscode');
  213. if(status && status.value != 'AUDITED'){
  214. btn.hide();
  215. }
  216. }
  217. }
  218. });
  219. },
  220. onGridItemClick: function(selModel, record){//grid行选择
  221. this.GridUtil.onGridItemClick(selModel, record);
  222. },
  223. getForm: function(btn){
  224. return btn.ownerCt.ownerCt;
  225. },
  226. beforeSaveSendNotify: function(){
  227. Ext.getCmp('sn_cop').setValue(en_uu);
  228. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  229. var bool = true;
  230. var cust = Ext.getCmp('sn_custid').value, sncode = Ext.getCmp('sn_code').value;
  231. if(cust == null || cust == '' || cust == '0' || cust == 0){
  232. showError('未选择客户,或客户编号无效!');
  233. return;
  234. }
  235. Ext.Array.each(items, function(item){
  236. item.set('snd_code',sncode);
  237. });
  238. //数量不能为空或0
  239. Ext.each(items, function(item){
  240. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  241. if(item.data['snd_outqty'] == null || item.data['snd_outqty'] == '' || item.data['snd_outqty'] == '0'
  242. || item.data['snd_outqty'] == 0){
  243. bool = false;
  244. showError('明细表第' + item.data['snd_pdno'] + '行的数量为空');return;
  245. }
  246. }
  247. });
  248. //销售价格不能为0
  249. Ext.each(items, function(item){
  250. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  251. if(item.data['snd_sendprice'] == null){
  252. bool = false;
  253. showError('明细表第' + item.data['snd_pdno'] + '行的价格为空');return;
  254. } else if(item.data['snd_sendprice'] == 0 || item.data['snd_sendprice'] == '0'){
  255. bool = false;
  256. showError('明细表第' + item.data['snd_pdno'] + '行的价格为0');return;
  257. }
  258. }
  259. });
  260. //保存sale
  261. if(bool)
  262. this.FormUtil.beforeSave(this);
  263. },
  264. beforeUpdate: function(){
  265. Ext.getCmp('sn_cop').setValue(en_uu);
  266. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  267. var bool = true;
  268. var cust = Ext.getCmp('sn_custid').value, sncode = Ext.getCmp('sn_code').value;
  269. if(cust == null || cust == '' || cust == '0' || cust == 0){
  270. showError('未选择客户,或客户编号无效!');
  271. return;
  272. }
  273. Ext.Array.each(items, function(item){
  274. item.set('snd_code',sncode);
  275. });
  276. //数量不能为空或0
  277. Ext.each(items, function(item){
  278. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  279. if(item.data['snd_outqty'] == null || item.data['snd_outqty'] == '' || item.data['snd_outqty'] == '0'
  280. || item.data['snd_outqty'] == 0){
  281. bool = false;
  282. showError('明细表第' + item.data['snd_pdno'] + '行的数量为空');return;
  283. }
  284. }
  285. });
  286. //销售价格不能为0
  287. Ext.each(items, function(item){
  288. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  289. if(item.data['snd_sendprice'] == null){
  290. bool = false;
  291. showError('明细表第' + item.data['snd_pdno'] + '行的价格为空');return;
  292. } else if(item.data['snd_sendprice'] == 0 || item.data['snd_sendprice'] == '0'){
  293. bool = false;
  294. showError('明细表第' + item.data['snd_pdno'] + '行的价格为0');return;
  295. }
  296. }
  297. });
  298. //保存
  299. if(bool)
  300. this.FormUtil.onUpdate(this);
  301. },
  302. /**
  303. * snd_ordercode的限制条件
  304. */
  305. getCodeCondition: function(){
  306. var field = null;
  307. var fields = '';
  308. var tablename = '';
  309. var myfield = '';
  310. var tFields = 'sn_custid,sn_custcode,sn_custname,sn_currency,sn_rate,sn_payments,sn_payment,sn_toplace,sn_sellerid,sn_sellername';
  311. switch (caller) {
  312. case 'SendNotify!Drp': //配货通知单
  313. field = "sa_custcode";
  314. fields = 'sa_custid,sa_custcode,sa_custname,sa_currency,sa_rate,sa_paymentsid,sa_payments,sa_toplace,sa_sellerid,sa_seller';
  315. tablename = 'Sale';
  316. myfield = 'sa_code';
  317. break;
  318. }
  319. var obj = new Object();
  320. obj.field = field;
  321. obj.fields = fields;
  322. obj.tFields = tFields;
  323. obj.tablename = tablename;
  324. obj.myfield = myfield;
  325. return obj;
  326. }
  327. });