Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion Modules/Account/functionalTest/testAccount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ private slots:
QFAIL (e.what());
}
}
void requestIncrease_COD_with_domain_claimOfflinePayment() {
void requestIncrease_COD_with_domain_claimOfflinePayment_1() {
if (this->Voucher.ID > 0) {
QT_TRY {
this->OfflinePaymentClaimID = callUserAPI(
Expand All @@ -971,6 +971,50 @@ private slots:
}
}
}
void requestIncrease_COD_with_domain_rejectOfflinePayment() {
if (this->OfflinePaymentClaimID > 0) {
QT_TRY {
QVariant Result = callUserAPI(
RESTClientHelper::POST,
"Account/rejectOfflinePayment",
{},
{
{ "offlinePaymentClaimID", this->OfflinePaymentClaimID },
}
);

QVERIFY(Result.toBool());

} QT_CATCH (const std::exception &exp) {
QTest::qFail(exp.what(), __FILE__, __LINE__);
}
this->OfflinePaymentClaimID = 0;
}
}
void requestIncrease_COD_with_domain_claimOfflinePayment_2() {
if (this->Voucher.ID > 0) {
QT_TRY {
this->OfflinePaymentClaimID = callUserAPI(
RESTClientHelper::POST,
"Account/claimOfflinePayment",
{},
{
{ "vchID", this->Voucher.ID },
{ "bank", "bank mellat 2" },
{ "receiptCode", "8090" },
{ "receiptDate", "2022/03/04" },
{ "amount", 250000 },
{ "note", "this is note for offline payment 2" },
}
);

QVERIFY(this->OfflinePaymentClaimID > 0);

} QT_CATCH (const std::exception &exp) {
QTest::qFail(exp.what(), __FILE__, __LINE__);
}
}
}
void requestIncrease_COD_with_domain_approveOfflinePayment() {
if (this->OfflinePaymentClaimID > 0) {
QT_TRY {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Migration File: m20220430_124913_AAA_add_enum_to_tblOfflinePaymentClaims_status.sql */
/* CAUTION: don't forget to use {{dbprefix}} for schemas */

ALTER TABLE `tblOfflinePaymentClaims`
CHANGE COLUMN `ofpcStatus` `ofpcStatus` CHAR(1) NOT NULL DEFAULT 'N' COMMENT 'N:New, P:Pending, Y:Payed, A:Succeded, E:Error, J:Rejected, R:Removed' COLLATE 'utf8mb4_general_ci' AFTER `ofpcNotes`;

ALTER TABLE `tblOfflinePayments`
CHANGE COLUMN `ofpStatus` `ofpStatus` CHAR(1) NOT NULL DEFAULT 'N' COMMENT 'N:New, P:Pending, Y:Payed, A:Succeded, E:Error, J:Rejected, R:Removed' COLLATE 'utf8mb4_general_ci' AFTER `ofpNotes`;

ALTER TABLE `tblOnlinePayments`
CHANGE COLUMN `onpStatus` `onpStatus` CHAR(1) NOT NULL DEFAULT 'P' COMMENT 'N:New, P:Pending, Y:Payed, A:Succeded, E:Error, J:Rejected, R:Removed' COLLATE 'utf8mb4_general_ci' AFTER `onpResult`;
65 changes: 64 additions & 1 deletion Modules/Account/moduleSrc/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,67 @@ quint64 Account::apiPOSTclaimOfflinePayment(
}));
}

/**
* @callby:
* operator
* owner
*/
bool Account::apiPOSTrejectOfflinePayment(
APICALLBOOM_TYPE_JWT_IMPL &APICALLBOOM_PARAM,
quint64 _offlinePaymentClaimID
) {
QJsonObject PaymentInfo = QJsonObject::fromVariantMap(SelectQuery(OfflinePaymentClaims::instance())
.addCol(tblOfflinePaymentClaims::ofpcID)
.addCol(tblOfflinePaymentClaims::ofpc_vchID)
.addCol(tblOfflinePaymentClaims::ofpcBank)
.addCol(tblOfflinePaymentClaims::ofpcReceiptCode)
.addCol(tblOfflinePaymentClaims::ofpcReceiptDate)
.addCol(tblOfflinePaymentClaims::ofpcAmount)
.addCol(tblOfflinePaymentClaims::ofpcNotes)
.addCol(tblOfflinePaymentClaims::ofpcStatus)
.addCol(tblOfflinePaymentClaims::ofpcCreationDateTime)
.addCol(tblOfflinePaymentClaims::ofpcCreatedBy_usrID)
.addCol(tblOfflinePaymentClaims::ofpcUpdatedBy_usrID)
.addCol(tblVoucher::vchID)
.addCol(tblVoucher::vch_usrID)
.addCol(tblVoucher::vchDesc)
.addCol(tblVoucher::vchType)
.addCol(tblVoucher::vchTotalAmount)
.addCol(tblVoucher::vchStatus)
.addCol(tblVoucher::vchCreationDateTime)
.innerJoin(tblVoucher::Name)
.where({ tblOfflinePaymentClaims::ofpcID, enuConditionOperator::Equal, _offlinePaymentClaimID })
.one()
);

tblOfflinePaymentClaims::DTO OfflinePaymentClaim;
OfflinePaymentClaim.fromJson(PaymentInfo);

tblVoucher::DTO Voucher;
Voucher.fromJson(PaymentInfo);

//check operator or owner
if (Authorization::hasPriv(_APICALLBOOM.getJWT(), { "AAA:rejectOfflinePayment" }) == false) {
if (Voucher.vch_usrID != _APICALLBOOM.getUserID())
throw exAuthorization("Voucher is not yours");
}

if (OfflinePaymentClaim.ofpcStatus != Targoman::API::AccountModule::enuPaymentStatus::New)
throw exAuthorization("Only new offline payments are allowed.");

this->Update(OfflinePaymentClaims::instance(),
_APICALLBOOM,
{},
TAPI::ORMFields_t({
{ tblOfflinePaymentClaims::ofpcStatus, Targoman::API::AccountModule::enuPaymentStatus::Rejected }
}),
{
{ tblOfflinePaymentClaims::ofpcID, _offlinePaymentClaimID }
});

return true;
}

/**
* @callby:
* operator
Expand Down Expand Up @@ -1125,8 +1186,10 @@ Targoman::API::AAA::stuVoucher Account::apiPOSTapproveOfflinePayment(
.where({ tblOfflinePaymentClaims::ofpcID, enuConditionOperator::Equal, _offlinePaymentClaimID })
.one()
);

tblOfflinePaymentClaims::DTO OfflinePaymentClaim;
OfflinePaymentClaim.fromJson(PaymentInfo);

tblVoucher::DTO Voucher;
Voucher.fromJson(PaymentInfo);

Expand All @@ -1137,7 +1200,7 @@ Targoman::API::AAA::stuVoucher Account::apiPOSTapproveOfflinePayment(
}

if (OfflinePaymentClaim.ofpcStatus != Targoman::API::AccountModule::enuPaymentStatus::New)
throw exAuthorization("Only new offline payments are approved.");
throw exAuthorization("Only new offline payments are allowed.");

// if (ApprovalLimit > 0) {
// if (Voucher.value(tblVoucher::vchTotalAmount).toLongLong() > ApprovalLimit)
Expand Down
9 changes: 9 additions & 0 deletions Modules/Account/moduleSrc/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ private slots:
"claim offline payment by user"
)

bool REST_POST(
rejectOfflinePayment,
(
APICALLBOOM_TYPE_JWT_DECL &APICALLBOOM_PARAM,
quint64 _offlinePaymentClaimID
),
"reject offline payment claim"
)

Targoman::API::AAA::stuVoucher REST_POST(
approveOfflinePayment,
(
Expand Down
1 change: 1 addition & 0 deletions Modules/Account/moduleSrc/ORM/Payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TARGOMAN_DEFINE_ENUM(enuPaymentStatus,
Payed = 'Y',
Succeded = 'A',
Error = 'E',
Rejected = 'J',
Removed = 'R'
)

Expand Down