mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-13 00:12:43 -04:00
For #3698. I'm pleased to announce that this set of changes seems to allow a simple order to be completed.
This commit is contained in:
@@ -634,10 +634,9 @@ class Sales extends Secure_Controller
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function complete(): void //TODO: this function is huge. Probably should be refactored.
|
||||
public function postComplete(): void //TODO: this function is huge. Probably should be refactored.
|
||||
{
|
||||
$sale_id = $this->sale_lib->get_sale_id();
|
||||
$sale_type = $this->sale_lib->get_sale_type(); //TODO: This variable gets overwritten way down below before being used.
|
||||
$data = [];
|
||||
$data['dinner_table'] = $this->sale_lib->get_dinner_table();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class Migration_add_missing_config extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
$image_values = [
|
||||
['key' => 'account_number', 'value' => ''], // This has no current maintenance, but it's used in Sales
|
||||
['key' => 'category_dropdown', 'value' => ''],
|
||||
['key' => 'smtp_host', 'value' => ''],
|
||||
['key' => 'smtp_user', 'value' => ''],
|
||||
|
||||
@@ -313,7 +313,7 @@ function tax_decimals(): int
|
||||
function to_date(int $date = DEFAULT_DATE): string
|
||||
{
|
||||
$config = config('OSPOS')->settings;
|
||||
return date($config['dateformat, $date']);
|
||||
return date($config['dateformat'], $date);
|
||||
}
|
||||
|
||||
function to_datetime(int $datetime = DEFAULT_DATETIME): string
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\Libraries;
|
||||
namespace App\Libraries;
|
||||
|
||||
use Exception;
|
||||
use Picqer\Barcode\BarcodeGeneratorPNG;
|
||||
use App\Libraries\Barcodes\Code39;
|
||||
use App\Libraries\Barcodes\Code128;
|
||||
use App\Libraries\Barcodes\Ean8;
|
||||
use App\Libraries\Barcodes\Ean13;
|
||||
|
||||
/**
|
||||
* Barcode library
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* Minimum Requirement: PHP 5.3.0
|
||||
*/
|
||||
|
||||
namespace emberlabs\Barcode;
|
||||
namespace App\Libraries\Barcodes;
|
||||
|
||||
/**
|
||||
* emberlabs Barcode Creator - Barcode Base
|
||||
@@ -214,4 +214,4 @@ abstract class BarcodeBase
|
||||
return base64_encode(ob_get_clean());
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@@ -9,7 +9,7 @@
|
||||
* Minimum Requirement: PHP 5.3.0
|
||||
*/
|
||||
|
||||
namespace emberlabs\Barcode;
|
||||
namespace App\Libraries\Barcodes;
|
||||
|
||||
/**
|
||||
* emberlabs Barcode Creator - Code128
|
||||
@@ -322,4 +322,4 @@ class Code128 extends BarcodeBase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@@ -9,7 +9,7 @@
|
||||
* Minimum Requirement: PHP 5.3.0
|
||||
*/
|
||||
|
||||
namespace emberlabs\Barcode;
|
||||
namespace App\Libraries\Barcodes;
|
||||
|
||||
/**
|
||||
* emberlabs Barcode Creator - Code39
|
||||
@@ -181,4 +181,4 @@ class Code39 extends BarcodeBase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@@ -30,7 +30,7 @@
|
||||
* @link http://pear.php.net/package/Image_Barcode2
|
||||
*/
|
||||
|
||||
namespace emberlabs\Barcode;
|
||||
namespace App\Libraries\Barcodes;
|
||||
|
||||
/**
|
||||
* emberlabs Barcode Creator - Ean13
|
||||
@@ -30,7 +30,7 @@
|
||||
* @link http://pear.php.net/package/Image_Barcode2
|
||||
*/
|
||||
|
||||
namespace emberlabs\Barcode;
|
||||
namespace App\Libraries\Barcodes;
|
||||
|
||||
/**
|
||||
* emberlabs Barcode Creator - Ean8
|
||||
@@ -774,7 +774,7 @@ class Sale_lib
|
||||
$this->session->set('sales_giftcard_remainder', $value);
|
||||
}
|
||||
|
||||
public function get_giftcard_remainder(): string
|
||||
public function get_giftcard_remainder(): ?string
|
||||
{
|
||||
return $this->session->get('sales_giftcard_remainder');
|
||||
}
|
||||
@@ -789,7 +789,7 @@ class Sale_lib
|
||||
$this->session->set('sales_rewards_remainder', $value);
|
||||
}
|
||||
|
||||
public function get_rewards_remainder(): string
|
||||
public function get_rewards_remainder(): ?string
|
||||
{
|
||||
return $this->session->get('sales_rewards_remainder');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use CodeIgniter\Database\ResultInterface;
|
||||
use CodeIgniter\Model;
|
||||
use CodeIgniter\Database\RawSql;
|
||||
use DateTime;
|
||||
use stdClass;
|
||||
use ReflectionClass;
|
||||
@@ -683,13 +684,38 @@ class Attribute extends Model
|
||||
|
||||
public function copy_attribute_links(int $item_id, string $sale_receiving_fk, int $id): void
|
||||
{
|
||||
//TODO: this likely needs to be rewritten as two different queries rather than a subquery within a query. Then use query_builder for both.
|
||||
$query = 'INSERT INTO ' . $this->db->prefixTable('attribute_links') . ' (item_id, definition_id, attribute_id, ' . $sale_receiving_fk . ') ';
|
||||
$query .= 'SELECT ' . $this->db->escape($item_id) . ', definition_id, attribute_id, ' . $this->db->escape($id);
|
||||
$query .= 'FROM ' . $this->db->prefixTable('attribute_links');
|
||||
$query .= 'WHERE item_id = ' . $this->db->escape($item_id);
|
||||
|
||||
// ERROR - 2023-04-19 21:39:45 --> mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'item_id = 1 AND sale_id IS NULL AND receiving_id IS NULL' at line 1 in C:\vroots\osposci4\vendor\codeigniter4\framework\system\Database\MySQLi\Connection.php:295
|
||||
//Stack trace:
|
||||
//#0 C:\vroots\osposci4\vendor\codeigniter4\framework\system\Database\MySQLi\Connection.php(295): mysqli->query('INSERT INTO osp...', 0)
|
||||
//#1 C:\vroots\osposci4\vendor\codeigniter4\framework\system\Database\BaseConnection.php(691): CodeIgniter\Database\MySQLi\Connection->execute('INSERT INTO osp...')
|
||||
//#2 C:\vroots\osposci4\vendor\codeigniter4\framework\system\Database\BaseConnection.php(605): CodeIgniter\Database\BaseConnection->simpleQuery('INSERT INTO osp...')
|
||||
//#3 C:\vroots\osposci4\app\Models\Attribute.php(692): CodeIgniter\Database\BaseConnection->query('INSERT INTO osp...')
|
||||
//#4 C:\vroots\osposci4\app\Models\Sale.php(814): App\Models\Attribute->copy_attribute_links(1, 'sale_id', 4)
|
||||
//#5 C:\vroots\osposci4\app\Controllers\Sales.php(874): App\Models\Sale->save_value(4, '0', Array, 2, 1, '', NULL, NULL, NULL, 0, Array, NULL, Array)
|
||||
//#6 C:\vroots\osposci4\vendor\codeigniter4\framework\system\CodeIgniter.php(934): App\Controllers\Sales->postComplete()
|
||||
//#7 C:\vroots\osposci4\vendor\codeigniter4\framework\system\CodeIgniter.php(499): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Sales))
|
||||
//#8 C:\vroots\osposci4\vendor\codeigniter4\framework\system\CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
|
||||
//#9 C:\vroots\osposci4\public\index.php(67): CodeIgniter\CodeIgniter->run()
|
||||
//#10 {main}
|
||||
|
||||
// $this->db->query(
|
||||
// 'INSERT INTO ' . $this->db->dbprefix('attribute_links') . ' (item_id, definition_id, attribute_id, ' . $sale_receiving_fk . ')
|
||||
// SELECT ' . $this->db->escape($item_id) . ', definition_id, attribute_id, ' . $this->db->escape($id) . '
|
||||
// FROM ' . $this->db->dbprefix('attribute_links') . '
|
||||
// WHERE item_id = ' . $this->db->escape($item_id) . ' AND sale_id IS NULL AND receiving_id IS NULL'
|
||||
// );
|
||||
|
||||
|
||||
$query = 'SELECT ' . $this->db->escape($item_id) . ', definition_id, attribute_id, ' . $this->db->escape($id);
|
||||
$query .= ' FROM ' . $this->db->prefixTable('attribute_links');
|
||||
$query .= ' WHERE item_id = ' . $this->db->escape($item_id);
|
||||
$query .=' AND sale_id IS NULL AND receiving_id IS NULL';
|
||||
$this->db->query($query);
|
||||
|
||||
$builder = $this->db->table('attribute_links');
|
||||
$builder->ignore(true)->setQueryAsData(new RawSql($query), null, 'item_id, definition_id, attribute_id, '. $sale_receiving_fk )->insertBatch();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function get_suggestions(int $definition_id, string $term): array
|
||||
|
||||
@@ -45,7 +45,7 @@ class Sale extends Model
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
helper('text');
|
||||
$this->sale_lib = new Sale_lib();
|
||||
}
|
||||
|
||||
@@ -640,8 +640,8 @@ class Sale extends Model
|
||||
* The sales_taxes variable needs to be initialized to an empty array before calling
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function save_value(int $sale_id, string &$sale_status, array &$items, int $customer_id, int $employee_id, string $comment, string $invoice_number,
|
||||
string $work_order_number, string $quote_number, int $sale_type, array $payments, int $dinner_table_id, array &$sales_taxes): int //TODO: this method returns the sale_id but the override is expecting it to return a bool. The signature needs to be reworked. Generally when there are more than 3 maybe 4 parameters, there's a good chance that an object needs to be passed rather than so many params.
|
||||
public function save_value(int $sale_id, string &$sale_status, array &$items, int $customer_id, int $employee_id, string $comment, ?string $invoice_number,
|
||||
?string $work_order_number, ?string $quote_number, int $sale_type, ?array $payments, ?int $dinner_table_id, ?array &$sales_taxes): int //TODO: this method returns the sale_id but the override is expecting it to return a bool. The signature needs to be reworked. Generally when there are more than 3 maybe 4 parameters, there's a good chance that an object needs to be passed rather than so many params.
|
||||
{
|
||||
$config = config('OSPOS')->settings;
|
||||
$attribute = model(Attribute::class);
|
||||
@@ -649,6 +649,7 @@ class Sale extends Model
|
||||
$giftcard = model(Giftcard::class);
|
||||
$inventory = model('Inventory');
|
||||
$item = model(Item::class);
|
||||
|
||||
$item_quantity = model(Item_quantity::class);
|
||||
|
||||
if($sale_id != NEW_ENTRY)
|
||||
@@ -656,8 +657,6 @@ class Sale extends Model
|
||||
$this->clear_suspended_sale_detail($sale_id);
|
||||
}
|
||||
|
||||
$tax_decimals = tax_decimals(); //TODO: $tax_decimals is never used.
|
||||
|
||||
if(count($items) == 0) //TODO: ===
|
||||
{
|
||||
return -1; //TODO: Replace -1 with a constant
|
||||
@@ -679,15 +678,15 @@ class Sale extends Model
|
||||
// Run these queries as a transaction, we want to make sure we do all or nothing
|
||||
$this->db->transStart();
|
||||
|
||||
$builder = $this->db->table('sales');
|
||||
|
||||
if($sale_id == NEW_ENTRY)
|
||||
{
|
||||
$builder = $this->db->table('sales');
|
||||
$builder->insert($sales_data);
|
||||
$sale_id = $this->db->insertID();
|
||||
}
|
||||
else
|
||||
{
|
||||
$builder = $this->db->table('sales');
|
||||
$builder->where('sale_id', $sale_id);
|
||||
$builder->update($sales_data);
|
||||
}
|
||||
@@ -695,8 +694,6 @@ class Sale extends Model
|
||||
$total_amount = 0;
|
||||
$total_amount_used = 0;
|
||||
|
||||
$builder = $this->db->table('sales_payments');
|
||||
|
||||
foreach($payments as $payment_id => $payment)
|
||||
{
|
||||
if(!empty(strstr($payment['payment_type'], lang('Sales.giftcard'))))
|
||||
@@ -722,6 +719,7 @@ class Sale extends Model
|
||||
'employee_id' => $employee_id
|
||||
];
|
||||
|
||||
$builder = $this->db->table('sales_payments');
|
||||
$builder->insert($sales_payments_data);
|
||||
|
||||
$total_amount = floatval($total_amount) + floatval($payment['payment_amount']) - floatval($payment['cash_refund']);
|
||||
@@ -731,8 +729,6 @@ class Sale extends Model
|
||||
|
||||
$customer = $customer->get_info($customer_id);
|
||||
|
||||
$builder = $this->db->table('sales_items');
|
||||
|
||||
foreach($items as $line => $item_data)
|
||||
{
|
||||
$cur_item_info = $item->get_info($item_data['item_id']);
|
||||
@@ -757,6 +753,7 @@ class Sale extends Model
|
||||
'print_option' => $item_data['print_option']
|
||||
];
|
||||
|
||||
$builder = $this->db->table('sales_items');
|
||||
$builder->insert($sales_items_data);
|
||||
|
||||
if($cur_item_info->stock_type == HAS_STOCK && $sale_status == COMPLETED) //TODO: === ?
|
||||
|
||||
@@ -873,12 +873,12 @@ $(document).ready(function()
|
||||
});
|
||||
|
||||
$('#finish_sale_button').click(function() {
|
||||
$('#buttons_form').attr('action', "<?php echo esc(site_url("$controller_name/complete"), 'url') ?>");
|
||||
$('#buttons_form').attr('action', "<?= "$controller_name/complete" ?>");
|
||||
$('#buttons_form').submit();
|
||||
});
|
||||
|
||||
$('#finish_invoice_quote_button').click(function() {
|
||||
$('#buttons_form').attr('action', "<?php echo esc(site_url("$controller_name/complete"), 'url') ?>");
|
||||
$('#buttons_form').attr('action', "<?= "$controller_name/complete" ?>");
|
||||
$('#buttons_form').submit();
|
||||
});
|
||||
|
||||
@@ -1024,7 +1024,7 @@ document.body.onkeyup = function(e)
|
||||
break;
|
||||
case 55: // Alt + 7 Add Payment and Complete Sales/Invoice
|
||||
$("#add_payment_button").click();
|
||||
window.location.href = "<?php echo site_url('sales/complete'); ?>";
|
||||
window.location.href = "<?= 'sales/complete' ?>";
|
||||
break;
|
||||
case 56: // Alt + 8 Finish Quote/Invoice without payment
|
||||
$("#finish_invoice_quote_button").click();
|
||||
|
||||
Reference in New Issue
Block a user