import commonFunctions from '~/mixin/commonFunctions.js';
import commonDepend from "~/mixin/commonDepend";
import BigNumber from "bignumber.js";
export default {
	mixins: [commonFunctions, commonDepend],
	methods: {
		addamtflg() {
			if ((this.model.bedgrp.cbs.max2.amt==null||(this.model.bedgrp.cbs.max2.amt != "" && new BigNumber(this.model.bedgrp.cbs.max2.amt).comparedTo(0) == 0))
				&&  (this.model.bedgrp.cbs.opn2.amt==null||(this.model.bedgrp.cbs.opn2.amt != "" && new BigNumber(this.model.bedgrp.cbs.opn2.amt).comparedTo(0) == 0))) {
				this.model.betp.addamtflg = "";
			} else {
				this.model.betp.addamtflg = "X";
			}
		},

		defaultDocsta() {
			//  If `Documents habe been refused and returned already` no other DOCSTA is possible
			//  Only in BETDCR DOCSTA R could be changed, in other BE-transactions ADVDOCFLG is not used
			if (this.model.bedgrp.rec.docsta === 'R') {
				if ((!this.model.bedgrp.rec.modifySet || this.model.bedgrp.rec.modifySet === null || this.model.bedgrp.rec.modifySet != null && !this.model.bedgrp.rec.modifySet.includes('advdocflg'))) {
					// if not "BETDCR" exit, no nothing

					// return;
				}
			}
			// # Advice of Payment?
			if (this.model.bedgrp.rec.advdat != null && this.model.bedgrp.rec.advdat != '' && this.model.bedgrp.rec.advtyp === '754') {
				if (this.model.bedgrp.rec.rcvdat === null || this.model.bedgrp.rec.rcvdat === '') {
					//Advice of Payment received, wait for documents
					this.model.bedgrp.rec.docsta = 'A';
				} else {
					//Advice of Payment received, documents received
					this.model.bedgrp.rec.docsta = 'B';
				}
			}
			// # Advice of Discrepancy?
			if (this.model.bedgrp.rec.disdat != null && this.model.bedgrp.rec.disdat != '' && this.model.bedgrp.rec.advtyp === '750') {
				if (this.model.bedgrp.rec.rcvdat === null || this.model.bedgrp.rec.rcvdat === '') {
					//Advice of Discrepancy received, wait for documents
					this.model.bedgrp.rec.docsta = 'C';
				} else {
					//Advice of Discrepancy received, documents received
					this.model.bedgrp.rec.docsta = 'D';
				}
			}
			//# Documents are received, no discrepancies
			if (this.model.bedgrp.rec.rcvdat != null && this.model.bedgrp.rec.rcvdat != '' && (this.model.bedgrp.blk.docdis === '' || this.model.bedgrp.blk.docdis === null)) {
				// Clean documents received
				this.model.bedgrp.rec.docsta = "E";
			}
			// # Documents are received with discrepancies
			if (this.model.bedgrp.rec.rcvdat != null && this.model.bedgrp.rec.rcvdat != '' && (this.model.bedgrp.blk.docdis != '' && this.model.bedgrp.blk.docdis != null)) {
				// Discrepant documents received
				this.model.bedgrp.rec.docsta = "F";
			}

			//# Documents taken up?
			if (this.model.bedgrp.rec.acpnowflg != null && this.model.bedgrp.rec.acpnowflg != '') {
				// Documents taken up
				this.model.bedgrp.rec.docsta = "I";
			}
			//# Free of Payment?
			if (this.model.bedgrp.rec.frepayflg != null && this.model.bedgrp.rec.frepayflg != '') {
				// Documents settled free of payment
				this.model.bedgrp.rec.docsta = "J";
			}


			if (this.model.bedgrp.rec.advdocflg != null && this.model.bedgrp.rec.advdocflg != '') {
				// Documents have been refused and returned
				this.model.bedgrp.rec.docsta = "R";
			}
		},

		defaultClsflg(){
			if(this.model.rejpenins!='X'){
				this.model.mtabut.clsflg = 'C';
			}else{
				this.model.mtabut.clsflg = 'O';
			}
		},

		defaultRejpenins(){
			if(!this.model.modifySet||this.model.modifySet==null||(this.model.modifySet!=null&&!this.model.modifySet.includes('rejpenins'))){
				if(this.model.bedgrp.rec.advdocflg!=''){
					this.model.rejpenins = '';
				}else{
					this.model.rejpenins = 'X';
				}
			}
		},
	},
}