Skip to content

Commit

Permalink
Improvement: Unfinished show receipt for cashback to users #125
Browse files Browse the repository at this point in the history
  • Loading branch information
georgmaisser committed Jan 31, 2025
1 parent d167186 commit 7c8822c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions classes/local/create_invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public static function create_receipt(
case 'id':
// In this case $identifier stores the ledger id.
$items = shopping_cart_history::return_data_from_ledger_via_id($identifier);
$identifier = $items[array_key_first($items)]->identifier;
break;
case 'identifier':
default:
Expand Down
4 changes: 4 additions & 0 deletions classes/output/shoppingcart_history_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public function __construct(int $userid, int $identifier = 0, $fromledger = fals
}
} else {
$items = shopping_cart_history::get_history_list_for_user($userid);

$ledgeritems = shopping_cart_history::return_extra_lines_from_ledger($userid);

$items = array_merge($ledgeritems, $items);
}
$iscashier = false;
$context = context_system::instance();
Expand Down
3 changes: 2 additions & 1 deletion classes/shopping_cart_credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ public static function credit_paid_back(
$ledgerrecord->itemname = get_string('paymentmethodcreditspaidbackcash', 'local_shopping_cart');
break;
}
$ledgerrecord->identifier = shopping_cart_history::create_unique_cart_identifier($userid);
$ledgerrecord->price = (float) (-1.0) * $data['deductible'];
$ledgerrecord->credits = (float) (-1.0) * $data['deductible'];
$ledgerrecord->currency = $currency;
Expand Down Expand Up @@ -588,6 +589,7 @@ public static function creditsmanager_correct_credits(stdClass $data) {
$ledgerrecord->credits = (float) $data->creditsmanagercredits;
$ledgerrecord->currency = $currency;
$ledgerrecord->componentname = 'local_shopping_cart';
$ledgerrecord->identifier = shopping_cart_history::create_unique_cart_identifier($data->userid);
$ledgerrecord->payment = LOCAL_SHOPPING_CART_PAYMENT_METHOD_CREDITS_CORRECTION;
$ledgerrecord->paymentstatus = LOCAL_SHOPPING_CART_PAYMENT_SUCCESS;
$ledgerrecord->usermodified = $USER->id;
Expand All @@ -601,5 +603,4 @@ public static function creditsmanager_correct_credits(stdClass $data) {
}
return true;
}

}
33 changes: 33 additions & 0 deletions classes/shopping_cart_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,39 @@ public static function return_data_from_ledger_via_identifier(int $identifier):
return [];
}

/**
* Return extra ledger data from DB via userid
*
* @param int $userid
* @return array
*/
public static function return_extra_lines_from_ledger(int $userid): array {
global $DB;

[$inorequal, $params] = $DB->get_in_or_equal(
[
LOCAL_SHOPPING_CART_PAYMENT_METHOD_CREDITS_CORRECTION,
LOCAL_SHOPPING_CART_PAYMENT_METHOD_CREDITS_PAID_BACK_BY_CASH,
LOCAL_SHOPPING_CART_PAYMENT_METHOD_CREDITS_PAID_BACK_BY_TRANSFER,
LOCAL_SHOPPING_CART_PAYMENT_METHOD_REBOOKING_CREDITS_CORRECTION,
],
SQL_PARAMS_NAMED
);

$sql = "SELECT *
FROM {local_shopping_cart_ledger} scl
WHERE scl.userid = :userid
AND scl.payment $inorequal
";
$params['userid'] = $userid;
if (
$data = $DB->get_records_sql($sql, $params)
) {
return $data;
}
return [];
}

/**
* Return ledger data from DB via ledger id (cash report data).
* This function won't return data if the payment is already aborted.
Expand Down
12 changes: 11 additions & 1 deletion classes/table/cash_report_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,17 @@ public function col_paymentstatus(object $values): string {
*/
public function col_receipt(object $values): string {

if (!empty($values->identifier)) {
if (
!in_array(
$values->payment,
[
LOCAL_SHOPPING_CART_PAYMENT_METHOD_CREDITS_CORRECTION,
LOCAL_SHOPPING_CART_PAYMENT_METHOD_CREDITS_PAID_BACK_BY_CASH,
LOCAL_SHOPPING_CART_PAYMENT_METHOD_CREDITS_PAID_BACK_BY_TRANSFER,
LOCAL_SHOPPING_CART_PAYMENT_METHOD_REBOOKING_CREDITS_CORRECTION,
]
)
) {
$url = new moodle_url(
'/local/shopping_cart/receipt.php',
[
Expand Down
2 changes: 1 addition & 1 deletion report.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
$fields = "s1.*";
$from = "(SELECT DISTINCT " . $uniqueidpart .
" AS uniqueid, scl.id, scl.userid, scl.identifier, scl.price, scl.discount, scl.credits, scl.fee, scl.currency,
u.lastname, u.firstname, u.email, scl.itemid, scl.itemname, scl.payment, scl.paymentstatus, " .
u.lastname, u.firstname, u.email, scl.itemid, scl.itemname, scl.payment, scl.paymentstatus, scl.schistoryid, " .
$ootid .
$DB->sql_concat("um.firstname", "' '", "um.lastname") . " as usermodified, scl.timecreated, scl.timemodified,
scl.annotation,
Expand Down

0 comments on commit 7c8822c

Please sign in to comment.