コード例 #1
0
 public function addMonthlyConsumption2Draft()
 {
     $data = $this->form_values;
     //        /App_Controller_Functions::pr($data);
     $date = date("Y-m-d h:i:s");
     $str_qry_detail = "DELETE hf_data_detail_draft.*\n                        FROM\n                       hf_data_master_draft,hf_data_detail_draft \n                       where\n                       hf_data_master_draft.pk_id = hf_data_detail_draft.hf_data_master_id\n                        and hf_data_master_draft.warehouse_id='" . $data['wh_id'] . "'\n                      and DATE_FORMAT(hf_data_master_draft.reporting_start_date, '%Y-%m-%d') = '" . $data['rpt_date'] . "'";
     $this->_em = Zend_Registry::get('doctrine');
     $row_detail = $row = $this->_em->getConnection()->prepare($str_qry_detail);
     $row_detail->execute();
     $str_qry_master = "DELETE hf_data_master_draft.*\n                        FROM\n                       hf_data_master_draft\n                       where\n                       hf_data_master_draft.warehouse_id='" . $data['wh_id'] . "'\n                      and DATE_FORMAT(hf_data_master_draft.reporting_start_date, '%Y-%m-%d') = '" . $data['rpt_date'] . "'";
     $this->_em = Zend_Registry::get('doctrine');
     $row_master = $row = $this->_em->getConnection()->prepare($str_qry_master);
     $row_master->execute();
     $this->_em->flush();
     $posted_array = $data['flitm_id'];
     $vaccine_schedule_id = $data['vaccine_schedule_id'];
     $opening_array = $data['opening_balance'];
     $received_array = $data['received'];
     $dispensed_array = $data['dispensed'];
     $pregenant_women = $data['pregenant_women'];
     $non_pregenant_women = $data['non_pregenant_women'];
     $pregnant_women = $data['pregnant_women1'];
     $cba = $data['cba'];
     $pregenant_women_total = $data['pregenant_women_total'];
     $non_pregenant_women_total = $data['non_pregenant_women_total'];
     $item_category = $data['item_category'];
     $unusable_vials_array = $data['unusable_vials'];
     $closing_balance_array = $data['closing_balance'];
     $doses_per_unit_array = $data['doses_per_unit'];
     $strat_no = $data['start_no'];
     $no_of_doses = $data['no_of_doses'];
     $children_live_birth = $data['children_live_birth'];
     $surviving_children_0_11_M = $data['surviving_children_0_11_M'];
     $children_aged_12_23_M = $data['children_aged_12_23_M'];
     $two_year_above = $data['2_year_above'];
     $fixed_planned_sessions = $data['fixed_planned_sessions'];
     $fixed_actually_held_sessions = $data['fixed_actually_held_sessions'];
     $outreach_planned_sessions = $data['outreach_planned_sessions'];
     $outreach_actually_held_sessions = $data['outreach_actually_held_sessions'];
     foreach ($closing_balance_array as $key => $val) {
         if ($val != '' && $val >= 0) {
             if ($item_category[$key] == 1 || $item_category[$key] == 2) {
                 $vials_used = $opening_array[$key] + $received_array[$key] - $closing_balance_array[$key] - $unusable_vials_array[$key];
             } else {
                 $vials_used = $opening_array[$key] + $received_array[$key] - $closing_balance_array[$key];
             }
             $year_month = $data['yearmonth'];
             $doses = $doses_per_unit_array[$key];
             $wh_id = $data['wh_id'];
             if ($item_category[$key] == 1) {
                 $nod = $no_of_doses[$key];
                 for ($i = $strat_no[$key]; $i <= $no_of_doses[$key]; $i++) {
                     if ($i == 0) {
                         $nod += 1;
                     }
                     $vacine_schedule = $i == 1 && $i == $nod ? '' : $i;
                     if (strlen($vacine_schedule) == 0) {
                         $vacine_schedule = 1;
                     }
                     $fix_inuc_m_11 = $data['fix_inuc_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_f_11 = $data['fix_inuc_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_m_11 = $data['fix_outuc_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_f_11 = $data['fix_outuc_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_m_11 = $data['outreach_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_f_11 = $data['outreach_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_m_11 = $data['outreach_outuc_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_f_11 = $data['outreach_outuc_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_m_23 = $data['fix_inuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_f_23 = $data['fix_inuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_m_23 = $data['fix_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_f_23 = $data['fix_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_m_23 = $data['outreach_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_f_23 = $data['outreach_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_m_23 = $data['outreach_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_f_23 = $data['outreach_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_m_24 = $data['fix_inuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_f_24 = $data['fix_inuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_m_24 = $data['fix_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_f_24 = $data['fix_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_m_24 = $data['outreach_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_f_24 = $data['outreach_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_m_24 = $data['outreach_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_f_24 = $data['outreach_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $issue += $fix_inuc_m_11 + $fix_inuc_f_11 + $fix_outuc_m_11 + $fix_outuc_f_11 + $outreach_m_11 + $outreach_f_11 + $outreach_outuc_m_11 + $outreach_outuc_f_11 + $fix_inuc_m_23 + $fix_inuc_f_23 + $fix_outuc_m_23 + $fix_outuc_f_23 + $outreach_m_23 + $outreach_f_23 + $outreach_outuc_m_23 + $outreach_outuc_f_23 + $fix_inuc_m_24 + $fix_inuc_f_24 + $fix_outuc_m_24 + $fix_outuc_f_24 + $outreach_m_24 + $outreach_f_24 + $outreach_outuc_m_24 + $outreach_outuc_f_24;
                 }
             } else {
                 if ($item_category[$key] == 2) {
                     $issue = $pregenant_women_total + $non_pregenant_women_total;
                 } else {
                     if ($item_category[$key] == 3) {
                         $issue = $dispensed_array[$key];
                     }
                 }
             }
             $itemid = $posted_array[$key];
             $wh_adj = $unusable_vials_array[$key];
             if ($item_category[$key] == 1 || $item_category[$key] == 2) {
                 $wastages = $vials_used - $issue + abs($wh_adj);
             } else {
                 $wastages = $vials_used - $issue;
             }
             $hf_data_master = new HfDataMasterDraft();
             $item = $this->_em->getRepository('ItemPackSizes')->find($posted_array[$key]);
             $warehouse = $this->_em->getRepository('Warehouses')->find($data['wh_id']);
             $hf_data_master->setItemPackSize($item);
             $hf_data_master->setWarehouse($warehouse);
             $user_id = $this->_em->getRepository('Users')->find($this->_user_id);
             $hf_data_master->setCreatedBy($user_id);
             $hf_data_master->setModifiedBy($user_id);
             $hf_data_master->setOpeningBalance($opening_array[$key]);
             $hf_data_master->setReceivedBalance($received_array[$key]);
             $hf_data_master->setIssueBalance($issue);
             $hf_data_master->setClosingBalance($val);
             $hf_data_master->setVialsUsed($vials_used);
             if ($item_category[$key] == 1 || $item_category[$key] == 2) {
                 $hf_data_master->setAdjustments($unusable_vials_array[$key]);
             }
             $hf_data_master->setReportingStartDate(new \DateTime(App_Controller_Functions::dateToDbFormat($data['rpt_date'])));
             $hf_data_master->setWastages($wastages);
             $hf_data_master->setCreatedDate(new \DateTime(App_Controller_Functions::dateToDbFormat($date)));
             $hf_data_master->setModifiedDate(new \DateTime(App_Controller_Functions::dateToDbFormat(date("Y-m-d"))));
             $this->updateYearlyTargets($wh_id, App_Controller_Functions::dateToDbFormat($data['rpt_date']), $children_live_birth, $surviving_children_0_11_M, $children_aged_12_23_M, $pregnant_women, $cba, $two_year_above);
             $this->updateHfSessions($wh_id, App_Controller_Functions::dateToDbFormat($data['rpt_date']), $fixed_planned_sessions, $fixed_actually_held_sessions, $outreach_planned_sessions, $outreach_actually_held_sessions);
             $this->_em->persist($hf_data_master);
             $this->_em->flush();
             $hf_data_master_id = $hf_data_master->getPkId();
             if ($item_category[$key] == 1) {
                 $nod = $no_of_doses[$key];
                 for ($i = $strat_no[$key]; $i <= $no_of_doses[$key]; $i++) {
                     if ($i == 0) {
                         $nod += 1;
                     }
                     $vacine_schedule = $i == 1 && $i == $nod ? '' : $i;
                     if (strlen($vacine_schedule) == 0) {
                         $vacine_schedule = 1;
                     }
                     $fix_inuc_m_11 = $data['fix_inuc_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_f_11 = $data['fix_inuc_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_m_11 = $data['fix_outuc_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_f_11 = $data['fix_outuc_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_m_11 = $data['outreach_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_f_11 = $data['outreach_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_m_11 = $data['outreach_outuc_m_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_f_11 = $data['outreach_outuc_f_11_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_m_23 = $data['fix_inuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_f_23 = $data['fix_inuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_m_23 = $data['fix_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_f_23 = $data['fix_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_m_23 = $data['outreach_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_f_23 = $data['outreach_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_m_23 = $data['outreach_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_f_23 = $data['outreach_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_m_24 = $data['fix_inuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_inuc_f_24 = $data['fix_inuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_m_24 = $data['fix_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $fix_outuc_f_24 = $data['fix_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_m_24 = $data['outreach_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_f_24 = $data['outreach_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_m_24 = $data['outreach_outuc_m_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $outreach_outuc_f_24 = $data['outreach_outuc_f_23_' . $posted_array[$key] . '_' . $vacine_schedule];
                     $hf_data_detail = new HfDataDetailDraft();
                     $ageGroup = $this->_em->getRepository('ListDetail')->find(Model_ListDetail::AGE_0_11);
                     $hf_data_detail->setAgeGroup($ageGroup);
                     $hf_data_detail->setFixedInsideUcFemale($fix_inuc_f_11);
                     $hf_data_detail->setFixedInsideUcMale($fix_inuc_m_11);
                     $hf_data_detail->setFixedOutsideUcFemale($fix_outuc_f_11);
                     $hf_data_detail->setFixedOutsideUcMale($fix_outuc_m_11);
                     $hf_data_detail->setOutreachFemale($outreach_f_11);
                     $hf_data_detail->setOutreachMale($outreach_m_11);
                     $hf_data_detail->setOutreachOutsideFemale($outreach_outuc_f_11);
                     $hf_data_detail->setOutreachOutsideMale($outreach_outuc_m_11);
                     $hf_data_detail->setVaccineScheduleId($vacine_schedule);
                     $hf_data_master_i = $this->_em->getRepository('HfDataMasterDraft')->find($hf_data_master_id);
                     $hf_data_detail->setHfDataMaster($hf_data_master_i);
                     $user = $this->_em->getRepository('Users')->find($this->_user_id);
                     $hf_data_detail->setModifiedBy($user);
                     $hf_data_detail->setCreatedBy($user);
                     $hf_data_detail->setCreatedDate(App_Tools_Time::now());
                     $hf_data_detail->setModifiedDate(App_Tools_Time::now());
                     $this->_em->persist($hf_data_detail);
                     $this->_em->flush();
                     $hf_data_detail1 = new HfDataDetailDraft();
                     $ageGroup1 = $this->_em->getRepository('ListDetail')->find(Model_ListDetail::AGE_12_23);
                     $hf_data_detail1->setAgeGroup($ageGroup1);
                     $hf_data_detail1->setFixedInsideUcFemale($fix_inuc_f_23);
                     $hf_data_detail1->setFixedInsideUcMale($fix_inuc_m_23);
                     $hf_data_detail1->setFixedOutsideUcFemale($fix_outuc_f_23);
                     $hf_data_detail1->setFixedOutsideUcMale($fix_outuc_m_23);
                     $hf_data_detail1->setOutreachFemale($outreach_f_23);
                     $hf_data_detail1->setOutreachMale($outreach_m_23);
                     $hf_data_detail1->setOutreachOutsideFemale($outreach_outuc_f_23);
                     $hf_data_detail1->setOutreachOutsideMale($outreach_outuc_m_23);
                     $hf_data_detail1->setVaccineScheduleId($vacine_schedule);
                     $hf_data_master_i1 = $this->_em->getRepository('HfDataMasterDraft')->find($hf_data_master_id);
                     $hf_data_detail1->setHfDataMaster($hf_data_master_i1);
                     $user = $this->_em->getRepository('Users')->find($this->_user_id);
                     $hf_data_detail1->setModifiedBy($user);
                     $hf_data_detail1->setCreatedBy($user);
                     $hf_data_detail1->setCreatedDate(App_Tools_Time::now());
                     $hf_data_detail1->setModifiedDate(App_Tools_Time::now());
                     $this->_em->persist($hf_data_detail1);
                     $this->_em->flush();
                     $hf_data_detail2 = new HfDataDetailDraft();
                     $ageGroup2 = $this->_em->getRepository('ListDetail')->find(Model_ListDetail::AGE_24);
                     $hf_data_detail2->setAgeGroup($ageGroup2);
                     $hf_data_detail2->setFixedInsideUcFemale($fix_inuc_f_24);
                     $hf_data_detail2->setFixedInsideUcMale($fix_inuc_m_24);
                     $hf_data_detail2->setFixedOutsideUcFemale($fix_outuc_f_24);
                     $hf_data_detail2->setFixedOutsideUcMale($fix_outuc_m_24);
                     $hf_data_detail2->setOutreachFemale($outreach_f_24);
                     $hf_data_detail2->setOutreachMale($outreach_m_24);
                     $hf_data_detail2->setOutreachOutsideFemale($outreach_outuc_f_24);
                     $hf_data_detail2->setOutreachOutsideMale($outreach_outuc_m_24);
                     $hf_data_detail2->setVaccineScheduleId($vacine_schedule);
                     $hf_data_master_i2 = $this->_em->getRepository('HfDataMasterDraft')->find($hf_data_master_id);
                     $hf_data_detail2->setHfDataMaster($hf_data_master_i2);
                     $user = $this->_em->getRepository('Users')->find($this->_user_id);
                     $hf_data_detail2->setModifiedBy($user);
                     $hf_data_detail2->setCreatedBy($user);
                     $hf_data_detail2->setCreatedDate(App_Tools_Time::now());
                     $hf_data_detail2->setModifiedDate(App_Tools_Time::now());
                     $this->_em->persist($hf_data_detail2);
                     $this->_em->flush();
                 }
             }
             if ($item_category[$key] == 2) {
                 foreach ($pregenant_women as $key => $val) {
                     $hf_data_detail = new HfDataDetailDraft();
                     $hf_data_detail->setPregnantWomen($val);
                     $hf_data_detail->setNonPregnantWomen($non_pregenant_women[$key]);
                     $hf_data_detail->setVaccineScheduleId($vaccine_schedule_id[$key]);
                     $hf_data_master_i = $this->_em->getRepository('HfDataMasterDraft')->find($hf_data_master_id);
                     $hf_data_detail->setHfDataMaster($hf_data_master_i);
                     $user = $this->_em->getRepository('Users')->find($this->_user_id);
                     $hf_data_detail->setModifiedBy($user);
                     $hf_data_detail->setCreatedBy($user);
                     $hf_data_detail->setCreatedDate(App_Tools_Time::now());
                     $hf_data_detail->setModifiedDate(App_Tools_Time::now());
                     $this->_em->persist($hf_data_detail);
                     $this->_em->flush();
                 }
             }
         }
     }
 }