Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/casewin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,46 @@ bool CaseWindow::RunSSCBaseCase(wxString& fn, bool silent, wxString* messages)
}


bool CaseWindow::ExportCashflowExcel()
{
if (m_case != NULL) {

// if no outputs run a simulation. this approach could result in exported cash flow not matching current inputs if user modifies inputs without running a simulation before exporting
if (m_case->BaseCase().Outputs().size() == 0) {
RunBaseCase();
}

// all cash flow models have cf_om_fixed_expense output except standalone battery
bool is_cf_model;
if (auto* vv = m_case->BaseCase().GetOutput("cf_om_fixed_expense"))
is_cf_model = true;
else if (auto* vv1 = m_case->BaseCase().GetOutput("cf_om_fixed1_expense")) // standalone battery
is_cf_model = true;
else
is_cf_model = false;

if ( is_cf_model ) {
#ifdef __WXMSW__
// UpdateResults();
m_baseCaseResults->Export(EXP_CASHFLOW, EXP_SEND_EXCEL);
return true;
#else
wxMessageBox("Excel export is only supported on Windows systems.");
return false;
#endif
}
else {
wxMessageBox("No cash flow to export. Export cash flow requires a cash flow-based financial model.");
return false;
}
}
else {
wxMessageBox("No active case selected.");
return false;
}
}


void CaseWindow::UpdateResults()
{
m_baseCaseResults->Setup( &m_case->BaseCase() );
Expand Down
2 changes: 2 additions & 0 deletions src/casewin.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class CaseWindow : public wxSplitterWindow, CaseEventListener
bool RunBaseCase( bool silent = false, wxString *messages = 0 );
void UpdateResults();

bool ExportCashflowExcel();

bool RunSSCBaseCase(wxString& fn, bool silent = false, wxString* messages = 0);

bool GenerateReport(
Expand Down
1 change: 1 addition & 0 deletions src/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include "macro.h"
#include "invoke.h"

class macro_vm : public lk::vm
{
Expand Down
25 changes: 15 additions & 10 deletions src/reports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,11 +2255,16 @@ void SamReportScriptObject::Render( wxPageOutputDevice &dv )
env.register_funcs( lk::stdlib_math() );
env.register_funcs( lk::stdlib_wxui() );

wxStopWatch sw;
lk::eval e( tree, &env );
if ( !e.run() )
for (size_t i=0;i<e.error_count();i++)
errors += e.get_error(i) + "\n";
try {
wxStopWatch sw;
lk::eval e(tree, &env);
if (!e.run())
for (size_t i = 0; i < e.error_count(); i++)
errors += e.get_error(i) + "\n";
}
catch (std::exception e) {
wxMessageBox(e.what());
}
}

int i=0;
Expand Down Expand Up @@ -2559,7 +2564,7 @@ void SamReportScriptObject::RenderTable( const matrix_t<wxString> &tab )
float xpos = tab_x;
for (int c=0;c<(int)tab.ncols();c++)
{
int align = (r==0) ? m_headerAlign : m_cellAlign;
int align = (r<m_headerLines) ? m_headerAlign : m_cellAlign;
switch( align )
{
case wxLEFT:
Expand Down Expand Up @@ -2602,11 +2607,11 @@ void SamReportScriptObject::RenderTable( const matrix_t<wxString> &tab )
}

m_curDevice->Color( *wxBLACK );
if (m_headerLine && row_heights.size() > 0)
m_curDevice->Line( tab_x, tab_y+row_heights[0],
tab_x+tab_width, tab_y+row_heights[0] );
if (m_headerLine && row_heights.size() > 0 )
m_curDevice->Line( tab_x, tab_y+m_headerLines*row_heights[0],
tab_x+tab_width, tab_y+ m_headerLines * row_heights[0] );
float ypos_total_lines = tab_y+row_heights[0];
for (int r = 1; r < (int)tab.nrows(); r++) {
for (int r = m_headerLines - 1; r < (int)tab.nrows(); r++) {
ypos_total_lines += row_heights[r];
for (int b = 0; b < m_totalLines.size(); b++) {
if (r == m_totalLines[b] && r != (int)tab.nrows() - 1) {
Expand Down
3 changes: 2 additions & 1 deletion src/results.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class ResultsViewer : public wxMetroNotebook
TabularBrowser *GetTabularBrowser() { return m_tables; }
wxString GetCurrentContext() const;

void Export(int data, int mechanism);

private:
Simulation *m_sim = nullptr;

Expand Down Expand Up @@ -227,7 +229,6 @@ class ResultsViewer : public wxMetroNotebook

void AddDataSet( wxDVTimeSeriesDataSet *ds, const wxString &group = wxEmptyString, bool update_ui = true );
void RemoveAllDataSets();
void Export(int data, int mechanism);
void GetExportData(int data, matrix_t<wxString> &table);
void ExportEqnExcel();

Expand Down
14 changes: 14 additions & 0 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,19 @@ void fcall_show_page(lk::invoke_t &cxt)
else cxt.error("no active case");
}

void fcall_export_cashflow_excel(lk::invoke_t& cxt)
{
LK_DOC("export_cashflow_excel", "Exports the current cash flow to Excel from the active case (Windows only). Runs a simulation before exporting only if the case has no results.", "():boolean");
Case* active_case = CurrentCase();
if (CaseWindow* case_window = SamApp::Window()->GetCaseWindow(active_case)) {
cxt.result().assign(case_window->ExportCashflowExcel() ? 1.0 : 0.0);
}
else {
cxt.error("no active case window");
cxt.result().assign(0.0);
}
}

void fcall_widgetpos( lk::invoke_t &cxt )
{
LK_DOC("widgetpos", "Get geometry in pixels in toplevel coordinates of the widget associated with the specified variable.", "(string:name):array" );
Expand Down Expand Up @@ -659,6 +672,7 @@ lk::fcall_t *sam_functions() {
fcall_simulate,
fcall_simulate_ssc_tests,
fcall_show_page,
fcall_export_cashflow_excel,
fcall_widgetpos,
fcall_focusto,
fcall_configuration,
Expand Down
Loading