CREATE VIEW `Sales_stage_history_pb` AS
select
`ac`.`name` AS `account_name`,
`ac`.`id` AS `account_id`,
`u`.`user_name` AS `kam`,
`oc`.`expected_er_delivery_date_c` AS `expected_delivery_date`,
`oc`.`numberoftons_c` AS `numbers_of_tons`,
o.lead_source AS lead_source,
ac.billing_address_country AS country,
oc.spcategorie_c AS practice,
o.probability AS probability,
`o`.`name` AS `opportunity_name`,
`o`.`description` AS `opportunity_description`,
`o`.`sales_stage` AS `current_stage`,
`o`.`amount` AS `gross_margin`,
`a`.`before_value_string` AS `old_value`,
`a`.`after_value_string` AS `new_value`,
`a`.`date_created` AS `changing_date`,
`acc`.`spindustrysectorii_c` AS `sp_industry`,
`acc`.`newaccountstatus_c` AS `acc_status`,
`acc`.`commitments_c` AS `acc_commitments`,
`acc`.`reportingto_c` AS `acc_reporting_to`,
`oc`.`spcategorie_c` AS `opp_solution`,
`o`.`date_entered` AS `opp_creation_date`,
`oc`.`reasonswonlost_c` AS `opp_reasonswonlost`,
`o`.`campaign_id` AS `opp_campaign` from ((((((`opportunities_audit` `a` join `opportunities` `o`) join `accounts_opportunities` `ao`) join `accounts` `ac`) join `users` `u`) join `accounts_cstm` `acc`) join `opportunities_cstm` `oc`)
where ((`a`.`field_name` = ‘sales_stage’)
and (`o`.`id` = `a`.`parent_id`)
and (`o`.`deleted` = 0)
and (`ao`.`opportunity_id` = `o`.`id`)
and (`ac`.`id` = `ao`.`account_id`)
and (`o`.`assigned_user_id` = `u`.`id`)
and (`ac`.`id` = `acc`.`id_c`)
and (`o`.`id` = `oc`.`id_c`)) ;
CREATE VIEW `sophies3` AS
select
`o`.`name` AS `Opportunity name`,
`ac`.`name` AS `Client name`,
`acc`.`newaccountstatus_c` AS `Account status`,
`ac`.`billing_address_country` AS `Country`,
`o`.`date_entered` AS `Date created`,
`oc`.`expected_er_delivery_date_c` AS `Estimated delivery date`,
`u`.`user_name` AS `KAM`,
`i`.`name` AS `SP industry`,
p.name AS Practice,
`o`.`amount` AS `Estimated SP gross margin (EUR)`,
o.probability AS probability,
oc.weightedgrossmargin_c AS `Estimated gross margin with probability`,
`o`.`sales_stage` AS `Sales stage`,
o.lead_source AS `Lead source`,
`o`.`campaign_id` AS `Campaign ID`
from ((((((((`opportunities_audit` `a` join `opportunities` `o`) join `accounts_opportunities` `ao`) join `accounts` `ac`) join `users` `u`) join `accounts_cstm` `acc`) join `opportunities_cstm` `oc`) join `practices` `p`)join `industries` `i`)
where ((`a`.`field_name` = ‘sales_stage’)
and (`o`.`id` = `a`.`parent_id`)
and (`o`.`deleted` = 0)
and (`ao`.`opportunity_id` = `o`.`id`)
and (`ac`.`id` = `ao`.`account_id`)
and (`o`.`assigned_user_id` = `u`.`id`)
and (`ac`.`id` = `acc`.`id_c`)
and (`oc`.`spcategorie_c` = `p`.`id`)
and (`acc`.`spindustrysectorii_c` = `i`.`id`)
and (`o`.`id` = `oc`.`id_c`)) ;