Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Provisiot();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Provisiot'])) {
         $model->attributes = $_POST['Provisiot'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 2
0
 public function provisiotRaportti($all, $thisYear, $thisMonth)
 {
     foreach ($all as $dataAll) {
         $id = $dataAll->id;
         // Omat
         $u = User::model()->findAll(" myyjaID='" . $id . "' ");
         $vahvistamattomat = array();
         $maksamattomat = array();
         foreach ($u as $data) {
             $o = $this->ordersDataForProvision($data->id, $thisYear, $thisMonth);
             foreach ($o as $ord) {
                 $v = date("Y-m-d", strtotime($ord->maksettu_pvm . " +14 day"));
                 $ord->hinta = $this->hintaLaske($ord, 0.3);
                 if ($v > date("Y-m-d")) {
                     $vahvistamattomat[$ord->id] = $ord->hinta;
                 } else {
                     $maksamattomat[$ord->id] = $ord->hinta;
                 }
             }
         }
         // Muut
         $u = User::model()->findAll(" paa_myyja='" . $id . "' ");
         foreach ($u as $uu) {
             if (isset($uu->id)) {
                 $criteria = new CDbCriteria();
                 $criteria->order = "  id DESC ";
                 $criteria->condition = " myyjaID='" . $uu->id . "' ";
                 $u = User::model()->findAll($criteria);
                 foreach ($u as $data) {
                     $o = $this->ordersDataForProvision($data->id, $thisYear, $thisMonth);
                     $vahvistamattomat2 = 0;
                     foreach ($o as $ord) {
                         $v = date("Y-m-d", strtotime($ord->maksettu_pvm . " +14 day"));
                         $ord->hinta = $this->hintaLaske($ord, 0.1);
                         if ($v > date("Y-m-d")) {
                             $vahvistamattomat[$ord->id] = $ord->hinta;
                         } else {
                             $maksamattomat[$ord->id] = $ord->hinta;
                         }
                     }
                 }
             }
         }
         //echo 'id '.$id.' '.array_sum($vahvistamattomat).'<br>';
         $pr = new Provisiot();
         $pr->myyja_id = $id;
         $pr->vuosi = $thisYear;
         $pr->kuukausi = $thisMonth;
         if (array_sum($vahvistamattomat) > 0) {
             $pr->vahvistamattomat_id = json_encode($vahvistamattomat);
             $pr->vahvistamattomat = round(array_sum($vahvistamattomat), 2);
         }
         if (array_sum($maksamattomat) > 0) {
             /*
                echo '<pre>'.$id;
                print_r($maksamattomat);
                echo '</pre>';
             */
             $pr->maksettu_id = json_encode($maksamattomat);
             $pr->maksetut = round(array_sum($maksamattomat), 2);
         } else {
             $pr->maksetut = 0;
         }
         $pr->save();
     }
 }