Expand variables available

mitchie
mitchie
Offline
0
Hi,
I Worked hard last two days to customize your nice script (congrats!) to fit my needs.
While layout customization can be done with the templates there are some that requires the script hack. It's not a big deal for me, fortunately, but they requires to re-hack the script on every upgrade. It would be nice if you would include the following (in bold) in view/invoice/templates/default.php:

$items = "";
$taxes = "";
$payments = "";
$payments2 = "";
$subtotal = 0 ;
$netSubtotal = 0;
$totalDiscount = 0;
$netDiscountedSubtotal = 0;

$outstanding_payments = 0;


if(!empty($this->items)){

$taxesArray = array();

foreach($this->items as $item){

// product net price
$netPrice = $item->value * $item->amount;

// net subtotal
$netSubtotal += $netPrice;

// net discounted subtotal
$netDiscountedPrice = (($item->value * $item->amount) - $item->discount);

// net discounted subtotal sum
$netDiscountedSubtotal += $netDiscountedPrice;

// product tax
$item->items_tax = (($item->value * $item->amount) - $item->discount)*($item->tax/100);

// array tax regrouped
// with Hikashop $this->taxes is not valorized so the standard routine is skipped
if(!isset($taxesArray[$item->tax])) { $taxesArray[$item->tax] = $item->items_tax; }
else { $taxesArray[$item->tax] += $item->items_tax; }


For the same reason you should process it separately
if( count($taxesArray) > 0 && empty($this->taxes))
{
while(list($k,$v)=each($taxesArray))
{
if($v >0)
{
$search = array(
"{name}",
"{value}"
);
$replace = array(
$k,
InvoicesHelper::format($v, $before, $after)
);
$taxes .= str_replace($search, $replace, $this->template->taxes) ;
}

}
}


Obviously you should include those variables in the
$items .= str_replace($search, $replace, $this->template->items) ;

and in
echo str_replace($search, $replace, $this->template->content) ;


So far all the variables that european invoicing laws require (even if not everybody respect them...), so them should be there.

And it would be very nice to get all payment details available and not just "Payment" listed as invoice items (like the title of payment type, "Paypal", "Wire Transfer" and so on) and shipping details as well. Or, alternatively, fire the plugins before each "search/replace" command so user could develop a customized one without hacking the core.
Responses (4)
  • Accepted Answer

    mitchie
    mitchie
    Offline
    Tuesday, October 14 2014, 05:57 PM - #Permalink
    0
    :) Great! I stop to hack it so. You saved me a bit of time!
    Thank you.

    Please think about variables availability... it would allow me to upgrade the script without having to hack it any time... :)
    Great work!
    By the way, I love your last comment too!
    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, October 14 2014, 05:34 PM - #Permalink
    0
    heheheh :) I love this last comment. do you know why? because we already did it! ;)
    it's one of the new things we're adding in the next version, and it's one that we have already coded. well, we did it with double brackets ;) [[text_to_translate]]
    The reply is currently minimized Show
  • Accepted Answer

    mitchie
    mitchie
    Offline
    Tuesday, October 14 2014, 05:31 PM - #Permalink
    0
    Hi, thanks for your fast reply!
    Well, as far as the variables are available I think is well generalized. Everyone who needs them can use them, otherwise they don't affect the script at all. The same for the plugin firing. It would allow a lot of expansions.

    By the way, you could use placeholder as well for text (labels and so on) included in square bracket like [this_is_my_text]. With regular expression search the script could replace [this_is_my_text] with JText::_( 'THIS_IS_MY_TEXT') allowing the script to be multilingual... ;-)
    I did it for a component of mine.
    Best regards.
    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, October 14 2014, 05:15 PM - #Permalink
    0
    Hello!

    we will add place for the payment "charges" or shipping or other in a future version. we will also add other improvements we're working on.

    your code is very good but it looks quite specific to your situation, I'm not sure this is a generalisable thing to put in the script.. thanks anyway!

    very nice work by the way! :) I love it when people work on the script for themselves and tweak it for their needs. very good to see you have such codin skills!
    The reply is currently minimized Show
Your Reply