Order of Total and Subtotal
Posted: 14 Jun 2024, 00:23
Code: Select all
$d['total']
Code: Select all
$newTotal =[];
$i = 1;
foreach($d['total'] as $k => $v) {
$newTotal[$i] = $v;
$i++;
}
// Latest item will become zero and last item removed
$newTotal[0] = $newTotal[$i-1];
unset($newTotal[$i-1]);
ksort($newTotal);
Thanks Jan. I am asking this because I get informed that in Sweden practice is when an invoice is issued to a person, the total amount should be listed first. If it is a company, then the subtotal is listed first.
Code: Select all
// TOTAL
// -----------
$t = array();
$toPay = '';
$tColspanLeft = 5;
$tColspanMid = 2;
$tColspanRight = 2;
if ($tax_calculation > 0) {
$tColspanLeft = 7;
$tColspanMid = 3;
$tColspanRight = 2;
}
if (!empty($d['total'])) {
foreach($d['total'] as $k => $v) {
// display or not display shipping and payment methods with zero amount
//if($v->amount == 0 && $v->amount_currency == 0 && $v->type != 'brutto' && $v->type != 'sbrutto' && $v->type != 'pbrutto') {
if($v->amount == 0 && $v->amount_currency == 0 && $v->type != 'brutto') {
// Don't display coupon if null
} else if ($v->type == 'netto') {
$t[] = '<tr '.$totalF.'>';
$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
$t[] = '<td colspan="'.$tColspanMid.'"><b>'. PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))).'</b></td>';
$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'"><b>'.$d['price']->getPriceFormat($v->amount).'</b></td>';
$t[] = '</tr>';
if ($pR) { $oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))), $d['price']->getPriceFormat($v->amount))); }
} else if ($v->type == 'brutto') {
// Brutto or Brutto currency
$amount = (isset($v->amount_currency) && $v->amount_currency > 0) ? $d['price']->getPriceFormat($v->amount_currency, 0, 1) : $d['price']->getPriceFormat($v->amount);
$t[] = '<tr '.$totalF.'>';
$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
$t[] = '<td colspan="'.$tColspanMid.'"><b>'.PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))).'</b></td>';
$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'"><b>'.$amount.'</b></td>';
$t[] = '</tr>';
if ($pR) {
$oPr[] = $pP->printSeparator();
$oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))), $amount), 0, 'pDoubleSize');
$oPr[] = $pP->printFeed(2);
}
if ($d['type'] == 2) {
$toPay = $amount;
}
} else if ($v->type == 'rounding') {
// Rounding or rounding currency
$amount = (isset($v->amount_currency) && $v->amount_currency > 0) ? $d['price']->getPriceFormat($v->amount_currency, 0, 1) : $d['price']->getPriceFormat($v->amount);
$t[] = '<tr '.$totalF.'>';
$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
$t[] = '<td colspan="'.$tColspanMid.'">'.PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))).'</td>';
$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'">'.$amount.'</td>';
$t[] = '</tr>';
if ($pR) { $oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' '), 1 => array($v->title_lang_suffix2, ' '))), $amount)); }
} else {
$t[] = '<tr '.$totalF.'>';
$t[] = '<td colspan="'.$tColspanLeft.'"></td>';
$t[] = '<td colspan="'.$tColspanMid.'">'.PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' - '), 1 => array($v->title_lang_suffix2, ' '))).'</td>';
$t[] = '<td style="text-align:right" colspan="'.$tColspanRight.'">'.$d['price']->getPriceFormat($v->amount).'</td>';
$t[] = '</tr>';
if ($pR) { $oPr[] = $pP->printLineColumns(array(PhocacartLanguage::renderTitle($v->title, $v->title_lang, array(0 => array($v->title_lang_suffix, ' - '), 1 => array($v->title_lang_suffix2, ' '))), $d['price']->getPriceFormat($v->amount))); }
}
}
}
if ($d['type'] != 3) {
$o[] = implode("\n", $t);
}
if ($tax_calculation > 0 || $d['type'] == 3) {
$o[] = '<tr><td colspan="12"> </td></tr>';
} else {
$o[] = '<tr><td colspan="9"> </td></tr>';
}
// -----------