コード例 #1
0
ファイル: Statistics.php プロジェクト: Maxlander/shixi
 public static function addStatisticsFromInvoice(SJB_Invoice $invoice)
 {
     $items = $invoice->getItemsInfo();
     if (empty($items)) {
         $items = $invoice->getPropertyValue('items');
     }
     foreach ($items['products'] as $key => $productSID) {
         $featured = 0;
         $priority = 0;
         $activate = 0;
         $type = 'product';
         if ($productSID == -1) {
             $productSID = isset($items['custom_info'][$key]['productSid']) ? $items['custom_info'][$key]['productSid'] : $invoice->getSID();
             $customType = $items['custom_info'][$key]['type'];
             switch ($customType) {
                 case 'activateListing':
                     $activate = 1;
                     break;
                 case 'priorityListing':
                     $priority = 1;
                     break;
                 case 'featuredListing':
                     $featured = 1;
                     break;
                 default:
                     $type = $customType;
             }
         }
         self::addStatistics('payment', $type, $productSID, false, $featured, $priority, $invoice->getUserSID(), $items['amount'][$key], 0, $activate);
     }
 }
コード例 #2
0
ファイル: PaymentGateway.php プロジェクト: Maxlander/shixi
 /**
  * @param SJB_Invoice $invoice
  * @return bool
  */
 public function checkPaymentAmount(SJB_Invoice $invoice)
 {
     $priceFromCallbackData = SJB_Request::getVar($this->amountField);
     //verifying that the item amounts match the amounts that you charge
     if ($invoice->getPropertyValue('total') != $priceFromCallbackData) {
         $this->errors['AMOUNT_IS_NOT_MATCH'] = 1;
         return false;
     }
     return true;
 }
コード例 #3
0
ファイル: InvoiceManager.php プロジェクト: Maxlander/shixi
 public static function getObjectBySID($invoiceSID)
 {
     $invoiceInfo = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSID);
     if (is_null($invoiceInfo)) {
         return null;
     }
     $invoice = new SJB_Invoice($invoiceInfo);
     $invoice->setSID($invoiceSID);
     return $invoice;
 }
コード例 #4
0
 private function assignInvoiceInfo()
 {
     $invoiceInfo['invoiceNumber'] = $this->invoice->getSID();
     $invoiceInfo['description'] = $this->invoice->getProductNames();
     $invoiceInfo['totalPrice'] = $this->invoice->getPropertyValue('total');
     $invoiceInfo['currencyCode'] = SJB_Payment_PaypalProFillPaymentCard::getCurrencyCode();
     $this->getTemplateProcessor()->assign('invoiceInfo', $invoiceInfo);
 }
コード例 #5
0
ファイル: add_invoice.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $userSID = SJB_Request::getVar('user_sid', false);
     $includeTax = SJB_Request::getVar('include_tax', SJB_Settings::getSettingByName('enable_taxes'));
     $errors = array();
     $invoiceErrors = array();
     $template = 'add_invoice.tpl';
     $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
     if ($userInfo) {
         if (!empty($userInfo['parent_sid'])) {
             $parent_sid = $userInfo['parent_sid'];
             $username = $userInfo['username'] . '/' . $userInfo['email'];
         } else {
             $parent_sid = $userSID;
             $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'] . ' ' . $userInfo['ContactName'] . ' ' . $userInfo['CompanyName'] . '/' . $userInfo['email'];
         }
         $formSubmitted = SJB_Request::getVar('action', '') == 'save';
         $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;
             } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                 unset($productInfo['volume_based_pricing']);
             }
             $products[$key] = $productInfo;
         }
         $total = SJB_I18N::getInstance()->getInput('float', SJB_Request::getVar('total', 0));
         $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($parent_sid, $total);
         $invoice = new SJB_Invoice($_REQUEST);
         $addForm = new SJB_Form($invoice);
         $addForm->registerTags($tp);
         if ($formSubmitted) {
             $invoiceErrors = $invoice->isValid();
             if (empty($invoiceErrors) && $addForm->isDataValid($errors)) {
                 $invoice->setFloatNumbersIntoValidFormat();
                 $invoice->setPropertyValue('success_page_url', SJB_System::getSystemSettings('USER_SITE_URL') . '/create-contract/');
                 SJB_InvoiceManager::saveInvoice($invoice);
                 if (SJB_Request::getVar('send_invoice', false)) {
                     SJB_Notifications::sendInvoiceToCustomer($invoice->getSID(), $userSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/manage-invoices/');
             } else {
                 $invoiceDate = SJB_I18N::getInstance()->getInput('date', $invoice->getPropertyValue('date'));
                 $invoice->setPropertyValue('date', $invoiceDate);
             }
         } else {
             $invoice->setPropertyValue('date', date('Y-m-d'));
             $invoice->setPropertyValue('status', SJB_Invoice::INVOICE_STATUS_UNPAID);
         }
         $invoice->setFloatNumbersIntoValidFormat();
         $tp->assign('username', $username);
         $tp->assign('user_sid', $userSID);
         $tp->assign('products', $products);
         $tp->assign('tax', $taxInfo);
         $tp->assign('include_tax', $includeTax);
     } else {
         $errors[] = 'CUSTOMER_NOT_SELECTED';
         $tp->assign('action', 'add');
         $template = 'errors.tpl';
     }
     $tp->assign("errors", array_merge($errors, $invoiceErrors));
     $tp->display($template);
 }
コード例 #6
0
ファイル: view_invoice.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $displayForm = new SJB_Form();
     $displayForm->registerTags($tp);
     $invoiceSid = SJB_Request::getVar('sid', false);
     if (SJB_Request::getVar('error', false)) {
         SJB_FlashMessages::getInstance()->addWarning('TCPDF_ERROR');
     }
     $action = SJB_Request::getVar('action', false);
     $paymentGateway = SJB_Request::getVar('payment_gateway', false);
     $template = 'print_invoice.tpl';
     $currentUserSID = SJB_UserManager::getCurrentUserSID();
     $invoiceInfo = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSid);
     if ($invoiceInfo) {
         if ($currentUserSID == $invoiceInfo['user_sid']) {
             $taxInfo = SJB_TaxesManager::getTaxInfoBySID($invoiceInfo['tax_info']['sid']);
             $invoiceInfo = array_merge($invoiceInfo, $_REQUEST);
             if (is_array($taxInfo)) {
                 $taxInfo = array_merge($invoiceInfo['tax_info'], $taxInfo);
             } else {
                 $taxInfo = $invoiceInfo['tax_info'];
             }
             $invoice = new SJB_Invoice($invoiceInfo);
             $invoice->setSID($invoiceSid);
             $userInfo = SJB_UserManager::getUserInfoBySID($currentUserSID);
             $username = $userInfo['CompanyName'] . ' ' . $userInfo['FirstName'] . ' ' . $userInfo['LastName'];
             $user = SJB_UserManager::getObjectBySID($currentUserSID);
             $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userInfo['user_group_sid']);
             $products = array();
             foreach ($productsSIDs as $key => $productSID) {
                 $product = SJB_ProductsManager::getProductInfoBySID($productSID);
                 $products[$key] = $product;
             }
             $displayForm = new SJB_Form($invoice);
             $displayForm->registerTags($tp);
             $show = true;
             if ($action == 'download_pdf_version' || $action == 'print') {
                 $show = false;
             }
             $tp->assign('show', $show);
             $tp->assign('products', $products);
             $tp->assign('invoice_sid', $invoiceSid);
             $tp->assign('invoice_status', $invoiceInfo['status']);
             $tp->assign('username', trim($username));
             $tp->assign('user_sid', $currentUserSID);
             $tp->assign('tax', $taxInfo);
             $userStructure = SJB_UserManager::createTemplateStructureForUser($user);
             $tp->assign('user', $userStructure);
             $tp->assign('include_tax', $invoiceInfo['include_tax']);
             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") . '/print-invoice/?sid=' . $invoiceSid . '&action=print&error=TCPDF_ERROR');
                 }
             }
         } else {
             SJB_FlashMessages::getInstance()->addError('NOT_OWNER');
         }
     } else {
         SJB_FlashMessages::getInstance()->addError('WRONG_INVOICE_ID_SPECIFIED');
     }
     if ($paymentGateway) {
         $gatewaySID = SJB_PaymentGatewayManager::getSIDByID($paymentGateway);
         $gatewayInfo = SJB_PaymentGatewayManager::getInfoBySID($gatewaySID);
         $tp->assign('gatewayInfo', $gatewayInfo);
     }
     $tp->assign('paymentError', SJB_Request::getVar('payment_error', false));
     $tp->display($template);
 }
コード例 #7
0
ファイル: payment_page.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $invoiceSID = SJB_Request::getVar('invoice_sid', null, 'default', 'int');
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $checkPaymentErrors = array();
     $currentUser = SJB_UserManager::getCurrentUser();
     if ($action == 'pay_for_products') {
         $subscribe = SJB_Request::getVar('subscribe', false);
         $subTotalPrice = SJB_Request::getVar('sub_total_price', 0);
         $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
         $codeInfo = array();
         $index = 1;
         $items = array();
         foreach ($products as $product) {
             $product_info = unserialize($product['product_info']);
             $items['products'][$index] = $product_info['sid'];
             $qty = !empty($product_info['number_of_listings']) ? $product_info['number_of_listings'] : null;
             if ($qty > 0) {
                 $items['price'][$index] = round($product_info['price'] / $qty, 2);
             } else {
                 $items['price'][$index] = round($product_info['price'], 2);
             }
             $items['amount'][$index] = $product_info['price'];
             $items['custom_item'][$index] = "";
             $items['qty'][$index] = $qty;
             $items['custom_info'][$index]['shoppingCartRecord'] = $product['sid'];
             if ($product_info['product_type'] == 'banners' && !empty($product_info['banner_info'])) {
                 $items['custom_info'][$index]['banner_info'] = $product_info['banner_info'];
             }
             $index++;
             SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product_info, $codeInfo);
         }
         $userSID = $currentUser->getSID();
         $invoiceSID = SJB_InvoiceManager::generateInvoice($items, $userSID, $subTotalPrice, SJB_System::getSystemSettings('SITE_URL') . "/create-contract/", (bool) $subscribe);
         SJB_PromotionsManager::addCodeToHistory($codeInfo, $invoiceSID, $userSID);
     }
     $gatewayId = SJB_Request::getVar('gw', false);
     if (SJB_Request::$method == SJB_Request::METHOD_POST && !$action && $gatewayId == 'authnet_sim') {
         if (isset($_REQUEST['submit'])) {
             $gateway = SJB_PaymentGatewayManager::getObjectByID($gatewayId, true);
             $subscriptionResult = $gateway->createSubscription($_REQUEST);
             if ($subscriptionResult !== true) {
                 $tp->assign('form_submit_url', $_SERVER['REQUEST_URI']);
                 $tp->assign('form_data_source', $_REQUEST);
                 $tp->assign('errors', $subscriptionResult);
                 $tp->display('recurring_payment_page.tpl');
             } else {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=true');
             }
         } else {
             $tp->assign('form_submit_url', $_SERVER['REQUEST_URI']);
             $tp->assign('form_data_source', $_REQUEST);
             $tp->display('recurring_payment_page.tpl');
         }
     } else {
         if (!is_null($invoiceSID)) {
             $invoice_info = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSID);
             $invoice = new SJB_Invoice($invoice_info);
             if (SJB_PromotionsManager::isPromoCodeExpired($invoiceSID)) {
                 $checkPaymentErrors['PROMOTION_TOO_MANY_USES'] = true;
             } else {
                 $invoice->setSID($invoiceSID);
                 if (count($invoice->isValid($invoiceSID)) == 0) {
                     $invoiceUserSID = $invoice->getPropertyValue('user_sid');
                     $currentUserSID = SJB_UserManager::getCurrentUserSID();
                     if ($invoiceUserSID === $currentUserSID) {
                         $payment_gateway_forms = SJB_InvoiceManager::getPaymentForms($invoice);
                         $tp->assign('productsNames', $invoice->getProductNames());
                         $tp->assign('gateways', $payment_gateway_forms);
                         $tp->assign('invoice_info', $invoice_info);
                     } else {
                         $checkPaymentErrors['NOT_OWNER'] = true;
                     }
                 } else {
                     $checkPaymentErrors['WRONG_INVOICE_PARAMETERS'] = true;
                 }
             }
             $tp->assign('checkPaymentErrors', $checkPaymentErrors);
             $tp->display('invoice_payment_page.tpl');
         } else {
             $tp->display('recurring_payment_page.tpl');
         }
     }
 }
コード例 #8
0
ファイル: my_invoices.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $userInfo = SJB_Authorization::getCurrentUserInfo();
     if (empty($userInfo)) {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
     $template = SJB_Request::getVar('template', 'my_invoices.tpl');
     $searchTemplate = SJB_Request::getVar('search_template', 'invoice_search_form.tpl');
     /***************************************************************/
     $_REQUEST['action'] = 'search';
     $_REQUEST['user_sid']['equal'] = $userInfo['sid'];
     if (!isset($_REQUEST['date'])) {
         $i18n = SJB_ObjectMother::createI18N();
         $_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'));
     }
     $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 *********************/
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice);
     $searcher = new SJB_InvoiceSearcher();
     $foundInvoices = array();
     $foundInvoicesInfo = array();
     if (SJB_Request::getVar('action', '') == 'search') {
         $foundInvoices = $searcher->getObjectsByCriteria($criteria, $aliases);
         $criteriaSaver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $foundInvoices = $criteriaSaver->getObjectsFromSession();
     }
     foreach ($foundInvoices as $id => $invoice) {
         $invoice->addProperty(array('id' => 'sid', 'type' => 'string', 'value' => $invoice->getSID()));
         $subUserSid = $invoice->getPropertyValue('subuser_sid');
         if ($subUserSid) {
             $payer = SJB_UserManager::getUserNameByUserSID($subUserSid);
         } else {
             $userSid = $invoice->getPropertyValue('user_sid');
             $payer = SJB_UserManager::getUserNameByUserSID($userSid);
         }
         $invoice->addProperty(array('id' => 'payer', 'type' => 'string', 'value' => $payer));
         $foundInvoices[$id] = $invoice;
         $foundInvoicesInfo[$invoice->getSID()] = SJB_InvoiceManager::getInvoiceInfoBySID($invoice->getSID());
     }
     $sortingField = SJB_Request::getVar('sorting_field', 'sid');
     $sortingOrder = SJB_Request::getVar('sorting_order', 'DESC');
     if ($invoice->propertyIsSet($sortingField)) {
         $sortArray = array();
         $sortedFoundInvoicesInfo = array();
         foreach ($foundInvoices as $id => $invoice) {
             $sortArray[$id] = $invoice->getPropertyValue($sortingField);
         }
         if ($sortingOrder == 'ASC') {
             asort($sortArray);
         } elseif ($sortingOrder == 'DESC') {
             arsort($sortArray);
         }
         foreach ($sortArray as $id => $value) {
             $sortedFoundInvoicesInfo[$id] = $foundInvoicesInfo[$id];
         }
     } else {
         $sortedFoundInvoicesInfo = $foundInvoicesInfo;
     }
     $formCollection = new SJB_FormCollection($foundInvoices);
     $formCollection->registerTags($tp);
     $subUsers = SJB_UserManager::getSubUsers($userInfo['sid']);
     $isSubUserExists = !empty($subUsers) ? true : false;
     $tp->assign('isSubUserExists', $isSubUserExists);
     $tp->assign('sorting_field', $sortingField);
     $tp->assign('sorting_order', $sortingOrder);
     $tp->assign('found_invoices', $sortedFoundInvoicesInfo);
     $tp->display($template);
 }
コード例 #9
0
ファイル: manage_invoices.php プロジェクト: Maxlander/shixi
 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);
 }
コード例 #10
0
ファイル: edit_invoice.php プロジェクト: Maxlander/shixi
 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);
 }