Jump to content
samverdyck

Verschillende facturatienummeringen per Klantengroep

Recommended Posts

Ik ben op zoek naar een manier waarop ik per klantengroep een andere facturatienummering kan laten lopen. 

Dus dat bijvoorbeeld klantengroep "Professionelen" een factuurnummering heeft op deze manier: PROF001 en dat klantengroep "Particulieren" een klantennummering heeft op deze manier: PART001.

 

Achterliggende reden van deze vraag is dat ik eigenlijk op zoek ben naar een oplossing om enkel de klanten die bestellen met een BTW nummer in de facturatieflow te laten, de particulieren moeten eruit. (die filter ik met een query, om ze boekhoudkundig op een bepaalde manier te verwerken). 

 

Ik heb een module gevonden die automatisch de klanten sorteert per klantengroep, op basis van een al dan niet ingevuld BTW-nummer veld. 

Nu moet ik er dus enkel  ;) voor zorgen dat enkel de orders binnen die klantengroep met BTW-nummers in de facturatieflow vallen. 

Share this post


Link to post
Share on other sites

Verder aan het zoeken geweest.

In de Classe Order (classes/order/order.php) ben ik de functie setInvoice tegenkomen, die het aanmaken van de eerste factuur per order regelt. 

 

Zou ik daar een conditie aan kunnen toevoegen in de stijl van: "als klantengroep id = 2, dan voer deze functie uit"?

De orders van de klanten die niet in die klantengroep zitten zouden zo uit de factuurflow vallen, omdat ze niet aan de conditie voldoen. 

 

Dit is de functie setInvoice

 /**
     * This method allows to generate first invoice of the current order
     */
    public function setInvoice($use_existing_payment = false)
    {
        // if ((int)$this->$id_customer > 2 ){
            if (!$this->hasInvoice()) {
                if ($id = (int)$this->getOrderInvoiceIdIfHasDelivery()) {
                    $order_invoice = new OrderInvoice($id);
                } else {
                    $order_invoice = new OrderInvoice();
                }
                $order_invoice->id_order = $this->id;
                if (!$id) {
                    $order_invoice->number = 0;
                }

                // Save Order invoice

                $this->setInvoiceDetails($order_invoice);

                if (Configuration::get('PS_INVOICE')) {
                    $this->setLastInvoiceNumber($order_invoice->id, $this->id_shop);
                }



                // Update order_carrier
                $id_order_carrier = Db::getInstance()->getValue('
    				SELECT `id_order_carrier`
    				FROM `'._DB_PREFIX_.'order_carrier`
    				WHERE `id_order` = '.(int)$order_invoice->id_order.'
    				AND (`id_order_invoice` IS NULL OR `id_order_invoice` = 0)');

                if ($id_order_carrier) {
                    $order_carrier = new OrderCarrier($id_order_carrier);
                    $order_carrier->id_order_invoice = (int)$order_invoice->id;
                    $order_carrier->update();
                }

                // Update order detail
                Db::getInstance()->execute('
    				UPDATE `'._DB_PREFIX_.'order_detail`
    				SET `id_order_invoice` = '.(int)$order_invoice->id.'
    				WHERE `id_order` = '.(int)$order_invoice->id_order);

                // Update order payment
                if ($use_existing_payment) {
                    $id_order_payments = Db::getInstance()->executeS('
    					SELECT DISTINCT op.id_order_payment
    					FROM `'._DB_PREFIX_.'order_payment` op
    					INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.reference = op.order_reference)
    					LEFT JOIN `'._DB_PREFIX_.'order_invoice_payment` oip ON (oip.id_order_payment = op.id_order_payment)
    					WHERE (oip.id_order != '.(int)$order_invoice->id_order.' OR oip.id_order IS NULL) AND o.id_order = '.(int)$order_invoice->id_order);

                    if (count($id_order_payments)) {
                        foreach ($id_order_payments as $order_payment) {
                            Db::getInstance()->execute('
    							INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
    							SET
    								`id_order_invoice` = '.(int)$order_invoice->id.',
    								`id_order_payment` = '.(int)$order_payment['id_order_payment'].',
    								`id_order` = '.(int)$order_invoice->id_order);
                        }
                        // Clear cache
                        Cache::clean('order_invoice_paid_*');
                    }
                }

                // Update order cart rule
                Db::getInstance()->execute('
    				UPDATE `'._DB_PREFIX_.'order_cart_rule`
    				SET `id_order_invoice` = '.(int)$order_invoice->id.'
    				WHERE `id_order` = '.(int)$order_invoice->id_order);

                // Keep it for backward compatibility, to remove on 1.6 version
                $this->invoice_date = $order_invoice->date_add;

                if (Configuration::get('PS_INVOICE')) {
                    $this->invoice_number = $this->getInvoiceNumber($order_invoice->id);
                    $invoice_number = Hook::exec('actionSetInvoice', array(
                        get_class($this) => $this,
                        get_class($order_invoice) => $order_invoice,
                        'use_existing_payment' => (bool)$use_existing_payment
                    ));

                    if (is_numeric($invoice_number)) {
                        $this->invoice_number = (int)$invoice_number;
                    } else {
                        $this->invoice_number = $this->getInvoiceNumber($order_invoice->id);
                    }
                }

                $this->update();
            }
        // }
    }

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More