public function execute()
 {
     $id = waRequest::get('id');
     $model = new shopNotificationModel();
     $n = $model->getById($id);
     $params_model = new shopNotificationParamsModel();
     $params = $params_model->getParams($id);
     // Orders used as sample data for testing
     $om = new shopOrderModel();
     $test_orders = $om->where("paid_date IS NOT NULL AND state_id <> 'deleted'")->order('id DESC')->limit(10)->fetchAll('id');
     shopHelper::workupOrders($test_orders);
     $im = new shopOrderItemsModel();
     foreach ($im->getByField('order_id', array_keys($test_orders), true) as $i) {
         $test_orders[$i['order_id']]['items'][] = $i;
     }
     foreach ($test_orders as &$o) {
         $o['items'] = ifset($o['items'], array());
         $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
     }
     $this->view->assign('n', $n);
     $this->view->assign('params', $params);
     $this->view->assign('transports', self::getTransports());
     $this->view->assign('events', $this->getEvents());
     $this->view->assign('test_orders', $test_orders);
     $this->view->assign('default_email_from', $this->getConfig()->getGeneralSettings('email'));
     $this->view->assign('sms_from', $this->getSmsFrom());
     $this->view->assign('routes', wa()->getRouting()->getByApp('shop'));
 }
示例#2
0
 public static function formatValue($c, $curr = null)
 {
     static $currencies = null;
     if ($currencies === null) {
         if ($curr) {
             $currencies = $curr;
         } else {
             $curm = new shopCurrencyModel();
             $currencies = $curm->getAll('code');
         }
     }
     if ($c['type'] == '$FS') {
         return _w('Free shipping');
     } else {
         if ($c['type'] === '%') {
             return waCurrency::format('%0', $c['value'], 'USD') . '%';
         } else {
             if (!empty($currencies[$c['type']])) {
                 return waCurrency::format('%0{s}', $c['value'], $c['type']);
             } else {
                 // Coupon of unknown type. Possibly from a plugin?..
                 return '';
             }
         }
     }
 }
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_modifier_wa_format_amount($string, $currency_id = null, $format = '%', $locale = null)
{
    if ($locale === null || $currency_id === null) {
        /**
         * @var waSmarty3View
         */
        $smarty = waConfig::get('current_smarty');
    }
    if ($locale === null) {
        $locale = $smarty->getVars('locale');
    }
    if ($locale === null) {
        $locale = wa()->getUser()->getLocale();
    }
    if ($currency_id === null) {
        $currency_id = $smarty->getVars('currency_id');
    }
    if ($currency_id && $locale) {
        if ($format == 'words') {
            $format = '%.W{n0} %.2{f0}';
        }
        $string = waCurrency::format($format, $string, $currency_id, $locale);
    }
    return $string;
}
 public function execute()
 {
     $id = waRequest::request('id', null, waRequest::TYPE_INT);
     $contact = new waContact($id);
     $contact->getName();
     // Customer orders
     $im = new shopOrderItemsModel();
     $orders_collection = new shopOrdersCollection('search/contact_id=' . $id);
     $orders = $orders_collection->getOrders('*,items,params', 0, 500);
     shopHelper::workupOrders($orders);
     foreach ($orders as &$o) {
         $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
         $o['shipping_name'] = ifset($o['params']['shipping_name'], '');
         $o['payment_name'] = ifset($o['params']['payment_name'], '');
     }
     $this->view->assign('orders', $orders);
     $this->view->assign('contact', $contact);
     $this->view->assign('def_cur_tmpl', str_replace('0', '%s', waCurrency::format('%{s}', 0, wa()->getConfig()->getCurrency())));
 }
 public function execute()
 {
     $contact = wa()->getUser();
     $scm = new shopCustomerModel();
     // Customer orders
     $om = new shopOrderModel();
     $orders = $om->where('contact_id=?', $contact->getId())->order('id DESC')->fetchAll('id');
     // Items for all orders, one query
     $im = new shopOrderItemsModel();
     foreach ($im->getByField('order_id', array_keys($orders), true) as $row) {
         $orders[$row['order_id']]['items'][] = $row;
     }
     // Params for all orders, one query
     $opm = new shopOrderParamsModel();
     foreach ($opm->getByField('order_id', array_keys($orders), true) as $row) {
         $orders[$row['order_id']]['params'][$row['name']] = $row['value'];
     }
     // Prepare order data for template
     $url_tmpl = wa()->getRouteUrl('/frontend/myOrder', array('id' => '%ID%'));
     $workflow = new shopWorkflow();
     foreach ($orders as $k => &$o) {
         if ($o['state_id'] == 'deleted') {
             unset($orders[$k]);
             continue;
         }
         $o['id_str'] = shopHelper::encodeOrderId($o['id']);
         $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
         $o['shipping_name'] = ifset($o['params']['shipping_name'], '');
         $o['payment_name'] = ifset($o['params']['payment_name'], '');
         $o['state'] = $workflow->getStateById($o['state_id']);
         $o['url'] = str_replace('%ID%', $o['id'], $url_tmpl);
     }
     $this->view->assign('orders', array_values($orders));
     $this->view->assign('my_nav_selected', 'orders');
     // Set up layout and template from theme
     $this->setThemeTemplate('my.orders.html');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('Orders'));
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_modifier_wa_format_amount($string, $currency_id = null, $locale = null)
{
    if ($locale === null || $currency_id === null) {
        /**
         * @var waSmarty3View
         */
        $smarty = waConfig::get('current_smarty');
    }
    if ($locale === null) {
        $locale = $smarty->getVars('locale');
    }
    if ($locale === null) {
        $locale = waSystem::getInstance()->getUser()->getLocale();
    }
    if ($currency_id === null) {
        $currency_id = $smarty->getVars('currency_id');
    }
    if ($currency_id && $locale) {
        $string = waCurrency::format('%', $string, $currency_id, $locale);
    }
    return $string;
}
 public function execute()
 {
     list($start_date, $end_date, $group_by) = self::getTimeframeParams();
     // Total sales for period, in default currency
     $total_sales = array('returning_customers' => 0, 'new_customers' => 0, 'total' => 0);
     // Total number of paid orders for the period
     $total_orders = array('returning_customers' => 0, 'new_customers' => 0, 'total' => 0);
     // Max total sales in a single day
     $max_day_sales = 0;
     // Loop over all days of a period that had at least one order paid,
     // and gather data into vars listed above.
     $om = new shopOrderModel();
     $sales_by_day = $om->getSales($start_date, $end_date, $group_by);
     foreach ($sales_by_day as $row) {
         $max_day_sales = max($max_day_sales, (double) $row['total']);
         $total_orders['new_customers'] += (int) $row['customer_first_count'];
         $total_sales['new_customers'] += (double) $row['customer_first_total'];
         $total_orders['total'] += (int) $row['count'];
         $total_sales['total'] += (double) $row['total'];
     }
     $total_sales['returning_customers'] += $total_sales['total'] - $total_sales['new_customers'];
     $total_orders['returning_customers'] += $total_orders['total'] - $total_orders['new_customers'];
     // Data for main chart
     $sales_data = array();
     foreach ($sales_by_day as &$d) {
         $d['total_percent'] = $max_day_sales ? $d['total'] * 100 / ifempty($max_day_sales, 1) : 0;
         $sales_data[] = array($d['date'], $d['total']);
     }
     unset($d);
     $def_cur = wa()->getConfig()->getCurrency();
     $this->view->assign('sales_by_day', $sales_by_day);
     $this->view->assign('sales_data', $sales_data);
     $this->view->assign('group_by', $group_by);
     $this->view->assign('def_cur', $def_cur);
     $this->view->assign('stat', array('total_formatted' => waCurrency::format('%{s}', $total_sales['total'], $def_cur), 'percent_returning' => round($total_sales['returning_customers'] * 100 / ifempty($total_sales['total'], 1), 1), 'percent_new' => round($total_sales['new_customers'] * 100 / ifempty($total_sales['total'], 1), 1), 'avg_total_formatted' => waCurrency::format('%{s}', round($total_sales['total'] / ifempty($total_orders['total'], 1), 1), $def_cur), 'avg_total_new_formatted' => waCurrency::format('%{s}', round($total_sales['new_customers'] / ifempty($total_orders['new_customers'], 1), 2), $def_cur), 'avg_total_returning_formatted' => waCurrency::format('%{s}', round($total_sales['returning_customers'] / ifempty($total_orders['returning_customers'], 1), 2), $def_cur), 'avg_total_daily_formatted' => waCurrency::format('%{s}', $sales_by_day ? round($total_sales['total'] / count($sales_by_day), 2) : 0, $def_cur)));
 }
 public function execute()
 {
     $id = waRequest::request('id', 0, 'int');
     $coupm = new shopCouponModel();
     $coupon = $coupm->getById($id);
     if ($coupon) {
         $coupon['value'] = (double) $coupon['value'];
         if (waRequest::request('delete')) {
             $coupm->delete($id);
             exit;
         }
     } else {
         if ($id) {
             throw new waException('Coupon not found.', 404);
         } else {
             // show form to create new coupon
             $coupon = $coupm->getEmptyRow();
             $coupon['code'] = self::generateCode();
         }
     }
     //
     // Process POST data
     //
     $duplicate_code_error = null;
     if (waRequest::post()) {
         $post_coupon = waRequest::post('coupon');
         if (is_array($post_coupon)) {
             $post_coupon = array_intersect_key($post_coupon, $coupon) + array('code' => '', 'type' => '%');
             if (empty($post_coupon['limit'])) {
                 $post_coupon['limit'] = null;
             }
             if (!empty($post_coupon['value'])) {
                 $post_coupon['value'] = (double) str_replace(',', '.', $post_coupon['value']);
             }
             if (empty($post_coupon['code'])) {
                 throw new waException('Bad parameters', 500);
                 // rely on JS validation
             }
             if (!empty($post_coupon['expire_datetime']) && strlen($post_coupon['expire_datetime']) == 10) {
                 $post_coupon['expire_datetime'] .= ' 23:59:59';
             }
             if ($post_coupon['type'] == '%') {
                 $post_coupon['value'] = min(max($post_coupon['value'], 0), 100);
             }
             if ($id) {
                 $coupm->updateById($id, $post_coupon);
                 echo '<script>window.location.hash = "#/coupons/' . $id . '";$.orders.dispatch();</script>';
                 exit;
             } else {
                 $post_coupon['create_contact_id'] = wa()->getUser()->getId();
                 $post_coupon['create_datetime'] = date('Y-m-d H:i:s');
                 try {
                     $id = $coupm->insert($post_coupon);
                     echo '<script>' . 'var counter = $("#s-coupons .count");' . 'var cnt = parseInt(counter.text(), 10) || 0;' . 'counter.text(cnt + 1);' . 'window.location.hash = "#/coupons/' . $id . '";' . '</script>';
                     exit;
                 } catch (waDbException $e) {
                     // Duplicate code. Show error in form.
                     $coupon = $post_coupon + $coupon;
                     $duplicate_code_error = true;
                 }
             }
         }
     }
     // Coupon types
     $curm = new shopCurrencyModel();
     $currencies = $curm->getAll('code');
     $types = self::getTypes($currencies);
     // Orders this coupon was used for
     $orders = array();
     $overall_discount = 0;
     $overall_discount_formatted = '';
     if ($coupon['id']) {
         $om = new shopOrderModel();
         $cm = new shopCurrencyModel();
         $orders = $om->getByCoupon($coupon['id']);
         shopHelper::workupOrders($orders);
         foreach ($orders as &$o) {
             $discount = ifset($o['params']['coupon_discount'], 0);
             $o['coupon_discount_formatted'] = waCurrency::format('%{s}', $discount, $o['currency']);
             if ($discount) {
                 $overall_discount += $cm->convert($discount, $o['currency'], $cm->getPrimaryCurrency());
                 $o['coupon_discount_percent'] = round($discount * 100.0 / ($discount + $o['total']), 1);
             } else {
                 $o['coupon_discount_percent'] = 0;
             }
         }
         unset($o);
         $overall_discount_formatted = waCurrency::format('%{s}', $overall_discount, $cm->getPrimaryCurrency());
     }
     $this->view->assign('types', $types);
     $this->view->assign('orders', $orders);
     $this->view->assign('coupon', $coupon);
     $this->view->assign('duplicate_code_error', $duplicate_code_error);
     $this->view->assign('overall_discount', $overall_discount);
     $this->view->assign('overall_discount_formatted', $overall_discount_formatted);
     $this->view->assign('formatted_value', shopCouponsAction::formatValue($coupon, $currencies));
     $this->view->assign('is_enabled', shopCouponsAction::isEnabled($coupon));
 }
示例#9
0
function wa_currency_html($n, $currency, $format = '%{h}')
{
    return waCurrency::format($format, $n, $currency);
}
 /**
  * Вспомогательный метод для печати формы с идентификатором 116.
  *
  * @param waOrder $order Объект, содержащий информацию о заказе
  * @param array $params
  * @return string HTML-код формы
  */
 private function displayPrintForm116(waOrder $order, $params = array())
 {
     $strict = true;
     $request = waRequest::request();
     switch ($side = waRequest::get('side', $order ? '' : 'print', waRequest::TYPE_STRING)) {
         case 'front':
             $image_info = null;
             if ($image = $this->read('f116_front.gif', $image_info)) {
                 $address = $this->splitAddress($order);
                 $this->printOnImage($image, waRequest::request('order_amount', $order->total), 294, 845, 24);
                 $this->printOnImage($image, waRequest::request('order_price', $order->total), 294, 747, 24);
                 //customer
                 $this->printOnImage($image, waRequest::request('shipping_name', $order->contact_name), 390, 915);
                 $this->printOnImage($image, waRequest::request('shipping_address_1', $address[0]), 390, 975);
                 $this->printOnImage($image, waRequest::request('shipping_address_2', $address[1]), 300, 1040);
                 $this->printOnImagePersign($image, waRequest::request('shipping_zip', $order->shipping_address['zip']), 860, 1105, 55, 35);
                 //company
                 $this->printOnImage($image, $this->company_name, 420, 1170);
                 $this->printOnImage($image, $this->address1, 400, 1237);
                 $this->printOnImage($image, $this->address2, 300, 1304);
                 $this->printOnImagePersign($image, $this->zip, 1230, 1304, 55, 35);
                 //additional
                 $this->printOnImage($image, waRequest::request('order_price_d', waCurrency::format('%2', $order->total, $order->currency)), 590, 2003);
                 $this->printOnImage($image, waRequest::request('order_amount_d', waCurrency::format('%2', $order->total, $order->currency)), 1280, 2003);
                 $this->printOnImage($image, waRequest::request('shipping_name', $order->contact_name), 390, 2085);
                 $this->printOnImage($image, waRequest::request('shipping_address_1', $address[0]), 390, 2170);
                 $this->printOnImage($image, waRequest::request('shipping_address_2', $address[1]), 300, 2260);
                 $this->printOnImagePersign($image, waRequest::request('shipping_zip', $order->shipping_address['zip']), 1230, 2260, 55, 35);
                 header("Content-type: image/gif");
                 imagegif($image);
                 exit;
             }
             break;
         case 'back':
             $image_info = null;
             if ($image = $this->read('f116_back.gif', $image_info)) {
                 header("Content-type: image/gif");
                 imagegif($image);
                 exit;
             }
             break;
         case 'print':
             if (!$strict && !$order) {
                 $this->view()->assign('action', 'preview');
             }
             $this->view()->assign('editable', false);
             $this->view()->assign('order', $order);
             break;
         default:
             $this->view()->assign(array('src_front' => http_build_query(array_merge($request, array('side' => 'front'))), 'src_back' => http_build_query(array_merge($request, array('side' => 'back')))));
             if (!$strict && !$order) {
                 $this->view()->assign('action', 'preview');
             }
             $this->view()->assign('editable', waRequest::post() ? false : true);
             $this->view()->assign('order', $order);
             $this->view()->assign('address', $this->splitAddress($order));
             break;
     }
     return $this->view()->fetch($this->path . '/templates/form116.html');
 }
示例#11
0
function wa_currency($n, $currency, $format = '%{s}')
{
    return waCurrency::format($format, $n, $currency);
}
 public function execute()
 {
     $id = waRequest::request('id', null, waRequest::TYPE_INT);
     $scm = new shopCustomerModel();
     $customer = $scm->getById($id);
     try {
         $contact = new waContact($id);
         $contact->getName();
     } catch (waException $e) {
         // !!! What to do when shop_customer exists, but no wa_contact found?
         throw $e;
     }
     $ccsm = new waContactCategoriesModel();
     $contact_categories = $ccsm->getContactCategories($id);
     $contacts_url = wa()->getAppUrl('contacts');
     // Info above tabs
     $top = array();
     foreach (array('email', 'phone', 'im') as $f) {
         if ($v = $contact->get($f, 'top,html')) {
             $top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v);
         }
     }
     // Get photo
     $photo = $contact->get('photo');
     $config = $this->getConfig();
     $use_gravatar = $config->getGeneralSettings('use_gravatar');
     $gravatar_default = $config->getGeneralSettings('gravatar_default');
     if (!$photo && $use_gravatar) {
         $photo = shopHelper::getGravatar($contact->get('email', 'default'), 96, $gravatar_default);
     } else {
         $photo = $contact->getPhoto(96);
     }
     $contact['photo'] = $photo;
     // Customer orders
     $im = new shopOrderItemsModel();
     $orders_collection = new shopOrdersCollection('search/contact_id=' . $id);
     $total_count = $orders_collection->count();
     $orders = $orders_collection->getOrders('*,items,params', 0, $total_count);
     shopHelper::workupOrders($orders);
     foreach ($orders as &$o) {
         $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
         $o['shipping_name'] = ifset($o['params']['shipping_name'], '');
         $o['payment_name'] = ifset($o['params']['payment_name'], '');
         // !!! TODO: shipping and payment icons
     }
     // Customer reviews
     $prm = new shopProductReviewsModel();
     $reviews = $prm->getList('*,is_new,product', array('escape' => false, 'where' => array('contact_id' => $id), 'limit' => false));
     // Customer affiliate transactions history
     $atm = new shopAffiliateTransactionModel();
     $affiliate_history = $atm->getByContact($id);
     $this->view->assign('top', $top);
     $this->view->assign('orders', $orders);
     $this->view->assign('reviews', $reviews);
     $this->view->assign('contact', $contact);
     $this->view->assign('customer', $customer);
     $this->view->assign('contacts_url', $contacts_url);
     $this->view->assign('affiliate_history', $affiliate_history);
     $this->view->assign('contact_categories', $contact_categories);
     $this->view->assign('def_cur_tmpl', str_replace('0', '%s', waCurrency::format('%{s}', 0, wa()->getConfig()->getCurrency())));
     $this->view->assign('point_rate', str_replace(',', '.', (double) str_replace(',', '.', wa()->getSetting('affiliate_usage_rate'))));
     $fields = waContactFields::getAll('person');
     if (isset($fields['name'])) {
         unset($fields['name']);
     }
     $this->view->assign('fields', $fields);
     $this->view->assign('orders_default_view', $config->getOption('orders_default_view'));
     /*
      * @event backend_customer
      * @return array[string]array $return[%plugin_id%] array of html output
      * @return array[string][string]string $return[%plugin_id%]['info_section'] html output
      * @return array[string][string]string $return[%plugin_id%]['name_suffix'] html output
      * @return array[string][string]string $return[%plugin_id%]['header'] html output
      * @return array[string][string]string $return[%plugin_id%]['action_link'] html output
      */
     $this->view->assign('backend_customer', wa()->event('backend_customer', $customer));
 }
示例#13
0
 public static function discount(&$order, $contact, $apply, $other_discounts)
 {
     if (!$contact || !$contact->getId()) {
         return 0;
     }
     $checkout_data = wa()->getStorage()->read('shop/checkout');
     if (empty($checkout_data['use_affiliate'])) {
         return 0;
         // !!! Will this fail when recalculating existing order?
     }
     $usage_rate = (double) wa()->getSetting('affiliate_usage_rate', 0, 'shop');
     if ($usage_rate <= 0) {
         return 0;
     }
     $cm = new shopCustomerModel();
     $customer = $cm->getById($contact->getId());
     if (!$customer || $customer['affiliate_bonus'] <= 0) {
         return 0;
     }
     $order_total = $order['total'] - $other_discounts;
     $max_bonus = $customer['affiliate_bonus'];
     if (!empty($order['params']['affiliate_bonus'])) {
         // Recalculating existing order: take old discount into account
         $max_bonus += $order['params']['affiliate_bonus'];
     }
     $crm = new shopCurrencyModel();
     $discount = (double) $crm->convert($max_bonus * $usage_rate, wa()->getConfig()->getCurrency(true), wa()->getConfig()->getCurrency(false));
     if ($discount > $order_total) {
         $discount = $order_total;
     }
     if ($discount < $order_total) {
         $bonus_used = $max_bonus;
     } else {
         $bonus_used = (double) $crm->convert($discount, wa()->getConfig()->getCurrency(false), wa()->getConfig()->getCurrency(true)) / $usage_rate;
     }
     if (empty($order['params'])) {
         $order['params'] = array();
     }
     $order['params']['affiliate_bonus'] = $bonus_used;
     if ($apply) {
         $balance_change = $max_bonus - $bonus_used - $customer['affiliate_bonus'];
         if (abs($balance_change) > 0.0001) {
             if (!empty($order['params']['affiliate_bonus'])) {
                 $message = sprintf_wp('Recalculation of order total, new discount: %s', waCurrency::format('%{s}', $discount, wa()->getConfig()->getCurrency()));
             } else {
                 $message = sprintf_wp('Discount of %s', waCurrency::format('%{s}', $discount, wa()->getConfig()->getCurrency()));
             }
             $atm = new shopAffiliateTransactionModel();
             $atm->applyBonus($contact->getId(), $balance_change, ifset($order['id']), $message);
         }
     }
     return $discount;
 }
 public function execute()
 {
     $id = waRequest::request('id');
     $fm = new shopFollowupModel();
     // Save data when POST came
     if ($id && waRequest::post()) {
         if (waRequest::post('delete')) {
             $f = $fm->getById($id);
             if ($f) {
                 /**
                  * @event followup_delete
                  *
                  * Notify plugins about deleted followup
                  *
                  * @param array[string]int $params['id'] followup_id
                  * @return void
                  */
                 wa()->event('followup_delete', $f);
                 $fm->deleteById($id);
             }
             exit;
         }
         $followup = waRequest::post('followup');
         if ($followup && is_array($followup)) {
             $empty_row = $fm->getEmptyRow();
             $followup = array_intersect_key($followup, $empty_row) + $empty_row;
             unset($followup['id']);
             $followup['delay'] = (double) str_replace(',', '.', ifempty($followup['delay'], '3')) * 24 * 3600;
             if (empty($followup['name'])) {
                 $followup['name'] = _w('<no name>');
             }
             $followup['from'] = $followup['from'] ? $followup['from'] : null;
             $followup['source'] = $followup['source'] ? $followup['source'] : null;
             if ($followup['from'] === 'other') {
                 $followup['from'] = waRequest::post('from');
             }
             if ($id && $id !== 'new') {
                 unset($followup['last_cron_time']);
                 $fm->updateById($id, $followup);
                 $just_created = false;
             } else {
                 $followup['last_cron_time'] = date('Y-m-d H:i:s');
                 $id = $fm->insert($followup);
                 $just_created = true;
             }
             $f = $fm->getById($id);
             if ($f) {
                 $f['just_created'] = $just_created;
                 /**
                  * Notify plugins about created or modified followup
                  * @event followup_save
                  * @param array[string]int $params['id'] followup_id
                  * @param array[string]bool $params['just_created']
                  * @return void
                  */
                 wa()->event('followup_save', $f);
             }
         }
     }
     // List of all follow-ups
     $followups = $fm->getAll('id');
     // Get data to show in form
     $followup = null;
     if ($id) {
         if (empty($followups[$id])) {
             if ($followups) {
                 $followup = reset($followups);
             }
         } else {
             $followup = $followups[$id];
         }
     }
     $test_orders = array();
     if (empty($followup)) {
         $followup = $fm->getEmptyRow();
         $followup['body'] = self::getDefaultBody();
     } else {
         // Orders used as sample data for testing
         $om = new shopOrderModel();
         $test_orders = $om->where("paid_date IS NOT NULL AND state_id <> 'deleted'")->order('id DESC')->limit(10)->fetchAll('id');
         shopHelper::workupOrders($test_orders);
         $im = new shopOrderItemsModel();
         foreach ($im->getByField('order_id', array_keys($test_orders), true) as $i) {
             $test_orders[$i['order_id']]['items'][] = $i;
         }
         foreach ($test_orders as &$o) {
             $o['items'] = ifset($o['items'], array());
             $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
         }
     }
     $this->view->assign('followup', $followup);
     $this->view->assign('followups', $followups);
     $this->view->assign('test_orders', $test_orders);
     $this->view->assign('last_cron', wa()->getSetting('last_followup_cli'));
     $this->view->assign('cron_ok', wa()->getSetting('last_followup_cli') + 3600 * 36 > time());
     $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php shop followup');
     $this->view->assign('default_email_from', $this->getConfig()->getGeneralSettings('email'));
     $this->view->assign('routes', wa()->getRouting()->getByApp('shop'));
 }
 /**
  * Вспомогательный метод для печати формы с идентификатором 112.
  *
  * @param waOrder $order Объект, содержащий информацию о заказе
  * @param array $params
  * @return string HTML-код формы
  */
 private function displayPrintForm112(waOrder $order, $params = array())
 {
     $strict = true;
     $request = waRequest::request();
     $order['rub'] = intval(waRequest::request('rub', round(floor($order->total))));
     $order['cop'] = min(99, max(0, intval(waRequest::request('cop', round($order->total * 100 - $order['rub'] * 100)))));
     switch ($side = waRequest::get('side', $order ? '' : 'print', waRequest::TYPE_STRING)) {
         case 'front':
             $image_info = null;
             if ($image = $this->read('f112ep_front.gif', $image_info)) {
                 $format = '%.W{n0} %.2{f0}';
                 $this->printOnImage($image, sprintf('%d', $order['rub']), 110, 680);
                 $this->printOnImage($image, sprintf('%02d', $order['cop']), 430, 680);
                 $this->printOnImage($image, waRequest::request('order_amount', waCurrency::format($format, $order->total, $order->currency)), 650, 620, 30);
                 $this->printOnImage($image, $this->company_name, 210, 875);
                 $this->printOnImage($image, $this->address1, 210, 957);
                 $this->printOnImage($image, $this->address2, 70, 1040);
                 $this->printOnImagePersign($image, $this->zip, 1965, 1020, 58.3, 50);
                 $this->printOnImagePersign($image, $this->inn, 227, 1330, 55.5, 45);
                 $this->printOnImagePersign($image, $this->bank_kor_number, 1207, 1330, 55.5, 45);
                 $this->printOnImage($image, $this->bank_name, 570, 1405);
                 $this->printOnImagePersign($image, $this->bank_account_number, 310, 1470, 55.5, 45);
                 $this->printOnImagePersign($image, $this->bik, 1815, 1470, 55.5, 45);
                 header("Content-type: image/gif");
                 imagegif($image);
                 exit;
             } else {
                 throw new waException('Image not found', 404);
             }
             break;
         case 'print':
             if (!$strict && !$order) {
                 $this->view()->assign('action', 'preview');
             }
             $this->view()->assign('editable', waRequest::post() ? false : true);
             break;
         default:
             $this->view()->assign('src_front', http_build_query(array_merge($request, array('side' => 'front'))));
             if (!$strict && !$order) {
                 $this->view()->assign('action', 'preview');
             }
             $this->view()->assign('order', $order);
             $this->view()->assign('editable', waRequest::post() ? false : true);
             break;
     }
     return $this->view()->fetch($this->path . '/templates/form112.html');
 }