mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-10-09 11:03:14 -04:00
Merge remote-tracking branch 'OpensourcePOS/master' into fix/pr-4361-camelcase
Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com> # Conflicts: # app/Models/Sale.php # tests/phpunit.xml
This commit is contained in:
commit
4917c4a97e
721 files changed
+59621
-41345
No files matched your search
+150
-140
@@ -78,7 +78,8 @@ class Sale extends Model
|
||||
MAX(IFnull(payments.sale_payment_amount, 0)) AS amount_tendered,
|
||||
(MAX(payments.sale_payment_amount)) - ($sale_total) AS change_due,
|
||||
" . '
|
||||
MAX(payments.payment_type) AS payment_type';
|
||||
MAX(payments.payment_type) AS payment_type,
|
||||
MAX(payments.reference_code) AS reference_code';
|
||||
|
||||
$builder = $this->db->table('sales_items AS sales_items');
|
||||
$builder->select($sql);
|
||||
@@ -95,7 +96,7 @@ class Sale extends Model
|
||||
|
||||
$builder->where('sales.sale_id', $sale_id);
|
||||
|
||||
$builder->groupBy('sales.sale_id');
|
||||
$builder->groupBy('sales.sale_id, payments.reference_code');
|
||||
$builder->orderBy('sales.sale_time', 'asc');
|
||||
|
||||
return $builder->get();
|
||||
@@ -179,7 +180,7 @@ class Sale extends Model
|
||||
$builder->join('sales', '`sales_items`.`sale_id` = `' . $db_prefix . 'sales`.`sale_id`', 'inner');
|
||||
$builder->join('people AS customer_p', '`' . $db_prefix . 'sales`.`customer_id` = `customer_p`.`person_id`', 'LEFT');
|
||||
$builder->join('customers AS customer', '`' . $db_prefix . 'sales`.`customer_id` = `customer`.`person_id`', 'LEFT');
|
||||
$builder->join('sales_payments_temp AS payments', '`' . $db_prefix . 'sales`.`sale_id` = `payments`.`sale_id`', 'LEFT OUTER');
|
||||
$builder->join('sales_search_payments_temp AS payments', '`' . $db_prefix . 'sales`.`sale_id` = `payments`.`sale_id`', 'LEFT OUTER');
|
||||
$builder->join(
|
||||
'sales_items_taxes_temp AS sales_items_taxes',
|
||||
'sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line',
|
||||
@@ -210,7 +211,7 @@ class Sale extends Model
|
||||
/**
|
||||
* Get the payment summary for the takings (sales/manage) view
|
||||
*/
|
||||
public function get_payments_summary(?string $search, array $filters): array
|
||||
public function getPaymentsSummary(?string $search, array $filters): array
|
||||
{
|
||||
$config = config(OSPOS::class)->settings;
|
||||
|
||||
@@ -238,6 +239,9 @@ class Sale extends Model
|
||||
$builder->orLike('customer_p.first_name', $search); // Customer first name
|
||||
$builder->orLike('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search); // Customer first and last name
|
||||
$builder->orLike('customer.company_name', $search); // Customer company name
|
||||
if (ctype_digit($search)) {
|
||||
$builder->orWhere('sales.sale_id', $search); // Sale ID
|
||||
}
|
||||
$builder->groupEnd();
|
||||
}
|
||||
}
|
||||
@@ -274,6 +278,18 @@ class Sale extends Model
|
||||
$builder->like('payment_type', lang('Sales.credit'));
|
||||
}
|
||||
|
||||
if ($filters['only_debit']) {
|
||||
$builder->like('payment_type', lang('Sales.debit'));
|
||||
}
|
||||
|
||||
if ($filters['only_bank_transfer']) {
|
||||
$builder->like('payment_type', lang('Sales.bank_transfer'));
|
||||
}
|
||||
|
||||
if ($filters['only_wallet']) {
|
||||
$builder->like('payment_type', lang('Sales.wallet'));
|
||||
}
|
||||
|
||||
$builder->groupBy('payment_type');
|
||||
|
||||
$payments = $builder->get()->getResultArray();
|
||||
@@ -316,7 +332,7 @@ class Sale extends Model
|
||||
{
|
||||
$suggestions = [];
|
||||
|
||||
if (!$this->is_valid_receipt($search)) {
|
||||
if (!$this->isValidReceipt($search)) {
|
||||
$builder = $this->db->table('sales');
|
||||
$builder->distinct()->select('first_name, last_name');
|
||||
$builder->join('people', 'people.person_id = sales.customer_id');
|
||||
@@ -397,21 +413,21 @@ class Sale extends Model
|
||||
/**
|
||||
* Checks if valid receipt
|
||||
*/
|
||||
public function is_valid_receipt(string|null &$receipt_sale_id): bool // TODO: like the others, maybe this should be an array rather than a delimited string... either that or the parameter name needs to be changed. $receipt_sale_id implies that it's an int.
|
||||
public function isValidReceipt(string|null &$receiptSaleId): bool // TODO: like the others, maybe this should be an array rather than a delimited string... either that or the parameter name needs to be changed. $receipt_sale_id implies that it's an int.
|
||||
{
|
||||
$config = config(OSPOS::class)->settings;
|
||||
|
||||
if (!empty($receipt_sale_id)) {
|
||||
if (!empty($receiptSaleId)) {
|
||||
// POS #
|
||||
$pieces = explode(' ', $receipt_sale_id);
|
||||
$pieces = explode(' ', trim($receiptSaleId));
|
||||
|
||||
if (count($pieces) == 2 && preg_match('/(POS)/i', $pieces[0])) {
|
||||
return $this->exists($pieces[1]);
|
||||
if (count($pieces) == 2 && strtoupper($pieces[0]) === 'POS' && ctype_digit($pieces[1])) {
|
||||
return $this->exists((int)$pieces[1]);
|
||||
} elseif ($config['invoice_enable']) {
|
||||
$sale_info = $this->get_sale_by_invoice_number($receipt_sale_id);
|
||||
$saleInfo = $this->get_sale_by_invoice_number($receiptSaleId);
|
||||
|
||||
if ($sale_info->getNumRows() > 0) {
|
||||
$receipt_sale_id = 'POS ' . $sale_info->getRow()->sale_id;
|
||||
if ($saleInfo->getNumRows() > 0) {
|
||||
$receiptSaleId = 'POS ' . $saleInfo->getRow()->sale_id;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -512,7 +528,8 @@ class Sale extends Model
|
||||
'payment_amount' => $paymentAmount,
|
||||
'cash_refund' => $cashRefund,
|
||||
'cash_adjustment' => $cashAdjustment,
|
||||
'employee_id' => $employeeId
|
||||
'employee_id' => $employeeId,
|
||||
'reference_code' => $payment['reference_code'] ?? null,
|
||||
];
|
||||
$success = $builder->insert($salesPaymentsData);
|
||||
} elseif ($paymentId != NEW_ENTRY) {
|
||||
@@ -604,19 +621,19 @@ class Sale extends Model
|
||||
* @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 $saleId,
|
||||
string &$saleStatus,
|
||||
array &$items,
|
||||
int $customerId,
|
||||
int $employeeId,
|
||||
string $comment,
|
||||
?string $invoiceNumber,
|
||||
?string $workOrderNumber,
|
||||
?string $quoteNumber,
|
||||
int $saleType,
|
||||
?array $payments,
|
||||
?int $dinnerTableId,
|
||||
?array &$salesTaxes
|
||||
): 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::class)->settings;
|
||||
$attribute = model(Attribute::class);
|
||||
@@ -625,11 +642,7 @@ class Sale extends Model
|
||||
$inventory = model('Inventory');
|
||||
$item = model(Item::class);
|
||||
|
||||
$item_quantity = model(Item_quantity::class);
|
||||
|
||||
if ($sale_id != NEW_ENTRY) {
|
||||
$this->clear_suspended_sale_detail($sale_id);
|
||||
}
|
||||
$itemQuantity = model(Item_quantity::class);
|
||||
|
||||
if (count($items) == 0) { // TODO: ===
|
||||
return -1; // TODO: Replace -1 with a constant
|
||||
@@ -637,47 +650,63 @@ class Sale extends Model
|
||||
|
||||
$salesData = [
|
||||
'sale_time' => date('Y-m-d H:i:s'),
|
||||
'customer_id' => $customer->exists($customer_id) ? $customer_id : null,
|
||||
'employee_id' => $employee_id,
|
||||
'customer_id' => $customer->exists($customerId) ? $customerId : null,
|
||||
'employee_id' => $employeeId,
|
||||
'comment' => $comment,
|
||||
'sale_status' => $sale_status,
|
||||
'invoice_number' => $invoice_number,
|
||||
'quote_number' => $quote_number,
|
||||
'work_order_number' => $work_order_number,
|
||||
'dinner_table_id' => $dinner_table_id,
|
||||
'sale_type' => $sale_type
|
||||
'sale_status' => $saleStatus,
|
||||
'invoice_number' => $invoiceNumber,
|
||||
'quote_number' => $quoteNumber,
|
||||
'work_order_number' => $workOrderNumber,
|
||||
'dinner_table_id' => $dinnerTableId,
|
||||
'sale_type' => $saleType
|
||||
];
|
||||
|
||||
$this->db->transStart();
|
||||
|
||||
if ($sale_id == NEW_ENTRY) {
|
||||
$builder = $this->db->table('sales');
|
||||
if ($saleId != NEW_ENTRY) {
|
||||
$this->clear_suspended_sale_detail($saleId);
|
||||
}
|
||||
|
||||
$builder = $this->db->table('sales');
|
||||
if ($saleId == NEW_ENTRY) {
|
||||
$builder->insert($salesData);
|
||||
$sale_id = $this->db->insertID();
|
||||
$saleId = $this->db->insertID();
|
||||
} else {
|
||||
$builder = $this->db->table('sales');
|
||||
$builder->where('sale_id', $sale_id);
|
||||
$builder->where('sale_id', $saleId);
|
||||
$builder->update($salesData);
|
||||
}
|
||||
|
||||
$totalAmount = 0;
|
||||
$totalAmountUsed = 0;
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
$totalAmountUsed += $this->processPaymentType(
|
||||
$payment,
|
||||
$customer_id,
|
||||
$customer,
|
||||
$giftcard
|
||||
);
|
||||
foreach ($payments as $paymentId => $payment) {
|
||||
$splitPayment = explode(':', $payment['payment_type'], 2);
|
||||
$paymentPrefix = $splitPayment[0];
|
||||
|
||||
if ($paymentPrefix === lang('Sales.giftcard')) {
|
||||
if (empty($splitPayment[1]) || ! $giftcard->decrementGiftcardValue($splitPayment[1], (float) $payment['payment_amount'])) {
|
||||
$this->db->transRollback();
|
||||
|
||||
return INSUFFICIENT_GIFTCARD_BALANCE;
|
||||
}
|
||||
} elseif ($paymentPrefix === lang('Sales.rewards')) {
|
||||
if (! $customer->adjustRewardPoints($customerId, -(float) $payment['payment_amount'])) {
|
||||
$this->db->transRollback();
|
||||
|
||||
return INSUFFICIENT_REWARD_POINTS;
|
||||
}
|
||||
|
||||
$totalAmountUsed = floatval($totalAmountUsed) + floatval($payment['payment_amount']);
|
||||
}
|
||||
|
||||
$salesPaymentsData = [
|
||||
'sale_id' => $sale_id,
|
||||
'sale_id' => $saleId,
|
||||
'payment_type' => $payment['payment_type'],
|
||||
'payment_amount' => $payment['payment_amount'],
|
||||
'cash_refund' => $payment['cash_refund'],
|
||||
'cash_adjustment' => $payment['cash_adjustment'],
|
||||
'employee_id' => $employee_id
|
||||
'employee_id' => $employeeId,
|
||||
'reference_code' => $payment['reference_code'] ?? '',
|
||||
];
|
||||
|
||||
$builder = $this->db->table('sales_payments');
|
||||
@@ -686,19 +715,19 @@ class Sale extends Model
|
||||
$totalAmount = floatval($totalAmount) + floatval($payment['payment_amount']) - floatval($payment['cash_refund']);
|
||||
}
|
||||
|
||||
$this->save_customer_rewards($customer_id, $sale_id, $totalAmount, $totalAmountUsed);
|
||||
$this->save_customer_rewards($customerId, $saleId, $totalAmount, $totalAmountUsed);
|
||||
|
||||
$customer = $customer->get_info($customer_id);
|
||||
$customer = $customer->get_info($customerId);
|
||||
|
||||
foreach ($items as $itemData) {
|
||||
$currentItemInfo = $item->get_info($itemData['item_id']);
|
||||
foreach ($items as $line => $itemData) {
|
||||
$curItemInfo = $item->get_info($itemData['item_id']);
|
||||
|
||||
if ($itemData['price'] == 0.00) {
|
||||
$itemData['discount'] = 0.00;
|
||||
}
|
||||
|
||||
$salesItemsData = [
|
||||
'sale_id' => $sale_id,
|
||||
'sale_id' => $saleId,
|
||||
'item_id' => $itemData['item_id'],
|
||||
'line' => $itemData['line'],
|
||||
'description' => character_limiter($itemData['description'], 255),
|
||||
@@ -715,56 +744,57 @@ class Sale extends Model
|
||||
$builder = $this->db->table('sales_items');
|
||||
$builder->insert($salesItemsData);
|
||||
|
||||
if ($currentItemInfo->stock_type == HAS_STOCK && $sale_status == COMPLETED) {
|
||||
$itemQuantityData = $item_quantity->get_item_quantity($itemData['item_id'], $itemData['item_location']);
|
||||
|
||||
$item_quantity->save_value(
|
||||
[
|
||||
'quantity' => $itemQuantityData->quantity - $itemData['quantity'],
|
||||
'item_id' => $itemData['item_id'],
|
||||
'location_id' => $itemData['item_location']
|
||||
],
|
||||
if ($curItemInfo->stock_type == HAS_STOCK && $saleStatus == COMPLETED) { // TODO: === ?
|
||||
// Update stock quantity if item type is a standard stock item and the sale is a standard sale
|
||||
if (! $itemQuantity->changeQuantity(
|
||||
$itemData['item_id'],
|
||||
$itemData['item_location']
|
||||
);
|
||||
$itemData['item_location'],
|
||||
-(float) $itemData['quantity'],
|
||||
)) {
|
||||
$this->db->transRollback();
|
||||
|
||||
return INSUFFICIENT_STOCK;
|
||||
}
|
||||
|
||||
// If an items was deleted but later returned it's restored with this rule
|
||||
if ($itemData['quantity'] < 0) {
|
||||
$item->undelete($itemData['item_id']);
|
||||
}
|
||||
|
||||
$saleRemarks = 'POS ' . $sale_id;
|
||||
$inventoryData = [
|
||||
// Inventory Count Details
|
||||
$saleRemarks = 'POS ' . $saleId; // TODO: Use string interpolation here.
|
||||
$invData = [
|
||||
'trans_date' => date('Y-m-d H:i:s'),
|
||||
'trans_items' => $itemData['item_id'],
|
||||
'trans_user' => $employee_id,
|
||||
'trans_user' => $employeeId,
|
||||
'trans_location' => $itemData['item_location'],
|
||||
'trans_comment' => $saleRemarks,
|
||||
'trans_inventory' => -$itemData['quantity']
|
||||
];
|
||||
|
||||
$inventory->insert($inventoryData, false);
|
||||
$inventory->insert($invData, false);
|
||||
}
|
||||
|
||||
$attribute->copy_attribute_links($itemData['item_id'], 'sale_id', $sale_id);
|
||||
$attribute->copy_attribute_links($itemData['item_id'], 'sale_id', $saleId);
|
||||
}
|
||||
|
||||
if ($customer_id == NEW_ENTRY || $customer->taxable) {
|
||||
$this->save_sales_tax($sale_id, $sales_taxes[0]);
|
||||
$this->save_sales_items_taxes($sale_id, $sales_taxes[1]);
|
||||
if ($customerId == NEW_ENTRY || $customer->taxable) {
|
||||
$this->save_sales_tax($saleId, $salesTaxes[0]);
|
||||
$this->save_sales_items_taxes($saleId, $salesTaxes[1]);
|
||||
}
|
||||
|
||||
if ($config['dinner_table_enable']) {
|
||||
$dinner_table = model(Dinner_table::class);
|
||||
if ($sale_status == COMPLETED) { // TODO: === ?
|
||||
$dinner_table->release($dinner_table_id);
|
||||
$dinnerTable = model(Dinner_table::class);
|
||||
if ($saleStatus == COMPLETED) { // TODO: === ?
|
||||
$dinnerTable->release($dinnerTableId);
|
||||
} else {
|
||||
$dinner_table->occupy($dinner_table_id);
|
||||
$dinnerTable->occupy($dinnerTableId);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->db->transStatus() ? $sale_id : -1;
|
||||
return $this->db->transStatus() ? $saleId : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -876,7 +906,7 @@ class Sale extends Model
|
||||
{
|
||||
$this->db->transStart();
|
||||
|
||||
$sale_status = $this->get_sale_status($sale_id);
|
||||
$sale_status = $this->getSaleStatus($sale_id);
|
||||
|
||||
if ($update_inventory && $sale_status == COMPLETED) {
|
||||
$inventory = model('Inventory');
|
||||
@@ -899,7 +929,7 @@ class Sale extends Model
|
||||
];
|
||||
$inventory->insert($inventoryData, false);
|
||||
|
||||
$itemQuantity->change_quantity($itemData['item_id'], $itemData['item_location'], $itemData['quantity_purchased']);
|
||||
$itemQuantity->changeQuantity($itemData['item_id'], $itemData['item_location'], $itemData['quantity_purchased']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1121,7 +1151,7 @@ class Sale extends Model
|
||||
{
|
||||
$giftcard = model(Giftcard::class);
|
||||
|
||||
if (!$giftcard->exists($giftcard->get_giftcard_id($giftcardNumber))) { // TODO: camelCase is used here for the variable name but we are using _ everywhere else. CI4 moved to camelCase... we should pick one and do that.
|
||||
if (!$giftcard->exists($giftcard->getGiftcardId($giftcardNumber))) { // TODO: camelCase is used here for the variable name but we are using _ everywhere else. CI4 moved to camelCase... we should pick one and do that.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1199,7 +1229,8 @@ class Sale extends Model
|
||||
SUM(CASE WHEN payments.cash_adjustment = 0 THEN payments.payment_amount ELSE 0 END) AS sale_payment_amount,
|
||||
SUM(CASE WHEN payments.cash_adjustment = 1 THEN payments.payment_amount ELSE 0 END) AS sale_cash_adjustment,
|
||||
SUM(payments.cash_refund) AS sale_cash_refund,
|
||||
GROUP_CONCAT(CONCAT(payments.payment_type, " ", (payments.payment_amount - payments.cash_refund)) SEPARATOR ", ") AS payment_type
|
||||
GROUP_CONCAT(CONCAT(payments.payment_type, " ", (payments.payment_amount - payments.cash_refund)) SEPARATOR ", ") AS payment_type,
|
||||
GROUP_CONCAT(NULLIF(payments.reference_code, "") SEPARATOR ", ") AS reference_code
|
||||
FROM ' . $this->db->prefixTable('sales_payments') . ' AS payments
|
||||
INNER JOIN ' . $this->db->prefixTable('sales') . ' AS sales
|
||||
ON sales.sale_id = payments.sale_id
|
||||
@@ -1322,12 +1353,14 @@ class Sale extends Model
|
||||
/**
|
||||
* Gets the sale status for the selected sale
|
||||
*/
|
||||
public function get_sale_status(int $sale_id): int
|
||||
public function getSaleStatus(int $sale_id): ?int
|
||||
{
|
||||
$builder = $this->db->table('sales');
|
||||
$builder->where('sale_id', $sale_id);
|
||||
|
||||
return $builder->get()->getRow()->sale_status;
|
||||
$row = $builder->get()->getRow();
|
||||
|
||||
return $row === null ? null : $row->sale_status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1486,24 +1519,21 @@ class Sale extends Model
|
||||
|
||||
if (!empty($customer_id) && $config['customer_reward_enable']) {
|
||||
$customer = model(Customer::class);
|
||||
$customer_rewards = model(Customer_rewards::class);
|
||||
$customerRewards = model(Customer_rewards::class);
|
||||
$rewards = model(Rewards::class);
|
||||
|
||||
$package_id = $customer->get_info($customer_id)->package_id;
|
||||
$packageId = $customer->get_info($customer_id)->package_id;
|
||||
|
||||
if (!empty($package_id)) {
|
||||
$points_percent = $customer_rewards->get_points_percent($package_id);
|
||||
$points = $customer->get_info($customer_id)->points;
|
||||
$points = ($points == null ? 0 : $points);
|
||||
$points_percent = ($points_percent == null ? 0 : $points_percent);
|
||||
$total_amount_earned = ($total_amount * $points_percent / 100);
|
||||
$points = $points + $total_amount_earned;
|
||||
if (! empty($packageId)) {
|
||||
$pointsPercent = $customerRewards->get_points_percent($packageId);
|
||||
$pointsPercent = ($pointsPercent === null ? 0 : $pointsPercent);
|
||||
$totalAmountEarned = ($total_amount * $pointsPercent / 100);
|
||||
|
||||
$customer->update_reward_points_value($customer_id, $points);
|
||||
$customer->adjustRewardPoints($customer_id, $totalAmountEarned);
|
||||
|
||||
$rewards_data = ['sale_id' => $sale_id, 'earned' => $total_amount_earned, 'used' => $total_amount_used];
|
||||
$rewardsData = ['sale_id' => $sale_id, 'earned' => $totalAmountEarned, 'used' => $total_amount_used];
|
||||
|
||||
$rewards->save_value($rewards_data);
|
||||
$rewards->save_value($rewardsData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1559,43 +1589,6 @@ class Sale extends Model
|
||||
return $labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes payment type for giftcard and reward deductions during sale creation.
|
||||
* Returns the amount used for rewards (0 for giftcards).
|
||||
*/
|
||||
private function processPaymentType(array $payment, int $customerId, object $customer, object $giftcard): float
|
||||
{
|
||||
$paymentType = $payment['payment_type'];
|
||||
$paymentAmount = $payment['payment_amount'];
|
||||
|
||||
if (!empty(strstr($paymentType, lang('Sales.giftcard')))) {
|
||||
$splitPayment = explode(':', $paymentType);
|
||||
if (count($splitPayment) < 2 || empty($splitPayment[1])) {
|
||||
log_message('error', 'Sale::processPaymentType invalid giftcard format: ' . $paymentType);
|
||||
return 0;
|
||||
}
|
||||
$giftcardNumber = $splitPayment[1];
|
||||
$currentGiftcardValue = $giftcard->get_giftcard_value($giftcardNumber);
|
||||
$giftcard->update_giftcard_value($giftcardNumber, $currentGiftcardValue - $paymentAmount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($this->isRewardPayment($paymentType)) {
|
||||
$currentRewardsValue = $customer->get_info($customerId)->points ?? 0;
|
||||
if ($currentRewardsValue < $paymentAmount) {
|
||||
log_message(
|
||||
'warning',
|
||||
'Sale::processPaymentType insufficient points customer_id=' . $customerId
|
||||
. ' available=' . $currentRewardsValue . ' requested=' . $paymentAmount
|
||||
);
|
||||
}
|
||||
$customer->update_reward_points_value($customerId, max(0, $currentRewardsValue - $paymentAmount));
|
||||
return floatval($paymentAmount);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary table to store the sales_payments data
|
||||
*
|
||||
@@ -1609,7 +1602,9 @@ class Sale extends Model
|
||||
'payments.sale_id',
|
||||
'SUM(CASE WHEN `payments`.`cash_adjustment` = 0 THEN `payments`.`payment_amount` ELSE 0 END) AS sale_payment_amount',
|
||||
'SUM(CASE WHEN `payments`.`cash_adjustment` = 1 THEN `payments`.`payment_amount` ELSE 0 END) AS sale_cash_adjustment',
|
||||
'GROUP_CONCAT(CONCAT(`payments`.`payment_type`, " ", (`payments`.`payment_amount` - `payments`.`cash_refund`)) SEPARATOR ", ") AS payment_type'
|
||||
'SUM(`payments`.`cash_refund`) AS sale_cash_refund',
|
||||
'GROUP_CONCAT(CONCAT(`payments`.`payment_type`, " ", (`payments`.`payment_amount` - `payments`.`cash_refund`)) SEPARATOR ", ") AS payment_type',
|
||||
'GROUP_CONCAT(NULLIF(`payments`.`reference_code`, "") SEPARATOR ", ") AS reference_code'
|
||||
]);
|
||||
$builder->join('sales', 'sales.sale_id = payments.sale_id', 'inner');
|
||||
$builder->where($where);
|
||||
@@ -1619,7 +1614,7 @@ class Sale extends Model
|
||||
log_message('error', $sub_query);
|
||||
|
||||
$this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS '
|
||||
. $this->db->prefixTable('sales_payments_temp')
|
||||
. $this->db->prefixTable('sales_search_payments_temp')
|
||||
. ' (PRIMARY KEY(`sale_id`), INDEX(`sale_id`)) AS (' . $sub_query . ')');
|
||||
}
|
||||
|
||||
@@ -1674,6 +1669,9 @@ class Sale extends Model
|
||||
$builder->orLike('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search);
|
||||
// Customer company name
|
||||
$builder->orLike('customer.company_name', $search);
|
||||
if (ctype_digit($search)) {
|
||||
$builder->orWhere('sales.sale_id', $search); // Sale ID
|
||||
}
|
||||
$builder->groupEnd();
|
||||
}
|
||||
}
|
||||
@@ -1703,6 +1701,10 @@ class Sale extends Model
|
||||
$builder->like('payments.payment_type', lang('Sales.credit'));
|
||||
}
|
||||
|
||||
if ($filters['only_debit']) {
|
||||
$builder->like('payments.payment_type', lang('Sales.debit'));
|
||||
}
|
||||
|
||||
if ($filters['only_due']) {
|
||||
$builder->like('payments.payment_type', lang('Sales.due'));
|
||||
}
|
||||
@@ -1710,5 +1712,13 @@ class Sale extends Model
|
||||
if ($filters['only_check']) {
|
||||
$builder->like('payments.payment_type', lang('Sales.check'));
|
||||
}
|
||||
|
||||
if ($filters['only_bank_transfer']) {
|
||||
$builder->like('payments.payment_type', lang('Sales.bank_transfer'));
|
||||
}
|
||||
|
||||
if ($filters['only_wallet']) {
|
||||
$builder->like('payments.payment_type', lang('Sales.wallet'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user