示例#1
0
 public static function importData()
 {
     $arr_error = [];
     $timeimport = time();
     foreach (ImportRaw::find()->where(['imported' => null])->each() as $rawData) {
         $data = $rawData->data;
         $arrayPos = self::getPosArray($rawData->type);
         //			$arrayPos = $$arrayPos;
         $codmodel = str_ireplace(' ', '', substr($data, $arrayPos['model'], 17));
         $codColor = trim(substr($data, $arrayPos['color'], 3));
         $codSalon = trim(substr($data, $arrayPos['salon'], 3));
         $codEnj = trim(substr($data, $arrayPos['enj'], 12));
         $prodOrd = trim(substr($data, $arrayPos['prod_ord'], 5));
         $carrier = trim(substr($data, $arrayPos['carrier'], 8));
         $keyCode = trim(substr($data, $arrayPos['key_code'], 5));
         $dateShipping = trim(substr($data, $arrayPos['date_shipping'], 8));
         $shipCode = trim(substr($data, $arrayPos['ship_code'], 3));
         $numInvoice = trim(substr($data, $arrayPos['num_invoice'], 16));
         $car = new Car();
         $car->model_id = CatModel::findOne(['code' => $codmodel])->id;
         $car->color_id = cats\Color::findOne(['code' => $codColor])->id;
         $car->color_sal_id = cats\ColorSalon::find()->where(['name' => $codSalon])->one()->id;
         $car->vin = $rawData->vin;
         $car->enj_num = $codEnj;
         if ($car->validate()) {
             $car->save();
         } else {
             $arr_error[] = $car->getErrorsAsString();
             //				continue;
         }
         if ($sCarmod = Car::findOne(['vin' => $rawData->vin])) {
             $impData = new ImportPlant();
             $impData->production_ord = $prodOrd;
             $impData->carrier = $carrier;
             $impData->key_code = $keyCode;
             $impData->car_id = $sCarmod->id;
             $impData->date_shipping = $dateShipping;
             $impData->ship_code = $shipCode;
             $impData->num_invoice = $numInvoice;
             if ($impData->validate()) {
                 $impData->save();
                 $car_status = new CarStatus();
                 $car_status->car_id = $sCarmod->id;
                 $car_status->status = 'way';
                 $car_status->imp_data_id = $impData->id;
                 if ($car_status->validate()) {
                     $car_status->save();
                 } else {
                     $arr_error[] = $car_status->getErrorsAsString();
                 }
             } else {
                 $arr_error[] = $impData->getErrorsAsString();
                 //					continue;
             }
         }
         $rawData->imported = $timeimport;
         $rawData->save();
     }
     return $arr_error;
 }
示例#2
0
 public function actionCustum()
 {
     $debug = '';
     $model = new Mod\Custum();
     $prompt = Yii::t('app', 'Select stock');
     $arrError = [];
     if ($model->load(Yii::$app->request->post())) {
         if (!$model->validate()) {
             $debug = print_r($model->geterrors(), true);
             return $this->render('finish', ['debug' => $debug]);
         }
         $arrvin = explode("\n", $model->vins);
         foreach ($arrvin as $vin) {
             if ($car = Mod\Car::findOne(['vin' => trim($vin)])) {
                 $status = Mod\CarStatus::findOne(['car_id' => $car->id]);
                 $status->custum_date = $model->custum_date;
                 $status->custum_num = $model->custum_num;
                 $status->save();
             } else {
                 $arrError[] = $vin . ' не найден VIN';
             }
         }
         $debug = implode('<br>', $arrError);
         return $this->render('finish', ['debug' => $debug]);
     }
     $arrVars = ['model' => $model, 'prompt' => $prompt, 'selLabel' => 'Склад', 'title' => 'Пакетное ведение деклараций'];
     return $this->render('custum', $arrVars);
 }
示例#3
0
 public function check_keyslot(Request $request)
 {
     $input = $request->only('provinceid', 'keyslot');
     $maxKeyNo = Car::where('provinceid', $input['provinceid'])->where('issold', false)->max('keyno');
     if ($maxKeyNo != null && $input['keyslot'] < $maxKeyNo) {
         return "true";
     }
 }
示例#4
0
文件: Car.php 项目: Ent-ch/stock_auto
 public static function getDiscArray($col_name)
 {
     $query = Car::find();
     $result = [];
     foreach ($query->select($col_name)->distinct()->asArray()->all() as $row) {
         $result[] = $row[$col_name];
     }
     return $result;
 }
  public function run () 
  {
  
    DB::table('car_attribs')->delete();

    $car = Car::all(); 


  
  }
 /**
  * Calculate distance traveled from the given date.
  *
  * @param  Request $request
  *
  * @return Response
  */
 public function distanceTraveledOn(Request $request)
 {
     $startDate = Carbon::parse($request->get('date'));
     $date = $startDate->format('Y-m-d');
     $cars = Car::whereIn('_id', $request->get('cars'))->get();
     $imeiTrackers = [];
     foreach ($cars as $car) {
         array_push($imeiTrackers, $car->tracker['imei']);
     }
     return Spot::whereIn('imei', $imeiTrackers)->where('time', 'LIKE', "%{$date}%")->get();
 }
 public function index()
 {
     if (!$this->hasPermission($this->menuPermissionName)) {
         return view($this->viewPermissiondeniedName);
     }
     $provinces = Province::whereHas('branchs', function ($q) {
         $q->where('isheadquarter', true);
     })->orderBy('name', 'asc')->get(['id', 'name']);
     $provinceselectlist = array();
     array_push($provinceselectlist, ':เลือกจังหวัด');
     foreach ($provinces as $item) {
         array_push($provinceselectlist, $item->id . ':' . $item->name);
     }
     if (Auth::user()->isadmin) {
         $customers = Customer::has('redLabels')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     } else {
         $customers = Customer::where('provinceid', Auth::user()->provinceid)->has('redLabels')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     }
     $customerselectlist = array();
     foreach ($customers as $item) {
         array_push($customerselectlist, $item->id . ':' . $item->title . ' ' . $item->firstname . ' ' . $item->lastname);
     }
     if (Auth::user()->isadmin) {
         $cars = Car::has('redLabel')->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']);
     } else {
         $cars = Car::where('provinceid', Auth::user()->provinceid)->has('redLabel')->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']);
     }
     $carselectlist = array();
     array_push($carselectlist, ':เลือกรถ');
     foreach ($cars as $item) {
         array_push($carselectlist, $item->id . ':' . $item->chassisno . '/' . $item->engineno);
     }
     if (Auth::user()->isadmin) {
         $carpreemptions = CarPreemption::has('redlabelhistories')->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no', 'buyercustomerid', 'salesmanemployeeid']);
     } else {
         $carpreemptions = CarPreemption::where('provinceid', Auth::user()->provinceid)->has('redlabelhistories')->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no', 'buyercustomerid', 'salesmanemployeeid']);
     }
     $carpreemptionselectlist = array();
     array_push($carpreemptionselectlist, ':เลือกการจอง');
     foreach ($carpreemptions as $item) {
         $buyercustomer = Customer::find($item->buyercustomerid);
         $buyercustomername = $buyercustomer->title . ' ' . $buyercustomer->firstname . ' ' . $buyercustomer->lastname;
         $salesmanemployee = Employee::find($item->salesmanemployeeid);
         $salesmanemployeename = $salesmanemployee->title . ' ' . $salesmanemployee->firstname . ' ' . $salesmanemployee->lastname;
         array_push($carpreemptionselectlist, $item->id . ':' . str_pad($item->bookno . '/' . $item->no, strlen($item->bookno . '/' . $item->no) + 15, " ") . str_pad($buyercustomername, strlen($buyercustomername) + 15, " ") . $salesmanemployeename);
     }
     $defaultProvince = '';
     if (Auth::user()->isadmin == false) {
         $defaultProvince = Auth::user()->provinceid;
     }
     return view('redlabel', ['provinceselectlist' => implode(";", $provinceselectlist), 'customerselectlist' => implode(";", $customerselectlist), 'carselectlist' => implode(";", $carselectlist), 'carpreemptionselectlist' => implode(";", $carpreemptionselectlist), 'defaultProvince' => $defaultProvince]);
 }
示例#8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Car::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'passengers' => $this->passengers, 'bags' => $this->bags]);
     $query->andFilterWhere(['like', 'name_en', $this->name_en])->andFilterWhere(['like', 'name_ru', $this->name_ru])->andFilterWhere(['like', 'description_en', $this->description_en])->andFilterWhere(['like', 'description_ru', $this->description_ru])->andFilterWhere(['like', 'internet', $this->internet])->andFilterWhere(['like', 'stars', $this->stars]);
     return $dataProvider;
 }
示例#9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Car::find();
     $query->joinWith('model');
     $query->joinWith('color');
     $query->joinWith('colorsal');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'model_id' => $this->model_id, 'color_id' => $this->color_id, 'color_sal_id' => $this->color_sal_id]);
     $query->andFilterWhere(['like', 'vin', $this->vin])->andFilterWhere(['like', 'enj_num', $this->enj_num]);
     return $dataProvider;
 }
示例#10
0
 public function import()
 {
     try {
         $file = Input::file('file');
         //$path = Input::file('pricelist')->getRealPath();
         $temp = null;
         Excel::load($file, function ($reader) use($temp) {
             //$reader->dump();
             $reader->skip(1);
             // Loop through all rows
             $reader->each(function ($row) {
                 $carBrand = CarBrand::where('name', 'NISSAN')->first();
                 $color = Color::where('code', trim($row->p))->first();
                 $carModel = CarModel::firstOrCreate(['name' => trim($row->c) . ' ' . trim($row->d), 'cartypeid' => $row->b, 'carbrandid' => $carBrand->id]);
                 $carSubModel = CarSubModel::firstOrCreate(['code' => trim($row->f), 'name' => trim($row->e), 'carmodelid' => $carModel->id]);
                 $car = Car::firstOrNew(['engineno' => trim($row->m), 'chassisno' => trim($row->n)]);
                 $car->datatype = 0;
                 $car->provinceid = trim($row->a);
                 $car->carmodelid = $carModel->id;
                 $car->carsubmodelid = $carSubModel->id;
                 $car->receivetype = trim($row->g);
                 $car->dealername = trim($row->h);
                 $car->no = trim($row->i);
                 $car->dodate = trim($row->j);
                 $car->dono = trim($row->k);
                 if ($row->l != null && $row->l != '') {
                     $car->receiveddate = trim($row->l);
                 }
                 if ($row->o != null && $row->o != '') {
                     $car->keyno = trim($row->o);
                 }
                 $car->colorid = $color->id;
                 $car->objective = trim($row->q);
                 if ($row->r != null && $row->r != '') {
                     $car->parklocation = trim($row->r);
                 }
                 if ($row->s != null && $row->s != '') {
                     $car->notifysolddate = trim($row->s);
                 }
                 if ($row->u != null && $row->u != '' && $row->v != null && $row->v != '') {
                     $customer = Customer::firstOrNew(['provinceid' => trim($row->a), 'title' => trim($row->u), 'firstname' => trim($row->v), 'lastname' => trim($row->w)]);
                     $customer->isreal = true;
                     if ($row->x != null && $row->x != '') {
                         $customer->phone1 = trim($row->x);
                     }
                     if ($row->y != null && $row->y != '') {
                         $customer->occupationid = trim($row->y);
                     }
                     if ($row->z != null && $row->z != '') {
                         $customer->birthdate = trim($row->z);
                     }
                     if ($row->aa != null && $row->aa != '') {
                         $customer->address = trim($row->aa);
                     }
                     $district = District::where('name', trim($row->ab))->first();
                     $amphur = Amphur::where('name', trim($row->ac))->first();
                     $province = Province::where('name', trim($row->ad))->first();
                     if ($district != null) {
                         $customer->districtid = $district->id;
                     }
                     if ($amphur != null) {
                         $customer->amphurid = $amphur->id;
                     }
                     if ($province != null) {
                         $customer->addprovinceid = $province->id;
                     }
                     if ($row->ad != null && $row->ad != '') {
                         $customer->zipcode = trim($row->ae);
                     }
                     $customer->save();
                     $car->issold = true;
                     $car->buyercustomerid = $customer->id;
                     if ($row->t != null && $row->t != '') {
                         $car->isdelivered = true;
                     }
                 }
                 $car->save();
             });
         });
     } catch (Exception $e) {
         return 'Message: ' . $e->getMessage();
     }
     return redirect()->action('CarController@index');
 }
示例#11
0
  public function getCarinfo (Request $request)
  {
    $cid = $request->input('oid');  

    $car = Car::where('id', '=', $cid)

      ->where('active', '=', 1)

      ->first();

    if (empty($car->id)) {
    
      return $this->failResponse();
    
    } else {
    
      return $this->successResponse('car', $car);
    
    }
  
  }
示例#12
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $item = \App\Models\Item::find($id);
     $document = \App\Models\Document::find($item->document_id);
     $type = $document->os_type;
     switch ($type) {
         case 'movables' || 'value_movables':
             $variable = \App\Models\Item::find($id)->variable();
             return View::make('item.edit', array('item' => $item, 'document' => $document, 'variable' => $variable));
             break;
         case 'car':
             $variable = \App\Models\Item::find($id)->variable();
             $car = \App\Models\Car::find($id)->car();
             return View::make('item.edit', array('item' => $item, 'document' => $document, 'variable' => $variable, 'car' => $car));
             break;
         case 'buildings':
             $variable = \App\Models\Item::find($id)->variable();
             $building = \App\Models\Item::find($id)->building();
             $address = \App\Models\Address::find($id)->address();
             return View::make('item.edit', array('item' => $item, 'document' => $document, 'building' => $building, 'variable' => $variable, 'address' => $address));
             break;
         case 'parcels':
             $parcel = \App\Models\Item::find($id)->parcel();
             $address = \App\Models\Address::find($id)->address();
             return View::make('item.edit', array('item' => $item, 'document' => $document, 'parcel' => $parcel, 'address' => $address));
             break;
     }
 }
示例#13
0
 public function readSelectlistForDisplayInGrid()
 {
     $carsubmodelids = Car::distinct()->lists('carsubmodelid');
     $carsubmodels = CarSubModel::whereIn('id', $carsubmodelids)->orderBy('name', 'asc')->get(['id', 'name']);
     $carsubmodelselectlist = array();
     array_push($carsubmodelselectlist, ':เลือกรุ่น');
     foreach ($carsubmodels as $item) {
         array_push($carsubmodelselectlist, $item->id . ':' . $item->name);
     }
     $colorids = Car::distinct()->lists('colorid');
     $colors = Color::whereIn('id', $colorids)->orderBy('code', 'asc')->get(['id', 'code', 'name']);
     $colorselectlist = array();
     array_push($colorselectlist, ':เลือกสี');
     foreach ($colors as $item) {
         array_push($colorselectlist, $item->id . ':' . $item->code . ' - ' . $item->name);
     }
     return ['carsubmodelselectlist' => implode(";", $carsubmodelselectlist), 'colorselectlist' => implode(";", $colorselectlist)];
 }
示例#14
0
  public function postPay(Request $request) 
  {
    /*
     * 防止表单重复提交
     * 
     * Session 存入表单令牌
     */
    if (Session::get('order_submit') == $request->input('form_code')) {

      $mb = $request->input('mb');

      if (empty($mb) || $mb == 'false') {
    
        return redirect('/order/pay?order=' . Session::get('order_code'));

      } else {
      
      
      }
    
    } else {

      Session::put('order_submit', $request->input('form_code'));
    
    }


    $user = Auth::user();

    $carHand = $request->input('car_hand');

    $required = null;

    if ($carHand == 'one') {

      $required = array (
      
        'good' => 'required',

        'num' => 'required|min:1',

        'car' => 'required',

        'receiver' => 'required'
      
      );

    } elseif ($carHand == 'second') {

      $required = array (
      
        'good' => 'required',

        'num' => 'required|min:1',

        'receiver' => 'required'
      
      );

    }

    $validate = Validator::make($request->input(), $required);

    if ($validate->fails()) {
    
      $failed = $validate->failed();
    
      return redirect()->back();
    
    }

    //获取输入参数
    $params = $request->input();

    //获取商品价格
    $gprice = GoodAttribsInfo::where('gid', '=', $params['good'])    

            ->where('acode', '=', 'price')

            ->first();

    //订单 
    $newOrder = [
    
      'code' => $this->generateOrderCode($user->id),

      'uid' => $user->id,

      'rid' => $params['receiver'],

      'cid' => $params['car'],

      'gid' => $params['good'],

      'num' => $params['num'], 

      'sum' => $gprice->value * $params['num'],

      'comment' => empty($params['comment']) ? null : $params['comment'],

      'status' => 0,

      'active' => 1
    
    ];

    //新建订单:
    $order = Order::create($newOrder);

    //记录用户选择的车型
    $car = Car::where('uid', '=', $user->id)

      ->where('last_used', '=', 1)

      ->where('active', '=', 1)

      ->first();

    if (!empty($car->id) && ($car->id != $params['car'])) {
    
      $car->last_used = 0;

      $car->save();
      
    }

    Car::where('id', '=', $params['car'])

      ->where('active', '=', 1)

      ->update(['last_used' => 1]);

    //记录用户选择的收货地址
    $receiver = ReceiverInfo::where('uid', '=', $user->id)

      ->where('last_used', '=', 1)

      ->where('active', '=', 1)

      ->first();

    if (!empty($receiver->id) && ($receiver->id != $params['receiver'])) {

      $receiver->last_used = 0;

      $receiver->save();

    }

    ReceiverInfo::where('id', '=', $params['receiver'])

      ->where('active', '=', 1)

      ->update(['last_used' => 1]);

    Session::put('order_code', $order->code);

    //检测优惠券是否可用
    $note = $this->measureDiscount($params); 

    $reduction = $note['reduction'];

    //订单最终价格
    $extraFee = 0;

    $orderPrices = [
    
      'oid' => $order->id,

      'orig_price' => $order->sum,

      'cut_fee' => $reduction,

      'extra_fee' => $extraFee,

      'final_price' => ($order->sum - $reduction + $extraFee),

      'active' => 1
    
    ];

    $op = OrderPrice::create($orderPrices);

    //记录优惠券使用信息
    foreach ($note['availableBouns'] as $boun) {

      $bobj = Boun::where('code', '=', $boun)

        ->where('active', '=', 1)

        ->first();

      if (!empty($bobj)) {
    
        OrderBoun::create([
        
          'oid' => $order->id,

          'uid' => $user->id,
        
          'bcode' => $boun,

          'btype' => $bobj->type,

          'rewarded' => 0,

          'success' => 0,

          'owner_id' => $bobj->uid
        
        ]);

      }
    
    }

    $good = Good::where('id', '=', $order->gid)->first();

    $receiver = ReceiverInfo::where('id', '=', $order->rid)->first();

    $pay_token = md5($order->id . time());

    $banks = Bank::all();

    $data = [
    
      'reduction' => $reduction,

      'order' => $order,

      'orderPrice' => $op,

      'note' => $note,

      'good' => $good,

      'receiver' => $receiver,

      'pay_token' => $pay_token,

      'banks' => $banks,

      'is_pay' => true,

      'wTitle' => '订单支付'
    
    ];

    $mb = $request->input('mb');

    if ($mb === 'true') {

      $car = Car::where('id', '=', $order->cid)->first();

      $data['car'] = $car;

      $data['step'] = 3;

      $data['header'] = '订单支付';

      return view('mobile/minipay', $data);
    
    } else {

      return view('orders/pay', $data);

    }
  
  }
示例#15
0
 public function check_keyslot(Request $request)
 {
     if (!$this->hasPermission($this->menuPermissionName)) {
         return view($this->viewPermissiondeniedName);
     }
     $input = $request->only('provinceid', 'keyslot');
     $maxKeyNo = Car::where('provinceid', $input['provinceid'])->where('issold', false)->max('keyno');
     if ($maxKeyNo != null && $input['keyslot'] < $maxKeyNo) {
         return "true";
     }
 }
示例#16
0
 /**
  * Save user profile
  * @return boolean whether the user is created successfully
  */
 public function saveProfile()
 {
     if (YII_DEBUG) {
         error_log("[ProfileForm::saveProfile]");
     }
     if (YII_DEBUG) {
         error_log("[ProfileForm::saveProfile] attributes : " . json_encode($this->getAttributes()));
     }
     if ($this->isEditable) {
         $formData = Yii::$app->request->post('ProfileForm');
         if ($formData) {
             $this->processFileField('photo', $this->_user);
             $_email = isset($formData['email']) ? strval($formData['email']) : null;
             if ($_email && $this->_user->email !== $_email) {
                 $v = new EmailValidator();
                 $err = null;
                 if ($v->validate($_email)) {
                     $u = User::findOne(['email' => $_email]);
                     if (null !== $u) {
                         $err = 'Email already exists';
                     } else {
                         $this->_user->email = $_email;
                     }
                 } else {
                     $err = 'Not a valid email address';
                 }
                 if ($err) {
                     Yii::$app->session->addFlash('email', $err);
                 }
             }
             $_phone = isset($formData['phone']) ? strval($formData['phone']) : null;
             if ($_phone && 0 == $this->_user->phone_verified && $this->_user->phone !== $_phone) {
                 $err = User::validatePhone($_phone);
                 if (true === $err) {
                     $u = User::findOne(['phone' => $_phone]);
                     if (null !== $u) {
                         $err = 'Phone already exists';
                     } else {
                         $this->_user->phone = $_phone;
                         $this->_user->phone_verified = 0;
                         $this->_user->generatePhoneToken();
                     }
                 }
                 if (is_string($err)) {
                     Yii::$app->session->addFlash('phone', $err);
                 }
             }
             $_address = isset($formData['address']) ? strval($formData['address']) : null;
             if ($_address && 0 < strlen($_address)) {
                 $addr = Address::findOne(['address' => $_address]);
                 if (!$addr) {
                     $addr = new Address();
                     $addr->address = $_address;
                     $addr->save();
                 }
                 if (User::$_TYPE_CUSTOMER === $this->_user->user_type) {
                     $rua = RelUserAddress::findOne(['user_id' => $this->_user->id, 'address_id' => $addr->id]);
                     if (!$rua) {
                         $rua = new RelUserAddress();
                         $rua->user_id = $this->_user->id;
                         $rua->address_id = $addr->id;
                         $rua->save();
                     }
                 } else {
                     $rua = RelUserAddress::findOne(['user_id' => $this->_user->id]);
                     if (!$rua) {
                         $rua = new RelUserAddress();
                         $rua->user_id = $this->_user->id;
                     }
                     $rua->address_id = $addr->id;
                     $rua->save();
                 }
             }
             $_fName = isset($formData['firstName']) ? strval($formData['firstName']) : null;
             if (strlen($_fName) > 0 && $this->_user->first_name !== $_fName) {
                 $this->_user->first_name = $_fName;
             }
             $_lName = isset($formData['lastName']) ? strval($formData['lastName']) : null;
             if (strlen($_lName) > 0 && $this->_user->last_name !== $_lName) {
                 $this->_user->last_name = $_lName;
             }
             $_ccInfo = isset($formData['creditCardInfo']) ? strval($formData['creditCardInfo']) : null;
             if ($this->_user->ccard_info !== $_ccInfo) {
                 $this->_user->ccard_info = $_ccInfo;
             }
             if (User::$_TYPE_DRIVER === $this->_user->user_type) {
                 $this->_car = Car::findOne(['driver_id' => $this->_user->id]);
                 if (!$this->_car) {
                     $this->_car = new Car();
                     $this->_car->driver_id = $this->_user->id;
                     $this->_car->save();
                 }
                 $this->processFileField('car_photo', $this->_car);
                 $this->processFileField('license_photo', $this->_user);
                 $this->processFileField('insurance_photo', $this->_user);
                 $_priceMile = isset($formData['priceMile']) ? strval($formData['priceMile']) : null;
                 if (strlen($_priceMile) > 0 && $this->_car->price_mile !== $_priceMile) {
                     $this->_car->price_mile = $_priceMile;
                 }
                 $_carMake = isset($formData['carMake']) ? strval($formData['carMake']) : null;
                 if (strlen($_carMake) > 0 && $this->_car->make !== $_carMake) {
                     $this->_car->make = $_carMake;
                 }
                 $_carModel = isset($formData['carModel']) ? strval($formData['carModel']) : null;
                 if (strlen($_carModel) > 0 && $this->_car->model !== $_carModel) {
                     $this->_car->model = $_carModel;
                 }
                 $_carYear = isset($formData['carYear']) ? strval($formData['carYear']) : null;
                 if (strlen($_carYear) > 0 && $this->_car->year !== $_carYear) {
                     $this->_car->year = $_carYear;
                 }
                 $_licensePlateNumber = isset($formData['licensePlateNumber']) ? strval($formData['licensePlateNumber']) : null;
                 $_existing_car = Car::findOne(['license_plate' => $_licensePlateNumber]);
                 if ($_existing_car) {
                     Yii::$app->session->addFlash('license_plate', 'License plate number already registered');
                 } elseif (strlen($_licensePlateNumber) > 0 && $this->_car->license_plate !== $_licensePlateNumber) {
                     $this->_car->license_plate = $_licensePlateNumber;
                 }
                 $this->_car->save();
             }
         }
         $this->_user->save();
     }
     $this->loadData();
     return true;
 }
示例#17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCar()
 {
     return $this->hasOne(Car::className(), ['id' => 'car_id']);
 }
示例#18
0
use yii\widgets\Menu;
use yii\bootstrap\Tabs;
/* @var $this yii\web\View */
/* @var $searchModel app\models\CarSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = $title;
$this->params['breadcrumbs'][] = $this->title;
?>

<?php 
echo Menu::widget(['options' => ['class' => 'nav nav-tabs'], 'items' => [['label' => Yii::t('app', 'Cars on road'), 'url' => ['/status/index']], ['label' => Yii::t('app', 'Cars on custum'), 'url' => ['/status/custum']], ['label' => Yii::t('app', 'Cars on distr'), 'url' => ['/status/distr']]]]);
?>
	

<div class="car-index">

    <h1><?php 
//= Html::encode($this->title)
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>


    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'model_id', 'value' => 'car.model.full_name', 'label' => Yii::t('app', 'Model ID'), 'filter' => Select2::widget(['model' => $searchModel, 'attribute' => 'model_id', 'data' => ArrayHelper::map(Mod\CatModel::findAll(Mod\Car::getDiscArray('model_id')), 'id', 'full_name'), 'options' => ['placeholder' => Yii::t('app', 'Select a model')], 'pluginOptions' => ['allowClear' => true]])], ['attribute' => 'color_id', 'value' => 'car.color.name', 'label' => Yii::t('app', 'Color ID'), 'filter' => Select2::widget(['model' => $searchModel, 'attribute' => 'color_id', 'data' => ArrayHelper::map(Mod\cats\Color::findAll(Mod\Car::getDiscArray('color_id')), 'id', 'name'), 'options' => ['placeholder' => Yii::t('app', 'Select a color')], 'pluginOptions' => ['allowClear' => true]])], ['attribute' => 'color_sal_id', 'value' => 'car.colorsal.name', 'label' => Yii::t('app', 'Color Sal ID'), 'filter' => ArrayHelper::map(Mod\cats\ColorSalon::findAll(Mod\Car::getDiscArray('color_sal_id')), 'id', 'name')], ['attribute' => 'diller.name', 'label' => Yii::t('app', 'Diller')], 'custum_date:date', ['attribute' => 'vin', 'value' => 'car.vin'], ['attribute' => 'enj_num', 'value' => 'car.enj_num', 'label' => Yii::t('app', 'Enj Num')], ['attribute' => 'stock.name', 'label' => Yii::t('app', 'Stock')], ['attribute' => 'plant.date_shipping', 'label' => Yii::t('app', 'Shiping date')]]]);
?>

</div>
示例#19
0
  public function getBuy(Request $request)
  {
    $gcode = $request->input('gcode');

    $ch = $request->input('car_hand');

    if (empty($ch) || strlen($ch) == 0) {
    
      return redirect('/miniorder/cartype');

    }

    $user = Auth::user();
    
    $gcode = (empty($gcode) || strlen($gcode) == 0) ? 'beyond-three' : $gcode;

    $good = Good::where('code', '=', $gcode)->first();

    if (empty($good)) {
      
      //todo
    
    }

    $carhand = $ch == 1 ? 'one' : 'second';

    $cars = Car::where('uid', '=', $user->id)->where('car_hand', '=', $carhand)->orderBy('last_used', 'desc')->get();

    $defaultCar = Car::where('uid', '=', $user->id)->where('car_hand', '=', $carhand)->where('last_used', '=', 1)->first();

    $receivers = Receiver::where('uid', '=', $user->id)->orderBy('last_used', 'desc')->get();
        
    $defaultReceiver = Receiver::where('uid', '=', $user->id)->where('last_used', '=', 1)->first();

    $bouns = Boun::where('uid', '=', $user->id)

        ->where('type', '=', 1)
      
        ->where('active', '=', 1)

        ->get();

    $goodInfo = GoodAttribsInfo::where('gid', '=', $good->id)->where('acode', '=', 'price')->first();

    $data = [
      
      'good' => $good,

      'receivers' => $receivers,

      'defaultReceiver' => $defaultReceiver,

      'cars' => $cars,

      'defaultCar' => $defaultCar,

      'bouns' => $bouns,

      'goodInfo' => $goodInfo,

      'formCode' => md5(time()),

      'car_hand' => $carhand,

      'step' => 2,

      'header' => '确认订单'
      
    ];

    return view('mobile/pay', $data);
  
  }
 public function getbyid($id)
 {
     if (!$this->hasPermission($this->menuPermissionName)) {
         return view($this->viewPermissiondeniedName);
     }
     $model = CarPreemption::find($id);
     $customer = Customer::find($model->buyercustomerid);
     $model->customer = $customer->title . ' ' . $customer->firstname . ' ' . $customer->lastname;
     $carmodel = CarModel::find($model->carmodelid);
     $carsubmodel = CarSubModel::find($model->carsubmodelid);
     $model->carmodel = $carmodel->name . '/' . $carsubmodel->name;
     $color = Color::find($model->colorid);
     $model->carcolor = $color->code . ' - ' . $color->name;
     $pricelist = Pricelist::find($model->pricelistid);
     $model->carprice = $pricelist->sellingpricewithaccessories + $model->colorprice;
     if (Auth::user()->isadmin) {
         if ($model->carobjectivetype == 0) {
             $cars = Car::doesntHave('carPayment')->where('objective', 0)->where('carmodelid', $model->carmodelid)->where('carsubmodelid', $model->carsubmodelid)->where('colorid', $model->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']);
         } else {
             $cars = Car::doesntHave('carPayment')->where('objective', '!=', 0)->where('carmodelid', $model->carmodelid)->where('carsubmodelid', $model->carsubmodelid)->where('colorid', $model->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']);
         }
     } else {
         if ($model->carobjectivetype == 0) {
             $cars = Car::where('provinceid', Auth::user()->provinceid)->doesntHave('carPayment')->where('objective', 0)->where('carmodelid', $model->carmodelid)->where('carsubmodelid', $model->carsubmodelid)->where('colorid', $model->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']);
         } else {
             $cars = Car::where('provinceid', Auth::user()->provinceid)->doesntHave('carPayment')->where('objective', '!=', 0)->where('carmodelid', $model->carmodelid)->where('carsubmodelid', $model->carsubmodelid)->where('colorid', $model->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']);
         }
     }
     $model->cars = $cars;
     if ($model->finacecompanyid != null && $model->finacecompanyid != '') {
         $finacecompany = FinaceCompany::find($model->finacecompanyid);
         $model->finacecompany = $finacecompany->name;
     }
     if ($model->interestratetypeid != null && $model->interestratetypeid != '') {
         $interestratetype = InterestRateType::find($model->interestratetypeid);
         $model->interestratetype = $interestratetype->name;
     }
     if ($model->purchasetype == 0) {
         $model->yodjud = 0;
         $model->realprice = $model->carprice - $model->discount;
     } else {
         $model->yodjud = $model->carprice - $model->discount - $model->down + $model->accessories;
         $model->realprice = $model->carprice - $model->discount - $model->subdown;
     }
     $salesmanemployee = Employee::find($model->salesmanemployeeid);
     $model->salesmanemployee = $salesmanemployee->title . ' ' . $salesmanemployee->firstname . ' ' . $salesmanemployee->lastname;
     $approversemployee = Employee::find($model->approversemployeeid);
     $model->approversemployee = $approversemployee->title . ' ' . $approversemployee->firstname . ' ' . $approversemployee->lastname;
     if ($model->carobjectivetype == 0) {
         $registerprovince = Province::find($model->registerprovinceid);
         $model->registerprovince = $registerprovince->name;
         $redlabelhistory = Redlabelhistory::where('carpreemptionid', $id)->first();
         if ($redlabelhistory != null) {
             $redlabel = Redlabel::find($redlabelhistory->redlabelid);
             $model->redlabel = $redlabel->no;
         } else {
             $model->redlabel = "ไม่มีป้าย";
         }
     } else {
         $model->redlabel = null;
     }
     //if($cust->birthdate != null)
     //$cust->birthdate = date('d-m-Y', strtotime($cust->birthdate));
     return $model;
 }
 public function getforaccountingdetailbyid($id, $donumberformat)
 {
     if (!$this->hasPermission($this->menuPermissionName)) {
         return view($this->viewPermissiondeniedName);
     }
     $accountingdetail = new AccountingDetail();
     $accountingdetail->carpaymentid = $id;
     $carpayment = CarPayment::find($id);
     $branch = Branch::find($carpayment->branchid);
     $accountingdetail->branchname = $branch->name;
     $carpreemption = CarPreemption::find($carpayment->carpreemptionid);
     $customer = Customer::find($carpreemption->buyercustomerid);
     $accountingdetail->customername = $customer->title . $customer->firstname . ' ' . $customer->lastname;
     if ($carpayment->deliverycardate != null && $carpayment->deliverycardate != '') {
         $accountingdetail->date = date('d-m-Y', strtotime($carpayment->deliverycardate));
         $accountingdetail->deliverycardate = date('d-m-Y', strtotime($carpayment->deliverycardate));
     } else {
         $accountingdetail->date = null;
         $accountingdetail->deliverycardate = "-";
     }
     $pricelist = Pricelist::find($carpreemption->pricelistid);
     $accountingdetail->carpriceinpricelist = $pricelist->sellingpricewithaccessories;
     $accountingdetail->colorprice = $carpreemption->colorprice;
     $carwithcolorprice = $pricelist->sellingpricewithaccessories + $carpreemption->colorprice;
     $accountingdetail->carwithcolorprice = $carwithcolorprice;
     $accountingdetail->purchasetype = $carpreemption->purchasetype;
     if ($carpreemption->purchasetype == 0) {
         $openbill = $accountingdetail->carwithcolorprice - $carpreemption->discount;
     } else {
         $openbill = $accountingdetail->carwithcolorprice - $carpreemption->discount + $carpreemption->accessories + $carpayment->accessoriesfeeincludeinyodjud;
     }
     $accountingdetail->openbill = $openbill;
     $accountingdetail->accessoriesfeeincludeinyodjud = $carpayment->accessoriesfeeincludeinyodjud;
     $accountingdetail->fakeaccessories = $carpreemption->accessories;
     $accountingdetail->discount = $carpreemption->discount;
     $accountingdetail->subdown = $carpreemption->subdown;
     $realsalesprice = $carwithcolorprice + $carpayment->accessoriesfeeincludeinyodjud - $carpreemption->discount - $carpreemption->subdown;
     $accountingdetail->realsalesprice = $realsalesprice;
     $accountingdetail->accessoriesfeeactuallypaid = $carpayment->accessoriesfeeactuallypaid;
     $registrationfee = $carpreemption->registrationfeefree ? 0 : $carpreemption->registrationfee;
     $accountingdetail->registrationfee = $registrationfee;
     $accountingdetail->actualinsurancefee = $carpreemption->insurancefee;
     if ($carpreemption->purchasetype == 0) {
         $compulsorymotorinsurancefeecash = $carpreemption->compulsorymotorinsurancefeefree ? 0 : $carpreemption->compulsorymotorinsurancefee;
         $conditioncompulsorymotorinsurancefeecustomerpaid = $compulsorymotorinsurancefeecash;
         $accountingdetail->compulsorymotorinsurancefeecash = $compulsorymotorinsurancefeecash;
         $insurancefeecash = $carpreemption->insurancefeefree ? 0 : $carpreemption->insurancefee;
         $accountingdetail->insurancefeecash = $insurancefeecash;
         $accountingdetail->compulsorymotorinsurancefeefn = 0;
         $compulsorymotorinsurancefeefn = 0;
         $accountingdetail->insurancefeefn = 0;
         $insurancefeefn = 0;
         $accountingdetail->firstinstallmentpayamount = 0;
         $firstinstallmentpayamount = 0;
         $accountingdetail->installmentsinadvance = 0;
         $accountingdetail->amountperinstallment = 0;
         $accountingdetail->payinadvanceamount = 0;
         $payinadvanceamount = 0;
         $accountingdetail->insurancepremium = 0;
         $accountingdetail->totalinadvancefees = 0;
         $totalinadvancefees = 0;
         $accountingdetail->conditioninsurancefee = $carpreemption->insurancefee;
         $accountingdetail->conditioninsurancefeecustomerpaid = $insurancefeecash;
         $conditioninsurancefeecompanypaid = $carpreemption->insurancefee - $insurancefeecash;
         $accountingdetail->conditioninsurancefeecompanypaid = $conditioninsurancefeecompanypaid;
         $accountingdetail->conditioncompulsorymotorinsurancefeecustomerpaid = $compulsorymotorinsurancefeecash;
     } else {
         $compulsorymotorinsurancefeecash = 0;
         $insurancefeecash = 0;
         $compulsorymotorinsurancefeefn = $carpreemption->compulsorymotorinsurancefeefree ? 0 : $carpreemption->compulsorymotorinsurancefee;
         $conditioncompulsorymotorinsurancefeecustomerpaid = $compulsorymotorinsurancefeefn;
         $accountingdetail->compulsorymotorinsurancefeefn = $compulsorymotorinsurancefeefn;
         $insurancefeefn = $carpreemption->insurancefeefree ? 0 : $carpreemption->insurancefee;
         $accountingdetail->insurancefeefn = $insurancefeefn;
         $firstinstallmentpayamount = $carpayment->firstinstallmentpay ? $carpayment->amountperinstallment : 0;
         $accountingdetail->firstinstallmentpayamount = $firstinstallmentpayamount;
         $accountingdetail->installmentsinadvance = $carpayment->installmentsinadvance;
         $accountingdetail->amountperinstallment = $carpayment->amountperinstallment;
         $payinadvanceamount = $carpayment->installmentsinadvance * $carpayment->amountperinstallment;
         $accountingdetail->payinadvanceamount = $payinadvanceamount;
         $accountingdetail->insurancepremium = $carpayment->insurancepremium;
         $totalinadvancefees = $insurancefeefn + $compulsorymotorinsurancefeefn + $firstinstallmentpayamount + $payinadvanceamount + $carpayment->insurancepremium;
         $accountingdetail->totalinadvancefees = $totalinadvancefees;
         $accountingdetail->compulsorymotorinsurancefeecash = 0;
         $accountingdetail->insurancefeecash = 0;
         $accountingdetail->conditioninsurancefee = $carpreemption->insurancefee;
         $accountingdetail->conditioninsurancefeecustomerpaid = $insurancefeefn;
         $conditioninsurancefeecompanypaid = $carpreemption->insurancefee - $insurancefeefn;
         $accountingdetail->conditioninsurancefeecompanypaid = $conditioninsurancefeecompanypaid;
         $accountingdetail->conditioncompulsorymotorinsurancefeecustomerpaid = $compulsorymotorinsurancefeefn;
     }
     $implementfee = $carpreemption->implementfeefree ? 0 : $carpreemption->implementfee;
     $accountingdetail->implementfee = $implementfee;
     $subsidise = $carpreemption->subsidisefree ? 0 : $carpreemption->subsidise;
     $accountingdetail->subsidise = $subsidise;
     $accountingdetail->giveawaywithholdingtax = $carpreemption->giveawaywithholdingtax;
     $accountingdetail->otherfee = $carpreemption->otherfee;
     $accountingdetail->otherfeedetail = $carpreemption->otherfeedetail;
     $accountingdetail->otherfee2 = $carpreemption->otherfee2;
     $accountingdetail->otherfeedetail2 = $carpreemption->otherfeedetail2;
     $accountingdetail->otherfee3 = $carpreemption->otherfee3;
     $accountingdetail->otherfeedetail3 = $carpreemption->otherfeedetail3;
     $totalotherfee = $subsidise + $carpreemption->giveawaywithholdingtax + $carpreemption->otherfee + $carpreemption->otherfee2 + $carpreemption->otherfee3;
     $accountingdetail->totalotherfee = $totalotherfee;
     $totalotherfees = $carpayment->accessoriesfeeactuallypaid + $registrationfee + $compulsorymotorinsurancefeecash + $insurancefeecash + $implementfee + $totalotherfee;
     $accountingdetail->totalotherfees = $totalotherfees;
     $carmodel = CarModel::find($carpreemption->carmodelid);
     $carsubmodel = CarSubModel::find($carpreemption->carsubmodelid);
     $accountingdetail->submodel = $carmodel->name . '/' . $carsubmodel->name;
     $car = Car::find($carpayment->carid);
     $accountingdetail->carno = $car->no;
     $accountingdetail->engineno = $car->engineno;
     $accountingdetail->chassisno = $car->chassisno;
     $color = Color::find($car->colorid);
     $accountingdetail->color = $color->code;
     $accountingdetail->purchasetypetext = $carpreemption->purchasetype == 0 ? "C" : "F";
     $accountingdetail->down = $carpreemption->down;
     $insurancecompany = InsuranceCompany::find($carpayment->insurancecompanyid);
     if ($insurancecompany != null) {
         $accountingdetail->insurancecompany = $insurancecompany->name;
     }
     $accountingdetail->capitalinsurance = $carpayment->capitalinsurance;
     $compulsorymotorinsurancecompany = InsuranceCompany::find($carpayment->compulsorymotorinsurancecompanyid);
     if ($compulsorymotorinsurancecompany != null) {
         $accountingdetail->compulsorymotorinsurancecompany = $compulsorymotorinsurancecompany->name;
     }
     $cartype = CarType::find($carmodel->cartypeid);
     $accountingdetail->conditioncompulsorymotorinsurancefee = $cartype->actpaidincludevat;
     $accountingdetail->hascompulsorymotorinsurancefee = $cartype->actpaidincludevat == 0 ? 0 : 1;
     $conditioncompulsorymotorinsurancefeecompanypaid = $cartype->actpaidincludevat - $conditioncompulsorymotorinsurancefeecustomerpaid;
     $accountingdetail->conditioncompulsorymotorinsurancefeecompanypaid = $conditioncompulsorymotorinsurancefeecompanypaid;
     $note1insurancefee = $carpreemption->insurancefee * 100 / 107.0;
     $accountingdetail->note1insurancefee = $note1insurancefee;
     $accountingdetail->note1insurancefeeincludevat = $carpreemption->insurancefee;
     $note1insurancefeevat = $carpreemption->insurancefee - $note1insurancefee;
     $accountingdetail->note1insurancefeevat = $note1insurancefeevat;
     $accountingdetail->note1compulsorymotorinsurancefee = $cartype->actpaid;
     $accountingdetail->note1compulsorymotorinsurancefeevat = $cartype->actpaidincludevat - $cartype->actpaid;
     $accountingdetail->note1compulsorymotorinsurancefeeincludevat = $cartype->actpaidincludevat;
     $note1totalfee = $note1insurancefee + $cartype->actpaid;
     $accountingdetail->note1totalfee = $note1totalfee;
     $note1totalfeevat = $note1insurancefeevat + ($cartype->actpaidincludevat - $cartype->actpaid);
     $accountingdetail->note1totalfeevat = $note1totalfeevat;
     $note1totalfeeincludevat = $carpreemption->insurancefee + $cartype->actpaidincludevat;
     $accountingdetail->note1totalfeeincludevat = $note1totalfeeincludevat;
     $cashpledgeredlabel = $carpreemption->cashpledgeredlabel;
     $accountingdetail->cashpledgeredlabel = $cashpledgeredlabel;
     if ($cashpledgeredlabel == null || $cashpledgeredlabel == 0) {
         $accountingdetail->hascashpledgeredlabel = 0;
     } else {
         $accountingdetail->hascashpledgeredlabel = 1;
     }
     $redlabelhistory = Redlabelhistory::where('carpreemptionid', $carpreemption->id)->orderBy('id', 'desc')->first();
     if ($redlabelhistory != null) {
         if ($redlabelhistory->returndate != null) {
             $accountingdetail->redlabelreturncashpledgedate = date('d-m-Y', strtotime($redlabelhistory->returncashpledgedate));
         } else {
             $accountingdetail->redlabelreturncashpledgedate = "-";
         }
     } else {
         $accountingdetail->redlabelreturncashpledgedate = "ไม่เอาป้าย";
     }
     $cashpledge = $carpreemption->cashpledge;
     $accountingdetail->cashpledge = $cashpledge;
     $totalcashpledge = $cashpledgeredlabel - $cashpledge;
     $accountingdetail->totalcashpledge = $totalcashpledge;
     $totalcash = $realsalesprice + $totalotherfees + $totalinadvancefees + $totalcashpledge;
     $accountingdetail->totalcash = $totalcash;
     $finacecompany = FinaceCompany::find($carpreemption->finacecompanyid);
     if ($finacecompany != null) {
         $accountingdetail->finacecompany = $finacecompany->name;
     }
     $accountingdetail->incasefinace = $carpreemption->purchasetype;
     if ($carpreemption->purchasetype == 1) {
         $accountingdetail->interest = $carpreemption->interest;
         $accountingdetail->installments = $carpreemption->installments;
         $pricelist = Pricelist::find($carpreemption->pricelistid);
         $carprice = $pricelist->sellingpricewithaccessories + $carpreemption->colorprice;
         $yodjud = $carprice - $carpreemption->discount - $carpreemption->down + $carpreemption->accessories + $carpayment->accessoriesfeeincludeinyodjud;
         $yodjudwithinsurancepremium = $yodjud + $carpayment->insurancepremium;
         $accountingdetail->yodjud = $yodjudwithinsurancepremium;
         $yodjudwithinterest = $yodjudwithinsurancepremium * ($carpreemption->interest + 100) / 100.0;
         $accountingdetail->yodjudwithinterest = $yodjudwithinterest;
         $finaceprofit = $yodjudwithinterest - $yodjudwithinsurancepremium;
         $commissionfinace = CommissionFinace::where('finacecompanyid', $carpreemption->finacecompanyid)->where('interestratetypeid', $carpreemption->interestratetypeid)->where('finaceminimumprofit', '<=', $finaceprofit)->where('effectivefrom', '<=', $carpreemption->date)->where('effectiveto', '>=', $carpreemption->date)->whereHas('commissionFinaceCars', function ($query) use($carpreemption) {
             $query->where('carmodelid', $carpreemption->carmodelid)->Where(function ($query) use($carpreemption) {
                 $query->where('carsubmodelid', $carpreemption->carsubmodelid)->orWhere('carsubmodelid', 0);
             });
         })->first();
         $percentdown = $carpreemption->down * 100.0 / ($carprice - $carpreemption->discount + $carpreemption->accessories);
         $accountingdetail->comfinpercent = null;
         $comfinpercent = 0;
         $accountingdetail->comfinyear = null;
         $comfinyear = 0;
         if ($commissionfinace != null) {
             $commissionfinaceinterest = CommissionFinaceInterest::where('commissionfinaceid', $commissionfinace->id)->where('downfrom', '<=', $percentdown)->where('downto', '>=', $percentdown)->first();
             if ($commissionfinaceinterest != null) {
                 $commissionstandardinterest = 0;
                 switch ($carpreemption->installments) {
                     case 24:
                         $commissionstandardinterest = $commissionfinaceinterest->installment24;
                         break;
                     case 36:
                         $commissionstandardinterest = $commissionfinaceinterest->installment36;
                         break;
                     case 48:
                         $commissionstandardinterest = $commissionfinaceinterest->installment48;
                         break;
                     case 60:
                         $commissionstandardinterest = $commissionfinaceinterest->installment60;
                         break;
                     case 72:
                         $commissionstandardinterest = $commissionfinaceinterest->installment72;
                         break;
                     case 84:
                         $commissionstandardinterest = $commissionfinaceinterest->installment84;
                         break;
                 }
                 $commissionfinaceinterests = CommissionFinaceCom::where('commissionfinaceid', $commissionfinace->id)->orderBy('com', 'asc')->get();
                 $previousstepcom = null;
                 foreach ($commissionfinaceinterests as $item) {
                     if ($carpreemption->interestratemode == 0) {
                         $currentstepinterest = $commissionstandardinterest + $item->interestcalculationbeginning;
                     } else {
                         $currentstepinterest = $commissionstandardinterest + $item->interestcalculationending;
                     }
                     if ($carpreemption->interest == $currentstepinterest) {
                         $accountingdetail->comfinpercent = $item->com;
                         $accountingdetail->comfinyear = $commissionfinace->years;
                         $comfinpercent = $item->com;
                         $comfinyear = $commissionfinace->years;
                         break;
                     } else {
                         if ($carpreemption->interest < $currentstepinterest) {
                             if ($previousstepcom != null) {
                                 $accountingdetail->comfinpercent = $previousstepcom;
                                 $accountingdetail->comfinyear = $commissionfinace->years;
                                 $comfinpercent = $previousstepcom;
                                 $comfinyear = $commissionfinace->years;
                             } else {
                                 $accountingdetail->comfinpercent = null;
                                 $accountingdetail->comfinyear = null;
                                 $comfinpercent = 0;
                                 $comfinyear = 0;
                             }
                             break;
                         } else {
                             if ($carpreemption->interest > $currentstepinterest) {
                                 $previousstepcom = $item->com;
                             }
                         }
                     }
                 }
                 if ($accountingdetail->comfinpercent == null) {
                     if ($previousstepcom != null) {
                         $accountingdetail->comfinpercent = $previousstepcom;
                         $accountingdetail->comfinyear = $commissionfinace->years;
                         $comfinpercent = $previousstepcom;
                         $comfinyear = $commissionfinace->years;
                     }
                 }
             }
         }
         $employee = Employee::find($carpreemption->salesmanemployeeid);
         $accountingdetail->salename = $employee->title . $employee->firstname . ' ' . $employee->lastname;
         $accountingdetail->incasefinaceinsurancefee = $carpreemption->insurancefee;
         $accountingdetail->note2insurancefeewhtax = $note1insurancefee / 100.0;
         $accountingdetail->note2insurancefee = $insurancefeefn;
         $note2insurancefeeexpense = $conditioninsurancefeecompanypaid > 0 ? $conditioninsurancefeecompanypaid : 0;
         $accountingdetail->note2insurancefeeexpense = $note2insurancefeeexpense;
         $note2insurancefeeincome = $conditioninsurancefeecompanypaid < 0 ? $conditioninsurancefeecompanypaid * -1 : 0;
         $accountingdetail->note2insurancefeeincome = $note2insurancefeeincome;
         $accountingdetail->incasefinacecompulsorymotorinsurancefee = $cartype->actpaidincludevat;
         $accountingdetail->note2compulsorymotorinsurancefeewhtax = $cartype->actpaid / 100.0;
         $accountingdetail->note2compulsorymotorinsurancefee = $compulsorymotorinsurancefeefn;
         $note2compulsorymotorinsurancefeeexpense = $conditioncompulsorymotorinsurancefeecompanypaid > 0 ? $conditioncompulsorymotorinsurancefeecompanypaid : 0;
         $accountingdetail->note2compulsorymotorinsurancefeeexpense = $note2compulsorymotorinsurancefeeexpense;
         $note2compulsorymotorinsurancefeeincome = $conditioncompulsorymotorinsurancefeecompanypaid < 0 ? $conditioncompulsorymotorinsurancefeecompanypaid * -1 : 0;
         $accountingdetail->note2compulsorymotorinsurancefeeincome = $note2compulsorymotorinsurancefeeincome;
         $accountingdetail->incasefinacefirstinstallmentpayamount = $firstinstallmentpayamount;
         $accountingdetail->note2firstinstallmentpayamount = $firstinstallmentpayamount;
         $accountingdetail->incasefinacepayinadvanceamount = $payinadvanceamount;
         $accountingdetail->note2payinadvanceamount = $payinadvanceamount;
         $accountingdetail->incasefinaceinsurancepremium = $carpayment->insurancepremium;
         $accountingdetail->note2insurancepremium = $carpayment->insurancepremium;
         $totalincasefinace = $carpreemption->insurancefee + $cartype->actpaidincludevat + $firstinstallmentpayamount + $payinadvanceamount + $carpayment->insurancepremium;
         $accountingdetail->totalincasefinace = $totalincasefinace;
         $accountingdetail->incasefinacereceivedcash = $yodjudwithinsurancepremium - $totalincasefinace;
         $note2total1 = $insurancefeefn + $compulsorymotorinsurancefeefn + $firstinstallmentpayamount + $payinadvanceamount + $carpayment->insurancepremium;
         $accountingdetail->note2total1 = $note2total1;
         $note2total2 = $note2insurancefeeexpense + $note2compulsorymotorinsurancefeeexpense;
         $accountingdetail->note2total2 = $note2total2;
         $note2total3 = $note2insurancefeeincome + $note2compulsorymotorinsurancefeeincome;
         $accountingdetail->note2total3 = $note2total3;
         $accountingdetail->incasefinacesubsidise = $carpreemption->subsidise;
         $incasefinacesubsidisewithvat = $carpreemption->subsidise + $carpreemption->subsidise * 0.07000000000000001;
         $accountingdetail->incasefinacesubsidisewithvat = $incasefinacesubsidisewithvat;
         $accountingdetail->note2subsidisewhtax = $carpreemption->subsidise * 0.03;
         $note2subsidisetotal = $carpreemption->subsidise + $carpreemption->subsidise * 0.07000000000000001 - $carpreemption->subsidise * 0.03;
         $accountingdetail->note2subsidisetotal = $note2subsidisetotal;
         $incasefinacehassubsidisereceivedcash = $yodjudwithinsurancepremium - $totalincasefinace - $incasefinacesubsidisewithvat;
         $accountingdetail->incasefinacehassubsidisereceivedcash = $incasefinacehassubsidisereceivedcash;
         $note2totalwhtax = $note1insurancefee / 100.0 + $cartype->actpaid / 100.0 + $carpreemption->subsidise * 0.03;
         $accountingdetail->note2totalwhtax = $note2totalwhtax;
         //NLTH,AYCAL,KL
         if ($carpreemption->finacecompanyid == 1 || $carpreemption->finacecompanyid == 2 || $carpreemption->finacecompanyid == 4) {
             $incasefinacecomfinamountwithvat = $yodjud * ($carpreemption->interest / 100.0) * $comfinyear * ($comfinpercent / 100.0);
             $incasefinacecomfinamount = $incasefinacecomfinamountwithvat / 1.07;
             $incasefinacecomfinvat = $incasefinacecomfinamountwithvat - $incasefinacecomfinamount;
         } else {
             if ($carpreemption->finacecompanyid == 3 || $carpreemption->finacecompanyid == 5) {
                 $incasefinacecomfinamount = floor($yodjud / 1.07 * ($carpreemption->interest / 100.0) * $comfinyear * ($comfinpercent / 100.0));
                 $incasefinacecomfinvat = $incasefinacecomfinamount * 0.07000000000000001;
                 $incasefinacecomfinamountwithvat = $incasefinacecomfinamount + $incasefinacecomfinvat;
             } else {
                 if ($carpreemption->finacecompanyid == 6) {
                     $incasefinacecomfinamount = round($yodjud / 1.07 * ($carpreemption->interest / 100.0) * $comfinyear * ($comfinpercent / 100.0), 2);
                     $incasefinacecomfinvat = $incasefinacecomfinamount * 0.07000000000000001;
                     $incasefinacecomfinamountwithvat = $incasefinacecomfinamount + $incasefinacecomfinvat;
                 } else {
                     if ($carpreemption->finacecompanyid == 7) {
                         $incasefinacecomfinamount = ($carpayment->amountperinstallment / 1.07 * $carpreemption->installments - $yodjud / 1.07) * ($comfinpercent / 100.0) * 48 / $carpreemption->installments;
                         $incasefinacecomfinvat = $incasefinacecomfinamount * 0.07000000000000001;
                         $incasefinacecomfinamountwithvat = $incasefinacecomfinamount + $incasefinacecomfinvat;
                     }
                 }
             }
         }
         $accountingdetail->incasefinacecomfinamount = $incasefinacecomfinamount;
         $accountingdetail->incasefinacecomfinvat = $incasefinacecomfinvat;
         $accountingdetail->incasefinacecomfinamountwithvat = $incasefinacecomfinamountwithvat;
         $accountingdetail->incasefinacecomfinwhtax = $incasefinacecomfinamount * 0.03;
         $incasefinacecomfintotal = $incasefinacecomfinamountwithvat - $incasefinacecomfinamount * 0.03;
         $accountingdetail->incasefinacecomfintotal = $incasefinacecomfintotal;
         $commissionextra = CommissionExtra::where('finacecompanyid', $carpreemption->finacecompanyid)->where('effectivefrom', '<=', $carpreemption->date)->where('effectiveto', '>=', $carpreemption->date)->whereHas('commissionExtraCars', function ($query) use($carpreemption) {
             $query->where('carmodelid', $carpreemption->carmodelid)->Where(function ($query) use($carpreemption) {
                 $query->where('carsubmodelid', $carpreemption->carsubmodelid)->orWhere('carsubmodelid', 0);
             });
         })->first();
         if ($commissionfinace != null) {
             $accountingdetail->incasefinacecomextraamount = $commissionextra->amount;
             $incasefinacecomextraamount = $commissionextra->amount;
             $accountingdetail->incasefinacecomextravat = $commissionextra->amount * 0.07000000000000001;
             $incasefinacecomextravat = $commissionextra->amount * 0.07000000000000001;
             $incasefinacecomextraamountwithvat = $commissionextra->amount + $commissionextra->amount * 0.07000000000000001;
             $accountingdetail->incasefinacecomextraamountwithvat = $incasefinacecomextraamountwithvat;
             $accountingdetail->incasefinacecomextrawhtax = $commissionextra->amount * 0.03;
             $incasefinacecomextrawhtax = $commissionextra->amount * 0.03;
             $incasefinacecomextratotal = $incasefinacecomextraamountwithvat - $commissionextra->amount * 0.03;
             $accountingdetail->incasefinacecomextratotal = $incasefinacecomextratotal;
         } else {
             $accountingdetail->incasefinacecomextraamount = 0;
             $incasefinacecomextraamount = 0;
             $accountingdetail->incasefinacecomextravat = 0;
             $incasefinacecomextravat = 0;
             $accountingdetail->incasefinacecomextraamountwithvat = 0;
             $accountingdetail->incasefinacecomextrawhtax = 0;
             $incasefinacecomextrawhtax = 0;
             $accountingdetail->incasefinacecomextratotal = 0;
             $incasefinacecomextratotal = 0;
         }
         if ($carpayment->insurancepremium > 0) {
             $commissionpa = CommissionPA::where('finacecompanyid', $carpreemption->finacecompanyid)->where('effectivefrom', '<=', $carpreemption->date)->where('effectiveto', '>=', $carpreemption->date)->first();
             if ($commissionpa != null) {
                 $accountingdetail->incasefinacecompaamount = $commissionpa->amount;
                 $incasefinacecompaamount = $commissionpa->amount;
                 $accountingdetail->incasefinacecompavat = $commissionpa->amount * 0.07000000000000001;
                 $incasefinacecompavat = $commissionpa->amount * 0.07000000000000001;
                 $incasefinacecompaamountwithvat = $commissionpa->amount + $commissionpa->amount * 0.07000000000000001;
                 $accountingdetail->incasefinacecompaamountwithvat = $incasefinacecompaamountwithvat;
                 $accountingdetail->incasefinacecompawhtax = $commissionpa->amount * 0.03;
                 $incasefinacecompawhtax = $commissionpa->amount * 0.03;
                 $incasefinacecompatotal = $incasefinacecompaamountwithvat - $commissionpa->amount * 0.03;
                 $accountingdetail->incasefinacecompatotal = $incasefinacecompatotal;
             } else {
                 $accountingdetail->incasefinacecompaamount = 0;
                 $incasefinacecompaamount = 0;
                 $accountingdetail->incasefinacecompavat = 0;
                 $incasefinacecompavat = 0;
                 $accountingdetail->incasefinacecompaamountwithvat = 0;
                 $accountingdetail->incasefinacecompawhtax = 0;
                 $incasefinacecompawhtax = 0;
                 $accountingdetail->incasefinacecompatotal = 0;
                 $incasefinacecompatotal = 0;
             }
         } else {
             $accountingdetail->incasefinacecompaamount = 0;
             $incasefinacecompaamount = 0;
             $accountingdetail->incasefinacecompavat = 0;
             $incasefinacecompavat = 0;
             $accountingdetail->incasefinacecompaamountwithvat = 0;
             $accountingdetail->incasefinacecompawhtax = 0;
             $incasefinacecompawhtax = 0;
             $accountingdetail->incasefinacecompatotal = 0;
             $incasefinacecompatotal = 0;
         }
         $incasefinacetotalcomamount = $incasefinacecomfinamount + $incasefinacecomextraamount + $incasefinacecompaamount;
         $accountingdetail->incasefinacetotalcomamount = $incasefinacetotalcomamount;
         $incasefinacetotalcomvat = $incasefinacecomfinamount * 0.07000000000000001 + $incasefinacecomextravat + $incasefinacecompavat;
         $accountingdetail->incasefinacetotalcomvat = $incasefinacetotalcomvat;
         $incasefinacetotalcomamountwithvat = $incasefinacetotalcomamount + $incasefinacetotalcomvat;
         $accountingdetail->incasefinacetotalcomamountwithvat = $incasefinacetotalcomamountwithvat;
         $incasefinacetotalcomwhtax = $incasefinacecomfinamount * 0.03 + $incasefinacecomextrawhtax + $incasefinacecompawhtax;
         $accountingdetail->incasefinacetotalcomwhtax = $incasefinacetotalcomwhtax;
         $incasefinacetotalcomtotal = $incasefinacecomfintotal + $incasefinacecomextratotal + $incasefinacecompatotal;
         $accountingdetail->incasefinacetotalcomtotal = $incasefinacetotalcomtotal;
         $receivedcashfromfinace = round($incasefinacehassubsidisereceivedcash, 2) + round($note2totalwhtax, 2) + round($incasefinacetotalcomtotal, 2);
         $accountingdetail->receivedcashfromfinace = $receivedcashfromfinace;
         $accountingdetail->receivedcashfromfinacenet = $receivedcashfromfinace;
         $accountingdetail->receivedcashfromfinaceshort = $receivedcashfromfinace;
         $accountingdetail->receivedcashfromfinacenetshort = $receivedcashfromfinace;
         $accountingdetail->receivedcashfromfinaceover = 0;
         $accountingdetail->receivedcashfromfinacenetover = 0;
     } else {
         $yodjud = 0;
         $yodjudwithinsurancepremium = 0;
         $accountingdetail->incasefinacereceivedcash = 0;
     }
     $tradereceivableaccount2amount = $totalcash - $yodjudwithinsurancepremium;
     $accountingdetail->tradereceivableaccount2amount = $tradereceivableaccount2amount;
     $oldcarprice = $carpreemption->oldcarprice;
     $accountingdetail->oldcarprice = $oldcarprice;
     $overdue = $carpayment->overdue;
     $accountingdetail->overdue = $overdue;
     $tradereceivableaccount2remainingamount = $tradereceivableaccount2amount - $oldcarprice - $overdue;
     $accountingdetail->tradereceivableaccount2remainingamount = $tradereceivableaccount2remainingamount;
     $accountingdetail->ins = $accountingdetail->note1insurancefeeincludevat;
     //$carpreemption->insurancefee;
     $accountingdetail->prb = $accountingdetail->note1compulsorymotorinsurancefeeincludevat;
     //$carpreemption->compulsorymotorinsurancefee;
     $accountingdetail->dc = $carpreemption->accessories + $carpreemption->subdown;
     $accountingdetail->totalacc2 = $tradereceivableaccount2remainingamount;
     $accountingdetail->totalacc2short = $tradereceivableaccount2remainingamount;
     $accountingdetail->totalacc2over = 0;
     $accountingdetail->totalaccount2 = $tradereceivableaccount2remainingamount;
     $accountingdetail->totalaccount2short = $tradereceivableaccount2remainingamount;
     $accountingdetail->totalaccount2over = 0;
     $arrNotFormatted = array("id", "purchasetype", "carpaymentid", "hasinsurancefee", "hascompulsorymotorinsurancefee", "hascashpledgeredlabel", "systemcalincasefinacecomfinamount", "systemcalincasefinacecomfinvat", "systemcalincasefinacecomfinamountwithvat", "systemcalincasefinacecomfinwhtax", "systemcalincasefinacecomfintotal", "receivedcashfromfinacenet", "receivedcashfromfinacenetshort", "receivedcashfromfinacenetover", "totalaccount1", "totalaccount1short", "totalaccount1over", "totalaccount2", "totalaccount2short", "totalaccount2over", 'totalaccounts', 'totalaccountsshort', 'totalaccountsover', "invoiceno", "additionalopenbill", "deliverycardate", "cashpledgeredlabelreceiptbookno", "cashpledgeredlabelreceiptno", "cashpledgeredlabelreceiptdate", "redlabelreturncashpledgedate", "cashpledgereceiptbookno", "cashpledgereceiptno", "cashpledgereceiptdate", "incasefinacecomfinamount", "incasefinacecomfinvat", "incasefinacecomfinamountwithvat", "incasefinacecomfinwhtax", "incasefinacecomfintotal", "oldcarcomamount", 'oldcarcomdate', "adj", "insurancefeereceiptcondition", "compulsorymotorinsurancefeereceiptcondition", "payinadvanceamountreimbursementdate", "payinadvanceamountreimbursementdocno", 'insurancebilldifferent', "note1insurancefeereceiptcondition", "note1compulsorymotorinsurancefeereceiptcondition", 'insurancefeepayment', 'insurancefeepaidseparatelydate', 'insurancepremiumnet', 'insurancepremiumcom', 'insurancefeepaidseparatelytotal', 'compulsorymotorinsurancefeepayment', 'compulsorymotorinsurancefeepaidseparatelydate', 'compulsorymotorinsurancepremiumnet', 'compulsorymotorinsurancepremiumcom', 'compulsorymotorinsurancefeepaidseparatelytotal', "carno", "installmentsinadvance", "installments", "comfinyear", "createdby", "createddate", "modifiedby", "modifieddate", 'actualinsurancefee');
     if ($donumberformat == 1) {
         foreach ($accountingdetail->toArray() as $key => $value) {
             if (!in_array($key, $arrNotFormatted)) {
                 if (is_numeric($value) && (double) $value != 0.0) {
                     $value = number_format($value, 2, '.', ',');
                 } else {
                     if ($value == null || $value == '' || is_numeric($value) && (double) $value == 0.0) {
                         $value = '-';
                     }
                 }
                 $accountingdetail->{$key} = $value;
             }
         }
     }
     return $accountingdetail;
 }
示例#22
0
 /**
  * Finds the Car model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Car the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Car::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#23
0
  public function getCarinfo()
  {
    $user = Auth::user();

    $attributes = Attribute::where('spec', '=', 'file_upload')

      ->where('active', '=', 1)

      ->get();

    $carSet = Car::where('uid', '=', $user->id)

      ->where('active', '=', 1)

      ->orderBy('last_used', 'desc')

      ->orderBy('created_at', 'desc')

      ->get();

    $cars = array();

    foreach ($carSet as $car) {
    
      array_push($cars, $car);
    
    }

    $data = [

      'car_hand' => 'one',
    
      'good_attribs' => $attributes,

      'cars' => $cars,

      'carActive' => true,

      'profile' => true,

      'wTitle' => '个人中心 - 车辆信息'
    
    ];

    return view('profile/carInfo', $data);

  }
示例#24
0
use yii\helpers\ArrayHelper;
use app\models as Mod;
use kartik\select2\Select2;
/* @var $this yii\web\View */
/* @var $searchModel app\models\CarSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Cars');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="car-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create Car'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'model.code', ['attribute' => 'model_id', 'value' => 'model.full_name', 'filter' => Select2::widget(['model' => $searchModel, 'attribute' => 'model_id', 'data' => ArrayHelper::map(Mod\CatModel::findAll(Mod\Car::getDiscArray('model_id')), 'id', 'full_name'), 'options' => ['placeholder' => Yii::t('app', 'Select a model')], 'pluginOptions' => ['allowClear' => true]])], ['attribute' => 'color_id', 'value' => 'color.name', 'filter' => Select2::widget(['model' => $searchModel, 'attribute' => 'color_id', 'data' => ArrayHelper::map(Mod\cats\Color::findAll(Mod\Car::getDiscArray('color_id')), 'id', 'name'), 'options' => ['placeholder' => Yii::t('app', 'Select a color')], 'pluginOptions' => ['allowClear' => true]])], ['attribute' => 'color_sal_id', 'value' => 'colorsal.name', 'filter' => ArrayHelper::map(Mod\cats\ColorSalon::findAll(Mod\Car::getDiscArray('color_sal_id')), 'id', 'name')], 'vin', 'enj_num', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
示例#25
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         $model->provinceid = $carpreemption->provinceid;
         $model->branchid = $carpreemption->branchid;
         if ($model->insurancecompanyid == '') {
             $model->insurancecompanyid = null;
         }
         if ($model->capitalinsurance == '') {
             $model->capitalinsurance = null;
         }
         if ($model->buyerpay == '') {
             $model->buyerpay = null;
         }
         if ($model->overdue == '') {
             $model->overdue = null;
         }
         if ($model->overdueinterest == '') {
             $model->overdueinterest = null;
         }
         if ($model->totaloverdue == '') {
             $model->totaloverdue = null;
         }
         if ($model->paybytype == '') {
             $model->paybytype = null;
         }
         if ($model->paybyotherdetails == '') {
             $model->paybyotherdetails = null;
         }
         if ($model->overdueinstallments == '') {
             $model->overdueinstallments = null;
         }
         if ($model->overdueinstallmentdate1 == '') {
             $model->overdueinstallmentdate1 = null;
         }
         if ($model->overdueinstallmentamount1 == '') {
             $model->overdueinstallmentamount1 = null;
         }
         if ($model->overdueinstallmentdate2 == '') {
             $model->overdueinstallmentdate2 = null;
         }
         if ($model->overdueinstallmentamount2 == '') {
             $model->overdueinstallmentamount2 = null;
         }
         if ($model->overdueinstallmentdate3 == '') {
             $model->overdueinstallmentdate3 = null;
         }
         if ($model->overdueinstallmentamount3 == '') {
             $model->overdueinstallmentamount3 = null;
         }
         if ($model->overdueinstallmentdate4 == '') {
             $model->overdueinstallmentdate4 = null;
         }
         if ($model->overdueinstallmentamount4 == '') {
             $model->overdueinstallmentamount4 = null;
         }
         if ($model->overdueinstallmentdate5 == '') {
             $model->overdueinstallmentdate5 = null;
         }
         if ($model->overdueinstallmentamount5 == '') {
             $model->overdueinstallmentamount5 = null;
         }
         if ($model->overdueinstallmentdate6 == '') {
             $model->overdueinstallmentdate6 = null;
         }
         if ($model->overdueinstallmentamount6 == '') {
             $model->overdueinstallmentamount6 = null;
         }
         if ($model->oldcarbuyername == '') {
             $model->oldcarbuyername = null;
         }
         if ($model->oldcarpayamount == '') {
             $model->oldcarpayamount = null;
         }
         if ($model->oldcarpaytype == '') {
             $model->oldcarpaytype = null;
         }
         if ($model->oldcarpaydate == '') {
             $model->oldcarpaydate = null;
         }
         if ($model->payeeemployeeid == '') {
             $model->payeeemployeeid = null;
         }
         if ($model->deliverycarbookno == '') {
             $model->deliverycarbookno = null;
         }
         if ($model->deliverycarno == '') {
             $model->deliverycarno = null;
         }
         if ($model->deliverycardate == '') {
             $model->deliverycardate = null;
         }
         $model->createdby = Auth::user()->id;
         $model->createddate = date("Y-m-d H:i:s");
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::created(function ($model) {
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         if ($carpreemption->carobjectivetype == 0) {
             $redlabelhistory = Redlabelhistory::where('carpreemptionid', $carpreemption->id)->first();
             $redlabel = Redlabel::find($redlabelhistory->redlabelid);
             $redlabel->carid = $model->carid;
             $redlabel->customerid = $carpreemption->buyercustomerid;
             $redlabel->deposit = $carpreemption->cashpledgeredlabel;
             $redlabel->save();
         }
         if ($model->isdraft) {
             $carpreemption->status = 3;
         } else {
             $carpreemption->status = 1;
         }
         $carpreemption->save();
         $car = Car::find($model->carid);
         $car->issold = true;
         $car->buyercustomerid = $carpreemption->buyercustomerid;
         if ($model->deliverycarbookno != null && $model->deliverycarbookno != '') {
             $car->isdelivered = true;
             KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->update(['carid' => null, 'active' => true]);
         }
         $car->save();
     });
     static::updating(function ($model) {
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         $model->provinceid = $carpreemption->provinceid;
         $model->branchid = $carpreemption->branchid;
         if ($model->insurancecompanyid == '') {
             $model->insurancecompanyid = null;
         }
         if ($model->capitalinsurance == '') {
             $model->capitalinsurance = null;
         }
         if ($model->buyerpay == '') {
             $model->buyerpay = null;
         }
         if ($model->overdue == '') {
             $model->overdue = null;
         }
         if ($model->overdueinterest == '') {
             $model->overdueinterest = null;
         }
         if ($model->totaloverdue == '') {
             $model->totaloverdue = null;
         }
         if ($model->paybytype == '') {
             $model->paybytype = null;
         }
         if ($model->paybyotherdetails == '') {
             $model->paybyotherdetails = null;
         }
         if ($model->overdueinstallments == '') {
             $model->overdueinstallments = null;
         }
         if ($model->overdueinstallmentdate1 == '') {
             $model->overdueinstallmentdate1 = null;
         }
         if ($model->overdueinstallmentamount1 == '') {
             $model->overdueinstallmentamount1 = null;
         }
         if ($model->overdueinstallmentdate2 == '') {
             $model->overdueinstallmentdate2 = null;
         }
         if ($model->overdueinstallmentamount2 == '') {
             $model->overdueinstallmentamount2 = null;
         }
         if ($model->overdueinstallmentdate3 == '') {
             $model->overdueinstallmentdate3 = null;
         }
         if ($model->overdueinstallmentamount3 == '') {
             $model->overdueinstallmentamount3 = null;
         }
         if ($model->overdueinstallmentdate4 == '') {
             $model->overdueinstallmentdate4 = null;
         }
         if ($model->overdueinstallmentamount4 == '') {
             $model->overdueinstallmentamount4 = null;
         }
         if ($model->overdueinstallmentdate5 == '') {
             $model->overdueinstallmentdate5 = null;
         }
         if ($model->overdueinstallmentamount5 == '') {
             $model->overdueinstallmentamount5 = null;
         }
         if ($model->overdueinstallmentdate6 == '') {
             $model->overdueinstallmentdate6 = null;
         }
         if ($model->overdueinstallmentamount6 == '') {
             $model->overdueinstallmentamount6 = null;
         }
         if ($model->oldcarbuyername == '') {
             $model->oldcarbuyername = null;
         }
         if ($model->oldcarpayamount == '') {
             $model->oldcarpayamount = null;
         }
         if ($model->oldcarpaytype == '') {
             $model->oldcarpaytype = null;
         }
         if ($model->oldcarpaydate == '') {
             $model->oldcarpaydate = null;
         }
         if ($model->payeeemployeeid == '') {
             $model->payeeemployeeid = null;
         }
         if ($model->deliverycarbookno == '') {
             $model->deliverycarbookno = null;
         }
         if ($model->deliverycarno == '') {
             $model->deliverycarno = null;
         }
         if ($model->deliverycardate == '') {
             $model->deliverycardate = null;
         }
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::updated(function ($model) {
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         if ($model->isdraft) {
             $carpreemption->status = 3;
         } else {
             $carpreemption->status = 1;
         }
         $carpreemption->save();
         $car = Car::find($model->carid);
         if ($model->deliverycarbookno != null && $model->deliverycarbookno != '') {
             $car->isdelivered = true;
             KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->where('carid', $car->id)->update(['carid' => null, 'active' => true]);
         } else {
             $car->isdelivered = false;
             KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->whereNull('carid')->update(['carid' => $car->id, 'active' => false]);
         }
         $car->save();
     });
     static::deleted(function ($model) {
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         if ($carpreemption->carobjectivetype == 0) {
             $redlabelhistory = Redlabelhistory::where('carpreemptionid', $carpreemption->id)->first();
             $redlabel = Redlabel::find($redlabelhistory->redlabelid);
             $redlabel->carid = null;
             $redlabel->save();
         }
         $carpreemption->status = 0;
         $carpreemption->save();
         $car = Car::find($model->carid);
         $car->issold = false;
         $car->isdelivered = false;
         KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->whereNull('carid')->update(['carid' => $car->id, 'active' => false]);
     });
 }
示例#26
0
文件: User.php 项目: alexletsu/kiytes
 public function beforeSave($insert)
 {
     $blnMakeSave = parent::beforeSave($insert);
     /** @TODO: add checking on profile completion **/
     if (!$insert) {
         $blnIsComplete = true;
         $rua = RelUserAddress::findOne(['user_id' => $this->id]);
         if (!$rua || 0 == strlen($this->first_name) || 0 == strlen($this->last_name) || 0 == strlen($this->email) || 0 == strlen($this->phone) || 0 == $this->phone_verified || 0 == strlen($this->photo) || 0 == strlen($this->ccard_info)) {
             $blnIsComplete = false;
         }
         if ($blnIsComplete && User::$_TYPE_DRIVER === $this->user_type) {
             $_car = Car::findOne(['driver_id' => $this->id]);
             if (0 == strlen($this->license_photo) || 0 == strlen($this->insurance_photo) || !$_car || 0 == strlen($_car->make) || 0 == strlen($_car->model) || 0 == strlen($_car->year) || 0 == strlen($_car->license_plate) || 0 == strlen($_car->car_photo) || 0 == strlen($_car->price_mile)) {
                 $blnIsComplete = false;
             }
         }
         $this->is_complete = $blnIsComplete ? 1 : 0;
     }
     return $blnMakeSave;
 }