Viewing file: payment.php (39.72 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include('rg_controller.php');
class Payment extends Rg_controller {
// function __construct() {
// parent::__construct();
// }
function check1To100($var) {
$str = intval($var);
if($str <= 0 || $str > $this->config->item('rg_refNoPmNo_max')) {
$this->form_validation->set_message('check1To100','เลขที่ต้องอยู่ในช่วง 1-'.$this->config->item('rg_refNoPmNo_max'));
return false;
} else {
return true;
}
}
// ### ชำระค่าลงทะเบียนเรียนรายกลุ่ม (ผ่านทางธนาคาร)
function paymentRegisCur() {
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');
$refNoPmBook = $this->input->post('refNoPmBook');
$refNoPmNo = $this->input->post('refNoPmNo');
$btnSend = $this->input->post('btnSend');
$btnConfirm = $this->input->post('btnConfirm');
$this->contents['refNoPmBook'] = $refNoPmBook;
$this->contents['refNoPmNo'] = $refNoPmNo;
// check validate
if ($this->input->server('REQUEST_METHOD') === 'POST')
{// do something
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
$this->form_validation->set_rules('refNoPmBook', ' ', 'trim|callback_checkInt|required|xss_clean');
$this->form_validation->set_rules('refNoPmNo', ' ', 'trim|required|callback_checkInt|callback_check1To100|xss_clean');
$this->form_validation->set_rules('uploadfile', ' ', 'trim|xss_clean');
if($this->form_validation->run() === FALSE) {}
}
// end check validate
$arr = array();
$dsb = 0;
if($btnSend && $this->form_validation->run() === TRUE) {
$this->contents['btnSend'] = $btnSend;
$config['upload_path'] = $this->config->item("rg_upload_doc");
$config['allowed_types'] = 'csv';
$config['max_size'] = $this->config->item("rg_upload_size");
$config['file_name'] = $this->session->userdata('acY_R').$this->session->userdata('tmId_R').date('dmY_His');
$this->load->library('upload', $config);
if (!$this->upload->do_upload('uploadfile')) {
$msg = $this->upload->display_errors();
$this->session->set_flashdata('msg', $msg);
redirect($this->config->item("rg_folder")."msg/err_msg");
} else {
$data = $this->upload->data();
$str = read_file($this->config->item("rg_upload_doc").$data['file_name']);
$lines = explode("\r\n", $str);
//print_r($lines); exit;
for ($i = 0; $i < count($lines); $i++) {
if ($lines[$i]) {
list($pmDate, $rfRefNo, $pmAmt) = preg_split("/,/", $lines[$i]);
//echo "$pmDate, $rfRefNo, $pmAmt <br>";
if ($pmDate || $rfRefNo || $pmAmt) {
$con_qu_rf = array('rfRefNo' => $rfRefNo);
$qu_rf = $this->rf->qryRf($con_qu_rf);
//echo " ==> ".$qu_rf->num_rows(); exit;
if ($qu_rf->num_rows()) {
$con_qu_std = array('stdId' => $qu_rf->row()->rfStdId);
$qu_std = $this->std->qryStdJoinPf($con_qu_std);
if ($qu_std->num_rows()) {
$arr[$i]['qu_std'] = $qu_std;
}
$row_rf = $qu_rf->row();
if (($row_rf->rfTotalAmt == $row_rf->rfBalance) && ($row_rf->rfBalance != 0)) {
$arr[$i]['refNo'] = $rfRefNo;
$arr[$i]['pmRfId'] = $row_rf->rfId;
} else {
$arr[$i]['refNo'] = "<span class='error'>** เลขที่ใบลงทะเบียน $rfRefNo ชำระค่าลงทะเบียนหมดแล้ว **</span>";
$dsb = 1;
}
if (($row_rf->rfTotalAmt == $row_rf->rfBalance) && ($row_rf->rfBalance != 0) && ($row_rf->rfTotalAmt == $pmAmt)) {
$arr[$i]['pmAmt'] = $pmAmt;
} else {
$arr[$i]['pmAmt'] = "<span class='error'>** จำนวนเงินไม่ตรง **</span>";
$dsb = 1;
}
} else {
$arr[$i]['qu_std'] = NULL;
$arr[$i]['refNo'] = "<span class='error'>** เลขที่ใบลงทะเบียน $rfRefNo ไม่ตรง **</span>";
$arr[$i]['pmAmt'] = "";
$dsb = 1;
} // end if rf
$qu_sd = $this->sd->qrySdByAcYTmIdPayDate(substr($rfRefNo, 0, 4), substr($rfRefNo, 4, 1), splitDateForm3($pmDate));
if ($qu_sd->num_rows()) {
$arr[$i]['payDate'] = abbreDate2(splitDateForm3($pmDate));
$arr[$i]['pmDate'] = splitDateForm3($pmDate);
} else {
$arr[$i]['payDate'] = "<span class='error'>** วันที่ชำระเกินช่วง **</span>";
$dsb = 1;
}
}
} // end if line
} // end for line
$this->contents['docPath'] = $this->config->item("rg_upload_doc").$data['file_name'];
$this->contents['action'] = "processPaymentRegisCur";
} // end if upload
} // end if btnSend
$this->contents['dsb'] = $dsb;
if ($btnConfirm) {
$this->contents['btnConfirm'] = $btnConfirm;
$pmRfId = $this->input->post('pmRfId');
$pmDate = $this->input->post('pmDate');
$pmAmt = $this->input->post('pmAmt');
for ($i = 0; $i < count($pmRfId); $i++) {
$flagEf = 0;
$flagSd = 0;
$flagPm = 0;
$row_pm = "";
$pmPrintDate = "";
$this->rf->rfId = $pmRfId[$i];
$qu_rf = $this->rf->get_by_key();
if ($qu_rf->num_rows()) {
$row_rf = $qu_rf->row();
$con_qu_std = array('stdId' => $row_rf->rfStdId);
$qu_std = $this->std->qryStdJoinPf($con_qu_std);
if ($qu_std->num_rows()) {
$arr[$i]['qu_std'] = $qu_std;
}
$qu_sd = $this->sd->qrySdByAcYTmIdPayDate(substr($row_rf->rfRefNo, 0, 4), substr($row_rf->rfRefNo, 4, 1), $pmDate[$i]);
if ($qu_sd->num_rows()) {
$flagSd = 1;
}
$con_rs_pm = array('pmRfId' => $row_rf->rfId);
$rs_pm = $this->pm->qryPm($con_rs_pm);
if ($rs_pm->num_rows()) {
$row_pm = $rs_pm->row();
$pmPrintDate = $row_pm->pmPrintDate;
$arr[$i]['pmId'] = $row_pm->pmId;
$arr[$i]['qu_rf'] = $qu_rf;
$flagPm = 1;
}
$flagEf = 1;
}
if ($flagSd && ($row_pm->pmPrintDate == getNowDate())) {
$arr[$i]['payDate'] = abbreDate2($pmDate[$i]);
} else {
$arr[$i]['payDate'] = "<span class='error'>** วันที่ชำระเกินช่วง **</span>";
}
if ($flagEf && ($row_pm->pmPrintDate == getNowDate())) {
$arr[$i]['refNo'] = $row_rf->rfRefNo;
} else {
$arr[$i]['refNo'] = "<span class='error'>** เลขที่ใบลงทะเบียน ".$row_rf->rfRefNo." ไม่ตรง **</span>";
}
if (($row_rf->rfTotalAmt == $pmAmt[$i]) && ($row_pm->pmPrintDate == getNowDate())) {
$arr[$i]['pmAmt'] = $pmAmt[$i];
} else {
$arr[$i]['pmAmt'] = "<span class='error'>** จำนวนเงินไม่ตรง **</span>";
}
if ($flagPm && ($row_pm->pmPrintDate == getNowDate())) {
//$arr[$i]['pmBook'] = substr($row_pm->pmRefNo, 0, 3);
$tmp = explode('|', $row_pm->pmRefNo);
$arr[$i]['pmBook'] = $tmp[0];
}
if ($flagPm && ($row_pm->pmPrintDate == getNowDate())) {
//$arr[$i]['pmNo'] = substr($row_pm->pmRefNo, -3);
$tmp = explode('|', $row_pm->pmRefNo, 2);
$arr[$i]['pmNo'] = $tmp[1];
}
}
}
$this->contents['rs'] = $arr;
$this->output($this->config->item("rg_folder")."v_paymentRegisCurriculum");
}
function processPaymentRegisCur() {
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$cnt = 0;
$pmRfId = $this->input->post('pmRfId');
$pmDate = $this->input->post('pmDate');
$pmType = $this->input->post('pmType');
$pmAmt = $this->input->post('pmAmt');
$refNoPmBook = $this->input->post('refNoPmBook');
$refNoPmNo = $this->input->post('refNoPmNo');
$this->db->trans_begin();
for ($i = 0; $i < count($pmRfId); $i++) {
if ($pmDate[$i] && $pmAmt[$i] && $pmRfId[$i]) {
$this->rf->rfId = $pmRfId[$i];
$this->rf->get_by_key(TRUE);
if ($this->rf->rfBalance > 0) {
// Insert Payment
$this->pm->pmDate = $pmDate[$i];
$this->pm->pmType = $pmType[$i];
$this->pm->pmAmt = $pmAmt[$i];
$this->pm->pmRfId = $pmRfId[$i];
$pBook = '';
for ($k = 1; $k < $this->config->item('rg_refNoPmBook_length'); $k++) {
$pBook .= '0';
}
$pNo = '';
for ($k = 1; $k < strlen($this->config->item('rg_refNoPmNo_max')); $k++) {
$pNo .= '0';
}
$this->pm->pmRefNo = substr($pBook.$refNoPmBook, (-1)*$this->config->item('rg_refNoPmBook_length')).'|'.substr($pNo.$refNoPmNo, (-1)*strlen($this->config->item('rg_refNoPmNo_max')));
//substr('00'.$refNoPmBook, -3).'|'.substr('0000'.$refNoPmNo, -5);
$this->pm->pmLateStatus = 'N';
$this->pm->pmLateFine = 0;
$this->pm->pmPrintDate = getNowDate();
$this->pm->insert();
// Update EnrollFee
$this->rf->rfBalance -= $pmAmt[$i];
$this->rf->rfUpdateDate = date('Y-m-d H:i:s');
$this->rf->rfUpdateUserId = $this->session->userdata('UsLogin');
$this->rf->update();
if ($refNoPmNo >= $this->config->item('rg_refNoPmNo_max')) {
$refNoPmBook = intval($refNoPmBook + 1);
$refNoPmNo = 1;
} else {
$refNoPmNo = intval($refNoPmNo + 1);
}
}
} else {
$cnt++;
}
}
if($this->db->trans_status() === false) {
$this->db->trans_rollback();
} else {
$this->db->trans_commit();
}
if ($cnt == count($pmRfId)) {
$this->delete_file();
}
$this->paymentRegisCur();
}
function delete_file() {
if($this->input->post('docPath')!="") {
unlink($this->input->post('docPath'));
}
redirect($this->config->item("rg_folder")."payment/paymentRegisCur");
}
function prePrintPaymentRegisAllPDF() {
$this->load->model($this->config->item("rg_folder").'mo_rg_receiptconfig','rc');
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$this->load->model($this->config->item("rg_folder").'mo_rg_receiptitemsincurriculum','ric');
$this->load->model($this->config->item("rg_folder").'mo_rg_receiptitems','rit');
$this->load->model($this->config->item("rg_folder").'mo_rg_coursefee','crf');
$this->load->model($this->config->item("rg_folder").'mo_rg_fee','fee');
$this->load->model($this->config->item("rg_folder").'mo_rg_commonfee','cmf');
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculumfee','cf');
$this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');
$pmIdArr = $this->input->post('pmId');
$stdIdArr = $this->input->post('stdId');
$acYArr = $this->input->post('acY');
$tmIdArr = $this->input->post('tmId');
$syIdArr = $this->input->post('syId');
$this->contents['qu_rc'] = $this->rc->qryRc();
$arr = array();
for ($k = 0; $k < count($pmIdArr); $k++) {
$pmId = $pmIdArr[$k];
$stdId = $stdIdArr[$k];
$acY = $acYArr[$k];
$tmId = $tmIdArr[$k];
$syId = $syIdArr[$k];
$this->pm->pmId = $pmId;
$qu_pm = $this->pm->get_by_key();
$row_pm = $qu_pm->row();
$arr[$k]['qu_pm'] = $qu_pm;
$con_qu_std = array('stdId' => $stdId);
$qu_std = $this->std->qryStdJoinPfCurSySstElv($con_qu_std);
$arr[$k]['qu_std'] = $qu_std;
$row_std = $qu_std->row();
$arr[$k]['acY'] = $acY;
$this->tm->tmId = $tmId;
$qu_tm = $this->tm->get_by_key();
$arr[$k]['tmCode'] = $qu_tm->row()->tmCode;
$this->sy->syId = $syId;
$qu_sy = $this->sy->get_by_key();
$arr[$k]['syCode'] = $qu_sy->row()->syCode;
$this->ric->ricCurId = $row_std->stdCurId;
$this->ric->ricAdY = $row_std->stdAdY;
$qu_ric = $this->ric->get_by_key();
if (($row_std->stdAdY >= $this->config->item("reviseY")) && $qu_ric->num_rows()) {
$this->rit->ritId = $qu_ric->row()->ricRitId;
$qu_rit = $this->rit->get_by_key();
$sumCrf = 0;
$this->crf->crfStdId = $stdId;
$this->crf->crfAcY = $acY;
$this->crf->crfTmId = $tmId;
$this->crf->crfRfId = $row_pm->pmRfId;
$qu_crf = $this->crf->get_by_key();
if ($qu_crf->num_rows()) {
$row_crf = $qu_crf->row();
$sumCrf = $row_crf->crfLecFeeAmt + $row_crf->crfLabFeeAmt + $row_crf->crfKssFeeAmt;
}
$con_qu_cmf = array('cmfStdId' => $stdId,
'cmfAcY' => $acY,
'cmfTmId' => $tmId,
'feeOutBudget' => 'N'
);
$sumCf = $this->cmf->getSumAmtJoinFee($con_qu_cmf);
$con_qu_cf = array('cfStdId' => $stdId,
'cfAcY' => $acY,
'cfTmId' => $tmId,
'feeOutBudget' => 'N'
);
$sumPf = $this->cf->getSumAmtJoinFee($con_qu_cf);
$sumAmt = $sumCrf + $sumCf + $sumPf;
$arr[$k]['item'][] = array($qu_rit->row()->ritName, $sumAmt);
$arr[$k]['sumAmt'] = $sumAmt;
} else {
$i = 1;
$crf = 0;
$kss = 0;
$this->crf->crfStdId = $stdId;
$this->crf->crfAcY = $acY;
$this->crf->crfTmId = $tmId;
$this->crf->crfRfId = $row_pm->pmRfId;
$qu_crf = $this->crf->get_by_key();
if ($qu_crf->num_rows()) {
$row_crf = $qu_crf->row();
if ($row_crf->crfLecFeeAmt || $row_crf->crfLabFeeAmt) {
$crf = $row_crf->crfLecFeeAmt + $row_crf->crfLabFeeAmt;
$arr[$k]['item'][] = array($i.". ค่าหน่วยกิต", $crf);
$arr[$k]['item'][] = array(" ค่าหน่วยกิตภาคทฤษฎี", $row_crf->crfLecFeeAmt);
$arr[$k]['item'][] = array(" ค่าหน่วยกิตภาคปฏิบัติ/ทดลอง", $row_crf->crfLabFeeAmt);
$kss = $row_crf->crfKssFeeAmt;
$i++;
} // end if
} // end if
$cfPf = 0;
$sumCfPf = 0;
$rs_fee = $this->fee->qryFeeByStdIdAcYTmIdGroupFgId($stdId, $acY, $tmId);
foreach ($rs_fee->result() as $row_fee) {
$con_qu_cmf = array('cmfStdId' => $stdId,
'cmfAcY' => $acY,
'cmfTmId' => $tmId,
'feeFgId' => $row_fee->feeFgId,
'feeOutBudget' => 'N'
);
$cfPf = $this->cmf->getSumAmtJoinFee($con_qu_cmf);
$con_qu_cf = array('cfStdId' => $stdId,
'cfAcY' => $acY,
'cfTmId' => $tmId,
'feeFgId' => $row_fee->feeFgId,
'feeOutBudget' => 'N'
);
$cfPf += $this->cf->getSumAmtJoinFee($con_qu_cf);
$arr[$k]['item'][] = array($i.". ".$row_fee->fgName, $cfPf);
$sumCfPf += $cfPf;
$i++;
} // end foreach
$arr[$k]['item'][] = array($i.". ค่ารักษาสถานภาพการเป็นนักศึกษา", $kss);
$arr[$k]['item'][] = array(($i + 1).". ค่าปรับล่าช้า", $row_pm->pmLateFine);
$arr[$k]['sumAmt'] = $crf + $sumCfPf + $kss + $row_pm->pmLateFine;
} // end if reviseY
} // end for
$this->contents['rs'] = $arr;
$con_qu_prs = array('personId' => $this->session->userdata('UsPsCode'));
$qu_prs = $this->prs->qryPrsJoinPPC($con_qu_prs);
if ($qu_prs->num_rows()) {
$this->contents['qu_prs'] = $qu_prs;
}
$this->output_pdf($this->config->item("rg_folder")."v_prePrintPaymentRegisAllPDF");
}
function printPaymentRegis2AllPDF() {
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->load->model($this->config->item("rg_folder").'mo_rg_commonfee','cmf');
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculumfee','cf');
$pmIdArr = $this->input->post('pmId');
$stdIdArr = $this->input->post('stdId');
$acYArr = $this->input->post('acY');
$tmIdArr = $this->input->post('tmId');
$arr = array();
for ($k = 0; $k < count($pmIdArr); $k++) {
$pmId = $pmIdArr[$k];
$stdId = $stdIdArr[$k];
$acY = $acYArr[$k];
$tmId = $tmIdArr[$k];
//$this->pm->pmId = $pmId;
//$qu_pm = $this->pm->get_by_key();
$con_rs = array('pmId' => $pmId);
$qu_pm = $this->pm->qryPmJoinRf($con_rs);
$row_pm = $qu_pm->row();
$arr[$k]['qu_pm'] = $qu_pm;
//$con_qu_std = array('stdId' => $stdId);
$con_qu_std = array('stdId' => $row_pm->rfStdId);
$arr[$k]['qu_std'] = $this->std->qryStdJoinPfCurSySstElv($con_qu_std);
$arr[$k]['acY'] = $acY;
$this->tm->tmId = $row_pm->rfTmId;//$tmId;
$qu_tm = $this->tm->get_by_key();
$arr[$k]['tmCode'] = $qu_tm->row()->tmCode;
$arr[$k]['item'] = array();
$sumCommonFee = 0;
$i = 1;
/* $con_rs_cmf = array('cmfStdId' => $stdId,'cmfAcY' => $acY,'cmfTmId' => $tmId,'feeOutBudget' => 'Y'); */
$con_rs_cmf = array('cmfStdId' => $row_pm->rfStdId,
'cmfAcY' => $row_pm->rfAcY ,
'cmfTmId' => $row_pm->rfTmId ,
'feeOutBudget' => 'Y'
);
$rs_cmf = $this->cmf->qryCmfJoinFee($con_rs_cmf);
foreach ($rs_cmf->result() as $row_cmf) {
$arr[$k]['item'][] = array($i.". ".$row_cmf->feeName, $row_cmf->cmfAmt);
$sumCommonFee += $row_cmf->cmfAmt;
$i++;
}
$sumProgramFee = 0;
$j = $i;
/* $con_rs_cf = array('cfStdId' => $stdId,'cfAcY' => $acY,'cfTmId' => $tmId,'feeOutBudget' => 'Y'); */
$con_rs_cf = array('cfStdId' => $row_pm->rfStdId,
'cfAcY' => $row_pm->rfAcY ,
'cfTmId' => $row_pm->rfTmId ,
'feeOutBudget' => 'Y'
);
$rs_cf = $this->cf->qryCfJoinFee($con_rs_cf);
foreach ($rs_cf->result() as $row_cf) {
$arr[$k]['item'][] = array($j.". ".$row_cf->feeName, $row_cf->cfAmt);
$sumProgramFee += $row_cf->cfAmt;
$j++;
}
$arr[$k]['sumAmt'] = $sumCommonFee + $sumProgramFee;
}
$this->contents['rs'] = $arr;
$this->output_pdf($this->config->item("rg_folder")."v_printPaymentRegis2AllPDF");
}
function printPaymentRegisTime2PDF() {
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$pmId = $this->input->post('pmId');
$stdId = $this->input->post('stdId');
$acY = $this->input->post('acY');
$tmId = $this->input->post('tmId');
$this->pm->pmId = $pmId;
$qu_pm = $this->pm->get_by_key();
if ($qu_pm->num_rows()) {
$this->contents['qu_pm'] = $qu_pm;
}
$con_qu_std = array('stdId' => $stdId);
$qu_std = $this->std->qryStdJoinPf($con_qu_std);
if ($qu_std->num_rows()) {
$this->contents['qu_std'] = $qu_std;
}
$this->contents['acY'] = $acY;
$this->tm->tmId = $tmId;
$qu_tm = $this->tm->get_by_key();
$this->contents['tmCode'] = ($qu_tm->num_rows()) ? $qu_tm->row()->tmCode : '';
$this->output_pdf($this->config->item("rg_folder")."v_printPaymentRegisTime2PDF");
}
// ##### start ชำระค่าลงทะเบียนเรียนรายนักศึกษา
function paymentRegis() {
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_coursefeetp','crft');
$refNo = $this->input->post('refNo');
$btnSearch = $this->input->post('btnSearch');
if ($btnSearch) {
$this->contents['refNo'] = "";
$con_qu_rf = array('rfRefNo' => $refNo);
$qu_rf = $this->rf->qryRf($con_qu_rf);
if ($qu_rf->num_rows()) {
$row_rf = $qu_rf->row();
$this->contents['refNo'] = $refNo;
$this->contents['qu_rf'] = $qu_rf;
$con_qu_std = array('stdId' => $row_rf->rfStdId);
$qu_std = $this->std->qryStdJoinPfCurSySstElv($con_qu_std);
$row_std = $qu_std->row();
$this->contents['qu_std'] = $qu_std;
$acY = substr($refNo, 0, 4);
$this->contents['acY'] = $acY;
$this->contents['acY_R'] = $this->session->userdata('acY_R');
$tmId = substr($refNo, 4, 1);
$this->contents['tmId'] = $tmId;
$this->contents['tmId_R'] = $this->session->userdata('tmId_R');
$this->sd->sdAcY = $acY;
$this->sd->sdTmId = $tmId;
$qu_sd = $this->sd->get_by_key();
if(!$qu_sd->num_rows()) {
$msg = "ไม่สามารถชำระค่าลงทะเบียนเรียนรายนักศึกษาได้<br />ต้องทำการเพิ่มข้อมูล ที่เมนูข้อมูลพื้นฐานของระบบ -> ข้อมูลปฏิทินการศึกษา";
$this->session->set_flashdata('msg', $msg);
redirect($this->config->item('rg_folder').'msg/err_msg');
}
$this->contents['qu_sd'] = $qu_sd;
$lateFine = 0;
$flagCalLateFine = 0;
// Calculate lateFine at the 1st time
$con_rs_pm = array('pmRfId' => $row_rf->rfId);
$rs_pm = $this->pm->qryPm($con_rs_pm);
$this->contents['rs_pm'] = $rs_pm;
if (!$rs_pm->num_rows()) {
$flagCalLateFine = 1;
}
if ($flagCalLateFine) {
$numDateDiff = $this->pm->getNumDateDiff(getNowDate(), $qu_sd->row()->sdPayEDate);
if ($numDateDiff > 0) {
$reviseY = 2552;
$this->crft->crftCurId = $row_std->stdCurId;
$this->crft->crftAdY = 0;
$this->crft->crftSyId = 0;
$this->crft->crftAcY = $acY;
$this->crft->crftTmId = $tmId;
if ($qu_std->row()->stdAdY >= $reviseY) {
$this->crft->crftAdY = $row_std->stdAdY;
$this->crft->crftSyId = $row_std->stdSyId;
}
$qu_crft = $this->crft->get_by_key();
if ($qu_crft->num_rows()) {
$row_crft = $qu_crft->row();
$this->contents['qu_crft'] = $qu_crft;
if ($row_crft->crftLateFineUnit == 'B') {
$lateFine = $numDateDiff * $row_crft->crftLateFine;
} else if ($row_crft->crftLateFineUnit == 'P') {
$lateFine = (($row_rf->rfTotalAmt * $row_crft->crftLateFine) / 100) * $numDateDiff;
}
if ($lateFine > $row_crft->crftMaxLateFine) {
$lateFine = $row_crft->crftMaxLateFine;
}
}
}
}
$this->contents['lateFine'] = $lateFine;
$this->contents['maxRefNo'] = $this->pm->getMaxRefNo();
$this->contents['action'] = "processPaymentRegis";
}
}
$this->output($this->config->item("rg_folder")."v_paymentRegis");
}
function processPaymentRegis() {
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_coursefeetp','crft');
$this->load->model($this->config->item("rg_folder").'mo_rg_coursefee','crf');
$rfId = $this->input->post('rfId');
$pmAmt = $this->input->post('pmAmt');
$pmType = $this->input->post('pmType');
$stdId = $this->input->post('stdId');
$acY = $this->input->post('acY');
$tmId = $this->input->post('tmId');
$lateFine = $this->input->post('lateFine');
$this->rf->rfId = $rfId;
$this->rf->get_by_key(TRUE);
if ($pmAmt > $this->rf->rfBalance) {
$this->contents['err_msg'] = "** กรุณาตรวจสอบจำนวนเงินของเลขที่ใบเสร็จให้ถูกต้อง **";
$this->paymentRegis();
}
$pmDate = "";
if ($pmType == 1) {
$pmDate = $this->input->post('pmDate1');
} else if ($pmType == 2) {
$pmDate = splitDateForm($this->input->post('pmDate2'), '/');
}
$numDateDiff = $this->pm->getNumDateDiff($pmDate, $this->input->post('sdPayEDate'));
// Insert Payment
$this->pm->pmDate = $pmDate;
$this->pm->pmType = $pmType;
$this->pm->pmAmt = $pmAmt;
$this->pm->pmRfId = $rfId;
$pBook = '';
for ($k = 1; $k < $this->config->item('rg_refNoPmBook_length'); $k++) {
$pBook .= '0';
}
$pNo = '';
for ($k = 1; $k < strlen($this->config->item('rg_refNoPmNo_max')); $k++) {
$pNo .= '0';
}
$this->pm->pmRefNo = substr($pBook.$this->input->post('refNoPmBook'), (-1)*$this->config->item('rg_refNoPmBook_length')).'|'.substr($pNo.$this->input->post('refNoPmNo'), (-1)*strlen($this->config->item('rg_refNoPmNo_max')));
//$this->pm->pmRefNo = substr('00'.$this->input->post('refNoPmBook'), -3).'|'.substr('0000'.$this->input->post('refNoPmNo'), -5);
$this->pm->pmLateStatus = 'N';
if ($numDateDiff > 0) {
$reviseY = 2552;
$this->std->stdId = $stdId;
$qu_std = $this->std->get_by_key();
$row_std = $qu_std->row();
$this->crft->crftCurId = $this->input->post('curId');
$this->crft->crftAdY = 0;
$this->crft->crftSyId = 0;
$this->crft->crftAcY = $acY;
$this->crft->crftTmId = $tmId;
if ($row_std->stdAdY >= $reviseY) {
$this->crft->crftAdY = $row_std->stdAdY;
$this->crft->crftSyId = $row_std->stdSyId;
}
$qu_crft = $this->crft->get_by_key();
if($qu_crft->num_rows()) {
$row_crft = $qu_crft->row();
if ($row_crft->crftLateFineUnit == 'B') {
$lateFine = $numDateDiff * $row_crft->crftLateFine;
} else if ($row_crft->crftLateFineUnit == 'P') {
$lateFine = (($this->rf->rfBalance * $row_crft->crftLateFine) / 100) * $numDateDiff;
}
if ($lateFine > $row_crft->crftMaxLateFine) {
$lateFine = $row_crft->crftMaxLateFine;
}
}
}
$this->pm->pmLateFine = $lateFine;
$this->pm->pmPrintDate = getNowDate();
$this->pm->insert();
// Update CourseFee
$this->crf->crfStdId = $stdId;
$this->crf->crfAcY = $acY;
$this->crf->crfTmId = $tmId;
$this->crf->crfRfId = $rfId;
$this->crf->get_by_key(TRUE);
$this->crf->crfLateFineAmt = $lateFine;
$this->crf->update();
// Update EnrollFee
$this->rf->rfBalance -= $pmAmt;
$this->rf->rfUpdateDate = date('Y-m-d H:i:s');
$this->rf->rfUpdateUserId = $this->session->userdata('UsLogin');
$this->rf->update();
$this->paymentRegis();
}
function pm_delete() {
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->load->model($this->config->item("rg_folder").'mo_rg_coursefee','crf');
// Delete Payment
$this->pm->pmId = $this->input->post('pmId');
$this->pm->get_by_key(TRUE);
// Update EnrollFee
$this->rf->rfId = $this->pm->pmRfId;
$this->rf->get_by_key(TRUE);
$this->rf->rfBalance += $this->pm->pmAmt;
$this->rf->rfUpdateDate = date('Y-m-d H:i:s');
$this->rf->rfUpdateUserId = $this->session->userdata('UsLogin');
$this->rf->update();
// Update CourseFee
$this->crf->crfStdId = $this->rf->rfStdId;
$this->crf->crfAcY = $this->rf->rfAcY;
$this->crf->crfTmId = $this->rf->rfTmId;
$this->crf->crfRfId = $this->pm->pmRfId;
$this->crf->get_by_key(TRUE);
$this->crf->crfLateFineAmt -= $this->pm->pmLateFine;
$this->crf->update();
$this->pm->delete();
if ($this->input->post('action') == "paymentRegisTime") {
$this->paymentRegisTime();
} else {
$this->paymentRegis();
}
}
// ##### end ชำระค่าลงทะเบียนเรียนรายนักศึกษา
// ##### start ผ่อนชำระค่าลงทะเบียนเรียนรายนักศึกษา
function paymentRegisTime() {
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_coursefeetp','crft');
$refNo = $this->input->post('refNo');
$btnSearch = $this->input->post('btnSearch');
if ($btnSearch) {
$this->contents['refNo'] = "";
$con_qu_rf = array('rfRefNo' => $refNo);
$qu_rf = $this->rf->qryRf($con_qu_rf);
if ($qu_rf->num_rows()) {
$row_rf = $qu_rf->row();
$this->contents['refNo'] = $refNo;
$this->contents['qu_rf'] = $qu_rf;
$con_qu_std = array('stdId' => $row_rf->rfStdId);
$qu_std = $this->std->qryStdJoinPfCurSySstElv($con_qu_std);
$row_std = $qu_std->row();
$this->contents['qu_std'] = $qu_std;
$acY = substr($refNo, 0, 4);
$this->contents['acY'] = $acY;
$this->contents['acY_R'] = $this->session->userdata('acY_R');
$tmId = substr($refNo, 4, 1);
$this->contents['tmId'] = $tmId;
$this->contents['tmId_R'] = $this->session->userdata('tmId_R');
$this->sd->sdAcY = $acY;
$this->sd->sdTmId = $tmId;
$qu_sd = $this->sd->get_by_key();
$this->contents['qu_sd'] = $qu_sd;
if(!$qu_sd->num_rows()) {
$msg = "ไม่สามารถชำระค่าลงทะเบียนเรียนรายนักศึกษาได้<br />ต้องทำการเพิ่มข้อมูล ที่เมนูข้อมูลพื้นฐานของระบบ -> ข้อมูลปฏิทินการศึกษา";
$this->session->set_flashdata('msg', $msg);
redirect($this->config->item('rg_folder').'msg/err_msg');
}
$lateFine = 0;
$flagCalLateFine = 0;
// Calculate lateFine at the 1st time
$con_rs_pm = array('pmRfId' => $row_rf->rfId);
$rs_pm = $this->pm->qryPm($con_rs_pm);
$this->contents['rs_pm'] = $rs_pm;
if (!$rs_pm->num_rows()) {
$flagCalLateFine = 1;
}
if ($flagCalLateFine) {
$numDateDiff = $this->pm->getNumDateDiff(getNowDate(), $qu_sd->row()->sdPayEDate);
if ($numDateDiff > 0) {
$reviseY = 2552;
$this->crft->crftCurId = $row_std->stdCurId;
$this->crft->crftAdY = 0;
$this->crft->crftSyId = 0;
$this->crft->crftAcY = $acY;
$this->crft->crftTmId = $tmId;
if ($row_std->stdAdY >= $reviseY) {
$this->crft->crftAdY = $row_std->stdAdY;
$this->crft->crftSyId = $row_std->stdSyId;
}
$qu_crft = $this->crft->get_by_key();
if ($qu_crft->num_rows()) {
$row_crft = $qu_crft->row();
if ($row_crft->crftLateFineUnit == 'B') {
$lateFine = $numDateDiff * $row_crft->crftLateFine;
} else if ($row_crft->crftLateFineUnit == 'P') {
$lateFine = (($row_rf->rfTotalAmt * $row_crft->crftLateFine) / 100) * $numDateDiff;
}
if ($lateFine > $row_crft->crftMaxLateFine) {
$lateFine = $row_crft->crftMaxLateFine;
}
}
}
}
$this->contents['lateFine'] = $lateFine;
$this->contents['maxRefNo'] = $this->pm->getMaxRefNo();
$con_qu_pm = array('pmRfId' => $row_rf->rfId);
$this->contents['maxPmId'] = $this->pm->getMaxId($con_qu_pm);
$this->contents['action'] = "processPaymentRegisTime";
}
}
$this->output($this->config->item("rg_folder")."v_paymentRegisTime");
}
function processPaymentRegisTime() {
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->load->model($this->config->item("rg_folder").'mo_rg_payment','pm');
$this->load->model($this->config->item("rg_folder").'mo_rg_coursefee','crf');
$rfId = $this->input->post('rfId');
$pmAmt = $this->input->post('pmAmt');
$stdId = $this->input->post('stdId');
$acY = $this->input->post('acY');
$tmId = $this->input->post('tmId');
$lateFine = $this->input->post('lateFine');
$this->rf->rfId = $rfId;
$this->rf->get_by_key(TRUE);
if ($pmAmt > $this->rf->rfBalance) {
$this->contents['err_msg'] = "** กรุณาตรวจสอบจำนวนเงินของเลขที่ใบเสร็จให้ถูกต้อง **";
$this->paymentRegisTime();
//echo "<meta http-equiv='refresh' content='2; URL=paymentEnrollTime.php?methodSearch=$methodSearch&refNo=$refNo'>";
//exit();
}
$flagCalLateFine = 0;
// Calculate lateFine at the 1st time
$con_rs_pm = array('pmRfId' => $rfId);
$rs_pm =$this->pm->qryPm($con_rs_pm);
if (!$rs_pm->num_rows()) {
$flagCalLateFine = 1;
}
// Insert Payment
$this->pm->pmDate = $this->input->post('pmDate');
$this->pm->pmType = $this->input->post('pmType');
$this->pm->pmAmt = $pmAmt;
$this->pm->pmRfId = $rfId;
$pBook = '';
for ($k = 1; $k < $this->config->item('rg_refNoPmBook_length'); $k++) {
$pBook .= '0';
}
$pNo = '';
for ($k = 1; $k < strlen($this->config->item('rg_refNoPmNo_max')); $k++) {
$pNo .= '0';
}
$this->pm->pmRefNo = substr($pBook.$this->input->post('refNoPmBook'), (-1)*$this->config->item('rg_refNoPmBook_length')).'|'.substr($pNo.$this->input->post('refNoPmNo'), (-1)*strlen($this->config->item('rg_refNoPmNo_max')));
//$this->pm->pmRefNo = substr('00'.$this->input->post('refNoPmBook'), -3).'|'.substr('0000'.$this->input->post('refNoPmNo'), -5);
$this->pm->pmLateStatus = 'N';
$this->pm->pmLateFine = $lateFine;
$this->pm->pmPrintDate = getNowDate();
$this->pm->insert();
if ($flagCalLateFine) {
// Update CourseFee
$this->crf->crfStdId = $stdId;
$this->crf->crfAcY = $acY;
$this->crf->crfTmId = $tmId;
$this->crf->crfRfId = $rfId;
$this->crf->get_by_key(TRUE);
$this->crf->crfLateFineAmt = $lateFine;
$this->crf->update();
}
// Update EnrollFee
$this->rf->rfBalance -= $pmAmt;
$this->rf->rfUpdateDate = date('Y-m-d H:i:s');
$this->rf->rfUpdateUserId = $this->session->userdata('UsLogin');
$this->rf->update();
$this->paymentRegisTime();
}
// ##### end ผ่อนชำระค่าลงทะเบียนเรียนรายนักศึกษา
// ##### start พ้นสภาพ
function checkOutSst() {
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->contents['acY'] = $this->session->userdata('acY');
$this->contents['tmId'] = $this->session->userdata('tmId');
$this->contents['rs_tm'] = $this->tm->get_options('','','', 'y');
$this->output($this->config->item("rg_folder")."v_checkOutSst");
}
function showOutSst() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<font color="red">','</font>');
$this->form_validation->set_rules('curName','ชื่อหลักสูตร','trim|xss_clean');
$this->form_validation->set_rules('curId','ชื่อหลักสูตร ','trim|required|xss_clean');
$this->form_validation->set_rules('adY','ปีการศึกษาที่เข้า','trim|required|xss_clean');
$this->form_validation->set_rules('acY','ปีการศึกษา','callback_checkAcY');
$this->form_validation->set_rules('tmId','ภาคการศึกษา','trim|required|xss_clean');
$this->form_validation->set_rules('syCode','ชั้นปี','callback_checkSy');
if($this->form_validation->run() == true) {
$curId = $this->input->post('curId');
$adY = $this->input->post('adY');
$acY = $this->input->post('acY');
$tmId = $this->input->post('tmId');
$syCode = $this->input->post('syCode');
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->load->model($this->config->item("rg_folder").'mo_rg_registfee','rf');
$this->cur->curId = $curId;
$this->contents['qu_cur'] = $this->cur->get_by_key();
$con_qu_sy = array('syCode' => $syCode);
$this->contents['qu_sy'] = $this->sy->qrySy($con_qu_sy,'','');
$this->tm->tmId = $tmId;
$this->contents['qu_tm'] = $this->tm->get_by_key();
$this->contents['adY'] = $adY;
$this->contents['acY'] = $acY;
$this->contents['rs_rf'] = '';
$rs_rf = $this->rf->qryRfStdIdGroupRfStdIdJoinStdPfSst($acY,$this->contents['qu_sy']->row()->syId,$tmId,$curId);
$i = 0;
$arr = array();
if($rs_rf->num_rows()) {
foreach($rs_rf->result() as $row_rf) {
$con_sumRfBalance = array('rfStdId' => $row_rf->stdId,
'rfAcY' => $acY,
'rfSyId' => $this->contents['qu_sy']->row()->syId,
'rfTmId' => $tmId);
$arr[$i]['std'] = $row_rf;
$arr[$i]['sumRfBalance'] = $this->rf->getSumBalance($con_sumRfBalance);
$i++;
}
}
$this->contents['arr'] = $arr;
$this->output($this->config->item("rg_folder")."v_showOutSst");
} else {
$this->checkOutSst();
}
}
function processOutSst() {
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_studentsummary','ssm');
$acY = $this->input->post('acY');
$tmId = $this->input->post('tmId');
$syCode = $this->input->post('syCode');
$curId = $this->input->post('curId');
$adY = $this->input->post('adY');
$this->db->trans_begin();
for($i=0; $i<$this->input->post('cnt'); $i++) {
if($this->input->post('chk'.$i)=='Y') {
$this->std->stdId = $this->input->post('stdId'.$i);
$this->std->get_by_key(TRUE);
$this->std->stdSstId = 9; // พ้นสภาพไม่ชำระเงิน
$this->std->stdUpdateDate = date('Y-m-d H:i:s');
$this->std->stdUpdateUsLogin = $this->session->userdata('UsLogin');
$this->std->update();
$this->ssm->ssmStdId = $this->input->post('stdId'.$i);
$this->ssm->ssmTmId = $tmId;
$this->ssm->ssmAcY = $acY;
$this->ssm->get_by_key(TRUE);
$this->ssm->ssmSstId = 9; // พ้นสภาพไม่ชำระเงิน
$this->ssm->ssmUpdateDate = date('Y-m-d H:i:s');
$this->ssm->ssmUpdateUserId = $this->session->userdata('UsLogin');
$this->ssm->update();
}
}
if($this->db->trans_status() === false)
$this->db->trans_rollback();
else {
$this->db->trans_commit();
$this->contents['flg_success'] = "บันทึกสถานะนักศึกษาสำเร็จ";
}
$this->showOutSst();
}
// ##### end พ้นสภาพ
// ##### start callback
function checkSy($str) {
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$con_qu_sy = array('syCode' => $str);
$qu_sy = $this->sy->qrySy($con_qu_sy,'','');
if($str=='') {
$this->form_validation->set_message('checkSy','กรุณาป้อน%s');
return false;
}
if($qu_sy->num_rows()==0) {
$this->form_validation->set_message('checkSy','%sไม่ถูกต้อง');
return false;
} else
return true;
}
function checkAcY($str) {
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
$adY = $this->input->post('adY');
$con_qu_tmc = array('tmcAcY' => $str);
$qu_tmc = $this->tmc->qryTmc($con_qu_tmc,'','');
if($str=='') {
$this->form_validation->set_message('checkAcY','กรุณาป้อน%s');
return false;
} else if(strlen($str)!=4) {
$this->form_validation->set_message('checkAcY','%sจะต้องมากกว่า 4 หลัก');
return false;
}
if($qu_tmc->num_rows() && $str >= $adY) {
return true;
} else {
$this->form_validation->set_message('checkAcY','%sไม่ถูกต้อง');
return false;
}
}
// ##### end callback
// 30/1/2556 sitthichai
function downloadFile($filename){
$this->load->helper('download');
$data = file_get_contents(base_url().$this->config->item("rg_upload_doc").$filename); // Read the file's contents
$name = $filename;
force_download($name, $data);
}
}
?>
|