/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new TmpDocd(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['TmpDocd'])) { $model->attributes = $_POST['TmpDocd']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
private function readsimple($thefile, $model) { TmpXml::model()->deleteAll('user='******'user='******'user='******'ALTER TABLE tmp_xml AUTO_INCREMENT = 1;')->execute(); // $connection->createCommand('ALTER TABLE tmp_docd AUTO_INCREMENT = 1;')->execute(); $ii = 0; $jj = 0; $result = false; // $data=array(); if (file_exists($thefile)) { if (($handle = fopen($thefile, "r")) === FALSE) { return 'empty'; } while (($cols = fgetcsv($handle, 1000, ";")) !== FALSE) { $ii++; if ($ii >= $model->n_str && $ii <= $model->n_fin) { if ($jj == 0) { $jj = 1; } $data = new TmpDocd(); $xml = new TmpXml(); $data->cnom = $jj; $data->ckey = $jj; $data->user = Yii::app()->user->uid; $xml->user = Yii::app()->user->uid; $xml->ckey = $jj++; $tmp = trim($cols[$model->n_nom - 1]); $tmp = iconv('windows-1251', 'UTF-8', $tmp . ""); $tmp = str_replace('""', '"', $tmp); $tmp = preg_replace("/^\"(.*)\"\$/sim", "\$1", $tmp); $xml->cname = $tmp; $tmp = trim($cols[$model->n_art - 1]); $xml->cgr = $tmp; $xml->save(); $tmp = trim($cols[$model->n_price - 1]); // echo $tmp."/"; $tmp = str_replace(',', '.', $tmp); // echo $tmp."/"; $price = filter_var($tmp, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $tmp = trim($cols[$model->n_quant - 1]); // echo $tmp."/"; $tmp = str_replace(',', '.', $tmp); // echo $tmp."/"; $sum = filter_var($tmp, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); // echo ":".$price.":".$sum."<hr>"; $data->bpri = $price; $data->bsum = $sum; if ($price != 0) { $data->bqua = round($sum / $price, 4); } $data->save(); } } } return jj; }
/** * Manages all models. */ private function readsimple($thefile) { $clis = array(); $firs = array(); $ords = array(); $invs = array(); $inf = array(); TmpXml::model()->deleteAll('user='******'user='******'user='******'ALTER TABLE tmp_xml AUTO_INCREMENT = 1;')->execute(); // $connection->createCommand('ALTER TABLE tmp_docd AUTO_INCREMENT = 1;')->execute(); $ii = 0; $result = false; if (file_exists($thefile)) { $result = simplexml_load_file($thefile); } $db = 1; foreach ($result as $key => $value) { switch ($key) { case 'xNom': $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $value[0]->tNam; $model->cgr = (string) $value[0]->cGr; $model->ctype = 0; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $value[0]->it; $model->ctype = 10; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } break; case 'xCli': $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $value[0]->tNam; $model->cgr = (string) $value[0]->cGr; $model->ctype = 1; $model->user = Yii::app()->user->uid; if ($model->save()) { $clis[$model->ckey] = $model->cname; $ii++; } foreach ($value[0]->props[0] as $ke => $valu) { $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $ke; $model->lname = (string) $valu[0]; $model->ctype = 11; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } } foreach ($value[0]->acc[0] as $ke => $valu) { $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $ke; $model->lname = (string) $valu[0]; $model->ctype = 12; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } } break; case 'xFir': $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $value[0]->tNam; $model->ctype = 2; $model->user = Yii::app()->user->uid; if ($model->save()) { $firs[$model->ckey] = $model->cname; $ii++; } break; case 'xAcc': $model = new TmpXml(); $id = (string) $value[0]->host; foreach ($value[0] as $ke => $valu) { $model = new TmpXml(); $model->ckey = $id; $model->cname = (string) $ke; $model->lname = (string) $valu[0]; $model->ctype = 13; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } } break; case 'xGrN': $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $value[0]->tNam; $model->ctype = 3; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } break; case 'xGrC': $model = new TmpXml(); $model->ckey = (string) $value[0]->cKey; $model->cname = (string) $value[0]->tNam; $model->ctype = 4; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } break; case 'xInv': $model = new TmpDoc(); $model->id = (int) $value[0]->cKey + 100 * Yii::app()->user->uid; $model->tnum = (string) $value[0]->tNum; $model->tonum = (string) $value[0]->tONum; $model->ddat = (string) $value[0]->dDat; $model->dodat = (string) $value[0]->dODat; $model->cfir = (string) $value[0]->cFir; $model->ccli = (string) $value[0]->cCli; $model->bsum = (double) $value[0]->bSum; $model->transport = (string) $value[0]->cClix; $model->ctype = 1; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; $invs[$model->id] = array($model->tnum, $model->ddat, $model->tonum, $model->dodat); } break; case 'xOrd': $model = new TmpDoc(); $model->id = (int) $value[0]->cKey + 100 * Yii::app()->user->uid; $model->tnum = (string) $value[0]->tNum; $model->tonum = (string) $value[0]->Acc; $model->ddat = (string) $value[0]->dDat; $model->cfir = (string) $value[0]->cFir; $model->ccli = (string) $value[0]->cCli; $model->bsum = (double) $value[0]->bSum; $model->transport = (string) $value[0]->Tran; $model->dbank = (string) $value[0]->Acc; $model->cbank = (string) $value[0]->cCAc; $model->man = (int) $value[0]->Man; $model->ctype = 0; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; $ords[$model->id] = array($model->tnum, $model->ddat); } if (isset($value[0]->Inf)) { $modelx = new TmpXml(); $modelx->ckey = $model->id; $modelx->cname = (string) $value[0]->Inf; $modelx->ctype = 14; $modelx->user = Yii::app()->user->uid; if ($modelx->save()) { $ii++; } } break; case 'xInvT': $model = new TmpDocd(); $model->ckey = (int) $value[0]->cDoc + 100 * Yii::app()->user->uid; $model->cnom = (string) $value[0]->cNom; $model->bqua = (string) $value[0]->bQua; $model->bvat = (string) $value[0]->bVat; $model->bpri = (string) $value[0]->bPri; $model->bsum = (double) $value[0]->bSum; $model->state = 1; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } break; case 'xOrdT': $model = new TmpDocd(); $model->ckey = (int) $value[0]->cDoc + 100 * Yii::app()->user->uid; $model->cnom = (string) $value[0]->cNom; $model->bqua = (string) $value[0]->bQua; $model->bvat = (string) $value[0]->bVat; $model->bpri = (string) $value[0]->bPri; $model->bsum = (double) $value[0]->bSum; $model->state = 0; $model->user = Yii::app()->user->uid; if ($model->save()) { $ii++; } break; } } $ii = 0; $prods = TmpXml::model()->with('productid')->findAll('user='******'lid'] = $value['productid']['product1']['ckey']; $value['lname'] = $value['productid']['product1']['tnam']; $value['state'] = 10; $value->save(); } } $inf[] = "Товары:{$ii}"; $prods = TmpXml::model()->with('clientid')->findAll('user='******'lid'] = $value['clientid']['client1']['id']; $value['lname'] = $value['clientid']['client1']['name']; $value['state'] = 10; $value->save(); } } $inf[] = "Клиенты:{$ii}"; $prods = TmpXml::model()->with('departmentid')->findAll('user='******'lid'] = $value['departmentid']['department1']['id']; $value['lname'] = $value['departmentid']['department1']['name']; $value['state'] = 10; $value->save(); } } $inf[] = "Фирмы:{$ii}"; $prods = TmpXml::model()->with('productgroupid')->findAll('user='******'lid'] = $value['productgroupid']['productgroup1']['ckey']; $value['lname'] = $value['productgroupid']['productgroup1']['tnam']; $value['state'] = 10; $value->save(); } } $prods = TmpXml::model()->with('countryid')->findAll('user='******'lid'] = $value['countryid']['country1']['id']; $value['lname'] = $value['countryid']['country1']['name']; $value['state'] = 10; $value->save(); } } foreach ($ords as $key => $value) { $criteria = new CDbCriteria(); $Datet = $value[1]; $Datef = date('Y-m-d', strtotime($Datet . ' - 3 days')); $Datet = date('Y-m-d', strtotime($Datet . ' + 3 days')); $criteria->addCondition("date >= '{$Datef}' and t.date <= '{$Datet}'"); $exp = Exp::model()->with(array('client', 'department'))->findByAttributes(array('name' => $value[0]), $criteria); $prod = TmpDoc::model()->findByPk($key); $prod->cliname = $clis[$prod->ccli]; $prod->firname = $firs[$prod->cfir]; if (!($exp === null)) { $prod->expid = $exp->id; $prod->expinfo = $exp->name . " - " . Yii::app()->dateFormatter->formatDateTime($exp->date, 'short', null) . " - " . $exp->depname . " - " . $exp->cliname . " - " . Yii::app()->numberFormatter->formatCurrency($exp->amount, ''); } $prod->save(); } foreach ($invs as $key => $value) { $criteria = new CDbCriteria(); $Datet = $value[1]; $Datef = date('Y-m-d', strtotime($Datet . ' - 3 days')); $Datet = date('Y-m-d', strtotime($Datet . ' + 3 days')); $criteria->addCondition("t.date >= '{$Datef}' and t.date <= '{$Datet}'"); $inv = Inv::model()->with(array('exp', 'exp.client', 'exp.department'))->findByAttributes(array('name' => $value[0]), $criteria); $prod = TmpDoc::model()->findByPk($key); $prod->cliname = $clis[$prod->ccli]; $prod->firname = $firs[$prod->cfir]; if ($inv === null) { $criteria = new CDbCriteria(); $Datet = $value[3]; $Datef = date('Y-m-d', strtotime($Datet . ' - 3 days')); $Datet = date('Y-m-d', strtotime($Datet . ' + 3 days')); $criteria->addCondition("date >= '{$Datef}' and t.date <= '{$Datet}'"); $exp = Exp::model()->with(array('client', 'department'))->findByAttributes(array('name' => $value[2]), $criteria); if (!($exp === null)) { $prod->expid = $exp->id; $prod->expinfo = $exp->name . " - " . Yii::app()->dateFormatter->formatDateTime($exp->date, 'short', null) . " - " . $exp->depname . " - " . $exp->cliname . " - " . Yii::app()->numberFormatter->formatCurrency($exp->amount, ''); } } else { $prod->docid = $inv->id; $prod->docinfo = $inv->name . " - " . Yii::app()->dateFormatter->formatDateTime($inv->date, 'short', null) . " - " . Yii::app()->numberFormatter->formatCurrency($inv->amount, ''); $prod->expid = $inv->exp_id; $prod->expinfo = $inv->exp->name . " - " . Yii::app()->dateFormatter->formatDateTime($inv->exp->date, 'short', null) . " - " . $inv->depname . " - " . $inv->cliname . " - " . Yii::app()->numberFormatter->formatCurrency($inv->exp->amount, ''); } $prod->save(); } return $ii; }