我已经制作了PHP代码来生成发票pdf。首先,打印所有购买产品的项目(required rows
),然后filler rows
(以便小计和总计始终打印在页面末尾),最后,小计和总计。经过几个小时的思考,我想出了以下逻辑。
我正在使用逻辑来计算从“必需行”计算的额外“填充行”。
这里,数字21
是第一页可以包含的总行数。其余页面可以包含27行。
if($required_rows < 21)
$filler_rows = 20 - $required_rows;
// I want a general formula for below series, which I currently use statically like this.
else if($required_rows < 48) // 21 + 27 = 48
$filler_rows = 24 - ($required_rows - 23 - (27*0));
else if($required_rows < 75) { // 48 + 27 = 75
$filler_rows = 24 - ($required_rows - 23 - (27*1));
} else if($required_rows < 102) { // 75 + 27 = 102
$filler_rows = 24 - ($required_rows - 23 - (27*2));
} else if($required_rows < 129) { // 102 + 27 = 129
$filler_rows = 24 - ($required_rows - 23 - (27*3));
} else if($required_rows < 156) { // 129 + 27 = 156
$filler_rows = 24 - ($required_rows - 23 - (27*4));
} else if($required_rows < 183) { // 156 + 27 = 183
$filler_rows = 24 - ($required_rows - 23 - (27*5));
} else if($required_rows < 210) { // 182 + 27 = 210
$filler_rows = 24 - ($required_rows - 23 - (27*6));
} else if($required_rows < 237) { // 210 + 27 = 237
$filler_rows = 24 - ($required_rows - 23 - (27*7));
} else if($required_rows < 264) { // 237 + 27 = 264
$filler_rows = 24 - ($required_rows - 23 - (27*8));
} else if($required_rows < 291) { // 264 + 27 = 291
$filler_rows = 24 - ($required_rows - 23 - (27*9));
} else if($required_rows < 318) { // 291 + 27 = 318
$filler_rows = 24 - ($required_rows - 23 - (27*10));
}
... ... ...
... ... ...
有什么想法吗?
答案 0 :(得分:2)
非常确定你正在寻找:
$filler_rows = 26 - ($required_rows - 21) % 27;
答案 1 :(得分:0)
请尝试以下代码。
if($required_rows < 21)
$filler_rows = 20 - $required_rows;
}else{
$multiplier = ($required_rows -21)/27;
if($multiplier>=0){
$filler_rows = 24 - ($required_rows - 23 - (27*$multiplier));
}
}
答案 2 :(得分:0)
最好用Paul Crovella的回答
MousetrapDiscreteEvents.nlogo