<li> <a href="members_list_withemail.php">Members who have email</a></li>
          <li class="last_of_group"> <a href="members_list_noemail.php">Members without email</a></li>
        </ul>
      </td>
      <td align="left" width="50%">
        <img src="' . DIR_GRAPHICS . 'bottom.png" width="32" height="32" align="left" hspace="2" alt="Membership Information"><br>
        <b>Membership Information</b>
        <ul class="fancyList1">
          <li><a href="member_lookup.php?action=find">Find/Edit Members</a></li>
          <li><a href="edit_member_types.php">Mass Edit Membership Types</a></li>
          <li><a href="edit_auth_types.php">Mass Edit Auth Types</a></li>
        </ul>
        <img src="' . DIR_GRAPHICS . 'kcron.png" width="32" height="32" align="left" hspace="2" alt="Delivery Cycle Functions"><br>
        <b>Delivery Cycle Functions</b>
        <ul class="fancyList1">
          <li class="last_of_group"><a href="orders_list_withtotals.php?delivery_id=' . ActiveCycle::delivery_id() . '">Members with orders this cycle (with totals)</a></li>
          <li><a href="members_list_emailorders.php?delivery_id=' . ActiveCycle::delivery_id() . '">Customer Email Addresses this cycle</a></li>
        </ul>
      </td>
    </tr>
  </table>';
$page_title_html = '<span class="title">' . $_SESSION['show_name'] . '</span>';
$page_subtitle_html = '<span class="subtitle">Member Admin Panel</span>';
$page_title = 'Member Admin Panel';
$page_tab = 'member_admin_panel';
include "template_header.php";
echo '
  <!-- CONTENT BEGINS HERE -->
  ' . $display_admin . '
  <!-- CONTENT ENDS HERE -->';
include "template_footer.php";
Example #2
0
      </td>
    </tr>
  </table>
  </div>';
$page_title_html = '<span class="title">' . $business_name . '</span>';
$page_subtitle_html = '<span class="subtitle">Edit Product' . ($product_id ? ' #' . $product_id : '') . '' . ($product_version ? '-' . $product_version : '') . '</span>';
$page_title = $business_name . ': Edit Product';
$page_tab = 'producer_panel';
$page_specific_javascript = '
  <script type="text/javascript" src="javascript_popup.js"></script>
  <script type="text/javascript">
  function updatePrices()
    {
    document.getElementById("unit_price_prdcr").value=(document.getElementById("unit_price_coop").value*' . (1 - ActiveCycle::producer_markdown_next()) . ').toFixed(2);
    document.getElementById("unit_price_cust").value=(document.getElementById("unit_price_coop").value*' . (1 + (SHOW_ACTUAL_PRICE ? ActiveCycle::retail_markup_next() : 0)) . '*(1+(document.getElementById("product_fee_percent").value/100)+' . ($subcat_adjust_fee + $producer_adjust_fee) . ')).toFixed(2);
    document.getElementById("unit_price_institution").value=(document.getElementById("unit_price_coop").value*' . (1 + (SHOW_ACTUAL_PRICE ? ActiveCycle::wholesale_markup_next() : 0)) . '*(1+(document.getElementById("product_fee_percent").value/100)+' . ($subcat_adjust_fee + $producer_adjust_fee) . ')).toFixed(2);
    }
  </script>';
$page_specific_css = '
<style type="text/css">
.normal_row {
  background-color:#ddd;
  }
.random_wt_row {
  background-color:#bbd;
  }
.control_row {
  background-color:#ddd;
  }
.admin_row {
  background-color:#fdb;
function get_delivery_codes_list($request_data)
{
    global $connection;
    // See if it is okay to open a basket...
    if (ActiveCycle::delivery_id() && (ActiveCycle::ordering_window() == 'open' || CurrentMember::auth_type('orderex'))) {
        // If requested to open-basket...
        if ($request_data['action'] == 'open_basket') {
            if ($request_data['site_id'] && $request_data['delivery_type']) {
                $site_id = $request_data['site_id'];
                $delivery_type = $request_data['delivery_type'];
                // First try an assigned delivery_id... then use the current active one
                $delivery_id = $request_data['delivery_id'];
                if (!$delivery_id) {
                    $delivery_id = ActiveCycle::delivery_id();
                }
                // First try an assigned member_id... then use the current session one
                $member_id = $request_data['member_id'];
                if (!$member_id) {
                    $member_id = $_SESSION['member_id'];
                }
                // Update the basket
                $basket_info = open_update_basket(array('member_id' => $member_id, 'delivery_id' => $delivery_id, 'site_id' => $site_id, 'delivery_type' => $delivery_type));
            }
        } else {
            $basket_info = get_basket($request_data['member_id'], $request_data['delivery_id']);
        }
        //         // Ordering is open and there is no basket open yet
        //         // Get this member's most recent delivery location
        //         $query = '
        //           SELECT
        //             '.NEW_TABLE_SITES.'.site_id,
        //             '.NEW_TABLE_SITES.'.deltype
        //           FROM
        //             '.NEW_TABLE_BASKETS.'
        //           LEFT JOIN
        //             '.NEW_TABLE_SITES.' USING(site_id)
        //           WHERE
        //             '.NEW_TABLE_BASKETS.'.member_id = "'.mysql_real_escape_string($_SESSION['member_id']).'"
        //             AND '.NEW_TABLE_SITES.'.inactive = "0"
        //           ORDER BY
        //             delivery_id DESC
        //           LIMIT
        //             1';
        //           $result = mysql_query ($query, $connection) or die(debug_print ("ERROR: 548167 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
        //           if ($row = mysql_fetch_array ($result))
        //             {
        //               $site_id_prior = $row['site_id'];
        //               $deltype_prior = $row['deltype'];
        //             }
        // Constrain this shopper's baskets to the site_type they are enabled to use
        $site_type_constraint = '';
        if (CurrentMember::auth_type('member')) {
            $site_type_constraint .= '
              ' . (strlen($site_type_constraint) > 0 ? 'OR ' : '') . 'site_type LIKE "%customer%"';
        }
        if (CurrentMember::auth_type('institution')) {
            $site_type_constraint .= '
              ' . (strlen($site_type_constraint) > 0 ? 'OR ' : '') . 'site_type LIKE "%institution%"';
        }
        $site_type_constraint = '
            AND (' . $site_type_constraint . '
              )';
        // Now get the list of all available delivery codes and flag the one
        // that corresponds to this member's prior order
        $query = '
          SELECT
            ' . NEW_TABLE_SITES . '.site_id,
            ' . NEW_TABLE_SITES . '.site_short,
            ' . NEW_TABLE_SITES . '.site_long,
            ' . NEW_TABLE_SITES . '.delivery_type,
            ' . NEW_TABLE_SITES . '.site_description,
            ' . NEW_TABLE_SITES . '.delivery_charge,
            ' . NEW_TABLE_SITES . '.inactive,
            ' . TABLE_MEMBER . '.address_line1,
            ' . TABLE_MEMBER . '.work_address_line1
          FROM
            (' . NEW_TABLE_SITES . ',
            ' . TABLE_MEMBER . ')
          WHERE
            ' . NEW_TABLE_SITES . '.inactive != "1"
            AND ' . TABLE_MEMBER . '.member_id = "' . mysql_real_escape_string($_SESSION['member_id']) . '"' . $site_type_constraint . '
          ORDER BY
            site_long';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 671934 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        $site_id_array = array();
        $delivery_type_array = array();
        $display .= '
            <div id="delivery_dropdown" class="dropdown">
              <a href="' . $_SERVER['SCRIPT_NAME'] . '?action=delivery_list_only"><h1 class="delivery_select">' . ($basket_info['site_id'] ? 'Selected: ' . $basket_info['site_long'] : 'Select Location') . '
              </h1></a>
              <div id="delivery_select">
                <ul class="delivery_select">';
        while ($row = mysql_fetch_array($result)) {
            // Simplify variables
            $site_id = $row['site_id'];
            $site_long = $row['site_long'];
            $delivery_type = $row['delivery_type'];
            $site_description = $row['site_description'];
            $delivery_charge = $row['delivery_charge'];
            $inactive = $row['inactive'];
            $address = $row['address_line1'];
            $work_address = $row['work_address_line1'];
            // Set up some text for the $delivery type (delivery or pickup)
            if ($delivery_type == 'P') {
                $delivery_type_text = 'Pick up your order here';
                $delivery_type_class = 'delivery_type-p';
            } elseif ($delivery_type == 'D') {
                $delivery_type_text_h = 'HOME delivery';
                $delivery_type_text_w = 'WORK delivery';
                if ($delivery_charge) {
                    $delivery_type_text_h .= ' ($' . number_format($delivery_charge, 2) . ' charge)';
                    $delivery_type_text_w .= ' ($' . number_format($delivery_charge, 2) . ' charge)';
                }
                $delivery_type_class = 'delivery_type-d';
            } else {
                $delivery_type_text = '';
                $delivery_type_class = '';
            }
            // Process the inactive options
            if ($inactive == 0) {
                $show_site = true;
                $active_class = ' active';
                $select_link_href = $_SERVER['SCRIPT_NAME'] . '?action=open_basket&amp;site_id=' . $site_id . '&amp;delivery_type=P';
                $select_link_h_href = $_SERVER['SCRIPT_NAME'] . '?action=open_basket&amp;site_id=' . $site_id . '&amp;delivery_type=H';
                $select_link_w_href = $_SERVER['SCRIPT_NAME'] . '?action=open_basket&amp;site_id=' . $site_id . '&amp;delivery_type=W';
                $delivery_type_class .= 'a';
                // color
            } elseif ($inactive == 2) {
                $show_site = true;
                $active_class = ' inactive';
                $select_link_href = '';
                $select_link_h_href = '';
                $select_link_w_href = '';
                $delivery_type_class .= 'i';
                // color
                $delivery_type_text = '(Not available for pick up this cycle)';
                // clobber the delivery type text
                $delivery_type_text_h = '(Not available for home delivery this cycle)';
                // clobber the delivery type text
                $delivery_type_text_w = '(Not available for work delivery this cycle)';
                // clobber the delivery type text
            } else {
                $show_site = false;
                $active_class = ' suspended';
                $select_link_href = '';
                $select_link_h_href = '';
                $select_link_w_href = '';
                $delivery_type_class .= 'i';
                // color
                $delivery_type_text = '(Not available for pick up this cycle)';
                // clobber the delivery type text
                $delivery_type_text_h = '(Not available for home delivery this cycle)';
                // clobber the delivery type text
                $delivery_type_text_w = '(Not available for work delivery this cycle)';
                // clobber the delivery type text
            }
            // Process current selection
            if ($site_id == CurrentBasket::site_id()) {
                $selected = true;
                $select_class = ' select';
                $delivery_type_class .= 'c';
                // color
            } else {
                $selected = 'false';
                $select_class = '';
                $delivery_type_class .= 'g';
                // greyscale
            }
            if ($show_site == true) {
                if ($delivery_type == 'P') {
                    $display .= '
                  <li class="' . $delivery_type_class . $active_class . $select_class . '" ' . ($select_link_href != '' ? 'onclick="javascript:location.href=\'' . $select_link_href : '') . '\';parent.close_delivery_selector();">
                      <span class="site_long">' . $site_long . '</span>
                      <span class="site_action">' . $delivery_type_text . '</span>
                      <span class="site_description">' . br2nl($site_description) . '</span>
                  </li>';
                }
                // For delivery_type = delivery, we will give an option for "home"
                if ($delivery_type == 'D' && $address) {
                    if ($basket_info['delivery_type'] != 'H') {
                        $select_class = '';
                    }
                    $display .= '
                  <li class="' . $delivery_type_class . $active_class . $select_class . '" ' . ($select_link_h_href != '' ? 'onclick="javascript:location.href=\'' . $select_link_h_href : '') . '\';parent.close_delivery_selector();">
                      <span class="site_long">' . $site_long . '</span>
                      <span class="site_action">' . $delivery_type_text_h . '</span>
                      <span class="site_description"><strong>To home address:</strong> ' . $address . '<br>' . br2nl($site_description) . '</span>
                  </li>';
                }
                // For delivery_type = delivery, we will also give an option for "work"
                if ($delivery_type == 'D' && $work_address) {
                    if ($basket_info['delivery_type'] != 'W') {
                        $select_class = '';
                    }
                    $display .= '
                  <li class="' . $delivery_type_class . $active_class . $select_class . '" ' . ($select_link_w_href != '' ? 'onclick="javascript:location.href=\'' . $select_link_w_href : '') . '\';parent.close_delivery_selector();">
                      <span class="site_long">' . $site_long . '</span>
                      <span class="site_action">' . $delivery_type_text_w . '</span>
                      <span class="site_description"><strong>To work address:</strong> ' . $work_address . '<br>' . br2nl($site_description) . '</span>
                  </li>';
                }
            }
        }
        $display .= '
                </ul>
              </div>
            </div>';
    }
    return $display;
}
            <td style="padding:0 1em;" rowspan="3"><b>per ' . $alert5a . '<input name="pricing_unit" size="12" maxlength="12" value="' . $product_info['pricing_unit'] . '"></b><br>
            <font size="-2">(Use singular, not plural; e.g. pound instead of pounds, loaf instead of loaves, ox instead of oxen, etc.)</font></td>
          </tr>
          <tr>
            <td style="padding:0 1em;" align="right">' . $alert5 . '<b>Coop&nbsp;Price:</td>
            <td><nobr>$</b> <input type="text" id="unit_price_coop" name="unit_price" value="' . number_format($show_unit_price, 3) . '" size=8 maxlength="8" onKeyUp="updatePrices()" onChange="document.getElementById("unit_price_coop").value=(document.getElementById("unit_price_coop").value*1).toFixed(2)"></nobr></td>
          </tr>
          <tr>
            <td style="padding:0 1em;" align="right">' . $alert5 . '<b>Retail&nbsp;Price:</b></td>
            <td><nobr>$</b> <input class="disabled" type="text" id="unit_price_cust" name="unit_price" value="' . number_format($show_unit_price * (1 + (SHOW_ACTUAL_PRICE ? ActiveCycle::retail_markup_next() : 0)) * (1 + $product_info['product_fee_percent'] / 100 + $product_info['subcategory_fee_percent'] / 100 + $product_info['producer_fee_percent'] / 100), 2) . '" size="8" maxlength="8" disabled></nobr></td>
          </tr>';
if (INSTITUTION_WINDOW > 0) {
    $display .= '
          <tr>
            <td style="padding:0 1em;" align="right">' . $alert5 . '<b>Wholesale&nbsp;Price:</b></td>
            <td><nobr>$</b> <input type="text" id="unit_price_institution" name="unit_price" value="' . number_format($show_unit_price * (1 + (SHOW_ACTUAL_PRICE ? ActiveCycle::wholesale_markup_next() : 0)) * (1 + $product_info['product_fee_percent'] / 100 + $product_info['subcategory_fee_percent'] / 100 + $product_info['producer_fee_percent'] / 100), 2) . '" size="8" maxlength="8" disabled></nobr></td>
          </tr>';
}
$display .= '
        </table>
      </td>
    </tr>
    <tr' . $norm_bg . '>
      <td>' . format_help_link('ordering_unit') . 'Ordering&nbsp;Unit</a></td>
      <td>
        Order by number of
        <input name="ordering_unit" size="20" maxlength="20" value="' . htmlspecialchars($product_info['ordering_unit'], ENT_QUOTES) . '">(s)<br>
        <font size=-2>(Use singular, not plural; e.g. package, steak, bag, jar, pound, ounce, item, dozen, etc.)</font>
      </td>
    </tr>
    <tr' . $norm_bg . '>
Example #5
0
$sqlmsg = '
  SELECT msg_all,
    delivery_id,
    msg_bottom
  FROM
    ' . TABLE_ORDER_CYCLES . '
  WHERE
    delivery_id = ' . ActiveCycle::delivery_id();
$resultmsg = @mysql_query($sqlmsg, $connection) or die('<br><br>You found a bug. If there is an error listed below, please copy and paste the error into an email to <a href="mailto:' . WEBMASTER_EMAIL . '">' . WEBMASTER_EMAIL . '</a><br><br><b>Error:</b> Selecting message ' . mysql_error() . '<br><b>Error No: </b>' . mysql_errno());
while ($row = mysql_fetch_array($resultmsg)) {
    $msg_all = $row['msg_all'];
    $msg_bottom = $row['msg_bottom'];
}
$content .= $font . '
  <h3>Editing Text on the Invoices</h3>
  <p>This will change the message for the current invoice (' . date(DATE_FORMAT_CLOSED, strtotime(ActiveCycle::delivery_date())) . ') and all future invoices until changed.</p>
  <table width="685" cellpadding="7" cellspacing="2" border="0">
    <tr bgcolor="#AE58DA">
      <td align="left"><b>Message to all Members ' . $message . '</b></td>
    </tr>
    <tr>
      <td align="left" bgcolor="#EEEEEE">
        <form action="' . $_SERVER['SCRIPT_NAME'] . '" method="POST">
          <b>Appears at the top of all Customer Invoices</b><br>
          <textarea name="msg_all" cols="75" rows="7">' . htmlspecialchars($msg_all, ENT_QUOTES) . '</textarea><br><br>
          <b>Appears at the bottom of all Customer Invoices</b><br>
          <textarea name="msg_bottom" cols="75" rows="7">' . htmlspecialchars($msg_bottom, ENT_QUOTES) . '</textarea><br>
          <input type="hidden" name="update" value="yes">
          <div align="center"><input type="submit" name="submit" value="Submit"></div>
        </form>
      </td>
Example #6
0
<?php

include_once 'config_openfood.php';
session_start();
// Items dependent upon the location of this header
$pager = array();
// Set up some variables that might be needed
if (isset($_SESSION['member_id'])) {
    $member_id = $_SESSION['member_id'];
}
if (isset($_SESSION['producer_id_you'])) {
    $producer_id_you = $_SESSION['producer_id_you'];
}
$delivery_id = mysql_real_escape_string(ActiveCycle::delivery_id());
// Allow cashier to override member_id
if (isset($_GET['member_id']) && CurrentMember::auth_type('cashier')) {
    $member_id = $_GET['member_id'];
}
// Allow producer_admin or cashier to override producer_id_you
if (isset($_GET['producer_id']) && CurrentMember::auth_type('cashier,producer_admin')) {
    $producer_id_you = $_GET['producer_id'];
}
// Allow anyone to override the delivery_id
if ($_GET['delivery_id']) {
    $delivery_id = mysql_real_escape_string($_GET['delivery_id']);
}
// Initialize display of wholesale and retail to false
$wholesale_member = false;
$retail_member = false;
//////////////////////////////////////////////////////////////////////////////////////
//                                                                                  //
function order_cycle_navigation($data)
{
    // Set up the previous/next order cycle (delivery_id) navigation
    $http_get_query = ($_GET['type'] ? '&type=' . $_GET['type'] : '') . ($_GET['producer_id'] ? '&producer_id=' . $_GET['producer_id'] : '') . ($_GET['category_id'] ? '&category_id=' . $_GET['category_id'] : '') . ($_GET['subcat_id'] ? '&subcat_id=' . $_GET['subcat_id'] : '') . ($_GET['query'] ? '&query=' . $_GET['query'] : '') . ($_GET['a'] ? '&a=' . $_GET['a'] : '');
    return '<div id="delivery_id_nav">
    <a class="prior" href="' . $_SERVER['SCRIPT_NAME'] . '?delivery_id=' . ($_GET['delivery_id'] ? $_GET['delivery_id'] - 1 : ActiveCycle::delivery_id() - 1) . $http_get_query . '">&larr; PRIOR ORDER </a>
    <span class="delivery_id">' . date(DATE_FORMAT_CLOSED, strtotime(ActiveCycle::delivery_date($_GET['delivery_id']))) . '</span>
    <a class="next" href="' . $_SERVER['SCRIPT_NAME'] . '?delivery_id=' . ($_GET['delivery_id'] ? $_GET['delivery_id'] + 1 : ActiveCycle::delivery_id() + 1) . $http_get_query . '"> NEXT ORDER &rarr;</a>
  </div>';
}
Example #8
0
             break;
         case 'MAX':
             $row['cost_multiplier'] = $row['maximum_weight'] * $row['unit_price'] * ($row['basket_quantity'] - $row['out_of_stock']);
             break;
     }
     $row['weight_needed'] = true;
 } elseif ($row['random_weight'] == 1) {
     $row['cost_multiplier'] = $row['total_weight'] * $row['unit_price'];
 } else {
     $row['cost_multiplier'] = ($row['basket_quantity'] - $row['out_of_stock']) * $row['unit_price'];
 }
 $row['producer_adjusted_cost'] = round($row['cost_multiplier'], 2) - round($row['producer_customer_adjust_fee'] * $row['cost_multiplier'], 2) - round($row['producer_subcat_adjust_fee'] * $row['cost_multiplier'], 2) - round($row['producer_producer_adjust_fee'] * $row['cost_multiplier'], 2);
 $row['customer_adjusted_cost'] = round($row['cost_multiplier'], 2) + round($row['customer_customer_adjust_fee'] * $row['cost_multiplier'], 2) + round($row['customer_product_adjust_fee'] * $row['cost_multiplier'], 2) + round($row['customer_subcat_adjust_fee'] * $row['cost_multiplier'], 2) + round($row['customer_producer_adjust_fee'] * $row['cost_multiplier'], 2);
 // Following values are for generalalized -- not-logged-in calculations
 $row['retail_unit_cost'] = round($row['unit_price'], 2) + (PAYS_CUSTOMER_FEE == 'customer' ? round(ActiveCycle::retail_markup_next() * $row['unit_price'], 2) : 0) + round($row['customer_product_adjust_fee'] * $row['unit_price'], 2) + round($row['customer_subcat_adjust_fee'] * $row['unit_price'], 2) + round($row['customer_producer_adjust_fee'] * $row['unit_price'], 2);
 $row['wholesale_unit_cost'] = round($row['unit_price'], 2) + (PAYS_CUSTOMER_FEE == 'customer' ? round(ActiveCycle::wholesale_markup_next() * $row['unit_price'], 2) : 0) + round($row['customer_product_adjust_fee'] * $row['unit_price'], 2) + round($row['customer_subcat_adjust_fee'] * $row['unit_price'], 2) + round($row['customer_producer_adjust_fee'] * $row['unit_price'], 2);
 // These are per-item values baseed on the SHOW_ACTUAL_PRICE setting
 if (SHOW_ACTUAL_PRICE) {
     $row['display_unit_wholesale_price'] = $row['wholesale_unit_cost'];
 } else {
     $row['display_unit_wholesale_price'] = $row['unit_price'];
 }
 if (SHOW_ACTUAL_PRICE) {
     $row['display_unit_retail_price'] = $row['retail_unit_cost'];
 } else {
     $row['display_unit_retail_price'] = $row['unit_price'];
 }
 // These are line-item totals based on the SHOW_ACTUAL_PRICE setting
 if (SHOW_ACTUAL_PRICE) {
     $row['customer_display_cost'] = $row['customer_adjusted_cost'];
 } else {
    if ($row["category_name"] && $row["subcategory_name"] && $row["delivery_date"]) {
        if (isset($categories[$row["category_name"]][$row["subcategory_name"]][$row["delivery_date"]])) {
            $categories[$row["category_name"]][$row["subcategory_name"]][$row["delivery_date"]] += $row["real_price"];
        } else {
            $categories[$row["category_name"]][$row["subcategory_name"]][$row["delivery_date"]] = $row["real_price"];
        }
    }
}
$query = '
  SELECT
    delivery_date
  FROM
    ' . TABLE_ORDER_CYCLES . '
  WHERE
    delivery_id <= "' . mysql_real_escape_string(ActiveCycle::delivery_id()) . '"
    AND delivery_id > "' . mysql_real_escape_string(ActiveCycle::delivery_id() - $num_cycles) . '"
  ORDER BY
    delivery_date DESC';
$dates_sql = mysql_query($query);
$delivery_dates = array();
$spreadsheet = "Subcategory / Date";
$date_headers = "";
while ($row = mysql_fetch_array($dates_sql)) {
    array_push($delivery_dates, $row["delivery_date"]);
    $date_headers .= '
      <th class="date">' . $row["delivery_date"] . '</th>';
    $spreadsheet .= "\t" . $row["delivery_date"];
}
$table = "";
$spreadsheet .= "\n";
ksort($categories);
    if ($this_slice) {
        $this_slice .= '&';
    }
    $this_slice .= 'slice_producer=' . $_GET['slice_producer'];
}
// Get the retail and wholesale markup amounts
$query = '
  SELECT
    delivery_date,
    producer_markdown,
    wholesale_markup,
    retail_markup
  FROM
    ' . TABLE_ORDER_CYCLES . '
  WHERE
    delivery_id = "' . mysql_real_escape_string(ActiveCycle::delivery_id_next()) . '"';
$result = @mysql_query($query, $connection) or die(mysql_error());
if ($row = mysql_fetch_array($result)) {
    $delivery_date = date("F j, Y", strtotime($row['delivery_date']));
    $producer_markdown = $row['producer_markdown'] / 100;
    $retail_markup = $row['retail_markup'] / 100;
    $wholesale_markup = $row['wholesale_markup'] / 100;
}
// Get the products meeting the requested criteria
$query = '
  SELECT
    ' . NEW_TABLE_PRODUCTS . '.*,
    ' . NEW_TABLE_PRODUCTS . '.product_fee_percent / 100 AS product_fee_percent,
    ' . TABLE_PRODUCER . '.business_name,
    ' . TABLE_PRODUCER . '.producer_fee_percent / 100 AS producer_fee_percent,
    ' . TABLE_SUBCATEGORY . '.subcategory_name,
function update_basket_item(array $data)
{
    //    debug_print ('INFO: Update Basket', $data);
    global $connection;
    //    $member_id_you = $_SESSION['member_id'];
    $producer_id_you = $_SESSION['producer_id_you'];
    // Allow admins to override certain checks if the requested action is not for themselves
    $admin_override_not_set = false;
    if ($member_id_you == $data['member_id'] || !CurrentMember::auth_type('cashier')) {
        $admin_override_not_set = true;
    }
    // Set flags for needed validations and operations
    switch ($data['action']) {
        case 'set_quantity':
            $test_for_valid_product = true;
            $test_for_customer_privilege = true;
            $test_for_membership_privilege = true;
            $test_customer_ordering_window = true;
            $test_product_availability = true;
            $test_for_producer_privilege = true;
            $initiate_basket_item = true;
            $initiate_change_quantity = true;
            $initiate_set_message_to_producer = true;
            break;
        case 'set_message_to_producer':
            $test_for_valid_product = true;
            $test_customer_ordering_window = true;
            $initiate_set_message_to_producer = true;
            break;
        case 'set_outs':
            $test_for_valid_product = true;
            $test_for_producer_privilege = true;
            $test_basket_item_exists = true;
            $test_producer_update_window = true;
            $initiate_change_outs = true;
            break;
        case 'set_weight':
            $test_for_valid_product = true;
            $test_for_producer_privilege = true;
            $test_basket_item_exists = true;
            $test_producer_update_window = true;
            $initiate_change_weight = true;
            break;
        case 'checkout':
            $test_for_valid_product = true;
            $test_for_membership_privilege = true;
            $test_customer_ordering_window = true;
            $test_basket_item_exists = true;
            $initiate_set_message_to_producer = true;
            $initiate_synch_ledger = true;
            break;
        case 'set_all_producer':
            $test_for_valid_product = true;
            $test_basket_item_exists = true;
            $test_for_producer_privilege = true;
            $test_producer_update_window = true;
            $initiate_change_outs = true;
            $initiate_change_weight = true;
            break;
        case 'set_everything':
            $test_for_valid_product = true;
            $test_basket_item_exists = true;
            $test_customer_ordering_window = true;
            $initiate_change_quantity = true;
            $initiate_change_outs = true;
            $initiate_clear_weight = true;
            $initiate_clear_item = true;
            $initiate_set_message_to_producer = true;
            break;
        case 'clear_item':
            // Used when un_checking_out
            $test_for_valid_product = true;
            $test_basket_item_exists = true;
            $test_customer_ordering_window = true;
            $data['quantity'] = '0';
            $data['out_of_stock'] = '0';
            $data['weight'] = '0';
            $initiate_change_quantity = true;
            $initiate_change_outs = true;
            $initiate_clear_weight = true;
            $initiate_clear_item = true;
            break;
        case 'synch_ledger':
            // Used when checking_out
            $test_for_valid_product = true;
            $test_basket_item_exists = true;
            $test_for_membership_privilege = true;
            $test_customer_ordering_window = true;
            $test_basket_item_exists = true;
            $initiate_synch_ledger = true;
            break;
        case 'producer_synch_ledger':
            // Used when checking_out
            $test_for_valid_product = true;
            $test_basket_item_exists = true;
            $test_for_producer_privilege = true;
            $test_producer_update_window = true;
            $initiate_synch_ledger = true;
            break;
        default:
            return 'Unexpected request ' . $action;
            break;
    }
    // Check if the product exists, regardless of $admin_override_not_set
    if ($test_for_valid_product) {
        $product_info = get_product($data['product_id'], $data['product_version'], $data['pvid']);
        if (!is_array($product_info)) {
            return 'Product not found in database';
        }
    }
    // Get  information about the basket for this member
    // This needs to be done before the availability check
    $basket_info = get_basket($data['member_id'], $data['delivery_id']);
    // See if we already have this basket_item
    if (is_array($basket_info)) {
        $basket_item_info = get_basket_item($basket_info['basket_id'], $data['product_id']);
    } else {
        return 'Basket does not exist';
    }
    // Check for basket item
    if ($test_basket_item_exists && !is_array($basket_item_info)) {
        return 'Basket item does not exist';
    }
    // Check if the basket is locked
    if ($basket_info['locked'] == 1) {
        return 'Basket is locked';
    }
    // Check if this producer is permitted and enabled to sell
    if ($test_for_producer_privilege && $admin_override_not_set) {
        $producer_info = get_producer($product_info['producer_id']);
        if ($producer_info['unlisted_producer'] > 0 || $producer_info['pending'] == 1) {
            return 'Producer is restricted from selling';
        }
    }
    // Check if the customer is allowed to purchase this product
    if ($test_for_customer_privilege && $admin_override_not_set) {
        $member_info = get_member($data['member_id']);
        $member_auth_type_array = explode(',', $member_info['auth_type']);
        // $product_info['listing_auth_type'] contains the *necessary* auth_type to buy this product
        // and $member_auth_type_array contains all the members' allowable auth_types
        // listing_auth_types archived and unlisted are not allowed for members, so can never be ordered
        if (!is_array($member_auth_type_array) || !in_array($product_info['listing_auth_type'], $member_auth_type_array)) {
            return 'Incorrect privilege to purchase requested product';
        }
    }
    // Check that the member is not pending or discontinued
    if ($test_for_membership_privilege && $admin_override_not_set) {
        if ($member_info['pending'] == 1 || $member_info['membership_discontinued'] == 1) {
            return 'Incorrect privilege to order';
        }
    }
    // Check if shopping is closed for this order
    if ($test_customer_ordering_window && $admin_override_not_set) {
        if (ActiveCycle::ordering_window() == 'closed') {
            return 'Customer ordering period is not in effect';
        }
    }
    // Check if the product can be delivered to this site_id
    if ($test_product_availability && $admin_override_not_set) {
        if ($producer_info['available_site_ids'] != '' && !in_array($basket_info['site_id'], explode(',', $producer_info['available_site_ids']))) {
            return 'Producer does not sell at this location';
        }
    }
    // Check if producer activity is taking place within the producer update window
    if ($test_producer_update_window && $producer_id_you && $admin_override_not_set) {
        if (ActiveCycle::producer_update_window() == 'closed') {
            return 'Producer update window is closed';
        }
    }
    // Create an empty basket item if one does not already exist
    if ($initiate_basket_item && !is_array($basket_item_info)) {
        $query = '
          INSERT INTO ' . NEW_TABLE_BASKET_ITEMS . '
            (
              /* bpid, */
              basket_id,
              product_id,
              product_version,
              quantity,
              total_weight,
              product_fee_percent,
              subcategory_fee_percent,
              producer_fee_percent,
              taxable,
              out_of_stock,
              future_delivery,
              future_delivery_type,
              date_added
            )
          SELECT
            ' . mysql_real_escape_string($basket_info['basket_id']) . ' AS basket_id,
            product_id,
            product_version,
            "0" AS quantity,
            "0" AS total_weight,
            product_fee_percent,
            subcategory_fee_percent,
            producer_fee_percent,
            taxable,
            "0" AS out_of_stock,
            future_delivery,
            future_delivery_type,
            NOW() AS date_added
          FROM ' . NEW_TABLE_PRODUCTS . '
          LEFT JOIN ' . TABLE_SUBCATEGORY . ' USING(subcategory_id)
          LEFT JOIN ' . TABLE_CATEGORY . ' USING(category_id)
          LEFT JOIN ' . TABLE_PRODUCER . ' USING(producer_id)
          WHERE
            product_id = "' . mysql_real_escape_string($product_info['product_id']) . '"
            AND product_version = "' . mysql_real_escape_string($product_info['product_version']) . '"';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 748032 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        // Now get the basket information we just posted
        $basket_item_info = get_basket_item($basket_info['basket_id'], $data['product_id']);
    }
    // Update the quantity for this basket_item and adjust inventory accordingly
    if ($initiate_change_quantity) {
        $old_requested_quantity = $basket_item_info['quantity'];
        $old_out_of_stock = $basket_item_info['out_of_stock'];
        // The following code is built around adding/subtracting [quantity], so we will first adjust
        // the input to fit that method. If $data['quantity'] is like "+1" or "-2" then increment/decrement
        if (preg_match('/^([\\+\\-])(\\d+)$/', $data['quantity'], $matches)) {
            if ($matches[1] == '+') {
                $data['quantity'] = $matches[2];
            } elseif ($matches[1] == '-') {
                $data['quantity'] = 0 - $matches[2];
            } else {
                return 'Unexpected result 789830';
            }
        } elseif (preg_match('/^(\\d+)$/', $data['quantity'], $matches)) {
            $data['quantity'] = $matches[1] - $old_requested_quantity;
            // Amount to increase the basket by
        } else {
            return 'Unexpected result 785932';
        }
        // If this is an inventory-controlled item
        if ($product_info['inventory_id']) {
            $old_actual_quantity = $old_requested_quantity - $old_out_of_stock;
            // Note that available_inventory is the number of inventory_pull units available for this
            // particular product and might actually leave a few inventory items remaining.
            $available_inventory = floor($product_info['inventory_quantity'] / $product_info['inventory_pull']);
            $inventory_reduction = 0;
            // Just for sanity, make sure the old out_of_stock is not more than the old_requested_quantity
            if ($old_out_of_stock > $old_requested_quantity) {
                $old_out_of_stock = $old_requested_quantity;
            }
            // Add the request, no matter what (unless the quantity goes negative)
            $new_requested_quantity = $old_requested_quantity + $data['quantity'];
            // If we brought the requested quantity in the basket down to zero
            if ($new_requested_quantity <= 0) {
                // then set the new_requested_quantity to [all of it]
                $data['quantity'] = 0 - $old_requested_quantity;
                $new_requested_quantity = 0;
                // and set out_of_stock to zero (empty the basket completely)
                $new_out_of_stock = 0;
            } else {
                // We will begin by considering all of the new quantity as "out"
                $new_out_of_stock = $old_out_of_stock + $data['quantity'];
            }
            // At this point, the new_requested_quantity is correct, but we might
            // have set the new_out_of_stock incorrectly, so we will adjust that
            // according to the inventory available
            // Check if there is enough inventory to cover our entire out_of_stock request
            if ($available_inventory > $new_out_of_stock) {
                $inventory_reduction = $new_out_of_stock;
                $new_out_of_stock = 0;
            } else {
                $inventory_reduction = $available_inventory;
                // all of it
                $new_out_of_stock = $new_out_of_stock - $inventory_reduction;
            }
        } else {
            // If this somehow changed, then clear the out_of_stock setting
            $new_out_of_stock = 0;
            $inventory_reduction = 0;
            // Add the new requested quantity
            $new_requested_quantity = $old_requested_quantity + $data['quantity'];
            // And make sure it isn't less than zero
            if ($new_requested_quantity < 0) {
                $new_requested_quantity = 0;
            }
        }
        // Set these variables for use later
        $basket_item_info['quantity'] = $new_requested_quantity;
        $basket_item_info['out_of_stock'] = $new_out_of_stock;
        // Update the basket quantity and out_of_stock
        $query = '
          UPDATE ' . NEW_TABLE_BASKET_ITEMS . '
          SET
            quantity = "' . mysql_real_escape_string($new_requested_quantity) . '",
            out_of_stock = "' . mysql_real_escape_string($new_out_of_stock) . '"
          WHERE bpid = "' . mysql_real_escape_string($basket_item_info['bpid']) . '"';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 842075 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        // And update the inventory amount
        if ($inventory_reduction != 0) {
            // This does work with negative numbers for $new_requested_quantity
            $query = '
              UPDATE ' . TABLE_INVENTORY . '
              SET quantity = quantity + "' . mysql_real_escape_string($new_requested_quantity * $product_info['inventory_pull']) . '"
              WHERE inventory_id = "' . mysql_real_escape_string($product_info['inventory_id']) . '"';
            $result = mysql_query($query, $connection) or die(debug_print("ERROR: 902784 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        }
    } else {
        $new_requested_quantity = $basket_item_info['quantity'];
    }
    // Change the "out" setting on this item
    if ($initiate_change_outs) {
        // If $data['out_of_stock'] is like "+1" or "-2" then increment/decrement
        if (preg_match('/^([\\+\\-])(\\d+)$/', $data['out_of_stock'], $matches)) {
            // Increase out_of_stock :: decreases actual order quantity
            if ($matches[1] == '+') {
                $new_out_of_stock = $basket_item_info['out_of_stock'] + $matches[2];
            } elseif ($matches[1] == '-') {
                $new_out_of_stock = $basket_item_info['out_of_stock'] - $matches[2];
            } else {
                return 'Unexpected result 578932';
            }
        } elseif (preg_match('/^(\\d+)$/', $data['out_of_stock'], $matches)) {
            $new_out_of_stock = $matches[1];
        } else {
            return 'Unexpected result 874042';
        }
        // Make sure we have not outed more than the total quantity in the basket
        if ($new_out_of_stock > $basket_item_info['quantity']) {
            $new_out_of_stock = $basket_item_info['quantity'];
        }
        // Make sure we have not outed a negative number
        if ($new_out_of_stock < 0) {
            $new_out_of_stock = 0;
        }
        // Update the basket_item with the new quantities
        $query = '
          UPDATE ' . NEW_TABLE_BASKET_ITEMS . '
          SET out_of_stock = "' . mysql_real_escape_string($new_out_of_stock) . '"
          WHERE bpid = "' . mysql_real_escape_string($basket_item_info['bpid']) . '"';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 784303 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
    }
    // Set a basket_item message for this item
    if ($initiate_set_message_to_producer && $basket_item_info['bpid'] && is_array($data['messages'])) {
        foreach ($data['messages'] as $message_type => $message) {
            // If there is a message, then add the message or replace an existing one
            if (strlen($message) > 0) {
                // Use [0]:orphaned message in case the description is not found
                $query_post_message = '
                  REPLACE INTO ' . NEW_TABLE_MESSAGES . '
                  SET
                    message = "' . mysql_real_escape_string($message) . '",
                    message_type_id = 
                      COALESCE((
                        SELECT message_type_id
                        FROM ' . NEW_TABLE_MESSAGE_TYPES . '
                        WHERE key1_target = "basket_items.bpid"
                        AND description = "' . mysql_real_escape_string($message_type) . '"
                        LIMIT 1
                        )
                      ,0),
                    referenced_key1 = "' . mysql_real_escape_string($basket_item_info['bpid']) . '"';
            } else {
                $query_post_message = '
                  DELETE FROM ' . NEW_TABLE_MESSAGES . '
                  WHERE
                    message_type_id = 
                      COALESCE((
                        SELECT message_type_id
                        FROM ' . NEW_TABLE_MESSAGE_TYPES . '
                        WHERE key1_target = "basket_items.bpid"
                        AND description = "' . mysql_real_escape_string($message_type) . '"
                        LIMIT 1
                        )
                      ,0)
                    AND referenced_key1 = "' . mysql_real_escape_string($basket_item_info['bpid']) . '"';
            }
            $result_post_message = mysql_query($query_post_message, $connection) or die(debug_print("ERROR: 789021 ", array($query_post_message, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        }
    }
    // Clear any weight that might have been set for this item
    if ($initiate_clear_weight && $basket_item_info['random_weight']) {
        $total_weight = $data['weight'];
        $query = '
          UPDATE ' . NEW_TABLE_BASKET_ITEMS . '
          SET total_weight = "' . mysql_real_escape_string($total_weight) . '"
          WHERE bpid = "' . mysql_real_escape_string($basket_item_info['bpid']) . '"';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 890254 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
    }
    // Update the weight for this item
    if ($initiate_change_weight && $basket_item_info['random_weight']) {
        $total_weight = $data['weight'];
        if ($new_requested_quantity - $new_out_of_stock) {
            $average_weight = $data['weight'] / ($new_requested_quantity - $new_out_of_stock);
            //             // Check for weight in specified range (admins may override this check)
            //             if (($average_weight < $basket_item_info['minimum_weight'] ||
            //               $average_weight > $basket_item_info['maximum_weight']) &&
            //               $admin_override_not_set)
            //               {
            //                 return ('Random-weight item outside declared weight range');
            //               }
        } else {
            $average_weight = 0;
            $total_weight = 0;
        }
        $query = '
          UPDATE ' . NEW_TABLE_BASKET_ITEMS . '
          SET total_weight = "' . mysql_real_escape_string($total_weight) . '"
          WHERE bpid = "' . mysql_real_escape_string($basket_item_info['bpid']) . '"';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 520561 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
    }
    if ($initiate_synch_ledger == true) {
        // If the requested action is just to synch the ledger, then we need to preset these values:
        $new_out_of_stock = $basket_item_info['out_of_stock'];
        $new_requested_quantity = $basket_item_info['quantity'];
        $product_tax_basis = 0;
        $fee_tax_basis = 0;
        // And make sure the basket is also checked out
        $test_info = update_basket(array('action' => 'set_checkout', 'basket_id' => $basket_info['basket_id']));
        // Sync the checked_out field
        $basket_info['checked_out'] = $test_info['checked_out'];
        $query = '
          UPDATE ' . NEW_TABLE_BASKET_ITEMS . '
          SET checked_out = "1"
          WHERE bpid = "' . mysql_real_escape_string($basket_item_info['bpid']) . '"';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 893020 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        // Sync the checked_out field
        $basket_item_info['checked_out'] = "1";
    }
    // If the quantity has become zero (i.e. out_of_stock == requested_quantity) then we don't want to
    // charge people for random weight items -- even if a weight is entered -- so clobber the weight
    if ($new_out_of_stock == $new_requested_quantity) {
        // i.e. There are no items in stock... then multiply certain costs by zero
        $basket_item_info['total_weight'] = 0;
    }
    // At this point, all basket_item information has been set, so we need to consider
    // changes in the ledger. This is done for any/all changes, so not conditional
    // except for baskets that are not checked-out.
    if ($basket_info['checked_out'] != 0) {
        // If this product is configured with an extra_charge, then post it
        if ($product_info['extra_charge'] != 0) {
            $extra_charge = ($new_requested_quantity - $new_out_of_stock) * $product_info['extra_charge'];
            // Assumption is that extra_charges are passed through to the producer
            // Should they/could they be held by the co-op???
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => 'member', 'source_key' => $data['member_id'], 'target_type' => 'producer', 'target_key' => $product_info['producer_id'], 'amount' => $extra_charge, 'text_key' => 'extra charge', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'bpid' => $basket_item_info['bpid'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'pvid' => $product_info['pvid'], 'match_keys' => array('text_key', 'bpid')));
        }
        // If this product is configured with a regular cost, then post it
        if ($product_info['unit_price'] != 0) {
            if ($product_info['random_weight'] == 1) {
                $total_price = $product_info['unit_price'] * $basket_item_info['total_weight'];
                $text_key = 'weight cost';
            } elseif ($product_info['random_weight'] == 0) {
                $total_price = $product_info['unit_price'] * ($new_requested_quantity - $new_out_of_stock);
                $text_key = 'quantity cost';
            } else {
                return 'Unexpected result 579210';
            }
            // Start accumulating basis for taxation
            $product_tax_basis += $total_price;
            // Write the transaction to the ledger
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => 'member', 'source_key' => $data['member_id'], 'target_type' => 'producer', 'target_key' => $product_info['producer_id'], 'amount' => $total_price, 'text_key' => $text_key, 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'bpid' => $basket_item_info['bpid'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'pvid' => $product_info['pvid'], 'match_keys' => array('text_key', 'bpid')));
        }
        // If there is a product fee, post it
        if ($basket_item_info['product_fee_percent'] != 0 && PAYS_PRODUCT_FEE != 'nobody') {
            $product_adjust_amount = $basket_item_info['product_fee_percent'] * $total_price / 100;
            if (PAYS_PRODUCT_FEE == 'customer') {
                $source_type = 'member';
                $source_key = $data['member_id'];
                // Accumulate basis for taxation
                $fee_tax_basis += $product_adjust_amount;
            } elseif (PAYS_PRODUCT_FEE == 'producer') {
                $source_type = 'producer';
                $source_key = $product_info['producer_id'];
            } else {
                return 'No designated payee for product fee';
            }
            // Post product fee to the ledger for each product
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => $source_type, 'source_key' => $source_key, 'target_type' => 'internal', 'target_key' => 'product_fee', 'amount' => $product_adjust_amount, 'text_key' => 'product fee', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'bpid' => $basket_item_info['bpid'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'pvid' => $product_info['pvid'], 'match_keys' => array('text_key', 'bpid')));
        }
        // If there is a subcategory fee, post it
        if ($basket_item_info['subcategory_fee_percent'] != 0 && PAYS_SUBCATEGORY_FEE != 'nobody') {
            $subcategory_adjust_amount = $basket_item_info['subcategory_fee_percent'] * $total_price / 100;
            if (PAYS_SUBCATEGORY_FEE == 'customer') {
                $source_type = 'member';
                $source_key = $data['member_id'];
                // Accumulate basis for taxation
                $fee_tax_basis += $subcategory_adjust_amount;
            } elseif (PAYS_SUBCATEGORY_FEE == 'producer') {
                $source_type = 'producer';
                $source_key = $product_info['producer_id'];
            } else {
                return 'No designated payee for subcategory fee';
            }
            // Post subcategory fee to the ledger for each product
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => $source_type, 'source_key' => $source_key, 'target_type' => 'internal', 'target_key' => 'subcategory_fee', 'amount' => $subcategory_adjust_amount, 'text_key' => 'subcategory fee', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'bpid' => $basket_item_info['bpid'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'pvid' => $product_info['pvid'], 'match_keys' => array('text_key', 'bpid')));
        }
        // If there is a producer fee, post it
        if ($basket_item_info['producer_fee_percent'] != 0 && PAYS_PRODUCER_FEE != 'nobody') {
            $producer_adjust_amount = $basket_item_info['producer_fee_percent'] * $total_price / 100;
            if (PAYS_PRODUCER_FEE == 'customer') {
                $source_type = 'member';
                $source_key = $data['member_id'];
                // Accumulate basis for taxation
                $fee_tax_basis += $producer_adjust_amount;
            } elseif (PAYS_PRODUCER_FEE == 'producer') {
                $source_type = 'producer';
                $source_key = $product_info['producer_id'];
            } else {
                return 'No designated payee for producer fee';
            }
            // Post producer fee to the ledger for each product
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => $source_type, 'source_key' => $source_key, 'target_type' => 'internal', 'target_key' => 'producer_fee', 'amount' => $producer_adjust_amount, 'text_key' => 'producer fee', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'bpid' => $basket_item_info['bpid'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'pvid' => $product_info['pvid'], 'match_keys' => array('text_key', 'bpid')));
        }
        // If there is a customer fee, post it
        if ($basket_info['customer_fee_percent'] != 0 && PAYS_CUSTOMER_FEE != 'nobody') {
            $customer_adjust_amount = $basket_info['customer_fee_percent'] * $total_price / 100;
            if (PAYS_CUSTOMER_FEE == 'customer') {
                $source_type = 'member';
                $source_key = $data['member_id'];
                // Accumulate basis for taxation
                $fee_tax_basis += $customer_adjust_amount;
            } elseif (PAYS_CUSTOMER_FEE == 'producer') {
                $source_type = 'producer';
                $source_key = $product_info['producer_id'];
            } else {
                return 'No designated payee for customer fee';
            }
            // Post customer fee to the ledger for each product
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => $source_type, 'source_key' => $source_key, 'target_type' => 'internal', 'target_key' => 'customer_fee', 'amount' => $customer_adjust_amount, 'text_key' => 'customer fee', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'bpid' => $basket_item_info['bpid'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'pvid' => $product_info['pvid'], 'match_keys' => array('text_key', 'bpid')));
        }
        // If this is a taxable item, then collect all the requisite taxes
        if ($basket_item_info['taxable'] == 1 || COOP_FEE_IS_TAXED == 'always') {
            // Get the tax information...
            $query = '
              SELECT
                tax_id,
                region_code,
                region_type,
                tax_percent
              FROM ' . NEW_TABLE_TAX_RATES . '
              WHERE
                postal_code = "' . mysql_real_escape_string($basket_info['delivery_postal_code']) . '"
                AND order_id_start <= "' . mysql_real_escape_string($data['delivery_id']) . '"
                AND (
                  order_id_stop >= "' . mysql_real_escape_string($data['delivery_id']) . '"
                  OR order_id_stop = "0"
                  )';
            $result = mysql_query($query, $connection) or die(debug_print("ERROR: 890236 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
            while ($row = mysql_fetch_array($result)) {
                $text_key = $row['region_type'] . ' tax';
                // e.g. 'county tax'
                // Just tax the item and not the fees
                if (COOP_FEE_IS_TAXED == 'never') {
                    $tax_amount = $row['tax_percent'] * $product_tax_basis / 100;
                } elseif (COOP_FEE_IS_TAXED == 'on taxable items' || COOP_FEE_IS_TAXED == 'always' && $basket_item_info['taxable'] == 1) {
                    $tax_amount = $row['tax_percent'] * ($product_tax_basis + $fee_tax_basis) / 100;
                } elseif (COOP_FEE_IS_TAXED == 'always' && $basket_item_info['taxable'] == 0) {
                    $tax_amount = $row['tax_percent'] * $fee_tax_basis / 100;
                }
                $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => 'member', 'source_key' => $data['member_id'], 'target_type' => 'tax', 'target_key' => $row['tax_id'], 'amount' => $tax_amount, 'text_key' => $text_key, 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'bpid' => $basket_item_info['bpid'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'pvid' => $product_info['pvid'], 'match_keys' => array('text_key', 'bpid')));
            }
        }
    }
    return $basket_item_info;
}
Example #12
0
 private static function get_basket_info()
 {
     if (self::$query_complete === false) {
         global $connection;
         $query = '
           SELECT
             ' . NEW_TABLE_BASKETS . '.basket_id,
             ' . NEW_TABLE_SITES . '.site_id,
             ' . NEW_TABLE_SITES . '.site_short,
             ' . NEW_TABLE_SITES . '.site_long,
             ' . NEW_TABLE_BASKETS . '.checked_out
           FROM
             ' . NEW_TABLE_BASKETS . '
           LEFT JOIN ' . NEW_TABLE_SITES . ' USING(site_id)
           WHERE
             ' . NEW_TABLE_BASKETS . '.delivery_id = "' . mysql_real_escape_string(ActiveCycle::delivery_id()) . '"
             AND ' . NEW_TABLE_BASKETS . '.member_id = "' . mysql_real_escape_string($_SESSION['member_id']) . '"';
         $result = @mysql_query($query, $connection) or die(debug_print("ERROR: 783032 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
         if ($row = mysql_fetch_object($result)) {
             self::$basket_id = $row->basket_id;
             self::$site_id = $row->site_id;
             self::$site_short = $row->site_short;
             self::$site_long = $row->site_long;
             self::$basket_checked_out = $row->checked_out;
             self::$query_complete = true;
         }
     }
 }
Example #13
0
  }

.c_list_header {
  position:relative;
  font-weight:bold;
  text-decoration:underline;
  color:#008;
  }

</style>';
$prior_delivery_link = ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ';
$next_delivery_link = ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ';
if ($delivery_id > 1) {
    $prior_delivery_link = '<a href="' . $_SERVER['SCRIPT_NAME'] . '?delivery_id=' . number_format($delivery_id - 1, 0) . '">&larr; PRIOR &#151;</a>';
}
if ($delivery_id < ActiveCycle::delivery_id()) {
    $next_delivery_link = '<a href="' . $_SERVER['SCRIPT_NAME'] . '?delivery_id=' . number_format($delivery_id + 1, 0) . '">&#151; NEXT &rarr;</a>';
}
$content .= '
<h1>Generate Invoices for Delivery #' . $delivery_id . '<br>' . $delivery_date . '</h1>
<p class="order_nav">' . $prior_delivery_link . ' &nbsp; &nbsp; OTHER ORDERS &nbsp; &nbsp; ' . $next_delivery_link . '</p>';
$customer_output_html = INVOICE_WEB_PATH . 'invoices_customers-' . $delivery_id . '.html';
$customer_output_pdf = INVOICE_WEB_PATH . 'invoices_customers-' . $delivery_id . '.pdf';
if (!file_exists(INVOICE_FILE_PATH . 'invoices_customers-' . $delivery_id . '.html')) {
    $cust_view_html = ' style="display:none;"';
}
if (!file_exists(INVOICE_FILE_PATH . 'invoices_customers-' . $delivery_id . '.pdf')) {
    $cust_view_pdf = ' style="display:none;"';
}
$content .= '
<div id="left-column">
<?php

include_once 'config_openfood.php';
session_start();
valid_auth('member');
include_once 'func.get_delivery_codes_list.php';
// If not the first_call (i.e. after being clicked), tell javascript to close the window.
if ($_GET['first_call'] != 'true') {
    $modal_action = 'just_close';
}
// Set content_top to show basket selector...
$delivery_codes_list .= get_delivery_codes_list(array('action' => $_GET['action'], 'member_id' => $_SESSION['member_id'], 'delivery_id' => ActiveCycle::delivery_id(), 'site_id' => $_GET['site_id'], 'delivery_type' => $_GET['delivery_type']));
// Add styles to override delivery location dropdown
$page_specific_css .= '
  <link href="' . PATH . 'stylesheet.css" rel="stylesheet" type="text/css">
  <link href="' . PATH . 'delivery_dropdown.css" rel="stylesheet" type="text/css">
  <style type="text/css">
  body {
    font-size:87%;
    }
  /* OVERRIDE THE DROPDOWN CLOSURE FOR MOBILE DEVICES */
  #delivery_dropdown {
    position:static;
    height:auto;
    width:100% !important;
    overflow:hidden;
    margin:0px;
    border:0;
    }
  #delivery_dropdown:hover {
    width:100%;
        $plain_display .= '<span>' . $email_address . '</span><br>';
        $mail_count++;
    }
}
$content_list = '
<table width="80%">
  <tr>
    <td align="left">
      <div align="center">
        <h3>Member Ordering for Delivery #' . $delivery_id . ': <?echo $mail_count;?> Members</h3>
      </div>
      ' . ($delivery_id > 1 ? '
      <div style="float:left;border:1px solid #440; background-color:#ffd;padding:3px 20px;">
        <a href="' . $_SERVER['SCRIPT_NAME'] . '?delivery_id=' . ($delivery_id - 1) . '">Get list for prior order</a>
      </div>' : '') . '
      ' . ($delivery_id < ActiveCycle::delivery_id() ? '
      <div style="float:right;border:1px solid #440; background-color:#ffd;padding:3px 20px;">
        <a href="' . $_SERVER['SCRIPT_NAME'] . '?delivery_id=' . ($delivery_id + 1) . '">Get list for next order</a>
      </div>' : '') . '
      <br><br>
      <input type="radio" name="display_type" onClick=\'{document.getElementById("fancy").style.display="none";document.getElementById("plain").style.display="";}\'>Show plain addresses
      <br>
      <input type="radio" name="display_type" onClick=\'{document.getElementById("plain").style.display="none";document.getElementById("fancy").style.display="";}\'>Show fancy addresses
      <br><br>
    <div id="fancy"><div style="float:left";>' . $home_phone_display . '</div><div style="float:left;margin-left:1em;">' . $fancy_display . '</div></div>
    <div id="plain" style="display:none">' . $plain_display . '</div>
  </td></tr>
</table>';
$page_title_html = '<span class="title">Delivery Cycle Functions</span>';
$page_subtitle_html = '<span class="subtitle">Email List of Members with Orders</span>';
$page_title = 'Delivery Cycle Functions: Email List of Members with Orders';
function update_basket(array $data)
{
    //    debug_print ('INFO: Update Basket', $data);
    global $connection;
    //    $member_id_you = $_SESSION['member_id'];
    $producer_id_you = $_SESSION['producer_id_you'];
    // Allow admins to override certain checks if the requested action is not for themselves
    $admin_override = true;
    if ($member_id_you == $data['member_id'] || !CurrentMember::auth_type('cashier')) {
        $admin_override = false;
    }
    // Set this value manually when converting from transactions to ledger accounting
    $admin_override = true;
    // Set flags for needed validations and operations
    switch ($data['action']) {
        // checkout will checkout all the items in the basket
        case 'checkout':
            $test_for_membership_privilege = true;
            $test_customer_ordering_window = true;
            $initiate_set_checkout = true;
            $initiate_checkout_items = true;
            break;
            // same as "checkout" but only synchs items that were already checked out
        // same as "checkout" but only synchs items that were already checked out
        case 'synch_ledger_items':
            $test_for_membership_privilege = true;
            $test_customer_ordering_window = true;
            $initiate_set_checkout = true;
            $synch_ledger_items = true;
            break;
            // set_uncheckout is currently disabled
        // set_uncheckout is currently disabled
        case 'set_checkout':
            $test_for_membership_privilege = true;
            $test_customer_ordering_window = true;
            $initiate_set_checkout = true;
            break;
            // un_checkout is currently disabled
        // un_checkout is currently disabled
        case 'un_checkout':
            $test_customer_ordering_window = true;
            $initiate_un_checkout = true;
            break;
            // update the site (Pickup|Home|Work)
        // update the site (Pickup|Home|Work)
        case 'set_site':
            $update_site = true;
            break;
        default:
            die(debug_print('ERROR: 679217 ', 'unexpected request', basename(__FILE__) . ' LINE ' . __LINE__));
            break;
    }
    // Get  information about the basket for this member
    // Prefer to access basket by basket_id
    if ($data['basket_id'] != 0) {
        $basket_info = get_basket($data['basket_id']);
    } elseif ($data['member_id'] != 0 && $data['delivery_id'] != 0) {
        $basket_info = get_basket($data['member_id'], $data['delivery_id']);
    } else {
        die(debug_print('ERROR: 970893 ', 'incomplete information to locate basket', basename(__FILE__) . ' LINE ' . __LINE__));
    }
    // Check that we actually got some basket information
    if (!is_array($basket_info)) {
        die(debug_print('ERROR: 701854 ', 'basket does not exist', basename(__FILE__) . ' LINE ' . __LINE__));
    }
    // Check that the member is not pending or discontinued
    if ($test_for_membership_privilege && !$admin_override) {
        if ($member_info['pending'] == 1 || $member_info['membership_discontinued'] == 1) {
            die(debug_print('ERROR: 974383 ', 'incorrect privilege to order', basename(__FILE__) . ' LINE ' . __LINE__));
        }
    }
    // Check if shopping is closed for this order
    if ($test_customer_ordering_window && !$admin_override) {
        if (ActiveCycle::ordering_window() == 'closed') {
            die(debug_print('ERROR: 823186 ', 'customer ordering period is not in effect', basename(__FILE__) . ' LINE ' . __LINE__));
        }
    }
    // Update the basket with a new site and information related to the new site
    if ($update_site) {
        debug_print("ERROR: 892573 ", "UPDATE DELCODE", basename(__FILE__) . ' LINE ' . __LINE__);
        if ($data['delivery_type'] == 'H' || $data['delivery_type'] == 'W') {
            $query_delivery_type = 'D';
        } else {
            $query_delivery_type = $data['delivery_type'];
        }
        // P[ickup]
        // Could check for changes and abort otherwise, but this will force updating
        // delivery_postal_code just in case it might have changed.
        $query_site = '
          SELECT
            delivery_charge,
            delivery_postal_code
          FROM ' . NEW_TABLE_SITES . '
          WHERE
            site_id = "' . mysql_real_escape_string($data['site_id']) . '"
            AND delivery_type = "' . $query_delivery_type . '"
            AND inactive = "0"
            AND site_type = "customer"';
        $result_site = mysql_query($query_site, $connection) or die(debug_print("ERROR: 892573 ", array($query_site, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        // Got we some information, then post the new information
        if ($row_site = mysql_fetch_array($result_site)) {
            $query_update_basket = '
              UPDATE ' . NEW_TABLE_BASKETS . '
              SET
                delivery_cost = "' . mysql_real_escape_string($row_site['delivery_charge']) . '",
                delivery_postal_code = "' . mysql_real_escape_string($row['delivery_postal_code']) . '",
                site_id = "' . mysql_real_escape_string($data['site_id']) . '",
                delivery_type = "' . mysql_real_escape_string($data['delivery_type']) . '"
              WHERE basket_id = "' . mysql_real_escape_string($basket_info['basket_id']) . '"';
            $result_update_basket = mysql_query($query_update_basket, $connection) or die(debug_print("ERROR: 892764 ", array($query_update_basket, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
            debug_print("INFO: 892573 ", $query_update_basket, basename(__FILE__) . ' LINE ' . __LINE__);
            // Update the $basket_info with changes
            $basket_info['delivery_cost'] = $row_site['delivery_charge'];
            $initiate_delivery_charge = true;
        } else {
            die(debug_print('ERROR: 898952 ', 'requested site does not exist or is not available', basename(__FILE__) . ' LINE ' . __LINE__));
        }
    }
    // Change the checked_out setting on the basket
    // Do this early so the update_basket_item will process the ledger items (only if they are in a checked-out state)
    if ($initiate_set_checkout) {
        // Get the number of items in the basket that are checked out
        $query = '
          SELECT
            ' . NEW_TABLE_PRODUCTS . '.tangible,
            COUNT(' . NEW_TABLE_BASKET_ITEMS . '.bpid) AS count
          FROM
            ' . NEW_TABLE_BASKET_ITEMS . '
          LEFT JOIN
            ' . NEW_TABLE_PRODUCTS . ' USING(product_id,product_version)
          WHERE
            ' . NEW_TABLE_BASKET_ITEMS . '.basket_id = "' . mysql_real_escape_string($basket_info['basket_id']) . '"
          GROUP BY
            ' . NEW_TABLE_PRODUCTS . '.tangible';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 758023 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        while ($row = mysql_fetch_array($result)) {
            if ($row['tangible'] == '0') {
                $intangible_count = $row['count'];
            }
            if ($row['tangible'] == '1') {
                $tangible_count = $row['count'];
            }
        }
        // Preference is to set basket count to the number of *tangible* items in the basket
        if ($tangible_count > 0) {
            $checked_out = $tangible_count;
        } elseif ($intangible_count > 0) {
            $checked_out = 0 - $intangible_count;
        } else {
            $checked_out = 0;
        }
        $query = '
          UPDATE ' . NEW_TABLE_BASKETS . '
          SET checked_out = "' . mysql_real_escape_string($checked_out) . '"
          WHERE basket_id = "' . mysql_real_escape_string($basket_info['basket_id']) . '"';
        $result = mysql_query($query, $connection) or die(debug_print("ERROR: 892764 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        // Sync the variable we just changed
        $basket_info['checked_out'] = $checked_out;
        // If there is an order cost (fixed), then post it (or clear it if wrongly set).
        if ($basket_info['order_cost'] != 0 && $basket_info['order_cost_type'] == 'fixed' && $basket_info['checked_out'] != 0) {
            // Add the order cost to the ledger for this basket
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => 'member', 'source_key' => $data['member_id'], 'target_type' => 'internal', 'target_key' => 'order_cost', 'amount' => $basket_info['order_cost'], 'text_key' => 'order cost', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'match_keys' => array('source_type', 'source_key', 'target_type', 'target_key', 'text_key', 'basket_id')));
        } elseif ($basket_info['order_cost'] != 0 && $basket_info['order_cost_type'] == 'percent' && $basket_info['checked_out'] != 0) {
            // First need to know the basket total to calculate the percent cost
            $query = '
              SELECT
                SUM(amount) AS order_total
              FROM
                ' . NEW_TABLE_LEDGER . '
              WHERE
                basket_id = "' . mysql_real_escape_string($basket_info['basket_id']) . '"
                AND (text_key = "quantity cost"
                  OR text_key = "weight cost")';
            $result = mysql_query($query, $connection) or die(debug_print("ERROR: 678304 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
            if ($row = mysql_fetch_array($result)) {
                $order_total = $row['order_total'];
                $order_cost_total = round($row['order_total'] * $basket_info['order_cost'] / 100, 2);
            }
            // Add the order cost to the ledger for this basket
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => 'member', 'source_key' => $data['member_id'], 'target_type' => 'internal', 'target_key' => 'order_cost', 'amount' => $basket_info['order_cost'], 'text_key' => 'order cost', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'match_keys' => array('source_type', 'source_key', 'target_type', 'target_key', 'text_key', 'basket_id')));
        }
    }
    // For checkout, synchronize ledger entries to all basket_items
    if ($initiate_checkout_items || $synch_ledger_items) {
        // $initiate_checkout_items: check out all items and synch ledger
        // $synch_ledger_items:      repost existing checked_out items to the ledger
        if ($synch_ledger_items) {
            // Restrict to just the checked_out items
            $query_where = '
              AND checked_out != "0"';
        }
        // Get the items currently in the basket
        $query_basket_items = '
          SELECT
            bpid,
            product_id,
            product_version
          FROM ' . NEW_TABLE_BASKET_ITEMS . '
          WHERE basket_id = "' . mysql_real_escape_string($basket_info['basket_id']) . '"' . $query_where;
        $result_basket_items = mysql_query($query_basket_items, $connection) or die(debug_print("ERROR: 892785 ", array($query_basket_items, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
        // Go through all the basket items (or all the checked_out items)
        while ($row_basket_items = mysql_fetch_array($result_basket_items)) {
            $basket_item_info = update_basket_item(array('action' => 'synch_ledger', 'delivery_id' => $data['delivery_id'], 'member_id' => $data['member_id'], 'product_id' => $row_basket_items['product_id'], 'product_version' => $row_basket_items['product_version']));
            if (!is_array($basket_item_info)) {
                die(debug_print("ERROR: 902784 ", 'update_basket_item() did not return array.', basename(__FILE__) . ' LINE ' . __LINE__));
            }
        }
    }
    // This is done for any/all changes, so not conditional except for baskets that are not checked-out.
    if ($basket_info['checked_out'] != 0) {
        // If there is a delivery charge, then post it (or clear it if wrongly set).
        if ($basket_info['delivery_cost'] != 0 || $initiate_delivery_charge) {
            // Add the delivery cost to the ledger for this basket
            $ledger_status = basket_item_to_ledger(array('transaction_group_id' => $data['transaction_group_id'], 'source_type' => 'member', 'source_key' => $data['member_id'], 'target_type' => 'internal', 'target_key' => 'delivery_cost', 'amount' => $basket_info['delivery_cost'], 'text_key' => 'delivery cost', 'posted_by' => $_SESSION['member_id'], 'basket_id' => $basket_info['basket_id'], 'site_id' => $basket_info['site_id'], 'delivery_id' => $basket_info['delivery_id'], 'match_keys' => array('source_type', 'source_key', 'target_type', 'target_key', 'text_key', 'basket_id')));
        }
    }
    //     // For un_checkout, clear all ledger entries related to the basket and basket_items
    //     // This will remove or clear the cost of ledger entries for all products in the basket
    //     if ($initiate_un_checkout)
    //       {
    //         // Get the items currently in the basket
    //         $query_basket_items = '
    //           SELECT
    //             bpid,
    //             product_id,
    //             product_version
    //           FROM '.NEW_TABLE_BASKET_ITEMS.'
    //           WHERE basket_id = "'.mysql_real_escape_string($basket_info['basket_id']).'"';
    //         $result_basket_items = mysql_query($query_basket_items, $connection) or die(debug_print ("ERROR: 892785 ", array ($query_basket_items,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
    //         // Go through all the basket items
    //         while ($row_basket_items = mysql_fetch_array($result_basket_items))
    //           {
    //             // Problem: clear_item removes all quantity from the basket. We would like to leave the basket unchanged.
    //             // ... but if we define that as the desired behavior, then we have something, at least...
    //             $basket_item_info = update_basket_item (array(
    //               'action' => 'un_checkout',
    //               'delivery_id' => $data['delivery_id'],
    //               'member_id' => $data['member_id'],
    //               'product_id' => $row_basket_items['product_id'],
    //               'product_version' => $row_basket_items['product_version'],
    //               'post_even_if_zero' => 'YES'
    //               ));
    //             if ($basket_item_info != 'clear_item:'.$row_basket_items['bpid'])
    //               {
    //                 return('error 100: expected "clear_item:'.$row_basket_items['bpid'].'" but got "'.$basket_item_info.'"');
    //               }
    //           }
    //         // And un-checkout the basket as well
    //         // Remove the delivery cost from the ledger for this basket
    //         $ledger_status = basket_item_to_ledger(array (
    //           'source_type' => 'member',
    //           'source_key' => $data['member_id'],
    //           'target_type' => 'internal',
    //           'target_key' => 'delivery_cost',
    //           'amount' => 0,
    //           'text_key' => 'delivery cost',
    //           'posted_by' => $_SESSION['member_id'],
    //           'basket_id' => $basket_info['basket_id'],
    //           'site_id' => $basket_info['site_id'],
    //           'delivery_id' => $basket_info['delivery_id'],
    //           'match_keys' => array ('source_type','source_key','target_type','target_key','text_key','basket_id')
    //           ));
    //       }
    //     // Change the checked_out setting on the basket
    //     // Do this last so the update_basket_item will clear ledger items (only if they are in a checked-out state)
    //     if ($initiate_un_checkout)
    //       {
    //         $query = '
    //           UPDATE '.NEW_TABLE_BASKETS.'
    //           SET checked_out = "0"
    //           WHERE basket_id = "'.mysql_real_escape_string($basket_info['basket_id']).'"';
    //         $result = mysql_query($query, $connection) or die(debug_print ("ERROR: 892764 ", array ($query,mysql_error()), basename(__FILE__).' LINE '.__LINE__));
    //         $basket_info['checked_out'] = 0;
    //       }
    // At this point, all basket information has been updated, so we need to consider any changes to the ledger.
    // * messages                    link a message to this transaction
    // * post_even_if_zero              'YES' will delete the transaction is zero and a singleton
    // NEED TO ADD PAYPAL SURCHARGE CALCULATION
    // Return the new (possibly changed) basket_info array
    return $basket_info;
}
Example #17
0
if (!$_GET['depth']) {
    $_GET['depth'] = 100;
} else {
    $_GET['depth'] = floor($_GET['depth']);
}
//Make sure offset is numeric
$_GET['offset'] = floor($_GET['offset']);
//Set up the root for the categories tree
if ($_GET['category_id']) {
    $base_category = preg_replace("/[^0-9]/", "", $_GET['category_id']);
} else {
    $base_category = 0;
}
$list_markup = '';
//If an order-cycle is open, then use the product_list table.  Otherwise use the product_list_prep table.
if (ActiveCycle::date_open_next() == 'open') {
    $product_list = 'product_list';
} else {
    $product_list = 'product_list_prep';
}
////////////////////////////////////////////////////////////////////////////////
///                                                                          ///
///    DEFINE listCategories FUNCTION, BUT ONLY IF NOT ALREADY DEFINED       ///
///                                                                          ///
///         THE FUNCTION RECURSIVELY GENERATES THE CATEGORIES LIST           ///
///                                                                          ///
////////////////////////////////////////////////////////////////////////////////
if (!$list_categories_defined) {
    function listCategories($parent_id, $level)
    {
        global $connection, $list_categories_defined, $classB_divider, $classC_divider, $product_list, $where_producer_pending, $where_confirmed, $where_auth_type, $where_unlisted_producer, $where_zero_inventory, $where_order_by;
Example #18
0
        You will also be able to view your finalized invoice online after delivery day. The mailing address is on the invoice.
        If paying by PayPal, email payment to <a href="mailto:' . PAYPAL_EMAIL . '">' . PAYPAL_EMAIL . '</a>

        <div id="pay2"></div>
        <br><br>

        <b>Q: How do I change my payment method?</b>
        <br>
        <b>A:</b> To change how you will pay, once your invoice is finalized after delivery day, you will be shown totals for different methods of payment. You can then decide to write a check, or log on and pay by PayPal online. You will also be able to change your method of payment at that time. If you have questions about this at that time, contact us at <a href="mailto:' . HELP_EMAIL . '">' . HELP_EMAIL . '</a>

        <div id="del1"></div>
        <br><br>

        <b>Q: When can I pick up or have my items delivered?</b>
        <br>
        <b>A:</b> Delivery Day is <strong>' . date('F j', strtotime(ActiveCycle::delivery_date())) . '</strong>. Your temporary invoice (viewable after ordering is closed) will have the information on pick up location or delivery. If you chose delivery, a route manager will be in touch to coordinate delivery with you.

        <div id="del2"></div>
        <br><br>

        <b>Q: Can I change my delivery method once I have chosen it?</b>
        <br>
        <b>A:</b> Contact us at <a href="mailto:' . ORDER_EMAIL . '">' . ORDER_EMAIL . '</a> to change your delivery method.' . '
        <div id="web1"></div>
        <br><br>

        <b>Q: I am getting an error on a page, what do I do?</b>
        <br>
        <b>A:</b> Please copy and paste the text of the error into an email along with what page it is and send it to <a href="mailto:' . WEBMASTER_EMAIL . '">' . WEBMASTER_EMAIL . '</a>. Please also explain what happened before that error occurred. Thank you for your help in keeping this website working smoothly.

        <div id="web2"></div>
Example #19
0
        sort($completion_array, SORT_NUMERIC);
        $display .= '
      <tr>
        <td colspan="3">
          <div class="completion_list">
          ' . implode('<br>', $completion_array) . '
          </div>
        </td>
      </tr>';
    }
    $display .= '
      <tr>
        <td align="left" style="border-bottom:1px solid #000;">
          <input type="hidden" name="repeat_id" value="' . $row->repeat_id . '">
          <input type="hidden" name="new_order_last_added" value="' . ActiveCycle::delivery_id_next() . '">
          ' . ($row->order_last_added < ActiveCycle::delivery_id_next() ? '<input class="button" type="submit" name="action" value="Post orders"><br><br>' : '') . '
        </td>
        <td align="right" colspan="2" style="border-bottom:1px solid #000;">
          <input class="button" type="submit" name="action" value="Update settings"><br><br>
        </td>
      </tr>
    </form>';
}
// Get the next repeat_id for adding a new repeating item
$display .= '
    <form action="' . $_SERVER['SCRIPT_NAME'] . '" method="post">
      <tr>
        <td rowspan="3" width="50%" valign="top" class="add"><strong>Add new item</strong><br>Use this section to add a new
        repeating item.  The cost of the item will be charged on the invoice only the first time the item is ordered.  Each
        subsequent invoice for the number of &quot;Repeat after first order&quot; times, will show the item at zero cost.  This
        is how the system can correctly count repeats.</td>
Example #20
0
    <strong>Basket Status</strong>
        <ul class="fancyList1">
          <li class="last_of_group">' . $basket_status . '</li>
        </ul>
        <img src="' . DIR_GRAPHICS . 'product.png" width="32" height="32" align="left" hspace="2" alt="Order Info"><br>
        <b>Order Info</b>
        <ul class="fancyList1">
          <li><a href="product_list.php?type=basket">View items in basket</a></li>
          <li><a href="show_report.php?type=customer_invoice">View invoice</a><br />
          <em>(Invoice is blank until after the order closes)</em></li>
          <li class="last_of_group"><a href="past_customer_invoices.php?member_id=' . $_SESSION['member_id'] . '">Past Customer Invoices</a></li>
        </ul>
      </td>
      <td align="left" width="50%">
        <img src="' . DIR_GRAPHICS . 'invoices.png" width="32" height="32" align="left" hspace="2" alt="Available Products"><br>
        <b>' . (ActiveCycle::ordering_window() == 'open' ? 'Available Products' : 'Products (Shopping is closed)') . '</b>
        <ul class="fancyList1">';
$search_display = '
  <form action="product_list.php" method="get">
    <input type="hidden" name="type" value="search">
    <input type="text" name="query" value="' . $_GET['query'] . '">
    <input type="submit" name="action" value="Search">
  </form>';
$display .= '
          <li class="last_of_group">' . $search_display . '</li>';
if (CurrentMember::auth_type('unfi')) {
    $display .= '
          <!-- <li><a href="product_list.php?type=unfi">All products (UNFI)</a></li> -->';
}
$display .= '
          <li>                        <a href=category_list2.php>                     Browse by category</a></li>
Example #21
0
        <div class="tab_frame">
          <a href="' . PATH . 'panel_cashier.php" class="' . ($page_tab == 'cashier_panel' ? ' current_tab' : '') . '">Cashiers</a>
        </div>';
    }
    if (CurrentMember::auth_type('site_admin')) {
        $panel_admin_menu = '
        <div class="tab_frame">
          <a href="' . PATH . 'panel_admin.php" class="' . ($page_tab == 'admin_panel' ? ' current_tab' : '') . '">Site Admin</a>
        </div>';
    }
    $logout_menu = '
        <div class="tab_frame right">
          <a href="' . PATH . 'index.php?action=logout" class="' . ($page_tab == 'login' ? ' current_tab' : '') . '">Logout</a>
        </div>';
    if (isset($basket_id) && $basket_id != 0) {
        if (CurrentMember::auth_type('orderex') || ActiveCycle::ordering_window() == 'open') {
            $basket_menu = '
        <div class="tab_frame right">
          <a href="' . PATH . 'product_list.php?type=basket" class="">View Basket [' . $basket_quantity . ' ' . Inflect::pluralize_if($basket_quantity, 'item') . ']</a>
        </div>';
        }
    }
} else {
    $login_menu = '
        <div class="tab_frame right">
          <a href="' . PATH . 'index.php?action=login" class="' . ($page_tab == 'login' ? ' current_tab' : '') . '">Login</a>
        </div>';
}
// Put it all together now
////////////////////////////////////////////////////////////////////////////////
//////////////                                              ////////////////////
Example #22
0
if ($row = mysql_fetch_object($result)) {
    $basket_quantity = $row->basket_quantity;
    $basket_id = $row->basket_id;
}
/////////////// FINISH PRE-PROCESSING AND BEGIN PAGE GENERATION /////////////////
// Generate the display output
$display .= '
  <table width="100%" class="compact">
    <tr valign="top">
      <td align="left" width="50%">
    <img src="' . DIR_GRAPHICS . 'current.png" width="32" height="32" align="left" hspace="2" alt="Order"><br>
    <strong>' . $relative_text . 'Order</strong>
        <ul class="fancyList1">
          <li><strong>Open' . $open_suffix . ':</strong>&nbsp;' . date('M&\\n\\b\\s\\p;j,&\\n\\b\\s\\p;g:i&\\n\\b\\s\\p;A&\\n\\b\\s\\p;(T)', strtotime(ActiveCycle::date_open_next())) . '</li>
          <li><strong>Close' . $close_suffix . ':</strong>&nbsp;' . date('M&\\n\\b\\s\\p;j,&\\n\\b\\s\\p;g:i&\\n\\b\\s\\p;A&\\n\\b\\s\\p;(T)', strtotime(ActiveCycle::date_closed_next())) . '</li>
          <li class="last_of_group"><strong>Delivery:</strong>&nbsp;' . date('F&\\n\\b\\s\\p;j', strtotime(ActiveCycle::delivery_date_next())) . '</li>
        </ul>
<!--
    <img src="' . DIR_GRAPHICS . 'shopping.png" width="32" height="32" align="left" hspace="2" alt="Basket Status"><br>
    <strong>Basket Status</strong>
        <ul class="fancyList1">
          <li class="last_of_group">' . $basket_status . '</li>
        </ul>
-->
    <img src="' . DIR_GRAPHICS . 'type.png" width="32" height="32" align="left" hspace="2" alt="Membership Type"><br>
    <strong>Membership Type</strong> [<a onClick="popup_src(\'update_membership.php?display_as=popup\', \'membership_renewal\', \'\');">Change</a>]
        <ul class="fancyList1">
          <li><strong>' . $_SESSION['renewal_info']['membership_class'] . ':</strong> ' . $_SESSION['renewal_info']['membership_description'] . '<br><br></li>
          <li class="last_of_group">' . $_SESSION['renewal_info']['membership_message'] . '</li>
        </ul>
    <img src="' . DIR_GRAPHICS . 'time.png" width="32" height="32" align="left" hspace="2" alt="Information"><br>
Example #23
0
        <ul class="fancyList1">

          <li><a href="category_list_edit.php">Edit Categories and Subcategories</a></li>
          <li><a href="edit_configuration.php">Edit Site Configuration</a></li>
          <li class="last_of_group"><a href="invoice_edittext.php">Edit Invoice Messages</a></li>
          <li><a href="view_order_schedule.php">View/Set Ordering Schedule</a></li>

        </ul>
      </td>
      <td align="left" width="50%">
        <img src="' . DIR_GRAPHICS . 'launch.png" width="32" height="32" align="left" hspace="2" alt="Current Delivery Cycle Functions"><br>
        <b>Current Delivery Cycle Functions</b>
        <ul class="fancyList1">
          <li><a href="orders_list_withtotals.php?delivery_id=' . ActiveCycle::delivery_id() . '">Members with orders this cycle (with totals)</a></li>
          <li><a href="members_list_emailorders.php?delivery_id=' . ActiveCycle::delivery_id() . '">Customer Email Addresses this cycle</a></li>
          <li class="last_of_group"><a href="orders_prdcr_list.php?delivery_id=' . ActiveCycle::delivery_id() . '">Producers with Customers this Cycle</a></li>
        </ul>
        <img src="' . DIR_GRAPHICS . 'kcron.png" width="32" height="32" align="left" hspace="2" alt="Previous Delivery Cycle Functions"><br>
        <b>Previous Delivery Cycle Functions</b>
        <ul class="fancyList1">
          <li class="last_of_group"><a href="generate_invoices.php">Generate Invoices</a></li>
        </ul>
      </td>
    </tr>
  </table>';
$page_title_html = '<span class="title">' . $_SESSION['show_name'] . '</span>';
$page_subtitle_html = '<span class="subtitle">Site Admin Panel</span>';
$page_title = 'Site Admin Panel';
$page_tab = 'admin_panel';
include "template_header.php";
echo '
Example #24
0
          <!-- <li class="last_of_group"><a href="producer_select_site.php">Select Collection Point</a></li> -->
          <li><a href="product_list.php?&type=labels_bystoragecustomer">Labels &ndash; One per Customer/Storage</a></li>
          <li class="last_of_group"><a href="product_list.php?&type=labels_byproduct">Labels &ndash; One per Item</a></li>
        </ul>
          <img src="' . DIR_GRAPHICS . 'invoices.png" width="32" height="32" align="left" hspace="2" alt="Producer invoices"><br>
          <b>' . $active_business_name . ' Producer Orders</b>
          <ul class="fancyList1">
            <li><a href="product_list.php?&type=producer_byproduct">Producer Basket (by product)</a></li>
            <li><a href="product_list.php?&type=producer_bystoragecustomer">Producer Basket List (by storage/customer)</a></li>
            <li class="last_of_group"><a href="product_list.php?&type=producer_bycustomer">Producer Basket List (by customer)</a></li>

            <li><a href="order_summary.php">Order Summary</a></li>
            <li><a href="show_report.php?type=producer_invoice">Producer Invoice</a></li>
            <li class="last_of_group"><a href="past_producer_invoices.php?producer_id=' . $_SESSION['producer_id_you'] . '">Past Producer Invoices</a></li>
            <li><a href="route_list.php?delivery_id=' . ActiveCycle::delivery_id() . '&type=pickup&producer_id=' . $_SESSION['producer_id_you'] . '">Routing Checklist (by customer)</a></li>
            <li class="last_of_group"><a href="route_list.php?delivery_id=' . ActiveCycle::delivery_id() . '&type=dropoff&producer_id=' . $_SESSION['producer_id_you'] . '">Routing Checklist (by destination)</a></li>

          </ul>
          <img src="' . DIR_GRAPHICS . 'product.png" width="32" height="32" align="left" hspace="2" alt="Edit your products"><br>
          <b>Edit ' . $active_business_name . ' Products</b>
          <ul class="fancyList1">
            <li><a href="product_list.php?a=retail&type=producer_list">Listed&nbsp;Retail</a></li>
            <li><a href="product_list.php?a=wholesale&type=producer_list">Listed&nbsp;Wholesale</a></li>
            <li><a href="product_list.php?a=unlisted&type=producer_list">Unlisted</a></li>
            <li class="last_of_group"><a href="product_list.php?a=archived&type=producer_list">Archived</a></li>
            <li class="last_of_group"><a href="edit_products.php?producer_id=' . $_SESSION['producer_id_you'] . '">Add A New Product</a></li>
            <li class="last_of_group"><a href="edit_inventory.php">Manage Your Inventory</a></li>
          </ul>
          ';
}
$display .= '
Example #25
0
<?php

include_once 'config_openfood.php';
session_start();
valid_auth('member_admin');
$delivery_id = ActiveCycle::delivery_id();
$sql = '
  SELECT
    ' . TABLE_MEMBER . '.*,
    ' . TABLE_MEMBERSHIP_TYPES . '.membership_class
  FROM
    ' . TABLE_MEMBER . '
  LEFT JOIN ' . TABLE_MEMBERSHIP_TYPES . ' on ' . TABLE_MEMBER . '.membership_type_id = ' . TABLE_MEMBERSHIP_TYPES . '.membership_type_id
  WHERE
    ' . TABLE_MEMBER . '.pending = "0"
    AND ' . TABLE_MEMBER . '.membership_discontinued != "1"
  ORDER BY
    member_id DESC,
    last_name ASC,
    first_name ASC';
$rs = @mysql_query($sql, $connection) or die(debug_print("ERROR: 785033 ", array($sql, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
$num = mysql_numrows($rs);
while ($row = mysql_fetch_array($rs)) {
    $member_id = $row['member_id'];
    $first_name = $row['first_name'];
    $last_name = $row['last_name'];
    $first_name_2 = $row['first_name_2'];
    $last_name_2 = $row['last_name_2'];
    $business_name = $row['business_name'];
    $address_line1 = $row['address_line1'];
    $address_line2 = $row['address_line2'];
Example #26
0
if ($_GET['delivery_id']) {
    // If we were passed a delivery_id, use  it
    $delivery_id = $_GET['delivery_id'];
} else {
    // Otherwise, use the current delivery_id
    $sqlp = '
      SELECT
        delivery_id,
        delivery_date,
        producer_markdown,
        wholesale_markup,
        retail_markup
      FROM
        ' . TABLE_ORDER_CYCLES . '
      WHERE
        delivery_id = ' . ActiveCycle::delivery_id();
    $resultp = @mysql_query($sqlp, $connection) or die(debug_print("ERROR: 675932 ", array($sqlp, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
    while ($row = mysql_fetch_array($resultp)) {
        $delivery_id = $row['delivery_id'];
        $delivery_date = $row['delivery_date'];
        $producer_markdown = $row['producer_markdown'] / 100;
        $retail_markup = $row['retail_markup'] / 100;
        $wholesale_markup = $row['wholesale_markup'] / 100;
    }
}
$producer_id = $_SESSION['producer_id_you'];
$display_page = generate_producer_summary($producer_id, $delivery_id, $detail_type, '');
include "func/show_businessname.php";
$page_title_html = '<span class="title">' . $business_name . '</span>';
$page_subtitle_html = '<span class="subtitle">Order Summary</span>';
$page_title = $business_name . ': Order Summary';