BatchDeal.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.BatchDeal', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'fa.ars.ProdToARBill.Viewport','fa.ars.ProdToARBill.Form','fa.ars.ProdToARBill.GridPanel','core.form.MultiField',
  7. 'core.form.SeparNumber','core.button.VastDeal','core.button.VastPrint','core.button.VastAnalyse','core.button.GetVendor',
  8. 'core.button.VastTurnPurc','core.button.DealMake','core.button.MakeOccur','core.button.SaleOccur',
  9. 'core.button.AllThrow','core.button.SelectThrow','core.button.VastTurnARAPCheck',
  10. 'core.trigger.DbfindTrigger','core.form.FtField','core.form.FtFindField','core.form.ConDateField',
  11. 'core.form.MonthDateField','core.button.ByAmount','core.trigger.TextAreaTrigger','core.form.YnField',
  12. 'core.trigger.AddDbfindTrigger','core.grid.YnColumn','core.form.SeparNumber'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. 'erpProdToARBillFormPanel': {
  18. alladded: function(form){
  19. var grid = Ext.getCmp('batchDealGridPanel');
  20. if(grid)
  21. me.resize(form, grid);
  22. }
  23. },
  24. 'erpProdToARBillGridPanel': {
  25. afterrender: function(grid){
  26. grid.plugins[0].on('afteredit',function(e){
  27. grid.selModel.countAmount();
  28. });
  29. var form = Ext.getCmp('dealform');
  30. if(form)
  31. me.resize(form, grid);
  32. }
  33. },
  34. 'erpVastDealButton': {
  35. click: function(btn){
  36. me.beforeVastDeal(btn);
  37. }
  38. },
  39. 'erpVastAnalyseButton': {
  40. click: function(btn){
  41. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  42. }
  43. },
  44. 'erpVastPrintButton': {
  45. click: function(btn){
  46. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  47. }
  48. },
  49. 'erpByAmountButton':{
  50. click: function(btn){
  51. //提取grid中的数据 查看数据中的客户编号是否与FORM中的一致 一致则可执行 不一直需要提示
  52. var grid =Ext.getCmp('batchDealGridPanel');
  53. var items = grid.store.data.items;
  54. var custcode = '', field = 'pi_arcode';
  55. if(caller =='ProdInOut!ToARBill!Deal!ars'){
  56. custcode = Ext.getCmp('pi_arcode').getValue();
  57. } else if(caller =='ProdInOut!ToAPBill!Deal!ars'){
  58. custcode = Ext.getCmp('pi_receivecode').getValue();
  59. field = 'pi_receivecode';
  60. }
  61. var bool = true;
  62. if(custcode==''||custcode == null){
  63. bool = false;
  64. }else{
  65. Ext.each(items,function(item,index){
  66. if(item.data[field]!=custcode){
  67. bool = false;
  68. }
  69. });
  70. }
  71. if(bool){
  72. me.amountButton();
  73. }else{
  74. if(caller =='ProdInOut!ToARBill!Deal!ars'){
  75. Ext.Msg.alert("提示","请按客户筛选结果!");
  76. }else if(caller =='ProdInOut!ToAPBill!Deal!ars'){
  77. Ext.Msg.alert("提示","请按供应商筛选结果");
  78. }
  79. }
  80. }
  81. },
  82. //应付的
  83. 'field[name=differ]': {
  84. change: function(field){
  85. var d = field.value || 0;
  86. var _v = Ext.getCmp('taxsum')._val || 0;
  87. Ext.getCmp('taxsum').setValue(Ext.util.Format.number(d + _v,'0.00'));
  88. }
  89. },
  90. //应收的
  91. 'field[name=ab_differ]': {
  92. change: function(field){
  93. var d = field.value || 0;
  94. var _v = Ext.getCmp('ab_taxamount')._val || 0;
  95. // var d = field.value;
  96. // var _v = Ext.getCmp('ab_taxamount')._val;
  97. Ext.getCmp('ab_taxamount').setValue(Ext.util.Format.number(d + _v,'0.00'));
  98. }
  99. }
  100. });
  101. },
  102. resize: function(form, grid){
  103. if(!this.resized && form && grid && form.items.items.length > 0){
  104. var height = window.innerHeight,
  105. fh = form.getEl().down('.x-panel-body>.x-column-inner').getHeight();
  106. if(Ext.isIE){
  107. height = screen.height*0.75;
  108. }
  109. form.setHeight(35 + fh);
  110. grid.setHeight(height - fh - 35);
  111. this.resized = true;
  112. }
  113. },
  114. beforeVastDeal:function(btn){
  115. //panduan 币别是否一致
  116. //判断客户是否一致
  117. var me = this;
  118. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  119. },
  120. formOnQuery:function(){
  121. var me = this;
  122. var grid = Ext.getCmp('batchDealGridPanel');
  123. var form = Ext.getCmp('dealform');
  124. var condition = grid.defaultCondition || '';
  125. Ext.each(form.items.items, function(f){
  126. // console.log(contains(f.logic, 'to:', true));
  127. if(f.logic != null && f.logic != ''){
  128. if(f.xtype == 'checkbox' && f.value == true){
  129. if(condition == ''){
  130. condition += f.logic;
  131. } else {
  132. condition += ' AND ' + f.logic;
  133. }
  134. } else if(f.xtype == 'datefield' && f.value != null&&!contains(f.logic, 'to:', true)){
  135. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  136. if(condition == ''){
  137. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  138. } else {
  139. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  140. }
  141. } else if(f.xtype == 'datetimefield' && f.value != null){
  142. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  143. if(condition == ''){
  144. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  145. } else {
  146. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  147. }
  148. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  149. if(condition == ''){
  150. condition += f.logic + '=' + f.value;
  151. } else {
  152. condition += ' AND ' + f.logic + '=' + f.value;
  153. }
  154. } else {
  155. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  156. //但某些情况下,需要将form的某些字段的值也传回去
  157. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  158. if(contains(f.logic, 'to:', true)){
  159. if(!grid.toField){
  160. grid.toField = new Array();
  161. }
  162. grid.toField.push(f.logic.split(':')[1]);
  163. } else {
  164. if(f.value != null && f.value != ''){
  165. if(contains(f.value, 'BETWEEN', true) && contains(f.value, 'AND', true)){
  166. if(condition == ''){
  167. condition += f.logic + " " + f.value;
  168. } else {
  169. condition += ' AND (' + f.logic + " " + f.value + ")";
  170. }
  171. } else if(contains(f.value, '||', true)){
  172. var str = '';
  173. Ext.each(f.value.split('||'), function(v){
  174. if(v != null && v != ''){
  175. if(str == ''){
  176. str += f.logic + "='" + v + "'";
  177. } else {
  178. str += ' OR ' + f.logic + "='" + v + "'";
  179. }
  180. }
  181. });
  182. if(condition == ''){
  183. condition += str;
  184. } else {
  185. condition += ' AND (' + str + ")";
  186. }
  187. } else {
  188. if(condition == ''){
  189. condition += f.logic + "='" + f.value + "'";
  190. } else {
  191. condition += ' AND (' + f.logic + "='" + f.value + "')";
  192. }
  193. }
  194. }
  195. }
  196. }
  197. }
  198. });
  199. var gridParam = {caller: caller, condition: condition};
  200. grid.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  201. Ext.getCmp('pi_counttotal').setValue('0');
  202. Ext.getCmp('pi_amounttotal').setValue('0');
  203. // me.amountButton();
  204. },
  205. //点击按金额开票按钮后的功能
  206. amountButton:function(){
  207. var totalStr = Ext.getCmp("pi_total").getValue();
  208. var grid = Ext.getCmp('batchDealGridPanel');
  209. var selectArray = new Array(); //前面需要打勾的数据
  210. var total = Ext.Number.from(totalStr,0); //开票金额field 中的数据
  211. // pd_thisvoqty pd_thisvoprice
  212. var total2 =0;
  213. var ar = 0;
  214. if(total>0){
  215. Ext.each(grid.store.data.items,function(item,index){
  216. //此方法是所选的金额总和刚好大于输入的金额
  217. if(item.data['pd_thisvoqty']>0){
  218. var oneitemtotal =Ext.Number.from(item.data['pd_thisvoprice'],0);
  219. var itemtotal = 0;
  220. if(caller =='ProdInOut!ToAPBill!Deal!ars'){
  221. itemtotal = (item.data['pd_inqty']-item.data['pd_invoqty'])*item.data['pd_thisvoprice'];
  222. }else if(caller =='ProdInOut!ToARBill!Deal!ars'){
  223. itemtotal = (item.data['pd_outqty']-item.data['pd_invoqty'])*item.data['pd_thisvoprice'];
  224. }
  225. if(total2<total){
  226. selectArray.push(item);
  227. if(total2+itemtotal>total){
  228. if(oneitemtotal!=0){
  229. ar = (total-total2)/oneitemtotal;
  230. if(ar>parseInt(ar)){
  231. ar = parseInt(ar)+1;
  232. }else{
  233. ar = parseInt(ar);
  234. }
  235. }
  236. }
  237. }
  238. // if(ar !=0){
  239. // return false;
  240. // }else{
  241. total2 = total2+itemtotal;
  242. // }
  243. }
  244. //下面的计算方式是所选的金额总和小于输入的金额
  245. /*
  246. //发货数量大于0 代表可以开票
  247. if(item.data['pd_thisvoqty']>0){
  248. var oneitemtotal =Ext.Number.from(item.data['pd_thisvoprice'],0);
  249. //本次开票数量 = 发货数量-已转发票数
  250. //当初始化的时候 本次开票数 为最大可开票数量
  251. var itemtotal = (item.data['pd_outqty']-item.data['pd_invoqty'])*item.data['pd_thisvoprice'];
  252. if(total2+oneitemtotal<=total){
  253. selectArray.push(item);
  254. if(total2+itemtotal>total){
  255. if(oneitemtotal!=0){
  256. ar = (total-total2)/oneitemtotal;
  257. //取最后一条的数量 取整数 比如:如果开票金额里填写5000 则ar个*单价 加前面所勾选的合计<=5000 (ar+1)*单价 加前面所勾选的合计>5000
  258. ar = parseInt(ar);
  259. }
  260. }
  261. }
  262. if(ar !=0){
  263. return false;
  264. }else{
  265. total2 = total2+itemtotal;
  266. }
  267. }
  268. */});
  269. }
  270. grid.selModel.select(selectArray); //在符合条件的数据前面打勾
  271. if(grid.selModel.lastSelected){
  272. grid.selModel.lastSelected.set('pd_thisvoqty',ar); //为最后一条数据中的数量赋值
  273. }
  274. //自动计算发票书的金额总和
  275. //相应的方法在此BatchDeal中GRID对应的view 中
  276. grid.selModel.countAmount();
  277. },
  278. countGrid: function(){
  279. //重新计算合计栏值
  280. var grid = Ext.getCmp('batchDealGridPanel');
  281. Ext.each(grid.columns, function(column){
  282. if(column.summary){
  283. var sum = 0;
  284. Ext.each(grid.store.data.items, function(item){
  285. if(item.value != null && item.value != ''){
  286. sum += Number(item.value);
  287. }
  288. });
  289. Ext.getCmp(column.dataIndex + '_sum').setText(column.text + '(sum):' + sum);
  290. } else if(column.average) {
  291. var average = 0;
  292. Ext.each(grid.store.data.items, function(item){
  293. if(item.value != null && item.value != ''){
  294. average += Number(item.value);
  295. }
  296. });
  297. average = average/grid.store.data.items.length;
  298. Ext.getCmp(column.dataIndex + '_average').setText(column.text + '(average):' + average);
  299. } else if(column.count) {
  300. var count = 0;
  301. Ext.each(grid.store.data.items, function(item){
  302. if(item.value != null && item.value != ''){
  303. count++;
  304. }
  305. });
  306. Ext.getCmp(column.dataIndex + '_count').setText(column.text + '(count):' + count);
  307. }
  308. });
  309. },
  310. vastDeal: function(url){
  311. var grid = Ext.getCmp('batchDealGridPanel');
  312. var form = Ext.getCmp('dealform');
  313. var records = grid.selModel.getSelection();
  314. if(records.length > 0){
  315. var params = new Object();
  316. params.caller = caller;
  317. var data = new Array();
  318. var bool = false;
  319. Ext.each(records, function(record, index){
  320. var f = form.fo_detailMainKeyField;
  321. if((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  322. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  323. ||(f && this.data[f] != null && this.data[f] != ''
  324. && this.data[f] != '0' && this.data[f] != 0)){
  325. bool = true;
  326. var o = new Object();
  327. if(grid.keyField){
  328. o[grid.keyField] = record.data[grid.keyField];
  329. } else {
  330. params.id[index] = record.data[form.fo_detailMainKeyField];
  331. }
  332. if(grid.toField){
  333. Ext.each(grid.toField, function(f, index){
  334. var v = Ext.getCmp(f).value;
  335. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  336. if(!Ext.isDate(v)){
  337. v = String(v);
  338. }
  339. o[f] = v;
  340. }
  341. });
  342. }
  343. if(grid.necessaryFields){
  344. Ext.each(grid.necessaryFields, function(f, index){
  345. var v = record.data[f];
  346. if(Ext.isDate(v)){
  347. v = Ext.Date.toString(v);
  348. } else {
  349. v = String(v);
  350. }
  351. o[f] = v;
  352. });
  353. }
  354. data.push(o);
  355. }
  356. });
  357. if(bool){
  358. params.data = Ext.encode(data);
  359. var main = parent.Ext.getCmp("content-panel");
  360. main.getActiveTab().setLoading(true);//loading...
  361. Ext.Ajax.request({
  362. url : basePath + url,
  363. params: params,
  364. method : 'post',
  365. callback : function(options,success,response){
  366. main.getActiveTab().setLoading(false);
  367. var localJson = new Ext.decode(response.responseText);
  368. if(localJson.exceptionInfo){
  369. showError(localJson.exceptionInfo);
  370. return "";
  371. }
  372. if(localJson.success){
  373. if(localJson.log){
  374. showMessage("提示", localJson.log);
  375. }
  376. Ext.Msg.alert("提示", "处理成功!", function(){
  377. Ext.getCmp('dealform').onQuery();
  378. });
  379. }/*else {
  380. showError("没有需要处理的数据!");
  381. }*/
  382. }
  383. });
  384. } else {
  385. showError("没有需要处理的数据!");
  386. }
  387. }else{
  388. showError("没有需要处理的数据!");
  389. }
  390. }
  391. });