export default class Icms { public csosn: string; public cst: string; public orig: string; public modbc: string; public cbenef: string; public modbcst: string; public picms: number; public picmsst: number; public predbc: number; public predbcst: number; public pfcp: number; public pfcpst: number; public vbc: number; public vbcst: number; public vicms: number; public vicmsst: number; public vbcprod: number; public vfcp: number; public vfcpst: number; public vfcpstret: number; public vicmsdeson: number; public pmvast: number; public pbc: number; public motdesicms : string; public pst : number; public pcredsn: number; public vcredicmssn: number; public vicmsop: number; public vicmsdif: number; public pdif: number; constructor(json) { json = json || {}; switch (json.crtEmpresa) { case '1': this.csosn = json.csosn || '102'; break; case '2': this.cst = json.cst || '00'; break; case '3': this.cst = json.cst || '00'; break; default: this.csosn = json.csosn || '102'; this.cst = json.cst || '00'; break; } this.orig = json.orig || '0'; this.modbc = json.modbc || '3'; this.modbcst = json.modbcst || '4'; this.picms = json.picms || 0.0; this.picmsst = json.picmsst || 0.0; this.predbc = json.predbc || 0.0; this.predbcst = json.predbcst || 0.0; this.pfcp = json.pfcp || 0.0; this.vbc = json.vbc || 0.0; this.vbcst = json.vbcst || 0.0; this.vicms = json.vicms || this.vbc * (this.picms || 0) / 100; this.vicmsst = json.vicmsst || this.vbcst * (this.picmsst || 0) / 100; this.vbcprod = json.vbcprod || 0.0; this.vfcp = json.vfcp || 0.0; this.vfcpst = json.vfcpst || 0.0; this.pmvast = json.pmvast || 0.0; this.vfcpstret = json.vfcpstret || 0.0; this.vicmsdeson = json.vicmsdeson || 0.0; this.pbc = json && json.pbc || 0.0; this.cbenef = json && json.cbenef || ''; this.motdesicms = json && json.motdesicms || ''; this.pst = json && json.pst || 0.0; this.pcredsn = json && json.pcredsn || 0.0; this.vcredicmssn = json && json.vcredicmssn || 0.0; this.vicmsop = json && json.vicmsop || 0.0; this.vicmsdif = json && json.vicmsdif || 0.0; this.pdif = json && json.pdif || 0.0; } public recalc(value: ({ valor_unitario: number, quantidade: number, extra: number, vipi: number })) { if (this.modbc == '3') this.vbcprod = value.valor_unitario || 0.0; if (this.csosn == '900') { if (this.pcredsn > 0) { this.vcredicmssn = (value.valor_unitario * (value.quantidade || 1)) * this.pcredsn; } else if (this.predbc > 0) { this.vbcst = (((value.valor_unitario * (value.quantidade || 1)) + value.extra) * (1 + this.pmvast / 100)) * (1 - (this.predbc / 100)); this.vicmsst = this.vbcst * (this.picmsst / 100); } } else if (((this.cst && ['10','30','70','90'].find(i => i == this.cst)) || (this.csosn && ['201','202','203'].find(i => i == this.csosn))) && this.pmvast > 0 && this.predbcst > 0 && this.picmsst > 0) { this.vbcst = (((value.valor_unitario * (value.quantidade || 1)) + value.extra) * (1 + this.pmvast / 100)) * (1 - (this.predbc / 100)); this.vicmsst = this.vbcst * (this.picmsst / 100); } else if (this.cst == '51' && this.predbc > 0 && this.picms > 0 && this.pdif > 0) { this.vbcst = (((value.valor_unitario * (value.quantidade || 1)) + value.extra) * (1 + this.pmvast / 100)) * (1 - (this.predbc / 100)); this.vicmsop = this.vbc * (this.picms / 100); this.vicmsdif = this.vicmsop * (this.pdif / 100); this.vicms = this.vicmsop - this.vicmsdif; } else if (this.csosn && ['101','201'].find(i => i == this.csosn) && this.pcredsn > 0) { this.vcredicmssn = (value.valor_unitario * (value.quantidade || 1)) * this.pcredsn; } else if (this.cst && ['20','90'].find(i => i == this.cst) && this.predbc > 0 && this.picms > 0) { this.vbc = ((this.vbcprod * (value.quantidade || 1)) + (value.extra || 0.0)) * (1 - (this.predbc / 100)); this.vicms = this.vbc * (this.picms / 100); } else if (this.cst && ['00','10','70','90'].find(i => i == this.cst) && this.picms > 0) { this.vbc = (this.vbcprod * (value.quantidade || 1)) + (value.extra || 0.0); this.vicms = this.vbc * (this.picms / 100); } else { this.vicmsst = this.vbcst * this.picmsst / 100; } if (this.cst != null && !(this.cst && ['00','10','70','90'].find(i => i == this.cst) && this.picms > 0) && !(this.cst && ['20','90'].find(i => i == this.cst) && this.predbc > 0 && this.picms > 0)) { this.vbc = (this.vbcprod * value.quantidade || 1) + (value.extra || 0.0) + (value.vipi || 0); if (!(this.cst == '51' && this.predbc > 0 && this.picms > 0 && this.pdif > 0)) this.vicms = this.vbc * this.picms / 100; } if (this.cst != null && !(this.cst == '51' && this.predbc > 0 && this.picms > 0 && this.pdif > 0) && !(((this.cst && ['10','30','70','90'].find(i => i == this.cst)) || (this.csosn && ['201','202','203'].find(i => i == this.csosn))) && this.pmvast > 0 && this.predbcst > 0 && this.picmsst > 0) && !(this.csosn == '900' && this.predbc > 0)) { this.vbcst = this.vbc * (1 + (this.pmvast / 100)); if (this.predbc != 0) this.vbcst *= (1 - this.predbc / 100); } this.predbcst = this.predbc; this.vfcp = this.vbc * this.pfcp / 100; this.vfcpst = this.vbcst * this.pfcpst / 100; //TO DO this.vfcpstret; let aliquota; if (this.motdesicms) aliquota = ((this.picms || 0 ) + (this.pfcp || 0)) / 100; if (this.cst == '20') this.vicmsdeson = aliquota ? this.vbc * ((1 - (aliquota * (1 - (this.predbc / 100)))) / (1 - aliquota)) - this.vbc : 0.0; else if (this.cst == '40') this.vicmsdeson = aliquota ? (this.vbc / (1 - aliquota)) * aliquota : 0.0; this.zeraItensIndisponiveis(this); } fromProduto(impostoProduto?){ if (impostoProduto.crtEmpresa == 1) this.csosn = impostoProduto && impostoProduto.csosn || '102'; else this.cst = impostoProduto && impostoProduto.cst || '00'; this.orig = impostoProduto && impostoProduto.orig || '0'; this.modbc = impostoProduto && impostoProduto.mobc || '3'; this.modbcst = impostoProduto && impostoProduto.modbcst || '4'; this.picms = impostoProduto && impostoProduto.picms || 0.0; this.picmsst = impostoProduto && impostoProduto.picmsst || 0.0; this.predbc = impostoProduto && impostoProduto.predbc || 0.0; this.predbcst = impostoProduto && impostoProduto.predbcst || 0.0; this.pfcp = impostoProduto && impostoProduto.pfcp || 0.0; this.pbc = impostoProduto && impostoProduto.pbc || 0.0; } zeraItensIndisponiveis(icms?) { let propertiesAvaibles = this.isFieldAvailableForCst(icms.cst || icms.csosn); Object.getOwnPropertyNames(icms).map(prop => { if ((prop == 'cst' || prop == 'csosn') && !propertiesAvaibles[prop]) return; return icms[prop] = propertiesAvaibles[prop] ? icms[prop] : 0; }); } isFieldAvailableForCst(cst?) { return { orig: ['00','10','20','30','40','41','50','51','60','70','90', '101','102','103','201','202','203','300','400','500','900'].includes(cst), cst: ['00','10','20','30','40','41','50','51','60','70','90'].includes(cst), csosn: ['101','102','103','201','202','203','300','400','500','900'].includes(cst), modbc: ['00','10','20','51','70','90','900'].includes(cst), predbc: ['20','70','90','900'].includes(cst), vbc: ['00','10','20','51','70','90','900'].includes(cst), picms: ['00','10','20','40','41','50','51','70','90','900'].includes(cst), vicms: ['00','10','20','40','41','50','51','70','90','900'].includes(cst), modbcst: ['10','30','70','90','201','202','203','900'].includes(cst), pmvast: ['10','30','70','90','201','202','203','900'].includes(cst), predbcst: ['10','30','70','90','201','202','203','900'].includes(cst), vbcst: ['10','30','70','90','201','202','203','900'].includes(cst), picmsst: ['10','30','70','90','201','202','203','900'].includes(cst), vicmsst: ['10','30','70','90','201','202','203','900'].includes(cst), vbcstret: ['60','90','500','900'].includes(cst), pcredsn: ['101','201','900'].includes(cst), vcredicmssn: ['101','201','900'].includes(cst), vicmsstdesti: ['41','90','900'].includes(cst), vbcstdest: ['41','90','900'].includes(cst), motdesicms: ['20', '30','40','90','900'].includes(cst), vicmsstret: ['41','60','90','500'].includes(cst), pbcop: ['90','900'].includes(cst), ufst: ['90','900'].includes(cst), pbc: ['00','10','20','51','70','90','900'].includes(cst), pst: ['60','500'].includes(cst), vbcfcp: ['10','20','51','70','90'].includes(cst), pfcp: ['00','10','20','51','70','90'].includes(cst), vfcp: ['00','10','20','51','70','90'].includes(cst), vbcfcpst: ['10','30','70','90','201','202','900'].includes(cst), pfcpst: ['10','30','70','90','201','202','900'].includes(cst), vfcpst: ['10','30','70','90','201','202','900'].includes(cst), vbcfcpstret: ['60','500'].includes(cst), pfcpstret: ['60','500'].includes(cst), vfcpstret: ['60','500'].includes(cst), vicmsdeson: ['20', '30','40','90','900'].includes(cst) }; } }