Exemplo n.º 1
0
 public static function getObjectBySID($trans_sid)
 {
     $trans_info = SJB_TransactionManager::getTransactionInfoBySID($trans_sid);
     if (is_null($trans_info)) {
         return null;
     }
     $transaction = new SJB_Transaction($trans_info);
     $transaction->setSID($trans_sid);
     return $transaction;
 }
Exemplo n.º 2
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('template', 'manage_invoices.tpl');
     $searchTemplate = SJB_Request::getVar('search_template', 'invoice_search_form.tpl');
     $action = SJB_Request::getVar('action_name');
     if (!empty($action)) {
         $invoicesSIDs = SJB_Request::getVar('invoices', array());
         $_REQUEST['restore'] = 1;
         switch ($action) {
             case 'paid':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     $invoice = SJB_InvoiceManager::getObjectBySID($invoiceSID);
                     $userSID = $invoice->getPropertyValue('user_sid');
                     if (SJB_UserManager::isUserExistsByUserSid($userSID)) {
                         $items = $invoice->getPropertyValue('items');
                         $productSIDs = $items['products'];
                         foreach ($productSIDs as $key => $productSID) {
                             if ($productSID != -1) {
                                 if (SJB_ProductsManager::isProductExists($productSID)) {
                                     $productInfo = $invoice->getItemValue($key);
                                     $listingNumber = $productInfo['qty'];
                                     $contract = new SJB_Contract(array('product_sid' => $productSID, 'numberOfListings' => $listingNumber, 'is_recurring' => $invoice->isRecurring()));
                                     $contract->setUserSID($userSID);
                                     $contract->setPrice($items['amount'][$key]);
                                     if ($contract->saveInDB()) {
                                         SJB_ListingManager::activateListingsAfterPaid($userSID, $productSID, $contract->getID(), $listingNumber);
                                         SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $userSID);
                                         $bannerInfo = $productInfo['banner_info'];
                                         if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) {
                                             $bannersObj = new SJB_Banners();
                                             $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $userSID, $contract->getID());
                                             $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                             SJB_AdminNotifications::sendAdminBannerAddedLetter($userSID, $bannerGroup);
                                         }
                                         if ($contract->isFeaturedProfile()) {
                                             SJB_UserManager::makeFeaturedBySID($userSID);
                                         }
                                         if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($userSID)) {
                                             SJB_Notifications::sendSubscriptionActivationLetter($userSID, $productInfo);
                                         }
                                     }
                                 }
                             } else {
                                 $type = SJB_Array::getPath($items, 'custom_info/' . $key . '/type');
                                 switch ($type) {
                                     case 'featuredListing':
                                         $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id');
                                         SJB_ListingManager::makeFeaturedBySID($listingId);
                                         break;
                                     case 'priorityListing':
                                         $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id');
                                         SJB_ListingManager::makePriorityBySID($listingId);
                                         break;
                                     case 'activateListing':
                                         $listingsIds = explode(",", SJB_Array::getPath($items, 'custom_info/' . $key . '/listings_ids'));
                                         foreach ($listingsIds as $listingId) {
                                             SJB_ListingManager::activateListingBySID($listingId);
                                         }
                                         break;
                                 }
                             }
                         }
                         SJB_Statistics::addStatisticsFromInvoice($invoice);
                     }
                     $total = $invoice->getPropertyValue('total');
                     if ($total > 0) {
                         $gatewayID = $invoice->getPropertyValue('payment_method');
                         $gatewayID = isset($gatewayID) ? $gatewayID : 'cash_payment';
                         $transactionId = md5($invoiceSID . $gatewayID);
                         $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoiceSID, 'amount' => $total, 'payment_method' => $gatewayID, 'user_sid' => $invoice->getPropertyValue('user_sid'));
                         $transaction = new SJB_Transaction($transactionInfo);
                         SJB_TransactionManager::saveTransaction($transaction);
                     }
                     SJB_InvoiceManager::markPaidInvoiceBySID($invoiceSID);
                     SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-invoices/");
                 break;
             case 'unpaid':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     SJB_InvoiceManager::markUnPaidInvoiceBySID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/');
                 break;
             case 'delete':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     SJB_InvoiceManager::deleteInvoiceBySID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/');
                 break;
             default:
                 unset($_REQUEST['restore']);
                 break;
         }
     }
     /***************************************************************/
     $_REQUEST['action'] = 'search';
     $invoice = new SJB_Invoice(array());
     $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserDBManager::getUserSIDsLikeSearchString'));
     $searchFormBuilder = new SJB_SearchFormBuilder($invoice);
     $criteriaSaver = new SJB_InvoiceCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria());
     }
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice);
     $searchFormBuilder->setCriteria($criteria);
     $searchFormBuilder->registerTags($tp);
     $tp->display($searchTemplate);
     /********************** S O R T I N G *********************/
     $paginator = new SJB_InvoicePagination();
     $innerJoin = false;
     if ($paginator->sortingField == 'username') {
         $innerJoin = array('users' => array('sort_field' => array(36 => array('FirstName', 'LastName'), 41 => 'CompanyName'), 'join_field' => 'sid', 'join_field2' => 'user_sid', 'main_table' => 'invoices', 'join' => 'LEFT JOIN'));
     }
     $searcher = new SJB_InvoiceSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder, $innerJoin);
     $foundInvoices = array();
     $foundInvoicesInfo = array();
     if (SJB_Request::getVar('action', '') == 'search') {
         $foundInvoices = $searcher->getObjectsByCriteria($criteria, $aliases);
         if (empty($foundInvoices) && $paginator->currentPage != 1) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/?page=1');
         }
         $criteriaSaver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $foundInvoices = $criteriaSaver->getObjectsFromSession();
     }
     foreach ($foundInvoices as $id => $invoice) {
         $subUserSID = $invoice->getPropertyValue('subuser_sid');
         if ($subUserSID) {
             $subUserInfo = SJB_UserManager::getUserInfoBySID($subUserSID);
             $parentInfo = SJB_UserManager::getUserInfoBySID($subUserInfo['parent_sid']);
             $username = $parentInfo['CompanyName'];
         } else {
             $userSID = $invoice->getPropertyValue('user_sid');
             $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
             if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'Employer') {
                 $username = $userInfo['CompanyName'];
             } else {
                 if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'JobSeeker') {
                     $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'];
                 } else {
                     $username = $userInfo['username'];
                 }
             }
         }
         $invoice->addProperty(array('id' => 'sid', 'type' => 'string', 'value' => $invoice->getSID()));
         $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => $username));
         $foundInvoices[$id] = $invoice;
         $foundInvoicesInfo[$invoice->getSID()] = SJB_InvoiceManager::getInvoiceInfoBySID($invoice->getSID());
         $foundInvoicesInfo[$invoice->getSID()]['userExists'] = !empty($username) ? 1 : 0;
     }
     /****************************************************************/
     $paginator->setItemsCount($searcher->getAffectedRows());
     $form_collection = new SJB_FormCollection($foundInvoices);
     $form_collection->registerTags($tp);
     $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     $tp->assign("found_invoices", $foundInvoicesInfo);
     $tp->display($template);
 }
Exemplo n.º 3
0
 /**
  * Recurring notification handlign function
  * @param array|null $callback_data Notification data
  */
 function handleRecurringNotification($callback_data)
 {
     if (SJB_Array::get($callback_data, 'txn_type') == 'subscr_cancel' || SJB_Array::get($callback_data, 'txn_type') == 'subscr_eot') {
         SJB_ContractManager::removeSubscriptionId(SJB_Array::get($callback_data, 'subscr_id'));
         return;
     }
     if (SJB_Array::get($callback_data, 'txn_type') != 'subscr_payment') {
         return;
     }
     $invoice_sid = isset($callback_data['item_number']) ? $callback_data['item_number'] : null;
     if (is_null($invoice_sid)) {
         return;
     }
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     if (is_null($invoice)) {
         return null;
     }
     $reactivation = false;
     $status = $invoice->getStatus();
     if ($invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) {
         // Пришёл рекьюринг платёж
         $invoice->setSID(null);
         $invoice->setDate(null);
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
         $reactivation = true;
     }
     $invoice->setCallbackData($callback_data);
     if ($this->isPaymentVerified($invoice) && in_array($callback_data['payment_status'], array('Completed', 'Processed'))) {
         $items = $invoice->getPropertyValue('items');
         $user_sid = $invoice->getUserSID();
         $subscriptionSID = $callback_data['custom'];
         if (!empty($items['products'])) {
             $recurringProductsInfo = array();
             foreach ($items['products'] as $key => $product) {
                 if ($product != -1) {
                     $productInfo = $invoice->getItemValue($key);
                     if ($status == SJB_Invoice::INVOICE_STATUS_PAID && $subscriptionSID == $product) {
                         $listingNumber = $productInfo['qty'];
                         $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $callback_data['subscr_id'], 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         $contract->setUserSID($user_sid);
                         $contractSID = SJB_ContractManager::getContractSIDByRecurringId($callback_data['subscr_id']);
                         SJB_ContractManager::deleteAllContractsByRecurringId($callback_data['subscr_id']);
                         $contract->setPrice($productInfo['amount']);
                         if ($contract->saveInDB()) {
                             SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                             $bannerInfo = $productInfo['banner_info'];
                             if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) {
                                 $bannersObj = new SJB_Banners();
                                 if (isset($contractSID)) {
                                     $bannerID = $bannersObj->getBannerIDByContract($contractSID);
                                     if ($bannerID) {
                                         $bannersObj->updateBannerContract($contract->getID(), $bannerID);
                                     }
                                 } else {
                                     $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                                     $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                     SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                                 }
                             }
                             if ($contract->isFeaturedProfile()) {
                                 SJB_UserManager::makeFeaturedBySID($user_sid);
                             }
                             SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                             if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                 SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo, $reactivation);
                             }
                         }
                         $recurringProductsInfo[$key] = $productInfo;
                     } elseif ($status != SJB_Invoice::INVOICE_STATUS_PAID) {
                         $listingNumber = $productInfo['qty'];
                         if ($subscriptionSID == $product) {
                             $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $callback_data['subscr_id'], 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         } else {
                             $contract = new SJB_Contract(array('product_sid' => $product, 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         }
                         $contract->setUserSID($user_sid);
                         $contract->setPrice($productInfo['amount']);
                         if ($contract->saveInDB()) {
                             SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                             $bannerInfo = $productInfo['banner_info'];
                             if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo) && $contractSID) {
                                 $bannersObj = new SJB_Banners();
                                 $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                                 $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                 SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                             }
                             if ($contract->isFeaturedProfile()) {
                                 SJB_UserManager::makeFeaturedBySID($user_sid);
                             }
                             SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                             if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                 SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo);
                             }
                         }
                     }
                 }
             }
             if ($reactivation) {
                 $invoice->setNewPropertiesToInvoice($recurringProductsInfo);
             }
             $price = isset($callback_data['payment_gross']) ? $callback_data['payment_gross'] : $invoice->getPropertyValue('total');
             $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
             $id = $this->details->getProperty('id');
             $invoice->setPropertyValue('payment_method', $id->getValue());
             SJB_InvoiceManager::saveInvoice($invoice);
             SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             $transactionID = $callback_data['txn_id'];
             $transactionInfo = array('transaction_id' => $transactionID, 'invoice_sid' => $invoice->getSID(), 'amount' => $price, 'payment_method' => $invoice->getPropertyValue('payment_method'), 'user_sid' => $invoice->getPropertyValue('user_sid'));
             $transaction = new SJB_Transaction($transactionInfo);
             SJB_TransactionManager::saveTransaction($transaction);
         }
     } else {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
         SJB_InvoiceManager::saveInvoice($invoice);
     }
 }
Exemplo n.º 4
0
 /**
  * @param $callbackData
  * @param $invoice
  */
 public function processTransaction($callbackData, $invoice)
 {
     $transactionID = $callbackData['sale_id'];
     $transactionInfo = array('transaction_id' => $transactionID, 'invoice_sid' => $invoice->getSID(), 'amount' => $invoice->getPropertyValue('total'), 'payment_method' => '2checkout', 'user_sid' => $invoice->getPropertyValue('user_sid'));
     $transaction = new SJB_Transaction($transactionInfo);
     SJB_TransactionManager::saveTransaction($transaction);
 }
Exemplo n.º 5
0
 function handleRecurringNotification($notification_data)
 {
     //набор полей такой же как и при callback с Authorize.NET
     //плюс два поля x_subscription_id и x_subscription_paynum
     if (!$this->isNotificationFromGateway($notification_data)) {
         return;
         //уведомление не от Authorize.NET
     } else {
         if ($this->isNotificationSuccessfull($notification_data)) {
             $invoice_sid = null;
             if (isset($notification_data['x_invoice_num'])) {
                 $invoice_sid = $notification_data['x_invoice_num'];
             }
             if (is_null($invoice_sid)) {
                 return;
             }
             $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
             if (is_null($invoice)) {
                 return null;
             }
             $reactivation = false;
             if ($invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) {
                 // Пришёл рекьюринг платёж
                 $invoice->setSID(null);
                 $invoice->setDate(null);
                 $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
                 $reactivation = true;
             }
             $invoice->setCallbackData($notification_data);
             if (!$this->checkPaymentAmount($invoice)) {
                 return null;
             }
             $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
             SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             $user_sid = $invoice->getPropertyValue('user_sid');
             $items = $invoice->getPropertyValue('items');
             if (!empty($items['products'])) {
                 $recurringProductsInfo = array();
                 foreach ($items['products'] as $key => $product) {
                     if ($product != -1) {
                         $productInfo = $invoice->getItemValue($key);
                         $listingNumber = $productInfo['qty'];
                         $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $notification_data['x_subscription_id'], 'gateway_id' => 'authnet_sim', 'numberOfListings' => $listingNumber));
                         if (isset($contract)) {
                             $contract->setUserSID($user_sid);
                             $contractSID = SJB_ContractManager::getContractSIDByRecurringId($notification_data['x_subscription_id']);
                             SJB_ContractManager::deleteAllContractsByRecurringId($notification_data['x_subscription_id']);
                             $contract->setPrice($productInfo['amount']);
                             if ($contract->saveInDB()) {
                                 SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                                 $bannerInfo = $productInfo['banner_info'];
                                 if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo) && $contractSID) {
                                     $bannersObj = new SJB_Banners();
                                     $bannerID = $bannersObj->getBannerIDByContract($contractSID);
                                     if ($bannerID) {
                                         $bannersObj->updateBannerContract($contract->getID(), $bannerID);
                                     }
                                 }
                                 SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                                 if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                     SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo, $reactivation);
                                 }
                             }
                         }
                         if (isset($productInfo['recurring'])) {
                             $recurringProductsInfo[$key] = $productInfo;
                         }
                     }
                 }
                 if ($reactivation) {
                     $invoice->setNewPropertiesToInvoice($recurringProductsInfo);
                 }
                 SJB_InvoiceManager::saveInvoice($invoice);
                 if (isset($notification_data['x_trans_id'])) {
                     $transactionId = $notification_data['x_trans_id'];
                     $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoice->getSID(), 'amount' => $invoice->getPropertyValue('total'), 'payment_method' => $invoice->getPropertyValue('payment_method'), 'user_sid' => $invoice->getPropertyValue('user_sid'));
                     $transaction = new SJB_Transaction($transactionInfo);
                     SJB_TransactionManager::saveTransaction($transaction);
                 }
             }
         } else {
             //уведомление о неуспешном платеже
         }
     }
 }
Exemplo n.º 6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = 'edit_invoice.tpl';
     $errors = array();
     $invoiceErrors = array();
     $invoiceSID = SJB_Request::getVar('sid', false);
     $action = SJB_Request::getVar('action', false);
     $tcpdfError = SJB_Request::getVar('error', false);
     if ($tcpdfError) {
         $invoiceErrors[] = $tcpdfError;
     }
     $invoiceInfo = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSID);
     $user_structure = null;
     if ($invoiceInfo) {
         $product_info = array();
         if (array_key_exists('custom_info', $invoiceInfo['items'])) {
             $product_info = $invoiceInfo['items']['custom_info'];
         }
         $invoiceInfo = array_merge($invoiceInfo, $_REQUEST);
         $invoiceInfo['items']['custom_info'] = $product_info;
         $includeTax = $invoiceInfo['include_tax'];
         $invoice = new SJB_Invoice($invoiceInfo);
         $invoice->setSID($invoiceSID);
         $userSID = $invoice->getPropertyValue('user_sid');
         $userExists = SJB_UserManager::isUserExistsByUserSid($userSID);
         $subUserSID = $invoice->getPropertyValue('subuser_sid');
         if (!empty($subUserSID)) {
             $userInfo = SJB_UserManager::getUserInfoBySID($subUserSID);
             $username = $userInfo['username'] . '/' . $userInfo['email'];
         } else {
             $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
             $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'] . ' ' . $userInfo['ContactName'] . ' ' . $userInfo['CompanyName'] . '/' . $userInfo['email'];
         }
         $taxInfo = $invoice->getPropertyValue('tax_info');
         $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userInfo['user_group_sid']);
         $products = array();
         foreach ($productsSIDs as $key => $productSID) {
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             if (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 $volumeBasedPricing = $productInfo['volume_based_pricing'];
                 $minListings = min($volumeBasedPricing['listings_range_from']);
                 $maxListings = max($volumeBasedPricing['listings_range_to']);
                 $countListings = array();
                 for ($i = $minListings; $i <= $maxListings; $i++) {
                     $countListings[$i]['number_of_listings'] = $i;
                     for ($j = 1; $j <= count($volumeBasedPricing['listings_range_from']); $j++) {
                         if ($i >= $volumeBasedPricing['listings_range_from'][$j] && $i <= $volumeBasedPricing['listings_range_to'][$j]) {
                             $countListings[$i]['price'] = $volumeBasedPricing['price_per_unit'][$j];
                         }
                     }
                 }
                 $productInfo['count_listings'] = $countListings;
             }
             $products[$key] = $productInfo;
         }
         $addForm = new SJB_Form($invoice);
         $addForm->registerTags($tp);
         $tp->assign('userExists', $userExists);
         $tp->assign('products', $products);
         $tp->assign('invoice_sid', $invoiceSID);
         $tp->assign('include_tax', $includeTax);
         $tp->assign('username', trim($username));
         if ($action) {
             switch ($action) {
                 case 'save':
                 case 'apply':
                     $invoiceErrors = $invoice->isValid();
                     if (empty($invoiceErrors) && $addForm->isDataValid($errors)) {
                         $invoice->setFloatNumbersIntoValidFormat();
                         SJB_InvoiceManager::saveInvoice($invoice);
                         if ($action == 'save') {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/manage-invoices/');
                         }
                     } else {
                         $invoiceDate = SJB_I18N::getInstance()->getInput('date', $invoice->getPropertyValue('date'));
                         $invoice->setPropertyValue('date', $invoiceDate);
                     }
                     $invoice->setFloatNumbersIntoValidFormat();
                     $taxInfo['tax_amount'] = SJB_I18N::getInstance()->getInput('float', $taxInfo['tax_amount']);
                     break;
                 case 'print':
                 case 'download_pdf_version':
                     $user = SJB_UserManager::getObjectBySID($userSID);
                     $user_structure = SJB_UserManager::createTemplateStructureForUser($user);
                     $template = 'print_invoice.tpl';
                     $username = SJB_Array::get($user_structure, 'CompanyName') . ' ' . SJB_Array::get($user_structure, 'FirstName') . ' ' . SJB_Array::get($user_structure, 'LastName');
                     $tp->assign('username', trim($username));
                     $tp->assign('user', $user_structure);
                     $tp->assign('tax', $taxInfo);
                     if ($action == 'download_pdf_version') {
                         $template = 'invoice_to_pdf.tpl';
                         $filename = 'invoice_' . $invoiceSID . '.pdf';
                         try {
                             SJB_HelperFunctions::html2pdf($tp->fetch($template), $filename);
                             exit;
                         } catch (Exception $e) {
                             SJB_Error::writeToLog($e->getMessage());
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/edit-invoice/?sid=' . $invoiceSID . '&error=TCPDF_ERROR');
                         }
                     }
                     break;
                 case 'send_invoice':
                     $result = SJB_Notifications::sendInvoiceToCustomer($invoiceSID, $userSID);
                     if ($result) {
                         echo SJB_I18N::getInstance()->gettext("Backend", "Invoice successfully sent");
                     } else {
                         echo SJB_I18N::getInstance()->gettext("Backend", "Invoice not sent");
                     }
                     exit;
                     break;
             }
         }
         $transactions = SJB_TransactionManager::getTransactionsByInvoice($invoiceSID);
         $tp->assign('tax', $taxInfo);
         $tp->assign('transactions', $transactions);
     } else {
         $tp->assign('action', 'edit');
         $errors[] = 'WRONG_INVOICE_ID_SPECIFIED';
         $template = 'errors.tpl';
     }
     $tp->assign("errors", array_merge($errors, $invoiceErrors));
     $tp->display($template);
 }
Exemplo n.º 7
0
 function getPaymentFromCallbackData($callback_data)
 {
     $invoice_sid = isset($callback_data['item_number']) ? $callback_data['item_number'] : null;
     if (is_null($invoice_sid)) {
         $this->errors['INVOICE_ID_IS_NOT_SET'] = 1;
         return null;
     }
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     if (is_null($invoice)) {
         $this->errors['NONEXISTED_INVOICE_ID_SPECIFIED'] = 1;
         return null;
     }
     if ($invoice->getStatus() != SJB_Invoice::INVOICE_STATUS_UNPAID) {
         $this->errors['INVOICE_IS_NOT_UNPAID'] = $invoice->getStatus();
         return null;
     }
     $invoice->setCallbackData($callback_data);
     if ($this->isPaymentVerified($invoice)) {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_VERIFIED);
     } else {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
     }
     if (!$this->checkPaymentAmount($invoice)) {
         return null;
     }
     $id = $this->details->getProperty('id');
     $invoice->setPropertyValue('payment_method', $id->getValue());
     SJB_InvoiceManager::saveInvoice($invoice);
     if (isset($callback_data['x_trans_id'])) {
         $transactionId = $callback_data['x_trans_id'];
         $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoice->getSID(), 'amount' => $invoice->getPropertyValue('total'), 'payment_method' => $invoice->getPropertyValue('payment_method'), 'user_sid' => $invoice->getPropertyValue('user_sid'));
         $transaction = new SJB_Transaction($transactionInfo);
         SJB_TransactionManager::saveTransaction($transaction);
     }
     return $invoice;
 }
Exemplo n.º 8
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     /********** A C T I O N S   W I T H   T R A N S A C T I O N S **********/
     $action = SJB_Request::getVar('action_name', SJB_Request::getVar('action', false));
     $transactions_sids = SJB_Request::getVar('transactions', false);
     if ($action && $transactions_sids) {
         $_REQUEST['restore'] = 1;
         if ($action == 'delete') {
             // DELETE
             foreach ($transactions_sids as $transaction_sid => $value) {
                 SJB_TransactionManager::deleteTransactionBySID($transaction_sid);
             }
         } else {
             unset($_REQUEST['restore']);
         }
     }
     /**********  D E F A U L T   V A L U E S   F O R   S E A R C H  **********/
     $_REQUEST['action'] = 'filter';
     $i18n = SJB_ObjectMother::createI18N();
     if (!isset($_REQUEST['date'])) {
         $_REQUEST['date']['not_less'] = $i18n->getDate(date('Y-m-d', time() - 30 * 24 * 60 * 60));
         $_REQUEST['date']['not_more'] = $i18n->getDate(date('Y-m-d', time() + 24 * 60 * 60));
     } else {
         if (!$i18n->isValidDate($_REQUEST['date']['not_less']) && !empty($_REQUEST['date']['not_less'])) {
             $errors[] = 'INVALID_PERIOD_FROM';
         }
         if (!$i18n->isValidDate($_REQUEST['date']['not_more']) && !empty($_REQUEST['date']['not_more'])) {
             $errors[] = 'INVALID_PERIOD_TO';
         }
     }
     /************************ S E A R C H   F O R M ***************************/
     $transaction = new SJB_Transaction();
     $transaction->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserManager::getUserSIDsLikeUsername'));
     $search_form_builder = new SJB_SearchFormBuilder($transaction);
     $criteria_saver = new SJB_TransactionCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
     }
     $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $transaction);
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $tp->display('payment_form.tpl');
     /********************  S E A R C H  ************************/
     $paginator = new SJB_TransactionHistoryPagination();
     $searcher = new SJB_TransactionSearcher($paginator);
     if (SJB_Request::getVar('action', '') == 'filter') {
         $transactions = $searcher->getObjectsByCriteria($criteria, $aliases);
         if (empty($transactions) && $paginator->currentPage != 1) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/payments/?page=1');
         }
         $criteria_saver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $transactions = $criteria_saver->getObjectsFromSession();
     }
     $paginator->setItemsCount($searcher->getAffectedRows());
     $found_trans = array();
     $found_trans_sids = array();
     foreach ($transactions as $transaction) {
         $user_sid = $transaction->getPropertyValue('user_sid');
         $username = SJB_UserManager::getUserNameByUserSID($user_sid);
         $transaction->addProperty(array('id' => 'username', 'type' => 'string', 'value' => $username));
         $found_trans[$transaction->getSID()] = $transaction;
         $found_trans_sids[$transaction->getSID()] = $transaction->getSID();
     }
     $sorted_found_trans_sids = $found_trans_sids;
     $form_collection = new SJB_FormCollection($found_trans);
     $form_collection->registerTags($tp);
     $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     $tp->assign('errors', $errors);
     $tp->assign('found_transactions_sids', $sorted_found_trans_sids);
     $tp->display('payments.tpl');
 }