Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once(WC()->plugin_path().'/includes/admin/reports/class-wc-admin-report.php');
- add_filter( 'woocommerce_admin_reports', 'my_custom_woocommerce_admin_reports', 10, 1 );
- function my_custom_woocommerce_admin_reports( $reports ) {
- $ventas_panuts = array(
- 'ventas_panuts' => array(
- 'title' => 'Informe Personalizado',
- 'description' => '',
- 'hide_title' => true,
- 'callback' => 'informe_panuts_callback',
- ),
- );
- // This can be: orders, customers, stock or taxes, based on where we want to insert our new reports page
- $reports['orders']['reports'] = array_merge( $reports['orders']['reports'], $ventas_panuts);
- return $reports;
- }
- function informe_panuts_callback() {
- $report = new WC_Reporte_Ventas_Panuts();
- $report->output_report();
- }
- function boton_exportar() {
- $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day';
- ?>
- <form method="post" id="export-form" action="">
- <?php submit_button('Descargar Reporte', 'primary', 'download_csv' ); ?>
- </form>
- <?php
- }
- add_action('admin_init', 'endo_stock_report_admin_init');
- function endo_stock_report_admin_init() {
- if ( isset($_POST['download_csv']) /*&& $plugin_page == 'endo_stock_report'*/ ) {
- //revisar
- $reporte = new WC_Reporte_Ventas_Panuts();
- $reporte->generate_stock_report_csv();
- die();
- }
- }
- class WC_Reporte_Ventas_Panuts extends WC_Admin_Report {
- /**
- * Output the report.
- */
- private $prerow;
- public $colector = array( 'esto es','la declaracion','del colector',':(');
- public function __construct($prerow) {
- // revisar en casa esto
- $row = array( 'esto es','la declaracion','del colector');
- $prerow = $row;
- $this->prerow = $prerow;
- }
- public function output_report() {
- $ranges = array(
- 'year' => __( 'Year', 'woocommerce' ),
- 'last_month' => __( 'Last month', 'woocommerce' ),
- 'month' => __( 'This month', 'woocommerce' ),
- );
- $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'month';
- if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', '7day' ) ) ) {
- $current_range = 'month';
- }
- $this->check_current_range_nonce( $current_range );
- $this->calculate_current_range( $current_range );
- $hide_sidebar = true;
- include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
- }
- /**
- * Output an export link.
- */
- public function get_export_button() {
- $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day';
- boton_exportar();
- }
- /**
- * Get the main chart.
- */
- public function get_main_chart($prerow) {
- global $wpdb;
- $query_data = array(
- 'ID' => array(
- 'type' => 'post_data',
- 'function' => '',
- 'name' => 'id_orden',
- 'distinct' => true,
- ),
- '_order_total' => array(
- 'type' => 'meta',
- 'function' => '',
- 'name' => 'orden_total'
- ),
- );
- $ventas_panuts_orders = $this->get_order_report_data( array(
- 'data' => $query_data,
- 'query_type' => 'get_results',
- //'group_by' => 'country',
- 'filter_range' => true,
- 'order_types' => wc_get_order_types( 'sales-reports' ),
- 'order_status' => array( 'completed' ),
- 'parent_order_status' => false,
- ) );
- ?>
- <table class="widefat">
- <thead>
- <tr>
- <th><strong>Fecha</strong></th>
- <th><strong>Mes</strong></th>
- <th><strong>Orden</strong></th>
- <th><strong>Nombre</strong></th>
- <th><strong>Apellido</strong></th>
- <th><strong>DNI</strong></th>
- <th><strong>Dirección</strong></th>
- <th><strong>Distrito</strong></th>
- <th><strong>Correo</strong></th>
- <th><strong>Teléfono</strong></th>
- <th><strong>Producto</strong></th>
- <th><strong>Cantidad</strong></th>
- <th><strong>Precio Unitario</strong></th>
- <th><strong>Subtotal</strong></th>
- <th><strong>Costo de Envío</strong></th>
- <th><strong>Total</strong></th>
- <th><strong>Método de Pago</strong></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach( $ventas_panuts_orders as $order ) {
- $order_obj = wc_get_order( $order->id_orden );
- $order_data = $order_obj->get_data();
- $date_created = $order_obj->order_date;
- $strtotime = strtotime($date_created);
- $order_items = $order_obj->get_items();
- $i=true;
- foreach( $order_items as $product ) {
- ?>
- <tr>
- <td><?php echo $date_created; ?></td>
- <td><?php echo date('M',$strtotime); ?></td>
- <td><?php echo $order->id_orden; ?></td>
- <td style="text-transform: capitalize;"><?php echo $order_obj->get_billing_first_name(); ?></td>
- <td style="text-transform: capitalize;"><?php echo $order_obj->get_billing_last_name(); ?></td>
- <td><?php echo get_post_meta( $order->id_orden, 'billing_dni', true ); ?></td>
- <td style="text-transform: capitalize;"><?php echo $order_obj->get_billing_address_1().' '.$order_obj->get_billing_address_2();?></td>
- <td><?php echo WC()->countries->get_states( $order_obj->get_billing_country() )[$order_obj->get_billing_state()]; ?></td>
- <td><?php echo $order_obj->get_billing_email(); ?></td>
- <td><?php echo get_post_meta( $order->id_orden, 'billing_cellphone', true ); ?></td>
- <td><?php echo '<p>'.$product['name'].'</p>'; ?></td>
- <td align="center"><?php echo '<p>'.$product['qty'].'</p>'; ?></td>
- <td align="center"><?php echo '<p>'.$product->get_total()/$product['qty'].'</p>'; ?></td>
- <td align="center"><?php echo $product->get_total(); ?></td>
- <?php
- if ($i){ ?>
- <td><?php echo $order_obj->get_shipping_total(); ?></td>
- <td><?php echo wc_price($order->orden_total); ?></td> <!-- total de orden -->
- <td><?php echo $order_obj->get_payment_method_title(); ?></td>
- <?php $i=false; } ?>
- </tr>
- <?php }
- } ?>
- </tbody>
- </table>
- <?php
- global $colector;
- $this->prerow = array( 'esto debería aparecer','si se ejecuta','en get_main_chart','y jala row con datos');
- }
- function generate_stock_report_csv() {
- // output headers so that the file is downloaded rather than displayed
- header('Content-Type: text/csv; charset=utf-8');
- // set file name with current date
- header('Content-Disposition: attachment; filename=reporte-panuts-' . date('Y-m-d') . '.csv');
- // create a file pointer connected to the output stream
- $output = fopen('php://output', 'w');
- // set the column headers for the csv
- $headings = array( 'Fecha', 'Mes', 'Orden', 'Nombre', 'Apellido', 'DNI', 'Dirección', 'Distrito', 'Correo', 'Teléfono', 'Producto', 'Cantidad', 'Precio', 'Subtotal', 'Envío', 'Total', 'Método de Pago' );
- // output the column headings
- fputcsv($output, $headings );
- global $colector;
- $row = $colector;
- $row = $this->prerow;
- $row = array( 'y esto debería aparecer','si accedo a mi función de botón',$order->id_orden,date('M',$strtotime));
- fputcsv($output, $row);
- foreach( $ventas_panuts_orders as $order ) {
- $i=true;
- foreach( $order_items as $product ) {
- $row = array( $date_created . ', ' . date('M',$strtotime) . ', ' . $order->id_orden . ', ' . $order_obj->get_billing_first_name() . ', ' . $order_obj->get_billing_last_name() . ', ' . get_post_meta( $order->id_orden, 'billing_dni', true ) . ', ' . $order_obj->get_billing_address_1().' '.$order_obj->get_billing_address_2() . ', ' . WC()->countries->get_states( $order_obj->get_billing_country() )[$order_obj->get_billing_state()] . ', ' . $order_obj->get_billing_email() . ', ' . get_post_meta( $order->id_orden, 'billing_cellphone', true ) . ', ' . $product['name'] . ', ' . $product['qty'] . ', ' . $product->get_total()/$product['qty'] . ', ' . $product->get_total());
- fputcsv($output, $row);
- /*?>
- <tr>
- <?php
- if ($i){ ?>
- <td><?php echo $order_obj->get_shipping_total(); ?></td>
- <td><?php echo wc_price($order->orden_total); ?></td> <!-- total de orden -->
- <td><?php echo $order_obj->get_payment_method_title(); ?></td>
- <?php $i=false; } ?>
- </tr>
- <?php
- */
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement