/** * @param int $customerId * @param int $invoiceId * @param Registry $registry * @param string $description */ public static function addPayment($customerId, $invoiceId, $registry, $description = "") { Transaction::$instance->log->write("Starting"); $customer = CustomerDAO::getInstance()->getCustomer($customerId); $invoice = InvoiceDAO::getInstance()->getInvoice($invoiceId); $transactionAmount = $invoice->getTotalCustomerCurrency(); if ($customer['balance'] < $transactionAmount && !$customer['allow_overdraft']) { InvoiceDAO::getInstance()->setInvoiceStatus($invoiceId, IS_AWAITING_PAYMENT); } else { $temp = $invoice->getCustomer(); Transaction::addTransaction($invoiceId, $customerId, $invoice->getTotalCustomerCurrency(), $temp['base_currency_code'], $description); InvoiceDAO::getInstance()->setInvoiceStatus($invoiceId, IS_PAID); } }
private function showEditForm() { if (!$this->parameters['invoiceId']) { return; } $invoice = InvoiceDAO::getInstance()->getInvoice($this->parameters['invoiceId']); /// Initialize interface values $this->data['button_action'] = $this->language->get('button_close'); $this->data['readOnly'] = "disabled"; $this->data['shippingMethods'] = ShippingMethodDAO::getInstance()->getShippingOptions($this->modelReferenceAddress->getAddress($invoice->getShippingAddressId())); $orderItemIdParam = ''; foreach ($invoice->getOrderItems() as $orderItem) { $this->data['orderItems'][] = array('id' => $orderItem->getId(), 'comment' => $orderItem->getPublicComment(), 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem->getImagePath()), 'model' => $orderItem->getModel(), 'name' => $orderItem->getName(), 'options' => OrderItemDAO::getInstance()->getOrderItemOptionsString($orderItem->getId()), 'order_id' => $orderItem->getOrderId(), 'price' => $this->getCurrency()->format($orderItem->getPrice(), $this->getConfig()->get('config_currency')), 'quantity' => $orderItem->getQuantity(), 'subtotal' => $this->getCurrency()->format($orderItem->getTotal(), $this->getConfig()->get('config_currency')), 'subtotalCustomerCurrency' => $this->getCurrency()->format($orderItem->getTotal(true), $orderItem->getCustomer()['base_currency_code'], 1), 'shipping' => $this->getCurrency()->format($orderItem->getShippingCost(), $this->getConfig()->get('config_currency'))); $orderItemIdParam .= '&orderItemId[]=' . $orderItem->getId(); } foreach ($this->data['orderItems'] as $item) { $ids[] = $item['id']; } if (empty($this->data['orderItems'])) { $_invoice = InvoiceDAO::getInstance()->getInvoice($this->parameters['invoiceId']); foreach (InvoiceDAO::getInstance()->getInvoiceItems($_invoice['invoice_id']) as $invoiceItem) { $orderItem = OrderItemDAO::getInstance()->getOrderItem($invoiceItem['order_item_id']); $this->data['orderItems'][] = array('id' => $orderItem->getId(), 'comment' => $orderItem->getPublicComment(), 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem->getImagePath()), 'model' => $orderItem->getModel(), 'name' => $orderItem->getName(), 'options' => OrderItemDAO::getInstance()->getOrderItemOptionsString($orderItem->getId()), 'order_id' => $orderItem->getOrderId(), 'price' => $this->currency->format($orderItem->getPrice(), $this->getConfig()->get('config_currency')), 'quantity' => $orderItem->getQuantity(), 'subtotal' => $this->currency->format($orderItem->getPrice() * $orderItem->getQuantity(), $this->getConfig()->get('config_currency'))); $orderItemIdParam .= '&orderItemId[]=' . $orderItem->getId(); } } $add = $this->modelReferenceAddress->getAddress($invoice->getShippingAddressId()); $this->getLoader()->model('sale/order'); $order_info = $this->model_sale_order->getOrderByShippingAddressId($invoice->getShippingAddressId()); /// Set invoice data // $customer = CustomerDAO::getInstance()->getCustomer($invoice['customer_id']); $this->data['comment'] = $invoice->getComment(); $this->data['discount'] = $invoice->getDiscount(); $this->data['invoiceId'] = $invoice->getId(); $this->data['packageNumber'] = $invoice->getPackageNumber(); $this->data['shippingAddress'] = nl2br($this->modelReferenceAddress->toString($invoice->getShippingAddressId())) . "<br />" . $order_info['shipping_phone']; //$add['phone']; $this->data['shippingCost'] = $this->getCurrency()->format($invoice->getShippingCost(), $this->getConfig()->get('config_currency')); $this->data['shippingCostRaw'] = $invoice->getShippingCost(); $this->data['shippingCostRoute'] = $this->url->link('sale/invoice/getShippingCost', 'token=' . $this->parameters['token'] . $orderItemIdParam, 'SSL'); $this->data['shippingMethod'] = $invoice->getShippingMethod(); $this->data['shippingDate'] = $invoice->getShippingDate(); $this->data['total'] = $this->getCurrency()->format($invoice->getSubtotal(), $this->getConfig()->get('config_currency')); $this->data['totalRaw'] = $invoice->getSubtotal(); $this->data['totalCustomerCurrency'] = $this->getCurrency()->format($invoice->getTotalCustomerCurrency(), $invoice->getCurrencyCode(), 1); $this->data['totalWeight'] = $invoice->getWeight(); $this->data['grandTotal'] = $this->getCurrency()->format($invoice->getTotal(), $this->getConfig()->get('config_currency')); $this->data['customerCurrencyCode'] = $invoice->getCurrencyCode(); // $this->log->write(print_r($this->data, true)); }
public function showForm() { // $this->log->write(print_r($this->session, true)); if (is_null($this->getRequest()->getParam('invoiceId'))) { return; } $modelOrderItem = $this->load->model('account/order_item'); $modelReferenceAddress = $this->load->model('reference/address'); $invoice = InvoiceDAO::getInstance()->getInvoice($this->getRequest()->getParam('invoiceId')); /// Initialize interface values $this->data['headingTitle'] = sprintf($this->language->get('INVOICE'), $invoice->getId()); $this->data['button_action'] = $this->language->get('button_close'); $this->data['submit_action'] = $this->url->link('account/invoice/close', '', 'SSL'); $this->data['textComment'] = $this->language->get('textComment'); $this->data['textConfirm'] = $this->language->get('CONFIRM'); $this->data['textDiscount'] = $this->language->get('DISCOUNT'); $this->data['textGrandTotal'] = $this->language->get('textGrandTotal'); $this->data['textItemImage'] = $this->language->get('textItemImage'); $this->data['textItemName'] = $this->language->get('textItemName'); $this->data['textOrderId'] = $this->language->get('textOrderId'); $this->data['textOrderItemId'] = $this->language->get('textOrderItemId'); $this->data['textPackageNumber'] = $this->language->get('PACKAGE_NUMBER'); $this->data['textPrice'] = $this->language->get('textPrice'); $this->data['textQuantity'] = $this->language->get('textQuantity'); $this->data['textShippingAddress'] = $this->language->get('textShippingAddress'); $this->data['textShippingCost'] = $this->language->get('textShippingCost'); $this->data['textShippingMethod'] = $this->language->get('textShippingMethod'); $this->data['textSubtotal'] = $this->language->get('SUBTOTAL'); $this->data['textTotal'] = $this->language->get('TOTAL'); $this->data['textWeight'] = $this->language->get('WEIGHT'); $temp = $invoice->getCustomer(); if ($temp['customer_id'] != $this->getCurrentCustomer()->getId()) { $invoice = null; $this->data['notifications']['error'] = $this->language->get('errorAccessDenied'); } else { /// Prepare list $subTotalCustomerCurrency = 0; foreach ($invoice->getOrderItems() as $orderItem) { $this->data['orderItems'][] = array('id' => $orderItem->getId(), 'comment' => $orderItem->getPublicComment(), 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem->getImagePath()), 'model' => $orderItem->getModel(), 'name' => $orderItem->getName(), 'options' => OrderItemDAO::getInstance()->getOrderItemOptionsString($orderItem->getId()), 'order_id' => $orderItem->getOrderId(), 'price' => $orderItem->getCurrency()->getString($orderItem->getPrice(true)), 'quantity' => $orderItem->getQuantity(), 'shipping' => $orderItem->getCurrency()->getString($orderItem->getShippingCost(true)), 'subtotal' => $orderItem->getCurrency()->getString($orderItem->getTotal(true))); $subTotalCustomerCurrency += $orderItem->getTotal(true); } // foreach ($this->data['orderItems'] as $item) { // $ids[] = $item['id']; // } // // $_invoice = InvoiceDAO::getInstance()->getInvoice($this->getRequest()->getParam('invoiceId')); // // foreach (InvoiceDAO::getInstance()->getInvoiceItems($_invoice->getId()) as $invoiceItem) { // if (!in_array($invoiceItem['order_item_id'], $ids)) { // $orderItem = $this->model_account_order->getOrderProduct($invoiceItem['order_item_id']); // // $this->data['orderItems'][] = array( // 'id' => $orderItem['order_product_id'], // 'comment' => $orderItem['public_comment'], // 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem['image_path']), // 'model' => $orderItem['model'], // 'name' => $orderItem['name'], // 'options' => $modelOrderItem->getOrderItemOptionsString($orderItem['order_product_id']), // 'order_id' => $orderItem['order_id'], // 'price' => $this->getCurrency()->format($orderItem['price']), // 'quantity' => $orderItem['quantity'], // 'subtotal' => $this->getCurrency()->format($orderItem['price'] * $orderItem['quantity']) // ); // } // } /// Set invoice data $this->data['invoiceId'] = $invoice->getId(); $this->data['comment'] = $invoice->getComment(); $this->data['discount'] = $this->getCurrency()->format($invoice->getDiscount(), $this->getCurrentCustomer()->getBaseCurrency()); $this->data['packageNumber'] = $invoice->getPackageNumber(); $this->data['shippingAddress'] = nl2br($modelReferenceAddress->toString($invoice->getShippingAddressId())); $this->data['shippingCost'] = $this->getCurrency()->format($invoice->getShippingCost()); $this->data['shippingMethod'] = ShippingMethodDAO::getInstance()->getMethod(explode('.', $invoice->getShippingMethod())[0])->getName(); $this->data['status'] = $this->load->model('localisation/invoice')->getInvoiceStatus($invoice->getStatusId(), $this->session->data['language_id']); $this->data['statusId'] = $invoice->getStatusId(); $this->data['total'] = $this->getCurrency()->format($subTotalCustomerCurrency, $this->getCurrentCustomer()->getBaseCurrency(), 1); $this->data['totalWeight'] = $invoice->getWeight(); $this->data['grandTotal'] = $this->getCurrency()->format($invoice->getTotalCustomerCurrency(), $this->getCurrentCustomer()->getBaseCurrency(), 1); } $templateName = '/template/account/invoiceForm.tpl.php'; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $templateName)) { $this->template = $this->config->get('config_template') . $templateName; } else { $this->template = 'default' . $templateName; } $this->setBreadcrumbs(); $this->children = array('common/header', 'common/footer', 'common/content_top', 'common/content_bottom', 'common/column_left', 'common/column_right'); $this->getResponse()->setOutput($this->render()); }