Это можно сделать с помощью ваучера № в массиве. Код контроллера:
<code>public function Purchase_Register1()
{
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
if( ($this->input->post('all')) && ($this->input->post('item')) ) {
$this->db->select('parmaster.PName, purchasebill.voucherno, purchaseitem.billdate, purchasebill.partyname, purchaseitem.prdtname, purchaseitem.quantity,purchaseitem.bundle');
$this->db->from('purchasebill');
$this->db->join('purchaseitem', 'purchasebill.voucherno = purchaseitem.vno');
$this->db->join('parmaster', 'parmaster.pcode = purchasebill.partyname');
$this->db->where('purchaseitem.billdate >=', $newDate);
$this->db->where('purchaseitem.billdate <=', $newDate2);
$this->db->order_by('purchasebill.voucherno');
$result = $this->db->get()->result_array();
if($result){
$finalArray = array();
$checkArray = array();
foreach ($result as $key => $value) {
if(in_array($value['voucherno'], $checkArray)){
$finalArray[$value['voucherno']][] = $value;
} else {
$checkArray[] = $value['voucherno'];
$finalArray[$value['voucherno']][] = $value;
}
}
$data['query'] = $finalArray;
$this->load->view('Whole_Sales/Purchase_Register2', $data);
//echo '<pre>';print_r($finalArray);echo '
'; exit ();}} else if (($ this-> input-> post ('selected')) && ($ this-> input-> post ('businessType')) && ($ this-> input-> post ('item')))) {$ name = $ this-> input-> post ('businessType');$ this-> db-> select ('parmaster.PName, purchasebill.voucherno, purchaseitem.billdate, purchasebill.partyname, purchaseitem.prdtname, purchaseitem.quantity, purchaseitem.bundle');$ This-> db-> из ( 'purchasebill');$ this-> db-> join ('purchaseitem', 'purchasebill.voucherno = purchaseitem.vno');$ this-> db-> join ('parmaster', 'parmaster.pcode = purchasebill.partyname');$ this-> db-> where ('purchaseitem.billdate> =', $ newDate);$ this-> db-> where ('purchaseitem.billdate <=', $ newDate2);$ This-> db-> где ( 'PNAME', $ название);$ This-> db-> order_by ( 'purchasebill.voucherno');$ result = $ this-> db-> get () -> result_array ();if ($ result) {$ finalArray = array ();$ checkArray = array ();foreach ($ result as $ key => $ value) {if (in_array ($ value ['voucherno'], $ checkArray)) {$ finalArray [$ value ['voucherno']] [] = $ value;} else {$ checkArray [] = $ value ['voucherno'];$ finalArray [$ value ['voucherno']] [] = $ value;}} $ data ['query'] = $ finalArray;$ this-> load-> view ('Whole_Sales / Purchase_Register2', $ data);
Просмотр страницы:
<?php
$totalQuantity = 0;
$totalBundle = 0;
$rowcount = 1;
foreach ($query as $key => $value){
$counter = 0;
?>
<?php
foreach ($value as $sub_key => $sub_value) {
if($counter == 0) {
$totalQuantity = $totalQuantity + $sub_value['quantity'];
$totalBundle = $totalBundle + $sub_value['bundle'];
?>
<tr>
<td><?php echo $rowcount?>
<td><?php echo $sub_value['voucherno'] ?></td>
<td><?php echo $sub_value['billdate'] ?></td>
<td><?php echo $sub_value['PName'] ?></td>
<td><?php echo $sub_value['prdtname'];?></td>
<td><?php echo $sub_value['quantity'];?></td>
<td><?php echo $sub_value['bundle'];?></td>
<?php $rowcount +=1?>
</tr>
<?php
$counter++;
} else {
$totalQuantity = $totalQuantity + $sub_value['quantity'];
$totalBundle = $totalBundle + $sub_value['bundle'];
?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $sub_value['prdtname'];?></td>
<td><?php echo $sub_value['quantity'];?></td>
<td><?php echo $sub_value['bundle'];?></td>
</tr>
<?php
} // else
} // foreach
}
?>