function save_html2xls($xls = null, $data = null) { //template header $hdata = file_get_contents(XLSTEMPLATE_HDR); //template footer $fdata = file_get_contents(XLSTEMPLATE_FTR); $uuid = u_generate_uuid(); $uudate = date('l jS \\of F Y h:i:s A'); $hdata = str_replace("#UUID#", $uuid, $hdata); $hdata = str_replace("#UDATE#", $uudate, $hdata); $hdata = str_replace("#IMG#", $data, $hdata); //#UUID# //#UDATE# //give the format return write_file($xls, sprintf("%s\n%s", $hdata, $fdata)); }
function search_revpervehicleXXXXX() { $this->etc->check_permission('REPORT.GENERATE'); //get params $vShiftCode = trim($this->input->get_post("vShiftCode")); $vVehicleType = trim($this->input->get_post("vVehicleType")); $vStationCode = trim($this->input->get_post("vStationCode")); $vMemberCode = trim($this->input->get_post("vMemberCode")); $vProductCode = trim($this->input->get_post("vProductCode")); $vTrafficName = trim($this->input->get_post("vTrafficName")); $vOfficerType = trim($this->input->get_post("vOfficerType")); $vOperatorCode = trim($this->input->get_post("vOperatorCode")); $vRecapType = trim($this->input->get_post("vRecapType")); $vLocList = $this->input->get_post('CHK_LIST_LOCATION[]'); //dates $dt1 = trim($this->input->get_post('dtRange1')); $dt2 = trim($this->input->get_post('dtRange2')); $dt1a = trim($this->input->get_post('vDate1')); $dt2a = trim($this->input->get_post('vDate2')); $vlocations = @var_export($vLocList, 1); $moreLocs = @count($vLocList) > 0 ? " IN ( '" . @implode("','", $vLocList) . "' ) " : ""; log_message("INFO", "filter() -> LOCATIONS: {$vlocations}; "); log_message("INFO", "filter() -> LOCATIONS: {$moreLocs} "); //get dropdownlists $err_msg = ''; $vdata = $this->get_fmt_vdata(); //save prev data $vdata['jData_Hidden'] = array('vDate1' => $dt1, 'vDate2' => $dt2, 'dtRange1' => $dt1, 'dtRange2' => $dt2, 'vShiftCode' => $vShiftCode, 'vVehicleType' => $vVehicleType, 'vStationCode' => $vStationCode, 'vMemberCode' => $vMemberCode, 'vProductCode' => $vProductCode, 'vTrafficName' => $vTrafficName, 'vOfficerType' => $vOfficerType, 'vOperatorCode' => $vOperatorCode, 'vRecapType' => $vRecapType); $fmtdt1 = null; $fmtdt2 = null; if (($fmtdt1 = strtotime($dt1)) === false) { log_message("INFO", "filter() -> failed-date:1 "); //set status $vdata['error_message'] = "Tanggal Awal: Start date is invalid! (YYYY-MM-DD)"; //fwd $this->load->view('reports.revpervehicle.search.php', $vdata); return; } $dtfmt1 = @date('Y-m-d', $fmtdt1); if (($fmtdt2 = strtotime($dt2)) === false) { log_message("INFO", "filter() -> failed-date:2 "); //set status $vdata['error_message'] = "Tanggal Awal: End date is invalid! (YYYY-MM-DD)"; //fwd $this->load->view('reports.revpervehicle.search.php', $vdata); return; } $dtfmt2 = @date('Y-m-d', $fmtdt2); if ($dtfmt2 < $dtfmt1) { log_message("INFO", "filter() -> failed-date:3 "); //set status $vdata['error_message'] = "Tanggal Awal: Start/End date is invalid! (YYYY-MM-DD)"; //fwd $this->load->view('reports.revpervehicle.search.php', $vdata); return; } //EXT-operator or EXT-location [ must choose an operator ] if ($vOperatorCode <= 0 and ($this->etc->is_user_ext_operator() or $this->etc->is_user_ext_location())) { log_message("INFO", "filter() -> failed-date:4 "); //set status $vdata['error_message'] = "Please select a valid operator!"; //fwd $this->load->view('reports.revpervehicle.search.php', $vdata); return; } //fmt params $sortdata = array(); $fdata = fmt_ajx_params($sortdata); //dmp $dmp = @var_export($fdata, true); log_message("INFO", "search_revpervehicle() : params [ {$dmp} ]"); //fmt xtra $fdata['date1'] = $dt1; $fdata['date2'] = $dt2; $fdata['shift'] = $vShiftCode; $fdata['vehicle'] = $vVehicleType; $fdata['station'] = $vStationCode; $fdata['member'] = $vMemberCode; $fdata['product'] = $vProductCode; $fdata['traffic'] = $vTrafficName; $fdata['officer'] = $vOfficerType; $fdata['operator'] = $vOperatorCode; $fdata['recap'] = $vRecapType; $fdata['location'] = $vLocList; //add user-id if ($this->etc->is_user_ext_operator() or $this->etc->is_user_ext_location()) { $fdata['user'] = $this->etc->get_id(); } // Recap => SUMMARY = 1 file // Non-Recap => PER LOCATION = X file(s) //fmt date $sdate = explode('-', $fdata['date1']); $edate = explode('-', $fdata['date2']); $range_s = sprintf("%s/%s/%s", $sdate[2], $sdate[1], $sdate[0]); $range_e = sprintf("%s/%s/%s", $edate[2], $edate[1], $edate[0]); //date format @date('Y-m-d h:i A'); log_message("INFO", "filter() -> data: dt1:{$dt1} "); log_message("INFO", "filter() -> data: dt2:{$dt2} "); //RECAP if (!@preg_match("/^(Non-Recap)\$/i", $vRecapType)) { //RECAP = 1 file $rdata = $this->rpt_mgmt_model->getReportRevenueVehicleType($fdata); } else { //NO-RECAP = multiple files $norecap = $this->rpt_mgmt_model->getLocationsPerOperator($fdata); $xtotal = @intval($norecap['total']); if ($xtotal <= 0) { $vdata['error_message'] = "( {$xtotal} ) Total location records found!"; $this->load->view('reports.revpervehicle.search.php', $vdata); return; } //all locations foreach ($norecap['data'] as $loc_k => $loc_v) { //fmt params $loc_arr = array(); $loc_arr[] = $loc_v->operator_id; $fdata['location'] = $loc_arr; //get all $rdata = $this->rpt_mgmt_model->getReportRevenueVehicleType($fdata); } } //else no-recap $xtotal = @intval($rdata['total']); //chk results if ($xtotal <= 0) { $vdata['error_message'] = "( {$xtotal} ) Total records found!"; $this->load->view('reports.revpervehicle.search.php', $vdata); return; } //good data $summdat = array(); $tcodes = array(); $tdata = array(); //template header $hdata = file_get_contents(PDF_TMPL8_REVENUEPERVEHICLE); $ddata = file_get_contents(PDF_TMPL8_REVENUEPERVEHICLE_TAB); $uuid = u_generate_uuid(); $pfx1 = @date('YmdhisA'); $tmf_dst = sprintf("%s/rpt-revpervehicle-uno-%s%s.pdf", FILEPATH_USERPDF, $pfx1, substr(@uniqid(rand(), true), 0, 8)); $record = 0; //loop foreach ($rdata['data'] as $kk => $vv) { //save it $trafficname = @strtoupper(trim($vv->traffic_name)); $sumdat["qtyinpc"] += sprintf("%d", $vv->qtyinpc); //computed $sumdat["qtyoutpc"] += sprintf("%d", $vv->qtyoutpc); //computed $sumdat["qtyinman"] += sprintf("%d", $vv->qtyinman); //manual $sumdat["qtyoutman"] += sprintf("%d", $vv->qtyoutman); //manual $sumdat["qtyvoucher"] += sprintf("%d", $vv->qtyvoucher); //voucher $sumdat["qtyloss"] += sprintf("%d", $vv->qtyloss); //masalah $sumdat["totalnettopc"] += sprintf("%.02f", $vv->totalnettopc); //tunai $sumdat["totalnettoman"] += sprintf("%.02f", $vv->totalnettoman); //tunai $sumdat["totallosspc"] += sprintf("%.02f", $vv->totallosspc); //masalah $sumdat["totallossman"] += sprintf("%.02f", $vv->totallossman); //masalah $sumdat["totalvaluefinepc"] += sprintf("%.02f", $vv->totalvaluefinepc); //denda $sumdat["totalvaluefineman"] += sprintf("%.02f", $vv->totalvaluefineman); //denda $sumdat["totalvoucherpc"] += sprintf("%.02f", $vv->totalvoucherpc); //voucher $sumdat["totalvoucherman"] += sprintf("%.02f", $vv->totalvoucherman); //voucher //revenue = (tunai+masalah+denda) $revenuepc = sprintf("%.02f", $vv->totalnettopc + $vv->totallosspc + $vv->totalvaluefinepc); $revenueman = sprintf("%.02f", $vv->totalnettoman + $vv->totallossman + $vv->totalvaluefineman); $sumdat["totalrevenuepc"] += $revenuepc; //pendapatan $sumdat["totalrevenueman"] += $revenueman; //pendapatan //one-rec $tmf_detail = $ddata; $tmf_detail = @preg_replace('/#P1#/', $trafficname, $tmf_detail); $tmf_detail = @preg_replace('/#P2#/', '', $tmf_detail); $tmf_detail = @preg_replace('/#P3#/', $vv->qtyinpc, $tmf_detail); $tmf_detail = @preg_replace('/#P4#/', $vv->qtyoutpc, $tmf_detail); $tmf_detail = @preg_replace('/#P5#/', $vv->qtyinman, $tmf_detail); $tmf_detail = @preg_replace('/#P6#/', $vv->qtyoutman, $tmf_detail); $tmf_detail = @preg_replace('/#P7#/', $vv->qtyvoucher, $tmf_detail); $tmf_detail = @preg_replace('/#P8#/', $vv->qtyloss, $tmf_detail); $tmf_detail = @preg_replace('/#P9#/', number_format($vv->totalnettopc, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P10#/', number_format($vv->totalnettoman, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P11#/', number_format($vv->totallosspc, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P12#/', number_format($vv->totallossman, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P13#/', number_format($vv->totalvaluefinepc, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P14#/', number_format($vv->totalvaluefineman, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P15#/', number_format($revenuepc, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P16#/', number_format($revenueman, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P17#/', number_format($vv->totalvoucherpc, 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P18#/', number_format($vv->totalvoucherman, 2, ".", ","), $tmf_detail); //add-in $tdata[] = $tmf_detail; $record++; } //operator-list $operators = '<span>'; foreach ($rdata['operators'] as $kk => $vv) { $operators .= sprintf("<label for='operators'>%s</label><br/>", trim($vv->description)); } $operators .= '</span>'; //summary $tmf_detail = $ddata; $tmf_detail = @preg_replace('/#P1#/', '', $tmf_detail); $tmf_detail = @preg_replace('/#P2#/', '', $tmf_detail); $tmf_detail = @preg_replace('/#P3#/', $sumdat["qtyinpc"], $tmf_detail); $tmf_detail = @preg_replace('/#P4#/', $sumdat["qtyoutpc"], $tmf_detail); $tmf_detail = @preg_replace('/#P5#/', $sumdat["qtyinman"], $tmf_detail); $tmf_detail = @preg_replace('/#P6#/', $sumdat["qtyoutman"], $tmf_detail); $tmf_detail = @preg_replace('/#P7#/', $sumdat["qtyvoucher"], $tmf_detail); $tmf_detail = @preg_replace('/#P8#/', $sumdat["qtyloss"], $tmf_detail); $tmf_detail = @preg_replace('/#P9#/', number_format($sumdat["totalnettopc"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P10#/', number_format($sumdat["totalnettoman"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P11#/', number_format($sumdat["totallosspc"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P12#/', number_format($sumdat["totallossman"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P13#/', number_format($sumdat["totalvaluefinepc"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P14#/', number_format($sumdat["totalvaluefineman"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P15#/', number_format($sumdat["totalrevenuepc"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P16#/', number_format($sumdat["totalrevenueman"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P17#/', number_format($sumdat["totalvoucherpc"], 2, ".", ","), $tmf_detail); $tmf_detail = @preg_replace('/#P18#/', number_format($sumdat["totalvoucherman"], 2, ".", ","), $tmf_detail); //add-in $tdata[] = $tmf_detail; $tmore = @count($tdata); $tmfstr = ''; for ($i = 0; $i < $tmore; $i++) { $tmfstr .= trim($tdata[$i]); } //replace the details $fmt_hdata = $hdata; $fmt_hdata = @preg_replace('/#OPER#/', $operators, $fmt_hdata); $fmt_hdata = @preg_replace('/#PAGE#/', 1, $fmt_hdata); $fmt_hdata = @preg_replace('/#RECORD#/', $record, $fmt_hdata); $fmt_hdata = @preg_replace('/<!--\\/\\/#DETAILS#\\/\\/-->/', $tmfstr, $fmt_hdata); //save the template $pdfStr = save2pdf($tmf_dst, $fmt_hdata, PDF_TMPL8_REVENUEPERVEHICLE_TITLE); //chk if (!write_file($tmf_dst, $pdfStr)) { log_message("INFO", "pdf() -> FAILED > {$tmf_dst}"); $vdata['error_message'] = "Failed to generate the Preview and/or the PDF file!"; $this->load->view('reports.revpervehicle.search.php', $vdata); return; } //download $href = sprintf("%s", site_url("reports/tmfdownload/" . basename($tmf_dst)), substr($tmf_dst, 2)); log_message("INFO", "pdf() -> file > {$tmf_dst}"); //save $allsummary[] = array('DETAILS' => $tmfstr, 'START-DT' => $range_s, 'END-DT' => $range_e, 'PDF' => $href, 'PAGE' => 1, 'RECORD' => $record, 'OPERATOR' => $operators, 'ERROR-MSG' => $err_msg); //prv $vdata['jSummary'] = $allsummary; $this->preview($vdata); }
/** | @name | - fgotpass_proc | | @params | - | | @return | - | | @description | - process forgot pass | **/ function fgotpass_proc() { //get chk post $email = trim($this->input->get_post('email')); //params log_message("INFO", "fgotpass_proc() : info-params [ {$email} ]"); //cancel? if (!$this->input->get_post('Submit')) { //set status log_message("INFO", "fgotpass_proc() : info [ NOT CLICKED ]"); //view redirect('/user/fgotpass'); return; } //get rec $gdata = $this->user_model->select_by_mail(array('mail' => $email)); //invalid id if (!$gdata['status']) { log_message("INFO", "fgotpass_proc() : info [ NOT IN DB ]"); //set status $this->etc->set_error_message($this->config->item('FORGOT_PWD_ERR_NO_DATA')); //fwd redirect('/user/fgotpass'); return; } //fmt $npass = random_string('alnum', 10); $msg = trim($this->config->item('FORGOT_PWD_CONF_EMAIL')); $msg = @str_replace('<_NAME_>', $gdata['data']->name, $msg); //calc $hash = u_generate_uuid('FP-'); $kk = 'FORGOT-PASS'; $ref_id = $this->user_model->bfr_usr($email, $hash, $kk, $npass); if (!$ref_id) { //set status $this->etc->set_error_message($this->config->item('FORGOT_PWD_ERR_NO_DATA')); log_message("INFO", "fgotpass_proc() : info [ FAILED Insert to USER_BUFFER ]"); //fwd redirect('/user/fgotpass'); return; } //url $raw_url = $this->config->item('base_url') . $this->config->item('FORGOT_PWD_CONF_URL') . '/' . @rawurlencode($ref_id) . '/' . base64url_encode($hash); $msg = @str_replace('<_URL_>', $raw_url, $msg); //snd mail $pdata = null; $pdata['to'] = $email; $pdata['from'] = $this->config->item('FORGOT_PWD_FROM_EMAIL'); $pdata['sub'] = $this->config->item('FORGOT_PWD_SUBJ_EMAIL'); $pdata['msg'] = $msg; //snd $ret = u_send_mail($pdata); log_message("INFO", "fgotpass_proc() : info#{$ret} [ {$msg} ]"); //okay $this->etc->set_success_message($this->config->item('FORGOT_PWD_CONF_EMAIL_SENT')); //fwd redirect('/user/fgotpass'); return; }
/** | @name | - download_csv | | @params | - | | @return | - | | @description | - fwd the necessary header for CSV downloading | **/ function download_csv($edata = null, $hdrs = null) { //fmt filename //$hdr = 'Events Log\n'; $pre = sprintf("%s-%s", 'Events.Log', date("Ymd")); //load helper $this->load->helper('misc'); $csv = u_generate_uuid("{$pre}-") . '.csv'; $more = @count($edata); $rec = null; for ($i = 0; $i < $more; $i++) { $jdata = $edata[$i]; $dmp = @var_export($pdata, true); log_message('DEBUG', "download_csv() : dmp# [ {$dmp} ]"); $j = 0; foreach ($jdata as $k => $v) { $pdata[$j] = $v; $j++; } $rec .= @join(',', array("\"{$pdata['0']}\"", "\"{$pdata['1']}\"", "\"{$pdata['2']}\"", "\"{$pdata['3']}\"")) . "\n"; } //helper ;-) set_downloadable_csv($rec, $hdr, $csv); die; }