Exemple #1
0
 public static function createPaymentMasterWithSamePaymentNo($inputs, $payment_no)
 {
     $paymentmaster = new PaymentMaster();
     $paymentmaster->payment_no = $payment_no;
     $paymentmaster->payment_due_id = $inputs->id;
     $paymentmaster->created_by = Session::get('userId');
     $paymentmaster->save();
     return $paymentmaster;
 }
 public function enrollkid1()
 {
     $inputs = Input::all();
     // ********working out for single batch*********//
     if ($inputs['batchCbx2'] == '' && $inputs['eligibleClassesCbx2'] == '' && $inputs['batchCbx'] != '' && $inputs['eligibleClassesCbx'] != '') {
         $studentClasses['classId'] = $inputs['eligibleClassesCbx'];
         $studentClasses['batchId'] = $inputs['batchCbx'];
         $studentClasses['studentId'] = $inputs['studentId'];
         $studentClasses['selected_sessions'] = $inputs['selectedSessions'];
         $studentClasses['seasonId'] = $inputs['SeasonsCbx'];
         $singleBatchstartDate = Carbon::createFromFormat('Y-m-d', $inputs['enrollmentStartDate']);
         $batch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $singleBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->take($inputs['selectedSessions'])->get();
         $studentClasses['enrollment_start_date'] = $batch_data[0]['schedule_date'];
         $studentClasses['enrollment_end_date'] = $batch_data[count($batch_data) - 1]['schedule_date'];
         $singleBatchendDate = Carbon::createFromFormat('Y-m-d', $batch_data[count($batch_data) - 1]['schedule_date']);
         $enrollment = StudentClasses::addStudentClass($studentClasses);
         // ********Adding to Student Classes table complete (single pay)*********//
         // ********working out for  payment Dues and Order table (singlepay)*********//
         $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'];
         //**getting value for each class amount for specific batch **//
         $singleBatchDataForEachClassCost = Batches::where('id', '=', $inputs['batchCbx'])->select('class_amount')->get();
         $paymentDuesInput['each_class_cost'] = $singleBatchDataForEachClassCost[0]['class_amount'];
         $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'];
         if ($inputs['paymentOptionsRadio'] == 'singlepay') {
             $paymentDuesInput['start_order_date'] = $singleBatchstartDate->toDateString();
             $paymentDuesInput['end_order_date'] = $singleBatchendDate->toDateString();
             $paymentDuesInput['payment_due_amount'] = $inputs['singlePayAmount'];
             $paymentDuesInput['payment_type'] = $inputs['paymentOptionsRadio'];
             $paymentDuesInput['payment_status'] = "paid";
             //** checking for Discount  applied by Discount Amount or Discount Percentage **//
             if ($inputs['discountPercentage'] != '') {
                 $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                 //$paymentDuesInput['discount_amount']=((($inputs['discountPercentage'])/100) *($inputs['singlePayAmount']));
                 $paymentDuesInput['discount_amount'] = 0;
             } else {
                 $paymentDuesInput['discount_applied'] = '0';
                 //** removing minus from discount textbox **//
                 $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                 $paymentDuesInput['discount_amount'] = $explodedDiscountAmount[1];
             }
             $paymentDuesInput['student_class_id'] = $enrollment->id;
             $paymentDuesInput['selected_order_sessions'] = $inputs['selectedSessions'];
             $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);
             $payment_master_data = PaymentMaster::createPaymentMaster($paymentDuesResult);
             $update_payment_due = PaymentDues::find($paymentDuesResult->id);
             $update_payment_due->payment_no = $payment_master_data->payment_no;
             $update_payment_due->save();
             //** paymentDue table Insertion Complete and working for order,followups**//
             //$order['payment_dues_id']   = $paymentDuesResult->id;
             $order['payment_no'] = $payment_master_data->payment_no;
             $order['order_status'] = "completed";
             if ($inputs['selectedSessions'] > 8) {
                 // ** working for single pay 1 batch followup (minimum 8 session required)**//
                 $presentDate = Carbon::now();
                 $session_number = (int) ($inputs['selectedSessions'] / 2);
                 $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'] = $batch_data[$session_number - 1]['schedule_date'];
                 $remindDate = Carbon::now();
                 $remindDate = $remindDate->createFromFormat('Y-m-d', $batch_data[$session_number - 1]['schedule_date']);
                 if ($remindDate->gt($presentDate)) {
                     $payment_master_data = PaymentMaster::createPaymentMaster($paymentDuesResult);
                     $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult, $payment_master_data->payment_no);
                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                     Comments::addSinglePayComment($customer_log_data);
                 }
             }
             //return Response::json(array('status'=>'success','data'=>$order));
             $orderCreated = Orders::createOrder($order);
             $update_payment_master = PaymentMaster::find($payment_master_data->id);
             $update_payment_master->order_id = $orderCreated->id;
             $update_payment_master->save();
             //** Followup for single pay 1 batch  is completed **//
         } elseif ($inputs['paymentOptionsRadio'] == 'bipay') {
             //return Response::json(array('status'=>'inputs','data'=>$inputs));
             //** working on the bipay  single batch **/
             $paymentDuesInput['payment_type'] = $inputs['paymentOptionsRadio'];
             //** 2 pays for loop runs twice **/
             for ($i = 1; $i <= 2; $i++) {
                 if (isset($inputs['bipayAmount' . $i])) {
                     if ($i == 1) {
                         //** creating first payment due **//
                         $paymentDuesInput['payment_status'] = "paid";
                         $order['amount'] = $inputs['bipayAmount' . $i];
                         $order['order_status'] = "completed";
                         //          $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'];
                         $session_no = $inputs['bipayAmount' . $i] / $paymentDuesInput['each_class_cost'] - 1;
                         $paymentDuesInput['start_order_date'] = $batch_data[0]['schedule_date'];
                         $paymentDuesInput['end_order_date'] = $batch_data[$session_no]['schedule_date'];
                         $firstsessionno = $session_no + 1;
                         //$endorderdateforbipay=$batch_data[(count($batch_data)-1)]['schedule_date'];
                         if ($firstsessionno >= 10) {
                             $followupFirstDate = $batch_data[$session_no - 2]['schedule_date'];
                             $followupSecondDate = $batch_data[$session_no - 1]['schedule_date'];
                             $followupThirdDate = $batch_data[$session_no]['schedule_date'];
                         } else {
                             $followupdate = $batch_data[$session_no]['schedule_date'];
                         }
                         if ($inputs['CustomerType'] == 'OldCustomer') {
                             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                             $order['created_at'] = $paymentDuesInput['created_at'];
                         }
                         //** updating student_classes for first pay enrollment **//
                         $update_student_classes = StudentClasses::find($enrollment->id);
                         $update_student_classes->enrollment_end_date = $paymentDuesInput['end_order_date'];
                         $update_student_classes->save();
                     } else {
                         //** working out for 2nd payment of bipay **/
                         $paymentDuesInput['start_order_date'] = $batch_data[$session_no + 1]['schedule_date'];
                         $paymentDuesInput['end_order_date'] = $batch_data[count($batch_data) - 1]['schedule_date'];
                         $paymentDuesInput['payment_status'] = "pending";
                         if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '') {
                             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate2']));
                         }
                     }
                     //** checking for Discount  applied by Discount Amount or Discount Percentage **//
                     if ($inputs['discountPercentage'] != '') {
                         $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                     } else {
                         $paymentDuesInput['discount_applied'] = '0';
                         $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                         $paymentDuesInput['discount_amount'] = $explodedDiscountAmount[1];
                     }
                     $paymentDuesInput['selected_order_sessions'] = $inputs['bipayAmount' . $i] / $paymentDuesInput['each_class_cost'];
                     $paymentDuesInput['payment_due_amount'] = $inputs['bipayAmount' . $i];
                     $paymentDuesInput['student_class_id'] = $enrollment->id;
                     $paymentDuesResult = PaymentDues::createPaymentDues($paymentDuesInput);
                     //** Working on Payment Master **//
                     $payment_master_data = PaymentMaster::createPaymentMaster($paymentDuesResult);
                     if ($i == 1) {
                         //** handling for Order table payment No **//
                         $order['payment_no'] = $payment_master_data->payment_no;
                     }
                     $update_payment_due = PaymentDues::find($paymentDuesResult->id);
                     $update_payment_due->payment_no = $payment_master_data->payment_no;
                     $update_payment_due->save();
                     if ($i == 2) {
                         //** creating followups for 2nd payment **/
                         if ($firstsessionno >= 10) {
                             $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'] = $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)) {
                                 //** creating three followups **//
                                 $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult, $payment_master_data->payment_no);
                                 $payment_followup_data2 = PaymentFollowups::createPaymentFollowup($paymentDuesResult, $payment_master_data->payment_no);
                                 $payment_followup_data3 = PaymentFollowups::createPaymentFollowup($paymentDuesResult, $payment_master_data->payment_no);
                                 $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, $payment_master_data->payment_no);
                                     $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, $payment_master_data->payment_no);
                                 $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);
                             }
                         }
                     }
                 }
             }
             //**create order **//
             //unset($order['seasonId']);
             $orderCreated = Orders::createOrder($order);
             //return Response ::json(array('payment_no'=>$orderCreated->payment_no,'order_id'=>$orderCreated->id));
             $update_payment_master = PaymentMaster::where('payment_no', '=', $orderCreated->payment_no)->update(array('order_id' => $orderCreated->id));
         }
         //** working out for multipay
         if ($orderCreated) {
             return Response::json(array('status' => 'success', 'data' => $inputs));
         } else {
             return Response::json(array('status' => 'failure'));
         }
     } else {
         if ($inputs['batchCbx3'] == '' && $inputs['eligibleClassesCbx3'] == '' && $inputs['batchCbx'] != '' && $inputs['eligibleClassesCbx'] != '' && $inputs['batchCbx2'] != '' && $inputs['eligibleClassesCbx2'] != '') {
             //********* working out for 2 batches ************//
             // return Response::json(array('status'=>'success','data'=>$inputs));
             if ($inputs['paymentOptionsRadio'] == 'singlepay') {
                 //working out for first batch enrollment
                 $studentClasses1['classId'] = $inputs['eligibleClassesCbx'];
                 $studentClasses1['batchId'] = $inputs['batchCbx'];
                 $studentClasses1['studentId'] = $inputs['studentId'];
                 $studentClasses1['seasonId'] = $inputs['SeasonsCbx'];
                 $firstBatchstartDate = Carbon::createFromFormat('Y-m-d', $inputs['enrollmentStartDate']);
                 $firstbatch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $firstBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                 $studentClasses1['selected_sessions'] = count($firstbatch_data);
                 $studentClasses1['enrollment_start_date'] = $firstbatch_data[0]['schedule_date'];
                 $studentClasses1['enrollment_end_date'] = $firstbatch_data[count($firstbatch_data) - 1]['schedule_date'];
                 $firstBatchendDate = Carbon::createFromFormat('Y-m-d', $firstbatch_data[count($firstbatch_data) - 1]['schedule_date']);
                 $enrollment1 = StudentClasses::addStudentClass($studentClasses1);
                 //** first batch enrollment completed**//
                 //** working out for second batch enrollment **//
                 $studentClasses2['classId'] = $inputs['eligibleClassesCbx2'];
                 $studentClasses2['batchId'] = $inputs['batchCbx2'];
                 $studentClasses2['studentId'] = $inputs['studentId'];
                 $studentClasses2['seasonId'] = $inputs['SeasonsCbx2'];
                 $secondBatchstartDate = $firstBatchstartDate->next(Carbon::MONDAY);
                 //** To get the proper selected No of sessions from second batch **/
                 $selectedNoOfSessionsForSecondBatch = $inputs['selectedSessions'] - count($firstbatch_data);
                 $secondbatch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx2'])->where('schedule_date', '>=', $secondBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->take($selectedNoOfSessionsForSecondBatch)->get();
                 $studentClasses2['selected_sessions'] = count($secondbatch_data);
                 $studentClasses2['enrollment_start_date'] = $secondbatch_data[0]['schedule_date'];
                 $studentClasses2['enrollment_end_date'] = $secondbatch_data[count($secondbatch_data) - 1]['schedule_date'];
                 $secondBatchendDate = Carbon::createFromFormat('Y-m-d', $secondbatch_data[count($secondbatch_data) - 1]['schedule_date']);
                 $enrollment2 = StudentClasses::addStudentClass($studentClasses2);
                 //** second batch enrollment completed**//
                 // ********working out for  payment Dues and Order table (singlepay)*********//
                 $paymentDuesInput1['student_id'] = $inputs['studentId'];
                 $paymentDuesInput1['customer_id'] = $inputs['customerId'];
                 $paymentDuesInput1['batch_id'] = $inputs['batchCbx'];
                 $paymentDuesInput1['class_id'] = $inputs['eligibleClassesCbx'];
                 $paymentDuesInput1['selected_sessions'] = $inputs['selectedSessions'];
                 $paymentDuesInput1['seasonId'] = $inputs['SeasonsCbx'];
                 $paymentDuesInput2['student_id'] = $inputs['studentId'];
                 $paymentDuesInput2['customer_id'] = $inputs['customerId'];
                 $paymentDuesInput2['batch_id'] = $inputs['batchCbx2'];
                 $paymentDuesInput2['class_id'] = $inputs['eligibleClassesCbx2'];
                 $paymentDuesInput2['selected_sessions'] = $inputs['selectedSessions'];
                 $paymentDuesInput2['seasonId'] = $inputs['SeasonsCbx2'];
                 //**getting value for each class amount for specific batch **//
                 $firstBatchDataForEachClassCost = Batches::where('id', '=', $inputs['batchCbx'])->select('class_amount')->get();
                 $secondBatchDataForEachClassCost = Batches::where('id', '=', $inputs['batchCbx2'])->select('class_amount')->get();
                 $paymentDuesInput1['each_class_cost'] = $firstBatchDataForEachClassCost[0]['class_amount'];
                 $paymentDuesInput2['each_class_cost'] = $secondBatchDataForEachClassCost[0]['class_amount'];
                 $order['customer_id'] = $inputs['customerId'];
                 $order['student_id'] = $inputs['studentId'];
                 //$order['seasonId']        = $inputs['SeasonsCbx'];
                 //$order['student_classes_id'] = $enrollment1->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'];
                 $paymentDuesInput1['start_order_date'] = $firstBatchstartDate->toDateString();
                 $paymentDuesInput1['end_order_date'] = $firstBatchendDate->toDateString();
                 $paymentDuesInput1['payment_due_amount'] = count($firstbatch_data) * $firstBatchDataForEachClassCost[0]['class_amount'];
                 $paymentDuesInput1['payment_type'] = $inputs['paymentOptionsRadio'];
                 $paymentDuesInput1['payment_status'] = "paid";
                 $paymentDuesInput2['start_order_date'] = $secondBatchstartDate->toDateString();
                 $paymentDuesInput2['end_order_date'] = $secondBatchendDate->toDateString();
                 $paymentDuesInput2['payment_due_amount'] = count($secondbatch_data) * $secondBatchDataForEachClassCost[0]['class_amount'];
                 $paymentDuesInput2['payment_type'] = $inputs['paymentOptionsRadio'];
                 $paymentDuesInput2['payment_status'] = "paid";
                 //** checking for Discount  applied by Discount Amount or Discount Percentage **//
                 if ($inputs['discountPercentage'] != '') {
                     $paymentDuesInput1['discount_applied'] = $inputs['discountPercentage'];
                     $paymentDuesInput1['discount_amount'] = 0;
                     //$paymentDuesInput1['discount_amount']=((($inputs['discountPercentage'])/100) *(count($firstbatch_data)*$firstBatchDataForEachClassCost[0]['class_amount']));
                     $paymentDuesInput2['discount_applied'] = $inputs['discountPercentage'];
                     $paymentDuesInput2['discount_amount'] = 0;
                     //$paymentDuesInput2['discount_amount']=((($inputs['discountPercentage'])/100) *(count($secondbatch_data)*$secondBatchDataForEachClassCost[0]['class_amount']));
                 } else {
                     $paymentDuesInput1['discount_applied'] = '0';
                     //** removing minus from discount textbox **//
                     $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                     $paymentDuesInput1['discount_amount'] = $explodedDiscountAmount[1];
                     $paymentDuesInput1['discount_amount'] = $paymentDuesInput1['discount_amount'];
                     $paymentDuesInput2['discount_applied'] = '0';
                     //** removing minus from discount textbox **//
                     $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                     $paymentDuesInput2['discount_amount'] = $explodedDiscountAmount[1];
                     $paymentDuesInput2['discount_amount'] = $paymentDuesInput2['discount_amount'];
                 }
                 $paymentDuesInput1['student_class_id'] = $enrollment1->id;
                 $paymentDuesInput1['selected_order_sessions'] = count($firstbatch_data);
                 $paymentDuesInput2['student_class_id'] = $enrollment2->id;
                 $paymentDuesInput2['selected_order_sessions'] = count($secondbatch_data);
                 $order['amount'] = $inputs['singlePayAmount'];
                 if ($inputs['CustomerType'] == 'OldCustomer') {
                     $paymentDuesInput1['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                     $paymentDuesInput2['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                     $order['created_at'] = $paymentDuesInput['created_at'];
                 }
                 $paymentDuesResult1 = PaymentDues::createPaymentDues($paymentDuesInput1);
                 $payment_master_data1 = PaymentMaster::createPaymentMaster($paymentDuesResult1);
                 $paymentDuesResult2 = PaymentDues::createPaymentDues($paymentDuesInput2);
                 $payment_master_data2 = PaymentMaster::createPaymentMasterWithSamePaymentNo($paymentDuesResult2, $payment_master_data1->payment_no);
                 $update_payment_due = PaymentDues::whereIn('id', array($paymentDuesResult1->id, $paymentDuesResult2->id))->update(array('payment_no' => $payment_master_data1->payment_no));
                 //** paymentDue table Insertion Complete and working for order,followups**//
                 //$order['payment_dues_id']   = $paymentDuesResult->id;
                 $order['payment_no'] = $payment_master_data1->payment_no;
                 $order['order_status'] = "completed";
                 if ($inputs['selectedSessions'] > 8) {
                     // ** working for single pay 1 batch followup (minimum 8 session required)**//
                     $presentDate = Carbon::now();
                     $session_number = (int) ($inputs['selectedSessions'] / 2);
                     $customer_log_data['customer_id'] = $paymentDuesResult1->customer_id;
                     $customer_log_data['student_id'] = $paymentDuesResult1->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';
                     //return Response::json(array('status'=>'success','data'=>$inputs));
                     if (count($firstbatch_data) <= $session_number) {
                         // return Response::json(array('status'=>'success','data'=>$inputs));
                         $customer_log_data['reminderDate'] = $firstbatch_data[$session_number - 1]['schedule_date'];
                         $remindDate = Carbon::now();
                         $remindDate = $remindDate->createFromFormat('Y-m-d', $customer_log_data['reminderDate']);
                         if ($remindDate->gt($presentDate)) {
                             $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult1, $payment_master_data1->id);
                             $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                             Comments::addSinglePayComment($customer_log_data);
                         }
                     } else {
                         //return Response::json(array('status'=>'secsuccess','data'=>$inputs,'session_number'=>$session_number,'firstbatch_count'=>count($firstbatch_data),'secbatch_count'=>count($secondbatch_data)));
                         $session_number = $inputs['selectedSessions'] - count($firstbatch_data) - 1;
                         $customer_log_data['reminderDate'] = $secondbatch_data[$session_number]['schedule_date'];
                         $remindDate = Carbon::now();
                         $remindDate = $remindDate->createFromFormat('Y-m-d', $customer_log_data['reminderDate']);
                         if ($remindDate->gt($presentDate)) {
                             $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult2, $payment_master_data2->id);
                             $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                             Comments::addSinglePayComment($customer_log_data);
                             //return Response::json(array('status'=>'secsuccess','data'=>$inputs,'session_number'=>$session_number,'firstbatch_count'=>count($firstbatch_data),'secbatch_count'=>count($secondbatch_data)));
                         }
                         //return Response::json(array('status'=>'afterifloop'));
                     }
                     //$remindDate=Carbon::now();
                 }
                 //** Followup for single pay 1 batch  is completed **//
                 $orderCreated = Orders::createOrder($order);
                 //** order creation completed**//
                 //** updating order_id in payment_master table **//
                 $orderPaymentMasterUpdate = PaymentMaster::where('payment_no', '=', $payment_master_data1->payment_no)->update(array('order_id' => $orderCreated->id));
             } elseif ($inputs['paymentOptionsRadio'] == 'bipay') {
                 //** working for the 2batch bipay **//
                 //working out for first batch enrollment
                 $studentClasses1['classId'] = $inputs['eligibleClassesCbx'];
                 $studentClasses1['batchId'] = $inputs['batchCbx'];
                 $studentClasses1['studentId'] = $inputs['studentId'];
                 $studentClasses1['seasonId'] = $inputs['SeasonsCbx'];
                 $firstBatchstartDate = Carbon::createFromFormat('Y-m-d', $inputs['enrollmentStartDate']);
                 $firstbatch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $firstBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                 $studentClasses1['selected_sessions'] = count($firstbatch_data);
                 $studentClasses1['enrollment_start_date'] = $firstbatch_data[0]['schedule_date'];
                 $studentClasses1['enrollment_end_date'] = $firstbatch_data[count($firstbatch_data) - 1]['schedule_date'];
                 $firstBatchendDate = Carbon::createFromFormat('Y-m-d', $firstbatch_data[count($firstbatch_data) - 1]['schedule_date']);
                 //** first batch enrollment completed**//
                 //** working out for second batch enrollment **//
                 $studentClasses2['classId'] = $inputs['eligibleClassesCbx2'];
                 $studentClasses2['batchId'] = $inputs['batchCbx2'];
                 $studentClasses2['studentId'] = $inputs['studentId'];
                 $studentClasses2['seasonId'] = $inputs['SeasonsCbx2'];
                 $secondBatchstartDate = $firstBatchstartDate->next(Carbon::MONDAY);
                 //** To get the proper selected No of sessions from second batch **/
                 $selectedNoOfSessionsForSecondBatch = $inputs['selectedSessions'] - count($firstbatch_data);
                 $secondbatch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx2'])->where('schedule_date', '>=', $secondBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->take($selectedNoOfSessionsForSecondBatch)->get();
                 $studentClasses2['selected_sessions'] = count($secondbatch_data);
                 $studentClasses2['enrollment_start_date'] = $secondbatch_data[0]['schedule_date'];
                 $studentClasses2['enrollment_end_date'] = $secondbatch_data[count($secondbatch_data) - 1]['schedule_date'];
                 $secondBatchendDate = Carbon::createFromFormat('Y-m-d', $secondbatch_data[count($secondbatch_data) - 1]['schedule_date']);
                 $paymentSession_no1;
                 $paymentSession_no2;
                 if ($inputs['selectedSessions'] % 2 == 0) {
                     $paymentSession_no1 = $inputs['selectedSessions'] / 2;
                     $paymentSession_no2 = $inputs['selectedSessions'] / 2;
                 } else {
                     $paymentSession_no1 = (int) ($inputs['selectedSessions'] / 2);
                     $paymentSession_no2 = (int) ($inputs['selectedSessions'] / 2) + 1;
                 }
                 //** working for class enrollment for different scenarios **//
                 if ($paymentSession_no1 == count($firstbatch_data)) {
                     $enrollment1 = StudentClasses::addStudentClass($studentClasses1);
                     $studentClasses2['status'] = 'pending';
                     $enrollment2 = StudentClasses::addStudentClass($studentClasses2);
                     for ($i = 1; $i <= 2; $i++) {
                         if ($i == 1) {
                             //** creating first payment due **//
                             $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['payment_type'] = $inputs['paymentOptionsRadio'];
                             $first_batch = Batches::find($firstbatch_data[0]['batch_id']);
                             $paymentDuesInput['each_class_cost'] = $first_batch->class_amount;
                             $paymentDuesInput['payment_status'] = "paid";
                             $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                             $order['amount'] = $inputs['bipayAmount' . $i];
                             $order['order_status'] = "completed";
                             $paymentDuesInput['start_order_date'] = $firstbatch_data[0]['schedule_date'];
                             $paymentDuesInput['end_order_date'] = $firstbatch_data[count($firstbatch_data) - 1]['schedule_date'];
                             $paymentDuesInput['selected_order_sessions'] = count($firstbatch_data);
                             $paymentDuesInput['payment_due_amount'] = $inputs['bipayAmount' . $i];
                             $paymentDuesInput['student_class_id'] = $enrollment1->id;
                             $firstsessionno = count($firstbatch_data);
                             $session_no = count($firstbatch_data) - 1;
                             if ($firstsessionno >= 10) {
                                 $followupFirstDate = $firstbatch_data[$session_no - 2]['schedule_date'];
                                 $followupSecondDate = $firstbatch_data[$session_no - 1]['schedule_date'];
                                 $followupThirdDate = $firstbatch_data[$session_no]['schedule_date'];
                             } else {
                                 $followupdate = $firstbatch_data[$session_no]['schedule_date'];
                             }
                             if ($inputs['CustomerType'] == 'OldCustomer') {
                                 $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                                 $order['created_at'] = $paymentDuesInput['created_at'];
                             }
                         } else {
                             //** working out for 2nd payment of bipay **/
                             $paymentDuesInput['start_order_date'] = $secondbatch_data[0]['schedule_date'];
                             $paymentDuesInput['end_order_date'] = $secondbatch_data[count($secondbatch_data) - 1]['schedule_date'];
                             $paymentDuesInput['payment_status'] = "pending";
                             $paymentDuesInput['batch_id'] = $inputs['batchCbx2'];
                             $paymentDuesInput['class_id'] = $inputs['eligibleClassesCbx2'];
                             $paymentDuesInput['selected_order_sessions'] = count($secondbatch_data);
                             $paymentDuesInput['payment_due_amount'] = $inputs['bipayAmount' . $i];
                             $paymentDuesInput['student_class_id'] = $enrollment2->id;
                             $paymentDuesInput['seasonId'] = $inputs['SeasonsCbx2'];
                             $second_batch = Batches::find($secondbatch_data[0]['batch_id']);
                             $paymentDuesInput['each_class_cost'] = $second_batch->class_amount;
                             if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '') {
                                 $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate2']));
                             }
                         }
                         //** checking for Discount  applied by Discount Amount or Discount Percentage **//
                         if ($inputs['discountPercentage'] != '') {
                             $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                         } else {
                             $paymentDuesInput['discount_applied'] = '0';
                             $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                             $paymentDuesInput['discount_amount'] = $explodedDiscountAmount[1];
                         }
                         if ($i == 1) {
                             $paymentDuesResult1 = PaymentDues::createPaymentDues($paymentDuesInput);
                         } else {
                             $paymentDuesResult2 = PaymentDues::createPaymentDues($paymentDuesInput);
                         }
                         //** Working on Payment Master **//
                         if ($i == 1) {
                             $payment_master_data1 = PaymentMaster::createPaymentMaster($paymentDuesResult1);
                             //** handling for Order table payment No **//
                             $order['payment_no'] = $payment_master_data1->payment_no;
                             $update_payment_due = PaymentDues::find($paymentDuesResult1->id);
                             $update_payment_due->payment_no = $payment_master_data1->payment_no;
                             $update_payment_due->save();
                         } else {
                             $payment_master_data2 = PaymentMaster::createPaymentMaster($paymentDuesResult2);
                             $update_payment_due = PaymentDues::find($paymentDuesResult2->id);
                             $update_payment_due->payment_no = $payment_master_data2->payment_no;
                             $update_payment_due->save();
                             $order['customer_id'] = $paymentDuesResult1->customer_id;
                             $order['student_id'] = $paymentDuesResult1->student_id;
                             $order['payment_no'] = $payment_master_data1->payment_no;
                             $order['payment_for'] = 'enrollment';
                             $order['payment_mode'] = $inputs['paymentTypeRadio'];
                             if ($inputs['paymentTypeRadio'] == 'cheque') {
                                 $order['bank_name'] = $inputs['bankName'];
                                 $order['cheque_number'] = $inputs['chequeNumber'];
                             } else {
                                 if ($inputs['paymentTypeRadio'] == 'card') {
                                     $order['card_last_digit'] = $inputs['card4digits'];
                                     $order['card_type'] = $inputs['cardType'];
                                     $order['bank_name'] = $inputs['bankName'];
                                     $order['receipt_number'] = $inputs['cardRecieptNumber'];
                                 }
                             }
                             //return Response:: json(array('status'=>'elsepart','data'=>$inputs ));
                         }
                     }
                 } elseif (count($firstbatch_data) > $paymentSession_no1) {
                     //return Response::json(array('status'=>'success','data'=>$inputs));
                     $studentClasses1['status'] = 'enrolled';
                     $studentClasses1['selected_sessions'] = $paymentSession_no1;
                     $studentClasses1['enrollment_end_date'] = $firstbatch_data[$paymentSession_no1 - 1]['schedule_date'];
                     $firstBatchendDate = Carbon::createFromFormat('Y-m-d', $firstbatch_data[$paymentSession_no1 - 1]['schedule_date']);
                     $enrollment1 = StudentClasses::addStudentClass($studentClasses1);
                     //** first batch inserted completely to student_classes **//
                     $studentClasses1['status'] = 'pending';
                     $studentClasses1['selected_sessions'] = count($firstbatch_data) - $paymentSession_no1;
                     $studentClasses1['enrollment_start_date'] = $firstbatch_data[$paymentSession_no1]['schedule_date'];
                     $studentClasses1['enrollment_end_date'] = $firstbatch_data[count($firstbatch_data) - 1]['schedule_date'];
                     $enrollment2 = StudentClasses::addStudentClass($studentClasses1);
                     //** second batch is inserted completed for student_classes **//
                     $studentClasses2['status'] = 'pending';
                     $enrollment3 = StudentClasses::addStudentClass($studentClasses2);
                     for ($i = 1; $i <= 3; $i++) {
                         if ($i == 1) {
                             //** creating first payment due **//
                             $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['payment_type'] = $inputs['paymentOptionsRadio'];
                             $first_batch = Batches::find($firstbatch_data[0]['batch_id']);
                             $paymentDuesInput['each_class_cost'] = $first_batch->class_amount;
                             $paymentDuesInput['payment_status'] = "paid";
                             $order['amount'] = $first_batch->class_amount * $paymentSession_no1;
                             $order['order_status'] = "completed";
                             $paymentDuesInput['start_order_date'] = $firstbatch_data[0]['schedule_date'];
                             $paymentDuesInput['end_order_date'] = $firstbatch_data[$paymentSession_no1 - 1]['schedule_date'];
                             $paymentDuesInput['selected_order_sessions'] = $paymentSession_no1;
                             $paymentDuesInput['payment_due_amount'] = $first_batch->class_amount * $paymentSession_no1;
                             $paymentDuesInput['student_class_id'] = $enrollment1->id;
                             if ($inputs['CustomerType'] == 'OldCustomer') {
                                 $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                                 $order['created_at'] = $paymentDuesInput['created_at'];
                             }
                         } else {
                             if ($i == 2) {
                                 $paymentDuesInput['student_class_id'] = $enrollment2->id;
                                 $paymentDuesInput['payment_status'] = "pending";
                                 $paymentDuesInput['start_order_date'] = $firstbatch_data[$paymentSession_no1]['schedule_date'];
                                 $paymentDuesInput['end_order_date'] = $firstbatch_data[count($firstbatch_data) - 1]['schedule_date'];
                                 $paymentDuesInput['selected_order_sessions'] = count($firstbatch_data) - $paymentSession_no1;
                                 $paymentDuesInput['payment_due_amount'] = $first_batch->class_amount * (count($firstbatch_data) - $paymentSession_no1);
                                 if ($inputs['CustomerType'] == 'OldCustomer') {
                                     $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate2']));
                                     $order['created_at'] = $paymentDuesInput['created_at'];
                                 }
                             } else {
                                 //** creating last payment_due **//
                                 $paymentDuesInput['batch_id'] = $inputs['batchCbx2'];
                                 $paymentDuesInput['class_id'] = $inputs['eligibleClassesCbx2'];
                                 $paymentDuesInput['seasonId'] = $inputs['SeasonsCbx2'];
                                 $second_batch = Batches::find($secondbatch_data[0]['batch_id']);
                                 $paymentDuesInput['each_class_cost'] = $second_batch->class_amount;
                                 $paymentDuesInput['payment_status'] = "pending";
                                 $paymentDuesInput['start_order_date'] = $secondbatch_data[0]['schedule_date'];
                                 $paymentDuesInput['end_order_date'] = $secondbatch_data[count($secondbatch_data) - 1]['schedule_date'];
                                 $paymentDuesInput['selected_order_sessions'] = count($secondbatch_data);
                                 $paymentDuesInput['payment_due_amount'] = $second_batch->class_amount * count($secondbatch_data);
                                 $paymentDuesInput['student_class_id'] = $enrollment3->id;
                             }
                         }
                         //** checking for Discount  applied by Discount Amount or Discount Percentage **//
                         if ($inputs['discountPercentage'] != '') {
                             $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                         } else {
                             $paymentDuesInput['discount_applied'] = '0';
                             $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                             $paymentDuesInput['discount_amount'] = $explodedDiscountAmount[1];
                         }
                         if ($i == 1) {
                             $paymentDuesResult1 = PaymentDues::createPaymentDues($paymentDuesInput);
                         } else {
                             if ($i == 2) {
                                 $paymentDuesResult2 = PaymentDues::createPaymentDues($paymentDuesInput);
                             } else {
                                 $paymentDuesResult3 = PaymentDues::createPaymentDues($paymentDuesInput);
                                 //return Response:: json(array('status'=>'elsepart','data'=>$inputs ));
                             }
                         }
                         //** Working on Payment Master **//
                         if ($i == 1) {
                             $payment_master_data1 = PaymentMaster::createPaymentMaster($paymentDuesResult1);
                             //** handling for Order table payment No **//
                             $order['payment_no'] = $payment_master_data1->payment_no;
                             $update_payment_due = PaymentDues::find($paymentDuesResult1->id);
                             $update_payment_due->payment_no = $payment_master_data1->payment_no;
                             $update_payment_due->save();
                         } else {
                             if ($i == 3) {
                                 $payment_master_data2 = PaymentMaster::createPaymentMaster($paymentDuesResult2);
                                 $update_payment_due = PaymentDues::whereIn('id', array($paymentDuesResult2->id, $paymentDuesResult3->id))->update(array('payment_no' => $payment_master_data2->payment_no));
                                 $order['customer_id'] = $paymentDuesResult1->customer_id;
                                 $order['student_id'] = $paymentDuesResult1->student_id;
                                 $order['payment_no'] = $payment_master_data1->payment_no;
                                 $order['payment_for'] = 'enrollment';
                                 $order['payment_mode'] = $inputs['paymentTypeRadio'];
                                 if ($inputs['paymentTypeRadio'] == 'cheque') {
                                     $order['bank_name'] = $inputs['bankName'];
                                     $order['cheque_number'] = $inputs['chequeNumber'];
                                 } else {
                                     if ($inputs['paymentTypeRadio'] == 'card') {
                                         $order['card_last_digit'] = $inputs['card4digits'];
                                         $order['card_type'] = $inputs['cardType'];
                                         $order['bank_name'] = $inputs['bankName'];
                                         $order['receipt_number'] = $inputs['cardRecieptNumber'];
                                     }
                                 }
                                 //return Response:: json(array('status'=>'elsepart','data'=>$inputs ));
                             }
                         }
                     }
                 } else {
                     if (count($firstbatch_data) < $paymentSession_no1) {
                         //return Response::json(array('status'=>'success','data'=>$inputs));
                         $studentClasses1['status'] = 'enrolled';
                         $studentClasses1['enrollment_end_date'] = $firstbatch_data[count($firstbatch_data) - 1]['schedule_date'];
                         $studentClasses1['selected_sessions'] = count($firstbatch_data);
                         $enrollment1 = StudentClasses::addStudentClass($studentClasses1);
                         $studentClasses2['enrollment_start_date'] = $secondbatch_data[0]['schedule_date'];
                         $studentClasses2['enrollment_end_date'] = $secondbatch_data[$paymentSession_no1 - count($firstbatch_data) - 1]['schedule_date'];
                         $studentClasses2['selected_sessions'] = $paymentSession_no1 - count($firstbatch_data);
                         $studentClasses2['status'] = 'enrolled';
                         $enrollment2 = StudentClasses::addStudentClass($studentClasses2);
                         $studentClasses2['status'] = 'pending';
                         $studentClasses2['enrollment_start_date'] = $secondbatch_data[$paymentSession_no1 - count($firstbatch_data)]['schedule_date'];
                         $studentClasses2['enrollment_end_date'] = $secondbatch_data[count($secondbatch_data) - 1]['schedule_date'];
                         $studentClasses2['selected_sessions'] = $paymentSession_no2;
                         $enrollment3 = StudentClasses::addStudentClass($studentClasses2);
                         for ($i = 1; $i <= 3; $i++) {
                             if ($i == 1) {
                                 $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['payment_type'] = $inputs['paymentOptionsRadio'];
                                 $first_batch = Batches::find($firstbatch_data[0]['batch_id']);
                                 $paymentDuesInput['each_class_cost'] = $first_batch->class_amount;
                                 $paymentDuesInput['payment_status'] = "paid";
                                 $order['amount'] = $inputs['bipayAmount' . $i];
                                 $order['order_status'] = "completed";
                                 $paymentDuesInput['start_order_date'] = $firstbatch_data[0]['schedule_date'];
                                 $paymentDuesInput['end_order_date'] = $enrollment1->enrollment_end_date;
                                 $paymentDuesInput['selected_order_sessions'] = count($firstbatch_data);
                                 $paymentDuesInput['payment_due_amount'] = count($firstbatch_data) * $first_batch->class_amount;
                                 $paymentDuesInput['student_class_id'] = $enrollment1->id;
                                 if ($inputs['CustomerType'] == 'OldCustomer') {
                                     $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                                     $order['created_at'] = $paymentDuesInput['created_at'];
                                 }
                             } else {
                                 if ($i == 2) {
                                     $paymentDuesInput['start_order_date'] = $enrollment2->enrollment_start_date;
                                     $paymentDuesInput['end_order_date'] = $enrollment2->enrollment_end_date;
                                     $paymentDuesInput['payment_status'] = "paid";
                                     $paymentDuesInput['batch_id'] = $inputs['batchCbx2'];
                                     $paymentDuesInput['class_id'] = $inputs['eligibleClassesCbx2'];
                                     $paymentDuesInput['selected_order_sessions'] = $enrollment2->selected_sessions;
                                     $paymentDuesInput['student_class_id'] = $enrollment2->id;
                                     $paymentDuesInput['seasonId'] = $inputs['SeasonsCbx2'];
                                     $second_batch = Batches::find($secondbatch_data[0]['batch_id']);
                                     $paymentDuesInput['each_class_cost'] = $second_batch->class_amount;
                                     $paymentDuesInput['payment_due_amount'] = $paymentDuesInput['selected_order_sessions'] * $paymentDuesInput['each_class_cost'];
                                     if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '') {
                                         $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate2']));
                                     }
                                 } else {
                                     if ($i == 3) {
                                         //** creating last payment_due **//
                                         $second_batch = Batches::find($secondbatch_data[0]['batch_id']);
                                         $paymentDuesInput['each_class_cost'] = $second_batch->class_amount;
                                         $paymentDuesInput['payment_status'] = "pending";
                                         $paymentDuesInput['start_order_date'] = $enrollment3->enrollment_start_date;
                                         $paymentDuesInput['end_order_date'] = $enrollment3->enrollment_end_date;
                                         $paymentDuesInput['selected_order_sessions'] = $paymentSession_no2;
                                         $paymentDuesInput['payment_due_amount'] = $paymentSession_no2 * $second_batch->class_amount;
                                         $paymentDuesInput['student_class_id'] = $enrollment3->id;
                                         if ($inputs['CustomerType'] == 'OldCustomer' && $inputs['OrderDate2'] != '') {
                                             $paymentDuesInput['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate2']));
                                         }
                                     }
                                 }
                             }
                             //** checking for Discount  applied by Discount Amount or Discount Percentage **//
                             if ($inputs['discountPercentage'] != '') {
                                 $paymentDuesInput['discount_applied'] = $inputs['discountPercentage'];
                             } else {
                                 $paymentDuesInput['discount_applied'] = '0';
                                 $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                                 $paymentDuesInput['discount_amount'] = $explodedDiscountAmount[1];
                             }
                             if ($i == 1) {
                                 $paymentDuesResult1 = PaymentDues::createPaymentDues($paymentDuesInput);
                             } else {
                                 if ($i == 2) {
                                     $paymentDuesResult2 = PaymentDues::createPaymentDues($paymentDuesInput);
                                 } else {
                                     $paymentDuesResult3 = PaymentDues::createPaymentDues($paymentDuesInput);
                                     //return Response:: json(array('status'=>'elsepart','data'=>$inputs ));
                                 }
                             }
                             //** Working on Payment Master **//
                             if ($i == 3) {
                                 $payment_master_data1 = PaymentMaster::createPaymentMaster($paymentDuesResult1);
                                 //** handling for Order table payment No **//
                                 $update_payment_due = PaymentDues::whereIn('id', array($paymentDuesResult1->id, $paymentDuesResult2->id))->update(array('payment_no' => $payment_master_data1->payment_no));
                                 $payment_master_data2 = PaymentMaster::createPaymentMaster($paymentDuesResult2);
                                 $update_payment_due = PaymentDues::find($paymentDuesResult3->id);
                                 $update_payment_due->payment_no = $payment_master_data2->payment_no;
                                 $update_payment_due->save();
                                 $order['customer_id'] = $paymentDuesResult1->customer_id;
                                 $order['student_id'] = $paymentDuesResult1->student_id;
                                 $order['payment_no'] = $payment_master_data1->payment_no;
                                 $order['payment_for'] = 'enrollment';
                                 $order['payment_mode'] = $inputs['paymentTypeRadio'];
                                 if ($inputs['paymentTypeRadio'] == 'cheque') {
                                     $order['bank_name'] = $inputs['bankName'];
                                     $order['cheque_number'] = $inputs['chequeNumber'];
                                 } else {
                                     if ($inputs['paymentTypeRadio'] == 'card') {
                                         $order['card_last_digit'] = $inputs['card4digits'];
                                         $order['card_type'] = $inputs['cardType'];
                                         $order['bank_name'] = $inputs['bankName'];
                                         $order['receipt_number'] = $inputs['cardRecieptNumber'];
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $orderCreated = Orders::createOrder($order);
                 $orderPaymentMasterUpdate = PaymentMaster::where('payment_no', '=', $orderCreated->payment_no)->update(array('order_id' => $orderCreated->id));
                 //return Response::json(array('status'=>'success','data'=>$inputs));
                 //** second batch enrollment completed**//
             }
             if ($orderCreated) {
                 return Response::json(array('status' => 'success', 'data' => $order));
             } else {
                 return Response::json(array('status' => 'failure'));
             }
         } else {
             if ($inputs['batchCbx3'] != '' && $inputs['eligibleClassesCbx3'] != '' && $inputs['batchCbx2'] != '' && $inputs['eligibleClassesCbx2'] != '' && $inputs['batchCbx'] != '' && $inputs['eligibleClassesCbx'] != '') {
                 //********* working out for 3 batches ************//
                 if ($inputs['paymentOptionsRadio'] == 'singlepay') {
                     //working out for first batch enrollment
                     $studentClasses1['classId'] = $inputs['eligibleClassesCbx'];
                     $studentClasses1['batchId'] = $inputs['batchCbx'];
                     $studentClasses1['studentId'] = $inputs['studentId'];
                     $studentClasses1['seasonId'] = $inputs['SeasonsCbx'];
                     $firstBatchstartDate = Carbon::createFromFormat('Y-m-d', $inputs['enrollmentStartDate']);
                     $firstbatch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx'])->where('schedule_date', '>=', $firstBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                     $studentClasses1['selected_sessions'] = count($firstbatch_data);
                     $studentClasses1['enrollment_start_date'] = $firstbatch_data[0]['schedule_date'];
                     $studentClasses1['enrollment_end_date'] = $firstbatch_data[count($firstbatch_data) - 1]['schedule_date'];
                     $firstBatchendDate = Carbon::createFromFormat('Y-m-d', $firstbatch_data[count($firstbatch_data) - 1]['schedule_date']);
                     $enrollment1 = StudentClasses::addStudentClass($studentClasses1);
                     //** first batch enrollment completed**//
                     //** working out for second batch enrollment **//
                     $studentClasses2['classId'] = $inputs['eligibleClassesCbx2'];
                     $studentClasses2['batchId'] = $inputs['batchCbx2'];
                     $studentClasses2['studentId'] = $inputs['studentId'];
                     $studentClasses2['seasonId'] = $inputs['SeasonsCbx2'];
                     $secondBatchstartDate = $firstBatchendDate->next(Carbon::MONDAY);
                     //** To get the proper selected No of sessions from second batch **/
                     $selectedNoOfSessionsForSecondBatch = $inputs['selectedSessions'] - count($firstbatch_data);
                     $secondbatch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx2'])->where('schedule_date', '>=', $secondBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->get();
                     $studentClasses2['selected_sessions'] = count($secondbatch_data);
                     $studentClasses2['enrollment_start_date'] = $secondbatch_data[0]['schedule_date'];
                     $studentClasses2['enrollment_end_date'] = $secondbatch_data[count($secondbatch_data) - 1]['schedule_date'];
                     $secondBatchendDate = Carbon::createFromFormat('Y-m-d', $secondbatch_data[count($secondbatch_data) - 1]['schedule_date']);
                     $enrollment2 = StudentClasses::addStudentClass($studentClasses2);
                     //** second batch enrollment completed**//
                     //** working  on third batch enrollment **//
                     $studentClasses3['classId'] = $inputs['eligibleClassesCbx3'];
                     $studentClasses3['batchId'] = $inputs['batchCbx3'];
                     $studentClasses3['studentId'] = $inputs['studentId'];
                     $studentClasses3['seasonId'] = $inputs['SeasonsCbx3'];
                     $thirdBatchstartDate = $secondBatchendDate->next(Carbon::MONDAY);
                     //** To get the proper selected No of sessions from second batch **/
                     $selectedNoOfSessionsForThirdBatch = $inputs['selectedSessions'] - (count($firstbatch_data) + count($secondbatch_data));
                     $thirdbatch_data = BatchSchedule::where('batch_id', '=', $inputs['batchCbx3'])->where('schedule_date', '>=', $thirdBatchstartDate->toDateString())->where('holiday', '!=', 1)->orderBy('id')->take($selectedNoOfSessionsForThirdBatch)->get();
                     $studentClasses3['selected_sessions'] = count($thirdbatch_data);
                     $studentClasses3['enrollment_start_date'] = $thirdbatch_data[0]['schedule_date'];
                     $studentClasses3['enrollment_end_date'] = $thirdbatch_data[count($thirdbatch_data) - 1]['schedule_date'];
                     $thirdBatchendDate = Carbon::createFromFormat('Y-m-d', $thirdbatch_data[count($thirdbatch_data) - 1]['schedule_date']);
                     $enrollment3 = StudentClasses::addStudentClass($studentClasses3);
                     //** third batch enrollment completed**//
                     // ********working out for  payment Dues and Order table (singlepay)*********//
                     $paymentDuesInput1['student_id'] = $inputs['studentId'];
                     $paymentDuesInput1['customer_id'] = $inputs['customerId'];
                     $paymentDuesInput1['batch_id'] = $inputs['batchCbx'];
                     $paymentDuesInput1['class_id'] = $inputs['eligibleClassesCbx'];
                     $paymentDuesInput1['selected_sessions'] = $inputs['selectedSessions'];
                     $paymentDuesInput1['seasonId'] = $inputs['SeasonsCbx'];
                     $paymentDuesInput2['student_id'] = $inputs['studentId'];
                     $paymentDuesInput2['customer_id'] = $inputs['customerId'];
                     $paymentDuesInput2['batch_id'] = $inputs['batchCbx2'];
                     $paymentDuesInput2['class_id'] = $inputs['eligibleClassesCbx2'];
                     $paymentDuesInput2['selected_sessions'] = $inputs['selectedSessions'];
                     $paymentDuesInput2['seasonId'] = $inputs['SeasonsCbx2'];
                     $paymentDuesInput3['student_id'] = $inputs['studentId'];
                     $paymentDuesInput3['customer_id'] = $inputs['customerId'];
                     $paymentDuesInput3['batch_id'] = $inputs['batchCbx3'];
                     $paymentDuesInput3['class_id'] = $inputs['eligibleClassesCbx3'];
                     $paymentDuesInput3['selected_sessions'] = $inputs['selectedSessions'];
                     $paymentDuesInput3['seasonId'] = $inputs['SeasonsCbx3'];
                     //**getting value for each class amount for specific batch **//
                     $firstBatchDataForEachClassCost = Batches::where('id', '=', $inputs['batchCbx'])->select('class_amount')->get();
                     $secondBatchDataForEachClassCost = Batches::where('id', '=', $inputs['batchCbx2'])->select('class_amount')->get();
                     $thirdBatchDataForEachClassCost = Batches::where('id', '=', $inputs['batchCbx3'])->select('class_amount')->get();
                     $paymentDuesInput1['each_class_cost'] = $firstBatchDataForEachClassCost[0]['class_amount'];
                     $paymentDuesInput2['each_class_cost'] = $secondBatchDataForEachClassCost[0]['class_amount'];
                     $paymentDuesInput3['each_class_cost'] = $thirdBatchDataForEachClassCost[0]['class_amount'];
                     $order['customer_id'] = $inputs['customerId'];
                     $order['student_id'] = $inputs['studentId'];
                     //$order['seasonId']        = $inputs['SeasonsCbx'];
                     //$order['student_classes_id'] = $enrollment1->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'];
                     $paymentDuesInput1['start_order_date'] = $studentClasses1['enrollment_start_date'];
                     $paymentDuesInput1['end_order_date'] = $studentClasses1['enrollment_end_date'];
                     $paymentDuesInput1['payment_due_amount'] = count($firstbatch_data) * $firstBatchDataForEachClassCost[0]['class_amount'];
                     $paymentDuesInput1['payment_type'] = $inputs['paymentOptionsRadio'];
                     $paymentDuesInput1['payment_status'] = "paid";
                     $paymentDuesInput2['start_order_date'] = $studentClasses2['enrollment_start_date'];
                     $paymentDuesInput2['end_order_date'] = $studentClasses2['enrollment_end_date'];
                     $paymentDuesInput2['payment_due_amount'] = count($secondbatch_data) * $secondBatchDataForEachClassCost[0]['class_amount'];
                     $paymentDuesInput2['payment_type'] = $inputs['paymentOptionsRadio'];
                     $paymentDuesInput2['payment_status'] = "paid";
                     $paymentDuesInput3['start_order_date'] = $studentClasses3['enrollment_start_date'];
                     $paymentDuesInput3['end_order_date'] = $studentClasses3['enrollment_end_date'];
                     $paymentDuesInput3['payment_due_amount'] = count($thirdbatch_data) * $thirdBatchDataForEachClassCost[0]['class_amount'];
                     $paymentDuesInput3['payment_type'] = $inputs['paymentOptionsRadio'];
                     $paymentDuesInput3['payment_status'] = "paid";
                     //** checking for Discount  applied by Discount Amount or Discount Percentage **//
                     if ($inputs['discountPercentage'] != '') {
                         $paymentDuesInput1['discount_applied'] = $inputs['discountPercentage'];
                         $paymentDuesInput1['discount_amount'] = 0;
                         //$paymentDuesInput1['discount_amount']=((($inputs['discountPercentage'])/100) *(count($firstbatch_data)*$firstBatchDataForEachClassCost[0]['class_amount']));
                         $paymentDuesInput2['discount_applied'] = $inputs['discountPercentage'];
                         $paymentDuesInput2['discount_amount'] = 0;
                         //$paymentDuesInput2['discount_amount']=((($inputs['discountPercentage'])/100) *(count($secondbatch_data)*$secondBatchDataForEachClassCost[0]['class_amount']));
                         $paymentDuesInput3['discount_applied'] = $inputs['discountPercentage'];
                         $paymentDuesInput3['discount_amount'] = 0;
                         //$paymentDuesInput3['discount_amount']=((($inputs['discountPercentage'])/100) *(count($thirdbatch_data)*$thirdBatchDataForEachClassCost[0]['class_amount']));
                     } else {
                         $paymentDuesInput1['discount_applied'] = '0';
                         //** removing minus from discount textbox **//
                         $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                         $paymentDuesInput1['discount_amount'] = $explodedDiscountAmount[1];
                         $paymentDuesInput1['discount_amount'] = $paymentDuesInput1['discount_amount'];
                         $paymentDuesInput2['discount_applied'] = '0';
                         //** removing minus from discount textbox **//
                         $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                         $paymentDuesInput2['discount_amount'] = $explodedDiscountAmount[1];
                         $paymentDuesInput2['discount_amount'] = $paymentDuesInput2['discount_amount'];
                         $paymentDuesInput3['discount_applied'] = '0';
                         //** removing minus from discount textbox **//
                         $explodedDiscountAmount = explode("-", $inputs['discountTextBox']);
                         $paymentDuesInput3['discount_amount'] = $explodedDiscountAmount[1];
                         $paymentDuesInput3['discount_amount'] = $paymentDuesInput3['discount_amount'];
                     }
                     $paymentDuesInput1['student_class_id'] = $enrollment1->id;
                     $paymentDuesInput1['selected_order_sessions'] = count($firstbatch_data);
                     $paymentDuesInput2['student_class_id'] = $enrollment2->id;
                     $paymentDuesInput2['selected_order_sessions'] = count($secondbatch_data);
                     $paymentDuesInput3['student_class_id'] = $enrollment3->id;
                     $paymentDuesInput3['selected_order_sessions'] = count($thirdbatch_data);
                     $order['amount'] = $inputs['singlePayAmount'];
                     if ($inputs['CustomerType'] == 'OldCustomer') {
                         $paymentDuesInput1['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                         $paymentDuesInput2['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                         $paymentDuesInput3['created_at'] = date('Y-m-d H:i:s', strtotime($inputs['OrderDate']));
                         $order['created_at'] = $paymentDuesInput['created_at'];
                     }
                     $paymentDuesResult1 = PaymentDues::createPaymentDues($paymentDuesInput1);
                     $payment_master_data1 = PaymentMaster::createPaymentMaster($paymentDuesResult1);
                     $paymentDuesResult2 = PaymentDues::createPaymentDues($paymentDuesInput2);
                     $payment_master_data2 = PaymentMaster::createPaymentMasterWithSamePaymentNo($paymentDuesResult2, $payment_master_data1->payment_no);
                     $paymentDuesResult3 = PaymentDues::createPaymentDues($paymentDuesInput3);
                     $payment_master_data3 = PaymentMaster::createPaymentMasterWithSamePaymentNo($paymentDuesResult3, $payment_master_data2->payment_no);
                     $update_payment_due = PaymentDues::whereIn('id', array($paymentDuesResult1->id, $paymentDuesResult2->id, $paymentDuesResult3->id))->update(array('payment_no' => $payment_master_data1->payment_no));
                     //** paymentDue table Insertion Complete and working for order,followups**//
                     //$order['payment_dues_id']   = $paymentDuesResult->id;
                     $order['order_status'] = "completed";
                     if ($inputs['selectedSessions'] > 8) {
                         // ** working for single pay 1 batch followup (minimum 8 session required)**//
                         $presentDate = Carbon::now();
                         $session_number = (int) ($inputs['selectedSessions'] / 2);
                         $customer_log_data['customer_id'] = $paymentDuesResult1->customer_id;
                         $customer_log_data['student_id'] = $paymentDuesResult1->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';
                         if ($session_number <= count($firstbatch_data)) {
                             $customer_log_data['reminderDate'] = $firstbatch_data[$session_number - 1]['schedule_date'];
                             $remindDate = $remindDate->createFromFormat('Y-m-d', $customer_log_data['reminderDate']);
                             if ($remindDate->gt($presentDate)) {
                                 $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult1, $payment_master_data1->payment_no);
                                 $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                 Comments::addSinglePayComment($customer_log_data);
                             }
                         } else {
                             if ($session_number > count($firstbatch_data) && $session_number <= count($firstbatch_data) + count($secondbatch_data)) {
                                 $session_number = $session_number - count($firstbatch_data) - 1;
                                 $customer_log_data['reminderDate'] = $secondbatch_data[$session_number]['schedule_date'];
                                 $remindDate = Carbon::now();
                                 $remindDate = $remindDate->createFromFormat('Y-m-d', $customer_log_data['reminderDate']);
                                 if ($remindDate->gt($presentDate)) {
                                     $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult2, $payment_master_data1->payment_no);
                                     //    return Response::json(array('firstbatchcount'=>count($firstbatch_data),'session_number'=>$session_number,'secondbatchcount'=>count($secondbatch_data)));
                                     $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                     Comments::addSinglePayComment($customer_log_data);
                                 }
                                 //return Response::json(array('status'=>'afterifloop'));
                             } else {
                                 if ($session_number > count($firstbatch_data) + count($secondbatch_data)) {
                                     $session_number = $session_number - (count($firstbatch_data) + count($secondbatch_data)) - 1;
                                     $customer_log_data['reminderDate'] = $secondbatch_data[$session_number]['schedule_date'];
                                     $remindDate = Carbon::now();
                                     $remindDate = $remindDate->createFromFormat('Y-m-d', $customer_log_data['reminderDate']);
                                     if ($remindDate->gt($presentDate)) {
                                         $payment_followup_data = PaymentFollowups::createPaymentFollowup($paymentDuesResult3, $payment_master_data1->payment_no);
                                         $customer_log_data['paymentfollowup_id'] = $payment_followup_data->id;
                                         Comments::addSinglePayComment($customer_log_data);
                                     }
                                 }
                             }
                         }
                         //$remindDate=Carbon::now();
                     }
                     //** Followup for single pay 1 batch  is completed **//
                     $orderCreated = Orders::createOrder($order);
                     $orderPaymentMasterUpdate = PaymentMaster::where('payment_no', '=', $payment_master_data1->payment_no)->update(array('order_id' => $orderCreated->id));
                 }
             }
         }
     }
     return Response::json(array('status' => 'success', 'data' => $inputs));
 }
Exemple #3
0
        $inputs = Input::all();
        $id = $inputs['id'];
        $countryCode = $inputs['countryCode'];
        $cities = Cities::getCities($id, $countryCode);
        return Response::json($cities);
    });
    Route::get('logout', "VaultController@logout");
});
Route::get('/test', function () {
    $base_price_no = Batches::find(130)->classes()->select('base_price_no')->get();
    $base_price_no = $base_price_no[0]['base_price_no'];
    echo $base_price_no;
    die;
    var_dump(ClassBasePrice::where('base_price_no', '=', Batches::find(130)->classes()->base_price_no)->select('base_price')->get());
    $classes_count = StudentClasses::where('student_id', '=', 88)->where('status', '=', 'enrolled')->distinct('class_id')->count();
    var_dump($classes_count);
    exit;
    echo PaymentMaster::max('payment_no');
    exit;
    echo Batches::where('id', '=', '2')->select('class_amount')->get();
    exit;
    $data = IntroVisit::join('students', 'student_id', '=', 'students.id')->where('introvisit.customer_id', '=', '44')->get();
    var_dump($data);
    exit;
    //  for($i=0;$i<count($birthday_data);$i++){
    //      $customer_data= Customers::where('id','=',$birthday_data[$i]['customer_id'])->get();
    //      $birthday_data[$i]['customer_name']=  $customer_data[0]['customer_name'];
    //      $birthday_data[$i]['membership']=  CustomerMembership::where('customer_id','=',$birthday_data[$i]['customer_id'])->count();
    //
    //   }
});