BatchDeal.js 13 KB

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