function listGiftCertificates()
 {
     global $osC_Database, $toC_Json, $osC_Language, $osC_Currencies;
     $osC_Currencies = new osC_Currencies_Admin();
     $start = empty($_REQUEST['start']) ? 0 : $_REQUEST['start'];
     $limit = empty($_REQUEST['limit']) ? MAX_DISPLAY_SEARCH_RESULTS : $_REQUEST['limit'];
     $Qcertificates = $osC_Database->query('select gc.*, o.customers_name, o.date_purchased from :table_gift_certificates gc, :table_orders o, :table_orders_products op where gc.orders_products_id = op.orders_products_id and op.orders_id = o.orders_id ');
     if (!empty($_REQUEST['search'])) {
         $Qcertificates->appendQuery('and o.customers_name like :customers_name');
         $Qcertificates->bindValue(':customers_name', '%' . $_REQUEST['search'] . '%');
     }
     $Qcertificates->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
     $Qcertificates->bindTable(':table_orders', TABLE_ORDERS);
     $Qcertificates->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
     $Qcertificates->setExtBatchLimit($start, $limit);
     $Qcertificates->execute();
     $records = array();
     while ($Qcertificates->next()) {
         $Qhistory = $osC_Database->query('select gcrh.*, o.customers_name from :table_gift_certificates_redeem_history gcrh, :table_orders o where gcrh.orders_id = o.orders_id and gcrh.gift_certificates_id = :gift_certificates_id');
         $Qhistory->bindTable(':table_gift_certificates_redeem_history', TABLE_GIFT_CERTIFICATES_REDEEM_HISTORY);
         $Qhistory->bindTable(':table_orders', TABLE_ORDERS);
         $Qhistory->bindInt(':gift_certificates_id', $Qcertificates->ValueInt('gift_certificates_id'));
         $Qhistory->execute();
         $history = '<table style="padding-left: 20px;" cellspacing="5">
                  <tr>
                    <td>' . $osC_Language->get('table_heading_customer') . '</td>
                    <td>' . $osC_Language->get('table_heading_redeem_date') . '</td>
                    <td>' . $osC_Language->get('table_heading_redeem_amount') . '</td>
                  </tr>';
         $redeem_amount = 0;
         while ($Qhistory->next()) {
             $redeem_amount += $Qhistory->Value('redeem_amount');
             $history .= '<tr><td>' . $Qhistory->Value('customers_name') . '</td>
                        <td>' . osC_DateTime::getShort($Qhistory->Value('redeem_date')) . '</td>
                        <td>' . $osC_Currencies->format($Qhistory->Value('redeem_amount')) . '</td></tr>';
         }
         $history .= '</table>';
         $Qhistory->freeResult();
         $certificate_details = '<table style="padding-left: 20px" cellspacing="5">';
         $certificate_details .= '<tr><td>' . $osC_Language->get('field_recipient_name') . '</td><td>' . $Qcertificates->Value('recipients_name') . '</td></tr>';
         if ($Qcertificates->valueInt('gift_certificates_type') == GIFT_CERTIFICATE_TYPE_EMAIL) {
             $certificate_details .= '<tr><td>' . $osC_Language->get('field_recipient_email') . '</td><td>' . $Qcertificates->Value('recipients_email') . '</td></tr>';
         }
         $certificate_details .= '<tr><td>' . $osC_Language->get('field_recipient_sender_name') . '</td><td>' . $Qcertificates->Value('senders_name') . '</td></tr>';
         if ($Qcertificates->valueInt('gift_certificates_type') == GIFT_CERTIFICATE_TYPE_EMAIL) {
             $certificate_details .= '<tr><td>' . $osC_Language->get('field_recipient_sender_email') . '</td><td>' . $Qcertificates->Value('senders_email') . '</td></tr>';
         }
         $certificate_details .= '<tr><td>' . $osC_Language->get('field_message') . '</td><td>' . $Qcertificates->Value('messages') . '</td></tr>';
         $certificate_details .= '</table>';
         $records[] = array('gift_certificates_id' => $Qcertificates->ValueInt('gift_certificates_id'), 'orders_products_id' => $Qcertificates->ValueInt('orders_products_id'), 'gift_certificates_code' => $Qcertificates->Value('gift_certificates_code'), 'gift_certificates_customer' => $Qcertificates->Value('customers_name'), 'gift_certificates_amount' => $osC_Currencies->format($Qcertificates->Value('amount')), 'gift_certificates_balance' => $osC_Currencies->format($Qcertificates->Value('amount') - $redeem_amount), 'gift_certificates_date_purchased' => osC_DateTime::getShort($Qcertificates->Value('date_purchased')), 'gift_certificates_date_status' => $Qcertificates->Value('status'), 'recipients_name' => $Qcertificates->Value('recipients_name'), 'recipients_email' => $Qcertificates->Value('recipients_email'), 'senders_name' => $Qcertificates->Value('senders_name'), 'senders_email' => $Qcertificates->Value('senders_email'), 'messages' => $Qcertificates->Value('messages'), 'certificate_details' => $certificate_details, 'history' => $history);
     }
     $response = array(EXT_JSON_READER_TOTAL => $Qcertificates->getBatchSize(), EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }
Exemple #2
0
 function listCurrencies()
 {
     global $toC_Json, $osC_Database, $osC_Language;
     $osC_Currencies = new osC_Currencies_Admin();
     $start = empty($_REQUEST['start']) ? 0 : $_REQUEST['start'];
     $limit = empty($_REQUEST['limit']) ? MAX_DISPLAY_SEARCH_RESULTS : $_REQUEST['limit'];
     $Qcurrencies = $osC_Database->query('select * from :table_currencies order by title');
     $Qcurrencies->bindTable(':table_currencies', TABLE_CURRENCIES);
     $Qcurrencies->setExtBatchLimit($start, $limit);
     $Qcurrencies->execute();
     $records = array();
     while ($Qcurrencies->next()) {
         $currency_name = $Qcurrencies->value('title');
         if ($Qcurrencies->value('code') == DEFAULT_CURRENCY) {
             $currency_name .= ' (' . $osC_Language->get('default_entry') . ')';
         }
         $records[] = array('currencies_id' => $Qcurrencies->valueInt('currencies_id'), 'title' => $currency_name, 'code' => $Qcurrencies->value('code'), 'value' => $Qcurrencies->value('value'), 'example' => $osC_Currencies->format(1499.99, $Qcurrencies->value('code'), 1));
     }
     $response = array(EXT_JSON_READER_TOTAL => $Qcurrencies->getBatchSize(), EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }
 function setStatus($id, $flag)
 {
     global $osC_Database;
     $Qstatus = $osC_Database->query('update :table_gift_certificates set status = :gift_certificates_status where gift_certificates_id = :gift_certificates_id');
     $Qstatus->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
     $Qstatus->bindInt(':gift_certificates_status', $flag);
     $Qstatus->bindInt(':gift_certificates_id', $id);
     $Qstatus->setLogging($_SESSION['module'], $id);
     $Qstatus->execute();
     if (!$osC_Database->isError()) {
         $data = self::getData($id);
         if ($flag == '1' && $data['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
             require_once 'includes/classes/currencies.php';
             $osC_Currencies = new osC_Currencies_Admin();
             require_once '../includes/classes/email_template.php';
             $email = toC_Email_Template::getEmailTemplate('active_gift_certificate');
             $email->setData($data['senders_name'], $data['senders_email'], $data['recipients_name'], $data['recipients_email'], $osC_Currencies->format($data['amount']), $data['gift_certificates_code'], $data['messages']);
             $email->buildMessage();
             $email->sendEmail();
         }
         return true;
     }
     return false;
 }
Exemple #4
0
 function getRefundHistory()
 {
     global $osC_Database, $osC_Language, $toC_Json;
     $osC_Currencies = new osC_Currencies_Admin();
     $osC_Order = new osC_Order($_REQUEST['orders_id']);
     $Qrefunds = $osC_Database->query('select * from :table_orders_refunds where orders_id = :orders_id');
     $Qrefunds->bindTable(':table_orders_refunds', TABLE_ORDERS_REFUNDS);
     $Qrefunds->bindInt(':orders_id', $_REQUEST['orders_id']);
     $Qrefunds->execute();
     $records = array();
     while ($Qrefunds->next()) {
         $Qproducts = $osC_Database->query('select * from :table_orders_refunds_products where orders_refunds_id = :orders_refunds_id');
         $Qproducts->bindTable(':table_orders_refunds_products', TABLE_ORDERS_REFUNDS_PRODUCTS);
         $Qproducts->bindInt(':orders_refunds_id', $Qrefunds->valueInt('orders_refunds_id'));
         $Qproducts->execute();
         $total_products = 0;
         $products = array();
         $products_table = '<table width="100%">';
         while ($Qproducts->next()) {
             foreach ($osC_Order->getProducts() as $product) {
                 if ($Qproducts->valueInt('orders_products_id') == $product['orders_products_id']) {
                     $total_products += $Qproducts->valueInt('products_quantity');
                     $product_info = $Qproducts->valueInt('products_quantity') . '&nbsp;x&nbsp;' . $product['name'];
                     if ($product['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_name') . ': ' . $product['senders_name'] . '</i></nobr>';
                         if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                             $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_email') . ': ' . $product['senders_email'] . '</i></nobr>';
                         }
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_name') . ': ' . $product['recipients_name'] . '</i></nobr>';
                         if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                             $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_email') . ': ' . $product['recipients_email'] . '</i></nobr>';
                         }
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('messages') . ': ' . $product['messages'] . '</i></nobr>';
                     }
                     if (isset($product['variants']) && is_array($product['variants']) && sizeof($product['variants']) > 0) {
                         foreach ($product['variants'] as $variants) {
                             $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $variants['groups_name'] . ': ' . $variants['values_name'] . '</i></nobr>';
                         }
                     }
                     $products[] = $product_info;
                     $products_table .= '<tr><td>' . $product_info . '</td><td width="60" valign="top" align="right">' . $osC_Currencies->displayPriceWithTaxRate($product['final_price'], $product['tax'], 1, $osC_Order->getCurrency(), $osC_Order->getCurrencyValue()) . '</td></tr>';
                 }
             }
         }
         $products_table .= '</table>';
         $order_total = '<table width="100%">';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_sub_total") . '&nbsp;&nbsp;&nbsp;</td><td width="60">' . $osC_Currencies->format($Qrefunds->value('sub_total')) . '</td></tr>';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_shipping_fee") . '&nbsp;&nbsp;&nbsp;</td><td width="60">' . $osC_Currencies->format($Qrefunds->value('shipping')) . '</td></tr>';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_handling") . '&nbsp;&nbsp;&nbsp;</td><td width="60">' . $osC_Currencies->format($Qrefunds->value('handling')) . '</td></tr>';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_refund_total") . '&nbsp;&nbsp;&nbsp;</td><td width="60">' . $osC_Currencies->format($Qrefunds->value('refund_total')) . '</td></tr>';
         $order_total .= '</table>';
         $records[] = array('orders_refunds_id' => $Qrefunds->valueInt('orders_refunds_id'), 'orders_refunds_type' => $Qrefunds->valueInt('orders_refunds_type') == ORDERS_RETURNS_TYPE_CREDIT_SLIP ? $osC_Language->get('text_credit_slip') : $osC_Language->get('text_store_credit'), 'total_products' => $total_products, 'total_refund' => $osC_Currencies->format($Qrefunds->value('refund_total')), 'sub_total' => $osC_Currencies->format($Qrefunds->value('sub_total')), 'date_added' => osC_DateTime::getShort($Qrefunds->value('date_added')), 'comments' => $Qrefunds->value('comments'), 'products' => $products_table, 'totals' => $order_total);
     }
     $response = array(EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }
Exemple #5
0
 function activeGiftCertificates($orders_id)
 {
     global $osC_Database;
     require_once 'includes/classes/currencies.php';
     $osC_Currencies = new osC_Currencies_Admin();
     //create email template object
     require_once '../includes/classes/email_template.php';
     $email = toC_Email_Template::getEmailTemplate('active_gift_certificate');
     //retrieve gift certifcates
     $Qcertificates = $osC_Database->query('select * from :table_gift_certificates where orders_id = :orders_id');
     $Qcertificates->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
     $Qcertificates->bindInt(':orders_id', $orders_id);
     $Qcertificates->execute();
     while ($Qcertificates->next()) {
         if ($Qcertificates->valueInt('status') == 0) {
             //update gift certificate status
             $Qupdate = $osC_Database->query('update :table_gift_certificates set status = :status where gift_certificates_id = :gift_certificates_id');
             $Qupdate->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
             $Qupdate->bindInt(':status', 1);
             $Qupdate->bindInt(':gift_certificates_id', $Qcertificates->valueInt('gift_certificates_id'));
             $Qupdate->setLogging($_SESSION['module'], $orders_id);
             $Qupdate->execute();
             //send notification email
             if ($Qcertificates->valueInt('type') == GIFT_CERTIFICATE_TYPE_EMAIL) {
                 $email->resetRecipients();
                 $email->setData($Qcertificates->value('senders_name'), $Qcertificates->value('senders_email'), $Qcertificates->value('recipients_name'), $Qcertificates->value('recipients_email'), $osC_Currencies->format($Qcertificates->value('amount')), $Qcertificates->value('gift_certificates_code'), $Qcertificates->value('messages'));
                 $email->buildMessage();
                 $email->sendEmail();
             }
         }
     }
 }
 function listCreditsMemo()
 {
     global $toC_Json, $osC_Database, $osC_Language;
     $osC_Currencies = new osC_Currencies_Admin();
     $start = empty($_REQUEST['start']) ? 0 : $_REQUEST['start'];
     $limit = empty($_REQUEST['limit']) ? MAX_DISPLAY_SEARCH_RESULTS : $_REQUEST['limit'];
     $Qslips = $osC_Database->query('select r.* from :table_orders_refunds r ');
     if (isset($_REQUEST['customers_id']) && !empty($_REQUEST['customers_id'])) {
         $Qslips->appendQuery(', ' . TABLE_ORDERS . ' o where r.orders_id = o.orders_id and o.customers_id = :customers_id and r.orders_refunds_type = :orders_refunds_type');
         $Qslips->bindInt(':customers_id', $_REQUEST['customers_id']);
     } else {
         $Qslips->appendQuery('where orders_refunds_type = :orders_refunds_type');
     }
     if (isset($_REQUEST['orders_id']) && !empty($_REQUEST['orders_id'])) {
         $Qslips->appendQuery('and orders_id = :orders_id ');
         $Qslips->bindInt(':orders_id', $_REQUEST['orders_id']);
     }
     $Qslips->bindTable(':table_orders_refunds', TABLE_ORDERS_REFUNDS);
     $Qslips->bindInt(':orders_refunds_type', ORDERS_RETURNS_TYPE_CREDIT_SLIP);
     $Qslips->setExtBatchLimit($start, $limit);
     $Qslips->execute();
     $records = array();
     while ($Qslips->next()) {
         $orders_refunds_id = $Qslips->value('orders_refunds_id');
         $Qproducts = $osC_Database->query("select orders_products_id, products_quantity from :table_orders_refunds_products where orders_refunds_id = :orders_refunds_id");
         $Qproducts->bindTable(':table_orders_refunds_products', TABLE_ORDERS_REFUNDS_PRODUCTS);
         $Qproducts->bindInt(':orders_refunds_id', $orders_refunds_id);
         $Qproducts->execute();
         $products_ids = array();
         $products_qty = array();
         while ($Qproducts->next()) {
             $products_ids[] = $Qproducts->valueInt('orders_products_id');
             $products_qty[$Qproducts->valueInt('orders_products_id')] = $Qproducts->valueInt('products_quantity');
         }
         $total = 0;
         $quantity = 0;
         $products = array();
         $osC_Order = new osC_Order($Qslips->valueInt('orders_id'));
         $products_table = '<table width="100%">';
         foreach ($osC_Order->getProducts() as $product) {
             if (in_array($product['orders_products_id'], $products_ids)) {
                 $product_info = $products_qty[$product['orders_products_id']] . '&nbsp;x&nbsp;' . $product['name'];
                 if ($product['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_name') . ': ' . $product['senders_name'] . '</i></nobr>';
                     if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_email') . ': ' . $product['senders_email'] . '</i></nobr>';
                     }
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_name') . ': ' . $product['recipients_name'] . '</i></nobr>';
                     if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_email') . ': ' . $product['recipients_email'] . '</i></nobr>';
                     }
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('messages') . ': ' . $product['messages'] . '</i></nobr>';
                 }
                 if (isset($product['variants']) && is_array($product['variants']) && sizeof($product['variants']) > 0) {
                     foreach ($product['variants'] as $variants) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $variants['groups_name'] . ': ' . $variants['values_name'] . '</i></nobr>';
                     }
                 }
                 $products[] = $product_info;
                 $quantity += $products_qty[$product['orders_products_id']];
                 $products_table .= '<tr><td>' . $product_info . '</td><td width="60" valign="top" align="right">' . $osC_Currencies->displayPriceWithTaxRate($product['final_price'], $product['tax'], 1, $osC_Order->getCurrency(), $osC_Order->getCurrencyValue()) . '</td></tr>';
             }
         }
         $products_table .= '</table>';
         $order_total = '<table width="100%">';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_sub_total") . '&nbsp;&nbsp;&nbsp;</td><td width="60" align="right">' . $osC_Currencies->format($Qslips->value('sub_total')) . '</td></tr>';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_shipping_fee") . '&nbsp;&nbsp;&nbsp;</td><td width="60" align="right">' . $osC_Currencies->format($Qslips->value('shipping')) . '</td></tr>';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_handling") . '&nbsp;&nbsp;&nbsp;</td><td width="60" align="right">' . $osC_Currencies->format($Qslips->value('handling')) . '</td></tr>';
         $order_total .= '<tr><td align="right">' . $osC_Language->get("field_refund_total") . '&nbsp;&nbsp;&nbsp;</td><td width="60" align="right">' . $osC_Currencies->format($Qslips->value('refund_total')) . '</td></tr>';
         $order_total .= '</table>';
         $records[] = array('orders_refunds_id' => $Qslips->valueInt('orders_refunds_id'), 'credit_slips_id' => $Qslips->valueInt('credit_slips_id'), 'orders_id' => $Qslips->valueInt('orders_id'), 'customers_name' => $osC_Order->getCustomer('name'), 'total_products' => $quantity, 'total_refund' => $osC_Currencies->format($Qslips->value('refund_total')), 'sub_total' => $osC_Currencies->format($Qslips->value('sub_total')), 'date_added' => osC_DateTime::getShort($Qslips->value('date_added')), 'shipping_address' => osC_Address::format($osC_Order->getDelivery(), '<br />'), 'shipping_method' => $osC_Order->getDeliverMethod(), 'billing_address' => osC_Address::format($osC_Order->getBilling(), '<br />'), 'payment_method' => $osC_Order->getPaymentMethod(), 'comments' => $Qslips->value('comments'), 'products' => $products_table, 'totals' => $order_total);
     }
     $response = array(EXT_JSON_READER_TOTAL => $Qslips->getBatchSize(), EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }
Exemple #7
0
 function saveBlance()
 {
     global $toC_Json, $osC_Language, $osC_Database;
     $osC_Currencies = new osC_Currencies_Admin();
     $data = array('amount' => $_REQUEST['amount'], 'comments' => $_REQUEST['comments'], 'customers_id' => $_REQUEST['customers_id'], 'notify' => isset($_REQUEST['notify']) && $_REQUEST['notify'] == 'on' ? '1' : '0');
     if (osC_Customers_Admin::saveBlance($data)) {
         $data = osC_Customers_Admin::getData($_REQUEST['customers_id']);
         $response = array('success' => true, 'customers_credits' => $osC_Currencies->format($data['customers_credits']), 'feedback' => $osC_Language->get('ms_success_action_performed'));
     } else {
         $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed'));
     }
     echo $toC_Json->encode($response);
 }
Exemple #8
0
 function render()
 {
     global $osC_Language;
     //New Page
     $this->_pdf->AddPage();
     //Title
     $this->_pdf->SetFont(TOC_PDF_FONT_B, 'B', TOC_PDF_TITLE_FONT_SIZE);
     $this->_pdf->SetY(TOC_PDF_POS_HEADING_TITLE_Y);
     $this->_pdf->MultiCell(0, 4, $osC_Language->get('pdf_order_heading_title'), 0, 'C');
     //Date purchase & order ID field title
     $this->_pdf->SetFont(TOC_PDF_FONT_B, 'B', TOC_PDF_FIELD_DATE_PURCHASE_FONT_SIZE);
     $this->_pdf->SetY(TOC_PDF_POS_DOC_INFO_FIELD_Y);
     $this->_pdf->SetX(150);
     $this->_pdf->MultiCell(25, 5, $osC_Language->get('operation_heading_order_date') . ':' . "\n" . $osC_Language->get('operation_heading_order_id') . ':', 0, 'R');
     //Date purchase & order ID field value
     $this->_pdf->SetFont(TOC_PDF_FONT, '', TOC_PDF_FIELD_DATE_PURCHASE_FONT_SIZE);
     $this->_pdf->SetY(TOC_PDF_POS_DOC_INFO_VALUE_Y);
     $this->_pdf->SetX(175);
     $this->_pdf->MultiCell(45, 5, osC_DateTime::getShort($this->_order->getDateCreated()) . "\n" . $this->_order->getOrderID(), 0, 'R');
     //Products
     $this->_pdf->SetFont(TOC_PDF_FONT_B, 'B', TOC_PDF_TABLE_HEADING_FONT_SIZE);
     $this->_pdf->SetY(TOC_PDF_POS_PRODUCTS_TABLE_HEADING_Y);
     $this->_pdf->Cell(10, 6, '', 'TB', 0, 'R', 0);
     $this->_pdf->Cell(80, 6, $osC_Language->get('table_heading_products'), 'TB', 0, 'C', 0);
     $this->_pdf->Cell(37, 6, $osC_Language->get('table_heading_quantity'), 'TB', 0, 'C', 0);
     $this->_pdf->Cell(32, 6, $osC_Language->get('table_heading_price'), 'TB', 0, 'C', 0);
     $this->_pdf->Cell(32, 6, $osC_Language->get('table_heading_total'), 'TB', 0, 'C', 0);
     $this->_pdf->Ln();
     $i = 0;
     $y_table_position = TOC_PDF_POS_PRODUCTS_TABLE_CONTENT_Y;
     $osC_Currencies = new osC_Currencies_Admin();
     foreach ($this->_order->getProducts() as $products) {
         $rowspan = 1;
         //Pos
         $this->_pdf->SetFont(TOC_PDF_FONT, 'B', TOC_PDF_TABLE_CONTENT_FONT_SIZE);
         $this->_pdf->SetY($y_table_position);
         $this->_pdf->MultiCell(8, 4, $i + 1, 0, 'C');
         //Product
         $this->_pdf->SetY($y_table_position);
         $this->_pdf->SetX(30);
         $product_info = $products['name'];
         if (strlen($products['name']) > 70) {
             $rowspan = 2;
         }
         if ($products['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
             $product_info .= "\n" . '   -' . $osC_Language->get('senders_name') . ': ' . $products['senders_name'];
             if ($products['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                 $product_info .= "\n" . '   -' . $osC_Language->get('senders_email') . ': ' . $products['senders_email'];
                 $rowspan++;
             }
             $product_info .= "\n" . '   -' . $osC_Language->get('recipients_name') . ': ' . $products['recipients_name'];
             if ($products['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                 $product_info .= "\n" . '   -' . $osC_Language->get('recipients_email') . ': ' . $products['recipients_email'];
                 $rowspan++;
             }
             $rowspan += 3;
             $product_info .= "\n" . '   -' . $osC_Language->get('messages') . ': ' . $products['messages'];
         }
         if (isset($products['variants']) && sizeof($products['variants']) > 0) {
             foreach ($products['variants'] as $variant) {
                 $product_info .= "\n" . $variant['groups_name'] . ": " . $variant['values_name'];
                 $rowspan++;
             }
         }
         $this->_pdf->MultiCell(80, 4, $product_info, 0, 'R');
         //Quantity
         $this->_pdf->SetY($y_table_position);
         $this->_pdf->SetX(113);
         $this->_pdf->MultiCell(10, 4, $products['quantity'], 0, 'C');
         //Price
         $this->_pdf->SetY($y_table_position);
         $this->_pdf->SetX(143);
         $price = $osC_Currencies->displayPriceWithTaxRate($products['final_price'], $products['tax'], 1, $this->_order->getCurrency(), $this->_order->getCurrencyValue());
         $price = str_replace('&nbsp;', ' ', $price);
         $this->_pdf->MultiCell(20, 4, $price, 0, 'C');
         //Total
         $this->_pdf->SetY($y_table_position);
         $this->_pdf->SetX(172);
         $total = $osC_Currencies->displayPriceWithTaxRate($products['final_price'], $products['tax'], $products['quantity'], $this->_order->getCurrency(), $this->_order->getCurrencyValue());
         $total = str_replace('&nbsp;', ' ', $total);
         $this->_pdf->MultiCell(30, 4, $total, 0, 'C');
         $y_table_position += $rowspan * TOC_PDF_TABLE_CONTENT_HEIGHT;
         //products list exceed page height, create a new page
         if ($y_table_position - TOC_PDF_POS_CONTENT_Y - 6 > 160) {
             $this->_pdf->AddPage();
             $y_table_position = TOC_PDF_POS_CONTENT_Y + 6;
             $this->_pdf->SetFont(TOC_PDF_FONT_B, 'B', TOC_PDF_TABLE_HEADING_FONT_SIZE);
             $this->_pdf->SetY(TOC_PDF_POS_CONTENT_Y);
             $this->_pdf->Cell(10, 6, '', 'TB', 0, 'R', 0);
             $this->_pdf->Cell(80, 6, $osC_Language->get('table_heading_products'), 'TB', 0, 'C', 0);
             $this->_pdf->Cell(37, 6, $osC_Language->get('table_heading_quantity'), 'TB', 0, 'C', 0);
             $this->_pdf->Cell(32, 6, $osC_Language->get('table_heading_price'), 'TB', 0, 'C', 0);
             $this->_pdf->Cell(32, 6, $osC_Language->get('table_heading_total'), 'TB', 0, 'C', 0);
             $this->_pdf->Ln();
         }
         $i++;
     }
     $this->_pdf->SetY($y_table_position + 1);
     $this->_pdf->Cell(191, 7, '', 'T', 0, 'C', 0);
     //Order Totals
     $this->_pdf->SetFont(TOC_PDF_FONT, 'B', TOC_PDF_TABLE_CONTENT_FONT_SIZE);
     foreach ($this->_order->getTotals() as $totals) {
         $y_table_position += 4;
         $this->_pdf->SetFont(TOC_PDF_FONT_B, 'B', TOC_PDF_TOTAL_FONT_SIZE);
         $this->_pdf->SetY($y_table_position);
         $this->_pdf->SetX(40);
         $this->_pdf->MultiCell(120, 5, $totals['title'], 0, 'L');
         $total_text = str_replace('&nbsp;', ' ', $totals['value']);
         $total_text = $osC_Currencies->format($total_text, $this->_order->getCurrency(), $this->_order->getCurrencyValue());
         $this->_pdf->SetFont(TOC_PDF_FONT, 'B', TOC_PDF_TOTAL_FONT_SIZE);
         $this->_pdf->SetY($y_table_position);
         $this->_pdf->SetX(166);
         $this->_pdf->MultiCell(40, 5, strip_tags($total_text), 0, 'C');
     }
     $this->_pdf->Output("Order.pdf", "I");
 }
 function createStoreCredit($data)
 {
     global $osC_Database, $osC_Language;
     $error = false;
     $osC_Database->startTransaction();
     //order refund
     $Qinsert = $osC_Database->query('insert into :table_orders_refunds (orders_refunds_type, orders_id, credit_slips_id, sub_total, shipping, handling, refund_total, comments, date_added) values (:orders_refunds_type, :orders_id, :credit_slips_id, :sub_total, :shipping, :handling, :refund_total, :comments, now())');
     $Qinsert->bindTable(':table_orders_refunds', TABLE_ORDERS_REFUNDS);
     $Qinsert->bindInt(':orders_refunds_type', ORDERS_RETURNS_TYPE_STORE_CREDIT);
     $Qinsert->bindInt(':orders_id', $data['orders_id']);
     $Qinsert->bindRaw(':credit_slips_id', 'null');
     $Qinsert->bindValue(':sub_total', $data['sub_total']);
     $Qinsert->bindValue(':shipping', $data['shipping_fee']);
     $Qinsert->bindValue(':handling', $data['handling']);
     $Qinsert->bindValue(':refund_total', $data['sub_total'] + $data['shipping_fee'] + $data['handling']);
     $Qinsert->bindValue(':comments', $data['comments']);
     $Qinsert->setLogging($_SESSION['module'], null);
     $Qinsert->execute();
     if ($osC_Database->isError()) {
         $error = true;
     } else {
         $orders_refunds_id = $osC_Database->nextID();
         //orders refunds products
         $return_products = explode(';', $data['return_quantity']);
         foreach ($return_products as $product) {
             list($orders_products_id, $quantity) = explode(':', $product);
             $Qproduct = $osC_Database->query('insert into :table_orders_refunds_products (orders_refunds_id, orders_products_id, products_quantity) values (:orders_refunds_id, :orders_products_id, :products_quantity)');
             $Qproduct->bindTable(':table_orders_refunds_products', TABLE_ORDERS_REFUNDS_PRODUCTS);
             $Qproduct->bindInt(':orders_refunds_id', $orders_refunds_id);
             $Qproduct->bindInt(':orders_products_id', $orders_products_id);
             $Qproduct->bindInt(':products_quantity', $quantity);
             $Qproduct->setLogging($_SESSION['module'], $orders_refunds_id);
             $Qproduct->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
             if ($error === false) {
                 $Qupdate = $osC_Database->query('update :table_orders_products set products_return_quantity = products_return_quantity + :products_return_quantity where orders_products_id = :orders_products_id');
                 $Qupdate->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
                 $Qupdate->bindInt(':products_return_quantity', $quantity);
                 $Qupdate->bindInt(':orders_products_id', $orders_products_id);
                 $Qupdate->setLogging($_SESSION['module'], $orders_refunds_id);
                 $Qupdate->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                     break;
                 }
             }
             if ($error === false && $data['restock_quantity'] === true) {
                 $Qcheck = $osC_Database->query('select products_id from :table_orders_products where orders_products_id = :orders_products_id and orders_id = :orders_id');
                 $Qcheck->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
                 $Qcheck->bindInt(':orders_products_id', $orders_products_id);
                 $Qcheck->bindInt(':orders_id', $data['orders_id']);
                 $Qcheck->setLogging($_SESSION['module'], $orders_refunds_id);
                 $Qcheck->execute();
                 $products_id = $Qcheck->valueInt('products_id');
                 if (!osC_Product::restock($data['orders_id'], $orders_products_id, $products_id, $quantity)) {
                     $error = true;
                     break;
                 }
             }
         }
     }
     if ($error === false) {
         $Qreturn = $osC_Database->query('update :table_orders_returns set orders_returns_status_id = :orders_returns_status_id, admin_comments = :admin_comments, date_updated = now() where orders_returns_id = :id');
         $Qreturn->bindTable(':table_orders_returns', TABLE_ORDERS_RETURNS);
         $Qreturn->bindInt(':orders_returns_status_id', ORDERS_RETURNS_STATUS_REFUNDED_STORE_CREDIT);
         $Qreturn->bindValue(':admin_comments', $data['comment']);
         $Qreturn->bindInt(':id', $data['orders_returns_id']);
         $Qreturn->setLogging($_SESSION['module'], $data['orders_returns_id']);
         $Qreturn->execute();
         if ($osC_Database->isError()) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
         $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
         $Qcustomer->bindInt(':orders_id', $data['orders_id']);
         $Qcustomer->execute();
         $customers_id = $Qcustomer->valueInt('customers_id');
         $Qhistory = $osC_Database->query('insert into :table_customers_credits_history (customers_id, action_type, date_added, amount, comments) values (:customers_id, :action_type, now(), :amount, :comments)');
         $Qhistory->bindTable(':table_customers_credits_history', TABLE_CUSTOMERS_CREDITS_HISTORY);
         $Qhistory->bindInt(':customers_id', $customers_id);
         $Qhistory->bindInt(':action_type', STORE_CREDIT_ACTION_TYPE_ORDER_REFUNDED);
         $Qhistory->bindValue(':amount', $data['sub_total'] + $data['shipping_fee'] + $data['handling']);
         $Qhistory->bindValue(':comments', sprintf($osC_Language->get('infomation_store_credit_from_order'), $data['orders_id']));
         $Qhistory->execute();
         if ($osC_Database->isError()) {
             $error = true;
         }
         if ($error === false) {
             $Qupdate = $osC_Database->query('update :table_customers set customers_credits = (customers_credits + :customers_credits) where customers_id = :customers_id');
             $Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS);
             $Qupdate->bindRaw(':customers_credits', $data['sub_total'] + $data['shipping_fee'] + $data['handling']);
             $Qupdate->bindInt(':customers_id', $customers_id);
             $Qupdate->setLogging($_SESSION['module'], $data['$orders_refunds_id']);
             $Qupdate->execute();
             if ($osC_Database->isError()) {
                 $error = true;
             }
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         $osC_Order = new osC_Order($data['orders_id']);
         $return_products_ids = array();
         $return_products_qty = array();
         $return_products = explode(';', $data['return_quantity']);
         foreach ($return_products as $product) {
             list($orders_products_id, $quantity) = explode(':', $product);
             $return_products_ids[] = $orders_products_id;
             $return_products_qty[$orders_products_id] = $quantity;
         }
         $products = array();
         foreach ($osC_Order->getProducts() as $product) {
             if (in_array($product['orders_products_id'], $return_products_ids)) {
                 $product_info = $return_products_qty[$product['orders_products_id']] . '&nbsp;x&nbsp;' . $product['name'];
                 if ($product['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_name') . ': ' . $product['senders_name'] . '</i></nobr>';
                     if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_email') . ': ' . $product['senders_email'] . '</i></nobr>';
                     }
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_name') . ': ' . $product['recipients_name'] . '</i></nobr>';
                     if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_email') . ': ' . $product['recipients_email'] . '</i></nobr>';
                     }
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('messages') . ': ' . $product['messages'] . '</i></nobr>';
                 }
                 if (isset($product['variants']) && is_array($product['variants']) && sizeof($product['variants']) > 0) {
                     foreach ($product['variants'] as $variants) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $variants['groups_name'] . ': ' . $variants['values_name'] . '</i></nobr>';
                     }
                 }
                 $products[] = $product_info;
             }
         }
         $customers_name = $osC_Order->getCustomer('name');
         $customers_email_address = $osC_Order->getCustomer('email_address');
         require_once 'includes/classes/currencies.php';
         $osC_Currencies = new osC_Currencies_Admin();
         include '../includes/classes/email_template.php';
         $email_template = toC_Email_Template::getEmailTemplate('admin_create_order_store_credit');
         $email_template->setData($customers_name, $customers_email_address, implode('<br />', $products), $data['orders_id'], $osC_Currencies->format($data['sub_total'] + $data['shipping_fee'] + $data['handling']));
         $email_template->buildMessage();
         $email_template->sendEmail();
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
 function getRedeemHistory()
 {
     global $toC_Json, $osC_Database;
     $start = empty($_REQUEST['start']) ? 0 : $_REQUEST['start'];
     $limit = empty($_REQUEST['limit']) ? MAX_DISPLAY_SEARCH_RESULTS : $_REQUEST['limit'];
     $coupons_id = isset($_REQUEST['coupons_id']) && is_numeric($_REQUEST['coupons_id']) ? $_REQUEST['coupons_id'] : null;
     $osC_Currencies = new osC_Currencies_Admin();
     $Qcoupons = $osC_Database->query("select crh.*, ot.value, c.customers_id, c.customers_firstname, c.customers_lastname from :table_coupons_redeem_history crh, :table_orders_total ot, :table_customers c where crh.coupons_id = :coupons_id and crh.orders_id = ot.orders_id and crh.customers_id = c.customers_id and ot.class = 'coupon' order by crh.orders_id");
     $Qcoupons->bindTable(':table_coupons_redeem_history', TABLE_COUPONS_REDEEM_HISTORY);
     $Qcoupons->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
     $Qcoupons->bindTable(':table_customers', TABLE_CUSTOMERS);
     $Qcoupons->bindInt(':coupons_id', $coupons_id);
     $Qcoupons->setExtBatchLimit($start, $limit);
     $Qcoupons->execute();
     $records = array();
     while ($Qcoupons->next()) {
         $records[] = array('customers_id' => $Qcoupons->valueInt('customers_id'), 'customers_name' => $Qcoupons->value('customers_firstname') . '&nbsp;' . $Qcoupons->value('customers_lastname'), 'orders_id' => $Qcoupons->valueInt('orders_id'), 'redeem_amount' => $osC_Currencies->format($Qcoupons->value('redeem_amount')), 'redeem_date' => osC_DateTime::getShort($Qcoupons->value('redeem_date')), 'redeem_id_address' => $Qcoupons->value('redeem_ip_address'));
     }
     $Qcoupons->freeResult();
     $response = array(EXT_JSON_READER_TOTAL => $Qcoupons->getBatchSize(), EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }