Ejemplo n.º 1
0
 /**
  * Creates a new Provider model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Provider();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->sub_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 public function store(ProviderRequest $request)
 {
     try {
         DB::transaction(function () use($request) {
             $inputs = $request->input();
             $time = time();
             $user = Auth::user();
             $year = CommonHelper::get_current_financial_year();
             $file = $request->file('picture');
             $provider = new Provider();
             $destinationPath = base_path() . '/public/image/provider/';
             if ($request->hasFile('picture')) {
                 $name = time() . $file->getClientOriginalName();
                 $file->move($destinationPath, $name);
                 $inputs['picture'] = $name;
                 $provider->picture = $inputs['picture'];
             }
             $provider->name = $inputs['name'];
             $provider->mobile = $inputs['mobile'];
             $provider->address = $inputs['address'];
             $provider->company_name = $inputs['company_name'];
             $provider->company_address = $inputs['company_address'];
             $provider->created_by = $user->id;
             $provider->created_at = $time;
             $provider->save();
             // Personal Account Creation
             $personal = new PersonalAccount();
             $personal->person_type = Config::get('common.person_type_provider');
             if (!empty($inputs['balance'])) {
                 $personal->balance = $inputs['balance'];
             }
             if (!empty($inputs['due'])) {
                 $personal->due = $inputs['due'];
             }
             $personal->person_id = $provider->id;
             $personal->created_by = Auth::user()->id;
             $personal->created_at = $time;
             $personal->save();
             if ($inputs['balance'] > 0) {
                 // Update Workspace Ledger
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 41000, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => $year])->first();
                 $workspaceLedger->balance += $inputs['balance'];
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_by = $time;
                 $workspaceLedger->save();
             }
             if ($inputs['due'] > 0) {
                 // Update Workspace Ledger
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 12000, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => $year])->first();
                 $workspaceLedger->balance += $inputs['due'];
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_by = $time;
                 $workspaceLedger->save();
             }
         });
     } catch (\Exception $e) {
         Session::flash('error_message', 'Failed to create Product & Service Provider. Please try again!');
         return Redirect::back();
     }
     Session::flash('flash_message', 'Product & Service Provider created successfully!');
     return redirect('providers');
 }
Ejemplo n.º 3
0
 private function _add($name, $parent_key, $ordinal, $active, $col_data)
 {
     try {
         if (in_array($name, $col_data)) {
             $this->error = true;
             $this->error_message = 'Tên nhà cung cấp đã tồn tại';
         } else {
             $Provider = new Provider();
             $Provider->name = $name;
             $Provider->create_time = date("Y-m-d H:i:s");
             $Provider->parent_key = $parent_key;
             $Provider->ordinal = $ordinal;
             $Provider->active = $active ? $active : 2;
             //1 is active and 2 is non active Provider
             $rs = $Provider->save();
             $LastInsertId = $Provider->id;
             $data = ['id' => $LastInsertId, 'name' => $name, 'create_time' => date("Y-m-d H:i:s"), 'parent_key' => $parent_key, 'ordinal' => $ordinal];
             $this->message = 'Thêm nhà cung cấp thành công !';
             return $data;
         }
     } catch (Exception $e) {
         $this->message = $e->getMessage();
         $this->error = true;
     }
 }