diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index ec34c08..c929dbb 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -13,45 +13,53 @@ const reactionEffects: IReactionEffect[] = [ x => x.value === leadId, ); - CalculationService.getEntityOptions({ - entityName: 'opportunity', - fields: undefined, - where: { opportunityid: lead?.evo_opportunityid }, - }) - .then(opportunities => { - calculationStore.setOptions('selectOpportunity', opportunities); - calculationStore.setValue( - 'opportunity', - opportunities[0].opportunityid, - ); + if (lead) + CalculationService.getEntityOptions({ + entityName: 'opportunity', + fields: undefined, + where: { opportunityid: lead.evo_opportunityid || null }, }) - .catch(err => { - throw err; - }); + .then(opportunities => { + console.log( + 'opportunities', + lead?.evo_opportunityid || '', + opportunities, + ); + if (opportunities) { + calculationStore.setOptions('selectOpportunity', opportunities); + calculationStore.setValue( + 'opportunity', + opportunities[0] ? opportunities[0].opportunityid : null, + ); + } + }) + .catch(err => { + throw err; + }); - if (leadId && lead?.evo_opportunityid) { - const opportunity = calculationStore.options.selectOpportunity?.find( - o => o.value === lead?.evo_opportunityid, - ); - if (opportunity) { - calculationStore.setValue('opportunity', opportunity.value); - } else { - calculationStore.setValue('opportunity', null); - } - } else { - calculationStore.setValue('opportunity', null); - } + // if (leadId && lead?.evo_opportunityid) { + // const opportunity = calculationStore.options.selectOpportunity?.find( + // o => o.value === lead?.evo_opportunityid, + // ); + // if (opportunity) { + // calculationStore.setValue('opportunity', opportunity.value); + // } else { + // calculationStore.setValue('opportunity', null); + // } + // } else { + // calculationStore.setValue('opportunity', null); + // } - if (leadId && lead) { - calculationStore.setFilter('selectQuote', quotes => { - return quotes.filter(q => q.evo_leadid === leadId); - }); - } else { - calculationStore.setFilter('selectQuote', quotes => { - return []; - }); - calculationStore.setValue('quote', null); - } + // if (leadId && lead) { + // calculationStore.setFilter('selectQuote', quotes => { + // return quotes.filter(q => q.evo_leadid === leadId); + // }); + // } else { + // calculationStore.setFilter('selectQuote', quotes => { + // return []; + // }); + // calculationStore.setValue('quote', null); + // } }, }), diff --git a/src/server/controllers/CalculationController.ts b/src/server/controllers/CalculationController.ts index 537bd1c..82b910a 100644 --- a/src/server/controllers/CalculationController.ts +++ b/src/server/controllers/CalculationController.ts @@ -18,10 +18,11 @@ function _getFakeEntities(entityName, fields?, where?, wherein?): IOption[] { if (Object.keys(totalWhere).length > 0) entities = entities.filter(entity => { for (let w in totalWhere) { - return entity[w] === totalWhere[w]; + if (entity[w] !== totalWhere[w]) { + return false; + } } - - return false; + return true; }); return entities; }