Chào mọi người, hiện phân mềm trên cakephp do it cũ viết nó bị lỗi thế này à.
LÀ nếu như mình tạo một hợp đồng mới thì có thể add bao nhiêu chỉ tiêu cũng được
Nhưng hợp đồng đó mình sửa và thêm chỉ tiêu thì các chỉ tiêu bị giới hạn 198 chỉ tiêu, nếu nhập hơn nó sẽ xóa và chỉ để lại 198 chỉ tiêu thôi ạ.
Phần mềm viết trên cakephp và mongodb
Em nghĩ do vòng lặp lỗi mà chưa tìm ra các bác soi giúp em ạ


Phân code đó đây ạ :
function add_samp($id = null){
$als = 'Contract';
$user_id = _getID($this->Auth->user('_id'));
if(!empty($this->request->data)){
$data = &$this->request->data[$als];
if(empty($data['customer_id'])){
$this->Session->setFlash( __('Tham số truyền vào không hợp lệ'), 'messages/message_error');
$this->redirect(array('action' => 'index'));
}
$data['customer_id'] = _getID($data['customer_id']);
$data['contract_id'] = (int) $data['contract_id'];
$info = $this->$als->getContract($data['_id']);
if(empty($info['Contract']['required_samp'])){
$ticket = []; $i=0;
$sum_ticket = 0;
foreach ($data['required_samp']['target_id'] as $key => $value) {
$target = $this->Target->getTarget($value);
$ticket[$key]['target_id'] = _getID($target['Target']['_id']);
$ticket[$key]['samp_id'] = $target['Target']['samp_id'];
$ticket[$key]['price'] = (int) $target['Target']['price'];
}
foreach ($data['required_samp']['unit'] as $k => $val) {
$ticket[$k]['unit'] = (int) $val;
}
foreach ($data['required_samp']['local'] as $k => $val) {
$ticket[$k]['local'] = $val;
$ticket[$k]['analytic_samp'] = "0";
}
foreach ($ticket as $k1 => $v1) {
$sum_ticket+= $v1['price']*$v1['unit'];
}
$data['required_samp'] = $ticket;
$info['Contract']['labor_cost'] = (int) $info['Contract']['labor_cost'];
$info['Contract']['transport_fee'] = (int) $info['Contract']['transport_fee'];
$sum_ticket+= $info['Contract']['labor_cost'] + $info['Contract']['transport_fee'];
$data['contract_value'] = $sum_ticket;
unset($data['samp']);
unset($data['target']);
unset($data['unit']);
}
else{
$ticket = []; $i=0;
$sum_ticket = 0;
if(!empty($data['new'])){
foreach ($data['new']['target_id'] as $key => $value) {
$target = $this->Target->getTarget($value);
$ticket[$key]['target_id'] = _getID($target['Target']['_id']);
$ticket[$key]['samp_id'] = $target['Target']['samp_id'];
$ticket[$key]['price'] = (int) $target['Target']['price'];
}
foreach ($data['new']['unit'] as $k => $val) {
$ticket[$k]['unit'] = (int) $val;
}
foreach ($data['new']['local'] as $k => $val) {
$ticket[$k]['local'] = $val;
$ticket[$k]['analytic_samp'] = "0";
}
foreach ($ticket as $kl => $v1) {
$sum_ticket+= $v1['price']*$v1['unit'];
}
unset($data['new']);
$i= count($ticket);
}
foreach ($data['required_samp'] as $key => $value) {
$ticket[$i]['target_id']= _getID($value['target_id']);
$ticket[$i]['samp_id']= _getID($value['samp_id']);
$ticket[$i]['price']= (int) $value['price'];
$ticket[$i]['unit']= (int) $value['unit'];
$ticket[$i]['local']= $value['local'];
$ticket[$i]['analytic_samp'] = "0";
$i++;
}
foreach ($ticket as $k1 => $v1) {
$sum_ticket+= $v1['price']*$v1['unit'];
}
$data['required_samp'] = $ticket;
$info['Contract']['labor_cost'] = (int) $info['Contract']['labor_cost'];
$info['Contract']['transport_fee'] = (int) $info['Contract']['transport_fee'];
$sum_ticket+= $info['Contract']['labor_cost'] + $info['Contract']['transport_fee'];
$data['contract_value'] = $sum_ticket;
$data['target_value_after'] = '';
}
unset($data['samp']);
unset($data['target']);
unset($data['unit']);
unset($data['local']);
$this->get_common_info($data);
if( $this->$als->saveWithKeys($data)){
$this->Session->setFlash( __('Lưu thành công'), 'messages/message_success');
if(!empty($_GET['callback'])){
$this->redirect($_GET['callback']);
}else{
$this->redirect(array('action' => 'index'));
}
} else{
$this->Session->setFlash( __('Lưu thất bại! Xin thử lại.'), 'messages/message_error');
}
}
$this->request->data = $this->$als->getContract(_getID($id));
if(empty($this->request->data)){
$this->Session->setFlash( __('Không tìm thấy hợp đồng bạn muốn chỉnh sửa.'), 'messages/message_error');
$this->redirect('/contracts/index');
}
$local = $this->Local->getLocal($id);
$lo = [];
if(!empty($local)){
foreach ($local['Local']['local'] as $t => $u) {
$lo[$u['code']] = $u['name'];
}
}
$customer_name = $this->Customer->getCustomer(_getID($this->request->data[$als]['customer_id']));
if(!empty($_GET['cus'])){
$customer_name = $this->Customer->getCustomer(_getID($_GET['cus']));
$this->set('customer_id', $_GET['cus']);
}
$tar = $this->Target->getList();
$tg = [];
foreach ($tar as $k => $v) {
$ta = $this->Target->getTarget($k);
$tg[$k] = $ta['Target']['name']."-".($ta['Target']['price']/1000)."k";
}
$this->set('local', $lo);
$this->set('customer_name', $customer_name['Customer']['name']);
$this->set('samps', $this->Samp->getList());
$this->set('targets', $this->Target->getList());
$this->set('ta', $tg);
$this->layout = "home";
}
Dạ ! nó không báo lỗi mới khó em ạ !.
cái này bạn debug để biet61 xem cái 198 đó là biến nào. rồi xem logic của nó. nhìn mắt k biết biến nào ráo