Esempio n. 1
0
 public function addLog()
 {
     $data = $this->form_values;
     $name = $data['name'];
     $father_name = $data['father_name'];
     $age = $data['age'];
     $contact = $data['contact'];
     $address = $data['address'];
     $district = $data['district'];
     $uc = $data['uc'];
     $item_id = $data['item_id'];
     $dose_no = $data['dose_no'];
     $vaccination_date = $data['vaccination_date'];
     $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");
     foreach ($district as $key => $val) {
         if ($val != '' && $val >= 0) {
             $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->setDistrictId($districtId);
             $ucId = $this->_em->getRepository('Locations')->find($uc[$key]);
             $log_book->setUnionCouncilId($ucId);
             $log_book->setVaccinationDate(new \DateTime(App_Controller_Functions::dateToDbFormat($vaccination_date[$key])));
             $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->setCreatedBy($user_id);
             $log_book->setModifiedBy($user_id);
             $log_book->setModifiedDate(App_Tools_Time::now());
             $this->_em->persist($log_book);
             $this->_em->flush();
             $log_book_id = $log_book->getPkId();
             foreach ($item_id as $key => $val) {
                 $log_book_item_doses = new LogBookItemDoses();
                 $logBook = $this->_em->getRepository('LogBook')->find($log_book_id);
                 $log_book_item_doses->setLogBookId($logBook);
                 $itemPack = $this->_em->getRepository('ItemPackSizes')->find($val);
                 $log_book_item_doses->setItemPackSize($itemPack);
                 $log_book_item_doses->setDoses($dose_no[$key]);
                 $log_book_item_doses->setCreatedDate(App_Tools_Time::now());
                 $log_book_item_doses->setCreatedBy($user_id);
                 $log_book_item_doses->setModifiedBy($user_id);
                 $log_book_item_doses->setModifiedDate(App_Tools_Time::now());
                 $this->_em->persist($log_book_item_doses);
                 $this->_em->flush();
             }
         }
     }
 }