public function readBkmv() { //sort $this->sortBkmvFile(); //skip for testing // //new company //get perm from ini //if (substr($line,395,1)=='2') // $encoding="ibm862"; //else $encoding = "windows-1255"; //$encoding="ibm862"; Yii::log('start Openimport', 'info', 'app'); //$bkmv = $yiiBasepath."/files/".$configPath."/openformt/bkmvdata.txt-sorted"; $bkmv = $this->bkmvFile . "-sorted"; $suc = array(); $suc['B110'] = 0; $suc['A100'] = 0; $suc['B100'] = 0; $suc['C100'] = 0; $suc['M100'] = 0; $suc['D110'] = 0; $suc['D120'] = 0; $suc['Z900'] = 0; $analze = array(); $analze['B110'] = 0; $analze['A100'] = 0; $analze['B100'] = 0; $analze['C100'] = 0; $analze['M100'] = 0; $analze['D110'] = 0; $analze['D120'] = 0; $analze['Z900'] = 0; $accType = 200; //DELETE FROM `qwe_docCheques` WHERE 1;DELETE FROM `qwe_docDetails` WHERE 1;DELETE FROM `qwe_accounts` WHERE 1;DELETE FROM `qwe_items` WHERE 1;DELETE FROM `qwe_docs` WHERE 1; if ($fp = fopen($bkmv, 'r')) { while ($line = fgets($fp)) { @($line = iconv($encoding, "UTF-8//IGNORE", $line)); //$line=utf8_encode($line); $type = substr($line, 0, 4); //$obj=$this->readline($line,$type); $obj = true; if (!$obj) { //$suc[$type]--; } else { //foreach ($obj as &$value) // if ($encoding=="ibm862") // $value = iconv("ISO-8859-8", "UTF-8", hebrev(iconv("UTF-8", "ISO-8859-8", $value))); if ($type == 'B110') { //Acc Haeder /* Account Import */ $acc = new Accounts(); $acc->readLine($line, $type); if (isset($this->accTypeIndex[$acc->type])) { $this->accDesc[$acc->type] = $this->accDesc[$acc->type] . "," . $acc->name; } else { $this->accDesc[$acc->type] = $acc->name; $this->accTypeIndex[$acc->type] = $accType; $accType++; } $acc->type = $this->accTypeIndex[$acc->type]; $acc->save(); //get new acc index save old unset($acc); //*/ } if ($type == 'M100') { //Item In Stock $item = new Item(); $item->category_id = 0; $item->parent_item_id = 0; $item->isProduct = 0; $item->profit = 0; $item->stockType = 0; $item->readLine($line, $type); $item->save(); unset($item); //*/ } if ($type == 'C100') { //Doc Haeder //return "done!"; //Yii::app()->end(); //find type //global $DocOpenType; $doc = new Docs(); $doc->readLine($line, $type); $doc->status = 1; //needtoChange //Yii::log($doc,'info','app'); $doc->save(); unset($doc); /* if ((isset($DocOpenType[$obj['doctype']])) && (isset($accIndex[$obj['account']]))){ $obj['doctype']=$DocOpenType[$obj['doctype']]; $doc=new document($obj['doctype']); $stype=$obj['doctype']; foreach($obj as $key=>$value){ $doc->$key=$value;//print "$key <br />"; } $doc->account=$accIndex[$doc->account]; //search for old acc index if (isset($doc->rcptdetials)) unset($doc->rcptdetials); if (isset($doc->docdetials)) unset($doc->docdetials); if($check){ if((strtotime($doc->issue_date)>$begindmy)&&(strtotime($doc->issue_date)<$enddmy)) $docIndex[$stype.$obj["docnum"]]=$doc->newDocument(); //print "we are chking!"; }else{ $docIndex[$stype.$obj["docnum"]]=$doc->newDocument(); } //get new doc index save old unset($doc); }*/ } if ($type == 'D110') { //Doc Detial $docdetial = new Docdetails(); $docdetial->readLine($line, $type); //Yii::log($docdetial,'info','app'); $docdetial->save(); unset($docdetial); /* global $DocOpenType; $stype=$DocOpenType[$obj['doctype']]; if (isset($docIndex[$stype.$obj["num"]])){ $docdetial=new documentDetail; $docdetial->price=$obj['price']; unset($obj['doctype']); unset($obj['price']); foreach($obj as $key=>$value){ $docdetial->{$key}=$value;//print "$key <br />"; } $docdetial->num=$docIndex[$stype.$obj["num"]]; $docdetial->newDetial(); //search for old doc index //die; //update to new index unset($docdetial); }//*/ } if ($type == 'D120') { //Kaballa Detial $rcptdetial = new Doccheques(); $rcptdetial->readLine($line, $type); Yii::log($rcptdetial, 'info', 'app'); $rcptdetial->save(); unset($rcptdetial); /* global $DocOpenType; $stype=$DocOpenType[$obj['doctype']]; if (isset($docIndex[$stype.$obj["refnum"]])){ $rcptdetial=new receiptDetail(); //$stype=$DocOpenType[$obj['doctype']]; $rcptdetial->sum=(float)$obj['sum']; unset($obj['sum']); unset($obj['doctype']); foreach($obj as $key=>$value){ $rcptdetial->$key=$value; } $rcptdetial->refnum=$docIndex[$stype.$obj["refnum"]]; $rcptdetial->newDetial(); //search for old doc index //update to new index unset($rcptdetial); }*/ } if ($type == 'B100') { //Move Recored $transaction = new Transactions(); $transaction->readLine($line, $type); $transaction->save(); //Yii::log($transaction,'info','app'); unset($transaction); /* //print $obj['value'].":".$obj['type']; global $openTransType; if (isset($accIndex[$obj['account']])){ $bsum= $obj['sum']; if($obj['value']==1) $bsum= -1 * $obj['sum']; //print $bsum."<br />\n"; $usum=$bsum*-1; $uaccount=$obj['account1']; $stype=$openTransType[$obj['type']]; unset($obj['sum']); unset($obj['value']); unset($obj['account1']); //adam:! need to reset type of action! $transaction=new transaction; foreach($obj as $key=>$value){ $transaction->$key=$value;//print "$key <br />"; } $transaction->type=$stype; $transaction->sum=$bsum; $transaction->account=$accIndex[$obj['account']]; if($check){ if((strtotime($transaction->date)>$begindmy)&&(strtotime($transaction->date)<$enddmy)){ // "gone"; $transaction->newTransactions(); } //print "gone2"; }else{ //print "gone1"; $transaction->newTransactions(); } unset($transaction); }//*/ } unset($obj); $suc[$type]++; } $analze[$type]++; //if ($analze[$type]>100) break; } Yii::log("End OpenImport", 'info', 'app'); //print_r($docIndex); //end loop //print_r($accIndex); } else { print _("error cant open file!"); } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $userincomemap = $model->userIncomeMaps; // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; if (isset($_POST['UserIncomeMap'])) { foreach ($_POST['UserIncomeMap'] as $key => $detial) { $saved = false; foreach ($userincomemap as $num => $submodel) { if ($submodel->itemVatCat_id == $detial['itemVatCat_id']) { //update lines unset($userincomemap[$num]); $submodel->attributes = $detial; $submodel->user_id = $model->id; //adam: if (!$submodel->save()) { echo "fatel error cant save doc detial"; } else { $saved = true; } } } //*/ if (!$saved) { //new line //unset($detial['id']); $detial['user_id'] = $model->id; $submodel = new Docdetails(); $submodel->attributes = $detial; if ($submodel->save()) { $saved = true; } else { echo "fatel error cant save doc detial"; } } } } if (count($userincomemap) != 0) { //if more items in $docdetails delete them foreach ($userincomemap as $userincome) { $userincome->delete(); } } if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model)); }
private function saveDet() { if (!is_null($this->docDet)) { $line = 1; foreach ($this->docDet as $key => $detial) { $fline = isset($detial['line']) ? $detial['line'] : 0; $submodel = Docdetails::model()->findByPk(array('doc_id' => $this->id, 'line' => $fline)); if ($submodel === null) { //new line $submodel = new Docdetails(); } $submodel->attributes = $detial; $submodel->line = $line; $submodel->doc_id = $this->id; if (Item::model()->findByPk((int) $detial["item_id"]) !== null) { $submodel->iItem = null; if ($submodel->save()) { $this->docDet[$key]['iTotalVat'] = $submodel->iTotalVat; $this->docDet[$key]['ihTotal'] = $submodel->ihTotal; $saved = true; $line++; } else { Yii::log("fatel error cant save docdetial,doc_id:" . $submodel->line . "," . $submodel->doc_id, CLogger::LEVEL_ERROR, __METHOD__); } } } if (count($this->docDetailes) != $line - 1) { //if more items in $docdetails delete them for ($curLine = $line; $curLine < count($this->docDetailes); $curLine++) { $this->docDetailes[$curLine]->delete(); } } } }