function open_csa_wp_show_products($display, $page_url) { wp_enqueue_script('open-csa-wp-general-scripts'); wp_enqueue_script('open-csa-wp-products-scripts'); wp_enqueue_script('jquery.datatables'); wp_enqueue_script('jquery.jeditable'); wp_enqueue_script('jquery.blockui'); ?> <br /> <div id="open-csa-wp-showProductsList_header"> <span style="cursor:pointer" id="open-csa-wp-showProductsList_formHeader_text" onclick="open_csa_wp_toggle_form('showProductsList','Product List', '')"> <font size='4'> <?php if ($display == false) { echo __('Product List', OPEN_CSA_WP_DOMAIN) . ' (' . __('show', OPEN_CSA_WP_DOMAIN) . ')'; } else { echo __('Product List', OPEN_CSA_WP_DOMAIN) . ' (' . __('hide', OPEN_CSA_WP_DOMAIN) . ')'; } ?> </font> </span> </div> <div id="open-csa-wp-showProductsList_div" <?php if ($display == false) { echo 'style="display:none"'; } ?> > <span class='open-csa-wp-tip_products' title=' If you want to update one among the name, variety, and description fields, click on it, write the new value, and then press ENTER. | To change the availilability of a product, you can either click on its field or click the "eye" icon. | If you want to edit some of the other product details, click on the "pen" icon. | If you want to delete some product, click on the "x" icon. '> <p style="color:green;font-style:italic; font-size:13px"> by pointing here you can read additional information...</p></span> <table class='table-bordered' id="open-csa-wp-showProductsList_table" style='border-spacing:1em' open-csa-wp-plugins_dir='<?php echo plugins_url(); ?> ' > <thead class='tableHeader'> <tr> <th><?php _e('Name', OPEN_CSA_WP_DOMAIN); ?> </th> <th><?php _e('Category', OPEN_CSA_WP_DOMAIN); ?> </th> <th><?php _e('Variety', OPEN_CSA_WP_DOMAIN); ?> </th> <th><?php _e('Price', OPEN_CSA_WP_DOMAIN); ?> (€)</th> <th><?php _e('Per', OPEN_CSA_WP_DOMAIN); ?> ...</th> <th><?php _e('Producer', OPEN_CSA_WP_DOMAIN); ?> </th> <th><?php _e('Description', OPEN_CSA_WP_DOMAIN); ?> </th> <th><?php _e('Available?', OPEN_CSA_WP_DOMAIN); ?> </th> <th/> <th/> <th/> </tr> </thead> <tbody> <?php global $wpdb; $plugins_dir = plugins_url(); $product_categories_map = $wpdb->get_results("SELECT id,name FROM " . OPEN_CSA_WP_TABLE_PRODUCT_CATEGORIES, OBJECT_K); $producers_map = open_csa_wp_producers_map_array(); $products = $wpdb->get_results("SELECT * FROM " . OPEN_CSA_WP_TABLE_PRODUCTS); foreach ($products as $row) { $product_id = $row->id; $category = $product_categories_map[$row->category]->name; $producer_id = $wpdb->get_var($wpdb->prepare("SELECT producer FROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " WHERE id=%d", $product_id)); $producer = $producers_map[$producer_id]; echo "\n\t\t\t\t\t<tr \n\t\t\t\t\t\tvalign='top' \n\t\t\t\t\t\tid='open-csa-wp-showProductsProductID_{$product_id}' \n\t\t\t\t\t\tclass='open-csa-wp-showProducts-product'\n\t\t\t\t\t\tstyle='text-align:center;color:" . ($row->is_available == '1' ? "black" : "gray") . "'\n\t\t\t\t\t>\n\t\t\t\t\t<td class='editable'>{$row->name} </td>\n\t\t\t\t\t<td>{$category} </td>\n\t\t\t\t\t<td class='editable'>{$row->variety}</td>\n\t\t\t\t\t<td>{$row->current_price_in_euro}</td>\n\t\t\t\t\t<td>{$row->measurement_unit}</td>\n\t\t\t\t\t<td\t>{$producer}</td>\n\t\t\t\t\t<td class='editable'>{$row->description}</td>\n\t\t\t\t\t<td \n\t\t\t\t\t\tclass='editable_boolean'\n\t\t\t\t\t\tid = 'open-csa-wp-showProductsAvailabilityID_{$product_id}'\n\t\t\t\t\t>" . ($row->is_available == 1 ? "yes" : "no") . "</td>\n\t\t\t\t\t<td style='text-align:center'><img \n\t\t\t\t\t\t\tstyle='cursor:pointer' \n\t\t\t\t\t\t\tsrc='" . plugins_url() . "/open-csa-wp/icons/" . ($row->is_available == 1 ? "visible" : "nonVisible") . ".png' \n\t\t\t\t\t\t\theight='24' width='24' \n\t\t\t\t\t\t\tid = 'open-csa-wp-showProductsAvailabilityIconID_{$product_id}'\n\t\t\t\t\t\t\ttitle='" . __('mark it as', OPEN_CSA_WP_DOMAIN) . " " . ($row->is_available == 1 ? __('unavailable', OPEN_CSA_WP_DOMAIN) : __('available', OPEN_CSA_WP_DOMAIN)) . "'\n\t\t\t\t\t\t\tonclick='open_csa_wp_request_toggle_product_visibility(this,\"{$plugins_dir}\")'></td>\n\t\t\t\t\t<td style='text-align:center'> \n\t\t\t\t\t\t<img \n\t\t\t\t\t\t\twidth='24' height='24' \n\t\t\t\t\t\t\tclass='delete no-underline' \n\t\t\t\t\t\t\tsrc='{$plugins_dir}/open-csa-wp/icons/edit.png' \n\t\t\t\t\t\t\tstyle='cursor:pointer;padding-left:10px;' \n\t\t\t\t\t\t\tonclick='open_csa_wp_edit_product(this, \"{$page_url}\")' \n\t\t\t\t\t\t\ttitle='" . __('click to edit this product', OPEN_CSA_WP_DOMAIN) . "'/></td>\n\t\t\t\t\t<td style='text-align:center'> <img \n\t\t\t\t\t\tstyle='cursor:pointer' \n\t\t\t\t\t\tsrc='" . plugins_url() . "/open-csa-wp/icons/delete.png' \n\t\t\t\t\t\theight='24' width='24'\n\t\t\t\t\t\tonmouseover='open_csa_wp_hover_icon(this, \"delete\", \"{$plugins_dir}\")' \n\t\t\t\t\t\tonmouseout='open_csa_wp_unhover_icon(this, \"delete\", \"{$plugins_dir}\")' \t\t\t\t\t\t\n\t\t\t\t\t\tonclick='open_csa_wp_request_delete_product(this)' \n\t\t\t\t\t\ttitle='" . __('delete product', OPEN_CSA_WP_DOMAIN) . "'></td>\n\t\t\t\t\t</tr>\n\t\t\t\t"; } ?> </tbody> </table> </div> <?php }
function open_csa_wp_show_total_orders_of_delivery($delivery_id, $producer_id, $page_url) { global $wpdb; $producers_map = open_csa_wp_producers_map_array(); if ($producer_id != null) { $producers_involved = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\t\t\t\tSELECT DISTINCT " . OPEN_CSA_WP_TABLE_PRODUCTS . ".producer \n\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " LEFT JOIN " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " ON " . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d AND\n\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".producer = %d\n\t\t\t\t\t\t\t", $delivery_id, $producer_id)); } else { $producers_involved = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\t\t\t\tSELECT DISTINCT " . OPEN_CSA_WP_TABLE_PRODUCTS . ".producer \n\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " LEFT JOIN " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " ON " . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id\n\t\t\t\t\t\t\t\tWHERE " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d\n\t\t\t\t\t\t\t\tORDER BY " . OPEN_CSA_WP_TABLE_PRODUCTS . ".producer\n\t\t\t\t\t\t\t", $delivery_id)); } $producers_count = count($producers_involved); if ($producer_id != null) { echo "<span class='info-text' style='font-size:15px'>Your orders in " . CsaWpPluginGetReadableDeliveryInfo($delivery_id) . " </span>"; } else { echo "<span class='info-text' style='font-size:15px'>Orders of " . CsaWpPluginGetReadableDeliveryInfo($delivery_id) . " </span>"; } if ($producers_count <= 0) { if ($producer_id == null) { echo "<br/><span class='info-text' style='font-size:15px;color:brown'>" . __('No order has yet been submitted, for this delivery.', OPEN_CSA_WP_DOMAIN) . " </span> <br>"; } else { echo "<br/><span class='info-text' style='font-size:15px;color:brown'>" . __('You have no orders in this delivery.', OPEN_CSA_WP_DOMAIN) . " </span> <br>"; } } else { $users_count = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\t\t\t\tSELECT COUNT(DISTINCT user_id)\n\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " \n\t\t\t\t\t\t\t\t\tWHERE " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d \n\t\t\t\t\t\t\t\t", $delivery_id)); $product_details_width = 130; $amount_perProduct_width = 30; $user_order_width = 58; //change also by css (class .left) ???? SHALL WE INCORPORATE THIS? ???? $product_value_width = 70; $main_width = $product_details_width + $amount_perProduct_width + $user_order_width * $users_count + 30; // +30 is an offset to accomodate the space of the first orders $table_width = $main_width + $product_value_width; foreach ($producers_involved as $producer) { $revenue = 0; //the amount to be paid to this producer echo "<p class='panel'> <span style='font-size:14px'> " . __('Producer', OPEN_CSA_WP_DOMAIN) . ": </span> <span class='producer'>" . $producers_map[$producer] . "</span> </p>"; //Get the products in order for this producer $products_in_order = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".name,\n\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".variety,\n\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".current_price_in_euro,\n\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".id,\n\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".measurement_unit, \n\t\t\t\t\t\t\t\t\t\t\tSUM(" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".quantity) AS total, \n\t\t\t\t\t\t\t\t\t\t\tFORMAT(SUM(" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".quantity*" . OPEN_CSA_WP_TABLE_PRODUCTS . ".current_price_in_euro),2) as costPerProduct\n\t\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " LEFT JOIN " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " ON " . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id\n\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d\n\t\t\t\t\t\t\t\t\t\t\tAND " . OPEN_CSA_WP_TABLE_PRODUCTS . ".producer = %d\n\t\t\t\t\t\t\t\t\t\tGROUP BY " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id \n\t\t\t\t\t\t\t\t\t", $delivery_id, $producer)); //display product details foreach ($products_in_order as $product) { $orders_of_product = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".user_id, \n\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".name,\n\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".variety,\n\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".quantity\n\t\t\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " LEFT JOIN " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " ON " . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id\n\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d AND\n\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = %d\n\t\t\t\t\t\t\t\t\t\t", $delivery_id, $product->id)); $total = $product->total; if (strpos($total, '.') !== FALSE) { $total = number_format((double) $product->total, 1, '.', ''); } ?> <div class='container' style='min-width:100%;width:<?php echo $table_width; ?> px;font-size:14px'> <!--keeps the quantity and total value divs together--> <div class='container' style='float:left; width:<?php echo $main_width; ?> px;'> <!--product details--> <div class='left' style='width:<?php echo $product_details_width; ?> px; background-color:Khaki; display:block; '> <div style='display:table-cell; vertical-align:middle; height:70px; padding-left:10px '> <?php echo $product->name . " " . $product->variety . "<br/> <span class='info-text'>(" . $product->current_price_in_euro . " € / " . $product->measurement_unit . ")</span>"; ?> </div> </div> <div class='left' style='width:<?php echo $amount_perProduct_width; ?> px;height:70px;line-height:70px;padding-left:10px;font-weight:bold;font-size:16px;background-color:Khaki'> <span style='display:inline-block; vertical-align:middle;'><?php echo $total; ?> </span> </div> <!--order details--> <div class="div_tr"> <?php foreach ($orders_of_product as $product_order) { echo "<div class='left' style='font-weight:bold;'>" . mb_substr(get_user_by('id', $product_order->user_id)->user_login, 0, 7, 'UTF-8') . "</div>"; } ?> </div> <!--<div style="height:37px;"></div>--> <div class="div_tr"> <?php foreach ($orders_of_product as $preOrder) { echo "<div class='left' >" . $product_order->quantity . "</div>"; } ?> </div> </div> <!-- price details--> <div class='left' style='display:table; height:70px;'> <div style='display:table-cell; vertical-align:bottom;'> <?php echo "<span class='info-text'>" . $product->costPerProduct . "€</span>"; ?> </div> </div> </div> <?php $revenue += $product->costPerProduct; } echo "<br/><p class='total' style='margin: -2% 0 3% 0'><span class='emphasis-box'>" . __('Total', OPEN_CSA_WP_DOMAIN) . ": " . $revenue . " € </span></p><br/>"; } ?> <table style="margin-top:30px" class='table-straight'> <!-- stucture table (to display the following table next to each other --> <tr><td> <span style="font-weight:bold;color:green"><?php _e('Cost per consumer', OPEN_CSA_WP_DOMAIN); ?> </span><?php //Show costs in total $total_user_costs = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".user_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\tFORMAT(SUM(" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".quantity*" . OPEN_CSA_WP_TABLE_PRODUCTS . ".current_price_in_euro),2) AS cost\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " LEFT JOIN " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " ON " . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d\n\t\t\t\t\t\t\t\t\t\t\t\tGROUP BY " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".user_id\n\t\t\t\t\t\t\t\t\t\t\t", $delivery_id)); $total_cost = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\t\tSELECT FORMAT(SUM(" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".quantity*" . OPEN_CSA_WP_TABLE_PRODUCTS . ".current_price_in_euro),2)\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " LEFT JOIN " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " ON " . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d\n\t\t\t\t\t\t\t\t\t\t\t", $delivery_id)); ?> <table style='width:280px;' class='table-bordered'> <thead> <tr> <td><?php _e('Consumer', OPEN_CSA_WP_DOMAIN); ?> </td> <td><?php _e('Total Cost', OPEN_CSA_WP_DOMAIN); ?> </td> </tr> </thead> <?php foreach ($total_user_costs as $tCost) { ?> <tr> <td style='width:200px;font-weight:bold'><?php echo open_csa_wp_user_readable(get_user_by('id', $tCost->user_id)); ?> </td> <td><?php echo round($tCost->cost, 1) . " €"; ?> </td> </tr> <?php } ?> <tr style='background-color:Khaki'> <td style="font-weight:bold"><?php _e('Total', OPEN_CSA_WP_DOMAIN); ?> </td> <td style="font-weight:bold"><?php echo round($total_cost, 1) . " €"; ?> </td> </tr> </tr> </table> </td> <td> <div style='width:80px'> </div> </td> <td> <?php //Show costs per producer ?> <span style="font-weight:bold;color:green;margin-left:5%">Cost per producer</span><?php $producer_costs = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCTS . ".producer,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFORMAT(SUM(" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".quantity*" . OPEN_CSA_WP_TABLE_PRODUCTS . ".current_price_in_euro),2) AS cost\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(" . OPEN_CSA_WP_TABLE_PRODUCTS . " LEFT JOIN " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " ON " . OPEN_CSA_WP_TABLE_PRODUCTS . ".id = " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".product_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . ".delivery_id = %d\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tGROUP BY " . OPEN_CSA_WP_TABLE_PRODUCTS . ".producer\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t", $delivery_id)); ?> <table style='width:200px;' class='table-bordered'> <thead> <tr> <td><?php _e('Procuder', OPEN_CSA_WP_DOMAIN); ?> </td> <td style='width:100px'><?php _e('Income', OPEN_CSA_WP_DOMAIN); ?> </td> </tr> </thead> <?php foreach ($producer_costs as $p_cost) { echo "\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td style='width:200px;font-weight:bold'>" . $producers_map[$p_cost->producer] . "</td>\n\t\t\t\t\t\t\t\t<td>" . round($p_cost->cost, 1) . " €</td>\n\t\t\t\t\t\t\t</tr>"; } ?> <tr style='background-color:Khaki'> <td style="font-weight:bold"><?php _e('Total', OPEN_CSA_WP_DOMAIN); ?> </td> <td style="font-weight:bold"><?php echo round($total_cost, 1) . " €"; ?> </td> </tr> </table> </td> </tr> </table> <br> <table class='table-bordered'> <?php $user_orders_comments = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\tSELECT user_id, comments \n\t\t\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_USER_ORDERS . " \n\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\tdelivery_id = %d AND\n\t\t\t\t\t\t\t\t\t\t\t\tcomments IS NOT NULL\n\t\t\t\t\t\t\t\t\t\t", $delivery_id)); if (count($user_orders_comments) > 0) { echo "<span style='font-weight:bold;color:green'>Comments:</span>"; foreach ($user_orders_comments as $user_order_comments) { echo "<tr><td style='font-weight:bold;width:200px'>" . open_csa_wp_user_readable_without_login(get_user_by('id', $user_order_comments->user_id)) . "</td><td>" . $user_order_comments->comments . "</td></tr>"; } } ?> </table> <?php } ?> <input type="button" class="button button-secondary" value='<?php _e('back to orders...', OPEN_CSA_WP_DOMAIN); ?> ' onclick='window.location.replace(" <?php echo $page_url; ?> ");' /> <?php }