From b6935cf673aaf383c430a6514b5698f43d217285 Mon Sep 17 00:00:00 2001 From: despiegk Date: Sun, 20 Jul 2025 11:04:10 +0200 Subject: [PATCH] ... --- examples/biztools/bizmodel1.vsh | 2 +- lib/biz/bizmodel/act.v | 1 - lib/biz/bizmodel/play_product_revenue.v | 28 ++++++++++++++++++- lib/biz/bizmodel/play_product_revenue_item.v | 22 ++++++++++++--- lib/biz/bizmodel/play_product_revenue_total.v | 14 +--------- lib/biz/spreadsheet/sheet_pprint.v | 4 +++ 6 files changed, 51 insertions(+), 20 deletions(-) diff --git a/examples/biztools/bizmodel1.vsh b/examples/biztools/bizmodel1.vsh index 5bab3b41..241071f2 100755 --- a/examples/biztools/bizmodel1.vsh +++ b/examples/biztools/bizmodel1.vsh @@ -25,4 +25,4 @@ bizmodel.play(heroscript:heroscript)! mut bm:=bizmodel.get("test")! -bm.sheet.pprint(nr_columns:40)! \ No newline at end of file +bm.sheet.pprint(nr_columns:30)! \ No newline at end of file diff --git a/lib/biz/bizmodel/act.v b/lib/biz/bizmodel/act.v index 8714d970..014a2c08 100644 --- a/lib/biz/bizmodel/act.v +++ b/lib/biz/bizmodel/act.v @@ -17,7 +17,6 @@ pub fn (mut m BizModel) act(action Action) !Action { 'revenue_define' { m.revenue_action(action)! m.revenue_item_action(action)! - m.revenue_name_total(action)! } 'costcenter_define' { m.costcenter_define_action(action)! diff --git a/lib/biz/bizmodel/play_product_revenue.v b/lib/biz/bizmodel/play_product_revenue.v index a69ddd5e..6e89ee22 100644 --- a/lib/biz/bizmodel/play_product_revenue.v +++ b/lib/biz/bizmodel/play_product_revenue.v @@ -18,6 +18,21 @@ fn (mut m BizModel) revenue_action(action Action) !Action { mut nr_months_recurring := action.params.get_int_default('nr_months_recurring', 60)! product.nr_months_recurring = nr_months_recurring + mut nr_sold := m.sheet.row_new( + name: '${r.name}_nr_sold' + growth: action.params.get_default('nr_sold', '0')! + tags: 'name:${r.name}' + descr: 'nr of items sold/month for ${r.name}' + aggregatetype: .avg + extrapolate: true + )! + + if nr_sold.max() > 0 { + //don't process if nr sold + return action + } + + mut revenue := m.sheet.row_new( name: '${r.name}_revenue' growth: action.params.get_default('revenue', '0:0')! @@ -56,12 +71,23 @@ fn (mut m BizModel) revenue_action(action Action) !Action { action: .add rows: [cogs_percent_temp] name: '${r.name}_cogs' - tags: 'cogs cogs:${r.name} name:${r.name}' + tags: 'cogs name:${r.name}' )! if revenue.max() > 0 { product.has_revenue = true } + mut margin := revenue.action( + name: '${r.name}_margin' + descr: 'Margin for ${r.name}' + action: .substract + rows: [cogs] + tags: 'name:${r.name} margin' + )! + + println(margin) + m.sheet.pprint(nr_columns:30)! + return action } \ No newline at end of file diff --git a/lib/biz/bizmodel/play_product_revenue_item.v b/lib/biz/bizmodel/play_product_revenue_item.v index da809afe..943cdadc 100644 --- a/lib/biz/bizmodel/play_product_revenue_item.v +++ b/lib/biz/bizmodel/play_product_revenue_item.v @@ -20,6 +20,8 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { if nr_sold.max() > 0 { product.has_items = true + }else{ + return action } mut revenue_item_setup_param := m.sheet.row_new( @@ -119,7 +121,7 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { descr: 'Setup sales for ${r.name} total' action: .multiply rows: [nr_sold] - tags: 'name:${r.name}' + tags: 'name:${r.name} rev' delaymonths: action.params.get_int_default('revenue_item_setup_delay', 0)! )! @@ -138,7 +140,7 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { descr: 'Setup COGS for ${r.name} total' action: .multiply rows: [nr_sold] - tags: 'name:${r.name}' + tags: 'name:${r.name} cogs' delaymonths: action.params.get_int_default('cogs_item_delay', 0)! )! @@ -159,6 +161,7 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { name: '${r.name}_revenue_monthly' descr: 'Revenue monthly recurring for ${r.name}' nrmonths: product.nr_months_recurring + tags: 'name:${r.name} rev' )! revenue_monthly_total.delete() @@ -167,6 +170,7 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { name: '${r.name}_cogs_monthly' descr: 'COGS monthly recurring for ${r.name}' nrmonths: product.nr_months_recurring + tags: 'name:${r.name} cogs' )! cogs_monthly_total.delete() @@ -177,11 +181,12 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { nrmonths: product.nr_months_recurring aggregatetype: .max delaymonths: action.params.get_int_default('revenue_item_monthly_delay', 0)! + )! //DEAL WITH MARGIN - mut margin_setup_total := revenue_setup.action( + mut margin_setup := revenue_setup.action( name: '${r.name}_margin_setup' descr: 'Setup margin for ${r.name}' action: .substract @@ -190,7 +195,7 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { )! - mut margin_monthly_total := revenue_monthly_recurring.action( + mut margin_monthly := revenue_monthly_recurring.action( name: '${r.name}_margin_monthly' descr: 'Monthly margin for ${r.name}' action: .substract @@ -198,6 +203,15 @@ fn (mut m BizModel) revenue_item_action(action Action) !Action { tags: 'name:${r.name}' )! + mut margin := margin_setup.action( + name: '${r.name}_margin' + descr: 'Margin for ${r.name}' + action: .add + rows: [margin_monthly] + tags: 'name:${r.name} margin' + )! + + return action } diff --git a/lib/biz/bizmodel/play_product_revenue_total.v b/lib/biz/bizmodel/play_product_revenue_total.v index 78d8ed4a..5e850464 100644 --- a/lib/biz/bizmodel/play_product_revenue_total.v +++ b/lib/biz/bizmodel/play_product_revenue_total.v @@ -9,20 +9,8 @@ fn (mut sim BizModel) revenue_total() ! { mut revenue_total := sheet.group2row(name:"revenue_total", include:['rev'], tags:"total", descr:'total revenue.')! mut cogs_total := sheet.group2row(name:"cogs_total", include:['cogs'], tags:"total", descr:'total cogs.')! + mut margin_total := sheet.group2row(name:"margin_total", include:['margin'], tags:"total", descr:'total margin.')! } - -fn (mut sim BizModel) revenue_name_total(action Action) !Action { - - mut r := get_action_descr(action)! - mut product := sim.products[r.name] - - mut sheet:= sim.sheet - - mut revenue_total := sheet.group2row(name:"${r.name}_revenue_total", include:['rev:${r.name}'], tags:"name:${r.name}", descr:'total revenue for ${r.name}.')! - mut cogs_total := sheet.group2row(name:"${r.name}_cogs_total", include:['cogs:${r.name}'], tags:"name:${r.name}", descr:'total cogs for ${r.name}.')! - - return action -} diff --git a/lib/biz/spreadsheet/sheet_pprint.v b/lib/biz/spreadsheet/sheet_pprint.v index 4d74836a..f1a3d79b 100644 --- a/lib/biz/spreadsheet/sheet_pprint.v +++ b/lib/biz/spreadsheet/sheet_pprint.v @@ -81,6 +81,7 @@ pub fn (mut s Sheet) pprint(args PPrintArgs) ! { // Prepare data rows for _, row in s.rows { + // println('Processing row: ${row.name}') mut row_data := []string{} // Initialize row_data for each row row_data << row.name // Add the name of the row if args.description { @@ -118,9 +119,12 @@ pub fn (mut s Sheet) pprint(args PPrintArgs) ! { data_start_index++ } + //check if row is empty + // println(row_data) for i := data_start_index; i < row_data.len; i++ { cell_val := row_data[i] if cell_val.trim_space() != '' && cell_val.trim_space() != '-' { + // println("Row '${row.name}' has non-empty cell at index $i: '$cell_val'") is_empty_row = false break }