Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export calendar / appointments directly via Excel or CSV file? #259

Open
ghost opened this issue Dec 4, 2016 · 5 comments
Open

Export calendar / appointments directly via Excel or CSV file? #259

ghost opened this issue Dec 4, 2016 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Dec 4, 2016

Is there a way to directly export calendar appointments from the backend to an Excel or CSV file?

Otherwise the usability of the system would be really limited when data needs to be integrated with other systems (which applies to most company settings).

@ghost
Copy link
Author

ghost commented Dec 5, 2016

I have actually never used CodeIgniter before, but I have started to work on a controller function (export_appointments() in Backend.php) that should download all appointments and related data as a csv-file.

The idea is to display a "Download CSV" button under "Settings" as a menu tab, which should be only visible to the administrator and secretaries of the application:

export_data

Here is export_appointments() so far:

public function export_appointments() {

        if (!$this->_has_privileges(PRIV_SYSTEM_SETTINGS, FALSE)
                && !$this->_has_privileges(PRIV_USER_SETTINGS)) return;

        $this->load->helper('download');

        $appointments = $this->db->get('ea_appointments')->result_array();

        $fp = fopen('php://output', 'w');
        foreach ($appointments as $fields) {
            fputcsv($fp, $fields);
        }

        $data = file_get_contents('php://output');
        $name = 'turnos.csv';

        // Build the headers to push out the file properly.
        header('Pragma: public');     // required
        header('Expires: 0');         // no cache
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: private',false);
        header('Content-Disposition: attachment; filename="'.basename($name).'"');  // Add the file name
        header('Content-Transfer-Encoding: binary');
        header('Connection: close');
        exit();

        force_download($name, $data);
        fclose($fp);
    }

The problem is that this will download only the entries of the appointment table with hashed data and relational IDs etc. I would appreciate some guidance how to actually query the relational data from the other tables in one go (i.e. service provider, service, client details etc.)

I am then calling this function on button-click in settings.php:

<?php
        // --------------------------------------------------------------
        //
        // DATA EXPORT TAB
        //
        // --------------------------------------------------------------
    ?>
    <?php $hidden = ($privileges[PRIV_SYSTEM_SETTINGS]['view'] == TRUE) ? '' : 'hidden'; ?>
    <div id="export" class="tab-content <?php echo $hidden; ?>">
        <form class="row">

            <fieldset class="col-xs-12 col-sm-6 miscellaneous-wrapper">
                <legend>Export Appointment Data</legend>

                <button type="button" id="data-csv-export" class="btn btn-default" onclick="window.location='<?php echo site_url("backend/export_appointments");?>'">Download CSV</button>
            </fieldset>
        </form>
    </div>

The problem I experience here is the view-restriction for users that are not administrators or secretaries. How can you limit access?

Would appreciate your feedback.

@alextselegidis
Copy link
Owner

alextselegidis commented Dec 5, 2016

Hey, this is a good idea, let me elaborate on this and I will get back to you again :)

  Alex Tselegidis, Easy!Appointments Creator
  Need a customization? Contact me in person!

@alextselegidis alextselegidis added the enhancement New feature or request label Dec 5, 2016
@alextselegidis alextselegidis self-assigned this Jan 28, 2018
@phenomeus
Copy link

+1

@h-e-l-l-o-w-o-r-l-d
Copy link

h-e-l-l-o-w-o-r-l-d commented Oct 6, 2021

+1

As far as I can see, there's no way to export the appointments in a common format with important fields like date/time, first name, last name, email and notes. This is what our secretaries need for further processing. Copying the list view in the backend results in bad formatted text and missing fields.

Workaround for now is an sql-query-result that we submit via .txt or .xlsx to the secretaries. Of course it would be better if secretaries could do that on their own without assistance of an admin.

I see this as a must have. :)

@stevenkissack
Copy link

@alextselegidis I've added this for my own purposes in a fork, though submitting as a clean PR is difficult as it's branched after I added some downstream features:

  • Appointment prices (Open PR)
  • (KoolReport based) Sales Report section (Can open a PR if the above is given the green light)

For the exports feature, I added the following under Settings -> Exports:

  • CSV export for Customers (not providers etc)
  • CSV export for Appointments
  • Entire Database export in SQL format
  • English translations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants