| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.fa.arp.PrePay', {
- extend: 'Ext.app.Controller',
- FormUtil: Ext.create('erp.util.FormUtil'),
- GridUtil: Ext.create('erp.util.GridUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- views:[
- 'core.form.Panel','fa.arp.PrePay','core.grid.Panel2','core.toolbar.Toolbar', 'core.form.SeparNumber',
- 'core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Submit','core.button.ResAudit','core.button.Print',
- 'core.button.Audit','core.button.ResSubmit','core.button.Post','core.button.ResPost','core.button.Update','core.button.DeleteDetail',
- 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.ResAccounted','core.button.AssMain','core.button.Accounted','core.button.StrikeBalance',
- 'core.grid.AssPanel','core.window.AssWindow','core.trigger.CateTreeDbfindTrigger','core.trigger.HrOrgTreeDbfindTrigger','core.button.Print','core.button.AssDetail','core.button.AssMain'
- ,'core.button.GetSumAmount'
- ],
- init:function(){
- var me = this;
- me.gridLastSelected = null;
- this.control({
- 'erpGridPanel2': {
- itemclick:function(selModel, record){
- me.onGridItemClick(selModel, record);
- var btn = Ext.getCmp('assdetail');
- var ass = record.data['ca_asstype'];
- if(!Ext.isEmpty(ass)){
- btn.setDisabled(false);
- } else {
- btn.setDisabled(true);
- }
- }
- },
- 'erpAssMainButton':{
- afterrender:function(btn){
-
- if(Ext.getCmp('ca_asstype').getValue()==null||Ext.getCmp('ca_asstype').getValue()==""){
- btn.setDisabled(true);
- }else{
- btn.setDisabled(false);
- }
- }
- },
- 'erpGetSumAmountButton':{
- click: function(btn){
- var grid = Ext.getCmp("grid"),items = grid.store.data.items;
- var detailamount1 = 0;
- Ext.each(items,function(item,index){
- if(!me.GridUtil.isBlank(grid,item.data)) {
- detailamount1 = detailamount1 + Number(item.data['ppd_nowbalance']);
- }
- });
- Ext.getCmp("pp_amount").setValue(detailamount1);
- Ext.getCmp("pp_vmamount").setValue(detailamount1);
- }
- },
- 'erpSaveButton': {
- click: function(btn){
- var form = me.getForm(btn);
- if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
- me.BaseUtil.getRandomNumber();
- }
- me.changeVmrateOrVmamount();
-
- me.getJsamount();
- //保存之前的一些前台的逻辑判定
- this.beforeSaveAccountRegister();
- }
- },
- 'erpDeleteDetailButton': {
- afterrender: function(btn){
- //辅助核算
- btn.ownerCt.add({
- xtype:'erpAssDetailButton',
- disabled:true
- });
- }
- },
- 'erpDeleteButton' : {
- click: function(btn){
- me.FormUtil.onDelete(Ext.getCmp('pp_id').value);
- }
- },
- 'erpPostButton' : {
- afterrender: function(btn){
- var status = Ext.getCmp(me.getForm(btn).statusCode);
- if(status && status.value == 'UNPOST'){
- btn.show();
- }else{
- btn.hide();
- }
- },
- click: function(btn){
- var amount = Number(Ext.getCmp('pp_amount').getValue());
- var cmamount =Number(Ext.getCmp('pp_vmamount').getValue());
- var cmcurrency = Ext.getCmp('pp_vmcurrency').getValue();
- var cmrate = Number(Ext.getCmp('pp_vmrate').getValue());
- var currency = Ext.getCmp('pp_currency').getValue();
- if(amount != 0 && cmamount != 0){
- if(Ext.Number.toFixed(cmrate, 8)!= Ext.Number.toFixed(cmamount/amount, 8)){
- showError('冲账汇率不正确,不能过账!');
- return;
- }
- }
- if(currency == cmcurrency){
- if(cmrate != 1){
- showError('币别相同,冲账汇率不等于1,不能过账!');
- return;
- }
- }
- if(currency != cmcurrency){
- if(cmrate == 1){
- showError('币别不相同,冲账汇率等于1,不能过账!');
- return;
- }
- }
- me.FormUtil.onPost(Ext.getCmp('pp_id').value);
- }
- },
- 'erpResPostButton' : {
- afterrender: function(btn){
- var status = Ext.getCmp(me.getForm(btn).statusCode);
- if(status && status.value == 'POSTED'){
- btn.show();
- }else{
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResPost(Ext.getCmp('pp_id').value);
- }
- },
- 'erpPrintButton': {
- click:function(btn){
- var reportName='';
- reportName="APPrePay";
- var condition='{PrePay.pp_id}='+Ext.getCmp('pp_id').value+'';
- var id=Ext.getCmp('pp_id').value;
- me.FormUtil.onwindowsPrint(id,reportName,condition);
- }
- },
- 'erpUpdateButton': {
- click: function(btn){
- me.changeVmrateOrVmamount();
-
- me.getJsamount();
- me.beforeUpdate();
- }
- },
- 'erpAddButton': {
- click: function(){
- var form = Ext.getCmp('form');
- var title = '新增';
- if(form){
- if(form.title){
- title = title+form.title;
- }
- }
- me.FormUtil.onAdd('addPrePay', title, 'jsps/fa/arp/prepay.jsp?whoami='+caller);
- }
- },
- 'erpCloseButton': {
- click: function(btn){
- me.FormUtil.beforeClose(me);
- }
- },
- 'erpSubmitButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'ENTERING'){
- btn.hide();
- }
- },
- click: function(btn){
- var amount = Number(Ext.getCmp('pp_amount').getValue());
- var cmamount =Number(Ext.getCmp('pp_vmamount').getValue());
- var cmcurrency = Ext.getCmp('pp_vmcurrency').getValue();
- var cmrate = Number(Ext.getCmp('pp_vmrate').getValue());
- var currency = Ext.getCmp('pp_currency').getValue();
- if(amount != 0 && cmamount != 0){
- if(Ext.Number.toFixed(cmrate, 8)!= Ext.Number.toFixed(cmamount/amount, 8)){
- showError('冲账汇率不正确,不能提交!');
- return;
- }
- }
- if(currency == cmcurrency){
- if(cmrate != 1){
- showError('币别相同,冲账汇率不等于1,不能提交!');
- return;
- }
- }
- if(currency != cmcurrency){
- if(cmrate == 1){
- showError('币别不相同,冲账汇率等于1,不能提交!');
- return;
- }
- }
- me.FormUtil.onSubmit(Ext.getCmp('pp_id').value);
- }
- },
- 'erpResSubmitButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResSubmit(Ext.getCmp('pp_id').value);
- }
- },
- 'erpAuditButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onAudit(Ext.getCmp('pp_id').value);
- }
- },
- 'erpResAuditButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'AUDITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResAudit(Ext.getCmp('pp_id').value);
- }
- },
- 'cateTreeDbfindTrigger[name=pp_accountcode]':{
- aftertrigger:function(trigger, data){
- Ext.getCmp('pp_accountname').setValue(data[0].raw.data.ca_name);
- var asstype = data[0].raw.data.ca_asstype;
- var btn = Ext.getCmp("assmainbutton");
- if (Ext.isEmpty(asstype)){
- btn.setDisabled(true);
- } else {
- btn.setDisabled(false);
- }
- }
- },
- 'dbfindtrigger[name=ppd_ordercode]':{
- afterrender:function(t){
- t.gridKey="pp_vendcode";
- t.mappinggirdKey="pu_vendcode";
- t.gridErrorMessage="请先选择供应商";
- },
- aftertrigger:function(t){
- var grid = Ext.getCmp('grid');
- var record = grid.selModel.lastSelected;
- var data = Ext.Number.from(record.data['ppd_orderamount'],0)-Ext.Number.from(record.data['ppd_havebalance'],0);
- record.set('ppd_nowbalance',data);
- }
- },
- 'dbfindtrigger[name=ppd_makecode]':{
- afterrender:function(t){
- t.gridKey="pp_vendcode";
- t.mappinggirdKey="ma_vendcode";
- t.gridErrorMessage="请先选择供应商";
- },
- aftertrigger:function(t){
- var grid = Ext.getCmp('grid');
- var record = grid.selModel.lastSelected;
- var data = Ext.Number.from(record.data['ppd_orderamount'],0)-Ext.Number.from(record.data['ppd_havebalance'],0);
- record.set('ppd_nowbalance',data);
- }
- },
- 'textfield[name=pp_amount]':{
- change: function(){
- me.changeVmrateOrVmamount();
- }
- },
- 'textfield[name=pp_vmrate]':{
- change: function(){
- me.changeVmrateOrVmamount();
- }
- },
- 'textfield[name=pp_vmamount]':{
- change: function(){
- me.changeVmrateOrVmamount();
- }
- }
- });
- },
- changeVmrateOrVmamount: function () {
- var me = this;
- if(Ext.getCmp('pp_vmrate').readOnly){
- me.changeVmrate();
- }else{
- me.changeVmamount();
- }
- },
-
- changeVmrate:function () {
- if(Ext.getCmp('pp_vmamount')&&Ext.getCmp('pp_amount')&&Ext.getCmp('pp_vmrate')){
- var vmamount = Ext.getCmp('pp_vmamount').getValue();;
- var amount = Ext.getCmp('pp_amount').getValue();
-
- var rate = Number(vmamount/amount);
- rate = Ext.Number.toFixed(rate,8);
- Ext.getCmp('pp_vmrate').setValue(rate);
- }
-
-
-
- },
- //计算冲账金额 = 预收金额*冲账汇率
- changeVmamount:function(){
- if(Ext.getCmp('pp_amount')&&Ext.getCmp('pp_vmrate')){
- var ppamount = Ext.getCmp('pp_amount').getValue();
- var ppvmrate = Ext.getCmp('pp_vmrate').getValue();
- if(!Ext.isNumber(ppamount)){
- ppamount = Ext.Number.from(ppamount,0);
- }
- if(!Ext.isNumber(ppvmrate)){
- ppvmrate = Ext.Number.from(ppvmrate,0);
- }
- var vmamount = ppamount*ppvmrate;
- Ext.getCmp('pp_vmamount').setValue(Ext.util.Format.number(vmamount,'0.00'));
- }
- },
- getJsamount: function(){
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items;
- var jsamount = 0;
- var detailcount = 0;
- var cateamount = 0;
- Ext.each(items,function(item,index){
- if(item.data['ppd_catecode']!=null&&item.data['ppd_catecode']!=""){
- cateamount = cateamount + Number(item.data['ppd_nowbalance']);
- }
- });
- Ext.getCmp('pp_jsamount').setValue(Ext.Number.from(Ext.getCmp('pp_vmamount').getValue())-cateamount);
- },
- onGridItemClick: function(selModel, record){//grid行选择
- this.gridLastSelected = record;
- var grid = Ext.getCmp('grid');
- if(record.data[grid.necessaryField] == null || record.data[grid.necessaryField] == ''){
- this.gridLastSelected.findable = true;//空数据可以在输入完code,并移开光标后,自动调出该条数据
- } else {
- this.gridLastSelected.findable = false;
- }
- this.GridUtil.onGridItemClick(selModel, record);
- },
- getForm: function(btn){
- return btn.ownerCt.ownerCt;
- },
- beforeSaveAccountRegister: function(){
- var me = this;
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items;
- var bool = true;
- var warnStr='';
- Ext.each(items,function(item,index){
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
- var orderamount =item.data['ppd_orderamount']; //订单金额
- var havebalance = item.data['ppd_havebalance']; //已预付金额
- var nowbalance = item.data['ppd_nowbalance']; //本次预付额
- //订单金额>=已预收金额+本次预收额
- //此种情况不能进行保存
- if(havebalance+nowbalance>orderamount){
- var i = index+1;
- if(warnStr ==''||warnStr.length<=0){
- warnStr = warnStr +i;
- }else{
- warnStr = warnStr +','+i;
- }
- bool = false;
- }
- }
- });
- if(bool){
- this.beforeSave(this);
- }else{
- if(warnStr != ''||warnStr.length>0){
- showError('明细表第'+warnStr+'行 已预收金额与本次预收额的合计超过订单金额,不能保存');return;
- }
- }
- },
- beforeSave:function(){
- var me = this;
- var form = Ext.getCmp('form');
- if(! me.FormUtil.checkForm()){
- return;
- }
- if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
- me.FormUtil.getSeqId(form);
- }
- var detail = Ext.getCmp('grid');
- var param2 = new Array();
- var param3 = new Array();
-
- if(Ext.getCmp('assdetail')){
- Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
- Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
- d['dass_condid'] = key;
- param2.push(d);
- });
- });
- }
- if(Ext.getCmp('assmainbutton')){
- Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
- Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
- d['ass_conid'] = key;
- param3.push(d);
- });
- });
- }
- Ext.each(detail.store.data.items, function(item){
- if(item.data.prd_id == null || item.data.prd_id == 0){
- item.data.prd_id = -item.index;
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- if(detail.necessaryField.length > 0 && (param1.length == 0)){
- showError($I18N.common.grid.emptyDetail);
- return;
- }
- me.onSave(form, param1, param2,param3);
- },
- onSave: function(form, param1, param2,param3) {
- var me = this;
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
- param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
- if(form.getForm().isValid()){
- Ext.each(form.items.items, function(item){
- if(item.xtype == 'numberfield'){
- if(item.value == null || item.value == ''){
- item.setValue(0);
- }
- }
- });
- var r = form.getValues();
- form.getForm().getFields().each(function(){
- if(this.logic == 'ignore') {
- delete r[this.name];
- }
- });
- me.FormUtil.save(r, param1, param2,param3);
- }else{
- me.FormUtil.checkForm();
- }
- },
- beforeUpdate: function(){
- var me = this;
- var grid = Ext.getCmp('grid');
- Ext.Array.each(grid.store.data.items, function(item){
- item.set('ppd_ppid',Ext.getCmp('pp_id').value);
- });
- //采购价格不能为0
- var grid = Ext.getCmp('grid');
-
-
- var items = grid.store.data.items;
- var bool = true;
- var warnStr='';
- Ext.each(items,function(item,index){
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
- var orderamount =item.data['ppd_orderamount']; //订单金额
- var havebalance = item.data['ppd_havebalance']; //已预付金额
- var nowbalance = item.data['ppd_nowbalance']; //本次预付额
- //订单金额>=已预收金额+本次预收额
- //此种情况不能进行保存
- if(havebalance+nowbalance>orderamount){
- var i = index+1;
- if(warnStr ==''||warnStr.length<=0){
- warnStr = warnStr +i;
- }else{
- warnStr = warnStr +','+i;
- }
- bool = false;
- }
- }
- });
- if(bool){
- me.onUpdate(this);
- }else{
- if(warnStr != ''||warnStr.length>0){
- showError('明细表第'+warnStr+'行 已预付金额与本次预付额的合计超过订单金额,不能保存');return;
- }
- }
- },
- onUpdate: function(){
- var me = this;
- var form = Ext.getCmp('form');
- if(! me.FormUtil.checkForm()){
- return;
- }
- var detail = Ext.getCmp('grid');
- Ext.each(detail.store.data.items, function(item){
- if(item.data.prd_id == null || item.data.prd_id == 0){
- item.data.prd_id = -item.index;
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- var param2 = new Array();
- var param3 = new Array();
- if(Ext.getCmp('assdetail')){
- Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
- Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
- d['dass_condid'] = key;
- param2.push(d);
- });
- });
- }
- if(Ext.getCmp('assmainbutton')){
- Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
- Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
- d['ass_conid'] = key;
- param3.push(d);
- });
- });
- }
- if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
- && param2.length == 0&& param3.length == 0){
- showError($I18N.common.grid.emptyDetail);
- return;
- } else {
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
- param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
- if(form.getForm().isValid()){
- Ext.each(form.items.items, function(item){
- if(item.xtype == 'numberfield'){
- if(item.value == null || item.value == ''){
- item.setValue(0);
- }
- }
- });
- var r = form.getValues();
- form.getForm().getFields().each(function(){
- if(this.logic == 'ignore') {
- delete r[this.name];
- }
- });
- me.FormUtil.update(r, param1, param2, param3);
- }else{
- me.FormUtil.checkForm();
- }
- }
- }
- });
|