'sold/record', 'title' => t('Record products sold.'),
'callback' => 'sold_record', 'access' => $access);
// This path is for the routine that actually does the multplication
// It is only setup as a callback (no menu entry)
$items[] = array('path' => 'sold/report', 'title' => t('Products information.'),
'type' => MENU_CALLBACK, 'callback' => 'sold_report', 'access' => $access);
}
$items[] = array('path' => 'sales/history',
'title' => t('Sales History'),
'callback' => 'sales_history',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
$items[] = array('path' => 'test/form',
'title' => t('Test Form'),
'callback' => 'drupal_get_form',
'callback arguments' => 'test_form',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
return $items;
}
function test_form() {
$form = array();
// Build up the form
$form['date1'] = array(
'#type' => 'textfield',
'#width' => 10,
);
$form['date2'] = array(
'#type' => 'textfield',
'#width' => 5,
);
// Make sure we have a submit button
$form['submit'] = array('#type' => 'submit', '#value' => t('Record'));
return ($form);
}
function test_form_submit($form_id, $form_values) {
global $user;
// Break the textrea into lines
$lines = explode("\n", trim($form_values['products']));
$output.=$lines[0];
$output.="testing";
$_SESSION['test']=$output;
return 'sales/history';
}
function sold_record() {
$form = array();
// Build up the form
$form['products'] = array(
'#type' => 'textarea',
'#title' => t('Products sold'),
'#cols' => 10,
'#rows' => 10,
'#description' => t('Paste in the product information.')
);
// Make sure we have a submit button
$form['submit'] = array('#type' => 'submit', '#value' => t('Record'));
return drupal_get_form('sold_record', $form);
}
function sold_record_validate($form_id, $form_values) {
if (strlen($form_values['products']) > 30000) {
form_set_error('products', t('Your submission contains more than 30,000 characters. Please break it down into smaller pieces, then resubmit'));
}
}
function deeptrim($string) {
$string = trim($string);
$tmp = explode(" ",$string);
foreach($tmp as $key => $val) {
if (!$val == "") {
$return[] = $val;
}
}
return implode(" ",$return);
}
function sold_record_submit($form_id, $form_values) {
global $user;
// Parse and save the values.
$sql = "INSERT INTO {sold} (uid, date, product, name, price, extra) VALUES(%d, '%s', '%s', '%s', %d, '%s')";
// Break the textrea into lines
$lines = explode("\n", trim($form_values['products']));
// For each line entered
foreach ( $lines as $line_item ) {
// Break the line on the space character
$line_item = str_replace("\t", " ", $line_item);
$line_item = deeptrim($line_item);
$details = explode(" ", $line_item);
// The first item will always be the date
// The last threee items will be name amount extra (in that order)
// The parts in between will be the product name
$cnt = count($details);
$date = $details[0];
$date_parts = explode('/', $date);
$when = mktime(12, 0, 0, $date_parts[1], $date_parts[0], $date_parts[2]);
$dates = explode("/",$date); //array of values
$when = $dates[2]."-".$dates[1]."-".$dates[0]; //d-m-y to y-m-d
$extra = trim($details[$cnt-1]); // remove any extra white space from the last part
$amount = str_replace(',', '', $details[$cnt-2]); // Remove any comma's from the amount
$name = $details[$cnt-3];
// The product starts at index 1 and includes upto everything but the last three parts
// So we slice out that part of the array
// And make a string of words separated by a space
$product = implode(' ', array_slice($details, 1, -3));
// Record the data
db_query($sql, $user->uid, $when, $product, $name, $amount, $extra);
}
return 'sold/report';
}
function sold_report() {
global $user;
// Report on the data just submitted by the user (recorded will be 1)
$results = db_query("SELECT COUNT(sid) as count,price, product FROM {sold} WHERE recorded = 1 AND uid = %d GROUP BY product,price", $user->uid);
$output.="
| Item | Number Sold | Price | ";
while ( $data = db_fetch_object($results))
{$output .= "
| $data->product | $data->count | $data->price |
| User | NP Spent | ";
while ( $data = db_fetch_object($results) )
{$output .= "
| " . $data->name . " | " . number_format($data->total) . " |
| Date | NP Spent | ";
while ( $data = db_fetch_object($results) )
{$output .= "
| " . $data->date . " | " . number_format($data->total) . " |
| Date | Product | Name | Price | Delete |
| << | "; else $output.="<< | "; if($page>=20) $index=($page-10); else $index=1; $start_page=$index; for(;$index<($start_page+20);$index++) if($index<=$num_pages) if($page!=$index) $output.=""; else $output.=" | $index | ";
// >> if page is the last page don't display line
if((!($num_pages==$page)) && (!($num_pages==0)))
$output.=">> | ";
else
$output.=">> | ";
$output.="
| ";
//total items sold
$output.=" Total Items Sold ";
$output.="(Full List - More in-depeth)
"; //sales total by user $output.=" Sale Totals by User (Full List) ";
$output.="
"; //sales total by date $output.=" Sale Totals by Date (Full List) ";
$output.="
|