###RUN THE FIRST TEMPDB PARTS EVERY SINGLE DAY FOR THE CURRENT MONTH of payments####
#####
##New leads all because dates selected later based on filename + implemented logic
###RUN THE FIRST TEMPDB PARTS EVERY SINGLE DAY FOR THE CURRENT MONTH of payments####
#####
##New leads all because dates selected later based on filename + implemented logic
cpf,My_ContractNumber,
Oldest_outstanding_installment_number,due_Date,
Description_of_region_code, region_code,
from tempdb.newleads22
from tempdb.new_leads_all;
select distinct *,
'244','362','15','65','83','153','175','188','254','317','53','140','275','363','52','112','201','276','101','129','1
30','270','272','129','128','177','222','72','131',
'208','289','85','124','156','250','364','45','86','243','342','343','372','84','158','209','283','305','306','309','
66','71','127','139','212','247','287','344','345',
'346','347','371','70','159','213','282','332','333','94','171','245','195','219','288')
from tempdb.new_leads
-- Generating RowNo
Set @RowNo := 0;
FROM tempdb.new_leads1;
select a.*,
ifnull(b.Lead_Sent_Date,curdate()) as Next_Lead_Sent_Date
from tempDB.newleads_rownum1 a
on a.My_contractnumber = b.My_contractnumber
order by My_contractnumber;
-- is there bias?
ON B.d0leads = A.my_contractnumber
from bvsatmap.tol_remessa_exclusao_retirada_21 a
left JOIN
TEMPDB.exclusao B
ON B.numero_do_contrato = A.my_contractnumber
-- two solutions-- add a filter in the join that removes these cases.
#####ALL PAYMENTS####
CD_CLI as Internal_code_for_phase,
NR_CNPJ_CPF as CPF,
CD_CTR as ContractNumber,
NR_PCL as InstallmentNumber,
DT_EMS_RCB as ReceiptDate,
DT_PGT_RCB as Invoice_Payment_Date,
VR_TOT_PGT as Total_Amount,
'NA' AS Bank_Invoice_Code
FROM bvsatmap.`bv_toledo.pagamentos`
count(*) Number_Payments,
SUM(Total_Amount) Total_Amount
FROM tempdb.PaymentsData_1
GROUP BY Toledo_Invoice_Code; ##group on bank invoice code for new payments format
CODE as Internal_code_for_phase,
CPF as CPF,
CONTRATOGESTAO as ContractNumber,
PAR as InstallmentNumber,
DT_STATUS as ReceiptDate,
DT_PAGAMENTO as Invoice_Payment_Date,
-- ID_SIT_RCB as Invoice_Status,
VR_PAGAMENTO as Total_Amount,
TPNOSSO_NUMERO AS Bank_Invoice_Code
FROM bvsatmap.`bv_toledo.payments_new`
where date(DT_PAGAMENTO)>='2017-06-01'
and month(DT_Pagamento) = month(@paymentstartdate)
count(*) Number_Payments,
SUM(Total_Amount) Total_Amount
FROM tempdb.PaymentsData_2 lm
GROUP BY Bank_Invoice_Code;
UNION
Lowest_Installment_cleared
FROM tempdb.newleads6 LL
ON LL.My_ContractNumber =PP.ContractNumber
order by My_ContractNumber;
from tempDB.Report ;
Lead_Sent_Date, Invoice_payment_date,
SUM(CASE WHEN (ON_OFF_1 = 1 and Invoice_Payment_Date is not NULL ) THEN 1 ELSE 0 END)
ON_Payments_made,
SUM(CASE WHEN ( ON_OFF_1 = 0 and Invoice_Payment_Date is not NULL ) THEN 1 ELSE 0 END)
OFF_Payments_made,
STDDEV(CASE WHEN (ON_OFF_1 = 1 and Invoice_Payment_Date is not NULL ) THEN 1 ELSE 0 END)
ON_Stddev,
STDDEV(CASE WHEN ( ON_OFF_1 = 0 and Invoice_Payment_Date is not NULL ) THEN 1 ELSE 0 END)
OFF_Stddev
FROM tempDB.Report2
where Lead_Sent_Date is not NULL and on_off_1 is not null and My_ContractNumber is not null
##CLIENT VIEW
set @PaymentMonth= 9;
FROM tempDB.Custom_Report
group by Month(lead_sent_date);
100*((ON_CR-OFF_CR)*ON_Leads)/(ON_Payments-((ON_CR-OFF_CR)*ON_Leads)) Gain
from tempDB.ClientPortal_Report;
##INTERNAL VIEW
sum(ON_Contracts_In_Leads) as ON_CONTRACTS_in_Leads,
sum(OFF_Contracts_In_Leads) as OFF_CONTRACTS_in_Leads,
from tempdb.custom_report
group by lead_sent_date
order by lead_sent_date;
FROM tempDB.InternalPortal_Report
group by lead_sent_date;
100*((ON_CR-OFF_CR)*ON_Leads)/(ON_Payments-((ON_CR-OFF_CR)*ON_Leads)) Gain
from tempDB.InternalPortal_Report2;