public function addLogBook() { $data = $this->form_values; $dose_no = $this->form_values['dose_no_of']; $temp = $this->form_values['temp']; $temp = base64_decode(substr($temp, 1, strlen($temp) - 1)); $temp = explode("|", $temp); $warehouse_id = $temp[0]; //$loc_id = $temp[1]; $rpt_date = $temp[1]; $is_new_rpt = $temp[2]; $tt = explode("-", $rpt_date); $yy = $tt[0]; $mm = $tt[1]; $dd = $tt[2]; $date = date("Y-m-d h:i:s"); $year_month = $yy . "-" . $mm; $vaccination_date = $yy . "-" . $mm . "-" . $this->form_values['day']; $user_id = $this->_user_id; $log_book = new LogBook(); $log_book->setName($this->form_values['name']); $log_book->setFatherName($this->form_values['father_name']); $log_book->setAge($this->form_values['age']); $log_book->setGender($this->form_values['gender']); $log_book->setContact($this->form_values['contact']); $log_book->setAddress($this->form_values['address']); //$refer_to_warehouseId = $this->_em->getRepository('Warehouses')->find($this->form_values['refer_to']); //$log_book->setReferToWarehouse($refer_to_warehouseId); $districtId = $this->_em->getRepository('Locations')->find($this->form_values['district']); $log_book->setDistrict($districtId); if (!empty($this->form_values['uc'])) { $ucId = $this->_em->getRepository('Locations')->find($this->form_values['uc']); $log_book->setUnionCouncil($ucId); } $log_book->setVaccinationDate(new \DateTime($vaccination_date)); //$log_book->setRefferTo(); //warehouseid from session $log_book->setRemarks($this->form_values['remarks']); $warehouse = $this->_em->getRepository('Warehouses')->find($warehouse_id); $log_book->setWarehouse($warehouse); $log_book->setCreatedDate(new \DateTime(App_Controller_Functions::dateToDbFormat($date))); $userId = $this->_em->getRepository('Users')->find($user_id); $log_book->setCreatedBy($userId); $this->_em->persist($log_book); $this->_em->flush(); $log_book_id = $log_book->getPkId(); foreach ($dose_no as $prodId => $value) { if ($value == "") { $value = NULL; } $log_book_item_doses = new LogBookItemDoses(); $logBook = $this->_em->getRepository('LogBook')->find($log_book_id); $log_book_item_doses->setLogBook($logBook); $itemPack = $this->_em->getRepository('ItemPackSizes')->find($prodId); $log_book_item_doses->setItemPackSize($itemPack); $log_book_item_doses->setDoses($value); $this->_em->persist($log_book_item_doses); $this->_em->flush(); } }
public function setDistrict(\Locations $district) { $this->__load(); return parent::setDistrict($district); }
public function addLog() { $data = $this->form_values; // App_Controller_Functions::pr($data); $temp = $this->form_values['temp']; $temp = base64_decode(substr($temp, 1, strlen($temp) - 1)); $temp = explode("|", $temp); $warehouse_id = $temp[0]; //$loc_id = $temp[1]; $rpt_date = $temp[1]; $is_new_rpt = $temp[2]; $tt = explode("-", $rpt_date); $yy = $tt[0]; $mm = $tt[1]; $dd = $tt[2]; $year_month = $yy . "-" . $mm; if ($is_new_rpt == 0) { $str_qry = "DELETE log_book.*,log_book_item_doses.*\n FROM\n log_book_item_doses,log_book \n where\n log_book.pk_id = log_book_item_doses.log_book_id\n and log_book.warehouse_id='{$warehouse_id}'\n and DATE_FORMAT(log_book.vaccination_date, '%Y-%m') = '{$year_month}'"; $this->_em = Zend_Registry::get('doctrine'); $row = $row = $this->_em->getConnection()->prepare($str_qry); $row->execute(); } $name = $data['name']; $father_name = $data['father_name']; $age = $data['age']; $contact = $data['contact']; $address = $data['address']; $district = $data['district']; $uc = $data['uc']; $serial_number = $data['serial_number']; $vaccination_day = $data['day']; $reffers_to = $data['reffers_to']; $remarks = $data['remarks']; $user_id = $this->_user_id; // $warehouse_id = $this->_identity->getWarehouseId(); $date = date("Y-m-d h:i:s"); $count = 0; foreach ($district as $key => $val) { if ($val != '' && $val >= 0 && $uc[$key] != '' && $uc[$key] >= 0) { $vaccination_date = $vaccination_day[$key] . "-" . $mm . "-" . $yy; $log_book = new LogBook(); $log_book->setName($name[$key]); $log_book->setFatherName($father_name[$key]); $log_book->setAge($age[$key]); $log_book->setContact($contact[$key]); $log_book->setAddress($address[$key]); $districtId = $this->_em->getRepository('Locations')->find($district[$key]); $log_book->setDistrict($districtId); $ucId = $this->_em->getRepository('Locations')->find($uc[$key]); $log_book->setUnionCouncil($ucId); $log_book->setVaccinationDate(new \DateTime(App_Controller_Functions::dateToDbFormat($vaccination_date))); $log_book->setRefferTo($reffers_to[$key]); $log_book->setRemarks($remarks[$key]); $warehouse = $this->_em->getRepository('Warehouses')->find($warehouse_id); $log_book->setWarehouse($warehouse); $log_book->setCreatedDate(App_Tools_Time::now()); $log_book->setModifiedDate(App_Tools_Time::now()); $userId = $this->_em->getRepository('Users')->find($user_id); $log_book->setCreatedBy($userId); $log_book->setModifiedBy($userId); $this->_em->persist($log_book); $this->_em->flush(); $log_book_id = $log_book->getPkId(); $item_id = $data[$serial_number[$key] . "_" . 'item_id']; $dose_no = $data[$serial_number[$key] . "_" . 'dose_no']; foreach ($item_id as $key => $val) { if ($dose_no[$key] == "") { $dose_no[$key] = 0; } else { $dose_no[$key] = $dose_no[$key]; } $log_book_item_doses = new LogBookItemDoses(); $logBook = $this->_em->getRepository('LogBook')->find($log_book_id); $log_book_item_doses->setLogBook($logBook); $itemPack = $this->_em->getRepository('ItemPackSizes')->find($val); $log_book_item_doses->setItemPackSize($itemPack); $log_book_item_doses->setDoses($dose_no[$key]); $user = $this->_em->getRepository('Users')->find($this->_user_id); $log_book_item_doses->setModifiedBy($user); $log_book_item_doses->setCreatedBy($user); $log_book_item_doses->setCreatedDate(App_Tools_Time::now()); $log_book_item_doses->setModifiedDate(App_Tools_Time::now()); $this->_em->persist($log_book_item_doses); $this->_em->flush(); } $count++; } } if ($count > 0) { return true; } else { return false; } }