Exemplo n.º 1
0
 public function addPaymentHistory(PaymentHistory $l)
 {
     $this->collPaymentHistorys[] = $l;
     $l->setAcademicCost($this);
 }
Exemplo n.º 2
0
 public function executeSave()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     $params = array();
     foreach (explode('&', $this->getRequestParameter('month_list_ser')) as $p) {
         $p = explode('=', $p);
         $params[rawurldecode($p[0])][] = rawurldecode($p[1]);
     }
     if (array_key_exists('months', $params)) {
         foreach ($params['months'] as $month_id) {
             $payment_student = new PaymentJournal();
             $student = StudentPeer::retrieveByPK($this->getRequestParameter('student_id'));
             $c = new Criteria();
             $c->add(StudentTypePeer::STUDENT_ID, $student->getId());
             $stu_type = StudentTypePeer::doSelectOne($c);
             $cr = new Criteria();
             $cton1 = $cr->getNewCriterion(AcademicCostPeer::PAYER_TYPE_ID, $stu_type->getPayerTypeId(), Criteria::IN);
             $cton2 = $cr->getNewCriterion(AcademicCostPeer::ACADEMIC_PROCESS_ID, 2, Criteria::IN);
             $cton3 = $cr->getNewCriterion(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $student->getAcademicCalendarId(), Criteria::IN);
             $cton4 = $cr->getNewCriterion(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $student->getAcademicCalendar()->getParent(), Criteria::IN);
             $cton3->addOr($cton4);
             $cton2->addAnd($cton3);
             $cton1->addAnd($cton2);
             $cr->add($cton1);
             $ac_cost = AcademicCostPeer::doSelectOne($cr);
             $payment_student->setPayer($this->getRequestParameter('student_id'));
             $payment_student->setAcademicCostId($ac_cost->getId());
             $payment_student->setAcademicProcessId($ac_cost->getAcademicProcessId());
             $payment_student->setAmount($ac_cost->getAmount());
             $payment_student->setPaid($ac_cost->getAmount());
             $payment_student->setReceivable($ac_cost->getAmount() - $ac_cost->getAmount());
             $payment_student->setPaidAt($this->getRequestParameter('paid_at'));
             $payment_student->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT);
             $payment_student->setPaymentModelId($this->getRequestParameter('payment_model_id'));
             $payment_student->setYear($this->getRequestParameter('year'));
             $payment_student->setMonth($month_id);
             $payment_student->setStatus('S');
             $payment_student->save();
             $amount_changed = $ac_cost->getAmount();
             if ($amount_changed != 0) {
                 $ph = new PaymentHistory();
                 $ph->setPaymentJournal($payment_student);
                 $ph->setAmount($amount_changed);
                 $ph->save();
             }
         }
     }
     return $this->redirect('payment_student/list');
     #return $this->forward('payment_student', 'preview?student_id='.$this->getRequestParameter('student_id').'&paid_at='.$this->getRequestParameter('paid_at').'&payment_model_id='.$this->getRequestParameter('payment_model_id').'&year='.$this->getRequestParameter('year'));
     #return $this->redirect('payment_student/preview?student_id='.$this->getRequestParameter('student_id').'&paid_at='.$this->getRequestParameter('paid_at').'&payment_model_id='.$this->getRequestParameter('payment_model_id').'&year='.$this->getRequestParameter('year'));
     #return $this->redirect('payment_student/list',
     #					    'before'=>"window.open('".$this->getController()->genUrl('/payment_student/printForm').
     #		  "?student_id='+$('student_id').value+'&paid_at='+$('paid_at').value+'&payment_model_id='+$('payment_model_id').value+'&year='+$('year').value,
     #								'link',
     #								'height=480,width=640,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no'
     #								)")
 }
Exemplo n.º 3
0
 public function executeUpdate()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     $student = StudentPeer::retrieveByPK($this->getRequestParameter('student_id'));
     $this->forward404Unless($student);
     $this->student = $student;
     if ($action_type == $action_i18n || !$this->getRequestParameter('id')) {
         $student_leave = new StudentLeave();
         $student_leave->setStatus(StudentLeave::STATUS_PROPOSED);
     } else {
         $student_leave = StudentLeavePeer::retrieveByPk($this->getRequestParameter('id'));
         $this->forward404Unless($student_leave);
         $student_leave->setStatus(StudentLeave::STATUS_CANCELED);
     }
     $student_leave->setId($this->getRequestParameter('id'));
     $student_leave->setStudentId($this->getRequestParameter('student_id'));
     $student_leave->setAcademicCalendarId($this->getRequestParameter('academic_calendar_id'));
     $student_leave->save();
     $stu = $student_leave->getStudent();
     if ($student_leave->getStatus() == StudentLeave::STATUS_ACTIVE) {
         // add payment journal
         $job = JobPeer::retrieveByCode($this->getModuleName());
         $academic_process = $job->getAcademicProcess();
         $c = new Criteria();
         $c->add(AcademicCostPeer::ACADEMIC_PROCESS_ID, $academic_process->getId());
         $c->add(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $student_leave->getAcademicCalendarId());
         $costs = AcademicCostPeer::doSelect($c);
         foreach ($costs as $c) {
             $pj = new PaymentJournal();
             $pj->setPayer($stu->getId());
             $pj->setAcademicCost($c);
             $pj->setJob($job);
             $pj->setAmount($c->getAmount());
             $pj->setPaid($c->getAmount());
             $pj->setReceivable(0);
             $pj->setAcademicProcess($academic_process);
             $pj->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT);
             $pj->save();
             $ph = new PaymentHistory();
             $ph->setPaymentJournal($pj);
             $ph->setAmount($c->getAmount());
             $ph->save();
         }
         // set student status
         $stu->setStatus(Student::STATUS_INACTIVE);
         $stu->save();
         // cancelled all student course
         $c = new Criteria();
         $c->add(StudentCoursePeer::STUDENT_ID, $stu->getId());
         $c->add(StudentCoursePeer::STATUS, array(StudentCourse::STATUS_PLANNED, StudentCourse::STATUS_APPROVED, StudentCourse::STATUS_ACTIVE), Criteria::IN);
         $scs = StudentCoursePeer::doSelect($c);
         foreach ($scs as $sc) {
             $sc->setStatus(StudentCourse::STATUS_CANCELED);
             $sc->save();
         }
     } elseif ($student_leave->getStatus() == StudentLeave::STATUS_DONE) {
         $stu->setStatus(Student::STATUS_ACTIVE);
         $stu->save();
     }
     return $this->redirect('student_leave_s/list?student_id=' . $student->getId());
 }
Exemplo n.º 4
0
 public function get_data_report_daily($date_start, $date_end)
 {
     $results = PaymentHistory::whereBetween('payment_histories.created_at', [$date_start, $date_end])->join('transactions', 'payment_histories.transaction_id', '=', 'transactions.id')->join('customers', 'transactions.customer_id', '=', 'customers.id')->join('status', 'transactions.status_id', '=', 'status.id')->select('payment_histories.amount as amount_payment', 'payment_histories.description as desc_payment', 'payment_histories.created_at as created_at_payment', 'transactions.invoice_number', 'transactions.date_checkout', 'transactions.discount', 'status.name as status_trans', 'transactions.date_order', 'customers.name as customer_name', 'customers.address as customer_address')->get();
     return $results;
 }
Exemplo n.º 5
0
 public function batchPayment($client_id, $employee_id, $account, $total_paid, $paid_date, $note)
 {
     $sql = "SELECT sale_id,sale_time,client_name,amount_to_paid\n                  FROM (\n                    SELECT s.sale_id,sale_time,client_name,(s.`sub_total`-IFNULL(sp.payment_amount,0)) amount_to_paid\n                    FROM \n                    (SELECT s.id sale_id,s.`sale_time`,CONCAT(c.first_name,' ',last_name) client_name,s.`sub_total`\n                     FROM sale s, `client` c\n                     WHERE s.`client_id` = c.id\n                     AND c.id=:client_id) s LEFT JOIN v_sale_payment sp ON sp.sale_id=s.sale_id\n                    ) AS t\n                  WHERE amount_to_paid>0\n                  ORDER BY sale_time";
     $result = Yii::app()->db->createCommand($sql)->queryAll(true, array(':client_id' => $client_id));
     $paid_amount = $total_paid;
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $payment_id = PaymentHistory::model()->savePaymentHistory($client_id, $total_paid, $paid_date, $employee_id, $note);
         foreach ($result as $record) {
             if ($paid_amount <= $record["amount_to_paid"]) {
                 $payment_amount = $paid_amount;
                 $this->saveSalePayment($record["sale_id"], $payment_id, $payment_amount, $paid_date, $note);
                 $this->saveAccuntRecv($account->id, $employee_id, $record["sale_id"], $payment_amount, $paid_date, $note);
                 break;
             } else {
                 $paid_amount = $paid_amount - $record["amount_to_paid"];
                 $payment_amount = $record["amount_to_paid"];
                 $this->saveSalePayment($record["sale_id"], $payment_id, $payment_amount, $paid_date, $note);
                 $this->saveAccuntRecv($account->id, $employee_id, $record["sale_id"], $payment_amount, $paid_date, $note);
             }
         }
         Account::model()->updateAccountBal($account, $total_paid);
         $transaction->commit();
         $message = $payment_id;
     } catch (Exception $e) {
         $transaction->rollback();
         //return $e->getMessage();
         $message = '-1' . $e->getMessage();
     }
     return $message;
 }
Exemplo n.º 6
0
 public function addPaymentHistory(PaymentHistory $l)
 {
     $this->collPaymentHistorys[] = $l;
     $l->setPaymentJournal($this);
 }
Exemplo n.º 7
0
 public function savePaymentHistory($client_id, $payment_amount, $paid_date, $employee_id, $note)
 {
     $payment_id = 0;
     if ($payment_amount != 0) {
         $payment_history = new PaymentHistory();
         $payment_history->client_id = $client_id;
         $payment_history->payment_amount = $payment_amount;
         $payment_history->date_paid = $paid_date;
         $payment_history->note = $note;
         $payment_history->employee_id = $employee_id;
         $payment_history->save();
         $payment_id = $payment_history->id;
     }
     return $payment_id;
 }
Exemplo n.º 8
0
 public function executeUpdate()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     if ($action_type == $action_i18n || !$this->getRequestParameter('id')) {
         $comprehensive_exam = new ComprehensiveExam();
     } else {
         $comprehensive_exam = ComprehensiveExamPeer::retrieveByPk($this->getRequestParameter('id'));
         $this->forward404Unless($comprehensive_exam);
     }
     $comprehensive_exam->setId($this->getRequestParameter('id'));
     $comprehensive_exam->setStudentId($this->getRequestParameter('student_id'));
     if ($this->getRequestParameter('exam_date')) {
         $comprehensive_exam->setExamDate($this->getRequestParameter('exam_date'));
     }
     $comprehensive_exam->setStatus($this->getRequestParameter('status'));
     $comprehensive_exam->save();
     $c = new Criteria();
     $c->add(ComprehensiveReviewerPeer::COMPREHENSIVE_EXAM_ID, $comprehensive_exam->getId());
     ComprehensiveReviewerPeer::doDelete($c);
     $reviewers = $this->getRequestParameter('isSelected');
     if ($reviewers) {
         foreach ($reviewers as $id) {
             $cr = new ComprehensiveReviewer();
             $cr->setComprehensiveExam($comprehensive_exam);
             $cr->setEmployeeId($id);
             $cr->save();
         }
     }
     if ($comprehensive_exam->getStatus() == ComprehensiveExam::STATUS_ACTIVE) {
         // add payment journal
         $job = JobPeer::retrieveByCode($this->getModuleName());
         $academic_process = $job->getAcademicProcess();
         $c = new Criteria();
         $c->add(AcademicCostPeer::ACADEMIC_PROCESS_ID, $academic_process->getId());
         $c->add(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $comprehensive_exam->getAcademicCalendarId());
         $costs = AcademicCostPeer::doSelect($c);
         foreach ($costs as $c) {
             $pj = new PaymentJournal();
             $pj->setPayer($comprehensive_exam->getStudent()->getId());
             $pj->setAcademicCost($c);
             $pj->setJob($job);
             $pj->setAmount($c->getAmount());
             $pj->setPaid($c->getAmount());
             $pj->setReceivable(0);
             $pj->setAcademicProcess($academic_process);
             $pj->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT);
             $pj->save();
             $ph = new PaymentHistory();
             $ph->setPaymentJournal($pj);
             $ph->setAmount($pj->getPaid());
             $ph->save();
         }
     } elseif ($comprehensive_exam->getStatus() == ComprehensiveExam::STATUS_PASSED) {
         $s = $comprehensive_exam->getStudent();
         $s->setStatus(Student::STATUS_GRADUATE);
         $s->save();
         $gc = new GradCeremony();
         $gc->setStudent($s);
         $gc->setStatus(GradCeremony::STATUS_UNLISTED);
         $gc->setAcademicCalendarId($comprehensive_exam->getAcademicCalendarId());
         $gc->save();
     }
     return $this->redirect('comprehensive_exam/list');
 }
Exemplo n.º 9
0
 public function executeInsertPaymentJournal()
 {
     $student_course = StudentCoursePeer::retrieveByPK($this->getRequestParameter('id'));
     $stu = StudentPeer::retrieveByPK($this->getRequestParameter('student_id'));
     $accal = $student_course->getAcademicCalendar();
     $job = JobPeer::retrieveByCode($this->getModuleName());
     $academic_process = $job->getAcademicProcess();
     $this->forward404Unless($student_course && $stu && $accal && $job && $academic_process);
     //		$c = new Criteria();
     //		$c->add(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $accal->getId());
     //		$c->add(AcademicProcessPeer::CODE, $academic_process->getCode());
     //		$c->addJoin(AcademicProcessPeer::ID, AcademicCostPeer::ACADEMIC_PROCESS_ID);
     //		$costs = AcademicCostPeer::doSelect($c);
     #$c = new Criteria();
     #$c->add(StudentCoursePeer::STUDENT_ID, $stu->getId());
     #$c->add(SubjectAccalPeer::ACADEMIC_CALENDAR_ID, $accal->getId());
     #$c->add(StudentCoursePeer::STATUS, StudentCourse::STATUS_APPROVED);
     #$c->addJoin(SubjectAccalPeer::ID, StudentCoursePeer::SUBJECT_ACCAL_ID);
     #$scs = StudentCoursePeer::doSelect($c);
     $paids = $this->getRequestParameter('paid');
     foreach ($paids as $key => $val) {
         $c = AcademicCostPeer::retrieveByPK($key);
         $payment_journal = new PaymentJournal();
         $payment_journal->setAcademicCost($c);
         $payment_journal->setJob($job);
         $payment_journal->setPayer($stu->getId());
         #$amount = 0;
         #if ($c->getAcademicCostComponent()->getUnit() == AcademicCostComponent::UNIT_CREDIT) {
         #	foreach ($scs as $sc) {
         #		$amount += $c->getAmount() * $sc->getSubjectAccal()->getSubject()->getCredit();
         #	}
         #} elseif ($c->getAcademicCostComponent()->getUnit() == AcademicCostComponent::UNIT_SUBJECT) {
         #	foreach ($scs as $sc) {
         #		$amount += $c->getAmount();
         #	}
         #} else {
         $amount = $c->getAmount();
         #}
         $payment_journal->setAmount($amount);
         $payment_journal->setPaid($val);
         $payment_journal->setReceivable($amount - $val);
         $payment_journal->setAcademicProcess($academic_process);
         $payment_journal->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT);
         if ($amount - $val == 0) {
             $payment_journal->setStatus('S');
         } elseif ($amount - $val > 0) {
             $payment_journal->setStatus('M');
         } elseif ($amount - $val < 0) {
             $payment_journal->setStatus('P');
         }
         $payment_journal->save();
         $ph = new PaymentHistory();
         $ph->setPaymentJournal($payment_journal);
         $ph->setAmount($val);
         $ph->save();
     }
     // activate all paid credit
     if ($this->hasRequestParameter('status[student_course]') && $this->getRequestParameter('status[student_course]') == 1) {
         $c = new Criteria();
         $c->add(StudentCoursePeer::STUDENT_ID, $stu->getId());
         $c->add(StudentCoursePeer::STATUS, StudentCourse::STATUS_APPROVED);
         $approved_scs = StudentCoursePeer::doSelect($c);
         foreach ($approved_scs as $asc) {
             $asc->setStatus(StudentCourse::STATUS_ACTIVE);
             $asc->save();
         }
     }
     // change student status to active
     if ($this->hasRequestParameter('status[student]') && $this->getRequestParameter('status[student]') == Student::STATUS_ACTIVE) {
         $stu->setStatus(Student::STATUS_ACTIVE);
         $stu->setAcademicCalendarId($accal->getId());
         $stu->save();
     }
     return $this->redirect('student_course/list?student_id=' . $stu->getId());
 }
Exemplo n.º 10
0
 public function executeSaveElse()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     $student = StudentPeer::retrieveByPk($this->getRequestParameter('student_id'));
     $this->forward404Unless($student);
     $payment_journal = PaymentJournalPeer::retrieveByPk($this->getRequestParameter('id'));
     $this->forward404Unless($payment_journal);
     $is_new = false;
     $amount_changed = $this->getRequestParameter('paid');
     $payment_journal->setId($this->getRequestParameter('id'));
     $payment_journal->setPayer($student->getId());
     $payment_journal->setAcademicCostId($this->getRequestParameter('academic_cost_id'));
     $ac_cost = AcademicCostPeer::retrieveByPK($this->getRequestParameter('academic_cost_id'));
     $payment_journal->setAcademicProcessId($ac_cost->getAcademicProcessId());
     $payment_journal->setMonth($this->getRequestParameter('month'));
     $payment_journal->setYear($this->getRequestParameter('year'));
     $payment_journal->setAmount($this->getRequestParameter('amount'));
     $payment_journal->setPaid($this->getRequestParameter('paid1') + $this->getRequestParameter('paid'));
     $payment_journal->setReceivable($this->getRequestParameter('receivable'));
     $payment_journal->setStatus($this->getRequestParameter('status'));
     $payment_journal->setComments($this->getRequestParameter('comments'));
     $payment_journal->setPaidAt($this->getRequestParameter('paid_at'));
     $payment_journal->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT);
     $payment_journal->setPaymentModelId($this->getRequestParameter('payment_model_id'));
     $payment_journal->save();
     if ($amount_changed != 0) {
         $ph = new PaymentHistory();
         $ph->setPaymentJournal($payment_journal);
         $ph->setAmount($amount_changed);
         $ph->setReceivable($payment_journal->getReceivable());
         $ph->setStatus($payment_journal->getStatus());
         $ph->setAcademicCostId($payment_journal->getAcademicCostId());
         $ph->setMonth($payment_journal->getMonth());
         $ph->setCredit($payment_journal->getMonth());
         $ph->save();
     }
     return $this->redirect('student_payment/listElse?student_id=' . $student->getId());
 }
Exemplo n.º 11
0
 private function getPaymentHistory($clientId)
 {
     $paymentHistory = new PaymentHistory();
     return $paymentHistory->findPaymentForClient($clientId);
 }
Exemplo n.º 12
0
 public function executeUpdate()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     if ($action_type == $action_i18n || !$this->getRequestParameter('id')) {
         $grad_ceremony = new GradCeremony();
     } else {
         $grad_ceremony = GradCeremonyPeer::retrieveByPk($this->getRequestParameter('id'));
         $this->forward404Unless($grad_ceremony);
     }
     $old_status = $grad_ceremony->getStatus();
     $grad_ceremony->setId($this->getRequestParameter('id'));
     $grad_ceremony->setStudentId($this->getRequestParameter('student_id'));
     $grad_ceremony->setAcademicCalendarId($this->getRequestParameter('academic_calendar_id'));
     $grad_ceremony->setStatus($this->getRequestParameter('status'));
     $grad_ceremony->save();
     if ($grad_ceremony->getStatus() != $old_status && $grad_ceremony->getStatus() == GradCeremony::STATUS_ENROLLED) {
         // add payment journal
         $job = JobPeer::retrieveByCode($this->getModuleName());
         $academic_process = $job->getAcademicProcess();
         $c = new Criteria();
         $c->add(AcademicCostPeer::ACADEMIC_PROCESS_ID, $academic_process->getId());
         $c->add(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $grad_ceremony->getAcademicCalendarId());
         $costs = AcademicCostPeer::doSelect($c);
         foreach ($costs as $c) {
             $pj = new PaymentJournal();
             $pj->setPayer($grad_ceremony->getStudent()->getId());
             $pj->setAcademicCost($c);
             $pj->setJob($job);
             $pj->setAmount($c->getAmount());
             $pj->setPaid($c->getAmount());
             $pj->setReceivable(0);
             $pj->setAcademicProcess($academic_process);
             $pj->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT);
             $pj->save();
             $ph = new PaymentHistory();
             $ph->setPaymentJournal($pj);
             $ph->setAmount($pj->getPaid());
             $ph->save();
         }
     }
     return $this->redirect('grad_ceremony/list');
 }
Exemplo n.º 13
0
 public function saveSale($in_sale_id, $items, $payments, $payment_received, $customer_id, $employee_id, $sub_total, $total, $comment, $status = self::sale_complete_status, $discount_amount, $discount_symbol, $gst_amount, $sale_rep_id)
 {
     if (count($items) == 0) {
         return '-1';
     }
     $message = "";
     //Check if invoice already exists
     $model = Sale::model()->findSale($in_sale_id);
     $payment_types = '';
     foreach ($payments as $payment_id => $payment) {
         $payment_types = $payment_types . $payment['payment_type'] . ': ' . $payment['payment_amount'] . '<br />';
     }
     $transaction = Yii::app()->db->beginTransaction();
     try {
         // Transaction Date for Inventory, Payment and sale trans date
         $trans_date = date('Y-m-d H:i:s');
         // Getting Customer Account Info
         $account = Account::model()->getAccountInfo($customer_id);
         $old_total = $this->getOldSaleTotal($in_sale_id);
         //Rolling back the Sale Total of old / previous Sale & Saving Change / Edit Sale into [account receivable] table
         if ($account && $in_sale_id) {
             AccountReceivable::model()->saveAccountRecv($account->id, $employee_id, $in_sale_id, -$old_total, $trans_date, 'Edit Sale', 'CHASALE', 'R');
             Account::model()->withdrawAccountBal($account, $old_total);
         }
         //Saving existing Sale Item to Inventory table and removing it out
         $this->updateSale($in_sale_id, $employee_id, $trans_date);
         $model->client_id = $customer_id;
         $model->employee_id = $employee_id;
         $model->payment_type = $payment_types;
         $model->remark = $comment;
         $model->sub_total = $sub_total;
         $model->status = $status;
         $model->discount_amount = $discount_amount === null ? 0 : $discount_amount;
         $model->discount_type = $discount_symbol === null ? '%' : $discount_symbol;
         $model->vat = $gst_amount == null ? 0 : $gst_amount;
         $model->salerep_id = $sale_rep_id;
         if ($model->save()) {
             $sale_id = $model->id;
             $date_paid = $trans_date;
             $trans_code = 'CHSALE';
             $trans_status = $total > 0 ? 'N' : 'R';
             // If Return Sale Transaction Type = 'CHSALE' same but Transaction Status = 'R' reverse
             // Saving Sale Item (Sale & Sale Item gotta save firstly even for Suspended Sale)
             $this->saveSaleItem($items, $sale_id, $employee_id);
             // We only save Sale Payment, Account Receivable transaction and update Account (outstanding balance) of completed sale transaction
             if ($status == self::sale_complete_status) {
                 //$account = Account::model()->getAccountInfo($customer_id);
                 if ($account) {
                     // Add hot bill before proceed payment
                     Account::model()->depositAccountBal($account, $total);
                     SalePayment::model()->batchPayment($customer_id, $employee_id, $account, $payment_received, $date_paid, $comment);
                     //Saving Account Receivable for Sale transaction code = 'CHSALE'
                     AccountReceivable::model()->saveAccountRecv($account->id, $employee_id, $sale_id, $total, $trans_date, $comment, $trans_code, $trans_status);
                 } else {
                     // If no customer selected only Sale Payment History
                     PaymentHistory::model()->savePaymentHistory($customer_id, $payment_received, $date_paid, $employee_id, $comment);
                 }
             }
             $message = $sale_id;
             $transaction->commit();
         }
     } catch (Exception $e) {
         $transaction->rollback();
         $message = '-1' . $e->getMessage();
     }
     return $message;
 }
Exemplo n.º 14
0
 public function storeStudent()
 {
     $cre = ["first_group" => Input::get('first_group'), 'name' => Input::get('name'), 'dob' => Input::get('dob'), 'gender' => Input::get('gender'), 'father_name' => Input::get('father_name'), 'month_plan' => Input::get('month_plan'), 'dor' => Input::get('dor'), 'doe' => Input::get('doe'), 'dos' => Input::get('dos')];
     $rules = ["first_group" => 'required', 'name' => 'required', 'dob' => 'required', 'gender' => 'required', 'father_name' => 'required', 'month_plan' => 'required', 'dor' => 'required', 'doe' => 'required', 'dos' => 'required'];
     $validator = Validator::make($cre, $rules);
     if ($validator->passes()) {
         $student = new Student();
         $student->name = Input::get('name');
         $student->dob = Input::get('dob');
         $student->gender = Input::get('gender');
         $student->first_group = Input::get('first_group');
         $student->dos = Input::get('dos');
         $student->doe = Input::get('doe');
         $student->added_by = Auth::User()->id;
         $student->add_date = strtotime("now");
         $student->save();
         $student_details = new StudentDetails();
         $student_details->student_id = $student->id;
         $student_details->school = Input::get('school_name');
         $student_details->status_email = Input::get('status_email');
         $student_details->status_mob = Input::get('status_mob');
         $student_details->father = Input::get('father_name');
         $student_details->mother = Input::get('mother');
         $student_details->father_mob = Input::get('father_mob');
         $student_details->father_email = Input::get('father_email');
         $student_details->mother_mob = Input::get('mother_mob');
         $student_details->mother_email = Input::get('mother_email');
         $student_details->address = Input::get('address');
         $student_details->city = Input::get('city');
         $student_details->state = Input::get('state');
         if (Input::hasFile('picture')) {
             $picture = Input::file('picture');
             $filename = Input::file('picture')->getClientOriginalName();
             Input::file('picture')->move('uploads/', 'st_' . $filename);
             $student_details->pic = 'st_' . $filename;
         }
         $student_details->father_status_email = Input::get('father_status_email');
         $student_details->father_status_mob = Input::get('father_status_mob');
         $student_details->mother_status_mob = Input::get('mother_status_mob');
         $student_details->mother_status_email = Input::get('mother_status_email');
         $student_details->save();
         $payment = new PaymentHistory();
         $payment->student_id = $student->id;
         $payment->dos = Input::get('dos');
         $payment->dor = Input::get('dor');
         $payment->doe = Input::get('doe');
         $payment->reg_fee = Input::get('reg_fee');
         $payment->sub_fee = Input::get('sub_fee');
         $payment->kit_fee = Input::get('kit_fee');
         $payment->amount = Input::get('amount');
         $payment->months = Input::get('month_plan');
         $payment->adjustment = Input::get('adjustment');
         $payment->p_remark = Input::get('p_remark');
         $payment->a_remark = Input::get('a_remark');
         $payment->date = strtotime("now");
         $payment->payment_mode = Input::get('payment_mode');
         $payment->save();
         return Redirect::Back()->with('success', 'New Student Added Successfully');
     }
     return "error";
 }
Exemplo n.º 15
0
 public function executeUpdate()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     $amount_changed = 0;
     if ($action_type == $action_i18n || !$this->getRequestParameter('id')) {
         $payment = new PaymentJournal();
         $amount_changed = $this->getRequestParameter('paid');
     } else {
         $payment = PaymentJournalPeer::retrieveByPk($this->getRequestParameter('id'));
         $this->forward404Unless($payment);
         $is_new = false;
         $amount_changed = $this->getRequestParameter('paid') - $payment->getPaid();
     }
     $payment->setId($this->getRequestParameter('id'));
     $payment->setPayer($this->getRequestParameter('payer'));
     $payment->setAcademicCostId($this->getRequestParameter('academic_cost_id'));
     $payment->setJobId($this->getRequestParameter('job_id'));
     $ac_cost = AcademicCostPeer::retrieveByPK($this->getRequestParameter('academic_cost_id'));
     $payment->setAcademicProcessId($ac_cost->getAcademicProcessId());
     $payment->setAmount($this->getRequestParameter('amount'));
     $payment->setPaid($this->getRequestParameter('paid'));
     $payment->setReceivable($this->getRequestParameter('amount') - $this->getRequestParameter('paid'));
     $payment->setStatus($this->getRequestParameter('status'));
     $payment->setComments($this->getRequestParameter('comments'));
     $payment->setPaidAt($this->getRequestParameter('paid_at'));
     $payment->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT);
     /*		
     if ($this->getRequestParameter('amount')-$this->getRequestParameter('paid') == 0) {
     	$payment->setStatus('S');
     } elseif ($this->getRequestParameter('amount')-$this->getRequestParameter('paid') > 0) {
     	$payment->setStatus('M');
     } elseif ($this->getRequestParameter('amount')-$this->getRequestParameter('paid') < 0) {
     	$payment->setStatus('P');
     } 
     */
     $payment->save();
     if ($amount_changed != 0) {
         $ph = new PaymentHistory();
         $ph->setPaymentJournal($payment);
         $ph->setAmount($amount_changed);
         $ph->save();
     }
     return $this->redirect('payment/list');
 }
Exemplo n.º 16
0
 public function batchPayment($client_id, $employee_id, $account, $total_paid, $paid_date, $note)
 {
     $sql = "SELECT s.id sale_id,s.`sale_time`,CONCAT(c.first_name,' ',c.last_name) client_name\n              ,(s.total - IFNULL(sp.payment_amount,0)) amount_to_paid\n            FROM v_sale s JOIN `client` c ON s.`client_id` = c.id AND c.id=:client_id\n                    LEFT JOIN v_sale_payment sp ON sp.sale_id=s.id\n            WHERE s.status=:status\n            AND (s.total - IFNULL(sp.payment_amount,0))>0\n            ORDER BY sale_time";
     $result = Yii::app()->db->createCommand($sql)->queryAll(true, array(':client_id' => $client_id, ':status' => $this->_sale_completed));
     $paid_amount = $total_paid;
     $trans_code = 'PAY';
     $trans_status = $total_paid > 0 ? 'N' : 'R';
     // If [Payment Amount] > 0 then Paid else Return to Customer
     $payment_id = PaymentHistory::model()->savePaymentHistory($client_id, $total_paid, $paid_date, $employee_id, $note);
     if ($payment_id != 0) {
         foreach ($result as $record) {
             if ($paid_amount <= $record["amount_to_paid"]) {
                 $payment_amount = $paid_amount;
                 $this->saveSalePayment($record["sale_id"], $payment_id, $payment_amount, $paid_date, $note);
                 AccountReceivable::model()->saveAccountRecv($account->id, $employee_id, $record["sale_id"], -$payment_amount, $paid_date, $note, $trans_code, $trans_status);
                 break;
             } else {
                 $paid_amount = $paid_amount - $record["amount_to_paid"];
                 $payment_amount = $record["amount_to_paid"];
                 $this->saveSalePayment($record["sale_id"], $payment_id, $payment_amount, $paid_date, $note);
                 AccountReceivable::model()->saveAccountRecv($account->id, $employee_id, $record["sale_id"], -$payment_amount, $paid_date, $note, $trans_code, $trans_status);
             }
         }
         Account::model()->withdrawAccountBal($account, $total_paid);
     }
     $message = $payment_id;
     return $message;
 }