here comes tricky part
in rent application, have arrays (of course array size , values may vary):
$dates = array(); // each "pipe" | item visual $dates['2013-07-15'] = 2; // || $dates['2013-07-16'] = 2; // || $dates['2013-07-17'] = 5; // ||||| $dates['2013-07-18'] = 3; // ||| $dates['2013-07-19'] = 4; // |||| $dates['2013-07-20'] = 2; // || $dates['2013-07-21'] = 1; // | the keys rent days, , values # of items rent user specific product
days consecutive (i yet grouped adjacent days another script)
5 consecutive days considered "working week", , special price applies: let's d daily price , w weekly price
as can see, in example total of 5 items rent dates' range:
- item 1 1 week , 2 spare days (15-16-17-18-19-20-21)
echo total price: 1*w + 2*d - item 2 1 week , 1 spare day (15-16-17-18-19-20)
echo total price: 1*w + 1*d - item 3 3 spare days (17-18-19)
echo total price: 0*w + 3*d - item 4 2 spare days (17-19)
echo total price: 0*w + 2*d - item 5 1 day (17)
echo total price: 0*w + 1*d
... , sum of above
ok, far good: can express concept in words
but... how translate script? difficult me!
many in advance!
edit: clarify, values each array item represents number of items of specific product rent user; let's product "vacuum cleaner brand-x" , there 10 items in shop's stock; cleaning company "your-clean-house inc." got big deal and, in case, going rent:
- 2 "vacuum cleaner brand-x" on 2013-07-15
- 2 "vacuum cleaner brand-x" on 2013-07-16
- 5 "vacuum cleaner brand-x" on 2013-07-17
- etc...
oozel answer make sense! in order work example, have modify script this:
foreach ($dates $items){ ($i=1; $i<=$items; $i++){ ... } } @oozel: have number (and not array of items) 'cause of specific ui
oversemplifying:
vacuum cleaner brand-x calendar july 2013 ... <td> 15<br> <input type="checkbox" title="activate day" value="2013-07-15"> <select title="choose how many vacuum cleaner brand-x rent on day"> <option>1</option> ... <option>10</option> </select> </td> <td> 16<br> <input type="checkbox" title="activate day" value="2013-07-16"> <select title="choose how many vacuum cleaner brand-x rent on day"> <option>1</option> ... <option>10</option> </select> </td> <td> 17<br> <input type="checkbox" title="activate day" value="2013-07-17"> <select title="choose how many vacuum cleaner brand-x rent on day"> <option>1</option> ... <option>10</option> </select> </td> ...
i don't understand $date array structure think should multidimensional array shown below calculate total price desire
$dates['2013-07-15'] = array('item2', 'item1'); $dates['2013-07-16'] = array('item2', 'item1'); $dates['2013-07-17'] = array('item5', 'item4', 'item3', 'item2', 'item1'); $dates['2013-07-18'] = array('item3', 'item2', 'item1'); $dates['2013-07-19'] = array('item4', 'item3', 'item2', 'item1'); $dates['2013-07-20'] = array('item2', 'item1'); $dates['2013-07-21'] = array('item1'); then calculate number of rent days every item , calculate how many w , d there.
$rent_days = array(); foreach($dates $date => $items) { foreach($items $item) { if(!isset($rent_days[$item])) $rent_days[$item] = 1; else $rent_days[$item]++; } } $w = 10.5; // example $d = 2.3; foreach($rent_days $item => $n) { $w_num = floor($n/5); // number of weeks (namely, 5 consecutive days) $d_num = $n % 5; // number of days printf('total price %s: %.2f<br/>', $item, $w_num*$w + $d_num*$d); } and output is
/* total price item2: 12.80 total price item1: 15.10 total price item5: 2.30 total price item4: 4.60 total price item3: 6.90 */
Comments
Post a Comment