/**
  * Delete a customer record
  */
 public function deleteAction()
 {
     $customersTable = new Customers();
     $customer = $customersTable->find($this->_getParam('id'))->current();
     !is_null($customer) && $customer->delete();
     $this->_redirect('/customers');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $validator = Validator::make(Input::all(), Customers::$rules);
     if ($validator->passes()) {
         $customer = Customers::find($id);
         $customer->name = Input::get('name');
         $customer->address = Input::get('address');
         $customer->contact = Input::get('contact');
         $customer->save();
         return Redirect::route('customers.index')->with('success', 'Customer updated successfully');
     } else {
         return Redirect::route('customers.edit', $id)->withErrors($validator)->withInput(Input::all());
     }
 }
Beispiel #3
0
 static function addSchedule($inputs)
 {
     $introVisit = new IntroVisit();
     $introVisit['customer_id'] = $inputs['customerId'];
     $introVisit->student_id = $inputs['studentIdIntroVisit'];
     $introVisit->class_id = $inputs['eligibleClassesCbx'];
     $introVisit->batch_id = $inputs['introbatchCbx'];
     //$introVisit->status             = 'ACTIVE/SCHEDULED';
     $introVisit->franchisee_id = Session::get('franchiseId');
     $introVisit->iv_date = date('Y-m-d', strtotime($inputs['introVisitTxtBox']));
     $introVisit->created_by = Session::get('userId');
     $introVisit->created_at = date("Y-m-d H:i:s");
     $introVisit->save();
     $customerObj = Customers::find($inputs['customerId']);
     if ($customerObj) {
         $customerObj->stage = "IV SCHEDULED";
         $customerObj->save();
     }
     return $introVisit;
 }
Beispiel #4
0
 public function insert($params)
 {
     $this->authenticate();
     $form = new Api_Form_CustomerForm(array('action' => '#', 'method' => 'post'));
     #Add email validator
     $mailValidator = new Shineisp_Validate_Email();
     $form->getElement('email')->addValidator($mailValidator);
     $form->addElement('password', 'password', array('filters' => array('StringTrim'), 'required' => true, 'decorators' => array('Composite'), 'validators' => array(array('regex', false, '/^[a-zA-Z0-9\\-\\_\\.\\%\\!\\$]{6,20}$/')), 'description' => 'Write here your password. (min.6 chars - max.20 chars)', 'label' => 'Password', 'class' => 'text-input large-input'));
     if (array_key_exists('countrycode', $params)) {
         $country_id = Countries::getIDbyCode($params['countrycode']);
         if ($country_id == null) {
             throw new Shineisp_Api_Exceptions(400005, ":: 'countrycode' not valid");
             exit;
         }
         unset($params['coutrycode']);
         $params['country_id'] = $country_id;
     }
     if (array_key_exists('provincecode', $params) && $params['provincecode'] != "") {
         $params['area'] = $params['provincecode'];
         unset($params['provincecode']);
     }
     if ($form->isValid($params)) {
         if ($params['status'] == false) {
             $params['status'] = 'disabled';
         }
         $idcustomers = Customers::Create($params);
         $customer = Customers::find($idcustomers);
         return $customer['uuid'];
     } else {
         $errors = $form->getMessages();
         $message = "";
         foreach ($errors as $field => $errorsField) {
             $message .= "Field '{$field}'<br/>";
             foreach ($errorsField as $error => $describe) {
                 $message .= " => {$error} ({$describe})";
             }
         }
         throw new Shineisp_Api_Exceptions(400004, ":\n{$message}");
         exit;
     }
 }
Beispiel #5
0
 static function saveCustomers($inputs)
 {
     $customer = Customers::find($inputs['customerId']);
     $customer->franchisee_id = Session::get('franchiseId');
     $customer->customer_name = $inputs['customerName'];
     $customer->customer_lastname = $inputs['customerLastName'];
     $customer->customer_email = $inputs['customerEmail'];
     $customer->mobile_no = $inputs['customerMobile'];
     $customer->building = $inputs['building'];
     $customer->apartment_name = $inputs['apartment'];
     $customer->lane = $inputs['lane'];
     $customer->locality = $inputs['locality'];
     if ($inputs['state'] == '') {
         $customer->state = 0;
     } else {
         $customer->state = $inputs['state'];
     }
     if (isset($inputs['city'])) {
         if ($inputs['city'] == '') {
             $customer->city = 0;
         } else {
             $customer->city = $inputs['city'];
         }
     }
     $customer->zipcode = $inputs['zipcode'];
     $customer->source = $inputs['source'];
     //$customer->stage          = 'inquire';
     $customer->referred_by = $inputs['referredBy'];
     $customer->created_by = Session::get('userId');
     $customer->updated_at = date("Y-m-d H:i:s");
     /* if(isset($inputs['eventsId']) && $inputs['eventsId'] != ""){
     		
     		$customer->source_event     = $inputs['eventsId'];
     		
     		} */
     $customer->save();
     return $customer;
 }
Beispiel #6
0
 public function insert($params)
 {
     $this->authenticate();
     $form = new Api_Form_CustomerForm(array('action' => '#', 'method' => 'post'));
     if (array_key_exists('countrycode', $params)) {
         $country_id = Countries::getIDbyCode($params['countrycode']);
         if ($country_id == null) {
             throw new Shineisp_Api_Exceptions(400005, ":: 'countrycode' not valid");
             exit;
         }
         unset($params['coutrycode']);
         $params['country_id'] = $country_id;
     }
     if (array_key_exists('provincecode', $params) && $params['provincecode'] != "") {
         $params['area'] = $params['provincecode'];
         unset($params['provincecode']);
     }
     if ($form->isValid($params)) {
         if ($params['status'] == false) {
             $params['status'] = 'disabled';
         }
         $idcustomers = Customers::Create($params);
         $customer = Customers::find($idcustomers);
         return $customer['uuid'];
     } else {
         $errors = $form->getMessages();
         $message = "";
         foreach ($errors as $field => $errorsField) {
             $message .= "Field '{$field}'<br/>";
             foreach ($errorsField as $error => $describe) {
                 $message .= " => {$error} ({$describe})";
             }
         }
         throw new Shineisp_Api_Exceptions(400004, ":\n{$message}");
         exit;
     }
 }
Beispiel #7
0
 public function create($params)
 {
     $this->authenticate();
     $uuid = $params['uuid'];
     $customers = Customers::find($uuid);
     if (empty($customers)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid");
         exit;
     }
     $trancheid = intval($params['trancheid']);
     $tranche = ProductsTranches::getTranchebyId($trancheid);
     if (empty($tranche)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'trancheid' not valid");
         exit;
     }
     #Check Products
     if (empty($params['products']) && !is_array($params['products'])) {
         throw new Shineisp_Api_Exceptions(400006, ":: not 'products' choose");
         exit;
     }
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $ttry = ProductsTranches::getTranchesBy_ProductId_BillingId($productid, $billingid);
         if (empty($ttry)) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'productid' or 'bilingid' not valid");
             exit;
         }
         $ttry = array_shift($ttry);
         if ($ttry['tranche_id'] != $trancheid) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'bilingid' not valid");
             exit;
         }
     }
     $id = $customers['customer_id'];
     $isVATFree = Customers::isVATFree($id);
     if ($params['status'] == "complete") {
         $status = Statuses::id('complete', 'orders');
     } else {
         $status = Statuses::id('tobepaid', 'orders');
     }
     $theOrder = Orders::create($customers['customer_id'], $status, $params['note']);
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $quantity = intval($product['quantity']);
         $p = Products::getAllInfo($productid);
         Orders::addItem($productid, $quantity, $billingid, $trancheid, $p['ProductsData'][0]['name'], array());
     }
     $orderID = $theOrder['order_id'];
     if ($params['sendemail'] == 1) {
         Orders::sendOrder($orderID);
     }
     $banks = Banks::find($params['payment'], "*", true);
     if (!empty($banks[0]['classname'])) {
         $class = $banks[0]['classname'];
         if (class_exists($class)) {
             // Get the payment form object
             $banks = Banks::findbyClassname($class);
             $gateway = new $class($orderID);
             $gateway->setFormHidden(true);
             $gateway->setRedirect(true);
             $gateway->setUrlOk($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlKo($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlCallback($_SERVER['HTTP_HOST'] . "/common/callback/gateway/" . md5($banks['classname']));
             return $gateway->CreateForm();
         }
     }
     throw new Shineisp_Api_Exceptions(400006, ":: bad request");
     exit;
 }
 public function actionUpdatekat($id)
 {
     $readonly = Customers::find()->where(['CUST_KD' => $id])->asArray()->one();
     // data for view
     $model = $this->findModelcust($id);
     $model->scenario = "updatekat";
     $dropparentkategori = ArrayHelper::map(Kategoricus::find()->where('CUST_KTG_PARENT = CUST_KTG')->asArray()->all(), 'CUST_KTG', 'CUST_KTG_NM');
     if ($model->load(Yii::$app->request->post())) {
         $tanggal = \Yii::$app->formatter->asDate($model->JOIN_DATE, 'Y-M-d');
         $model->JOIN_DATE = $tanggal;
         if ($model->validate()) {
             $model->UPDATED_AT = date("Y-m-d H:i:s");
             $model->UPDATED_BY = Yii::$app->user->identity->username;
             if ($model->save()) {
                 echo 1;
             } else {
                 echo 0;
             }
         }
         //  return $this->redirect(['index']);
     } else {
         return $this->renderAjax('type', ['model' => $model, 'dropparentkategori' => $dropparentkategori, 'readonly' => $readonly]);
     }
 }
Beispiel #9
0
 public function getCustomerList()
 {
     $customers = Customers::find()->where(['user_id' => Yii::$app->user->id])->all();
     return ArrayHelper::map($customers, 'id', 'name');
 }
Beispiel #10
0
 public function linkAction()
 {
     $request = $this->getRequest();
     $NS = new Zend_Session_Namespace('Default');
     try {
         $code = $request->getParam('id');
         $link = Fastlinks::findbyCode($code);
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('default'));
         if (!empty($link[0]['controller'])) {
             $customer = Customers::find($link[0]['customer_id']);
             //TODO: GUEST - ALE - 20130516: remove access for disabled customers
             if (isset($customer) && in_array($customer['status_id'], array(Statuses::id("active", "customers"), Statuses::id("disabled", "customers")))) {
                 $NS->customer = $customer;
                 Fastlinks::updateVisits($link[0]['fastlink_id']);
                 $this->_helper->redirector($link[0]['action'], $link[0]['controller'], 'default', json_decode($link[0]['params'], true));
             } else {
                 header('location: /customer/login');
                 die;
             }
         } else {
             header('location: /customer/login');
             die;
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         die;
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update($id)
 {
     $validator = Validator::make(Input::all(), Sales::$rules);
     if ($validator->passes()) {
         $customerId = Input::get('customer_id', null);
         // Create customer if required
         $customer = new Customers();
         if ($customerId) {
             $customer = Customers::find($customerId);
         }
         if (Input::get('name')) {
             $customer->name = Input::get('name');
             $customer->address = Input::get('address');
             $customer->contact = Input::get('contact');
             $customer->save();
         }
         $sale = Sales::find($id);
         $sale->customer_id = $customer->id ? $customer->id : 0;
         $sale->outlet_id = $this->user->outlet_id;
         $sale->paid = Input::get('paid');
         $sale->notes = Input::get('notes');
         $sale->status = Input::get('paid') == Input::get('grandtotal') ? 'completed' : 'credit';
         $sale->save();
         return Redirect::route('sales.edit', $id)->with('success', 'Sale updated successfully');
     } else {
         return Redirect::route('sales.edit', $id)->withErrors($validator)->withInput(Input::all());
     }
 }
Beispiel #12
0
 /**
  * ownerGrid
  * Get the customer/owner information.
  * @return array
  */
 private function ownerGrid($customerid)
 {
     if (is_numeric($customerid)) {
         $customer = Customers::find($customerid, 'company, firstname, lastname, email');
         if (isset($customer)) {
             return array('records' => array($customer), 'editpage' => 'customers');
         }
     }
 }
Beispiel #13
0
 public function enrollKid()
 {
     $inputs = Input::all();
     $batch_data = Batches::find($inputs['batchCbx']);
     $eachClassCost = $batch_data->class_amount;
     //return Response::json(array('status'=>$inputs));
     //$inputs['discountPercentage']=$inputs['discountP'];
     $studentClasses['classId'] = $inputs['eligibleClassesCbx'];
     $studentClasses['batchId'] = $inputs['batchCbx'];
     $studentClasses['studentId'] = $inputs['studentId'];
     $season_data = Seasons::find($inputs['SeasonsCbx']);
     //$inputs['enrollmentEndDate']=$season_data->end_date;
     //$studentClasses['enrollment_start_date'] = date('Y-m-d', strtotime($inputs['enrollmentStartDate']));
     //return Response::json(array('status'=>'working'));
     //$studentClasses['enrollment_end_date']   = date('Y-m-d', strtotime($inputs['enrollmentEndDate']));
     $studentClasses['selected_sessions'] = $inputs['selectedSessions'];
     $studentClasses['seasonId'] = $inputs['SeasonsCbx'];
     //for proper enrollment start date and end date
     $end = Carbon::now();
     $start = Carbon::now();
     $start->year = date('Y', strtotime($inputs['enrollmentStartDate']));
     $start->month = date('m', strtotime($inputs['enrollmentStartDate']));
     $start->day = date('d', strtotime($inputs['enrollmentStartDate']));
     $end->year = date('Y', strtotime($inputs['enrollmentEndDate']));
     $end->month = date('m', strtotime($inputs['enrollmentEndDate']));
     $end->day = date('d', strtotime($inputs['enrollmentEndDate']));
     $batch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $start->toDateString())->where('schedule_date', '<=', $end->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
     $studentClasses['enrollment_start_date'] = $batch_data[0]['schedule_date'];
     $studentClasses['enrollment_end_date'] = $batch_data[count($batch_data) - 1]['schedule_date'];
     //Batch Start date
     $BatchDetails = Batches::where('id', '=', $inputs['batchCbx'])->first();
     $reminderStartDate = $BatchDetails->start_date;
     $enrollment = StudentClasses::addStudentClass($studentClasses);
     $paymentDuesInput['student_id'] = $inputs['studentId'];
     $paymentDuesInput['customer_id'] = $inputs['customerId'];
     $paymentDuesInput['batch_id'] = $inputs['batchCbx'];
     $paymentDuesInput['class_id'] = $inputs['eligibleClassesCbx'];
     $paymentDuesInput['selected_sessions'] = $inputs['selectedSessions'];
     $paymentDuesInput['seasonId'] = $inputs['SeasonsCbx'];
     $paymentDuesInput['each_class_cost'] = $eachClassCost;
     $order['customer_id'] = $inputs['customerId'];
     $order['student_id'] = $inputs['studentId'];
     $order['seasonId'] = $inputs['SeasonsCbx'];
     $order['student_classes_id'] = $enrollment->id;
     $order['payment_mode'] = $inputs['paymentTypeRadio'];
     $order['payment_for'] = "enrollment";
     $order['card_last_digit'] = $inputs['card4digits'];
     $order['card_type'] = $inputs['cardType'];
     $order['bank_name'] = $inputs['bankName'];
     $order['cheque_number'] = $inputs['chequeNumber'];
     //$order['each_class_cost']   =$eachClassCost;
     if (isset($inputs['membershipType'])) {
         $order['membershipType'] = $inputs['membershipType'];
     }
     $paydue_id;
     if ($inputs['paymentOptionsRadio'] == 'singlepay') {
         // for starting and end date of enrollment
         $enddate = Carbon::now();
         $startdate = Carbon::now();
         $startdate->year = date('Y', strtotime($inputs['enrollmentStartDate']));
         $startdate->month = date('m', strtotime($inputs['enrollmentStartDate']));
         $startdate->day = date('d', strtotime($inputs['enrollmentStartDate']));
         $enddate->year = date('Y', strtotime($inputs['enrollmentEndDate']));
         $enddate->month = date('m', strtotime($inputs['enrollmentEndDate']));
         $enddate->day = date('d', strtotime($inputs['enrollmentEndDate']));
         $batch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $startdate->toDateString())->where('schedule_date', '<=', $enddate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
         $paymentDuesInput['start_order_date'] = $batch_data[0]['schedule_date'];
         $paymentDuesInput['end_order_date'] = $batch_data[count($batch_data) - 1]['schedule_date'];
         $paymentDuesInput['payment_due_amount'] = $inputs['singlePayAmount'];
         $paymentDuesInput['payment_type'] = $inputs['paymentOptionsRadio'];
         $paymentDuesInput['payment_status'] = "paid";
         $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
         $paymentDuesInput['student_class_id'] = $enrollment->id;
         $paymentDuesInput['selected_order_sessions'] = $inputs['selectedSessions'];
         //$paymentDuesInput['start_order_date']=$studentClasses['enrollment_start_date'];
         //$paymentDuesInput['end_order_date']=$studentClasses['enrollment_end_date'];
         $paymentDuesInput['discount_amount'] = $inputs['discountPercentage'] / 100 * $inputs['singlePayAmount'];
         $order['amount'] = $inputs['singlePayAmount'];
         if ($inputs['CustomerType'] == 'OldCustomer') {
             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
             $order['created_at'] = $paymentDuesInput['created_at'];
         }
         $paymentDuesResult = PaymentDues::createPaymentDues($paymentDuesInput);
         $order['payment_dues_id'] = $paymentDuesResult->id;
         $order['order_status'] = "completed";
         if ($inputs['selectedSessions'] > 8) {
             // creating followup for the single pay
             $presentDate = Carbon::now();
             $startdate = Carbon::now();
             $startdate->year = date('Y', strtotime($inputs['enrollmentStartDate']));
             $startdate->month = date('m', strtotime($inputs['enrollmentStartDate']));
             $startdate->day = date('d', strtotime($inputs['enrollmentStartDate']));
             $batch_schedule_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $startdate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
             $session_number = (int) ($inputs['selectedSessions'] / 2);
             $reminder_date = $batch_schedule_data[$session_number]['schedule_date'];
             $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
             $customer_log_data['student_id'] = $paymentDuesResult->student_id;
             $customer_log_data['franchisee_id'] = Session::get('franchiseId');
             $customer_log_data['followup_type'] = 'PAYMENT';
             $customer_log_data['followup_status'] = 'REMINDER_CALL';
             $customer_log_data['comment_type'] = 'VERYINTERESTED';
             $customer_log_data['reminderDate'] = $reminder_date;
             $remindDate = Carbon::now();
             $remindDate = $remindDate->createFromFormat('Y-m-d', $reminder_date);
             if ($remindDate->gt($presentDate)) {
                 $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                 $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                 Comments::addSinglePayComment($customer_log_data);
             }
         }
     } else {
         if ($inputs['paymentOptionsRadio'] == 'multipay') {
             $today = Carbon::now();
             $paymentDuesInput['payment_type'] = $inputs['paymentOptionsRadio'];
             for ($i = 1; $i <= 4; $i++) {
                 if (isset($inputs['multipayAmount' . $i])) {
                     $firstBrushupCallReminderDate;
                     $firstInitialPaymentCallReminderDate;
                     $firstFinalPaymentCallReminderDate;
                     if ($i == 1) {
                         $paymentDuesInput['payment_status'] = "paid";
                         $order['amount'] = $inputs['multipayAmount' . $i];
                         $enddate = Carbon::now();
                         $startdate = Carbon::now();
                         $startdate->year = date('Y', strtotime($inputs['enrollmentStartDate']));
                         $startdate->month = date('m', strtotime($inputs['enrollmentStartDate']));
                         $startdate->day = date('d', strtotime($inputs['enrollmentStartDate']));
                         $enddate->year = date('Y', strtotime($inputs['enrollmentEndDate']));
                         $enddate->month = date('m', strtotime($inputs['enrollmentEndDate']));
                         $enddate->day = date('d', strtotime($inputs['enrollmentEndDate']));
                         $batch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $startdate->toDateString())->where('schedule_date', '<=', $enddate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                         $paymentDuesInput['start_order_date'] = $batch_data[0]['schedule_date'];
                         $endorderdate = $batch_data[count($batch_data) - 1]['schedule_date'];
                         //$paymentDuesInput['start_order_date']=$studentClasses['enrollment_start_date'];
                         //$startdate=  Carbon::create(date('Y,m,d,0', strtotime($inputs['enrollmentStartDate'])));
                         $startdate = Carbon::now();
                         $startdate->year = date('Y', strtotime($inputs['enrollmentStartDate']));
                         $startdate->month = date('m', strtotime($inputs['enrollmentStartDate']));
                         $startdate->day = date('d', strtotime($inputs['enrollmentStartDate']));
                         $session_no = $inputs['multipayAmount' . $i] / $eachClassCost;
                         $firstSessionNumber = $session_no;
                         $batch_schedule_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $startdate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                         $session_no = $session_no - 1;
                         //$startdate=$startdate->addWeeks(($inputs['bipayAmount'.$i]/500));
                         //$startdate=$startdate->addWeeks(($inputs['multipayAmount'.$i]/500));
                         $paymentDuesInput['end_order_date'] = $batch_schedule_data[$session_no]['schedule_date'];
                         if ($firstSessionNumber >= 6) {
                             $firstBrushupCallReminderDate = $batch_schedule_data[$session_no - 2]['schedule_date'];
                             $firstInitialPaymentCallReminderDate = $batch_schedule_data[$session_no - 1]['schedule_date'];
                             $firstFinalPaymentCallReminderDate = $batch_schedule_data[$session_no]['schedule_date'];
                         } else {
                             $firstFinalPaymentCallReminderDate = $batch_schedule_data[$session_no]['schedule_date'];
                         }
                         $nextstartdate = $batch_schedule_data[$session_no]['schedule_date'];
                         //$paymentDuesInput['end_order_date']=$startdate->toDateString();
                         $paymentDuesInput['discount_amount'] = $inputs['discountPercentage'] / 100 * $inputs['multipayAmount' . $i];
                         if ($inputs['CustomerType'] == 'OldCustomer') {
                             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                             $order['created_at'] = $paymentDuesInput['created_at'];
                         }
                     } else {
                         $paymentDuesInput['start_order_date'] = $nextstartdate;
                         $batch_schedule_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $startdate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                         $session_no = $session_no + $inputs['multipayAmount' . $i] / $eachClassCost;
                         $firstBrushupCallReminderDate = $batch_schedule_data[$session_no - 2]['schedule_date'];
                         $firstInitialPaymentCallReminderDate = $batch_schedule_data[$session_no - 1]['schedule_date'];
                         $firstFinalPaymentCallReminderDate = $batch_schedule_data[$session_no]['schedule_date'];
                         //$startdate=$startdate->addWeeks(($inputs['multipayAmount'.$i]/500));
                         $paymentDuesInput['end_order_date'] = $batch_schedule_data[$session_no]['schedule_date'];
                         if ($i == 4) {
                             //$paymentDuesInput['end_order_date']=date('Y-m-d', strtotime($inputs['enrollmentEndDate']));
                             $paymentDuesInput['end_order_date'] = $endorderdate;
                         }
                         $nextstartdate = $batch_schedule_data[$session_no]['schedule_date'];
                         //$paymentDuesInput['end_order_date']=   $startdate->toDateString();
                         $paymentDuesInput['payment_status'] = "pending";
                         $paymentDuesInput['discount_amount'] = $inputs['discountPercentage'] / 100 * $inputs['multipayAmount' . $i];
                         if ($i == 2 && $inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '') {
                             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate2']));
                             $paymentDuesInput['payment_status'] = "paid";
                         }
                         if ($i == 3 && $inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate3'] != '') {
                             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate3']));
                             $paymentDuesInput['payment_status'] = "paid";
                         }
                         if ($i == 4 && $inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate4'] != '') {
                             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate4']));
                             $paymentDuesInput['payment_status'] = "paid";
                         }
                     }
                     $paymentDuesInput['payment_due_amount'] = $inputs['multipayAmount' . $i];
                     $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                     $paymentDuesInput['selected_order_sessions'] = $inputs['multipayAmount' . $i] / $eachClassCost;
                     $paymentDuesInput['student_class_id'] = $enrollment->id;
                     $paymentDuesResult = PaymentDues::createPaymentDues($paymentDuesInput);
                     if ($i >= 1 && $i <= 3) {
                         if ($i == 1) {
                             if ($firstSessionNumber >= 6) {
                                 $firstremind = Carbon::now();
                                 $firstremind = $firstremind->createFromFormat('Y-m-d', $firstBrushupCallReminderDate);
                                 //return Response::json(array('status'=>$firstBrushupCallReminderDate,'today'=>$today));
                                 if ($firstremind->gt($today)) {
                                     //create 3 payment followup
                                     $payment_followup_data1 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $payment_followup_data2 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $payment_followup_data3 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     //creating logs/followup for first payment
                                     $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                     $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                     $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data1->id;
                                     $customer_log_data['paymentfollowup_id2'] = $payment_followup_data2->id;
                                     $customer_log_data['paymentfollowup_id3'] = $payment_followup_data3->id;
                                     $customer_log_data['followup_type'] = 'PAYMENT';
                                     $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                     $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                     $customer_log_data['firstReminderDate'] = $firstBrushupCallReminderDate;
                                     $customer_log_data['secondReminderDate'] = $firstInitialPaymentCallReminderDate;
                                     $customer_log_data['thirdReminderDate'] = $firstFinalPaymentCallReminderDate;
                                     Comments::addPaymentComments($customer_log_data);
                                 } else {
                                     $final_remind = Carbon::now();
                                     $final_remind = $final_remind->createFromFormat('Y-m-d', $firstFinalPaymentCallReminderDate);
                                     if ($final_remind->gt($today)) {
                                         $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                         $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                         $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                         $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                         $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                         //$customer_log_data['paymentfollowup_id2']=$payment_followup_data2->id;
                                         //$customer_log_data['paymentfollowup_id3']=$payment_followup_data3->id;
                                         $customer_log_data['followup_type'] = 'PAYMENT';
                                         $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                         $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                         //  $customer_log_data['firstReminderDate']=$firstBrushupCallReminderDate;
                                         //  $customer_log_data['secondReminderDate']=$firstInitialPaymentCallReminderDate;
                                         $customer_log_data['reminderDate'] = $firstFinalPaymentCallReminderDate;
                                         Comments::addOnebiPaymentComment($customer_log_data);
                                     }
                                 }
                             } else {
                                 $final_r = Carbon::now();
                                 $final_r = $final_r->createFromFormat('Y-m-d', $firstFinalPaymentCallReminderDate);
                                 if ($final_r->gt($today)) {
                                     //create 1 followup
                                     $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                     $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                     $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                     //$customer_log_data['paymentfollowup_id2']=$payment_followup_data2->id;
                                     //$customer_log_data['paymentfollowup_id3']=$payment_followup_data3->id;
                                     $customer_log_data['followup_type'] = 'PAYMENT';
                                     $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                     $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                     //  $customer_log_data['firstReminderDate']=$firstBrushupCallReminderDate;
                                     //  $customer_log_data['secondReminderDate']=$firstInitialPaymentCallReminderDate;
                                     $customer_log_data['reminderDate'] = $firstFinalPaymentCallReminderDate;
                                     Comments::addOnebiPaymentComment($customer_log_data);
                                 }
                             }
                         } else {
                             //when i>=3
                             $firstre = Carbon::now();
                             $firstre = $firstre->createFromFormat('Y-m-d', $firstBrushupCallReminderDate);
                             if ($firstre->gt($today)) {
                                 $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                 $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                 $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                 $customer_log_data['followup_type'] = 'PAYMENT';
                                 $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                 $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                 $customer_log_data['firstReminderDate'] = $firstBrushupCallReminderDate;
                                 $customer_log_data['secondReminderDate'] = $firstInitialPaymentCallReminderDate;
                                 $customer_log_data['thirdReminderDate'] = $firstFinalPaymentCallReminderDate;
                                 if ($i == 2 && isset($inputs['multipayAmount3'])) {
                                     $payment_followup_data1 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $payment_followup_data2 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $payment_followup_data3 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data1->id;
                                     $customer_log_data['paymentfollowup_id2'] = $payment_followup_data2->id;
                                     $customer_log_data['paymentfollowup_id3'] = $payment_followup_data3->id;
                                     Comments::addPaymentComments($customer_log_data);
                                 } else {
                                     if ($i == 3 && isset($inputs['multipayAmount4'])) {
                                         $payment_followup_data1 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                         $payment_followup_data2 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                         $payment_followup_data3 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                         $customer_log_data['paymentfollowup_id'] = $payment_followup_data1->id;
                                         $customer_log_data['paymentfollowup_id2'] = $payment_followup_data2->id;
                                         $customer_log_data['paymentfollowup_id3'] = $payment_followup_data3->id;
                                         Comments::addPaymentComments($customer_log_data);
                                     } else {
                                         if ($i != 3 && $i != 2) {
                                             $payment_followup_data1 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                             $payment_followup_data2 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                             $payment_followup_data3 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                             $customer_log_data['paymentfollowup_id'] = $payment_followup_data1->id;
                                             $customer_log_data['paymentfollowup_id2'] = $payment_followup_data2->id;
                                             $customer_log_data['paymentfollowup_id3'] = $payment_followup_data3->id;
                                             Comments::addPaymentComments($customer_log_data);
                                         }
                                     }
                                 }
                             } else {
                                 $final = Carbon::now();
                                 $final = $final->createFromFormat('Y-m-d', $firstFinalPaymentCallReminderDate);
                                 if ($final->gt($today)) {
                                     $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                     $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                     $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                     //$customer_log_data['paymentfollowup_id2']=$payment_followup_data2->id;
                                     //$customer_log_data['paymentfollowup_id3']=$payment_followup_data3->id;
                                     $customer_log_data['followup_type'] = 'PAYMENT';
                                     $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                     $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                     //  $customer_log_data['firstReminderDate']=$firstBrushupCallReminderDate;
                                     //  $customer_log_data['secondReminderDate']=$firstInitialPaymentCallReminderDate;
                                     $customer_log_data['reminderDate'] = $firstFinalPaymentCallReminderDate;
                                     Comments::addOnebiPaymentComment($customer_log_data);
                                 }
                             }
                         }
                     }
                     $paydue_id[] = $paymentDuesResult->id;
                     if ($i == 1) {
                         $order['payment_dues_id'] = $paymentDuesResult->id;
                         $order['order_status'] = "completed";
                     }
                 }
             }
             /*
             			$weeksDues = array("6", "9", "14", "19", "24", "29", "34");
             			$date = date('Y/m/d', strtotime($reminderStartDate));
             			foreach($weeksDues as $weeksDue){
             					
             				$weeks = $weeksDue;
             				// Create and modify the date.
             				$dateTime = DateTime::createFromFormat('Y/m/d', $date);
             				$dateTime->add(DateInterval::createFromDateString($weeks . ' weeks'));
             				//$dateTime->modify('next monday');
             					
             				// Output the new date.
             				//echo $dateTime->format('Y-m-d')."<br>";
             			
             			
             				$paymentReminderInput['customerId']    = $inputs['customerId'];
             				$paymentReminderInput['studentId']     = $inputs['studentId'];
                                             $paymentReminderInput['seasonId']     = $inputs['SeasonsCbx'];
             				$paymentReminderInput['classId']       = $inputs['eligibleClassesCbx'];
             				$paymentReminderInput['batchId']       = $inputs['batchCbx'];
             				$paymentReminderInput['reminder_date'] = $dateTime->format('Y-m-d');
             			
             				PaymentReminders::addReminderDates($paymentReminderInput);
             			
             			
             					
             			}*/
         } else {
             if ($inputs['paymentOptionsRadio'] == 'bipay') {
                 $followupFirstDate;
                 $followupSecondDate;
                 $followupThirdDate;
                 $paymentDuesInput['payment_type'] = $inputs['paymentOptionsRadio'];
                 for ($i = 1; $i <= 2; $i++) {
                     if (isset($inputs['bipayAmount' . $i])) {
                         if ($i == 1) {
                             //for bipay enrollment classes
                             $paymentDuesInput['payment_status'] = "paid";
                             $order['amount'] = $inputs['bipayAmount' . $i];
                             //$paymentDuesInput['start_order_date']=$studentClasses['enrollment_start_date'];
                             //$startdate=  Carbon::create(date('Y,m,d,0', strtotime($inputs['enrollmentStartDate'])));
                             $startdate = Carbon::now();
                             $enddate = Carbon::now();
                             $startdate->year = date('Y', strtotime($inputs['enrollmentStartDate']));
                             $startdate->month = date('m', strtotime($inputs['enrollmentStartDate']));
                             $startdate->day = date('d', strtotime($inputs['enrollmentStartDate']));
                             $enddate->year = date('Y', strtotime($inputs['enrollmentEndDate']));
                             $enddate->month = date('m', strtotime($inputs['enrollmentEndDate']));
                             $enddate->day = date('d', strtotime($inputs['enrollmentEndDate']));
                             //return Response::json(array('status'=>'success'));
                             $session_no = $inputs['bipayAmount' . $i] / $eachClassCost;
                             $firstsessionno = $session_no;
                             $batch_schedule_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $startdate->toDateString())->where('schedule_date', '<=', $enddate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                             $session_no = $session_no - 1;
                             //$startdate=$startdate->addWeeks(($inputs['bipayAmount'.$i]/500));
                             $paymentDuesInput['start_order_date'] = $batch_schedule_data[0]['schedule_date'];
                             $paymentDuesInput['end_order_date'] = $batch_schedule_data[$session_no]['schedule_date'];
                             $endorderdateforbipay = $batch_schedule_data[count($batch_schedule_data) - 1]['schedule_date'];
                             if ($firstsessionno >= 10) {
                                 $followupFirstDate = $batch_schedule_data[$session_no - 2]['schedule_date'];
                                 $followupSecondDate = $batch_schedule_data[$session_no - 1]['schedule_date'];
                                 $followupThirdDate = $batch_schedule_data[$session_no]['schedule_date'];
                             } else {
                                 $followupdate = $batch_schedule_data[$session_no]['schedule_date'];
                             }
                             $paymentDuesInput['discount_amount'] = $inputs['discountPercentage'] / 100 * $inputs['bipayAmount' . $i];
                             if ($inputs['CustomerType'] == 'OldCustomer') {
                                 $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                                 $order['created_at'] = $paymentDuesInput['created_at'];
                             }
                         } else {
                             $paymentDuesInput['start_order_date'] = $batch_schedule_data[$session_no]['schedule_date'];
                             //$startdate=$startdate->addWeeks(($inputs['bipayAmount'.$i]/500));
                             //$paymentDuesInput['end_order_date']=   date('Y-m-d', strtotime($inputs['enrollmentEndDate']));
                             $paymentDuesInput['end_order_date'] = $endorderdateforbipay;
                             $paymentDuesInput['payment_status'] = "pending";
                             $paymentDuesInput['discount_amount'] = $inputs['discountPercentage'] / 100 * $inputs['bipayAmount' . $i];
                             if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '') {
                                 $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate2']));
                                 // $order['created_at']=$paymentDuesInput['created_at'];
                             }
                         }
                         $paymentDuesInput['selected_order_sessions'] = $inputs['bipayAmount' . $i] / $eachClassCost;
                         $paymentDuesInput['payment_due_amount'] = $inputs['bipayAmount' . $i];
                         $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                         $paymentDuesInput['student_class_id'] = $enrollment->id;
                         $paymentDuesResult = PaymentDues::createPaymentDues($paymentDuesInput);
                         if ($i == 1) {
                             $order['payment_dues_id'] = $paymentDuesResult->id;
                             $order['order_status'] = "completed";
                             $paydueid1 = $paymentDuesResult->id;
                         }
                         if ($i == 2) {
                             if ($firstsessionno >= 10) {
                                 // creating customer followup
                                 $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                 $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                 $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                 $paydue_id2 = $paymentDuesResult->id;
                                 $paymentDuesResult->id = $paydueid1;
                                 $customer_log_data['followup_type'] = 'PAYMENT';
                                 $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                 $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                 $customer_log_data['firstReminderDate'] = $followupFirstDate;
                                 $customer_log_data['secondReminderDate'] = $followupSecondDate;
                                 $customer_log_data['thirdReminderDate'] = $followupThirdDate;
                                 $brushupremind = Carbon::now();
                                 $finalremind = Carbon::now();
                                 $brushupremind = $brushupremind->createFromFormat('Y-m-d', $followupFirstDate);
                                 $finalremind = $finalremind->createFromFormat('Y-m-d', $followupThirdDate);
                                 $today = Carbon::now();
                                 if ($brushupremind->gt($today)) {
                                     $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $payment_followup_data2 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $payment_followup_data3 = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                     $customer_log_data['paymentfollowup_id2'] = $payment_followup_data2->id;
                                     $customer_log_data['paymentfollowup_id3'] = $payment_followup_data3->id;
                                     Comments::addPaymentComments($customer_log_data);
                                 } else {
                                     if ($finalremind->gt($today)) {
                                         //create single followup
                                         $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                         $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                         $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                         $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                         $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                         $customer_log_data['followup_type'] = 'PAYMENT';
                                         $customer_log_data['reminderDate'] = $followupThirdDate;
                                         $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                         $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                         Comments::addOnebiPaymentComment($customer_log_data);
                                     }
                                 }
                             } else {
                                 $today = Carbon::now();
                                 $reminddate = Carbon::now();
                                 $reminddate = $reminddate->createFromFormat('Y-m-d', $followupdate);
                                 if ($reminddate->gt($today)) {
                                     $paymentDuesResult->id = $paydueid1;
                                     $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult);
                                     $customer_log_data['customer_id'] = $paymentDuesResult->customer_id;
                                     $customer_log_data['student_id'] = $paymentDuesResult->student_id;
                                     $customer_log_data['franchisee_id'] = Session::get('franchiseId');
                                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                     $customer_log_data['followup_type'] = 'PAYMENT';
                                     $customer_log_data['reminderDate'] = $followupdate;
                                     $customer_log_data['followup_status'] = 'REMINDER_CALL';
                                     $customer_log_data['comment_type'] = 'VERYINTERESTED';
                                     Comments::addOnebiPaymentComment($customer_log_data);
                                 }
                             }
                         }
                     }
                 }
                 // to create payment reminders
                 /*
                 			$weeksDues = array("6", "12", "19", "24", "34");
                 			$date = date('Y/m/d', strtotime($reminderStartDate));
                 			foreach($weeksDues as $weeksDue){
                 					
                 				$weeks = $weeksDue;
                 				// Create and modify the date.
                 				$dateTime = DateTime::createFromFormat('Y/m/d', $date);
                 				$dateTime->add(DateInterval::createFromDateString($weeks . ' weeks'));
                 				//$dateTime->modify('next monday');
                 					
                 				// Output the new date.
                 				//echo $dateTime->format('Y-m-d')."<br>";
                 					
                 					
                 				$paymentReminderInput['customerId']    = $inputs['customerId'];
                 				$paymentReminderInput['studentId']     = $inputs['studentId'];
                        $paymentDuesInput['seasonId']             =$inputs['SeasonsCbx'];
                 				$paymentReminderInput['classId']       = $inputs['eligibleClassesCbx'];
                 				$paymentReminderInput['batchId']       = $inputs['batchCbx'];
                        $paymentReminderInput['seasonId']       =$inputs['SeasonsCbx'];
                        $paymentDuesInput['seasonId']          = $inputs['SeasonsCbx'];
                 				$paymentReminderInput['reminder_date'] = $dateTime->format('Y-m-d');
                 					
                 				PaymentReminders::addReminderDates($paymentReminderInput);
                 					
                 					
                 					
                 			}
                 * 
                 */
                 //payment reminders for followups.
                 if ($i == 1) {
                     $order['payment_mode'] = $inputs['paymentTypeRadio'];
                     $order['card_last_digit'] = $inputs['card4digits'];
                     $order['cardType'] = $inputs['card_type'];
                     $order['bank_name'] = $inputs['cardBankName'];
                     $order['receipt_number'] = $inputs['cardRecieptNumber'];
                 }
             }
         }
     }
     $orderCreated = Orders::createOrder($order);
     if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '' && $inputs['paymentOptionsRadio'] == 'bipay') {
         $payment_due = new PaymentDues();
         $payment_due = PaymentDues::find($paydue_id2);
         $payment_due->payment_status = 'paid';
         $payment_due->save();
         $order['created_at'] = $paymentDuesInput['created_at'];
         $order['amount'] = $paymentDuesResult->payment_due_amount - $paymentDuesResult->discount_amount;
         $order['payment_dues_id'] = $paydue_id2;
         if ($inputs['paymentTypeRadioOldCustomer2'] == 'cash') {
             $order['payment_mode'] = 'cash';
             $orderCreated = Orders::createOrder($order);
         } elseif ($inputs['paymentTypeRadioOldCustomer2'] == 'cheque') {
             $order['payment_mode'] = 'cheque';
             $order['bank_name'] = $inputs['bankName2'];
             $order['cheque_number'] = $inputs['chequeNumber2'];
             $orderCreated = Orders::createOrder($order);
         } elseif ($inputs['paymentTypeRadioOldCustomer2'] == 'card') {
             $order['payment_mode'] = 'card';
             $order['card_type'] = $inputs['cardType2'];
             $order['card_last_digit'] = $inputs['card4digits2'];
             $order['bank_name'] = $inputs['cardBankName2'];
             $order['receipt_number'] = $inputs['cardRecieptNumber2'];
             $orderCreated = Orders::createOrder($order);
         }
     }
     if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '' && $inputs['paymentOptionsRadio'] == 'multipay') {
         $paydue_data = PaymentDues::where('id', '=', $paydue_id[1])->get();
         $paydue_data = $paydue_data[0];
         $neworder = new Orders();
         $neworder['customer_id'] = $paydue_data['customer_id'];
         $neworder['student_id'] = $paydue_data['student_id'];
         $neworder['season_id'] = $paydue_data['season_id'];
         $neworder['student_classes_id'] = $paydue_data['student_class_id'];
         $neworder['payment_for'] = "enrollment";
         $neworder['payment_dues_id'] = $paydue_id[1];
         $neworder['amount'] = $paydue_data['payment_due_amount'];
         $neworder['order_status'] = "completed";
         if ($inputs['paymentTypeRadioOldCustomer2'] == 'cash') {
             $neworder['payment_mode'] = 'cash';
         } else {
             if ($inputs['paymentTypeRadioOldCustomer2'] == 'cheque') {
                 $neworder['payment_mode'] = 'cheque';
                 $neworder['bank_name'] = $inputs['bankName2'];
                 $neworder['cheque_number'] = $inputs['chequeNumber2'];
             } else {
                 if ($inputs['paymentTypeRadioOldCustomer2'] == 'card') {
                     $neworder['payment_mode'] = 'card';
                     $neworder['card_type'] = $inputs['cardType2'];
                     $neworder['card_last_digit'] = $inputs['card4digits2'];
                     $neworder['bank_name'] = $inputs['cardBankName2'];
                     $neworder['receipt_number'] = $inputs['cardRecieptNumber2'];
                 }
             }
         }
         $neworder['created_at'] = $paydue_data['created_at'];
         $neworder->created_by = Session::get('userId');
         $neworder->save();
     }
     if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate3'] != '' && $inputs['paymentOptionsRadio'] == 'multipay') {
         $paydue_data = PaymentDues::where('id', '=', $paydue_id[2])->get();
         $paydue_data = $paydue_data[0];
         $neworder = new Orders();
         $neworder['customer_id'] = $paydue_data['customer_id'];
         $neworder['student_id'] = $paydue_data['student_id'];
         $neworder['season_id'] = $paydue_data['season_id'];
         $neworder['student_classes_id'] = $paydue_data['student_class_id'];
         $neworder['payment_for'] = "enrollment";
         $neworder['payment_dues_id'] = $paydue_id[2];
         $neworder['amount'] = $paydue_data['payment_due_amount'];
         $neworder['order_status'] = "completed";
         if ($inputs['paymentTypeRadioOldCustomer3'] == 'cash') {
             $neworder['payment_mode'] = 'cash';
         } else {
             if ($inputs['paymentTypeRadioOldCustomer3'] == 'cheque') {
                 $neworder['payment_mode'] = 'cheque';
                 $neworder['bank_name'] = $inputs['bankName3'];
                 $neworder['cheque_number'] = $inputs['chequeNumber3'];
             } else {
                 if ($inputs['paymentTypeRadioOldCustomer3'] == 'card') {
                     $neworder['payment_mode'] = 'card';
                     $neworder['card_type'] = $inputs['cardType3'];
                     $neworder['card_last_digit'] = $inputs['card4digits3'];
                     $neworder['bank_name'] = $inputs['cardBankName3'];
                     $neworder['receipt_number'] = $inputs['cardRecieptNumber3'];
                 }
             }
         }
         $neworder['created_at'] = $paydue_data['created_at'];
         $neworder->created_by = Session::get('userId');
         $neworder->save();
     }
     if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate4'] != '' && $inputs['paymentOptionsRadio'] == 'multipay') {
         $paydue_data = PaymentDues::where('id', '=', $paydue_id[3])->get();
         $paydue_data = $paydue_data[0];
         $neworder = new Orders();
         $neworder['customer_id'] = $paydue_data['customer_id'];
         $neworder['student_id'] = $paydue_data['student_id'];
         $neworder['season_id'] = $paydue_data['season_id'];
         $neworder['student_classes_id'] = $paydue_data['student_class_id'];
         $neworder['payment_for'] = "enrollment";
         $neworder['payment_dues_id'] = $paydue_id[3];
         $neworder['amount'] = $paydue_data['payment_due_amount'];
         $neworder['order_status'] = "completed";
         if ($inputs['paymentTypeRadioOldCustomer4'] == 'cash') {
             $neworder['payment_mode'] = 'cash';
         } else {
             if ($inputs['paymentTypeRadioOldCustomer4'] == 'cheque') {
                 $neworder['payment_mode'] = 'cheque';
                 $neworder['bank_name'] = $inputs['bankName4'];
                 $neworder['cheque_number'] = $inputs['chequeNumber4'];
             } else {
                 if ($inputs['paymentTypeRadioOldCustomer4'] == 'card') {
                     $neworder['payment_mode'] = 'card';
                     $neworder['card_type'] = $inputs['cardType4'];
                     $neworder['card_last_digit'] = $inputs['card4digits4'];
                     $neworder['bank_name'] = $inputs['cardBankName4'];
                     $neworder['receipt_number'] = $inputs['cardRecieptNumber4'];
                 }
             }
         }
         $neworder['created_at'] = $paydue_data['created_at'];
         $neworder->created_by = Session::get('userId');
         $neworder->save();
     }
     if (isset($inputs['membershipType'])) {
         $membershipInputs['customer_id'] = $inputs['customerId'];
         $membershipInputs['membership_type_id'] = $inputs['membershipType'];
         CustomerMembership::addMembership($membershipInputs);
     }
     $student = Students::with('Customers', 'StudentClasses')->where('id', '=', $enrollment->student_id)->get();
     $class = Classes::where('id', '=', $enrollment->class_id)->get();
     $CustomerObject = Customers::find($inputs['customerId']);
     $CustomerObject->stage = "ENROLLED";
     $CustomerObject->save();
     $customer = array();
     $customer['customerName'] = $student['0']->Customers->customer_name;
     $customer['customerEmail'] = $student['0']->Customers->customer_email;
     $customer['kidName'] = $student['0']->student_name;
     $customer['className'] = $class['0']->class_name;
     $commentsInput['customerId'] = $inputs['customerId'];
     $commentsInput['commentText'] = Config::get('constants.ENROLLED') . ' for ' . $class['0']->class_name;
     $commentsInput['commentType'] = 'FOLLOW_UP';
     $commentsInput['reminderDate'] = null;
     Comments::addComments($commentsInput);
     if (isset($inputs['emailOption']) && $inputs['emailOption'] == 'yes') {
         $orders = Orders::with('Customers', 'Students', 'StudentClasses')->where('id', '=', $orderCreated->id)->get();
         $orders = $orders['0'];
         $paymentDues = PaymentDues::where('id', '=', $orders->payment_dues_id)->get();
         $batchDetails = Batches::where('id', '=', $orders->StudentClasses->batch_id)->get();
         $class = Classes::where('id', '=', $orders->StudentClasses->class_id)->where('franchisee_id', '=', Session::get('franchiseId'))->first();
         $customerMembership = CustomerMembership::getCustomerMembership($orders->customer_id);
         $class = Classes::where('id', '=', $inputs['eligibleClassesCbx'])->where('franchisee_id', '=', Session::get('franchiseId'))->first();
         $batch = Batches::where('id', '=', $inputs['batchCbx'])->first();
         $orderDetailsTomail['orders'] = $orders;
         $orderDetailsTomail['customers'] = $customer;
         $orderDetailsTomail['paymentDues'] = $paymentDues;
         $orderDetailsTomail['customerMembership'] = $customerMembership;
         $orderDetailsTomail['class'] = $class;
         $orderDetailsTomail['batchDetails'] = $batchDetails;
         $orderDetailsTomail['studentbatch']['start_date'] = date('Y-m-d', strtotime($inputs['enrollmentStartDate']));
         $orderDetailsTomail['studentbatch']['end_date'] = date('Y-m-d', strtotime($inputs['enrollmentEndDate']));
         $orderDetailsTomail['customers']['customerMembership'] = CustomerMembership::getCustomerMembership($orders->customer_id);
         Mail::send('emails.account.enrollment', $orderDetailsTomail, function ($msg) use($orderDetailsTomail) {
             $msg->from(Config::get('constants.EMAIL_ID'), Config::get('constants.EMAIL_NAME'));
             $msg->to($orderDetailsTomail['customers']['customerEmail'], $orderDetailsTomail['customers']['customerName'])->subject('The Little Gym - Kids Enrollment Successful');
         });
     }
     if (isset($inputs['invoicePrintOption']) && $inputs['invoicePrintOption'] == 'yes') {
         $printUrl = url() . '/orders/print/' . Crypt::encrypt($orderCreated->id);
     } else {
         $printUrl = "";
     }
     //header('Access-Control-Allow-Origin: *');
     if ($enrollment) {
         return Response::json(array("status" => "success", "printUrl" => $printUrl));
     } else {
         return Response::json(array("status" => "failed"));
     }
 }
Beispiel #14
0
 /**
  * editAction
  * Get a record and populate the application form 
  * @return unknown_type
  */
 public function editAction()
 {
     $form = $this->getForm('/admin/orders/process');
     $currency = Shineisp_Registry::getInstance()->Zend_Currency;
     $customer = null;
     $createInvoiceConfirmText = $this->translator->translate('Are you sure you want to create or overwrite the invoice for this order?');
     $id = intval($this->getRequest()->getParam('id'));
     $this->view->description = $this->translator->translate("Here you can edit the selected order.");
     if (!empty($id) && is_numeric($id)) {
         $rs = $this->orders->find($id);
         if (!empty($rs)) {
             $rs = $rs->toArray();
             $rs['setupfee'] = Orders::getSetupfee($id);
             $rs['order_date'] = Shineisp_Commons_Utilities::formatDateOut($rs['order_date']);
             $rs['expiring_date'] = Shineisp_Commons_Utilities::formatDateOut($rs['expiring_date']);
             $rs['received_income'] = 0;
             $rs['missing_income'] = $rs['grandtotal'];
             $rs['order_number'] = !empty($rs['order_number']) ? $rs['order_number'] : Orders::formatOrderId($rs['order_id']);
             $payments = Payments::findbyorderid($id, 'income', true);
             if (isset($payments)) {
                 foreach ($payments as $payment) {
                     $rs['received_income'] += isset($payment['income']) ? $payment['income'] : 0;
                     $rs['missing_income'] -= isset($payment['income']) ? $payment['income'] : 0;
                 }
             }
             $rs['profit'] = $rs['total'] - $rs['cost'];
             $rs['profit'] = $currency->toCurrency($rs['profit'], array('currency' => Settings::findbyParam('currency')));
             // set the default income to prepare the payment task
             $rs['income'] = $rs['missing_income'];
             $rs['missing_income'] = sprintf('%.2f', $rs['missing_income']);
             unset($payments);
             $parent = Customers::find($rs['customer_id']);
             //if customer comes from reseller
             if ($parent['parent_id']) {
                 $rs['customer_parent_id'] = $parent['parent_id'];
             } else {
                 $rs['customer_parent_id'] = $rs['customer_id'];
             }
             $link = Fastlinks::findlinks($id, $rs['customer_id'], 'Orders');
             if (isset($link[0])) {
                 $rs['fastlink'] = $link[0]['code'];
                 $rs['visits'] = $link[0]['visits'];
             }
             $form->populate($rs);
             $this->view->id = $id;
             $this->view->customerid = $rs['customer_id'];
             if (!empty($rs['fastlink'])) {
                 $this->view->titlelink = "/index/link/id/" . $rs['fastlink'];
             }
             if (!empty($rs['order_number'])) {
                 $this->view->title = $this->translator->_("Order nr. %s", $rs['order_number']);
             }
             $this->view->messages = Messages::getbyOrderId($id);
             $createInvoiceConfirmText = $rs['missing_income'] > 0 ? $this->translator->translate('Are you sure you want to create or overwrite the invoice for this order? The order status is: not paid.') : $createInvoiceConfirmText;
             $customer = Customers::get_by_customerid($rs['customer_id'], 'company, firstname, lastname, email');
         } else {
             $this->_helper->redirector('list', 'orders', 'admin');
         }
     }
     $this->view->mex = urldecode($this->getRequest()->getParam('mex'));
     $this->view->mexstatus = $this->getRequest()->getParam('status');
     // Create the buttons in the edit form
     $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('id' => 'submit', 'css' => array('btn btn-success'))), array("url" => "/admin/orders/print/id/{$id}", "label" => $this->translator->translate('Print'), "params" => array('css' => null)), array("url" => "/admin/orders/dropboxit/id/{$id}", "label" => $this->translator->translate('Dropbox It'), "params" => array('css' => null)), array("url" => "/admin/orders/clone/id/{$id}", "label" => $this->translator->translate('Clone'), "params" => array('css' => null)), array("url" => "/admin/orders/sendorder/id/{$id}", "label" => $this->translator->translate('Email'), "params" => array('css' => array('btn btn-danger'))), array("url" => "/admin/orders/confirm/id/{$id}", "label" => $this->translator->translate('Delete'), "params" => array('css' => array('btn btn-danger'))), array("url" => "/admin/orders/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null)));
     // Check if the order has been invoiced
     $invoice_id = Orders::isInvoiced($id);
     if ($invoice_id) {
         $this->view->buttons[] = array("url" => "/admin/orders/sendinvoice/id/{$invoice_id}", "label" => $this->translator->translate('Email invoice'), "params" => array('css' => array('btn btn-danger')));
         $this->view->buttons[] = array("url" => "/admin/invoices/print/id/{$invoice_id}", "label" => $this->translator->translate('Print invoice'), "params" => array('css' => null));
     } else {
         // Order not invoiced, show button to create a new invoice
         $this->view->buttons[] = array("url" => "/admin/orders/createinvoice/id/{$id}", "label" => $this->translator->translate('Invoice'), "params" => array('css' => array('btn btn-danger')), 'onclick' => "return confirm('" . $createInvoiceConfirmText . "')");
     }
     $this->view->customer = array('records' => $customer, 'editpage' => 'customers');
     $this->view->ordersdatagrid = $this->orderdetailGrid();
     $this->view->paymentsdatagrid = $this->paymentsGrid();
     $this->view->statushistory = StatusHistory::getStatusList($id);
     // Get Order status history
     $this->view->filesgrid = $this->filesGrid();
     $this->view->statushistorygrid = $this->statusHistoryGrid();
     $this->view->form = $form;
     $this->render('applicantform');
 }
Beispiel #15
0
 public function uploadProfilePicture()
 {
     $file = Input::file('profileImage');
     $destinationPath = 'upload/profile/customer/';
     $filename = $file->getClientOriginalName();
     $fileExtension = '.' . $file->getClientOriginalExtension();
     $customerId = Input::get('customerId');
     $filename = 'customer_profile_' . $customerId . '_medium' . $fileExtension;
     $result = Input::file('profileImage')->move($destinationPath, $filename);
     if ($result) {
         $customer = Customers::find($customerId);
         $customer->profile_image = $filename;
         $customer->save();
     }
     Session::flash('imageUploadMessage', "Profile picture updated successfully.");
     return Redirect::to("/customers/view/" . $customerId);
 }
Beispiel #16
0
 /**
  * Get customer info
  * @return Json
  */
 public function getcustomerinfoAction()
 {
     $id = $this->getRequest()->getParam('id');
     $customer = Customers::find($id, null, true);
     if (!empty($customer)) {
         die(json_encode($customer));
     }
     die(json_encode(array()));
 }
Beispiel #17
0
 /**
  * Set domain hosts (records) for a domain name.
  * 
  * Executes the '...' command on Registrar's servers, to set domain hosts (records)
  * for a domain name that is active and belongs to your Ascio account.
  * 
  * @param      integer     $domainID   Domain code identifier
  * @return     bool        True if succeed and False if failed.
  * @access     public
  * @see        getDomainHosts
  */
 function setDomainHosts($domainID)
 {
     $zonesrows = "";
     $nserver = "";
     // Connection to the SOAP system
     $soap = $this->Connect();
     if (empty($this->session)) {
         throw new Exception('SOAP connection system error');
     }
     // Get the domain information
     $domain = Domains::find($domainID);
     if (!empty($domain[0])) {
         $domain_name = $domain[0]['domain'] . "." . $domain[0]['DomainsTlds']['WhoisServers']['tld'];
         $customer = Customers::find($domain[0]['customer_id']);
     } else {
         throw new Exception('Domain information has not found.');
     }
     // Get the customer dns set in his control panel
     $NS = Dns_Zones::getCustomNameServers($domainID);
     // Get the default domain set
     $NSDefault = $soap->domainInfo($this->session['id'], $domain_name);
     // START NAMESERVER MANAGEMENT
     if (!empty($NS)) {
         // Get the client nameserver set in the shineisp control panel
         foreach ($NS as $ns) {
             $nameservers[] = $ns['target'];
         }
     } else {
         // Get the domain nameservers set in Ascio
         if (!empty($NSDefault->dns[0]) && !empty($NSDefault->dns[1])) {
             $nameservers[] = $NSDefault->dns[0]->name . ".";
             $nameservers[] = $NSDefault->dns[1]->name . ".";
         } else {
             // Get the common domain dns zones information set in shineisp preferences
             $NSDefault = Servers::getDnsserver();
             foreach ($NSDefault as $ns) {
                 $nameservers[] = $ns['host'] . "." . $ns['domain'] . ".";
             }
         }
     }
     // Create the NS records
     foreach ($nameservers as $ns) {
         $nameserver = array();
         $nameserver[] = "";
         $nameserver[] = " IN ";
         $nameserver[] = " NS ";
         $nameserver[] = $ns;
         $nserver .= implode("\t", $nameserver) . "\n";
     }
     // END NAMESERVER MANAGEMENT
     if (!empty($nameservers[0])) {
         $zoneTemplate = "\$TTL 86400\n@   IN SOA " . $nameservers[0] . " tech.ascio.net. (2011022503 86400 3600 3600000 86400)\n";
         // Get the domain dns zones information
         $dnsZones = Dns_Zones::getZones($domainID);
         // Create the DNS Zones records
         if (!empty($dnsZones)) {
             foreach ($dnsZones as $zone) {
                 if ($zone['fieldtype'] != "NS") {
                     // Exclude the NS because already included above
                     $zones = array();
                     $zones[] = $zone['subdomain'];
                     $zones[] = " IN ";
                     $zones[] = $zone['fieldtype'];
                     $zones[] = $zone['target'];
                     $zonesrows .= implode("\t", $zones) . "\n";
                 }
             }
             $zones = array();
             $zone = $zoneTemplate . $nserver . $zonesrows;
         } else {
             $webservers = Servers::getWebserver();
             $mailservers = Servers::getMailserver();
             // Set Web server zone
             $zones[] = "www\tIN\tCNAME\t" . $domain_name . ".";
             if (!empty($webservers['ip'])) {
                 $zones[] = "\tIN\tA\t" . $webservers['ip'];
             }
             // Set mail zone
             $zones[] = "\tIN\tMX 1\tmail." . $domain_name . ".";
             if (isset($mailservers)) {
                 $zones[] = "mail\tIN\tA\t" . $mailservers['ip'];
             } else {
                 $zones[] = "mail\tIN\tA\t" . $webservers['ip'];
             }
             $zonesrows = implode("\n", $zones) . "\n";
             $zone = $zoneTemplate . $nserver . $zonesrows;
         }
         // Reset of the Zone dns
         $soap->dnsReset($this->session['id'], $domain_name, 'REDIRECT', true);
         // Import the DNS Custom Zone
         $soap->zoneImport($this->session['id'], $domain_name, $zone);
         return true;
     }
     return false;
 }
Beispiel #18
0
 /**
  * editAction
  * Get a record and populate the application form 
  * @return unknown_type
  */
 public function editAction()
 {
     $form = $this->getForm('/admin/invoices/process');
     $id = $this->getRequest()->getParam('id');
     if (!empty($id) && is_numeric($id)) {
         $rs = $this->invoices->find($id)->toArray();
         if (!empty($rs)) {
             $rs['invoice_date'] = Shineisp_Commons_Utilities::formatDateOut($rs['invoice_date']);
             $parent = Customers::find($rs['customer_id']);
             //if customer comes from reseller
             if ($parent['parent_id']) {
                 $rs['customer_parent_id'] = $parent['parent_id'];
             } else {
                 $rs['customer_parent_id'] = $rs['customer_id'];
             }
             // Create the buttons in the edit form
             $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/invoices/confirm/id/{$id}", "label" => $this->translator->translate('Delete'), "params" => array('css' => null)), array("url" => "/admin/invoices/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/invoices/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null)));
             // Check if the order has been invoiced
             $this->view->buttons[] = array("url" => "/admin/orders/sendinvoice/id/{$id}", "label" => $this->translator->translate('Email invoice'), "params" => array('css' => null));
             $this->view->buttons[] = array("url" => "/admin/invoices/print/id/{$id}", "label" => $this->translator->translate('Print invoice'), "params" => array('css' => null));
             $this->view->buttons[] = array("url" => "/admin/invoices/confirmoverwrite/id/{$id}", "label" => $this->translator->translate('Overwrite invoice'), "params" => array('css' => null));
             $this->view->buttons[] = array("url" => "/admin/orders/edit/id/" . $rs['order_id'], "label" => $this->translator->translate('Order'), "params" => array('css' => null));
             $form->populate($rs);
         }
     }
     $this->view->title = $this->translator->translate("Invoice Edit");
     $this->view->description = $this->translator->translate("Here you can edit the selected order.");
     $this->view->mex = urldecode($this->getRequest()->getParam('mex'));
     $this->view->mexstatus = $this->getRequest()->getParam('status');
     $this->view->form = $form;
     $this->render('applicantform');
 }