Added POS and cash sale support.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 31 Oct 2008 18:19:09 +0000 (18:19 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 31 Oct 2008 18:19:09 +0000 (18:19 +0000)
12 files changed:
admin/db/users_db.inc
admin/users.php
applications/setup.php
includes/current_user.inc
includes/ui/ui_lists.inc
sales/includes/cart_class.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/db/sales_order_db.inc
sales/includes/sales_db.inc
sales/includes/ui/sales_order_ui.inc
sales/sales_order_entry.php
sql/alter2.1.sql

index 32f7c88c55a3a566b01123916327f45d80193361..8580733fcf3fdd84036e6e6cdc6e90f41032bbdc 100644 (file)
@@ -1,13 +1,14 @@
 <?php
 
 function add_user($user_id, $real_name, $password, $phone, $email, $full_access, 
-       $language, $profile, $rep_popup)
+       $language, $profile, $rep_popup, $pos)
 {
-       $sql = "INSERT INTO ".TB_PREF."users (user_id, real_name, password, phone, email, full_access, language, print_profile)
+       $sql = "INSERT INTO ".TB_PREF."users (user_id, real_name, password"
+               .", phone, email, full_access, language, pos, print_profile, rep_popup)
                VALUES (".db_escape($user_id).", 
                ".db_escape($real_name).", ".db_escape($password) .",".db_escape($phone).",
                 ".db_escape($email).", $full_access, ".db_escape($language).",
-                ".db_escape($profile).", rep_popup=$rep_popup)";
+                $pos,".db_escape($profile).",$rep_popup)";
 
        db_query($sql, "could not add user for $user_id");
 }
@@ -25,7 +26,7 @@ function update_user_password($user_id, $password)
 //-----------------------------------------------------------------------------------------------
 
 function update_user($user_id, $real_name, $phone, $email, $full_access, 
-       $language, $profile, $rep_popup)
+       $language, $profile, $rep_popup, $pos)
 {
        $sql = "UPDATE ".TB_PREF."users SET real_name=".db_escape($real_name).
        ", phone=".db_escape($phone).",
@@ -33,7 +34,8 @@ function update_user($user_id, $real_name, $phone, $email, $full_access,
                full_access=$full_access,
                language=".db_escape($language).",
                print_profile=".db_escape($profile).",
-               rep_popup=$rep_popup
+               rep_popup=$rep_popup,
+               pos=$pos
                WHERE user_id = ".db_escape($user_id);
        db_query($sql, "could not update user for $user_id");
 }
index 889d89ba24845bd98ec006a9f7b32ca73749b0e4..05e9adc973b406c414626dbd844f64d106a772da 100644 (file)
@@ -55,7 +55,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
        {
                update_user($_POST['user_id'], $_POST['real_name'], $_POST['phone'],
                        $_POST['email'], $_POST['Access'], $_POST['language'], 
-                               $_POST['profile'], check_value('rep_popup'));
+                               $_POST['profile'], check_value('rep_popup'), $_POST['pos']);
 
                if ($_POST['password'] != "")
                        update_user_password($_POST['user_id'], md5($_POST['password']));
@@ -66,7 +66,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
        {
                add_user($_POST['user_id'], $_POST['real_name'], md5($_POST['password']),
                                $_POST['phone'], $_POST['email'], $_POST['Access'], $_POST['language'],
-                               $_POST['profile'], check_value('rep_popup'));
+                               $_POST['profile'], check_value('rep_popup'), $_POST['pos']);
 
                        display_notification_centered(_("A new user has been added."));
        }
@@ -151,6 +151,7 @@ if ($selected_id != '')
                $_POST['language'] = $myrow["language"];
                $_POST['profile'] = $myrow["print_profile"];
                $_POST['rep_popup'] = $myrow["rep_popup"];
+               $_POST['pos'] = $myrow["pos"];
        }
        hidden('selected_id', $selected_id);
        hidden('user_id');
@@ -184,6 +185,8 @@ security_headings_list_row(_("Access Level:"), 'Access', null);
 
 languages_list_row(_("Language:"), 'language', null);
 
+pos_list_row(_("User's POS"). ':', 'pos', null);
+
 print_profiles_list_row(_("Printing profile"). ':', 'profile', null,
        _('Browser printing support'));
 
index b1e4dbf08a942525f745aa02cb9b516f5087d891..95164fd2f023ca16c8873b1728cd4e88fefb6238 100644 (file)
@@ -24,6 +24,7 @@
                        $this->add_module(_("Miscellaneous"));
                        $this->add_lapp_function(1, _("Pa&yment Terms"),"admin/payment_terms.php?");
                        $this->add_lapp_function(1, _("Shi&pping Company"),"admin/shipping_companies.php?");
+                       $this->add_rapp_function(1, _("&Points of Sale"),"sales/manage/sales_points.php?");
                        $this->add_rapp_function(1, _("&Printers"),"admin/printers.php?");
 
                        $this->add_module(_("Maintanance"));
index 05b98800643be3190a59d21175450dd77377b5a4..0e7a4a878091330b7cfa3564e11cb03d971a4b9d 100644 (file)
@@ -11,6 +11,7 @@ class current_user
        var $username;
        var     $name;
        var $company;
+       var $pos;
        var $access;
 
        var $logged;
@@ -48,6 +49,7 @@ class current_user
 
                    $this->access = $myrow["full_access"];
                    $this->name = $myrow["real_name"];
+                   $this->pos = $myrow["pos"];
                    $this->loginname = $loginname;
                    $this->username = $this->loginname;
                    $this->prefs = new user_prefs($myrow);
@@ -182,6 +184,11 @@ function user_company()
        return $_SESSION["wa_current_user"]->company;
 }
 
+function user_pos()
+{
+       return $_SESSION["wa_current_user"]->pos;
+}
+
 function user_language()
 {
        return $_SESSION["wa_current_user"]->prefs->language();
index e53d0eb23f4499631d182bc5ec30e8e943994a92..6b9d714d504787d877bbf5ba0a7e25bdf1857bfc 100644 (file)
@@ -1225,7 +1225,61 @@ function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_cha
        echo "</tr>\n";
        return $str;
 }
+//-----------------------------------------------------------------------------------------------
+
+function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
+{
+       $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
+               FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
+               WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code"
+               . " AND ".TB_PREF."bank_accounts.account_type=3";
+
+       if ($label != null)
+               echo "<tr><td>$label</td>\n";
+       echo "<td>";
+       $str = combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
+       array(
+               'format' => '_format_add_curr',
+               'select_submit'=> $submit_on_change,
+               'async' => true
+       ) );
+       echo "</td></tr>\n";
+       return $str;
+}
+//-----------------------------------------------------------------------------------------------
+
+function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
+{
+       $sql = "SELECT id, pos_name FROM ".TB_PREF."sales_pos";
+
+       default_focus($name);
+       echo '<tr>';
+       if ($label != null)
+               echo "<td>$label</td>\n";
+       echo "<td>";
+
+       $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
+       array(
+               'select_submit'=> $submit_on_change,
+               'async' => true,
+               'spec_option' =>$spec_option,
+               'spec_id' => -1,
+       ) );
+       echo "</td></tr>\n";
 
+       return $str;    
+}
+//-----------------------------------------------------------------------------------------------
+
+function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
+{
+       if ($label != null)
+               echo "<td>$label</td>\n";
+       echo "<td>";
+       $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
+       echo "</td>\n";
+       return $str;
+}
 //-----------------------------------------------------------------------------------------------
 
 function class_list($name, $selected_id=null, $submit_on_change=false)
index 78cf46a88f0712d84a72e3c55588980a94ad98a8..991139121954c66d6be78e232dc34bf40a840e08 100644 (file)
@@ -55,6 +55,12 @@ class cart
        var $tax_group_name;
        var $tax_group_array = null; // saves db queries
        var $price_factor;       // ditto for price calculations
+
+       var     $pos;                   // user assigned POS
+       var $cash;                      // cash transaction
+       var $cash_account;
+       var $account_name;
+       var $cash_discount;     // not used as of FA 2.1
        //-------------------------------------------------------------------------
        //
        //  $trans_no==0 => open new/direct document
@@ -135,10 +141,23 @@ class cart
                                if (!is_date_in_fiscalyear($this->document_date))
                                        $this->document_date = end_fiscalyear();
                                $this->reference = references::get_next($this->trans_type);
-                               if ($type == 10)
+                               if ($type == 10) {
                                  $this->due_date =
                                        get_invoice_duedate($this->customer_id, $this->document_date);
-                               else
+                                 $this->pos = user_pos();
+                                 $pos = get_sales_point($this->pos);
+                                 $this->cash = !$pos['credit_sale'];
+                                 if (!$pos['cash_sale'] || !$pos['credit_sale']) 
+                                       $this->pos = -1; // mark not editable payment type
+                                 else
+                                       $this->cash = date_diff($this->due_date, Today(), 'd')<2;
+                               if ($this->cash) {
+                                       $this->Location = $pos['pos_location'];
+                                       $this->location_name = $pos['location_name'];
+                                       $this->cash_account = $pos['account_code'];
+                                       $this->account_name = $pos['bank_account_name'];
+                               }
+                               } else
                                  $this->due_date =
                                        add_days($this->document_date, sys_prefs::default_delivery_required_by());
                        }
@@ -193,11 +212,12 @@ class cart
                }
        }
 
-       function set_customer($customer_id, $customer_name, $currency, $discount)
+       function set_customer($customer_id, $customer_name, $currency, $discount, $cdiscount=0)
        {
                $this->customer_name = $customer_name;
                $this->customer_id = $customer_id;
                $this->default_discount = $discount;
+               $this->cash_discount = $cdiscount;
                $this->customer_currency = $currency;
        }
 
index c4303fc60561f2b14ae2b3bba9d1217c8a1d859f..e63ce8427423217f85e9d6b5fcd08f7dafb1c7ae 100644 (file)
@@ -148,8 +148,21 @@ function write_sales_invoice(&$invoice)
 
        if ($trans_no == 0) {
                references::save_last($invoice->reference, 10);
+               if ($invoice->cash) {
+                       $amount = $items_total + $items_added_tax + $invoice->freight_cost 
+                               + $freight_added_tax;
+
+                       // to use debtors.pmt_discount on cash sale:
+                       // extend invoice entry page with final amount after discount 
+                       // and change line below.
+                       $discount = 0; // $invoice->cash_discount*$amount;
+                       $pmtno = write_customer_payment(0, $invoice->customer_id, 
+                               $invoice->Branch, $invoice->cash_account, $date_, 1,
+                               references::get_next(12), $amount-$discount, $discount,
+                               _('Cash invoice').' '.$invoice->trans_no);
+                       add_cust_allocation($amount, 12, $pmtno, 10, $invoice_no);
+               }
        }
-
        commit_transaction();
 
        return $invoice_no;
index 34e4ad9d89b3c0ed8e1a74f95910a3db1d9bc179..25e39abf579fb66c7da65065ffd856a96d810421 100644 (file)
@@ -60,7 +60,7 @@ function add_sales_order(&$order)
                        db_escape($order->Comments) .",'" . 
                        date2sql($order->document_date) . "', " .
                        db_escape($order->sales_type) . ", " .
-                       $_POST['ship_via'] ."," . 
+                       db_escape($order->ship_via)."," . 
                        db_escape($order->deliver_to) . "," .
                        db_escape($order->delivery_address) . ", " .
                        db_escape($order->phone) . ", " . 
@@ -454,7 +454,8 @@ function get_customer_to_order($customer_id) {
                  .TB_PREF."sales_types.tax_included, "
                  .TB_PREF."sales_types.factor, "
                  .TB_PREF."debtors_master.curr_code, "
-                 .TB_PREF."debtors_master.discount
+                 .TB_PREF."debtors_master.discount,"
+                 .TB_PREF."debtors_master.pymt_discount
                FROM ".TB_PREF."debtors_master, "
                  .TB_PREF."credit_status, "
                  .TB_PREF."sales_types
index 5c4fffdb763b9d907731d531521448f609101c1e..4f98c78fc6ab5df0774ae38db8edd43026f9c213 100644 (file)
@@ -7,6 +7,7 @@ include_once($path_to_root . "/sales/includes/db/sales_credit_db.inc");
 include_once($path_to_root . "/sales/includes/db/sales_invoice_db.inc");
 include_once($path_to_root . "/sales/includes/db/sales_delivery_db.inc");
 include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
+include_once($path_to_root . "/sales/includes/db/sales_points_db.inc");
 include_once($path_to_root . "/sales/includes/db/custalloc_db.inc");
 include_once($path_to_root . "/sales/includes/db/cust_trans_db.inc");
 include_once($path_to_root . "/sales/includes/db/cust_trans_details_db.inc");
index 2b2b028465ea5d045677f52ec424a38fa8f3bd29..ae2bd96471b46aa8bf830d7d441d5f667f80da56 100644 (file)
@@ -34,38 +34,44 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id)
 
        $deliver = $myrow['address']; // in case no delivery address.
 
-       $order->set_customer($customer_id, $name, $myrow['curr_code'], $myrow['discount']);
+       $order->set_customer($customer_id, $name, $myrow['curr_code'], 
+               $myrow['discount'], $myrow['pymt_discount']);
 
        // the sales type determines the price list to be used by default
        $order->set_sales_type($myrow['salestype'], $myrow['sales_type'], $myrow['tax_included'],
            $myrow['factor']);
 
-//     if ($order->Branch != 0)
-       {
-               $result = get_branch_to_order($customer_id, $branch_id);
+       $result = get_branch_to_order($customer_id, $branch_id);
 
-               if (db_num_rows($result) == 0)
-               {
+       if (db_num_rows($result) == 0)
+       {
                return _("The selected customer and branch are not valid, or the customer does not have any branches.");
-               }
-
-               $myrow = db_fetch($result);
+       }
 
-               $order->set_branch($branch_id, $myrow["tax_group_id"],
-               $myrow["tax_group_name"], $myrow["phone"], $myrow["email"]);
+       $myrow = db_fetch($result);
 
-               $address = $myrow["br_post_address"];
+       $order->set_branch($branch_id, $myrow["tax_group_id"],
+       $myrow["tax_group_name"], $myrow["phone"], $myrow["email"]);
 
-               if (strlen($address) <= 1)      // if branch has no address
-                       $address = $deliver;    // set sales order address
+       $address = $myrow["br_post_address"];
 
-               $order->set_location($myrow["default_location"], $myrow["location_name"]);
-               $order->set_delivery($myrow["default_ship_via"], $myrow["br_name"],
+       if (strlen($address) <= 1)      // if branch has no address
+               $address = $deliver;    // set sales order address
+       $order->set_delivery($myrow["default_ship_via"], $myrow["br_name"],
                $address);
-               if ($order->trans_type == 10)
-                       $order->due_date = get_invoice_duedate($customer_id, $order->document_date);
+       if ($order->trans_type == 10) {
+               $order->due_date = get_invoice_duedate($customer_id, $order->document_date);
+               if ($order->pos != -1)
+                       $order->cash = date_diff($order->due_date, Today(), 'd')<2;
        }
-
+       if($order->cash ) {
+               if($order->pos != -1) {
+               $paym = get_sales_point($order->pos);
+               $order->set_location($paym["pos_location"], $paym["location_name"]);
+               }
+       } else
+               $order->set_location($myrow["default_location"], $myrow["location_name"]);
+               
        return $ret_error;
 }
 
@@ -73,7 +79,7 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id)
 
 function display_order_summary($title, &$order, $editable_items=false)
 {
-       global $table_style, $path_to_root, $Ajax;
+       global $table_style, $path_to_root;
 
        display_heading($title);
 
@@ -205,6 +211,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
                                $_POST['deliver_to'] = $order->deliver_to;
                                $_POST['delivery_address'] = $order->delivery_address;
                                $_POST['phone'] = $order->phone;
+                               $_POST['cash'] = $order->cash;
                                if ($order->trans_type == 10)
                                {
                                        $_POST['delivery_date'] = $order->due_date;
@@ -214,6 +221,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
                                $Ajax->activate('deliver_to');
                                $Ajax->activate('phone');
                                $Ajax->activate('delivery_address');
+                               $Ajax->activate('cash');
                                // change prices if necessary
                                // what about discount in template case?
                                if ($old_order->customer_currency != $order->customer_currency) {
@@ -253,6 +261,26 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
 
 
        echo "<table height='5'>";
+       if ($order->trans_type == 10 && $order->pos != -1) {
+               sale_payment_list_cells(_('Payment:'), 'cash', null, true);
+               $cash_payment = get_post('cash', 0);
+               // current user can issue both credit and cash invoices
+               if ($order->cash != $cash_payment) {
+                       $order->cash = $cash_payment;
+                       if ($cash_payment) {
+                               $paym = get_sales_point(user_pos());
+                               $order->cash_account = $paym['pos_account'];
+                               $order->account_name = $paym['bank_account_name'];
+                               $_POST['Location'] = $order->Location = $paym['pos_location'];
+                               $order->location_name = $paym['location_name'];
+                       }
+                       check_qoh($order);
+                       $Ajax->activate('delivery');
+                       set_focus($order->pos == -1 ? 'delivery_date' : 'account');
+               }
+       } else
+               hidden('cash', $order->cash);
+
        if($editable) {
                $str = sales_types_list_row(_("Price List"), 'sales_type', null, true);
        } else {
@@ -403,61 +431,95 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
 
 function display_delivery_details(&$order)
 {
-       global $table_style2;
-       if ($order->trans_type==10)
-       {
-               $title = _("Delivery Details");
-               $delname = _("Due Date").':';
-       }
-       elseif ($order->trans_type==13)
-       {
-               $title = _("Invoice Delivery Details");
-               $delname = _("Invoice before").':';
-       }
-       else
-       {
-               $title = _("Order Delivery Details");
-               $delname = _("Required Delivery Date").':';
-       }
-       display_heading($title);
-       echo "<br>";
-       start_table("$table_style2 width=90%");
-       echo "<tr valign=top><td>"; // outer table
-
-       echo "<table>";
-
-       locations_list_row(_("Deliver from Location:"), 'Location', $order->Location);
-
-       date_row($delname, 'delivery_date',
-           _('Enter requested day of delivery'), $order->due_date, 0, 0, 0);
+       global $table_style2, $Ajax;
 
-       text_row(_("Deliver To:"), 'deliver_to', $order->deliver_to, 40, 40,
-       _('Additional identifier for delivery e.g. name of receiving person'));
+div_start('delivery'); 
 
-       textarea_row(_("Address:"), 'delivery_address', $order->delivery_address, 35, 5,
-       _('Delivery address. Default is address of customer branch'));
-       text_row(_("Contact Phone Number:"), 'phone', $order->phone, 25, 25,
-           _('Phone number of ordering person. Defaults to branch phone number'));
+       if (get_post('cash', 0)) {      // Direct payment sale
+               display_heading(_('Cash payment'));
+               echo "<table $table_style2 width=60% align=center>";
+               label_row(_("Deliver from Location:"), $order->location_name);
 
-       echo "</table>";
+               hidden('Location', $order->Location);
+               label_row(_("Cash account:"), $order->account_name);
+               textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5);
+               echo "</table>";
+       } else {
 
-       echo "</td><td>"; // outer table
+               if ($order->trans_type==10)
+               {
+                       $title = _("Delivery Details");
+                       $delname = _("Due Date").':';
+               }
+               elseif ($order->trans_type==13)
+               {
+                       $title = _("Invoice Delivery Details");
+                       $delname = _("Invoice before").':';
+               }
+               else
+               {
+                       $title = _("Order Delivery Details");
+                       $delname = _("Required Delivery Date").':';
+               }
+               display_heading($title);
+               echo "<br>";
+               start_table("$table_style2 width=90%");
+               echo "<tr valign=top><td>"; // outer table
+               echo "<table>";
+
+               locations_list_row(_("Deliver from Location:"), 'Location', null, 
+                       false, true);
+               if (list_updated('Location'))
+                       check_qoh($order);
+
+               date_row($delname, 'delivery_date',
+                       $order->trans_type==30 ?  _('Enter requested day of delivery') : '', 
+                       $order->due_date, 0, 0, 0);
+               text_row(_("Deliver To:"), 'deliver_to', $order->deliver_to, 40, 40,
+                       _('Additional identifier for delivery e.g. name of receiving person'));
+
+               textarea_row(_("Address:"), 'delivery_address', $order->delivery_address, 35, 5,
+                       _('Delivery address. Default is address of customer branch'));
+               text_row(_("Contact Phone Number:"), 'phone', $order->phone, 25, 25,
+                   _('Phone number of ordering person. Defaults to branch phone number'));
 
-       echo "<table>";
+               echo "</table>";
 
-       text_row(_("Customer Reference:"), 'cust_ref', $order->cust_ref, 25, 25,
-         _('Customer reference number for this order (if any)'));
-       textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5);
+               echo "</td><td>"; // outer table
 
-       small_amount_row(_("Shipping Charge:"), 'freight_cost',
-           price_format(get_post('freight_cost',0)));
+               echo "<table>";
 
-       shippers_list_row(_("Shipping Company:"), 'ship_via', $order->ship_via);
+               text_row(_("Customer Reference:"), 'cust_ref', $order->cust_ref, 25, 25,
+                 _('Customer reference number for this order (if any)'));
+               textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5);
 
-       echo "</table>";
+               small_amount_row(_("Shipping Charge:"), 'freight_cost',
+               price_format(get_post('freight_cost',0)));
 
-       echo "</td></tr>";
-       end_table(1); // outer table
+               shippers_list_row(_("Shipping Company:"), 'ship_via', $order->ship_via);
+               echo "</table>";
+               echo "</td></tr>";
+               end_table(1); // outer table
+       }
+       div_end();
 }
 
+function check_qoh($order) 
+{
+       $msg = '';
+       foreach($order->line_items as $line_no => $line) {
+               $qoh = get_qoh_on_date($line->stock_id, $_POST['Location'], $_POST['OrderDate']);
+               if ($line->qty_dispatched > $qoh)       {
+                       $msg .= $line->stock_id . " - " . $line->item_description . ": " .
+                               _("Quantity On Hand") . " = " 
+                               . number_format2($qoh, get_qty_dec($line->stock_id)) . '<br>';
+               }
+       }
+       if (strlen($msg)) {
+               display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:")
+                       . '<br>'. $msg);
+               return false;
+       }
+       return true;
+}
 ?>
\ No newline at end of file
index edfc3455daccecc1e94a15db82ac0ee3a54d515b..3017f0221a9b502a6769bf5292a4d0155e46f66a 100644 (file)
@@ -143,19 +143,28 @@ function copy_to_cart()
 
        if ($cart->trans_type!=30) {
                $cart->reference = $_POST['ref'];
-       }
+       } 
        $cart->Comments =  $_POST['Comments'];
 
        $cart->document_date = $_POST['OrderDate'];
-       $cart->due_date = $_POST['delivery_date'];
-       $cart->cust_ref = $_POST['cust_ref'];
-       $cart->freight_cost = input_num('freight_cost');
-       $cart->deliver_to = $_POST['deliver_to'];
-       $cart->delivery_address = $_POST['delivery_address'];
-       $cart->phone = $_POST['phone'];
-       $cart->Location = $_POST['Location'];
-       $cart->ship_via = $_POST['ship_via'];
-
+       if ($cart->trans_type == 10)
+               $cart->cash = $_POST['cash']; 
+       if ($cart->cash) {
+               $cart->due_date = $cart->document_date;
+               $cart->phone = $cart->cust_ref = $cart->delivery_address = '';
+               $cart->freight_cost = 0;
+               $cart->ship_via = 1;
+               $cart->deliver_to = '';//$_POST['deliver_to'];
+       } else {
+               $cart->due_date = $_POST['delivery_date'];
+               $cart->cust_ref = $_POST['cust_ref'];
+               $cart->freight_cost = input_num('freight_cost');
+               $cart->deliver_to = $_POST['deliver_to'];
+               $cart->delivery_address = $_POST['delivery_address'];
+               $cart->phone = $_POST['phone'];
+               $cart->Location = $_POST['Location'];
+               $cart->ship_via = $_POST['ship_via'];
+       }
        if (isset($_POST['email']))
                $cart->email =$_POST['email'];
        else
@@ -163,6 +172,7 @@ function copy_to_cart()
        $cart->customer_id      = $_POST['customer_id'];
        $cart->Branch = $_POST['branch_id'];
        $cart->sales_type = $_POST['sales_type'];
+       // POS 
 }
 
 //-----------------------------------------------------------------------------
@@ -190,6 +200,9 @@ function copy_from_cart()
 
        $_POST['branch_id'] = $cart->Branch;
        $_POST['sales_type'] = $cart->sales_type;
+       // POS 
+       if ($cart->trans_type == 10)
+               $_POST['cash'] = $cart->cash;
 }
 //--------------------------------------------------------------------------------
 
@@ -217,35 +230,38 @@ function can_process() {
                set_focus('AddItem');
                return false;
        }
+       if ($_SESSION['Items']->cash == 0) {
        if (strlen($_POST['deliver_to']) <= 1) {
                display_error(_("You must enter the person or company to whom delivery should be made to."));
                set_focus('deliver_to');
                return false;
        }
-       if (strlen($_POST['delivery_address']) <= 1) {
-               display_error( _("You should enter the street address in the box provided. Orders cannot be accepted without a valid street address."));
-               set_focus('delivery_address');
-               return false;
-       }
 
-       if ($_POST['freight_cost'] == "")
-               $_POST['freight_cost'] = price_format(0);
+               if (strlen($_POST['delivery_address']) <= 1) {
+                       display_error( _("You should enter the street address in the box provided. Orders cannot be accepted without a valid street address."));
+                       set_focus('delivery_address');
+                       return false;
+               }
 
-       if (!check_num('freight_cost',0)) {
-               display_error(_("The shipping cost entered is expected to be numeric."));
-               set_focus('freight_cost');
-               return false;
-       }
-       if (!is_date($_POST['delivery_date'])) {
-               display_error(_("The delivery date is invalid."));
-               set_focus('delivery_date');
-               return false;
-       }
-       //if (date1_greater_date2($_SESSION['Items']->document_date, $_POST['delivery_date'])) {
-       if (date1_greater_date2($_POST['OrderDate'], $_POST['delivery_date'])) {
-               display_error(_("The requested delivery date is before the date of the order."));
-               set_focus('delivery_date');
-               return false;
+               if ($_POST['freight_cost'] == "")
+                       $_POST['freight_cost'] = price_format(0);
+
+               if (!check_num('freight_cost',0)) {
+                       display_error(_("The shipping cost entered is expected to be numeric."));
+                       set_focus('freight_cost');
+                       return false;
+               }
+               if (!is_date($_POST['delivery_date'])) {
+                       display_error(_("The delivery date is invalid."));
+                       set_focus('delivery_date');
+                       return false;
+               }
+               //if (date1_greater_date2($_SESSION['Items']->document_date, $_POST['delivery_date'])) {
+               if (date1_greater_date2($_POST['OrderDate'], $_POST['delivery_date'])) {
+                       display_error(_("The requested delivery date is before the date of the order."));
+                       set_focus('delivery_date');
+                       return false;
+               }
        }
        if ($_SESSION['Items']->trans_type != 30 && !references::is_valid($_POST['ref'])) {
                display_error(_("You must enter a reference."));
@@ -409,9 +425,16 @@ function create_cart($type, $trans_no)
                $doc->trans_type = $type;
                $doc->trans_no = 0;
                $doc->document_date = Today(); // 2006-06-15. Added so Invoices and Deliveries get current day
-               if ($type == 10)
+               if ($type == 10) {
                        $doc->due_date = get_invoice_duedate($doc->customer_id, $doc->document_date);
-               else
+                       $doc->pos = user_pos();
+                       $pos = get_sales_point($doc->pos);
+                       $doc->cash = $pos['cash_sale'];
+                       if (!$pos['cash_sale'] || !$pos['credit_sale']) 
+                               $doc->pos = -1; // mark not editable payment type
+                       else
+                               $doc->cash = date_diff($doc->due_date, Today(), 'd')<2;
+               } else
                        $doc->due_date = $doc->document_date;
                $doc->reference = references::get_next($doc->trans_type);
                $doc->Comments='';
index 85127db6931d7b108e7162083b6e3b0242e57b30..2fe22c858fe3b00d0724c8a3050dccbd39775be7 100644 (file)
@@ -1,3 +1,21 @@
+DROP TABLE IF EXISTS `0_sales_pos`;
+
+CREATE TABLE `0_sales_pos` (
+  `id` smallint(6) NOT NULL auto_increment,
+  `pos_name` varchar(30) NOT NULL,
+  `cash_sale` tinyint(1) NOT NULL,
+  `credit_sale` tinyint(1) NOT NULL,
+  `pos_location` varchar(5) NOT NULL,
+  `pos_account` varchar(11) NOT NULL,
+  PRIMARY KEY  (`id`),
+  UNIQUE KEY(`pos_name`)
+) ENGINE=MyISAM AUTO_INCREMENT=3;
+
+INSERT INTO `0_sales_pos` VALUES ('1', 'Default', '1', '1', 'DEF', '1705');
+INSERT INTO `0_sales_pos` VALUES ('2', 'Cash sale', '1', '0', 'CWA', '1705');
+
+ALTER TABLE `0_users` ADD `pos` SMALLINT(6) DEFAULT '1';
+
 DROP TABLE IF EXISTS `0_quick_entries`;
 
 CREATE TABLE `0_quick_entries` (
@@ -13,7 +31,6 @@ INSERT INTO `0_quick_entries` VALUES ('1', 'Maintenance', '6600', '0');
 INSERT INTO `0_quick_entries` VALUES ('2', 'Phone', '6730', '0');
 INSERT INTO `0_quick_entries` VALUES ('3', 'Cash Sales', '3000', '1');
 
-
 ALTER TABLE `0_users` ADD `print_profile` VARCHAR(30) DEFAULT '' AFTER `show_hints` ;
 ALTER TABLE `0_users` ADD `rep_popup` TINYINT(1) DEFAULT '1' AFTER `print_profile` ;