Snapper / Sources

#--------------------------------------------------------------------
# Customer Detail Screen
#
#
#--------------------------------------------------------------------

package GtkPizza;

use strict;

#
# Customer Order Select
#
sub GtkPizza::customer_order_select {
my($widget, $row, $column, $event) = @_;
my ($text, $store_id, $order_id);

$row = ($widget->selection())[0];

$widget->set_focus_row ($row);

$text = $widget->get_text($row,0);
$store_id = int $text;
$order_id = (split('-', $text))[1];

GtkPizza::docket_screen_display($store_id, $order_id, !$GtkPizza::from_order);
}
#
# Customer Screen Quit BTN
#
sub GtkPizza::customer_quit_btn {
my ($w, $d) = @_;

$GtkPizza::MyXML->get_widget('docket_screen')->hide();
$GtkPizza::MyXML->get_widget('customer_screen')->hide();

if (!$GtkPizza::from_order) {
if (!$GtkPizza::from_select) {
GtkPizza::select_screen_redisplay();
} else {
GtkPizza::select_cust_screen_redisplay();
}
} else {
GtkPizza::order_screen_redisplay();
}

return Gtk->true();
}
#
# Display Customer Detail Screen (from select)
#
sub GtkPizza::do_customer_screen_from_select {
my ($old_cust_id) = @_;

GtkPizza::do_customer_screen($old_cust_id, '', '', 0);
$GtkPizza::from_select = 1;
}
#
# Display Customer Detail Screen (from order)
#
sub GtkPizza::do_customer_screen_from_order {
my ($old_cust_id) = @_;

GtkPizza::do_customer_screen($old_cust_id, '', '', 0);
}
#
# Display Customer Detail Screen
#
sub GtkPizza::do_customer_screen {
my ($old_cust_id, $newname, $newphone, $new_cust) = @_;
my ($w, $p, @d, $r, @rows);
my ($sql, $sth, $scombo,$olist,@s);

$GtkPizza::from_select = 0;
$GtkPizza::from_order = 0;
$GtkPizza::is_new_cust = $new_cust;
$GtkPizza::customer_number = $old_cust_id;

$GtkPizza::customer_number = 0 if $GtkPizza::is_new_cust;

#
# Show Window
#
$w = $GtkPizza::MyXML->get_widget('customer_screen');
$w->show();

if (!$GtkPizza::customer_screen_up) {
#
# Populate Suburb Combo
#
$scombo = $GtkPizza::MyXML->get_widget('customer_suburb_select');
$olist = $GtkPizza::MyXML->get_widget('customer_order_list');
$sql = q{
SELECT suburb
FROM suburbs
ORDER BY suburb
};
$sth = $GtkPizza::db->db_sql($sql);
while (@rows = $GtkPizza::db->db_fetch($sth)) {
push @s, $rows[0];
}
$GtkPizza::db->db_done($sth);
$scombo->set_popdown_strings(@s);
$olist->set_column_width(0,70);
$olist->set_column_width(1,120);
$olist->set_column_width(2,400);
$olist->set_column_width(3,40);
# done
$GtkPizza::customer_screen_up = 1;
}

#
# New Customer / Existing Customer
#
if ($new_cust) {
$GtkPizza::MyXML->get_widget('customer_screen')->set_title("New Customer Details");
# clear all the fields
$GtkPizza::MyXML->get_widget('customer_id')->set("");
$GtkPizza::MyXML->get_widget('customer_lastorder_num')->set("");
$GtkPizza::MyXML->get_widget('customer_lastorder_date')->set("");
$GtkPizza::MyXML->get_widget('customer_name')->set_text($newname);
$GtkPizza::MyXML->get_widget('customer_address')->set_text("");
$GtkPizza::MyXML->get_widget('customer_phone')->set_text($newphone);
$GtkPizza::MyXML->get_widget('customer_ubd')->set_text("");
$GtkPizza::MyXML->get_widget('customer_discount')->set_text("");
$GtkPizza::MyXML->get_widget('customer_deliv')->set_text("");
$GtkPizza::MyXML->get_widget('customer_suburb_entry')->set_text("ADELAIDE");
$GtkPizza::MyXML->get_widget('customer_comment')->delete_text(0, -1);
$GtkPizza::MyXML->get_widget('customer_bad')->set_state(0);
$GtkPizza::MyXML->get_widget('customer_order_list')->clear();
GtkPizza::reload_image($GtkPizza::MyXML->get_widget('customer_pixmap'),
"NewCustomer.xpm");
} else {
$GtkPizza::MyXML->get_widget('customer_screen')->set_title("Customer Details");
#
# Grab Last Order
#
$sql = q{
SELECT custnum,custname,address,phone,suburb,ubd,comments,
lastorder_num,lastorder_date,bad_cust,
discount,deliv_charge
FROM customers
WHERE custnum = ?
};
$sth = $GtkPizza::db->db_sql($sql,$old_cust_id);
@d = $GtkPizza::db->db_fetch($sth);
$GtkPizza::db->db_done($sth);
$GtkPizza::MyXML->get_widget('customer_id')->set($d[0]);
$GtkPizza::MyXML->get_widget('customer_lastorder_num')->set($d[7]);
$GtkPizza::MyXML->get_widget('customer_lastorder_date')->set($d[8]);
$GtkPizza::MyXML->get_widget('customer_name')->set_text($d[1]);
$GtkPizza::MyXML->get_widget('customer_address')->set_text($d[2]);
$GtkPizza::MyXML->get_widget('customer_phone')->set_text($d[3]);
$GtkPizza::MyXML->get_widget('customer_suburb_entry')->set_text($d[4]);
$GtkPizza::MyXML->get_widget('customer_ubd')->set_text($d[5]);
$GtkPizza::MyXML->get_widget('customer_discount')->set_text($d[10]);
$GtkPizza::MyXML->get_widget('customer_deliv')->set_text($d[11]);
$GtkPizza::MyXML->get_widget('customer_comment')->delete_text(0, -1);
$GtkPizza::MyXML->get_widget('customer_comment')->insert_text($d[6]);
my ($state, $bmp);
if ($d[9]) { $state = 1; $bmp = "BadCustomer.xpm"; } else {
$state = 0;
if ($GtkPizza::is_new_cust) { $bmp = "NewCustomer.xpm"; } else {
$bmp = "Customer.xpm"; }
$GtkPizza::MyXML->get_widget('customer_bad')->set_state($state);
GtkPizza::reload_image($GtkPizza::MyXML->get_widget('customer_pixmap'),
$bmp);
}
GtkPizza::customer_order_populate();
#
# validate that they belong to this store
#
$sql = q{
SELECT c.suburb,u.store_id,s.id,s.store_name,s.suburb,s.phone
FROM customers c, suburbs u, stores s
WHERE c.custnum = ?
AND u.suburb = c.suburb
AND s.id = u.store_id
};
$sth = $GtkPizza::db->db_sql($sql,$old_cust_id);
@d = $GtkPizza::db->db_fetch($sth);
$r = $GtkPizza::db->db_rows($sth);
$GtkPizza::db->db_done($sth);
if ($r) {
if ($GtkPizza::current_store != $d[1]) {
# found out which store then
my $msg = "Please call: " . $d[5] . "\nfor " .
$rows[3] . "\n at " . $rows[4] . " for your order";
GtkPizza::do_message_box($msg);
}
}
}
#
$GtkPizza::MyXML->get_widget('customer_name')->grab_focus();
}
#
# Customer Bad Toggled
#
sub GtkPizza::customer_bad_toggled {
my ($w, $d) = @_;
my ($bmp);
if ($w->active()) {
$bmp = "BadCustomer.xpm";
} else {
if ($GtkPizza::is_new_cust) { $bmp = "NewCustomer.xpm"; } else {
$bmp = "Customer.xpm"; }
}
GtkPizza::reload_image($GtkPizza::MyXML->get_widget('customer_pixmap'),
$bmp);
}
#
# Customer Suburb Combo Focus In Event
#
sub GtkPizza::customer_suburb_focus_in {
my ($w, $d) = @_;

$GtkPizza::MyXML->get_widget('customer_suburb_entry')->grab_focus();
$GtkPizza::MyXML->get_widget('customer_suburb_entry')->select_region(0,-1);
}
#
# Customer Suburb Combo Changed
#
sub GtkPizza::customer_suburb_changed {
my ($w, $d) = @_;
my ($text, $sql, $r, $sth, @data);

return if $GtkPizza::inside;

$GtkPizza::inside = 1;

$text = $GtkPizza::MyXML->get_widget('customer_suburb_entry')->get_text();

$sql = "select suburb,min_order,ubd,deliv_charge from suburbs where ".
"suburb like '" . $text . "%'";
$sth = $GtkPizza::db->db_sql($sql);
@data = $GtkPizza::db->db_fetch($sth);
$r = $GtkPizza::db->db_rows($sth);
$GtkPizza::db->db_done($sth);

if ($r == 1) {
$GtkPizza::cust_deliv_override = 0;
$GtkPizza::cust_ubd_override = 0;
$GtkPizza::cust_min_override = 0;

$text = $GtkPizza::MyXML->get_widget('customer_suburb_entry')->set_text($data[0]);
} else {
@data = ('',0,'',0);
}
$text = $GtkPizza::MyXML->get_widget('customer_ubd')->set_text($data[2]);
$text = $GtkPizza::MyXML->get_widget('customer_min')->set_text('$ ' . sprintf("%01.2f", $data[1]));
$text = $GtkPizza::MyXML->get_widget('customer_deliv')->set_text('$ ' . sprintf("%01.2f", $data[3]));

$GtkPizza::inside = 0;

}
#
# Customer Refresh Details
#
sub GtkPizza::customer_refresh_details {

$GtkPizza::MyXML->get_widget('customer_screen')->show();
GtkPizza::customer_order_populate();
}
#
# Customer Order Populate
#
sub GtkPizza::customer_order_populate {
my ($sql, @order_list_row, $store_string, $sth1, $sth,$olist);
my ($qty, $sote_id, $order_id, $i);

$olist = $GtkPizza::MyXML->get_widget('customer_order_list');

$olist->freeze();
$olist->clear();

$sql = q{
SELECT store_id,ordernum,order_date,total_price
FROM orders
WHERE custnum = ?
ORDER BY order_date DESC
};

$sth = $GtkPizza::db->db_sql($sql, $GtkPizza::customer_number);

$i = 0;
while (my @rows = $GtkPizza::db->db_fetch($sth)) {
$order_list_row[0] = $rows[0] . "-" . $rows[1];
if ($GtkPizza::db_type eq 'PG') {
$order_list_row[1] = substr($rows[2],0,16); # . ' ' .
} else {
$order_list_row[1] = $rows[2];
}
$order_list_row[3] = '$ ' . sprintf("%01.2f", $rows[3]);

my $buffer = '';
if ($i++ < 12) { # only show 12 descriptions
# Get Description
$sql = q{select qty, item_code from ordet where ordernum = ?
and store_id = ?};
$sth1 = $GtkPizza::db->db_sql($sql, $rows[1], $rows[0]);
while (my @details = $GtkPizza::db->db_fetch($sth1)) {
$buffer .= ',' if $buffer ne '';
$buffer .= $details[0] . " " . $details[1];
}
$GtkPizza::db->db_done($sth1);
} else {
$buffer = 'Click for details';
}
$order_list_row[2] = $buffer;

$olist->append(@order_list_row);
}
$GtkPizza::db->db_done($sth);
$olist->thaw();
$GtkPizza::MyXML->get_widget('customer_name')->grab_focus();
}

#
# Accept Button
#
sub GtkPizza::customer_accept_btn {
my ($w, $d) = @_;

my ($ubd, $suburb, $phone, $name, $address, $sub_store, $deliv,
$disc, $comments, $bad, $suburb_text);
my ($sql, $sth, @data, $r);

# validate the entry fields first
$phone = $GtkPizza::MyXML->get_widget('customer_phone' )->get_text();
$name = $GtkPizza::MyXML->get_widget('customer_name' )->get_text();
$address = $GtkPizza::MyXML->get_widget('customer_address' )->get_text();
$ubd = $GtkPizza::MyXML->get_widget('customer_ubd' )->get_text();
$deliv = $GtkPizza::MyXML->get_widget('customer_deliv' )->get_text();
$disc = $GtkPizza::MyXML->get_widget('customer_discount')->get_text();
$suburb = $GtkPizza::MyXML->get_widget('customer_suburb_entry')->get_text();
$comments = $GtkPizza::MyXML->get_widget('customer_comment')->get_chars(0,-1);
$bad = $GtkPizza::MyXML->get_widget('customer_bad')->get_active();
$deliv =~ s/[\$ ]//g;

if ($address eq '') {
GtkPizza::do_message_box('You MUST enter an address for deliveries');
$GtkPizza::MyXML->get_widget('customer_address')->grab_focus();
return;
}

if ($name eq '' && $phone eq '') {
GtkPizza::do_message_box('You MUST enter either a name or a phone number');
$GtkPizza::MyXML->get_widget('customer_name')->grab_focus();
return;
}

if ($GtkPizza::is_new_cust) {
# sort out the suburb
$sql = q{select store_id from suburbs where suburb = ?};
$sth = $GtkPizza::db->db_sql($sql,$suburb);
@data = $GtkPizza::db->db_fetch($sth);
$r = $GtkPizza::db->db_rows($sth);
$GtkPizza::db->db_done($sth);
if ($r) {
$sub_store = $data[0];
if ($sub_store != $GtkPizza::current_store) {
# found out which store then
$sql = q{select store_name,suburb,phone from stores where id = ?};
$sth = $GtkPizza::db->db_sql($sql,$sub_store);
@data = $GtkPizza::db->db_fetch($sth);
$GtkPizza::db->db_done($sth);
my $msg = "Please call: " . $data[2] . "\nfor " .
$data[0] . "\n at " . $data[1] . " for your order";
GtkPizza::do_message_box($msg);
return;
}
} else {
# no suburb - create one on the fly
$sql = q{insert into suburbs (suburb,ubd,store_id,deliv_charge)
values (?,?,?,?)};
$sth = $GtkPizza::db->db_sql($sql,$suburb, $ubd, $GtkPizza::current_store, $deliv);
$GtkPizza::db->db_done($sth);
}

$GtkPizza::customer_number = GtkPizza::get_new_customer_number();

# sort out UBD code
if ($ubd eq '') {
$sql = q{select ubd from suburbs where suburb = ?};
$sth = $GtkPizza::db->db_sql($sql,$suburb);
@data = $GtkPizza::db->db_fetch($sth);
$GtkPizza::db->db_done($sth);
$ubd = $data[0];
}

# create new customer
$sql = q{insert into customers (custnum,custname,address,phone,
suburb,ubd,comments,bad_cust,discount,deliv_charge)
values (?,?,?,?,?,?,?,?,?,?)};
$sth = $GtkPizza::db->db_sql($sql,$GtkPizza::customer_number,
$name,
$address,
$phone,
$suburb_text,
$ubd,
$comments,
$bad?'t':'f',
$disc,
$deliv
);
$GtkPizza::db->db_done($sth);
} else {
# update the customer
# sort out the suburb
$sql = q{select store_id from suburbs where suburb = ?};
$sth = $GtkPizza::db->db_sql($sql,$suburb);
@data = $GtkPizza::db->db_fetch($sth);
$r = $GtkPizza::db->db_rows($sth);
$GtkPizza::db->db_done($sth);
if ($r) {
$sub_store = $data[0];
if ($sub_store != $GtkPizza::current_store) {
# found out which store then
$sql = q{select store_name,suburb,phone from stores where id = ?};
$sth = $GtkPizza::db->db_sql($sql,$sub_store);
@data = $GtkPizza::db->db_fetch($sth);
$GtkPizza::db->db_done($sth);
my $msg = "Please call: " . $data[2] . "\nfor " .
$data[0] . "\n at " . $data[1] . " for your order";
GtkPizza::do_message_box($msg);
return;
}
} else {
# no suburb - create one on the fly
$sql = q{insert into suburbs (suburb,ubd,store_id,deliv_charge)
values (?,?,?,?)};
$sth = $GtkPizza::db->db_sql($sql,$suburb, $ubd, $GtkPizza::current_store, $deliv);
$GtkPizza::db->db_done($sth);
}
# sort out UBD code
if ($ubd eq '') {
$sql = q{select ubd from suburbs where suburb = ?};
$sth = $GtkPizza::db->db_sql($sql, $suburb);
@data = $GtkPizza::db->db_fetch($sth);
$GtkPizza::db->db_done($sth);
$ubd = $data[0];
}

#update customer
$sql = q{update customers set custname = ?,address = ?,phone = ?,
suburb = ?,ubd = ?,comments = ?,bad_cust = ?,
discount = ?, deliv_charge = ? where custnum = ?};
$sth = $GtkPizza::db->db_sql($sql,$name,
$address,
$phone,
$suburb_text,
$ubd,
$comments,
$bad?'t':'f',
$disc,
$deliv,
$GtkPizza::customer_number
);
$GtkPizza::db->db_done($sth);
}
GtkPizza::docket_screen_hide();
$GtkPizza::MyXML->get_widget('customer_screen')->hide();
if (!$GtkPizza::from_order) {
GtkPizza::order_screen_new(0,$GtkPizza::customer_number);
}
}
1;


Valid HTML 4.01!
Content owned by Albacore Technology is copyright 1999-2000 Albacore Technology, LLC All rights reserved.