Prestashop/factura por abono

De josalba
Ir a la navegación Ir a la búsqueda

Reiniciar la numeraciones de factura por abono en Prestashop.

FICHERO A MODIFICAR

Modifcar el fichero de prestashop /classes/pdf/HTMLTemplateOrderSlip.php

AÑADIR

Añadir esta nueva función

     /**
     * Returns the numbering of the subscription invoice with respect to the year.
     *
     * @param int $id_order_slip order_slip
     *
     * @return int number for year
     */
    public function getNumberOrderSlip($id_order_slip)
    {
        $temporary_order_slip = Db::getInstance()->executeS('SELECT date_add FROM `' . _DB_PREFIX_ . 'order_slip` WHERE id_order_slip=' . $id_order_slip);

        $current_day = date('Y', strtotime($temporary_order_slip[0]['date_add']));
        $current_year = $current_day . '-01-01 00:00:00';

        $number_order_slip = Db::getInstance()->executeS(
            'SELECT count(*) as "n" FROM `' . _DB_PREFIX_ . 'order_slip` WHERE date_add > "' . $current_year . '" AND date_add < "' . $temporary_order_slip[0]['date_add'] . '"'
        );

        return intval($number_order_slip[0]['n']) + 1;
    }

REMPLAZAR

Buscar esta linea

 $this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->order_slip->id);

Y sustituirla por esta nueva

 $this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->getNumberOrderSlip($order_slip->id));

RESULTADO

Así es como tiene que quedar el principio del archivo.

class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
{
    public $order;
    public $order_slip;

    /**
     * Returns the numbering of the subscription invoice with respect to the year.
     *
     * @param int $id_order_slip order_slip
     *
     * @return int number for year
     */
    public function getNumberOrderSlip($id_order_slip)
    {
        $temporary_order_slip = Db::getInstance()->executeS('SELECT date_add FROM `' . _DB_PREFIX_ . 'order_slip` WHERE id_order_slip=' . $id_order_slip);

        $current_day = date('Y', strtotime($temporary_order_slip[0]['date_add']));
        $current_year = $current_day . '-01-01 00:00:00';

        $number_order_slip = Db::getInstance()->executeS(
            'SELECT count(*) as "n" FROM `' . _DB_PREFIX_ . 'order_slip` WHERE date_add > "' . $current_year . '" AND date_add < "' . $temporary_order_slip[0]['date_add'] . '"'
        );

        return intval($number_order_slip[0]['n']) + 1;
    }

    /**
     * @param OrderSlip $order_slip
     * @param $smarty
     *
     * @throws PrestaShopException
     */
    public function __construct(OrderSlip $order_slip, $smarty)
    {
        $this->order_slip = $order_slip;
        $this->order = new Order((int) $order_slip->id_order);
        $this->id_cart = $this->order->id_cart;

        $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order);

        foreach ($products as $product) {
            $customized_datas = Product::getAllCustomizedDatas($this->id_cart, null, true, null, (int) $product['id_customization']);
            Product::addProductCustomizationPrice($product, $customized_datas);
        }

        $this->order->products = $products;
        $this->smarty = $smarty;

        // header informations
        $this->date = Tools::displayDate($this->order_slip->date_add);
        $prefix = Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id);
        //$this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->order_slip->id);

        //Cambio para que aparezca el id.
        $this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->getNumberOrderSlip($order_slip->id));

        $this->shop = new Shop((int) $this->order->id_shop);
    }