public function delete()
 {
     $usr_id = Auth::user()->id;
     if (User::destroy($usr_id)) {
         Thread::where('user_id', '=', $usr_id)->delete();
         Relation::where('user_id', '=', $usr_id)->delete();
         Comment::where('user_id', '=', $usr_id)->delete();
     }
 }
 public function deleteThreadById($id)
 {
     $user = User::findOrFail(Auth::user()->id);
     if (Thread::where('id', '=', $id)->where('user_id', '=', $user->id)->delete()) {
         Relation::where('thread_id', '=', $id)->delete();
         Comment::where('thread_id', '=', $id)->delete();
         return Response::json(['response' => true]);
     } else {
         return Response::json(['response' => false]);
     }
 }
Пример #3
0
 public function testCreateRelationsEndpoint()
 {
     $this->delete('/relations');
     $data = array("org_name" => "Paradise Island", "daughters" => array(0 => array("org_name" => "Banana tree", "daughters" => array(0 => array("org_name" => "Yellow Banana"), 1 => array("org_name" => "Red Banana"), 2 => array("org_name" => "Green Banana")))));
     $this->post('/relations', $data)->seeJson(['success' => true]);
     $this->assertEquals(5, Organization::get()->count());
     $this->assertEquals(4, Relation::get()->count());
     $this->post('/relations')->seeJson(['success' => false, 'error' => 'No request parameters']);
     $this->delete('/relations');
     $data = array("org_name" => "Paradise Island", "daughters" => array(0 => array("org_name" => "Banana tree", "daughters" => array(0 => array("org_name" => "Yellow Banana"), 1 => array("org_name" => "Yellow Banana"), 2 => array("org_name" => "Green Banana")))));
     $this->post('/relations', $data)->seeJson(['success' => false])->see('Duplicate organization name');
     $this->assertEquals(4, Organization::get()->count());
     $this->assertEquals(3, Relation::get()->count());
 }
 public function postComment(Request $request)
 {
     $thread = Thread::findOrFail($request->input('thread_id'));
     $user = User::where('id', '=', Auth::user()->id)->first();
     $relation = Relation::where([['user_id', '=', $user->id], ['thread_id', '=', $thread->id]])->first();
     if (empty($relation)) {
         $relation = User::find(Auth::user()->id)->threads->find($thread->id);
         if (empty($relation)) {
             return Response::json(['response' => 'error']);
         }
         $comment = new Comment(['comments' => $request->input('comments')]);
         $comment->user_id = $user->id;
         $comment->relation_id = $relation->id;
         $comment->save();
         return Response::json(['response' => 'Ok', 'comment' => $comment]);
     } else {
         $comment = new Comment(['comments' => $request->input('comments')]);
         $comment->user_id = $user->id;
         $comment->thread_id = $relation->thread_id;
         $comment->save();
         return Response::json(['response' => 'Ok', 'comment' => $comment]);
     }
 }
Пример #5
0
 public static function getRelationsByOrgId($org_id)
 {
     $target_org = Organization::find($org_id);
     if ($target_org == null) {
         return array('success' => false, 'error' => 'organization not found by ID ' . $org_id);
     }
     $result['success'] = true;
     $data = array();
     $daughters = Relation::where('parent_org_id', $org_id)->get();
     $parent = Relation::where('org_id', $org_id)->get()->first();
     $parent_org = $parent == null ? $target_org : Organization::find($parent->parent_org_id);
     //is parent organization
     if ($parent != null) {
         $data[] = array('id' => $parent->relation_id, 'type' => $parent->type, 'calculated_type' => 'parent', 'parent_org' => array('id' => $parent_org->id, 'name' => $parent_org->name), 'daughter_org' => array('id' => $target_org->id, 'name' => $target_org->name));
     }
     if ($daughters && count($daughters)) {
         foreach ($daughters as $key => $value) {
             $org = Organization::find($value->org_id);
             $data[] = array('id' => $value->relation_id, 'type' => $value->type, 'calculated_type' => 'daughter', 'parent_org' => array('id' => $parent_org->id, 'name' => $parent_org->name), 'daughter_org' => array('id' => $org->id, 'name' => $org->name));
         }
     }
     $result['data'] = $data;
     return $result;
 }
Пример #6
0
 public function relationsByClient($id)
 {
     $relations = Relation::where('client_id', '=', $id)->with('debtor')->get();
     return response()->json($relations);
 }
Пример #7
0
 public function store()
 {
     //Session::start();
     //dd(Input::file('report'));
     if (Input::file('report')) {
         $result = Excel::load(Input::file('report'), function ($reader) {
             $reader->setDateFormat('Y-m-d');
             $reader->toObject();
         }, 'UTF-8')->get();
         $resultNotJson = $result->each(function ($sheet) {
             $sheet->each(function ($row) {
             });
         });
         $resultArrayNull = json_decode($resultNotJson);
         $resultArrayVar = [];
         $resultArray = [];
         $deliveryCheck = 0;
         $invoicesCheck = 0;
         for ($i = 0; $i < count($resultArrayNull); $i++) {
             for ($j = 0; $j < count($resultArrayNull[$i]); $j++) {
                 if (!empty($resultArrayNull[$i][$j])) {
                     if ($resultArrayNull[$i][$j] == 'Накладная' || $resultArrayNull[$i][$j] == 'накладная') {
                         $deliveryCheck++;
                     }
                     if ($resultArrayNull[$i][$j] == 'Счет-фактура' || $resultArrayNull[$i][$j] == 'счет-фактура') {
                         $invoicesCheck++;
                     }
                     array_push($resultArrayVar, $resultArrayNull[$i][$j]);
                 }
             }
             if (count($resultArrayVar) > 0) {
                 array_push($resultArray, $resultArrayVar);
             }
             $resultArrayVar = [];
         }
         //dd($invoicesCheck);
         if ($deliveryCheck > 0 && $invoicesCheck > 0 && $deliveryCheck == $invoicesCheck) {
             if (count($resultArray[0] === 4) && count($resultArray[1] === 4) && count($resultArray[2] === 4) && count($resultArray[3] === 2) && count($resultArray[4] === 4)) {
                 $clientInn = $resultArray[1][3];
                 $clientName = $resultArray[1][1];
                 $debtorInn = $resultArray[2][3];
                 $debtorName = $resultArray[2][1];
                 $contractCode = strval($resultArray[3][1]);
                 $contractDate = new Carbon($resultArray[4][2]);
                 $registryVar = $resultArray[0][3];
                 $registryDate = new Carbon($resultArray[0][1]);
                 $client = Client::where('inn', '=', $clientInn)->first();
                 $debtor = Debtor::where('inn', '=', $debtorInn)->first();
                 $registryDelivery = Delivery::where('registry', '=', $registryVar)->where('client_id', '=', $client->id)->first();
                 if ($registryDelivery === null) {
                     if ($client) {
                         if ($debtor) {
                             $clientId = $client->id;
                             $debtorId = $debtor->id;
                             $relation = Relation::where('client_id', $client->id)->where('debtor_id', $debtor->id)->whereHas('contract', function ($q) use($contractCode, $contractDate) {
                                 $q->where('code', '=', $contractCode);
                                 $q->whereDate('created_at', '=', $contractDate);
                             })->first();
                             if ($relation) {
                                 $row = 0;
                                 $stop = 0;
                                 $i = 7;
                                 //dd($resultArray);
                                 while ($stop === 0) {
                                     if (isset($resultArray[$i][1]) && ($resultArray[$i][1] == 'Накладная' || $resultArray[$i][1] == 'накладная')) {
                                         $waybillDateVar = new Carbon($resultArray[$i][3]);
                                         //Дата накладной
                                         $waybillVar = strval($resultArray[$i][2]);
                                         //Накладная
                                         if (count($resultArray[$i + 1]) == 3) {
                                             $invoiceDateVar = new Carbon($resultArray[$i + 1][2]);
                                             //Дата счет фактуры
                                             $invoiceVar = $resultArray[$i + 1][1];
                                         } elseif (count($resultArray[$i + 1]) == 2) {
                                             if (strtotime($resultArray[$i + 1][1])) {
                                                 $invoiceDateVar = new Carbon($resultArray[$i + 1][1]);
                                                 //Дата счет фактуры
                                                 $invoiceVar = null;
                                             } else {
                                                 $invoiceDateVar = null;
                                                 //Дата счет фактуры
                                                 $invoiceVar = $resultArray[$i + 1][1];
                                             }
                                         } else {
                                             $invoiceVar = null;
                                             $invoiceDateVar = null;
                                         }
                                         $sum = $resultArray[$i][5];
                                         $debtDate = $resultArray[$i][4];
                                         //не используется
                                         if (isset($resultArray[$i][6])) {
                                             $notes = $resultArray[$i][6];
                                         } else {
                                             $notes = null;
                                         }
                                         $waybillExist = $relation->deliveries->where('waybill', $waybillVar)->where('date_of_waybill', $waybillDateVar->format('Y-m-d'))->first();
                                         if ($waybillExist === null) {
                                             $dateOfRecourse = clone $waybillDateVar;
                                             $dateOfRecourse->addDays($relation->deferment);
                                             //Срок оплаты
                                             $dateNowVar = new Carbon(date('Y-m-d'));
                                             //Сегодняшнее число
                                             $actualDeferment = clone $dateNowVar;
                                             $dateOfRecourseClone = clone $dateOfRecourse;
                                             $actualDeferment = $dateOfRecourseClone->diffInDays($actualDeferment, false);
                                             //Фактическая просрочка
                                             $dateOfRegress = clone $dateOfRecourse;
                                             $dateOfRegress->addDays($relation->waiting_period);
                                             //Дата регресса
                                             $theDateOfTerminationOfThePeriodOfRegression = clone $dateOfRegress;
                                             $theDateOfTerminationOfThePeriodOfRegression->addDays($relation->regress_period);
                                             //Дата окончания регресса
                                             $delivery = new Delivery();
                                             $delivery->client_id = $relation->client_id;
                                             $delivery->debtor_id = $relation->debtor_id;
                                             $delivery->relation_id = $relation->id;
                                             $delivery->waybill = $waybillVar;
                                             $delivery->waybill_amount = $sum;
                                             $rpp = $relation->rpp;
                                             $delivery->first_payment_amount = $sum / 100.0 * $rpp;
                                             $delivery->date_of_waybill = $waybillDateVar;
                                             $delivery->due_date = $relation->deferment;
                                             $delivery->date_of_recourse = $dateOfRecourse;
                                             //срок оплаты
                                             //$delivery->date_of_payment = $dateNowVar->format('Y-m-d');//дата оплаты(ложь)
                                             $delivery->date_of_regress = $dateOfRegress;
                                             $delivery->the_date_of_termination_of_the_period_of_regression = $theDateOfTerminationOfThePeriodOfRegression;
                                             $delivery->the_date_of_a_registration_supply = $dateNowVar->format('Y-m-d');
                                             $delivery->the_actual_deferment = $actualDeferment;
                                             $delivery->invoice = $invoiceVar;
                                             $delivery->date_of_invoice = $invoiceDateVar;
                                             $delivery->registry = $registryVar;
                                             $delivery->date_of_registry = $registryDate;
                                             //$delivery->date_of_funding = ;
                                             //$delivery->end_date_of_funding = $dateNowVar->format('Y-m-d');;//(ложь)
                                             $delivery->notes = $notes;
                                             $delivery->return = "";
                                             $delivery->status = 'Зарегистрирована';
                                             $delivery->state = false;
                                             $delivery->the_presence_of_the_original_document = Input::get('the_presence_of_the_original_document');
                                             if ($relation->confedential_factoring) {
                                                 $delivery->type_of_factoring = $relation->confedential_factoring;
                                             } else {
                                                 $delivery->type_of_factoring = false;
                                             }
                                             if (!$delivery->save()) {
                                                 Session::flash('success', 'Реестр успешно загружен');
                                             }
                                         } else {
                                             //накладная с таким номером существует
                                         }
                                         $i = $i + 2;
                                     } else {
                                         $stop = 1;
                                     }
                                 }
                             } else {
                                 Session::flash('danger', 'Связь между клиентом и дебитором, либо договор не найдены');
                             }
                         } else {
                             Session::flash('danger', 'Дебитор с таким ИНН не найден');
                         }
                     } else {
                         Session::flash('danger', 'Клиент с таким ИНН не найден');
                     }
                 } else {
                     Session::flash('danger', 'Реестр с таким номером уже существует');
                 }
             } else {
                 Session::flash('danger', 'Заполните все поля реестра');
             }
         } else {
             Session::flash('danger', 'Проверьте наличие ключей \'Накладная\' и \'Счет-фактура\'');
         }
     } else {
         Session::flash('danger', 'Файл не был загружен');
     }
     return Redirect::to('delivery');
 }
Пример #8
0
 public function getDeliveriesCommission($repayment)
 {
     if ($repayment->type === 1) {
         $korresp = $repayment->client;
     } else {
         $clientVar = $repayment->client->id;
         $debtorVar = $repayment->debtor->id;
         $korresp = Relation::where('client_id', '=', $clientVar)->where('debtor_id', '=', $debtorVar)->first();
     }
     $deliveries = $korresp->deliveries()->whereHas('chargeCommission', function ($query) {
         $query->where('waybill_status', false);
     })->get();
     return $deliveries;
 }
Пример #9
0
 public function update($id)
 {
     $rules = array();
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::to('relation')->withErrors($validator);
     } else {
         if (!empty(Input::get('original_documents_value'))) {
             //echo "string";
             $original_document_value = Input::get('original_documents_value');
         } else {
             //echo "string1";
             $original_document_value = 0;
         }
         $relation = Relation::find($id);
         $relation->originalDocument->type = Input::get('original_documents_select');
         $relation->originalDocument->name = Input::get('original_documents_select');
         $relation->originalDocument->value = $original_document_value;
         $relation->originalDocument->save();
         $relation->contract->code = Input::get('contract_code');
         $relation->contract->name = Input::get('contract_name');
         $relation->contract->code_1c = Input::get('contract_code_1c');
         $relation->contract->gd_debitor_1c = Input::get('contract_gd_debitor_1c');
         $relation->contract->description = Input::get('contract_description');
         $relation->contract->created_at = Input::get('contract_created_at');
         if (Input::get('contract_date_end') != NULL) {
             $relation->contract->date_end = Input::get('contract_date_end');
         }
         $relation->contract->save();
         // $relation->client_id = Input::get('client_id');
         //  $relation->debtor_id = Input::get('debtor_id');
         if (Input::get('active')) {
             $relation->active = true;
         } else {
             $relation->active = false;
         }
         $relation->confedential_factoring = Input::get('confedential_factoring');
         $relation->created_at = Input::get('created_at');
         $relation->rpp = Input::get('rpp');
         $relation->agreement_id = $relation->agreement_id;
         $relation->deferment = Input::get('deferment');
         $relation->deferment_type = Input::get('deferment_type');
         $relation->waiting_period = Input::get('waiting_period');
         $relation->waiting_period_type = Input::get('waiting_period_type');
         $relation->regress_period = Input::get('regress_period');
         $relation->regress_period_type = Input::get('regress_period_type');
         $relation->original_document_id = $relation->originalDocument->id;
         $relation->contract_id = $relation->contract->id;
         $relation->save();
         // redirect
         Session::flash('success', 'Связь сохранена');
         return Redirect::to('relation');
     }
 }
Пример #10
0
 /**
  *	get relations from database
  */
 public function show(Request $request)
 {
     $res = $request->all();
     if (isset($res['org_id']) && intval($res['org_id'])) {
         $relations = Relation::getRelationsByOrgId($res['org_id']);
         return response()->json($relations);
     } else {
         return response()->json(['success' => false, 'error' => 'Invalid org_id parameter']);
     }
 }